Change Output Locations
This commit is contained in:
@@ -21,6 +21,29 @@ const (
|
||||
PackageTLKFileName = defaultTLKName
|
||||
)
|
||||
|
||||
func compiled2DAOutputDir(p *project.Project) string {
|
||||
if useDedicatedTopDataBuildDir(p) {
|
||||
return filepath.Join(p.TopDataBuildDir(), "2da")
|
||||
}
|
||||
return filepath.Join(p.TopDataSourceDir(), "assets", "2da")
|
||||
}
|
||||
|
||||
func compiledTLKOutputPath(p *project.Project) string {
|
||||
if useDedicatedTopDataBuildDir(p) {
|
||||
return filepath.Join(p.TopDataBuildDir(), "tlk", defaultTLKName)
|
||||
}
|
||||
return filepath.Join(p.BuildDir(), defaultTLKName)
|
||||
}
|
||||
|
||||
func compiledTLKOutputDir(p *project.Project) string {
|
||||
return filepath.Dir(compiledTLKOutputPath(p))
|
||||
}
|
||||
|
||||
func useDedicatedTopDataBuildDir(p *project.Project) bool {
|
||||
defaultBuildDir := filepath.Join(p.BuildDir(), "topdata")
|
||||
return p.TopDataBuildDir() != defaultBuildDir
|
||||
}
|
||||
|
||||
func BuildPackage(p *project.Project, progress func(string)) (PackageResult, error) {
|
||||
if progress == nil {
|
||||
progress = func(string) {}
|
||||
@@ -68,9 +91,12 @@ func packageBuiltTopData(p *project.Project, nativeResult BuildResult, progress
|
||||
}
|
||||
|
||||
progress("Preparing compiled TLK release output...")
|
||||
sourceTLK, err := resolveCompiledTLKPath(nativeResult.OutputTLKDir)
|
||||
if err != nil {
|
||||
return PackageResult{}, err
|
||||
sourceTLK := compiledTLKOutputPath(p)
|
||||
if nativeResult.OutputTLKDir != "" {
|
||||
sourceTLK, err = resolveCompiledTLKPath(nativeResult.OutputTLKDir)
|
||||
if err != nil {
|
||||
return PackageResult{}, err
|
||||
}
|
||||
}
|
||||
if err := copyFile(outputTLK, sourceTLK); err != nil {
|
||||
return PackageResult{}, err
|
||||
@@ -113,12 +139,16 @@ func collectTopPackageResources(p *project.Project, compiled2DADir string) ([]er
|
||||
|
||||
assetFiles := 0
|
||||
assetsDir := filepath.Join(p.TopDataSourceDir(), "assets")
|
||||
skipDir := compiled2DAOutputDir(p)
|
||||
info, err := os.Stat(assetsDir)
|
||||
if err == nil && info.IsDir() {
|
||||
err = filepath.WalkDir(assetsDir, func(path string, d os.DirEntry, walkErr error) error {
|
||||
if walkErr != nil {
|
||||
return walkErr
|
||||
}
|
||||
if d.IsDir() && path == skipDir {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
@@ -214,6 +244,9 @@ func resolveCompiledTLKPath(outputDir string) (string, error) {
|
||||
}
|
||||
|
||||
func copyFile(dst, src string) error {
|
||||
if samePath(dst, src) {
|
||||
return nil
|
||||
}
|
||||
input, err := os.Open(src)
|
||||
if err != nil {
|
||||
return fmt.Errorf("open %s: %w", src, err)
|
||||
@@ -232,18 +265,26 @@ func copyFile(dst, src string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func samePath(left, right string) bool {
|
||||
leftAbs, leftErr := filepath.Abs(left)
|
||||
rightAbs, rightErr := filepath.Abs(right)
|
||||
if leftErr != nil || rightErr != nil {
|
||||
return left == right
|
||||
}
|
||||
return leftAbs == rightAbs
|
||||
}
|
||||
|
||||
func packagedBuildResult(p *project.Project) (BuildResult, error) {
|
||||
if !p.HasTopData() {
|
||||
return BuildResult{}, errors.New("topdata is not configured for this project")
|
||||
}
|
||||
|
||||
buildDir := p.TopDataBuildDir()
|
||||
output2DA := filepath.Join(buildDir, "2da")
|
||||
outputTLK := filepath.Join(buildDir, "tlk")
|
||||
output2DA := compiled2DAOutputDir(p)
|
||||
outputTLK := compiledTLKOutputDir(p)
|
||||
if _, err := os.Stat(output2DA); err != nil {
|
||||
return BuildResult{}, fmt.Errorf("topdata build output missing: run build-topdata first")
|
||||
}
|
||||
if _, err := os.Stat(outputTLK); err != nil {
|
||||
if _, err := os.Stat(compiledTLKOutputPath(p)); err != nil {
|
||||
return BuildResult{}, fmt.Errorf("topdata tlk output missing: run build-topdata first")
|
||||
}
|
||||
|
||||
@@ -251,16 +292,15 @@ func packagedBuildResult(p *project.Project) (BuildResult, error) {
|
||||
if err != nil {
|
||||
return BuildResult{}, err
|
||||
}
|
||||
filesTLK, oldestTLK, err := countCompiledFiles(outputTLK, ".tlk")
|
||||
filesTLK := 1
|
||||
tlkInfo, err := os.Stat(compiledTLKOutputPath(p))
|
||||
if err != nil {
|
||||
return BuildResult{}, err
|
||||
return BuildResult{}, fmt.Errorf("stat compiled tlk output %s: %w", compiledTLKOutputPath(p), err)
|
||||
}
|
||||
oldestTLK := tlkInfo.ModTime()
|
||||
if files2DA == 0 {
|
||||
return BuildResult{}, fmt.Errorf("topdata build output missing: run build-topdata first")
|
||||
}
|
||||
if filesTLK != 1 {
|
||||
return BuildResult{}, fmt.Errorf("expected exactly 1 compiled tlk output, found %d", filesTLK)
|
||||
}
|
||||
|
||||
newestSource, newestPath, err := newestTopDataSource(p.TopDataSourceDir())
|
||||
if err != nil {
|
||||
@@ -311,6 +351,7 @@ func newestTopDataSource(sourceDir string) (time.Time, string, error) {
|
||||
newestPath := ""
|
||||
templatesDir := filepath.Join(sourceDir, "templates")
|
||||
wikiDir := filepath.Join(sourceDir, wikiRootDirName)
|
||||
generated2DADir := filepath.Join(sourceDir, "assets", "2da")
|
||||
err := filepath.WalkDir(sourceDir, func(path string, d fs.DirEntry, walkErr error) error {
|
||||
if walkErr != nil {
|
||||
return walkErr
|
||||
@@ -321,6 +362,9 @@ func newestTopDataSource(sourceDir string) (time.Time, string, error) {
|
||||
if d.IsDir() && path == wikiDir {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
if d.IsDir() && path == generated2DADir {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user