1 package com.nokia.carbide.cpp.internal.api.sdk; |
1 package com.nokia.carbide.cpp.internal.api.sdk; |
2 |
2 |
3 import java.io.File; |
3 import java.io.File; |
|
4 import java.io.StringReader; |
|
5 import java.util.ArrayList; |
4 import java.util.Collections; |
6 import java.util.Collections; |
5 import java.util.List; |
7 import java.util.List; |
6 |
8 |
|
9 import javax.xml.parsers.DocumentBuilder; |
|
10 import javax.xml.parsers.DocumentBuilderFactory; |
|
11 |
7 import org.eclipse.core.runtime.IPath; |
12 import org.eclipse.core.runtime.IPath; |
|
13 import org.eclipse.core.runtime.Path; |
8 import org.osgi.framework.Version; |
14 import org.osgi.framework.Version; |
|
15 import org.w3c.dom.Element; |
|
16 import org.w3c.dom.NamedNodeMap; |
|
17 import org.w3c.dom.Node; |
|
18 import org.w3c.dom.NodeList; |
|
19 import org.xml.sax.InputSource; |
|
20 import org.xml.sax.helpers.DefaultHandler; |
9 |
21 |
10 import com.nokia.carbide.cpp.epoc.engine.preprocessor.IDefine; |
22 import com.nokia.carbide.cpp.epoc.engine.preprocessor.IDefine; |
11 import com.nokia.carbide.cpp.internal.sdk.core.model.SBSv2BuildInfo; |
23 import com.nokia.carbide.cpp.internal.sdk.core.model.SBSv2BuildInfo; |
12 import com.nokia.carbide.cpp.internal.sdk.core.model.SymbianSDK; |
24 import com.nokia.carbide.cpp.internal.sdk.core.model.SymbianSDK; |
13 import com.nokia.carbide.cpp.sdk.core.IBSFCatalog; |
|
14 import com.nokia.carbide.cpp.sdk.core.IBSFPlatform; |
|
15 import com.nokia.carbide.cpp.sdk.core.IRVCTToolChainInfo; |
25 import com.nokia.carbide.cpp.sdk.core.IRVCTToolChainInfo; |
16 import com.nokia.carbide.cpp.sdk.core.ISBSv2BuildContext; |
26 import com.nokia.carbide.cpp.sdk.core.ISBSv2BuildContext; |
17 import com.nokia.carbide.cpp.sdk.core.ISymbianBuildContext; |
27 import com.nokia.carbide.cpp.sdk.core.ISymbianBuildContext; |
18 import com.nokia.carbide.cpp.sdk.core.ISymbianBuilderID; |
28 import com.nokia.carbide.cpp.sdk.core.ISymbianBuilderID; |
19 import com.nokia.carbide.cpp.sdk.core.ISymbianSDK; |
29 import com.nokia.carbide.cpp.sdk.core.ISymbianSDK; |
20 import com.nokia.carbide.cpp.sdk.core.SDKCorePlugin; |
30 import com.nokia.carbide.cpp.sdk.core.SDKCorePlugin; |
21 import com.nokia.cpp.internal.api.utils.core.Check; |
31 import com.nokia.cpp.internal.api.utils.core.Check; |
|
32 import com.nokia.cpp.internal.api.utils.core.Logging; |
22 |
33 |
23 public class BuildContextSBSv2 implements ISBSv2BuildContext { |
34 public class BuildContextSBSv2 implements ISBSv2BuildContext { |
24 |
35 |
25 private String platform; |
36 private String platform; |
26 private String target; |
37 private String target; |
27 private String sbsv2Alias; |
38 private String sbsv2Alias; |
|
39 private String meaning; |
28 private ISymbianSDK sdk; |
40 private ISymbianSDK sdk; |
29 private String displayString; |
41 private String displayString; |
30 private String configID; // cconfiguration 'id' attribute from .cproject |
42 private String configID; // cconfiguration 'id' attribute from .cproject |
|
43 |
|
44 // Raptor config query data |
|
45 String outputPathString; |
|
46 List<String> metaDataMacros = new ArrayList<String>(); // macros to parse the INF/MMPs files (these do not contain values) |
|
47 List<String> metaDataIncludes = new ArrayList<String>(); |
|
48 String metaDataVariantHRH; |
|
49 String configParseErrorMessage = null; |
31 |
50 |
32 public BuildContextSBSv2(ISymbianSDK theSDK, String thePlatform, String theTarget, String theSBSv2Alias, String displayName, String configID) { |
51 public BuildContextSBSv2(ISymbianSDK theSDK, String thePlatform, String theTarget, String theSBSv2Alias, String displayName, String configID) { |
33 this.sdk = theSDK; |
52 this.sdk = theSDK; |
34 this.platform = thePlatform.toUpperCase(); |
53 this.platform = thePlatform.toUpperCase(); |
35 this.target = theTarget.toUpperCase(); |
54 this.target = theTarget.toUpperCase(); |
36 this.sbsv2Alias = theSBSv2Alias; |
55 this.sbsv2Alias = theSBSv2Alias; |
37 this.displayString = displayName; |
56 this.displayString = displayName; |
38 this.configID = configID; |
57 this.configID = configID; |
39 } |
58 } |
40 |
59 |
|
60 public BuildContextSBSv2(ISymbianSDK sdk, String alias, String meaning, String contextQueryXML) { |
|
61 this.sdk = sdk; |
|
62 this.sbsv2Alias = alias; |
|
63 this.meaning = meaning; |
|
64 this.configID = ISBSv2BuildContext.BUILDER_ID + "." + sbsv2Alias + "." + sdk.getUniqueId(); |
|
65 parseQueryConfigResults(contextQueryXML); |
|
66 |
|
67 this.displayString = getPlatformString().toUpperCase() + " " + getTargetString().toUpperCase(); |
|
68 } |
|
69 |
41 @Override |
70 @Override |
42 public ISymbianSDK getSDK() { |
71 public ISymbianSDK getSDK() { |
43 return sdk; |
72 return sdk; |
44 } |
73 } |
45 |
74 |
46 @Override |
75 @Override |
47 public String getPlatformString() { |
76 public String getPlatformString() { |
|
77 |
|
78 if (platform == null){ |
|
79 return configParseErrorMessage; |
|
80 } |
|
81 |
|
82 if (platform.contains(".")){ |
|
83 return platform.split(".")[0]; |
|
84 } |
48 return platform; |
85 return platform; |
49 } |
86 } |
|
87 |
|
88 public String getPlatformReleaseDirName() { |
|
89 return platform; |
|
90 } |
50 |
91 |
51 @Override |
92 @Override |
52 public String getTargetString() { |
93 public String getTargetString() { |
|
94 if (target == null){ |
|
95 return configParseErrorMessage; |
|
96 } |
53 return target; |
97 return target; |
54 } |
98 } |
55 |
99 |
56 public String getConfigID(){ |
100 public String getConfigID(){ |
57 return configID; |
101 return configID; |
323 return configName.substring(indexBegin+1, indexEnd); |
367 return configName.substring(indexBegin+1, indexEnd); |
324 } else { |
368 } else { |
325 return ""; //$NON-NLS-1$ |
369 return ""; //$NON-NLS-1$ |
326 } |
370 } |
327 } |
371 } |
328 |
372 |
329 |
373 |
|
374 private void parseQueryConfigResults(String queryResult) { |
|
375 |
|
376 try { |
|
377 Element root = null; |
|
378 DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
|
379 parser.setErrorHandler(new DefaultHandler()); |
|
380 |
|
381 StringReader reader = new StringReader( queryResult ); |
|
382 InputSource inputSource = new InputSource( reader ); |
|
383 root = parser.parse(inputSource).getDocumentElement(); |
|
384 |
|
385 NodeList children = root.getChildNodes(); |
|
386 for (int i=0; i< children.getLength(); i++) { |
|
387 Node configNode = children.item(i); |
|
388 if (configNode.getNodeName().equals("config")){ |
|
389 NamedNodeMap aliasAttribs = configNode.getAttributes(); |
|
390 String dottedName = aliasAttribs.getNamedItem("meaning").getNodeValue(); |
|
391 if (!dottedName.equalsIgnoreCase(meaning)){ |
|
392 continue; |
|
393 } |
|
394 if (configNode.getTextContent() != null&& configNode.getTextContent().length() > 0){ |
|
395 // The config failed, likely due to envrionment set up issue. |
|
396 // Save the error message |
|
397 configParseErrorMessage = configNode.getTextContent(); |
|
398 break; |
|
399 } |
|
400 |
|
401 String outputpath = aliasAttribs.getNamedItem("outputpath").getNodeValue(); |
|
402 if (outputpath != null){ |
|
403 outputPathString = outputpath; |
|
404 } |
|
405 |
|
406 // get <metadata> |
|
407 NodeList configChillens = configNode.getChildNodes(); |
|
408 for (int ii = 0; ii < configChillens.getLength(); ii++){ |
|
409 Node metaDataNode = configChillens.item(ii); |
|
410 if (metaDataNode.getNodeName().equals("metadata")){ |
|
411 NodeList metaDataChillens = metaDataNode.getChildNodes(); |
|
412 for (int iii = 0; iii < metaDataChillens.getLength(); iii++){ |
|
413 Node metaChild = metaDataChillens.item(iii); |
|
414 NamedNodeMap attribs = metaChild.getAttributes(); |
|
415 try { |
|
416 if (metaChild.getNodeName().equals("macro")){ |
|
417 String name = attribs.getNamedItem("name").getNodeValue(); |
|
418 metaDataMacros.add(name); |
|
419 } else if (metaChild.getNodeName().equals("include")){ |
|
420 String path = attribs.getNamedItem("path").getNodeValue(); |
|
421 metaDataIncludes.add(path); |
|
422 } else if (metaChild.getNodeName().equals("preinclude")){ |
|
423 metaDataVariantHRH = attribs.getNamedItem("file").getNodeValue(); |
|
424 } |
|
425 } catch (Exception e) { |
|
426 // skip it |
|
427 e.printStackTrace(); |
|
428 } |
|
429 } |
|
430 |
|
431 } else if (metaDataNode.getNodeName().equals("compilerinfo")){ |
|
432 // TODO: Placeholder for future cpp preprocessor macros and compiler prefix |
|
433 // Not sure what it will be called yet. |
|
434 } |
|
435 } |
|
436 |
|
437 break; |
|
438 } |
|
439 } |
|
440 |
|
441 } catch (Exception e) { |
|
442 e.printStackTrace(); |
|
443 Logging.log(SDKCorePlugin.getDefault(), Logging.newStatus(SDKCorePlugin.getDefault(), e)); |
|
444 } |
|
445 |
|
446 setPlatformAndTargetFromOutputPath(); |
|
447 |
|
448 } |
|
449 |
|
450 private void setPlatformAndTargetFromOutputPath() { |
|
451 if (outputPathString == null) return; |
|
452 |
|
453 IPath releasePath = new Path(outputPathString); |
|
454 int epoc32SegmentIndex = 0; |
|
455 for (String segment : releasePath.segments()){ |
|
456 if (segment.toLowerCase().equals("epoc32")) |
|
457 break; |
|
458 epoc32SegmentIndex++; |
|
459 } |
|
460 // assuming /epoc32/<release>/<target>/ |
|
461 platform = releasePath.segment(epoc32SegmentIndex+2); |
|
462 target = releasePath.segment(epoc32SegmentIndex+3); |
|
463 } |
|
464 |
|
465 /** |
|
466 * Error message, if any. |
|
467 * @return An error message if a problem occurred while trying to get config info from Raptor. Null if no error. |
|
468 */ |
|
469 public String getConfigurationErrorMessage(){ |
|
470 return configParseErrorMessage; |
|
471 } |
330 |
472 |
331 } |
473 } |