From 098e0bf7ddf2a72bade9aa34925c4a87455809c5 Mon Sep 17 00:00:00 2001 From: "jm.jaemin.kim" Date: Thu, 20 Mar 2014 15:57:32 +0900 Subject: [PATCH] BUILD: support to pass build environment to build process The IDE have ignored build environment when building a project. Now pass build environment to build process when environment is set by user. Change-Id: I732044e2366bbba296639d4754d1d0f46dfac965 Signed-off-by: jm.jaemin.kim --- .../build/PlatformBuildCommandLauncher.java | 92 +++++++++++----------- .../build/PlatformProjectDependentPackager.java | 41 +++++++++- 2 files changed, 85 insertions(+), 48 deletions(-) diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/build/PlatformBuildCommandLauncher.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/build/PlatformBuildCommandLauncher.java index 9a996fb..697e09a 100644 --- a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/build/PlatformBuildCommandLauncher.java +++ b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/build/PlatformBuildCommandLauncher.java @@ -44,55 +44,55 @@ import org.tizen.nativecommon.build.ProjectTypeManager; import org.tizen.nativecommon.build.SmartBuildInterface; import org.tizen.nativeplatform.Activator; +public class PlatformBuildCommandLauncher extends CommandLauncher { + @Override + public Process execute(IPath commandPath, String[] args, String[] env, IPath changeToDirectory, + IProgressMonitor monitor) throws CoreException { -public class PlatformBuildCommandLauncher extends CommandLauncher { - @Override - public Process execute(IPath commandPath, String[] args, String[] env, - IPath changeToDirectory, IProgressMonitor monitor) throws CoreException { + Process proc = null; - Process proc = null; - - if (commandPath.toString().contains("sbi-make")) { - IProject proj = getProject(); - PlatformProjectDependentPackager packager = (PlatformProjectDependentPackager) - ProjectTypeManager.getProjectPackagerInstance(proj); - SmartBuildInterface sbi = SmartBuildInterface.getInstance(proj); - IConfiguration config = ManagedBuildManager.getBuildInfo(proj).getDefaultConfiguration(); - IPath workingPath = new Path(proj.getLocation().toOSString()); - String[] newEnvs = packager.getEnvsWithProxy(); - - String cmd = ""; - if ("clean".equals(args[0])) { - cmd = packager.getCleanCmd(config); + if (commandPath.toString().contains("sbi-make")) { + IProject proj = getProject(); + PlatformProjectDependentPackager packager = (PlatformProjectDependentPackager) ProjectTypeManager + .getProjectPackagerInstance(proj); + SmartBuildInterface sbi = SmartBuildInterface.getInstance(proj); + IConfiguration config = ManagedBuildManager.getBuildInfo(proj) + .getDefaultConfiguration(); + IPath workingPath = new Path(proj.getLocation().toOSString()); + String[] new_envs = packager.getEnvironment(config); + String cmd = ""; + if ("clean".equals(args[0])) { + cmd = packager.getCleanCmd(config); } else { - cmd = packager.getBuildPackageCmd(config); + cmd = packager.getBuildPackageCmd(config); + } + if (cmd == null || cmd.isEmpty()) { + Status status = new Status(Status.ERROR, Activator.PLUGIN_ID, + "Failed to build the project", null); + throw new CoreException(status); } - if (cmd == null || cmd.isEmpty()) { - Status status = new Status(Status.ERROR, Activator.PLUGIN_ID, - "Failed to build the project", null); - throw new CoreException(status); - } - - String[] cmds = sbi.parseCommandString(cmd); - String[] argus = new String[cmds.length - 1]; - for (int i = 0; i < cmds.length - 1; i++) { - argus[i] = cmds[i + 1]; - } - - proc = super.execute(new Path(cmds[0]), argus, newEnvs, workingPath, new NullProgressMonitor()); - - if ("clean".equals(args[0])) { - proj.touch(monitor); - ProjectUtil.refreshResources(proj); - } - - } else { - proc = super.execute(commandPath, args, env, changeToDirectory, monitor); - } - - ProcessMonitorThread pmt = new ProcessMonitorThread(proc, monitor); - pmt.start(); - return proc; - } + String[] cmds = sbi.parseCommandString(cmd); + String[] argus = new String[cmds.length - 1]; + for (int i = 0; i < cmds.length - 1; i++) { + argus[i] = cmds[i + 1]; + } + + proc = super.execute(new Path(cmds[0]), argus, new_envs, workingPath, + new NullProgressMonitor()); + + if ("clean".equals(args[0])) { + proj.touch(monitor); + ProjectUtil.refreshResources(proj); + } + + } else { + proc = super.execute(commandPath, args, env, changeToDirectory, monitor); + } + + ProcessMonitorThread pmt = new ProcessMonitorThread(proc, monitor); + pmt.start(); + + return proc; + } } diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/build/PlatformProjectDependentPackager.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/build/PlatformProjectDependentPackager.java index f0ce2fa..2c3bed7 100644 --- a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/build/PlatformProjectDependentPackager.java +++ b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/build/PlatformProjectDependentPackager.java @@ -27,6 +27,16 @@ package org.tizen.nativeplatform.build; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.envvar.IEnvironmentVariable; +import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.core.resources.IProject; @@ -43,7 +53,6 @@ import org.tizen.nativeplatform.views.model.PlatformRootstrap; public class PlatformProjectDependentPackager extends CommonProjectDependentPackager { private static final String ACTION_BUILDPACKAGE = "buildpackage"; - private static final String ACTION_CHECKPKGDEPS = "checkbuilddeps"; private static final String CONSOLE_NAME = "Packaging"; private static PlatformProjectDependentPackager instance = new PlatformProjectDependentPackager(); @@ -139,7 +148,7 @@ public class PlatformProjectDependentPackager extends CommonProjectDependentPack // command "build package" from specified configuration and pkgType private void buildPackage(IConfiguration config, String pkgType) throws SBIException { String projectDir = getProjectPath(); - String[] new_envs = getEnvsWithProxy(); + String[] new_envs = getEnvironment(config); String cmd = getBuildPackageCmd(config); if (cmd == null || cmd.isEmpty()) { throw new SBIException("Failed to build the project"); @@ -147,6 +156,34 @@ public class PlatformProjectDependentPackager extends CommonProjectDependentPack sbi.actionConsole(cmd, projectDir, new_envs, CONSOLE_NAME); } + public String[] getEnvironment(IConfiguration config) { + List newEnvArray = new ArrayList(); + ICConfigurationDescription cfgDes = ManagedBuildManager + .getDescriptionForConfiguration(config); + IEnvironmentVariableManager mngr = CCorePlugin.getDefault().getBuildEnvironmentManager(); + IEnvironmentVariable[] vars = mngr.getVariables(cfgDes, true); + Map envMap = new HashMap(); + for (IEnvironmentVariable var : vars) { + envMap.put(var.getName(), var.getValue()); + } + // add proxySet variable to Map + if (PreferencesManager.isProxyUsed()) { + String[] proxyInfo = PreferencesManager.getProxyParsedURL(); + if (proxyInfo != null) { + String protocol = proxyInfo[0]; + String host = proxyInfo[1]; + String port = proxyInfo[2]; + String envKey = String.format("%s_proxy", protocol); + String envValue = String.format("%s://%s:%s", protocol, host, port); + envMap.put(envKey, envValue); + } + } + for (Entry entry : envMap.entrySet()) { + newEnvArray.add(String.format("%s=%s", entry.getKey(), entry.getValue())); + } + return newEnvArray.toArray(new String[0]); + } + public String getCleanCmd(IConfiguration config) { String targetId = getTargetID(config); IPath configPath = project.getLocation().append(config.getName()); -- 2.7.4