Skip to content

Commit 58b2d16

Browse files
committed
Added --path option to dependencies set local command.
1 parent 7555ab3 commit 58b2d16

6 files changed

Lines changed: 52 additions & 31 deletions

File tree

src/PostSharp.Engineering.BuildTools/Dependencies/DependenciesHelper.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,12 @@ bool TryGetBuildId( [NotNullWhen( true )] out CiBuildId? ciBuildId )
208208
break;
209209

210210
case DependencySourceKind.Local:
211-
dependencySource = DependencySource.CreateLocalRepo( DependencyConfigurationOrigin.Transitive );
211+
{
212+
var localPath = transitiveDependency.GetMetadata( "Path" )?.EvaluatedValue;
213+
dependencySource = DependencySource.CreateLocalDependency( DependencyConfigurationOrigin.Transitive, localPath );
212214

213-
break;
215+
break;
216+
}
214217

215218
case DependencySourceKind.RestoredDependency:
216219
{
@@ -442,12 +445,10 @@ private static bool ResolveLocalDependencies( BuildContext context, ImmutableDic
442445
{
443446
if ( dependency.Source.VersionFile == null )
444447
{
445-
dependency.Source.VersionFile = Path.GetFullPath(
448+
dependency.Source.VersionFile =
446449
Path.Combine(
447-
context.RepoDirectory,
448-
"..",
449-
dependency.Dependency.Name,
450-
dependency.Dependency.Name + ".Import.props" ) );
450+
dependency.Source.GetResolvedLocalPath( context, dependency.Dependency.Name ),
451+
dependency.Dependency.Name + ".Import.props" );
451452
}
452453

453454
if ( !File.Exists( dependency.Source.VersionFile ) )

src/PostSharp.Engineering.BuildTools/Dependencies/Model/DependenciesConfigurationFile.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,12 @@ bool TryGetBuildId( out string? versionFile1, out ICiBuildSpec? ciBuildSpec )
197197

198198
case DependencySourceKind.Local:
199199
{
200-
var dependencySource = DependencySource.CreateLocalRepo( origin );
200+
var localPath = item.Element( "Path" )?.Value;
201+
var dependencySource = DependencySource.CreateLocalDependency( origin, localPath );
201202

202-
dependencySource.VersionFile = Path.GetFullPath(
203-
Path.Combine(
204-
context.RepoDirectory,
205-
"..",
206-
name,
207-
name + ".Import.props" ) );
203+
dependencySource.VersionFile = Path.Combine(
204+
dependencySource.GetResolvedLocalPath( context, name ),
205+
name + ".Import.props" );
208206

209207
file.Dependencies[name] = dependencySource;
210208

@@ -435,12 +433,10 @@ void WriteBuildServerSource()
435433

436434
case DependencySourceKind.Local:
437435
{
436+
AddIfNotNull( "Path", dependencySource.LocalPath );
437+
438438
var importProjectFile = Path.GetFullPath(
439-
Path.Combine(
440-
context.RepoDirectory,
441-
"..",
442-
dependency.Key,
443-
dependency.Key + ".Import.props" ) );
439+
Path.Combine( dependencySource.GetResolvedLocalPath( context, dependency.Key ), dependency.Key + ".Import.props" ) );
444440

445441
AddImport( importProjectFile );
446442
}

src/PostSharp.Engineering.BuildTools/Dependencies/Model/DependencySource.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
22

33
using PostSharp.Engineering.BuildTools.Build;
4+
using System;
45
using System.Globalization;
56
using System.IO;
67
using System.Xml.Linq;
@@ -19,12 +20,31 @@ public sealed class DependencySource
1920

2021
internal string? VersionFile { get; set; }
2122

22-
public DependencySourceKind SourceKind { get; internal set; }
23+
public DependencySourceKind SourceKind { get; private init; }
2324

24-
public DependencyConfigurationOrigin Origin { get; internal init; }
25+
public DependencyConfigurationOrigin Origin { get; private init; }
2526

26-
public static DependencySource CreateLocalRepo( DependencyConfigurationOrigin origin )
27-
=> new() { Origin = origin, SourceKind = DependencySourceKind.Local };
27+
public string? LocalPath { get; private init; }
28+
29+
public string GetResolvedLocalPath( BuildContext context, string dependencyKey )
30+
{
31+
if ( this.SourceKind != DependencySourceKind.Local )
32+
{
33+
throw new InvalidOperationException( "The dependency source must be local." );
34+
}
35+
36+
var localPath = this.LocalPath == null
37+
? Path.Combine(
38+
context.RepoDirectory,
39+
"..",
40+
dependencyKey )
41+
: Path.Combine( context.RepoDirectory, this.LocalPath );
42+
43+
return Path.GetFullPath( localPath );
44+
}
45+
46+
public static DependencySource CreateLocalDependency( DependencyConfigurationOrigin origin, string? path )
47+
=> new() { Origin = origin, SourceKind = DependencySourceKind.Local, LocalPath = path };
2848

2949
/// <summary>
3050
/// Creates a <see cref="DependencySource"/> that represents a build server artifact dependency that has been restored,

src/PostSharp.Engineering.BuildTools/Dependencies/Model/VersionFile.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static bool TryRead(
3636
versionFile = null;
3737
var dependenciesBuilder = ImmutableDictionary.CreateBuilder<string, DependencySource>();
3838
var versionsPath = Path.Combine( context.RepoDirectory, context.Product.VersionsFilePath );
39-
var centralPackageManangementVersionsPath = Path.Combine( context.RepoDirectory, "Directory.Packages.props" );
39+
var centralPackageManagementVersionsPath = Path.Combine( context.RepoDirectory, "Directory.Packages.props" );
4040

4141
if ( !File.Exists( versionsPath ) )
4242
{
@@ -48,18 +48,18 @@ public static bool TryRead(
4848
var projectOptions = new ProjectOptions { GlobalProperties = new Dictionary<string, string>() { ["DoNotLoadGeneratedVersionFiles"] = "True" } };
4949

5050
var versionsProject = Project.FromFile( versionsPath, projectOptions );
51-
Project? centralPackageManangementVersionsProject = null;
51+
Project? centralPackageManagementVersionsProject = null;
5252

53-
if ( File.Exists( centralPackageManangementVersionsPath ) )
53+
if ( File.Exists( centralPackageManagementVersionsPath ) )
5454
{
55-
centralPackageManangementVersionsProject = Project.FromFile( centralPackageManangementVersionsPath, projectOptions );
55+
centralPackageManagementVersionsProject = Project.FromFile( centralPackageManagementVersionsPath, projectOptions );
5656
}
5757

5858
var defaultDependencyProperties = context.Product.ParametrizedDependencies
5959
.ToDictionary(
6060
d => d.Name,
6161
d => versionsProject.Properties.SingleOrDefault( p => p.Name == d.NameWithoutDot + "Version" )?.EvaluatedValue
62-
?? centralPackageManangementVersionsProject?.Properties.SingleOrDefault( p => p.Name == d.NameWithoutDot + "Version" )?.EvaluatedValue );
62+
?? centralPackageManagementVersionsProject?.Properties.SingleOrDefault( p => p.Name == d.NameWithoutDot + "Version" )?.EvaluatedValue );
6363

6464
ProjectCollection.GlobalProjectCollection.UnloadAllProjects();
6565

@@ -80,7 +80,7 @@ public static bool TryRead(
8080
dependencyVersion = dependencyVersion.Trim();
8181

8282
// The property value can be either empty or a semantic version, but empty values are not allowed on guest devices,
83-
// i.e. for build outside of our VPN.
83+
// i.e. for build outside our VPN.
8484

8585
if ( dependencyVersion != "" && !Regex.IsMatch( dependencyVersion, @"^\d+.*$" ) )
8686
{
@@ -110,7 +110,7 @@ public static bool TryRead(
110110
}
111111
else if ( settings.UseLocalDependencies && dependencyDefinition.Definition.ProductFamily == context.Product.ProductFamily )
112112
{
113-
dependencySource = DependencySource.CreateLocalRepo( DependencyConfigurationOrigin.Default );
113+
dependencySource = DependencySource.CreateLocalDependency( DependencyConfigurationOrigin.Default, null );
114114
}
115115
else if ( context.IsContinuousIntegrationBuild )
116116
{

src/PostSharp.Engineering.BuildTools/Dependencies/SetDependenciesCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected override bool ConfigureDependency(
2626
switch ( settings.Source )
2727
{
2828
case DependencySourceKind.Local:
29-
dependencySource = DependencySource.CreateLocalRepo( DependencyConfigurationOrigin.Override );
29+
dependencySource = DependencySource.CreateLocalDependency( DependencyConfigurationOrigin.Override, settings.LocalPath );
3030

3131
break;
3232

src/PostSharp.Engineering.BuildTools/Dependencies/SetDependenciesCommandSettings.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public class SetDependenciesCommandSettings : ConfigureDependenciesCommandSettin
3939
[CommandOption( "--buildTypeId" )]
4040
public string? CiBuildTypeId { get; protected set; }
4141

42+
[Description( "Specifies the path of the local dependency. By default, the dependency is assumed to be in the parent directory of the current repo." )]
43+
[CommandOption( "--path" )]
44+
public string? LocalPath { get; protected set; }
45+
4246
public override string[] GetDependencies() => this.Dependencies;
4347

4448
public override bool GetAllFlag() => this.All;

0 commit comments

Comments
 (0)