Skip to content

Commit

Permalink
Added support for regular expressions in remove_compile_flags (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkryza committed Aug 14, 2024
1 parent 2f11e5f commit f8435db
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
8 changes: 8 additions & 0 deletions docs/common_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ struct config : public inheritable_diagram_options {
/*! List of compilation flags to be removed from the compilation
* commands from database
*/
option<std::vector<std::string>> remove_compile_flags{
option<std::vector<common::string_or_regex>> remove_compile_flags{
"remove_compile_flags"};

/*! Extract include paths by executing specified compiler driver.
Expand Down
2 changes: 1 addition & 1 deletion src/config/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<string;diagram_t>
Expand Down
11 changes: 7 additions & 4 deletions tests/test_cases.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ std::pair<clanguml::config::config_ptr,
clanguml::common::compilation_database_ptr>
load_config(const std::string &test_name)
{
using clanguml::common::string_or_regex;

std::pair<clanguml::config::config_ptr,
clanguml::common::compilation_database_ptr>
res;
Expand All @@ -69,10 +71,11 @@ load_config(const std::string &test_name)
LOG_DBG("Loading compilation database from {}",
res.first->compilation_database_dir());

std::vector<std::string> 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<string_or_regex> 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);

Expand Down
12 changes: 12 additions & 0 deletions tests/test_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
5 changes: 5 additions & 0 deletions tests/test_config_data/complete.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f8435db

Please sign in to comment.