Skip to content

(#1670) Add noshims options for install and upgrade #2003

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
75 changes: 72 additions & 3 deletions Scenarios.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Chocolatey Usage Scenarios

### ChocolateyInstallCommand [ 35 Scenario(s), 293 Observation(s) ]
### ChocolateyInstallCommand [ 42 Scenario(s), 312 Observation(s) ]

#### when force installing a package that depends on an unavailable newer version of an installed dependency forcing dependencies

Expand Down Expand Up @@ -247,6 +247,20 @@
* should not install a package in the lib directory
* should put a package in the lib bad directory

#### when installing a package that tries to overwrite another shim

* should have a shim
* should have a shim with target in other package tools folder
* should have an error message
* should have shim target

#### when installing a package that tries to overwrite its own shim

* should create a shim
* should have a shim with target in tools folder
* should have an error message
* should have shim targets

#### when installing a package with a dependent package that also depends on a less constrained but still valid dependency of the same package

* [PENDING] should contain a message that everything installed successfully
Expand Down Expand Up @@ -282,6 +296,18 @@
* should not install a package in the lib directory
* should not install the dependency in the lib directory

#### when installing a package with dependencies and noshims

* should create a shim for the dependency
* should have shim targets
* should not create a shim for the package

#### when installing a package with dependencies and noshimsglobal

* should have shim targets
* should not create a shim for the dependency
* should not create a shim for the package

#### when installing a package with dependencies happy

* should contain a message that everything installed successfully
Expand Down Expand Up @@ -326,11 +352,25 @@
* [PENDING] should not install the conflicting package in the lib directory
* [PENDING] should not upgrade the exact version dependency

#### when installing a package with install bin file

* should not see the shim as an existing shim and remove it

#### when installing a package with install bin file and noshims

* should have shim target
* should not create a shim

#### when installing a package with no sources enabled

* should have no sources enabled result
* should not install any packages

#### when installing a package with noshims

* should have shim target
* should not create a shim for the package

#### when installing a side by side package

* config should match package result name
Expand Down Expand Up @@ -541,7 +581,7 @@

* should contain success message

### ChocolateyUninstallCommand [ 13 Scenario(s), 93 Observation(s) ]
### ChocolateyUninstallCommand [ 14 Scenario(s), 95 Observation(s) ]

#### when force uninstalling a package

Expand Down Expand Up @@ -617,6 +657,11 @@
* should not remove package from the lib directory
* should still have the package file in the directory

#### when uninstalling a package that forgets to call uninstall bin file

* should have had a shim
* should have removed the shim
Copy link
Member

Choose a reason for hiding this comment

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

Awesome, thanks for doing this!

Copy link
Author

Choose a reason for hiding this comment

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

Of course, this only applies to packages that install into ..\chocolatey\lib\<package-name>, so shims targetting binaries somewhere else would not get removed.

If Shimgen accepted the package name as a parameter and stored this in the shim's FileVersionInfo data (together with the target binary, as suggested elsewhere), then this limitation disappears.


#### when uninstalling a package with a read and delete share locked file

* should contain a message that it uninstalled successfully
Expand Down Expand Up @@ -675,7 +720,7 @@

* should throw an error that it is not allowed

### ChocolateyUpgradeCommand [ 36 Scenario(s), 295 Observation(s) ]
### ChocolateyUpgradeCommand [ 40 Scenario(s), 307 Observation(s) ]

#### when force upgrading a package

Expand Down Expand Up @@ -920,6 +965,11 @@
* should have no sources enabled result
* should not have any packages upgraded

#### when upgrading a package with noshims

* should have shim target
* should not create a shim

#### when upgrading a package with readonly files

* should contain a warning message that it upgraded successfully
Expand All @@ -933,6 +983,25 @@
* should upgrade the package
* should upgrade where install location reports

#### when upgrading a package with shims
Copy link
Member

Choose a reason for hiding this comment

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

What about when upgrading a package that has existing shims with no shims in the upgrade? What's the expected behavior for that use case?

Copy link
Author

Choose a reason for hiding this comment

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

The default behaviour in install and upgrade scenarios is to remove all shims for the package first, then install any shims if not prohibited by --noshims or --noshimsglobal.

So the existing shims will be removed and the new shims will not be installed.


* should create a shim
* should have had original shim
* should have shim target
* should not have original shim

#### when upgrading a package with shims that errors

* should have original shim
* should not create a shim

#### when upgrading a package with shims with noshims

* should have had original shim
* should have shim target
* should not create a shim
* should not have original shim

#### when upgrading a package with unavailable dependencies

* should contain a message that it was unable to upgrade anything
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ param(

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

if ($env:ChocolateyNoShims) {
Write-Debug "File shimming disabled for `'$($env:ChocolateyPackageName)`'."
Write-Debug "Removing any existing shim for `'$name`'."
Uninstall-BinFile $name $path
return
}
Copy link
Member

Choose a reason for hiding this comment

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

Following my last comment, I see you have code to remove shims if no shims is called. Might be good to add a scenario for that use case

Copy link
Author

Choose a reason for hiding this comment

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

Not quite sure what you want here, so I have added an extra upgrade scenario in b496390

This tests an upgrade to a package that has a shim, with the --noshims flag.

Is this the sort of thing you wanted?


$nugetPath = [System.IO.Path]::GetFullPath((Join-Path "$helpersPath" '..\'))
$nugetExePath = Join-Path "$nugetPath" 'bin'
$packageBatchFileName = Join-Path $nugetExePath "$name.bat"
Expand Down
2 changes: 2 additions & 0 deletions src/chocolatey.tests.integration/Scenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ private static ChocolateyConfiguration baseline_configuration()
config.PinCommand.Name = string.Empty;
config.PinCommand.Command = PinCommandType.unknown;
config.ListCommand.IdOnly = false;
config.NoShims = false;
config.NoShimsGlobal = false;

return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,105 @@
<None Include="context\nonterminatingerror\1.0\tools\chocolateyInstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimbasepackage\1.0.0\shimbasepackage.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimbasepackage\1.0.0\tools\chocolateyinstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimbasepackage\1.0.0\tools\chocolateyuninstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimbasepackage\1.0.0\tools\shimbasepackage1.exe.">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimhasdependency\1.0.0\shimhasdependency.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimhasdependency\1.0.0\tools\chocolateyinstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimhasdependency\1.0.0\tools\chocolateyuninstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimhasdependency\1.0.0\tools\shimhasdependency1.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimoverwrite\1.0.0\shimoverwrite.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimoverwrite\1.0.0\tools\chocolateyinstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimoverwrite\1.0.0\tools\chocolateyuninstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimoverwrite\1.0.0\tools\shimoverwrite1.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimoverwrite\1.0.0\tools\install\shimoverwrite1.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimoverwriteother\1.0.0\shimoverwriteother.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimoverwriteother\1.0.0\tools\chocolateyinstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimoverwriteother\1.0.0\tools\chocolateyuninstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimoverwriteother\1.0.0\tools\shimbasepackage1.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimupgrade\1.0.0\shimupgrade.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimupgrade\1.0.0\tools\chocolateyinstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimupgrade\1.0.0\tools\chocolateyuninstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimupgrade\1.0.0\tools\shimupgrade1.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimupgrade\2.0.0\shimupgrade.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimupgrade\2.0.0\tools\chocolateyinstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimupgrade\2.0.0\tools\chocolateyuninstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimupgrade\2.0.0\tools\shimupgrade2.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimupgrade\3.0.0\shimupgrade.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimupgrade\3.0.0\tools\chocolateyinstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimupgrade\3.0.0\tools\chocolateyuninstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimupgrade\3.0.0\tools\shimupgrade3.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimwithbinfile\1.0.0\shimwithbinfile.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimwithbinfile\1.0.0\tools\chocolateyinstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimwithbinfile\1.0.0\tools\chocolateyuninstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\shims\shimwithbinfile\1.0.0\tools\shimwithbinfile1.bat">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\testing.packages.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>shimbasepackage</id>
<version>1.0.0</version>
<title>shimbasepackage</title>
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
<owners>__REPLACE_YOUR_NAME__</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>__REPLACE__</description>
<summary>__REPLACE__</summary>
<tags>shimbasepackage</tags>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "$env:PackageName $env:PackageVersion Installed"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "$env:PackageName $env:PackageVersion Uninstalled"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>shimhasdependency</id>
<version>1.0.0</version>
<title>shimhasdependency</title>
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
<owners>__REPLACE_YOUR_NAME__</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>__REPLACE__</description>
<summary>__REPLACE__</summary>
<tags>shimhasdependency</tags>
<dependencies>
<dependency id="shimbasepackage" version="1.0.0" />
</dependencies>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "$env:PackageName $env:PackageVersion Installed"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "$env:PackageName $env:PackageVersion Uninstalled"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>shimoverwrite</id>
<version>1.0.0</version>
<title>shimoverwrite</title>
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
<owners>__REPLACE_YOUR_NAME__</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>__REPLACE__</description>
<summary>__REPLACE__</summary>
<tags>overwrite-own</tags>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "$env:PackageName $env:PackageVersion Installed"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "$env:PackageName $env:PackageVersion Uninstalled"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>shimoverwriteother</id>
<version>1.0.0</version>
<title>shimoverwriteother</title>
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
<owners>__REPLACE_YOUR_NAME__</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>__REPLACE__</description>
<summary>__REPLACE__</summary>
<tags>shimoverwriteother</tags>
<dependencies>
<dependency id="shimbasepackage" version="1.0.0" />
</dependencies>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "$env:PackageName $env:PackageVersion Installed"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "$env:PackageName $env:PackageVersion Uninstalled"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>shimupgrade</id>
<version>1.0.0</version>
<title>shimupgrade</title>
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
<owners>__REPLACE_YOUR_NAME__</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>__REPLACE__</description>
<summary>__REPLACE__</summary>
<tags>shimupgrade</tags>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "$env:PackageName $env:PackageVersion Installed"
Loading