Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 163 lines (141 sloc) 4.198 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
990ce10 @Aqua-Ye [fix] git_version: should fix problem with opa version = 0
Aqua-Ye authored
90 P=`pwd`
91 # in case we are in another sub-dir, for instance _buuild...
92 cd $ROOTDIR
93 if [ "$LOOKED_FOR_REPO" != "$ROOT_REPO" ]; then
94 cd $PATH_TO_REPOS/$LOOKED_FOR_REPO
95 fi
96 if [ -d .git ] && git remote show -n origin | grep -q 'URL:.*'$LOOKED_FOR_REPO; then
97 cd $P
98 return 0
99 else
100 cd $P
101 return 1
102 fi
fccc685 Initial open-source release
MLstate authored
103 }
104
105 in_repo () {
106 REPO=$1; shift
107 P=$PWD
108 cd $ROOTDIR
109 if [ "$REPO" != "$ROOT_REPO" ]; then
110 cd $PATH_TO_REPOS/$REPO
111 fi
112 if ! is_git_root $REPO; then
113 echo "[!] Git repo info for $REPO not found" >&2; exit 1
114 fi
115 "$@"
116 cd $P
117 }
118
119 if [ "$MLSTATE_DIFFING" = 1 ] ; then
120 cat <<EOF
121 (*
122 The following informations are not correct, because the toggle var
123 MLSTATE_DIFFING was set during the generation of this file.
124 This debug var is meant to reduce as much as possible the output
125 of the compiler for comparing 2 branches.
126 *)
127 EOF
128 fi
129
130 # opa version
131 echo "let opa_version_name = \"${OPA_VERSION}\""
132
133 # git infos
134 for repo in $REPOS ; do
135 if [ "$MLSTATE_DIFFING" = 1 ] ; then
136 echo "let ${repo}_git_version = 0"
137 echo "let ${repo}_git_sha = \"diffing\""
0b2b4ab @shadinger [fix] build: Allows for correct compilation even if no GIT repository…
shadinger authored
138 elif ! is_git_root $repo; then
139 echo "let ${repo}_git_version = 0"
140 echo "let ${repo}_git_sha = \"\""
fccc685 Initial open-source release
MLstate authored
141 else
607c286 [feature] compiler option: --minimal-version for Makefile
Mathieu Barbin authored
142 if [ "$repo" = "$ROOT_REPO" ] ; then
143 echo "let ${repo}_git_version = $(in_repo $repo git_opalang_version_cmd)"
144 else
145 echo "let ${repo}_git_version = $(in_repo $repo git_version_cmd)"
146 fi
fccc685 Initial open-source release
MLstate authored
147 echo "let ${repo}_git_sha = \"$(in_repo $repo git_sha_cmd)\""
148 fi
149 done
150 echo
151
152 # date
153 if [ "$MLSTATE_DIFFING" = 1 ] ; then
154 echo "let date = \"diffing\""
155 echo "let year = \"diffing\""
156 else
157 echo "let date = \"$(in_repo $ROOT_REPO git_date_cmd)\""
158 echo "let year = \"$(date +%Y)\""
159 fi
160
161 # release
162 echo "let is_release = $IS_RELEASE"
Something went wrong with that request. Please try again.