diff --git a/.gitignore b/.gitignore index 4f15af1..ad561a9 100644 --- a/.gitignore +++ b/.gitignore @@ -109,3 +109,6 @@ site/ docs/public/ .gluon + +# Patch generation +.moz-central diff --git a/.npmignore b/.npmignore index c3c10a1..6a195cb 100644 --- a/.npmignore +++ b/.npmignore @@ -16,4 +16,8 @@ yarn.lock .vscode/ .github/ .eslintrc.js -jest.config.js \ No newline at end of file +jest.config.js + +# Patch generation +.moz-central +patches.sh \ No newline at end of file diff --git a/patches.sh b/patches.sh new file mode 100755 index 0000000..98fd61e --- /dev/null +++ b/patches.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +action=$1 + +# Make sure the user has specified the location of mozilla-central in their +# environment. Some people (i.e. trickypr) prefer to clone it into other places +if [ ! -f .moz-central ] +then + echo "Please make sure you specify the location of your checkout of `mozilla-central`" + echo "inside of the `.moz-central` file." + exit 1 +fi + +mozilla_centeral_repo=$(cat .moz-central) +last_patch=`exec ls -1 ./template/patches.optional | sed 's/-.*//g' | sort -n | tail -1` +next_patch=`expr 1 + ${last_patch:=0}` +root_pwd=$PWD + +if [ $action = "import" ] +then + echo "Importing:" + echo + + cd $mozilla_centeral_repo + for file in $root_pwd/template/patches.optional/*.patch + do + echo " $file..." + # --forward is used to skip the patch if it has already been applied + patch -p1 --forward < $file + done + + cd $root_pwd +elif [ $action = "export" ] +then + if [ -x "$2" ] + then + echo "Please provide a file name. Usage: $0 $action " + exit 1 + fi + + echo "Exporting: ${@:2}" + echo + + cd $mozilla_centeral_repo + git add ${@:2} + git commit + git format-patch --start-number $next_patch -1 -o $root_pwd/template/patches.optional + cd $root_pwd +else + echo "Usage: $0 import|export" + echo + echo " import: Import all patches in ./template/patches.optional" + echo " export: Exports a specific patch. Usage: $0 export " +fi \ No newline at end of file diff --git a/src/commands/patches/command.ts b/src/commands/patches/command.ts index de51949..1d6369d 100644 --- a/src/commands/patches/command.ts +++ b/src/commands/patches/command.ts @@ -13,6 +13,7 @@ import { existsSync, writeFileSync } from 'fs' import { patchCountFile } from '../../middleware/patch-check' import { checkHash } from '../../utils' import { log } from '../../log' +import { templateDir } from '../setupProject' type ListrTaskGroup = Listr.ListrTask @@ -95,8 +96,32 @@ function importGitPatch(): ListrTaskGroup { ) } -export async function applyPatches(): Promise { - await new Listr([importMelonPatches(), importFolders(), importGitPatch()], { - renderer: log.isDebug ? 'verbose' : 'default', - }).run() +function importInternalPatch(): ListrTaskGroup { + const patches = sync('*.patch', { + nodir: true, + cwd: join(templateDir, 'patches.optional'), + }).map((path) => ({ + name: path, + path: join(templateDir, 'patches.optional', path), + })) + + return patchMethod( + 'gluon', + patches, + async (patch) => await gitPatch.apply(patch.path) + ) +} + +export async function applyPatches(): Promise { + await new Listr( + [ + importInternalPatch(), + importMelonPatches(), + importFolders(), + importGitPatch(), + ], + { + renderer: log.isDebug ? 'verbose' : 'default', + } + ).run() } diff --git a/template/patches.optional/0001-Reduce-update-info.patch b/template/patches.optional/0001-Reduce-update-info.patch new file mode 100644 index 0000000..a1979b1 --- /dev/null +++ b/template/patches.optional/0001-Reduce-update-info.patch @@ -0,0 +1,26 @@ +From d1a2aac4daffb822afcee499ee329304dd53a520 Mon Sep 17 00:00:00 2001 +From: trickypr +Date: Thu, 23 Jun 2022 16:13:36 +1000 +Subject: [PATCH] Reduce update info + +The default mozilla update config will send a bunch of unnessisary +config to the update server, which just increases the complexity of the +updates that gluon needs to generate. +--- + build/application.ini.in | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/build/application.ini.in b/build/application.ini.in +index 6df13230a4..797006c4ee 100644 +--- a/build/application.ini.in ++++ b/build/application.ini.in +@@ -52,5 +52,5 @@ ServerURL=@MOZ_CRASHREPORTER_URL@/submit?id=@MOZ_APP_ID@&version=@MOZ_APP_VERSIO + + #if MOZ_UPDATER + [AppUpdate] +-URL=https://@MOZ_APPUPDATE_HOST@/update/6/%PRODUCT%/%VERSION%/%BUILD_ID%/%BUILD_TARGET%/%LOCALE%/%CHANNEL%/%OS_VERSION%/%SYSTEM_CAPABILITIES%/%DISTRIBUTION%/%DISTRIBUTION_VERSION%/update.xml ++URL=http://@MOZ_APPUPDATE_HOST@/update/browser/%BUILD_TARGET%/%CHANNEL%/update.xml + #endif +-- +2.36.1 +