Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet tool run and install roll-forward option #37231

Merged
merged 52 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
8fcf234
--roll-forward for dotnet tool run for local tools
JL03-Yue Nov 17, 2023
0b15684
add roll forward cli option to tool run
JL03-Yue Nov 29, 2023
4bcbd46
fix nonnullable source commandArguments in muxer
JL03-Yue Nov 29, 2023
da7206b
add tool run roll forward test
JL03-Yue Nov 30, 2023
9a04a62
add roll-forward options for install command
JL03-Yue Nov 30, 2023
171306b
parse roll forward for global tools
JL03-Yue Nov 30, 2023
458b7d2
pass in the parse result
JL03-Yue Nov 30, 2023
3790495
skeleton for update runtime config for global tool
JL03-Yue Nov 30, 2023
6bcf9fd
add CliOption
JL03-Yue Nov 30, 2023
4cb5503
draft for global tool roll forward
JL03-Yue Nov 30, 2023
ef927ac
fix path errors in global tool roll forward
JL03-Yue Nov 30, 2023
80d4d00
add exception for setting files not found
JL03-Yue Nov 30, 2023
2313cf0
write rollforward in manifest file
JL03-Yue Dec 4, 2023
da7e49d
read from manifest file
JL03-Yue Dec 4, 2023
e4b098e
Remove the tool manifest editor edit option
JL03-Yue Dec 4, 2023
0261149
Update the tool manifest if --roll-forward changes
JL03-Yue Dec 4, 2023
c0b0f81
fix tests
JL03-Yue Dec 4, 2023
7d2b7e2
fix test
JL03-Yue Dec 4, 2023
386ff2e
change default to major
JL03-Yue Dec 4, 2023
0d1ce8b
change global default to major
JL03-Yue Dec 6, 2023
02c6fc7
add test to local tool roll forward to manifest
JL03-Yue Dec 6, 2023
d94b809
change description
JL03-Yue Dec 7, 2023
28be00f
remove extra using
JL03-Yue Dec 19, 2023
6ff1d8d
update rollforward to write bool in manifest file
JL03-Yue Dec 19, 2023
7d04503
update format
JL03-Yue Dec 19, 2023
ae81457
change run and install option to allow roll forward and update tests
JL03-Yue Jan 8, 2024
b8b620e
change names
JL03-Yue Jan 8, 2024
f5f9b88
Merge branch 'release/8.0.2xx' into local-tool-rollforward
JL03-Yue Jan 9, 2024
c141353
fix read bool error
JL03-Yue Jan 10, 2024
421714e
fix tests and add roll forward option
JL03-Yue Jan 11, 2024
0b261a7
use sdk test
JL03-Yue Jan 11, 2024
cd88305
fix test use _testAssetsManager.CreateTestDirectory
JL03-Yue Jan 11, 2024
16d98c6
moving check roll forward logic to GetPackageCommandSpecUsingMuxer
JL03-Yue Jan 12, 2024
26af58b
fix tests
JL03-Yue Jan 16, 2024
129b393
update the muxer method
JL03-Yue Jan 16, 2024
7a562eb
fix tests
JL03-Yue Jan 16, 2024
6f7ecda
fix tests
JL03-Yue Jan 16, 2024
8c8f6cd
improve the way to UpdateRuntimeConfig
JL03-Yue Jan 16, 2024
9186c42
update roll forward description
JL03-Yue Jan 18, 2024
f7e4732
skip updating runtime config if does not exist
JL03-Yue Jan 18, 2024
1f08c96
take roll forward into consideration in ToolManifestPackage
JL03-Yue Jan 18, 2024
5718c7e
change from --roll-forward to --allow-roll-forward
JL03-Yue Jan 18, 2024
6459f96
simplify logic
JL03-Yue Jan 18, 2024
85a6344
remove RollForwardOption in ToolRunCommand and reuse the one in install
JL03-Yue Jan 18, 2024
565cb9a
update runtimeconfig for all commands
JL03-Yue Jan 23, 2024
d40d4d2
add test for not include roll-forward
JL03-Yue Jan 23, 2024
451a849
change local tool roll forward installation
JL03-Yue Jan 23, 2024
146aa83
read rollforwad from run command and add tool manifest together
JL03-Yue Jan 23, 2024
6167e9a
update the logic detection fo --allow-roll-forward and improve coding…
JL03-Yue Jan 25, 2024
b784fed
fixed tests
JL03-Yue Jan 25, 2024
2ba007b
fix tests
JL03-Yue Jan 25, 2024
892811c
fix tests
JL03-Yue Jan 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Linq;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ToolManifest;
Expand All @@ -27,7 +28,7 @@ public LocalToolsCommandResolver(
_fileSystem = fileSystem ?? new FileSystemWrapper();
}

public CommandSpec ResolveStrict(CommandResolverArguments arguments)
public CommandSpec ResolveStrict(CommandResolverArguments arguments, bool allowRollForward = false)
{
if (arguments == null || string.IsNullOrWhiteSpace(arguments.CommandName))
{
Expand All @@ -40,7 +41,7 @@ public CommandSpec ResolveStrict(CommandResolverArguments arguments)
}

var resolveResult = GetPackageCommandSpecUsingMuxer(arguments,
new ToolCommandName(arguments.CommandName.Substring(LeadingDotnetPrefix.Length)));
new ToolCommandName(arguments.CommandName.Substring(LeadingDotnetPrefix.Length)), allowRollForward);

