Skip to content
Merged
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ You can get further information on how to use U3d by running `u3d --help` (or `u

## How-tos

### Install in a custom location

`u3d install` accepts an argument `--installation_path` which can install unity and its additional components to the location you want.

However, there is a pitfall to that: you need to tell u3d where to look for the versions you installed in custom location. Doing so is quite easy, you just have to set the `U3D_EXTRA_PATHS`, to a list of paths that you want u3d to look for versions.

_NOTE:_ The list of paths `U3D_EXTRA_PATHS` is formatted as your standard `PATH`, ie `U3D_EXTRA_PATHS=/path/to/something:/another/path` on Unix systems, and `U3D_EXTRA_PATHS=C:\Path\To\Something;E:\Another\Path` on Windows.

### Run several Unity instances in parallel

The only thing you have to watch for while trying to run multiple instances of Unity in parallel is the fact that they will share the same log file by default (the `Editor.log`). Therefore you will have to specify it using the [command line arguments](https://docs.unity3d.com/Manual/CommandLineArguments.html), you can do so with u3d the following way from each of your project root folder:
Expand Down
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
19 changes: 19 additions & 0 deletions spec/support/installations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ def macinstall_5_6_default
return unity
end

def macinstall_5_6_custom_location
unity = double("MacInstallation")
# allow(unity).to receive(:path) { '/Applications/Unity/Unity.app' }
allow(unity).to receive(:version) { '5.6.0f1' }
allow(unity).to receive(:build_number) { 'bf5cca3e2788' }
allow(unity).to receive(:clean_install?) { false }
allow(unity).to receive(:root_path) { '/tmp/Applications/Unity' }
return unity
end

def macinstall_5_6_custom_with_space
unity = double("MacInstallation")
# allow(unity).to receive(:path) { '/Applications/Unity 5.6.0f1/Unity.app' }
Expand Down Expand Up @@ -89,6 +99,15 @@ def windows_2017_1_64bits_renamed
return unity
end

def windows_2017_1_64bits_custom_location
unity = double("WindowsInstallation")
# allow(unity).to receive(:path) { 'C:/Program Files/Unity_2017.1.0f3' }
allow(unity).to receive(:version) { '2017.1.0f3' }
allow(unity).to receive(:build_number) { '472613c02cf7' }
allow(unity).to receive(:root_path) { 'E:/Program Files/Unity_2017.1.0f3' }
return unity
end

def fake_linux(version)
unity = double("LinuxInstallation")
allow(unity).to receive(:version) { version }
Expand Down
57 changes: 55 additions & 2 deletions spec/u3d/installer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,59 @@ class DummyInstaller < U3d::BaseInstaller
end

describe U3d::MacInstaller, unless: WINDOWS do
describe '.list' do
it 'finds installs in default locations' do
unity = macinstall_5_6_default
installer = U3d::MacInstaller.new

allow(Dir).to receive(:glob).with('/Applications/Unity*/Unity.app') { ["#{unity.root_path}/Unity.app"] }
allow(U3d::MacInstallation).to receive(:new).with(root_path: unity.root_path) { unity }
allow(installer).to receive(:spotlight_installed_paths) { [] }

expect(installer.installed).to eql [unity]
end

it 'does not find installs in custom locations without U3D_EXTRA_PATHS' do
unity = macinstall_5_6_custom_location
installer = U3d::MacInstaller.new

allow(Dir).to receive(:glob).with('/Applications/Unity*/Unity.app') { [] }
allow(Dir).to receive(:glob).with('/tmp/Applications/Unity*/Unity.app') { ["#{unity.root_path}/Unity.app"] }
allow(U3d::MacInstallation).to receive(:new).with(root_path: unity.root_path) { unity }
allow(installer).to receive(:spotlight_installed_paths) { [] }

expect(installer.installed).to eql []
end

it 'finds installs in custom locations with U3D_EXTRA_PATHS' do
unity = macinstall_5_6_custom_location
installer = U3d::MacInstaller.new

allow(ENV).to receive(:[]).with('U3D_EXTRA_PATHS') { '/tmp' }
allow(Dir).to receive(:glob).with('/Applications/Unity*/Unity.app') { [] }
allow(Dir).to receive(:glob).with('/tmp/Applications/Unity*/Unity.app') { ["#{unity.root_path}/Unity.app"] }
allow(U3d::MacInstallation).to receive(:new).with(root_path: unity.root_path) { unity }
allow(installer).to receive(:spotlight_installed_paths) { [] }

expect(installer.installed).to eql [unity]
end

it 'finds both custom and default installs' do
unity_default = macinstall_5_6_default
unity_custom = macinstall_5_6_custom_location
installer = U3d::MacInstaller.new

allow(ENV).to receive(:[]).with('U3D_EXTRA_PATHS') { '/tmp' }
allow(Dir).to receive(:glob).with('/Applications/Unity*/Unity.app') { ["#{unity_default.root_path}/Unity.app"] }
allow(Dir).to receive(:glob).with('/tmp/Applications/Unity*/Unity.app') { ["#{unity_custom.root_path}/Unity.app"] }
allow(U3d::MacInstallation).to receive(:new).with(root_path: unity_default.root_path) { unity_default }
allow(U3d::MacInstallation).to receive(:new).with(root_path: unity_custom.root_path) { unity_custom }
allow(installer).to receive(:spotlight_installed_paths) { [] }

expect(installer.installed).to eql [unity_default, unity_custom]
end
end

context 'when using a default install' do
let(:unity) { macinstall_5_6_default }
it 'sanitizes install' do
Expand Down Expand Up @@ -180,8 +233,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