Skip to content

include ability to exclude certain directories from compilation #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2019

Conversation

dolfandringa
Copy link
Contributor

Exclude certain directories from exclusion in compilation

  • Add exclude_dirs option to [unittest] section in configuration file
  • Add a filter in ArduinoCI::CppLibrary to filter out the files in directories specified there
  • Adjust unittests to take the new feature into account

Issues Fixed

@dolfandringa dolfandringa changed the title #29 include ability to exclude certain directories from compilation include ability to exclude certain directories from compilation Jul 27, 2019
@ianfixes
Copy link
Collaborator

ianfixes commented Jul 28, 2019

I want to sleep on this but I still want to help you with the problem you described in #29 . Can we resolve that first (changing directories) and then resume here?

Immediate thoughts on this PR:

  • Overall, I like it and I like your addition to the config file
  • It looks like you're trying to add some directories (excludeThis) that, if included, would break the build and/or break the tests. Some more explicit documentation around that would be helpful
  • I'm nervous about the change to CppLibrary; I think that rather than array, this should probably accept some kind of block that selects/rejects files from the library. But I have to think more about that.
  • Needs unit tests

@dolfandringa
Copy link
Contributor Author

dolfandringa commented Jul 29, 2019

@ianfixes The feature request of #29 is about excluding directories from the tree walk process when looking for CPP files. That is exactly what this ticket addresses. It so happens, that with that addition, my use-case is actually solved. I don't need to make separate arduino_ci installations for each library. My working demo is on https://github.com/dolfandringa/Bare-Arduino-Project

I modified the tests so they explicitly test my new feature. Without my feature, the tests would fail because "excludeThis" contains code that would make the compilation fail.
Also in spec/testsomething_unittests_spec.rb the cpp_files test in TestSomething C++ has specifically been adjusted to test that the files in the 'excludeThis' folder are excluded from compilation. Without my feature, this test would now fail. The only thing I can think to change is to duplicate that test, once with, and once without the exclude_dirs parameter. Right now it's one combined test.

Documentation: I adjusted the README.md to document the feature. What else should I document?

raise ArgumentError, 'base_dir is not a Pathname' unless base_dir.is_a? Pathname
raise ArgumentError, 'arduino_lib_dir is not a Pathname' unless arduino_lib_dir.is_a? Pathname
raise ArgumentError, 'exclude_dir is not an array of Pathnames' unless exclude_dirs.is_a?(Array) &&
exclude_dirs.each { |p| p.is_a? Pathname }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be .all?, not .each.

int* aNullPointer(void) {
int* ret = nullptr;
return ret;
}
Copy link
Collaborator

@ianfixes ianfixes Aug 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contents of this directory appear to be a simple copy of files that already exist elsewhere in this project.

If the purpose of this file (and the .h) is just to cause some form of compilation error, I'd prefer that its contents speak entirely to that. Just fill it with a syntax error in the form of

This file was placed here specifically to break unit test compilation.  
If arduino_ci is working properly, it should exclude this file (as per 
the .arduino-ci.yml configuration) and compilation should succeed. 

And name it something like break-compilation.cpp.

cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path, Pathname.new("my_fake_arduino_lib_dir"))
cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path,
Pathname.new("my_fake_arduino_lib_dir"),
["excludeThis"])
Copy link
Collaborator

@ianfixes ianfixes Aug 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace ["excludeThis"] with [], or add tests to the spec file that specifically refer to the excludeThis directory and/or the files it contains.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To say this another way: I assume ["excludeThis"] prevents a regression on the existing tests in this spec file. That's fine, but you should add a different test section that shows that without excluding a directory, cpp_library.cpp_files contains the extra files.

The easiest way I can think of would be to give each context section its own cpp_library = line, instead of using a common one.

  context "cpp_files without an exclude directory" do
    cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path, 
                                            Pathname.new("my_fake_arduino_lib_dir"),
                                            [])
    it "finds all cpp files in directory" do
      testsomething_cpp_files = [
        Pathname.new("TestSomething/test-something.cpp"),
        Pathname.new("TestSomething/excludeThis/break-compilation.cpp"),
      ]
      relative_paths = cpp_library.cpp_files.map { |f| get_relative_dir(f) }
      expect(relative_paths).to match_array(testsomething_cpp_files)
    end
  end

  context "cpp_files with an exclude directory" do
    cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path, 
                                            Pathname.new("my_fake_arduino_lib_dir"),
                                            ["excludeThis"])
    it "finds cpp files in directory and ignores some" do
      testsomething_cpp_files = [Pathname.new("TestSomething/test-something.cpp")]
      relative_paths = cpp_library.cpp_files.map { |f| get_relative_dir(f) }
      expect(relative_paths).to match_array(testsomething_cpp_files)
    end
  end

  context "unit tests" do
    cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path, 
                                            Pathname.new("my_fake_arduino_lib_dir"),
                                            ["excludeThis"])

@@ -37,11 +37,14 @@ class CppLibrary

# @param base_dir [Pathname] The path to the library being tested
# @param arduino_lib_dir [Pathname] The path to the libraries directory
def initialize(base_dir, arduino_lib_dir)
def initialize(base_dir, arduino_lib_dir, exclude_dirs = [])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exclude_dirs should not be an optional argument here. You'll need update all instances of CppLibrary.new (i.e. the spec files) to explicitly pass in the empty array.

@ianfixes
Copy link
Collaborator

ianfixes commented Aug 7, 2019

Thanks for contributing this, and I appreciate the attention you've paid to copying the existing style of the project. I have a few small fixes to request, and then this is good to merge.

@ianfixes ianfixes changed the base branch from master to develop August 15, 2019 11:26
@ianfixes
Copy link
Collaborator

Merging to non-master branch as my requested edits are easy to make myself

@ianfixes ianfixes merged commit f03bea2 into Arduino-CI:develop Aug 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants