Skip to content

Commit bb554e0

Browse files
committed
Misc fixes.
1 parent 864aa2d commit bb554e0

File tree

4 files changed

+64
-24
lines changed

4 files changed

+64
-24
lines changed

src/PostSharp.Engineering.BuildTools/BaseCommand.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,30 +105,31 @@ public sealed override int Execute( CommandContext context, T settings )
105105
{
106106
var globalJsonPath = Path.Combine( buildContext.RepoDirectory, "global.json" );
107107

108-
if ( !File.Exists( globalJsonPath ) )
108+
if ( File.Exists( globalJsonPath ) )
109109
{
110-
buildContext.Console.WriteWarning( "global.json does not exist." );
111-
buildContext.Console.WriteLine();
112-
}
110+
var globalJson = JsonDocument.Parse( File.ReadAllText( globalJsonPath ) );
113111

114-
var globalJson = JsonDocument.Parse( File.ReadAllText( globalJsonPath ) );
112+
if ( !globalJson.RootElement.TryGetProperty( "msbuild-sdks", out var sdks ) ||
113+
!sdks.TryGetProperty( "PostSharp.Engineering.Sdk", out var sdk ) ||
114+
sdk.GetString() == null )
115+
{
116+
buildContext.Console.WriteWarning( "global.json does not import the PostSharp.Engineering.Sdk." );
117+
buildContext.Console.WriteLine();
118+
}
119+
else
120+
{
121+
if ( sdk.GetString() != myVersion )
122+
{
123+
buildContext.Console.WriteWarning(
124+
$"global.json imports PostSharp.Engineering.Sdk version {sdk.GetString()}, but the BuildTools version is {myVersion}." );
115125

116-
if ( !globalJson.RootElement.TryGetProperty( "msbuild-sdks", out var sdks ) ||
117-
!sdks.TryGetProperty( "PostSharp.Engineering.Sdk", out var sdk ) ||
118-
sdk.GetString() == null )
119-
{
120-
buildContext.Console.WriteWarning( "global.json does not import the PostSharp.Engineering.Sdk." );
121-
buildContext.Console.WriteLine();
126+
buildContext.Console.WriteLine();
127+
}
128+
}
122129
}
123130
else
124131
{
125-
if ( sdk.GetString() != myVersion )
126-
{
127-
buildContext.Console.WriteWarning(
128-
$"global.json imports PostSharp.Engineering.Sdk version {sdk.GetString()}, but the BuildTools version is {myVersion}." );
129-
130-
buildContext.Console.WriteLine();
131-
}
132+
// global.json might be generated by PostSharp.Engineering.
132133
}
133134
}
134135

