Skip to content

Commit

Permalink
profiling: add tool path settings in project properity for profiling
Browse files Browse the repository at this point in the history
tools
  • Loading branch information
zhangzegang committed Jun 27, 2023
1 parent 2c9fc6f commit ba74365
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui;bundle-version="3.7.0",
org.eclipse.linuxtools.profiling.launch;bundle-version="0.10.0",
org.eclipse.core.filesystem;bundle-version="1.3.100",
com.jcraft.jsch
com.jcraft.jsch,
org.eclipse.core.variables;bundle-version="3.5.100"
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.linuxtools.tools.launch.core,org.eclipse.l
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
public interface LaunchCoreConstants {
String PLUGIN_ID = "org.eclipse.linuxtools.tools.launch.core"; //$NON-NLS-1$
String LINUXTOOLS_PATH_NAME = LaunchCoreConstants.PLUGIN_ID + ".LinuxtoolsPath"; //$NON-NLS-1$
String LINUXTOOLS_PREFIX_NAME = LaunchCoreConstants.PLUGIN_ID + ".LinuxtoolsPrefix"; //$NON-NLS-1$
String LINUXTOOLS_PATH_SYSTEM_NAME = LaunchCoreConstants.PLUGIN_ID + ".LinuxtoolsSystemEnvPath"; //$NON-NLS-1$
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.variables.IStringVariableManager;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.linuxtools.profiling.launch.RemoteEnvProxyManager;
import org.eclipse.linuxtools.tools.launch.core.properties.LinuxtoolsPathProperty;

Expand All @@ -41,7 +44,9 @@ public abstract class LinuxtoolsProcessFactory {

private static final String PATH = "PATH"; //$NON-NLS-1$
private static final String PATH_EQUAL = "PATH="; //$NON-NLS-1$
private static final String SEPARATOR = ":"; //$NON-NLS-1$
private static final String SEPARATOR_WIN32 = ";"; //$NON-NLS-1$
private static final String SEPARATOR_LINUX = ":"; //$NON-NLS-1$
private static final String SEPARATOR = ":"; //$NON-NLS-1$

private String getEnvpPath(String[] envp) {
if (envp == null) {
Expand All @@ -66,7 +71,14 @@ private String getEnvpPath(String[] envp) {
* will be updated.
* @return The new environment.
*/
protected String[] updateEnvironment(String[] envp, IProject project) {
protected String[] updateEnvironment(String[] envp, IProject project) {
String separator;
if (Platform.OS_WIN32.equals(Platform.getOS())) {
separator = SEPARATOR_WIN32;
} else {
separator = SEPARATOR_LINUX;
}

String ltPath = LinuxtoolsPathProperty.getInstance().getLinuxtoolsPath(project);
String envpPath = getEnvpPath(envp);

Expand Down Expand Up @@ -96,13 +108,28 @@ protected String[] updateEnvironment(String[] envp, IProject project) {
StringBuilder newPath = new StringBuilder();
newPath.append(PATH_EQUAL);

IStringVariableManager varManager = VariablesPlugin.getDefault().getStringVariableManager();


if (ltPath != null && !ltPath.isEmpty()) {
try {
ltPath = varManager.performStringSubstitution(ltPath);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
newPath.append(ltPath);
newPath.append(SEPARATOR);
newPath.append(separator);
}
if (envpPath != null && !envpPath.isEmpty()) {
try {
envpPath = varManager.performStringSubstitution(envpPath);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
newPath.append(envpPath);
newPath.append(SEPARATOR);
newPath.append(separator);
}
if (systemPath != null && !systemPath.isEmpty()) {
newPath.append(systemPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher;
import org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy;
import org.eclipse.linuxtools.profiling.launch.RemoteProxyManager;
import org.eclipse.linuxtools.tools.launch.core.properties.LinuxtoolsPathProperty;

/*
* Create process using Runtime.getRuntime().exec and prepends the
Expand Down Expand Up @@ -81,8 +82,15 @@ private String[] fillPathSudoCommand(String[] cmdarray, IProject project) throws
*
* @since 1.1
*/
public String whichCommand(String command, IProject project) throws IOException {
public String whichCommand(String command, IProject project) throws IOException {
String[] envp = updateEnvironment(null, project);

String ltPrefix = LinuxtoolsPathProperty.getInstance().getLinuxtoolsPrefix(project);

if (!ltPrefix.isEmpty()) {
command = ltPrefix + command;
}

try {
IRemoteFileProxy proxy = RemoteProxyManager.getInstance().getFileProxy(project);
URI whichUri;
Expand All @@ -107,7 +115,7 @@ public String whichCommand(String command, IProject project) throws IOException
}
}
if (!lines.isEmpty()) {
if (project != null && project.getLocationURI() != null) {
if (project != null && project.getLocationURI() != null) {
if (project.getLocationURI().toString()
.startsWith("rse:")) { //$NON-NLS-1$
// RSE output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class LinuxtoolsPathProperty {
private static final String LINUXTOOLS_PATH_OPTION_PATH = "path"; //$NON-NLS-1$
private static final String LINUXTOOLS_PATH_OPTION_DEFAULT = "default"; //$NON-NLS-1$
private String linuxtoolsPathDefault = ""; //$NON-NLS-1$
private String linuxtoolsPrefixDefault = ""; //$NON-NLS-1$
private boolean linuxtoolsPathSystemDefault = true;
private static LinuxtoolsPathProperty instance = null;

Expand Down Expand Up @@ -109,10 +110,33 @@ public String getLinuxtoolsPath(IProject project) {
return path;
}

public String getLinuxtoolsPrefix(IProject project) {
if (project == null) {
return ""; //$NON-NLS-1$
}

ScopedPreferenceStore store = new ScopedPreferenceStore(new ProjectScope(project),
LaunchCoreConstants.PLUGIN_ID);

String prefix = null;
if (store.contains(LaunchCoreConstants.LINUXTOOLS_PREFIX_NAME)) {
prefix = store.getString(LaunchCoreConstants.LINUXTOOLS_PREFIX_NAME);
}

if (prefix == null) {
return getLinuxtoolsPrefixDefault();
}
return prefix;
}

public String getLinuxtoolsPathDefault() {
return linuxtoolsPathDefault;
}

public String getLinuxtoolsPrefixDefault() {
return linuxtoolsPrefixDefault;
}

public boolean getLinuxtoolsPathSystemDefault() {
return linuxtoolsPathSystemDefault;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class LinuxtoolsPathPropertyPage extends PropertyPage {
{"Custom", ""}, //$NON-NLS-1$ //$NON-NLS-2$
};
private StringFieldEditor linuxtoolsPath;
private StringFieldEditor linuxtoolsPrefix;
private CustomComboFieldEditor linuxtoolsPathCombo;
private IAdaptable element = null;
private Composite result;
Expand Down Expand Up @@ -150,6 +151,17 @@ protected Control createContents(Composite parent) {
linuxtoolsPath.setPage(this);
linuxtoolsPath.setPreferenceStore(getPreferenceStore());
linuxtoolsPath.getTextControl(result).setToolTipText(Messages.LINUXTOOLS_PATH_TOOLTIP);



//Add textbox
linuxtoolsPrefix = new StringFieldEditor(LaunchCoreConstants.LINUXTOOLS_PREFIX_NAME,Messages.LINUXTOOLS_PREFIX_COMBO, result);
linuxtoolsPrefix.setPage(this);
linuxtoolsPrefix.setPreferenceStore(getPreferenceStore());
linuxtoolsPrefix.getTextControl(result).setToolTipText(Messages.LINUXTOOLS_PREFIX_TOOLTIP);

getPreferenceStore().setDefault(LaunchCoreConstants.LINUXTOOLS_PREFIX_NAME, LinuxtoolsPathProperty.getInstance().getLinuxtoolsPrefixDefault());
linuxtoolsPrefix.load();

String selected = getPreferenceStore().getString(LINUXTOOLS_PATH_COMBO_NAME);
customSelected = selected.equals(""); //$NON-NLS-1$
Expand All @@ -176,6 +188,7 @@ private void updateOptionsEnable() {
protected void performDefaults() {
if (initialized) {
linuxtoolsPath.loadDefault();
linuxtoolsPrefix.loadDefault();
linuxtoolsPathCombo.loadDefault();
customButton.setSelection(!LinuxtoolsPathProperty.getInstance().getLinuxtoolsPathSystemDefault());
systemEnvButton.setSelection(LinuxtoolsPathProperty.getInstance().getLinuxtoolsPathSystemDefault());
Expand All @@ -187,6 +200,7 @@ protected void performDefaults() {
public boolean performOk() {
if (initialized) {
linuxtoolsPath.store();
linuxtoolsPrefix.store();
linuxtoolsPathCombo.store();
getPreferenceStore().setValue(LaunchCoreConstants.LINUXTOOLS_PATH_SYSTEM_NAME, systemEnvButton.getSelection());
}
Expand All @@ -197,6 +211,7 @@ public boolean performOk() {
protected void performApply() {
if (initialized) {
linuxtoolsPath.store();
linuxtoolsPrefix.store();
linuxtoolsPathCombo.store();
getPreferenceStore().setValue(LaunchCoreConstants.LINUXTOOLS_PATH_SYSTEM_NAME, systemEnvButton.getSelection());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public class Messages extends NLS {
public static String LINUXTOOLS_PATH_CUSTOM_TOOLTIP;
public static String LINUXTOOLS_PATH_SYSTEM_ENV;
public static String LINUXTOOLS_PATH_TOOLTIP;
public static String LINUXTOOLS_PREFIX;
public static String LINUXTOOLS_PREFIX_COMBO;
public static String LINUXTOOLS_PREFIX_TOOLTIP;
public static String LINUXTOOLS_PREFIX_CUSTOM;
public static String LINUXTOOLS_PREFIX_SYSTEM_ENV;
public static String LINUXTOOLS_PREFIX_CUSTOM_TOOLTIP;


static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ LINUXTOOLS_PATH_TOOLTIP=Use ':' as Path separator
LINUXTOOLS_PATH_CUSTOM=Prepend string to PATH
LINUXTOOLS_PATH_SYSTEM_ENV=Use the System Environment PATH
LINUXTOOLS_PATH_CUSTOM_TOOLTIP=Append the selected string to the beginning of the current system Path
LINUXTOOLS_PREFIX=
LINUXTOOLS_PREFIX_COMBO=Prefix:
LINUXTOOLS_PREFIX_TOOLTIP=Add extra prefix to command such as gcov addr2line nm c++filt strings gprof, eg, prefix riscv-nuclei-elf-, command, strings will be riscv-nuclei-elf-strings
LINUXTOOLS_PREFIX_CUSTOM=
LINUXTOOLS_PREFIX_SYSTEM_ENV=
LINUXTOOLS_PREFIX_CUSTOM_TOOLTIP=

0 comments on commit ba74365

Please sign in to comment.