Skip to content

Commit

Permalink
Pull in Git for git sources
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin Zhao <[email protected]>
  • Loading branch information
GZGavinZhao committed Jun 10, 2024
1 parent 2d5aeef commit 47bb34e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
6 changes: 5 additions & 1 deletion builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions builder/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
9 changes: 8 additions & 1 deletion builder/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions builder/source/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions builder/source/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions builder/source/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 47bb34e

Please sign in to comment.