Skip to content

Commit 5683991

Browse files
committed
Put build artifacts in temporary directories
1 parent 32196ac commit 5683991

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
### Changed
1515
- Update .gitattributes so we have consistent line endings
1616
- Test runner detects console width if possible, allowing variable width from 80-132 chars
17+
- Unit test executables are now built as tempfiles
1718

1819
### Deprecated
1920

Diff for: exe/arduino_ci.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,9 @@ def perform_unit_tests(cpp_library, config)
439439
puts cpp_library.last_err
440440
next false
441441
end
442-
cpp_library.run_test_file(exe)
442+
cpp_library.run_test_file(exe.path)
443+
ensure
444+
exe.unlink unless exe.nil?
443445
end
444446
end
445447
end

Diff for: lib/arduino_ci/cpp_library.rb

+8-10
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ class CppLibrary
2323
# @return [ArduinoBackend] The backend support for this library
2424
attr_reader :backend
2525

26-
# @return [Array<Pathname>] The set of artifacts created by this class (note: incomplete!)
27-
attr_reader :artifacts
28-
2926
# @return [Array<Pathname>] The set of directories that should be excluded from compilation
3027
attr_reader :exclude_dirs
3128

@@ -50,7 +47,6 @@ def initialize(friendly_name, backend)
5047
@name = friendly_name
5148
@backend = backend
5249
@info_cache = nil
53-
@artifacts = []
5450
@last_err = ""
5551
@last_out = ""
5652
@last_msg = ""
@@ -491,13 +487,13 @@ def test_args(aux_libraries, ci_gcc_config)
491487
# @param test_file [Pathname] The path to the file containing the unit tests
492488
# @param aux_libraries [Array<Pathname>] The external Arduino libraries required by this project
493489
# @param ci_gcc_config [Hash] The GCC config object
494-
# @return [Pathname] path to the compiled test executable
490+
# @return [Tempfile] the compiled test executable
495491
def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_gcc_config)
496492
base = test_file.basename
497-
executable = Pathname.new("unittest_#{base}.bin").expand_path
498-
File.delete(executable) if File.exist?(executable)
493+
executable = Tempfile.new("unittest_#{base}.bin")
494+
executable.close
499495
arg_sets = []
500-
arg_sets << ["-std=c++0x", "-o", executable.to_s, "-DARDUINO=100"]
496+
arg_sets << ["-std=c++0x", "-o", executable.path, "-DARDUINO=100"]
501497
if libasan?(gcc_binary)
502498
arg_sets << [ # Stuff to help with dynamic memory mishandling
503499
"-g", "-O1",
@@ -514,9 +510,11 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g
514510
arg_sets << cpp_files_libraries(full_dependencies).map(&:to_s)
515511
arg_sets << [test_file.to_s]
516512
args = arg_sets.flatten(1)
517-
return nil unless run_gcc(gcc_binary, *args)
513+
unless run_gcc(gcc_binary, *args)
514+
executable.unlink
515+
return nil
516+
end
518517

519-
artifacts << executable
520518
executable
521519
end
522520

Diff for: spec/cpp_library_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def verified_install(backend, path)
307307
it "tests #{File.basename(path)} with #{compiler} expecting #{expected}" do
308308
exe = @cpp_library.build_for_test_with_configuration(path, [], compiler, config.gcc_config("uno"))
309309
expect(exe).not_to be nil
310-
expect(@cpp_library.run_test_file(exe)).to eq(expected)
310+
expect(@cpp_library.run_test_file(exe.path)).to eq(expected)
311311
end
312312
end
313313
end

Diff for: spec/testsomething_unittests_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090

9191
it "#{tfn} builds successfully and passes tests" do
9292
expect(@exe).not_to be nil
93-
expect(@cpp_library.run_test_file(@exe)).to_not be_falsey
93+
expect(@cpp_library.run_test_file(@exe.path)).to_not be_falsey
9494
end
9595
end
9696
end

0 commit comments

Comments
 (0)