Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bundles/com.espressif.idf.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Bundle-ClassPath: .,
lib/commons-text-1.10.0.jar,
lib/commons-compress-1.21.jar,
lib/xz-1.9.jar
Import-Package: org.eclipse.embedcdt.core,
Import-Package: org.eclipse.cdt.debug.core.launch,
org.eclipse.embedcdt.core,
org.eclipse.launchbar.ui.target,
org.eclipse.ui.console
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream;

import org.eclipse.cdt.build.gcc.core.ClangToolChain;
import org.eclipse.cdt.cmake.core.ICMakeToolChainFile;
Expand Down Expand Up @@ -67,7 +66,6 @@
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.launchbar.core.ILaunchBarManager;
import org.eclipse.launchbar.core.target.ILaunchTarget;
Expand All @@ -85,6 +83,7 @@
import com.espressif.idf.core.util.DfuCommandsUtil;
import com.espressif.idf.core.util.HintsUtil;
import com.espressif.idf.core.util.IDFUtil;
import com.espressif.idf.core.util.LaunchUtil;
import com.espressif.idf.core.util.LspService;
import com.espressif.idf.core.util.ParitionSizeHandler;
import com.espressif.idf.core.util.ProjectDescriptionReader;
Expand Down Expand Up @@ -113,7 +112,6 @@ public class IDFBuildConfiguration extends CBuildConfiguration
* To work around that, we run cmake in advance with its dedicated working error parser.
*/
private ICMakeToolChainFile toolChainFile;
private String customBuildDir;
private IProgressMonitor monitor;
public boolean isProgressSet;

Expand Down Expand Up @@ -158,43 +156,12 @@ public IContainer getBuildContainer() throws CoreException

public IPath getBuildContainerPath() throws CoreException
{
if (hasCustomBuild())
org.eclipse.core.runtime.Path path = new org.eclipse.core.runtime.Path(IDFUtil.getBuildDir(getProject()));
if (!path.toFile().exists())
{
org.eclipse.core.runtime.Path path = new org.eclipse.core.runtime.Path(customBuildDir);
if (!path.toFile().exists())
{
path.toFile().mkdirs();
}
return path;
}

return getBuildContainer().getLocation();
}

private boolean hasCustomBuild()
{
String userArgs = getProperty(CMAKE_ARGUMENTS);
// Custom build directory
String[] cmakeArgumentsArr = userArgs.split(" "); //$NON-NLS-1$
customBuildDir = StringUtil.EMPTY;
for (int i = 0; i < cmakeArgumentsArr.length; i++)
{
if (cmakeArgumentsArr[i].equals("-B")) //$NON-NLS-1$
{
customBuildDir = cmakeArgumentsArr[i + 1];
break;
}
}
try
{
IDFUtil.setBuildDir(getProject(), customBuildDir);
}
catch (CoreException e)
{
Logger.log(e);
path.toFile().mkdirs();
}

return !customBuildDir.isBlank();
return path;
}

@Override
Expand Down Expand Up @@ -232,7 +199,8 @@ public String getProperty(String name)
if (configuration != null
&& configuration.getType().getIdentifier().equals(IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE))
{
configuration = getBoundConfiguration(configuration);
configuration = new LaunchUtil(DebugPlugin.getDefault().getLaunchManager())
.getBoundConfiguration(configuration);
}
String property = configuration == null ? StringUtil.EMPTY
: configuration.getAttribute(name, StringUtil.EMPTY);
Expand All @@ -247,22 +215,6 @@ public String getProperty(String name)
return super.getProperty(name);
}

/*
* In case when the active configuration is debugging, we are using bound launch configuration to build the project
*/
private ILaunchConfiguration getBoundConfiguration(ILaunchConfiguration configuration) throws CoreException
{
String bindedLaunchConfigName = configuration.getAttribute(IDFLaunchConstants.ATTR_LAUNCH_CONFIGURATION_NAME,
StringUtil.EMPTY);
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(DebugPlugin.getDefault()
.getLaunchManager().getLaunchConfigurationType(IDFLaunchConstants.RUN_LAUNCH_CONFIG_TYPE));
ILaunchConfiguration defaultConfiguration = launchConfigurations[0];
return Stream.of(launchConfigurations).filter(config -> config.getName().contentEquals(bindedLaunchConfigName))
.findFirst().orElse(defaultConfiguration);

}

