Skip to content

Commit e980ddd

Browse files
authored
Merge pull request #388 from lacostej/fix/windows_extra_install_path
u3d/install: convert Windows paths to ruby paths when treating U3D_EXTRA_PATHS
2 parents c8be812 + 8700d6a commit e980ddd

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

lib/u3d/installer.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,12 @@ def package_destination(info, unity_root_path)
146146
end
147147
end
148148

149+
# extra installation paths are stored in U3D_EXTRA_PATHS environment variable,
150+
# following a standard PATH variable format.
151+
# Returns an array of ruby style paths
149152
def extra_installation_paths
150153
return [] if ENV['U3D_EXTRA_PATHS'].nil?
151-
ENV['U3D_EXTRA_PATHS'].strip.split(File::PATH_SEPARATOR)
154+
ENV['U3D_EXTRA_PATHS'].strip.split(File::PATH_SEPARATOR).map { |p| File.expand_path p }
152155
end
153156

154157
def find_installations_with_path(default_root_path: '', postfix: [])

spec/u3d/installer_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,30 @@ class DummyInstaller < U3d::BaseInstaller
8888
expect(installer.installed_sorted_by_versions).to eq(sorted_installed)
8989
end
9090
end
91+
92+
describe ".extra_installation_paths" do
93+
describe "converts paths to ruby paths" do
94+
def expect_extra_installation_paths(env_var, expected_paths)
95+
installer = DummyInstaller.new
96+
with_env_values('U3D_EXTRA_PATHS' => env_var) do
97+
expect(installer.send(:extra_installation_paths)).to eql(expected_paths)
98+
end
99+
end
100+
it "works on Windows", if: WINDOWS do
101+
expect_extra_installation_paths(
102+
"C:\\Program Files\\Unity;D:\\",
103+
["C:/Program Files/Unity", "D:/"]
104+
)
105+
end
106+
107+
it "works on Unix", unless: WINDOWS do
108+
expect_extra_installation_paths(
109+
"/Applications/here:/Applications/else",
110+
["/Applications/here", "/Applications/else"]
111+
)
112+
end
113+
end
114+
end
91115
end
92116

93117
describe U3d::MacInstaller, unless: WINDOWS do

spec/u3d_core/helper_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## --- BEGIN LICENSE BLOCK ---
2+
# Copyright (c) 2019-present WeWantToKnow AS
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy
5+
# of this software and associated documentation files (the "Software"), to deal
6+
# in the Software without restriction, including without limitation the rights
7+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
# copies of the Software, and to permit persons to whom the Software is
9+
# furnished to do so, subject to the following conditions:
10+
#
11+
# The above copyright notice and this permission notice shall be included in all
12+
# copies or substantial portions of the Software.
13+
#
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
# SOFTWARE.
21+
## --- END LICENSE BLOCK ---
22+
23+
require 'u3d/utils'
24+
25+
describe U3dCore do
26+
describe U3d::Helper do
27+
describe '.windows_path' do
28+
it 'converts paths' do
29+
expect(U3dCore::Helper.windows_path('/path/to/file')).to eql "\\path\\to\\file"
30+
end
31+
end
32+
end
33+
end

0 commit comments

Comments
 (0)