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

Added support for better handling of transitive dependencies #539

Merged
merged 4 commits into from
Jul 20, 2023

Conversation

popara96
Copy link
Collaborator

Details of new usage are explained in README file.

Copy link
Collaborator

@JoC0de JoC0de left a comment

Choose a reason for hiding this comment

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

Hi @popara96,
thanks for the contribution. It was a much requested feature, I also wanted to include the feature but had no time. It generally looks good, I added some comments it would be nice if you fix them.
Also one UnitTest is failing.

.gitignore Outdated
@@ -1,3 +1,4 @@
/[Bb]in/

*.log
/src/NuGetForUnity.CreateDll/.idea/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/src/NuGetForUnity.CreateDll/.idea/**
**/.idea

@@ -67,6 +67,8 @@ public static class NugetHelper
/// </summary>
private static readonly List<NugetPackageSource> packageSources = new List<NugetPackageSource>();

public static event Action OnInstalledPackagesChanged;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't like events especially static ones. The UI (NugetWindow) knows when packages are installed so it don't needs to depend on NugetHelper to manage a event.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I remember there being a code earlier that would automatically trigger Restore when packages.config file was changed and we thought we needed this event because of that case but it seems that code is now only triggered the first time project is loaded.

Is that right? Does that mean if I install some packages and push packages.config other developers won't automatically get that package installed when they pull my changes if they already have project open in Unity and they will have to manually run Restore?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes for packages.config change detection we would need to implement a AssetPostprocessor / add this feature to the NugetPackageAssetPostprocessor

Comment on lines 761 to 764
installedPackages?.Remove(foundPackage.Id);

if (installedPackages != null && installedPackages.Count > 0)
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
installedPackages?.Remove(foundPackage.Id);
if (installedPackages != null && installedPackages.Count > 0)
{
if (installedPackages != null && installedPackages.Count > 0)
{
installedPackages.Remove(foundPackage.Id);


if (installedPackages != null && installedPackages.Count > 0)
{
var frameworkGroup = GetBestDependencyFrameworkGroupForCurrentSettings(foundPackage);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
var frameworkGroup = GetBestDependencyFrameworkGroupForCurrentSettings(foundPackage);
// uninstall all non manually installed dependencies that are not a dependency of another installed package
var frameworkGroup = GetBestDependencyFrameworkGroupForCurrentSettings(foundPackage);

Comment on lines 871 to 875
var actualData = PackagesConfigFile.Packages.Find(pkg => pkg.Id == package.Id);
if (actualData != null)
{
package.IsManuallyInstalled = actualData.IsManuallyInstalled;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
var actualData = PackagesConfigFile.Packages.Find(pkg => pkg.Id == package.Id);
if (actualData != null)
{
package.IsManuallyInstalled = actualData.IsManuallyInstalled;
}
package.IsManuallyInstalled = PackagesConfigFile.Packages.FirstOrDefault(pkg => pkg.Id == package.Id)?.IsManuallyInstalled ?? false;

I more like this "one liners"

src/NuGetForUnity/Editor/PackagesConfigFile.cs Outdated Show resolved Hide resolved
src/NuGetForUnity/Editor/NugetWindow.cs Outdated Show resolved Hide resolved
src/NuGetForUnity/Editor/NugetWindow.cs Outdated Show resolved Hide resolved
src/NuGetForUnity/Editor/NugetWindow.cs Outdated Show resolved Hide resolved
src/NuGetForUnity/Editor/NugetWindow.cs Outdated Show resolved Hide resolved
@igor84
Copy link
Collaborator

igor84 commented Jul 17, 2023

The unit test that is failing tests the following:

  1. Installs bootstrap 3.3.7 which depends on jQuery [1.9.1, 4.0.0).
  2. Checks that jquery 1.9.1 is installed.
  3. Upgrades jquery to 3.1.1.
  4. Reinstalls bootstrap 3.3.7 and checks if jquery 3.1.1 is still installed.

But with new functionality uninstalling bootstrap uninstalls the jquery since it is a transitive dependency and also reinstalls the old version again. The question is what do we want to do when updating packages.

I guess the most correct option would be to update all the transitive dependencies that no other package depends on but only to a newer version, so if some dependency was already manually updated to a new version there is no need to downgrade it.

Or maybe if you manually update some transitive dependency we should just mark it as manually installed from then on?

@igor84
Copy link
Collaborator

igor84 commented Jul 17, 2023

One more thing we considered is that people with old packages.config files when they update to this new version of NugetForUnity all their packages will be marked as transitive dependencies. They can, of course, manually mark some as manually installed afterwards.

The only other option that came to our mind is to detect when none of the packages are marked as manually installed and then to mark them all. What do you think?

@JoC0de
Copy link
Collaborator

JoC0de commented Jul 17, 2023

One more thing we considered is that people with old packages.config files when they update to this new version of NugetForUnity all their packages will be marked as transitive dependencies. They can, of course, manually mark some as manually installed afterwards.

The only other option that came to our mind is to detect when none of the packages are marked as manually installed and then to mark them all. What do you think?

I think best way would be to mark all packages as manually installed that are not a dependency of any other installed package. So only the root packages in the dependency tree are considered manually installed. This way we mark the minimum number of packages as manually installed to get a state that lead to the current amount of packages being installed.

@JoC0de
Copy link
Collaborator

JoC0de commented Jul 17, 2023

The unit test that is failing tests the following:

  1. Installs bootstrap 3.3.7 which depends on jQuery [1.9.1, 4.0.0).
  2. Checks that jquery 1.9.1 is installed.
  3. Upgrades jquery to 3.1.1.
  4. Reinstalls bootstrap 3.3.7 and checks if jquery 3.1.1 is still installed.

But with new functionality uninstalling bootstrap uninstalls the jquery since it is a transitive dependency and also reinstalls the old version again. The question is what do we want to do when updating packages.

I guess the most correct option would be to update all the transitive dependencies that no other package depends on but only to a newer version, so if some dependency was already manually updated to a new version there is no need to downgrade it.

Or maybe if you manually update some transitive dependency we should just mark it as manually installed from then on?

Updating a package always ensures that the minimum version of all its dependencies are also installed so the only issue here is that the test expects jquery to not being uninstalled. I think uninstalling jquery is the scorest behavior, even if the package is updated manually, the user has the possibility to mark it as manually installed to prevent this. So in the UnitTest I would just mark jquery as manually installed so the test can still check the dependency installation.

@popara96 popara96 merged commit 6a2fa48 into master Jul 20, 2023
@popara96 popara96 deleted the smarter-dependencies branch July 20, 2023 12:08
@popara96
Copy link
Collaborator Author

I decided to merge this because I think we agreed on all or almost all points, and all of the suggested fixes were implemented. In case you do have some additional comments, I can fix them later. This way it will be easier to work on other issues as most of them would make conflict with these changes.

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.

Unclear outcome for Unity's embedded packages.
3 participants