-
Notifications
You must be signed in to change notification settings - Fork 24
/
cmsBuild_consts.py
310 lines (283 loc) · 10.5 KB
/
cmsBuild_consts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
from sys import platform
REFERENCE_PACKAGE_POST = """
%%prep
%%build
%%install
%%postun
rm -rf "$RPM_INSTALL_PREFIX/%(pkgdir)s"
%%description
No description
%%files
%%post
PKG="%(pkgdir)s"
REF="%(refroot)s"
DIR="%(cmsroot)s"
if [ ! -e "$REF/$PKG" ] ; then exit 0 ; fi
mkdir -p "$DIR/$PKG"
SCRAM_PROJECT=false
if [ -d "$REF/$PKG/.SCRAM" ] ; then SCRAM_PROJECT=true ; fi
for d in $(find "$REF/$PKG" -maxdepth 1 -mindepth 1 | sed 's|.*/||') ; do
if [ "$d" = "etc" ] && [ -e "$REF/$PKG/etc/profile.d" ] ; then
mkdir "$DIR/$PKG/$d"
for sd in $(find "$REF/$PKG/$d" -maxdepth 1 -mindepth 1 | sed 's|.*/||') ; do
if [ "$sd" = "profile.d" ] && [ -e "$REF/$PKG/$d/$sd/init.sh" ] ; then
rsync -a "$REF/$PKG/$d/$sd/" "$DIR/$PKG/$d/$sd/"
elif [ "$sd" = "scram.d" ] ; then
rsync -a "$REF/$PKG/$d/$sd/" "$DIR/$PKG/$d/$sd/"
else
ln -s "$REF/$PKG/$d/$sd" "$DIR/$PKG/$d/$sd"
fi
done
elif [ "$d" = "tools" ] && [ -d "$REF/$PKG/$d/selected" ] ; then
rsync -a "$REF/$PKG/$d/" "$DIR/$PKG/$d/"
elif [ "$SCRAM_PROJECT" = "true" ] && [ "$d" = ".SCRAM" ] ; then
rsync -a "$REF/$PKG/$d/" "$DIR/$PKG/$d/"
elif [ "$SCRAM_PROJECT" = "true" ] && [ "$d" = "config" ] ; then
rsync -a "$REF/$PKG/$d/" "$DIR/$PKG/$d/"
else
ln -s $REF/$PKG/$d $DIR/$PKG/$d
fi
done
find $DIR/$PKG -type f | xargs --no-run-if-empty chmod +w
if [ "$SCRAM_PROJECT" = "true" ] ; then
chmod -R +w "$DIR/$PKG/.SCRAM" "$DIR/$PKG/config"
$DIR/$PKG/config/SCRAM/projectAreaRename.pl "$REF" "$DIR" %(cmsplatf)s "$DIR/$PKG"
fi
find $DIR/$PKG -type f | xargs --no-run-if-empty grep -Il '%(refroot)s' | xargs -n1 --no-run-if-empty perl -p -i -e "s|\\Q%(refroot)s\\E|$DIR|g"
"""
# Macros for creating git repo out of sources and applying patches
PATCH_SOURCE_MACROS = """
%define package_init_source if [ ! -d .git ] ; then git init && git add . && git commit -a -m 'init repo' && _PKGTOOLS_PKG_BASE_DIR=`/bin/pwd` && PKGTOOLS_PATCH_NUM=0 ; fi
%define package_commit_patch let PKGTOOLS_PATCH_NUM=$PKGTOOLS_PATCH_NUM+1 && git add . && [ $(git diff --name-only HEAD | wc -l) -gt 0 ] && git commit -a -m "applying patch ${PKGTOOLS_PATCH_NUM}"
%define package_final_source if [ "X${_PKGTOOLS_PKG_BASE_DIR}" != "X" ] ; then mv ${_PKGTOOLS_PKG_BASE_DIR}/.git %{_builddir}/pkgtools-pkg-src-move2git ; fi
"""
# FIXME: write a more valuable description
DEFAULT_SECTIONS = {"": """
""",
"%%description": """
No description
""",
"%prep": """
%%setup -n %n-%realversion
""",
"%build": """
%initenv
./configure --prefix=%i
make
""",
"%install": """
%initenv
make install
""",
"%pre": """
if [ X"$(id -u)" = X0 ]; then
if [ ! -f /etc/cms-root-install-allowed ]; then
echo "*** CMS SOFTWARE INSTALLATION ABORTED ***"
echo "CMS software cannot be installed as the super-user."
echo "(We recommend reading a unix security guide)."
exit 1
fi
fi
""",
"%post": """
if [ "X$CMS_INSTALL_PREFIX" = "X" ] ; then CMS_INSTALL_PREFIX=$RPM_INSTALL_PREFIX; export CMS_INSTALL_PREFIX; fi
%{relocateConfig}etc/profile.d/init.sh
%{relocateConfig}etc/profile.d/init.csh
""",
"%preun": """
""",
"%postun": """
if [ "X$CMS_INSTALL_PREFIX" = "X" ] ; then CMS_INSTALL_PREFIX=$RPM_INSTALL_PREFIX; export CMS_INSTALL_PREFIX; fi
""",
"%files": """
%{i}/
%dir %{instroot}/
%dir %{instroot}/%{cmsplatf}/
%dir %{instroot}/%{cmsplatf}/%{pkgcategory}/
%dir %{instroot}/%{cmsplatf}/%{pkgcategory}/%{pkgname}/
"""}
COMPILER_DETECTION = { "gcc": "gcc -v 2>&1 | grep version | sed -e \'s|.*\\([0-9][.][0-9][.][0-9]\\).*|\\1|\'",
"icc": "echo no detection callback for icc."}
SYS_COMPILER_DETECTION = { "gcc": "gcc -v 2>&1 | grep \'\sversion\s\' | sed -e \'s|.*\sversion\s\s*\([1-9][0-9]*[.][0-9]*[.][0-9]*\).*|\\1|\'",
"icc": "echo no detection callback for icc."}
# Preambles. %dynamic_path_var is defined in rpm-preamble.
INITENV_PREAMBLE = [
("CMD_SH", "if", "[ -f %i/etc/profile.d/dependencies-setup.sh ]; then . %i/etc/profile.d/dependencies-setup.sh; fi"),
("CMD_CSH", "if", "( -f %i/etc/profile.d/dependencies-setup.csh ) source %i/etc/profile.d/dependencies-setup.csh; endif"),
("SETV", "%(uppername)s_ROOT", "%i"),
("SETV", "%(uppername)s_VERSION", "%v"),
("SETV", "%(uppername)s_REVISION", "%pkgrevision"),
("SETV", "%(uppername)s_CATEGORY", "%pkgcategory"),
("+PATH", "PATH", "%i/bin"),
("+PATH", "%%{dynamic_path_var}", "%i/lib")]
RUNPATH_ENV = {
"START_SH": '',
"START_CSH": 'if (! $?_CMSBUILD_BUILD_ENV_) setenv _CMSBUILD_BUILD_ENV_ ""\n',
"END_SH": '',
"END_CSH": '',
"PRE_SH": 'if [ "${_CMSBUILD_BUILD_ENV_}" != "" ] ; then\n',
"POST_SH": 'fi\n',
"PRE_CSH": 'if ( ${%_CMSBUILD_BUILD_ENV_} != 0 ) then\n',
"POST_CSH": 'endif\n'
}
DEFAULT_PREAMBLE = """
"""
if platform == 'darwin' : DEFAULT_PREAMBLE = """
AutoReqProv: no
"""
DEFAULT_DESCRIPTION_PREAMBLE = """
"""
DEFAULT_PREP_PREAMBLE = """
%initenv
[ -d %i ] && chmod -R u+w %i
rm -fr %i
"""
DEFAULT_BUILD_PREAMBLE = """
%initenv
"""
DEFAULT_INSTALL_PREABLE = """
mkdir -p %i
mkdir -p %_rpmdir
mkdir -p %_srcrpmdir
%initenv
"""
DEFAULT_PRE_PREAMBLE = """
if [ X"$(id -u)" = X0 ]; then
echo "*** CMS SOFTWARE INSTALLATION ABORTED ***"
echo "CMS software cannot be installed as the super-user."
echo "(We recommend reading a unix security guide)."
exit 1
fi
"""
DEFAULT_POST_PREAMBLE = """
if [ "X$CMS_INSTALL_PREFIX" = "X" ] ; then CMS_INSTALL_PREFIX=$RPM_INSTALL_PREFIX; export CMS_INSTALL_PREFIX; fi
%{relocateConfig}etc/profile.d/init.sh
%{relocateConfig}etc/profile.d/init.csh
"""
DEFAULT_PREUN_PREAMBLE = """
"""
DEFAULT_POSTUN_PREAMBLE = """
if [ "X$CMS_INSTALL_PREFIX" = "X" ] ; then CMS_INSTALL_PREFIX=$RPM_INSTALL_PREFIX; export CMS_INSTALL_PREFIX; fi
"""
DEFAULT_FILES_PREAMBLE = """
%%defattr(-, root, root)
"""
DEFAULT_RPATH_PREAMBLE_INSTALL = "\n%{?runpath_install:%runpath_install}\n"
DEFAULT_RPATH_PREAMBLE_POST = "\n%{?runpath_post:%runpath_post}\n"
COMMANDS_SH = {"SETV": """%(var)s="%(value)s"\n""",
"SET": """export %(var)s="%(value)s";\n""",
"+PATH": """[ ! -d %(value)s ] || export %(var)s="%(value)s${%(var)s:+:$%(var)s}";\n""",
"UNSET": """unset %(var)s || true\n""",
"CMD": """%(var)s %(value)s\n""",
"CMD_SH": """%(var)s %(value)s\n""",
"CMD_CSH": "",
"ALIAS": """alias %(var)s="%(value)s"\n""",
"ALIAS_CSH": "",
"ALIAS_SH": """alias %(var)s="%(value)s"\n"""}
COMMANDS_CSH = {"SETV": """set %(var)s="%(value)s"\n""",
"SET": """setenv %(var)s "%(value)s"\n""",
"+PATH": """if ( -d %(value)s ) then\n"""
""" if ( ${?%(var)s} ) then\n"""
""" setenv %(var)s "%(value)s:$%(var)s"\n"""
""" else\n"""
""" setenv %(var)s "%(value)s"\n"""
""" endif\n"""
"""endif\n""",
"UNSET": """unset %(var)s || true\n""",
"CMD": """%(var)s %(value)s\n""",
"CMD_SH": "",
"CMD_CSH": """%(var)s %(value)s\n""",
"ALIAS": """alias %(var)s "%(value)s"\n""",
"ALIAS_SH": "",
"ALIAS_CSH":"""alias %(var)s "%(value)s"\n"""}
SPEC_REFERENCE_REPO = """
%%define relocateReference find %%{instroot} -type f | xargs --no-run-if-empty grep -Il '%(reference_repo)s' | xargs -n1 --no-run-if-empty perl -p -i -e "s|\\\\Q%(reference_repo)s\\\\E|%%{cmsroot}|g;"
"""
SPEC_HEADER = """
%%define pkgname %(name)s
%%define pkgversion %(version)s
%%define pkgcategory %(group)s
%%define cmsroot %(workDir)s
%%define instroot %(workDir)s/%(tempDirPrefix)s/BUILDROOT/%(checksum)s%(installDir)s
%%define realversion %(realVersion)s
%%define gccver %(compilerRealVersion)s
%%define compilerRealVersion %(compilerRealVersion)s
%%define pkgrevision %(pkgRevision)s
%%define pkgreqs %(pkgreqs)s
%%define directpkgreqs %(directpkgreqs)s
%%define specchecksum %(checksum)s
%%define cmscompiler %(compilerName)s
%%define cmsbuildApiVersion 1
%%define installroot %(installDir)s
%%define tempprefix %(tempDirPrefix)s
Name: %(group)s+%(name)s+%(version)s
Group: %(group)s
Version: %(rpmVersion)s
Release: %(pkgRevision)s
License: "As required by the orginal provider of the software."
Summary: %(summary)s SpecChecksum:%(checksum)s
%(requiresStatement)s
Packager: CMS <[email protected]>
Distribution: CMS
Vendor: CMS
Provides: %(group)s+%(name)s+%(version)s
Obsoletes: %(group)s+%(name)s+%(version)s
Prefix: %(installDir)s
"""
DEFAULT_INSTALL_POSTAMBLE="""
# Avoid pkgconfig dependency. Notice you still need to keep the rm statement
# to support architectures not being build with cmsBuild > V00-19-XX
%if "%{?keep_pkgconfig:set}" != "set"
if [ -d "%i/lib/pkgconfig" ]; then rm -rf %i/lib/pkgconfig; fi
%endif
# Do not package libtool and archive libraries, unless required.
%if "%{?keep_archives:set}" != "set"
# Don't need archive libraries.
rm -f %i/lib/*.{l,}a
%endif
# Strip executable / paths which were specified in the strip_files macro.
%if "%{?strip_files:set}" == "set"
for x in %strip_files
do
if [ -e $x ]
then
find $x -type f -perm -a+x -exec %strip {} \;
fi
done
%endif
# remove files / directories which were specified by the drop_files macro.
%if "%{?drop_files:set}" == "set"
for x in %drop_files
do
if [ -e $x ]; then rm -rf $x; fi
done
%endif
case %{cmsplatf} in
osx* )
for x in `find %{i} -type f -perm -u+x | grep -v -e "[.]pyc"`;
do
if [ "X`file --mime $x | sed -e 's| ||g' | cut -d: -f2 | cut -d\; -f1`" = Xapplication/octet-stream ]
then
chmod +w $x
old_install_name=`otool -D $x | tail -1 | sed -e's|:$||'`
new_install_name=`basename $old_install_name`
install_name_tool -change $old_install_name $new_install_name -id $new_install_name $x
# Make sure also dependencies do not have an hardcoded path.
for dep in `otool -L $x | sed -e"s|[^\\t\\s ]*%{instroot}|%{instroot}|" | grep -e '^/' | sed -e's|(.*||'`
do
install_name_tool -change $dep `basename $dep` $x
done
chmod -w $x
fi
done
;;
* )
;;
esac
"""
DEFAULT_PREP_POSTAMBLE="""
"""
DEFAULT_BUILD_POSTAMBLE="""
# make sure that at least an empty file list does exist
touch %_builddir/files
"""