-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Migrate make.js
to gulpfile.js
#8349
Conversation
Unfortunately this fails on Windows, during pdf.js/external/builder/builder.js Lines 285 to 298 in 71bbcfa
As far as I can ascertain, builder.js implicitly depend on some methods (e.g. ls ) from ShellJS, and with make.js now being removed those are no longer available. Hence I think that you'll you probably need to rewrite that part of builder.js too as part of these patches.
|
The code in the builder.js above just expanding wildcards. I think we can remove that since preprocessor is/must be working with particular/known files. |
gulpfile.js
Outdated
spawnSync('git', ['add', '.'], {cwd: MOZCENTRAL_BASELINE_DIR}); | ||
spawnSync('git', ['commit', '-m', 'mozcentral baseline'], | ||
{cwd: MOZCENTRAL_BASELINE_DIR}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to use done()
function here (and below) since this task is async.
We also have |
d69ffd6
to
9a54834
Compare
There is one Windows issue to resolve with @Snuffleupagus before we can land this. |
I've been attempting to debug this further today, but unfortunately I've been unable to make any progress :-( The main problem is that I know next to nothing (or at least very little) about Node.js, so I'm not sure what steps to take. In case it's useful: I can successfully run It would probably be good if someone else could test this on Windows, just to check that it's indeed a platform specific issue, and not my configuration that is somehow a special snowflake. |
I have a feeling it's related to Windows treating quotes in commands differently than Linux does. Related sites: |
While this is probably true, I can't help thinking that part of the issue may occur even before that.
If I instead run
In this case, since Could the main issue here be that the |
It seems that if I make a couple of small adjustments, based on skimming through the links in #8349 (comment), the follow diff actually seem to work! diff --git a/gulpfile.js b/gulpfile.js
index 0058fb94..c6ed3e6e 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -1361,7 +1361,8 @@ gulp.task('mozcentralbaseline', function (done) {
console.log();
console.log('### Creating mozcentral baseline environment');
- safeSpawnSync('gulp', ['baseline'], {env: process.env});
+ safeSpawnSync('gulp', ['baseline'],
+ {env: process.env, shell: true, stdio: 'inherit'});
// Create a mozcentral build. We have to pass the working directory to the
// Gulp process using the `--cwd` option to override the behavior of Gulp
@@ -1370,7 +1371,7 @@ gulp.task('mozcentralbaseline', function (done) {
rimraf.sync(BASELINE_DIR + BUILD_DIR);
}
safeSpawnSync('gulp', ['mozcentral', '--cwd', BASELINE_DIR],
- {env: process.env});
+ {env: process.env, shell: true, stdio: 'inherit'});
// Copy the mozcentral build to the mozcentral baseline directory.
if (checkDir(MOZCENTRAL_BASELINE_DIR)) {
@@ -1394,7 +1395,8 @@ gulp.task('mozcentraldiff', ['mozcentral'], function (done) {
console.log();
console.log('### Creating mozcentral diff');
- safeSpawnSync('gulp', ['mozcentralbaseline'], {env: process.env});
+ safeSpawnSync('gulp', ['mozcentralbaseline'],
+ {env: process.env, shell: true, stdio: 'inherit'});
// Create the diff between the current mozcentral build and the
// baseline mozcentral build, which both exist at this point. |
The We should probably pass this to every command, so I'll try to solve it in the |
9a54834
to
1c75ce5
Compare
I have updated the patch. The @Snuffleupagus Could you test this again on Windows to make sure all is well now? |
Unfortunately, that doesn't work :-( However, even with that adjusted, I'm now getting the same @timvandermeij Since I could swear that a previous version worked, once I applied the changes described in #8349 (comment), do you have an interdiff for the last round of changes? Edit: If I didn't know better, I'd say that you probably need to pass in |
The I only added the code from https://github.com/mozilla/pdf.js/pull/8349/files#diff-b9e12334e9eafd8341a6107dd98510c9R87 to line 94. No other changes were made. Maybe the platform test gives a different result for you, and the Note that if this doesn't work out, I have an alternative approach to all of this. I'm just hoping to avoid it if we can make this work with minimal changes. |
I'm thinking gulp does not allow run gulp. Can we replace spawnSync gulp with calling tasks? I'm thinking we don't have to have a special version of spawnSync for Windows. Also rimraf's don't need checkDir's |
To get everything to work, and to also get meaningful console output, the following diff works for me (note that it doesn't touch the part that you out pointed out as problematic w.r.t. diff --git a/gulpfile.js b/gulpfile.js
index 16447700..8e79d372 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -1369,7 +1369,7 @@ gulp.task('mozcentralbaseline', function (done) {
console.log();
console.log('### Creating mozcentral baseline environment');
- safeSpawnSync('gulp', ['baseline'], {env: process.env});
+ safeSpawnSync('gulp', ['baseline'], {env: process.env, stdio: 'inherit'});
// Create a mozcentral build. We have to pass the working directory to the
// Gulp process using the `--cwd` option to override the behavior of Gulp
@@ -1377,8 +1377,9 @@ gulp.task('mozcentralbaseline', function (done) {
if (checkDir(BASELINE_DIR + BUILD_DIR)) {
rimraf.sync(BASELINE_DIR + BUILD_DIR);
}
- safeSpawnSync('gulp', ['mozcentral', '--cwd', BASELINE_DIR],
- {env: process.env});
+ var workingDirectory = path.resolve(process.cwd(), BASELINE_DIR);
+ safeSpawnSync('gulp', ['mozcentral'],
+ {env: process.env, cwd: workingDirectory, stdio: 'inherit'});
// Copy the mozcentral build to the mozcentral baseline directory.
if (checkDir(MOZCENTRAL_BASELINE_DIR)) {
@@ -1392,7 +1393,7 @@ gulp.task('mozcentralbaseline', function (done) {
// Commit the mozcentral baseline.
safeSpawnSync('git', ['init'], {cwd: MOZCENTRAL_BASELINE_DIR});
safeSpawnSync('git', ['add', '.'], {cwd: MOZCENTRAL_BASELINE_DIR});
- safeSpawnSync('git', ['commit', '-m', 'mozcentral baseline'],
+ safeSpawnSync('git', ['commit', '-m', '"mozcentral baseline"'],
{cwd: MOZCENTRAL_BASELINE_DIR});
done();
});
@@ -1402,7 +1403,8 @@ gulp.task('mozcentraldiff', ['mozcentral'], function (done) {
console.log();
console.log('### Creating mozcentral diff');
- safeSpawnSync('gulp', ['mozcentralbaseline'], {env: process.env});
+ safeSpawnSync('gulp', ['mozcentralbaseline'],
+ {env: process.env, stdio: 'inherit'});
// Create the diff between the current mozcentral build and the
// baseline mozcentral build, which both exist at this point. |
I reverted the changes in |
Almost, but on Windows However, could the questions/suggestions in #8349 (comment) help remove the need for calling |
The fix for Windows is back in place. Fortunately it's only a few lines, so I'm not too worried about it. I have also removed the unnecessary checks around |
gulpfile.js
Outdated
if (taskName in gulp.tasks) { | ||
continue; | ||
} | ||
safeSpawnSync('gulp', ['baseline'], {env: process.env, stdio: 'inherit'}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this as a dependency for mozcentralbaseline task instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in the new commit.
gulpfile.js
Outdated
} | ||
|
||
var result = spawnSync(command, parameters, options); | ||
if (result.status) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change it to result.status !== 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spawnSync
may exit with result status null
, which is a valid value according to https://github.com/nodejs/node/pull/11288/files (see the IRC discussion at http://logs.glob.uno/?c=mozilla%23pdfjs&s=28+Apr+2017&e=28+Apr+2017#c60549). Such a check would disallow null
, so we chose for this. Note that we already have this at the moment in https://github.com/mozilla/pdf.js/blob/master/make.js#L31.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think null
is code of error/termination, e.g. ctrl+c.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely right, now that I look at the code again! Done in the new commit.
gulpfile.js
Outdated
@@ -81,6 +83,22 @@ var DEFINES = { | |||
PDFJS_NEXT: false, | |||
}; | |||
|
|||
function safeSpawnSync(command, parameters, options) { | |||
// Windows has problems executing commands outside a shell. | |||
if (process.platform === 'win32') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need it for all commands or for some?
can we add shell option for certain command on all platforms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that it's mainly an issue when spawn
ing a gulp
task, but otherwise I think it's fine without it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose to solve it in safeSpawnSync
to prevent issues for other (or future) commands. It's not entirely clear to me if Windows requires it all the time or just for some commands, so in this way we do not have to duplicate it and prevent any issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shell option does work on Linux as well after adjusting the stdio
behavior, so we can indeed enable it on all platforms to not make it Windows-specific anymore. Done in the new commit.
The baseline fix is dead code since three years, so we can safely remove it.
To run the regression tests, developers use `gulp browsertest` and the bot uses `gulp bottest`. We're not passing the `noreftest` option anywhere in the code (probably because the `bottest` command takes care of this already), so we should remove this.
Note that we have to use `fs.writeFileSync` since `.to()` is not available anymore. Moreover, introduce `safeSpawnSync` to make sure that we check the return codes of the spawned processes properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works just fine on Windows now; thank you for seeing this through to the end, and sorry about all the back-and-fourth here!
Thank you both for reviewing this! |
Migrate `make.js` to `gulpfile.js`
Fixes #7062.
It is easier to review each patch on its own since the overall diff is slightly hard to read because of the last commit.
Testing the
mozcentralbaseline
/mozcentraldiff
conversion is done by runningBASELINE=17d135f gulp mozcentralbaseline mozcentraldiff
without and with these patches applied and checking that the resulting diffs are equal in size.Note that the tasks properly depend on each other now, so running
BASELINE=17d135f gulp mozcentraldiff
gives the same result as the command above sincemozcentraldiff
depends onmozcentralbaseline
to run.