Skip to content

Commit

Permalink
Merge branch 'feature/PLCR-559-Provide-CFBundleShortVersionString-value'
Browse files Browse the repository at this point in the history
  • Loading branch information
landonf committed Feb 22, 2015
2 parents 9ea6cda + 5246f11 commit e6d1ac1
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Resources/crash_report.proto
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ message CrashReport {

/* Application version string */
required string version = 2;

/* Application marketing version string */
optional string marketing_version = 3;
}
required ApplicationInfo application_info = 2;

Expand Down
4 changes: 4 additions & 0 deletions Source/PLCrashLogWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ typedef struct plcrash_log_writer {

/** Application version */
char *app_version;

/** Application marketing version (may be null) */
char *app_marketing_version;
} application_info;

/** Process data */
Expand Down Expand Up @@ -212,6 +215,7 @@ typedef struct plcrash_log_signal_info {
plcrash_error_t plcrash_log_writer_init (plcrash_log_writer_t *writer,
NSString *app_identifier,
NSString *app_version,
NSString *app_marketing_version,
plcrash_async_symbol_strategy_t symbol_strategy,
BOOL user_requested);
void plcrash_log_writer_set_exception (plcrash_log_writer_t *writer, NSException *exception);
Expand Down
21 changes: 18 additions & 3 deletions Source/PLCrashLogWriter.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@

/** CrashReport.app_info.app_version */
PLCRASH_PROTO_APP_INFO_APP_VERSION_ID = 2,

/** CrashReport.app_info.app_marketing_version */
PLCRASH_PROTO_APP_INFO_APP_MARKETING_VERSION_ID = 3,


/** CrashReport.symbol.name */
Expand Down Expand Up @@ -257,6 +260,7 @@
* @param writer Writer instance to be initialized.
* @param app_identifier Unique per-application identifier. On Mac OS X, this is likely the CFBundleIdentifier.
* @param app_version Application version string.
* @param app_marketing_version Application marketing version string (may be nil).
* @param symbol_strategy The strategy to use for local symbolication.
* @param user_requested If true, the written report will be marked as a 'generated' non-crash report, rather than as
* a true crash report created upon an actual crash.
Expand All @@ -269,6 +273,7 @@
plcrash_error_t plcrash_log_writer_init (plcrash_log_writer_t *writer,
NSString *app_identifier,
NSString *app_version,
NSString *app_marketing_version,
plcrash_async_symbol_strategy_t symbol_strategy,
BOOL user_requested)
{
Expand All @@ -295,6 +300,9 @@ plcrash_error_t plcrash_log_writer_init (plcrash_log_writer_t *writer,
{
writer->application_info.app_identifier = strdup([app_identifier UTF8String]);
writer->application_info.app_version = strdup([app_version UTF8String]);
if (app_marketing_version != nil) {
writer->application_info.app_marketing_version = strdup([app_marketing_version UTF8String]);
}
}

/* Fetch the process information */
Expand Down Expand Up @@ -509,6 +517,8 @@ void plcrash_log_writer_free (plcrash_log_writer_t *writer) {
free(writer->application_info.app_identifier);
if (writer->application_info.app_version != NULL)
free(writer->application_info.app_version);
if (writer->application_info.app_marketing_version != NULL)
free(writer->application_info.app_marketing_version);

/* Free the process info */
if (writer->process_info.process_name != NULL)
Expand Down Expand Up @@ -643,8 +653,9 @@ static size_t plcrash_writer_write_machine_info (plcrash_async_file_t *file, plc
* @param file Output file
* @param app_identifier Application identifier
* @param app_version Application version
* @param app_marketing_version Application marketing version
*/
static size_t plcrash_writer_write_app_info (plcrash_async_file_t *file, const char *app_identifier, const char *app_version) {
static size_t plcrash_writer_write_app_info (plcrash_async_file_t *file, const char *app_identifier, const char *app_version, const char *app_marketing_version) {
size_t rv = 0;

/* App identifier */
Expand All @@ -653,6 +664,10 @@ static size_t plcrash_writer_write_app_info (plcrash_async_file_t *file, const c
/* App version */
rv += plcrash_writer_pack(file, PLCRASH_PROTO_APP_INFO_APP_VERSION_ID, PLPROTOBUF_C_TYPE_STRING, app_version);

/* App marketing version */
if (app_marketing_version != NULL)
rv += plcrash_writer_pack(file, PLCRASH_PROTO_APP_INFO_APP_MARKETING_VERSION_ID, PLPROTOBUF_C_TYPE_STRING, app_marketing_version);

return rv;
}

Expand Down Expand Up @@ -1273,11 +1288,11 @@ plcrash_error_t plcrash_log_writer_write (plcrash_log_writer_t *writer,
uint32_t size;

/* Determine size */
size = plcrash_writer_write_app_info(NULL, writer->application_info.app_identifier, writer->application_info.app_version);
size = plcrash_writer_write_app_info(NULL, writer->application_info.app_identifier, writer->application_info.app_version, writer->application_info.app_marketing_version);

/* Write message */
plcrash_writer_pack(file, PLCRASH_PROTO_APP_INFO_ID, PLPROTOBUF_C_TYPE_MESSAGE, &size);
plcrash_writer_write_app_info(file, writer->application_info.app_identifier, writer->application_info.app_version);
plcrash_writer_write_app_info(file, writer->application_info.app_identifier, writer->application_info.app_version, writer->application_info.app_marketing_version);
}

/* Process info */
Expand Down
3 changes: 2 additions & 1 deletion Source/PLCrashLogWriterTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ - (void) checkAppInfo: (Plcrash__CrashReport *) crashReport {

STAssertTrue(strcmp(appInfo->identifier, "test.id") == 0, @"Incorrect app ID written");
STAssertTrue(strcmp(appInfo->version, "1.0") == 0, @"Incorrect app version written");
STAssertTrue(strcmp(appInfo->marketing_version, "2.0") == 0, @"Incorrect app marketing version written");
}

// check a crash report's process info
Expand Down Expand Up @@ -323,7 +324,7 @@ - (void) testWriteReport {
plcrash_async_file_init(&file, fd, 0);

/* Initialize a writer */
STAssertEquals(PLCRASH_ESUCCESS, plcrash_log_writer_init(&writer, @"test.id", @"1.0", PLCRASH_ASYNC_SYMBOL_STRATEGY_ALL, false), @"Initialization failed");
STAssertEquals(PLCRASH_ESUCCESS, plcrash_log_writer_init(&writer, @"test.id", @"1.0", @"2.0", PLCRASH_ASYNC_SYMBOL_STRATEGY_ALL, false), @"Initialization failed");

/* Set an exception with a valid return address call stack. */
NSException *e;
Expand Down
10 changes: 9 additions & 1 deletion Source/PLCrashReport.m
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ - (PLCrashReportMachineInfo *) extractMachineInfo: (Plcrash__CrashReport__Machin
- (PLCrashReportApplicationInfo *) extractApplicationInfo: (Plcrash__CrashReport__ApplicationInfo *) applicationInfo
error: (NSError **) outError
{
NSString *marketingVersion = nil;

/* Validate */
if (applicationInfo == NULL) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid,
Expand All @@ -493,12 +495,18 @@ - (PLCrashReportApplicationInfo *) extractApplicationInfo: (Plcrash__CrashReport
return nil;
}

/* Marketing Version available? */
if (applicationInfo->marketing_version != NULL) {
marketingVersion = [NSString stringWithUTF8String: applicationInfo->marketing_version];
}

/* Done */
NSString *identifier = [NSString stringWithUTF8String: applicationInfo->identifier];
NSString *version = [NSString stringWithUTF8String: applicationInfo->version];

return [[[PLCrashReportApplicationInfo alloc] initWithApplicationIdentifier: identifier
applicationVersion: version] autorelease];
applicationVersion: version
applicationMarketingVersion:marketingVersion] autorelease];
}


Expand Down
11 changes: 10 additions & 1 deletion Source/PLCrashReportApplicationInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@

/** Application version */
NSString *_applicationVersion;

/** Application marketing version */
NSString *_applicationMarketingVersion;
}

- (id) initWithApplicationIdentifier: (NSString *) applicationIdentifier
applicationVersion: (NSString *) applicationVersion;
applicationVersion: (NSString *) applicationVersion
applicationMarketingVersion: (NSString *) applicationMarketingVersion;

/**
* The application identifier. This is usually the application's CFBundleIdentifier value.
Expand All @@ -50,4 +54,9 @@
*/
@property(nonatomic, readonly) NSString *applicationVersion;

/**
* The application marketing version. This is usually the application's CFBundleShortVersionString value if available. May be nil.
*/
@property(nonatomic, readonly) NSString *applicationMarketingVersion;

@end
4 changes: 4 additions & 0 deletions Source/PLCrashReportApplicationInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,27 @@ @implementation PLCrashReportApplicationInfo
*/
- (id) initWithApplicationIdentifier: (NSString *) applicationIdentifier
applicationVersion: (NSString *) applicationVersion
applicationMarketingVersion: (NSString *) applicationMarketingVersion
{
if ((self = [super init]) == nil)
return nil;

_applicationIdentifier = [applicationIdentifier retain];
_applicationVersion = [applicationVersion retain];
_applicationMarketingVersion = [applicationMarketingVersion retain];

return self;
}

- (void) dealloc {
[_applicationIdentifier release];
[_applicationVersion release];
[_applicationMarketingVersion release];
[super dealloc];
}

@synthesize applicationIdentifier = _applicationIdentifier;
@synthesize applicationVersion = _applicationVersion;
@synthesize applicationMarketingVersion = _applicationMarketingVersion;

@end
2 changes: 1 addition & 1 deletion Source/PLCrashReportTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ - (void) testWriteReport {
plcrash_async_file_init(&file, fd, 0);

/* Initialize a writer */
STAssertEquals(PLCRASH_ESUCCESS, plcrash_log_writer_init(&writer, @"test.id", @"1.0", PLCRASH_ASYNC_SYMBOL_STRATEGY_ALL, false), @"Initialization failed");
STAssertEquals(PLCRASH_ESUCCESS, plcrash_log_writer_init(&writer, @"test.id", @"1.0", @"1.0", PLCRASH_ASYNC_SYMBOL_STRATEGY_ALL, false), @"Initialization failed");

/* Set an exception with a valid return address call stack. */
NSException *exception;
Expand Down
7 changes: 6 additions & 1 deletion Source/PLCrashReportTextFormatter.m
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,15 @@ + (NSString *) stringValueForCrashReport: (PLCrashReport *) report withTextForma
parentProcessId = [[NSNumber numberWithUnsignedInteger: report.processInfo.parentProcessID] stringValue];
}

NSString *versionString = report.applicationInfo.applicationVersion;
/* Marketing version is optional */
if (report.applicationInfo.applicationMarketingVersion != nil)
versionString = [NSString stringWithFormat: @"%@ (%@)", report.applicationInfo.applicationMarketingVersion, report.applicationInfo.applicationVersion];

[text appendFormat: @"Process: %@ [%@]\n", processName, processId];
[text appendFormat: @"Path: %@\n", processPath];
[text appendFormat: @"Identifier: %@\n", report.applicationInfo.applicationIdentifier];
[text appendFormat: @"Version: %@\n", report.applicationInfo.applicationVersion];
[text appendFormat: @"Version: %@\n", versionString];
[text appendFormat: @"Code Type: %@\n", codeType];
[text appendFormat: @"Parent Process: %@ [%@]\n", parentProcessName, parentProcessId];
}
Expand Down
3 changes: 3 additions & 0 deletions Source/PLCrashReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ typedef struct PLCrashReporterCallbacks {

/** Application version */
NSString *_applicationVersion;

/** Application marketing version */
NSString *_applicationMarketingVersion;

/** Path to the crash reporter internal data directory */
NSString *_crashReportDirectory;
Expand Down
14 changes: 9 additions & 5 deletions Source/PLCrashReporter.m
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ static void uncaught_exception_handler (NSException *exception) {
@interface PLCrashReporter (PrivateMethods)

- (id) initWithBundle: (NSBundle *) bundle configuration: (PLCrashReporterConfig *) configuration;
- (id) initWithApplicationIdentifier: (NSString *) applicationIdentifier appVersion: (NSString *) applicationVersion configuration: (PLCrashReporterConfig *) configuration;
- (id) initWithApplicationIdentifier: (NSString *) applicationIdentifier appVersion: (NSString *) applicationVersion appMarketingVersion: (NSString *) applicationMarketingVersion configuration: (PLCrashReporterConfig *) configuration;

- (PLCrashMachExceptionServer *) enableMachExceptionServerWithPreviousPortSet: (PLCrashMachExceptionPortSet **) previousPortSet
callback: (PLCrashMachExceptionHandlerCallback) callback
Expand Down Expand Up @@ -577,7 +577,7 @@ - (BOOL) enableCrashReporterAndReturnError: (NSError **) outError {
signal_handler_context.path = strdup([[self crashReportPath] UTF8String]); // NOTE: would leak if this were not a singleton struct
assert(_applicationIdentifier != nil);
assert(_applicationVersion != nil);
plcrash_log_writer_init(&signal_handler_context.writer, _applicationIdentifier, _applicationVersion, [self mapToAsyncSymbolicationStrategy: _config.symbolicationStrategy], false);
plcrash_log_writer_init(&signal_handler_context.writer, _applicationIdentifier, _applicationVersion, _applicationMarketingVersion, [self mapToAsyncSymbolicationStrategy: _config.symbolicationStrategy], false);


/* Enable the signal handler */
Expand Down Expand Up @@ -702,7 +702,7 @@ - (NSData *) generateLiveReportWithThread: (thread_t) thread error: (NSError **)
}

/* Initialize the output context */
plcrash_log_writer_init(&writer, _applicationIdentifier, _applicationVersion, [self mapToAsyncSymbolicationStrategy: _config.symbolicationStrategy], true);
plcrash_log_writer_init(&writer, _applicationIdentifier, _applicationVersion, _applicationMarketingVersion, [self mapToAsyncSymbolicationStrategy: _config.symbolicationStrategy], true);
plcrash_async_file_init(&file, fd, MAX_REPORT_BYTES);

/* Mock up a SIGTRAP-based signal info */
Expand Down Expand Up @@ -835,12 +835,13 @@ @implementation PLCrashReporter (PrivateMethods)
*
* @param applicationIdentifier The application identifier to be included in crash reports.
* @param applicationVersion The application version number to be included in crash reports.
* @param applicationMarketingVersion The application marketing version number to be included in crash reports.
* @param configuration The PLCrashReporter configuration.
*
* @todo The appId and version values should be fetched from the PLCrashReporterConfig, once the API
* has been extended to allow supplying these values.
*/
- (id) initWithApplicationIdentifier: (NSString *) applicationIdentifier appVersion: (NSString *) applicationVersion configuration: (PLCrashReporterConfig *) configuration {
- (id) initWithApplicationIdentifier: (NSString *) applicationIdentifier appVersion: (NSString *) applicationVersion appMarketingVersion: (NSString *) applicationMarketingVersion configuration: (PLCrashReporterConfig *) configuration {
/* Initialize our superclass */
if ((self = [super init]) == nil)
return nil;
Expand All @@ -849,6 +850,7 @@ - (id) initWithApplicationIdentifier: (NSString *) applicationIdentifier appVers
_config = [configuration retain];
_applicationIdentifier = [applicationIdentifier retain];
_applicationVersion = [applicationVersion retain];
_applicationMarketingVersion = [applicationMarketingVersion retain];

/* No occurances of '/' should ever be in a bundle ID, but just to be safe, we escape them */
NSString *appIdPath = [applicationIdentifier stringByReplacingOccurrencesOfString: @"/" withString: @"_"];
Expand All @@ -872,6 +874,7 @@ - (id) initWithApplicationIdentifier: (NSString *) applicationIdentifier appVers
- (id) initWithBundle: (NSBundle *) bundle configuration: (PLCrashReporterConfig *) configuration {
NSString *bundleIdentifier = [bundle bundleIdentifier];
NSString *bundleVersion = [[bundle infoDictionary] objectForKey: (NSString *) kCFBundleVersionKey];
NSString *bundleMarketingVersion = [[bundle infoDictionary] objectForKey: @"CFBundleShortVersionString"];

/* Verify that the identifier is available */
if (bundleIdentifier == nil) {
Expand All @@ -892,7 +895,7 @@ - (id) initWithBundle: (NSBundle *) bundle configuration: (PLCrashReporterConfig
bundleVersion = @"";
}

return [self initWithApplicationIdentifier: bundleIdentifier appVersion: bundleVersion configuration: configuration];
return [self initWithApplicationIdentifier: bundleIdentifier appVersion: bundleVersion appMarketingVersion:bundleMarketingVersion configuration: configuration];
}

#if PLCRASH_FEATURE_MACH_EXCEPTIONS
Expand Down Expand Up @@ -980,6 +983,7 @@ - (void) dealloc {
[_crashReportDirectory release];
[_applicationIdentifier release];
[_applicationVersion release];
[_applicationMarketingVersion release];

[super dealloc];
}
Expand Down

0 comments on commit e6d1ac1

Please sign in to comment.