Seperate Module and Topdata Pipeline
This commit is contained in:
+1
-5
@@ -30,7 +30,7 @@ type context struct {
|
|||||||
var commands = []command{
|
var commands = []command{
|
||||||
{
|
{
|
||||||
name: "build",
|
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,
|
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, "project: %s\n", p.Config.Module.Name)
|
||||||
fmt.Fprintf(ctx.stdout, "module: %s\n", result.ModulePath)
|
fmt.Fprintf(ctx.stdout, "module: %s\n", result.ModulePath)
|
||||||
fmt.Fprintf(ctx.stdout, "resources: %d\n", result.Resources)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+14
-25
@@ -63,6 +63,15 @@ type hakChunk struct {
|
|||||||
type ProgressFunc func(string)
|
type ProgressFunc func(string)
|
||||||
|
|
||||||
func Build(p *project.Project) (BuildResult, error) {
|
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)
|
moduleResult, err := BuildModule(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return BuildResult{}, err
|
return BuildResult{}, err
|
||||||
@@ -74,6 +83,9 @@ func Build(p *project.Project) (BuildResult, error) {
|
|||||||
moduleResult.HAKPaths = hakResult.HAKPaths
|
moduleResult.HAKPaths = hakResult.HAKPaths
|
||||||
moduleResult.Manifest = hakResult.Manifest
|
moduleResult.Manifest = hakResult.Manifest
|
||||||
moduleResult.HAKAssets = hakResult.HAKAssets
|
moduleResult.HAKAssets = hakResult.HAKAssets
|
||||||
|
moduleResult.TopPackageHAK = topPackage.OutputHAKPath
|
||||||
|
moduleResult.TopPackageTLK = topPackage.OutputTLKPath
|
||||||
|
moduleResult.TopPackageFiles = topPackage.HAKResources
|
||||||
return moduleResult, nil
|
return moduleResult, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,26 +103,6 @@ func buildModule(p *project.Project, progress ProgressFunc) (BuildResult, error)
|
|||||||
return BuildResult{}, err
|
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...")
|
progressf(progress, "Resolving module HAK order...")
|
||||||
moduleHakOrder, err := plannedModuleHAKOrder(p)
|
moduleHakOrder, err := plannedModuleHAKOrder(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -136,11 +128,8 @@ func buildModule(p *project.Project, progress ProgressFunc) (BuildResult, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return BuildResult{
|
return BuildResult{
|
||||||
ModulePath: outputPath,
|
ModulePath: outputPath,
|
||||||
Resources: len(moduleResources),
|
Resources: len(moduleResources),
|
||||||
TopPackageHAK: topPackage.OutputHAKPath,
|
|
||||||
TopPackageTLK: topPackage.OutputTLKPath,
|
|
||||||
TopPackageFiles: topPackage.HAKResources,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -204,12 +204,6 @@ func ensureBuildIsCurrent(p *project.Project, modulePath string, hakPaths []stri
|
|||||||
archivePaths := make([]string, 0, 1+len(hakPaths))
|
archivePaths := make([]string, 0, 1+len(hakPaths))
|
||||||
archivePaths = append(archivePaths, modulePath)
|
archivePaths = append(archivePaths, modulePath)
|
||||||
archivePaths = append(archivePaths, hakPaths...)
|
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{}
|
oldestArchive := time.Time{}
|
||||||
for _, path := range archivePaths {
|
for _, path := range archivePaths {
|
||||||
@@ -232,13 +226,6 @@ func ensureBuildIsCurrent(p *project.Project, modulePath string, hakPaths []stri
|
|||||||
for _, rel := range p.Inventory.AssetFiles {
|
for _, rel := range p.Inventory.AssetFiles {
|
||||||
sourcePaths = append(sourcePaths, filepath.Join(p.AssetsDir(), filepath.FromSlash(rel)))
|
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{}
|
newestSource := time.Time{}
|
||||||
newestPath := ""
|
newestPath := ""
|
||||||
|
|||||||
@@ -429,7 +429,7 @@ printf 'compiled:%s\n' "$(basename "$src")" > "$out"
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuildModuleBuildsTopPackageAndInjectsHAKList(t *testing.T) {
|
func TestBuildBuildsTopPackageAndInjectsHAKList(t *testing.T) {
|
||||||
root := t.TempDir()
|
root := t.TempDir()
|
||||||
mustMkdir(t, filepath.Join(root, "src", "module"))
|
mustMkdir(t, filepath.Join(root, "src", "module"))
|
||||||
mustMkdir(t, filepath.Join(root, "assets"))
|
mustMkdir(t, filepath.Join(root, "assets"))
|
||||||
@@ -486,9 +486,9 @@ func TestBuildModuleBuildsTopPackageAndInjectsHAKList(t *testing.T) {
|
|||||||
t.Fatalf("scan: %v", err)
|
t.Fatalf("scan: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := BuildModule(p)
|
result, err := Build(p)
|
||||||
if err != nil {
|
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 {
|
if _, err := os.Stat(filepath.Join(root, "build", "sow_top.hak")); err != nil {
|
||||||
t.Fatalf("expected sow_top.hak: %v", err)
|
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()
|
root := t.TempDir()
|
||||||
mustMkdir(t, filepath.Join(root, "src", "module"))
|
mustMkdir(t, filepath.Join(root, "src", "module"))
|
||||||
mustMkdir(t, filepath.Join(root, "assets"))
|
mustMkdir(t, filepath.Join(root, "assets"))
|
||||||
@@ -609,12 +609,18 @@ func TestBuildModuleCompilesTopDataOnlyOnce(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
joined := strings.Join(progress, "\n")
|
joined := strings.Join(progress, "\n")
|
||||||
if got := strings.Count(joined, "Building native topdata datasets..."); got != 1 {
|
if got := strings.Count(joined, "Building native topdata datasets..."); got != 0 {
|
||||||
t.Fatalf("expected exactly one native topdata compile pass, got %d\nprogress:\n%s", got, joined)
|
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()
|
root := t.TempDir()
|
||||||
mustMkdir(t, filepath.Join(root, "src", "module"))
|
mustMkdir(t, filepath.Join(root, "src", "module"))
|
||||||
mustMkdir(t, filepath.Join(root, "assets"))
|
mustMkdir(t, filepath.Join(root, "assets"))
|
||||||
@@ -677,8 +683,12 @@ func TestCompareFailsWhenTopPackageIsStale(t *testing.T) {
|
|||||||
if err := os.Chtimes(topdataBase, newTime, newTime); err != nil {
|
if err := os.Chtimes(topdataBase, newTime, newTime); err != nil {
|
||||||
t.Fatalf("touch topdata source: %v", err)
|
t.Fatalf("touch topdata source: %v", err)
|
||||||
}
|
}
|
||||||
if _, err := Compare(p); err == nil {
|
result, err := Compare(p)
|
||||||
t.Fatalf("expected compare to fail when top package is stale")
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user