# HG changeset patch
# User timkelly
# Date 1263851722 21600
# Node ID f90a80bff7529fbde6f68eb8bd1a912e54e279d3
# Parent 86c3b9a58e5c6d6fa63a973b74d9504d650456c8
Fix bug 10467. Raptor startup issues when raptor crashes or hangs.
diff -r 86c3b9a58e5c -r f90a80bff752 core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/HostOS.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/HostOS.java Mon Jan 18 15:55:22 2010 -0600
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Nokia and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Nokia - Initial API and implementation
+ *******************************************************************************/
+package com.nokia.carbide.cpp.internal.api.sdk;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+
+/**
+ * Utilities used for portability between hosts.
+ */
+public class HostOS {
+ /** Is the host Windows? */
+ public static boolean IS_WIN32 = File.separatorChar == '\\';
+ /** Is the host some Unix variant? */
+ public static boolean IS_UNIX = File.separatorChar == '/';
+ /** Executable file extension */
+ public static final String EXE_EXT = IS_WIN32 ? ".exe" : "";
+
+ /**
+ * Ensure that the executable name mentioned is canonical for the machine.
+ * This only affects Windows, currently, ensuring that an ".exe" is attached.
+ * @param executablePath
+ * @return updated path
+ */
+ public static String canonicalizeExecutableName(String executable) {
+ if (IS_WIN32) {
+ IPath executablePath = new Path(executable);
+ String ext = executablePath.getFileExtension();
+ if (ext == null) {
+ executable += EXE_EXT;
+ }
+ }
+ return executable;
+ }
+
+ /**
+ * Scan the PATH variable and see if the given binary is visible on
+ * the PATH that will be used at runtime (with the default environment and overrides).
+ * @param pathValue the expected Path
+ * @param program
+ * @return IPath if program is on PATH, else null
+ */
+ public static IPath findProgramOnPath(String program, String pathValue) {
+
+ // be sure proper path/extension are present
+ program = HostOS.canonicalizeExecutableName(program);
+
+ IPath path = null;
+
+ IPath[] pathEntries = getPathEntries(pathValue);
+ for (IPath pathEntry : pathEntries) {
+ IPath testPath = pathEntry.append(program);
+ if (testPath.toFile().exists()) {
+ path = testPath;
+ break;
+ }
+ }
+
+ return path;
+ }
+
+ /**
+ * Get the PATH entries from the given path environment value or the
+ * system environment.
+ * @param pathValue the expected PATH/Path value, or null
for the system value
+ * @return array of IPath, never null
+ */
+ private static IPath[] getPathEntries(String pathValue) {
+ String pathVar = null;
+ if (pathValue != null) {
+ pathVar = pathValue;
+ } else {
+ if (HostOS.IS_WIN32) {
+ // canonical name, plus fallback below
+ pathVar = System.getenv("Path"); //$NON-NLS-1$
+ }
+ if (pathVar == null) {
+ pathVar = System.getenv("PATH"); //$NON-NLS-1$
+ }
+ }
+
+ if (pathVar == null)
+ pathVar = "";
+
+ String pathSeparator = System.getProperty("path.separator");
+ String[] pathEntries = pathVar.split(pathSeparator);
+ IPath[] paths = new IPath[pathEntries.length];
+ for (int i = 0; i < pathEntries.length; i++) {
+ paths[i] = new Path(pathEntries[i]);
+ }
+ return paths;
+ }
+
+
+}
diff -r 86c3b9a58e5c -r f90a80bff752 core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SBSv2Utils.java
--- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SBSv2Utils.java Mon Jan 18 14:38:14 2010 -0600
+++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SBSv2Utils.java Mon Jan 18 15:55:22 2010 -0600
@@ -14,20 +14,29 @@
import java.io.File;
import java.io.FileFilter;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.eclipse.cdt.utils.spawner.EnvironmentReader;
import org.eclipse.core.filesystem.URIUtil;
-import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Preferences;
import org.osgi.framework.Version;
-import org.w3c.dom.*;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.DefaultHandler;
-import com.nokia.carbide.cpp.sdk.core.*;
+import com.nokia.carbide.cpp.sdk.core.ISymbianBuildContext;
+import com.nokia.carbide.cpp.sdk.core.ISymbianSDK;
+import com.nokia.carbide.cpp.sdk.core.SDKCorePlugin;
import com.nokia.cpp.internal.api.utils.core.FileUtils;
import com.nokia.cpp.internal.api.utils.core.Logging;
@@ -40,6 +49,13 @@
private static final String SBSV2_FILTERED_CONFIGS_STORE = "sbsv2FilteredConfigs"; //$NON-NLS-1$
private static final String SBSV2_FILTERED_CONFIGS_DELIMETER = ";"; //$NON-NLS-1$
+ protected static String sbsHome;
+ protected static IPath sbsPath;
+
+ private static boolean scannedSbsState = false;
+ private static final String sbsScriptName = "sbs.bat";
+ protected static final String SBS_HOME = "SBS_HOME";
+
private static List unfilteredSBSv2ConfigNames;
@@ -276,4 +292,35 @@
}
}
}
+
+ /**
+ * (Re-)scan the SBSv2 / Raptor configuration
+ * @return message if error, else null
+ **/
+ public static String scanSBSv2() {
+ // do some basic checks
+ sbsHome = System.getenv(SBS_HOME);
+ if (sbsHome == null) {
+ return "Please define the SBS_HOME environment (e.g. /path/to/raptor) and add $SBS_HOME/bin to your PATH before running Carbide.";
+ }
+
+ sbsPath = HostOS.findProgramOnPath(sbsScriptName, null);
+ if (sbsPath == null) {
+ return "Please add $SBS_HOME/bin to your PATH before running Carbide.";
+ }
+
+ return null;
+ }
+
+ /**
+ * Get the path to SBSv2 (sbs.bat or sbs)
+ **/
+ public static IPath getSBSPath() {
+ if (!scannedSbsState) {
+ scanSBSv2();
+ scannedSbsState = true;
+ }
+ return sbsPath != null ? sbsPath : new Path(sbsScriptName);
+ }
+
}
diff -r 86c3b9a58e5c -r f90a80bff752 core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/model/SDKManager.java
--- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/model/SDKManager.java Mon Jan 18 14:38:14 2010 -0600
+++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/model/SDKManager.java Mon Jan 18 15:55:22 2010 -0600
@@ -60,6 +60,7 @@
import com.nokia.carbide.cpp.internal.api.sdk.BuildPlat;
import com.nokia.carbide.cpp.internal.api.sdk.ICarbideDevicesXMLChangeListener;
import com.nokia.carbide.cpp.internal.api.sdk.ISDKManagerInternal;
+import com.nokia.carbide.cpp.internal.api.sdk.SBSv2Utils;
import com.nokia.carbide.cpp.internal.api.sdk.SDKManagerInternalAPI;
import com.nokia.carbide.cpp.internal.api.sdk.SymbianMacroStore;
import com.nokia.carbide.cpp.internal.sdk.core.gen.Devices.DeviceType;
@@ -77,7 +78,6 @@
import com.nokia.cpp.internal.api.utils.core.Logging;
import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils;
import com.sun.org.apache.xpath.internal.XPathAPI;
-import com.sun.org.apache.xpath.internal.operations.Minus;
public class SDKManager implements ISDKManager, ISDKManagerInternal {
@@ -964,16 +964,30 @@
sbsV2Version = new Version(0, 0, 0);
Runtime rt=Runtime.getRuntime();
+ IPath sbsPath = SBSv2Utils.getSBSPath();
+ Process p = null;
try {
- Process p = rt.exec("sbs.bat -v");
+
+ p = rt.exec(new String[] { sbsPath.toOSString(), "-v" });
+ }
+ catch (IOException e) {
+ // no such process, SBSv2 not available
+ Logging.log(SDKCorePlugin.getDefault(), Logging.newSimpleStatus(0, IStatus.WARNING,
+ MessageFormat.format("Could not find or launch Raptor script ''{0}''; SBSv2 support will not be available",
+ sbsPath), e));
+ }
+ if (p != null) {
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String overallOutput = null;
String stdErrLine = null;
- while ((stdErrLine = br.readLine()) != null) {
- overallOutput += stdErrLine;
+ try {
+ while ((stdErrLine = br.readLine()) != null) {
+ overallOutput += stdErrLine;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
}
-
if (overallOutput != null) {
{
String[] tokens = overallOutput.split(" ");
@@ -1001,13 +1015,9 @@
}
p.destroy();
+ }
}
}
- } catch (IOException e) {
- e.printStackTrace();
- }
-
-
}
return sbsV2Version;