Skip to content

Commit afce5ef

Browse files
committed
Clean up ruby style
1 parent e76c402 commit afce5ef

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lib/arduino_ci/cpp_library.rb

+13-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'pathname'
44
require 'shellwords'
55
require 'os'
6+
require 'fileutils'
67

78
HPP_EXTENSIONS = [".hpp", ".hh", ".h", ".hxx", ".h++"].freeze
89
CPP_EXTENSIONS = [".cpp", ".cc", ".c", ".cxx", ".c++"].freeze
@@ -512,6 +513,15 @@ def build_for_test(test_file, gcc_binary)
512513
executable
513514
end
514515

516+
# Add build dir to path
517+
def add_build_dirs_to_env
518+
ENV["LD_LIBRARY_PATH"] = BUILD_DIR unless OS.windows?
519+
paths = ENV["PATH"].split(File::PATH_SEPARATOR)
520+
return if paths.include?(BUILD_DIR)
521+
522+
ENV["PATH"] = BUILD_DIR + File::PATH_SEPARATOR + ENV["PATH"] if OS.windows?
523+
end
524+
515525
# build a shared library to be used by each test
516526
#
517527
# The dependent libraries configuration is appended with data from library.properties internal to the library under test
@@ -521,15 +531,9 @@ def build_for_test(test_file, gcc_binary)
521531
# @param ci_gcc_config [Hash] The GCC config object
522532
# @return [Pathname] path to the compiled test executable
523533
def build_shared_library(aux_libraries, gcc_binary, ci_gcc_config)
524-
Dir.mkdir BUILD_DIR unless File.exist?(BUILD_DIR)
525-
if OS.windows?
526-
flag = ENV["PATH"].include? ";"
527-
ENV["PATH"] = BUILD_DIR + (flag ? ";" : ":") + ENV["PATH"] unless ENV["PATH"].include? BUILD_DIR
528-
suffix = "dll"
529-
else
530-
ENV["LD_LIBRARY_PATH"] = BUILD_DIR
531-
suffix = "so"
532-
end
534+
FileUtils.mkdir_p(BUILD_DIR)
535+
add_build_dirs_to_env
536+
suffix = OS.windows? ? "dll" : "so"
533537
full_lib_name = "#{BUILD_DIR}/lib#{LIBRARY_NAME}.#{suffix}"
534538
executable = Pathname.new(full_lib_name).expand_path
535539
File.delete(executable) if File.exist?(executable)

0 commit comments

Comments
 (0)