Skip to content

Commit

Permalink
Make repos defined in project.yml implicitly allowed
Browse files Browse the repository at this point in the history
Repositories defined in project.yml should be allowed by default (even
if omitted on allowed list) unless ignored explicitly.
  • Loading branch information
andrzej-kaczmarek committed Oct 25, 2024
1 parent fa83de6 commit b48b874
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/newt_upgrade/allowed-ignored/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ arm-CMSIS_5
mcuboot
nordic-nrfx
stm-stm32g4xx_hal_driver
tinyusb
2 changes: 1 addition & 1 deletion .github/newt_upgrade/fail/core-ignored/expected.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Error: apache-mynewt-core repository must be allowed. Please add it to the allowed list and/or remove it from the ignored list.
Error: apache-mynewt-core repository cannot be on ignored list.
1 change: 0 additions & 1 deletion .github/newt_upgrade/fail/core-not-allowed/expected.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
apache-mynewt-core
apache-mynewt-nimble
30 changes: 21 additions & 9 deletions newt/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ func (proj *Project) patternsMatch(patterns *[]*regexp.Regexp, repoName string)
return false
}

func (proj *Project) isRepoIgnored(repoName string) bool {
return proj.patternsMatch(&proj.reposIgnoredRe, repoName)
}

func (proj *Project) isRepoAllowed(repoName string) bool {
if (len(proj.reposAllowedRe) == 0) || proj.patternsMatch(&proj.reposAllowedRe, repoName) {
return !proj.patternsMatch(&proj.reposIgnoredRe, repoName)
Expand Down Expand Up @@ -219,6 +223,10 @@ func (proj *Project) GetPkgRepos() error {
fields, err := pkg.PkgConfig().GetValStringMapString(k, nil)
util.OneTimeWarningError(err)

if !proj.isRepoAllowed(repoName) {
continue
}

r, err := proj.loadRepo(repoName, fields)
if err != nil {
// if `repository.yml` does not exist, it is not an error; we
Expand Down Expand Up @@ -437,10 +445,6 @@ func (proj *Project) InfoIf(predicate func(r *repo.Repo) bool,
// @return error Error on failure.
func (proj *Project) loadRepo(name string, fields map[string]string) (
*repo.Repo, error) {

if !proj.isRepoAllowed(name) {
return nil, nil
}
// First, read the repo description from the supplied fields.
if fields["type"] == "" {
return nil,
Expand Down Expand Up @@ -523,6 +527,11 @@ func (proj *Project) loadRepoDeps(download bool) error {
depRepo := proj.repos[dep.Name]
if depRepo == nil {
var err error

if !proj.isRepoAllowed(dep.Name) {
continue
}

depRepo, err = proj.loadRepo(dep.Name, dep.Fields)
if err != nil {
// if `repository.yml` does not exist, it is not an
Expand Down Expand Up @@ -720,18 +729,17 @@ func (proj *Project) loadConfig(download bool) error {

reposAllowed, err = yc.GetValStringSlice("project.repositories.allowed", nil)
util.OneTimeWarningError(err)
proj.reposAllowedRe, err = proj.createRegexpPatterns(reposAllowed)
proj.reposAllowedRe, err = proj.createRegexpPatterns(util.UniqueStrings(reposAllowed))
util.OneTimeWarningError(err)

reposIgnored, err = yc.GetValStringSlice("project.repositories.ignored", nil)
util.OneTimeWarningError(err)
reposIgnored = append(reposIgnored, newtutil.NewtIgnore...)
proj.reposIgnoredRe, err = proj.createRegexpPatterns(reposIgnored)
proj.reposIgnoredRe, err = proj.createRegexpPatterns(util.UniqueStrings(reposIgnored))
util.OneTimeWarningError(err)

if !proj.isRepoAllowed("apache-mynewt-core") {
return util.NewNewtError("apache-mynewt-core repository must be allowed. " +
"Please add it to the allowed list and/or remove it from the ignored list.")
if proj.isRepoIgnored("apache-mynewt-core") {
return util.NewNewtError("apache-mynewt-core repository cannot be on ignored list.")
}

// Local repository always included in initialization
Expand All @@ -754,6 +762,10 @@ func (proj *Project) loadConfig(download bool) error {
fields, err := yc.GetValStringMapString(k, nil)
util.OneTimeWarningError(err)

if proj.isRepoIgnored(repoName) {
continue
}

r, err := proj.loadRepo(repoName, fields)
if err != nil {
// if `repository.yml` does not exist, it is not an error; we
Expand Down

0 comments on commit b48b874

Please sign in to comment.