Add ability to only copy native test files to managed tests in build-test scripts...
authorJeremy Koritzinsky <jekoritz@microsoft.com>
Fri, 30 Aug 2019 23:08:36 +0000 (16:08 -0700)
committerGitHub <noreply@github.com>
Fri, 30 Aug 2019 23:08:36 +0000 (16:08 -0700)
* Add MSBuild targets neccesary to copy native test assets to managed projects that need them in a way separate from the managed test build.

* Hook up native test binary copying through build-test scripts.

* Unix script changes/cleanup

* Remove unconditional generatelayout in runtest.sh

* Add new options to usage

Commit migrated from https://github.com/dotnet/coreclr/commit/05c6400d3614ef15dc76e458ff83e54dc0326c4c

src/coreclr/build-test.cmd
src/coreclr/build-test.sh
src/coreclr/tests/dir.traversal.targets
src/coreclr/tests/runtest.sh
src/coreclr/tests/src/dir.targets
src/coreclr/tests/src/dirs.proj

index 70811ff..cf0f1b8 100644 (file)
@@ -54,6 +54,8 @@ set __SkipNative=
 set __RuntimeId=
 set __TargetsWindows=1
 set __DoCrossgen=
+set __CopyNativeTestBinaries=0
+set __SkipGenerateLayout=0
 
 @REM CMD has a nasty habit of eating "=" on the argument list, so passing:
 @REM    -priority=1
