From 47bb34eb8e03e7a8f4dea2b6816995d7aa5adec7 Mon Sep 17 00:00:00 2001 From: Gavin Zhao Date: Wed, 10 Apr 2024 10:52:43 -0400 Subject: [PATCH] Pull in Git for git sources Signed-off-by: Gavin Zhao --- builder/build.go | 6 +++++- builder/pkg.go | 9 +++++++++ builder/resolver.go | 9 ++++++++- builder/source/git.go | 4 ++++ builder/source/main.go | 2 ++ builder/source/simple.go | 4 ++++ 6 files changed, 32 insertions(+), 2 deletions(-) diff --git a/builder/build.go b/builder/build.go index fcb943b..ed227fb 100644 --- a/builder/build.go +++ b/builder/build.go @@ -231,7 +231,11 @@ func (p *Package) CopyAssets(h *PackageHistory, o *Overlay) error { func (p *Package) calcDeps(resolver *Resolver) ([]Dep, error) { // hash = LayersFakeHash - return resolver.Query(p.Deps, true, true, p.Emul32) + if p.HasGitSource() { + return resolver.Query(p.Deps, true, true, p.Emul32, []string{"git"}) + } else { + return resolver.Query(p.Deps, true, true, p.Emul32, []string{}) + } } // PrepYpkg will do the initial leg work of preparing us for a ypkg build. diff --git a/builder/pkg.go b/builder/pkg.go index 043b6aa..f21a291 100644 --- a/builder/pkg.go +++ b/builder/pkg.go @@ -257,3 +257,12 @@ func NewYmlPackageFromBytes(by []byte) (*Package, error) { return ret, nil } + +func (p *Package) HasGitSource() bool { + for _, source := range p.Sources { + if source.IsGit() { + return true + } + } + return false +} diff --git a/builder/resolver.go b/builder/resolver.go index 37dee55..cd9a9fb 100644 --- a/builder/resolver.go +++ b/builder/resolver.go @@ -51,7 +51,7 @@ func (r *Resolver) AddIndex(i *index.Index) { } } -func (r *Resolver) Query(pkgs []string, withBase bool, withDevel bool, emul32 bool) (res []Dep, err error) { +func (r *Resolver) Query(pkgs []string, withBase bool, withDevel bool, emul32 bool, extras []string) (res []Dep, err error) { visited := make(map[string]bool) var dfs func(name string) error @@ -110,6 +110,13 @@ func (r *Resolver) Query(pkgs []string, withBase bool, withDevel bool, emul32 bo } } + for _, pkg := range extras { + err = dfs(pkg) + if err != nil { + return + } + } + slices.SortFunc(res, func(a, b Dep) int { return cmp.Compare(a.Name, b.Name) }) return } diff --git a/builder/source/git.go b/builder/source/git.go index 9c6d5cd..bc8c1d2 100644 --- a/builder/source/git.go +++ b/builder/source/git.go @@ -39,6 +39,10 @@ type GitSource struct { ClonePath string // This is where we will have cloned into } +func (s *GitSource) IsGit() bool { + return true +} + // NewGit will create a new GitSource for the given URI & ref combination. func NewGit(uri, ref string) (*GitSource, error) { // Ensure we have a valid URL first. diff --git a/builder/source/main.go b/builder/source/main.go index f7e3760..314ce55 100644 --- a/builder/source/main.go +++ b/builder/source/main.go @@ -63,6 +63,8 @@ type Source interface { // GetIdentifier will return the appropriate representation for a given // source URL. GetIdentifier() string + + IsGit() bool } // New will return a new source for the specified URL. diff --git a/builder/source/simple.go b/builder/source/simple.go index 25a959a..c174cff 100644 --- a/builder/source/simple.go +++ b/builder/source/simple.go @@ -47,6 +47,10 @@ type SimpleSource struct { url *url.URL } +func (s *SimpleSource) IsGit() bool { + return false +} + // NewSimple will create a new source instance. func NewSimple(uri, validator string, legacy bool) (*SimpleSource, error) { // Ensure the URI is actually valid.