From 1ee342c18740e665b265cc81af346c9ee160c208 Mon Sep 17 00:00:00 2001 From: Ian Katz Date: Mon, 5 Apr 2021 00:00:25 -0400 Subject: [PATCH] Put build artifacts in temporary directories --- CHANGELOG.md | 1 + exe/arduino_ci.rb | 4 +++- lib/arduino_ci/cpp_library.rb | 23 +++++++++++------------ spec/cpp_library_spec.rb | 2 +- spec/testsomething_unittests_spec.rb | 2 +- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f161e1b7..8531167d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed - Update .gitattributes so we have consistent line endings - Test runner detects console width if possible, allowing variable width from 80-132 chars +- Unit test executables are now built as tempfiles ### Deprecated diff --git a/exe/arduino_ci.rb b/exe/arduino_ci.rb index 8c21761c..4abeaac2 100755 --- a/exe/arduino_ci.rb +++ b/exe/arduino_ci.rb @@ -439,7 +439,9 @@ def perform_unit_tests(cpp_library, config) puts cpp_library.last_err next false end - cpp_library.run_test_file(exe) + cpp_library.run_test_file(Pathname.new(exe.path)) + ensure + exe&.unlink end end end diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 0a9bac2e..c7736a40 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -23,9 +23,6 @@ class CppLibrary # @return [ArduinoBackend] The backend support for this library attr_reader :backend - # @return [Array] The set of artifacts created by this class (note: incomplete!) - attr_reader :artifacts - # @return [Array] The set of directories that should be excluded from compilation attr_reader :exclude_dirs @@ -50,7 +47,6 @@ def initialize(friendly_name, backend) @name = friendly_name @backend = backend @info_cache = nil - @artifacts = [] @last_err = "" @last_out = "" @last_msg = "" @@ -491,13 +487,13 @@ def test_args(aux_libraries, ci_gcc_config) # @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 + # @return [Tempfile] 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) + executable = Tempfile.new("unittest_#{base}.bin") + executable.close arg_sets = [] - arg_sets << ["-std=c++0x", "-o", executable.to_s, "-DARDUINO=100"] + arg_sets << ["-std=c++0x", "-o", executable.path, "-DARDUINO=100"] if libasan?(gcc_binary) arg_sets << [ # Stuff to help with dynamic memory mishandling "-g", "-O1", @@ -514,17 +510,20 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g 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) + unless run_gcc(gcc_binary, *args) + executable.unlink + return nil + end - artifacts << executable executable end # print any found stack dumps - # @param executable [Pathname] the path to the test file + # @param executable [Tempfile] the path to the test file def print_stack_dump(executable) + path = Pathname.new(executable.path) possible_dumpfiles = [ - executable.sub_ext("#{executable.extname}.stackdump") + path.sub_ext("#{path.extname}.stackdump") ] possible_dumpfiles.select(&:exist?).each do |dump| puts "========== Stack dump from #{dump}:" diff --git a/spec/cpp_library_spec.rb b/spec/cpp_library_spec.rb index 825c3650..c531cfd0 100644 --- a/spec/cpp_library_spec.rb +++ b/spec/cpp_library_spec.rb @@ -307,7 +307,7 @@ def verified_install(backend, path) it "tests #{File.basename(path)} with #{compiler} expecting #{expected}" do exe = @cpp_library.build_for_test_with_configuration(path, [], compiler, config.gcc_config("uno")) expect(exe).not_to be nil - expect(@cpp_library.run_test_file(exe)).to eq(expected) + expect(@cpp_library.run_test_file(Pathname.new(exe.path))).to eq(expected) end end end diff --git a/spec/testsomething_unittests_spec.rb b/spec/testsomething_unittests_spec.rb index 1f7bce72..2dbdf540 100644 --- a/spec/testsomething_unittests_spec.rb +++ b/spec/testsomething_unittests_spec.rb @@ -90,7 +90,7 @@ it "#{tfn} builds successfully and passes tests" do expect(@exe).not_to be nil - expect(@cpp_library.run_test_file(@exe)).to_not be_falsey + expect(@cpp_library.run_test_file(Pathname.new(@exe.path))).to_not be_falsey end end end