Skip to content

Commit

Permalink
git-node v8: remove eu-strip during major upgrades (#243)
Browse files Browse the repository at this point in the history
* git-node v8: remove eu-strip during major upgrades

Ref: nodejs/node#20304
  • Loading branch information
Alicia Lopez committed May 3, 2018
1 parent 170a4c9 commit 47e2139
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 22 deletions.
46 changes: 46 additions & 0 deletions lib/update-v8/applyNodeChanges.js
Original file line number Diff line number Diff line change
@@ -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;
27 changes: 11 additions & 16 deletions lib/update-v8/majorUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -28,6 +34,7 @@ module.exports = function() {
cloneLocalV8(),
removeDepsV8Git(),
updateV8Deps(),
applyNodeChanges(),
moveGypfilesIn(),
updateGypfiles()
]);
Expand Down Expand Up @@ -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) {
Expand All @@ -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 = {');
Expand Down
30 changes: 24 additions & 6 deletions lib/update-v8/util.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'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`,
Expand All @@ -21,11 +20,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
};

0 comments on commit 47e2139

Please sign in to comment.