9
9
CI_CPP_DIR = Pathname . new ( __dir__ ) . parent . parent + "cpp"
10
10
ARDUINO_HEADER_DIR = CI_CPP_DIR + "arduino"
11
11
UNITTEST_HEADER_DIR = CI_CPP_DIR + "unittest"
12
+ LIBRARY_NAME = "arduino"
13
+ BUILD_DIR = "#{ Dir . pwd } /.arduino_ci" # hide build artifacts
14
+
12
15
13
16
module ArduinoCI
14
17
@@ -485,31 +488,53 @@ def test_args(aux_libraries, ci_gcc_config)
485
488
#
486
489
# The dependent libraries configuration is appended with data from library.properties internal to the library under test
487
490
#
488
- # @param test_file [Pathname] The path to the file containing the unit tests (nil to compile application as shared library)
491
+ # @param test_file [Pathname] The path to the file containing the unit tests
489
492
# @param aux_libraries [Array<Pathname>] The external Arduino libraries required by this project
490
493
# @param ci_gcc_config [Hash] The GCC config object
491
494
# @return [Pathname] path to the compiled test executable
492
495
def build_for_test_with_configuration ( test_file , aux_libraries , gcc_binary , ci_gcc_config )
493
- build_dir = "#{ Dir . pwd } /.arduino_ci" # hide build artifacts
494
- Dir . mkdir build_dir unless File . exist? ( build_dir )
495
- lib_name = "arduino"
496
+ executable = Pathname . new ( "#{ BUILD_DIR } /#{ test_file . basename } .bin" ) . expand_path
497
+ File . delete ( executable ) if File . exist? ( executable )
498
+ arg_sets = [ "-std=c++0x" , "-o" , executable . to_s , "-L#{ BUILD_DIR } " , "-DARDUINO=100" ]
499
+ if libasan? ( gcc_binary )
500
+ arg_sets << [ # Stuff to help with dynamic memory mishandling
501
+ "-g" , "-O1" ,
502
+ "-fno-omit-frame-pointer" ,
503
+ "-fno-optimize-sibling-calls" ,
504
+ "-fsanitize=address"
505
+ ]
506
+ end
507
+ arg_sets << @test_args
508
+ arg_sets << [ test_file . to_s , "-l#{ LIBRARY_NAME } " ]
509
+ args = arg_sets . flatten ( 1 )
510
+ return nil unless run_gcc ( gcc_binary , *args )
511
+
512
+ artifacts << executable
513
+ executable
514
+ end
515
+
516
+ # build a shared library to be used by each test
517
+ #
518
+ # The dependent libraries configuration is appended with data from library.properties internal to the library under test
519
+ #
520
+ # @param aux_libraries [Array<Pathname>] The external Arduino libraries required by this project
521
+ # @param ci_gcc_config [Hash] The GCC config object
522
+ # @return [Pathname] path to the compiled test executable
523
+ def build_share_library_with_configuration ( aux_libraries , gcc_binary , ci_gcc_config )
524
+ Dir . mkdir BUILD_DIR unless File . exist? ( BUILD_DIR )
496
525
if OS . windows?
497
- full_lib_name = "#{ build_dir } /lib#{ lib_name } .dll"
498
526
flag = ENV [ "PATH" ] . include? ";"
499
- ENV [ "PATH" ] = build_dir + ( flag ? ";" : ":" ) + ENV [ "PATH" ] unless ENV [ "PATH" ] . include? build_dir
527
+ ENV [ "PATH" ] = BUILD_DIR + ( flag ? ";" : ":" ) + ENV [ "PATH" ] unless ENV [ "PATH" ] . include? build_dir
528
+ suffix = "dll"
500
529
else
501
- full_lib_name = "#{ build_dir } /lib#{ lib_name } .so"
502
- ENV [ "LD_LIBRARY_PATH" ] = build_dir
503
- end
504
- arg_sets = [ "-std=c++0x" ]
505
- if test_file . nil?
506
- executable = Pathname . new ( full_lib_name ) . expand_path
507
- arg_sets << [ "-shared" , "-fPIC" , "-Wl,-undefined,dynamic_lookup" ]
508
- else
509
- executable = Pathname . new ( "#{ build_dir } /unittest_#{ test_file . basename } .bin" ) . expand_path
530
+ ENV [ "LD_LIBRARY_PATH" ] = BUILD_DIR
531
+ suffix = "so"
510
532
end
533
+ full_lib_name = "#{ BUILD_DIR } /lib#{ LIBRARY_NAME } .#{ suffix } "
534
+ executable = Pathname . new ( full_lib_name ) . expand_path
511
535
File . delete ( executable ) if File . exist? ( executable )
512
- arg_sets << [ "-o" , executable . to_s , "-L#{ build_dir } " , "-DARDUINO=100" ]
536
+ arg_sets = [ "-std=c++0x" , "-shared" , "-fPIC" , "-Wl,-undefined,dynamic_lookup" ,
537
+ "-o" , executable . to_s , "-L#{ BUILD_DIR } " , "-DARDUINO=100" ]
513
538
if libasan? ( gcc_binary )
514
539
arg_sets << [ # Stuff to help with dynamic memory mishandling
515
540
"-g" , "-O1" ,
@@ -522,19 +547,14 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g
522
547
# combine library.properties defs (if existing) with config file.
523
548
# TODO: as much as I'd like to rely only on the properties file(s), I think that would prevent testing 1.0-spec libs
524
549
# the following two take some time, so are cached when we build the shared library
525
- @full_dependencies ||= all_arduino_library_dependencies! ( aux_libraries )
526
- @test_args ||= test_args ( @full_dependencies , ci_gcc_config )
527
- arg_sets << @test_args # used cached value since building full set of include directories can take time
528
-
529
- if File . exist? ( full_lib_name ) # add the test file and the shared library
530
- arg_sets << [ test_file . to_s , "-l#{ lib_name } " ] if test_file
531
- else # CPP files for the shared library
532
- arg_sets << cpp_files_arduino . map ( &:to_s ) # Arduino.cpp, Godmode.cpp, and stdlib.cpp
533
- arg_sets << cpp_files_unittest . map ( &:to_s ) # ArduinoUnitTests.cpp
534
- arg_sets << cpp_files . map ( &:to_s ) # CPP files for the primary application library under test
535
- arg_sets << cpp_files_libraries ( @full_dependencies ) . map ( &:to_s ) # CPP files for all the libraries we depend on
536
- arg_sets << [ test_file . to_s ] if test_file
537
- end
550
+ @full_dependencies = all_arduino_library_dependencies! ( aux_libraries )
551
+ @test_args = test_args ( @full_dependencies , ci_gcc_config ) # build full set of include directories to be cached for later
552
+
553
+ arg_sets << @test_args
554
+ arg_sets << cpp_files_arduino . map ( &:to_s ) # Arduino.cpp, Godmode.cpp, and stdlib.cpp
555
+ arg_sets << cpp_files_unittest . map ( &:to_s ) # ArduinoUnitTests.cpp
556
+ arg_sets << cpp_files . map ( &:to_s ) # CPP files for the primary application library under test
557
+ arg_sets << cpp_files_libraries ( @full_dependencies ) . map ( &:to_s ) # CPP files for all the libraries we depend on
538
558
args = arg_sets . flatten ( 1 )
539
559
return nil unless run_gcc ( gcc_binary , *args )
540
560
0 commit comments