Skip to content

Commit

Permalink
Source-build fixes in build scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Haplois committed Feb 1, 2022
1 parent dd1928a commit 9988689
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 35 deletions.
14 changes: 0 additions & 14 deletions eng/SourceBuild.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,4 @@
<InnerBuildArgs>$(InnerBuildArgs) -c $(Configuration)</InnerBuildArgs>
</PropertyGroup>

<!-- TODO: Remove once all patches have been removed. -->
<Target Name="ApplySourceBuildPatchFiles"
AfterTargets="PrepareInnerSourceBuildRepoRoot"
BeforeTargets="RunInnerSourceBuildCommand">
<ItemGroup>
<SourceBuildPatchFile Include="$(RepositoryEngineeringDir)source-build-patches\*.patch" />
</ItemGroup>

<Exec
Command="git --work-tree=$(InnerSourceBuildRepoRoot) apply --ignore-whitespace --whitespace=nowarn &quot;%(SourceBuildPatchFile.FullPath)&quot;"
WorkingDirectory="$(InnerSourceBuildRepoRoot)"
Condition="'@(SourceBuildPatchFile)' != ''" />
</Target>

</Project>
44 changes: 37 additions & 7 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -770,22 +770,40 @@ function Create-NugetPackages
"Microsoft.TestPlatform.AdapterUtilities.nuspec",
"Microsoft.TestPlatform.nuspec",
"Microsoft.TestPlatform.Portable.nuspec",
"TestPlatform.Build.nuspec",
"TestPlatform.CLI.nuspec",
"TestPlatform.Extensions.TrxLogger.nuspec",
"TestPlatform.ObjectModel.nuspec",
"TestPlatform.TestHost.nuspec",
"TestPlatform.TranslationLayer.nuspec"
"TestPlatform.Internal.Uwp.nuspec"
)

$targetFiles = @("Microsoft.CodeCoverage.targets")
$propFiles = @("Microsoft.NET.Test.Sdk.props", "Microsoft.CodeCoverage.props")
$contentDirs = @("netcoreapp", "netfx")
$projectFiles = @(
"Microsoft.TestPlatform.CLI.csproj",
"Microsoft.TestPlatform.Build.csproj"
)

$dependencies = @(
"TestPlatform.Build.nuspec",
"TestPlatform.CLI.nuspec",

## .target and .props Files
"Microsoft.NET.Test.Sdk.props",
"Microsoft.CodeCoverage.props",
"Microsoft.CodeCoverage.targets",

## Content Directories
"netcoreapp",
"netfx"
)

# Nuget pack analysis emits warnings if binaries are packaged as content. It is intentional for the below packages.
$skipAnalysis = @("TestPlatform.CLI.nuspec")
foreach ($item in $nuspecFiles + $targetFiles + $propFiles + $contentDirs) {
$skipAnalysis = @(
"TestPlatform.CLI.nuspec",
"Microsoft.TestPlatform.CLI.csproj"
)


foreach ($item in $nuspecFiles + $projectFiles + $dependencies) {
Copy-Item $tpNuspecDir\$item $stagingDir -Force -Recurse
}

Expand All @@ -810,6 +828,7 @@ function Create-NugetPackages

# Call nuget pack on these components.
$nugetExe = Join-Path $env:TP_PACKAGES_DIR -ChildPath "Nuget.CommandLine" | Join-Path -ChildPath $env:NUGET_EXE_Version | Join-Path -ChildPath "tools\NuGet.exe"
$dotnetExe = Get-DotNetPath

# Pass Newtonsoft.Json version to nuget pack to keep the version consistent across all nuget packages.
$JsonNetVersion = ([xml](Get-Content $env:TP_ROOT_DIR\scripts\build\TestPlatform.Dependencies.props)).Project.PropertyGroup.JsonNetVersion
Expand Down Expand Up @@ -839,6 +858,17 @@ function Create-NugetPackages
Invoke-Exe $nugetExe -Arguments "pack $stagingDir\$file -OutputDirectory $packageOutputDir -Version $TPB_Version -Properties Version=$TPB_Version;JsonNetVersion=$JsonNetVersion;Runtime=$TPB_TargetRuntime;NetCoreTargetFramework=$TPB_TargetFrameworkCore20;FakesPackageDir=$FakesPackageDir;NetStandard10Framework=$TPB_TargetFrameworkNS10;NetStandard13Framework=$TPB_TargetFrameworkNS13;NetStandard20Framework=$TPB_TargetFrameworkNS20;Uap10Framework=$uap10Nuget;BranchName=$TPB_BRANCH;CommitId=$TPB_COMMIT $additionalArgs"
}

