Skip to content

Commit 0ef9f10

Browse files
committed
Fix path generation on windows by using Pathname
1 parent 6f7ea9e commit 0ef9f10

13 files changed

+141
-119
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1919
- External libraries aren't forcibly installed via the Arduino binary (in `arduino_cmd_remote.rb`) if they appear to exist on disk already
2020
- `attachInterrupt` and `detachInterrupt` are now mocked instead of `_NOP`
2121
- Unit test binaries now run with debugging symbols and address sanitization (if available), to help isolate the causes of segfaults
22+
- `ArduinoCommand::libdir` logic is now centralized, using `sketchbook.path` from prefs instead of hard-coding
2223

2324
### Deprecated
2425

@@ -31,6 +32,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3132
- CPP file aggregation now ignores dotfiles
3233
- Unit test `compilers` section of YAML configuration is now properly inherited from parent configuration files
3334
- Retrieving preferences is now properly cached
35+
- Paths on Windows should now work due to the use of `Pathname`
3436

3537
### Security
3638

exe/arduino_ci_remote.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env ruby
22
require 'arduino_ci'
33
require 'set'
4+
require 'pathname'
45

56
WIDTH = 80
67

@@ -72,7 +73,9 @@ def assured_platform(purpose, name, config)
7273
@arduino_cmd = ArduinoCI::ArduinoInstallation.autolocate!
7374

7475
# initialize library under test
75-
installed_library_path = assure("Installing library under test") { @arduino_cmd.install_local_library(".") }
76+
installed_library_path = attempt("Installing library under test") do
77+
@arduino_cmd.install_local_library(Pathname.new("."))
78+
end
7679
library_examples = @arduino_cmd.library_examples(installed_library_path)
7780
cpp_library = ArduinoCI::CppLibrary.new(installed_library_path, @arduino_cmd.lib_dir)
7881
attempt("Library installed at #{installed_library_path}") { true }
@@ -129,7 +132,7 @@ def assured_platform(purpose, name, config)
129132

