From 7685201906b55d93be6151fa4681e8b24d6c9c74 Mon Sep 17 00:00:00 2001 From: Nathan Scoglio Date: Fri, 4 Feb 2022 14:24:50 -0800 Subject: [PATCH] Add support for product_name in Mac sym_upload v2 Change-Id: I6fab9f62434fd19eb7aea4a66f0dd809af57e595 Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/3436859 Reviewed-by: Nelson Billing Reviewed-by: Mark Mentovai --- src/common/mac/SymbolCollectorClient.h | 3 ++- src/common/mac/SymbolCollectorClient.m | 18 +++++++++++------- src/tools/mac/symupload/symupload.mm | 22 +++++++++++++++------- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/common/mac/SymbolCollectorClient.h b/src/common/mac/SymbolCollectorClient.h index 9e955c8e..8848cca6 100644 --- a/src/common/mac/SymbolCollectorClient.h +++ b/src/common/mac/SymbolCollectorClient.h @@ -96,7 +96,8 @@ typedef NS_ENUM(NSInteger, SymbolStatus) { withUploadKey:(NSString*)uploadKey withDebugFile:(NSString*)debugFile withDebugID:(NSString*)debugID - withType:(NSString*)type; + withType:(NSString*)type + withProductName:(NSString*)productName; @end diff --git a/src/common/mac/SymbolCollectorClient.m b/src/common/mac/SymbolCollectorClient.m index 5926d2ad..ae2e2db3 100644 --- a/src/common/mac/SymbolCollectorClient.m +++ b/src/common/mac/SymbolCollectorClient.m @@ -190,18 +190,22 @@ withUploadKey:(NSString*)uploadKey withDebugFile:(NSString*)debugFile withDebugID:(NSString*)debugID - withType:(NSString*)type { + withType:(NSString*)type + withProductName:(NSString*)productName { NSURL* URL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/v1/uploads/%@:complete?key=%@", APIURL, uploadKey, APIKey]]; - NSDictionary* symbolIdDictionary = - [NSDictionary dictionaryWithObjectsAndKeys:debugFile, @"debug_file", - debugID, @"debug_id", nil]; - NSDictionary* jsonDictionary = [NSDictionary - dictionaryWithObjectsAndKeys:symbolIdDictionary, @"symbol_id", type, - @"symbol_upload_type", nil]; + NSMutableDictionary* jsonDictionary = [@{ + @"symbol_id" : @{@"debug_file" : debugFile, @"debug_id" : debugID}, + @"symbol_upload_type" : type + } mutableCopy]; + + if (productName != nil) { + jsonDictionary[@"metadata"] = @{@"product_name": productName}; + } + NSError* error = nil; NSData* jsonData = [NSJSONSerialization dataWithJSONObject:jsonDictionary diff --git a/src/tools/mac/symupload/symupload.mm b/src/tools/mac/symupload/symupload.mm index 10cf293d..727834ce 100644 --- a/src/tools/mac/symupload/symupload.mm +++ b/src/tools/mac/symupload/symupload.mm @@ -73,6 +73,7 @@ typedef struct { NSString* type; NSString* codeFile; NSString* debugID; + NSString* productName; } Options; //============================================================================= @@ -212,7 +213,8 @@ static void StartSymUploadProtocolV2(Options* options, withUploadKey:[URLResponse uploadKey] withDebugFile:debugFile withDebugID:debugID - withType:options->type]; + withType:options->type + withProductName:options->productName]; [URLResponse release]; if (completeUploadResult == CompleteUploadResultError) { fprintf(stdout, "Failed to complete upload.\n"); @@ -271,18 +273,20 @@ static void Usage(int argc, const char* argv[]) { "[Only in sym-upload-v2 protocol mode]\n"); fprintf( stderr, - "-t:\t Explicitly set symbol upload type (" + "\t-t: Explicitly set symbol upload type (" "default is 'breakpad').\n" "\t One of ['breakpad', 'elf', 'pe', 'macho', 'debug_only', 'dwp', " "'dsym', 'pdb'].\n" "\t Note: When this flag is set to anything other than 'breakpad', then " "the '-c' and '-i' flags must also be set.\n"); - fprintf(stderr, "-c:\t Explicitly set 'code_file' for symbol " + fprintf(stderr, "\t-c: Explicitly set 'code_file' for symbol " "upload (basename of executable).\n"); - fprintf(stderr, "-i:\t Explicitly set 'debug_id' for symbol " + fprintf(stderr, "\t-i: Explicitly set 'debug_id' for symbol " "upload (typically build ID of executable). The debug-id for " "symbol-types 'dsym' and 'macho' will be determined " "automatically. \n"); + fprintf(stderr, "\t-n: Optionally set 'product_name' for " + "symbol upload\n"); fprintf(stderr, "\t-h: Usage\n"); fprintf(stderr, "\t-?: Usage\n"); fprintf(stderr, "\n"); @@ -329,11 +333,12 @@ static void SetupOptions(int argc, const char* argv[], Options* options) { options->codeFile = nil; options->debugID = nil; options->force = NO; + options->productName = nil; extern int optind; int ch; - while ((ch = getopt(argc, (char* const*)argv, "p:k:t:c:i:hf?")) != -1) { + while ((ch = getopt(argc, (char* const*)argv, "p:k:t:c:i:n:hf?")) != -1) { switch (ch) { case 'p': if (strcmp(optarg, "sym-upload-v2") == 0) { @@ -362,12 +367,15 @@ static void SetupOptions(int argc, const char* argv[], Options* options) { case 'c': options->codeFile = [NSString stringWithCString:optarg encoding:NSASCIIStringEncoding]; - ; break; case 'i': options->debugID = [NSString stringWithCString:optarg encoding:NSASCIIStringEncoding]; - ; + break; + case 'n': + options->productName = + [NSString stringWithCString:optarg + encoding:NSASCIIStringEncoding]; break; case 'f': options->force = YES;