Skip to content

Commit

Permalink
Source Refactor (#117)
Browse files Browse the repository at this point in the history
* Port source refactor changes over to new branch based on main

* Remove unused Result type

* Rename tests

* Reconcile source changes with new source_tests

* Remove comment out test code

* Move filtering out of GetSource() and update tests

* Add source inline support to refactor

* Address review feedback, fix bug with not filtering sources before passing into nested build
  • Loading branch information
adamperlin authored Feb 27, 2024
1 parent c526b9b commit 4fe9f4b
Show file tree
Hide file tree
Showing 7 changed files with 425 additions and 204 deletions.
5 changes: 1 addition & 4 deletions frontend/debug/handle_sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ func HandleSources(ctx context.Context, gwc client.Client, spec *dalec.Spec) (cl

sources := make([]llb.State, 0, len(spec.Sources))
for name, src := range spec.Sources {
name := name
src := src
f := dalec.Source2LLBGetter(spec, src, name)
st, err := f(sOpt)
st, err := src.AsState(name, sOpt)
if err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/rpm/handle_sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func Dalec2SourcesLLB(spec *dalec.Spec, sOpt dalec.SourceOpts, opts ...llb.Const
}

pg := dalec.ProgressGroup("Add spec source: " + k + " " + s)
st, err := dalec.Source2LLBGetter(spec, src, k)(sOpt, append(opts, pg)...)
st, err := src.AsState(k, sOpt, append(opts, pg)...)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func RunTests(ctx context.Context, client gwclient.Client, spec *dalec.Spec, ref
pg := llb.ProgressGroup(identity.NewID(), "Test: "+path.Join(target, test.Name), false)

for _, sm := range test.Mounts {
st, err := dalec.Source2LLBGetter(spec, sm.Spec, sm.Dest)(sOpt, pg)
st, err := sm.Spec.AsMount(sm.Dest, sOpt, pg)
if err != nil {
return err
}
Expand Down
8 changes: 3 additions & 5 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,9 @@ func (f localOptionFunc) SetLocalOption(li *llb.LocalInfo) {
f(li)
}

func localIncludeExcludeMerge(src *Source) localOptionFunc {
func localIncludeExcludeMerge(includes []string, excludes []string) localOptionFunc {
return func(li *llb.LocalInfo) {
if len(src.Excludes) > 0 {
excludes := src.Excludes
if len(excludes) > 0 {
if li.ExcludePatterns != "" {
var ls []string
if err := json.Unmarshal([]byte(li.ExcludePatterns), &ls); err != nil {
Expand All @@ -154,8 +153,7 @@ func localIncludeExcludeMerge(src *Source) localOptionFunc {
llb.ExcludePatterns(excludes).SetLocalOption(li)
}

if len(src.Includes) > 0 {
includes := src.Includes
if len(includes) > 0 {
if li.IncludePatterns != "" {
var ls []string
if err := json.Unmarshal([]byte(li.IncludePatterns), &ls); err != nil {
Expand Down
Loading

0 comments on commit 4fe9f4b

Please sign in to comment.