Skip to content

Commit 06b3c08

Browse files
m-goreckiandrzej-kaczmarek
authored andcommitted
Add ignored repositories list
This allows to specify a list of repositories names that will be ignored by upgrade command. The list should be placed inside project.yml file and look for example like this: project.repositories.ignored: - apache-mynewt-nimble - stm-cmsis_device_f3 - stm-stm32f3xx_hal_driver apache-mynewt-core repository can't be ignored.
1 parent 1686c67 commit 06b3c08

File tree

4 files changed

+44
-20
lines changed

4 files changed

+44
-20
lines changed

newt/builder/build.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -944,18 +944,9 @@ func (b *Builder) CleanArtifacts() {
944944
}
945945
}
946946

947-
func Contains(elements []string, val string) bool {
948-
for _, s := range elements {
949-
if val == s {
950-
return true
951-
}
952-
}
953-
return false
954-
}
955-
956947
func (b *Builder) AppendModifiedRepos(modifiedRepos []string) {
957948
for _, repo := range modifiedRepos {
958-
if !Contains(b.modifiedExtRepos, repo) {
949+
if !util.SliceContains(b.modifiedExtRepos, repo) {
959950
b.modifiedExtRepos = append(b.modifiedExtRepos, repo)
960951
}
961952
}

newt/project/project.go

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

73+
// Contains names of repositories that will not be upgraded/downloaded.
74+
reposIgnored []string
75+
7376
// The local repository at the top-level of the project. This repo is
7477
// excluded from most repo operations.
7578
localRepo *repo.Repo
@@ -188,7 +191,7 @@ func (proj *Project) GetPkgRepos() error {
188191
if pkg.PkgConfig().HasKey("repository") {
189192
for k, _ := range pkg.PkgConfig().AllSettings() {
190193
repoName := strings.TrimPrefix(k, "repository.")
191-
if repoName != k {
194+
if repoName != k && !util.SliceContains(proj.reposIgnored, repoName) {
192195
fields, err := pkg.PkgConfig().GetValStringMapString(k, nil)
193196
util.OneTimeWarningError(err)
194197

@@ -429,7 +432,7 @@ func (proj *Project) loadRepo(name string, fields map[string]string) (
429432
}
430433

431434
// Read the full repo definition from its `repository.yml` file.
432-
if err := r.Read(); err != nil {
435+
if err := r.Read(proj.reposIgnored); err != nil {
433436
return r, err
434437
}
435438

@@ -504,7 +507,7 @@ func (proj *Project) loadRepoDeps(download bool) error {
504507
newRepos = append(newRepos, depRepo)
505508

506509
if download {
507-
if _, err := depRepo.UpdateDesc(); err != nil {
510+
if _, err := depRepo.UpdateDesc(proj.reposIgnored); err != nil {
508511
return nil, err
509512
}
510513
}
@@ -539,7 +542,7 @@ func (proj *Project) downloadRepositoryYmlFiles() error {
539542
// specified in the `project.yml` file).
540543
for _, r := range proj.repos.Sorted() {
541544
if !r.IsLocal() && !r.IsExternal(r.Path()) {
542-
if _, err := r.UpdateDesc(); err != nil {
545+
if _, err := r.UpdateDesc(proj.reposIgnored); err != nil {
543546
return err
544547
}
545548
}
@@ -628,6 +631,15 @@ func (proj *Project) loadConfig(download bool) error {
628631
proj.name, err = yc.GetValString("project.name", nil)
629632
util.OneTimeWarningError(err)
630633

634+
proj.reposIgnored = make([]string, 0)
635+
proj.reposIgnored, err = yc.GetValStringSlice("project.repositories.ignored", nil)
636+
util.OneTimeWarningError(err)
637+
638+
if util.SliceContains(proj.reposIgnored, "apache-mynewt-core") {
639+
return util.NewNewtError("apache-mynewt-core repository can't be ignored. " +
640+
"Please remove it from the ignored repositories list.")
641+
}
642+
631643
// Local repository always included in initialization
632644
r, err := repo.NewLocalRepo(proj.name)
633645
if err != nil {
@@ -644,7 +656,7 @@ func (proj *Project) loadConfig(download bool) error {
644656
// and try to load it.
645657
for k, _ := range yc.AllSettings() {
646658
repoName := strings.TrimPrefix(k, "repository.")
647-
if repoName != k {
659+
if repoName != k && !util.SliceContains(proj.reposIgnored, repoName) {
648660
fields, err := yc.GetValStringMapString(k, nil)
649661
util.OneTimeWarningError(err)
650662

newt/repo/repo.go

Lines changed: 8 additions & 5 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() (bool, error) {
400+
func (r *Repo) UpdateDesc(reposIgnored []string) (bool, error) {
401401
if r.updated {
402402
return false, nil
403403
}
@@ -417,7 +417,7 @@ func (r *Repo) UpdateDesc() (bool, error) {
417417
}
418418

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

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

558-
func (r *Repo) readDepRepos(yc ycfg.YCfg) error {
558+
func (r *Repo) readDepRepos(yc ycfg.YCfg, reposIgnored []string) 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+
}
563566
rdm, err := parseRepoDepMap(depName, repoMapYml)
564567
if err != nil {
565568
return util.FmtNewtError(
@@ -577,7 +580,7 @@ func (r *Repo) readDepRepos(yc ycfg.YCfg) error {
577580

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

583586
yc, err := config.ReadFile(r.repoFilePath() + "/" + REPO_FILE_NAME)
@@ -604,7 +607,7 @@ func (r *Repo) Read() error {
604607
r.vers[vers] = commit
605608
}
606609

607-
if err := r.readDepRepos(yc); err != nil {
610+
if err := r.readDepRepos(yc, reposIgnored); err != nil {
608611
return err
609612
}
610613

util/util.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"os/exec"
3131
"os/signal"
3232
"path/filepath"
33+
"reflect"
3334
"runtime"
3435
"sort"
3536
"strconv"
@@ -1026,3 +1027,20 @@ func DirsAreEqual(dira string, dirb string) (bool, error) {
10261027

10271028
return true, nil
10281029
}
1030+
1031+
// Function that checks if the slice of any type contains a
1032+
// specified value
1033+
func SliceContains(slice interface{}, elem interface{}) bool {
1034+
s := reflect.ValueOf(slice)
1035+
1036+
if s.Kind() != reflect.Slice {
1037+
panic("SliceContains() called with non-slice type")
1038+
}
1039+
1040+
for i := 0; i < s.Len(); i++ {
1041+
if reflect.DeepEqual(s.Index(i).Interface(), elem) {
1042+
return true
1043+
}
1044+
}
1045+
return false
1046+
}

0 commit comments

Comments
 (0)