Skip to content

Commit 8975138

Browse files
authored
IEP-1472 Custom build folder: Whitespace in build folder path lead to error (#1193)
* feat: add separate field for build folder
1 parent 5f89823 commit 8975138

File tree

17 files changed

+203
-118
lines changed

17 files changed

+203
-118
lines changed

bundles/com.espressif.idf.core/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Bundle-ClassPath: .,
6363
lib/commons-text-1.10.0.jar,
6464
lib/commons-compress-1.21.jar,
6565
lib/xz-1.9.jar
66-
Import-Package: org.eclipse.embedcdt.core,
66+
Import-Package: org.eclipse.cdt.debug.core.launch,
67+
org.eclipse.embedcdt.core,
6768
org.eclipse.launchbar.ui.target,
6869
org.eclipse.ui.console

bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.util.List;
3030
import java.util.Map;
3131
import java.util.Objects;
32-
import java.util.stream.Stream;
3332

3433
import org.eclipse.cdt.build.gcc.core.ClangToolChain;
3534
import org.eclipse.cdt.cmake.core.ICMakeToolChainFile;
@@ -67,7 +66,6 @@
6766
import org.eclipse.core.runtime.jobs.Job;
6867
import org.eclipse.debug.core.DebugPlugin;
6968
import org.eclipse.debug.core.ILaunchConfiguration;
70-
import org.eclipse.debug.core.ILaunchManager;
7169
import org.eclipse.debug.core.ILaunchMode;
7270
import org.eclipse.launchbar.core.ILaunchBarManager;
7371
import org.eclipse.launchbar.core.target.ILaunchTarget;
@@ -85,6 +83,7 @@
8583
import com.espressif.idf.core.util.DfuCommandsUtil;
8684
import com.espressif.idf.core.util.HintsUtil;
8785
import com.espressif.idf.core.util.IDFUtil;
86+
import com.espressif.idf.core.util.LaunchUtil;
8887
import com.espressif.idf.core.util.LspService;
8988
import com.espressif.idf.core.util.ParitionSizeHandler;
9089
import com.espressif.idf.core.util.ProjectDescriptionReader;
@@ -113,7 +112,6 @@ public class IDFBuildConfiguration extends CBuildConfiguration
113112
* To work around that, we run cmake in advance with its dedicated working error parser.
114113
*/
115114
private ICMakeToolChainFile toolChainFile;
116-
private String customBuildDir;
117115
private IProgressMonitor monitor;
118116
public boolean isProgressSet;
119117

@@ -158,43 +156,12 @@ public IContainer getBuildContainer() throws CoreException
158156

159157
public IPath getBuildContainerPath() throws CoreException
160158
{
161-
if (hasCustomBuild())
159+
org.eclipse.core.runtime.Path path = new org.eclipse.core.runtime.Path(IDFUtil.getBuildDir(getProject()));
160+
if (!path.toFile().exists())
162161
{
163-
org.eclipse.core.runtime.Path path = new org.eclipse.core.runtime.Path(customBuildDir);
164-
if (!path.toFile().exists())
165-
{
166-
path.toFile().mkdirs();
167-
}
168-
return path;
169-
}
170-
171-
return getBuildContainer().getLocation();
172-
}
173-
174-
private boolean hasCustomBuild()
175-
{
176-
String userArgs = getProperty(CMAKE_ARGUMENTS);
177-
// Custom build directory
178-
String[] cmakeArgumentsArr = userArgs.split(" "); //$NON-NLS-1$
179-
customBuildDir = StringUtil.EMPTY;
180-
for (int i = 0; i < cmakeArgumentsArr.length; i++)
181-
{
182-
if (cmakeArgumentsArr[i].equals("-B")) //$NON-NLS-1$
183-
{
184-
customBuildDir = cmakeArgumentsArr[i + 1];
185-
break;
186-
}
187-
}
188-
try
189-
{
190-
IDFUtil.setBuildDir(getProject(), customBuildDir);
191-
}
192-
catch (CoreException e)
193-
{
194-
Logger.log(e);
162+
path.toFile().mkdirs();
195163
}
196-
197-
return !customBuildDir.isBlank();
164+
return path;
198165
}
199166

200167
@Override
@@ -232,7 +199,8 @@ public String getProperty(String name)
232199
if (configuration != null
233200
&& configuration.getType().getIdentifier().equals(IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE))
234201
{
235-
configuration = getBoundConfiguration(configuration);
202+
configuration = new LaunchUtil(DebugPlugin.getDefault().getLaunchManager())
203+
.getBoundConfiguration(configuration);
236204
}
237205
String property = configuration == null ? StringUtil.EMPTY
238206
: configuration.getAttribute(name, StringUtil.EMPTY);
@@ -247,22 +215,6 @@ public String getProperty(String name)
247215
return super.getProperty(name);
248216
}
249217

