33require 'pathname'
44require 'shellwords'
55require 'os'
6+ require 'fileutils'
67
78HPP_EXTENSIONS = [ ".hpp" , ".hh" , ".h" , ".hxx" , ".h++" ] . freeze
89CPP_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