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

Make repos defined in project.yml implicitly allowed #575

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
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.

31 changes: 0 additions & 31 deletions .github/newt_upgrade/fail/core-not-allowed/project.yml

This file was deleted.

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
Loading