From: Jean Privat Date: Sat, 21 May 2016 05:40:13 +0000 (-0400) Subject: Merge: src/platforms: fallback to version field "0" on error when asking for a git_re... X-Git-Url: http://nitlanguage.org?hp=c0bed41fb03af8de1dcdceacfb7895d3bf7ab6a2 Merge: src/platforms: fallback to version field "0" on error when asking for a git_revision The _app.nit_ annotation `version` sets the version of mobile app packages (.apk and .app). For example, `version(1, 5, git_revision)` may produce the version string "1.5.6b42a7c". This PR fixes an error when asking for a `git_revision` but the call to `git rev-parse` fails. Note that the normal git error is printed before the nitc warning message, so debugging should be easy. Close #2111 Pull-Request: #2113 Reviewed-by: Jean Privat --- diff --git a/src/platform/app_annotations.nit b/src/platform/app_annotations.nit index 62fbbb0..1d60f15 100644 --- a/src/platform/app_annotations.nit +++ b/src/platform/app_annotations.nit @@ -88,8 +88,6 @@ redef class AAnnotation return "" else for arg in args do - var format_error = "Syntax Eror: `{name}` expects its arguments to be of type Int or a call to `git_revision`." - var value value = arg.as_int if value != null then @@ -107,7 +105,13 @@ redef class AAnnotation # Get Git short revision var proc = new ProcessReader("git", "rev-parse", "--short", "HEAD") proc.wait - assert proc.status == 0 + if proc.status != 0 then + # Fallback if this is not a git repository or git bins are missing + version_fields.add "0" + modelbuilder.warning(self, "git_revision", "Warning: `git_revision` used outside of a git repository or git binaries not available") + continue + end + var lines = proc.read_all var revision = lines.split("\n").first @@ -122,6 +126,7 @@ redef class AAnnotation continue end + var format_error = "Syntax Error: `{name}` expects its arguments to be of type Int or a call to `git_revision`." modelbuilder.error(self, format_error) return "" end