private IBinary[] getBuildOutput(final IBinaryContainer binaries, final IPath outputPath) throws CoreException
{
return Arrays.stream(binaries.getBinaries()).filter(b -> b.isExecutable() && outputPath.isPrefixOf(b.getPath()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public final class IDFLaunchConstants
public static final String IDF_TARGET_TYPE = "com.espressif.idf.launch.serial.core.serialFlashTarget"; //$NON-NLS-1$
public static final String OPEN_SERIAL_MONITOR = "OPEN_SERIAL_MONITOR"; //$NON-NLS-1$
public static final String SERIAL_MONITOR_ENCODING = "SERIAL_MONITOR_ENCODING"; //$NON-NLS-1$
public static final String BUILD_FOLDER_PATH = "com.espressif.idf.launch.serial.core.idfBuildFolderPath"; //$NON-NLS-1$
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.stream.Stream;

import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
import org.eclipse.cdt.debug.core.launch.CoreBuildLaunchConfigDelegate;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
Expand All @@ -31,6 +32,7 @@
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.launchbar.core.ILaunchBarManager;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.swt.widgets.Display;
Expand All @@ -46,6 +48,7 @@
import com.espressif.idf.core.LaunchBarTargetConstants;
import com.espressif.idf.core.ProcessBuilderFactory;
import com.espressif.idf.core.SystemExecutableFinder;
import com.espressif.idf.core.build.IDFLaunchConstants;
import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.core.toolchain.ESPToolChainManager;

Expand Down Expand Up @@ -560,6 +563,46 @@ public static void setBuildDir(IProject project, String pathToBuildDir) throws C
pathToBuildDir);
}

/**
* Updates the build folder for the specified project in the given launch configuration.
*
* This method retrieves the project associated with the given launch configuration, checks if a build folder path
* is specified in the configuration, and sets the build directory for the project. If no build folder path is
* specified, a default value is used. If the specified path is relative, it is converted to an absolute path based
* on the project's location.
*
* @param configuration The launch configuration whose associated project’s build folder is to be updated. This
* parameter cannot be {@code null}.
* @throws CoreException If there is an issue with accessing the project or updating the build folder. This
* exception is logged, but not rethrown.
*/
public static void updateProjectBuildFolder(ILaunchConfigurationWorkingCopy configuration)
{
try
{
IProject project = CoreBuildLaunchConfigDelegate.getProject(configuration);
if (project == null)
{
return;
}
String buildFolder = configuration.getAttribute(IDFLaunchConstants.BUILD_FOLDER_PATH,
IDFUtil.getBuildDir(project));
buildFolder = buildFolder.isBlank() ? IDFConstants.BUILD_FOLDER : buildFolder;

IPath path = new Path(buildFolder);
if (!path.isAbsolute())
{
IPath projectLocation = project.getLocation();
path = projectLocation.append(path);
}
IDFUtil.setBuildDir(project, path.toOSString());
}
catch (CoreException e)
{
Logger.log(e);
}
}

/**
* Project .map file path
*
Expand Down Expand Up @@ -765,7 +808,7 @@ public static boolean isReparseTag(File file)
}
return false;
}

public static String resolveEnvVariable(String path)
{
Pattern winEnvPattern = Pattern.compile("%(\\w+)%"); //$NON-NLS-1$
Expand Down Expand Up @@ -801,7 +844,7 @@ public static String resolveEnvVariable(String path)
return resolvedPath.toString();

}

public static Map<String, String> getSystemEnv()
{
Map<String, String> env = new HashMap<String, String>(System.getenv());
Expand All @@ -810,17 +853,17 @@ public static Map<String, String> getSystemEnv()
env.put(IDFCorePreferenceConstants.IDF_TOOLS_PATH, idfToolsPath);
return env;
}

public static String getIDFToolsPathFromPreferences()
{
String idfToolsPath = Platform.getPreferencesService().getString(IDFCorePlugin.PLUGIN_ID,
IDFCorePreferenceConstants.IDF_TOOLS_PATH, IDFCorePreferenceConstants.IDF_TOOLS_PATH_DEFAULT, null);
return idfToolsPath;
}

public static void closeWelcomePage(IWorkbenchWindow activeww)
{
Display.getDefault().syncExec(()-> {
Display.getDefault().syncExec(() -> {
if (activeww != null)
{
IWorkbenchPage page = activeww.getActivePage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public IStatus executeReconfigure(IProject project)
private IStatus runIdfReconfigureCommand(IProject project)
{
ProcessBuilderFactory processRunner = new ProcessBuilderFactory();
setBuildFolder(project);
List<String> arguments = prepareCmakeArguments(project);
Map<String, String> environment = new HashMap<>(new IDFEnvironmentVariables().getSystemEnvMap());

Expand Down Expand Up @@ -97,32 +96,6 @@ private List<String> prepareCmakeArguments(IProject project)
return arguments;
}

private boolean setBuildFolder(IProject project)
{
String userArgs = getProperty(CMAKE_ARGUMENTS);
// Custom build directory
String[] cmakeArgumentsArr = userArgs.split(" "); //$NON-NLS-1$
String customBuildDir = StringUtil.EMPTY;
for (int i = 0; i < cmakeArgumentsArr.length; i++)
{
if (cmakeArgumentsArr[i].equals("-B")) //$NON-NLS-1$
{
customBuildDir = cmakeArgumentsArr[i + 1];
break;
}
}
try
{
IDFUtil.setBuildDir(project, customBuildDir);
}
catch (CoreException e)
{
Logger.log(e);
}

return !customBuildDir.isBlank();
}

public String getProperty(String name)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
*******************************************************************************/
package com.espressif.idf.core.util;

import java.util.stream.Stream;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.launchbar.core.ILaunchDescriptor;

import com.espressif.idf.core.build.IDFLaunchConstants;

public class LaunchUtil
{
private final ILaunchManager launchManager;
Expand All @@ -36,4 +41,19 @@ public ILaunchConfiguration findAppropriateLaunchConfig(ILaunchDescriptor descri
return null;
}

/*
* In case when the active configuration is debugging, we are using bound launch configuration to build the project
*/
public ILaunchConfiguration getBoundConfiguration(ILaunchConfiguration configuration) throws CoreException
{
String bindedLaunchConfigName = configuration.getAttribute(IDFLaunchConstants.ATTR_LAUNCH_CONFIGURATION_NAME,
StringUtil.EMPTY);
ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(DebugPlugin.getDefault()
.getLaunchManager().getLaunchConfigurationType(IDFLaunchConstants.RUN_LAUNCH_CONFIG_TYPE));
ILaunchConfiguration defaultConfiguration = launchConfigurations[0];
return Stream.of(launchConfigurations).filter(config -> config.getName().contentEquals(bindedLaunchConfigName))
.findFirst().orElse(defaultConfiguration);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@

package com.espressif.idf.debug.gdbjtag.openocd.ui;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
import org.eclipse.debug.ui.CommonTab;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.debug.ui.sourcelookup.SourceLookupTab;

import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.core.util.IDFUtil;
import com.espressif.idf.core.util.LaunchUtil;

public class TabGroupLaunchConfiguration extends AbstractLaunchConfigurationTabGroup
{

Expand All @@ -38,12 +45,28 @@ public void createTabs(ILaunchConfigurationDialog dialog, String mode)
// we manually define the tabs here.

TabStartup tabStartup = new TabStartup();

ILaunchConfigurationTab tabs[] = new ILaunchConfigurationTab[] { new TabMain(), new TabDebugger(tabStartup),
tabStartup, new SourceLookupTab(), new CommonTab(), new TabSvdTarget() };

setTabs(tabs);

}

@Override
public void performApply(ILaunchConfigurationWorkingCopy configuration)
{
super.performApply(configuration);
try
{
IDFUtil.updateProjectBuildFolder(new LaunchUtil(DebugPlugin.getDefault().getLaunchManager())
.getBoundConfiguration(configuration).getWorkingCopy());
}
catch (CoreException e)
{
Logger.log(e);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.cdt.cmake.core.internal.CMakeBuildConfiguration;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
Expand Down Expand Up @@ -483,6 +484,13 @@ public boolean isValid(ILaunchConfiguration launchConfig)
{
hasProject = launchConfig.getMappedResources() != null
&& launchConfig.getMappedResources()[0].getProject().exists();
// Manually check for "-B" in cmakeArgs here because CMakeBuildTab2's isValid() method is not being called
String cmakeArgs = launchConfig.getAttribute(CMakeBuildConfiguration.CMAKE_ARGUMENTS, StringUtil.EMPTY);
if (cmakeArgs.contains("-B")) //$NON-NLS-1$
{
setErrorMessage(Messages.CMakeMainTab2_CmakeArgsDeprecatedBArgMessage);
return false;
}
}
catch (CoreException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class Messages extends NLS
public static String NewSerialFlashTargetWizardPage_Title;
public static String CMakeMainTab2_FlashComboLbl;
public static String CMakeMainTab2_Arguments;
public static String CMakeMainTab2_CmakeArgsDeprecatedBArgMessage;
public static String CMakeMainTab2_NoDfuTargetSelectedError;
public static String CMakeMainTab2_Note;
public static String CMakeMainTab2_TargetsComboLbl;
Expand Down
Loading
Loading