From 3693aaff2e1c006520c390f9e3401d3802924213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Tue, 1 May 2018 13:33:11 +0200 Subject: [PATCH] git-node v8: remove eu-strip during major upgrades Ref: https://github.com/nodejs/node/pull/20304 --- lib/update-v8/applyNodeChanges.js | 46 +++++++++++++++++++++++++++++++ lib/update-v8/majorUpdate.js | 27 ++++++++---------- lib/update-v8/util.js | 28 ++++++++++++++++--- 3 files changed, 81 insertions(+), 20 deletions(-) create mode 100644 lib/update-v8/applyNodeChanges.js diff --git a/lib/update-v8/applyNodeChanges.js b/lib/update-v8/applyNodeChanges.js new file mode 100644 index 00000000..1e39f28f --- /dev/null +++ b/lib/update-v8/applyNodeChanges.js @@ -0,0 +1,46 @@ +'use strict'; + +const path = require('path'); + +const fs = require('fs-extra'); +const Listr = require('listr'); + +const { + getNodeV8Version, + filterForVersion, + replaceGitignore +} = require('./util'); + +const nodeChanges = [ + { + since: 66, + task: removeEuStrip + } +]; + +function applyNodeChanges() { + return { + title: 'Apply Node-specific changes', + task: (ctx) => { + const v8Version = getNodeV8Version(ctx.nodeDir); + const list = filterForVersion(nodeChanges, v8Version); + return new Listr(list.map((change) => change.task())); + } + }; +} + +// Ref: https://github.com/nodejs/node/pull/20304 +function removeEuStrip() { + return { + title: 'Remove eu-strip binary', + task: async(ctx) => { + await replaceGitignore(ctx.nodeDir, { + match: '!/third_party/eu-strip\n', + replace: '' + }); + await fs.remove(path.join(ctx.nodeDir, 'deps/v8/third_party/eu-strip')); + } + }; +} + +module.exports = applyNodeChanges; diff --git a/lib/update-v8/majorUpdate.js b/lib/update-v8/majorUpdate.js index a2c1bfb1..0fc88de8 100644 --- a/lib/update-v8/majorUpdate.js +++ b/lib/update-v8/majorUpdate.js @@ -8,13 +8,19 @@ const Listr = require('listr'); const mkdirp = require('mkdirp'); const common = require('./common'); -const util = require('./util'); +const { + getNodeV8Version, + filterForVersion, + addToGitignore, + replaceGitignore +} = require('./util'); const { moveGypfilesOut, moveGypfilesIn, updateGypfiles } = require('./gypfiles'); -const { chromiumGit } = require('./constants'); +const applyNodeChanges = require('./applyNodeChanges'); +const { chromiumGit, v8Deps } = require('./constants'); module.exports = function() { return { @@ -28,6 +34,7 @@ module.exports = function() { cloneLocalV8(), removeDepsV8Git(), updateV8Deps(), + applyNodeChanges(), moveGypfilesIn(), updateGypfiles() ]); @@ -102,8 +109,8 @@ function updateV8Deps() { return { title: 'Update V8 DEPS', task: async(ctx) => { - const newV8Version = util.getNodeV8Version(ctx.nodeDir); - const deps = util.getV8Deps(newV8Version); + const newV8Version = getNodeV8Version(ctx.nodeDir); + const deps = filterForVersion(v8Deps, newV8Version); if (deps.length === 0) return; /* eslint-disable no-await-in-loop */ for (const dep of deps) { @@ -123,18 +130,6 @@ function updateV8Deps() { }; } -async function addToGitignore(nodeDir, value) { - const gitignorePath = path.join(nodeDir, 'deps/v8/.gitignore'); - await fs.appendFile(gitignorePath, `${value}\n`); -} - -async function replaceGitignore(nodeDir, options) { - const gitignorePath = path.join(nodeDir, 'deps/v8/.gitignore'); - let gitignore = await fs.readFile(gitignorePath, 'utf8'); - gitignore = gitignore.replace(options.match, options.replace); - await fs.writeFile(gitignorePath, gitignore); -} - async function readDeps(nodeDir, depName) { const depsStr = await fs.readFile(path.join(nodeDir, 'deps/v8/DEPS'), 'utf8'); const start = depsStr.indexOf('deps = {'); diff --git a/lib/update-v8/util.js b/lib/update-v8/util.js index 5ff4caa9..2f27ef9b 100644 --- a/lib/update-v8/util.js +++ b/lib/update-v8/util.js @@ -1,10 +1,11 @@ 'use strict'; -const fs = require('fs'); +const fs = require('fs-extra'); +const path = require('path'); const constants = require('./constants'); -exports.getNodeV8Version = function getNodeV8Version(cwd) { +function getNodeV8Version(cwd) { try { const v8VersionH = fs.readFileSync( `${cwd}/deps/v8/include/v8-version.h`, @@ -21,11 +22,30 @@ exports.getNodeV8Version = function getNodeV8Version(cwd) { } }; -exports.getV8Deps = function getV8Deps(version) { +function filterForVersion(list, version) { const major = version[0]; const minor = version[1]; const number = major * 10 + minor; - return constants.v8Deps.filter( + return list.filter( (dep) => dep.since <= number && (dep.until || Infinity) >= number ); +} + +async function addToGitignore(nodeDir, value) { + const gitignorePath = path.join(nodeDir, 'deps/v8/.gitignore'); + await fs.appendFile(gitignorePath, `${value}\n`); +} + +async function replaceGitignore(nodeDir, options) { + const gitignorePath = path.join(nodeDir, 'deps/v8/.gitignore'); + let gitignore = await fs.readFile(gitignorePath, 'utf8'); + gitignore = gitignore.replace(options.match, options.replace); + await fs.writeFile(gitignorePath, gitignore); +} + +module.exports = { + getNodeV8Version, + filterForVersion, + addToGitignore, + replaceGitignore };