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 8 commits
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
39 changes: 39 additions & 0 deletions .github/workflows/pkg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build and Upload Artifacts for Multiple OS

on: [push]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: ubuntu-latest
run_script: pkg:linux
artifact_name: symbol-upload-linux
- os: macos-latest
run_script: pkg:macos
artifact_name: symbol-upload-macos
- os: windows-latest
run_script: pkg:windows
artifact_name: symbol-upload-win

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Install dependencies
run: npm ci

- name: Run platform-specific script
run: npm run ${{ matrix.run_script }} # Executes the script based on the operating system

- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_name }}
path: pkg/* # Uploads the artifact with a platform-specific name and path
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
45 changes: 36 additions & 9 deletions bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
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 { 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 +23,7 @@ import { existsSync } from 'node:fs';
remove,
files,
directory,
dumpSyms
} = await getCommandLineOptions(argDefinitions);

if (help) {
Expand Down Expand Up @@ -94,15 +97,39 @@ 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) {
try {
// @ts-ignore: Cannot find module
const nodeDumpSyms = (await import('node-dump-syms')).dumpSyms;
symbolFilePaths = symbolFilePaths.map(file => {
console.log(`Dumping syms for ${file}...`);
const symFile = join(tmpDir, `${basename(file)}.sym`);
nodeDumpSyms(file, symFile);
return symFile;
});
} catch (cause) {
throw new Error('Can\'t run dump_syms! Please ensure node-dump-syms is installed https://github.com/BugSplat-Git/node-dump-syms', { cause });
}
}

await uploadSymbolFiles(bugsplat, database, application, version, directory, symbolFilePaths);
await safeRemoveTmp();
process.exit(0);
})().catch((error) => {
})().catch(async (error) => {
console.error(error.message);
process.exit(1);
}).finally(async () => {
await safeRemoveTmp();
})
process.exit(1);
});

async function createBugSplatClient({
user,
Expand Down Expand Up @@ -160,12 +187,12 @@ function logHelpAndExit() {

function logMissingArgAndExit(arg: string): void {
console.log(`\nMissing argument: -${arg}\n`);
process.exit(1);
logHelpAndExit()
}

function logMissingAuthAndExit(): void {
console.log('\nInvalid authentication arguments: please provide either a user and password, or a clientId and clientSecret\n');
process.exit(1);
logHelpAndExit()
}

function normalizeDirectory(directory: string): string {
Expand Down
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@
"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",
"prebuild": "npm run clean",
"build": "tsc",
"prerelease": "npm run build",
"release": "npm publish --access public",
"prepkg": "npm run build",
"pkg": "npx pkg package.json",
"prepkg:linux": "npm run build",
"pkg:linux": "npx pkg package.json --targets node18-linux-x64 --output ./pkg/symbol-upload-linux",
"prepkg:macos": "npm run build",
"pkg:macos": "npx pkg package.json --targets node18-macos-x64 --output ./pkg/symbol-upload-macos",
"prepkg:windows": "npm run build",
"pkg:windows": "npx pkg package.json --targets node18-win-x64 --output ./pkg/symbol-upload-windows",
"act": "act --secret-file .env"
},
"repository": {
Expand All @@ -47,15 +52,10 @@
"homepage": "https://github.com/BugSplat-Git/symbol-upload#readme",
"pkg": {
"scripts": "./dist/**/*.js",
"targets": [
"node18-macos-x64",
"node18-linux-x64",
"node18-win-x64"
],
"outputPath": "./pkg",
"compress": "GZip",
"assets": [
"package.json"
"package.json",
"node_modules/node-dump-syms/dist/native/index.addon"
]
},
"devDependencies": {
Expand Down Expand Up @@ -90,5 +90,8 @@
"promise-retry": "^2.0.1",
"rxjs": "^7.8.1",
"workerpool": "^6.5.1"
},
"optionalDependencies": {
"node-dump-syms": "^3.0.6"
}
}
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
4 changes: 2 additions & 2 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ export class UploadWorker {
let tmpFileName = '';

if (dbgId && !isZip) {
tmpFileName = join(tmpDir, `${fileName}.gz`);
let tmpSubdir = join(tmpDir, dirname(fileName));
const tmpSubdir = join(tmpDir, dirname(fileName));
if (!existsSync(tmpSubdir)) {
mkdirSync(tmpSubdir, { recursive: true });
}
tmpFileName = join(tmpSubdir, `${fileName}.gz`);
client = this.symbolsClient;
await this.pool.exec('createGzipFile', [path, tmpFileName]);
} else if (!isZip) {
Expand Down
Loading