foreach ($file in $projectFiles) {
$additionalArgs = ""
if ($skipAnalysis -contains $file) {
$additionalArgs = "-NoPackageAnalysis"
}

Write-Host "Attempting to build package from '$file'."
Invoke-Exe $dotnetExe -Arguments "restore $stagingDir\$file" -CaptureOutput | Out-Null
Invoke-Exe $dotnetExe -Arguments "pack --no-build $stagingDir\$file -o $packageOutputDir -p:Version=$TPB_Version -p:BranchName=`"$TPB_BRANCH`" -p:CommitId=`"$TPB_COMMIT`" /bl:pack_$file.binlog"
}

# Verifies that expected number of files gets shipped in nuget packages.
# Few nuspec uses wildcard characters.
Verify-Nuget-Packages $packageOutputDir $TPB_Version
Expand Down
11 changes: 7 additions & 4 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ TPB_Verbose=$VERBOSE
TPB_EXTERNALS_VERSION=$(grep TestPlatformExternalsVersion $TP_ROOT_DIR/scripts/build/TestPlatform.Dependencies.props | head -1 | cut -d'>' -f2 | cut -d'<' -f1 || echo $VERSION)
TPB_CC_EXTERNALS_VERSION=$(grep MicrosoftInternalCodeCoverageVersion $TP_ROOT_DIR/eng/Versions.props | head -1 | cut -d'>' -f2 | cut -d'<' -f1 || echo $VERSION)

TPB_BRANCH="$(git -C "." rev-parse --abbrev-ref HEAD 2>/dev/null)" || TPB_BRANCH="LOCALBRANCH" # detached HEAD
TPB_COMMIT="$(git -C "." rev-parse HEAD 2>/dev/null)" || TPB_COMMIT="LOCALBUILD" # detached HEAD

if [[ $TP_USE_REPO_API = 1 ]]; then
TPB_TargetFrameworkCore="net6.0"
fi
Expand Down Expand Up @@ -508,15 +511,15 @@ function create_package()

for i in ${projectFiles[@]}; do
if [[ $TP_USE_REPO_API = 0 ]]; then
log "$dotnet pack --no-build $stagingDir/${i} -o $packageOutputDir -p:Version=$TPB_Version"
log "$dotnet pack --no-build $stagingDir/${i} -o $packageOutputDir -p:Version=$TPB_Version -p:BranchName=$TPB_BRANCH -p:CommitId=$TPB_COMMIT"

$dotnet restore $stagingDir/${i} \
&& $dotnet pack --no-build $stagingDir/${i} -o $packageOutputDir -p:Version=$TPB_Version /bl:pack_$i.binlog
&& $dotnet pack --no-build $stagingDir/${i} -o $packageOutputDir -p:Version=$TPB_Version -p:BranchName="$TPB_BRANCH" -p:CommitId="$TPB_COMMIT" /bl:pack_$i.binlog
else
log "$dotnet pack --no-build $stagingDir/${i} -o $packageOutputDir -p:Version=$TPB_Version (Source Build)"
log "$dotnet pack --no-build $stagingDir/${i} -o $packageOutputDir -p:Version=$TPB_Version -p:BranchName=$TPB_BRANCH -p:CommitId=$TPB_COMMIT (Source Build)"

