Skip to content

Commit

Permalink
feat(installer): start downloadinb Ubuntu 20.04 builds (microsoft#3126)
Browse files Browse the repository at this point in the history
Start auto-detecting Ubuntu 20.04 and downloading custom webkit
build for it.

References microsoft#2745
  • Loading branch information
aslushnikov authored Jul 24, 2020
1 parent 0b9c647 commit bbe7dbe
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 37 deletions.
41 changes: 41 additions & 0 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
import * as crypto from 'crypto';
import { EventEmitter } from 'events';
import * as fs from 'fs';
import * as os from 'os';
import * as removeFolder from 'rimraf';
import * as util from 'util';
import * as types from './types';
import { Progress } from './progress';

const removeFolderAsync = util.promisify(removeFolder);
const readFileAsync = util.promisify(fs.readFile.bind(fs));

export type RegisteredListener = {
emitter: EventEmitter;
Expand Down Expand Up @@ -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 {
if (!value)
throw new Error(message);
Expand Down
15 changes: 10 additions & 5 deletions src/install/browserFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ const ENV_DOWNLOAD_HOSTS: { [key: string]: string } = {
function getDownloadUrl(browserName: BrowserName, revision: number, platform: BrowserPlatform): string | undefined {
if (browserName === 'chromium') {
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.14', '%s/chromium-browser-snapshots/Mac/%d/chrome-mac.zip'],
['mac10.15', '%s/chromium-browser-snapshots/Mac/%d/chrome-mac.zip'],
Expand All @@ -71,15 +72,17 @@ function getDownloadUrl(browserName: BrowserName, revision: number, platform: Br
const FIREFOX_RENAME_LINUX_TO_UBUNTU_REVISION = 1139;
return revision < FIREFOX_RENAME_LINUX_TO_UBUNTU_REVISION ?
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.14', '%s/builds/firefox/%s/firefox-mac.zip'],
['mac10.15', '%s/builds/firefox/%s/firefox-mac.zip'],
['win32', '%s/builds/firefox/%s/firefox-win32.zip'],
['win64', '%s/builds/firefox/%s/firefox-win64.zip'],
]).get(platform) :
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.14', '%s/builds/firefox/%s/firefox-mac.zip'],
['mac10.15', '%s/builds/firefox/%s/firefox-mac.zip'],
Expand All @@ -92,15 +95,17 @@ function getDownloadUrl(browserName: BrowserName, revision: number, platform: Br
const WEBKIT_RENAME_LINUX_TO_UBUNTU_REVISION = 1315;
return revision < WEBKIT_RENAME_LINUX_TO_UBUNTU_REVISION ?
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.14', '%s/builds/webkit/%s/minibrowser-mac-10.14.zip'],
['mac10.15', '%s/builds/webkit/%s/minibrowser-mac-10.15.zip'],
['win32', '%s/builds/webkit/%s/minibrowser-win64.zip'],
['win64', '%s/builds/webkit/%s/minibrowser-win64.zip'],
]).get(platform) :
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.14', '%s/builds/webkit/%s/minibrowser-mac-10.14.zip'],
['mac10.15', '%s/builds/webkit/%s/minibrowser-mac-10.15.zip'],
Expand Down
27 changes: 18 additions & 9 deletions src/install/browserPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import { execSync } from 'child_process';
import * as os from 'os';
import * as path from 'path';
import { getFromENV } from '../helper';
import { getFromENV, getUbuntuVersionSync } from '../helper';

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 = {
name: BrowserName,
revision: string
name: BrowserName,
revision: string
};

export const hostPlatform = ((): BrowserPlatform => {
Expand All @@ -33,8 +33,14 @@ export const hostPlatform = ((): BrowserPlatform => {
const macVersion = execSync('sw_vers -productVersion').toString('utf8').trim().split('.').slice(0, 2).join('.');
return `mac${macVersion}` as BrowserPlatform;
}
if (platform === 'linux')
return 'linux';
if (platform === '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')
return os.arch() === 'x64' ? 'win64' : 'win32';
return platform as BrowserPlatform;
Expand All @@ -58,7 +64,8 @@ export function executablePath(browserPath: string, browser: BrowserDescriptor):
let tokens: string[] | undefined;
if (browser.name === 'chromium') {
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.14', ['chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium']],
['mac10.15', ['chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium']],
Expand All @@ -69,7 +76,8 @@ export function executablePath(browserPath: string, browser: BrowserDescriptor):

if (browser.name === 'firefox') {
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.14', ['firefox', 'Nightly.app', 'Contents', 'MacOS', 'firefox']],
['mac10.15', ['firefox', 'Nightly.app', 'Contents', 'MacOS', 'firefox']],
Expand All @@ -80,7 +88,8 @@ export function executablePath(browserPath: string, browser: BrowserDescriptor):

if (browser.name === 'webkit') {
tokens = new Map<BrowserPlatform, string[] | undefined>([
['linux', ['pw_run.sh']],
['ubuntu18.04', ['pw_run.sh']],
['ubuntu20.04', ['pw_run.sh']],
['mac10.13', undefined],
['mac10.14', ['pw_run.sh']],
['mac10.15', ['pw_run.sh']],
Expand Down
26 changes: 3 additions & 23 deletions src/server/validateDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import * as fs from 'fs';
import * as util from 'util';
import * as path from 'path';
import * as os from 'os';
import {spawn} from 'child_process';
import {linuxLddDirectories, BrowserDescriptor} from '../install/browserPaths.js';
import { spawn } from 'child_process';
import { getUbuntuVersion } from '../helper';
import { linuxLddDirectories, BrowserDescriptor } from '../install/browserPaths.js';

const accessAsync = util.promisify(fs.access.bind(fs));
const checkExecutable = (filePath: string) => accessAsync(filePath, fs.constants.X_OK).then(() => true).catch(e => false);
const statAsync = util.promisify(fs.stat.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) {
// We currently only support Linux.
Expand Down Expand Up @@ -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
const LIBRARY_TO_PACKAGE_NAME_UBUNTU_18_04: { [s: string]: string} = {
'libEGL.so.1': 'libegl1',
Expand Down

0 comments on commit bbe7dbe

Please sign in to comment.