src/PostSharp.Engineering.BuildTools/Build/Files/NuGetConfigFile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ internal static bool TryWrite( BuildContext context, DependenciesConfigurationFi
9090
if ( dependencySource.Value.SourceKind == DependencySourceKind.Feed )
9191
{
9292
// Skip any feed dependency, so it will be fall back to the default package source.
93+
packageSourcesElement.Add( new XComment( $" {dependencySource.Key} maps to the default nuget.org. " ) );
94+
9395
continue;
9496
}
9597
else if ( dependencySource.Value.VersionFile == null )

src/PostSharp.Engineering.BuildTools/Build/Helpers/SourceDependenciesHelper.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ internal static class SourceDependenciesHelper
1010
internal static bool RestoreSourceDependencies( BuildContext context )
1111
{
1212
var product = context.Product;
13+
var console = context.Console;
1314

1415
if ( product.SourceDependencies.Length == 0 )
1516
{
@@ -25,7 +26,7 @@ internal static bool RestoreSourceDependencies( BuildContext context )
2526

2627
foreach ( var dependency in product.SourceDependencies )
2728
{
28-
context.Console.WriteMessage( $"Restoring '{dependency.Name}' source dependency." );
29+
console.WriteMessage( $"Restoring '{dependency.Name}' source dependency." );
2930

3031
var localDirectory = Path.Combine( context.RepoDirectory, "..", dependency.Name );
3132

@@ -35,28 +36,43 @@ internal static bool RestoreSourceDependencies( BuildContext context )
3536
{
3637
if ( !Directory.Exists( targetDirectory ) )
3738
{
38-
context.Console.WriteMessage( $"Creating symbolic link to '{localDirectory}' in '{targetDirectory}'." );
39+
if ( context.IsContinuousIntegrationBuild )
40+
{
41+
console.WriteError( "Cannot restore source dependencies in a Docker container. Prepare the build in the host first." );
42+
43+
return false;
44+
}
45+
46+
console.WriteMessage( $"Creating symbolic link to '{localDirectory}' in '{targetDirectory}'." );
3947
Directory.CreateSymbolicLink( targetDirectory, localDirectory );
4048

4149
if ( !Directory.Exists( targetDirectory ) )
4250
{
43-
context.Console.WriteError( $"Symbolic link was not created for '{targetDirectory}'." );
51+
console.WriteError( $"Symbolic link was not created for '{targetDirectory}'." );
4452

4553
return false;
4654
}
4755
}
4856
else
4957
{
50-
context.Console.WriteMessage( $"Directory '{targetDirectory}' already exists." );
58+
console.WriteMessage( $"Directory '{targetDirectory}' already exists." );
5159
}
5260
}
5361
else
5462
{
5563
if ( !Directory.Exists( targetDirectory ) )
5664
{
65+
if ( context.IsContinuousIntegrationBuild )
66+
{
67+
// Avoid creating a mess in the host.
68+
console.WriteError( "Cannot restore source dependencies in a Docker container. Prepare the build in the host first." );
69+
70+
return false;
71+
}
72+
5773
// If the target directory doesn't exist, we clone it to the source-dependencies directory with depth of 1 to mitigate the impact of cloning the whole history.
5874
if ( !ToolInvocationHelper.InvokeTool(
59-
context.Console,
75+
console,
6076
"git",
6177
$"clone {dependency.VcsRepository.DeveloperMachineRemoteUrl} --branch {dependency.Branch} --depth 1",
6278
sourceDependenciesDirectory ) )
@@ -66,7 +82,7 @@ internal static bool RestoreSourceDependencies( BuildContext context )
6682
}
6783
else
6884
{
69-
context.Console.WriteMessage( $"Directory '{targetDirectory}' already exists." );
85+
console.WriteMessage( $"Directory '{targetDirectory}' already exists." );
7086
}
7187
}
7288
}

src/PostSharp.Engineering.BuildTools/Resources/DockerBuild.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,27 @@ if (-not $NoNuGetCache)
160160
# We must add a MountPoint anyway so the directory is created in the container.
161161
$MountPoints += "c:\packages"
162162

163+
# Discover symbolic links in source-dependencies and add their targets to mount points
164+
$sourceDependenciesDir = Join-Path $SourceDirName "source-dependencies"
165+
if (Test-Path $sourceDependenciesDir)
166+
{
167+
$symbolicLinks = Get-ChildItem -Path $sourceDependenciesDir -Force | Where-Object { $_.LinkType -eq 'SymbolicLink' }
168+
169+
foreach ($link in $symbolicLinks)
170+
{
171+
$targetPath = $link.Target
172+
if (-not [string]::IsNullOrEmpty($targetPath) -and (Test-Path $targetPath))
173+
{
174+
Write-Host "Found symbolic link '$($link.Name)' -> '$targetPath'" -ForegroundColor Cyan
175+
$volumeMappings += @("-v", "${targetPath}:${targetPath}")
176+
$MountPoints += $targetPath
177+
}
178+
else
179+
{
180+
Write-Host "Warning: Symbolic link '$($link.Name)' target '$targetPath' does not exist or is invalid" -ForegroundColor Yellow
181+
}
182+
}
183+
}
163184

164185
# Execute auto-generated DockerMounts.g.ps1 script to add more directory mounts.
165186
$dockerMountsScript = Join-Path $EngPath 'DockerMounts.g.ps1'

0 commit comments

Comments
 (0)