From 4667db94582ecb63afe1f1f61661352e3627f723 Mon Sep 17 00:00:00 2001 From: James Foster Date: Wed, 24 Mar 2021 00:17:07 -0700 Subject: [PATCH 01/54] Speed up tests by building a shared library with everything but the tests and reusing it for each test. --- .gitignore | 2 ++ exe/arduino_ci.rb | 24 ++++++++++++++--- lib/arduino_ci/cpp_library.rb | 51 +++++++++++++++++++++++++---------- 3 files changed, 60 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 2b5aa6a7..ea2d3da0 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ vendor # C++ stuff *.bin *.bin.dSYM +*.so +*.so.dSYM diff --git a/exe/arduino_ci.rb b/exe/arduino_ci.rb index 01234e7c..9e5c2be5 100755 --- a/exe/arduino_ci.rb +++ b/exe/arduino_ci.rb @@ -416,9 +416,27 @@ def perform_unit_tests(cpp_library, file_config) platforms.each do |p| puts - config.allowable_unittest_files(cpp_library.test_files).each do |unittest_path| - unittest_name = unittest_path.basename.to_s - compilers.each do |gcc_binary| + compilers.each do |gcc_binary| + # before compiling the tests, build a shared library of everything except the test code + attempt_multiline("Build shared library with #{gcc_binary} for #{p}") do + exe = cpp_library.build_for_test_with_configuration( + nil, # nil is a flag that we are building the shared library with everything else + config.aux_libraries_for_unittest, + gcc_binary, + config.gcc_config(p) + ) + puts + unless exe + puts "Last command: #{cpp_library.last_cmd}" + puts cpp_library.last_out + puts cpp_library.last_err + next false + end + true + end + # now build and run each test using the shared library build above + config.allowable_unittest_files(cpp_library.test_files).each do |unittest_path| + unittest_name = unittest_path.basename.to_s attempt_multiline("Unit testing #{unittest_name} with #{gcc_binary} for #{p}") do exe = cpp_library.build_for_test_with_configuration( unittest_path, diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 4ad7307f..e40ab2e8 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -41,6 +41,12 @@ class CppLibrary # @return [Array] Directories suspected of being vendor-bundle attr_reader :vendor_bundle_cache + # @return [Array] Libraries we are dependent on + @@full_dependencies + + # @return [Array] Compiler arguments, including include directories, but not .cpp files + @@test_args + # @param friendly_name [String] The "official" name of the library, which can contain spaces # @param backend [ArduinoBackend] The support backend def initialize(friendly_name, backend) @@ -471,9 +477,9 @@ def flag_args(ci_gcc_config) def test_args(aux_libraries, ci_gcc_config) # TODO: something with libraries? ret = include_args(aux_libraries) - ret += cpp_files_arduino.map(&:to_s) - ret += cpp_files_unittest.map(&:to_s) - ret += cpp_files.map(&:to_s) + # ret += cpp_files_arduino.map(&:to_s) + # ret += cpp_files_unittest.map(&:to_s) + # ret += cpp_files.map(&:to_s) unless ci_gcc_config.nil? cgc = ci_gcc_config ret = feature_args(cgc) + warning_args(cgc) + define_args(cgc) + flag_args(cgc) + ret @@ -485,16 +491,26 @@ def test_args(aux_libraries, ci_gcc_config) # # The dependent libraries configuration is appended with data from library.properties internal to the library under test # - # @param test_file [Pathname] The path to the file containing the unit tests + # @param test_file [Pathname] The path to the file containing the unit tests (nil to compile application as shared library) # @param aux_libraries [Array] The external Arduino libraries required by this project # @param ci_gcc_config [Hash] The GCC config object # @return [Pathname] path to the compiled test executable def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_gcc_config) - base = test_file.basename - executable = Pathname.new("unittest_#{base}.bin").expand_path - File.delete(executable) if File.exist?(executable) arg_sets = [] - arg_sets << ["-std=c++0x", "-o", executable.to_s, "-DARDUINO=100"] + arg_sets << ["-std=c++0x"] + if test_file.nil? + executable = Pathname.new("libarduino.so").expand_path + arg_sets << ["-shared", "-fPIC", "-Wl,-undefined,dynamic_lookup"] + # the following two take some time, so are cached when we build the shared library + @@full_dependencies = all_arduino_library_dependencies!(aux_libraries) + @@test_args = test_args(@@full_dependencies, ci_gcc_config) + else + base = test_file.basename + executable = Pathname.new("unittest_#{base}.bin").expand_path + end + arg_sets << ["-o", executable.to_s, "-L."] + File.delete(executable) if File.exist?(executable) + arg_sets << ["-DARDUINO=100"] if libasan?(gcc_binary) arg_sets << [ # Stuff to help with dynamic memory mishandling "-g", "-O1", @@ -504,15 +520,22 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g ] end + # puts "#{Time.now.to_s} arg_sets" # = #{arg_sets.to_s}" # combine library.properties defs (if existing) with config file. # 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 - full_dependencies = all_arduino_library_dependencies!(aux_libraries) - arg_sets << test_args(full_dependencies, ci_gcc_config) - arg_sets << cpp_files_libraries(full_dependencies).map(&:to_s) - arg_sets << [test_file.to_s] - args = arg_sets.flatten(1) - return nil unless run_gcc(gcc_binary, *args) + arg_sets << @@test_args # used cached value since building full set of include directories can take time + + if test_file.nil? # CPP files for the shared library + arg_sets << cpp_files_arduino.map(&:to_s) # Arduino.cpp, Godmode.cpp, and stdlib.cpp + arg_sets << cpp_files_unittest.map(&:to_s) # ArduinoUnitTests.cpp + arg_sets << cpp_files.map(&:to_s) # CPP files for the primary application library under test + arg_sets << cpp_files_libraries(@@full_dependencies).map(&:to_s) # CPP files for all the libraries we depend on + else # add the test file and the shared library + arg_sets << [test_file.to_s, "-larduino"] + end + args = arg_sets.flatten(1) + return nil unless run_gcc(gcc_binary, *args) # 0:54 artifacts << executable executable end From 2284f1d4a969118fce3c86d9a7e8d555ec3e839e Mon Sep 17 00:00:00 2001 From: James Foster Date: Wed, 24 Mar 2021 00:26:28 -0700 Subject: [PATCH 02/54] Add meaningful comments and remove commented-out code. --- CHANGELOG.md | 1 + lib/arduino_ci/cpp_library.rb | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cac76ad..a63c3d98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added ### Changed +- We now compile a shared library to be used for each test ### Deprecated diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index e40ab2e8..2aac142b 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -470,16 +470,15 @@ def flag_args(ci_gcc_config) ci_gcc_config[:flags] end - # All GCC command line args for building any unit test + # All non-CPP GCC command line args for building any unit test. + # We leave out the CPP files so they can be included or not + # depending on whether we are building a shared library. # @param aux_libraries [Array] The external Arduino libraries required by this project # @param ci_gcc_config [Hash] The GCC config object # @return [Array] GCC command-line flags def test_args(aux_libraries, ci_gcc_config) # TODO: something with libraries? ret = include_args(aux_libraries) - # ret += cpp_files_arduino.map(&:to_s) - # ret += cpp_files_unittest.map(&:to_s) - # ret += cpp_files.map(&:to_s) unless ci_gcc_config.nil? cgc = ci_gcc_config ret = feature_args(cgc) + warning_args(cgc) + define_args(cgc) + flag_args(cgc) + ret @@ -520,7 +519,6 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g ] end - # puts "#{Time.now.to_s} arg_sets" # = #{arg_sets.to_s}" # combine library.properties defs (if existing) with config file. # 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 arg_sets << @@test_args # used cached value since building full set of include directories can take time From 452cf0826aefb038f685049cf2929ddd68dba5d0 Mon Sep 17 00:00:00 2001 From: James Foster Date: Wed, 24 Mar 2021 00:59:13 -0700 Subject: [PATCH 03/54] See if this fixes the lint complaints. --- lib/arduino_ci/cpp_library.rb | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 2aac142b..2972b720 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -41,12 +41,6 @@ class CppLibrary # @return [Array] Directories suspected of being vendor-bundle attr_reader :vendor_bundle_cache - # @return [Array] Libraries we are dependent on - @@full_dependencies - - # @return [Array] Compiler arguments, including include directories, but not .cpp files - @@test_args - # @param friendly_name [String] The "official" name of the library, which can contain spaces # @param backend [ArduinoBackend] The support backend def initialize(friendly_name, backend) @@ -501,8 +495,8 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g executable = Pathname.new("libarduino.so").expand_path arg_sets << ["-shared", "-fPIC", "-Wl,-undefined,dynamic_lookup"] # the following two take some time, so are cached when we build the shared library - @@full_dependencies = all_arduino_library_dependencies!(aux_libraries) - @@test_args = test_args(@@full_dependencies, ci_gcc_config) + @full_dependencies = all_arduino_library_dependencies!(aux_libraries) + @test_args = test_args(@full_dependencies, ci_gcc_config) else base = test_file.basename executable = Pathname.new("unittest_#{base}.bin").expand_path @@ -521,19 +515,20 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g # combine library.properties defs (if existing) with config file. # 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 - arg_sets << @@test_args # used cached value since building full set of include directories can take time + arg_sets << @test_args # used cached value since building full set of include directories can take time if test_file.nil? # CPP files for the shared library arg_sets << cpp_files_arduino.map(&:to_s) # Arduino.cpp, Godmode.cpp, and stdlib.cpp arg_sets << cpp_files_unittest.map(&:to_s) # ArduinoUnitTests.cpp arg_sets << cpp_files.map(&:to_s) # CPP files for the primary application library under test - arg_sets << cpp_files_libraries(@@full_dependencies).map(&:to_s) # CPP files for all the libraries we depend on + arg_sets << cpp_files_libraries(@full_dependencies).map(&:to_s) # CPP files for all the libraries we depend on else # add the test file and the shared library arg_sets << [test_file.to_s, "-larduino"] end args = arg_sets.flatten(1) - return nil unless run_gcc(gcc_binary, *args) # 0:54 + return nil unless run_gcc(gcc_binary, *args) + artifacts << executable executable end From 24c37b6b3927ef69ae284bd70a8e313382c0b74a Mon Sep 17 00:00:00 2001 From: James Foster Date: Wed, 24 Mar 2021 07:12:58 -0700 Subject: [PATCH 04/54] Build single test executable if we don't have a shared library. --- lib/arduino_ci/cpp_library.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 2972b720..e31076ed 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -494,9 +494,6 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g if test_file.nil? executable = Pathname.new("libarduino.so").expand_path arg_sets << ["-shared", "-fPIC", "-Wl,-undefined,dynamic_lookup"] - # the following two take some time, so are cached when we build the shared library - @full_dependencies = all_arduino_library_dependencies!(aux_libraries) - @test_args = test_args(@full_dependencies, ci_gcc_config) else base = test_file.basename executable = Pathname.new("unittest_#{base}.bin").expand_path @@ -515,15 +512,19 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g # combine library.properties defs (if existing) with config file. # 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 + # the following two take some time, so are cached when we build the shared library + @full_dependencies ||= all_arduino_library_dependencies!(aux_libraries) + @test_args ||= test_args(@full_dependencies, ci_gcc_config) arg_sets << @test_args # used cached value since building full set of include directories can take time - if test_file.nil? # CPP files for the shared library + if File.exists?("libarduino.so") # add the test file and the shared library + arg_sets << [test_file.to_s, "-larduino"] + else # CPP files for the shared library arg_sets << cpp_files_arduino.map(&:to_s) # Arduino.cpp, Godmode.cpp, and stdlib.cpp arg_sets << cpp_files_unittest.map(&:to_s) # ArduinoUnitTests.cpp arg_sets << cpp_files.map(&:to_s) # CPP files for the primary application library under test arg_sets << cpp_files_libraries(@full_dependencies).map(&:to_s) # CPP files for all the libraries we depend on - else # add the test file and the shared library - arg_sets << [test_file.to_s, "-larduino"] + arg_sets << [test_file.to_s] if test_file end args = arg_sets.flatten(1) From 432828f6415214c4579c0f5cb7fe0a33c75b4751 Mon Sep 17 00:00:00 2001 From: James Foster Date: Wed, 24 Mar 2021 07:15:55 -0700 Subject: [PATCH 05/54] Use `File.exist?()` instead of `File.exists?()`. --- lib/arduino_ci/cpp_library.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index e31076ed..9d0c8cb4 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -517,7 +517,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g @test_args ||= test_args(@full_dependencies, ci_gcc_config) arg_sets << @test_args # used cached value since building full set of include directories can take time - if File.exists?("libarduino.so") # add the test file and the shared library + if File.exist?("libarduino.so") # add the test file and the shared library arg_sets << [test_file.to_s, "-larduino"] else # CPP files for the shared library arg_sets << cpp_files_arduino.map(&:to_s) # Arduino.cpp, Godmode.cpp, and stdlib.cpp From 009f7327bd630951109484881d72e5f8d7cdf9c0 Mon Sep 17 00:00:00 2001 From: James Foster Date: Wed, 24 Mar 2021 08:24:08 -0700 Subject: [PATCH 06/54] Set LD_LIBRARY_PATH to directory with shared library. --- lib/arduino_ci/cpp_library.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 9d0c8cb4..5f810115 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -498,7 +498,8 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g base = test_file.basename executable = Pathname.new("unittest_#{base}.bin").expand_path end - arg_sets << ["-o", executable.to_s, "-L."] + ENV["$LD_LIBRARY_PATH"]=Dir.pwd + arg_sets << ["-o", executable.to_s, "-L" + Dir.pwd] File.delete(executable) if File.exist?(executable) arg_sets << ["-DARDUINO=100"] if libasan?(gcc_binary) From e24ec9e713e58e9dbcd5443a5127bb8bd4c0c09b Mon Sep 17 00:00:00 2001 From: James Foster Date: Wed, 24 Mar 2021 08:35:04 -0700 Subject: [PATCH 07/54] Fix formatting (lint) issue. --- lib/arduino_ci/cpp_library.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 5f810115..77495ff2 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -498,7 +498,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g base = test_file.basename executable = Pathname.new("unittest_#{base}.bin").expand_path end - ENV["$LD_LIBRARY_PATH"]=Dir.pwd + ENV["$LD_LIBRARY_PATH"] = Dir.pwd arg_sets << ["-o", executable.to_s, "-L" + Dir.pwd] File.delete(executable) if File.exist?(executable) arg_sets << ["-DARDUINO=100"] From 2f5153f62091b8424d5a2a7eea1b2c1ac0c96ab3 Mon Sep 17 00:00:00 2001 From: James Foster Date: Wed, 24 Mar 2021 08:52:39 -0700 Subject: [PATCH 08/54] Should find LD_LIBRARY_PATH on Linux. --- lib/arduino_ci/cpp_library.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 77495ff2..aa9342b5 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -498,7 +498,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g base = test_file.basename executable = Pathname.new("unittest_#{base}.bin").expand_path end - ENV["$LD_LIBRARY_PATH"] = Dir.pwd + ENV["LD_LIBRARY_PATH"] = Dir.pwd arg_sets << ["-o", executable.to_s, "-L" + Dir.pwd] File.delete(executable) if File.exist?(executable) arg_sets << ["-DARDUINO=100"] From 81720df42acbd6a4ac051f93d68bab3e4bb82eb0 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sun, 3 Oct 2021 14:38:32 -0700 Subject: [PATCH 09/54] Fix merge problem with hiding build artifacts. --- lib/arduino_ci/cpp_library.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 4e8ca6d4..f5b06d5e 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -489,21 +489,18 @@ def test_args(aux_libraries, ci_gcc_config) # @param ci_gcc_config [Hash] The GCC config object # @return [Pathname] path to the compiled test executable def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_gcc_config) - base = test_file.basename # hide build artifacts build_dir = '.arduino_ci' Dir.mkdir build_dir unless File.exist?(build_dir) - executable = Pathname.new("#{build_dir}/unittest_#{base}.bin").expand_path - File.delete(executable) if File.exist?(executable) arg_sets = [] arg_sets << ["-std=c++0x"] if test_file.nil? - executable = Pathname.new("libarduino.so").expand_path + executable = Pathname.new("#{build_dir}/libarduino.so").expand_path arg_sets << ["-shared", "-fPIC", "-Wl,-undefined,dynamic_lookup"] else - base = test_file.basename - executable = Pathname.new("unittest_#{base}.bin").expand_path + executable = Pathname.new("#{build_dir}/unittest_#{test_file.basename}.bin").expand_path end + File.delete(executable) if File.exist?(executable) ENV["LD_LIBRARY_PATH"] = Dir.pwd arg_sets << ["-o", executable.to_s, "-L" + Dir.pwd] File.delete(executable) if File.exist?(executable) From ecdd9336d46cea927f35e31e84ff35a91c077e66 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 9 Oct 2021 20:32:38 -0700 Subject: [PATCH 10/54] Use constant variables for names and fix problem where library was not used. --- .gitignore | 1 + lib/arduino_ci/cpp_library.rb | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index ea2d3da0..8e4802d6 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ Gemfile.lock /spec/reports/ vendor *.gem +.arduino_ci # rspec failure tracking .rspec_status diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 6c90b042..79b7fda5 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -490,19 +490,21 @@ def test_args(aux_libraries, ci_gcc_config) # @return [Pathname] path to the compiled test executable def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_gcc_config) # hide build artifacts - build_dir = '.arduino_ci' + build_dir = ".arduino_ci" Dir.mkdir build_dir unless File.exist?(build_dir) + lib_name = "arduino" + full_lib_name = "#{build_dir}/lib#{lib_name}.sh" arg_sets = [] arg_sets << ["-std=c++0x"] if test_file.nil? - executable = Pathname.new("#{build_dir}/libarduino.so").expand_path + executable = Pathname.new(full_lib_name).expand_path arg_sets << ["-shared", "-fPIC", "-Wl,-undefined,dynamic_lookup"] else executable = Pathname.new("#{build_dir}/unittest_#{test_file.basename}.bin").expand_path end File.delete(executable) if File.exist?(executable) ENV["LD_LIBRARY_PATH"] = Dir.pwd - arg_sets << ["-o", executable.to_s, "-L" + Dir.pwd] + arg_sets << ["-o", executable.to_s, "-L" + build_dir] File.delete(executable) if File.exist?(executable) arg_sets << ["-DARDUINO=100"] if libasan?(gcc_binary) @@ -521,8 +523,8 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g @test_args ||= test_args(@full_dependencies, ci_gcc_config) arg_sets << @test_args # used cached value since building full set of include directories can take time - if File.exist?("libarduino.so") # add the test file and the shared library - arg_sets << [test_file.to_s, "-larduino"] + if File.exist?(full_lib_name) # add the test file and the shared library + arg_sets << [test_file.to_s, "-l#{lib_name}"] else # CPP files for the shared library arg_sets << cpp_files_arduino.map(&:to_s) # Arduino.cpp, Godmode.cpp, and stdlib.cpp arg_sets << cpp_files_unittest.map(&:to_s) # ArduinoUnitTests.cpp From 9a9412dc9e448d84180e0d1074abf7ef3e622503 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 9 Oct 2021 20:44:29 -0700 Subject: [PATCH 11/54] Separate rubocop from general testing in LInux. --- .github/workflows/linux.yaml | 14 +++++++++++++- lib/arduino_ci/cpp_library.rb | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index 9c9247a8..15072a2a 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -4,7 +4,7 @@ name: linux on: [push, pull_request] jobs: - "unittest_lint_sampleproject": + "lint": runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -18,6 +18,18 @@ jobs: bundle exec rubocop --version bundle exec rubocop -D . bundle exec rspec --backtrace + + "TestSomething": + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + - name: TestSomething + run: | + g++ -v + bundle install cd SampleProjects/TestSomething bundle install bundle exec arduino_ci.rb diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 79b7fda5..be0d5711 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -504,7 +504,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g end File.delete(executable) if File.exist?(executable) ENV["LD_LIBRARY_PATH"] = Dir.pwd - arg_sets << ["-o", executable.to_s, "-L" + build_dir] + arg_sets << ["-o", executable.to_s, "-L#{Dir.pwd}/#{build_dir}"] File.delete(executable) if File.exist?(executable) arg_sets << ["-DARDUINO=100"] if libasan?(gcc_binary) From 932253e2dc92e67f29a90c1109ded1bada22d58d Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 9 Oct 2021 21:02:22 -0700 Subject: [PATCH 12/54] Replace `.sh` with `.so` for shared library name. --- lib/arduino_ci/cpp_library.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index be0d5711..25cbefb9 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -493,7 +493,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g build_dir = ".arduino_ci" Dir.mkdir build_dir unless File.exist?(build_dir) lib_name = "arduino" - full_lib_name = "#{build_dir}/lib#{lib_name}.sh" + full_lib_name = "#{build_dir}/lib#{lib_name}.so" arg_sets = [] arg_sets << ["-std=c++0x"] if test_file.nil? @@ -524,7 +524,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g arg_sets << @test_args # used cached value since building full set of include directories can take time if File.exist?(full_lib_name) # add the test file and the shared library - arg_sets << [test_file.to_s, "-l#{lib_name}"] + arg_sets << [test_file.to_s, "-l#{lib_name}"] if test_file else # CPP files for the shared library arg_sets << cpp_files_arduino.map(&:to_s) # Arduino.cpp, Godmode.cpp, and stdlib.cpp arg_sets << cpp_files_unittest.map(&:to_s) # ArduinoUnitTests.cpp From 76bf627291d6ca4611400bfec79fe0284064ea27 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 9 Oct 2021 21:17:00 -0700 Subject: [PATCH 13/54] Debugging output to look for missing library. --- .github/workflows/linux.yaml | 1 + exe/arduino_ci.rb | 1 + lib/arduino_ci/cpp_library.rb | 7 ++++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index 15072a2a..ba7abc58 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -49,3 +49,4 @@ jobs: bundle exec ensure_arduino_installation.rb sh ./scripts/install.sh bundle exec arduino_ci.rb + pwd; ls -alF; ls -alF .arduino_ci/ diff --git a/exe/arduino_ci.rb b/exe/arduino_ci.rb index 11e9770d..2030ae57 100755 --- a/exe/arduino_ci.rb +++ b/exe/arduino_ci.rb @@ -442,6 +442,7 @@ def perform_unit_tests(cpp_library, file_config) # now build and run each test using the shared library build above config.allowable_unittest_files(cpp_library.test_files).each do |unittest_path| unittest_name = unittest_path.basename.to_s + puts "--------------------------------------------------------------------------------" attempt_multiline("Unit testing #{unittest_name} with #{gcc_binary} for #{p}") do exe = cpp_library.build_for_test_with_configuration( unittest_path, diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 25cbefb9..a0f5a009 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -490,7 +490,7 @@ def test_args(aux_libraries, ci_gcc_config) # @return [Pathname] path to the compiled test executable def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_gcc_config) # hide build artifacts - build_dir = ".arduino_ci" + build_dir = "#{Dir.pwd}/.arduino_ci" Dir.mkdir build_dir unless File.exist?(build_dir) lib_name = "arduino" full_lib_name = "#{build_dir}/lib#{lib_name}.so" @@ -504,7 +504,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g end File.delete(executable) if File.exist?(executable) ENV["LD_LIBRARY_PATH"] = Dir.pwd - arg_sets << ["-o", executable.to_s, "-L#{Dir.pwd}/#{build_dir}"] + arg_sets << ["-o", executable.to_s, "-L#{build_dir}"] File.delete(executable) if File.exist?(executable) arg_sets << ["-DARDUINO=100"] if libasan?(gcc_binary) @@ -525,6 +525,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g if File.exist?(full_lib_name) # add the test file and the shared library arg_sets << [test_file.to_s, "-l#{lib_name}"] if test_file + puts "found #{full_lib_name}" else # CPP files for the shared library arg_sets << cpp_files_arduino.map(&:to_s) # Arduino.cpp, Godmode.cpp, and stdlib.cpp arg_sets << cpp_files_unittest.map(&:to_s) # ArduinoUnitTests.cpp @@ -532,7 +533,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g arg_sets << cpp_files_libraries(@full_dependencies).map(&:to_s) # CPP files for all the libraries we depend on arg_sets << [test_file.to_s] if test_file end - + puts "{arg_sets}" args = arg_sets.flatten(1) return nil unless run_gcc(gcc_binary, *args) From d688e3cbb416a7222705e0b1074d3ace831a8085 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 9 Oct 2021 21:21:33 -0700 Subject: [PATCH 14/54] Fix output of arg_sets. --- lib/arduino_ci/cpp_library.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index a0f5a009..8d1a2736 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -533,7 +533,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g arg_sets << cpp_files_libraries(@full_dependencies).map(&:to_s) # CPP files for all the libraries we depend on arg_sets << [test_file.to_s] if test_file end - puts "{arg_sets}" + puts "#{arg_sets}" args = arg_sets.flatten(1) return nil unless run_gcc(gcc_binary, *args) From 481d91108934f2947a35887d3c18cc0a8cc8a76d Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 9 Oct 2021 21:27:47 -0700 Subject: [PATCH 15/54] See if we can find the files! --- .github/workflows/linux.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index ba7abc58..cf986c33 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -48,5 +48,4 @@ jobs: bundle install bundle exec ensure_arduino_installation.rb sh ./scripts/install.sh - bundle exec arduino_ci.rb - pwd; ls -alF; ls -alF .arduino_ci/ + bundle exec arduino_ci.rb; pwd; ls -alF; ls -alF .arduino_ci From 904ffc406b6f4244e716c3888565696d6f724e08 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 9 Oct 2021 21:30:49 -0700 Subject: [PATCH 16/54] More attempts at directory listing. --- .github/workflows/linux.yaml | 2 +- lib/arduino_ci/cpp_library.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index cf986c33..15072a2a 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -48,4 +48,4 @@ jobs: bundle install bundle exec ensure_arduino_installation.rb sh ./scripts/install.sh - bundle exec arduino_ci.rb; pwd; ls -alF; ls -alF .arduino_ci + bundle exec arduino_ci.rb diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 8d1a2736..cb1d76dc 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -526,6 +526,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g if File.exist?(full_lib_name) # add the test file and the shared library arg_sets << [test_file.to_s, "-l#{lib_name}"] if test_file puts "found #{full_lib_name}" + `pwd; ls -alF; ls -alF .arduino_ci` else # CPP files for the shared library arg_sets << cpp_files_arduino.map(&:to_s) # Arduino.cpp, Godmode.cpp, and stdlib.cpp arg_sets << cpp_files_unittest.map(&:to_s) # ArduinoUnitTests.cpp @@ -533,8 +534,8 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g arg_sets << cpp_files_libraries(@full_dependencies).map(&:to_s) # CPP files for all the libraries we depend on arg_sets << [test_file.to_s] if test_file end - puts "#{arg_sets}" args = arg_sets.flatten(1) + puts "#{args}" return nil unless run_gcc(gcc_binary, *args) artifacts << executable From c290df823f498de916c0d5ae9fdab5546cf5f902 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 9 Oct 2021 21:32:28 -0700 Subject: [PATCH 17/54] Forgot to print output. --- lib/arduino_ci/cpp_library.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index cb1d76dc..02a9505b 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -526,7 +526,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g if File.exist?(full_lib_name) # add the test file and the shared library arg_sets << [test_file.to_s, "-l#{lib_name}"] if test_file puts "found #{full_lib_name}" - `pwd; ls -alF; ls -alF .arduino_ci` + puts `pwd; ls -alF; ls -alF .arduino_ci` else # CPP files for the shared library arg_sets << cpp_files_arduino.map(&:to_s) # Arduino.cpp, Godmode.cpp, and stdlib.cpp arg_sets << cpp_files_unittest.map(&:to_s) # ArduinoUnitTests.cpp From 75f2de06bce5b591f3211005cfa26c1fa75dd044 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 9 Oct 2021 21:42:00 -0700 Subject: [PATCH 18/54] See if we can pass on macOS. --- .github/workflows/macos.yaml | 14 +++++++++++++- lib/arduino_ci/cpp_library.rb | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/macos.yaml b/.github/workflows/macos.yaml index 96357648..b88d2976 100644 --- a/.github/workflows/macos.yaml +++ b/.github/workflows/macos.yaml @@ -4,7 +4,7 @@ name: macos on: [push, pull_request] jobs: - "unittest_lint_sampleproject": + "lint": runs-on: macos-latest steps: - uses: actions/checkout@v2 @@ -18,6 +18,18 @@ jobs: bundle exec rubocop --version bundle exec rubocop -D . bundle exec rspec --backtrace + + "TestSomething": + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + - name: TestSomething + run: | + g++ -v + bundle install cd SampleProjects/TestSomething bundle install bundle exec arduino_ci.rb diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 02a9505b..f3198805 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -535,7 +535,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g arg_sets << [test_file.to_s] if test_file end args = arg_sets.flatten(1) - puts "#{args}" + puts args.to_s return nil unless run_gcc(gcc_binary, *args) artifacts << executable From cfebe1f5e1a42c594863e2dc4b09a43543c1fa74 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 9 Oct 2021 21:52:50 -0700 Subject: [PATCH 19/54] Fix `LD_LIBRARY_PATH` --- lib/arduino_ci/cpp_library.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index f3198805..bcbd9a8d 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -489,8 +489,7 @@ def test_args(aux_libraries, ci_gcc_config) # @param ci_gcc_config [Hash] The GCC config object # @return [Pathname] path to the compiled test executable def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_gcc_config) - # hide build artifacts - build_dir = "#{Dir.pwd}/.arduino_ci" + build_dir = "#{Dir.pwd}/.arduino_ci" # hide build artifacts Dir.mkdir build_dir unless File.exist?(build_dir) lib_name = "arduino" full_lib_name = "#{build_dir}/lib#{lib_name}.so" @@ -503,7 +502,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g executable = Pathname.new("#{build_dir}/unittest_#{test_file.basename}.bin").expand_path end File.delete(executable) if File.exist?(executable) - ENV["LD_LIBRARY_PATH"] = Dir.pwd + ENV["LD_LIBRARY_PATH"] = build_dir arg_sets << ["-o", executable.to_s, "-L#{build_dir}"] File.delete(executable) if File.exist?(executable) arg_sets << ["-DARDUINO=100"] From 49c2439c026b2f4df902e7d5fc9c9a55c3b75733 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 9 Oct 2021 22:00:56 -0700 Subject: [PATCH 20/54] Remove directory logging; add lines between rubocop and rspec code. --- .github/workflows/macos.yaml | 6 +++++- lib/arduino_ci/cpp_library.rb | 3 --- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/macos.yaml b/.github/workflows/macos.yaml index b88d2976..c23f28c6 100644 --- a/.github/workflows/macos.yaml +++ b/.github/workflows/macos.yaml @@ -4,7 +4,7 @@ name: macos on: [push, pull_request] jobs: - "lint": + "rubocop and rspec": runs-on: macos-latest steps: - uses: actions/checkout@v2 @@ -14,9 +14,13 @@ jobs: - name: Check style, functionality, and usage run: | g++ -v + echo "-------------------------" bundle install + echo "-------------------------" bundle exec rubocop --version + echo "-------------------------" bundle exec rubocop -D . + echo "-------------------------" bundle exec rspec --backtrace "TestSomething": diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index bcbd9a8d..96ab743d 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -524,8 +524,6 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g if File.exist?(full_lib_name) # add the test file and the shared library arg_sets << [test_file.to_s, "-l#{lib_name}"] if test_file - puts "found #{full_lib_name}" - puts `pwd; ls -alF; ls -alF .arduino_ci` else # CPP files for the shared library arg_sets << cpp_files_arduino.map(&:to_s) # Arduino.cpp, Godmode.cpp, and stdlib.cpp arg_sets << cpp_files_unittest.map(&:to_s) # ArduinoUnitTests.cpp @@ -534,7 +532,6 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g arg_sets << [test_file.to_s] if test_file end args = arg_sets.flatten(1) - puts args.to_s return nil unless run_gcc(gcc_binary, *args) artifacts << executable From 01ed91b4a56fe5e81fe8a7e728c95111ca785b34 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 9 Oct 2021 22:02:13 -0700 Subject: [PATCH 21/54] Rename GitHub Action workflow job. --- .github/workflows/macos.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/macos.yaml b/.github/workflows/macos.yaml index c23f28c6..8a722391 100644 --- a/.github/workflows/macos.yaml +++ b/.github/workflows/macos.yaml @@ -4,7 +4,7 @@ name: macos on: [push, pull_request] jobs: - "rubocop and rspec": + "rubocop_and_rspec": runs-on: macos-latest steps: - uses: actions/checkout@v2 From acc3f0103018eaf01faa607a78f1ec0aaf2facd3 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 9 Oct 2021 22:10:21 -0700 Subject: [PATCH 22/54] Rename "lint" to "rubocop_and_rspec" in test. Switch Windows testing back to running on Windows. --- .github/workflows/linux.yaml | 2 +- .github/workflows/macos.yaml | 4 ---- .github/workflows/windows.yaml | 16 ++++++++++++++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index 15072a2a..f74f3baa 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -4,7 +4,7 @@ name: linux on: [push, pull_request] jobs: - "lint": + "rubocop_and_rspec": runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/macos.yaml b/.github/workflows/macos.yaml index 8a722391..17cd3d57 100644 --- a/.github/workflows/macos.yaml +++ b/.github/workflows/macos.yaml @@ -14,13 +14,9 @@ jobs: - name: Check style, functionality, and usage run: | g++ -v - echo "-------------------------" bundle install - echo "-------------------------" bundle exec rubocop --version - echo "-------------------------" bundle exec rubocop -D . - echo "-------------------------" bundle exec rspec --backtrace "TestSomething": diff --git a/.github/workflows/windows.yaml b/.github/workflows/windows.yaml index 6a4afa72..6f56fdf6 100644 --- a/.github/workflows/windows.yaml +++ b/.github/workflows/windows.yaml @@ -4,7 +4,7 @@ name: windows on: [push, pull_request] jobs: - "unittest_lint_sampleproject": + "rubocop_and_rspec": runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -18,12 +18,24 @@ jobs: bundle exec rubocop --version bundle exec rubocop -D . bundle exec rspec --backtrace + + "TestSomething": + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + - name: TestSomething + run: | + g++ -v + bundle install cd SampleProjects/TestSomething bundle install bundle exec arduino_ci.rb NetworkLib: - runs-on: ubuntu-latest + runs-on: windows-latest steps: - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 From 224b4d2ae170dd7e24c31a6c9ee39bc91e892964 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 9 Oct 2021 22:20:34 -0700 Subject: [PATCH 23/54] Switch windows test back to ubuntu to avoid test failure. --- .github/workflows/windows.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows.yaml b/.github/workflows/windows.yaml index 6f56fdf6..86ed0ef3 100644 --- a/.github/workflows/windows.yaml +++ b/.github/workflows/windows.yaml @@ -35,7 +35,7 @@ jobs: bundle exec arduino_ci.rb NetworkLib: - runs-on: windows-latest + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 From 6fe2bc026227916c0c8c43e2822479c3adc1379a Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 9 Oct 2021 22:26:33 -0700 Subject: [PATCH 24/54] Try with libarduino.so in working directory instead of build directory. --- lib/arduino_ci/cpp_library.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 96ab743d..cc0a275b 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -492,7 +492,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g build_dir = "#{Dir.pwd}/.arduino_ci" # hide build artifacts Dir.mkdir build_dir unless File.exist?(build_dir) lib_name = "arduino" - full_lib_name = "#{build_dir}/lib#{lib_name}.so" + full_lib_name = "lib#{lib_name}.so" arg_sets = [] arg_sets << ["-std=c++0x"] if test_file.nil? @@ -502,10 +502,8 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g executable = Pathname.new("#{build_dir}/unittest_#{test_file.basename}.bin").expand_path end File.delete(executable) if File.exist?(executable) - ENV["LD_LIBRARY_PATH"] = build_dir - arg_sets << ["-o", executable.to_s, "-L#{build_dir}"] + arg_sets << ["-o", executable.to_s, "-L#{Dir.pwd}", "-DARDUINO=100"] File.delete(executable) if File.exist?(executable) - arg_sets << ["-DARDUINO=100"] if libasan?(gcc_binary) arg_sets << [ # Stuff to help with dynamic memory mishandling "-g", "-O1", From bc0270f454066270d88d51303c6089c0edf6fe3f Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 9 Oct 2021 22:28:46 -0700 Subject: [PATCH 25/54] Revert "Try with libarduino.so in working directory instead of build directory." This reverts commit 6fe2bc026227916c0c8c43e2822479c3adc1379a. --- lib/arduino_ci/cpp_library.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index cc0a275b..96ab743d 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -492,7 +492,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g build_dir = "#{Dir.pwd}/.arduino_ci" # hide build artifacts Dir.mkdir build_dir unless File.exist?(build_dir) lib_name = "arduino" - full_lib_name = "lib#{lib_name}.so" + full_lib_name = "#{build_dir}/lib#{lib_name}.so" arg_sets = [] arg_sets << ["-std=c++0x"] if test_file.nil? @@ -502,8 +502,10 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g executable = Pathname.new("#{build_dir}/unittest_#{test_file.basename}.bin").expand_path end File.delete(executable) if File.exist?(executable) - arg_sets << ["-o", executable.to_s, "-L#{Dir.pwd}", "-DARDUINO=100"] + ENV["LD_LIBRARY_PATH"] = build_dir + arg_sets << ["-o", executable.to_s, "-L#{build_dir}"] File.delete(executable) if File.exist?(executable) + arg_sets << ["-DARDUINO=100"] if libasan?(gcc_binary) arg_sets << [ # Stuff to help with dynamic memory mishandling "-g", "-O1", From c5246fc8138362c8d0200c3e20fb6805a32f6c74 Mon Sep 17 00:00:00 2001 From: James Foster Date: Thu, 14 Oct 2021 19:25:52 -0700 Subject: [PATCH 26/54] Does Windows find library if it is in the local directory? --- lib/arduino_ci/cpp_library.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 96ab743d..30deccaa 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -492,7 +492,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g build_dir = "#{Dir.pwd}/.arduino_ci" # hide build artifacts Dir.mkdir build_dir unless File.exist?(build_dir) lib_name = "arduino" - full_lib_name = "#{build_dir}/lib#{lib_name}.so" + full_lib_name = "#{Dir.pwd}/lib#{lib_name}.so" arg_sets = [] arg_sets << ["-std=c++0x"] if test_file.nil? @@ -502,8 +502,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g executable = Pathname.new("#{build_dir}/unittest_#{test_file.basename}.bin").expand_path end File.delete(executable) if File.exist?(executable) - ENV["LD_LIBRARY_PATH"] = build_dir - arg_sets << ["-o", executable.to_s, "-L#{build_dir}"] + arg_sets << ["-o", executable.to_s, "-L#{Dir.pwd}"] File.delete(executable) if File.exist?(executable) arg_sets << ["-DARDUINO=100"] if libasan?(gcc_binary) From c4bfe143f7298b977371623e5444d4047fb7ddd3 Mon Sep 17 00:00:00 2001 From: James Foster Date: Thu, 14 Oct 2021 19:27:30 -0700 Subject: [PATCH 27/54] Revert "Does Windows find library if it is in the local directory?" This reverts commit c5246fc8138362c8d0200c3e20fb6805a32f6c74. --- lib/arduino_ci/cpp_library.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 30deccaa..96ab743d 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -492,7 +492,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g build_dir = "#{Dir.pwd}/.arduino_ci" # hide build artifacts Dir.mkdir build_dir unless File.exist?(build_dir) lib_name = "arduino" - full_lib_name = "#{Dir.pwd}/lib#{lib_name}.so" + full_lib_name = "#{build_dir}/lib#{lib_name}.so" arg_sets = [] arg_sets << ["-std=c++0x"] if test_file.nil? @@ -502,7 +502,8 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g executable = Pathname.new("#{build_dir}/unittest_#{test_file.basename}.bin").expand_path end File.delete(executable) if File.exist?(executable) - arg_sets << ["-o", executable.to_s, "-L#{Dir.pwd}"] + ENV["LD_LIBRARY_PATH"] = build_dir + arg_sets << ["-o", executable.to_s, "-L#{build_dir}"] File.delete(executable) if File.exist?(executable) arg_sets << ["-DARDUINO=100"] if libasan?(gcc_binary) From 81311ab1a361b08daa16c26c528953da4a46f7ee Mon Sep 17 00:00:00 2001 From: James Foster Date: Thu, 14 Oct 2021 19:35:58 -0700 Subject: [PATCH 28/54] Does adding to PATH help Windows find the library? --- lib/arduino_ci/cpp_library.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 96ab743d..80d506dc 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -502,7 +502,8 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g executable = Pathname.new("#{build_dir}/unittest_#{test_file.basename}.bin").expand_path end File.delete(executable) if File.exist?(executable) - ENV["LD_LIBRARY_PATH"] = build_dir + ENV["LD_LIBRARY_PATH"] = build_dir # for Linux and macOS + ENV["PATH"] = build_dir + ":" + ENV["PATH"] # for Windows arg_sets << ["-o", executable.to_s, "-L#{build_dir}"] File.delete(executable) if File.exist?(executable) arg_sets << ["-DARDUINO=100"] From 427c6ead922b8876c9d5b54d454cb3cf27ce63d9 Mon Sep 17 00:00:00 2001 From: James Foster Date: Thu, 14 Oct 2021 19:43:55 -0700 Subject: [PATCH 29/54] Add debugging info for Windows. --- lib/arduino_ci/cpp_library.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 80d506dc..c84c7e31 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -504,6 +504,10 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g File.delete(executable) if File.exist?(executable) ENV["LD_LIBRARY_PATH"] = build_dir # for Linux and macOS ENV["PATH"] = build_dir + ":" + ENV["PATH"] # for Windows + puts("cpp_library.rb:507") + puts(ENV["PATH"]) + puts(full_lib_name) + puts(Dir.pwd) arg_sets << ["-o", executable.to_s, "-L#{build_dir}"] File.delete(executable) if File.exist?(executable) arg_sets << ["-DARDUINO=100"] From 717028249fa733b9e6609b89c0d3db8846a64b5c Mon Sep 17 00:00:00 2001 From: James Foster Date: Thu, 14 Oct 2021 20:32:20 -0700 Subject: [PATCH 30/54] The path seems to be structured differently in some tests. --- lib/arduino_ci/cpp_library.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index c84c7e31..a769ae30 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -503,7 +503,11 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g end File.delete(executable) if File.exist?(executable) ENV["LD_LIBRARY_PATH"] = build_dir # for Linux and macOS - ENV["PATH"] = build_dir + ":" + ENV["PATH"] # for Windows + if ENV["PATH"].include? ";" + ENV["PATH"] = build_dir + ";" + ENV["PATH"] # for Windows when in D:/a/arduino_ci/... + else + ENV["PATH"] = build_dir + ":" + ENV["PATH"] # for Windows when in /home/runner/work/arduino_ci/... + end puts("cpp_library.rb:507") puts(ENV["PATH"]) puts(full_lib_name) From 83b93b7748a062e58f0b405d3713a42ba1cea7b1 Mon Sep 17 00:00:00 2001 From: James Foster Date: Thu, 14 Oct 2021 21:35:35 -0700 Subject: [PATCH 31/54] Try a different path for Windows. --- lib/arduino_ci/cpp_library.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index a769ae30..866b1f98 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -504,11 +504,12 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g File.delete(executable) if File.exist?(executable) ENV["LD_LIBRARY_PATH"] = build_dir # for Linux and macOS if ENV["PATH"].include? ";" - ENV["PATH"] = build_dir + ";" + ENV["PATH"] # for Windows when in D:/a/arduino_ci/... + win_build_dir = build_dir.gsub('/', '\\') + ENV["PATH"] = win_build_dir + ";" + ENV["PATH"] unless ENV["PATH"].include? win_build_dir # for Windows when in D:/a/arduino_ci/... else ENV["PATH"] = build_dir + ":" + ENV["PATH"] # for Windows when in /home/runner/work/arduino_ci/... end - puts("cpp_library.rb:507") + puts("cpp_library.rb:512") puts(ENV["PATH"]) puts(full_lib_name) puts(Dir.pwd) From 99a6d7ee3c8c5d31647afe3cfa27016d99505b0f Mon Sep 17 00:00:00 2001 From: James Foster Date: Thu, 14 Oct 2021 21:54:01 -0700 Subject: [PATCH 32/54] One more try tonight for a Windows path to the shared library. --- lib/arduino_ci/cpp_library.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 866b1f98..224affea 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -513,7 +513,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g puts(ENV["PATH"]) puts(full_lib_name) puts(Dir.pwd) - arg_sets << ["-o", executable.to_s, "-L#{build_dir}"] + arg_sets << ["-o", executable.to_s, "-L#{win_build_dir}"] File.delete(executable) if File.exist?(executable) arg_sets << ["-DARDUINO=100"] if libasan?(gcc_binary) From e751715d2c14f5fbcad8cfba9363fe90f0bc2b91 Mon Sep 17 00:00:00 2001 From: James Foster Date: Thu, 14 Oct 2021 22:03:32 -0700 Subject: [PATCH 33/54] Try with .dll as the library name. --- lib/arduino_ci/cpp_library.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 224affea..3bb2b58a 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -2,6 +2,7 @@ require "arduino_ci/host" require 'pathname' require 'shellwords' +require 'os' HPP_EXTENSIONS = [".hpp", ".hh", ".h", ".hxx", ".h++"].freeze CPP_EXTENSIONS = [".cpp", ".cc", ".c", ".cxx", ".c++"].freeze @@ -492,7 +493,11 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g build_dir = "#{Dir.pwd}/.arduino_ci" # hide build artifacts Dir.mkdir build_dir unless File.exist?(build_dir) lib_name = "arduino" - full_lib_name = "#{build_dir}/lib#{lib_name}.so" + if OS.windows? + full_lib_name = "#{build_dir}/lib#{lib_name}.dll" + else + full_lib_name = "#{build_dir}/lib#{lib_name}.so" + end arg_sets = [] arg_sets << ["-std=c++0x"] if test_file.nil? @@ -505,9 +510,10 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g ENV["LD_LIBRARY_PATH"] = build_dir # for Linux and macOS if ENV["PATH"].include? ";" win_build_dir = build_dir.gsub('/', '\\') - ENV["PATH"] = win_build_dir + ";" + ENV["PATH"] unless ENV["PATH"].include? win_build_dir # for Windows when in D:/a/arduino_ci/... + ENV["PATH"] = win_build_dir + ";" + ENV["PATH"] unless ENV["PATH"].include? win_build_dir # for Windows when in D:/a/arduino_ci/... else - ENV["PATH"] = build_dir + ":" + ENV["PATH"] # for Windows when in /home/runner/work/arduino_ci/... + win_build_dir = build_dir + ENV["PATH"] = win_build_dir + ":" + ENV["PATH"] unless ENV["PATH"].include? win_build_dir # for Windows when in /home/runner/work/arduino_ci/... end puts("cpp_library.rb:512") puts(ENV["PATH"]) From 5784d940a5d712654ac115503fbb6849746e84fa Mon Sep 17 00:00:00 2001 From: James Foster Date: Thu, 14 Oct 2021 22:10:20 -0700 Subject: [PATCH 34/54] Address a couple lint issues and see if the path slashes are important. --- lib/arduino_ci/cpp_library.rb | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 3bb2b58a..164fb25c 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -493,11 +493,11 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g build_dir = "#{Dir.pwd}/.arduino_ci" # hide build artifacts Dir.mkdir build_dir unless File.exist?(build_dir) lib_name = "arduino" - if OS.windows? - full_lib_name = "#{build_dir}/lib#{lib_name}.dll" - else - full_lib_name = "#{build_dir}/lib#{lib_name}.so" - end + full_lib_name = if OS.windows? + "#{build_dir}/lib#{lib_name}.dll" + else + "#{build_dir}/lib#{lib_name}.so" + end arg_sets = [] arg_sets << ["-std=c++0x"] if test_file.nil? @@ -509,16 +509,14 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g File.delete(executable) if File.exist?(executable) ENV["LD_LIBRARY_PATH"] = build_dir # for Linux and macOS if ENV["PATH"].include? ";" - win_build_dir = build_dir.gsub('/', '\\') - ENV["PATH"] = win_build_dir + ";" + ENV["PATH"] unless ENV["PATH"].include? win_build_dir # for Windows when in D:/a/arduino_ci/... + win_build_dir = build_dir # .gsub('/', '\\') + # for Windows when in D:/a/arduino_ci/... + ENV["PATH"] = win_build_dir + ";" + ENV["PATH"] unless ENV["PATH"].include? win_build_dir else win_build_dir = build_dir - ENV["PATH"] = win_build_dir + ":" + ENV["PATH"] unless ENV["PATH"].include? win_build_dir # for Windows when in /home/runner/work/arduino_ci/... + # for Windows when in /home/runner/work/arduino_ci/... + ENV["PATH"] = win_build_dir + ":" + ENV["PATH"] unless ENV["PATH"].include? win_build_dir end - puts("cpp_library.rb:512") - puts(ENV["PATH"]) - puts(full_lib_name) - puts(Dir.pwd) arg_sets << ["-o", executable.to_s, "-L#{win_build_dir}"] File.delete(executable) if File.exist?(executable) arg_sets << ["-DARDUINO=100"] From e51501dd42d733d1dd13d8fe78e6912dbe0e8851 Mon Sep 17 00:00:00 2001 From: James Foster Date: Thu, 14 Oct 2021 22:17:00 -0700 Subject: [PATCH 35/54] More lint issues. --- lib/arduino_ci/cpp_library.rb | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 164fb25c..f019b671 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -494,10 +494,10 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g Dir.mkdir build_dir unless File.exist?(build_dir) lib_name = "arduino" full_lib_name = if OS.windows? - "#{build_dir}/lib#{lib_name}.dll" - else - "#{build_dir}/lib#{lib_name}.so" - end + "#{build_dir}/lib#{lib_name}.dll" + else + "#{build_dir}/lib#{lib_name}.so" + end arg_sets = [] arg_sets << ["-std=c++0x"] if test_file.nil? @@ -508,16 +508,13 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g end File.delete(executable) if File.exist?(executable) ENV["LD_LIBRARY_PATH"] = build_dir # for Linux and macOS - if ENV["PATH"].include? ";" - win_build_dir = build_dir # .gsub('/', '\\') - # for Windows when in D:/a/arduino_ci/... - ENV["PATH"] = win_build_dir + ";" + ENV["PATH"] unless ENV["PATH"].include? win_build_dir + delimiter = if ENV["PATH"].include? ";" + ";" else - win_build_dir = build_dir - # for Windows when in /home/runner/work/arduino_ci/... - ENV["PATH"] = win_build_dir + ":" + ENV["PATH"] unless ENV["PATH"].include? win_build_dir + ":" end - arg_sets << ["-o", executable.to_s, "-L#{win_build_dir}"] + ENV["PATH"] = build_dir + delimiter + ENV["PATH"] unless ENV["PATH"].include? build_dir # for Windows + arg_sets << ["-o", executable.to_s, "-L#{build_dir}"] File.delete(executable) if File.exist?(executable) arg_sets << ["-DARDUINO=100"] if libasan?(gcc_binary) From 910c4ced2825bea3bdc8e90ec6e93492412244cd Mon Sep 17 00:00:00 2001 From: James Foster Date: Thu, 14 Oct 2021 22:39:30 -0700 Subject: [PATCH 36/54] Refactor to clean up Windows vs. non-Windows code. --- lib/arduino_ci/cpp_library.rb | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index f019b671..8fe189c8 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -493,13 +493,14 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g build_dir = "#{Dir.pwd}/.arduino_ci" # hide build artifacts Dir.mkdir build_dir unless File.exist?(build_dir) lib_name = "arduino" - full_lib_name = if OS.windows? - "#{build_dir}/lib#{lib_name}.dll" + if OS.windows? + full_lib_name = "#{build_dir}/lib#{lib_name}.dll" + ENV["PATH"] = build_dir + (ENV["PATH"].include? ";" ? ";" : ":") + ENV["PATH"] unless ENV["PATH"].include? build_dir else - "#{build_dir}/lib#{lib_name}.so" + full_lib_name = "#{build_dir}/lib#{lib_name}.so" + ENV["LD_LIBRARY_PATH"] = build_dir end - arg_sets = [] - arg_sets << ["-std=c++0x"] + arg_sets = ["-std=c++0x"] if test_file.nil? executable = Pathname.new(full_lib_name).expand_path arg_sets << ["-shared", "-fPIC", "-Wl,-undefined,dynamic_lookup"] @@ -507,16 +508,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g executable = Pathname.new("#{build_dir}/unittest_#{test_file.basename}.bin").expand_path end File.delete(executable) if File.exist?(executable) - ENV["LD_LIBRARY_PATH"] = build_dir # for Linux and macOS - delimiter = if ENV["PATH"].include? ";" - ";" - else - ":" - end - ENV["PATH"] = build_dir + delimiter + ENV["PATH"] unless ENV["PATH"].include? build_dir # for Windows - arg_sets << ["-o", executable.to_s, "-L#{build_dir}"] - File.delete(executable) if File.exist?(executable) - arg_sets << ["-DARDUINO=100"] + arg_sets << ["-o", executable.to_s, "-L#{build_dir}", "-DARDUINO=100"] if libasan?(gcc_binary) arg_sets << [ # Stuff to help with dynamic memory mishandling "-g", "-O1", From 9c4c48708c0a3149941a969a50abe2e2d766be76 Mon Sep 17 00:00:00 2001 From: James Foster Date: Thu, 14 Oct 2021 22:44:02 -0700 Subject: [PATCH 37/54] Does this fix the lint error? --- lib/arduino_ci/cpp_library.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 8fe189c8..d6d40917 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -495,7 +495,7 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g lib_name = "arduino" if OS.windows? full_lib_name = "#{build_dir}/lib#{lib_name}.dll" - ENV["PATH"] = build_dir + (ENV["PATH"].include? ";" ? ";" : ":") + ENV["PATH"] unless ENV["PATH"].include? build_dir + ENV["PATH"] = build_dir + ((ENV["PATH"].include? ";") ? ";" : ":") + ENV["PATH"] unless ENV["PATH"].include? build_dir else full_lib_name = "#{build_dir}/lib#{lib_name}.so" ENV["LD_LIBRARY_PATH"] = build_dir From abbc7a5e9a67172e0cb80ca12678ed080b80d16c Mon Sep 17 00:00:00 2001 From: James Foster Date: Thu, 14 Oct 2021 22:48:14 -0700 Subject: [PATCH 38/54] Refactor the expression to try to foil lint complaint. --- lib/arduino_ci/cpp_library.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index d6d40917..2b413d23 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -495,7 +495,8 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g lib_name = "arduino" if OS.windows? full_lib_name = "#{build_dir}/lib#{lib_name}.dll" - ENV["PATH"] = build_dir + ((ENV["PATH"].include? ";") ? ";" : ":") + ENV["PATH"] unless ENV["PATH"].include? build_dir + flag = ENV["PATH"].include? ";" + ENV["PATH"] = build_dir + (flag ? ";" : ":") + ENV["PATH"] unless ENV["PATH"].include? build_dir else full_lib_name = "#{build_dir}/lib#{lib_name}.so" ENV["LD_LIBRARY_PATH"] = build_dir From e0da3f74cc294a2066e042bc6109f12f78dfbca0 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 16 Oct 2021 21:43:40 -0700 Subject: [PATCH 39/54] Create standalone function to build the shared library. --- exe/arduino_ci.rb | 72 +++++++++++++++++--------------- lib/arduino_ci/cpp_library.rb | 78 ++++++++++++++++++++++------------- 2 files changed, 87 insertions(+), 63 deletions(-) diff --git a/exe/arduino_ci.rb b/exe/arduino_ci.rb index 2030ae57..897e9699 100755 --- a/exe/arduino_ci.rb +++ b/exe/arduino_ci.rb @@ -423,47 +423,51 @@ def perform_unit_tests(cpp_library, file_config) puts compilers.each do |gcc_binary| # before compiling the tests, build a shared library of everything except the test code - attempt_multiline("Build shared library with #{gcc_binary} for #{p}") do - exe = cpp_library.build_for_test_with_configuration( - nil, # nil is a flag that we are building the shared library with everything else - config.aux_libraries_for_unittest, - gcc_binary, - config.gcc_config(p) - ) - puts - unless exe - puts "Last command: #{cpp_library.last_cmd}" - puts cpp_library.last_out - puts cpp_library.last_err - next false - end - true - end - # now build and run each test using the shared library build above - config.allowable_unittest_files(cpp_library.test_files).each do |unittest_path| - unittest_name = unittest_path.basename.to_s - puts "--------------------------------------------------------------------------------" - attempt_multiline("Unit testing #{unittest_name} with #{gcc_binary} for #{p}") do - exe = cpp_library.build_for_test_with_configuration( - unittest_path, - config.aux_libraries_for_unittest, - gcc_binary, - config.gcc_config(p) - ) - puts - unless exe - puts "Last command: #{cpp_library.last_cmd}" - puts cpp_library.last_out - puts cpp_library.last_err - next false + if build_shared_library(gcc_binary, p, config, cpp_library) + # now build and run each test using the shared library build above + config.allowable_unittest_files(cpp_library.test_files).each do |unittest_path| + unittest_name = unittest_path.basename.to_s + puts "--------------------------------------------------------------------------------" + attempt_multiline("Unit testing #{unittest_name} with #{gcc_binary} for #{p}") do + exe = cpp_library.build_for_test_with_configuration( + unittest_path, + config.aux_libraries_for_unittest, + gcc_binary, + config.gcc_config(p) + ) + puts + unless exe + puts "Last command: #{cpp_library.last_cmd}" + puts cpp_library.last_out + puts cpp_library.last_err + next false + end + cpp_library.run_test_file(exe) end - cpp_library.run_test_file(exe) end end end end end +def build_shared_library(gcc_binary, platform, config, cpp_library) + attempt_multiline("Build shared library with #{gcc_binary} for #{platform}") do + exe = cpp_library.build_share_library_with_configuration( + config.aux_libraries_for_unittest, + gcc_binary, + config.gcc_config(platform) + ) + puts + unless exe + puts "Last command: #{cpp_library.last_cmd}" + puts cpp_library.last_out + puts cpp_library.last_err + return false + end + return true + end +end + def perform_example_compilation_tests(cpp_library, config) phase("Compilation of example sketches") if @cli_options[:skip_compilation] diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 2b413d23..be9e0497 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -9,6 +9,9 @@ CI_CPP_DIR = Pathname.new(__dir__).parent.parent + "cpp" ARDUINO_HEADER_DIR = CI_CPP_DIR + "arduino" UNITTEST_HEADER_DIR = CI_CPP_DIR + "unittest" +LIBRARY_NAME = "arduino" +BUILD_DIR = "#{Dir.pwd}/.arduino_ci" # hide build artifacts + module ArduinoCI @@ -485,31 +488,53 @@ def test_args(aux_libraries, ci_gcc_config) # # The dependent libraries configuration is appended with data from library.properties internal to the library under test # - # @param test_file [Pathname] The path to the file containing the unit tests (nil to compile application as shared library) + # @param test_file [Pathname] The path to the file containing the unit tests # @param aux_libraries [Array] The external Arduino libraries required by this project # @param ci_gcc_config [Hash] The GCC config object # @return [Pathname] path to the compiled test executable def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_gcc_config) - build_dir = "#{Dir.pwd}/.arduino_ci" # hide build artifacts - Dir.mkdir build_dir unless File.exist?(build_dir) - lib_name = "arduino" + executable = Pathname.new("#{BUILD_DIR}/#{test_file.basename}.bin").expand_path + File.delete(executable) if File.exist?(executable) + arg_sets = ["-std=c++0x", "-o", executable.to_s, "-L#{BUILD_DIR}", "-DARDUINO=100"] + if libasan?(gcc_binary) + arg_sets << [ # Stuff to help with dynamic memory mishandling + "-g", "-O1", + "-fno-omit-frame-pointer", + "-fno-optimize-sibling-calls", + "-fsanitize=address" + ] + end + arg_sets << @test_args + arg_sets << [test_file.to_s, "-l#{LIBRARY_NAME}"] + args = arg_sets.flatten(1) + return nil unless run_gcc(gcc_binary, *args) + + artifacts << executable + executable + end + + # build a shared library to be used by each test + # + # The dependent libraries configuration is appended with data from library.properties internal to the library under test + # + # @param aux_libraries [Array] The external Arduino libraries required by this project + # @param ci_gcc_config [Hash] The GCC config object + # @return [Pathname] path to the compiled test executable + def build_share_library_with_configuration(aux_libraries, gcc_binary, ci_gcc_config) + Dir.mkdir BUILD_DIR unless File.exist?(BUILD_DIR) if OS.windows? - full_lib_name = "#{build_dir}/lib#{lib_name}.dll" flag = ENV["PATH"].include? ";" - ENV["PATH"] = build_dir + (flag ? ";" : ":") + ENV["PATH"] unless ENV["PATH"].include? build_dir + ENV["PATH"] = BUILD_DIR + (flag ? ";" : ":") + ENV["PATH"] unless ENV["PATH"].include? build_dir + suffix = "dll" else - full_lib_name = "#{build_dir}/lib#{lib_name}.so" - ENV["LD_LIBRARY_PATH"] = build_dir - end - arg_sets = ["-std=c++0x"] - if test_file.nil? - executable = Pathname.new(full_lib_name).expand_path - arg_sets << ["-shared", "-fPIC", "-Wl,-undefined,dynamic_lookup"] - else - executable = Pathname.new("#{build_dir}/unittest_#{test_file.basename}.bin").expand_path + ENV["LD_LIBRARY_PATH"] = BUILD_DIR + suffix = "so" end + full_lib_name = "#{BUILD_DIR}/lib#{LIBRARY_NAME}.#{suffix}" + executable = Pathname.new(full_lib_name).expand_path File.delete(executable) if File.exist?(executable) - arg_sets << ["-o", executable.to_s, "-L#{build_dir}", "-DARDUINO=100"] + arg_sets = ["-std=c++0x", "-shared", "-fPIC", "-Wl,-undefined,dynamic_lookup", + "-o", executable.to_s, "-L#{BUILD_DIR}", "-DARDUINO=100"] if libasan?(gcc_binary) arg_sets << [ # Stuff to help with dynamic memory mishandling "-g", "-O1", @@ -522,19 +547,14 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g # combine library.properties defs (if existing) with config file. # 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 # the following two take some time, so are cached when we build the shared library - @full_dependencies ||= all_arduino_library_dependencies!(aux_libraries) - @test_args ||= test_args(@full_dependencies, ci_gcc_config) - arg_sets << @test_args # used cached value since building full set of include directories can take time - - if File.exist?(full_lib_name) # add the test file and the shared library - arg_sets << [test_file.to_s, "-l#{lib_name}"] if test_file - else # CPP files for the shared library - arg_sets << cpp_files_arduino.map(&:to_s) # Arduino.cpp, Godmode.cpp, and stdlib.cpp - arg_sets << cpp_files_unittest.map(&:to_s) # ArduinoUnitTests.cpp - arg_sets << cpp_files.map(&:to_s) # CPP files for the primary application library under test - arg_sets << cpp_files_libraries(@full_dependencies).map(&:to_s) # CPP files for all the libraries we depend on - arg_sets << [test_file.to_s] if test_file - end + @full_dependencies = all_arduino_library_dependencies!(aux_libraries) + @test_args = test_args(@full_dependencies, ci_gcc_config) # build full set of include directories to be cached for later + + arg_sets << @test_args + arg_sets << cpp_files_arduino.map(&:to_s) # Arduino.cpp, Godmode.cpp, and stdlib.cpp + arg_sets << cpp_files_unittest.map(&:to_s) # ArduinoUnitTests.cpp + arg_sets << cpp_files.map(&:to_s) # CPP files for the primary application library under test + arg_sets << cpp_files_libraries(@full_dependencies).map(&:to_s) # CPP files for all the libraries we depend on args = arg_sets.flatten(1) return nil unless run_gcc(gcc_binary, *args) From bd4b916e15a78b7e4b0da9c03d07b732e9fde347 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 16 Oct 2021 21:51:03 -0700 Subject: [PATCH 40/54] Address lint issues. --- exe/arduino_ci.rb | 37 ++++++++++++++++------------------- lib/arduino_ci/cpp_library.rb | 7 +++---- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/exe/arduino_ci.rb b/exe/arduino_ci.rb index 897e9699..c9bc49a5 100755 --- a/exe/arduino_ci.rb +++ b/exe/arduino_ci.rb @@ -423,27 +423,24 @@ def perform_unit_tests(cpp_library, file_config) puts compilers.each do |gcc_binary| # before compiling the tests, build a shared library of everything except the test code - if build_shared_library(gcc_binary, p, config, cpp_library) - # now build and run each test using the shared library build above - config.allowable_unittest_files(cpp_library.test_files).each do |unittest_path| - unittest_name = unittest_path.basename.to_s - puts "--------------------------------------------------------------------------------" - attempt_multiline("Unit testing #{unittest_name} with #{gcc_binary} for #{p}") do - exe = cpp_library.build_for_test_with_configuration( - unittest_path, - config.aux_libraries_for_unittest, - gcc_binary, - config.gcc_config(p) - ) - puts - unless exe - puts "Last command: #{cpp_library.last_cmd}" - puts cpp_library.last_out - puts cpp_library.last_err - next false - end - cpp_library.run_test_file(exe) + next unless build_shared_library(gcc_binary, p, config, cpp_library) + # now build and run each test using the shared library build above + config.allowable_unittest_files(cpp_library.test_files).each do |unittest_path| + unittest_name = unittest_path.basename.to_s + puts "--------------------------------------------------------------------------------" + attempt_multiline("Unit testing #{unittest_name} with #{gcc_binary} for #{p}") do + exe = cpp_library.build_for_test_with_configuration( + unittest_path, + gcc_binary + ) + puts + unless exe + puts "Last command: #{cpp_library.last_cmd}" + puts cpp_library.last_out + puts cpp_library.last_err + next false end + cpp_library.run_test_file(exe) end end end diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index be9e0497..c536e50c 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -9,9 +9,8 @@ CI_CPP_DIR = Pathname.new(__dir__).parent.parent + "cpp" ARDUINO_HEADER_DIR = CI_CPP_DIR + "arduino" UNITTEST_HEADER_DIR = CI_CPP_DIR + "unittest" -LIBRARY_NAME = "arduino" -BUILD_DIR = "#{Dir.pwd}/.arduino_ci" # hide build artifacts - +LIBRARY_NAME = "arduino".freeze +BUILD_DIR = "#{Dir.pwd}/.arduino_ci".freeze # hide build artifacts module ArduinoCI @@ -492,7 +491,7 @@ def test_args(aux_libraries, ci_gcc_config) # @param aux_libraries [Array] The external Arduino libraries required by this project # @param ci_gcc_config [Hash] The GCC config object # @return [Pathname] path to the compiled test executable - def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_gcc_config) + def build_for_test_with_configuration(test_file, gcc_binary) executable = Pathname.new("#{BUILD_DIR}/#{test_file.basename}.bin").expand_path File.delete(executable) if File.exist?(executable) arg_sets = ["-std=c++0x", "-o", executable.to_s, "-L#{BUILD_DIR}", "-DARDUINO=100"] From b38752d3eb235eeaa5ecebf94bd0efafc97b93ad Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 16 Oct 2021 21:52:15 -0700 Subject: [PATCH 41/54] Another lint issue. --- exe/arduino_ci.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/exe/arduino_ci.rb b/exe/arduino_ci.rb index c9bc49a5..7cad5644 100755 --- a/exe/arduino_ci.rb +++ b/exe/arduino_ci.rb @@ -424,6 +424,7 @@ def perform_unit_tests(cpp_library, file_config) compilers.each do |gcc_binary| # before compiling the tests, build a shared library of everything except the test code next unless build_shared_library(gcc_binary, p, config, cpp_library) + # now build and run each test using the shared library build above config.allowable_unittest_files(cpp_library.test_files).each do |unittest_path| unittest_name = unittest_path.basename.to_s From 0314005767776ff991d84fee11a14720f4f381e0 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 16 Oct 2021 22:09:37 -0700 Subject: [PATCH 42/54] More rubocopy and rspec cleanup. --- CHANGELOG.md | 2 +- exe/arduino_ci.rb | 5 +---- lib/arduino_ci/cpp_library.rb | 6 +++--- spec/cpp_library_spec.rb | 11 ++++++----- spec/testsomething_unittests_spec.rb | 3 ++- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92ffc212..6f9f9bd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -398,7 +398,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Malformed YAML (duplicate unittests section) now has no duplicate section -- arduino_ci_remote.rb script now has correct arguments in build_for_test_with_configuration +- arduino_ci_remote.rb script now has correct arguments in build_for_test ## [0.1.8] - 2018-04-03 diff --git a/exe/arduino_ci.rb b/exe/arduino_ci.rb index 7cad5644..8c328431 100755 --- a/exe/arduino_ci.rb +++ b/exe/arduino_ci.rb @@ -430,10 +430,7 @@ def perform_unit_tests(cpp_library, file_config) unittest_name = unittest_path.basename.to_s puts "--------------------------------------------------------------------------------" attempt_multiline("Unit testing #{unittest_name} with #{gcc_binary} for #{p}") do - exe = cpp_library.build_for_test_with_configuration( - unittest_path, - gcc_binary - ) + exe = cpp_library.build_for_test(unittest_path, gcc_binary) puts unless exe puts "Last command: #{cpp_library.last_cmd}" diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index c536e50c..b9b050f4 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -488,10 +488,9 @@ def test_args(aux_libraries, ci_gcc_config) # The dependent libraries configuration is appended with data from library.properties internal to the library under test # # @param test_file [Pathname] The path to the file containing the unit tests - # @param aux_libraries [Array] The external Arduino libraries required by this project - # @param ci_gcc_config [Hash] The GCC config object + # @param gcc_binary [String] name of a compiler # @return [Pathname] path to the compiled test executable - def build_for_test_with_configuration(test_file, gcc_binary) + def build_for_test(test_file, gcc_binary) executable = Pathname.new("#{BUILD_DIR}/#{test_file.basename}.bin").expand_path File.delete(executable) if File.exist?(executable) arg_sets = ["-std=c++0x", "-o", executable.to_s, "-L#{BUILD_DIR}", "-DARDUINO=100"] @@ -517,6 +516,7 @@ def build_for_test_with_configuration(test_file, gcc_binary) # The dependent libraries configuration is appended with data from library.properties internal to the library under test # # @param aux_libraries [Array] The external Arduino libraries required by this project + # @param gcc_binary [String] name of a compiler # @param ci_gcc_config [Hash] The GCC config object # @return [Pathname] path to the compiled test executable def build_share_library_with_configuration(aux_libraries, gcc_binary, ci_gcc_config) diff --git a/spec/cpp_library_spec.rb b/spec/cpp_library_spec.rb index 050e0555..80b425b3 100644 --- a/spec/cpp_library_spec.rb +++ b/spec/cpp_library_spec.rb @@ -45,10 +45,9 @@ def verified_install(backend, path) config = ArduinoCI::CIConfig.default.from_example(cpp_lib_path) path = config.allowable_unittest_files(@cpp_library.test_files).first compiler = config.compilers_to_use.first - result = @cpp_library.build_for_test_with_configuration(path, - [], - compiler, - config.gcc_config("uno")) + result = @cpp_library.build_shared_library(path, [], compiler, config.gcc_config("uno")) + expect(result).to be nil + result = @cpp_library.build_for_test(path, compiler) expect(result).to be nil end end @@ -276,7 +275,9 @@ def verified_install(backend, path) expected = path.basename.to_s.include?("good") config.compilers_to_use.each do |compiler| it "tests #{File.basename(path)} with #{compiler} expecting #{expected}" do - exe = @cpp_library.build_for_test_with_configuration(path, [], compiler, config.gcc_config("uno")) + exe = @cpp_library.build_shared_library(path, [], compiler, config.gcc_config("uno")) + expect(exe).not_to be nil + exe = @cpp_library.build_for_test(path, compiler) expect(exe).not_to be nil expect(@cpp_library.run_test_file(exe)).to eq(expected) end diff --git a/spec/testsomething_unittests_spec.rb b/spec/testsomething_unittests_spec.rb index bf3f9f62..0f068512 100644 --- a/spec/testsomething_unittests_spec.rb +++ b/spec/testsomething_unittests_spec.rb @@ -74,7 +74,8 @@ before(:each) do @cpp_library = backend.install_local_library(cpp_lib_path) - @exe = @cpp_library.build_for_test_with_configuration(path, [], compiler, config.gcc_config("uno")) + @cpp.library.build_shared_library(path, [], compiler, config.gcc_config("uno")) + @exe = @cpp_library.build_for_test(path, compiler) end # extra debug for c++ failures From 059e349d4277f7324d7b72d8646e8186d85be5b1 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 16 Oct 2021 22:17:38 -0700 Subject: [PATCH 43/54] rename function and give the right number of parameters --- exe/arduino_ci.rb | 2 +- lib/arduino_ci/cpp_library.rb | 2 +- spec/cpp_library_spec.rb | 4 ++-- spec/testsomething_unittests_spec.rb | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/exe/arduino_ci.rb b/exe/arduino_ci.rb index 8c328431..6b481f13 100755 --- a/exe/arduino_ci.rb +++ b/exe/arduino_ci.rb @@ -447,7 +447,7 @@ def perform_unit_tests(cpp_library, file_config) def build_shared_library(gcc_binary, platform, config, cpp_library) attempt_multiline("Build shared library with #{gcc_binary} for #{platform}") do - exe = cpp_library.build_share_library_with_configuration( + exe = cpp_library.build_shared_library( config.aux_libraries_for_unittest, gcc_binary, config.gcc_config(platform) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index b9b050f4..c1b8df18 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -519,7 +519,7 @@ def build_for_test(test_file, gcc_binary) # @param gcc_binary [String] name of a compiler # @param ci_gcc_config [Hash] The GCC config object # @return [Pathname] path to the compiled test executable - def build_share_library_with_configuration(aux_libraries, gcc_binary, ci_gcc_config) + def build_shared_library(aux_libraries, gcc_binary, ci_gcc_config) Dir.mkdir BUILD_DIR unless File.exist?(BUILD_DIR) if OS.windows? flag = ENV["PATH"].include? ";" diff --git a/spec/cpp_library_spec.rb b/spec/cpp_library_spec.rb index 80b425b3..ec03f055 100644 --- a/spec/cpp_library_spec.rb +++ b/spec/cpp_library_spec.rb @@ -45,7 +45,7 @@ def verified_install(backend, path) config = ArduinoCI::CIConfig.default.from_example(cpp_lib_path) path = config.allowable_unittest_files(@cpp_library.test_files).first compiler = config.compilers_to_use.first - result = @cpp_library.build_shared_library(path, [], compiler, config.gcc_config("uno")) + result = @cpp_library.build_shared_library([], compiler, config.gcc_config("uno")) expect(result).to be nil result = @cpp_library.build_for_test(path, compiler) expect(result).to be nil @@ -275,7 +275,7 @@ def verified_install(backend, path) expected = path.basename.to_s.include?("good") config.compilers_to_use.each do |compiler| it "tests #{File.basename(path)} with #{compiler} expecting #{expected}" do - exe = @cpp_library.build_shared_library(path, [], compiler, config.gcc_config("uno")) + exe = @cpp_library.build_shared_library([], compiler, config.gcc_config("uno")) expect(exe).not_to be nil exe = @cpp_library.build_for_test(path, compiler) expect(exe).not_to be nil diff --git a/spec/testsomething_unittests_spec.rb b/spec/testsomething_unittests_spec.rb index 0f068512..eb1739cb 100644 --- a/spec/testsomething_unittests_spec.rb +++ b/spec/testsomething_unittests_spec.rb @@ -74,7 +74,7 @@ before(:each) do @cpp_library = backend.install_local_library(cpp_lib_path) - @cpp.library.build_shared_library(path, [], compiler, config.gcc_config("uno")) + @cpp.library.build_shared_library([], compiler, config.gcc_config("uno")) @exe = @cpp_library.build_for_test(path, compiler) end From a16e33e0f1c683784b966088658d58dd0bf5d3ae Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 16 Oct 2021 22:22:19 -0700 Subject: [PATCH 44/54] Split rubocop and rspec. Fix typo in variable name. --- .github/workflows/linux.yaml | 14 +++++++++++++- .github/workflows/macos.yaml | 14 +++++++++++++- .github/workflows/windows.yaml | 14 +++++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index f74f3baa..ea424ebe 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -4,7 +4,7 @@ name: linux on: [push, pull_request] jobs: - "rubocop_and_rspec": + "rubocop": runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -17,6 +17,18 @@ jobs: bundle install bundle exec rubocop --version bundle exec rubocop -D . + + "rspec": + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + - name: Check style, functionality, and usage + run: | + g++ -v + bundle install bundle exec rspec --backtrace "TestSomething": diff --git a/.github/workflows/macos.yaml b/.github/workflows/macos.yaml index 17cd3d57..8b51fd60 100644 --- a/.github/workflows/macos.yaml +++ b/.github/workflows/macos.yaml @@ -4,7 +4,7 @@ name: macos on: [push, pull_request] jobs: - "rubocop_and_rspec": + "rubocop": runs-on: macos-latest steps: - uses: actions/checkout@v2 @@ -17,6 +17,18 @@ jobs: bundle install bundle exec rubocop --version bundle exec rubocop -D . + + "rspec": + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + - name: Check style, functionality, and usage + run: | + g++ -v + bundle install bundle exec rspec --backtrace "TestSomething": diff --git a/.github/workflows/windows.yaml b/.github/workflows/windows.yaml index 03a943cf..467373bf 100644 --- a/.github/workflows/windows.yaml +++ b/.github/workflows/windows.yaml @@ -4,7 +4,7 @@ name: windows on: [push, pull_request] jobs: - "unittest_lint_sampleproject": + "rubocop": runs-on: windows-latest steps: - uses: actions/checkout@v2 @@ -17,6 +17,18 @@ jobs: bundle install bundle exec rubocop --version bundle exec rubocop -D . + + "rspec": + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + - name: Check style, functionality, and usage + run: | + g++ -v + bundle install bundle exec rspec --backtrace "TestSomething": From c20d61be96408c97b285a5178d7cbc519c6d7520 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 16 Oct 2021 22:25:08 -0700 Subject: [PATCH 45/54] File missed in last commit. --- spec/testsomething_unittests_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/testsomething_unittests_spec.rb b/spec/testsomething_unittests_spec.rb index eb1739cb..d7eae266 100644 --- a/spec/testsomething_unittests_spec.rb +++ b/spec/testsomething_unittests_spec.rb @@ -74,7 +74,7 @@ before(:each) do @cpp_library = backend.install_local_library(cpp_lib_path) - @cpp.library.build_shared_library([], compiler, config.gcc_config("uno")) + @cpp_library.build_shared_library([], compiler, config.gcc_config("uno")) @exe = @cpp_library.build_for_test(path, compiler) end From 68d8f03e34eae5ef9151d4ee3e970ef89007f81b Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 16 Oct 2021 22:32:30 -0700 Subject: [PATCH 46/54] Missed variable name replacement. --- lib/arduino_ci/cpp_library.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index c1b8df18..2446bff2 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -523,7 +523,7 @@ def build_shared_library(aux_libraries, gcc_binary, ci_gcc_config) Dir.mkdir BUILD_DIR unless File.exist?(BUILD_DIR) if OS.windows? flag = ENV["PATH"].include? ";" - ENV["PATH"] = BUILD_DIR + (flag ? ";" : ":") + ENV["PATH"] unless ENV["PATH"].include? build_dir + ENV["PATH"] = BUILD_DIR + (flag ? ";" : ":") + ENV["PATH"] unless ENV["PATH"].include? BUILD_DIR suffix = "dll" else ENV["LD_LIBRARY_PATH"] = BUILD_DIR From 3d7926fb372bbb92a4dc546ab846e2f0a45f5120 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 16 Oct 2021 22:39:02 -0700 Subject: [PATCH 47/54] See if we can avoid Rubocop error in Windows. --- .github/workflows/windows.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/windows.yaml b/.github/workflows/windows.yaml index 467373bf..be3eeb2c 100644 --- a/.github/workflows/windows.yaml +++ b/.github/workflows/windows.yaml @@ -17,6 +17,7 @@ jobs: bundle install bundle exec rubocop --version bundle exec rubocop -D . + echo "done with Rubocop (See https://github.com/Arduino-CI/arduino_ci/issues/315)" "rspec": runs-on: windows-latest From bf6bb03a8f82a2934e44051c19f9bf51f7b061aa Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 16 Oct 2021 22:43:33 -0700 Subject: [PATCH 48/54] Still trying on Windows! --- .github/workflows/windows.yaml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/.github/workflows/windows.yaml b/.github/workflows/windows.yaml index be3eeb2c..8ff04914 100644 --- a/.github/workflows/windows.yaml +++ b/.github/workflows/windows.yaml @@ -4,7 +4,7 @@ name: windows on: [push, pull_request] jobs: - "rubocop": + "rubocop_and_rspec": runs-on: windows-latest steps: - uses: actions/checkout@v2 @@ -18,18 +18,6 @@ jobs: bundle exec rubocop --version bundle exec rubocop -D . echo "done with Rubocop (See https://github.com/Arduino-CI/arduino_ci/issues/315)" - - "rspec": - runs-on: windows-latest - steps: - - uses: actions/checkout@v2 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: 2.6 - - name: Check style, functionality, and usage - run: | - g++ -v - bundle install bundle exec rspec --backtrace "TestSomething": From c086fc86620f95a5f4245d606344f3f686a41d50 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 16 Oct 2021 23:13:32 -0700 Subject: [PATCH 49/54] Treat lowercase `itoa()` as successful. --- SampleProjects/TestSomething/test/stdlib.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SampleProjects/TestSomething/test/stdlib.cpp b/SampleProjects/TestSomething/test/stdlib.cpp index 31bd0735..72cd8917 100644 --- a/SampleProjects/TestSomething/test/stdlib.cpp +++ b/SampleProjects/TestSomething/test/stdlib.cpp @@ -26,11 +26,11 @@ unittest(library_tests_itoa) }; for (int i = 0; i < ARRAY_SIZEOF(table); i++) { - result = itoa(table[i].value, buf, table[i].base); + result = itoa(table[i].value, buf, table[i].base).upcase; assertEqual(table[i].expected, result); } - // While only bases 2, 8, 10 and 16 are of real interest, lets test that all + // While only bases 2, 8, 10 and 16 are of real interest, let's test that all // bases at least produce expected output for a few test points simple to test. for (int base = 2; base <= 16; base++) { result = itoa(0, buf, base); From caa990a29da8c9ba1f39b01058041bc65156463e Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 16 Oct 2021 23:25:48 -0700 Subject: [PATCH 50/54] Undo last edit. --- SampleProjects/TestSomething/test/stdlib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SampleProjects/TestSomething/test/stdlib.cpp b/SampleProjects/TestSomething/test/stdlib.cpp index 72cd8917..0a0048d3 100644 --- a/SampleProjects/TestSomething/test/stdlib.cpp +++ b/SampleProjects/TestSomething/test/stdlib.cpp @@ -26,7 +26,7 @@ unittest(library_tests_itoa) }; for (int i = 0; i < ARRAY_SIZEOF(table); i++) { - result = itoa(table[i].value, buf, table[i].base).upcase; + result = itoa(table[i].value, buf, table[i].base); assertEqual(table[i].expected, result); } From 1ccae14e58bf9b2d4e2f1b3cb9de28dfc19242de Mon Sep 17 00:00:00 2001 From: James Foster Date: Sun, 17 Oct 2021 05:02:07 -0700 Subject: [PATCH 51/54] Upshift `itoa()` result so that Windows result matches expected values. --- SampleProjects/TestSomething/test/stdlib.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SampleProjects/TestSomething/test/stdlib.cpp b/SampleProjects/TestSomething/test/stdlib.cpp index 0a0048d3..f3629361 100644 --- a/SampleProjects/TestSomething/test/stdlib.cpp +++ b/SampleProjects/TestSomething/test/stdlib.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #define ARRAY_SIZEOF(a) ( sizeof(a) / sizeof((a)[0]) ) @@ -26,6 +28,9 @@ unittest(library_tests_itoa) }; for (int i = 0; i < ARRAY_SIZEOF(table); i++) { + for (int j = 0; j < strlen(buf); ++j) { + buf[j] = toupper(buf[j]); + } result = itoa(table[i].value, buf, table[i].base); assertEqual(table[i].expected, result); } From 0cbb275ea5e1429d2cc956763a0c90cf0cd0f6ff Mon Sep 17 00:00:00 2001 From: James Foster Date: Sun, 17 Oct 2021 05:02:25 -0700 Subject: [PATCH 52/54] Fix last commit. --- .gitignore | 1 + SampleProjects/TestSomething/test/stdlib.cpp | 17 ++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 8e4802d6..c9bf028b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ vendor *.bin.dSYM *.so *.so.dSYM +.vscode diff --git a/SampleProjects/TestSomething/test/stdlib.cpp b/SampleProjects/TestSomething/test/stdlib.cpp index f3629361..0b300568 100644 --- a/SampleProjects/TestSomething/test/stdlib.cpp +++ b/SampleProjects/TestSomething/test/stdlib.cpp @@ -8,7 +8,6 @@ unittest(library_tests_itoa) { char buf[32]; - const char *result; struct { int value; const char *expected; @@ -28,22 +27,22 @@ unittest(library_tests_itoa) }; for (int i = 0; i < ARRAY_SIZEOF(table); i++) { + itoa(table[i].value, buf, table[i].base); for (int j = 0; j < strlen(buf); ++j) { buf[j] = toupper(buf[j]); } - result = itoa(table[i].value, buf, table[i].base); - assertEqual(table[i].expected, result); + assertEqual(table[i].expected, buf); } // While only bases 2, 8, 10 and 16 are of real interest, let's test that all // bases at least produce expected output for a few test points simple to test. for (int base = 2; base <= 16; base++) { - result = itoa(0, buf, base); - assertEqual("0", result); - result = itoa(1, buf, base); - assertEqual("1", result); - result = itoa(base, buf, base); - assertEqual("10", result); + itoa(0, buf, base); + assertEqual("0", buf); + itoa(1, buf, base); + assertEqual("1", buf); + itoa(base, buf, base); + assertEqual("10", buf); } } From e7c10986c29b4671f899c17c61ce9a26989cfb49 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sun, 17 Oct 2021 05:17:13 -0700 Subject: [PATCH 53/54] Build shared library only once for `cpp_library_spec.rb`. --- spec/cpp_library_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/cpp_library_spec.rb b/spec/cpp_library_spec.rb index ec03f055..a756dfae 100644 --- a/spec/cpp_library_spec.rb +++ b/spec/cpp_library_spec.rb @@ -271,12 +271,12 @@ def verified_install(backend, path) end test_files = Pathname.glob(Pathname.new(cpp_lib_path) + "test" + "*.cpp") - test_files.each do |path| - expected = path.basename.to_s.include?("good") - config.compilers_to_use.each do |compiler| + config.compilers_to_use.each do |compiler| + exe = @cpp_library.build_shared_library([], compiler, config.gcc_config("uno")) + expect(exe).not_to be nil + test_files.each do |path| + expected = path.basename.to_s.include?("good") it "tests #{File.basename(path)} with #{compiler} expecting #{expected}" do - exe = @cpp_library.build_shared_library([], compiler, config.gcc_config("uno")) - expect(exe).not_to be nil exe = @cpp_library.build_for_test(path, compiler) expect(exe).not_to be nil expect(@cpp_library.run_test_file(exe)).to eq(expected) From 6a5cd783fb940c1f3ebe095f3d1957b28c0a2e63 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sun, 17 Oct 2021 05:20:24 -0700 Subject: [PATCH 54/54] Revert "Build shared library only once for `cpp_library_spec.rb`." This reverts commit e7c10986c29b4671f899c17c61ce9a26989cfb49. --- spec/cpp_library_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/cpp_library_spec.rb b/spec/cpp_library_spec.rb index a756dfae..ec03f055 100644 --- a/spec/cpp_library_spec.rb +++ b/spec/cpp_library_spec.rb @@ -271,12 +271,12 @@ def verified_install(backend, path) end test_files = Pathname.glob(Pathname.new(cpp_lib_path) + "test" + "*.cpp") - config.compilers_to_use.each do |compiler| - exe = @cpp_library.build_shared_library([], compiler, config.gcc_config("uno")) - expect(exe).not_to be nil - test_files.each do |path| - expected = path.basename.to_s.include?("good") + test_files.each do |path| + expected = path.basename.to_s.include?("good") + config.compilers_to_use.each do |compiler| it "tests #{File.basename(path)} with #{compiler} expecting #{expected}" do + exe = @cpp_library.build_shared_library([], compiler, config.gcc_config("uno")) + expect(exe).not_to be nil exe = @cpp_library.build_for_test(path, compiler) expect(exe).not_to be nil expect(@cpp_library.run_test_file(exe)).to eq(expected)