Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git-node v8: remove eu-strip during major upgrades #243

Merged
merged 2 commits into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 24 additions & 4 deletions lib/update-v8/util.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict';

const fs = require('fs');
const fs = require('fs-extra');
const path = require('path');

const constants = require('./constants');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line needs be removed, the lint fails here since its not required anymore.


exports.getNodeV8Version = function getNodeV8Version(cwd) {
function getNodeV8Version(cwd) {
try {
const v8VersionH = fs.readFileSync(
`${cwd}/deps/v8/include/v8-version.h`,
Expand All @@ -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
};