mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore: enhance repack-juggler (#8586)
Instead of building firefox using `//browser_patches/buid.sh ff-beta`, one can use `//browser_patches/repack-juggler.mjs ff-beta`. The script will download the last Playwright build, and repack Juggler and preferences there.
This commit is contained in:
parent
9da26f9534
commit
16b0a96e78
@ -83,6 +83,9 @@ function copyFile({from, to}) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = { installFirefoxPreferences };
|
||||||
|
|
||||||
|
if (require.main === module) {
|
||||||
if (process.argv.length !== 3) {
|
if (process.argv.length !== 3) {
|
||||||
console.log('ERROR: expected a path to the directory with browser build');
|
console.log('ERROR: expected a path to the directory with browser build');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
@ -94,3 +97,4 @@ installFirefoxPreferences(process.argv[2]).catch(error => {
|
|||||||
console.error(error);
|
console.error(error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|||||||
@ -83,6 +83,9 @@ function copyFile({from, to}) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = { installFirefoxPreferences };
|
||||||
|
|
||||||
|
if (require.main === module) {
|
||||||
if (process.argv.length !== 3) {
|
if (process.argv.length !== 3) {
|
||||||
console.log('ERROR: expected a path to the directory with browser build');
|
console.log('ERROR: expected a path to the directory with browser build');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
@ -94,3 +97,4 @@ installFirefoxPreferences(process.argv[2]).catch(error => {
|
|||||||
console.error(error);
|
console.error(error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|||||||
@ -14,8 +14,25 @@ const existsAsync = path => new Promise(resolve => fs.stat(path, err => resolve(
|
|||||||
const __filename = URL.fileURLToPath(import.meta.url);
|
const __filename = URL.fileURLToPath(import.meta.url);
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
|
if (process.argv[2] === '--help' || process.argv[2] === '-h') {
|
||||||
|
console.log(`usage: ${path.basename(process.argv[1])} [firefox|ff|firefox-beta|ff-beta] [build number] [build platform]`);
|
||||||
|
console.log(``);
|
||||||
|
console.log(`Repackages Firefox with tip-of-tree Juggler implementation`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let browserName = '';
|
||||||
|
if (process.argv[2] === 'firefox' || process.argv[2] === 'ff') {
|
||||||
|
browserName = 'firefox';
|
||||||
|
} else if (process.argv[2] === 'firefox-beta' || process.argv[2] === 'ff-beta') {
|
||||||
|
browserName = 'firefox-beta';
|
||||||
|
} else {
|
||||||
|
console.error('ERROR: unknown firefox to repackage - either "firefox", "ff", "firefox-beta" or "ff-beta" is allowed as first argument');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
// Path to jar.mn in the juggler
|
// Path to jar.mn in the juggler
|
||||||
const JARMN_PATH = path.join(__dirname, 'juggler', 'jar.mn');
|
const JARMN_PATH = path.join(__dirname, browserName, 'juggler', 'jar.mn');
|
||||||
// Workdir for Firefox repackaging
|
// Workdir for Firefox repackaging
|
||||||
const BUILD_DIRECTORY = `/tmp/repackaged-firefox`;
|
const BUILD_DIRECTORY = `/tmp/repackaged-firefox`;
|
||||||
// Information about currently downloaded build
|
// Information about currently downloaded build
|
||||||
@ -30,7 +47,6 @@ const OMNI_JUGGLER_DIR = path.join(OMNI_EXTRACT_DIR, 'chrome', 'juggler');
|
|||||||
const EXECUTABLE_PATHS = {
|
const EXECUTABLE_PATHS = {
|
||||||
'ubuntu18.04': ['firefox', 'firefox'],
|
'ubuntu18.04': ['firefox', 'firefox'],
|
||||||
'ubuntu20.04': ['firefox', 'firefox'],
|
'ubuntu20.04': ['firefox', 'firefox'],
|
||||||
'mac10.13': ['firefox', 'Nightly.app', 'Contents', 'MacOS', 'firefox'],
|
|
||||||
'mac10.14': ['firefox', 'Nightly.app', 'Contents', 'MacOS', 'firefox'],
|
'mac10.14': ['firefox', 'Nightly.app', 'Contents', 'MacOS', 'firefox'],
|
||||||
'mac10.15': ['firefox', 'Nightly.app', 'Contents', 'MacOS', 'firefox'],
|
'mac10.15': ['firefox', 'Nightly.app', 'Contents', 'MacOS', 'firefox'],
|
||||||
'mac11': ['firefox', 'Nightly.app', 'Contents', 'MacOS', 'firefox'],
|
'mac11': ['firefox', 'Nightly.app', 'Contents', 'MacOS', 'firefox'],
|
||||||
@ -40,59 +56,55 @@ const EXECUTABLE_PATHS = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const DOWNLOAD_URLS = {
|
const DOWNLOAD_URLS = {
|
||||||
|
'firefox': {
|
||||||
'ubuntu18.04': 'https://playwright.azureedge.net/builds/firefox/%s/firefox-ubuntu-18.04.zip',
|
'ubuntu18.04': 'https://playwright.azureedge.net/builds/firefox/%s/firefox-ubuntu-18.04.zip',
|
||||||
'ubuntu20.04': 'https://playwright.azureedge.net/builds/firefox/%s/firefox-ubuntu-20.04.zip',
|
'ubuntu20.04': 'https://playwright.azureedge.net/builds/firefox/%s/firefox-ubuntu-20.04.zip',
|
||||||
'mac10.13': 'https://playwright.azureedge.net/builds/firefox/%s/firefox-mac-10.14.zip',
|
|
||||||
'mac10.14': 'https://playwright.azureedge.net/builds/firefox/%s/firefox-mac-10.14.zip',
|
'mac10.14': 'https://playwright.azureedge.net/builds/firefox/%s/firefox-mac-10.14.zip',
|
||||||
'mac10.15': 'https://playwright.azureedge.net/builds/firefox/%s/firefox-mac-10.14.zip',
|
'mac10.15': 'https://playwright.azureedge.net/builds/firefox/%s/firefox-mac-10.14.zip',
|
||||||
'mac11': 'https://playwright.azureedge.net/builds/firefox/%s/firefox-mac-10.14.zip',
|
'mac11': 'https://playwright.azureedge.net/builds/firefox/%s/firefox-mac-10.14.zip',
|
||||||
'mac11-arm64': 'https://playwright.azureedge.net/builds/firefox/%s/firefox-mac-11.0-arm64.zip',
|
'mac11-arm64': 'https://playwright.azureedge.net/builds/firefox/%s/firefox-mac-11.0-arm64.zip',
|
||||||
'win32': 'https://playwright.azureedge.net/builds/firefox/%s/firefox-win32.zip',
|
'win32': 'https://playwright.azureedge.net/builds/firefox/%s/firefox-win32.zip',
|
||||||
'win64': 'https://playwright.azureedge.net/builds/firefox/%s/firefox-win64.zip',
|
'win64': 'https://playwright.azureedge.net/builds/firefox/%s/firefox-win64.zip',
|
||||||
|
},
|
||||||
|
'firefox-beta': {
|
||||||
|
'ubuntu18.04': 'https://playwright.azureedge.net/builds/firefox-beta/%s/firefox-beta-ubuntu-18.04.zip',
|
||||||
|
'ubuntu20.04': 'https://playwright.azureedge.net/builds/firefox-beta/%s/firefox-beta-ubuntu-20.04.zip',
|
||||||
|
'mac10.14': 'https://playwright.azureedge.net/builds/firefox-beta/%s/firefox-beta-mac-10.14.zip',
|
||||||
|
'mac10.15': 'https://playwright.azureedge.net/builds/firefox-beta/%s/firefox-beta-mac-10.14.zip',
|
||||||
|
'mac11': 'https://playwright.azureedge.net/builds/firefox-beta/%s/firefox-beta-mac-10.14.zip',
|
||||||
|
'mac11-arm64': 'https://playwright.azureedge.net/builds/firefox-beta/%s/firefox-beta-mac-11.0-arm64.zip',
|
||||||
|
'win32': 'https://playwright.azureedge.net/builds/firefox-beta/%s/firefox-beta-win32.zip',
|
||||||
|
'win64': 'https://playwright.azureedge.net/builds/firefox-beta/%s/firefox-beta-win64.zip',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (process.argv[2] === '--help' || process.argv[2] === '-h') {
|
async function ensureFirefoxBuild(browserName, buildNumber, buildPlatform) {
|
||||||
console.log(`usage: ${path.basename(process.argv[1])} [--prepare] [build number]`);
|
|
||||||
console.log(``);
|
|
||||||
console.log(`Repackages Firefox with tip-of-tree Juggler implementation`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.argv[2] === '--prepare')
|
|
||||||
await prepareFirefoxBuild(process.argv[3], process.argv[4]);
|
|
||||||
else
|
|
||||||
await repackageJuggler();
|
|
||||||
|
|
||||||
async function prepareFirefoxBuild(buildNumber, buildPlatform) {
|
|
||||||
if (!buildNumber)
|
if (!buildNumber)
|
||||||
buildNumber = (await fs.promises.readFile(path.join(__dirname, 'BUILD_NUMBER'), 'utf8')).split('\n').shift();
|
buildNumber = (await fs.promises.readFile(path.join(__dirname, browserName, 'BUILD_NUMBER'), 'utf8')).split('\n').shift();
|
||||||
if (!buildPlatform)
|
if (!buildPlatform)
|
||||||
buildPlatform = getHostPlatform();
|
buildPlatform = getHostPlatform();
|
||||||
const currentBuildInfo = await fs.promises.readFile(BUILD_INFO_PATH).then(text => JSON.parse(text)).catch(e => ({ buildPlatform: '', buildNumber: '' }));
|
const currentBuildInfo = await fs.promises.readFile(BUILD_INFO_PATH).then(text => JSON.parse(text)).catch(e => ({ buildPlatform: '', buildNumber: '', browserName: '' }));
|
||||||
|
|
||||||
if (currentBuildInfo.buildPlatform === buildPlatform && currentBuildInfo.buildNumber === buildNumber)
|
if (currentBuildInfo.buildPlatform === buildPlatform && currentBuildInfo.buildNumber === buildNumber && currentBuildInfo.browserName === browserName)
|
||||||
return;
|
return currentBuildInfo;
|
||||||
await fs.promises.rm(BUILD_DIRECTORY, { recursive: true }).catch(e => {});
|
await fs.promises.rmdir(BUILD_DIRECTORY, { recursive: true }).catch(e => {});
|
||||||
await fs.promises.mkdir(BUILD_DIRECTORY);
|
await fs.promises.mkdir(BUILD_DIRECTORY);
|
||||||
const buildZipPath = path.join(BUILD_DIRECTORY, 'firefox.zip');
|
const buildZipPath = path.join(BUILD_DIRECTORY, 'firefox.zip');
|
||||||
|
|
||||||
const urlTemplate = DOWNLOAD_URLS[buildPlatform];
|
const urlTemplate = DOWNLOAD_URLS[browserName][buildPlatform];
|
||||||
if (!urlTemplate)
|
if (!urlTemplate)
|
||||||
throw new Error(`ERROR: repack-juggler does not support ${buildPlatform}`);
|
throw new Error(`ERROR: repack-juggler does not support ${buildPlatform}`);
|
||||||
const url = util.format(urlTemplate, buildNumber);
|
const url = util.format(urlTemplate, buildNumber);
|
||||||
console.log(`Downloading Firefox r${buildNumber} for ${buildPlatform} - it might take a few minutes`);
|
console.log(`Downloading ${browserName} r${buildNumber} for ${buildPlatform} - it might take a few minutes`);
|
||||||
await downloadFile(url, buildZipPath);
|
await downloadFile(url, buildZipPath);
|
||||||
await spawnAsync('unzip', [ buildZipPath ], {cwd: BUILD_DIRECTORY});
|
await spawnAsync('unzip', [ buildZipPath ], {cwd: BUILD_DIRECTORY});
|
||||||
await fs.promises.writeFile(BUILD_INFO_PATH, JSON.stringify({ buildNumber, buildPlatform }), 'utf8');
|
const buildInfo = { buildNumber, buildPlatform, browserName };
|
||||||
|
await fs.promises.writeFile(BUILD_INFO_PATH, JSON.stringify(buildInfo), 'utf8');
|
||||||
|
return buildInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function repackageJuggler() {
|
async function repackageJuggler(browserName, buildInfo) {
|
||||||
const currentBuildInfo = await fs.promises.readFile(BUILD_INFO_PATH).then(text => JSON.parse(text)).catch(e => null);
|
const {buildNumber, buildPlatform} = buildInfo;
|
||||||
if (!currentBuildInfo) {
|
|
||||||
console.log('ERROR: build is not prepared!');
|
|
||||||
console.log(`run ${path.basename(process.argv[1])} --prepare`);
|
|
||||||
}
|
|
||||||
const {buildNumber, buildPlatform} = currentBuildInfo;
|
|
||||||
|
|
||||||
// Find all omni.ja files in the Firefox build.
|
// Find all omni.ja files in the Firefox build.
|
||||||
const omniPaths = await spawnAsync('find', ['.', '-name', 'omni.ja'], {
|
const omniPaths = await spawnAsync('find', ['.', '-name', 'omni.ja'], {
|
||||||
@ -118,28 +130,32 @@ async function repackageJuggler() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Let's repackage omni folder!
|
// Let's repackage omni folder!
|
||||||
await fs.promises.rm(OMNI_EXTRACT_DIR, { recursive: true }).catch(e => {});
|
await fs.promises.rmdir(OMNI_EXTRACT_DIR, { recursive: true }).catch(e => {});
|
||||||
await fs.promises.mkdir(OMNI_EXTRACT_DIR);
|
await fs.promises.mkdir(OMNI_EXTRACT_DIR);
|
||||||
|
|
||||||
await spawnAsync('unzip', [OMNI_BACKUP_PATH], {cwd: OMNI_EXTRACT_DIR });
|
await spawnAsync('unzip', [OMNI_BACKUP_PATH], {cwd: OMNI_EXTRACT_DIR });
|
||||||
// Remove current juggler directory
|
// Remove current juggler directory
|
||||||
await fs.promises.rm(OMNI_JUGGLER_DIR, { recursive: true });
|
await fs.promises.rmdir(OMNI_JUGGLER_DIR, { recursive: true });
|
||||||
// Repopulate with tip-of-tree juggler files
|
// Repopulate with tip-of-tree juggler files
|
||||||
const jarmn = await fs.promises.readFile(JARMN_PATH, 'utf8');
|
const jarmn = await fs.promises.readFile(JARMN_PATH, 'utf8');
|
||||||
const jarLines = jarmn.split('\n').map(line => line.trim()).filter(line => line.startsWith('content/') && line.endsWith(')'));
|
const jarLines = jarmn.split('\n').map(line => line.trim()).filter(line => line.startsWith('content/') && line.endsWith(')'));
|
||||||
for (const line of jarLines) {
|
for (const line of jarLines) {
|
||||||
const tokens = line.split(/\s+/);
|
const tokens = line.split(/\s+/);
|
||||||
const toPath = path.join(OMNI_JUGGLER_DIR, tokens[0]);
|
const toPath = path.join(OMNI_JUGGLER_DIR, tokens[0]);
|
||||||
const fromPath = path.join(__dirname, 'juggler', tokens[1].slice(1, -1));
|
const fromPath = path.join(__dirname, browserName, 'juggler', tokens[1].slice(1, -1));
|
||||||
await fs.promises.mkdir(path.dirname(toPath), { recursive: true});
|
await fs.promises.mkdir(path.dirname(toPath), { recursive: true});
|
||||||
await fs.promises.copyFile(fromPath, toPath);
|
await fs.promises.copyFile(fromPath, toPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
await fs.promises.rm(omniWithJugglerPath);
|
await fs.promises.unlink(omniWithJugglerPath);
|
||||||
await spawnAsync('zip', ['-0', '-qr9XD', omniWithJugglerPath, '.'], {cwd: OMNI_EXTRACT_DIR, stdio: 'inherit'});
|
await spawnAsync('zip', ['-0', '-qr9XD', omniWithJugglerPath, '.'], {cwd: OMNI_EXTRACT_DIR, stdio: 'inherit'});
|
||||||
|
|
||||||
|
const module = await import(path.join(__dirname, browserName, 'install-preferences.js'));
|
||||||
|
await module.default.installFirefoxPreferences(path.join(BUILD_DIRECTORY, 'firefox'));
|
||||||
|
|
||||||
// Output executable path to be used in test.
|
// Output executable path to be used in test.
|
||||||
console.log(`
|
console.log(`
|
||||||
|
browser: ${browserName}
|
||||||
buildNumber: ${buildNumber}
|
buildNumber: ${buildNumber}
|
||||||
buildPlatform: ${buildPlatform}
|
buildPlatform: ${buildPlatform}
|
||||||
executablePath: ${path.join(BUILD_DIRECTORY, ...EXECUTABLE_PATHS[buildPlatform])}
|
executablePath: ${path.join(BUILD_DIRECTORY, ...EXECUTABLE_PATHS[buildPlatform])}
|
||||||
@ -286,3 +302,11 @@ function getHostPlatform() {
|
|||||||
return os.arch() === 'x64' ? 'win64' : 'win32';
|
return os.arch() === 'x64' ? 'win64' : 'win32';
|
||||||
return platform;
|
return platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const buildInfo = await ensureFirefoxBuild(browserName, process.argv[3], process.argv[4]);
|
||||||
|
await repackageJuggler(browserName, buildInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
await main();
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user