Skip to content

Commit

Permalink
Merge pull request #76 from readdle/version-improvements
Browse files Browse the repository at this point in the history
Added version flag and included HEAD commit hash into version string
  • Loading branch information
nikinapi authored Feb 1, 2024
2 parents b0514c1 + 3cb4f69 commit c777809
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion buildme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ xcodebuild_cmd() {
# these headers are unwanted and may cause module import conflicts
unset USER_HEADER_SEARCH_PATHS
unset HEADER_SEARCH_PATHS
S7_OTHER_CFLAGS="-DCOMMIT_HASH=\\\"$(git rev-parse --short HEAD)\\\""
xcodebuild -target system7 -configuration Release clean
xcodebuild -target system7 -configuration Release DSTROOT="$HOME" install
xcodebuild -target system7 -configuration Release DSTROOT="$HOME" OTHER_CFLAGS="$S7_OTHER_CFLAGS" install
}

if ! xcodebuild_cmd
Expand Down
9 changes: 7 additions & 2 deletions system7/Commands/S7VersionCommand.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

#import "HelpPager.h"

#ifndef VERSION_NUMBER
static const char VERSION_NUMBER[] = "1.0";
static const char VERSION_DATE[] = "2021-02-04";
#endif

@implementation S7VersionCommand

Expand All @@ -31,7 +32,11 @@ + (void)printCommandHelp {
}

- (int)runWithArguments:(NSArray<NSString *> *)arguments {
logInfo("s7 version %s (%s)\n", VERSION_NUMBER, VERSION_DATE);
logInfo("s7 version %s", VERSION_NUMBER);
#ifdef COMMIT_HASH
logInfo(" (%s)", COMMIT_HASH);
#endif
logInfo("\n");
return S7ExitCodeSuccess;
}

Expand Down
2 changes: 2 additions & 0 deletions system7/Utils/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ int saveUpdatedConfigToMainAndControlFile(S7Config *updatedConfig);

NSString *_Nullable getGlobalGitConfigValue(NSString *key);

BOOL S7ArgumentMatchesFlag(NSString *argument, NSString *longFlag, NSString *shortFlag);

#define S7_REPO_PRECONDITION_CHECK() \
do { \
const int result = s7RepoPreconditionCheck(); \
Expand Down
6 changes: 6 additions & 0 deletions system7/Utils/Utils.m
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,9 @@ int installHook(GitRepository *repo, NSString *hookName, NSString *commandLine,

return S7ExitCodeSuccess;
}

BOOL S7ArgumentMatchesFlag(NSString *argument, NSString *longFlag, NSString *shortFlag) {
argument = [argument stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"-"]];

return [argument isEqualToString:shortFlag] || [argument isEqualToString:longFlag];
}
6 changes: 5 additions & 1 deletion system7/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,14 @@ int main(int argc, const char * argv[]) {
[arguments addObject:argument];
}

if ([commandName isEqualToString:@"help"]) {
if (S7ArgumentMatchesFlag(commandName, @"help", @"h")) {
return helpCommand(arguments);
}

if (S7ArgumentMatchesFlag(commandName, @"version", @"v")) {
return [[S7VersionCommand new] runWithArguments:@[]];
}

NSString *cwd = [[NSFileManager defaultManager] currentDirectoryPath];
BOOL isDirectory = NO;
if (NO == [[NSFileManager defaultManager] fileExistsAtPath:[cwd stringByAppendingPathComponent:@".git"] isDirectory:&isDirectory] || NO == isDirectory) {
Expand Down

0 comments on commit c777809

Please sign in to comment.