diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java index db14e3ec1..d5b2f05dd 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java @@ -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; @@ -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" }) @@ -285,6 +287,18 @@ private boolean isLocal() throws CoreException public IProject[] build(int kind, Map args, IConsole console, IProgressMonitor monitor) throws CoreException { + try + { + if (!buildPrechecks(console)) + { + return new IProject[] { getProject() }; + } + } + catch (Exception e) + { + Logger.log(e); + } + this.monitor = monitor; isProgressSet = false; @@ -334,6 +348,41 @@ public IProject[] build(int kind, Map 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; + } + private void runCmakeBuildCommand(IConsole console, IProgressMonitor monitor, IProject project, Instant start, String generator, ConsoleOutputStream infoStream, Path buildDir) throws CoreException, IOException, CmakeBuildException diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/Messages.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/Messages.java index 5c0190d7e..a38a424aa 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/Messages.java +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/Messages.java @@ -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; diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/messages.properties b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/messages.properties index 0848f9106..bc44bce0c 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/messages.properties +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/messages.properties @@ -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... \ No newline at end of file +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. diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/ProjectDescriptionReader.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/ProjectDescriptionReader.java index 42f4c430d..947b36a81 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/ProjectDescriptionReader.java +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/ProjectDescriptionReader.java @@ -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; @@ -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); @@ -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; + } } diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsJob.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsJob.java index 9b965dbca..52acd16b8 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsJob.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsJob.java @@ -362,7 +362,6 @@ protected IStatus runCommandIdfPyInIdfEnv(List arguments, MessageConsole while ((line = reader.readLine()) != null) { output.append(line).append(System.lineSeparator()); - console.println(line); } while (process.isAlive() && waitCount > 0)