fixed go . -a -c not resolving correct directory

This commit is contained in:
partisan 2025-01-19 18:29:42 +01:00
parent 4aaee3d230
commit 61bd6bba74

79
main.go
View file

@ -74,70 +74,61 @@ func printHelp() {
} }
func main() { func main() {
flag.Parse() flag.Parse()
if flag.Lookup("h").Value.(flag.Getter).Get().(bool) { if flag.Lookup("h").Value.(flag.Getter).Get().(bool) {
printHelp() printHelp()
} }
// Only check dependencies if NOT skipping them
if !skipDeps { if !skipDeps {
if err := spitfire.CheckDependencies(); err != nil { if err := spitfire.CheckDependencies(); err != nil {
log.Fatalf("System check failed: %v", err) log.Fatalf("System check failed: %v", err)
} }
} }
// Set version to current date if it's empty and release is nightly
if version == "" && release == "nightly" { if version == "" && release == "nightly" {
version = time.Now().Format("2006.01.02") // Set version to current date if nightly version = time.Now().Format("2006.01.02")
} }
// Save the initial directory // Save the initial directory
var err2 error var err error
initialDir, err2 = os.Getwd() initialDir, err = os.Getwd()
if err2 != nil { if err != nil {
log.Fatalf("Failed to get current working directory: %v", err2) log.Fatalf("Failed to get current working directory: %v", err)
}
fmt.Printf("Initial working directory: %s\n", initialDir)
if uploadPath != "" {
uploadPath, err2 = spitfire.ResolvePath(uploadPath)
if err2 != nil {
log.Fatalf("Failed to convert uploadPath to absolute path: %v", err2)
}
fmt.Printf("Resolved uploadPath: %s\n", uploadPath)
} }
var buildDir string // Store the resolved build directory here
// Perform build if necessary
if all || buildFlag || prePatch || postPatch || clean || update || run { if all || buildFlag || prePatch || postPatch || clean || update || run {
BuildProcess() buildDir = BuildProcess()
if buildDir == "" {
log.Fatalf("Build process completed, but no build directory was found.")
}
fmt.Printf("Build directory from process: %s\n", buildDir)
} }
// Resolve build directory for compression/upload
if compress || upload { if compress || upload {
// Resolve the build directory dynamically if buildDir == "" { // Resolve dynamically if no build was performed
fmt.Println("Resolving build directory dynamically...") fmt.Println("No build directory detected during build process. Resolving dynamically...")
sourcePath, err := spitfire.ResolvePath("./mozilla-release") sourcePath, err := spitfire.ResolvePath("./mozilla-release")
if err != nil { if err != nil {
log.Fatalf("Error resolving source path: %v", err) log.Fatalf("Error resolving source path: %v", err)
}
fmt.Printf("Resolved source path: %s\n", sourcePath)
buildDir, err = spitfire.ResolveBuildDir(sourcePath)
if err != nil {
log.Fatalf("Error resolving build directory dynamically: %v", err)
}
} }
buildDir, err := spitfire.ResolveBuildDir(sourcePath) if buildDir == "" {
if err != nil { log.Fatalf("No build directory found for compression or upload.")
log.Fatalf("Error resolving build directory dynamically: %v", err)
} }
fmt.Printf("Resolved build directory: %s\n", buildDir) fmt.Printf("Resolved build directory for compress/upload: %s\n", buildDir)
// Validate that the build directory exists
stat, err := os.Stat(buildDir)
if os.IsNotExist(err) {
log.Fatalf("Error: build directory does not exist at %s\n", buildDir)
} else if err != nil {
log.Fatalf("Error accessing build directory: %v\n", err)
} else if !stat.IsDir() {
log.Fatalf("Error: path exists but is not a directory: %s\n", buildDir)
}
// Proceed with packaging and uploading
PackageAndUploadProcess(buildDir) PackageAndUploadProcess(buildDir)
} }
@ -145,12 +136,14 @@ func main() {
} }
// Update the BuildProcess function to pass patchesRepo // Update the BuildProcess function to pass patchesRepo
func BuildProcess() { func BuildProcess() string {
sourcePath, err := spitfire.ResolvePath("./mozilla-release") sourcePath, err := spitfire.ResolvePath("./mozilla-release")
if err != nil { if err != nil {
log.Fatalf("Error resolving source path: %v", err) log.Fatalf("Error resolving source path: %v", err)
} }
var buildDir string
if all { if all {
spitfire.DownloadSource(sourcePath, sourceRepo) spitfire.DownloadSource(sourcePath, sourceRepo)
spitfire.DiscardChanges(sourcePath) spitfire.DiscardChanges(sourcePath)
@ -162,7 +155,7 @@ func BuildProcess() {
spitfire.Configure(sourcePath) spitfire.Configure(sourcePath)
spitfire.Build(sourcePath) spitfire.Build(sourcePath)
// Detect the build directory dynamically // Detect the build directory dynamically
buildDir, err := spitfire.ResolveBuildDir(sourcePath) buildDir, err = spitfire.ResolveBuildDir(sourcePath)
if err != nil { if err != nil {
log.Fatalf("Error resolving build directory: %v", err) log.Fatalf("Error resolving build directory: %v", err)
} }
@ -182,7 +175,7 @@ func BuildProcess() {
spitfire.Configure(sourcePath) spitfire.Configure(sourcePath)
spitfire.Build(sourcePath) spitfire.Build(sourcePath)
// Detect the build directory dynamically // Detect the build directory dynamically
buildDir, err := spitfire.ResolveBuildDir(sourcePath) buildDir, err = spitfire.ResolveBuildDir(sourcePath)
if err != nil { if err != nil {
log.Fatalf("Error resolving build directory: %v", err) log.Fatalf("Error resolving build directory: %v", err)
} }
@ -210,7 +203,7 @@ func BuildProcess() {
fmt.Println("Patches updated.") fmt.Println("Patches updated.")
} else if postPatch { } else if postPatch {
// Detect the build directory dynamically // Detect the build directory dynamically
buildDir, err := spitfire.ResolveBuildDir(sourcePath) buildDir, err = spitfire.ResolveBuildDir(sourcePath)
if err != nil { if err != nil {
log.Fatalf("Error resolving build directory: %v", err) log.Fatalf("Error resolving build directory: %v", err)
} }
@ -225,6 +218,8 @@ func BuildProcess() {
} else if run { } else if run {
spitfire.RunProject(sourcePath) spitfire.RunProject(sourcePath)
} }
return buildDir
} }
// PackageAndUploadProcess handles compressing, packaging, and uploading the build to SourceForge. // PackageAndUploadProcess handles compressing, packaging, and uploading the build to SourceForge.