Add support for getting the Symbian Binary Variation name for variant builds. Bug 8793.
authortimkelly
Thu, 07 May 2009 12:10:50 -0500
changeset 139 e743b7cf572c
parent 138 c16ad3b964c3
child 140 697b7727d088
child 145 385c4eb053ad
Add support for getting the Symbian Binary Variation name for variant builds. Bug 8793.
builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/builder/EpocEngineHelper.java
builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/builder/builder/CarbideCPPBuilder.java
builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideBuildConfiguration.java
carbidesdk/com.nokia.carbide.cpp.sdk.doc.user/html/reference/api_Change_Notes.htm
core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SymbianBuildContext.java
core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/sdk/core/ISymbianBuildContext.java
--- a/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/builder/EpocEngineHelper.java	Wed May 06 10:58:40 2009 -0500
+++ b/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/builder/EpocEngineHelper.java	Thu May 07 12:10:50 2009 -0500
@@ -16,29 +16,71 @@
 */
 package com.nokia.carbide.cdt.builder;
 
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+
+import com.nokia.carbide.cdt.builder.builder.CarbideCPPBuilder;
 import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration;
 import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo;
 import com.nokia.carbide.cdt.builder.project.ISISBuilderInfo;
-import com.nokia.carbide.cpp.epoc.engine.*;
-import com.nokia.carbide.cpp.epoc.engine.image.*;
-import com.nokia.carbide.cpp.epoc.engine.model.bldinf.*;
+import com.nokia.carbide.cpp.epoc.engine.BldInfDataRunnableAdapter;
+import com.nokia.carbide.cpp.epoc.engine.BldInfViewRunnableAdapter;
+import com.nokia.carbide.cpp.epoc.engine.EpocEnginePlugin;
+import com.nokia.carbide.cpp.epoc.engine.ImageMakefileDataRunnableAdapter;
+import com.nokia.carbide.cpp.epoc.engine.MMPDataRunnableAdapter;
+import com.nokia.carbide.cpp.epoc.engine.MMPViewRunnableAdapter;
+import com.nokia.carbide.cpp.epoc.engine.PKGViewRunnableAdapter;
+import com.nokia.carbide.cpp.epoc.engine.image.IBitmapSource;
+import com.nokia.carbide.cpp.epoc.engine.image.IImageSource;
+import com.nokia.carbide.cpp.epoc.engine.image.IMultiImageSource;
+import com.nokia.carbide.cpp.epoc.engine.model.bldinf.IBldInfData;
+import com.nokia.carbide.cpp.epoc.engine.model.bldinf.IBldInfView;
+import com.nokia.carbide.cpp.epoc.engine.model.bldinf.IExport;
 import com.nokia.carbide.cpp.epoc.engine.model.bldinf.IExtension;
+import com.nokia.carbide.cpp.epoc.engine.model.bldinf.IMMPReference;
+import com.nokia.carbide.cpp.epoc.engine.model.bldinf.IMakMakeReference;
+import com.nokia.carbide.cpp.epoc.engine.model.bldinf.IMakefileReference;
 import com.nokia.carbide.cpp.epoc.engine.model.makefile.image.IImageMakefileData;
-import com.nokia.carbide.cpp.epoc.engine.model.mmp.*;
+import com.nokia.carbide.cpp.epoc.engine.model.mmp.EMMPLanguage;
+import com.nokia.carbide.cpp.epoc.engine.model.mmp.EMMPStatement;
+import com.nokia.carbide.cpp.epoc.engine.model.mmp.IMMPAIFInfo;
+import com.nokia.carbide.cpp.epoc.engine.model.mmp.IMMPBitmap;
+import com.nokia.carbide.cpp.epoc.engine.model.mmp.IMMPData;
+import com.nokia.carbide.cpp.epoc.engine.model.mmp.IMMPResource;
+import com.nokia.carbide.cpp.epoc.engine.model.mmp.IMMPView;
+import com.nokia.carbide.cpp.epoc.engine.model.mmp.IMMPViewConfiguration;
 import com.nokia.carbide.cpp.epoc.engine.preprocessor.AcceptedNodesViewFilter;
 import com.nokia.carbide.cpp.epoc.engine.preprocessor.AllNodesViewFilter;
