Skip to content

Commit

Permalink
IEP-1230, IEP-1231: ESP-IDF Version Switching and build impact (#964)
Browse files Browse the repository at this point in the history
* fix for active build and redundant output in console for targets output

* ux improvement

* fix path handling for different formats and their comparison
  • Loading branch information
alirana01 authored May 28, 2024
1 parent 422aff6 commit 9c3dd8a
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import com.espressif.idf.core.IDFConstants;
import com.espressif.idf.core.IDFCorePlugin;
import com.espressif.idf.core.IDFCorePreferenceConstants;
import com.espressif.idf.core.IDFEnvironmentVariables;
import com.espressif.idf.core.internal.CMakeConsoleWrapper;
import com.espressif.idf.core.internal.CMakeErrorParser;
import com.espressif.idf.core.logging.Logger;
Expand All @@ -90,6 +91,7 @@
import com.espressif.idf.core.util.HintsUtil;
import com.espressif.idf.core.util.IDFUtil;
import com.espressif.idf.core.util.ParitionSizeHandler;
import com.espressif.idf.core.util.ProjectDescriptionReader;
import com.espressif.idf.core.util.StringUtil;

@SuppressWarnings(value = { "restriction" })
Expand Down Expand Up @@ -285,6 +287,18 @@ private boolean isLocal() throws CoreException
public IProject[] build(int kind, Map<String, String> args, IConsole console, IProgressMonitor monitor)
throws CoreException
{
try
{
if (!buildPrechecks(console))
{
return new IProject[] { getProject() };
}
}
catch (Exception e)
{
Logger.log(e);
}

this.monitor = monitor;

Check warning on line 302 in bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java

View workflow job for this annotation

GitHub Actions / spotbugs

EI_EXPOSE_REP2

com.espressif.idf.core.build.IDFBuildConfiguration.build(int, Map, IConsole, IProgressMonitor) may expose internal representation by storing an externally mutable object into IDFBuildConfiguration.monitor
Raw output
This code stores a reference to an externally mutable object into the internal representation of the object.  If instances are accessed by untrusted code, and unchecked changes to the mutable object would compromise security or other important properties, you will need to do something different. Storing a copy of the object is better approach in many situations.
isProgressSet = false;

Expand Down Expand Up @@ -334,6 +348,41 @@ public IProject[] build(int kind, Map<String, String> args, IConsole console, IP
}
}

private boolean buildPrechecks(IConsole console) throws Exception
{
ProjectDescriptionReader projectDescriptionReader = new ProjectDescriptionReader(getProject());
String projectDescriptionIdfPath = projectDescriptionReader.getIdfPath();
Path pathPdIdfPath = Paths.get(projectDescriptionIdfPath);

if (StringUtil.isEmpty(projectDescriptionIdfPath))
{
return true;
}
IDFEnvironmentVariables idfEnvironmentVariables = new IDFEnvironmentVariables();
String envIdfPath = idfEnvironmentVariables.getEnvValue(IDFEnvironmentVariables.IDF_PATH);
Path pathEnvIdf = Paths.get(envIdfPath);

boolean samePaths = false;
if (Platform.getOS().equals(Platform.OS_WIN32))
{
samePaths = pathEnvIdf.toString().equalsIgnoreCase(pathPdIdfPath.toString());
}
else
{
samePaths = pathEnvIdf.toString().equals(pathPdIdfPath.toString());
}

if (!samePaths)
{
String outputMessage = MessageFormat.format(Messages.IDFBuildConfiguration_PreCheck_DifferentIdfPath, projectDescriptionIdfPath, envIdfPath);
console.getInfoStream().write(outputMessage);

return false;
}

return true;

Check warning on line 383 in bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java

View workflow job for this annotation

GitHub Actions / spotbugs

THROWS_METHOD_THROWS_CLAUSE_BASIC_EXCEPTION

Method lists Exception in its throws clause.
Raw output
Method lists Exception in its throws clause.
When declaring a method, the types of exceptions in the throws clause should be the most specific. Therefore, using Exception in the throws clause would force the caller to either use it in its own throws clause, or use it in a try-catch block (when it does not necessarily contain any meaningful information about the thrown exception).

For more information, see the SEI CERT ERR07-J rule [https://wiki.sei.cmu.edu/confluence/display/java/ERR07-J.+Do+not+throw+RuntimeException%2C+Exception%2C+or+Throwable].
}

private void runCmakeBuildCommand(IConsole console, IProgressMonitor monitor, IProject project, Instant start,
String generator, ConsoleOutputStream infoStream, Path buildDir)
throws CoreException, IOException, CmakeBuildException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class Messages extends NLS
public static String CMakeErrorParser_NotAWorkspaceResource;
public static String IDFBuildConfiguration_CMakeBuildConfiguration_NoToolchainFile;
public static String IDFBuildConfiguration_ParseCommand;
public static String IDFBuildConfiguration_PreCheck_DifferentIdfPath;
public static String IncreasePartitionSizeTitle;
public static String IncreasePartitionSizeMessage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ ToolsInitializationDifferentPathMessageBoxTitle=Different IDF path found in the
ToolsInitializationDifferentPathMessageBoxMessage=A different ESP-IDF path was found in the esp_idf.json.json configuration file. Do you want to install the tools in the new path or the old path? Please click on the appropriate button.\nNew Path: {0}\nOld Path: {1}
ToolsInitializationDifferentPathMessageBoxOptionYes=Use New Path
ToolsInitializationDifferentPathMessageBoxOptionNo=Use Old Path
RefreshingProjects_JobName=Refreshing Projects...
RefreshingProjects_JobName=Refreshing Projects...
IDFBuildConfiguration_PreCheck_DifferentIdfPath=The project was built using the ESP-IDF located at the {0} path.\nThe currently active ESP-IDF path in the IDE is {1}.\nPlease clean the project using "ESP-IDF:Project Clean" menu option to use the active ESP-IDF configuration.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.espressif.idf.core.util;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -37,7 +39,7 @@ public IFile getAppElfFile()

private String getAppElfFileName()
{
String appElfFileName = ""; //$NON-NLS-1$
String appElfFileName = StringUtil.EMPTY;
try
{
String buildDir = IDFUtil.getBuildDir(project);
Expand All @@ -52,4 +54,26 @@ private String getAppElfFileName()

return appElfFileName;
}

public String getIdfPath()
{
String idfPath = StringUtil.EMPTY;
try
{
String buildDir = IDFUtil.getBuildDir(project);
String filePath = buildDir + File.separator + IDFConstants.PROECT_DESCRIPTION_JSON;
if (Files.notExists(Paths.get(filePath)))
{
return idfPath;
}
GenericJsonReader jsonReader = new GenericJsonReader(filePath);
idfPath = jsonReader.getValue("idf_path"); //$NON-NLS-1$
}
catch (CoreException e)
{
Logger.log(e);
}

return idfPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ protected IStatus runCommandIdfPyInIdfEnv(List<String> arguments, MessageConsole
while ((line = reader.readLine()) != null)
{
output.append(line).append(System.lineSeparator());
console.println(line);
}

while (process.isAlive() && waitCount > 0)
Expand Down

0 comments on commit 9c3dd8a

Please sign in to comment.