-
Notifications
You must be signed in to change notification settings - Fork 93
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
Conversation
3253174
to
282ada3
Compare
There was a problem hiding this 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.
newt/toolchain/compiler.go
Outdated
|
||
for i, flag := range c.lclInfo.Lflags { | ||
if strings.Contains(flag, "$("+wildcard+")") { | ||
c.lclInfo.Lflags[i] = strings.ReplaceAll(flag, "$("+wildcard+")", c.settings.Get(wildcard)) |
There was a problem hiding this comment.
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.
newt/toolchain/compiler.go
Outdated
@@ -260,6 +291,7 @@ func NewCompiler(compilerDir string, dstDir string, | |||
dstDir: dstDir, | |||
extraDeps: []string{}, | |||
compileCommands: []CompileCommand{}, | |||
settings: cfg, |
There was a problem hiding this comment.
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
newt/toolchain/compiler.go
Outdated
@@ -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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loadFlags()
can handle it
282ada3
to
48a3b12
Compare
48a3b12
to
455cc4d
Compare
newt/toolchain/compiler.go
Outdated
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)) |
There was a problem hiding this comment.
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
455cc4d
to
496741f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
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