Builder/builder.sh

195 lines
6 KiB
Bash
Raw Normal View History

2024-03-25 20:31:58 +01:00
#!/bin/bash
# Define source paths
2024-03-25 22:03:46 +01:00
SOURCE_PATH="./mozilla-central"
PATCHES_DIR="$SOURCE_PATH/Spitfire"
2024-03-25 20:31:58 +01:00
SOURCE_REPO="https://hg.mozilla.org/mozilla-central"
2024-03-25 22:03:46 +01:00
PATCHES_REPO="https://weforgecode.xyz/Spitfire/Browser.git"
2024-03-25 20:31:58 +01:00
2024-07-18 14:48:06 +02:00
SOURCE_PATH=$(realpath "$SOURCE_PATH") || { echo "Failed to resolve SOURCE_PATH. Exiting."; exit 1; }
PATCHES_DIR=$(realpath "$PATCHES_DIR") || { echo "Failed to resolve PATCHES_DIR. Exiting."; exit 1; }
2024-03-25 22:03:46 +01:00
2024-09-04 19:11:37 +02:00
# Array to store errors
errors=()
2024-03-25 22:03:46 +01:00
# Function to download Mozilla source if not present
2024-03-25 20:31:58 +01:00
download_source() {
if [ ! -d "$SOURCE_PATH" ]; then
2024-03-25 22:03:46 +01:00
echo "Mozilla source not found. Cloning from repository..."
2024-09-04 19:11:37 +02:00
hg clone "$SOURCE_REPO" "$SOURCE_PATH" || errors+=("Failed to clone Mozilla repository.")
2024-03-25 20:31:58 +01:00
else
2024-03-25 22:03:46 +01:00
echo "Mozilla source already exists."
2024-03-25 20:31:58 +01:00
fi
}
# Function to discard uncommitted changes
discard_changes() {
echo "Discarding uncommitted changes..."
2024-09-04 19:11:37 +02:00
hg revert --all --no-backup -R "$SOURCE_PATH" || errors+=("Failed to revert changes in Mozilla repository.")
2024-03-25 20:31:58 +01:00
}
# Function to clean build
clean_build() {
echo "Cleaning build..."
2024-09-04 19:11:37 +02:00
cd "$SOURCE_PATH" || { errors+=("Failed to navigate to source directory."); return; }
hg revert --all --no-backup || errors+=("Failed to revert changes in Mozilla repository.")
./mach clobber || errors+=("Failed to clean build.")
2024-03-25 20:31:58 +01:00
}
# Function to update Mozilla repository
update_repo() {
echo "Updating Mozilla repository..."
2024-09-04 19:11:37 +02:00
cd "$SOURCE_PATH" || { errors+=("Failed to navigate to source directory."); return; }
hg pull -u || errors+=("Failed to update Mozilla repository.")
2024-03-25 20:31:58 +01:00
}
# Function to update patches
update_patches() {
echo "Updating patches..."
2024-03-25 22:03:46 +01:00
if [ -d "$PATCHES_DIR" ]; then
echo "Patches directory already exists. Cleaning and pulling updates..."
2024-09-04 19:11:37 +02:00
cd "$PATCHES_DIR" || { errors+=("Failed to navigate to patches directory."); return; }
git clean -xdf || errors+=("Failed to clean patches directory.")
2024-09-04 19:11:37 +02:00
git stash push --include-untracked || echo "No local changes to save."
2024-09-04 19:11:37 +02:00
git fetch || errors+=("Failed to fetch updates from patches repository.")
if git show-ref --verify --quiet refs/heads/main; then
2024-09-04 19:11:37 +02:00
git rebase origin/main || errors+=("Failed to rebase updates from main branch.")
elif git show-ref --verify --quiet refs/heads/master; then
2024-09-04 19:11:37 +02:00
git rebase origin/master || errors+=("Failed to rebase updates from master branch.")
else
2024-09-04 19:11:37 +02:00
errors+=("No valid branch (main or master) found in patches repository.")
return
fi
2024-09-04 19:11:37 +02:00
# Check if there are any stashes before popping
if git stash list | grep -q 'stash@{0}'; then
git stash pop || errors+=("Failed to apply and drop stashed changes.")
else
echo "No stash entries found, skipping pop."
fi
2024-03-25 22:03:46 +01:00
else
echo "Patches directory does not exist. Cloning repository..."
2024-09-04 19:11:37 +02:00
git clone "$PATCHES_REPO" "$PATCHES_DIR" || errors+=("Failed to clone patches repository.")
2024-03-25 22:03:46 +01:00
fi
echo "Copying files from patches directory to Firefox source directory..."
2024-09-04 19:11:37 +02:00
rsync -av --exclude='.git' "$PATCHES_DIR/" "$SOURCE_PATH/" || errors+=("Failed to copy files.")
2024-03-25 20:31:58 +01:00
}
2024-07-18 14:48:06 +02:00
# Function to configure Spitfire
configure() {
2024-03-25 20:31:58 +01:00
echo "Configuring Spitfire..."
2024-09-04 19:11:37 +02:00
cd "$SOURCE_PATH" || { errors+=("Failed to navigate to source directory."); return; }
./mach configure || errors+=("Configuration failed.")
2024-07-18 14:48:06 +02:00
}
2024-03-25 20:31:58 +01:00
2024-07-18 14:48:06 +02:00
# Function to build Spitfire
build() {
2024-03-25 20:31:58 +01:00
echo "Building Spitfire..."
2024-09-04 19:11:37 +02:00
cd "$SOURCE_PATH" || { errors+=("Failed to navigate to source directory."); return; }
./mach build || errors+=("Build failed.")
2024-03-25 20:31:58 +01:00
}
2024-03-26 21:15:14 +01:00
# Function to run the project after build
run_project() {
echo "Running the project..."
2024-09-04 19:11:37 +02:00
cd "$SOURCE_PATH" || { errors+=("Failed to navigate to browser directory."); return; }
./mach run || errors+=("Failed to run the project.")
2024-03-26 21:15:14 +01:00
}
2024-03-25 22:03:46 +01:00
# Function to print usage instructions
print_help() {
echo "Usage: ./builder.sh [options]"
echo "Options:"
echo " -a, --all : Perform all steps (build, clean, update)"
echo " -b, --build : Build Spitfire"
echo " -c, --clean : Clean build"
echo " -u, --update : Update Mozilla repository"
echo " -p, --patches : Update patches"
2024-03-26 21:15:14 +01:00
echo " -r, --run : Run the project after build using mach run in the browser directory"
2024-03-25 22:03:46 +01:00
echo " -h, --help : Display this help message"
2024-07-18 14:48:06 +02:00
exit 0
2024-03-25 22:03:46 +01:00
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-a|--all)
all=true
;;
-b|--build)
build=true
;;
-c|--clean)
clean=true
;;
-u|--update)
update=true
;;
-p|--patches)
patches=true
;;
2024-03-26 21:15:14 +01:00
-r|--run)
run=true
;;
2024-03-25 22:03:46 +01:00
-h|--help)
print_help
;;
*)
echo "Invalid option: $key"
print_help
;;
esac
shift
done
# Main script execution based on flags
if [ "$all" = true ]; then
download_source
discard_changes
clean_build
update_repo
update_patches
2024-07-18 14:48:06 +02:00
configure
build
2024-03-26 21:15:14 +01:00
if [ "$run" = true ]; then
run_project
fi
2024-03-25 22:03:46 +01:00
echo "Spitfire build completed successfully."
2024-03-26 21:15:14 +01:00
elif [ "$build" = true ]; then
2024-07-18 14:48:06 +02:00
configure
build
2024-03-26 21:15:14 +01:00
if [ "$run" = true ]; then
run_project
fi
2024-03-25 22:03:46 +01:00
echo "Spitfire build completed successfully."
elif [ "$clean" = true ]; then
clean_build
echo "Cleaned Firefox build."
elif [ "$update" = true ]; then
download_source
update_repo
echo "Mozilla repository updated."
elif [ "$patches" = true ]; then
download_source
update_patches
echo "Patches updated."
2024-03-26 21:15:14 +01:00
elif [ "$run" = true ]; then
run_project
2024-03-25 22:03:46 +01:00
else
print_help
fi
2024-03-25 20:31:58 +01:00
2024-09-04 19:11:37 +02:00
# Print all collected errors at the end
if [ ${#errors[@]} -ne 0 ]; then
echo "The following errors occurred during execution:"
for error in "${errors[@]}"; do
echo "- $error"
done
fi
2024-03-25 22:03:46 +01:00
exit 0