Skip to content

Commit 5a13f17

Browse files
m-goreckiandrzej-kaczmarek
authored andcommitted
Add allowed repositories list
This in addition to ignored repositories list allows to specify a list of repositories that will be upgraded. The list should be placed inside project.yml and look for example like this: project.repositories.allowed: - apache-mynewt-core - apache-mynewt-nimble - apache-mynewt-mcumgr - mcuboot - arm-CMSIS_5 - nordic-nrfx - mbedtls If the same repository will be placed on both lists, it will be ignored by newt. IMPORTANT NOTE: Ignored repositories will be ignored even if they were previously downloaded. So if repo was downloaded by newt upgrade and then added to ignored list, targets that depend on this repo won't build.
1 parent 966db46 commit 5a13f17

File tree

4 files changed

+56
-20
lines changed

4 files changed

+56
-20
lines changed

newt/deprepo/deprepo.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ func BuildDepGraph(repos RepoMap, rootReqs RequirementMap) (DepGraph, error) {
136136
reqMap := RequirementMap{}
137137
for _, d := range deps {
138138
depRepo := repos[d.Name]
139+
// This might be nil if d.Name is not on allowed repositories list
140+
if depRepo == nil {
141+
continue
142+
}
139143
verReqs, err := depRepo.NormalizeVerReq(d.VerReqs)
140144
if err != nil {
141145
return nil, err

newt/install/install.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ func (inst *Installer) ensureDepsInList(repos []*repo.Repo,
199199
}
200200
for _, d := range deps {
201201
depRepo := inst.repos[d.Name]
202+
// This might be nil if d.Name is not on allowed repositories list
203+
if depRepo == nil {
204+
continue
205+
}
202206
result = append(result, recurse(depRepo)...)
203207
}
204208

newt/project/project.go

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ type Project struct {
7070
// read.
7171
repos deprepo.RepoMap
7272

73-
// Contains names of repositories that will not be upgraded/downloaded.
73+
// Contains names of repositories that will be upgraded.
74+
// If it's empty all repos are allowed.
75+
reposAllowed []string
76+
77+
// Contains names of repositories that will be excluded from upgrade.
78+
// Can override repositories from reposAllowed.
7479
reposIgnored []string
7580

7681
// The local repository at the top-level of the project. This repo is
@@ -176,9 +181,16 @@ func NewProject(dir string, download bool) (*Project, error) {
176181
return proj, nil
177182
}
178183

179-
func (proj *Project) isRepoAdded(r *repo.Repo) bool {
184+
func (proj *Project) isRepoAllowed(repoName string) bool {
185+
if (len(proj.reposAllowed) == 0) || (util.SliceContains(proj.reposAllowed, repoName)) {
186+
return !util.SliceContains(proj.reposIgnored, repoName)
187+
}
188+
return false
189+
}
190+
191+
func (proj *Project) isRepoAdded(repoName string) bool {
180192
for _, pr := range proj.repos {
181-
if pr.Name() == r.Name() {
193+
if pr.Name() == repoName {
182194
return true
183195
}
184196
}
@@ -191,7 +203,7 @@ func (proj *Project) GetPkgRepos() error {
191203
if pkg.PkgConfig().HasKey("repository") {
192204
for k, _ := range pkg.PkgConfig().AllSettings() {
193205
repoName := strings.TrimPrefix(k, "repository.")
194-
if repoName != k && !util.SliceContains(proj.reposIgnored, repoName) {
206+
if repoName != k {
195207
fields, err := pkg.PkgConfig().GetValStringMapString(k, nil)
196208
util.OneTimeWarningError(err)
197209

@@ -203,6 +215,10 @@ func (proj *Project) GetPkgRepos() error {
203215
return err
204216
}
205217
}
218+
if r == nil {
219+
continue
220+
}
221+
206222
verReq, err := newtutil.ParseRepoVersion(fields["vers"])
207223
if err != nil {
208224
return util.FmtNewtError(
@@ -212,7 +228,7 @@ func (proj *Project) GetPkgRepos() error {
212228
}
213229
r.SetPkgName(pkg.Name())
214230

215-
if !proj.isRepoAdded(r) {
231+
if !proj.isRepoAdded(r.Name()) {
216232
if err := proj.addRepo(r, true); err != nil {
217233
return err
218234
}
@@ -405,7 +421,7 @@ func (proj *Project) InfoIf(predicate func(r *repo.Repo) bool,
405421
// @param name The name of the repo to read.
406422
// @param fields Fields containing the basic repo description.
407423
//
408-
// @return *Repo The fully-read repo on success; nil on failure.
424+
// @return *Repo The fully-read repo on success; nil on failure or when repo is not allowed
409425
// @return error Error on failure.
410426
func (proj *Project) loadRepo(name string, fields map[string]string) (
411427
*repo.Repo, error) {
@@ -427,12 +443,16 @@ func (proj *Project) loadRepo(name string, fields map[string]string) (
427443
return nil, err
428444
}
429445

446+
if !proj.isRepoAllowed(r.Name()) {
447+
return nil, nil
448+
}
449+
430450
for _, ignDir := range ignoreSearchDirs {
431451
r.AddIgnoreDir(ignDir)
432452
}
433453

434454
// Read the full repo definition from its `repository.yml` file.
435-
if err := r.Read(proj.reposIgnored); err != nil {
455+
if err := r.Read(); err != nil {
436456
return r, err
437457
}
438458

@@ -500,14 +520,17 @@ func (proj *Project) loadRepoDeps(download bool) error {
500520
return nil, err
501521
}
502522
}
523+
if depRepo == nil {
524+
continue
525+
}
503526
if err := proj.addRepo(depRepo, download); err != nil {
504527
return nil, err
505528
}
506529
}
507530
newRepos = append(newRepos, depRepo)
508531

509532
if download {
510-
if _, err := depRepo.UpdateDesc(proj.reposIgnored); err != nil {
533+
if _, err := depRepo.UpdateDesc(); err != nil {
511534
return nil, err
512535
}
513536
}
@@ -542,7 +565,7 @@ func (proj *Project) downloadRepositoryYmlFiles() error {
542565
// specified in the `project.yml` file).
543566
for _, r := range proj.repos.Sorted() {
544567
if !r.IsLocal() && !r.IsExternal(r.Path()) {
545-
if _, err := r.UpdateDesc(proj.reposIgnored); err != nil {
568+
if _, err := r.UpdateDesc(); err != nil {
546569
return err
547570
}
548571
}
@@ -631,14 +654,18 @@ func (proj *Project) loadConfig(download bool) error {
631654
proj.name, err = yc.GetValString("project.name", nil)
632655
util.OneTimeWarningError(err)
633656

657+
proj.reposAllowed = make([]string, 0)
658+
proj.reposAllowed, err = yc.GetValStringSlice("project.repositories.allowed", nil)
659+
util.OneTimeWarningError(err)
660+
634661
proj.reposIgnored = make([]string, 0)
635662
proj.reposIgnored, err = yc.GetValStringSlice("project.repositories.ignored", nil)
636663
util.OneTimeWarningError(err)
637664
proj.reposIgnored = append(proj.reposIgnored, newtutil.NewtIgnore...)
638665

639-
if util.SliceContains(proj.reposIgnored, "apache-mynewt-core") {
640-
return util.NewNewtError("apache-mynewt-core repository can't be ignored. " +
641-
"Please remove it from the ignored repositories list.")
666+
if !proj.isRepoAllowed("apache-mynewt-core") {
667+
return util.NewNewtError("apache-mynewt-core repository must be allowed. " +
668+
"Please add it to the allowed list and/or remove it from the ignored list.")
642669
}
643670

644671
// Local repository always included in initialization
@@ -669,6 +696,10 @@ func (proj *Project) loadConfig(download bool) error {
669696
return err
670697
}
671698
}
699+
if r == nil {
700+
continue
701+
}
702+
672703
verReq, err := newtutil.ParseRepoVersion(fields["vers"])
673704
if err != nil {
674705
return util.FmtNewtError(

newt/repo/repo.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ func (r *Repo) Upgrade(ver newtutil.RepoVersion) error {
397397
// from master. The repo object is then populated with the contents of the
398398
// downladed file. If this repo has already had its descriptor updated, this
399399
// function is a no-op.
400-
func (r *Repo) UpdateDesc(reposIgnored []string) (bool, error) {
400+
func (r *Repo) UpdateDesc() (bool, error) {
401401
if r.updated {
402402
return false, nil
403403
}
@@ -417,7 +417,7 @@ func (r *Repo) UpdateDesc(reposIgnored []string) (bool, error) {
417417
}
418418

419419
// Read `repository.yml` and populate this repo object.
420-
if err := r.Read(reposIgnored); err != nil {
420+
if err := r.Read(); err != nil {
421421
return false, err
422422
}
423423

@@ -555,14 +555,11 @@ func parseRepoDepMap(depName string,
555555
return result, nil
556556
}
557557

558-
func (r *Repo) readDepRepos(yc ycfg.YCfg, reposIgnored []string) error {
558+
func (r *Repo) readDepRepos(yc ycfg.YCfg) error {
559559
depMap, err := yc.GetValStringMap("repo.deps", nil)
560560
util.OneTimeWarningError(err)
561561

562562
for depName, repoMapYml := range depMap {
563-
if util.SliceContains(reposIgnored, depName) {
564-
continue
565-
}
566563
rdm, err := parseRepoDepMap(depName, repoMapYml)
567564
if err != nil {
568565
return util.FmtNewtError(
@@ -580,7 +577,7 @@ func (r *Repo) readDepRepos(yc ycfg.YCfg, reposIgnored []string) error {
580577

581578
// Reads a `repository.yml` file and populates the receiver repo with its
582579
// contents.
583-
func (r *Repo) Read(reposIgnored []string) error {
580+
func (r *Repo) Read() error {
584581
r.Init(r.Name(), r.downloader)
585582

586583
yc, err := config.ReadFile(r.repoFilePath() + "/" + REPO_FILE_NAME)
@@ -607,7 +604,7 @@ func (r *Repo) Read(reposIgnored []string) error {
607604
r.vers[vers] = commit
608605
}
609606

610-
if err := r.readDepRepos(yc, reposIgnored); err != nil {
607+
if err := r.readDepRepos(yc); err != nil {
611608
return err
612609
}
613610

0 commit comments

Comments
 (0)