return resolveResult;
}
Expand Down Expand Up @@ -73,7 +74,7 @@ public CommandSpec Resolve(CommandResolverArguments arguments)
}

private CommandSpec GetPackageCommandSpecUsingMuxer(CommandResolverArguments arguments,
ToolCommandName toolCommandName)
ToolCommandName toolCommandName, bool allowRollForward = false)
{
if (!_toolManifest.TryFind(toolCommandName, out var toolManifestPackage))
JL03-Yue marked this conversation as resolved.
Show resolved Hide resolved
{
Expand All @@ -95,6 +96,11 @@ private CommandSpec GetPackageCommandSpecUsingMuxer(CommandResolverArguments arg
toolCommandName.ToString()));
}

if (toolManifestPackage.RollForward || allowRollForward)
{
arguments.CommandArguments = ["--roll-forward", "Major", .. arguments.CommandArguments];
}

return MuxerCommandSpecMaker.CreatePackageCommandSpecUsingMuxer(
restoredCommand.Executable.Value,
arguments.CommandArguments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ internal static CommandSpec CreatePackageCommandSpecUsingMuxer(
string commandPath,
IEnumerable<string> commandArguments)
{
var arguments = new List<string>();

var muxer = new Muxer();

var host = muxer.MuxerPath;

if (host == null)
{
throw new Exception(LocalizableStrings.UnableToLocateDotnetMultiplexer);
}

arguments.Add(commandPath);
var previousArg = string.Empty;

if (commandArguments != null)
{
arguments.AddRange(commandArguments);
}
// Group the arguments by if the previous argument or the current argument is --roll-forward.
var argGroups = (commandArguments ?? [])
.GroupBy(a => previousArg.Equals("--roll-forward", StringComparison.OrdinalIgnoreCase)
| (previousArg = a).Equals("--roll-forward", StringComparison.OrdinalIgnoreCase))
.ToArray();

string[] arguments = [..argGroups.Where(g => g.Key).SelectMany(g => g), commandPath, .. argGroups.Where(g => !g.Key).SelectMany(g => g)];
JL03-Yue marked this conversation as resolved.
Show resolved Hide resolved
JL03-Yue marked this conversation as resolved.
Show resolved Hide resolved
return CreateCommandSpec(host, arguments);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Cli/dotnet/CommonLocalizableStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -733,4 +733,7 @@ The default is 'false.' However, when targeting .NET 7 or lower, the default is
<data name="ArtifactsPathArgumentName" xml:space="preserve">
<value>ARTIFACTS_DIR</value>
</data>
<data name="ToolSettingsNotFound" xml:space="preserve">
<value>Tool settings file does not exist for the tool {0}.</value>
</data>
</root>
2 changes: 1 addition & 1 deletion src/Cli/dotnet/ToolManifest/IToolManifestEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.DotNet.ToolManifest
{
internal interface IToolManifestEditor
{
void Add(FilePath manifest, PackageId packageId, NuGetVersion nuGetVersion, ToolCommandName[] toolCommandNames);
void Add(FilePath manifest, PackageId packageId, NuGetVersion nuGetVersion, ToolCommandName[] toolCommandNames, bool RollForward = false);
void Remove(FilePath manifest, PackageId packageId);
void Edit(FilePath manifest, PackageId packageId, NuGetVersion newNuGetVersion, ToolCommandName[] newToolCommandNames);
}
Expand Down
3 changes: 3 additions & 0 deletions src/Cli/dotnet/ToolManifest/LocalizableStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,7 @@ For a list of locations searched, specify the "-d" option before the tool name.<
<data name="MultipleSamePackageId" xml:space="preserve">
<value>More than one entry exists for package(s): {0}.</value>
</data>
<data name="ToolMissingRollForward" xml:space="preserve">
<value>Missing 'rollForward' entry.</value>
</data>
</root>
24 changes: 20 additions & 4 deletions src/Cli/dotnet/ToolManifest/ToolManifestEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal class ToolManifestEditor : IToolManifestEditor
private const string JsonPropertyIsRoot = "isRoot";
private const string JsonPropertyCommands = "commands";
private const string JsonPropertyTools = "tools";
private const string JsonPropertyRollForward = "rollForward";

public ToolManifestEditor(IFileSystem fileSystem = null, IDangerousFileDetector dangerousFileDetector = null)
{
Expand All @@ -32,7 +33,8 @@ public void Add(
FilePath manifest,
PackageId packageId,
NuGetVersion nuGetVersion,
ToolCommandName[] toolCommandNames)
ToolCommandName[] toolCommandNames,
bool rollForward = false)
{
SerializableLocalToolsManifest deserializedManifest =
DeserializeLocalToolsManifest(manifest);
Expand All @@ -45,10 +47,14 @@ public void Add(
{
var existingPackage = existing.Single();

// Update the tool manifest if --roll-forward changes
if (existingPackage.PackageId.Equals(packageId)
&& existingPackage.Version == nuGetVersion
&& CommandNamesEqual(existingPackage.CommandNames, toolCommandNames))
{
var toEdit = deserializedManifest.Tools.Single(t => new PackageId(t.PackageId).Equals(packageId));
toEdit.RollForward = rollForward;
_fileSystem.File.WriteAllText(manifest.Value, deserializedManifest.ToJson());
return;
}

Expand All @@ -70,7 +76,8 @@ public void Add(
{
PackageId = packageId.ToString(),
Version = nuGetVersion.ToNormalizedString(),
Commands = toolCommandNames.Select(c => c.Value).ToArray()
Commands = toolCommandNames.Select(c => c.Value).ToArray(),
RollForward = rollForward,
});

_fileSystem.File.WriteAllText(manifest.Value, deserializedManifest.ToJson());
Expand Down Expand Up @@ -199,6 +206,11 @@ private SerializableLocalToolsManifest DeserializeLocalToolsManifest(FilePath po
serializableLocalToolSinglePackage.Commands = commands.ToArray();
}

if (toolJson.Value.TryGetBooleanValue(JsonPropertyRollForward, out var rollForwardJson))
{
serializableLocalToolSinglePackage.RollForward = rollForwardJson;
}

serializableLocalToolsManifest.Tools.Add(serializableLocalToolSinglePackage);
}
}
Expand Down Expand Up @@ -269,6 +281,8 @@ private List<ToolManifestPackage> GetToolManifestPackageFromOneManifestFile(
packageLevelErrors.Add(LocalizableStrings.FieldCommandsIsMissing);
}

bool rollForward = tools.RollForward;

if (packageLevelErrors.Any())
{
var joinedWithIndentation = string.Join(Environment.NewLine,
Expand All @@ -282,7 +296,8 @@ private List<ToolManifestPackage> GetToolManifestPackageFromOneManifestFile(
packageId,
version,
ToolCommandName.Convert(tools.Commands),
correspondingDirectory));
correspondingDirectory,
rollForward));
}
}

Expand Down Expand Up @@ -325,6 +340,7 @@ private class SerializableLocalToolSinglePackage
public string PackageId { get; set; }
public string Version { get; set; }
public string[] Commands { get; set; }
public bool RollForward { get; set; }
}