+import com.nokia.carbide.cpp.internal.api.sdk.SymbianBuildContext;
 import com.nokia.carbide.cpp.sdk.core.ISymbianBuildContext;
 import com.nokia.carbide.cpp.sdk.core.ISymbianSDK;
-import com.nokia.carbide.internal.api.cpp.epoc.engine.model.pkg.*;
-import com.nokia.cpp.internal.api.utils.core.*;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.*;
-
-import java.io.*;
-import java.util.*;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import com.nokia.carbide.internal.api.cpp.epoc.engine.model.pkg.EPKGLanguage;
+import com.nokia.carbide.internal.api.cpp.epoc.engine.model.pkg.IPKGEmbeddedSISFile;
+import com.nokia.carbide.internal.api.cpp.epoc.engine.model.pkg.IPKGInstallFile;
+import com.nokia.carbide.internal.api.cpp.epoc.engine.model.pkg.IPKGView;
+import com.nokia.carbide.internal.api.cpp.epoc.engine.model.pkg.PKGModelHelper;
+import com.nokia.cpp.internal.api.utils.core.CommonPathFinder;
+import com.nokia.cpp.internal.api.utils.core.FileUtils;
+import com.nokia.cpp.internal.api.utils.core.Logging;
 
 public class EpocEngineHelper {
 
@@ -665,8 +707,11 @@
 
 										// adapt to variant, if needed
 										IPath targetPath = path.append(exePath);
-										if (isVariantBldInf(buildConfig.getCarbideProject().getAbsoluteBldInfPath())) {
-											targetPath = getVariantTargetName(mmpData, targetPath);
+										if (isVariantBldInf(buildConfig.getCarbideProject().getAbsoluteBldInfPath()) || isFeatureVariantMMP(mmpData, info.getProject())) {
+											targetPath = getBinaryVariantTargetName(mmpData, targetPath, info.getProject());
+											if (targetPath == null){
+												return null; 
+											}
 										}
 										
 										exePath = targetPath.toOSString();
@@ -793,8 +838,13 @@
 					}
 
 					// adapt the exe filename to the variant, if any
-					if (isVariantBldInf(cpi.getAbsoluteBldInfPath())) {
-						exePath = getVariantTargetName(mmpData, new Path(exePath)).lastSegment();
+					IPath tempPath = null;
+					if (isVariantBldInf(cpi.getAbsoluteBldInfPath()) || isFeatureVariantMMP(mmpData, cpi.getProject())) {
+						tempPath = getBinaryVariantTargetName(mmpData, new Path(exePath), cpi.getProject());
+						if (tempPath == null){
+							return null; 
+						}
+						exePath = tempPath.lastSegment();
 					}
 					
 					String releasePlatform = buildConfig.getSDK().getBSFCatalog().getReleasePlatform(buildConfig.getPlatformString());
@@ -1873,7 +1923,34 @@
 		});
 		return result != null ? result.booleanValue() : false;
 	}
-
+	
+	/**
+	 * A particular MMP file is considered to be a Symbian Binary Variation iff the MMP file
+	 * has the keyword "FEATUREVARIANT" flag defined and the build configuration has a valid
+	 * build variant target in it's configuration name.
+	 * @param mmpData - The data for the MMP file we want to inspect
+	 * @param project - The project we need to get the build configuration name from
+	 * @return true if a variant executable will be built for this mmp
+	 */
+	public static boolean isFeatureVariantMMP(IMMPData mmpData, IProject project){
+		
+		boolean isFeatureVariant = false;
+		ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project);
+		if (cpi != null){
+			ICarbideBuildConfiguration defaultConfig = cpi.getDefaultConfiguration();
+			if (defaultConfig != null){
+				if (defaultConfig.getBuildVariationName().length() > 0 && 
+					mmpData.getFlags().contains(EMMPStatement.FEATUREVARIANT)) {
+					
+					isFeatureVariant = true;
+				}
+			}
+			
+		}
+		
+		return isFeatureVariant;
+	}
+	
 	/**
 	 * If the given MMP builds variant executables, return its current target.
 	 * Returns the normal target if not variant.
@@ -1884,7 +1961,7 @@
 	 * @return the epocroot-relative target path.  Only null if no target defined in MMP at all.
 	 * @see #isVariantBldInf(IPath)
 	 */
