paths.build fix
This commit is contained in:
@@ -788,6 +788,13 @@ func (p *Project) ValidateLayout() error {
|
||||
}
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
// An output dir that does not exist yet is fine: the builder creates
|
||||
// it (MkdirAll) before writing. A bare clone must validate/build from
|
||||
// a clean tree with no pre-step (R2/parity) — only a path that exists
|
||||
// but is NOT a directory is a real error.
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
continue
|
||||
}
|
||||
failures = append(failures, fmt.Errorf("%s: %w", label, err))
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -1113,6 +1113,52 @@ func TestValidateLayoutAllowsMissingAssetsDir(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// paths.build is an OUTPUT dir the builder creates (MkdirAll) before writing, so
|
||||
// a bare clone with no build dir yet must still validate/build with no pre-step
|
||||
// (R2/parity). Only a build path that exists but is not a directory is an error.
|
||||
func TestValidateLayoutAllowsMissingBuildDir(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
mkdirAll(t, filepath.Join(root, "src"))
|
||||
// deliberately do NOT create build/
|
||||
|
||||
proj := &Project{
|
||||
Root: root,
|
||||
Config: Config{
|
||||
Module: ModuleConfig{Name: "Test", ResRef: "test"},
|
||||
Paths: PathConfig{Source: "src", Build: "build"},
|
||||
},
|
||||
}
|
||||
|
||||
if err := proj.ValidateLayout(); err != nil {
|
||||
t.Fatalf("ValidateLayout returned error for missing build dir: %v", err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(root, "build")); !errors.Is(err, os.ErrNotExist) {
|
||||
t.Fatalf("expected missing build dir to remain absent, got err=%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// A build path that exists but is a regular file is still a hard error.
|
||||
func TestValidateLayoutRejectsBuildDirThatIsAFile(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
mkdirAll(t, filepath.Join(root, "src"))
|
||||
if err := os.WriteFile(filepath.Join(root, "build"), []byte("i am a file, not a dir"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
proj := &Project{
|
||||
Root: root,
|
||||
Config: Config{
|
||||
Module: ModuleConfig{Name: "Test", ResRef: "test"},
|
||||
Paths: PathConfig{Source: "src", Build: "build"},
|
||||
},
|
||||
}
|
||||
|
||||
err := proj.ValidateLayout()
|
||||
if err == nil || !strings.Contains(err.Error(), "paths.build must be a directory") {
|
||||
t.Fatalf("expected paths.build-must-be-a-directory error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateLayoutRejectsInvalidTopDataPackageOutputNames(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
mkdirAll(t, filepath.Join(root, "src"))
|
||||
|
||||
Reference in New Issue
Block a user