RTSDK: append debug & build meta file
authorgyeongmin.ju <gyeongmin.ju@samsung.com>
Thu, 27 Apr 2017 13:58:36 +0000 (22:58 +0900)
committergyeongmin.ju <gyeongmin.ju@samsung.com>
Thu, 27 Apr 2017 13:58:36 +0000 (22:58 +0900)
append debug meta file (debug.xml)
change build meta file order

Change-Id: I0fc861a6a95b582ec2cddb0edb20d9b9a8fbcc73
Signed-off-by: gyeongmin.ju <gyeongmin.ju@samsung.com>
resources/scripts/debug.xml [new file with mode: 0644]
rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/BuildCommand.java
rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/Messages.java
rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/launch/LaunchShortcut.java
rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/messages.properties

diff --git a/resources/scripts/debug.xml b/resources/scripts/debug.xml
new file mode 100644 (file)
index 0000000..ffe42bb
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<launch>
+       <!--
+               predefined macro values:
+               * PROJECT_PATH - current project path
+               * BOARD - selected board name
+               * SCRIPT_PATH - selected script path
+               * SCRIPT_FILE - selected script file
+       -->
+
+       <debug name="openocd" type="openocd">
+               <reqired name="scriptfile" type="file" curdir="${PROJECT_PATH}/configs/${BOARD}/scripts" filter="*.cfg" default=""/>
+
+               <execute platform="linux32" execute="${PROJECT_PATH}/build/configs/${BOARD}/tools/openocd/linux32/openocd">
+                       <param prefix="-s" value="${SCRIPT_PATH}" />
+                       <param prefix="-f" value="${SCRIPT_FILE}" />
+               </execute>
+               <execute platform="linux64" execute="${PROJECT_PATH}/build/configs/${BOARD}/tools/openocd/linux64/openocd">
+                       <param prefix="-s" value="${SCRIPT_PATH}" />
+                       <param prefix="-f" value="${SCRIPT_FILE}" />
+               </execute>
+       </debug>
+</launch>
+
index 925f153..44ae423 100644 (file)
@@ -259,13 +259,14 @@ public class BuildCommand {
     protected int executeBuild(BuildOption buildOption, String toolchainPath, ConsoleManager consoleManager,
             IProgressMonitor monitor) {
 
+        String sdkPath = SDKUtil.getSdkPath();
         String homePath = LINUX_BUILD_RTOS_HOME_PATH;
+        String boardPath = LINUX_BUILD_RTOS_HOME_PATH + File.separator + "configs" + File.separator + buildOption.getBoard();
         String outputPath = LINUX_BUILD_RTOS_HOME_PATH + File.separator + PATH_LINUX_BUILD_OUTPUT;
-
-        String sdkPath = SDKUtil.getSdkPath();
-        File buildScriptFile = new File(sdkPath, "rt-ide" + File.separator + "resources" + File.separator + "scripts" + File.separator + FILE_NAME_BUILD_SCRIPT);
+        
+        File buildScriptFile = new File(boardPath, FILE_NAME_BUILD_SCRIPT);
         if (!buildScriptFile.exists()) {
-            buildScriptFile = new File(homePath, FILE_NAME_BUILD_SCRIPT);
+            buildScriptFile = new File(sdkPath, "rt-ide" + File.separator + "resources" + File.separator + "scripts" + File.separator + FILE_NAME_BUILD_SCRIPT);
             if (!buildScriptFile.exists()) {
                 return 1;
             }
index 68445b3..6121bec 100644 (file)
@@ -70,6 +70,7 @@ public class Messages extends NLS {
     public static String RtosBuildDialogPage_lblNewLabel_text;
     public static String RtosBuildDialogPage_clearToolchainBtn_text;
 
+    public static String RtosDebug_ERROR_DEBUGSCRIPT_NOT_EXIST;
     public static String RtosDebug_ERROR_OPENOCD_NOT_EXIST;
     
     public static String RtosNewRtAppWizard_WindowTitle;
index aa6d591..0baf921 100644 (file)
@@ -30,6 +30,10 @@ import java.io.File;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 
 import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
@@ -55,7 +59,15 @@ import org.eclipse.ui.IEditorPart;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.tizen.rt.ide.Messages;
+import org.tizen.rt.ide.util.MacroUtil;
 import org.tizen.rt.ide.util.OSChecker;
+import org.tizen.rt.ide.util.ResourceUtil;
+import org.tizen.rt.ide.util.SDKUtil;
+import org.tizen.rt.ide.util.XMLUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 import ilg.gnuarmeclipse.debug.gdbjtag.openocd.ConfigurationAttributes;
 
@@ -75,23 +87,193 @@ public class LaunchShortcut implements ILaunchShortcut {
     private static final String PATH_BUILD_OUTPUT = "build/output"; //$NON-NLS-1$
     private static final String PATH_BUILD_CONFIGS = "build/configs"; //$NON-NLS-1$
     private static final String PATH_OPENOCD = "openocd"; //$NON-NLS-1$
+    private static final String PATH_OPENOCD_SCRIPT = "tools/openocd"; //$NON-NLS-1$
+    // private static final String PATH_DEBUG_OPENOCD = "tools/openocd"; //$NON-NLS-1$
     private static final String PROGRAM_NAME = PATH_BUILD_OUTPUT + "/bin/tinyara"; //$NON-NLS-1$
-    private static final String OPENOCD_EXECUTABLE_32 = "openocd_0.10_linux32_t20"; //$NON-NLS-1$
-    private static final String OPENOCD_EXECUTABLE_64 = "openocd_0.10_linux64_t20"; //$NON-NLS-1$
+    // private static final String OPENOCD_EXECUTABLE_32 = "openocd_0.10_linux32_t20"; //$NON-NLS-1$
+    // private static final String OPENOCD_EXECUTABLE_64 = "openocd_0.10_linux64_t20"; //$NON-NLS-1$
+    // private static final String OPENOCD_EXECUTABLE_32 = "linux32/openocd"; //$NON-NLS-1$
+    // private static final String OPENOCD_EXECUTABLE_64 = "linux64/openocd"; //$NON-NLS-1$
     private static final String DEBUGGER_NAME = "arm-none-eabi-gdb"; //$NON-NLS-1$
+    private static final String FILE_NAME_DEBUG_SCRIPT = "debug.xml"; //$NON-NLS-1$
 
     private final String OPENOCD_LAUNCHTYPE = "ilg.gnuarmeclipse.debug.gdbjtag.openocd.launchConfigurationType"; //$NON-NLS-1$
 
+    private class LaunchParam {
+        public String name;
+        public String prefix;
+        public String value;
+
+        public LaunchParam(String name, String prefix, String value) {
+            this.name = name;
+            this.prefix = prefix;
+            this.value = value;
+        }
+    }
+
+    private class LaunchExecute {
+        public String platform;
+        public String execute;
+        public List<LaunchParam> params;
+
+        public LaunchExecute(String platform, String execute, List<LaunchParam> params) {
+            this.platform = platform;
+            this.execute = execute;
+            this.params = params;
+        }
+
+        public String getFullParam() {
+            if (params == null) {
+                return null;
+            }
+
+            String fullParam = null;
+            for (LaunchParam param : params) {
+                if (fullParam != null && !fullParam.isEmpty()) {
+                    fullParam += " ";
+                } else {
+                    fullParam = "";
+                }
+                fullParam += param.prefix + " " + param.value;
+            }
+
+            return fullParam;
+        }
+    }
+
+    private class LaunchScript {
+        public String type;
+        public Map<String, LaunchExecute> executes;
+
+        public LaunchScript(String type, Map<String, LaunchExecute> executes) {
+            this.type = type;
+            this.executes = executes;
+        }
+
+        public LaunchExecute getExecute(String platformName) {
+            if (executes == null) {
+                return null;
+            }
+
+            return executes.get(platformName);
+        }
+    }
+
+    private Map<String, LaunchScript> getBuildScripts(File buildScriptFile, Map<String, String> macros) {
+        Document doc = XMLUtil.readXML(buildScriptFile);
+
+        NodeList commands = XMLUtil.getDOMNodes(doc.getDocumentElement(), "/launch/debug");
+        if (commands == null || commands.getLength() <= 0) {
+            return null;
+        }
+
+        Map<String, LaunchScript> scripts = new HashMap<String, LaunchScript>();
+
+        int len = commands.getLength();
+        for (int i = 0; i < len; i++) {
+            Node node = commands.item(i);
+            if (node instanceof Element) {
+                Element elm = (Element) node;
+
+                String name = elm.getAttribute("name");
+                String type = elm.getAttribute("type");
+
+                Map<String, LaunchExecute> executes = new HashMap<String, LaunchExecute>();
+
+                NodeList execNodes = XMLUtil.getDOMNodes(elm, "execute");
+                if (execNodes != null && execNodes.getLength() > 0) {
+                    int len2 = execNodes.getLength();
+                    for (int j = 0; j < len2; j++) {
+                        Node execNode = execNodes.item(j);
+                        if (execNode instanceof Element) {
+                            Element execElm = (Element) execNode;
+
+                            String platform = execElm.getAttribute("platform");
+                            String execute = execElm.getAttribute("execute");
+                            execute = MacroUtil.processMacro(execute, macros);
+                            
+                            List<LaunchParam> params = new ArrayList<LaunchParam> ();                            
+                            NodeList paramNodes = XMLUtil.getDOMNodes(execElm, "param");
+                            if (paramNodes != null && paramNodes.getLength() > 0) {
+                                int len3 = paramNodes.getLength();
+                                for (int k = 0; k < len3; k++) {
+                                    Node paramNode = paramNodes.item(k);
+                                    if (paramNode instanceof Element) {
+                                        Element paramElm = (Element) paramNode;
+                
+                                        String prefix = paramElm.getAttribute("prefix");
+                                        String value = paramElm.getAttribute("value");
+                                        value = MacroUtil.processMacro(value, macros);
+                                        
+                                        params.add(new LaunchParam(name, prefix, value));
+                                    }
+                                }
+                            }
+    
+                            executes.put(platform, new LaunchExecute(platform, execute, params));
+                        }
+                    }
+                }
+
+                scripts.put(name, new LaunchScript(type, executes));
+            }
+        }
+
+        return scripts;
+    }
+
     private ILaunchConfiguration createConfiguration(String projectName, IPath targetPath, String boardName, String debugCfg) throws CoreException {
-        String openocdPath = targetPath.toOSString() + File.separator + PATH_BUILD_CONFIGS + File.separator + boardName + File.separator + PATH_OPENOCD;
-        String openocdExec = null;
+        String sdkPath = SDKUtil.getSdkPath();
+        String homePath = ResourceUtil.getCurrentProject().getLocation().toString();
+        String boardPath = homePath + File.separator + "configs" + File.separator + boardName;
+
+        File launchScriptFile = new File(boardPath, FILE_NAME_DEBUG_SCRIPT);
+        if (!launchScriptFile.exists()) {
+            launchScriptFile = new File(sdkPath, "rt-ide" + File.separator + "resources" + File.separator + "scripts" + File.separator + FILE_NAME_DEBUG_SCRIPT);
+            if (!launchScriptFile.exists()) {
+                MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", Messages.RtosDebug_ERROR_DEBUGSCRIPT_NOT_EXIST); //$NON-NLS-1$
+                return null;
+            }
+        }
+
+        String scriptPath = new File(debugCfg).getParent();
+        debugCfg = new File(debugCfg).getName();
+
+        Map<String, String> macros = new HashMap<String, String>();
+        macros.put("PROJECT_PATH", homePath);
+        macros.put("BOARD", boardName);
+        macros.put("SCRIPT_PATH", scriptPath);
+        macros.put("SCRIPT_FILE", debugCfg);
+
+        // consoleManager.println("Launch project using " + launchScriptFile);
+
+        Map<String, LaunchScript> scripts = getBuildScripts(launchScriptFile, macros);
+        if (scripts == null) {
+            return null;
+        }
+        LaunchScript launch = scripts.get("openocd");
+        if (launch == null) {
+            return null;
+        }
+
+        String platformName;
         if (OSChecker.is64bit()) {
-            openocdExec = OPENOCD_EXECUTABLE_64;
+            platformName = "linux64";
         } else {
-            openocdExec = OPENOCD_EXECUTABLE_32;
+            platformName = "linux32";
         }
-        openocdExec = openocdPath + File.separator + openocdExec;
-        if (!new File(openocdExec).exists()) {
+        LaunchExecute openocdExec = launch.getExecute(platformName);
+
+        // String openocdPath = targetPath.toOSString() + File.separator + PATH_BUILD_CONFIGS + File.separator + boardName + File.separator + PATH_DEBUG_OPENOCD;
+        // String openocdExec = null;
+        // if (OSChecker.is64bit()) {
+        // openocdExec = OPENOCD_EXECUTABLE_64;
+        // } else {
+        // openocdExec = OPENOCD_EXECUTABLE_32;
+        // }
+        // openocdExec = openocdPath + File.separator + openocdExec;
+
+        if (!new File(openocdExec.execute).exists()) {
             MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", Messages.RtosDebug_ERROR_OPENOCD_NOT_EXIST); //$NON-NLS-1$
             return null;
         }
@@ -101,8 +283,8 @@ public class LaunchShortcut implements ILaunchShortcut {
 
         ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, manager.generateLaunchConfigurationName(targetPath.lastSegment()));
 
-        wc.setAttribute(ConfigurationAttributes.GDB_SERVER_EXECUTABLE, openocdExec);
-        wc.setAttribute(ConfigurationAttributes.GDB_SERVER_OTHER, "-f " + debugCfg); //$NON-NLS-1$
+        wc.setAttribute(ConfigurationAttributes.GDB_SERVER_EXECUTABLE, openocdExec.execute);
+        wc.setAttribute(ConfigurationAttributes.GDB_SERVER_OTHER, openocdExec.getFullParam()); // $NON-NLS-1$
 
         wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
         wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, PROGRAM_NAME);
@@ -159,7 +341,7 @@ public class LaunchShortcut implements ILaunchShortcut {
                 }
                 if (debugCfg == null || debugCfg.isEmpty()) {
                     FileDialog dialog = new FileDialog(Display.getDefault().getActiveShell(), SWT.SHEET);
-                    File home = new File(proj.getLocation().toString(), PATH_BUILD_CONFIGS + File.separator + board + File.separator + PATH_OPENOCD);
+                    File home = new File(proj.getLocation().toString(), PATH_BUILD_CONFIGS + File.separator + board + File.separator + PATH_OPENOCD_SCRIPT);
                     dialog.setFilterPath(home.toString());
                     dialog.setFilterExtensions(new String[] { "*.cfg" }); //$NON-NLS-1$
                     debugCfg = dialog.open();
index d2a3581..06abf66 100644 (file)
@@ -35,6 +35,7 @@ RtosFlashDialogPage_Title=Select a Flash option
 RtosFlashDialogPage_Description=To upload a built project to the board, use the flash function.\nSelect a Flash option.
 RtosFlashDialogPage_OptionNameColumn=Flash Options
 
+RtosDebug_ERROR_DEBUGSCRIPT_NOT_EXIST=debug.xml file must be exist
 RtosDebug_ERROR_OPENOCD_NOT_EXIST=OpenOCD must be exist
 
 RtosNewRtAppWizard_WindowTitle=New TizenRT Application