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

u3d/install: do not reinstall already installed packages #202

Merged
merged 21 commits into from
Jan 2, 2018

Conversation

niezbop
Copy link
Member

@niezbop niezbop commented Dec 26, 2017

Fixes #198

This solve the issues of non-matching package name between installed and available by:

  • Mapping the names of the installed package and the available package
  • Detecting some folders on the local install for "special package" (Documentation, Standard Assets...)

@niezbop niezbop requested a review from lacostej December 26, 2017 01:53
@niezbop niezbop self-assigned this Dec 26, 2017
@niezbop
Copy link
Member Author

niezbop commented Dec 26, 2017

This is still [WIP] because:

  • Example package is still not detected as it is not installed in the install but in the public home (ie C:\Users\Public\Documents\Unity Projects\Standard Assets Example Project on Windows), and I'm not sure we want to track this, especially given the fact that it probably shouldn't be installed in the first place on a CI environment.
  • We lack local folder detection for Mac, as I have limited access to this OS for now.

end
pack << 'Documentation' if specific_dir?("#{root_path}/Editor/Data/Documentation/", check_empty: true)
Copy link
Member

Choose a reason for hiding this comment

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

we could have a method under each PlatformInstallation called

def module_files_pattern(module_name)
  return "#{root_path}/Editor/Data/Documentation/*" if module_name == "Documentation"
  return ....
end

or something similar

and then do a

['Documentation', 'StandardAssets', 'MonoDevelop'].each do |module_name|
  patern = module_files_pattern(module_name)
  pack << module_name if Dir.glob(pattern).count > 0
end

better idea?

Copy link
Member

Choose a reason for hiding this comment

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

I installed 2017.3.0f3 on the first slave with all sub-modules, in case you need to find the paths.

UI.important "Ignoring #{pack} module, it is already installed" if packages.delete(pack)
installed_packages = unity.packages
packages.each do |pack|
if installed_packages.include?(pack) || installed_packages.any? { |installed| !package_aliases[pack].nil? && package_aliases[pack].include?(installed) }
Copy link
Member

Choose a reason for hiding this comment

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

feel free to move this whole logic into a method "package_installed?" or similar.

installed_packages = unity.packages
packages.each do |pack|
if installed_packages.include?(pack) || installed_packages.any? { |installed| !package_aliases[pack].nil? && package_aliases[pack].include?(installed) }
UI.important "Ignoring #{pack} module, it is already installed" if packages.delete(pack)
Copy link
Member

Choose a reason for hiding this comment

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

Does the if need to go away?

packages.delete(pack)
UI.important "Ignoring #{pack} module, it is already installed"

@niezbop
Copy link
Member Author

niezbop commented Dec 29, 2017

Implemented modifications and the Mac part. Example question is still not solved, should we try to detect it as well?

result
end

def package_installed?(package, installed_packages)
Copy link
Member

Choose a reason for hiding this comment

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

would it be better to move this to unity? I don't think command should have too much logic anyway.

E.g. if unity.package_installed? existed, it would be less code here.

when 'MonoDevelop'
return "#{root_path}/MonoDevelop.app/"
else
return ''
Copy link
Member

Choose a reason for hiding this comment

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

fail here instead of silent return

@niezbop niezbop changed the title [WIP] Correct installed package detection Correct installed package detection Dec 29, 2017
Copy link
Member

@lacostej lacostej left a comment

Choose a reason for hiding this comment

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

Let's also give a good name to this PR. And make it so that it's description explicitly mark the proper issues as closed.

when 'MonoDevelop'
return "#{root_path}/MonoDevelop.app/"
else
UI.user_error! "No pattern is known for #{module_name} on Mac"
Copy link
Member

Choose a reason for hiding this comment

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

maybe crash! instead?

@@ -95,5 +95,6 @@ def fake_installation(version, packages: [])
allow(unity).to receive(:version) { version }
allow(unity).to receive(:root_path) { 'foo' }
allow(unity).to receive(:packages) { packages }
unity.stub(:package_installed?) { |arg| packages.include?(arg) }
Copy link
Member

Choose a reason for hiding this comment

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

PlaybackEngineUtils.list_module_configs(root_path).each do |mpath|
pack << PlaybackEngineUtils.module_name(mpath)
end
%w[Documentation StandardAssets MonoDevelop].each do |module_name|
Copy link
Member

Choose a reason for hiding this comment

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

Let's move that to a module or Installation class constant. Maybe something like SPECIAL_PACKAGES? Better name idea?

end

def package_installed?(package)
return false unless packages
Copy link
Member

Choose a reason for hiding this comment

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

we can replace the two lines with

return true if (packages || []).include?(package)

and maybe change the default packages implementation to return a [] instead of false?

return true if packages.include?(package)

aliases = Installation.package_aliases[package]
return false if aliases[package].nil?
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 think aliases[package] can get nil. You meant empty right?

In which case, we may just skip the line entirely as it is covered by the next one?

Copy link
Member Author

@niezbop niezbop Dec 31, 2017

Choose a reason for hiding this comment

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

I believe it can when the package is not known ie aliases['NewPackage'] = nil. It makes it so that we don't crash when some package is not known, which would make u3d unusable for versions with unknown packages. So this line is mandatory imo.

@niezbop niezbop changed the title Correct installed package detection Match available package name with installed name Dec 31, 2017
@lacostej lacostej changed the title Match available package name with installed name u3d/install: do not reinstall already installed packages Dec 31, 2017
@@ -44,6 +46,37 @@ def self.create(root_path: nil, path: nil)
WindowsInstallation.new(root_path: root_path, path: path)
end
end

def self.package_aliases
Copy link
Member

Choose a reason for hiding this comment

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

This could be cached as well into a PACKAGE_ALIASES and documented.

@lacostej
Copy link
Member

We should add some tests to the Installation classes changes at least. I am sure things will break when we have different Unity versions.

@niezbop niezbop merged commit 96eaeb3 into DragonBox:master Jan 2, 2018
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.

2 participants