587
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 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 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.helium.imaker.ant.types;
|
628
|
19 |
import java.io.File;
|
|
20 |
import java.util.ArrayList;
|
|
21 |
import java.util.HashSet;
|
|
22 |
import java.util.List;
|
|
23 |
import java.util.Set;
|
|
24 |
import java.util.Vector;
|
|
25 |
import java.util.regex.Pattern;
|
|
26 |
|
587
|
27 |
import org.apache.tools.ant.BuildException;
|
|
28 |
import org.apache.tools.ant.DirectoryScanner;
|
|
29 |
import org.apache.tools.ant.Project;
|
|
30 |
import org.apache.tools.ant.types.DataType;
|
|
31 |
import org.apache.tools.ant.types.PatternSet;
|
|
32 |
|
|
33 |
import com.nokia.helium.imaker.IMaker;
|
|
34 |
import com.nokia.helium.imaker.IMakerException;
|
|
35 |
import com.nokia.helium.imaker.ant.Command;
|
|
36 |
import com.nokia.helium.imaker.ant.IMakerCommandSet;
|
|
37 |
|
|
38 |
/**
|
|
39 |
* The imakerconfiguration enables the build manager to configure his iMaker
|
|
40 |
* builds based on introspection.
|
|
41 |
*
|
|
42 |
* The makefileset element will configure the filtering of the "imaker help-config"
|
|
43 |
* command. Then for each of the configuration found the targetset elements will be used
|
|
44 |
* to filter the output from the "imaker -f <i>configuration.mk</i> help-target-*-list"
|
|
45 |
* command. Finally a set of command will be generated.
|
|
46 |
*
|
|
47 |
* Each command will then be configure using the set of variables defined by the variableset
|
|
48 |
* elements. Only the WORKDIR variable is under the task control to ensure call safety during the
|
|
49 |
* parallelization.
|
|
50 |
*
|
|
51 |
* The usage of the variablegroup will allow you to duplicate the common set of commands
|
|
52 |
* and apply additional variables.
|
|
53 |
*
|
|
54 |
* Example:
|
|
55 |
* <pre>
|
|
56 |
* <imakerconfiguration regionalVariation="true">
|
|
57 |
* <makefileset>
|
|
58 |
* <include name="**/product/*ui.mk"/>
|
|
59 |
* </makefileset>
|
|
60 |
* <targetset>
|
|
61 |
* <include name="^core$" />
|
|
62 |
* <include name="langpack_\d+" />
|
|
63 |
* <include name="^custvariant_.*$" />
|
|
64 |
* <include name="^udaerase$" />
|
|
65 |
* </targetset>
|
|
66 |
* <variableset>
|
|
67 |
* <variable name="USE_FOTI" value="0"/>
|
|
68 |
* <variable name="USE_FOTA" value="1"/>
|
|
69 |
* </variableset>
|
|
70 |
* <variablegroup>
|
|
71 |
* <variable name="TYPE" value="rnd"/>
|
|
72 |
* </variablegroup>
|
|
73 |
* <variablegroup>
|
|
74 |
* <variable name="TYPE" value="subcon"/>
|
|
75 |
* </variablegroup>
|
|
76 |
* </imakerconfiguration>
|
|
77 |
* </pre>
|
|
78 |
*
|
|
79 |
* This configuration might produce the following calls :
|
|
80 |
* <pre>
|
|
81 |
* imaker -f /epoc32/rom/config/platform/product/image_conf_product_ui.mk TYPE=rnd USE_FOTI=0 USE_FOTA=1 core
|
|
82 |
* imaker -f /epoc32/rom/config/platform/product/image_conf_product_ui.mk TYPE=subcon USE_FOTI=0 USE_FOTA=1 core
|
|
83 |
* imaker -f /epoc32/rom/config/platform/product/image_conf_product_ui.mk TYPE=rnd USE_FOTI=0 USE_FOTA=1 langpack_01
|
|
84 |
* imaker -f /epoc32/rom/config/platform/product/image_conf_product_ui.mk TYPE=subcon USE_FOTI=0 USE_FOTA=1 langpack_01
|
|
85 |
* </pre>
|
|
86 |
*
|
628
|
87 |
* Remember to update helium/sf/java/imaker/imaker.rst if you change this
|
|
88 |
*
|
587
|
89 |
* @ant.type name="imakerconfiguration" category="imaker"
|
|
90 |
*/
|
|
91 |
public class Configuration extends DataType implements IMakerCommandSet {
|
|
92 |
|
|
93 |
private Vector<PatternSet> makefiles = new Vector<PatternSet>();
|
|
94 |
private Vector<MakefileSelector> selectors = new Vector<MakefileSelector>();
|
|
95 |
private Vector<PatternSet> targets = new Vector<PatternSet>();
|
|
96 |
private Vector<VariableSet> variables = new Vector<VariableSet>();
|
|
97 |
private Vector<VariableGroup> variablegroups = new Vector<VariableGroup>();
|
|
98 |
private boolean regionalVariation;
|
|
99 |
|
|
100 |
/**
|
|
101 |
* Create a makefileset element.
|
|
102 |
* Makefileset elements are based on regular Ant PatternSet.
|
|
103 |
* @return a PatternSet object.
|
|
104 |
*/
|
|
105 |
public PatternSet createMakefileSet() {
|
|
106 |
PatternSet makefile = new PatternSet();
|
|
107 |
makefiles.add(makefile);
|
|
108 |
return makefile;
|
|
109 |
}
|
|
110 |
|
|
111 |
/**
|
|
112 |
* Get the list of makefileset element.
|
|
113 |
* @return a vector of PatternSet objects.
|
|
114 |
*/
|
|
115 |
public Vector<PatternSet> getMakefileSet() {
|
|
116 |
return makefiles;
|
|
117 |
}
|
|
118 |
|
|
119 |
/**
|
|
120 |
* Add a Makefile selector configuration (e.g: products)
|
|
121 |
* @param filter
|
|
122 |
*/
|
|
123 |
public void add(MakefileSelector filter) {
|
|
124 |
selectors.add(filter);
|
|
125 |
}
|
|
126 |
|
|
127 |
/**
|
|
128 |
* Create a targetset element.
|
|
129 |
* Targetset elements are based on regular Ant PatternSet.
|
|
130 |
* @return a PatternSet object.
|
|
131 |
*/
|
|
132 |
public PatternSet createTargetSet() {
|
|
133 |
PatternSet target = new PatternSet();
|
|
134 |
targets.add(target);
|
|
135 |
return target;
|
|
136 |
}
|
|
137 |
|
|
138 |
/**
|
|
139 |
* Get the list of targetset.
|
|
140 |
* @return a vector of PatternSet objects.
|
|
141 |
*/
|
|
142 |
public Vector<PatternSet> getTargetSet() {
|
|
143 |
return targets;
|
|
144 |
}
|
|
145 |
|
|
146 |
/**
|
|
147 |
* Create a VariableSet element.
|
|
148 |
* @return a VariableSet object.
|
|
149 |
*/
|
|
150 |
public VariableSet createVariableSet() {
|
|
151 |
VariableSet var = new VariableSet();
|
|
152 |
variables.add(var);
|
|
153 |
return var;
|
|
154 |
}
|
|
155 |
|
|
156 |
/**
|
|
157 |
* Create a VariableSet element.
|
|
158 |
* @return a VariableSet object.
|
|
159 |
*/
|
|
160 |
public VariableGroup createVariableGroup() {
|
|
161 |
VariableGroup var = new VariableGroup();
|
|
162 |
variablegroups.add(var);
|
|
163 |
return var;
|
|
164 |
}
|
|
165 |
|
|
166 |
/**
|
|
167 |
* Get the list of variableset.
|
|
168 |
* @return a vector of VariableSet objects.
|
|
169 |
*/
|
|
170 |
public Vector<VariableSet> getVariableSet() {
|
|
171 |
return variables;
|
|
172 |
}
|
|
173 |
|
|
174 |
/**
|
|
175 |
* Enables the sorting of images per region.
|
|
176 |
* @deprecated The usage of this feature is now ignored.
|
|
177 |
* @param value the state of the regional variation
|
|
178 |
* @ant.not-required Default is false - The usage of this feature is now ignored.
|
|
179 |
*/
|
|
180 |
@Deprecated
|
|
181 |
public void setRegionalVariation(boolean value) {
|
|
182 |
log(this.getDataTypeName() + ": the usage of the regionalVariation attribute is now ignored.", Project.MSG_WARN);
|
|
183 |
regionalVariation = value;
|
|
184 |
}
|
|
185 |
|
|
186 |
/**
|
|
187 |
* Get the status of the regional variation enabling.
|
|
188 |
* @deprecated The usage of this feature is now ignored.
|
|
189 |
* @return returns true is the regional variation should be enabled.
|
|
190 |
*/
|
|
191 |
public boolean getRegionalVariation() {
|
|
192 |
return regionalVariation;
|
|
193 |
}
|
|
194 |
|
|
195 |
/**
|
|
196 |
* Check if name is matching any of the pattern under patterns list.
|
|
197 |
* @param name the string to match
|
|
198 |
* @param patterns a list of PatternSet
|
|
199 |
* @return Returns true if name matches at least one pattern.
|
|
200 |
*/
|
|
201 |
protected boolean isIncluded(String name, Vector<PatternSet> patterns) {
|
|
202 |
for (PatternSet patternSet : patterns) {
|
|
203 |
if (patternSet.isReference()) {
|
|
204 |
patternSet = (PatternSet) patternSet.getRefid().getReferencedObject();
|
|
205 |
}
|
|
206 |
String[] includes = patternSet.getIncludePatterns(getProject());
|
|
207 |
if (includes != null) {
|
|
208 |
for (String pattern : includes) {
|
|
209 |
if (Pattern.matches(pattern, name)) {
|
|
210 |
return true;
|
|
211 |
}
|
|
212 |
}
|
|
213 |
}
|
|
214 |
}
|
|
215 |
return false;
|
|
216 |
}
|
|
217 |
|
|
218 |
/**
|
|
219 |
* Check if name is matching any of the pattern under patterns list.
|
|
220 |
* @param name the string to match
|
|
221 |
* @param patterns a list of PatternSet
|
|
222 |
* @return Returns true if name matches at least one pattern.
|
|
223 |
*/
|
|
224 |
protected boolean isExcluded(String name, Vector<PatternSet> patterns) {
|
|
225 |
for (PatternSet patternSet : patterns) {
|
|
226 |
if (patternSet.isReference()) {
|
|
227 |
patternSet = (PatternSet) patternSet.getRefid().getReferencedObject();
|
|
228 |
}
|
|
229 |
String[] excludes = patternSet.getExcludePatterns(getProject());
|
|
230 |
if (excludes != null) {
|
|
231 |
for (String pattern : excludes) {
|
|
232 |
if (Pattern.matches(pattern, name)) {
|
|
233 |
return true;
|
|
234 |
}
|
|
235 |
}
|
|
236 |
}
|
|
237 |
}
|
|
238 |
return false;
|
|
239 |
}
|
|
240 |
|
|
241 |
/**
|
|
242 |
* Get a configured matcher.
|
|
243 |
* @return a configured makefile matcher.
|
|
244 |
*/
|
|
245 |
protected Matcher getMakefileMatcher(IMaker imaker) {
|
|
246 |
Matcher matcher = new Matcher();
|
|
247 |
List<String> includes = new ArrayList<String>();
|
|
248 |
List<String> excludes = new ArrayList<String>();
|
|
249 |
for (PatternSet patternSet : makefiles) {
|
|
250 |
if (patternSet.isReference()) {
|
|
251 |
patternSet = (PatternSet) patternSet.getRefid().getReferencedObject();
|
|
252 |
}
|
|
253 |
String[] patterns = patternSet.getIncludePatterns(getProject());
|
|
254 |
if (patterns != null) {
|
|
255 |
for (String pattern : patterns) {
|
|
256 |
includes.add(pattern);
|
|
257 |
}
|
|
258 |
}
|
|
259 |
patterns = patternSet.getExcludePatterns(getProject());
|
|
260 |
if (patterns != null) {
|
|
261 |
for (String pattern : patterns) {
|
|
262 |
excludes.add(pattern);
|
|
263 |
}
|
|
264 |
}
|
|
265 |
}
|
|
266 |
matcher.setIncludes(includes.toArray(new String[includes.size()]));
|
|
267 |
matcher.setExcludes(excludes.toArray(new String[excludes.size()]));
|
|
268 |
matcher.setBasedir(imaker.getEpocroot());
|
|
269 |
return matcher;
|
|
270 |
}
|
|
271 |
|
|
272 |
/**
|
|
273 |
* {@inheritDoc}
|
|
274 |
*/
|
|
275 |
@Override
|
|
276 |
public List<List<Command>> getCommands(IMaker imaker) {
|
|
277 |
List<List<Command>> cmdSet = new ArrayList<List<Command>>();
|
|
278 |
List<Command> cmds = new ArrayList<Command>();
|
|
279 |
// Let's add one fake group.
|
|
280 |
if (variablegroups.size() == 0) {
|
|
281 |
variablegroups.add(new VariableGroup());
|
|
282 |
}
|
|
283 |
try {
|
|
284 |
for (String configuration : getConfigurations(imaker.getConfigurations(), imaker)) {
|
|
285 |
log("Including configuration: " + configuration);
|
|
286 |
for (String target : imaker.getTargets(configuration)) {
|
|
287 |
if (isIncluded(target, targets) && !isExcluded(target, targets)) {
|
|
288 |
log("Including target: " + target);
|
|
289 |
for (VariableGroup group : variablegroups) {
|
|
290 |
if (group.isReference()) {
|
|
291 |
group = (VariableGroup)group.getRefid().getReferencedObject();
|
|
292 |
}
|
|
293 |
Command cmd = new Command();
|
|
294 |
cmd.setCommand("imaker");
|
|
295 |
cmd.addArgument("-f");
|
|
296 |
cmd.addArgument(configuration);
|
|
297 |
// Adding variables
|
|
298 |
for (VariableSet vs : variables) {
|
|
299 |
cmd.addVariables(vs.toMap());
|
|
300 |
}
|
|
301 |
// Adding variables from groups
|
|
302 |
cmd.addVariables(group.toMap());
|
|
303 |
cmd.setTarget(target);
|
|
304 |
cmds.add(cmd);
|
|
305 |
}
|
|
306 |
}
|
|
307 |
}
|
|
308 |
}
|
|
309 |
} catch (IMakerException e) {
|
|
310 |
throw new BuildException(e.getMessage());
|
|
311 |
}
|
|
312 |
// adding all the commands.
|
|
313 |
if (cmds.size() > 0) {
|
|
314 |
cmdSet.add(cmds);
|
|
315 |
}
|
|
316 |
return cmdSet;
|
|
317 |
}
|
|
318 |
|
|
319 |
/**
|
|
320 |
* Select which iMaker configuration should be built.
|
|
321 |
* @param configurations
|
|
322 |
* @return
|
|
323 |
*/
|
|
324 |
protected Set<String> getConfigurations(List<String> configurations, IMaker imaker) {
|
|
325 |
Set<String> result = new HashSet<String>();
|
|
326 |
if (makefiles.size() > 0) {
|
|
327 |
Matcher matcher = getMakefileMatcher(imaker);
|
|
328 |
for (String configuration : configurations) {
|
|
329 |
if (matcher.match(configuration)) {
|
|
330 |
result.add(configuration);
|
|
331 |
}
|
|
332 |
}
|
|
333 |
}
|
|
334 |
for (MakefileSelector selector : selectors) {
|
|
335 |
result.addAll(selector.selectMakefile(configurations));
|
|
336 |
}
|
|
337 |
return result;
|
|
338 |
}
|
|
339 |
|
|
340 |
/**
|
|
341 |
* Matcher object to filter discovered configurations.
|
|
342 |
* iMaker configuration.
|
|
343 |
*/
|
|
344 |
public class Matcher extends DirectoryScanner {
|
|
345 |
|
|
346 |
/**
|
|
347 |
* Check is a particular configuration can
|
|
348 |
* is selected.
|
|
349 |
* @param path the string to match.
|
|
350 |
* @return return true is the path is selected.
|
|
351 |
*/
|
|
352 |
public boolean match(String path) {
|
|
353 |
String vpath = path.replace('/', File.separatorChar).
|
|
354 |
replace('\\', File.separatorChar);
|
|
355 |
return isIncluded(vpath) && !isExcluded(vpath);
|
|
356 |
}
|
|
357 |
}
|
|
358 |
|
|
359 |
}
|