|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | + |
| 4 | +// This tests the creation of a single executable application. |
| 5 | + |
| 6 | +const fixtures = require('../common/fixtures'); |
| 7 | +const tmpdir = require('../common/tmpdir'); |
| 8 | +const { copyFileSync, readFileSync, writeFileSync } = require('fs'); |
| 9 | +const { execFileSync } = require('child_process'); |
| 10 | +const { join } = require('path'); |
| 11 | +const { strictEqual } = require('assert'); |
| 12 | + |
| 13 | +if (!process.config.variables.single_executable_application) |
| 14 | + common.skip('Single Executable Application support has been disabled.'); |
| 15 | + |
| 16 | +if (!['darwin', 'win32', 'linux'].includes(process.platform)) |
| 17 | + common.skip(`Unsupported platform ${process.platform}.`); |
| 18 | + |
| 19 | +if (process.platform === 'linux' && process.config.variables.asan) |
| 20 | + common.skip('Running the resultant binary fails with `Segmentation fault (core dumped)`.'); |
| 21 | + |
| 22 | +if (process.platform === 'linux' && process.config.variables.is_debug === 1) |
| 23 | + common.skip('Running the resultant binary fails with `Couldn\'t read target executable"`.'); |
| 24 | + |
| 25 | +if (process.config.variables.node_shared) |
| 26 | + common.skip('Running the resultant binary fails with ' + |
| 27 | + '`/home/iojs/node-tmp/.tmp.2366/sea: error while loading shared libraries: ' + |
| 28 | + 'libnode.so.112: cannot open shared object file: No such file or directory`.'); |
| 29 | + |
| 30 | +if (process.config.variables.icu_gyp_path === 'tools/icu/icu-system.gyp') |
| 31 | + common.skip('Running the resultant binary fails with ' + |
| 32 | + '`/home/iojs/node-tmp/.tmp.2379/sea: error while loading shared libraries: ' + |
| 33 | + 'libicui18n.so.71: cannot open shared object file: No such file or directory`.'); |
| 34 | + |
| 35 | +if (!process.config.variables.node_use_openssl || process.config.variables.node_shared_openssl) |
| 36 | + common.skip('Running the resultant binary fails with `Node.js is not compiled with OpenSSL crypto support`.'); |
| 37 | + |
| 38 | +if (process.config.variables.want_separate_host_toolset !== 0) |
| 39 | + common.skip('Running the resultant binary fails with `Segmentation fault (core dumped)`.'); |
| 40 | + |
| 41 | +if (process.platform === 'linux') { |
| 42 | + try { |
| 43 | + const osReleaseText = readFileSync('/etc/os-release', { encoding: 'utf-8' }); |
| 44 | + if (!/^NAME="Ubuntu"/m.test(osReleaseText)) { |
| 45 | + throw new Error('Not Ubuntu.'); |
| 46 | + } |
| 47 | + } catch { |
| 48 | + common.skip('Only supported Linux distribution is Ubuntu.'); |
| 49 | + } |
| 50 | + |
| 51 | + if (process.arch !== 'x64') { |
| 52 | + common.skip(`Unsupported architecture for Linux - ${process.arch}.`); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +const inputFile = fixtures.path('sea.js'); |
| 57 | +const requirableFile = join(tmpdir.path, 'requirable.js'); |
| 58 | +const outputFile = join(tmpdir.path, process.platform === 'win32' ? 'sea.exe' : 'sea'); |
| 59 | + |
| 60 | +tmpdir.refresh(); |
| 61 | + |
| 62 | +writeFileSync(requirableFile, ` |
| 63 | +module.exports = { |
| 64 | + hello: 'world', |
| 65 | +}; |
| 66 | +`); |
| 67 | + |
| 68 | +copyFileSync(process.execPath, outputFile); |
| 69 | +const postjectFile = fixtures.path('postject-copy', 'node_modules', 'postject', 'dist', 'cli.js'); |
| 70 | +execFileSync(process.execPath, [ |
| 71 | + postjectFile, |
| 72 | + outputFile, |
| 73 | + 'NODE_JS_CODE', |
| 74 | + inputFile, |
| 75 | + '--sentinel-fuse', 'NODE_JS_FUSE_fce680ab2cc467b6e072b8b5df1996b2', |
| 76 | + ...process.platform === 'darwin' ? [ '--macho-segment-name', 'NODE_JS' ] : [], |
| 77 | +]); |
| 78 | + |
| 79 | +if (process.platform === 'darwin') { |
| 80 | + execFileSync('codesign', [ '--sign', '-', outputFile ]); |
| 81 | + execFileSync('codesign', [ '--verify', outputFile ]); |
| 82 | +} else if (process.platform === 'win32') { |
| 83 | + let signtoolFound = false; |
| 84 | + try { |
| 85 | + execFileSync('where', [ 'signtool' ]); |
| 86 | + signtoolFound = true; |
| 87 | + } catch (err) { |
| 88 | + console.log(err.message); |
| 89 | + } |
| 90 | + if (signtoolFound) { |
| 91 | + let certificatesFound = false; |
| 92 | + try { |
| 93 | + execFileSync('signtool', [ 'sign', '/fd', 'SHA256', outputFile ]); |
| 94 | + certificatesFound = true; |
| 95 | + } catch (err) { |
| 96 | + if (!/SignTool Error: No certificates were found that met all the given criteria/.test(err)) { |
| 97 | + throw err; |
| 98 | + } |
| 99 | + } |
| 100 | + if (certificatesFound) { |
| 101 | + execFileSync('signtool', 'verify', '/pa', 'SHA256', outputFile); |
| 102 | + } |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +const singleExecutableApplicationOutput = execFileSync( |
| 107 | + outputFile, |
| 108 | + [ '-a', '--b=c', 'd' ], |
| 109 | + { env: { COMMON_DIRECTORY: join(__dirname, '..', 'common') } }); |
| 110 | +strictEqual(singleExecutableApplicationOutput.toString(), 'Hello, world! 😊\n'); |
0 commit comments