diff --git a/CHANGELOG.md b/CHANGELOG.md index fa5ff943..f161e1b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Referring to an undefined platform no longer causes a crash; it's now a helpful error message - A copy/paste error that prevented compiler warning flags from being supplied has been fixed, via jgfoster - RSpec was not communicating compile errors from unit test executables that failed to build. Now it does, via jgfoster +- Windows paths now avoid picking up backslashes, for proper equality comparisons ### Security diff --git a/lib/arduino_ci/arduino_backend.rb b/lib/arduino_ci/arduino_backend.rb index 4e04f5b3..cb3e4238 100644 --- a/lib/arduino_ci/arduino_backend.rb +++ b/lib/arduino_ci/arduino_backend.rb @@ -90,7 +90,9 @@ def config_dump # @return [String] the path to the Arduino libraries directory def lib_dir - Pathname.new(config_dump["directories"]["user"]) + "libraries" + user_dir_raw = config_dump["directories"]["user"] + user_dir = OS.windows? ? Host.windows_to_pathname(user_dir_raw) : user_dir_raw + Pathname.new(user_dir) + "libraries" end # Board manager URLs diff --git a/lib/arduino_ci/arduino_downloader.rb b/lib/arduino_ci/arduino_downloader.rb index 2acdf30c..c3081f7d 100644 --- a/lib/arduino_ci/arduino_downloader.rb +++ b/lib/arduino_ci/arduino_downloader.rb @@ -43,7 +43,7 @@ def self.autolocated_executable # The executable Arduino file in an existing installation, or nil # @return [Pathname] def self.existing_executable - self.must_implement(__method__) + Host.which("arduino-cli") end # The local file (dir) name of the desired IDE package (zip/tar/etc) diff --git a/lib/arduino_ci/arduino_downloader_linux.rb b/lib/arduino_ci/arduino_downloader_linux.rb index 487273d1..8eb787eb 100644 --- a/lib/arduino_ci/arduino_downloader_linux.rb +++ b/lib/arduino_ci/arduino_downloader_linux.rb @@ -17,12 +17,6 @@ def self.extracted_file "arduino-cli" end - # The executable Arduino file in an existing installation, or nil - # @return [string] - def self.existing_executable - Host.which("arduino-cli") - end - # Make any preparations or run any checks prior to making changes # @return [string] Error message, or nil if success def prepare diff --git a/lib/arduino_ci/arduino_downloader_osx.rb b/lib/arduino_ci/arduino_downloader_osx.rb index 89890599..9e77505b 100644 --- a/lib/arduino_ci/arduino_downloader_osx.rb +++ b/lib/arduino_ci/arduino_downloader_osx.rb @@ -17,12 +17,6 @@ def self.extracted_file "arduino-cli" end - # The executable Arduino file in an existing installation, or nil - # @return [string] - def self.existing_executable - Host.which("arduino-cli") - end - # Make any preparations or run any checks prior to making changes # @return [string] Error message, or nil if success def prepare diff --git a/lib/arduino_ci/arduino_downloader_windows.rb b/lib/arduino_ci/arduino_downloader_windows.rb index 9b7d1862..ffb952a2 100644 --- a/lib/arduino_ci/arduino_downloader_windows.rb +++ b/lib/arduino_ci/arduino_downloader_windows.rb @@ -28,12 +28,6 @@ def package_file "arduino-cli_#{@desired_version}_Windows_64bit.zip" end - # The executable Arduino file in an existing installation, or nil - # @return [string] - def self.existing_executable - Host.which("arduino-cli") - end - # The technology that will be used to extract the download # (for logging purposes) # @return [string] @@ -57,5 +51,11 @@ def self.extracted_file "arduino-cli.exe" end + # The executable Arduino file in a forced installation, or nil + # @return [Pathname] + def self.force_installed_executable + Pathname.new(Host.windows_to_pathname(ENV['HOME'])) + self.extracted_file + end + end end diff --git a/lib/arduino_ci/host.rb b/lib/arduino_ci/host.rb index dc8e2911..4cd5e243 100644 --- a/lib/arduino_ci/host.rb +++ b/lib/arduino_ci/host.rb @@ -17,13 +17,14 @@ class Host # via https://stackoverflow.com/a/5471032/2063546 # which('ruby') #=> /usr/bin/ruby # @param cmd [String] the command to search for - # @return [String] the full path to the command if it exists + # @return [Pathname] the full path to the command if it exists def self.which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] - ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| + ENV['PATH'].split(File::PATH_SEPARATOR).each do |string_path| + path = OS.windows? ? windows_to_pathname(string_path) : Pathname.new(string_path) exts.each do |ext| - exe = File.join(path, "#{cmd}#{ext}") - return exe if File.executable?(exe) && !File.directory?(exe) + exe = path.join("#{cmd}#{ext}") + return exe if exe.executable? && !exe.directory? end end nil diff --git a/spec/arduino_downloader_spec.rb b/spec/arduino_downloader_spec.rb index 9158b439..6fda6366 100644 --- a/spec/arduino_downloader_spec.rb +++ b/spec/arduino_downloader_spec.rb @@ -7,7 +7,6 @@ it "has correct class properties" do ad = ArduinoCI::ArduinoDownloader - expect{ad.existing_executable}.to raise_error(NotImplementedError) expect{ad.extracted_file}.to raise_error(NotImplementedError) expect{ad.extracter}.to raise_error(NotImplementedError) expect{ad.extract("foo")}.to raise_error(NotImplementedError) diff --git a/spec/host_spec.rb b/spec/host_spec.rb index ac40f4e0..f9b94f4b 100644 --- a/spec/host_spec.rb +++ b/spec/host_spec.rb @@ -54,7 +54,7 @@ def with_tmpdir(path) it "can find things with which" do ruby_path = ArduinoCI::Host.which("ruby") expect(ruby_path).not_to be nil - expect(ruby_path.include? "ruby").to be true + expect(ruby_path.to_s.include? "ruby").to be true end end