From e9924421bf53275ccdcf7d9ecd15e584dee6ad35 Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 12 Sep 2007 07:11:48 +0000 Subject: (svn r11089) -Codechange: add revision detection to MSVC. --- Makefile.src.in | 26 +++----- config.lib | 2 +- projects/determineversion.vbs | 129 ++++++++++++++++++++++++++++++++++++++++ projects/openttd.vcproj | 11 +++- projects/openttd.vcproj.in | 8 ++- projects/openttd_vs80.vcproj | 12 ++++ projects/openttd_vs80.vcproj.in | 8 +++ source.list | 1 + src/network/network.cpp | 12 +--- src/network/network.h | 2 - src/ottdres.rc | 107 --------------------------------- src/ottdres.rc.in | 107 +++++++++++++++++++++++++++++++++ src/rev.cpp.in | 4 ++ 13 files changed, 287 insertions(+), 142 deletions(-) create mode 100644 projects/determineversion.vbs delete mode 100644 src/ottdres.rc create mode 100644 src/ottdres.rc.in create mode 100644 src/rev.cpp.in diff --git a/Makefile.src.in b/Makefile.src.in index 2d3a5205c..7d2be57b3 100644 --- a/Makefile.src.in +++ b/Makefile.src.in @@ -249,15 +249,15 @@ $(OBJS_RC): %.o: $(SRC_DIR)/%.rc $(FILE_DEP) $(BIN_DIR)/$(TTD): $(TTD) $(Q)cp $< $@ -$(TTD): rev.o $(OBJS) $(CONFIG_CACHE_LINKER) +$(TTD): $(OBJS) $(CONFIG_CACHE_LINKER) $(E) '$(STAGE) Linking $@' ifeq ($(OS), PSP) # Because of a bug in the PSP GCC tools, linking via CXX results # in total chaos and more problems then you can handle. So we need # CC to link OpenTTD for PSP - $(Q)$(CC_HOST) $(LDFLAGS) rev.o $(OBJS) $(LIBS) -o $@ + $(Q)$(CC_HOST) $(LDFLAGS) $(OBJS) $(LIBS) -o $@ else - $(Q)$(CXX_HOST) $(LDFLAGS) rev.o $(OBJS) $(LIBS) -o $@ + $(Q)$(CXX_HOST) $(LDFLAGS) $(OBJS) $(LIBS) -o $@ endif ifdef STRIP $(Q)$(STRIP) $@ @@ -275,19 +275,11 @@ $(ENDIAN_CHECK): $(SRC_DIR)/endian_check.cpp # Revision files -rev.cpp: $(CONFIG_CACHE_VERSION) -# setting the revision number in a place, there the binary can read it - @echo 'extern const char _openttd_revision[] = "$(REV)";' > rev.cpp -# Some additions for MorphOS versions tag -ifeq ($(OS),MORPHOS) - @echo '#ifdef __MORPHOS__' >> rev.cpp - @echo 'extern const char morphos_versions_tag[] = "\\0$$VER: OpenTTD $(REV) ('`date +%d.%m.%y`') (C) OpenTTD Team [MorphOS, PowerPC]";' >> rev.cpp - @echo '#endif' >> rev.cpp -endif +$(SRC_DIR)/rev.cpp: $(CONFIG_CACHE_VERSION) $(SRC_DIR)/rev.cpp.in + $(Q)cat $(SRC_DIR)/rev.cpp.in | sed "s#@@VERSION@@#$(REV)#g;s#@@DATE@@#`date +%d.%m.%y`#g" > $(SRC_DIR)/rev.cpp -rev.o: rev.cpp $(FILE_DEP) - $(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.cpp=%.cpp)' - $(Q)$(CXX_HOST) $(CFLAGS) -c -o $@ $< +$(SRC_DIR)/ottdres.rc: $(CONFIG_CACHE_VERSION) $(SRC_DIR)/ottdres.rc.in + $(Q)cat $(SRC_DIR)/ottdres.rc.in | sed "s#@@VERSION@@#$(REV)#g;s#@@DATE@@#`date +%d.%m.%y`#g" > $(SRC_DIR)/ottdres.rc FORCE: @@ -295,10 +287,10 @@ depend: $(DEPS) clean: $(E) '$(STAGE) Cleaning up object files' - $(Q)rm -f $(DEPS) $(OBJS) $(TTD) $(TTD:%=$(BIN_DIR)/%) $(CONFIG_CACHE_COMPILER) $(CONFIG_CACHE_LINKER) $(CONFIG_CACHE_ENDIAN) $(CONFIG_CACHE_SOURCE) $(ENDIAN_TARGETS) rev.o rev.cpp + $(Q)rm -f $(DEPS) $(OBJS) $(TTD) $(TTD:%=$(BIN_DIR)/%) $(CONFIG_CACHE_COMPILER) $(CONFIG_CACHE_LINKER) $(CONFIG_CACHE_ENDIAN) $(CONFIG_CACHE_SOURCE) $(ENDIAN_TARGETS) mrproper: clean - $(Q)rm -f rev.cpp + $(Q)rm -f $(SRC_DIR)/rev.cpp $(SRC_DIR)/ottdres.rc %.o: @echo '$(STAGE) No such source-file: $(@:%.o=%).[c|cpp|mm|rc]' diff --git a/config.lib b/config.lib index bd3fbdb9c..dff8be929 100644 --- a/config.lib +++ b/config.lib @@ -745,7 +745,7 @@ make_cflags_and_ldflags() { # General CFlags for BUILD CFLAGS_BUILD="" # General CFlags for HOST - CFLAGS="$CFLAGS -D$os -DWITH_REV" + CFLAGS="$CFLAGS -D$os" # CFlags for HOST and C-Compiler CC_FLAGS="" # Libs to compile. In fact this is just LDFLAGS diff --git a/projects/determineversion.vbs b/projects/determineversion.vbs new file mode 100644 index 000000000..fc1c31405 --- /dev/null +++ b/projects/determineversion.vbs @@ -0,0 +1,129 @@ +Option Explicit + +Dim FSO +Set FSO = CreateObject("Scripting.FileSystemObject") + +Sub FindReplaceInFile(filename, to_find, replacement) + Dim file, data + Set file = FSO.OpenTextFile(filename, 1, 0, 0) + data = file.ReadAll + file.Close + data = Replace(data, to_find, replacement) + Set file = FSO.CreateTextFile(FileName, -1, 0) + file.Write data + file.Close +End Sub + +Sub UpdateFile(version, cur_date, filename) + FSO.CopyFile filename & ".in", filename + FindReplaceInFile filename, "@@VERSION@@", version + FindReplaceInFile filename, "@@DATE@@", cur_date +End Sub + +Sub UpdateFiles(version) + Dim cur_date + cur_date = DatePart("D", Date) & "." & DatePart("M", Date) & "." & DatePart("YYYY", Date) + UpdateFile version, cur_date, "../src/rev.cpp" + UpdateFile version, cur_date, "../src/ottdres.rc" +End Sub + +Function DetermineSVNVersion() + Dim WshShell, version, url, oExec + Set WshShell = CreateObject("WScript.Shell") + On Error Resume Next + + ' Try TortoiseSVN + ' Get the directory where TortoiseSVN (should) reside(s) + Dim sTortoise + sTortoise = WshShell.RegRead("HKLM\SOFTWARE\TortoiseSVN\Directory") + + Dim file + ' Write some "magic" to a temporary file so we can acquire the svn revision/state + Set file = FSO.CreateTextFile("tsvn_tmp", -1, 0) + file.WriteLine "$WCREV$$WCMODS?M:$" + file.WriteLine "$WCURL$" + file.Close + Set oExec = WshShell.Exec(sTortoise & "\bin\SubWCRev.exe ../src tsvn_tmp tsvn_tmp") + ' Wait till the application is finished ... + Do + OExec.StdOut.ReadLine() + Loop While Not OExec.StdOut.atEndOfStream + + Set file = FSO.OpenTextFile("tsvn_tmp", 1, 0, 0) + version = file.ReadLine + url = file.ReadLine + file.Close + + Set file = FSO.GetFile("tsvn_tmp") + file.Delete + + ' Looks like there is no TortoiseSVN installed either. Then we don't know it. + If InStr(version, "$") Then + ' Reset error and version + Err.Clear + version = "norev000" + ' Do we have subversion installed? Check immediatelly whether we've got a modified WC. + Set oExec = WshShell.Exec("svnversion ../src") + If Err.Number = 0 Then + Dim modified + If InStr(OExec.StdOut.ReadLine(), "M") Then + modified = "M" + Else + modified = "" + End If + + ' Set the environment to english + WshShell.Environment("PROCESS")("LANG") = "en" + + ' And use svn info to get the correct revision and branch information. + Set oExec = WshShell.Exec("svn info ../src") + If Err.Number = 0 Then + Dim line + Do + line = OExec.StdOut.ReadLine() + If InStr(line, "URL") Then + url = line + End If + If InStr(line, "Last Changed Rev") Then + version = Mid(line, 19) & modified + End If + Loop While Not OExec.StdOut.atEndOfStream + End If + End If + End If + + If version <> "norev000" Then + If InStr(url, "branches") Then + url = Mid(url, InStr(url, "branches") + 8) + url = Mid(url, 1, InStr(2, url, "/") - 1) + version = version & Replace(url, "/", "-") + End If + End If + + DetermineSVNVersion = version +End Function + +Function IsCachedVersion(version) + Dim cache_file, cached_version + cached_version = "" + Set cache_file = FSO.OpenTextFile("../config.cache.version", 1, True, 0) + If Not cache_file.atEndOfStream Then + cached_version = cache_file.ReadLine() + End If + cache_file.Close + + If version <> cached_version Then + Set cache_file = fso.CreateTextFile("../config.cache.version", True) + cache_file.WriteLine(version) + cache_file.Close + IsCachedVersion = False + Else + IsCachedVersion = True + End If +End Function + +Dim version +version = DetermineSVNVersion +If Not (IsCachedVersion(version) And FSO.FileExists("../src/rev.cpp") And FSO.FileExists("../src/ottdres.rc")) Then + UpdateFiles version +End If diff --git a/projects/openttd.vcproj b/projects/openttd.vcproj index bd6617768..fae3678b5 100644 --- a/projects/openttd.vcproj +++ b/projects/openttd.vcproj @@ -73,7 +73,9 @@ + Name="VCPreBuildEventTool" + Description="Determining version number" + CommandLine="$(InputDir)/determineversion.vbs"/> + Name="VCPreBuildEventTool" + Description="Determining version number" + CommandLine="$(InputDir)/determineversion.vbs"/> + + diff --git a/projects/openttd.vcproj.in b/projects/openttd.vcproj.in index 0bf01c070..bf58713a0 100644 --- a/projects/openttd.vcproj.in +++ b/projects/openttd.vcproj.in @@ -73,7 +73,9 @@ + Name="VCPreBuildEventTool" + Description="Determining version number" + CommandLine="$(InputDir)/determineversion.vbs"/> + Name="VCPreBuildEventTool" + Description="Determining version number" + CommandLine="$(InputDir)/determineversion.vbs"/> + + diff --git a/projects/openttd_vs80.vcproj.in b/projects/openttd_vs80.vcproj.in index 83dab75d3..de8feb428 100644 --- a/projects/openttd_vs80.vcproj.in +++ b/projects/openttd_vs80.vcproj.in @@ -33,6 +33,8 @@ >