|
| 1 | +'use strict'; |
| 2 | +var cp = require('child_process'); |
| 3 | +var fs = require('fs'); |
| 4 | +var path = require('path'); |
| 5 | + |
| 6 | +var toolsPath = path.join(__dirname, '..', '..', 'deps', 'v8', 'tools'); |
| 7 | +var scriptFiles = [ |
| 8 | + path.join(__dirname, 'polyfill.js'), |
| 9 | + path.join(toolsPath, 'splaytree.js'), |
| 10 | + path.join(toolsPath, 'codemap.js'), |
| 11 | + path.join(toolsPath, 'csvparser.js'), |
| 12 | + path.join(toolsPath, 'consarray.js'), |
| 13 | + path.join(toolsPath, 'csvparser.js'), |
| 14 | + path.join(toolsPath, 'consarray.js'), |
| 15 | + path.join(toolsPath, 'profile.js'), |
| 16 | + path.join(toolsPath, 'profile_view.js'), |
| 17 | + path.join(toolsPath, 'logreader.js'), |
| 18 | + path.join(toolsPath, 'tickprocessor.js'), |
| 19 | + path.join(toolsPath, 'SourceMap.js'), |
| 20 | + path.join(toolsPath, 'tickprocessor-driver.js')]; |
| 21 | +var tempScript = path.join(__dirname, 'tick-processor-tmp-' + process.pid); |
| 22 | + |
| 23 | +process.on('exit', function() { |
| 24 | + try { fs.unlinkSync(tempScript); } catch (e) {} |
| 25 | +}); |
| 26 | +process.on('uncaughtException', function(err) { |
| 27 | + try { fs.unlinkSync(tempScript); } catch (e) {} |
| 28 | + throw err; |
| 29 | +}); |
| 30 | + |
| 31 | +var inStreams = scriptFiles.map(function(f) { |
| 32 | + return fs.createReadStream(f); |
| 33 | +}); |
| 34 | +var outStream = fs.createWriteStream(tempScript); |
| 35 | +inStreams.reduce(function(prev, curr, i) { |
| 36 | + prev.on('end', function() { |
| 37 | + curr.pipe(outStream, { end: i === inStreams.length - 1}); |
| 38 | + }); |
| 39 | + return curr; |
| 40 | +}); |
| 41 | +inStreams[0].pipe(outStream, { end: false }); |
| 42 | +outStream.on('close', function() { |
| 43 | + var tickArguments = [tempScript]; |
| 44 | + if (process.platform === 'darwin') { |
| 45 | + tickArguments.push('--mac', '--nm=' + path.join(toolsPath, 'mac-nm')); |
| 46 | + } else if (process.platform === 'win32') { |
| 47 | + tickArguments.push('--windows'); |
| 48 | + } |
| 49 | + tickArguments.push.apply(tickArguments, process.argv.slice(2)); |
| 50 | + var processTicks = cp.spawn(process.execPath, tickArguments, { stdio: 'inherit' }); |
| 51 | +}); |
0 commit comments