-	public static IPath getVariantMMPTarget(ICarbideBuildConfiguration buildConfiguration, IPath projectRelativeMMPPath) {
+	public static IPath getVariantMMPTarget(final ICarbideBuildConfiguration buildConfiguration, final IPath projectRelativeMMPPath) {
 		IPath result = (IPath) EpocEnginePlugin.runWithMMPData(
 			projectRelativeMMPPath, 
 			new DefaultMMPViewConfiguration(
@@ -1892,7 +1969,7 @@
 					new AcceptedNodesViewFilter()),
 			new MMPDataRunnableAdapter() {
 				public Object run(IMMPData data) {
-					return getVariantTargetName(data, data.getTargetFilePath());
+					return getBinaryVariantTargetName(data, data.getTargetFilePath(), buildConfiguration.getCarbideProject().getProject());
 				}
 		});
 		return result;
@@ -1903,14 +1980,108 @@
 	 * @param mmpData
 	 * @param target
 	 * @return updated target name
+	 * 
+	 * @deprecated Deprecated in 2.1. Use {@link #getBinaryVariantTargetName(IMMPData mmpData, IPath target, IProject project)} instead.
 	 */
 	private static IPath getVariantTargetName(IMMPData mmpData, IPath target) {
 		if (target == null)
 			return null;
+		
 		String suffix = mmpData.getSingleArgumentSettings().get(EMMPStatement.VAR);
 		if (suffix != null) {
 			target = target.removeFileExtension().addFileExtension(suffix + "." + FileUtils.getSafeFileExtension(target)); //$NON-NLS-1$
 		}
+		
+		return target;
+	}
+	
+	/**
+	 * Get the target name with a variant suffix inserted. Since 2.1 this includes support for Symbian Binary Variation builds
+	 * that have the FEATUREVARIANT keyword in their MMP file.
+	 * @param mmpData
+	 * @param target
+	 * @return updated target name. This may return null for Symbian Binary Variation builds that do not yet have calcualted target files names (i.e. no makefiles)
+	 */
+	private static IPath getBinaryVariantTargetName(IMMPData mmpData, IPath target, IProject project) {
+		if (target == null)
+			return null;
+		
+		if (isFeatureVariantMMP(mmpData, project)) {
+			
+			// get the Symbian Binary Variation Name
+			
+			if (CarbideBuilderPlugin.getBuildManager().isCarbideSBSv2Project(project)){
+				// raptor is not yet supported
+				return null;
+			}
+			
+			ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project);
+			if (cpi != null){
+				// construct the location of the binary variant makefile.
+				// we can parse the makefile and get the variant name for each in the comments:
+				//
+				//# FeatureVariantURELLabel d41d8cd98f00b204e9800998ecf8427e
+				//# FeatureVariantUDEBLabel d41d8cd98f00b204e9800998ecf8427e
+				
+				ICarbideBuildConfiguration defaultConfig = cpi.getDefaultConfiguration();
+				IPath makefileDir = CarbideCPPBuilder.getBuilderMakefileDir(defaultConfig);
+				
+				IPath mmpFile = mmpData.getModelPath();
+				mmpFile = mmpFile.removeFileExtension();
+				String mmpRootName = mmpFile.lastSegment();
+				String plat = defaultConfig.getPlatformString();
+				String variant = defaultConfig.getBuildVariationName();
+				
+				String makefilePath = makefileDir.toOSString() + File.separator + mmpRootName + File.separator + plat + File.separator;
+				String variantMakeFileName = mmpRootName + "." + plat + "." + variant;
+				String MD5Name = "";
+				
+				//System.out.println("Makefile dir: " + makefilePath +  variantMakeFileName);
+				File realMakeFile = new File(makefilePath + variantMakeFileName);
+				if (realMakeFile.exists()){
+					String text = "";
+					try {
+						text = new String(FileUtils.readFileContents(realMakeFile, null));
+					} catch (CoreException e) {
+						e.printStackTrace();
+					}
+					
+					String searchString = "";
+					if (defaultConfig.getTargetString().equals(SymbianBuildContext.DEBUG_TARGET)){
+						searchString = "# FeatureVariantUDEBLabel";
+					} else {
+						searchString = "# FeatureVariantURELLabel";
+					}
+					
+					for (String line : text.split("\n")) {
+						if (line.startsWith(searchString)){
+							String tokens[] = line.split(" ");
+							if (tokens.length == 3){
+								MD5Name = tokens[2];
+								break;
+							}
+						}
+					}
+					
+					if (MD5Name.length() > 0){
+						System.out.println("The target is: " + target.removeFileExtension().addFileExtension(MD5Name + "." + FileUtils.getSafeFileExtension(target)).toOSString()); //$NON-NLS-1$
+						return 	target = target.removeFileExtension().addFileExtension(MD5Name + "." + FileUtils.getSafeFileExtension(target)); //$NON-NLS-1$
+					}
+					
+				} else {
+					return null; // makefile likely not created yet so no need for error, this is normal case.
+				}
+			} else {
+				return null;
+			}
+			
+		}
+		else {
+			String suffix = mmpData.getSingleArgumentSettings().get(EMMPStatement.VAR);
+			if (suffix != null) {
+				target = target.removeFileExtension().addFileExtension(suffix + "." + FileUtils.getSafeFileExtension(target)); //$NON-NLS-1$
+			}
+		}
 		return target;
 	}
 	
--- a/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/builder/builder/CarbideCPPBuilder.java	Wed May 06 10:58:40 2009 -0500
+++ b/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/builder/builder/CarbideCPPBuilder.java	Thu May 07 12:10:50 2009 -0500
@@ -2061,4 +2061,8 @@
 		
 		return false;
     }
+    
+    public static IPath getBuilderMakefileDir(ICarbideBuildConfiguration config){
+    	return getBuilder(config.getCarbideProject().getProject()).getMakefileDirectory(config);
+    }
 }
