Skip to content

Commit c46e64f

Browse files
authored
Fix roundtrip of Git engine spec query string (#338)
1 parent 0d2f73f commit c46e64f

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

UET/Redpoint.Uet.BuildPipeline/Executors/BuildEngineSpecification.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using System.Collections.Specialized;
44
using System.Diagnostics.CodeAnalysis;
5+
using System.Web;
56

67
public enum BuildEngineSpecificationEngineBuildType
78
{
@@ -146,7 +147,25 @@ public string ToReparsableString()
146147
{
147148
options.Add($",mc:{_gitSharedMacCachePath}");
148149
}
149-
return $"git:{_gitCommit}@{_gitUrl}{string.Join("", options)}";
150+
if (options.Count > 0)
151+
{
152+
if (_queryString == null)
153+
{
154+
_queryString = [];
155+
}
156+
if (_queryString["config"] == null)
157+
{
158+
// Only set 'config' if it's not already set, since the options
159+
// will have originally come from the 'config' key if it exists.
160+
_queryString["config"] = string.Join("", options).TrimStart(',');
161+
}
162+
}
163+
164+
var queryString = (_queryString == null || _queryString.Count == 0)
165+
? string.Empty
166+
: ("?" + string.Join("&",
167+
_queryString.AllKeys.Select(a => HttpUtility.UrlEncode(a) + "=" + HttpUtility.UrlEncode(_queryString[a]))));
168+
return $"git:{_gitCommit}@{_gitUrl}{queryString}";
150169
}
151170
else
152171
{

UET/Redpoint.Uet.Tests/EngineSpecTests.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public void Path()
1919
Assert.NotNull(spec);
2020
Assert.Equal(EngineSpecType.Path, spec.Type);
2121
Assert.Equal(Environment.CurrentDirectory, spec.Path);
22+
Assert.Equal(Environment.CurrentDirectory, spec.ToBuildEngineSpecification(string.Empty).ToReparsableString());
2223
}
2324

2425
[Fact]
@@ -34,6 +35,9 @@ public void Git()
3435
Assert.Equal(EngineSpecType.GitCommit, spec.Type);
3536
Assert.Equal("main", spec.GitCommit);
3637
Assert.Equal("[email protected]:group/repository.git", spec.GitUrl);
38+
Assert.Equal(
39+
"git:main@[email protected]:group/repository.git",
40+
spec.ToBuildEngineSpecification(string.Empty).ToReparsableString());
3741
}
3842

3943
[Fact]
@@ -55,6 +59,9 @@ public void GitLegacy()
5559
Assert.Equal("b", Assert.Single(spec.ZipLayers));
5660
Assert.Equal("c", spec.WindowsSharedGitCachePath);
5761
Assert.Equal("d", spec.MacSharedGitCachePath);
62+
Assert.Equal(
63+
"git:main@[email protected]:group/repository.git?config=z%3ab%2cwc%3ac%2cmc%3ad",
64+
spec.ToBuildEngineSpecification(string.Empty).ToReparsableString());
5865
}
5966

6067
[Fact]
@@ -63,7 +70,7 @@ public void GitWithOptions()
6370
var option = new Option<EngineSpec>("--engine", parseArgument: EngineSpec.ParseEngineSpecContextless());
6471
var result = option.Parse([
6572
"--engine",
66-
"git:main@[email protected]:group/repository.git?submodules=false&lfs=true&config=f:a,z:b,wc:c,mc:d"
73+
"git:main@[email protected]:group/repository.git?submodules=false&lfs=true&lfsStoragePath=C%3A%5CGitLFSCache&config=f:a,z:b,wc:c,mc:d"
6774
]);
6875
var spec = result.GetValueForOption(option);
6976
Assert.NotNull(spec);
@@ -72,13 +79,17 @@ public void GitWithOptions()
7279
Assert.Equal("[email protected]:group/repository.git", spec.GitUrl);
7380
Assert.Equal("false", spec.GitQueryString?["submodules"]);
7481
Assert.Equal("true", spec.GitQueryString?["lfs"]);
82+
Assert.Equal(@"C:\GitLFSCache", spec.GitQueryString?["lfsStoragePath"]);
7583
Assert.Equal("f:a,z:b,wc:c,mc:d", spec.GitQueryString?["config"]);
7684
Assert.NotNull(spec.FolderLayers);
7785
Assert.Equal("a", Assert.Single(spec.FolderLayers));
7886
Assert.NotNull(spec.ZipLayers);
7987
Assert.Equal("b", Assert.Single(spec.ZipLayers));
8088
Assert.Equal("c", spec.WindowsSharedGitCachePath);
8189
Assert.Equal("d", spec.MacSharedGitCachePath);
90+
Assert.Equal(
91+
"git:main@[email protected]:group/repository.git?submodules=false&lfs=true&lfsStoragePath=C%3a%5cGitLFSCache&config=f%3aa%2cz%3ab%2cwc%3ac%2cmc%3ad",
92+
spec.ToBuildEngineSpecification(string.Empty).ToReparsableString());
8293
}
8394

8495
[Fact]
@@ -93,6 +104,9 @@ public void Uefs()
93104
Assert.NotNull(spec);
94105
Assert.Equal(EngineSpecType.UEFSPackageTag, spec.Type);
95106
Assert.Equal("example.com/path:tag", spec.UEFSPackageTag);
107+
Assert.Equal(
108+
"uefs:example.com/path:tag",
109+
spec.ToBuildEngineSpecification(string.Empty).ToReparsableString());
96110
}
97111
}
98112
}

UET/uet/Commands/ParameterSpec/EngineSpec.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,10 @@ public BuildEngineSpecification ToBuildEngineSpecification(
609609
GitCommit!,
610610
ZipLayers,
611611
isEngineBuild: false,
612+
windowsSharedGitCachePath:
613+
windowsSharedGitCachePath ?? WindowsSharedGitCachePath,
614+
macSharedGitCachePath:
615+
macSharedGitCachePath ?? MacSharedGitCachePath,
612616
queryString: GitQueryString);
613617
case EngineSpecType.SelfEngineByBuildConfig:
614618
if (distributionSpec != null)

0 commit comments

Comments
 (0)