Browse Source

Do not write to stdout in Electron when running on win32 CI machine

This makes Electron crash on CI machine somehow.
Cheng Zhao 9 years ago
parent
commit
8aa88067ca
3 changed files with 22 additions and 9 deletions
  1. 3 2
      script/cibuild
  2. 5 0
      script/test.py
  3. 14 7
      spec/static/main.js

+ 3 - 2
script/cibuild

@@ -39,7 +39,6 @@ def main():
   if os.environ.has_key('TARGET_ARCH'):
     target_arch = os.environ['TARGET_ARCH']
 
-  is_appveyor = (os.getenv('APPVEYOR') == 'True')
   is_travis = (os.getenv('TRAVIS') == 'true')
   if is_travis and PLATFORM == 'linux':
     print 'Setup travis CI'
@@ -76,8 +75,10 @@ def main():
     run_script('create-dist.py')
     run_script('upload.py')
   else:
+    if PLATFORM == 'win32':
+      os.environ['OUTPUT_TO_FILE'] = 'output.log'
     run_script('build.py', ['-c', 'D'])
-    if not is_appveyor and target_arch == 'x64':
+    if target_arch == 'x64':
       run_script('test.py', ['--ci'])
 
 

+ 5 - 0
script/test.py

@@ -32,6 +32,11 @@ def main():
 
   subprocess.check_call([atom_shell, 'spec'] + sys.argv[1:])
 
+  if os.environ.has_key('OUTPUT_TO_FILE'):
+    output_to_file = os.environ['OUTPUT_TO_FILE']
+    with open(output_to_file, 'r') as f:
+      print f.read()
+
 
 if __name__ == '__main__':
   sys.exit(main())

+ 14 - 7
spec/static/main.js

@@ -7,8 +7,10 @@ const ipcMain = electron.ipcMain
 const dialog = electron.dialog
 const BrowserWindow = electron.BrowserWindow
 
+const fs = require('fs')
 const path = require('path')
 const url = require('url')
+const util = require('util')
 
 var argv = require('yargs')
   .boolean('ci')
@@ -35,13 +37,18 @@ ipcMain.on('message', function (event, arg) {
   event.sender.send('message', arg)
 })
 
-ipcMain.on('console.log', function (event, args) {
-  console.error.apply(console, args)
-})
-
-ipcMain.on('console.error', function (event, args) {
-  console.error.apply(console, args)
-})
+// Write output to file if OUTPUT_TO_FILE is defined.
+const outputToFile = process.env.OUTPUT_TO_FILE
+const print = function (_, args) {
+  let output = util.format.apply(null, args)
+  if (outputToFile) {
+    fs.appendFileSync(outputToFile, output + '\n')
+  } else {
+    console.error(output)
+  }
+}
+ipcMain.on('console.log', print)
+ipcMain.on('console.error', print)
 
 ipcMain.on('process.exit', function (event, code) {
   process.exit(code)