Skip to content

Commit

Permalink
fix: generate kotlin deps transitively, always depend on "builtin" (#999
Browse files Browse the repository at this point in the history
)
  • Loading branch information
worstell authored Feb 27, 2024
1 parent f1bed9e commit 9914282
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
14 changes: 5 additions & 9 deletions buildengine/build_kotlin.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@ type externalModuleContext struct {
}

func (e externalModuleContext) ExternalModules() []*schema.Module {
depsSet := make(map[string]struct{})
for _, dep := range e.module.Dependencies {
depsSet[dep] = struct{}{}
}

modules := make([]*schema.Module, 0)
modules := make([]*schema.Module, 0, len(e.Modules))
for _, module := range e.Modules {
if _, exists := depsSet[module.Name]; exists || module.Name == "builtin" {
modules = append(modules, module)
if module.Name == e.module.Module {
continue
}
modules = append(modules, module)
}
return modules
}
Expand Down Expand Up @@ -149,7 +145,7 @@ func generateExternalModules(ctx context.Context, module Module, sch *schema.Sch
return internal.ScaffoldZip(kotlinruntime.ExternalModuleTemplates(), config.Dir, externalModuleContext{
module: module,
Schema: sch,
}, scaffolder.Functions(funcs))
}, scaffolder.Exclude("^go.mod$"), scaffolder.Functions(funcs))
}

var scaffoldFuncs = scaffolder.FuncMap{
Expand Down
10 changes: 10 additions & 0 deletions buildengine/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ func UpdateDependencies(ctx context.Context, config moduleconfig.ModuleConfig) (
if err != nil {
return Module{}, err
}
containsBuiltin := false
for _, dep := range dependencies {
if dep == "builtin" {
containsBuiltin = true
break
}
}
if !containsBuiltin {
dependencies = append(dependencies, "builtin")
}
out := reflect.DeepCopy(config)
return Module{ModuleConfig: out, Dependencies: dependencies}, nil
}
Expand Down
5 changes: 3 additions & 2 deletions buildengine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ func TestEngine(t *testing.T) {
engine.Import(ctx, otherSchema)

expected := map[string][]string{
"alpha": {"another", "other"},
"another": {},
"alpha": {"another", "other", "builtin"},
"another": {"builtin"},
"other": {},
"builtin": {},
}
graph, err := engine.Graph()
assert.NoError(t, err)
Expand Down
3 changes: 0 additions & 3 deletions buildengine/testdata/modules/echokotlin/go.mod

This file was deleted.

0 comments on commit 9914282

Please sign in to comment.