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

Exclude package versions from tool package folders #1410

Merged

Conversation

thomaslevesque
Copy link
Member

@thomaslevesque thomaslevesque commented Aug 17, 2018

Just an idea, feel free to close if you don't like it...

This will make updates easier as we won't have to update the paths in csx scripts.

Small gotcha: you have to remove the packages already installed first. Even with -ExcludeVersion, nuget install won't reinstall package Foo 1.0.0 if it already exists in folder Foo.1.0.0 (which feels like a bug to me) (solved by checking if packages.config's SHA1 has changed since last run)

@@ -26,10 +26,10 @@ if not exist %TOOLS_DIR%\.nuget md %TOOLS_DIR%\.nuget
copy /Y %NUGET_CACHE_DIR%\NuGet.exe %TOOLS_DIR%\.nuget\NuGet.exe > nul

rem restore packages for build script
%TOOLS_DIR%\.nuget\NuGet.exe restore %TOOLS_DIR%\packages.config -PackagesDirectory %TOOLS_DIR%\packages -Verbosity quiet
%TOOLS_DIR%\.nuget\NuGet.exe install %TOOLS_DIR%\packages.config -OutputDirectory %TOOLS_DIR%\packages -Verbosity quiet -ExcludeVersion
Copy link
Member Author

Choose a reason for hiding this comment

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

nuget install on a packages.config basically does the same thing as nuget restore, but has the -ExcludeVersion switch

@thomaslevesque thomaslevesque changed the title Exclude package versions from tool package folders [DO NOT MERGE] Exclude package versions from tool package folders Aug 17, 2018
@thomaslevesque
Copy link
Member Author

Actually I just realized something... If we update the version in packages.config, NuGet won't know that the currently installed version isn't the right one, so it won't reinstall it. I have an idea to work around this, stay tuned.

@blairconrad
Copy link
Member

blairconrad commented Aug 17, 2018

I see a failing build that is not your fault:

https://ci.appveyor.com/project/FakeItEasy/fakeiteasy/build/633-cyahcldk#L342

FakeItEasy.Specs.GenericDummyCreationSpecs.ClassWhoseLongerConstructorThrowsCreation() [10] And the longer constructor was only attempted once [FAIL]

The actual count was 2. I suspect this is a race condition, which you predicted, @thomaslevesque. I'll investigate as time allows.

@thomaslevesque
Copy link
Member Author

Actually I just realized something... If we update the version in packages.config, NuGet won't know that the currently installed version isn't the right one, so it won't reinstall it. I have an idea to work around this, stay tuned.

Here's my idea:

  • compute a hash of the packages.config file
  • compare with a previously stored hash
  • if the hashes are different, delete everything in the packages directory
  • store the new hash in a file