250-
/*
251-
* In case when the active configuration is debugging, we are using bound launch configuration to build the project
252-
*/
253-
private ILaunchConfiguration getBoundConfiguration(ILaunchConfiguration configuration) throws CoreException
254-
{
255-
String bindedLaunchConfigName = configuration.getAttribute(IDFLaunchConstants.ATTR_LAUNCH_CONFIGURATION_NAME,
256-
StringUtil.EMPTY);
257-
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
258-
ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(DebugPlugin.getDefault()
259-
.getLaunchManager().getLaunchConfigurationType(IDFLaunchConstants.RUN_LAUNCH_CONFIG_TYPE));
260-
ILaunchConfiguration defaultConfiguration = launchConfigurations[0];
261-
return Stream.of(launchConfigurations).filter(config -> config.getName().contentEquals(bindedLaunchConfigName))
262-
.findFirst().orElse(defaultConfiguration);
263-
264-
}
265-
266218
private IBinary[] getBuildOutput(final IBinaryContainer binaries, final IPath outputPath) throws CoreException
267219
{
268220
return Arrays.stream(binaries.getBinaries()).filter(b -> b.isExecutable() && outputPath.isPrefixOf(b.getPath()))

bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFLaunchConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ public final class IDFLaunchConstants
1717
public static final String IDF_TARGET_TYPE = "com.espressif.idf.launch.serial.core.serialFlashTarget"; //$NON-NLS-1$
1818
public static final String OPEN_SERIAL_MONITOR = "OPEN_SERIAL_MONITOR"; //$NON-NLS-1$
1919
public static final String SERIAL_MONITOR_ENCODING = "SERIAL_MONITOR_ENCODING"; //$NON-NLS-1$
20+
public static final String BUILD_FOLDER_PATH = "com.espressif.idf.launch.serial.core.idfBuildFolderPath"; //$NON-NLS-1$
2021
}

bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IDFUtil.java

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.stream.Stream;
1919

2020
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
21+
import org.eclipse.cdt.debug.core.launch.CoreBuildLaunchConfigDelegate;
2122
import org.eclipse.core.resources.IProject;
2223
import org.eclipse.core.resources.IResource;
2324
import org.eclipse.core.runtime.CoreException;
@@ -31,6 +32,7 @@
3132
import org.eclipse.core.runtime.preferences.IScopeContext;
3233
import org.eclipse.core.runtime.preferences.InstanceScope;
3334
import org.eclipse.debug.core.ILaunchConfiguration;
35+
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
3436
import org.eclipse.launchbar.core.ILaunchBarManager;
3537
import org.eclipse.launchbar.core.target.ILaunchTarget;
3638
import org.eclipse.swt.widgets.Display;
@@ -46,6 +48,7 @@
4648
import com.espressif.idf.core.LaunchBarTargetConstants;
4749
import com.espressif.idf.core.ProcessBuilderFactory;
4850
import com.espressif.idf.core.SystemExecutableFinder;
51+
import com.espressif.idf.core.build.IDFLaunchConstants;
4952
import com.espressif.idf.core.logging.Logger;
5053
import com.espressif.idf.core.toolchain.ESPToolChainManager;
5154

@@ -560,6 +563,46 @@ public static void setBuildDir(IProject project, String pathToBuildDir) throws C
560563
pathToBuildDir);
561564
}
562565