@@ -94,6 +96,8 @@ if /i "%1" == "runtimeid"             (set __RuntimeId=%2&set processedArgs=!pro
 if /i "%1" == "targetsNonWindows"     (set __TargetsWindows=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
 if /i "%1" == "Exclude"               (set __Exclude=%2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop)
 if /i "%1" == "-priority"             (set __Priority=%2&shift&set processedArgs=!processedArgs! %1=%2&shift&goto Arg_Loop)
+if /i "%1" == "copynativeonly"        (set __CopyNativeTestBinaries=1&set __SkipNative=1&set __SkipRestorePackages=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
+if /i "%1" == "skipgeneratelayout"    (set __SkipGenerateLayout=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
 if /i "%1" == "--"                    (set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
 
 if [!processedArgs!]==[] (
@@ -256,7 +260,7 @@ REM === Restore product binaries from packages
 REM ===
 REM =========================================================================================
 
-if "%__SkipRestorePackages%" == 1 goto SkipRestoreProduct
+if "%__SkipRestorePackages%" == "1" goto SkipRestoreProduct
 
 echo %__MsgPrefix%Restoring CoreCLR product from packages
 
@@ -319,21 +323,41 @@ for /l %%G in (1, 1, %__NumberOfTestGroups%) do (
     set __Logging='!__MsbuildLog!' '!__MsbuildWrn!' '!__MsbuildErr!'
 
     set __TestGroupToBuild=%%G
-    echo Running: msbuild %__ProjectDir%\tests\build.proj !__MsbuildLog! !__MsbuildWrn! !__MsbuildErr! %TargetsWindowsMsbuildArg% %__msbuildArgs% !__PriorityArg! %__UnprocessedBuildArgs%
-
-    REM Disable warnAsError - coreclr issue 19922
-    powershell -NoProfile -ExecutionPolicy ByPass -NoLogo -Command "%__ProjectDir%\eng\common\msbuild.ps1" %__ArcadeScriptArgs%^
-        %__ProjectDir%\tests\build.proj -warnAsError:0 !__Logging! %TargetsWindowsMsbuildArg% %__msbuildArgs% !__PriorityArg! %__UnprocessedBuildArgs%
-
-    if errorlevel 1 (
-        echo %__ErrMsgPrefix%%__MsgPrefix%Error: managed test build failed. Refer to the build log files for details:
-        echo     %__BuildLog%
-        echo     %__BuildWrn%
-        echo     %__BuildErr%
-        REM This is necessary because of a(n apparent) bug in the FOR /L command.  Under certain circumstances,
-        REM such as when this script is invoke with CMD /C "build-test.cmd", a non-zero exit directly from
-        REM within the loop body will not propagate to the caller.  For some reason, goto works around it.
-        goto     :Exit_Failure
+
+    if not "%__CopyNativeTestBinaries%" == "1" (
+        echo Running: msbuild %__ProjectDir%\tests\build.proj !__MsbuildLog! !__MsbuildWrn! !__MsbuildErr! %TargetsWindowsMsbuildArg% %__msbuildArgs% !__PriorityArg! %__UnprocessedBuildArgs%
+
+        REM Disable warnAsError - coreclr issue 19922
+        powershell -NoProfile -ExecutionPolicy ByPass -NoLogo -Command "%__ProjectDir%\eng\common\msbuild.ps1" %__ArcadeScriptArgs%^
+            %__ProjectDir%\tests\build.proj -warnAsError:0 !__Logging! %TargetsWindowsMsbuildArg% %__msbuildArgs% !__PriorityArg! %__UnprocessedBuildArgs%
+
+        if errorlevel 1 (
+            echo %__ErrMsgPrefix%%__MsgPrefix%Error: managed test build failed. Refer to the build log files for details:
+            echo     %__BuildLog%
+            echo     %__BuildWrn%
+            echo     %__BuildErr%
+            REM This is necessary because of a(n apparent) bug in the FOR /L command.  Under certain circumstances,
+            REM such as when this script is invoke with CMD /C "build-test.cmd", a non-zero exit directly from
+            REM within the loop body will not propagate to the caller.  For some reason, goto works around it.
+            goto     :Exit_Failure
+        )
+    ) else (
+        echo Running: msbuild %__ProjectDir%\tests\build.proj !__MsbuildLog! !__MsbuildWrn! !__MsbuildErr! %TargetsWindowsMsbuildArg% %__msbuildArgs% !__PriorityArg! %__UnprocessedBuildArgs% /t:CopyAllNativeProjectReferenceBinaries
+
+        REM Disable warnAsError - coreclr issue 19922
+        powershell -NoProfile -ExecutionPolicy ByPass -NoLogo -Command "%__ProjectDir%\eng\common\msbuild.ps1" %__ArcadeScriptArgs%^
+            %__ProjectDir%\tests\build.proj -warnAsError:0 !__Logging! %TargetsWindowsMsbuildArg% %__msbuildArgs% !__PriorityArg! %__UnprocessedBuildArgs% "/t:CopyAllNativeProjectReferenceBinaries"
+
+        if errorlevel 1 (
+            echo %__ErrMsgPrefix%%__MsgPrefix%Error: copying native test binaries failed. Refer to the build log files for details:
+            echo     %__BuildLog%
+            echo     %__BuildWrn%
+            echo     %__BuildErr%
+            REM This is necessary because of a(n apparent) bug in the FOR /L command.  Under certain circumstances,
+            REM such as when this script is invoke with CMD /C "build-test.cmd", a non-zero exit directly from
+            REM within the loop body will not propagate to the caller.  For some reason, goto works around it.
+            goto     :Exit_Failure
+        )
     )
 
     set __SkipPackageRestore=true
@@ -341,6 +365,8 @@ for /l %%G in (1, 1, %__NumberOfTestGroups%) do (
     set __AppendToLog=true
 )
 
+if "%__CopyNativeTestBinaries%" == "1" goto :SkipManagedBuild
+
 REM Check that we've built about as many tests as we expect. This is primarily intended to prevent accidental changes that cause us to build
 REM drastically fewer Pri-1 tests than expected.
 echo %__MsgPrefix%Check the managed tests build
@@ -354,6 +380,8 @@ if errorlevel 1 (
 
 :SkipManagedBuild
 
+if "%__SkipGenerateLayout%" == "1" goto TestBuildDone
+
 REM =========================================================================================
 REM ===
 REM === Prepare the test drop
@@ -499,6 +527,7 @@ REM ===
 REM === All builds complete!
 REM ===
 REM =========================================================================================
+:TestBuildDone
 
 echo %__MsgPrefix%Test build succeeded.  Finished at %TIME%
 echo %__MsgPrefix%Test binaries are available at !__TestBinDir!
@@ -534,6 +563,8 @@ echo     ubuntu.16.10-x64: Builds overlay for Ubuntu 16.10
 echo     win-x64: Builds overlay for portable Windows
 echo     win7-x64: Builds overlay for Windows 7
 echo crossgen: Precompiles the framework managed assemblies
+echo copynativeonly: Only copy the native test binaries to the managed output. Do not build the native or managed tests.
+echo skipgeneratelayout: Do not generate the Core_Root layout or the CoreFX testhost.
 echo targetsNonWindows:
 echo Exclude- Optional parameter - specify location of default exclusion file ^(defaults to tests\issues.targets if not specified^)
 echo     Set to "" to disable default exclusion file.
index 1923962..ed42541 100755 (executable)
@@ -349,15 +349,28 @@ build_Tests()
         fi
 
         echo "Managed tests build success!"
+
+        build_test_wrappers
     fi
 
-    build_test_wrappers
+    if [ $__CopyNativeTestBinaries == 1 ]; then
+        echo "Copying native test binaries to output..."
+
+        build_MSBuild_projects "Tests_Managed" "$__ProjectDir/tests/build.proj" "Managed tests build (build tests)" "/t:CopyAllNativeProjectReferenceBinaries"
+
+        if [ $? -ne 0 ]; then
+            echo "${__ErrMsgPrefix}${__MsgPrefix}Error: copying native test binaries failed. Refer to the build log files for details (above)"
+            exit 1
+        fi
+    fi
 
     if [ -n "$__UpdateInvalidPackagesArg" ]; then
         __up="/t:UpdateInvalidPackageVersions"
     fi
 
-    generate_layout
+    if [ $__SkipGenerateLayout != 1 ]; then
+        generate_layout
+    fi
 }
 
 build_MSBuild_projects()
@@ -571,6 +584,8 @@ usage()
     echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
     echo "msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
     echo "priority1 - include priority=1 tests in the build"
+    echo "copynativeonly: Only copy the native test binaries to the managed output. Do not build the native or managed tests."
+    echo "skipgeneratelayout: Do not generate the Core_Root layout or the CoreFX testhost."
     exit 1
 }
 
@@ -699,6 +714,8 @@ __GenerateTestHostOnly=
 __priority1=
 __BuildTestWrappersOnly=
 __DoCrossgen=0
+__CopyNativeTestBinaries=0
+__SkipGenerateLayout=0
 CORE_ROOT=
 
 while :; do
@@ -911,6 +928,17 @@ while :; do
             __UnprocessedBuildArgs+=("/p:CLRTestPriorityToBuild=1")
             ;;
 
+        copynativeonly)
+            __SkipNative=1
+            __SkipManaged=1
+            __CopyNativeTestBinaries=1
+            __SkipRestorePackages=1
+            ;;
+
+        skipgeneratelayout)
+            __SkipGenerateLayout=1
+            ;;
+
         *)
             __UnprocessedBuildArgs+=("$1")
             ;;
index ad5a710..22e5586 100644 (file)
     <!-- Given we ErrorAndContinue we need to propagate the error if the overall task failed -->
     <Error Condition="'$(MSBuildLastTaskResult)'=='false'" />
   </Target>
+  
+  <Target Name="CopyAllNativeTestProjectBinaries">
+    <Message Importance="High" Text="Copying native test binaries..." />
+
+    <PropertyGroup>
+      <DefaultCopyAllNativeTestProjectBinariesTarget Condition="'$(DefaultCopyAllNativeTestProjectBinariesTarget)'==''">CopyAllNativeProjectReferenceBinaries</DefaultCopyAllNativeTestProjectBinariesTarget>
+    </PropertyGroup>
+
+    <!-- To Serialize we use msbuild's batching functionality '%' to force it to batch all similar projects with the same identity 
+      however since the project names are unique it will essentially force each to run in its own batch -->
+    <MSBuild Targets="$(DefaultCopyAllNativeTestProjectBinariesTarget)"
+             Projects="@(Project)"
+             Condition="'$(SerializeProjects)'=='true'"
+             Properties="Dummy=%(Identity)"
+             ContinueOnError="ErrorAndContinue" />
+
+    <MSBuild Targets="$(DefaultCopyAllNativeTestProjectBinariesTarget)"
+             Projects="@(Project)"
+             Condition="'$(SerializeProjects)'!='true'"
+             BuildInParallel="true"
+             ContinueOnError="ErrorAndContinue" />
+
+    <!-- Given we ErrorAndContinue we need to propagate the error if the overall task failed -->
+    <Error Condition="'$(MSBuildLastTaskResult)'=='false'" />
+  </Target>
 
   <PropertyGroup>
     <TraversalBuildDependsOn>
       RestoreAllProjectPackages;
       $(TraversalRestorePackagesDependsOn)
     </TraversalRestorePackagesDependsOn>
+    <TraversalCopyAllNativeProjectReferenceBinariesDependsOn>
+      CopyAllNativeTestProjectBinaries;
+      $(TraversalCopyAllNativeProjectReferenceBinariesDependsOn)
+    </TraversalCopyAllNativeProjectReferenceBinariesDependsOn>
   </PropertyGroup>
 
   <Target Name="Build" DependsOnTargets="$(TraversalBuildDependsOn)" />
 
   <Target Name="RestorePackages" DependsOnTargets="$(TraversalRestorePackagesDependsOn)" />
 
-</Project>
\ No newline at end of file
+  <Target Name="CopyAllNativeProjectReferenceBinaries" DependsOnTargets="$(TraversalCopyAllNativeProjectReferenceBinariesDependsOn)" />
+</Project>
index 2cb5fbc..47bd80c 100755 (executable)
@@ -482,13 +482,6 @@ if [ ! -z "$coreClrBinDir" ]; then
     echo "Product Location              : ${coreClrBinDir}"
 fi
 
-if [ -z "$coreOverlayDir" ]; then
-    runtestPyArguments+=("--generate_layout")
-else
-    runtestPyArguments+=("-core_root" "$coreOverlayDir")
-    echo "Core Root Location            : ${coreOverlayDir}"
-fi
-
 if [ ! -z "$testNativeBinDir" ]; then
     runtestPyArguments+=("-test_native_bin_location" "$testNativeBinDir")
     echo "Test Native Bin Location      : ${testNativeBinDir}"
index 24c0abe..82d242a 100644 (file)
     <_WillCLRTestProjectBuild Condition="'$(BuildAllProjects)' != 'true'">true</_WillCLRTestProjectBuild>
     <_WillCLRTestProjectBuild Condition="'$(DisableProjectBuild)' != 'true' And '$(BuildAllProjects)' == 'true' And '$(CLRTestPriority)' &lt;= '$(CLRTestPriorityToBuild)'">true</_WillCLRTestProjectBuild>
   </PropertyGroup>
+
+  <PropertyGroup>
+    <CopyNativeProjectBinaries Condition="'$(CopyNativeProjectBinaries)' == '' And '$(_WillCLRTestProjectBuild)' == 'true' And '$(DisableProjectBuild)' != 'true'">true</CopyNativeProjectBinaries>
+    <CopyNativeProjectBinaries Condition="'$(CopyNativeProjectBinaries)' == '' And ('$(_WillCLRTestProjectBuild)' == 'false' Or '$(DisableProjectBuild)' == 'true')">false</CopyNativeProjectBinaries>
+  </PropertyGroup>
     
   <!-- if we have determined that there is nothing to build, overwrite the build targets so that nothing happens -->
   <Import Project="nobuild.targets" Condition="'$(_WillCLRTestProjectBuild)' == 'false'" />
   </Target>
 
   <Target Name="ConsolidateNativeProjectReference"
-          Condition="'@(NativeProjectReferenceNormalized)' != ''"
+          Condition="'@(NativeProjectReferenceNormalized)' != '' and '$(CopyNativeProjectBinaries)' == 'true'"
           BeforeTargets="Build" >
      <ItemGroup>
         <NativeProjectOutputFoldersToCopy Include="$([System.String]::Copy('%(NativeProjectReferenceNormalized.RelativeDir)').Replace($(SourceDir),$(__NativeTestIntermediatesDir)\src\))" Condition="'$(RunningOnUnix)' == 'true'" />
 
   </Target>
 
+  <Target Name="CopyAllNativeProjectReferenceBinaries" DependsOnTargets="ResolveCmakeNativeProjectReference;ConsolidateNativeProjectReference" />
+
   <Target Name="UpdateReferenceItems"
           BeforeTargets="BeforeResolveReferences"
   >
index e809a93..66b6a95 100644 (file)
@@ -12,7 +12,7 @@
     <Warning Text="Looks like there may be an update to the build tools. Please run buildtest.cmd from the root of the repo to refresh the build tools." /> 
   </Target>
 
-  <Target Name="ResolveDisabledProjects" BeforeTargets="BuildAllProjects" >
+  <Target Name="ResolveDisabledProjects" BeforeTargets="BuildAllProjects;CopyAllNativeTestProjectBinaries" >
     <ItemGroup>
       <DisabledProjects Include="TestWrappers*\**\*.csproj" />
       <DisabledProjects Include="*\**\cs_template.csproj" />