(it's the approach used by Cake)

What do you think?

@blairconrad
Copy link
Member

That sounds pretty good, @thomaslevesque.

@thomaslevesque
Copy link
Member Author

Would you mind if I converted run-csx.cmd to PowerShell? PowerShell (4+) has a Get-FileHash command that would be very helpful

@thomaslevesque
Copy link
Member Author

All done, tell me what you think!

Copy link
Member

@blairconrad blairconrad left a comment

Choose a reason for hiding this comment

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

I like it, @thomaslevesque.
I was going to suggest a more granular approach to deleting the old packages, but they're probably just sitting in the NuGet cache anyhow, so I think this is the right approach.

I did make some minor comments, but would not hold up the merge for them, nor for this one:
now that we have PowerShell, I notice the various comments in the file and in some cases think that the blocks of functionality could easily be extracted into their own functions, as part of my motto "if it's worth commenting, it could be a function". Do you think there's value in that? If not, say the word, update the title (to not be WIP) and I'll merge.

& $NuGetExe install $PackagesConfig -OutputDirectory $PackagesDir -Verbosity quiet -ExcludeVersion

# run build script
$CsiExe = "$ToolsDir\packages\Microsoft.Net.Compilers\tools\csi.exe"
Copy link
Member

Choose a reason for hiding this comment

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

It's a small thing, but $PackagesDir instead of $ToolsDir\package?

$PackagesHash = (Get-FileHash -Algorithm SHA1 -Path $PackagesConfig).Hash
# if packages.config has changed, clear packages and store new hash
if ($PackagesHash -ne $PreviousPackagesHash) {
Write-Host "Packages.config has changed, reinstalling packages..."
Copy link
Member

Choose a reason for hiding this comment

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

I'd consider $PackagesConfig instead of "Packages.config", unless you want to hide the path (which is fine)

@thomaslevesque
Copy link
Member Author

now that we have PowerShell, I notice the various comments in the file and in some cases think that the blocks of functionality could easily be extracted into their own functions, as part of my motto "if it's worth commenting, it could be a function". Do you think there's value in that?

Sure, I'll do it

@thomaslevesque thomaslevesque changed the title [DO NOT MERGE] Exclude package versions from tool package folders Exclude package versions from tool package folders Aug 19, 2018
Push-Location $RepoRoot

DownloadNuGetToCache
CopyNuGetLocally
Copy link
Member Author

Choose a reason for hiding this comment

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

I assume there's a good reason for copying nuget in a local folder, but I don't remember what it is... Why don't we use it directly from the cache directory? Or why don't we download it directly to the local directory?
I think the local directory could act as the cache; a build script has no business writing to the user's AppData folder.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I stumble over this as well. I think @adamralph originated the behaviour or imported from somewhere else.
I wouldn't mind if either the caching or the copying went away (I don't mind the build script writing to the AppData folder, but don't mind it not doing it either).
The current system does give a way to always have the correct nuget in the local directory (because the cache directory is versioned) without downloading it all the time or having the rest of the build system need to know what the version is.
I guess it also allows one to switch between (already cached) versions while disconnected. but that's a small concern.

Copy link
Member

Choose a reason for hiding this comment

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

I don't even mind the idea of committing the nuget exe, if we want.

Copy link
Contributor

Choose a reason for hiding this comment

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

You might find it simpler to do away with scripting completely, as I've done with xbehave and @blairconrad has done with SelfInitializingFakes. It allows you to drop nuget.exe, csi.exe, packages.config, etc. All you need is a csproj for package references and a Program.Main for your build "script". You can then invoke simply with dotnet run.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it might make things easier...

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, a mixed VB/C# solution isn't a use-case either, since an analyzer is installed in a project, which can't be mixed language.

Copy link
Member

Choose a reason for hiding this comment

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

No, but the meta-package does provide a convenient way to update both C# and VB versions at once. For me, it's not enough of an advantage to continue with it, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Another option is to use dotnet script instead of manually invoking csi.exe. It natively supports NuGet references. It requires .NET Core SDK 2.1+, though, since it's a global tool.

Copy link
Contributor

Choose a reason for hiding this comment

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

dotnet script also requires bootstrapping, or listing as another pre-requisite. The beauty of the dotnet run approach is that nothing else is required other than the dotnet SDK, which is already a pre-requisite.

Also, you get full tooling support, in all IDEs, since it's just a regular C# project. No special scripting plug-ins, etc. required.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point!

@blairconrad
Copy link
Member

@thomaslevesque, thanks for the changes. It looks great. I'm happy to merge after squash. And continue to explore the "cached and copied nuget" either here or elsewhere.

@thomaslevesque
Copy link
Member Author

And continue to explore the "cached and copied nuget" either here or elsewhere.

👍

@blairconrad blairconrad merged commit 169b809 into FakeItEasy:develop Aug 19, 2018
@blairconrad
Copy link
Member

Nice job, @thomaslevesque. Thanks.

@blairconrad blairconrad added this to the vNext milestone Aug 19, 2018
@thomaslevesque thomaslevesque deleted the exclude-package-version branch August 19, 2018 21:51
@thomaslevesque
Copy link
Member Author

Thanks for the merge, and the comments!

#r "packages/Bullseye.1.1.0-rc.2/lib/netstandard2.0/Bullseye.dll"
#r "packages/SimpleExec.2.2.0/lib/netstandard2.0/SimpleExec.dll"
#r "packages/Bullseye/lib/netstandard2.0/Bullseye.dll"
#r "packages/SimpleExec/lib/netstandard1.3/SimpleExec.dll"
Copy link
Contributor

Choose a reason for hiding this comment

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

@FakeItEasy/owners was the change back to netstandard1.3 intentional? The restoration graph is much lighter if you use netstandard2.0.

Copy link
Member Author

Choose a reason for hiding this comment

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

@adamralph no, it's not intentional. I must have done it when I resolved a conflict with #1409

Copy link
Member

Choose a reason for hiding this comment

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

Whoops. That had caught my eye initially and I forgot about it in the other conversation (none of which was as important as that).

@blairconrad
Copy link
Member

This change has been released as part of FakeItEasy 4.8.1.

1 similar comment
@blairconrad
Copy link
Member

This change has been released as part of FakeItEasy 4.8.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants