From: hyunsik.noh Date: Wed, 30 Oct 2013 05:31:25 +0000 (+0900) Subject: Title: Add build-native for new cli X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F60%2F11560%2F2;p=sdk%2Ftools%2Fcli.git Title: Add build-native for new cli Change-Id: If17c10e6ca7ce66da501323384b5e7c4c68bc3f9 Signed-off-by: hyunsik.noh --- diff --git a/MANIFEST.MF b/MANIFEST.MF deleted file mode 100644 index 2780568..0000000 --- a/MANIFEST.MF +++ /dev/null @@ -1,5 +0,0 @@ -Manifest-Version: 1.0 -Ant-Version: Apache Ant 1.8.2 -Created-By: 1.6.0_24-b07 (Sun Microsystems Inc.) -Main-Class: org/tizen/ncli/ide/autocomplete/TizenAutoComplete - diff --git a/org.tizen.ncli.ide/META-INF/MANIFEST.MF b/org.tizen.ncli.ide/META-INF/MANIFEST.MF index 3c05fda..d67f6f1 100644 --- a/org.tizen.ncli.ide/META-INF/MANIFEST.MF +++ b/org.tizen.ncli.ide/META-INF/MANIFEST.MF @@ -9,6 +9,8 @@ Require-Bundle: org.tizen.common;bundle-version="2.0.0", org.tizen.common.verrari, org.tizen.common.verrari.realm Import-Package: + org.tizen.nativecommon.build, + org.tizen.nativecommon.build.exception, org.tizen.web.builder, org.tizen.web.builder.exception, org.tizen.web.common diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java index 5f0865c..dbad0e2 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java @@ -39,7 +39,7 @@ public class TizenAutoComplete { public static String[][] options = { {"cli-config", "--list --global"}, - {"build-native", "--predefine-option --platform --toolchain --arch"}, + {"build-native", "--predefine-option --platform --toolchain --build-target --build-configuration"}, {"build-web", "--output -opt --optimize -euf --exclude-uifw -efum --exclude-uifw-min"}, {"sign", "--profile"}, {"package", "-t --type --sign -ref --ref-project"}, diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/AbstractCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/AbstractCLI.java index 7cea7e3..4937905 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/AbstractCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/AbstractCLI.java @@ -35,36 +35,40 @@ import org.slf4j.LoggerFactory; /** * Implemented common function of CLI options + * * @author Harry Hyeongseok Heo{@literal } (S-core) */ public abstract class AbstractCLI { - protected Logger log = LoggerFactory.getLogger(getClass()); - - @Option(name="--" , metaVar="target path" , usage="Specify where is the root path for the command") + protected Logger log = LoggerFactory.getLogger(getClass()); + + @Option(name = "--", metaVar = "target path", usage = "Specify where is the root path for the command") public File targetPath; - + + @Option(name = "--current-workspace-path", metaVar = "current workspace path", usage = "Specify where is the root path for the command as a default") + public String currentWorkspacePath; + protected PrintWriter output = new PrintWriter(System.out);; - + public final void execute(String[] args) { parseArgument(args); execute(); } - + /** * @param args */ private void parseArgument(String[] args) { log.trace("Could not use parsing argument again!"); -// log.trace("parseArgument..."); -// CmdLineParser parser = new CmdLineParser(this); -// -// try { -// parser.parseArgument(args); -// } catch (CmdLineException e) { -// e.printStackTrace(); -// System.err.println("Error occurred during parsing the arguments."); -// System.exit(1); -// } + // log.trace("parseArgument..."); + // CmdLineParser parser = new CmdLineParser(this); + // + // try { + // parser.parseArgument(args); + // } catch (CmdLineException e) { + // e.printStackTrace(); + // System.err.println("Error occurred during parsing the arguments."); + // System.exit(1); + // } } public abstract void execute(); diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildNativeCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildNativeCLI.java index 61f6367..88a4dca 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildNativeCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildNativeCLI.java @@ -4,8 +4,8 @@ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: + * Hyunsik Noh * Hyeongseok Heo - * Kangho Kim * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,22 +24,53 @@ */ package org.tizen.ncli.ide.shell; +import org.kohsuke.args4j.Option; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.tizen.ncli.ide.subcommands.BuildNative; +import org.tizen.ncli.ide.subcommands.BuildNativeCLICommand; /** - * @author Harry Hyeongseok Heo{@leteral } (S-core) + * @author Hyunsik Noh{@leteral } (S-core) */ -public class BuildNativeCLI extends AbstractCLI{ +public class BuildNativeCLI extends AbstractCLI { private Logger log = LoggerFactory.getLogger(getClass()); - /* (non-Javadoc) + @Option(name = "--platform", usage = "Platform id when create new build target") + private String platform; + + @Option(name = "--toolchain", usage = "Toolchain id when create new build target") + private String toolchain; + + @Option(name = "--build-target", required = true, usage = "") + private String buildTarget; + + @Option(name = "--build-configuration", required = true, usage = "") + private String buildConfiguration; + + @Option(name = "--predefine-option", usage = "") + private String predefineOption; + + /* + * (non-Javadoc) + * * @see org.tizen.ncli.ide.shell.AbstractCLI#execute() */ @Override public void execute() { - // TODO Auto-generated method stub - + log.trace("Execute BuildWebCLI..."); + + BuildNativeCLICommand command = new BuildNativeCLICommand(); + + command.setTargetPath(targetPath); + command.setCurrentWorkspacePath(currentWorkspacePath); + command.setPlatform(platform); + command.setToolchain(toolchain); + command.setBuildTarget(buildTarget); + command.setBuildConfiguration(buildConfiguration); + command.setPredefineOption(predefineOption); + + BuildNative runCommand = command.runCommand(); } -} +} \ No newline at end of file diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/AbstractSubCommand.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/AbstractSubCommand.java index 71a1afc..9dbb5b5 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/AbstractSubCommand.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/AbstractSubCommand.java @@ -36,35 +36,41 @@ import org.tizen.ncli.ide.core.config.NCLIConfigLoader; import org.tizen.ncli.ide.core.config.TizenCLIConfigProvider; import org.tizen.ncli.ide.exec.NewCommandLineExecutor; - /** * This class provides common environment to other SubCommand. * * @author Harry Hyeongseok Heo{@literal } (S-core) */ abstract public class AbstractSubCommand { - protected final Logger log = LoggerFactory.getLogger( getClass() ); + protected final Logger log = LoggerFactory.getLogger(getClass()); protected File targetPath; - + protected String currentWorkspacePath; + /** - * @param targetPath the targetPath to set - */ - public void setTargetPath(File targetPath) { - this.targetPath = targetPath; - } + * @param targetPath + * the targetPath to set + */ + public void setTargetPath(File targetPath) { + this.targetPath = targetPath; + } + + public void setCurrentWorkspacePath(String currentWorkspacePath) { + this.currentWorkspacePath = currentWorkspacePath; + } - /** - * This method is called by CLI entry class.

- * And then call call() method. + /** + * This method is called by CLI entry class. + *

+ * And then call call() method. * * @return T * @throws Exception */ public T runCommand() { initializeConfig(); - + T ret = call(); - + return ret; } @@ -72,15 +78,16 @@ abstract public class AbstractSubCommand { * */ private void initializeConfig() { - Preference.register( "OS", new EnvironmentProvider() ); - Preference.register( "JVM", new SystemPropertiesProvider() ); + Preference.register("OS", new EnvironmentProvider()); + Preference.register("JVM", new SystemPropertiesProvider()); Preference.register(CLIConstant.TIZEN_CLI_GLOBAL_KEY, new TizenCLIConfigProvider(NCLIConfigLoader.loadGlobalConf())); Preference.register(CLIConstant.TIZEN_CLI_LOCAL_KEY, new TizenCLIConfigProvider(NCLIConfigLoader.loadLocalConf())); } - + /** - * Execute command logic - *

This method should be called only by {@link #runCommand()}
+ * Execute command logic + *

+ * This method should be called only by {@link #runCommand()}
* Do not call this directly * */ diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/BuildNative.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/BuildNative.java new file mode 100644 index 0000000..7db18ff --- /dev/null +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/BuildNative.java @@ -0,0 +1,5 @@ +package org.tizen.ncli.ide.subcommands; + +public class BuildNative { + +} diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/BuildNativeCLICommand.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/BuildNativeCLICommand.java new file mode 100644 index 0000000..2b1d9db --- /dev/null +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/BuildNativeCLICommand.java @@ -0,0 +1,129 @@ +package org.tizen.ncli.ide.subcommands; + +import java.io.File; + +import org.tizen.common.core.application.InstallPathConfig; +import org.tizen.common.util.HostUtil; +import org.tizen.common.util.StringUtil; +import org.tizen.nativecommon.build.CommonConfigurationManager; +import org.tizen.nativecommon.build.SmartBuildInterface; +import org.tizen.nativecommon.build.exception.SBIException; + +public class BuildNativeCLICommand extends AbstractSubCommand { + private String platformId; + private String toolchainId; + private String buildConfiguration; + private String predefineOption; + + private SmartBuildInterface sbi = null; + + private String idePath = null; + private String importPath = null; + private String buildPath = null; + private String buildTarget = null; + private String dataPath = null; + private String HEADLESS_CMD = "%s/eclipse -nosplash --launcher.suppressErrors -application org.eclipse.cdt.managedbuilder.core.headlessbuild " + + "-import %s " + + "-build %s " + + "-data %s " + + "-Ea CLI=true " + + "-T org.tizen.nativecpp.tool.sbi.gnu.cpp.compiler sbi.gnu.cpp.compiler.option=%s"; + + private void makeBuildCommand() { + sbi = SmartBuildInterface.getInstance(); + + if (targetPath == null) { + importPath = currentWorkspacePath; + } else { + importPath = targetPath.getAbsolutePath(); + } + + idePath = InstallPathConfig.getSDKPath() + File.separatorChar + "ide"; + + buildPath = StringUtil.getLastStringAfter(importPath, "/") + "/" + buildConfiguration; + File file = new File(buildPath); + if (!file.exists()) { + file.mkdir(); + } + dataPath = importPath + "/../" + "headless"; + + log.debug("Import Path: " + importPath); + log.debug("Ide Path: " + idePath); + log.debug("Build Path: " + buildPath); + log.debug("Data Path: " + dataPath); + } + + /* + * (non-Javadoc) + * + * @see org.tizen.ncli.ide.subcommands.AbstractSubCommand#call() + */ + @Override + protected BuildNative call() { + makeBuildCommand(); + try { + if (isValidPair(platformId, toolchainId)) { + createTarget(buildTarget, platformId, toolchainId); + } + } catch (SBIException e) { + System.out.println("[Fail] Create the build target: " + e.getMessage()); + return null; + } + + String command = String.format(HEADLESS_CMD, idePath, importPath, buildPath, dataPath, buildTarget); + System.out.println(command); + System.out.println(HostUtil.returnExecute(command)); + + return null; + } + + private boolean isValidPair(String rootstrapId, String toolchainId) throws SBIException { + if (rootstrapId == null || toolchainId == null) { + return false; + } + return ((isSameArch(rootstrapId, toolchainId)) && (supportToolchainType(rootstrapId, toolchainId))); + } + + private void createTarget(String targetId, String rootstrapId, String toolchainId) throws SBIException { + sbi.create(targetId, rootstrapId, toolchainId); + } + + private boolean isSameArch(String rootstrapId, String toolchainId) throws SBIException { + String platformArch = getPlatformArch(rootstrapId); + String toolchainArch = getToolchainArch(toolchainId); + return CommonConfigurationManager.isSameArchType(platformArch, toolchainArch); + } + + private boolean supportToolchainType(String rootstrapId, String toolchainId) throws SBIException { + String toolchainType = sbi.getToolchainTypeFromToolchainID(toolchainId); + return sbi.doesRootstrapSupportToolchainType(rootstrapId, toolchainType); + } + + private String getPlatformArch(String rootstrapId) throws SBIException { + return sbi.getArchitectureFromRootstrapID(rootstrapId); + } + + private String getToolchainArch(String toolchainId) throws SBIException { + return sbi.getArchitectureFromToolchainID(toolchainId); + } + + public void setPlatform(String platform) { + this.platformId = platform; + } + + public void setToolchain(String toolchain) { + this.toolchainId = toolchain; + } + + public void setBuildTarget(String buildTarget) { + this.buildTarget = buildTarget; + } + + public void setBuildConfiguration(String buildConfiguration) { + this.buildConfiguration = buildConfiguration; + } + + public void setPredefineOption(String predefineOption) { + this.predefineOption = predefineOption; + } +} diff --git a/org.tizen.ncli.ide/tizen.sh b/org.tizen.ncli.ide/tizen.sh index dfac996..a7bd843 100755 --- a/org.tizen.ncli.ide/tizen.sh +++ b/org.tizen.ncli.ide/tizen.sh @@ -17,6 +17,8 @@ for ARG in "$@" ; do ARGS="$ARGS $(escapeSpace $ARG)" done +ARGS="$ARGS --current-workspace-path $CURRENT_WORKSPACE_PATH" + MAIN=org.tizen.ncli.ide.shell.Main EXEC="java -cp $CLASSPATH $MAIN $ARGS"