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

(GH-839) Switch to apply package parameters to dependent packages #915

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -151,6 +151,18 @@ public void should_add_short_version_of_packageparameters_to_the_option_set()
optionSet.Contains("params").ShouldBeTrue();
}

[Fact]
public void should_add_applyPackageParametersToDependencies_to_the_option_set()
{
optionSet.Contains("apply-package-parameters-to-dependencies").ShouldBeTrue();
}

[Fact]
public void should_add_applyInstallArgumentsToDependencies_to_the_option_set()
{
optionSet.Contains("apply-install-arguments-to-dependencies").ShouldBeTrue();
}

[Fact]
public void should_add_allowmultipleversions_to_the_option_set()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ public void should_add_short_version_of_packageparameters_to_the_option_set()
optionSet.Contains("params").ShouldBeTrue();
}

[Fact]
public void should_add_applyPackageParametersToDependencies_to_the_option_set()
{
optionSet.Contains("apply-package-parameters-to-dependencies").ShouldBeTrue();
}

[Fact]
public void should_add_applyInstallArgumentsToDependencies_to_the_option_set()
{
optionSet.Contains("apply-install-arguments-to-dependencies").ShouldBeTrue();
}

[Fact]
public void should_add_forcedependencies_to_the_option_set()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ public void should_add_short_version_of_packageparameters_to_the_option_set()
optionSet.Contains("params").ShouldBeTrue();
}

[Fact]
public void should_add_applyPackageParametersToDependencies_to_the_option_set()
{
optionSet.Contains("apply-package-parameters-to-dependencies").ShouldBeTrue();
}

[Fact]
public void should_add_applyInstallArgumentsToDependencies_to_the_option_set()
{
optionSet.Contains("apply-install-arguments-to-dependencies").ShouldBeTrue();
}

