From: Jean Privat Date: Fri, 26 Jun 2009 04:55:52 +0000 (-0400) Subject: tools: generate version number and give it to tools X-Git-Tag: v0.3~208 X-Git-Url: http://nitlanguage.org tools: generate version number and give it to tools Signed-off-by: Jean Privat --- diff --git a/.gitignore b/.gitignore index 8b5a929..50ed558 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ src/parser/.nit.sablecc3 src/parser/.nit.sablecc3.dump src/parser/parser_abs.patch src/parser/parser_nodes.nit.rej +src/nit_version.nit c_src/*.o c_src/*.cksum diff --git a/Makefile b/Makefile index 6521d64..bb36721 100644 --- a/Makefile +++ b/Makefile @@ -24,12 +24,14 @@ bin/nitc: c_src/nitc src/parser/parser.nit @echo '***************************************************************' mkdir .nit_compile 2> /dev/null || true cp c_src/* .nit_compile + src/git-gen-version.sh c_src/nitc ${NITCOPT} -o bin/nitc -O src/nitc.nit bin/nitdoc: bin/nitc @echo '***************************************************************' @echo '* Compile nitdoc from NIT source files *' @echo '***************************************************************' + src/git-gen-version.sh bin/nitc ${NITCOPT} -o bin/nitdoc -O src/nitdoc.nit doc/stdlib/index.html: bin/nitdoc diff --git a/src/abstracttool.nit b/src/abstracttool.nit index 756117a..b03c827 100644 --- a/src/abstracttool.nit +++ b/src/abstracttool.nit @@ -21,6 +21,7 @@ package abstracttool import mmloader import syntax +import nit_version class AbstractCompiler special ToolContext @@ -40,6 +41,11 @@ special ToolContext do process_options + if opt_version.value then + print "{tool_name} version {nit_version}" + exit(0) + end + if opt_help.value then print "usage: {tool_name} [options] file..." option_context.usage diff --git a/src/git-gen-version.sh b/src/git-gen-version.sh new file mode 100755 index 0000000..601b2b2 --- /dev/null +++ b/src/git-gen-version.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2008 Jean Privat +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This program is used to generate version number from git refs. +# The version number is stored in a dedicated Nit module. + +gen_version() { +cat > nit_version.nit<&2 + exit 1 + fi +fi + +VN=$(git describe --tags --always HEAD) +if [ -z "$VN" ]; then + VN="undefined" +fi +if [ -n "$1" ]; then + VN="${VN}_$1" +fi +if [ -n "$(git diff HEAD)" ]; then + VN="${VN}_dirty" +fi + +gen_version "$VN" diff --git a/src/mmloader.nit b/src/mmloader.nit index 13adce2..6b44267 100644 --- a/src/mmloader.nit +++ b/src/mmloader.nit @@ -76,10 +76,13 @@ special MMContext # Option --help readable attr _opt_help: OptionBool = new OptionBool("Show Help (This screen)", "-h", "-?", "--help") + # Option --version + readable attr _opt_version: OptionBool = new OptionBool("Show version and exit", "--version") + init do super - option_context.add_option(opt_warn, opt_path, opt_log, opt_only_parse, opt_only_metamodel, opt_help) + option_context.add_option(opt_warn, opt_path, opt_log, opt_only_parse, opt_only_metamodel, opt_help, opt_version) end # Parse and process the options given on the command line diff --git a/src/nc b/src/nc index df75d19..8060070 100755 --- a/src/nc +++ b/src/nc @@ -29,6 +29,8 @@ case $name in *) echo "unknown mode $name"; exit 1;; esac +./git-gen-version.sh "$name" + echo ${NITC} ${NITCOPTS} ${opts} "$@" ${NITC} ${NITCOPTS} ${opts} "$@"