diff --git a/internal/app/app.go b/internal/app/app.go index f2c6b9f..a88cde7 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -30,7 +30,7 @@ type context struct { var commands = []command{ { name: "build", - description: "Build module and HAK outputs into build/.", + description: "Build module and HAK outputs into build/, plus top package output when topdata is configured.", run: runBuild, }, { @@ -175,10 +175,6 @@ func runBuildModule(ctx context) error { fmt.Fprintf(ctx.stdout, "project: %s\n", p.Config.Module.Name) fmt.Fprintf(ctx.stdout, "module: %s\n", result.ModulePath) fmt.Fprintf(ctx.stdout, "resources: %d\n", result.Resources) - if result.TopPackageHAK != "" { - fmt.Fprintf(ctx.stdout, "top package hak: %s\n", result.TopPackageHAK) - fmt.Fprintf(ctx.stdout, "top package tlk: %s\n", result.TopPackageTLK) - } return nil } diff --git a/internal/pipeline/build.go b/internal/pipeline/build.go index 601862d..edc8b9d 100644 --- a/internal/pipeline/build.go +++ b/internal/pipeline/build.go @@ -63,6 +63,15 @@ type hakChunk struct { type ProgressFunc func(string) func Build(p *project.Project) (BuildResult, error) { + var topPackage topdata.PackageResult + var err error + if p.HasTopData() { + topPackage, err = topdata.BuildAndPackage(p, nil) + if err != nil { + return BuildResult{}, err + } + } + moduleResult, err := BuildModule(p) if err != nil { return BuildResult{}, err @@ -74,6 +83,9 @@ func Build(p *project.Project) (BuildResult, error) { moduleResult.HAKPaths = hakResult.HAKPaths moduleResult.Manifest = hakResult.Manifest moduleResult.HAKAssets = hakResult.HAKAssets + moduleResult.TopPackageHAK = topPackage.OutputHAKPath + moduleResult.TopPackageTLK = topPackage.OutputTLKPath + moduleResult.TopPackageFiles = topPackage.HAKResources return moduleResult, nil } @@ -91,26 +103,6 @@ func buildModule(p *project.Project, progress ProgressFunc) (BuildResult, error) return BuildResult{}, err } - var topPackage topdata.PackageResult - var err error - if p.HasTopData() { - progressf(progress, "Building native topdata...") - nativeTopData, buildErr := topdata.BuildNative(p, func(message string) { - progressf(progress, "Top package: "+message) - }) - if buildErr != nil { - return BuildResult{}, buildErr - } - - progressf(progress, "Packaging native top package...") - topPackage, err = topdata.BuildPackageFromBuild(p, nativeTopData, func(message string) { - progressf(progress, "Top package: "+message) - }) - if err != nil { - return BuildResult{}, err - } - } - progressf(progress, "Resolving module HAK order...") moduleHakOrder, err := plannedModuleHAKOrder(p) if err != nil { @@ -136,11 +128,8 @@ func buildModule(p *project.Project, progress ProgressFunc) (BuildResult, error) } return BuildResult{ - ModulePath: outputPath, - Resources: len(moduleResources), - TopPackageHAK: topPackage.OutputHAKPath, - TopPackageTLK: topPackage.OutputTLKPath, - TopPackageFiles: topPackage.HAKResources, + ModulePath: outputPath, + Resources: len(moduleResources), }, nil } diff --git a/internal/pipeline/compare.go b/internal/pipeline/compare.go index 2915c15..f20f764 100644 --- a/internal/pipeline/compare.go +++ b/internal/pipeline/compare.go @@ -204,12 +204,6 @@ func ensureBuildIsCurrent(p *project.Project, modulePath string, hakPaths []stri archivePaths := make([]string, 0, 1+len(hakPaths)) archivePaths = append(archivePaths, modulePath) archivePaths = append(archivePaths, hakPaths...) - if p.HasTopData() { - archivePaths = append(archivePaths, - filepath.Join(p.BuildDir(), topdata.PackageHAKFileName), - filepath.Join(p.BuildDir(), topdata.PackageTLKFileName), - ) - } oldestArchive := time.Time{} for _, path := range archivePaths { @@ -232,13 +226,6 @@ func ensureBuildIsCurrent(p *project.Project, modulePath string, hakPaths []stri for _, rel := range p.Inventory.AssetFiles { sourcePaths = append(sourcePaths, filepath.Join(p.AssetsDir(), filepath.FromSlash(rel))) } - if p.HasTopData() { - topSources, err := topPackageSourcePaths(p) - if err != nil { - return err - } - sourcePaths = append(sourcePaths, topSources...) - } newestSource := time.Time{} newestPath := "" diff --git a/internal/pipeline/pipeline_test.go b/internal/pipeline/pipeline_test.go index e7a38a3..c7a1f1f 100644 --- a/internal/pipeline/pipeline_test.go +++ b/internal/pipeline/pipeline_test.go @@ -429,7 +429,7 @@ printf 'compiled:%s\n' "$(basename "$src")" > "$out" } } -func TestBuildModuleBuildsTopPackageAndInjectsHAKList(t *testing.T) { +func TestBuildBuildsTopPackageAndInjectsHAKList(t *testing.T) { root := t.TempDir() mustMkdir(t, filepath.Join(root, "src", "module")) mustMkdir(t, filepath.Join(root, "assets")) @@ -486,9 +486,9 @@ func TestBuildModuleBuildsTopPackageAndInjectsHAKList(t *testing.T) { t.Fatalf("scan: %v", err) } - result, err := BuildModule(p) + result, err := Build(p) if err != nil { - t.Fatalf("build module: %v", err) + t.Fatalf("build: %v", err) } if _, err := os.Stat(filepath.Join(root, "build", "sow_top.hak")); err != nil { t.Fatalf("expected sow_top.hak: %v", err) @@ -546,7 +546,7 @@ func TestBuildModuleBuildsTopPackageAndInjectsHAKList(t *testing.T) { } } -func TestBuildModuleCompilesTopDataOnlyOnce(t *testing.T) { +func TestBuildModuleDoesNotCompileTopData(t *testing.T) { root := t.TempDir() mustMkdir(t, filepath.Join(root, "src", "module")) mustMkdir(t, filepath.Join(root, "assets")) @@ -609,12 +609,18 @@ func TestBuildModuleCompilesTopDataOnlyOnce(t *testing.T) { } joined := strings.Join(progress, "\n") - if got := strings.Count(joined, "Building native topdata datasets..."); got != 1 { - t.Fatalf("expected exactly one native topdata compile pass, got %d\nprogress:\n%s", got, joined) + if got := strings.Count(joined, "Building native topdata datasets..."); got != 0 { + t.Fatalf("expected build-module to skip topdata compilation, got %d compile pass(es)\nprogress:\n%s", got, joined) + } + if _, err := os.Stat(filepath.Join(root, "build", "sow_top.hak")); !os.IsNotExist(err) { + t.Fatalf("expected build-module not to generate sow_top.hak, got err=%v", err) + } + if _, err := os.Stat(filepath.Join(root, "build", "sow_tlk.tlk")); !os.IsNotExist(err) { + t.Fatalf("expected build-module not to generate sow_tlk.tlk, got err=%v", err) } } -func TestCompareFailsWhenTopPackageIsStale(t *testing.T) { +func TestCompareIgnoresTopPackageStaleness(t *testing.T) { root := t.TempDir() mustMkdir(t, filepath.Join(root, "src", "module")) mustMkdir(t, filepath.Join(root, "assets")) @@ -677,8 +683,12 @@ func TestCompareFailsWhenTopPackageIsStale(t *testing.T) { if err := os.Chtimes(topdataBase, newTime, newTime); err != nil { t.Fatalf("touch topdata source: %v", err) } - if _, err := Compare(p); err == nil { - t.Fatalf("expected compare to fail when top package is stale") + result, err := Compare(p) + if err != nil { + t.Fatalf("expected compare to ignore topdata staleness: %v", err) + } + if result.Checked != 1 { + t.Fatalf("expected 1 compared resource, got %d", result.Checked) } }