diff options
author | Gun Kim <gune.kim@samsung.com> | 2013-02-24 18:19:43 +0900 |
---|---|---|
committer | Gun Kim <gune.kim@samsung.com> | 2013-02-24 18:28:09 +0900 |
commit | aa739d0b2851a0326a0033ab595dab38d43b59cf (patch) | |
tree | 1eae64562be3b5504254d8039b484e3235dc594f | |
parent | e8f3bdc1684be90a6abef149ace0a4506ed18449 (diff) | |
download | codecoverage-eplugin-aa739d0b2851a0326a0033ab595dab38d43b59cf.tar.gz codecoverage-eplugin-aa739d0b2851a0326a0033ab595dab38d43b59cf.tar.bz2 codecoverage-eplugin-aa739d0b2851a0326a0033ab595dab38d43b59cf.zip |
[Title] supported gcda file download when toolchain was LLVM.
[Type]
[Module]
[Priority]
[Jira#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]
Change-Id: Iafca6774508b3ff91e4d020ea71f714dce592c47
3 files changed, 182 insertions, 137 deletions
diff --git a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/CovManager.java b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/CovManager.java index 0379e3c..dc2c7c4 100644 --- a/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/CovManager.java +++ b/org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/CovManager.java @@ -39,9 +39,9 @@ import org.eclipse.linuxtools.gcov.model.CovFileTreeElement; import org.eclipse.linuxtools.gcov.model.CovFolderTreeElement;
import org.eclipse.linuxtools.gcov.model.CovFunctionTreeElement;
import org.eclipse.linuxtools.gcov.model.CovRootTreeElement;
+import org.tizen.common.util.FilenameUtil;
import org.tizen.common.util.OSChecker;
import org.tizen.nativecommon.build.SmartBuildInterface;
-
/**
* @author Xavier Raynaud <xavier.raynaud@st.com>
*
@@ -252,9 +252,40 @@ public class CovManager implements Serializable { */
public List<String> getGCDALocations() throws CoreException, IOException, InterruptedException
{
+ List<String> gcdaPaths = null;
+ List<String> tempGcdaPaths = new LinkedList<String>();
+
+ boolean isLLVM = getGCDALocations(tempGcdaPaths);
+ if ( isLLVM ) {
+ gcdaPaths = new LinkedList<String>();
+ IPath binaryPath = new Path(this.getBinaryPath());
+ for ( String gcda : tempGcdaPaths ) {
+ gcdaPaths.add(remakeGcdaPathForLLVM( gcda, binaryPath));
+ }
+ }
+ else {
+ gcdaPaths = tempGcdaPaths;
+ }
+ return gcdaPaths;
+ }
+
+ /**
+ * makes a gcda file path that contains the project path.
+ * @param gcdaPathInGcno gcda file path to be modified.
+ * @param binaryPath executable file's absolute path.
+ * @throws IOException
+ * @return String
+ */
+ public static String remakeGcdaPathForLLVM( String gcdaPathInGcno, IPath binaryPath ) throws IOException {
+ String binaryDirectory = FilenameUtil.getCanonicalPath( binaryPath.removeLastSegments(1).toFile() ) + "/";
+
+ return binaryDirectory + gcdaPathInGcno;
+ }
+
+ public boolean getGCDALocations( List<String> gcdaPaths) throws CoreException, IOException, InterruptedException
+ {
IBinaryObject binaryObject = STSymbolManager.sharedInstance.getBinaryObject(new Path(binaryPath));
String binaryPath = binaryObject.getPath().toOSString();
- List<String> l = new LinkedList<String>();
String cpu = binaryObject.getCPU();
Process p;
if ("sh".equals(cpu)) {
@@ -280,13 +311,19 @@ public class CovManager implements Serializable { Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR,
"An error occured during analysis: unable to retrieve gcov data", new IOException());
Activator.getDefault().getLog().log(status);
- return l;
+ return false;
}
- ThreadConsumer t = new ThreadConsumer(p, l);
+ ThreadConsumer t = new ThreadConsumer(p, gcdaPaths);
t.start();
p.waitFor();
t.join();
- return l;
+
+ if ( gcdaPaths.get(0).startsWith("/") ) {
+ return false;
+ }
+ else { // LLVM
+ return true;
+ }
}
@@ -332,9 +369,9 @@ public class CovManager implements Serializable { // be prefixed by random printable characters so strip leading
// characters until the filepath starts with "X:/", "X:\", "/" or "\"
// FIXME: need a more robust mechanism to locate .gcda files [Bugzilla 329710]
- while ((line.length() > 6) && !line.matches("^([A-Za-z]:)?[/\\\\].*")) {
- line = line.substring(1);
- }
+// while ((line.length() > 6) && !line.matches("^([A-Za-z]:)?[/\\\\].*")) {
+// line = line.substring(1);
+// }
IPath p = new Path(line);
String filename = p.toString();
if (!list.contains(filename)) list.add(filename);
diff --git a/org.tizen.codecoverage/META-INF/MANIFEST.MF b/org.tizen.codecoverage/META-INF/MANIFEST.MF index 35f833e..446ec02 100644 --- a/org.tizen.codecoverage/META-INF/MANIFEST.MF +++ b/org.tizen.codecoverage/META-INF/MANIFEST.MF @@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.ui, org.eclipse.cdt.debug.core, org.eclipse.debug.core, org.eclipse.linuxtools.gcov, - org.tizen.common + org.tizen.common, + org.tizen.nativecommon Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Import-Package: org.tizen.common.connection, diff --git a/org.tizen.codecoverage/src/org/tizen/codecoverage/helper/GcovHelper.java b/org.tizen.codecoverage/src/org/tizen/codecoverage/helper/GcovHelper.java index ff487f4..7053d27 100644 --- a/org.tizen.codecoverage/src/org/tizen/codecoverage/helper/GcovHelper.java +++ b/org.tizen.codecoverage/src/org/tizen/codecoverage/helper/GcovHelper.java @@ -20,12 +20,14 @@ package org.tizen.codecoverage.helper; +import java.util.LinkedList; import java.util.List; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; @@ -38,139 +40,144 @@ import org.eclipse.linuxtools.gcov.view.CovView; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; import org.tizen.common.connection.ConnectionPlugin; +import org.tizen.common.util.IOUtil; +import org.tizen.nativecommon.ProjectUtil; import org.tizen.nativecpp.editors.manifest.PackageModel; import org.tizen.sdblib.IDevice; import org.tizen.sdblib.SyncService; import org.tizen.sdblib.SyncService.SyncResult; public class GcovHelper { - final static String DATA_DIR = "/data/"; - - static public void run(IProject project) { - // null check project - if (project == null || !project.exists()) { - final String message = "Please select a project."; - Shell s = PlatformUI.getWorkbench().getDisplay().getActiveShell(); - MessageDialog.openInformation(s, "Project not found", message); - return; - } - - IDevice currentDevice = ConnectionPlugin.getDefault().getCurrentDevice(); - if (currentDevice == null) { -// final String message = "Target device is not running"; -// Shell s = PlatformUI.getWorkbench().getDisplay().getActiveShell(); -// MessageDialog.openError(s, "Gcov Error", message); - return; - } - - String binary = GcovHelper.getBinary(project); - if (binary == null) { - final String message = "Gcov failed. Binary file not found.\n" - + "Please check Build Settings"; - Shell s = PlatformUI.getWorkbench().getDisplay().getActiveShell(); - MessageDialog.openError(s, "Gcov Error", message); - return; - } - - try { - GcovHelper.downloadGcdaFile(binary); - } catch (Exception e) { - final String message = "Gcov failed. Coverage data file not found."; - Shell s = PlatformUI.getWorkbench().getDisplay().getActiveShell(); - MessageDialog.openError(s, "Gcov Error", message); - return; - } - CovView.displayCovResults(binary); - } - - private static String getBinary(IResource binary, String target) { - if (binary.getLocation().toOSString().contains( target ) && binary.getLocation().lastSegment().contains(binary.getProject().getName())) { - return binary.getLocation().toOSString(); + final static String DATA_DIR = "/data/"; + + static public void run(IProject project) { + // null check project + if (project == null || !project.exists()) { + final String message = "Please select a project."; + Shell s = PlatformUI.getWorkbench().getDisplay().getActiveShell(); + MessageDialog.openInformation(s, "Project not found", message); + return; + } + + IDevice currentDevice = ConnectionPlugin.getDefault().getCurrentDevice(); + if (currentDevice == null) { + // final String message = "Target device is not running"; + // Shell s = PlatformUI.getWorkbench().getDisplay().getActiveShell(); + // MessageDialog.openError(s, "Gcov Error", message); + return; + } + + String binary = GcovHelper.getBinary(project); + if (binary == null) { + final String message = "Gcov failed. Binary file not found.\n" + + "Please check Build Settings"; + Shell s = PlatformUI.getWorkbench().getDisplay().getActiveShell(); + MessageDialog.openError(s, "Gcov Error", message); + return; + } + + try { + GcovHelper.downloadGcdaFile(binary); + } catch (Exception e) { + final String message = "Gcov failed. Coverage data file not found."; + Shell s = PlatformUI.getWorkbench().getDisplay().getActiveShell(); + MessageDialog.openError(s, "Gcov Error", message); + return; } - return null; - } - // FIXME searching a selected binary is not complete - // This part is affected IDE launch part - // TODO Fix this method - public static String getBinary(IProject project) { - String binary = null; - ICProject cproject = CoreModel.getDefault().create(project); - if (cproject == null) { - return binary; - } - IBinary[] bins = null; - try { - bins = cproject.getBinaryContainer().getBinaries(); - } catch (CModelException e) { - e.printStackTrace(); - } - - IDevice currentDevice = ConnectionPlugin.getDefault().getCurrentDevice(); - if (currentDevice.isEmulator()) { - for( IBinary bin : bins ) { - binary = getBinary( bin.getResource(), "Emulator" ); - break; - } - } else { - for( IBinary bin : bins ) { - binary = getBinary( bin.getResource(), "Device" ); - break; - } - } - return binary; - } - - static IProject getProject(IPath file) { - IFile c = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(file); - return c.getProject(); - } - - public static void downloadGcdaFile(String binaryPath) throws Exception { - CovManager cvrgeMnger = null; - List<String> gcdaPaths = null; - cvrgeMnger = new CovManager(binaryPath); - try { - gcdaPaths = cvrgeMnger.getGCDALocations(); - } catch (Exception e) { - final String message = "Gcov failed. Binary not found."; - Shell s = PlatformUI.getWorkbench().getDisplay().getActiveShell(); - MessageDialog.openError(s, "Gcov Error", message); - return; - } - // download gcda file - IPath file = new Path(binaryPath); - IProject project = getProject(file); - String targetPath = getGcdaPath(project); - - @SuppressWarnings("restriction") - IDevice currentDevice = ConnectionPlugin.getDefault().getCurrentDevice(); - @SuppressWarnings("restriction") - SyncService syncService = currentDevice.getSyncService(); - - for (String gcdaPath: gcdaPaths) { - int start = gcdaPath.lastIndexOf('/') + 1; - int end = gcdaPath.length(); - String gcdaFile = gcdaPath.substring(start, end); - String srcFile = targetPath + gcdaFile; - String dstFile = gcdaPath; - @SuppressWarnings("restriction") - SyncResult syncSuccess = syncService.pullFile(srcFile, dstFile, SyncService.getNullProgressMonitor()); - if (syncSuccess.getCode() != SyncService.RESULT_OK) { - Exception e = new Exception(); - throw e; - } - } - } - - static public String getGcdaPath(IProject project) { - String installPath = getPackageInstallPath(project); - String gcdaPath = installPath + DATA_DIR; - return gcdaPath; - } - - static String getPackageInstallPath(IProject project) { - PackageModel packageModel = PackageModel.newInstance(project); - String installPath = packageModel.getAppInstallPath(); - return installPath; - } + CovView.displayCovResults(binary); + } + + private static String getBinary(IResource binary, String target) { + if (binary.getLocation().toOSString().contains( target ) && binary.getLocation().lastSegment().contains(binary.getProject().getName())) { + return binary.getLocation().toOSString(); + } + return null; + } + // FIXME searching a selected binary is not complete + // This part is affected IDE launch part + // TODO Fix this method + public static String getBinary(IProject project) { + String binaryName = ProjectUtil.getBinaryName(project); + IConfiguration config = ProjectUtil.getDefaultConfiguration(project); + IFile binaryFile = project.getFile(config.getName() + "/" + binaryName); + + if ( binaryFile.exists() ) { + return binaryFile.getLocation().toString(); + } + else { + return null; + } + } + + static IProject getProject(IPath file) { + IFile c = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(file); + return c.getProject(); + } + + public static void downloadGcdaFile(String binaryPath) throws Exception { + CovManager cvrgeMnger = null; + List<String> gcdaPaths = new LinkedList<String>(); + cvrgeMnger = new CovManager(binaryPath); + IPath binaryFile = new Path(binaryPath); + boolean isLLVM = false; + + try { + isLLVM = cvrgeMnger.getGCDALocations(gcdaPaths); + } catch (Exception e) { + final String message = "Gcov failed. Binary not found."; + Shell s = PlatformUI.getWorkbench().getDisplay().getActiveShell(); + MessageDialog.openError(s, "Gcov Error", message); + return; + } + + IProject project = getProject(binaryFile); + + downloadGcda(gcdaPaths, binaryFile, project, isLLVM); + } + + public static void downloadGcda( List<String> gcdaPathsInGcno, IPath binaryPath, IProject project, boolean isLLVM ) throws Exception{ + String targetPath = getGcdaPath(project); + + IDevice currentDevice = ConnectionPlugin.getDefault().getCurrentDevice(); + SyncService syncService = currentDevice.getSyncService(); + String dstFile = ""; + String srcFile = ""; + + try { + for (String gcdaPath: gcdaPathsInGcno) { + if ( isLLVM ) { + dstFile = CovManager.remakeGcdaPathForLLVM(gcdaPath, binaryPath); + srcFile = targetPath + gcdaPath; + } + else { + int start = gcdaPath.lastIndexOf('/') + 1; + int end = gcdaPath.length(); + + dstFile = gcdaPath; + srcFile = targetPath + gcdaPath.substring(start, end); + } + + SyncResult syncSuccess = syncService.pullFile(srcFile, dstFile, SyncService.getNullProgressMonitor()); + if (syncSuccess.getCode() != SyncService.RESULT_OK) { + Exception e = new Exception(); + throw e; + } + } + } finally { + IOUtil.tryClose(syncService); + } + + } + + static public String getGcdaPath(IProject project) { + String installPath = getPackageInstallPath(project); + String gcdaPath = installPath + DATA_DIR; + return gcdaPath; + } + + static String getPackageInstallPath(IProject project) { + PackageModel packageModel = PackageModel.newInstance(project); + String installPath = packageModel.getAppInstallPath(); + return installPath; + } } |