Skip to content

Commit

Permalink
fix(kconfig): Correctly execute shell commands in working directory
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Jung <[email protected]>
  • Loading branch information
nderjung committed Aug 21, 2024
1 parent 2f89be2 commit c321a9c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions kconfig/kconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func ParseData(data []byte, file string, extra ...*KeyValue) (*KConfigFile, erro
env[kcv.Key] = kcv
}
kp := &kconfigParser{
parser: newParser(data, file, env),
parser: newParser(data, filepath.Dir(file), file, env),
baseDir: filepath.Dir(file),
}

Expand Down Expand Up @@ -426,7 +426,7 @@ func (kp *kconfigParser) includeSource(file string) {
}

kp.includes = append(kp.includes, kp.parser)
kp.parser = newParser(data, file, kp.env)
kp.parser = newParser(data, kp.baseDir, file, kp.env)
kp.parseFile()
err = kp.err
kp.parser = kp.includes[len(kp.includes)-1]
Expand Down
11 changes: 7 additions & 4 deletions kconfig/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ type parser struct {
line int
err error
env KeyValueMap
baseDir string
}

func newParser(data []byte, file string, env KeyValueMap) *parser {
func newParser(data []byte, baseDir, file string, env KeyValueMap) *parser {
return &parser{
data: data,
file: file,
env: env,
data: data,
file: file,
env: env,
baseDir: baseDir,
}
}

Expand Down Expand Up @@ -211,6 +213,7 @@ func (p *parser) interpolate(b []byte) string {

var buf bytes.Buffer
cmd := exec.Command(args[0], args[1:]...)
cmd.Dir = p.baseDir
cmd.Stdout = bufio.NewWriter(&buf)
if err := cmd.Run(); err != nil {
p.failf("could not execute shell: %s", err.Error())
Expand Down

0 comments on commit c321a9c

Please sign in to comment.