added post compile patch
This commit is contained in:
parent
bb6e62e569
commit
ef936f3aab
3 changed files with 49 additions and 34 deletions
21
main.go
21
main.go
|
@ -159,19 +159,25 @@ func BuildProcess() {
|
||||||
log.Fatalf("Error resolving source path: %v", err)
|
log.Fatalf("Error resolving source path: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Detect the build directory dynamically
|
||||||
|
buildDir, err := spitfire.ResolveBuildDir(sourcePath)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Error resolving build directory: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
if all {
|
if all {
|
||||||
spitfire.DownloadSource(sourcePath, sourceRepo)
|
spitfire.DownloadSource(sourcePath, sourceRepo)
|
||||||
spitfire.DiscardChanges(sourcePath)
|
spitfire.DiscardChanges(sourcePath)
|
||||||
spitfire.CleanBuild(sourcePath)
|
spitfire.CleanBuild(sourcePath)
|
||||||
spitfire.UpdateRepo(sourcePath)
|
spitfire.UpdateRepo(sourcePath)
|
||||||
|
if err := spitfire.ApplyPatches(sourcePath, patchesRepo, "pre-compile-patches", filepath.Join(sourcePath, "patcher")); err != nil {
|
||||||
// Pass patchesRepo to ApplyPatches
|
|
||||||
if err := spitfire.ApplyPatches(sourcePath, patchesRepo); err != nil {
|
|
||||||
log.Fatalf("Error during patch application: %v", err)
|
log.Fatalf("Error during patch application: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
spitfire.Configure(sourcePath)
|
spitfire.Configure(sourcePath)
|
||||||
spitfire.Build(sourcePath)
|
spitfire.Build(sourcePath)
|
||||||
|
if err := spitfire.ApplyPatches(buildDir, patchesRepo, "post-compile-patches", filepath.Join(sourcePath, "patcher")); err != nil {
|
||||||
|
log.Fatalf("Error during patch application: %v", err)
|
||||||
|
}
|
||||||
if run {
|
if run {
|
||||||
spitfire.RunProject(sourcePath)
|
spitfire.RunProject(sourcePath)
|
||||||
}
|
}
|
||||||
|
@ -185,15 +191,16 @@ func BuildProcess() {
|
||||||
fmt.Println("Mozilla repository updated.")
|
fmt.Println("Mozilla repository updated.")
|
||||||
} else if patches {
|
} else if patches {
|
||||||
spitfire.DownloadSource(sourcePath, sourceRepo)
|
spitfire.DownloadSource(sourcePath, sourceRepo)
|
||||||
|
if err := spitfire.ApplyPatches(sourcePath, patchesRepo, "pre-compile-patches", filepath.Join(sourcePath, "patcher")); err != nil {
|
||||||
// Pass patchesRepo to ApplyPatches
|
|
||||||
if err := spitfire.ApplyPatches(sourcePath, patchesRepo); err != nil {
|
|
||||||
log.Fatalf("Error during patch application: %v", err)
|
log.Fatalf("Error during patch application: %v", err)
|
||||||
}
|
}
|
||||||
fmt.Println("Patches updated.")
|
fmt.Println("Patches updated.")
|
||||||
} else if buildFlag {
|
} else if buildFlag {
|
||||||
spitfire.Configure(sourcePath)
|
spitfire.Configure(sourcePath)
|
||||||
spitfire.Build(sourcePath)
|
spitfire.Build(sourcePath)
|
||||||
|
if err := spitfire.ApplyPatches(buildDir, patchesRepo, "post-compile-patches", filepath.Join(sourcePath, "patcher")); err != nil {
|
||||||
|
log.Fatalf("Error during patch application: %v", err)
|
||||||
|
}
|
||||||
if run {
|
if run {
|
||||||
spitfire.RunProject(sourcePath)
|
spitfire.RunProject(sourcePath)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ApplyPatches handles cloning, updating, and applying patches
|
// ApplyPatches handles cloning, updating, and applying patches
|
||||||
func ApplyPatches(sourcePath string, patchesRepo string) error {
|
func ApplyPatches(sourcePath string, patchesRepo string, patchesPath string, patchesCloneDir string) error {
|
||||||
// Define the patches repository and clone directory
|
// Define the full patches path
|
||||||
patchesCloneDir := filepath.Join(sourcePath, "patches")
|
fullPatchesPath := filepath.Join(patchesCloneDir, patchesPath) // Cleaned path without double slashes
|
||||||
|
|
||||||
fmt.Printf("Source Path: %s\n", sourcePath)
|
fmt.Printf("Source Path: %s\n", sourcePath)
|
||||||
fmt.Printf("Patches Clone Directory: %s\n", patchesCloneDir)
|
fmt.Printf("Patches Clone Directory: %s\n", patchesCloneDir)
|
||||||
fmt.Printf("Patches Repository URL: %s\n", patchesRepo)
|
fmt.Printf("Patches Repository URL: %s\n", patchesRepo)
|
||||||
|
fmt.Printf("Patches Path: %s\n", fullPatchesPath)
|
||||||
|
|
||||||
// Check if the patches directory already exists
|
// Check if the patches directory already exists
|
||||||
if _, err := os.Stat(patchesCloneDir); os.IsNotExist(err) {
|
if _, err := os.Stat(patchesCloneDir); os.IsNotExist(err) {
|
||||||
|
@ -26,34 +28,15 @@ func ApplyPatches(sourcePath string, patchesRepo string) error {
|
||||||
return fmt.Errorf("failed to clone patches repository: %v", err)
|
return fmt.Errorf("failed to clone patches repository: %v", err)
|
||||||
}
|
}
|
||||||
fmt.Println("Patches repository cloned successfully.")
|
fmt.Println("Patches repository cloned successfully.")
|
||||||
} else {
|
|
||||||
// If the directory exists, fetch and pull the latest changes
|
|
||||||
fmt.Println("Patches directory already exists. Fetching latest changes.")
|
|
||||||
cmdFetch := exec.Command("git", "fetch", "--all")
|
|
||||||
cmdFetch.Dir = patchesCloneDir
|
|
||||||
cmdFetch.Stdout = os.Stdout
|
|
||||||
cmdFetch.Stderr = os.Stderr
|
|
||||||
if err := cmdFetch.Run(); err != nil {
|
|
||||||
return fmt.Errorf("failed to fetch updates for patches repository: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdReset := exec.Command("git", "reset", "--hard", "origin/main")
|
|
||||||
cmdReset.Dir = patchesCloneDir
|
|
||||||
cmdReset.Stdout = os.Stdout
|
|
||||||
cmdReset.Stderr = os.Stderr
|
|
||||||
if err := cmdReset.Run(); err != nil {
|
|
||||||
return fmt.Errorf("failed to reset patches repository to latest state: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Println("Patches repository updated successfully.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the directory exists
|
// Verify the patches directory exists
|
||||||
if _, err := os.Stat(patchesCloneDir); os.IsNotExist(err) {
|
if _, err := os.Stat(fullPatchesPath); os.IsNotExist(err) {
|
||||||
return fmt.Errorf("patches directory not found after update: %s", patchesCloneDir)
|
return fmt.Errorf("patches path not found: %s", fullPatchesPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply the patches using `go run apply.go`
|
// Apply the patches using `run.sh`
|
||||||
applyCmd := exec.Command("run.sh", "--path "+sourcePath)
|
applyCmd := exec.Command("./run.sh", "--path", sourcePath, "--patches", fullPatchesPath)
|
||||||
applyCmd.Dir = patchesCloneDir // Run from the patches directory
|
applyCmd.Dir = patchesCloneDir // Run from the patches directory
|
||||||
applyCmd.Stdout = os.Stdout
|
applyCmd.Stdout = os.Stdout
|
||||||
applyCmd.Stderr = os.Stderr
|
applyCmd.Stderr = os.Stderr
|
||||||
|
|
25
spitfire/resolvebuilddir.go
Normal file
25
spitfire/resolvebuilddir.go
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
package spitfire
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ResolveBuildDir detects the build directory dynamically
|
||||||
|
func ResolveBuildDir(sourcePath string) (string, error) {
|
||||||
|
// The expected build directory pattern
|
||||||
|
globPattern := filepath.Join(sourcePath, "obj-*")
|
||||||
|
|
||||||
|
// Find matching directories
|
||||||
|
matches, err := filepath.Glob(globPattern)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error resolving build directory: %v", err)
|
||||||
|
}
|
||||||
|
if len(matches) == 0 {
|
||||||
|
return "", fmt.Errorf("build directory not found under %s", sourcePath)
|
||||||
|
}
|
||||||
|
full := filepath.Join(matches[0], "dist", "bin")
|
||||||
|
|
||||||
|
// Return the first match (assumes one build directory exists)
|
||||||
|
return full, nil
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue