From: gyeongmin.ju Date: Thu, 27 Apr 2017 08:26:08 +0000 (+0900) Subject: RTSDK: change build process X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b5549a2d5b1e409776df0a82e55b293eca08aea7;p=sdk%2Fide%2Frt-ide-product.git RTSDK: change build process add build.xml file change build processor to one change sdk build script change toolchain editor to editable on build wizard Change-Id: If459f0f315d6e166945dc89baab657ccecbd1aec Signed-off-by: gyeongmin.ju --- diff --git a/package/build.linux b/package/build.linux index a0b3cda..b49943e 100755 --- a/package/build.linux +++ b/package/build.linux @@ -74,7 +74,8 @@ install() { rm -rf ${INSTALL_DIR}/rt-ide/IDE.bat rm -rf ${INSTALL_DIR}/rt-ide/eclipse.exe cp -rf ${SRCDIR}/package/addingFiles/executable/windows/win32/eclipse_32.exe ${INSTALL_DIR}/rt-ide/eclipse.exe - cp -rf ${SRCDIR}/resources/templates/* ${INSTALL_DIR}/rt-ide/resources/templates/ + cp -rf ${SRCDIR}/resources/templates/* ${INSTALL_DIR}/platforms/tizen-rt/ + cp -rf ${SRCDIR}/resources/scripts/* ${INSTALL_DIR}/rt-ide/resources/ ;; windows-64) mv ${SRCDIR}/rt-ide/tizen.rt.product/target/products/org.tizen.rt.ide/win32/win32/x86_64/* ${INSTALL_DIR} @@ -86,7 +87,8 @@ install() { rm -rf ${INSTALL_DIR}/rt-ide/IDE.bat rm -rf ${INSTALL_DIR}/rt-ide/eclipse.exe cp -rf ${SRCDIR}/package/addingFiles/executable/windows/win64/eclipse_64.exe ${INSTALL_DIR}/rt-ide/eclipse.exe - cp -rf ${SRCDIR}/resources/templates/* ${INSTALL_DIR}/rt-ide/resources/templates/ + cp -rf ${SRCDIR}/resources/templates/* ${INSTALL_DIR}/platforms/tizen-rt/ + cp -rf ${SRCDIR}/resources/scripts/* ${INSTALL_DIR}/rt-ide/resources/ ;; ubuntu-32) mv ${SRCDIR}/rt-ide/tizen.rt.product/target/products/org.tizen.rt.ide/linux/gtk/x86/* ${INSTALL_DIR} @@ -108,6 +110,11 @@ install() { echo 'copied ${SRCDIR}/resources/templates to ${INSTALL_DIR}/platforms/tizen-rt/' fi + if [ -d "${SRCDIR}/resources/scripts" ]; then + cp -rf ${SRCDIR}/resources/scripts ${INSTALL_DIR}/rt-ide/resources/ + echo 'copied ${SRCDIR}/resources/scripts to ${INSTALL_DIR}/rt-ide/resources/' + fi + cp -rf ${SRCDIR}/lib/plugins/* ${INSTALL_DIR}/rt-ide/plugins/ if [ ! -d "${INSTALL_DIR}/tools" ]; then @@ -143,6 +150,11 @@ install() { echo 'copied ${SRCDIR}/resources/templates to ${INSTALL_DIR}/platforms/tizen-rt/' fi + if [ -d "${SRCDIR}/resources/scripts" ]; then + cp -rf ${SRCDIR}/resources/scripts ${INSTALL_DIR}/rt-ide/resources/ + echo 'copied ${SRCDIR}/resources/scripts to ${INSTALL_DIR}/rt-ide/resources/' + fi + cp -rf ${SRCDIR}/lib/plugins/* ${INSTALL_DIR}/rt-ide/plugins/ if [ ! -d "${INSTALL_DIR}/tools" ]; then @@ -160,7 +172,7 @@ install() { ;; macos-64) mv ${SRCDIR}/rt-ide/tizen.rt.product/target/products/org.tizen.rt.ide/macosx/cocoa/x86_64/* ${INSTALL_DIR} - cp -rf ${SRCDIR}/resources/templates/* ${INSTALL_DIR}/rt-ide/resources/templates/ + cp -rf ${SRCDIR}/resources/templates/* ${INSTALL_DIR}/platforms/tizen-rt/ ;; esac echo "Install Finished." diff --git a/rt-ide/tizen.rt.product.plugin/resources/scripts/build.xml b/rt-ide/tizen.rt.product.plugin/resources/scripts/build.xml new file mode 100644 index 0000000..935282c --- /dev/null +++ b/rt-ide/tizen.rt.product.plugin/resources/scripts/build.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/BuildCommand.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/BuildCommand.java index f2e9a59..925f153 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/BuildCommand.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/BuildCommand.java @@ -30,7 +30,9 @@ import java.io.FileWriter; import java.io.FilenameFilter; 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.core.resources.IProject; @@ -39,8 +41,15 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tizen.rt.ide.build.BuildOption; import org.tizen.rt.ide.console.ConsoleManager; +import org.tizen.rt.ide.util.MacroUtil; import org.tizen.rt.ide.util.ProcUtil; 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; /** * LinuxCommand @@ -52,18 +61,19 @@ public class BuildCommand { private static String LINUX_BUILD_RTOS_HOME_PATH = null; - private static final String PATH_LINUX_BUILD_OS_HOME = "os"; //$NON-NLS-1$ - private static final String PATH_LINUX_BUILD_TOOLS = "os/tools"; //$NON-NLS-1$ + // private static final String PATH_LINUX_BUILD_OS_HOME = "os"; //$NON-NLS-1$ + // private static final String PATH_LINUX_BUILD_TOOLS = "os/tools"; //$NON-NLS-1$ private static final String PATH_LINUX_BUILD_OUTPUT = "build/output"; //$NON-NLS-1$ - private static final String LINUX_EXECUTE_SET_BUILD_OPTION = "./configure.sh"; //$NON-NLS-1$ - private static final String[] LINUX_EXECUTE_SETENV = new String[] {".", "./setenv.sh"}; //$NON-NLS-1$ - private static final String LINUX_EXECUTE_BUILD = "make"; //$NON-NLS-1$ + // private static final String LINUX_EXECUTE_SET_BUILD_OPTION = "./configure.sh"; //$NON-NLS-1$ + // private static final String[] LINUX_EXECUTE_SETENV = new String[] { ".", "./setenv.sh" }; //$NON-NLS-1$ + // private static final String LINUX_EXECUTE_BUILD = "make"; //$NON-NLS-1$ private static final String PROP_NAME_OPTION = "option"; //$NON-NLS-1$ private static final String PROP_NAME_BOARD = "board"; //$NON-NLS-1$ private static final String FILE_NAME_DEFCONFIG = "defconfig"; //$NON-NLS-1$ private static final String PATH_BUILD_CONFIGS = "build/configs"; //$NON-NLS-1$ + private static final String FILE_NAME_BUILD_SCRIPT = "build.xml"; //$NON-NLS-1$ private static final String FILE_NAME_BUILD_INFO = "build.info"; //$NON-NLS-1$ private static final String PROP_COMMENT_DEBUG_INFO = "TinyARA Debug information"; //$NON-NLS-1$ @@ -200,34 +210,108 @@ public class BuildCommand { return buildOptionList; } + private class BuildScript { + public String cmdStr; + public String curDir; + public boolean isShellCmd; + public String shell; + + public BuildScript(String cmdStr, String curDir, boolean isShellCmd, String shell) { + this.cmdStr = cmdStr; + this.curDir = curDir; + this.isShellCmd = isShellCmd; + this.shell = shell; + } + } + + private Map getBuildScripts(File buildScriptFile, Map macros) { + Document doc = XMLUtil.readXML(buildScriptFile); + + NodeList commands = XMLUtil.getDOMNodes(doc.getDocumentElement(), "/sbi/build/command"); + if (commands == null || commands.getLength() <= 0) { + return null; + } + + Map scripts = new HashMap(); + + 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 cmd = elm.getAttribute("command"); + cmd = MacroUtil.processMacro(cmd, macros); + String curdir = elm.getAttribute("curdir"); + curdir = MacroUtil.processMacro(curdir, macros); + String shellcmd = elm.getAttribute("shellcmd"); + boolean isShellCmd = Boolean.valueOf(shellcmd); + String shell = elm.getAttribute("shell"); + + scripts.put(name, new BuildScript(cmd, curdir, isShellCmd, shell)); + } + } + + return scripts; + } + protected int executeBuild(BuildOption buildOption, String toolchainPath, ConsoleManager consoleManager, IProgressMonitor monitor) { - String homePath = LINUX_BUILD_RTOS_HOME_PATH + File.separator + PATH_LINUX_BUILD_OS_HOME; - String toolPath = LINUX_BUILD_RTOS_HOME_PATH + File.separator + PATH_LINUX_BUILD_TOOLS; + String homePath = LINUX_BUILD_RTOS_HOME_PATH; 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); + if (!buildScriptFile.exists()) { + buildScriptFile = new File(homePath, FILE_NAME_BUILD_SCRIPT); + if (!buildScriptFile.exists()) { + return 1; + } + } + + Map macros = new HashMap(); + macros.put("PROJECT_PATH", homePath); + macros.put("BOARD", buildOption.getBoard()); + macros.put("BUILD_OPTION", buildOption.getBuildOption()); + if (toolchainPath != null && !toolchainPath.isEmpty()) { + macros.put("TOOLCHAIN_PATH", toolchainPath); + } + + consoleManager.println("Build project using " + buildScriptFile); + + Map scripts = getBuildScripts(buildScriptFile, macros); + ProcessBuilder pb = ProcUtil.genProcessBuilder(null); - int result = ProcUtil.executeProcess(pb, new String[] { LINUX_EXECUTE_SET_BUILD_OPTION, buildOption.getBoard() - + File.separator + buildOption.getBuildOption() }, - toolPath, consoleManager, resultBuildExecute); + String buildCmdName = "config"; + BuildScript script = scripts.get(buildCmdName); + if (script == null) { + consoleManager.println("Cannot found build command : " + buildCmdName); + return 1; + } + int result = ProcUtil.executeProcess(pb, new String[] { script.cmdStr }, script.isShellCmd, script.shell, + script.curDir, consoleManager, resultBuildExecute); + monitor.worked(1); if (result != 0) { return result; } if (toolchainPath != null && !toolchainPath.isEmpty()) { - result = ProcUtil.executeProcess(pb, new String[] { LINUX_EXECUTE_SETENV[0], LINUX_EXECUTE_SETENV[1], toolchainPath }, - toolPath, consoleManager, resultBuildExecute); - monitor.worked(1); - if (result != 0) { - return result; - } + buildCmdName = "buildWithToolchain"; + } else { + buildCmdName = "build"; + } + script = scripts.get(buildCmdName); + if (script == null) { + consoleManager.println("Cannot found build command : " + buildCmdName); + return 1; } + result = ProcUtil.executeProcess(pb, new String[] { script.cmdStr }, script.isShellCmd, script.shell, + script.curDir, consoleManager, resultBuildExecute); - result = ProcUtil.executeProcess(pb, new String[] { LINUX_EXECUTE_BUILD, "V=1" }, homePath, //$NON-NLS-1$ - consoleManager, resultBuildExecute); monitor.worked(1); if (result != 0) { return result; diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/FlashCommand.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/FlashCommand.java index 5a1662b..80233f2 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/FlashCommand.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/FlashCommand.java @@ -103,7 +103,7 @@ public class FlashCommand { LINUX_EXECUTE_BUILD[2] = flashOption.getFlashOption(); - int result = ProcUtil.executeProcess(null, LINUX_EXECUTE_BUILD, + int result = ProcUtil.executeProcess(null, LINUX_EXECUTE_BUILD, false, LINUX_FLASH_OPTION_PATH, consoleManager, resultFlashExecute); monitor.worked(1); diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/RtosBuildDialogPage.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/RtosBuildDialogPage.java index a26dfe2..5fae587 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/RtosBuildDialogPage.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/RtosBuildDialogPage.java @@ -43,6 +43,8 @@ import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Image; @@ -211,7 +213,12 @@ public class RtosBuildDialogPage extends WizardPage { toolchainText = new Text(composite, SWT.BORDER); toolchainText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - toolchainText.setEditable(false); + toolchainText.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + RtosBuildWizardDialog.selectionToolchain(toolchainText.getText()); + } + }); selectToolchainBtn = new Button(composite, SWT.NONE); selectToolchainBtn.setText(Messages.RtosBuildDialogPage_ToolchainButtonText); diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/RtosBuildWizardDialog.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/RtosBuildWizardDialog.java index 2f42fee..0352e3d 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/RtosBuildWizardDialog.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/RtosBuildWizardDialog.java @@ -102,7 +102,6 @@ public class RtosBuildWizardDialog extends WizardDialog { public static void selectionToolchain(String toolchain) { toolchainPath = toolchain; - } public static String getSelectionToolchain() { diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/util/ProcUtil.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/util/ProcUtil.java index 4ea79f6..84af4e1 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/util/ProcUtil.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/util/ProcUtil.java @@ -38,7 +38,7 @@ public class ProcUtil { protected static final Logger logger = LoggerFactory.getLogger(ProcUtil.class); - private static final String SHELL_COMMAND_LINUX = "/bin/bash"; //$NON-NLS-1$ + private static final String SHELL_COMMAND_LINUX = "/bin/sh"; //$NON-NLS-1$ private static final String SHELL_COMMAND_MINGW = "sh"; //$NON-NLS-1$ private static final String SHELL_COMMAND_LINUX_PARAM = "-c"; //$NON-NLS-1$ private static final String SHELL_COMMAND_WINDOW = "cmd"; //$NON-NLS-1$ @@ -47,8 +47,15 @@ public class ProcUtil { private static final String SHELL_WIN_PATH_NAME = "Path"; //$NON-NLS-1$ private static final int CMDLINEMAX = 65535; - public static String[] getCommand(String commands[], boolean isLinux) { + public static String[] getCommand(String commands[], boolean shellCmd, String shell, boolean isLinux) { + if (!shellCmd) { + return commands; + } + String[] fullCommand; + if (shell == null || shell.isEmpty()) { + shell = SHELL_COMMAND_LINUX; + } if (OSChecker.isWindows()) { if (isLinux) { @@ -69,7 +76,7 @@ public class ProcUtil { } } else { fullCommand = new String[2 + 1]; - fullCommand[0] = SHELL_COMMAND_LINUX; + fullCommand[0] = shell; fullCommand[1] = SHELL_COMMAND_LINUX_PARAM; // System.arraycopy(commands, 0, fullCommand, 2, commands.length); String st = ""; //$NON-NLS-1$ @@ -111,17 +118,20 @@ public class ProcUtil { return pb; } - public static int executeProcess(ProcessBuilder pb, String[] cmds, String curDir, ConsoleManager consoleManager, + public static int executeProcess(ProcessBuilder pb, String[] cmds, boolean isShellCmd, String shell, String curDir, ConsoleManager consoleManager, List resultBuildExecute) { - String sbiTrace = "[SBI] command : "; //$NON-NLS-1$ + String sbiTrace = "[Command]"; //$NON-NLS-1$ for (String c : cmds) { - sbiTrace += c + " "; //$NON-NLS-1$ + sbiTrace += " " + c; //$NON-NLS-1$ } logger.info(sbiTrace); + if (consoleManager != null) { + consoleManager.println(sbiTrace); + } pb = genProcessBuilder(pb); - cmds = getCommand(cmds, false); + cmds = getCommand(cmds, isShellCmd, shell, false); pb.command(cmds); pb.redirectErrorStream(true); if (curDir != null) { @@ -152,6 +162,7 @@ public class ProcUtil { proc.waitFor(); } catch (IOException e) { logger.error("IOException occurred:", e); //$NON-NLS-1$ + consoleManager.println(e.getMessage()); return -1; } catch (InterruptedException e) { logger.error(e.getMessage(), e); @@ -173,4 +184,8 @@ public class ProcUtil { return proc.exitValue(); } + public static int executeProcess(ProcessBuilder pb, String[] cmds, boolean isShellCmd, String curDir, ConsoleManager consoleManager, + List resultBuildExecute) { + return executeProcess(pb, cmds, isShellCmd, null, curDir, consoleManager, resultBuildExecute); + } }