Fix incremental build when dummy version.cpp is generated (dotnet/coreclr#8547)
authorJan Vorlicek <janvorli@microsoft.com>
Fri, 9 Dec 2016 09:50:01 +0000 (10:50 +0100)
committerGitHub <noreply@github.com>
Fri, 9 Dec 2016 09:50:01 +0000 (10:50 +0100)
This change fixes a problem with incremental build on Unix. When the
version.cpp is generated by the build.sh as a dummy one with no real
version stamp in it, it is recreated every time the build.sh is run.
That means that build needs to rebuild that file and also re-link
all the components that include it.
This change tests the file presence and contents before actually
regenerating it.

Commit migrated from https://github.com/dotnet/coreclr/commit/101168c7a41058436f592bd9cb0a1a70f0f1b0ad

src/coreclr/build.sh

index 1017d5c..50cbc70 100755 (executable)
@@ -167,16 +167,22 @@ build_coreclr()
     if [ $__SkipConfigure == 0 ]; then
         # if msbuild is not supported, then set __SkipGenerateVersion to 1
         if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
-        # Drop version.c file
+        # Drop version.cpp file
         __versionSourceFile=$__IntermediatesDir/version.cpp
         if [ $__SkipGenerateVersion == 0 ]; then
             "$__ProjectRoot/run.sh" build -Project=$__ProjectDir/build.proj -generateHeaderUnix -NativeVersionSourceFile=$__versionSourceFile $__RunArgs $__UnprocessedBuildArgs
         else
+            # Generate the dummy version.cpp, but only if it didn't exist to make sure we don't trigger unnecessary rebuild
             __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
-            echo $__versionSourceLine > $__versionSourceFile
+            if [ -e $__versionSourceFile ]; then
+                read existingVersionSourceLine < $__versionSourceFile
+            fi
+            if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then
+                echo $__versionSourceLine > $__versionSourceFile
+            fi
         fi
 
-               pushd "$__IntermediatesDir"
+        pushd "$__IntermediatesDir"
         # Regenerate the CMake solution
         __ExtraCmakeArgs="-DCLR_CMAKE_TARGET_OS=$__BuildOS -DCLR_CMAKE_PACKAGES_DIR=$__PackagesDir -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument"
         echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion $__ClangMinorVersion $__BuildArch $__BuildType $__CodeCoverage $__IncludeTests $generator $__ExtraCmakeArgs $__cmakeargs"