Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 151 lines (129 sloc) 3.916 kB
22b433a @fperrin Don't assume that bash is in /bin
fperrin authored
1 #!/usr/bin/env bash
2
3 set -e
4 set -u
607c286 [feature] compiler option: --minimal-version for Makefile
Mathieu Barbin authored
5 # Copyright © 2011 MLstate
fccc685 Initial open-source release
MLstate authored
6
607c286 [feature] compiler option: --minimal-version for Makefile
Mathieu Barbin authored
7 # This file is part of OPA.
8
9 # OPA is free software: you can redistribute it and/or modify it under the
10 # terms of the GNU Affero General Public License, version 3, as published by
11 # the Free Software Foundation.
12
13 # OPA is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
16 # more details.
17
18 # You should have received a copy of the GNU Affero General Public License
19 # along with OPA. If not, see <http://www.gnu.org/licenses/>.
fccc685 Initial open-source release
MLstate authored
20
21 # This script is used to generate the module BuildInfos
22 # it is called by bld at build time of the repositories.
23 # Since this module is very high regarding to the dependencies
24 # it is regenerated only in release mode, or after a clean.
607c286 [feature] compiler option: --minimal-version for Makefile
Mathieu Barbin authored
25
26 MLSTATE_DIFFING=${MLSTATE_DIFFING:-"0"}
27
fccc685 Initial open-source release
MLstate authored
28 help () {
29 cat <<EOF
30 generating buildInfos.ml
31 Use:
32 $0 opageneral-dir [options]
33 Options:
34 --version file.txt precise the file to read the name of opa version
35 --release release mode
36 EOF
37 }
38
39 OPA_VERSION="S?"
40 ROOTDIR=""
41 IS_RELEASE="false"
42
43 if [ -z "$1" ]; then
44 help
45 echo "opageneral-dir is not specified"
46 exit 1
47 else
48 ROOTDIR="$1"
49 shift
50 fi
51
52 while [ "$#" -gt 0 ]; do
53 case "$1" in
54 -h|--help|help)
55 help
56 exit 0
57 ;;
58 --release)
59 IS_RELEASE="true"
60 ;;
61 --version)
62 if [ -z "$2" ]; then echo "Error: option $1 requires an argument"; exit 1; fi
63 shift;
64 OPA_VERSION="$(cat $1)"
65 ;;
66 *)
67 help
68 exit 1
69 ;;
70 esac
71 shift
72 done
73
74 ROOT_REPO="opalang"
75 REPOS="$ROOT_REPO"
76 PATH_TO_REPOS="repos"
77
78 git_version_cmd () { git log --pretty=oneline | wc -l; }
79 git_sha_cmd () { git log -n1 --pretty=format:%h; }
80 git_date_cmd () { git log -n1 --pretty=format:%ad --date=short; }
81
607c286 [feature] compiler option: --minimal-version for Makefile
Mathieu Barbin authored
82 # special case for opalang, the origin is the publication
83 git_opalang_version_cmd () {
84 local ORIGIN_SHA='fccc6851ccd2cb4fd9e83ba7b8c8d6d780ed3e13'
ec1c23d [fix] release: build version was taged with an offset of 1 between op…
Louis Gesbert authored
85 git log --pretty=oneline "$ORIGIN_SHA".. | awk '/^'$ORIGIN_SHA'/ { x=1 } END { print NR+1-x }'
607c286 [feature] compiler option: --minimal-version for Makefile
Mathieu Barbin authored
86 }
87
fccc685 Initial open-source release
MLstate authored
88 is_git_root () {
89 LOOKED_FOR_REPO=$1
90 [ -d .git ] && git remote show -n origin | grep -q 'URL:.*'$LOOKED_FOR_REPO
91 }
92
93 in_repo () {
94 REPO=$1; shift
95 P=$PWD
96 cd $ROOTDIR
97 if [ "$REPO" != "$ROOT_REPO" ]; then
98 cd $PATH_TO_REPOS/$REPO
99 fi
100 if ! is_git_root $REPO; then
101 echo "[!] Git repo info for $REPO not found" >&2; exit 1
102 fi
103 "$@"
104 cd $P
105 }
106
107 if [ "$MLSTATE_DIFFING" = 1 ] ; then
108 cat <<EOF
109 (*
110 The following informations are not correct, because the toggle var
111 MLSTATE_DIFFING was set during the generation of this file.
112 This debug var is meant to reduce as much as possible the output
113 of the compiler for comparing 2 branches.
114 *)
115 EOF
116 fi
117
118 # opa version
119 echo "let opa_version_name = \"${OPA_VERSION}\""
120
121 # git infos
122 for repo in $REPOS ; do
123 if [ "$MLSTATE_DIFFING" = 1 ] ; then
124 echo "let ${repo}_git_version = 0"
125 echo "let ${repo}_git_sha = \"diffing\""
0b2b4ab @shadinger [fix] build: Allows for correct compilation even if no GIT repository…
shadinger authored
126 elif ! is_git_root $repo; then
127 echo "let ${repo}_git_version = 0"
128 echo "let ${repo}_git_sha = \"\""
fccc685 Initial open-source release
MLstate authored
129 else
607c286 [feature] compiler option: --minimal-version for Makefile
Mathieu Barbin authored
130 if [ "$repo" = "$ROOT_REPO" ] ; then
131 echo "let ${repo}_git_version = $(in_repo $repo git_opalang_version_cmd)"
132 else
133 echo "let ${repo}_git_version = $(in_repo $repo git_version_cmd)"
134 fi
fccc685 Initial open-source release
MLstate authored
135 echo "let ${repo}_git_sha = \"$(in_repo $repo git_sha_cmd)\""
136 fi
137 done
138 echo
139
140 # date
141 if [ "$MLSTATE_DIFFING" = 1 ] ; then
142 echo "let date = \"diffing\""
143 echo "let year = \"diffing\""
144 else
145 echo "let date = \"$(in_repo $ROOT_REPO git_date_cmd)\""
146 echo "let year = \"$(date +%Y)\""
147 fi
148
149 # release
150 echo "let is_release = $IS_RELEASE"
Something went wrong with that request. Please try again.