Move Generation Destinations
This commit is contained in:
@@ -145,6 +145,12 @@ func (p *Project) ValidateLayout() error {
|
||||
} {
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
if label == "paths.assets" && errors.Is(err, os.ErrNotExist) && p.isCachePath(path) {
|
||||
if mkErr := os.MkdirAll(path, 0o755); mkErr != nil {
|
||||
failures = append(failures, fmt.Errorf("%s: create cache directory %s: %w", label, path, mkErr))
|
||||
}
|
||||
continue
|
||||
}
|
||||
failures = append(failures, fmt.Errorf("%s: %w", label, err))
|
||||
continue
|
||||
}
|
||||
@@ -160,6 +166,15 @@ func (p *Project) ValidateLayout() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Project) isCachePath(path string) bool {
|
||||
rel, err := filepath.Rel(p.Root, path)
|
||||
if err != nil || strings.HasPrefix(rel, ".."+string(filepath.Separator)) || rel == ".." {
|
||||
return false
|
||||
}
|
||||
parts := strings.Split(filepath.Clean(rel), string(filepath.Separator))
|
||||
return len(parts) > 0 && parts[0] == ".cache"
|
||||
}
|
||||
|
||||
func (p *Project) Scan() error {
|
||||
sourceFiles, sourceExts, err := scanDir(p.SourceDir(), func(path string) bool {
|
||||
ext := strings.ToLower(filepath.Ext(path))
|
||||
@@ -334,7 +349,7 @@ func defaultConfig() Config {
|
||||
Build: "build",
|
||||
},
|
||||
TopData: TopDataConfig{
|
||||
Build: "build/topdata",
|
||||
Build: ".cache/topdata",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,29 @@ func TestTopDataAssetsDirReturnsEmptyForNoConfig(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateLayoutCreatesMissingCacheAssetsDir(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
mkdirAll(t, filepath.Join(root, "src"))
|
||||
mkdirAll(t, filepath.Join(root, "build"))
|
||||
|
||||
proj := &Project{
|
||||
Root: root,
|
||||
Config: Config{
|
||||
Module: ModuleConfig{Name: "Test", ResRef: "test"},
|
||||
Paths: PathConfig{Source: "src", Assets: ".cache/module-assets", Build: "build"},
|
||||
},
|
||||
}
|
||||
|
||||
if err := proj.ValidateLayout(); err != nil {
|
||||
t.Fatalf("ValidateLayout returned error: %v", err)
|
||||
}
|
||||
if info, err := os.Stat(filepath.Join(root, ".cache", "module-assets")); err != nil {
|
||||
t.Fatalf("expected cache assets dir to be created: %v", err)
|
||||
} else if !info.IsDir() {
|
||||
t.Fatalf("expected cache assets path to be a directory")
|
||||
}
|
||||
}
|
||||
|
||||
func mkdirAll(t *testing.T, path string) {
|
||||
t.Helper()
|
||||
if err := os.MkdirAll(path, 0o755); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user