Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add dump_syms #102

Merged
merged 9 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@
],
"type": "node"
},
{
"name": "Start: dump_syms",
"request": "launch",
"runtimeArgs": [
"run-script",
"start:dump_syms",
],
"runtimeExecutable": "npm",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
},
{
"name": "Test",
"request": "launch",
Expand Down
10 changes: 9 additions & 1 deletion bin/command-line-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ export const argDefinitions: Array<CommandLineDefinition> = [
typeLabel: '{underline string} (optional)',
description: 'Path of the base directory used to search for symbol files. This value will be combined with the --files glob. Defaults to \'.\'',
},
{
name: 'dumpSyms',
alias: 'm',
type: Boolean,
defaultValue: false,
description: 'Use dump_syms to generate and upload sym files for specified binaries.',
typeLabel: '{underline boolean} (optional)',
}
];

export const usageDefinitions: Array<Section> = [
Expand Down Expand Up @@ -134,7 +142,7 @@ function getPackageVersion(): string {
}

const packageJson = readFileSync(path, 'utf-8').toString();

try {
return JSON.parse(packageJson).version;
} catch {
Expand Down
29 changes: 26 additions & 3 deletions bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
import { ApiClient, BugSplatApiClient, OAuthClientCredentialsClient, VersionsApiClient } from '@bugsplat/js-api-client';
import commandLineArgs, { CommandLineOptions } from 'command-line-args';
import commandLineUsage from 'command-line-usage';
import { glob } from 'glob';
import { dumpSyms as nodeDumpSyms } from 'node-dump-syms';
import { existsSync } from 'node:fs';
import { mkdir, readFile, stat } from 'node:fs/promises';
import { basename, join } from 'node:path';
import { safeRemoveTmp, tmpDir } from '../src/tmp';
import { uploadSymbolFiles } from '../src/upload';
import { CommandLineDefinition, argDefinitions, usageDefinitions } from './command-line-definitions';
import { safeRemoveTmp, tmpDir } from '../src/tmp';
import { existsSync } from 'node:fs';

(async () => {
let {
Expand All @@ -21,6 +24,7 @@ import { existsSync } from 'node:fs';
remove,
files,
directory,
dumpSyms
} = await getCommandLineOptions(argDefinitions);

if (help) {
Expand Down Expand Up @@ -94,7 +98,26 @@ import { existsSync } from 'node:fs';
await mkdir(tmpDir);
}

await uploadSymbolFiles(bugsplat, database, application, version, directory, files);
const globPattern = `${directory}/${files}`;

let symbolFilePaths = await glob(globPattern);

if (!symbolFilePaths.length) {
throw new Error(`Could not find any files to upload using glob ${globPattern}!`);
}

console.log(`Found files:\n ${symbolFilePaths.join('\n')}`);

if (dumpSyms) {
symbolFilePaths = symbolFilePaths.map(file => {
console.log(`Dumping syms for ${file}...`);
const symFile = join(tmpDir, `${basename(file)}.sym`);
nodeDumpSyms(file, symFile);
return symFile;
});
}

await uploadSymbolFiles(bugsplat, database, application, version, directory, symbolFilePaths);

process.exit(0);
})().catch((error) => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"start:dsym": "ts-node -r dotenv/config ./bin/index.ts -d ./spec/support -f \"*.dSYM\" -a BugSplatTester -v \"1.0 (1)\"",
"start:xcarchive": "ts-node -r dotenv/config ./bin/index.ts -d ./spec/support -f \"*.xcarchive/**/*.dSYM\" -v \"4.5.6 (1)\"",
"start:elf": "ts-node -r dotenv/config ./bin/index.ts -d ./spec -f \"**/*.elf\"",
"start:dump_syms": "ts-node -r dotenv/config ./bin/index.ts -d ./spec -f \"**/*.dSYM\" -m",
"test": "ts-node node_modules/jasmine/bin/jasmine",
"help": "ts-node ./bin/index.ts -h",
"clean": "rimraf ./dist",
Expand Down
12 changes: 1 addition & 11 deletions src/upload.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ApiClient, SymbolsApiClient, VersionsApiClient } from "@bugsplat/js-api-client";
import { glob } from "glob";
import { basename, dirname, extname, join, relative } from "node:path";
import { pool } from "workerpool";
import { getDSymFileInfos } from './dsym';
Expand All @@ -11,16 +10,7 @@ import { createWorkersFromSymbolFiles } from './worker';

const workerPool = pool(join(__dirname, 'compression.js'));

export async function uploadSymbolFiles(bugsplat: ApiClient, database: string, application: string, version: string, directory: string, filesGlob: string) {
const globPattern = `${directory}/${filesGlob}`;

const symbolFilePaths = await glob(globPattern);

if (!symbolFilePaths.length) {
throw new Error(`Could not find any files to upload using glob ${globPattern}!`);
}

console.log(`Found files:\n ${symbolFilePaths.join('\n')}`);
export async function uploadSymbolFiles(bugsplat: ApiClient, database: string, application: string, version: string, directory: string, symbolFilePaths: Array<string>) {
console.log(`About to upload symbols for ${database}-${application}-${version}...`);

const symbolsApiClient = new SymbolsApiClient(bugsplat);
Expand Down
Loading