mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
feat(installer): start downloadinb Ubuntu 20.04 builds (#3126)
Start auto-detecting Ubuntu 20.04 and downloading custom webkit build for it. References #2745
This commit is contained in:
parent
0b9c6473b6
commit
bbe7dbe9ae
@ -18,12 +18,14 @@
|
|||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
import * as os from 'os';
|
||||||
import * as removeFolder from 'rimraf';
|
import * as removeFolder from 'rimraf';
|
||||||
import * as util from 'util';
|
import * as util from 'util';
|
||||||
import * as types from './types';
|
import * as types from './types';
|
||||||
import { Progress } from './progress';
|
import { Progress } from './progress';
|
||||||
|
|
||||||
const removeFolderAsync = util.promisify(removeFolder);
|
const removeFolderAsync = util.promisify(removeFolder);
|
||||||
|
const readFileAsync = util.promisify(fs.readFile.bind(fs));
|
||||||
|
|
||||||
export type RegisteredListener = {
|
export type RegisteredListener = {
|
||||||
emitter: EventEmitter;
|
emitter: EventEmitter;
|
||||||
@ -325,6 +327,45 @@ class Helper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getUbuntuVersion(): Promise<string> {
|
||||||
|
if (os.platform() !== 'linux')
|
||||||
|
return '';
|
||||||
|
const osReleaseText = await readFileAsync('/etc/os-release', 'utf8').catch(e => '');
|
||||||
|
if (!osReleaseText)
|
||||||
|
return '';
|
||||||
|
return getUbuntuVersionInternal(osReleaseText);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUbuntuVersionSync(): string {
|
||||||
|
if (os.platform() !== 'linux')
|
||||||
|
return '';
|
||||||
|
try {
|
||||||
|
const osReleaseText = fs.readFileSync('/etc/os-release', 'utf8');
|
||||||
|
if (!osReleaseText)
|
||||||
|
return '';
|
||||||
|
return getUbuntuVersionInternal(osReleaseText);
|
||||||
|
} catch (e) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getUbuntuVersionInternal(osReleaseText: string): string {
|
||||||
|
const fields = new Map();
|
||||||
|
for (const line of osReleaseText.split('\n')) {
|
||||||
|
const tokens = line.split('=');
|
||||||
|
const name = tokens.shift();
|
||||||
|
let value = tokens.join('=').trim();
|
||||||
|
if (value.startsWith('"') && value.endsWith('"'))
|
||||||
|
value = value.substring(1, value.length - 1);
|
||||||
|
if (!name)
|
||||||
|
continue;
|
||||||
|
fields.set(name.toLowerCase(), value);
|
||||||
|
}
|
||||||
|
if (!fields.get('name') || fields.get('name').toLowerCase() !== 'ubuntu')
|
||||||
|
return '';
|
||||||
|
return fields.get('version_id') || '';
|
||||||
|
}
|
||||||
|
|
||||||
export function assert(value: any, message?: string): asserts value {
|
export function assert(value: any, message?: string): asserts value {
|
||||||
if (!value)
|
if (!value)
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
|
@ -58,7 +58,8 @@ const ENV_DOWNLOAD_HOSTS: { [key: string]: string } = {
|
|||||||
function getDownloadUrl(browserName: BrowserName, revision: number, platform: BrowserPlatform): string | undefined {
|
function getDownloadUrl(browserName: BrowserName, revision: number, platform: BrowserPlatform): string | undefined {
|
||||||
if (browserName === 'chromium') {
|
if (browserName === 'chromium') {
|
||||||
return new Map<BrowserPlatform, string>([
|
return new Map<BrowserPlatform, string>([
|
||||||
['linux', '%s/chromium-browser-snapshots/Linux_x64/%d/chrome-linux.zip'],
|
['ubuntu18.04', '%s/chromium-browser-snapshots/Linux_x64/%d/chrome-linux.zip'],
|
||||||
|
['ubuntu20.04', '%s/chromium-browser-snapshots/Linux_x64/%d/chrome-linux.zip'],
|
||||||
['mac10.13', '%s/chromium-browser-snapshots/Mac/%d/chrome-mac.zip'],
|
['mac10.13', '%s/chromium-browser-snapshots/Mac/%d/chrome-mac.zip'],
|
||||||
['mac10.14', '%s/chromium-browser-snapshots/Mac/%d/chrome-mac.zip'],
|
['mac10.14', '%s/chromium-browser-snapshots/Mac/%d/chrome-mac.zip'],
|
||||||
['mac10.15', '%s/chromium-browser-snapshots/Mac/%d/chrome-mac.zip'],
|
['mac10.15', '%s/chromium-browser-snapshots/Mac/%d/chrome-mac.zip'],
|
||||||
@ -71,7 +72,8 @@ function getDownloadUrl(browserName: BrowserName, revision: number, platform: Br
|
|||||||
const FIREFOX_RENAME_LINUX_TO_UBUNTU_REVISION = 1139;
|
const FIREFOX_RENAME_LINUX_TO_UBUNTU_REVISION = 1139;
|
||||||
return revision < FIREFOX_RENAME_LINUX_TO_UBUNTU_REVISION ?
|
return revision < FIREFOX_RENAME_LINUX_TO_UBUNTU_REVISION ?
|
||||||
new Map<BrowserPlatform, string>([
|
new Map<BrowserPlatform, string>([
|
||||||
['linux', '%s/builds/firefox/%s/firefox-linux.zip'],
|
['ubuntu18.04', '%s/builds/firefox/%s/firefox-linux.zip'],
|
||||||
|
['ubuntu20.04', '%s/builds/firefox/%s/firefox-linux.zip'],
|
||||||
['mac10.13', '%s/builds/firefox/%s/firefox-mac.zip'],
|
['mac10.13', '%s/builds/firefox/%s/firefox-mac.zip'],
|
||||||
['mac10.14', '%s/builds/firefox/%s/firefox-mac.zip'],
|
['mac10.14', '%s/builds/firefox/%s/firefox-mac.zip'],
|
||||||
['mac10.15', '%s/builds/firefox/%s/firefox-mac.zip'],
|
['mac10.15', '%s/builds/firefox/%s/firefox-mac.zip'],
|
||||||
@ -79,7 +81,8 @@ function getDownloadUrl(browserName: BrowserName, revision: number, platform: Br
|
|||||||
['win64', '%s/builds/firefox/%s/firefox-win64.zip'],
|
['win64', '%s/builds/firefox/%s/firefox-win64.zip'],
|
||||||
]).get(platform) :
|
]).get(platform) :
|
||||||
new Map<BrowserPlatform, string>([
|
new Map<BrowserPlatform, string>([
|
||||||
['linux', '%s/builds/firefox/%s/firefox-ubuntu-18.04.zip'],
|
['ubuntu18.04', '%s/builds/firefox/%s/firefox-ubuntu-18.04.zip'],
|
||||||
|
['ubuntu20.04', '%s/builds/firefox/%s/firefox-ubuntu-18.04.zip'],
|
||||||
['mac10.13', '%s/builds/firefox/%s/firefox-mac.zip'],
|
['mac10.13', '%s/builds/firefox/%s/firefox-mac.zip'],
|
||||||
['mac10.14', '%s/builds/firefox/%s/firefox-mac.zip'],
|
['mac10.14', '%s/builds/firefox/%s/firefox-mac.zip'],
|
||||||
['mac10.15', '%s/builds/firefox/%s/firefox-mac.zip'],
|
['mac10.15', '%s/builds/firefox/%s/firefox-mac.zip'],
|
||||||
@ -92,7 +95,8 @@ function getDownloadUrl(browserName: BrowserName, revision: number, platform: Br
|
|||||||
const WEBKIT_RENAME_LINUX_TO_UBUNTU_REVISION = 1315;
|
const WEBKIT_RENAME_LINUX_TO_UBUNTU_REVISION = 1315;
|
||||||
return revision < WEBKIT_RENAME_LINUX_TO_UBUNTU_REVISION ?
|
return revision < WEBKIT_RENAME_LINUX_TO_UBUNTU_REVISION ?
|
||||||
new Map<BrowserPlatform, string | undefined>([
|
new Map<BrowserPlatform, string | undefined>([
|
||||||
['linux', '%s/builds/webkit/%s/minibrowser-gtk-wpe.zip'],
|
['ubuntu18.04', '%s/builds/webkit/%s/minibrowser-gtk-wpe.zip'],
|
||||||
|
['ubuntu20.04', '%s/builds/webkit/%s/minibrowser-gtk-wpe.zip'],
|
||||||
['mac10.13', undefined],
|
['mac10.13', undefined],
|
||||||
['mac10.14', '%s/builds/webkit/%s/minibrowser-mac-10.14.zip'],
|
['mac10.14', '%s/builds/webkit/%s/minibrowser-mac-10.14.zip'],
|
||||||
['mac10.15', '%s/builds/webkit/%s/minibrowser-mac-10.15.zip'],
|
['mac10.15', '%s/builds/webkit/%s/minibrowser-mac-10.15.zip'],
|
||||||
@ -100,7 +104,8 @@ function getDownloadUrl(browserName: BrowserName, revision: number, platform: Br
|
|||||||
['win64', '%s/builds/webkit/%s/minibrowser-win64.zip'],
|
['win64', '%s/builds/webkit/%s/minibrowser-win64.zip'],
|
||||||
]).get(platform) :
|
]).get(platform) :
|
||||||
new Map<BrowserPlatform, string | undefined>([
|
new Map<BrowserPlatform, string | undefined>([
|
||||||
['linux', '%s/builds/webkit/%s/minibrowser-gtk-wpe-ubuntu-18.04.zip'],
|
['ubuntu18.04', '%s/builds/webkit/%s/minibrowser-gtk-wpe-ubuntu-18.04.zip'],
|
||||||
|
['ubuntu20.04', '%s/builds/webkit/%s/minibrowser-gtk-wpe-ubuntu-20.04.zip'],
|
||||||
['mac10.13', undefined],
|
['mac10.13', undefined],
|
||||||
['mac10.14', '%s/builds/webkit/%s/minibrowser-mac-10.14.zip'],
|
['mac10.14', '%s/builds/webkit/%s/minibrowser-mac-10.14.zip'],
|
||||||
['mac10.15', '%s/builds/webkit/%s/minibrowser-mac-10.15.zip'],
|
['mac10.15', '%s/builds/webkit/%s/minibrowser-mac-10.15.zip'],
|
||||||
|
@ -18,10 +18,10 @@
|
|||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { getFromENV } from '../helper';
|
import { getFromENV, getUbuntuVersionSync } from '../helper';
|
||||||
|
|
||||||
export type BrowserName = 'chromium'|'webkit'|'firefox';
|
export type BrowserName = 'chromium'|'webkit'|'firefox';
|
||||||
export type BrowserPlatform = 'win32'|'win64'|'mac10.13'|'mac10.14'|'mac10.15'|'linux';
|
export type BrowserPlatform = 'win32'|'win64'|'mac10.13'|'mac10.14'|'mac10.15'|'ubuntu18.04'|'ubuntu20.04';
|
||||||
export type BrowserDescriptor = {
|
export type BrowserDescriptor = {
|
||||||
name: BrowserName,
|
name: BrowserName,
|
||||||
revision: string
|
revision: string
|
||||||
@ -33,8 +33,14 @@ export const hostPlatform = ((): BrowserPlatform => {
|
|||||||
const macVersion = execSync('sw_vers -productVersion').toString('utf8').trim().split('.').slice(0, 2).join('.');
|
const macVersion = execSync('sw_vers -productVersion').toString('utf8').trim().split('.').slice(0, 2).join('.');
|
||||||
return `mac${macVersion}` as BrowserPlatform;
|
return `mac${macVersion}` as BrowserPlatform;
|
||||||
}
|
}
|
||||||
if (platform === 'linux')
|
if (platform === 'linux') {
|
||||||
return 'linux';
|
const ubuntuVersion = getUbuntuVersionSync();
|
||||||
|
if (ubuntuVersion === '20.04')
|
||||||
|
return 'ubuntu20.04';
|
||||||
|
// For the sake of downloading logic, consider any other Linux distribution
|
||||||
|
// to be "ubuntu18.04".
|
||||||
|
return 'ubuntu18.04';
|
||||||
|
}
|
||||||
if (platform === 'win32')
|
if (platform === 'win32')
|
||||||
return os.arch() === 'x64' ? 'win64' : 'win32';
|
return os.arch() === 'x64' ? 'win64' : 'win32';
|
||||||
return platform as BrowserPlatform;
|
return platform as BrowserPlatform;
|
||||||
@ -58,7 +64,8 @@ export function executablePath(browserPath: string, browser: BrowserDescriptor):
|
|||||||
let tokens: string[] | undefined;
|
let tokens: string[] | undefined;
|
||||||
if (browser.name === 'chromium') {
|
if (browser.name === 'chromium') {
|
||||||
tokens = new Map<BrowserPlatform, string[]>([
|
tokens = new Map<BrowserPlatform, string[]>([
|
||||||
['linux', ['chrome-linux', 'chrome']],
|
['ubuntu18.04', ['chrome-linux', 'chrome']],
|
||||||
|
['ubuntu20.04', ['chrome-linux', 'chrome']],
|
||||||
['mac10.13', ['chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium']],
|
['mac10.13', ['chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium']],
|
||||||
['mac10.14', ['chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium']],
|
['mac10.14', ['chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium']],
|
||||||
['mac10.15', ['chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium']],
|
['mac10.15', ['chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium']],
|
||||||
@ -69,7 +76,8 @@ export function executablePath(browserPath: string, browser: BrowserDescriptor):
|
|||||||
|
|
||||||
if (browser.name === 'firefox') {
|
if (browser.name === 'firefox') {
|
||||||
tokens = new Map<BrowserPlatform, string[]>([
|
tokens = new Map<BrowserPlatform, string[]>([
|
||||||
['linux', ['firefox', 'firefox']],
|
['ubuntu18.04', ['firefox', 'firefox']],
|
||||||
|
['ubuntu20.04', ['firefox', 'firefox']],
|
||||||
['mac10.13', ['firefox', 'Nightly.app', 'Contents', 'MacOS', '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']],
|
||||||
@ -80,7 +88,8 @@ export function executablePath(browserPath: string, browser: BrowserDescriptor):
|
|||||||
|
|
||||||
if (browser.name === 'webkit') {
|
if (browser.name === 'webkit') {
|
||||||
tokens = new Map<BrowserPlatform, string[] | undefined>([
|
tokens = new Map<BrowserPlatform, string[] | undefined>([
|
||||||
['linux', ['pw_run.sh']],
|
['ubuntu18.04', ['pw_run.sh']],
|
||||||
|
['ubuntu20.04', ['pw_run.sh']],
|
||||||
['mac10.13', undefined],
|
['mac10.13', undefined],
|
||||||
['mac10.14', ['pw_run.sh']],
|
['mac10.14', ['pw_run.sh']],
|
||||||
['mac10.15', ['pw_run.sh']],
|
['mac10.15', ['pw_run.sh']],
|
||||||
|
@ -18,13 +18,13 @@ import * as util from 'util';
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import { spawn } from 'child_process';
|
import { spawn } from 'child_process';
|
||||||
|
import { getUbuntuVersion } from '../helper';
|
||||||
import { linuxLddDirectories, BrowserDescriptor } from '../install/browserPaths.js';
|
import { linuxLddDirectories, BrowserDescriptor } from '../install/browserPaths.js';
|
||||||
|
|
||||||
const accessAsync = util.promisify(fs.access.bind(fs));
|
const accessAsync = util.promisify(fs.access.bind(fs));
|
||||||
const checkExecutable = (filePath: string) => accessAsync(filePath, fs.constants.X_OK).then(() => true).catch(e => false);
|
const checkExecutable = (filePath: string) => accessAsync(filePath, fs.constants.X_OK).then(() => true).catch(e => false);
|
||||||
const statAsync = util.promisify(fs.stat.bind(fs));
|
const statAsync = util.promisify(fs.stat.bind(fs));
|
||||||
const readdirAsync = util.promisify(fs.readdir.bind(fs));
|
const readdirAsync = util.promisify(fs.readdir.bind(fs));
|
||||||
const readFileAsync = util.promisify(fs.readFile.bind(fs));
|
|
||||||
|
|
||||||
export async function validateDependencies(browserPath: string, browser: BrowserDescriptor) {
|
export async function validateDependencies(browserPath: string, browser: BrowserDescriptor) {
|
||||||
// We currently only support Linux.
|
// We currently only support Linux.
|
||||||
@ -122,26 +122,6 @@ function lddAsync(filePath: string): Promise<{stdout: string, stderr: string, co
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getUbuntuVersion(): Promise<string> {
|
|
||||||
const osRelease = await readFileAsync('/etc/os-release', 'utf8').catch(e => '');
|
|
||||||
if (!osRelease)
|
|
||||||
return '';
|
|
||||||
const fields = new Map();
|
|
||||||
for (const line of osRelease.split('\n')) {
|
|
||||||
const tokens = line.split('=');
|
|
||||||
const name = tokens.shift();
|
|
||||||
let value = tokens.join('=').trim();
|
|
||||||
if (value.startsWith('"') && value.endsWith('"'))
|
|
||||||
value = value.substring(1, value.length - 1);
|
|
||||||
if (!name)
|
|
||||||
continue;
|
|
||||||
fields.set(name.toLowerCase(), value);
|
|
||||||
}
|
|
||||||
if (!fields.get('name') || fields.get('name').toLowerCase() !== 'ubuntu')
|
|
||||||
return '';
|
|
||||||
return fields.get('version_id') || '';
|
|
||||||
}
|
|
||||||
|
|
||||||
// This list is generated with https://gist.github.com/aslushnikov/2766200430228c3700537292fccad064
|
// This list is generated with https://gist.github.com/aslushnikov/2766200430228c3700537292fccad064
|
||||||
const LIBRARY_TO_PACKAGE_NAME_UBUNTU_18_04: { [s: string]: string} = {
|
const LIBRARY_TO_PACKAGE_NAME_UBUNTU_18_04: { [s: string]: string} = {
|
||||||
'libEGL.so.1': 'libegl1',
|
'libEGL.so.1': 'libegl1',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user