From 5f1eb0da07876f2506b39162b2b34df043841216 Mon Sep 17 00:00:00 2001 From: Jon Poole Date: Wed, 15 Nov 2023 13:12:35 +0000 Subject: [PATCH 1/3] Use the subrepo's FS for reading config --- src/core/state.go | 2 +- src/core/subrepo.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/state.go b/src/core/state.go index 71367d139a..ee401a7510 100644 --- a/src/core/state.go +++ b/src/core/state.go @@ -255,7 +255,7 @@ func (state *BuildState) Initialise(subrepo *Subrepo) (err error) { // handled for us already in plz.go if state.CurrentSubrepo != "" { state.RepoConfig = &Configuration{} - err = readConfigFilesInto(state.RepoConfig, append(subrepo.AdditionalConfigFiles, filepath.Join(subrepo.Root, ".plzconfig"))) + err = readSubrepoConfig(state.RepoConfig, subrepo) if err != nil { return } diff --git a/src/core/subrepo.go b/src/core/subrepo.go index bd5831239f..a033186ba6 100644 --- a/src/core/subrepo.go +++ b/src/core/subrepo.go @@ -81,14 +81,14 @@ func (s *Subrepo) Dir(dir string) string { return filepath.Join(s.Root, dir) } -func readConfigFilesInto(repoConfig *Configuration, files []string) error { - for _, file := range files { +func readSubrepoConfig(repoConfig *Configuration, subrepo *Subrepo) error { + for _, file := range subrepo.AdditionalConfigFiles { err := readConfigFile(fs.HostFS, repoConfig, file, true) if err != nil { return err } } - return nil + return readConfigFile(subrepo.FS, repoConfig, ".plzconfig", true) } func validateSubrepoNameAndPluginConfig(config, repoConfig *Configuration, subrepo *Subrepo) error { From 21ad65650083c946e9e48aed18b06babe36ee31f Mon Sep 17 00:00:00 2001 From: Jon Poole Date: Wed, 15 Nov 2023 13:32:17 +0000 Subject: [PATCH 2/3] Use subrepo FS for glob() --- src/core/package.go | 8 -------- src/parse/asp/builtins.go | 8 ++++++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/core/package.go b/src/core/package.go index 3786586e93..dac2270147 100644 --- a/src/core/package.go +++ b/src/core/package.go @@ -67,14 +67,6 @@ func (pkg *Package) TargetOrDie(name string) *BuildTarget { return t } -// SourceRoot returns the root directory of source files for this package. -// This is equivalent to .Name for in-repo packages but differs for those in subrepos. -func (pkg *Package) SourceRoot() string { - if pkg.Subrepo != nil { - return pkg.Subrepo.Dir(pkg.Name) - } - return pkg.Name -} // AddTarget adds a new target to this package with the given name. // It doesn't check for duplicates. diff --git a/src/parse/asp/builtins.go b/src/parse/asp/builtins.go index b31e43c5db..f33b715710 100644 --- a/src/parse/asp/builtins.go +++ b/src/parse/asp/builtins.go @@ -607,10 +607,14 @@ func glob(s *scope, args []pyObject) pyObject { allowEmpty := args[4].IsTruthy() exclude = append(exclude, s.state.Config.Parse.BuildFileName...) if s.globber == nil { - s.globber = fs.NewGlobber(fs.HostFS, s.state.Config.Parse.BuildFileName) + if s.pkg.Subrepo != nil { + s.globber = fs.NewGlobber(s.pkg.Subrepo.FS, s.state.Config.Parse.BuildFileName) + } else { + s.globber = fs.NewGlobber(fs.HostFS, s.state.Config.Parse.BuildFileName) + } } - glob := s.globber.Glob(s.pkg.SourceRoot(), include, exclude, hidden, includeSymlinks) + glob := s.globber.Glob(s.pkg.Name, include, exclude, hidden, includeSymlinks) if !allowEmpty && len(glob) == 0 { // Strip build file name from exclude list for error message exclude = exclude[:len(exclude)-len(s.state.Config.Parse.BuildFileName)] From 026b74ae228ba949f8d6fd6113641f4601018a5a Mon Sep 17 00:00:00 2001 From: Jon Poole Date: Wed, 15 Nov 2023 14:26:03 +0000 Subject: [PATCH 3/3] Fix architecture subrepos --- src/core/package.go | 1 - src/core/state.go | 3 +-- src/core/subrepo.go | 7 ++++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/core/package.go b/src/core/package.go index dac2270147..93c9a85c6c 100644 --- a/src/core/package.go +++ b/src/core/package.go @@ -67,7 +67,6 @@ func (pkg *Package) TargetOrDie(name string) *BuildTarget { return t } - // AddTarget adds a new target to this package with the given name. // It doesn't check for duplicates. func (pkg *Package) AddTarget(target *BuildTarget) { diff --git a/src/core/state.go b/src/core/state.go index ee401a7510..3f9490eb56 100644 --- a/src/core/state.go +++ b/src/core/state.go @@ -255,8 +255,7 @@ func (state *BuildState) Initialise(subrepo *Subrepo) (err error) { // handled for us already in plz.go if state.CurrentSubrepo != "" { state.RepoConfig = &Configuration{} - err = readSubrepoConfig(state.RepoConfig, subrepo) - if err != nil { + if err := readSubrepoConfig(state.RepoConfig, subrepo); err != nil { return } if err = validateSubrepoNameAndPluginConfig(state.Config, state.RepoConfig, subrepo); err != nil { diff --git a/src/core/subrepo.go b/src/core/subrepo.go index a033186ba6..3bb4445a97 100644 --- a/src/core/subrepo.go +++ b/src/core/subrepo.go @@ -36,10 +36,15 @@ type Subrepo struct { } func NewSubrepo(state *BuildState, name, root string, target *BuildTarget, arch cli.Arch, isCrosscompile bool) *Subrepo { + subrepoFS := os.DirFS(root) + if root == "" { + // This happens for architecture subrepos, which should use the same FS as the host repo + subrepoFS = fs.HostFS + } return &Subrepo{ Name: name, Root: root, - FS: os.DirFS(root), + FS: subrepoFS, State: state, Target: target, Arch: arch,