Skip to content

Commit

Permalink
Project: Add build version (#736)
Browse files Browse the repository at this point in the history
  • Loading branch information
russellhancox authored Feb 28, 2022
1 parent c7e309c commit e60f9cf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
7 changes: 6 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ exports_files(["LICENSE"])
# The version label for mac_* rules.
apple_bundle_version(
name = "version",
build_version = SANTA_VERSION,
build_label_pattern = "{build}",
build_version = SANTA_VERSION + ".{build}",
capture_groups = {
"build": "\\d+",
},
fallback_build_label = "1",
short_version_string = SANTA_VERSION,
)

Expand Down
13 changes: 10 additions & 3 deletions Source/santactl/Commands/SNTCommandVersion.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,25 @@ - (NSString *)santaKextVersion {
return @"not found";
}

- (NSString *)composeVersionsFromDict:(NSDictionary *)dict {
if (!dict[@"CFBundleVersion"]) return @"";
NSString *productVersion = dict[@"CFBundleShortVersionString"];
NSString *buildVersion = [[dict[@"CFBundleVersion"] componentsSeparatedByString:@"."] lastObject];
return [NSString stringWithFormat:@"%@ (build %@)", productVersion, buildVersion];
}

- (NSString *)santadVersion {
SNTFileInfo *daemonInfo = [[SNTFileInfo alloc] initWithPath:@(kSantaDPath)];
return daemonInfo.bundleVersion ?: @"";
return [self composeVersionsFromDict:daemonInfo.infoPlist];
}

- (NSString *)santaAppVersion {
SNTFileInfo *guiInfo = [[SNTFileInfo alloc] initWithPath:@(kSantaAppPath)];
return guiInfo.bundleVersion ?: @"";
return [self composeVersionsFromDict:guiInfo.infoPlist];
}

- (NSString *)santactlVersion {
return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"] ?: @"";
return [self composeVersionsFromDict:[[NSBundle mainBundle] infoDictionary]];
}

@end
8 changes: 6 additions & 2 deletions Source/santad/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,16 @@ int main(int argc, const char *argv[]) {
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
NSProcessInfo *pi = [NSProcessInfo processInfo];

NSString *productVersion = infoDict[@"CFBundleShortVersionString"];
NSString *buildVersion =
[[infoDict[@"CFBundleVersion"] componentsSeparatedByString:@"."] lastObject];

if ([pi.arguments containsObject:@"-v"]) {
printf("%s\n", [infoDict[@"CFBundleVersion"] UTF8String]);
printf("%s (build %s)\n", [productVersion UTF8String], [buildVersion UTF8String]);
return 0;
}

LOGI(@"Started, version %@", infoDict[@"CFBundleVersion"]);
LOGI(@"Started, version %@ (build %@)", productVersion, buildVersion);

// Handle the case of macOS < 10.15 updating to >= 10.15.
if ([[SNTConfigurator configurator] enableSystemExtension]) {
Expand Down

0 comments on commit e60f9cf

Please sign in to comment.