Skip to content

Commit

Permalink
feat: uuids for ELF files (#89)
Browse files Browse the repository at this point in the history
* feat: uuids for ELF files

* fix: make pkg compatible

* chore: install @bugsplat/elfy
  • Loading branch information
bobbyg603 authored Feb 29, 2024
1 parent f11dd46 commit 6ddc406
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 51 deletions.
116 changes: 73 additions & 43 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"start:pdb": "ts-node -r dotenv/config ./bin/index.ts -d ./spec -f \"**/*.+(exe|dll|pdb)\"",
"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\"",
"test": "ts-node node_modules/jasmine/bin/jasmine",
"help": "ts-node ./bin/index.ts -h",
"clean": "rimraf ./dist",
Expand Down Expand Up @@ -73,10 +74,11 @@
"jasmine": "^4.6.0",
"pkg": "^5.8.1",
"rimraf": "^5.0.0",
"ts-node": "^10.2.1",
"typescript": "^4.3.2"
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"dependencies": {
"@bugsplat/elfy": "^1.0.0",
"@bugsplat/js-api-client": "^8.0.1",
"archiver": "^5.3.1",
"command-line-args": "^5.2.0",
Expand Down
9 changes: 9 additions & 0 deletions spec/elf.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { tryGetElfUUID } from "../src/elf";

describe('elf', () => {
describe('tryGetElfUUID', () => {
it('should return uuid for elf file', async () => {
return expectAsync(tryGetElfUUID('spec/support/bugsplat.elf')).toBeResolvedTo('005f5f676d6f6e5f73746172745f5f006c696263');
});
});
});
Binary file added spec/support/bugsplat.elf
Binary file not shown.
34 changes: 34 additions & 0 deletions src/elf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ElfFile } from '@bugsplat/elfy';

export async function tryGetElfUUID(path: string) {
let success: boolean, section: Buffer | undefined;

// TODO BG use a using statement here when we move away from pkg and can use node 20+
let elfFile = await ElfFile.create(path);
try {
({ success, section } = await elfFile.tryReadSection('.note.gnu.build-id'));
} finally {
elfFile.dispose();
}

if (success) {
return getUUID(section!);
}

elfFile = await ElfFile.create(path);
try {
({ success, section } = await elfFile.tryReadSection('.sce_special'));
} finally {
elfFile.dispose();
}

if (success) {
return getUUID(section!);
}

return '';
}

function getUUID(section: Buffer) {
return section.subarray(0, 20).toString('hex');
}
13 changes: 13 additions & 0 deletions src/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { glob } from "glob";
import { basename, dirname, extname, join, relative } from "node:path";
import { pool } from "workerpool";
import { getDSymFileInfos } from './dsym';
import { tryGetElfUUID } from './elf';
import { SymbolFileInfo } from './info';
import { tryGetPdbGuid, tryGetPeGuid } from './pdb';
import { getSymFileInfo } from './sym';
Expand Down Expand Up @@ -41,6 +42,7 @@ async function createSymbolFileInfos(searchDirectory: string, symbolFilePath: st
const isSymFile = extLowerCase.includes('.sym');
const isPdbFile = extLowerCase.includes('.pdb');
const isPeFile = extLowerCase.includes('.exe') || extLowerCase.includes('.dll');
const isElfFile = extLowerCase.includes('.elf') || extLowerCase.includes('.self');
const isDsymFile = extLowerCase.includes('.dsym');

if (isPdbFile) {
Expand Down Expand Up @@ -79,6 +81,17 @@ async function createSymbolFileInfos(searchDirectory: string, symbolFilePath: st
return getDSymFileInfos(path);
}

if (isElfFile) {
const dbgId = await tryGetElfUUID(path);
const moduleName = basename(path);
return [{
path,
dbgId,
moduleName,
relativePath
} as SymbolFileInfo];
}

const dbgId = '';
const moduleName = basename(path);
return [{
Expand Down
9 changes: 3 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"target": "es2020",
"lib": ["es2022"],
"module": "commonjs",
"declaration": true,
"sourceMap": true,
Expand All @@ -12,9 +13,5 @@
"forceConsistentCasingInFileNames": true,
"allowJs": true
},
"files": [
"./index.ts",
"./bin/index.ts",
"src/compression.js"
]
}
"files": ["./index.ts", "./bin/index.ts", "src/compression.js"]
}

0 comments on commit 6ddc406

Please sign in to comment.