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 0db6dbcd Make repos defined in project.yml implicitly allowed
0db6dbcd is described below

commit 0db6dbcd274c2c2dfd918259ae52dd659373c025
Author: Andrzej Kaczmarek <[email protected]>
AuthorDate: Fri Oct 25 16:10:59 2024 +0200

    Make repos defined in project.yml implicitly allowed
    
    Repositories defined in project.yml should be allowed by default (even
    if omitted on allowed list) unless ignored explicitly.
---
 .github/newt_upgrade/allowed-ignored/expected.txt  |  1 +
 .../newt_upgrade/fail/core-ignored/expected.txt    |  2 +-
 .../fail/core-not-allowed/expected.txt             |  1 -
 .../newt_upgrade/fail/core-not-allowed/project.yml | 31 ----------------------
 newt/project/project.go                            | 30 ++++++++++++++-------
 5 files changed, 23 insertions(+), 42 deletions(-)

diff --git a/.github/newt_upgrade/allowed-ignored/expected.txt 
b/.github/newt_upgrade/allowed-ignored/expected.txt
index 571ed69f..2951299b 100644
--- a/.github/newt_upgrade/allowed-ignored/expected.txt
+++ b/.github/newt_upgrade/allowed-ignored/expected.txt
@@ -4,3 +4,4 @@ arm-CMSIS_5
 mcuboot
 nordic-nrfx
 stm-stm32g4xx_hal_driver
+tinyusb
diff --git a/.github/newt_upgrade/fail/core-ignored/expected.txt 
b/.github/newt_upgrade/fail/core-ignored/expected.txt
index af5781a9..1fec7419 100644
--- a/.github/newt_upgrade/fail/core-ignored/expected.txt
+++ b/.github/newt_upgrade/fail/core-ignored/expected.txt
@@ -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.
diff --git a/.github/newt_upgrade/fail/core-not-allowed/expected.txt 
b/.github/newt_upgrade/fail/core-not-allowed/expected.txt
deleted file mode 100644
index af5781a9..00000000
--- a/.github/newt_upgrade/fail/core-not-allowed/expected.txt
+++ /dev/null
@@ -1 +0,0 @@
-Error: apache-mynewt-core repository must be allowed. Please add it to the 
allowed list and/or remove it from the ignored list.
diff --git a/.github/newt_upgrade/fail/core-not-allowed/project.yml 
b/.github/newt_upgrade/fail/core-not-allowed/project.yml
deleted file mode 100644
index 588caf33..00000000
--- a/.github/newt_upgrade/fail/core-not-allowed/project.yml
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#  http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-project.repositories:
-   - apache-mynewt-core
-
-repository.apache-mynewt-core:
-   type: github
-   vers: 0-dev
-   user: apache
-   repo: mynewt-core
-
-project.repositories.allowed:
-   - apache-mynewt-nimble
-   - apache-mynewt-mcumgr
diff --git a/newt/project/project.go b/newt/project/project.go
index 2bafb42f..48ac5774 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -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)
@@ -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
@@ -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,
@@ -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
@@ -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
@@ -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

Reply via email to