Files
azuredatastudio/build/linux/debian/install-sysroot.js
Cheena Malhotra 2c07c09d0d Compile build folder (#22811)
* Compile build folder

* Fix build compile issues (#22813)

* Revert changes

* Update gulp-shell

* Test

* Update

* Update modifiers

* Try reverting minimist

* Generates linux deb artifact (#22922)

* Remove deb files that were brought in with the latest merge.

* Add debian back to linux gulp file

* Remove async from anonymous function.

* Remove run core integration tests build step in pipeline

* Revert "Remove async from anonymous function."

This reverts commit 7ad1ce2942954fce58939b9965343b46b9311a7e.

* Revert "Add debian back to linux gulp file"

This reverts commit 96b7c0f0995c8024ef67ed886da34255a5caa325.

* Revert "Remove deb files that were brought in with the latest merge."

This reverts commit bf3aae233b8da1f9111a149a96d77cc78d376094.

* Removes dependency checks

* Fix dependency gen errors

* Reenable "Build Deb" step

* Reenable publish deb

* Run core integration tests

* Revert "Run core integration tests"

This reverts commit 7cafbada194feebe771862af796fb3416b5dd686.

* Revert "Try reverting minimist"

This reverts commit 38fd843c1d5c33318a92f4bbc7057e951c5a9f71.

* Disable code coverage step intermin

---------

Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>
Co-authored-by: Lewis Sanchez <87730006+lewis-sanchez@users.noreply.github.com>
2023-05-02 19:32:46 -07:00

82 lines
3.3 KiB
JavaScript

"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSysroot = void 0;
const child_process_1 = require("child_process");
const crypto_1 = require("crypto");
const os_1 = require("os");
const fs = require("fs");
const https = require("https");
const path = require("path");
const sysroots_1 = require("./sysroots");
// Based on https://source.chromium.org/chromium/chromium/src/+/main:build/linux/sysroot_scripts/install-sysroot.py.
const URL_PREFIX = 'https://msftelectron.blob.core.windows.net';
const URL_PATH = 'sysroots/toolchain';
function getSha(filename) {
const hash = (0, crypto_1.createHash)('sha1');
// Read file 1 MB at a time
const fd = fs.openSync(filename, 'r');
const buffer = Buffer.alloc(1024 * 1024);
let position = 0;
let bytesRead = 0;
while ((bytesRead = fs.readSync(fd, buffer, 0, buffer.length, position)) === buffer.length) {
hash.update(buffer);
position += bytesRead;
}
hash.update(buffer.slice(0, bytesRead));
return hash.digest('hex');
}
async function getSysroot(arch) {
const sysrootDict = sysroots_1.sysrootInfo[arch];
const tarballFilename = sysrootDict['Tarball'];
const tarballSha = sysrootDict['Sha1Sum'];
const sysroot = path.join((0, os_1.tmpdir)(), sysrootDict['SysrootDir']);
const url = [URL_PREFIX, URL_PATH, tarballSha, tarballFilename].join('/');
const stamp = path.join(sysroot, '.stamp');
if (fs.existsSync(stamp) && fs.readFileSync(stamp).toString() === url) {
return sysroot;
}
console.log(`Installing Debian ${arch} root image: ${sysroot}`);
fs.rmSync(sysroot, { recursive: true, force: true });
fs.mkdirSync(sysroot);
const tarball = path.join(sysroot, tarballFilename);
console.log(`Downloading ${url}`);
let downloadSuccess = false;
for (let i = 0; i < 3 && !downloadSuccess; i++) {
await new Promise((c) => {
https.get(url, (res) => {
const chunks = [];
res.on('data', (chunk) => {
chunks.push(chunk);
});
res.on('end', () => {
fs.writeFileSync(tarball, Buffer.concat(chunks));
downloadSuccess = true;
c();
});
}).on('error', (err) => {
console.error('Encountered an error during the download attempt: ' + err.message);
c();
});
});
}
if (!downloadSuccess) {
throw new Error('Failed to download ' + url);
}
const sha = getSha(tarball);
if (sha !== tarballSha) {
throw new Error(`Tarball sha1sum is wrong. Expected ${tarballSha}, actual ${sha}`);
}
const proc = (0, child_process_1.spawnSync)('tar', ['xf', tarball, '-C', sysroot]);
if (proc.status) {
throw new Error('Tarball extraction failed with code ' + proc.status);
}
fs.rmSync(tarball);
fs.writeFileSync(stamp, url);
return sysroot;
}
exports.getSysroot = getSysroot;