Skip to content

Commit 38d54cb

Browse files
authored
Merge pull request #305 from bkryza/add-regex-in-remove-compile-flags
Added support for regular expressions in remove_compile_flags (#303)
2 parents 2f11e5f + f8435db commit 38d54cb

File tree

8 files changed

+40
-7
lines changed

8 files changed

+40
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# CHANGELOG
22

3+
* Added regular expression support to remove_compile_flags (#303)
4+
* Fixed repeated comments in sequence diagrams (#301)
35
* Added regular expression support to glob patterns (#299)
46
* Enabled relative link patterns in generate_links option (#297)
57
* Added advanced diagram filter config with anyof and allof operators (#289)

docs/common_options.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@ remove_compile_flags:
219219
- -I/usr/include
220220
```
221221
222+
`remove_compile_flags` also accepts regular expression, so a single entry can
223+
remove a whole set of flags, e.g.:
224+
225+
```yaml
226+
remove_compile_flags:
227+
- r: "-m.*"
228+
```
229+
222230
These options can be also passed on the command line, for instance:
223231

224232
```bash

docs/troubleshooting.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,9 @@ If this doesn't help to include paths can be customized using config options:
271271
* `add_compile_flags` - which adds a list of compile flags such as include paths
272272
to each entry of the compilation database
273273
* `remove_compile_flags` - which removes existing compile flags from each entry
274-
of the compilation database
274+
of the compilation database, it can be provided as a regular string that
275+
must match the entire flag or as an object with `r:` key, which can contain
276+
a regular expression that will match a set of flags
275277

276278
For instance:
277279

@@ -280,6 +282,7 @@ add_compile_flags:
280282
- -I/opt/my_toolchain/include
281283
remove_compile_flags:
282284
- -I/usr/include
285+
- r: "-m.*"
283286
```
284287

285288
These options can be also passed on the command line, for instance:

src/config/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ struct config : public inheritable_diagram_options {
759759
/*! List of compilation flags to be removed from the compilation
760760
* commands from database
761761
*/
762-
option<std::vector<std::string>> remove_compile_flags{
762+
option<std::vector<common::string_or_regex>> remove_compile_flags{
763763
"remove_compile_flags"};
764764

765765
/*! Extract include paths by executing specified compiler driver.

src/config/schema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ const std::string schema_str = R"(
339339
output_directory: !optional string
340340
query_driver: !optional string
341341
add_compile_flags: !optional [string]
342-
remove_compile_flags: !optional [string]
342+
remove_compile_flags: !optional [regex_or_string_t]
343343
allow_empty_diagrams: !optional bool
344344
diagram_templates: !optional diagram_templates_t
345345
diagrams: !required map_t<string;diagram_t>

tests/test_cases.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ std::pair<clanguml::config::config_ptr,
4444
clanguml::common::compilation_database_ptr>
4545
load_config(const std::string &test_name)
4646
{
47+
using clanguml::common::string_or_regex;
48+
4749
std::pair<clanguml::config::config_ptr,
4850
clanguml::common::compilation_database_ptr>
4951
res;
@@ -69,10 +71,11 @@ load_config(const std::string &test_name)
6971
LOG_DBG("Loading compilation database from {}",
7072
res.first->compilation_database_dir());
7173

72-
std::vector<std::string> remove_compile_flags{
73-
std::string{"-Wno-class-memaccess"},
74-
std::string{"-forward-unknown-to-host-compiler"},
75-
std::string{"--generate-code=arch=compute_75,code=[compute_75,sm_75]"}};
74+
std::vector<string_or_regex> remove_compile_flags{
75+
string_or_regex{"-Wno-class-memaccess"},
76+
string_or_regex{"-forward-unknown-to-host-compiler"},
77+
string_or_regex{
78+
std::regex{"--generate-code=.*"}, "--generate-code=.*"}};
7679

7780
res.first->remove_compile_flags.set(remove_compile_flags);
7881

tests/test_config.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,18 @@ TEST_CASE("Test config layout")
242242
clanguml::common::model::diagram_t::kPackage);
243243
}
244244

245+
TEST_CASE("Test add and remove compile flags options")
246+
{
247+
auto cfg = clanguml::config::load("./test_config_data/complete.yml");
248+
249+
REQUIRE(cfg.add_compile_flags().size() == 1);
250+
REQUIRE(cfg.add_compile_flags()[0] == "-fparse-all-comments");
251+
REQUIRE(cfg.remove_compile_flags().size() == 2);
252+
REQUIRE(cfg.remove_compile_flags()[0] == "-Werror");
253+
REQUIRE_FALSE(cfg.remove_compile_flags()[1] == "-Wwarning");
254+
REQUIRE(cfg.remove_compile_flags()[1] == "-march=amd64");
255+
}
256+
245257
TEST_CASE("Test config emitters")
246258
{
247259
auto cfg = clanguml::config::load("./test_config_data/complete.yml");

tests/test_config_data/complete.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ generate_links:
1212
link: "https://github.com/bkryza/clang-uml/blob/{{ git.commit }}/{{ element.source.path }}#L{{ element.source.line }}"
1313
# Tooltip pattern
1414
tooltip: "{{ element.name }}"
15+
add_compile_flags:
16+
- -fparse-all-comments
17+
remove_compile_flags:
18+
- -Werror
19+
- r: "-m.*"
1520
# The map of diagrams - keys are also diagram file names
1621
diagrams:
1722
config_class:

0 commit comments

Comments
 (0)