130133
# iterate boards / tests
131134
last_board = nil
132-
if !File.exist?(cpp_library.tests_dir)
135+
if !cpp_library.tests_dir.exist?
133136
attempt("Skipping unit tests; no tests dir at #{cpp_library.tests_dir}") { true }
134137
elsif cpp_library.test_files.empty?
135138
attempt("Skipping unit tests; no test files were found in #{cpp_library.tests_dir}") { true }
@@ -141,7 +144,7 @@ def assured_platform(purpose, name, config)
141144
assure("Switching to board for #{p} (#{board})") { @arduino_cmd.use_board(board) } unless last_board == board
142145
last_board = board
143146
cpp_library.test_files.each do |unittest_path|
144-
unittest_name = File.basename(unittest_path)
147+
unittest_name = unittest_path.basename.to_s
145148
compilers.each do |gcc_binary|
146149
attempt_multiline("Unit testing #{unittest_name} with #{gcc_binary}") do
147150
exe = cpp_library.build_for_test_with_configuration(

lib/arduino_ci/arduino_cmd.rb

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'fileutils'
2+
require 'pathname'
23

34
module ArduinoCI
45

@@ -67,7 +68,7 @@ def parse_pref_string(arduino_output)
6768

6869
# @return [String] the path to the Arduino libraries directory
6970
def lib_dir
70-
"<lib_dir not defined>"
71+
Pathname.new(get_pref("sketchbook.path")) + "libraries"
7172
end
7273

7374
# fetch preferences in their raw form
@@ -192,9 +193,9 @@ def install_library(library_name)
192193

193194
# generate the (very likely) path of a library given its name
194195
# @param library_name [String] The name of the library
195-
# @return [String] The fully qualified library name
196+
# @return [Pathname] The fully qualified library name
196197
def library_path(library_name)
197-
File.join(lib_dir, library_name)
198+
Pathname.new(lib_dir) + library_name
198199
end
199200

200201
# Determine whether a library is present in the lib dir
@@ -205,7 +206,7 @@ def library_path(library_name)
205206
# @param library_name [String] The name of the library
206207
# @return [bool]
207208
def library_present?(library_name)
208-
File.exist?(library_path(library_name))
209+
library_path(library_name).exist?
209210
end
210211

211212
# update the library index
@@ -254,24 +255,24 @@ def verify_sketch(path)
254255

255256
# ensure that the given library is installed, or symlinked as appropriate
256257
# return the path of the prepared library, or nil
257-
# @param path [String] library to use
258+
# @param path [Pathname] library to use
258259
# @return [String] the path of the installed library
259260
def install_local_library(path)
260-
realpath = File.expand_path(path)
261-
library_name = File.basename(realpath)
261+
src_path = path.realpath
262+
library_name = src_path.basename
262263
destination_path = library_path(library_name)
263264

264265
# things get weird if the sketchbook contains the library.
265266
# check that first
266-
if File.exist? destination_path
267+
if destination_path.exist?
267268
uhoh = "There is already a library '#{library_name}' in the library directory"
268-
return destination_path if destination_path == realpath
269+
return destination_path if destination_path == src_path
269270

270271
# maybe it's a symlink? that would be OK
271-
if File.symlink?(destination_path)
272-
return destination_path if File.readlink(destination_path) == realpath
272+
if destination_path.symlink?
273+
return destination_path if destination_path.readlink == src_path
273274

274-
@last_msg = "#{uhoh} and it's not symlinked to #{realpath}"
275+
@last_msg = "#{uhoh} and it's not symlinked to #{src_path}"
275276
return nil
276277
end
277278

@@ -280,20 +281,20 @@ def install_local_library(path)
280281
end
281282

282283
# install the library
283-
Host.symlink(realpath, destination_path)
284+
Host.symlink(src_path, destination_path)
284285
destination_path
285286
end
286287

287288
# @param installed_library_path [String] The library to query
288289
# @return [Array<String>] Example sketch files
289290
def library_examples(installed_library_path)
290-
example_path = File.join(installed_library_path, "examples")
291+
example_path = Pathname.new(installed_library_path) + "examples"
291292
return [] unless File.exist?(example_path)
292293

293-
examples = Pathname.new(example_path).children.select(&:directory?).map(&:to_path).map(&File.method(:basename))
294+
examples = example_path.children.select(&:directory?).map(&:to_path).map(&File.method(:basename))
294295
files = examples.map do |e|
295-
proj_file = File.join(example_path, e, "#{e}.ino")
296-
File.exist?(proj_file) ? proj_file : nil
296+
proj_file = example_path + e + "#{e}.ino"
297+
proj_file.exist? ? proj_file.to_s : nil
297298
end
298299
files.reject(&:nil?)
299300
end

lib/arduino_ci/arduino_cmd_linux.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ def _prefs_raw
3232
resp[:out]
3333
end
3434

35-
# implementation for Arduino library dir location
36-
# @return [String] the path to the Arduino libraries directory
37-
def lib_dir
38-
File.join(get_pref("sketchbook.path"), "libraries")
39-
end
40-
4135
def run_with_gui_guess(message, *args, **kwargs)
4236
# On Travis CI, we get an error message in the GUI instead of on STDERR
4337
# so, assume that if we don't get a rapid reply that things are not installed

lib/arduino_ci/arduino_cmd_linux_builder.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ class ArduinoCmdLinuxBuilder < ArduinoCmd
1414
flag :install_library, "--install-library" # apparently doesn't exist
1515
flag :verify, "-compile"
1616

17-
# linux-specific implementation
18-
# @return [String] The path to the library dir
19-
def lib_dir
20-
File.join(get_pref("sketchbook.path"), "libraries")
21-
end
22-
2317
end
2418

2519
end

lib/arduino_ci/arduino_cmd_osx.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ class ArduinoCmdOSX < ArduinoCmd
1212
flag :install_boards, "--install-boards"
1313
flag :install_library, "--install-library"
1414
flag :verify, "--verify"
15-
16-
def lib_dir
17-
File.join(ENV['HOME'], "Documents", "Arduino", "libraries")
18-
end
19-
2015
end
2116

2217
end

lib/arduino_ci/arduino_cmd_windows.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ class ArduinoCmdWindows < ArduinoCmd
1212
flag :install_boards, "--install-boards"
1313
flag :install_library, "--install-library"
1414
flag :verify, "--verify"
15-
16-
def lib_dir
17-
File.join(ENV['userprofile'], "Documents", "Arduino", "libraries")
18-
end
19-
2015
end
2116

2217
end

0 commit comments

Comments
 (0)