diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b0a152fa..1886d5ec8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # CHANGELOG + * Added regular expression support to remove_compile_flags (#303) + * Fixed repeated comments in sequence diagrams (#301) * Added regular expression support to glob patterns (#299) * Enabled relative link patterns in generate_links option (#297) * Added advanced diagram filter config with anyof and allof operators (#289) diff --git a/docs/common_options.md b/docs/common_options.md index 175295829..1fd89c6ac 100644 --- a/docs/common_options.md +++ b/docs/common_options.md @@ -219,6 +219,14 @@ remove_compile_flags: - -I/usr/include ``` +`remove_compile_flags` also accepts regular expression, so a single entry can +remove a whole set of flags, e.g.: + +```yaml +remove_compile_flags: + - r: "-m.*" +``` + These options can be also passed on the command line, for instance: ```bash diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 801798f36..d4bb11085 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -271,7 +271,9 @@ If this doesn't help to include paths can be customized using config options: * `add_compile_flags` - which adds a list of compile flags such as include paths to each entry of the compilation database * `remove_compile_flags` - which removes existing compile flags from each entry - of the compilation database + of the compilation database, it can be provided as a regular string that + must match the entire flag or as an object with `r:` key, which can contain + a regular expression that will match a set of flags For instance: @@ -280,6 +282,7 @@ add_compile_flags: - -I/opt/my_toolchain/include remove_compile_flags: - -I/usr/include + - r: "-m.*" ``` These options can be also passed on the command line, for instance: diff --git a/src/config/config.h b/src/config/config.h index 94b9a77ac..67f3dd006 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -759,7 +759,7 @@ struct config : public inheritable_diagram_options { /*! List of compilation flags to be removed from the compilation * commands from database */ - option> remove_compile_flags{ + option> remove_compile_flags{ "remove_compile_flags"}; /*! Extract include paths by executing specified compiler driver. diff --git a/src/config/schema.h b/src/config/schema.h index a90f7cdbd..1f8bb767f 100644 --- a/src/config/schema.h +++ b/src/config/schema.h @@ -339,7 +339,7 @@ const std::string schema_str = R"( output_directory: !optional string query_driver: !optional string add_compile_flags: !optional [string] - remove_compile_flags: !optional [string] + remove_compile_flags: !optional [regex_or_string_t] allow_empty_diagrams: !optional bool diagram_templates: !optional diagram_templates_t diagrams: !required map_t diff --git a/tests/test_cases.cc b/tests/test_cases.cc index 16560ef8d..59c5779de 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -44,6 +44,8 @@ std::pair load_config(const std::string &test_name) { + using clanguml::common::string_or_regex; + std::pair res; @@ -69,10 +71,11 @@ load_config(const std::string &test_name) LOG_DBG("Loading compilation database from {}", res.first->compilation_database_dir()); - std::vector remove_compile_flags{ - std::string{"-Wno-class-memaccess"}, - std::string{"-forward-unknown-to-host-compiler"}, - std::string{"--generate-code=arch=compute_75,code=[compute_75,sm_75]"}}; + std::vector remove_compile_flags{ + string_or_regex{"-Wno-class-memaccess"}, + string_or_regex{"-forward-unknown-to-host-compiler"}, + string_or_regex{ + std::regex{"--generate-code=.*"}, "--generate-code=.*"}}; res.first->remove_compile_flags.set(remove_compile_flags); diff --git a/tests/test_config.cc b/tests/test_config.cc index 1c0d073d6..5b5132cee 100644 --- a/tests/test_config.cc +++ b/tests/test_config.cc @@ -242,6 +242,18 @@ TEST_CASE("Test config layout") clanguml::common::model::diagram_t::kPackage); } +TEST_CASE("Test add and remove compile flags options") +{ + auto cfg = clanguml::config::load("./test_config_data/complete.yml"); + + REQUIRE(cfg.add_compile_flags().size() == 1); + REQUIRE(cfg.add_compile_flags()[0] == "-fparse-all-comments"); + REQUIRE(cfg.remove_compile_flags().size() == 2); + REQUIRE(cfg.remove_compile_flags()[0] == "-Werror"); + REQUIRE_FALSE(cfg.remove_compile_flags()[1] == "-Wwarning"); + REQUIRE(cfg.remove_compile_flags()[1] == "-march=amd64"); +} + TEST_CASE("Test config emitters") { auto cfg = clanguml::config::load("./test_config_data/complete.yml"); diff --git a/tests/test_config_data/complete.yml b/tests/test_config_data/complete.yml index 727e103ac..b0a96a229 100644 --- a/tests/test_config_data/complete.yml +++ b/tests/test_config_data/complete.yml @@ -12,6 +12,11 @@ generate_links: link: "https://github.com/bkryza/clang-uml/blob/{{ git.commit }}/{{ element.source.path }}#L{{ element.source.line }}" # Tooltip pattern tooltip: "{{ element.name }}" +add_compile_flags: + - -fparse-all-comments +remove_compile_flags: + - -Werror + - r: "-m.*" # The map of diagrams - keys are also diagram file names diagrams: config_class: