Skip to content

Commit 836be5c

Browse files
committed
cross-platform symlinking
1 parent a7d715e commit 836be5c

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111
- Windows / Appveyor support, enabled largely by contributions from @tomduff
1212
- `long long` support in `String`
1313
- Representative `.gitignore` files in sample projects
14+
- Cross-platform symlinking
1415

1516
### Changed
1617
- Author

lib/arduino_ci/arduino_cmd.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def install_local_library(path)
274274
end
275275

276276
# install the library
277-
FileUtils.ln_s(realpath, destination_path)
277+
Host.symlink(realpath, destination_path)
278278
destination_path
279279
end
280280

lib/arduino_ci/host.rb

+11
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,16 @@ def self.os
3737
return :windows if OS.windows?
3838
end
3939

40+
# if on windows, call mklink, else self.symlink
41+
# https://stackoverflow.com/a/22716582/2063546
42+
def self.symlink(old_path, new_path)
43+
return FileUtils.ln_s(old_path, new_path) unless RUBY_PLATFORM =~ /mswin32|cygwin|mingw|bccwin/
44+
45+
# windows mklink syntax is reverse of unix ln -s
46+
# windows mklink is built into cmd.exe
47+
# vulnerable to command injection, but okay because this is a hack to make a cli tool work.
48+
_stdin, _stdout, _stderr, wait_thr = Open3.popen3('cmd.exe', "/c mklink #{new_path} #{old_path}")
49+
wait_thr.value.exitstatus
50+
end
4051
end
4152
end

0 commit comments

Comments
 (0)