- # Get the date and time (down to the minute) as string
- var local_time = new Tm.localtime
- var local_time_s = local_time.strftime("%y%m%d%H%M")
- project.version_code = local_time_s.to_i
-
- toolcontext.check_errors
-
- return project
- end
-end
-
-redef class AAnnotation
- # Returns a version string (example: "1.5.6b42a7c") from an annotation `version(1, 5, git_revision)`.
- #
- # The user can enter as many fields as needed. The call to `git_revision` will be replaced by the short
- # revision number. If the working tree is dirty, it will append another field with "d" for dirty.
- private fun as_version(modelbuilder: ModelBuilder): String
- do
- var version_fields = new Array[Object]
-
- var args = n_args
- if args.length < 1 then
- modelbuilder.error(self, "Annotation error: \"{name}\" expects at least a single argument.")
- return ""
- else
- for arg in args do
- var format_error = "Annotation error: \"{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
- version_fields.add value
- continue
- end
-
- value = arg.as_string
- if value != null then
- version_fields.add value
- end
-
- value = arg.as_id
- if value == "git_revision" then
- # Get Git short revision
- var proc = new IProcess("git", "rev-parse", "--short", "HEAD")
- proc.wait
- assert proc.status == 0
- var lines = proc.read_all
- var revision = lines.split("\n").first
-
- # Is it dirty?
- # If not, the return of `git diff --shortstat` is an empty line
- proc = new IProcess("git", "diff-index", "--quiet", "HEAD")
- proc.wait
- var dirty = proc.status != 0
- if dirty then revision += ".d"
-
- version_fields.add revision
- continue
- end
-
- modelbuilder.error(self, format_error)
- return ""
- end