private static bool CommandNamesEqual(ToolCommandName[] left, ToolCommandName[] right)
Expand Down Expand Up @@ -379,8 +395,8 @@ public string ToJson()
{
writer.WriteStringValue(toolCommandName);
}

writer.WriteEndArray();
writer.WriteBoolean(JsonPropertyRollForward, tool.RollForward);
writer.WriteEndObject();
}

Expand Down
10 changes: 7 additions & 3 deletions src/Cli/dotnet/ToolManifest/ToolManifestPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ internal struct ToolManifestPackage : IEquatable<ToolManifestPackage>
public PackageId PackageId { get; }
public NuGetVersion Version { get; }
public ToolCommandName[] CommandNames { get; }
public bool RollForward { get; }
JL03-Yue marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// The directory that will take effect first.
/// When it is under .config directory, it is not .config directory
Expand All @@ -23,12 +24,14 @@ internal struct ToolManifestPackage : IEquatable<ToolManifestPackage>
public ToolManifestPackage(PackageId packagePackageId,
NuGetVersion version,
ToolCommandName[] toolCommandNames,
DirectoryPath firstEffectDirectory)
DirectoryPath firstEffectDirectory,
bool rollForward)
{
FirstEffectDirectory = firstEffectDirectory;
PackageId = packagePackageId;
Version = version ?? throw new ArgumentNullException(nameof(version));
CommandNames = toolCommandNames ?? throw new ArgumentNullException(nameof(toolCommandNames));
RollForward = rollForward;
}

public override bool Equals(object obj)
Expand All @@ -43,7 +46,8 @@ public bool Equals(ToolManifestPackage other)
EqualityComparer<NuGetVersion>.Default.Equals(Version, other.Version) &&
CommandNamesEqual(other.CommandNames) &&
FirstEffectDirectory.Value.TrimEnd('/', '\\')
.Equals(other.FirstEffectDirectory.Value.TrimEnd('/', '\\'), StringComparison.Ordinal);
.Equals(other.FirstEffectDirectory.Value.TrimEnd('/', '\\'), StringComparison.Ordinal) &&
RollForward.Equals(other.RollForward);
JL03-Yue marked this conversation as resolved.
Show resolved Hide resolved
}

private bool CommandNamesEqual(ToolCommandName[] otherCommandNames)
Expand All @@ -63,7 +67,7 @@ private bool CommandNamesEqual(ToolCommandName[] otherCommandNames)

public override int GetHashCode()
{
return HashCode.Combine(PackageId, Version, CommandNames);
return HashCode.Combine(PackageId, Version, CommandNames, RollForward);
}

public static bool operator ==(ToolManifestPackage tool1,
Expand Down
5 changes: 5 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading