calabash/calabash-ios-server — pull request #25 by jmoody (2013-09-01 10:44:33+00:00)
Title: adds git revision and branch information to output of server_output

#### Change

adds git branch and revision information to `server_version` route.

```
> server_version
{

"git branch" => "0.9.x-add-git-versioning-information",
"git revision" => "e1abd85",

}
```

#### Motivation

the `server_version` route does not provide enough information about what version of the server is installed on an .ipa.

* when developing features for the server where you might testing and developing several feature branches at once over several days
* when you are presented with a stand-alone ipa and you what to know exactly what features are available in the installed framework

#### Implementation

adds two Run Script build phases to calabash target:

1. Run Script - git versioning 1 of 2: runs before compile phase
2. Run Script - git versioning 2 of 2: runs after compile phase

the first script writes git branch and revision information to `calabash/LPGitVersionDefines.h` and the second script performs a `git co -- calabash/LPGitVersionDefines.h` to remove the changes.

in `LPVersionRoute.m`, i use preprocessor conditionals:

```
#ifdef LP_GIT_SHORT_REVISION
static NSString *const kLPGitShortRevision = LP_GIT_SHORT_REVISION;
#else
static NSString *const kLPGitShortRevision = @"Unknown";
#endif
```
to define static constants.

#### Notes

the second Run Script build phase is necessary because we don't what to track changes in this file:
* it changes for every commit
* if we tracked changes, there would always be conflicts in this file.

in iOS and MacOS projects, i use a versioning target and a preprocessed InfoPlist.h to cache this kind of information in my application Info.plist where it is available in the `NSBundle`. i tried a similar approach here, but i could get the Info.plist preprocessing step to work.

i experimented with adding a Bundle to the framework, but that would have required some changes to the `calabash-ios setup` proceedure (an additonal Copy Files build phase).

if a compilation fails, the second Run Script build phase will not be executed, so the `LPGitVersionDefines.h` will have untracked changes. i guard against this by regenerating the whole `LPGitVersionDefines.h` before compilation. you probably should not or won't be committing changes when a build does not compile. for an additional guard, i thought it might make sense to update the file index to `assume-unchanged`:

`git update-index --assume-unchanged calabash/LPGitVersionDefines.h`

but this is a little dangerous and potentially confusing to the uninitiated.