forked from cms-sw/cmssw-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateConfig.pl
executable file
·170 lines (154 loc) · 4.87 KB
/
updateConfig.pl
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
#!/usr/bin/env perl
use File::Basename;
use Getopt::Long;
if(&GetOptions(
"--project=s",\$project,
"--version=s",\$version,
"--scram=s",\$scram,
"--toolbox=s",\$toolbox,
"--config=s",\$config,
"--keys=s",\%keys,
"--arch=s",\$arch,
"--help",\$help,
) eq ""){print "ERROR: Wrong arguments.\n"; &usage_msg(1);}
if(defined $help){&usage_msg(0);}
if((!defined $project) || ($project=~/^\s*$/)){die "Missing or empty project name.";}
else{$project=uc($project);}
if((!defined $version) || ($version=~/^\s*$/)){die "Missing or empty project version.";}
if((!defined $scram) || ($scram=~/^\s*$/)){die "Missing or empty scram version.";}
if((!defined $toolbox) || ($toolbox=~/^\s*$/)){die "Missing or empty SCRAM tool box path.";}
my $tooldir="configurations";
if($scram=~/^V[2-9]/){$tooldir="tools";}
if(!-d "${toolbox}/${tooldir}"){die "Wrong toolbox directory. Missing directory ${toolbox}/${tooldir}.";}
my $dir="";
if((!defined $config) || ($config=~/^\s*$/))
{
$dir=dirname($0);
if($dir!~/^\//){use Cwd;$dir=getcwd()."/${dir}";}
$dir=&fixPath($dir);
if($dir=~/^(.+)\/config$/){$config=$1;}
else{die "Missing config directory path which needs to be updated.";}
}
$dir="${config}/config";
if ((!defined $arch) || ($arch eq ""))
{
if (!exists $ENV{SCRAM_ARCH}){$arch=`scram arch`; chomp $arch;}
else{$arch=$ENV{SCRAM_ARCH};}
}
$ENV{SCRAM_ARCH}=$arch;
my %cache=();
foreach my $f ("bootsrc","BuildFile","Self","SCRAM_ExtraBuildRule","boot"){$cache{SCRAMFILES}{$f}=1;}
$cache{KEYS}{PROJECT_NAME}=$project;
$cache{KEYS}{PROJECT_VERSION}=$version;
$cache{KEYS}{PROJECT_TOOL_CONF}=$toolbox;
$cache{KEYS}{PROJECT_CONFIG_BASE}=$config;
$cache{KEYS}{SCRAM_VERSION}=$scram;
$cache{KEYS}{SCRAM_COMPILER}="gcc";
foreach my $k (keys %keys){$cache{KEYS}{$k}=$keys{$k};}
if (!exists $cache{KEYS}{PROJECT_GIT_HASH}){$cache{KEYS}{PROJECT_GIT_HASH}=$version;}
my $regexp="";
foreach my $k (keys %{$cache{KEYS}})
{
my $v=$cache{KEYS}{$k};
$regexp.="s|\@$k\@|$v|g;";
}
foreach my $k (keys %{$cache{EXKEYS}})
{
my $xk=$k;
foreach my $a (keys %{$cache{EXKEYS}{$k}})
{
if($arch=~/^$a/)
{
$xk=$cache{EXKEYS}{$k}{$a};
last;
}
}
$regexp.="s|\@$k\@|$xk|g;";
}
opendir(DIR,$dir) || die "Can not open directory for reading: $dir";
foreach my $file (readdir(DIR))
{
if($file=~/^CVS$/){next;}
if($file=~/^\./){next;}
my $fpath="${dir}/${file}";
if((!-e $fpath) || (-d $fpath) || (-l $fpath)){next;}
if($file=~/^${project}_(.+)$/){system("mv $fpath ${dir}/${1}");}
}
closedir(DIR);
foreach my $type (keys %{$cache{SCRAMFILES}}){system("touch ${dir}/XXX_${type}; rm -f ${dir}/*_${type}*");}
system("find $dir -name \"*\" -type f | xargs sed -i.backup$$ -e '".$regexp."'");
system("find $dir -name \"*.backup$$\" -type f | xargs rm -f");
system("rm -rf ${dir}/site; echo $scram > ${dir}/scram_version");
if ($replaceArch)
{
my $thisscript=basename($0);
$regexp="";
foreach my $k (keys %{$cache{REPLACE}{$replaceArch}})
{
my $v=$cache{REPLACE}{$replaceArch};
$regexp.="s|\@$k\@|$v|g;";
}
foreach my $f (`find $dir -name "*" -type f`)
{
chomp $f;
if ($f=~/\/${thisscript}$/){next;}
system("sed -i -e '".$regexp."' $f");
}
}
sub usage_msg()
{
my $code=shift || 0;
print "$0 --project <name> --version <version> --scram <scram version>\n",
" --toolbox <toolbox> [--config <dir>] [--arch <arch>] [--help]\n\n",
" This script will copy all <name>_<files> files into <files>\n",
" and replace project names, version, scram verion, toolbox path",
" and extra keys/values provided via the command line. e.g.\n",
" $0 -p CMSSW -v CMSSW_4_5_6 -s V1_2_0 -t /path/cmssw-tool-conf/CMS170 --keys MYSTRING1=MYVALUE1 --keys MYSTRING2=MYVALUE2\n",
" will release\n",
" \@PROJECT_NAME\@=CMSSW\n",
" \@PROJECT_VERSION\@=CMSSW_4_5_6\n",
" \@SCRAM_VERSION\@=V1_2_0\n",
" \@PROJECT_TOOL_CONF\@=/path/cmssw-tool-conf/CMS170\n",
" \@MYSTRING1\@=MYVALUE1\n",
" \@MYSTRING2\@=MYVALUE2\n\n";
exit $code;
}
#############################################################
sub fixPath ()
{
my $dir=shift || return "";
my @parts=();
my $p="/";
if($dir!~/^\//){$p="";}
foreach my $part (split /\//, $dir)
{
if($part eq ".."){pop @parts;}
elsif(($part ne "") && ($part ne ".")){push @parts, $part;}
}
return "$p".join("/",@parts);
}
sub scramReleaseTop()
{return &checkWhileSubdirFound(shift,".SCRAM");}
sub checkWhileSubdirFound()
{
my $dir=shift;
my $subdir=shift;
while((!-d "${dir}/${subdir}") && ($dir ne "/")){$dir=dirname($dir);}
if(-d "${dir}/${subdir}"){return $dir;}
return "";
}
sub scramVersion ()
{
my $dir=shift;
my $ver="";
if (-f "${dir}/config/scram_version")
{
my $ref;
if(open($ref,"${dir}/config/scram_version"))
{
$ver=<$ref>; chomp $ver;
close($ref);
}
}
return $ver;
}