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/installer: support custom install paths through U3D_EXTRA_PATHS #373

56 changes: 45 additions & 11 deletions lib/u3d/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ def installed_sorted_by_versions
return [] if list.empty?
list.sort { |a, b| UnityVersionComparator.new(a.version) <=> UnityVersionComparator.new(b.version) }
end

protected

def extra_installation_paths
return [] if ENV['U3D_EXTRA_PATHS'].nil?
ENV['U3D_EXTRA_PATHS'].strip.split(File::PATH_SEPARATOR)
end

def find_installations_with_path(default_root_path: '', postfix: [])
([default_root_path] | extra_installation_paths).map do |path|
UI.verbose "Looking for installed Unity version under #{path}"
pattern = File.join([path] + postfix)
Dir.glob(pattern).map { |found_path| yield found_path }
end.flatten
end
end

# deprecated
Expand Down Expand Up @@ -169,9 +184,14 @@ def uninstall(unity: nil)
private

def list_installed_paths
find = File.join(DEFAULT_MAC_INSTALL, 'Applications', 'Unity*', 'Unity.app')
paths = Dir[find]
paths = paths.map { |u| Pathname.new(u).parent.to_s }
paths = find_installations_with_path(
default_root_path: DEFAULT_MAC_INSTALL,
postfix: %w[
Applications
Unity*
Unity.app
]
) { |u| Pathname.new(u).parent.to_s }
UI.verbose "Found list_installed_paths: #{paths}"
paths
end
Expand Down Expand Up @@ -332,17 +352,25 @@ def pkg_install_path(unity_root_path, pinfo_path)
end

def list_installed_paths
find = File.join(DEFAULT_LINUX_INSTALL, 'unity-editor-*', 'Editor')
paths = Dir[find]
paths = paths.map { |u| Pathname.new(u).parent.to_s }
paths = find_installations_with_path(
default_root_path: DEFAULT_LINUX_INSTALL,
postfix: %w[
unity-editor-*
Editor
]
) { |u| Pathname.new(u).parent.to_s }
UI.verbose "Found list_installed_paths: #{paths}"
paths
end

def debian_installed_paths
find = File.join(DEFAULT_LINUX_INSTALL, 'Unity', 'Editor')
paths = Dir[find]
paths = paths.map { |u| Pathname.new(u).parent.to_s }
paths = find_installations_with_path(
default_root_path: DEFAULT_LINUX_INSTALL,
postfix: %w[
Unity
Editor
]
) { |u| Pathname.new(u).parent.to_s }
UI.verbose "Found debian_installed_paths: #{paths}"
paths
end
Expand All @@ -362,8 +390,14 @@ def sanitize_install(unity, long: false, dry_run: false)
end

def installed
find = File.join(DEFAULT_WINDOWS_INSTALL, 'Unity*', 'Editor', 'Uninstall.exe')
Dir[find].map { |path| WindowsInstallation.new(root_path: File.expand_path('../..', path)) }
find_installations_with_path(
default_root_path: DEFAULT_WINDOWS_INSTALL,
postfix: %w[
Unity*
Editor
Uninstall.exe
]
) { |path| WindowsInstallation.new(root_path: File.expand_path('../..', path)) }
end

def install(file_path, version, installation_path: nil, info: {})
Expand Down
4 changes: 2 additions & 2 deletions spec/u3d/installer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ class DummyInstaller < U3d::BaseInstaller
u1 = linux_5_6_standard
u2 = linux_5_6_debian
u3 = linux_2017_1_weird
allow(Dir).to receive(:[]).with('/opt/unity-editor-*/Editor') { ["#{u1.root_path}/Editor", "#{u3.root_path}/Editor"] }
allow(Dir).to receive(:[]).with('/opt/Unity/Editor') { ["#{u2.root_path}/Editor"] }
allow(Dir).to receive(:glob).with('/opt/unity-editor-*/Editor') { ["#{u1.root_path}/Editor", "#{u3.root_path}/Editor"] }
allow(Dir).to receive(:glob).with('/opt/Unity/Editor') { ["#{u2.root_path}/Editor"] }

allow(U3d::LinuxInstallation).to receive(:new).with(root_path: u1.root_path) { u1 }
allow(U3d::LinuxInstallation).to receive(:new).with(root_path: u2.root_path) { u2 }
Expand Down