This is an automated email from the ASF dual-hosted git repository.
janc 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 ba89f152 builder: Print warning if external repository is modified or
missing
ba89f152 is described below
commit ba89f15262bab671b61e146ea99edc4497202dd2
Author: Michal Gorecki <[email protected]>
AuthorDate: Tue Sep 5 14:55:50 2023 +0200
builder: Print warning if external repository is modified or missing
This adds functionality described in this issue:
https://github.com/apache/mynewt-newt/issues/524
Warning is only shown when the build failed
---
newt/builder/build.go | 24 +++++++++++++++++++++++
newt/builder/buildpackage.go | 46 ++++++++++++++++++++++++++++++++++++++++++++
newt/cli/build_cmds.go | 5 +++++
3 files changed, 75 insertions(+)
diff --git a/newt/builder/build.go b/newt/builder/build.go
index 543c5cb9..651c7dc4 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -57,6 +57,7 @@ type Builder struct {
buildName string
linkElf string
injectedSettings map[string]string
+ modifiedExtRepos []string
}
func NewBuilder(
@@ -680,6 +681,8 @@ func (b *Builder) Build() error {
}
entries = append(entries, subEntries...)
+ b.modifiedExtRepos = append(b.modifiedExtRepos,
bpkg.getModifiedReposNames()...)
+
if len(subEntries) > 0 {
bpkgCompilerMap[bpkg] = subEntries[0].Compiler
}
@@ -920,3 +923,24 @@ func (b *Builder) CleanArtifacts() {
os.Remove(p)
}
}
+
+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) {
+ b.modifiedExtRepos = append(b.modifiedExtRepos, repo)
+ }
+ }
+}
+
+func (b *Builder) GetModifiedRepos() []string {
+ return b.modifiedExtRepos
+}
diff --git a/newt/builder/buildpackage.go b/newt/builder/buildpackage.go
index c731872e..b5a9135b 100644
--- a/newt/builder/buildpackage.go
+++ b/newt/builder/buildpackage.go
@@ -20,9 +20,12 @@
package builder
import (
+ "mynewt.apache.org/newt/newt/downloader"
+ "mynewt.apache.org/newt/newt/repo"
"os"
"path/filepath"
"regexp"
+ "strings"
"mynewt.apache.org/newt/newt/newtutil"
"mynewt.apache.org/newt/newt/pkg"
@@ -341,3 +344,46 @@ func (bpkg *BuildPackage) privateIncludeDirs(b *Builder)
[]string {
return incls
}
+
+func (bpkg *BuildPackage) getModifiedReposNames() []string {
+ var modifiedRepos []string
+
+ settings := bpkg.rpkg.Lpkg.PkgY.AllSettings()
+ for settingName, setting := range settings {
+ if strings.HasPrefix(settingName, "repository") {
+ var version string
+
+ dl := downloader.NewGitDownloader()
+ rName := strings.TrimPrefix(settingName, "repository.")
+ r, _ := repo.NewRepo(rName, dl)
+
+ if util.NodeNotExist(r.Path()) {
+ modifiedRepos = append(modifiedRepos, r.Name())
+ continue
+ }
+
+ currentHash, _ := dl.HashFor(r.Path(), "HEAD")
+
+ aSetting, ok := setting.(map[interface{}]interface{})
+ if ok {
+ for field, value := range aSetting {
+ if field == "vers" {
+ aValue, ok := value.(string)
+ if ok {
+ version =
strings.TrimSuffix(aValue, "-commit")
+ }
+ }
+ }
+ }
+
+ expectedHash, _ := dl.HashFor(r.Path(), version)
+ dirtyState, _ := r.DirtyState()
+
+ if currentHash != expectedHash || dirtyState != "" {
+ modifiedRepos = append(modifiedRepos, r.Name())
+ }
+ }
+ }
+
+ return modifiedRepos
+}
diff --git a/newt/cli/build_cmds.go b/newt/cli/build_cmds.go
index 6902e098..309b4345 100644
--- a/newt/cli/build_cmds.go
+++ b/newt/cli/build_cmds.go
@@ -161,6 +161,11 @@ func buildRunCmd(cmd *cobra.Command, args []string,
printShellCmds bool, execute
}
if err := b.Build(); err != nil {
+ if b.AppBuilder.GetModifiedRepos() != nil {
+ util.ErrorMessage(util.VERBOSITY_DEFAULT,
+ "Warning: Following external repos are
modified or missing, which might be causing build errors:\n%v\n",
+ b.AppBuilder.GetModifiedRepos())
+ }
NewtUsage(nil, err)
}