updates for SBV support to build and compile with proper platform name and makefile. Updates to refactor support to get MD5 from build target mmp.
authortimkelly
Fri, 15 May 2009 16:31:41 -0500
changeset 156 66bb501740a4
parent 155 78392c1e45bf
child 157 d0e39a2b6afc
updates for SBV support to build and compile with proper platform name and makefile. Updates to refactor support to get MD5 from build target mmp.
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/internal/builder/CarbideSBSv1Builder.java
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/internal/sdk/core/model/SBVPlatform.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	Fri May 15 09:32:15 2009 -0500
+++ b/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/builder/EpocEngineHelper.java	Fri May 15 16:31:41 2009 -0500
@@ -16,71 +16,30 @@
 */
 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.io.*;
+import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.eclipse.core.resources.IFile;
 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 org.eclipse.core.runtime.*;
 
 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.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.cdt.builder.project.*;
+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.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.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.model.mmp.*;
 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.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;
+import com.nokia.carbide.internal.api.cpp.epoc.engine.model.pkg.*;
+import com.nokia.cpp.internal.api.utils.core.*;
 
 public class EpocEngineHelper {
 
@@ -847,7 +806,7 @@
 						exePath = tempPath.lastSegment();
 					}
 					
-					String releasePlatform = buildConfig.getSDK().getBSFCatalog().getReleasePlatform(buildConfig.getPlatformString());
+					String releasePlatform = buildConfig.getSDK().getBSFCatalog().getReleasePlatform(buildConfig.getBasePlatformForVariation());
 					IPath path = buildConfig.getSDK().getReleaseRoot().append(releasePlatform).append(buildConfig.getTargetString());
 
 					// if targetpath is non-null and this is an EKA1 emulator config then add it
@@ -2017,60 +1976,21 @@
 			
 			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();
+				// construct the location of the binary variant makefile.
+				ICarbideBuildConfiguration defaultConfig = cpi.getDefaultConfiguration();
+				File realMakeFile = getMakeFileForSymbianBinaryVariant(mmpData, defaultConfig);	
 				
-				String makefilePath = makefileDir.toOSString() + File.separator + mmpRootName + File.separator + plat + File.separator;
-				String variantMakeFileName = mmpRootName + "." + plat + "." + variant;
-				String MD5Name = "";
+				String MD5Name = getMD5HashForBinaryVariant(defaultConfig, mmpData.getModelPath());
 				
-				//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$
-					}
-					
+				if (MD5Name != null && 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.
+					// The MD5 may not be able to be calculated
+					return null;
 				}
+				
 			} else {
 				return null;
 			}
@@ -2085,6 +2005,88 @@
 		return target;
 	}
 	
