GSI - Employe Self Service Mobile
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
3.3 KiB

2 months ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const os = require("os");
  5. const path = require("path");
  6. const uuid = require("uuid");
  7. const command_1 = require("../command");
  8. const error_1 = require("../error");
  9. const utils = require("../utils");
  10. const buildToolsJarHelper_1 = require("../crashlytics/buildToolsJarHelper");
  11. var SymbolGenerator;
  12. (function (SymbolGenerator) {
  13. SymbolGenerator["breakpad"] = "breakpad";
  14. SymbolGenerator["csym"] = "csym";
  15. })(SymbolGenerator || (SymbolGenerator = {}));
  16. const SYMBOL_CACHE_ROOT_DIR = process.env.FIREBASE_CRASHLYTICS_CACHE_PATH || os.tmpdir();
  17. exports.command = new command_1.Command("crashlytics:symbols:upload <symbolFiles...>")
  18. .description("upload symbols for native code, to symbolicate stack traces")
  19. .option("--app <appID>", "the app id of your Firebase app")
  20. .option("--generator [breakpad|csym]", "the symbol generator being used, default is breakpad")
  21. .option("--dry-run", "generate symbols without uploading them")
  22. .action(async (symbolFiles, options) => {
  23. const app = getGoogleAppID(options);
  24. const generator = getSymbolGenerator(options);
  25. const dryRun = !!options.dryRun;
  26. const debug = !!options.debug;
  27. const jarFile = await (0, buildToolsJarHelper_1.fetchBuildtoolsJar)();
  28. const jarOptions = {
  29. app,
  30. generator,
  31. cachePath: path.join(SYMBOL_CACHE_ROOT_DIR, `crashlytics-${uuid.v4()}`, "nativeSymbols", app.replace(/:/g, "-"), generator),
  32. symbolFile: "",
  33. generate: true,
  34. };
  35. for (const symbolFile of symbolFiles) {
  36. utils.logBullet(`Generating symbols for ${symbolFile}`);
  37. const generateArgs = buildArgs(Object.assign(Object.assign({}, jarOptions), { symbolFile }));
  38. (0, buildToolsJarHelper_1.runBuildtoolsCommand)(jarFile, generateArgs, debug);
  39. utils.logBullet(`Generated symbols for ${symbolFile}`);
  40. utils.logBullet(`Output Path: ${jarOptions.cachePath}`);
  41. }
  42. if (dryRun) {
  43. utils.logBullet("Skipping upload because --dry-run was passed");
  44. return;
  45. }
  46. utils.logBullet(`Uploading all generated symbols...`);
  47. const uploadArgs = buildArgs(Object.assign(Object.assign({}, jarOptions), { generate: false }));
  48. (0, buildToolsJarHelper_1.runBuildtoolsCommand)(jarFile, uploadArgs, debug);
  49. utils.logBullet("Successfully uploaded all symbols");
  50. });
  51. function getGoogleAppID(options) {
  52. if (!options.app) {
  53. throw new error_1.FirebaseError("set --app <appId> to a valid Firebase application id, e.g. 1:00000000:android:0000000");
  54. }
  55. return options.app;
  56. }
  57. function getSymbolGenerator(options) {
  58. if (!options.generator) {
  59. return SymbolGenerator.breakpad;
  60. }
  61. if (!Object.values(SymbolGenerator).includes(options.generator)) {
  62. throw new error_1.FirebaseError('--symbol-generator should be set to either "breakpad" or "csym"');
  63. }
  64. return options.generator;
  65. }
  66. function buildArgs(options) {
  67. const baseArgs = [
  68. "-symbolGenerator",
  69. options.generator,
  70. "-symbolFileCacheDir",
  71. options.cachePath,
  72. "-verbose",
  73. ];
  74. if (options.generate) {
  75. return baseArgs.concat(["-generateNativeSymbols", "-unstrippedLibrary", options.symbolFile]);
  76. }
  77. return baseArgs.concat(["-uploadNativeSymbols", "-googleAppId", options.app]);
  78. }