$dotnet restore $stagingDir/${i} \
&& $dotnet pack --no-build $stagingDir/${i} -o $packageOutputDir -p:Version=$TPB_Version /bl:pack_$i.binlog -p:DotNetBuildFromSource=true
&& $dotnet pack --no-build $stagingDir/${i} -o $packageOutputDir -p:Version=$TPB_Version /bl:pack_$i.binlog -p:DotNetBuildFromSource=true -p:BranchName="$TPB_BRANCH" -p:CommitId="$TPB_COMMIT"
fi
done

Expand Down
4 changes: 2 additions & 2 deletions src/package/nuspec/Microsoft.TestPlatform.Build.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework Condition=" '$(DotNetBuildFromSource)' != 'true' ">netcoreapp1.0</TargetFramework>
<TargetFramework Condition=" '$(DotNetBuildFromSource)' != 'true' ">netstandard2.0</TargetFramework>
<TargetFramework Condition=" '$(DotNetBuildFromSource)' == 'true' ">net6.0</TargetFramework>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<NuspecFile>TestPlatform.Build.nuspec</NuspecFile>
<NuspecProperties>version=$(Version)</NuspecProperties>
<NuspecProperties>BranchName=$(BranchName);CommitId=$(CommitId);Version=$(Version);TargetFramework=$(TargetFramework)</NuspecProperties>

<!-- Don't include the output.dll and output.runtimeconfig.json files in nuget package -->
<IncludeBuildOutput>false</IncludeBuildOutput>
Expand Down
6 changes: 3 additions & 3 deletions src/package/nuspec/Microsoft.TestPlatform.CLI.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework Condition=" '$(DotNetBuildFromSource)' != 'true' ">netcoreapp1.0</TargetFramework>
<TargetFramework Condition=" '$(DotNetBuildFromSource)' == 'true' ">net6.0</TargetFramework>
<TargetFramework Condition=" '$(DotNetBuildFromSource)' != 'true' ">netcoreapp2.1</TargetFramework>
<OutputType>Exe</OutputType>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<NuspecFile>TestPlatform.CLI.nuspec</NuspecFile>
<NuspecProperties>version=$(Version)</NuspecProperties>
<NuspecProperties>BranchName=$(BranchName);CommitId=$(CommitId);Version=$(Version);TargetFramework=$(TargetFramework)</NuspecProperties>

<!-- Don't include the output.dll and output.runtimeconfig.json files in nuget package -->
<IncludeBuildOutput>false</IncludeBuildOutput>
Expand Down
7 changes: 3 additions & 4 deletions src/package/nuspec/TestPlatform.Build.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
commit="$CommitId$" />

<dependencies>
<group targetFramework="netstandard2.0"></group>
<group targetFramework="net6.0"></group>
<group targetFramework="$TargetFramework$"></group>
</dependencies>
</metadata>
<files>
<file src="Icon.png" target="" />
<file src="licenses\LICENSE_NET.txt" target="" />
<file src="Microsoft.TestPlatform.Build\netstandard2.0\Microsoft.TestPlatform.targets" target="runtimes\any\native" />
<file src="Microsoft.TestPlatform.Build\$TargetFramework$\Microsoft.TestPlatform.targets" target="runtimes\any\native" />

<!-- Add localized resources -->
<file src="Microsoft.TestPlatform.Build\netstandard2.0\**\*.dll" target="lib\netstandard2.0" />
<file src="Microsoft.TestPlatform.Build\$TargetFramework$\**\*.dll" target="lib\$TargetFramework$" />

</files>
</package>
2 changes: 1 addition & 1 deletion src/package/nuspec/TestPlatform.CLI.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
<!-- Add a third party notice file -->
<file src="ThirdPartyNotices.txt" target="" />

<file src="netcoreapp2.1\**\*.*" exclude="**\*.pdb" target="contentFiles\any\netcoreapp2.1" />
<file src="$TargetFramework$\**\*.*" exclude="**\*.pdb" target="contentFiles\any\$TargetFramework$" />
</files>
</package>

0 comments on commit 9988689

Please sign in to comment.