This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git
The following commit(s) were added to refs/heads/master by this push:
new 06b3c08a Add ignored repositories list
06b3c08a is described below
commit 06b3c08a7fe2187584b491b4f3fb36792c07aac4
Author: Michal Gorecki <[email protected]>
AuthorDate: Mon May 13 15:28:43 2024 +0200
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.
---
newt/builder/build.go | 11 +----------
newt/project/project.go | 22 +++++++++++++++++-----
newt/repo/repo.go | 13 ++++++++-----
util/util.go | 18 ++++++++++++++++++
4 files changed, 44 insertions(+), 20 deletions(-)
diff --git a/newt/builder/build.go b/newt/builder/build.go
index 287ef0b2..6ce3fb4c 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -944,18 +944,9 @@ func (b *Builder) CleanArtifacts() {
}
}
-func Contains(elements []string, val string) bool {
- for _, s := range elements {
- if val == s {
- return true
- }
- }
- return false
-}
-
func (b *Builder) AppendModifiedRepos(modifiedRepos []string) {
for _, repo := range modifiedRepos {
- if !Contains(b.modifiedExtRepos, repo) {
+ if !util.SliceContains(b.modifiedExtRepos, repo) {
b.modifiedExtRepos = append(b.modifiedExtRepos, repo)
}
}
diff --git a/newt/project/project.go b/newt/project/project.go
index b285e664..e4f4bae9 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -70,6 +70,9 @@ type Project struct {
// read.
repos deprepo.RepoMap
+ // Contains names of repositories that will not be upgraded/downloaded.
+ reposIgnored []string
+
// The local repository at the top-level of the project. This repo is
// excluded from most repo operations.
localRepo *repo.Repo
@@ -188,7 +191,7 @@ func (proj *Project) GetPkgRepos() error {
if pkg.PkgConfig().HasKey("repository") {
for k, _ := range pkg.PkgConfig().AllSettings()
{
repoName := strings.TrimPrefix(k,
"repository.")
- if repoName != k {
+ if repoName != k &&
!util.SliceContains(proj.reposIgnored, repoName) {
fields, err :=
pkg.PkgConfig().GetValStringMapString(k, nil)
util.OneTimeWarningError(err)
@@ -429,7 +432,7 @@ func (proj *Project) loadRepo(name string, fields
map[string]string) (
}
// Read the full repo definition from its `repository.yml` file.
- if err := r.Read(); err != nil {
+ if err := r.Read(proj.reposIgnored); err != nil {
return r, err
}
@@ -504,7 +507,7 @@ func (proj *Project) loadRepoDeps(download bool) error {
newRepos = append(newRepos, depRepo)
if download {
- if _, err :=
depRepo.UpdateDesc(); err != nil {
+ if _, err :=
depRepo.UpdateDesc(proj.reposIgnored); err != nil {
return nil, err
}
}
@@ -539,7 +542,7 @@ func (proj *Project) downloadRepositoryYmlFiles() error {
// specified in the `project.yml` file).
for _, r := range proj.repos.Sorted() {
if !r.IsLocal() && !r.IsExternal(r.Path()) {
- if _, err := r.UpdateDesc(); err != nil {
+ if _, err := r.UpdateDesc(proj.reposIgnored); err !=
nil {
return err
}
}
@@ -628,6 +631,15 @@ func (proj *Project) loadConfig(download bool) error {
proj.name, err = yc.GetValString("project.name", nil)
util.OneTimeWarningError(err)
+ proj.reposIgnored = make([]string, 0)
+ proj.reposIgnored, err =
yc.GetValStringSlice("project.repositories.ignored", nil)
+ util.OneTimeWarningError(err)
+
+ if util.SliceContains(proj.reposIgnored, "apache-mynewt-core") {
+ return util.NewNewtError("apache-mynewt-core repository can't
be ignored. " +
+ "Please remove it from the ignored repositories list.")
+ }
+
// Local repository always included in initialization
r, err := repo.NewLocalRepo(proj.name)
if err != nil {
@@ -644,7 +656,7 @@ func (proj *Project) loadConfig(download bool) error {
// and try to load it.
for k, _ := range yc.AllSettings() {
repoName := strings.TrimPrefix(k, "repository.")
- if repoName != k {
+ if repoName != k && !util.SliceContains(proj.reposIgnored,
repoName) {
fields, err := yc.GetValStringMapString(k, nil)
util.OneTimeWarningError(err)
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index 79165671..b5f6c1c0 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -397,7 +397,7 @@ func (r *Repo) Upgrade(ver newtutil.RepoVersion) error {
// from master. The repo object is then populated with the contents of the
// downladed file. If this repo has already had its descriptor updated, this
// function is a no-op.
-func (r *Repo) UpdateDesc() (bool, error) {
+func (r *Repo) UpdateDesc(reposIgnored []string) (bool, error) {
if r.updated {
return false, nil
}
@@ -417,7 +417,7 @@ func (r *Repo) UpdateDesc() (bool, error) {
}
// Read `repository.yml` and populate this repo object.
- if err := r.Read(); err != nil {
+ if err := r.Read(reposIgnored); err != nil {
return false, err
}
@@ -555,11 +555,14 @@ func parseRepoDepMap(depName string,
return result, nil
}
-func (r *Repo) readDepRepos(yc ycfg.YCfg) error {
+func (r *Repo) readDepRepos(yc ycfg.YCfg, reposIgnored []string) error {
depMap, err := yc.GetValStringMap("repo.deps", nil)
util.OneTimeWarningError(err)
for depName, repoMapYml := range depMap {
+ if util.SliceContains(reposIgnored, depName) {
+ continue
+ }
rdm, err := parseRepoDepMap(depName, repoMapYml)
if err != nil {
return util.FmtNewtError(
@@ -577,7 +580,7 @@ func (r *Repo) readDepRepos(yc ycfg.YCfg) error {
// Reads a `repository.yml` file and populates the receiver repo with its
// contents.
-func (r *Repo) Read() error {
+func (r *Repo) Read(reposIgnored []string) error {
r.Init(r.Name(), r.downloader)
yc, err := config.ReadFile(r.repoFilePath() + "/" + REPO_FILE_NAME)
@@ -604,7 +607,7 @@ func (r *Repo) Read() error {
r.vers[vers] = commit
}
- if err := r.readDepRepos(yc); err != nil {
+ if err := r.readDepRepos(yc, reposIgnored); err != nil {
return err
}
diff --git a/util/util.go b/util/util.go
index 5823762a..b1b2101f 100644
--- a/util/util.go
+++ b/util/util.go
@@ -30,6 +30,7 @@ import (
"os/exec"
"os/signal"
"path/filepath"
+ "reflect"
"runtime"
"sort"
"strconv"
@@ -1026,3 +1027,20 @@ func DirsAreEqual(dira string, dirb string) (bool,
error) {
return true, nil
}
+
+// Function that checks if the slice of any type contains a
+// specified value
+func SliceContains(slice interface{}, elem interface{}) bool {
+ s := reflect.ValueOf(slice)
+
+ if s.Kind() != reflect.Slice {
+ panic("SliceContains() called with non-slice type")
+ }
+
+ for i := 0; i < s.Len(); i++ {
+ if reflect.DeepEqual(s.Index(i).Interface(), elem) {
+ return true
+ }
+ }
+ return false
+}