|
1 #!perl -w |
|
2 # Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of the License "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # MergeTwoEnvironments |
|
16 # |
|
17 |
|
18 use strict; |
|
19 use FindBin; |
|
20 use lib "$FindBin::Bin"; |
|
21 use RelData; |
|
22 use IniData; |
|
23 use MrpData; |
|
24 use EnvDb; |
|
25 use Getopt::Long; |
|
26 use Data::Dumper; |
|
27 use Utils; |
|
28 |
|
29 # Process command-line options |
|
30 Getopt::Long::Configure ("bundling"); |
|
31 my ($help, $verbose, $project, $releasenotes, $dummyrun, $internalver, $force); |
|
32 GetOptions("h" => \$help, "v+" => \$verbose, "w=s" => \$project, "r=s" => \$releasenotes, "d" => \$dummyrun, "i=s" => \$internalver, 'f' => \$force); |
|
33 $verbose ||= 0; |
|
34 $internalver ||= "-"; |
|
35 |
|
36 |
|
37 # Get the name and version of the new environment |
|
38 my ($newcomp, $newver, @argsleft) = @ARGV; |
|
39 print "Using \"$newcomp\" \"$newver\"\n" if ($verbose); |
|
40 |
|
41 # Eat up the environments to merge |
|
42 my @envstomerge; |
|
43 while (scalar @argsleft) { |
|
44 my ($oldcomp, $oldver, $prefix); |
|
45 ($oldcomp, $oldver, $prefix, @argsleft) = @argsleft; |
|
46 print "Adding \"$oldcomp\" \"$oldver\" prefix \"$prefix\"\n" if ($verbose); |
|
47 push @envstomerge, { |
|
48 comp => $oldcomp, |
|
49 ver => $oldver, |
|
50 prefix => $prefix |
|
51 }; |
|
52 die "You must provide a component, version and environment for each environment you want to merge" unless $oldcomp && $oldver && defined $prefix; |
|
53 # In fact, a blank (but defined) prefix might be worth having so we'll let them get away with that |
|
54 } |
|
55 |
|
56 print <<ENDHELP and exit if $help; |
|
57 Merges several environments into a new release. |
|
58 Usage: |
|
59 MergeEnvironments <options> newcomp newver {oldcomp oldver prefix} ... |
|
60 |
|
61 The {oldcomp oldver prefix} section must be repeated at least twice |
|
62 |
|
63 Options: |
|
64 |
|
65 -r <release.src> the release.src file to use (mandatory) |
|
66 -h show this help |
|
67 -w <project> make the reldata in this project |
|
68 -v verbose |
|
69 -f (deprecated) |
|
70 -d dummy run (just report the environment to be produced) |
|
71 -i <ver> internal version number of the release we're creating |
|
72 ENDHELP |
|
73 |
|
74 die "You must specify a release notes file" unless $releasenotes; |
|
75 die "Release notes file \"$releasenotes\" doesn't exist" unless -e $releasenotes; |
|
76 |
|
77 ############################################################################## |
|
78 |
|
79 # Create objects that the Release Tools need |
|
80 my $iniData = New IniData; |
|
81 my $envDb = Open EnvDb($iniData); |
|
82 |
|
83 # The final environment we're going to use |
|
84 my %newenv; |
|
85 |
|
86 foreach my $mergeenv (@envstomerge) { |
|
87 my $env = ReadEnvironmentFromRelData($mergeenv->{comp}, $mergeenv->{ver}); |
|
88 my %copy = %$env; |
|
89 |
|
90 # Delete things according to the prefix |
|
91 foreach (keys %copy) { |
|
92 my $prefix = $mergeenv->{prefix}; |
|
93 delete $copy{$_} if ($copy{$_} !~ m/^$prefix/i); |
|
94 } |
|
95 |
|
96 %newenv = (%copy, %newenv); |
|
97 } |
|
98 |
|
99 # Finally make sure our new component itself is in the environment |
|
100 $newenv{$newcomp} = $newver; |
|
101 |
|
102 if ($verbose || $dummyrun) { |
|
103 print "Have combined the two environments. Results are:\n"; |
|
104 print Dumper(\%newenv); |
|
105 } |
|
106 |
|
107 CreateNewRelease($newcomp, $newver, \%newenv, $project) unless $dummyrun; |
|
108 |
|
109 exit; |
|
110 |
|
111 ############################################################################## |
|
112 sub ReadEnvironmentFromRelData { |
|
113 my $comp = shift; |
|
114 my $ver = shift; |
|
115 print "Reading environment from \"$comp\", \"$ver\"...\n" if ($verbose); |
|
116 my $rd = Open RelData($iniData, $comp, $ver, 2) or die "Couldn't open reldata for \"$comp\" \"$ver\""; |
|
117 return $rd->Environment; |
|
118 } |
|
119 |
|
120 sub CreateNewRelease { |
|
121 my $comp = shift; |
|
122 my $ver = shift; |
|
123 my $env = shift; |
|
124 my $project = shift; |
|
125 |
|
126 my $fakeMrpName = Utils::PrependEpocRoot("\\__reltools_tmp_mrp"); |
|
127 WriteFakeMrp($fakeMrpName, $comp, $releasenotes); |
|
128 |
|
129 my $mrpData = New MrpData($fakeMrpName, |
|
130 $ver, |
|
131 $internalver, |
|
132 $iniData, |
|
133 $verbose, # verbosity |
|
134 0); # fixLibs |
|
135 |
|
136 unlink($fakeMrpName); |
|
137 |
|
138 my $dir = $iniData->PathData->LocalArchivePathForNewComponent($comp, $ver, $project); |
|
139 print "Making directory \"$dir\"\n" if ($verbose); |
|
140 Utils::MakeDir($dir); |
|
141 print "Writing out reldata\n"; |
|
142 my $relData = New RelData($iniData, |
|
143 $mrpData, |
|
144 $releasenotes, |
|
145 $env, |
|
146 "MergeTwoEnvironments", |
|
147 $verbose, # verbosity |
|
148 undef, # dontPersist |
|
149 $project); |
|
150 print "$comp $ver created.\n"; |
|
151 } |
|
152 |
|
153 sub WriteFakeMrp { |
|
154 my $name = shift; |
|
155 my $comp = shift; |
|
156 my $relnotes = shift; |
|
157 open(FILE, ">$name") or die "Couldn't write to \"$name\" because $!"; |
|
158 print FILE "component $comp\nnotes_source $relnotes\n"; |
|
159 close FILE; |
|
160 } |
|
161 |
|
162 __END__ |
|
163 |
|
164 =head1 NAME |
|
165 |
|
166 MergeEnvironments - Merge the environments of several existing releases into a new release |
|
167 |
|
168 =head1 SYNOPSIS |
|
169 |
|
170 MergeEnvironments <options> newcomp newver {oldcomp oldver prefix} ... |
|
171 |
|
172 The {oldcomp oldver prefix} section must be repeated at least twice. |
|
173 |
|
174 Options: |
|
175 |
|
176 -r <release.src> the release.src file to use (mandatory) |
|
177 -h help |
|
178 -w <project> make the new release in this project (only applicable for new-style archive-path arrangements) |
|
179 -v verbose (-vv = very verbose) |
|
180 -f (deprecated) |
|
181 -d dummy run (just report the environment to be produced) |
|
182 -i <ver> internal version number of the release we're creating |
|
183 |
|
184 =head1 DESCRIPTION |
|
185 |
|
186 This tool will merge several environments to produce a new one. It reads the environment from two existing components, and produces another one. This new component just contains an environment; it has no binaries nor source. |
|
187 |
|
188 It is expected that you will then use C<validateenv> to validate against that environment. |
|
189 |
|
190 =head1 KNOWN BUGS |
|
191 |
|
192 Not really a defect, but it's limiting that you can only merge the environments based on the prefix of the version number. It would be nice to have more flexible criteria. |
|
193 |
|
194 The command line syntax is not intuitive. This may be fixed one day. |
|
195 |
|
196 But much more likely, the whole issue will go away with Release Tools 3, when validation will be substantially changed. |
|
197 |
|
198 =head1 STATUS |
|
199 |
|
200 Supported. If you find a problem, please report it to us. |
|
201 |
|
202 =head1 COPYRIGHT |
|
203 |
|
204 Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
205 All rights reserved. |
|
206 This component and the accompanying materials are made available |
|
207 under the terms of the License "Eclipse Public License v1.0" |
|
208 which accompanies this distribution, and is available |
|
209 at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
210 |
|
211 Initial Contributors: |
|
212 Nokia Corporation - initial contribution. |
|
213 |
|
214 Contributors: |
|
215 |
|
216 Description: |
|
217 |
|
218 |
|
219 =cut |