1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @format
8 */
9
10'use strict';
11
12const fs = require('fs');
13const os = require('os');
14const path = require('path');
15
16/**
17 * This script creates a Hermes prebuilt artifacts tarball.
18 * Must be invoked after Hermes has been built.
19 */
20const yargs = require('yargs');
21const {createHermesPrebuiltArtifactsTarball} = require('./hermes-utils');
22
23let argv = yargs
24  .option('i', {
25    alias: 'inputDir',
26    describe: 'Path to directory where Hermes build artifacts were generated.',
27  })
28  .option('b', {
29    alias: 'buildType',
30    type: 'string',
31    describe: 'Specifies whether Hermes was built for Debug or Release.',
32    default: 'Debug',
33  })
34  .option('o', {
35    alias: 'outputDir',
36    describe: 'Location where the tarball will be saved to.',
37  })
38  .option('exclude-debug-symbols', {
39    describe: 'Whether dSYMs should be excluded from the tarball.',
40    type: 'boolean',
41    default: true,
42  }).argv;
43
44async function main() {
45  const hermesDir = argv.inputDir;
46  const buildType = argv.buildType;
47  const excludeDebugSymbols = argv.excludeDebugSymbols;
48  let tarballOutputDir = argv.outputDir;
49
50  if (!tarballOutputDir) {
51    try {
52      tarballOutputDir = fs.mkdtempSync(
53        path.join(os.tmpdir(), 'hermes-engine-tarball-'),
54      );
55    } catch (error) {
56      throw new Error(
57        `[Hermes] Failed to create temporary output directory: ${error}`,
58      );
59    }
60  }
61
62  const tarballOutputPath = createHermesPrebuiltArtifactsTarball(
63    hermesDir,
64    buildType,
65    tarballOutputDir,
66    excludeDebugSymbols,
67  );
68  console.log(tarballOutputPath);
69  return tarballOutputPath;
70}
71
72main().then(() => {
73  process.exit(0);
74});
75