566+
/**
567+
* Updates the build folder for the specified project in the given launch configuration.
568+
*
569+
* This method retrieves the project associated with the given launch configuration, checks if a build folder path
570+
* is specified in the configuration, and sets the build directory for the project. If no build folder path is
571+
* specified, a default value is used. If the specified path is relative, it is converted to an absolute path based
572+
* on the project's location.
573+
*
574+
* @param configuration The launch configuration whose associated project’s build folder is to be updated. This
575+
* parameter cannot be {@code null}.
576+
* @throws CoreException If there is an issue with accessing the project or updating the build folder. This
577+
* exception is logged, but not rethrown.
578+
*/
579+
public static void updateProjectBuildFolder(ILaunchConfigurationWorkingCopy configuration)
580+
{
581+
try
582+
{
583+
IProject project = CoreBuildLaunchConfigDelegate.getProject(configuration);
584+
if (project == null)
585+
{
586+
return;
587+
}
588+
String buildFolder = configuration.getAttribute(IDFLaunchConstants.BUILD_FOLDER_PATH,
589+
IDFUtil.getBuildDir(project));
590+
buildFolder = buildFolder.isBlank() ? IDFConstants.BUILD_FOLDER : buildFolder;
591+
592+
IPath path = new Path(buildFolder);
593+
if (!path.isAbsolute())
594+
{
595+
IPath projectLocation = project.getLocation();
596+
path = projectLocation.append(path);
597+
}
598+
IDFUtil.setBuildDir(project, path.toOSString());
599+
}
600+
catch (CoreException e)
601+
{
602+
Logger.log(e);
603+
}
604+
}
605+
563606
/**
564607
* Project .map file path
565608
*
@@ -765,7 +808,7 @@ public static boolean isReparseTag(File file)
765808
}
766809
return false;
767810
}
768-
811+
769812
public static String resolveEnvVariable(String path)
770813
{
771814
Pattern winEnvPattern = Pattern.compile("%(\\w+)%"); //$NON-NLS-1$
@@ -801,7 +844,7 @@ public static String resolveEnvVariable(String path)
801844
return resolvedPath.toString();
802845

803846
}
804-
847+
805848
public static Map<String, String> getSystemEnv()
806849
{
807850
Map<String, String> env = new HashMap<String, String>(System.getenv());
@@ -810,17 +853,17 @@ public static Map<String, String> getSystemEnv()
810853
env.put(IDFCorePreferenceConstants.IDF_TOOLS_PATH, idfToolsPath);
811854
return env;
812855
}
813-
856+
814857
public static String getIDFToolsPathFromPreferences()
815858
{
816859
String idfToolsPath = Platform.getPreferencesService().getString(IDFCorePlugin.PLUGIN_ID,
817860
IDFCorePreferenceConstants.IDF_TOOLS_PATH, IDFCorePreferenceConstants.IDF_TOOLS_PATH_DEFAULT, null);
818861
return idfToolsPath;
819862
}
820-
863+
821864
public static void closeWelcomePage(IWorkbenchWindow activeww)
822865
{
823-
Display.getDefault().syncExec(()-> {
866+
Display.getDefault().syncExec(() -> {
824867
if (activeww != null)
825868
{
826869
IWorkbenchPage page = activeww.getActivePage();

bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IdfCommandExecutor.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public IStatus executeReconfigure(IProject project)
5454
private IStatus runIdfReconfigureCommand(IProject project)
5555
{
5656
ProcessBuilderFactory processRunner = new ProcessBuilderFactory();
57-
setBuildFolder(project);
5857
List<String> arguments = prepareCmakeArguments(project);
5958
Map<String, String> environment = new HashMap<>(new IDFEnvironmentVariables().getSystemEnvMap());
6059

@@ -97,32 +96,6 @@ private List<String> prepareCmakeArguments(IProject project)
9796
return arguments;
9897
}
9998

100-
private boolean setBuildFolder(IProject project)
101-
{
102-
String userArgs = getProperty(CMAKE_ARGUMENTS);
103-
// Custom build directory
104-
String[] cmakeArgumentsArr = userArgs.split(" "); //$NON-NLS-1$
105-
String customBuildDir = StringUtil.EMPTY;
106-
for (int i = 0; i < cmakeArgumentsArr.length; i++)
107-
{
108-
if (cmakeArgumentsArr[i].equals("-B")) //$NON-NLS-1$
109-
{
110-
customBuildDir = cmakeArgumentsArr[i + 1];
111-
break;
112-
}
113-
}
114-
try
115-
{
116-
IDFUtil.setBuildDir(project, customBuildDir);
117-
}
118-
catch (CoreException e)
119-
{
120-
Logger.log(e);
121-
}
122-
123-
return !customBuildDir.isBlank();
124-
}
125-
12699
public String getProperty(String name)
127100
{
128101
try

bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/LaunchUtil.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44
*******************************************************************************/
55
package com.espressif.idf.core.util;
66

7+
import java.util.stream.Stream;
8+
79
import org.eclipse.core.resources.IProject;
810
import org.eclipse.core.resources.IResource;
911
import org.eclipse.core.runtime.CoreException;
12+
import org.eclipse.debug.core.DebugPlugin;
1013
import org.eclipse.debug.core.ILaunchConfiguration;
1114
import org.eclipse.debug.core.ILaunchManager;
1215
import org.eclipse.launchbar.core.ILaunchDescriptor;
1316

