forked from cms-sw/cmsdist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cms-common.spec
260 lines (219 loc) · 7.04 KB
/
cms-common.spec
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
### RPM cms cms-common 1.0
## REVISION 1113
## NOCOMPILER
%define online %(case %cmsplatf in (*onl_*_*) echo true;; (*) echo false;; esac)
%if "%{?cmsroot:set}" != "set"
%define cmsroot %instroot
%endif
Source: cmsos
Source1: migrate-cvsroot
Source2: cmspm
%prep
#Make sure that we always build cms-common with a different revision and
#hardcoded version 1.0 because this is what bootstrap.sh is going to install
%if "%v" != "1.0"
echo "ERROR: Please do not change the version. We have to build this RPM with a different REVISION"
echo " Please update the revision in %n.spec and make sure that version is set to 1.0"
exit 1
%endif
%build
%install
#Create all files in %i/%{pkgrevision} directory.
mkdir -p %i/%{pkgrevision}/common
cd %i/%{pkgrevision}
cp %_sourcedir/cmsos ./common/cmsos
cp %_sourcedir/migrate-cvsroot ./common/migrate-cvsroot
cp %_sourcedir/cmspm ./common/cmspm
%if "%online" != "true"
cat << \EOF_CMSARCH_SH > ./common/cmsarch
#!/bin/sh
osarch=`%instroot/common/cmsos`
compilerv=gcc462
# We need to assume 1 compiler per platform.
# There is no other way around this.
if [ ! "$SCRAM_ARCH" ]
then
case $osarch in
osx104_ia32) compilerv=gcc401;;
osx104_ppc32) compilerv=gcc400;;
osx105_*) compilerv=gcc401;;
osx106_*) compilerv=gcc421;;
osx107_*) compilerv=gcc462;;
osx108_*) compilerv=gcc472;;
slc6_*) compilerv=gcc472; osarch=slc6_amd64;;
slc5_*) compilerv=gcc462; osarch=slc5_amd64;;
fc18_*) compilerv=gcc480; osarch=fc18_armv7hl;;
*) compilerv=gcc462; osarch=slc5_amd64;;
esac
echo ${osarch}_${compilerv}
else
echo $SCRAM_ARCH
fi
EOF_CMSARCH_SH
%else
cat << \EOF_CMSARCH_SH > ./common/cmsarch
#!/bin/sh
if [ ! "$SCRAM_ARCH" ] ; then
echo %cmsplatf
else
echo $SCRAM_ARCH
fi
EOF_CMSARCH_SH
%endif
### BASH code
cat << \EOF_CMSSET_DEFAULT_SH > ./cmsset_default.sh
export PATH=%instroot/common:%instroot/bin:$PATH
here=%{instroot}
if [ "$VO_CMS_SW_DIR" != "" ]
then
here=$VO_CMS_SW_DIR
else
if [ "$OSG_APP" != "" ]
then
here=$OSG_APP/cmssoft/cms
fi
fi
if [ ! $SCRAM_ARCH ]
then
SCRAM_ARCH=`%instroot/common/cmsarch`
if [ ! -d $here/${SCRAM_ARCH}/etc/profile.d ]
then
SCRAM_ARCH=%cmsplatf
fi
export SCRAM_ARCH
fi
if [ -d $here/${SCRAM_ARCH}/etc/profile.d ]
then
for pkg in `/bin/ls $here/${SCRAM_ARCH}/etc/profile.d/ | grep 'S.*[.]sh'`
do
source $here/${SCRAM_ARCH}/etc/profile.d/$pkg
done
fi
if [ ! $CMS_PATH ]
then
export CMS_PATH=$here
fi
# aliases
alias cmsenv='eval `scramv1 runtime -sh`'
alias cmsrel='scramv1 project CMSSW'
if [ -f $CMS_PATH/SITECONF/local/JobConfig/cmsset_local.sh ]; then
. $CMS_PATH/SITECONF/local/JobConfig/cmsset_local.sh
fi
if [ ! $CVSROOT ]
then
CVSROOT=:gserver:cmssw.cvs.cern.ch:/local/reps/CMSSW
export CVSROOT
fi
EOF_CMSSET_DEFAULT_SH
### CSH code
cat << \EOF_CMSSET_DEFAULT_CSH > ./cmsset_default.csh
if (${?PATH}) then
setenv PATH %instroot/common:%instroot/bin:$PATH
else
setenv PATH %instroot/common:%instroot/bin
endif
set here=%instroot
if ( ${?VO_CMS_SW_DIR} ) then
set here=$VO_CMS_SW_DIR
else
if ( ${?OSG_APP} ) then
set here=$OSG_APP/cmssoft/cms
endif
endif
if ( ! ${?SCRAM_ARCH}) then
setenv SCRAM_ARCH `sh -c %instroot/common/cmsarch`
if ( ! -d $here/${SCRAM_ARCH}/etc/profile.d ) then
setenv SCRAM_ARCH %cmsplatf
endif
endif
if ( -d $here/${SCRAM_ARCH}/etc/profile.d ) then
foreach pkg ( `/bin/ls ${here}/${SCRAM_ARCH}/etc/profile.d/ | grep 'S.*[.]csh'` )
source ${here}/${SCRAM_ARCH}/etc/profile.d/$pkg
end
endif
if ( ! ${?CMS_PATH} ) then
setenv CMS_PATH $here
endif
# aliases
alias cmsenv 'eval `scramv1 runtime -csh`'
alias cmsrel 'scramv1 project CMSSW'
if( -e $CMS_PATH/SITECONF/local/JobConfig/cmsset_local.csh ) then
source $CMS_PATH/SITECONF/local/JobConfig/cmsset_local.csh
endif
if ( ! ${?CVSROOT}) then
setenv CVSROOT :gserver:cmssw.cvs.cern.ch:/local/reps/CMSSW
endif
unset here
EOF_CMSSET_DEFAULT_CSH
cat << \EOF_COMMON_SCRAM > ./common/scram
#!/bin/sh
export SCRAM_ARCH=`%instroot/common/cmsarch`
srbase=%{instroot}/$SCRAM_ARCH
sver=$SCRAM_VERSION
dir=`/bin/pwd`
if [ "X${dir}" = "X" ] ; then
echo "Unable to find current working directory, may be directory was deleted." >&2
exit 1
fi
while [ ! -d ${dir}/.SCRAM ] && [ "$dir" != "/" ] ; do
dir=`dirname $dir`
done
if [ "${dir}" != "/" ] && [ -f ${dir}/config/scram_version ] ; then
sver=`cat ${dir}/config/scram_version`
elif [ "X$sver" = "X" ] ; then
if [ -f %{instroot}/share/etc/default-scramv1-version ] ; then
sver=`cat %{instroot}/share/etc/default-scramv1-version`
elif [ -f ${srbase}/etc/default-scramv1-version ] ; then
sver=`cat ${srbase}/etc/default-scramv1-version`
else
echo "Error: Unable to find ${srbase}/etc/default-scramv1-version. Looks like SCRAMV1 is not installed." >&2
exit 1
fi
fi
scram_rel_series=`echo $sver | grep '^V[0-9][0-9]*_[0-9][0-9]*_[0-9][0-9]*' | sed 's|^\(V[0-9][0-9]*_[0-9][0-9]*\)_.*|\1|'`
scram_main_series=`echo $scram_rel_series | sed 's|_.*||'`
if [ "X${scram_rel_series}" != "X" ] ; then
if [ -f %{instroot}/share/etc/default-scram/${scram_main_series} ] ; then
sver=`cat %{instroot}/share/etc/default-scram/${scram_main_series}`
srbase=%{instroot}/share
elif [ -f %{instroot}/share/etc/default-scram/${scram_rel_series} ] ; then
sver=`cat %{instroot}/share/etc/default-scram/${scram_rel_series}`
srbase=%{instroot}/share
elif [ -f ${srbase}/etc/default-scram/${scram_main_series} ] ; then
sver=`cat ${srbase}/etc/default-scram/${scram_main_series}`
elif [ -f ${srbase}/etc/default-scram/${scram_rel_series} ] ; then
sver=`cat ${srbase}/etc/default-scram/${scram_rel_series}`
fi
fi
srbase=${srbase}/lcg/SCRAMV1/${sver}
if [ ! -f ${srbase}/etc/profile.d/init.sh ] ; then
echo "Unable to find SCRAM version $sver for $SCRAM_ARCH architecture." >&2
exit 1
fi
. ${srbase}/etc/profile.d/init.sh
${srbase}/bin/scram $@
EOF_COMMON_SCRAM
find . -name "*" -type f | xargs chmod +x
%post
cd $RPM_INSTALL_PREFIX/%{pkgrel}/%{pkgrevision}
%{relocateCmsFiles} `find . -name "*" -type f`
mkdir -p $RPM_INSTALL_PREFIX/common $RPM_INSTALL_PREFIX/bin $RPM_INSTALL_PREFIX/etc/%{pkgname} $RPM_INSTALL_PREFIX/%{cmsplatf}/etc/profile.d
#Check if a newer revision is already installed
#Also force installation if older revision has deleted cmsset_default.sh
if [ -f $RPM_INSTALL_PREFIX/cmsset_default.csh ] && [ -f $RPM_INSTALL_PREFIX/etc/%{pkgname}/revision ] ; then
oldrev=`cat $RPM_INSTALL_PREFIX/etc/%{pkgname}/revision`
if [ $oldrev -ge %{pkgrevision} ] ; then
exit 0
fi
fi
for file in `find . -name "*" -type f`; do
rm -f $RPM_INSTALL_PREFIX/$file
cp $file $RPM_INSTALL_PREFIX/$file
done
cd $RPM_INSTALL_PREFIX
rm -f common/scramv1; ln -s scram common/scramv1
rm -f common/scramv0; ln -s scram common/scramv0
rm -f bin/cmsarch; ln -s ../common/cmsarch bin/cmsarch
rm -f bin/cmsos; ln -s ../common/cmsarch bin/cmsos
rm -f bin/scramv1; ln -s ../common/scramv1 bin/scramv1
echo %{pkgrevision} > etc/%{pkgname}/revision