+	static public String getMD5HashForBinaryVariant(final ICarbideBuildConfiguration config, final IPath mmpFullPath){
+		
+		return (String)EpocEnginePlugin.runWithMMPData(mmpFullPath, 
+				new DefaultMMPViewConfiguration(config, new AcceptedNodesViewFilter()),
+				new MMPDataRunnableAdapter() {
+
+				public Object run(IMMPData mmpData) {
+					
+					String md5 = "";
+					
+					File makefile = getMakeFileForSymbianBinaryVariant(mmpData, config);
+					if (makefile != null && makefile.exists()){
+						md5 = getMD5VariantFromMakefile(makefile, config);
+					}
+
+					return md5;	
+				}
+		});								
+	}
+	
+	
+	private static File getMakeFileForSymbianBinaryVariant(IMMPData mmpData, ICarbideBuildConfiguration config){
+		
+		IPath makefileDir = CarbideCPPBuilder.getBuilderMakefileDir(config);
+		
+		IPath mmpFile = mmpData.getModelPath();
+		mmpFile = mmpFile.removeFileExtension();
+		String mmpRootName = mmpFile.lastSegment();
+		String plat = config.getPlatformString();
+		String basePlat = config.getBasePlatformForVariation();
+		
+		String makefilePath = makefileDir.toOSString() + File.separator + mmpRootName + File.separator + basePlat + File.separator;
+		String variantMakeFileName = mmpRootName + "." + plat;
+		File realMakeFile = new File(makefilePath + variantMakeFileName);
+		
+		return realMakeFile;
+	}
+	
+	/**
+	 * Get the MD5 hash value for an existing configuration by parsing its makefile.
+	 * @param makefile - The build makefile to parse to check for the MD5
+	 * @param config - The build configuration to check under
+	 * @return The string for the MD5 hash. An empty string if it cannot be determined.
+	 */
+	private static String getMD5VariantFromMakefile(File makefile, ICarbideBuildConfiguration config){
+		// TODO: We can also use the .vmap in the release folder as well.
+		// we can parse the makefile and get the variant name for each in the comments:
+		//
+		//# FeatureVariantURELLabel d41d8cd98f00b204e9800998ecf8427e
+		//# FeatureVariantUDEBLabel d41d8cd98f00b204e9800998ecf8427e
+		String MD5Str = "";
+
+		if (makefile.exists()){
+			String text = "";
+			try {
+				text = new String(FileUtils.readFileContents(makefile, null));
+			} catch (CoreException e) {
+				e.printStackTrace();
+			}
+			
+			String searchString = "";
+			if (config.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){
+						MD5Str = tokens[2];
+						break;
+					}
+				}
+			}
+			
+		} 
+		
+		return MD5Str;
+	}
+	
 	/**
 	 * If the given MMP builds variant executables, return all the variant targets it builds.
 	 * <p>
--- a/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideSBSv1Builder.java	Fri May 15 09:32:15 2009 -0500
+++ b/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideSBSv1Builder.java	Fri May 15 16:31:41 2009 -0500
@@ -531,8 +531,19 @@
 			view.dispose();
 			modelProvider.releaseSharedModel(model);
 
-			IPath objectDir = new Path(epocBldMacros[0].getValue().toString()).append(buildConfig.getTargetString());
-
+			IPath objectDir = null;
+			if (buildConfig.isSymbianBinaryVariation()){
+				// if symbian binary variation, then the object file dir will be in sub-directory with <md5>/udeb/<obj>
+				String MD5Name = EpocEngineHelper.getMD5HashForBinaryVariant(buildConfig, fullMMPPath);
+				if (MD5Name != null && MD5Name.length() > 0){
+					objectDir = new Path(epocBldMacros[0].getValue().toString()).append(MD5Name).append(buildConfig.getTargetString());
+				}
+			} 
+			
+			if (objectDir == null){
+				objectDir = new Path(epocBldMacros[0].getValue().toString()).append(buildConfig.getTargetString());
+			}
+			
 			IPath path = objectDir.append(file.removeFileExtension().lastSegment() + ".o").removeTrailingSeparator();
 			
 			if (FileUtils.getSafeFileExtension(file).toLowerCase().compareTo("cia") == 0) {
@@ -2429,11 +2440,16 @@
 
 		// each platform has its own directory
 		String platformName = config.getPlatformString().toUpperCase();
-		makefilePath = makefilePath.append(platformName);
+		makefilePath = makefilePath.append(config.getBasePlatformForVariation().toUpperCase());
 
 		// and the makefile has the form MMPNAME.PLATFORM
 		makefilePath = makefilePath.append(mmpName + "." + platformName);
-
+		
+		if (!makefilePath.toFile().exists()){
+			makefilePath = makefilePath.removeLastSegments(1);
+			makefilePath = makefilePath.append(mmpName + "." + platformName + ".DEFAULT");
+		}
+		
 		return makefilePath.toFile();
 	}
 	
--- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SymbianBuildContext.java	Fri May 15 09:32:15 2009 -0500
+++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SymbianBuildContext.java	Fri May 15 16:31:41 2009 -0500
@@ -517,4 +517,29 @@
 		
 		return varName;
 	}
+
+
+	public boolean isSymbianBinaryVariation() {
+		if (getPlatformString().split("\\.").length == 2){
+			return true;
+		} else {
+			return false;
+		}
+	}
+
+
+	public String getBasePlatformForVariation() {
+		String plat = "";
+		
+		String[] tokens = getPlatformString().split("\\.");
+		if (tokens.length == 2){
+			plat = tokens[0];
+		} else {
+			return platform;
+		}
+		
+		return plat;
+	}
+	
+	
 }
--- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/model/SBVPlatform.java	Fri May 15 09:32:15 2009 -0500
+++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/model/SBVPlatform.java	Fri May 15 16:31:41 2009 -0500
@@ -178,9 +178,10 @@
 	}
 
 	public IPath getBuildVariantHRHFile() {
-		
+		// TODO: If the bldvariant is not defined we are supposed to use the <variant name>.hrh
+		// as the preinclude. But currently we aren't sure how to look that up or where the default
+		// location should be
 		return bldVarintHRH;
-		
 	}
 	
 	protected void setBuildIncludePaths(Map<String, String> incPaths){
--- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/sdk/core/ISymbianBuildContext.java	Fri May 15 09:32:15 2009 -0500
+++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/sdk/core/ISymbianBuildContext.java	Fri May 15 16:31:41 2009 -0500
@@ -62,6 +62,14 @@
 	public String getPlatformString();
 	
 	/**
+	 * For Symbian Bianry Variation, platforms will be names <plat>.<variation>
+	 * So in some cases you need to know only the platforms that the variant is based on.
+	 * @return The base platform string.
+	 * @see isSymbianBinaryVariation()
+	 */
+	public String getBasePlatformForVariation();
+	
+	/**
 	 * The debug or release target the platform is building for.
 	 * @return UDEB or UREL.
 	 * @see DEBUG_TARGET and RELEASE_TARGET
@@ -117,4 +125,10 @@
 	 * @return The name of the Symbian Binary Variation, or an empy String if the configuration is not a variation.
 	 */
 	public String getBuildVariationName();
+	
+	/**
+	 * Is the current build context building as a Symbian Binary Variation? Not to be confused with BSF.
+	 * @return true if this is a binary variant build
+	 */
+	public boolean isSymbianBinaryVariation();
 }