17+
import com.espressif.idf.core.build.IDFLaunchConstants;
18+
1419
public class LaunchUtil
1520
{
1621
private final ILaunchManager launchManager;
@@ -36,4 +41,19 @@ public ILaunchConfiguration findAppropriateLaunchConfig(ILaunchDescriptor descri
3641
return null;
3742
}
3843

44+
/*
45+
* In case when the active configuration is debugging, we are using bound launch configuration to build the project
46+
*/
47+
public ILaunchConfiguration getBoundConfiguration(ILaunchConfiguration configuration) throws CoreException
48+
{
49+
String bindedLaunchConfigName = configuration.getAttribute(IDFLaunchConstants.ATTR_LAUNCH_CONFIGURATION_NAME,
50+
StringUtil.EMPTY);
51+
ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(DebugPlugin.getDefault()
52+
.getLaunchManager().getLaunchConfigurationType(IDFLaunchConstants.RUN_LAUNCH_CONFIG_TYPE));
53+
ILaunchConfiguration defaultConfiguration = launchConfigurations[0];
54+
return Stream.of(launchConfigurations).filter(config -> config.getName().contentEquals(bindedLaunchConfigName))
55+
.findFirst().orElse(defaultConfiguration);
56+
57+
}
58+
3959
}

bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabGroupLaunchConfiguration.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@
1414

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

17+
import org.eclipse.core.runtime.CoreException;
18+
import org.eclipse.debug.core.DebugPlugin;
19+
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
1720
import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
1821
import org.eclipse.debug.ui.CommonTab;
1922
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
2023
import org.eclipse.debug.ui.ILaunchConfigurationTab;
2124
import org.eclipse.debug.ui.sourcelookup.SourceLookupTab;
2225

26+
import com.espressif.idf.core.logging.Logger;
27+
import com.espressif.idf.core.util.IDFUtil;
28+
import com.espressif.idf.core.util.LaunchUtil;
29+
2330
public class TabGroupLaunchConfiguration extends AbstractLaunchConfigurationTabGroup
2431
{
2532

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

4047
TabStartup tabStartup = new TabStartup();
41-
48+
4249
ILaunchConfigurationTab tabs[] = new ILaunchConfigurationTab[] { new TabMain(), new TabDebugger(tabStartup),
4350
tabStartup, new SourceLookupTab(), new CommonTab(), new TabSvdTarget() };
4451

4552
setTabs(tabs);
4653

4754
}
4855

56+
@Override
57+
public void performApply(ILaunchConfigurationWorkingCopy configuration)
58+
{
59+
super.performApply(configuration);
60+
try
61+
{
62+
IDFUtil.updateProjectBuildFolder(new LaunchUtil(DebugPlugin.getDefault().getLaunchManager())
63+
.getBoundConfiguration(configuration).getWorkingCopy());
64+
}
65+
catch (CoreException e)
66+
{
67+
Logger.log(e);
68+
}
69+
70+
}
71+
4972
}

bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/CMakeMainTab2.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.stream.Collectors;
2626
import java.util.stream.Stream;
2727

28+
import org.eclipse.cdt.cmake.core.internal.CMakeBuildConfiguration;
2829
import org.eclipse.cdt.core.CCorePlugin;
2930
import org.eclipse.cdt.core.model.CModelException;
3031
import org.eclipse.cdt.core.model.CoreModel;
@@ -483,6 +484,13 @@ public boolean isValid(ILaunchConfiguration launchConfig)
483484
{
484485
hasProject = launchConfig.getMappedResources() != null
485486
&& launchConfig.getMappedResources()[0].getProject().exists();
487+
// Manually check for "-B" in cmakeArgs here because CMakeBuildTab2's isValid() method is not being called
488+
String cmakeArgs = launchConfig.getAttribute(CMakeBuildConfiguration.CMAKE_ARGUMENTS, StringUtil.EMPTY);
489+
if (cmakeArgs.contains("-B")) //$NON-NLS-1$
490+
{
491+
setErrorMessage(Messages.CMakeMainTab2_CmakeArgsDeprecatedBArgMessage);
492+
return false;
493+
}
486494
}
487495
catch (CoreException e)
488496
{

bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class Messages extends NLS
3030
public static String NewSerialFlashTargetWizardPage_Title;
3131
public static String CMakeMainTab2_FlashComboLbl;
3232
public static String CMakeMainTab2_Arguments;
33+
public static String CMakeMainTab2_CmakeArgsDeprecatedBArgMessage;
3334
public static String CMakeMainTab2_NoDfuTargetSelectedError;
3435
public static String CMakeMainTab2_Note;
3536
public static String CMakeMainTab2_TargetsComboLbl;

0 commit comments

Comments
 (0)