improving windows compatability

This commit is contained in:
partisan 2025-01-11 23:11:11 +01:00
parent 921540d5a4
commit 8de4db960a
6 changed files with 73 additions and 107 deletions

91
main.go
View file

@ -5,7 +5,6 @@ import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"runtime" // for detecting system architecture and platform
"spitfire-builder/spitfire"
@ -25,7 +24,6 @@ var (
skipPatchUpdate bool
run bool
compress bool
buildPath string
target string
version string
component string
@ -46,7 +44,6 @@ var (
)
func init() {
flag.StringVar(&buildPath, "p", "", "Path to the build directory")
flag.StringVar(&target, "t", "", "Target location format: component-arch-release-platform")
flag.BoolVar(&compress, "c", false, "Compress the build directory into a tar.gz file before uploading")
flag.StringVar(&version, "v", "", "Specify version for the package. For nightly, use current date if not specified.")
@ -76,37 +73,6 @@ func printHelp() {
os.Exit(0)
}
// checkDependencies verifies if required dependencies are installed
func checkDependencies() error {
dependencies := map[string]string{
"mercurial": "hg",
"python3": "python3",
"rsync": "rsync",
"git": "git",
}
// Log the PATH for debugging
fmt.Printf("Current PATH: %s\n", os.Getenv("PATH"))
for dep, cmd := range dependencies {
// Use LookPath to check availability
if _, err := exec.LookPath(cmd); err != nil {
return fmt.Errorf("dependency %s is not installed or not found in PATH. Please run: sudo apt install %s", dep, dep)
}
// For python3, run a specific version check to confirm
if dep == "python3" {
out, err := exec.Command(cmd, "--version").Output()
if err != nil {
return fmt.Errorf("dependency %s is installed but not functional. Ensure 'python3 --version' works correctly: %v", dep, err)
}
fmt.Printf("Detected %s: %s", dep, string(out))
}
}
return nil
}
func main() {
flag.Parse()
@ -117,7 +83,7 @@ func main() {
// Only check dependencies if NOT skipping them
if !skipDeps {
if err := checkDependencies(); err != nil {
if err := spitfire.CheckDependencies(); err != nil {
log.Fatalf("System check failed: %v", err)
}
}
@ -135,28 +101,6 @@ func main() {
}
fmt.Printf("Initial working directory: %s\n", initialDir)
// Determine buildPath dynamically if not provided
if buildPath == "" {
sourcePath, err := spitfire.ResolvePath("./mozilla-central")
if err != nil {
log.Fatalf("Error resolving source path: %v", err)
}
resolvedBuildPath, err := spitfire.ResolveBuildDir(sourcePath)
if err != nil {
log.Fatalf("Failed to detect build directory dynamically: %v", err)
}
buildPath = resolvedBuildPath
fmt.Printf("Automatically detected buildPath: %s\n", buildPath)
} else {
// Convert buildPath to absolute path
buildPath, err2 = spitfire.ResolvePath(buildPath)
if err2 != nil {
log.Fatalf("Failed to convert buildPath to absolute path: %v", err2)
}
fmt.Printf("Resolved buildPath: %s\n", buildPath)
}
if uploadPath != "" {
uploadPath, err2 = spitfire.ResolvePath(uploadPath)
if err2 != nil {
@ -170,7 +114,31 @@ func main() {
}
if compress || upload {
PackageAndUploadProcess()
// Resolve the build directory dynamically
fmt.Println("Resolving build directory dynamically...")
sourcePath, err := spitfire.ResolvePath("./mozilla-central")
if err != nil {
log.Fatalf("Error resolving source path: %v", err)
}
buildDir, err := spitfire.ResolveBuildDir(sourcePath)
if err != nil {
log.Fatalf("Error resolving build directory dynamically: %v", err)
}
fmt.Printf("Resolved build directory: %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)
}
spitfire.PrintErrors()
@ -260,12 +228,12 @@ func BuildProcess() {
}
// PackageAndUploadProcess handles compressing, packaging, and uploading the build to SourceForge.
func PackageAndUploadProcess() {
func PackageAndUploadProcess(buildDir string) {
// Restore working directory before performing SourceForge operations
restoreWorkingDirectory()
pathToUse := buildPath
pathToUse := buildDir
if upload && uploadPath != "" {
pathToUse = uploadPath
}
@ -308,6 +276,9 @@ func PackageAndUploadProcess() {
fmt.Printf("Compression ratio: %.2f:1\n", compressionRatio)
fmt.Printf("Compression efficiency: %.2f%%\n", efficiency)
// Display compressed directory path
fmt.Printf("Compressed dir: %s", pathToUse)
// If not uploading, we're done
if !upload {
return