Skip to content

Commit

Permalink
(chocolateyGH-839) Switch to apply package parameters to dependent pa…
Browse files Browse the repository at this point in the history
…ckages

In version 0.9.9.12 and earlier, install arguments and package-parameters would also be applied to dependent packages, but in choco 0.9.10 this was changed so that it would only be applied to the specified package.
Sometimes it will be useful to pass the install arguments and package parameters further to dependent packages. This can be controlled by using cmdline switches.
  • Loading branch information
eirikatdips committed Aug 22, 2016
1 parent edc338e commit 5d26773
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 7 deletions.
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
23 changes: 16 additions & 7 deletions src/chocolatey/infrastructure.app/services/PowershellService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,14 @@ public string wrap_script_with_module(string script, ChocolateyConfiguration con

private string get_script_arguments(string script, ChocolateyConfiguration config)
{
return "-packageScript '{0}' -installArguments '{1}' -packageParameters '{2}'{3}{4}".format_with(
return "-packageScript '{0}' -installArguments '{1}' -packageParameters '{2}'{3}{4}{5}".format_with(
script,
prepare_powershell_arguments(config.InstallArguments),
prepare_powershell_arguments(config.PackageParameters),
config.ForceX86 ? " -forceX86" : string.Empty,
config.OverrideArguments ? " -overrideArgs" : string.Empty
config.OverrideArguments ? " -overrideArgs" : string.Empty,
config.ApplyPackageParametersToDependencies ? " -apply-package-parameters-to-dependencies" : string.Empty,
config.ApplyInstallArgumentsToDependencies ? " -apply-install-arguments-to-dependencies" : string.Empty
);
}

Expand Down Expand Up @@ -403,22 +405,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);
}

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

0 comments on commit 5d26773

Please sign in to comment.