3
3
require 'pathname'
4
4
require 'shellwords'
5
5
require 'os'
6
+ require 'fileutils'
6
7
7
8
HPP_EXTENSIONS = [ ".hpp" , ".hh" , ".h" , ".hxx" , ".h++" ] . freeze
8
9
CPP_EXTENSIONS = [ ".cpp" , ".cc" , ".c" , ".cxx" , ".c++" ] . freeze
@@ -512,6 +513,15 @@ def build_for_test(test_file, gcc_binary)
512
513
executable
513
514
end
514
515
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
+
515
525
# build a shared library to be used by each test
516
526
#
517
527
# 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)
521
531
# @param ci_gcc_config [Hash] The GCC config object
522
532
# @return [Pathname] path to the compiled test executable
523
533
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"
533
537
full_lib_name = "#{ BUILD_DIR } /lib#{ LIBRARY_NAME } .#{ suffix } "
534
538
executable = Pathname . new ( full_lib_name ) . expand_path
535
539
File . delete ( executable ) if File . exist? ( executable )
0 commit comments