Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builder: Print warning if external repository is modified or missing #529

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions newt/builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type Builder struct {
buildName string
linkElf string
injectedSettings map[string]string
modifiedExtRepos []string
}

func NewBuilder(
Expand Down Expand Up @@ -652,6 +653,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
}
Expand Down Expand Up @@ -893,3 +896,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
}
46 changes: 46 additions & 0 deletions newt/builder/buildpackage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions newt/cli/build_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Loading