Skip to content

Commit

Permalink
Allow building with desktop msbuild only
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorHofer committed Nov 21, 2024
1 parent 31975d7 commit ec997da
Showing 1 changed file with 39 additions and 22 deletions.
61 changes: 39 additions & 22 deletions eng/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ param(
[Alias('v')]
[string]$Verbosity = 'minimal',
[switch]$DumpProcesses, # Capture all running processes and dump them to a file.
[string]$msbuildEngine = 'dotnet',

# Other lifecycle targets
[switch]$Help, # Show help
Expand Down Expand Up @@ -286,24 +287,20 @@ if ($RuntimeSourceFeed -or $RuntimeSourceFeedKey) {
}

# Split build categories between dotnet msbuild and desktop msbuild. Use desktop msbuild as little as possible.
[string[]]$dotnetBuildArguments = ''
[string[]]$MSBuildOnlyArguments = ''

# Don't pass Sign and Publish to desktop msbuild as that would result in double signing and publishing
$MSBuildArguments += "/p:Sign=$Sign"
$MSBuildArguments += "/p:Publish=$Publish"
if ($All) { $dotnetBuildArguments += '/p:BuildAllProjects=true' }
if ($Projects) { $MSBuildArguments += "/p:ProjectToBuild=$Projects" }

if ($All) { $MSBuildArguments += '/p:BuildAllProjects=true' }
if ($Projects) {
$MSBuildArguments += "/p:ProjectToBuild=$Projects"
}

if ($NoBuildInstallers) { $MSBuildArguments += "/p:BuildInstallers=false"; $BuildInstallers = $false }
if ($BuildInstallers) { $MSBuildArguments += "/p:BuildInstallers=true" }
if ($NoBuildInstallers) { $MSBuildOnlyArguments += "/p:BuildInstallers=false"; $BuildInstallers = $false }
if ($BuildInstallers) { $MSBuildOnlyArguments += "/p:BuildInstallers=true" }

# Build native projects by default unless -NoBuildNative was specified.
$specifiedBuildNative = $BuildNative
$BuildNative = $true
if ($NoBuildNative) { $MSBuildArguments += "/p:BuildNative=false"; $BuildNative = $false }
if ($BuildNative) { $MSBuildArguments += "/p:BuildNative=true"}
if ($NoBuildNative) { $MSBuildOnlyArguments += "/p:BuildNative=false"; $BuildNative = $false }
if ($BuildNative) { $MSBuildOnlyArguments += "/p:BuildNative=true"}

if ($NoBuildJava) { $MSBuildArguments += "/p:BuildJava=false"; $BuildJava = $false }
if ($BuildJava) { $MSBuildArguments += "/p:BuildJava=true" }
Expand All @@ -315,23 +312,24 @@ if ($BuildNodeJS) { $MSBuildArguments += "/p:BuildNodeJSUnlessSourcebuild=true"
# Don't bother with two builds if just one will build everything. Ignore super-weird cases like
# "-Projects ... -NoBuildJava -NoBuildManaged -NoBuildNodeJS". An empty `./build.ps1` command will build both
# managed and native projects.
$performDesktopBuild = $BuildInstallers -or $BuildNative
$performDotnetBuild = $BuildJava -or $BuildManaged -or $BuildNodeJS -or `

# If -msbuildEngine vs is explicitly passed in, use desktop msbuild only.
# This is necessary for one-shot builds like within the VMR.

$performDesktopBuild = $BuildInstallers -or $BuildNative -or $msbuildEngine -eq 'vs'
$performDotnetBuild = $msBuildEngine -ne 'vs' -and ($BuildJava -or $BuildManaged -or $BuildNodeJS -or `
($All -and -not ($NoBuildJava -and $NoBuildManaged -and $NoBuildNodeJS)) -or `
($Projects -and -not ($BuildInstallers -or $specifiedBuildNative))
($Projects -and -not ($BuildInstallers -or $specifiedBuildNative)))

# Initialize global variables need to be set before the import of Arcade is imported
$restore = $RunRestore

# Though VS Code may indicate $nodeReuse and $msbuildEngine are unused, tools.ps1 uses them.
# Though VS Code may indicate $nodeReuse is unused, tools.ps1 uses them.

# Disable node reuse - Workaround perpetual issues in node reuse and custom task assemblies
$nodeReuse = $false
$env:MSBUILDDISABLENODEREUSE=1

# Use `dotnet msbuild` by default
$msbuildEngine = 'dotnet'

# Ensure passing neither -bl nor -nobl on CI avoids errors in tools.ps1. This is needed because both parameters are
# $false by default i.e. they always exist. (We currently avoid binary logs but that is made visible in the YAML.)
if ($CI -and -not $excludeCIBinarylog) {
Expand Down Expand Up @@ -411,12 +409,18 @@ function LocateJava {
if ($BinaryLog) {
$bl = GetMSBuildBinaryLogCommandLineArgument($MSBuildArguments)
if (-not $bl) {
$MSBuildArguments += "/bl:" + (Join-Path $LogDir "Build.binlog")
$dotnetBuildArguments += "/bl:" + (Join-Path $LogDir "Build.binlog")

# When running both builds, use a different binary log path for the desktop msbuild.
if ($performDesktopBuild -and $performDotnetBuild) {
$MSBuildOnlyArguments += "/bl:" + (Join-Path $LogDir "Build.native.binlog")
}

$ToolsetBuildArguments += "/bl:" + (Join-Path $LogDir "Build.repotasks.binlog")
} else {
# Use a different binary log path when running desktop msbuild if doing both builds.
if ($performDesktopBuild -and $performDotnetBuild) {
$MSBuildArguments += "/bl:" + [System.IO.Path]::ChangeExtension($bl, "native.binlog")
$MSBuildOnlyArguments += "/bl:" + [System.IO.Path]::ChangeExtension($bl, "native.binlog")
}

$ToolsetBuildArguments += "/bl:" + [System.IO.Path]::ChangeExtension($bl, "repotasks.binlog")
Expand Down Expand Up @@ -474,7 +478,20 @@ try {
Remove-Item variable:global:_BuildTool -ErrorAction Ignore
$msbuildEngine = 'vs'

MSBuild $toolsetBuildProj /p:RepoRoot=$RepoRoot @MSBuildArguments
# When running with desktop msbuild only, append the dotnet build specific arguments.
if (-not $performDotnetBuild) {
$MSBuildOnlyArguments += $dotnetBuildArguments
}

MSBuild $toolsetBuildProj /p:RepoRoot=$RepoRoot @MSBuildArguments @MSBuildOnlyArguments
}

if ($performDotnetBuild) {
Write-Host
Remove-Item variable:global:_BuildTool -ErrorAction Ignore
$msbuildEngine = 'dotnet'

MSBuild $toolsetBuildProj /p:RepoRoot=$RepoRoot @MSBuildArguments @dotnetBuildArguments
}
}
catch {
Expand Down

0 comments on commit ec997da

Please sign in to comment.