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

Use the subrepo's FS for reading config and globbing #2960

Merged
merged 3 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/core/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,7 @@
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
}

Check failure on line 70 in src/core/package.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/thought-machine/please) (gci)
// AddTarget adds a new target to this package with the given name.
// It doesn't check for duplicates.
func (pkg *Package) AddTarget(target *BuildTarget) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Could we do an if err here?

if err != nil {
return
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/subrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions src/parse/asp/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Loading