--- a/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideBuildConfiguration.java	Wed May 06 10:58:40 2009 -0500
+++ b/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideBuildConfiguration.java	Thu May 07 12:10:50 2009 -0500
@@ -67,7 +67,7 @@
 	
 
 	public CarbideBuildConfiguration(IProject project, ISymbianBuildContext context) {
-		super(context.getSDK(), context.getPlatformString(), context.getTargetString());
+		super(context.getSDK(), context.getPlatformString(), context.getTargetString(), context.getBuildVariationName());
 		projectTracker = new TrackedResource(project);
 		sisBuilderInfoList = new ArrayList<ISISBuilderInfo>(0);
 		envVarsInfo = new EnvironmentVarsInfo2(project, context);
--- a/carbidesdk/com.nokia.carbide.cpp.sdk.doc.user/html/reference/api_Change_Notes.htm	Wed May 06 10:58:40 2009 -0500
+++ b/carbidesdk/com.nokia.carbide.cpp.sdk.doc.user/html/reference/api_Change_Notes.htm	Thu May 07 12:10:50 2009 -0500
@@ -62,6 +62,19 @@
   <li>Added <em> com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration#setBuildArgumentsInfo(BuildArgumentsInfo bldArgInfo)</em>.</li>
 </ul>
 
+<p>Since Carbide 2.1.0</p>
+<ul>
+  <li>Added <em> com.nokia.carbide.cdt.builder.builder.CarbideCPPBuilder#getBuilderMakefileDir(ICarbideBuildConfiguration config)</em>.</li>
+</ul>
+
+<ul>
+  <li>Added <em> com.nokia.carbide.cpp.sdk.core.ISymbianBuildContext#getBuildVariationName( )</em>.</li>
+</ul>
+
+<ul>
+  <li>Added <em> com.nokia.carbide.cdt.builder.EpocEngineHelper#isFeatureVariantMMP(IMMPData mmpData, IProject project)</em>.</li>
+</ul>
+
 <h3>Deprecated APIs</h3>
 <p>The following Carbide APIs have been deprecated and should not be used anymore.  Please see the JavaDoc for these classes and methods for more information.</p>
 <p>Since Carbide 1.2.0</p>
@@ -98,6 +111,11 @@
   <li><i>com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration#getBuildArgumentsInfo( )</i></li>
 </ul>
 
+<p>Since Carbide 2.1</p>
+<ul>
+  <li><i>com.nokia.carbide.cdt.builder.getVariantTargetName(IMMPData mmpData, IPath target)</i></li>
+</ul>
+
 <h3>Removed APIs</h3>
 <p>The following Carbide APIs have been removed and are no longer available to plug-ins.</p>
 <p>Since Carbide 1.2.0</p>
@@ -122,6 +140,12 @@
 <ul>
   <li>None</li>
 </ul>
+
+<p>Since Carbide 2.1.0</p>
+<ul>
+  <li>None</li>
+</ul>
+
 <div id="footer">Copyright &copy; 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. <br>License: <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a></div>
 </div></body>
 </html>
--- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SymbianBuildContext.java	Wed May 06 10:58:40 2009 -0500
+++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SymbianBuildContext.java	Thu May 07 12:10:50 2009 -0500
@@ -41,6 +41,7 @@
 	private String platform;
 	private String target;
 	private String displayString = null;
+	private String symbianBuildVariationString;
 	
 	private static String EMULATOR_DISPLAY_TEXT = "Emulator"; //$NON-NLS-1$
 	private static String PHONE_DISPLAY_TEXT = "Phone"; //$NON-NLS-1$
@@ -62,11 +63,26 @@
 	
 	public SymbianBuildContext(ISymbianSDK theSDK, String thePlatform, String theTarget) {
 		sdkId = theSDK.getUniqueId();
-		platform = thePlatform;
+		String[] platformString = thePlatform.split("\\.");
+		if (platformString != null && platformString.length == 2){
+			platform = platformString[0];
+			symbianBuildVariationString = platformString[1];
+		} else {
+			platform = thePlatform;
+			symbianBuildVariationString = "";
+		}
+		
 		target = theTarget;
 		getDisplayString();
 	}
-
+	
+	public SymbianBuildContext(ISymbianSDK theSDK, String thePlatform, String theTarget, String theBinaryVariationName) {
+		sdkId = theSDK.getUniqueId();
+		platform = thePlatform;
+		target = theTarget;
+		symbianBuildVariationString = theBinaryVariationName;
+		getDisplayString();
+	}
 	
 	@Override
 	public int hashCode() {
@@ -141,8 +157,13 @@
 			} else {
 				displayString = displayString + SPACE_DISPLAY_TEXT + RELEASE_DISPLAY_TEXT;
 			}
-
-			displayString = displayString + " (" + platform + ") [" + getSDK().getUniqueId() + "]"; //$NON-NLS-1$
+			
+			String platDisplay = platform;
+			if (symbianBuildVariationString.length() > 0){
+				platDisplay = platform + "." + symbianBuildVariationString;
+			}
+			
+			displayString = displayString + " (" + platDisplay + ") [" + getSDK().getUniqueId() + "]"; //$NON-NLS-1$
 		}
 		return displayString;
 	}
@@ -505,4 +526,9 @@
 			
 		return compilerPrefixMacros;
 	}
+
+
+	public String getBuildVariationName() {
+		return symbianBuildVariationString;
+	}
 }
--- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/sdk/core/ISymbianBuildContext.java	Wed May 06 10:58:40 2009 -0500
+++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/sdk/core/ISymbianBuildContext.java	Thu May 07 12:10:50 2009 -0500
@@ -110,4 +110,10 @@
 	 * @return a list of macros which may be empty.
 	 */
 	public List<IDefine> getCompilerMacros();
+	
+	/**
+	 * For platforms that are building with Symbian Binary Variation, this suffix will be included in the configuration name
+	 * @return The name of the Symbian Binary Variation, or an empy String if the configuration is not a variation.
+	 */
+	public String getBuildVariationName();
 }