[Fact]
public void should_add_allowmultipleversions_to_the_option_set()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
.Add("params=|parameters=|pkgparameters=|packageparameters=|package-parameters=",
"PackageParameters - Parameters to pass to the package. Defaults to unspecified.",
option => configuration.PackageParameters = option.remove_surrounding_quotes())
.Add("apply-install-arguments-to-dependencies",
"Apply Install Arguments To Dependencies - Should install arguments be applied to dependent packages? Defaults to false.",
option => configuration.ApplyInstallArgumentsToDependencies = option != null)
.Add("apply-package-parameters-to-dependencies",
"Apply Package Parameters To Dependencies - Should package parameters be applied to dependent packages? Defaults to false.",
option => configuration.ApplyPackageParametersToDependencies = option != null)
.Add("allowdowngrade|allow-downgrade",
"AllowDowngrade - Should an attempt at downgrading be allowed? Defaults to false.",
option => configuration.AllowDowngrade = option != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
.Add("params=|parameters=|pkgparameters=|packageparameters=|package-parameters=",
"PackageParameters - Parameters to pass to the package. Defaults to unspecified.",
option => configuration.PackageParameters = option.remove_surrounding_quotes())
.Add("apply-install-arguments-to-dependencies",
"Apply Install Arguments To Dependencies - Should install arguments be applied to dependent packages? Defaults to false.",
option => configuration.ApplyInstallArgumentsToDependencies = option != null)
.Add("apply-package-parameters-to-dependencies",
"Apply Package Parameters To Dependencies - Should package parameters be applied to dependent packages? Defaults to false.",
option => configuration.ApplyPackageParametersToDependencies = option != null)
.Add("m|sxs|sidebyside|side-by-side|allowmultiple|allow-multiple|allowmultipleversions|allow-multiple-versions",
"AllowMultipleVersions - Should multiple versions of a package be installed? Defaults to false.",
option => configuration.AllowMultipleVersions = option != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
.Add("params=|parameters=|pkgparameters=|packageparameters=|package-parameters=",
"PackageParameters - Parameters to pass to the package. Defaults to unspecified.",
option => configuration.PackageParameters = option.remove_surrounding_quotes())
.Add("apply-install-arguments-to-dependencies",
"Apply Install Arguments To Dependencies - Should install arguments be applied to dependent packages? Defaults to false.",
option => configuration.ApplyInstallArgumentsToDependencies = option != null)
.Add("apply-package-parameters-to-dependencies",
"Apply Package Parameters To Dependencies - Should package parameters be applied to dependent packages? Defaults to false.",
option => configuration.ApplyPackageParametersToDependencies = option != null)
.Add("allowdowngrade|allow-downgrade",
"AllowDowngrade - Should an attempt at downgrading be allowed? Defaults to false.",
option => configuration.AllowDowngrade = option != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ private void append_output(StringBuilder propertyValues, string append)
public bool OverrideArguments { get; set; }
public bool NotSilent { get; set; }
public string PackageParameters { get; set; }
public bool ApplyPackageParametersToDependencies { get; set; }
public bool ApplyInstallArgumentsToDependencies { get; set; }
public bool IgnoreDependencies { get; set; }
public bool AllowMultipleVersions { get; set; }
public bool AllowDowngrade { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public sealed class PackagesConfigFilePackageSetting
[XmlAttribute(AttributeName = "packageParameters")]
public string PackageParameters { get; set; }

[XmlAttribute(AttributeName = "applyPackageParametersToDependencies")]
public bool ApplyPackageParametersToDependencies { get; set; }

[XmlAttribute(AttributeName = "applyInstallArgumentsToDependencies")]
public bool ApplyInstallArgumentsToDependencies { get; set; }

[XmlAttribute(AttributeName = "forceX86")]
public bool ForceX86 { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ private string capture_arguments(ChocolateyConfiguration config, PackageResult p
if (!string.IsNullOrWhiteSpace(config.InstallArguments)) arguments.Append(" --install-arguments=\"'{0}'\"".format_with(config.InstallArguments));
if (config.OverrideArguments) arguments.Append(" --override-arguments");
if (!string.IsNullOrWhiteSpace(config.PackageParameters)) arguments.Append(" --package-parameters=\"'{0}'\"".format_with(config.PackageParameters));
if (config.ApplyPackageParametersToDependencies) arguments.Append(" --apply-package-parameters-to-dependencies");
if (config.ApplyInstallArgumentsToDependencies) arguments.Append(" --apply-install-arguments-to-dependencies");
if (config.AllowDowngrade) arguments.Append(" --allow-downgrade");
if (config.AllowMultipleVersions) arguments.Append(" --allow-multiple-versions");
if (config.IgnoreDependencies) arguments.Append(" --ignore-dependencies");
Expand Down Expand Up @@ -572,6 +574,8 @@ private IEnumerable<ChocolateyConfiguration> get_packages_from_config(string pac
if (pkgSettings.ForceX86) packageConfig.ForceX86 = true;
if (pkgSettings.AllowMultipleVersions) packageConfig.AllowMultipleVersions = true;
if (pkgSettings.IgnoreDependencies) packageConfig.IgnoreDependencies = true;
if (pkgSettings.ApplyInstallArgumentsToDependencies) packageConfig.ApplyInstallArgumentsToDependencies = true;
if (pkgSettings.ApplyPackageParametersToDependencies) packageConfig.ApplyPackageParametersToDependencies = true;

this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(packageConfig.PackageNames));
packageConfigs.Add(packageConfig);
Expand Down
17 changes: 12 additions & 5 deletions src/chocolatey/infrastructure.app/services/PowershellService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,22 +403,29 @@ public void prepare_powershell_environment(IPackage package, ChocolateyConfigura

// we only want to pass the following args to packages that would apply.
// like choco install git -params '' should pass those params to git.install,
// but not another package
if (!package_is_a_dependency_not_a_virtual(configuration, package.Id))
// but not another package unless the switch apply-install-arguments-to-dependencies is used
if (!package_is_a_dependency_not_a_virtual(configuration, package.Id) || configuration.ApplyInstallArgumentsToDependencies)
{
this.Log().Debug(ChocolateyLoggers.Verbose, "Setting installer args and package parameters for {0}".format_with(package.Id));
this.Log().Debug(ChocolateyLoggers.Verbose, "Setting installer args for {0}".format_with(package.Id));
Environment.SetEnvironmentVariable("installArguments", configuration.InstallArguments);
Environment.SetEnvironmentVariable("installerArguments", configuration.InstallArguments);
Environment.SetEnvironmentVariable("chocolateyInstallArguments", configuration.InstallArguments);
Environment.SetEnvironmentVariable("packageParameters", configuration.PackageParameters);
Environment.SetEnvironmentVariable("chocolateyPackageParameters", configuration.PackageParameters);

if (configuration.OverrideArguments)
{
Environment.SetEnvironmentVariable("chocolateyInstallOverride", "true");
}
}

// we only want to pass package parameters to packages that would apply.
// but not another package unless the switch apply-package-parameters-to-dependencies is used
if (!package_is_a_dependency_not_a_virtual(configuration, package.Id) || configuration.ApplyPackageParametersToDependencies)
{
this.Log().Debug(ChocolateyLoggers.Verbose, "Setting package parameters for {0}".format_with(package.Id));
Environment.SetEnvironmentVariable("packageParameters", configuration.PackageParameters);
Environment.SetEnvironmentVariable("chocolateyPackageParameters", configuration.PackageParameters);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the operation for checking whether package is a dependency expensive? Other than that, 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure why your asking that question. Can you please elaborate? Or are you proposing that I change something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a question, just a statement mostly. Something for me to consider later when pulling this in.

if (!string.IsNullOrWhiteSpace(configuration.DownloadChecksum))
{
Environment.SetEnvironmentVariable("chocolateyChecksum32", configuration.DownloadChecksum);
Expand Down