Skip to content
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

compiler: Add compiler flags $(...) patterns #510

Merged
merged 1 commit into from
Apr 13, 2023

Conversation

m-gorecki
Copy link
Contributor

@m-gorecki m-gorecki commented Feb 27, 2023

This adds the possibility to define and use $(...) patterns with
compiler flags. To do so you have to define new value in compiler's syscfg.yml
file, for example:

EXAMPLE_FLAGS:
value:"-my -compiler -flags"

Expression "$(EXAMPLE_FLAGS)" used in any compiler flags definition in compiler.yml will
be now replaced with the defined value (in this case whith "-my -compiler -flags").
It is also possible to override or add new patterns from other syscfg.yml files, for example
from some application's syscfg.yml

@m-gorecki m-gorecki force-pushed the flags-wildcards branch 2 times, most recently from 3253174 to 282ada3 Compare February 27, 2023 16:03
Copy link
Contributor

@andrzej-kaczmarek andrzej-kaczmarek left a comment

Choose a reason for hiding this comment

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

commit description is confusing - there are no wildcards used here, it just replaces syscfgs referenced using $(syscfgname) pattern with their values in compiler settings.


for i, flag := range c.lclInfo.Lflags {
if strings.Contains(flag, "$("+wildcard+")") {
c.lclInfo.Lflags[i] = strings.ReplaceAll(flag, "$("+wildcard+")", c.settings.Get(wildcard))
Copy link
Contributor

Choose a reason for hiding this comment

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

would be better to match all $(...) in string and then replace each with corresponding syscfg value. this also allows to emit an error if referenced syscfg does not exist.

@@ -260,6 +291,7 @@ func NewCompiler(compilerDir string, dstDir string,
dstDir: dstDir,
extraDeps: []string{},
compileCommands: []CompileCommand{},
settings: cfg,
Copy link
Contributor

Choose a reason for hiding this comment

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

pass directly to load(), no need to store it if not used in other places

@@ -332,6 +364,10 @@ func (c *Compiler) load(compilerDir string, buildProfile string) error {
c.lclInfo.Lflags = loadFlags(yc, settings, "compiler.ld.flags")
c.lclInfo.Aflags = loadFlags(yc, settings, "compiler.as.flags")

if c.settings != nil {
c.ReplaceWildcardFlags()
Copy link
Contributor

Choose a reason for hiding this comment

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

loadFlags() can handle it

@m-gorecki m-gorecki changed the title compiler: Add flags wildcard expressions compiler: Add compiler flags $(...) patterns Feb 28, 2023
for i, flag := range flags {
for _, c := range cfg.Names() {
if strings.Contains(flag, "$("+c+")") && cfg.Exists(c) {
flags[i] = strings.ReplaceAll(flag, "$("+c+")", cfg.Get(c))
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to iterate all syscfg names to find matches, use ReplaceAllStringFunc instead

This adds the possibility to define and use $(...) patterns with
compiler flags. To do so you have to define new value in compiler's syscfg.yml
file, for example:

EXAMPLE_FLAGS:
  value:"-my -compiler -flags"

Expression "$(EXAMPLE_FLAGS)" used in any compiler flags definition in compiler.yml will
be now replaced with the defined value (in this case whith "-my -compiler -flags").
It is also possible to override or add new patterns from other syscfg.yml files, for example
from some application's syscfg.yml
Copy link
Contributor

@andrzej-kaczmarek andrzej-kaczmarek left a comment

Choose a reason for hiding this comment

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

lgtm

@sjanc sjanc merged commit c7b9664 into apache:master Apr 13, 2023
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.

None yet

3 participants