CREATE_PROJECT: Update revision number support (fixes bug #3280881)

Replace existing environment variable based revision number support by a file-based method
 - Generate a special header file in the build output folder with the current revision number
 - Include the new header file from internal_version.h when a specific define is set
 - Update create_project to define SCUMMVM_INTERNAL_REVISION as needed and add the build output folder to the include path
 - Remove support for git-svn clones in the revision script (not useful anymore after the switch to git)
This commit is contained in:
Littleboy 2011-04-24 12:34:57 -04:00
parent 4f708b0212
commit 11b907ebf4
12 changed files with 86 additions and 53 deletions

View file

@ -0,0 +1,6 @@
#ifndef SCUMMVM_INTERNAL_REVISION_H
#define SCUMMVM_INTERNAL_REVISION_H
#define SCUMMVM_REVISION "@REVISION@"
#endif

View file

@ -2,6 +2,12 @@
#error This file may only be included by base/version.cpp #error This file may only be included by base/version.cpp
#endif #endif
// Reads revision number from file
// (this is used when building with Visual Studio)
#ifdef SCUMMVM_INTERNAL_REVISION
#include "internal_revision.h"
#endif
#ifdef RELEASE_BUILD #ifdef RELEASE_BUILD
#undef SCUMMVM_REVISION #undef SCUMMVM_REVISION
#endif #endif

View file

@ -2,6 +2,12 @@
#error This file may only be included by base/version.cpp #error This file may only be included by base/version.cpp
#endif #endif
// Reads revision number from file
// (this is used when building with Visual Studio)
#ifdef SCUMMVM_INTERNAL_REVISION
#include "internal_revision.h"
#endif
#ifdef RELEASE_BUILD #ifdef RELEASE_BUILD
#undef SCUMMVM_REVISION #undef SCUMMVM_REVISION
#endif #endif

View file

@ -283,7 +283,7 @@ void MSBuildProvider::outputProjectSettings(std::ofstream &project, const std::s
project << "\t</ItemDefinitionGroup>\n"; project << "\t</ItemDefinitionGroup>\n";
} }
void MSBuildProvider::outputGlobalPropFile(std::ofstream &properties, int bits, const StringList &defines, const std::string &prefix) { void MSBuildProvider::outputGlobalPropFile(std::ofstream &properties, int bits, const StringList &defines, const std::string &prefix, bool runBuildEvents) {
std::string warnings; std::string warnings;
for (StringList::const_iterator i = _globalWarnings.begin(); i != _globalWarnings.end(); ++i) for (StringList::const_iterator i = _globalWarnings.begin(); i != _globalWarnings.end(); ++i)
@ -293,6 +293,10 @@ void MSBuildProvider::outputGlobalPropFile(std::ofstream &properties, int bits,
for (StringList::const_iterator i = defines.begin(); i != defines.end(); ++i) for (StringList::const_iterator i = defines.begin(); i != defines.end(); ++i)
definesList += *i + ';'; definesList += *i + ';';
// Add define to include revision header
if (runBuildEvents)
definesList += "SCUMMVM_INTERNAL_REVISION;";
properties << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" properties << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n" "<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n"
"\t<PropertyGroup>\n" "\t<PropertyGroup>\n"
@ -308,7 +312,7 @@ void MSBuildProvider::outputGlobalPropFile(std::ofstream &properties, int bits,
"\t\t<ClCompile>\n" "\t\t<ClCompile>\n"
"\t\t\t<DisableLanguageExtensions>true</DisableLanguageExtensions>\n" "\t\t\t<DisableLanguageExtensions>true</DisableLanguageExtensions>\n"
"\t\t\t<DisableSpecificWarnings>" << warnings << ";%(DisableSpecificWarnings)</DisableSpecificWarnings>\n" "\t\t\t<DisableSpecificWarnings>" << warnings << ";%(DisableSpecificWarnings)</DisableSpecificWarnings>\n"
"\t\t\t<AdditionalIncludeDirectories>$(SCUMMVM_LIBS)\\include;" << prefix << ";" << prefix << "\\engines;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n" "\t\t\t<AdditionalIncludeDirectories>$(SCUMMVM_LIBS)\\include;" << prefix << ";" << prefix << "\\engines;$(TargetDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n"
"\t\t\t<PreprocessorDefinitions>" << definesList << "%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" "\t\t\t<PreprocessorDefinitions>" << definesList << "%(PreprocessorDefinitions)</PreprocessorDefinitions>\n"
"\t\t\t<ExceptionHandling></ExceptionHandling>\n" "\t\t\t<ExceptionHandling></ExceptionHandling>\n"
"\t\t\t<RuntimeTypeInfo>false</RuntimeTypeInfo>\n" "\t\t\t<RuntimeTypeInfo>false</RuntimeTypeInfo>\n"
@ -436,9 +440,6 @@ void MSBuildProvider::writeFileListToProject(const FileNode &dir, std::ofstream
projectFile << "\t\t<ClCompile Include=\"" << (*entry).path << "\">\n" projectFile << "\t\t<ClCompile Include=\"" << (*entry).path << "\">\n"
"\t\t\t<ObjectFileName>$(IntDir)" << (*entry).prefix << "%(Filename).obj</ObjectFileName>\n"; "\t\t\t<ObjectFileName>$(IntDir)" << (*entry).prefix << "%(Filename).obj</ObjectFileName>\n";
if (hasEnding((*entry).path, "base\\version.cpp"))
projectFile << "\t\t\t<PreprocessorDefinitions Condition=\"'$(Configuration)'=='Debug'\">SCUMMVM_REVISION#&quot; $(SCUMMVM_REVISION_STRING)&quot;;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n";
projectFile << "\t\t</ClCompile>\n"; projectFile << "\t\t</ClCompile>\n";
} else { } else {
projectFile << "\t\t<ClCompile Include=\"" << (*entry).path << "\" />\n"; projectFile << "\t\t<ClCompile Include=\"" << (*entry).path << "\" />\n";

View file

@ -45,7 +45,7 @@ protected:
void writeReferences(std::ofstream &output); void writeReferences(std::ofstream &output);
void outputGlobalPropFile(std::ofstream &properties, int bits, const StringList &defines, const std::string &prefix); void outputGlobalPropFile(std::ofstream &properties, int bits, const StringList &defines, const std::string &prefix, bool runBuildEvents);
void createBuildProp(const BuildSetup &setup, bool isRelease, bool isWin32, bool enableAnalysis); void createBuildProp(const BuildSetup &setup, bool isRelease, bool isWin32, bool enableAnalysis);

View file

@ -124,7 +124,7 @@ void MSVCProvider::createGlobalProp(const BuildSetup &setup) {
if (!properties) if (!properties)
error("Could not open \"" + setup.outputDir + '/' + "ScummVM_Global" + getPropertiesExtension() + "\" for writing"); error("Could not open \"" + setup.outputDir + '/' + "ScummVM_Global" + getPropertiesExtension() + "\" for writing");
outputGlobalPropFile(properties, 32, setup.defines, convertPathToWin(setup.filePrefix)); outputGlobalPropFile(properties, 32, setup.defines, convertPathToWin(setup.filePrefix), setup.runBuildEvents);
properties.close(); properties.close();
properties.open((setup.outputDir + '/' + "ScummVM_Global64" + getPropertiesExtension()).c_str()); properties.open((setup.outputDir + '/' + "ScummVM_Global64" + getPropertiesExtension()).c_str());
@ -143,7 +143,7 @@ void MSVCProvider::createGlobalProp(const BuildSetup &setup) {
x64Defines.push_back("WIN32"); x64Defines.push_back("WIN32");
x64Defines.push_back("SDL_BACKEND"); x64Defines.push_back("SDL_BACKEND");
outputGlobalPropFile(properties, 64, x64Defines, convertPathToWin(setup.filePrefix)); outputGlobalPropFile(properties, 64, x64Defines, convertPathToWin(setup.filePrefix), setup.runBuildEvents);
} }
std::string MSVCProvider::getPreBuildEvent() const { std::string MSVCProvider::getPreBuildEvent() const {
@ -152,7 +152,7 @@ std::string MSVCProvider::getPreBuildEvent() const {
cmdLine = "@echo off\n" cmdLine = "@echo off\n"
"echo Executing Pre-Build script...\n" "echo Executing Pre-Build script...\n"
"echo.\n" "echo.\n"
"@call &quot;$(SolutionDir)../../devtools/create_project/scripts/prebuild.cmd&quot; &quot;$(SolutionDir)/../..&quot;\n" "@call &quot;$(SolutionDir)../../devtools/create_project/scripts/prebuild.cmd&quot; &quot;$(SolutionDir)/../..&quot; &quot;$(TargetDir)&quot;\n"
"EXIT /B0"; "EXIT /B0";
return cmdLine; return cmdLine;

View file

@ -59,8 +59,9 @@ protected:
* @param bits Number of bits the platform supports. * @param bits Number of bits the platform supports.
* @param defines Defines the platform needs to have set. * @param defines Defines the platform needs to have set.
* @param prefix File prefix, used to add additional include paths. * @param prefix File prefix, used to add additional include paths.
* @param runBuildEvents true if generating a revision number, false otherwise
*/ */
virtual void outputGlobalPropFile(std::ofstream &properties, int bits, const StringList &defines, const std::string &prefix) = 0; virtual void outputGlobalPropFile(std::ofstream &properties, int bits, const StringList &defines, const std::string &prefix, bool runBuildEvents) = 0;
/** /**
* Generates the project properties for debug and release settings. * Generates the project properties for debug and release settings.

View file

@ -12,7 +12,7 @@ REM Root folder
REM Output folder REM Output folder
REM Architecture REM Architecture
if "%~1"=="" goto error_input if "%~1"=="" goto error_root
if "%~2"=="" goto error_output if "%~2"=="" goto error_output
if "%~3"=="" goto error_arch if "%~3"=="" goto error_arch
@ -29,7 +29,7 @@ xcopy /F /Y "%~1/gui/themes/translations.dat" %~2 > NUL 2>&1
xcopy /F /Y "%SCUMMVM_LIBS%/lib/%~3/SDL.dll" %~2 > NUL 2>&1 xcopy /F /Y "%SCUMMVM_LIBS%/lib/%~3/SDL.dll" %~2 > NUL 2>&1
goto done goto done
:error_output :error_root
echo Invalid root folder (%~1)! echo Invalid root folder (%~1)!
goto done goto done

View file

@ -4,22 +4,28 @@ REM ---------------------------------------------------------------
REM -- Pre-Build Script REM -- Pre-Build Script
REM --------------------------------------------------------------- REM ---------------------------------------------------------------
REM REM
REM Generate file with proper revision number REM Generate file with revision number
REM REM
REM Expected parameters REM Expected parameters
REM Root folder REM Root folder (the source root folder)
REM Target folder (the build output folder, will be used to copy internal_revision.h)
if "%~1"=="" goto error_input if "%~1"=="" goto error_root
if "%~2"=="" goto error_target
REM Run the revision script REM Run the revision script
@call cscript "%~1/devtools/create_project/scripts/revision.vbs" %~1 1>NUL @call cscript "%~1/devtools/create_project/scripts/revision.vbs" %~1 %~2 1>NUL
if not %errorlevel% == 0 goto error_script if not %errorlevel% == 0 goto error_script
goto done goto done
:error_output :error_root
echo Invalid root folder (%~1)! echo Invalid root folder (%~1)!
goto done goto done
:error_target
echo Invalid target folder (%~2)!
goto done
:error_script: :error_script:
echo An error occured while running the revision script! echo An error occured while running the revision script!

View file

@ -35,6 +35,7 @@ Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
' Folders ' Folders
Dim rootFolder : rootFolder = "" Dim rootFolder : rootFolder = ""
Dim targetFolder : targetFolder = ""
' Info variables ' Info variables
Dim tool : tool = "" Dim tool : tool = ""
@ -85,23 +86,25 @@ Sub DetermineRevision()
Wscript.StdErr.WriteLine "Found revision " & revision & " on branch " & branch & vbCrLf Wscript.StdErr.WriteLine "Found revision " & revision & " on branch " & branch & vbCrLf
' Setup our revision string ' Setup our revision string
Dim revisionString : revisionString = "r" & revision Dim revisionString : revisionString = revision
If (modified) Then If (modified) Then
revisionString = revisionString & " M" revisionString = revisionString & "-dirty"
End If End If
' If we are not on trunk, add the branch name to the revision string ' If we are not on trunk, add the branch name to the revision string
If (branch <> "trunk" And branch <> "") Then If (branch <> "trunk" And branch <> "master" And branch <> "") Then
revisionString = revisionString & " (" & branch & ")" revisionString = revisionString & "(" & branch & ")"
End If End If
' Add the DVCS name at the end ' Add the DVCS name at the end (when not git)
revisionString = revisionString & " - " & tool If (tool <> "git") Then
revisionString = revisionString & "-" & tool
End If
' Setup an environment variable with the revision string ' Output revision header file
Dim Env: Set Env = WshShell.Environment("User") FSO.CopyFile rootFolder & "\\base\\internal_revision.h.in", targetFolder & "\\internal_revision.h"
Env.item("SCUMMVM_REVISION_STRING") = revisionString FindReplaceInFile targetFolder & "\\internal_revision.h", "@REVISION@", revisionString
End Sub End Sub
Function DetermineTortoiseSVNVersion() Function DetermineTortoiseSVNVersion()
@ -283,29 +286,9 @@ Function DetermineGitVersion()
End If End If
End If End If
' Check for svn clones
Set oExec = WshShell.Exec(gitPath & "log --pretty=format:%s --grep=" & Chr(34) & "^(svn r[0-9]*)" & Chr(34) & " -1 " & rootFolder)
if Err.Number = 0 Then
revision = Mid(oExec.StdOut.ReadLine(), 7)
revision = Mid(revision, 1, InStr(revision, ")") - 1)
tool = "svn-git"
End If
' No revision? Maybe it is a custom git-svn clone
If revision = "" Then
Err.Clear
Set oExec = WshShell.Exec(gitPath & "log --pretty=format:%b --grep=" & Chr(34) & "git-svn-id:.*@[0-9]*" & Chr(34) & " -1 " & rootFolder)
If Err.Number = 0 Then
revision = oExec.StdOut.ReadLine()
revision = Mid(revision, InStr(revision, "@") + 1)
revision = Mid(revision, 1, InStr(revision, " ") - 1)
tool = "svn-git"
End If
End If
' Fallback to abbreviated revision number ' Fallback to abbreviated revision number
If revision = "" Then If revision = "" Then
revision = Mid(hash, 1, 8) revision = Mid(hash, 1, 7)
End If End If
DetermineGitVersion = True DetermineGitVersion = True
@ -385,8 +368,8 @@ End Function
Function ParseCommandLine() Function ParseCommandLine()
ParseCommandLine = True ParseCommandLine = True
If Wscript.Arguments.Count <> 1 Then If Wscript.Arguments.Count <> 2 Then
Wscript.StdErr.WriteLine "[Error] Invalid number of arguments (was: " & Wscript.Arguments.Count & ", expected: 1)" Wscript.StdErr.WriteLine "[Error] Invalid number of arguments (was: " & Wscript.Arguments.Count & ", expected: 2)"
ParseCommandLine = False ParseCommandLine = False
Exit Function Exit Function
@ -394,6 +377,7 @@ Function ParseCommandLine()
' Get our arguments ' Get our arguments
rootFolder = Wscript.Arguments.Item(0) rootFolder = Wscript.Arguments.Item(0)
targetFolder = Wscript.Arguments.Item(1)
' Check that the folders are valid ' Check that the folders are valid
If Not FSO.FolderExists(rootFolder) Then If Not FSO.FolderExists(rootFolder) Then
@ -403,8 +387,16 @@ Function ParseCommandLine()
Exit Function Exit Function
End If End If
' Set absolute path If Not FSO.FolderExists(targetFolder) Then
Wscript.StdErr.WriteLine "[Error] Invalid target folder (" & targetFolder & ")"
ParseCommandLine = False
Exit Function
End If
' Set absolute paths
rootFolder = FSO.GetAbsolutePathName(rootFolder) rootFolder = FSO.GetAbsolutePathName(rootFolder)
targetFolder = FSO.GetAbsolutePathName(targetFolder)
End Function End Function
Function ReadRegistryKey(shive, subkey, valuename, architecture) Function ReadRegistryKey(shive, subkey, valuename, architecture)
@ -443,3 +435,14 @@ Function ReadRegistryKey(shive, subkey, valuename, architecture)
ReadRegistryKey = Outparams.SValue ReadRegistryKey = Outparams.SValue
End Function End Function
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

View file

@ -193,7 +193,7 @@ void VisualStudioProvider::writeReferences(std::ofstream &output) {
output << "\tEndProjectSection\n"; output << "\tEndProjectSection\n";
} }
void VisualStudioProvider::outputGlobalPropFile(std::ofstream &properties, int bits, const StringList &defines, const std::string &prefix) { void VisualStudioProvider::outputGlobalPropFile(std::ofstream &properties, int bits, const StringList &defines, const std::string &prefix, bool runBuildEvents) {
std::string warnings; std::string warnings;
for (StringList::const_iterator i = _globalWarnings.begin(); i != _globalWarnings.end(); ++i) for (StringList::const_iterator i = _globalWarnings.begin(); i != _globalWarnings.end(); ++i)
warnings += *i + ';'; warnings += *i + ';';
@ -205,6 +205,10 @@ void VisualStudioProvider::outputGlobalPropFile(std::ofstream &properties, int b
definesList += *i; definesList += *i;
} }
// Add define to include revision header
if (runBuildEvents)
definesList += "SCUMMVM_INTERNAL_REVISION;";
properties << "<?xml version=\"1.0\" encoding=\"Windows-1252\"?>\n" properties << "<?xml version=\"1.0\" encoding=\"Windows-1252\"?>\n"
"<VisualStudioPropertySheet\n" "<VisualStudioPropertySheet\n"
"\tProjectType=\"Visual C++\"\n" "\tProjectType=\"Visual C++\"\n"
@ -217,7 +221,7 @@ void VisualStudioProvider::outputGlobalPropFile(std::ofstream &properties, int b
"\t\tName=\"VCCLCompilerTool\"\n" "\t\tName=\"VCCLCompilerTool\"\n"
"\t\tDisableLanguageExtensions=\"true\"\n" "\t\tDisableLanguageExtensions=\"true\"\n"
"\t\tDisableSpecificWarnings=\"" << warnings << "\"\n" "\t\tDisableSpecificWarnings=\"" << warnings << "\"\n"
"\t\tAdditionalIncludeDirectories=\"" << prefix << ";" << prefix << "\\engines;$(SCUMMVM_LIBS)\\include\"\n" "\t\tAdditionalIncludeDirectories=\"" << prefix << ";" << prefix << "\\engines;$(SCUMMVM_LIBS)\\include;$(TargetDir)\"\n"
"\t\tPreprocessorDefinitions=\"" << definesList << "\"\n" "\t\tPreprocessorDefinitions=\"" << definesList << "\"\n"
"\t\tExceptionHandling=\"0\"\n" "\t\tExceptionHandling=\"0\"\n"
"\t\tRuntimeTypeInfo=\"false\"\n" "\t\tRuntimeTypeInfo=\"false\"\n"

View file

@ -43,7 +43,7 @@ protected:
void writeReferences(std::ofstream &output); void writeReferences(std::ofstream &output);
void outputGlobalPropFile(std::ofstream &properties, int bits, const StringList &defines, const std::string &prefix); void outputGlobalPropFile(std::ofstream &properties, int bits, const StringList &defines, const std::string &prefix, bool runBuildEvents);
void createBuildProp(const BuildSetup &setup, bool isRelease, bool isWin32, bool enableAnalysis); void createBuildProp(const BuildSetup &setup, bool isRelease, bool isWin32, bool enableAnalysis);