Fix build-test.sh wrapper build (dotnet/coreclr#19779)
authorJarret Shook <jashoo@microsoft.com>
Fri, 31 Aug 2018 18:25:20 +0000 (11:25 -0700)
committerGitHub <noreply@github.com>
Fri, 31 Aug 2018 18:25:20 +0000 (11:25 -0700)
* Fix build-test.sh wrapper build

In addition this change creates a json file with the build info so that the wrapper build
may be skipped if it was built on the same os/arch/buildtype.

* Address pr feedback

Commit migrated from https://github.com/dotnet/coreclr/commit/6de8d61ab595b2975a01ba4068a3840a6f7aaacd

src/coreclr/build-test.cmd
src/coreclr/build-test.sh
src/coreclr/tests/runtest.py
src/coreclr/tests/runtest.sh

index 1810051..361a3f8 100644 (file)
@@ -482,6 +482,8 @@ if errorlevel 1 (
     exit /b 1
 )
 
+echo { "build_os": "%__BuildOS%", "build_arch": "%__BuildArch%", "build_type": "%__BuildType%" } > "%__TestBinDir%/build_info.json"
+
 :SkipBuildingWrappers
 
 REM =========================================================================================
index 7ae045b..b7feaa4 100755 (executable)
@@ -203,6 +203,10 @@ build_Tests()
     __ProjectFilesDir=$__TestDir
     __TestBinDir=$__TestWorkingDir
 
+    if [ -f  "${__TestWorkingDir}/build_info.json" ]; then
+        rm  "${__TestWorkingDir}/build_info.json"
+    fi
+
     if [ $__RebuildTests -ne 0 ]; then
         if [ -d "${__TestBinDir}" ]; then
             echo "Removing tests build dir: ${__TestBinDir}"
@@ -289,18 +293,31 @@ build_Tests()
     if [ $__BuildTestWrappers -ne -0 ]; then
         echo "${__MsgPrefix}Creating test wrappers..."
 
-        # Always create the test wrappers and set the exclude file.
-        export __Exclude="$__TestDir/issues.targets"
-        echo "Exclude set to $__TestDir/issues.targets"
-        build_MSBuild_projects "Tests_XunitWrapper" "$__ProjectDir/tests/runtest.proj" "Test Xunit Wrapper" "-BuildWrappers" "-MsBuildEventLogging= " "-TargetsWindows=false"
+        export __Exclude="${__ProjectDir}/tests/issues.targets"
+        export __BuildLogRootName="Tests_XunitWrapper"
+
+        # Set up directories and file names
+        __BuildLogRootName=$subDirectoryName
+        __BuildLog="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.log"
+        __BuildWrn="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.wrn"
+        __BuildErr="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.err"
+
+        buildVerbosity="Summary"
+
+        if [ $__VerboseBuild == 1 ]; then
+            buildVerbosity="Diag"
+        fi
+
+        echo "${__DotNetCli}" msbuild "${__ProjectDir}/tests/runtest.proj" /p:RestoreAdditionalProjectSources=https://dotnet.myget.org/F/dotnet-core/ /p:BuildWrappers=true /p:TargetsWindows=false /fileloggerparameters:"\"Verbosity=normal;LogFile=${__BuildLog}\"" /fileloggerparameters1:"\"WarningsOnly;LogFile=${__BuildWrn}\"" /fileloggerparameters2:"\"ErrorsOnly;LogFile=${__BuildErr}\"" /consoleloggerparameters:$buildVerbosity /p:__BuildOS=$__BuildOS /p:__BuildType=$__BuildType /p:__BuildArch=$__BuildArch
+        "${__DotNetCli}" msbuild "${__ProjectDir}/tests/runtest.proj" /p:RestoreAdditionalProjectSources=https://dotnet.myget.org/F/dotnet-core/ /p:BuildWrappers=true /p:TargetsWindows=false /fileloggerparameters:"\"Verbosity=normal;LogFile=${__BuildLog}\"" /fileloggerparameters1:"\"WarningsOnly;LogFile=${__BuildWrn}\"" /fileloggerparameters2:"\"ErrorsOnly;LogFile=${__BuildErr}\"" /consoleloggerparameters:$buildVerbosity /p:__BuildOS=$__BuildOS /p:__BuildType=$__BuildType /p:__BuildArch=$__BuildArch
 
         if [ $? -ne 0 ]; then
             echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
             exit 1
         else
             echo "XUnit Wrappers have been built."
-            echo "Create marker \"${__XUnitWrapperBuiltMarker}\""
-            touch $__XUnitWrapperBuiltMarker
+            echo { "\"build_os\"": "\"${__BuildOS}\"", "\"build_arch\"": "\"${__BuildArch}\"", "\"build_type\"": "\"${__BuildType}\"" } > "${__TestWorkingDir}/build_info.json"
+
         fi
     fi
 
@@ -612,6 +629,7 @@ __SourceDir="$__ProjectDir/src"
 __PackagesDir="$__ProjectDir/packages"
 __RootBinDir="$__ProjectDir/bin"
 __BuildToolsDir="$__ProjectDir/Tools"
+__DotNetCli="${__BuildToolsDir}/dotnetcli/dotnet"
 __UnprocessedBuildArgs=
 __RunArgs=
 __MSBCleanBuildArgs=
@@ -862,7 +880,6 @@ initHostDistroRid
 # Set the remaining variables based upon the determined build configuration
 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
 __PackagesBinDir="$__BinDir/.nuget"
-__ToolsDir="$__RootBinDir/tools"
 __TestDir="$__ProjectDir/tests"
 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
 __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
index 36f3f8e..bd45d11 100755 (executable)
@@ -1914,6 +1914,23 @@ def do_setup(host_os,
 
     if unprocessed_args.build_test_wrappers:
         build_test_wrappers(host_os, arch, build_type, coreclr_repo_location, test_location)
+    else:
+        # We will write out build information into the test directory. This is used
+        # by runtest.py to determine whether we need to rebuild the test wrappers.
+        if os.path.isfile(os.path.join(test_location, "build_info.json")):
+            build_info = None
+            with open(os.path.join(test_location, "build_info.json")) as file_handle:
+                build_info = json.load(file_handle)
+
+            is_same_os = build_info["build_os"] == host_os
+            is_same_arch = build_info["build_arch"] == arch
+            is_same_build_type = build_info["build_type"] == build_type
+
+            # We will force a build of the test wrappers if they were cross built
+            if not (is_same_os and is_same_arch and is_same_build_type):
+                build_test_wrappers(host_os, arch, build_type, coreclr_repo_location, test_location)
+        else:
+            build_test_wrappers(host_os, arch, build_type, coreclr_repo_location, test_location)
 
     run_tests(host_os, 
               arch,
index 614692e..0917094 100755 (executable)
@@ -40,7 +40,7 @@ function print_usage {
     echo '  --tieredcompilation              : Runs the tests with COMPlus_TieredCompilation=1'
     echo '  --link <ILlink>                  : Runs the tests after linking via ILlink'
     echo '  --xunitOutputPath=<path>         : Create xUnit XML report at the specifed path (default: <test root>/coreclrtests.xml)'
-    echo '  --skipXunitWrapperBuild          : Skip creating the xunit wrapper'
+    echo '  --buildXUnitWrappers             : Force creating the xunit wrappers, this is useful if there have been changes to issues.targets'
     echo '  --printLastResultsOnly           : Print the results of the last run'
     echo ''
     echo 'CoreFX Test Options '
@@ -219,7 +219,7 @@ verbose=0
 doCrossgen=0
 jitdisasm=0
 ilasmroundtrip=
-skipXunitWrapperBuild=
+buildXUnitWrappers=
 printLastResultsOnly=
 generateLayoutOnly=
 generateLayout=
@@ -255,8 +255,8 @@ do
         release|Release)
             buildConfiguration="Release"
             ;;
-        --skipXunitWrapperBuild)
-            skipXunitWrapperBuild=1
+        --buildXUnitWrappers)
+            buildXUnitWrappers=1
             ;;
         --printLastResultsOnly)
             printLastResultsOnly=1
@@ -515,20 +515,11 @@ if [ ! -z "$ilasmroundtrip" ]; then
     runtestPyArguments+=("--ilasmroundtrip")
 fi
 
-if [ ! -z "$skipXunitWrapperBuild" ]; then
+if [ ! -z "$buildXUnitWrappers" ]; then
+    runtestPyArguments+=("--build_xunit_test_wrappers")
+else
     echo "Skipping xunit wrapper build. If build-test was called on a different"
     echo "host_os or arch the test run will most likely have failures."
-else
-    # By default rebuild the test wrappers, as we cannot gaurentee the following
-    # is true:
-    #   1) There are no added or removed excludes since the tests were built
-    #   2) That the wrapper generation happened on the same host_os and arch
-    #      as where we are running now
-    #
-    # Note that the wrapper generation is slow. To skip this pass --skipXunitWrapperBuild
-    # if the above requirements are met.
-
-    runtestPyArguments+=("--build_xunit_test_wrappers")
 fi
 
 if (($verbose!=0)); then