Skip to content

Commit

Permalink
parser: add ability to configure system include paths
Browse files Browse the repository at this point in the history
  • Loading branch information
mpontillo authored and xlab committed Feb 26, 2024
1 parent 623b32c commit 2942bd1
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import (
)

type Config struct {
Arch string `yaml:"Arch"`
IncludePaths []string `yaml:"IncludePaths"`
SourcesPaths []string `yaml:"SourcesPaths"`
IgnoredPaths []string `yaml:"IgnoredPaths"`
Arch string `yaml:"Arch"`
IncludePaths []string `yaml:"IncludePaths"`
SysIncludePaths []string `yaml:"SysIncludePaths"`
SourcesPaths []string `yaml:"SourcesPaths"`
IgnoredPaths []string `yaml:"IgnoredPaths"`

Defines map[string]interface{} `yaml:"Defines"`

Expand Down Expand Up @@ -64,13 +65,17 @@ func ParseWith(cfg *Config) (*cc.AST, error) {
// if expanded, err := exec.LookPath(cppPath); err == nil {
// cppPath = expanded
// }
ccpredef, _, sysIncludePaths, err := hostCppConfig(cppPath)
ccpredef, includePaths, sysIncludePaths, err := hostCppConfig(cppPath)
if err != nil {
log.Println("[WARN] `cpp -dM` failed:", err)
} else {
if cfg.CCIncl && len(includePaths) > 0 {
// add on top of includePaths if allowed by config
cfg.IncludePaths = append(includePaths, cfg.IncludePaths...)
}
if cfg.CCIncl && len(sysIncludePaths) > 0 {
// add on top of sysIncludePaths if allowed by config
cfg.IncludePaths = append(sysIncludePaths, cfg.IncludePaths...)
cfg.SysIncludePaths = append(sysIncludePaths, cfg.SysIncludePaths...)
}
ccDefs = ccpredef
ccDefsOK = true
Expand All @@ -83,6 +88,7 @@ func ParseWith(cfg *Config) (*cc.AST, error) {
// Let cc provide all predefines and builtins. Only append custom definitions.
ccConfig.Predefined += predefined
ccConfig.IncludePaths = append(ccConfig.IncludePaths, cfg.IncludePaths...)
ccConfig.SysIncludePaths = append(ccConfig.SysIncludePaths, cfg.SysIncludePaths...)
var sources []cc.Source
sources = append(sources, cc.Source{Name: "<predefined>", Value: ccConfig.Predefined})
sources = append(sources, cc.Source{Name: "<builtin>", Value: cc.Builtin})
Expand Down

0 comments on commit 2942bd1

Please sign in to comment.