Skip to content

Commit 5a7100b

Browse files
authored
Merge pull request #195 from atom-ide-community/parallel-build
2 parents 4d69ca2 + ed3f73c commit 5a7100b

9 files changed

+101
-47
lines changed

script/build

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ const notarizeOnMac = require('./lib/notarize-on-mac')
5656
const packageApplication = require('./lib/package-application')
5757
const prebuildLessCache = require('./lib/prebuild-less-cache')
5858
const testSignOnMac = require('./lib/test-sign-on-mac')
59-
const transpileBabelPaths = require('./lib/transpile-babel-paths')
60-
const transpileCoffeeScriptPaths = require('./lib/transpile-coffee-script-paths')
61-
const transpileCsonPaths = require('./lib/transpile-cson-paths')
62-
const transpilePegJsPaths = require('./lib/transpile-peg-js-paths')
63-
const transpilePackagesWithCustomTranspilerPaths = require('./lib/transpile-packages-with-custom-transpiler-paths.js')
6459

6560
process.on('unhandledRejection', function (e) {
6661
console.error(e.stack || e)
@@ -69,31 +64,41 @@ process.on('unhandledRejection', function (e) {
6964

7065
process.env.ELECTRON_VERSION = CONFIG.appMetadata.electronVersion
7166

72-
let binariesPromise = Promise.resolve()
73-
74-
if (!argv.existingBinaries) {
75-
checkChromedriverVersion()
76-
cleanOutputDirectory()
77-
copyAssets()
78-
transpilePackagesWithCustomTranspilerPaths()
79-
transpileBabelPaths()
80-
transpileCoffeeScriptPaths()
81-
transpileCsonPaths()
82-
transpilePegJsPaths()
83-
generateModuleCache()
84-
prebuildLessCache()
85-
generateMetadata()
86-
generateAPIDocs()
87-
if (!argv.generateApiDocs) {
88-
binariesPromise = dumpSymbols()
89-
}
67+
async function transpile() {
68+
const { spawn, Thread, Worker } = require(`${CONFIG.scriptRunnerModulesPath}/threads`)
69+
70+
const transpilePackagesWithCustomTranspilerPaths = await spawn(new Worker('./lib/transpile-packages-with-custom-transpiler-paths'))
71+
const transpilePackagesWithCustomTranspilerPathsPromise = transpilePackagesWithCustomTranspilerPaths()
72+
73+
const transpileBabelPaths = await spawn(new Worker('./lib/transpile-babel-paths'))
74+
const transpileBabelPathsPromise = transpileBabelPaths()
75+
76+
const transpileCoffeeScriptPaths = await spawn(new Worker('./lib/transpile-coffee-script-paths'))
77+
const transpileCoffeeScriptPathsPromise = transpileCoffeeScriptPaths()
78+
79+
const transpileCsonPaths = await spawn(new Worker('./lib/transpile-cson-paths'))
80+
const transpileCsonPathsPromise = transpileCsonPaths()
81+
82+
const transpilePegJsPaths = await spawn(new Worker('./lib/transpile-peg-js-paths'))
83+
const transpilePegJsPathsPromise = transpilePegJsPaths()
84+
85+
await transpilePackagesWithCustomTranspilerPathsPromise;
86+
await Thread.terminate(transpilePackagesWithCustomTranspilerPaths)
87+
88+
await transpileBabelPathsPromise;
89+
await Thread.terminate(transpileBabelPaths)
90+
91+
await transpileCoffeeScriptPathsPromise;
92+
await Thread.terminate(transpileCoffeeScriptPaths)
93+
94+
await transpileCsonPathsPromise;
95+
await Thread.terminate(transpileCsonPaths)
96+
97+
await transpilePegJsPathsPromise;
98+
await Thread.terminate(transpilePegJsPaths)
9099
}
91100

92-
if (!argv.generateApiDocs) {
93-
binariesPromise
94-
.then(packageApplication)
95-
.then(packagedAppPath => generateStartupSnapshot(packagedAppPath).then(() => packagedAppPath))
96-
.then(async packagedAppPath => {
101+
async function singAndCreateInstaller(packagedAppPath) {
97102
switch (process.platform) {
98103
case 'darwin': {
99104
if (argv.codeSign) {
@@ -148,7 +153,29 @@ if (!argv.generateApiDocs) {
148153
}
149154

150155
return Promise.resolve(packagedAppPath)
151-
}).then(packagedAppPath => {
156+
}
157+
158+
159+
async function build() {
160+
161+
if (!argv.existingBinaries) {
162+
checkChromedriverVersion()
163+
cleanOutputDirectory()
164+
copyAssets()
165+
await transpile()
166+
generateModuleCache()
167+
prebuildLessCache()
168+
generateMetadata()
169+
generateAPIDocs()
170+
if (!argv.generateApiDocs) {
171+
await dumpSymbols()
172+
}
173+
}
174+
175+
if (!argv.generateApiDocs) {
176+
const packagedAppPath = await packageApplication()
177+
await generateStartupSnapshot(packagedAppPath)
178+
await singAndCreateInstaller(packagedAppPath)
152179
if (argv.compressArtifacts) {
153180
compressArtifacts(packagedAppPath)
154181
} else {
@@ -160,5 +187,9 @@ if (!argv.generateApiDocs) {
160187
} else {
161188
console.log('Skipping installation. Specify the --install option to install Atom'.gray)
162189
}
163-
})
190+
}
191+
164192
}
193+
194+
195+
build().then(() => {process.exit(0)}).catch((e) => {throw e;})

script/config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,7 @@ function getNpmBinPath(external = false) {
126126
: npmBinName;
127127
}
128128

129-
process.env.JOBS = 'max'; // parallel build in node-gyp
129+
// parallel build in node-gyp
130+
if (!process.env.JOBS) {
131+
process.env.JOBS = 'max';
132+
}

script/lib/install-apm.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ const childProcess = require('child_process');
44

55
const CONFIG = require('../config');
66

7-
function installApm(ci) {
7+
function installApm(ci = false, showVersion = true) {
88
console.log('Installing apm');
99
// npm ci leaves apm with a bunch of unmet dependencies
1010
childProcess.execFileSync(
1111
CONFIG.getNpmBinPath(),
1212
['--global-style', '--loglevel=error', 'install'],
1313
{ env: process.env, cwd: CONFIG.apmRootPath }
1414
);
15-
childProcess.execFileSync(CONFIG.getApmBinPath(), ['--version'], {
16-
stdio: 'inherit'
17-
});
15+
if (showVersion) {
16+
childProcess.execFileSync(CONFIG.getApmBinPath(), ['--version'], {
17+
stdio: 'inherit'
18+
});
19+
}
1820
}
1921

2022
const { expose } = require(`${CONFIG.scriptRunnerModulesPath}/threads/worker`);

script/lib/install-script-runner-dependencies.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ const childProcess = require('child_process');
44

55
const CONFIG = require('../config');
66

7-
process.env.ELECTRON_CUSTOM_VERSION = CONFIG.appMetadata.electronVersion;
8-
97
function installScriptRunnerDependencies(ci) {
108
console.log('Installing script runner dependencies');
119
childProcess.execFileSync(

script/lib/transpile-babel-paths.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const path = require('path');
77

88
const CONFIG = require('../config');
99

10-
module.exports = function() {
10+
function transpileBabelPaths() {
1111
console.log(`Transpiling Babel paths in ${CONFIG.intermediateAppPath}`);
1212
for (let path of getPathsToTranspile()) {
1313
transpileBabelPath(path);
1414
}
15-
};
15+
}
1616

1717
function getPathsToTranspile() {
1818
let paths = [];
@@ -49,3 +49,7 @@ function transpileBabelPath(path) {
4949
CompileCache.addPathToCache(path, CONFIG.atomHomeDirPath)
5050
);
5151
}
52+
53+
const { expose } = require(`${CONFIG.scriptRunnerModulesPath}/threads/worker`);
54+
expose(transpileBabelPaths);
55+
module.exports = transpileBabelPaths;

script/lib/transpile-coffee-script-paths.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ const path = require('path');
77

88
const CONFIG = require('../config');
99

10-
module.exports = function() {
10+
function transpileCoffeeScriptPaths() {
1111
console.log(
1212
`Transpiling CoffeeScript paths in ${CONFIG.intermediateAppPath}`
1313
);
1414
for (let path of getPathsToTranspile()) {
1515
transpileCoffeeScriptPath(path);
1616
}
17-
};
17+
}
1818

1919
function getPathsToTranspile() {
2020
let paths = [];
@@ -63,3 +63,7 @@ function transpileCoffeeScriptPath(coffeePath) {
6363
);
6464
fs.unlinkSync(coffeePath);
6565
}
66+
67+
const { expose } = require(`${CONFIG.scriptRunnerModulesPath}/threads/worker`);
68+
expose(transpileCoffeeScriptPaths);
69+
module.exports = transpileCoffeeScriptPaths;

script/lib/transpile-cson-paths.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const path = require('path');
77

88
const CONFIG = require('../config');
99

10-
module.exports = function() {
10+
function transpileCsonPaths() {
1111
console.log(`Transpiling CSON paths in ${CONFIG.intermediateAppPath}`);
1212
for (let path of getPathsToTranspile()) {
1313
transpileCsonPath(path);
1414
}
15-
};
15+
}
1616

1717
function getPathsToTranspile() {
1818
let paths = [];
@@ -53,3 +53,7 @@ function transpileCsonPath(csonPath) {
5353
);
5454
fs.unlinkSync(csonPath);
5555
}
56+
57+
const { expose } = require(`${CONFIG.scriptRunnerModulesPath}/threads/worker`);
58+
expose(transpileCsonPaths);
59+
module.exports = transpileCsonPaths;

script/lib/transpile-packages-with-custom-transpiler-paths.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const runApmInstall = require('./run-apm-install');
1111

1212
require('colors');
1313

14-
module.exports = function() {
14+
function transpilePackagesWithCustomTranspilerPaths() {
1515
console.log(
1616
`Transpiling packages with custom transpiler configurations in ${
1717
CONFIG.intermediateAppPath
@@ -78,11 +78,15 @@ module.exports = function() {
7878
intermediatePackageBackup.restore();
7979
}
8080
}
81-
};
81+
}
8282

8383
function transpilePath(path) {
8484
fs.writeFileSync(
8585
path,
8686
CompileCache.addPathToCache(path, CONFIG.atomHomeDirPath)
8787
);
8888
}
89+
90+
const { expose } = require(`${CONFIG.scriptRunnerModulesPath}/threads/worker`);
91+
expose(transpilePackagesWithCustomTranspilerPaths);
92+
module.exports = transpilePackagesWithCustomTranspilerPaths;

script/lib/transpile-peg-js-paths.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const path = require('path');
77

88
const CONFIG = require('../config');
99

10-
module.exports = function() {
10+
function transpilePegJsPaths() {
1111
console.log(`Transpiling PEG.js paths in ${CONFIG.intermediateAppPath}`);
1212
for (let path of getPathsToTranspile()) {
1313
transpilePegJsPath(path);
1414
}
15-
};
15+
}
1616

1717
function getPathsToTranspile() {
1818
let paths = [];
@@ -41,3 +41,7 @@ function transpilePegJsPath(pegJsPath) {
4141
fs.writeFileSync(jsPath, outputCode);
4242
fs.unlinkSync(pegJsPath);
4343
}
44+
45+
const { expose } = require(`${CONFIG.scriptRunnerModulesPath}/threads/worker`);
46+
expose(transpilePegJsPaths);
47+
module.exports = transpilePegJsPaths;

0 commit comments

Comments
 (0)