Skip to content

Commit

Permalink
IEP-1375 Master branch: unable to flash projects. (#1089)
Browse files Browse the repository at this point in the history
* fix: adding all variable from idfToolSet

* fix: making adding env variables more robust for null values

* fix: remove redundant path
  • Loading branch information
sigmaaa authored Dec 9, 2024
1 parent f9c06bb commit 1b584a3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ protected void launchInternal(ILaunchConfiguration configuration, String mode, I

// Reading CDT build environment variables
Map<String, String> envMap = new IDFEnvironmentVariables().getSystemEnvMap();

if (envMap.containsKey("PATH") && envMap.containsKey("Path")) //$NON-NLS-1$
{
envMap.remove("Path"); //$NON-NLS-1$
}
// Turn it into an envp format
List<String> strings = new ArrayList<>(envMap.size());
for (Entry<String, String> entry : envMap.entrySet())
Expand All @@ -184,6 +187,7 @@ protected void launchInternal(ILaunchConfiguration configuration, String mode, I
strings.add(buffer.toString());
}
Logger.log(String.format("flash command: %s", String.join(" ", commands))); //$NON-NLS-1$ //$NON-NLS-2$

String[] envArray = strings.toArray(new String[strings.size()]);
Process p = DebugPlugin.exec(commands.toArray(new String[0]), workingDir, envArray);
DebugPlugin.newProcess(launch, p, String.join(" ", commands)); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@
import com.espressif.idf.ui.update.Messages;

/**
* Job to activate the provide
* {@link IDFToolSet} in the given ide environment
* Job to activate the provide {@link IDFToolSet} in the given ide environment
*
* @author Ali Azam Rana
*
*/
public class ToolsActivationJob extends ToolsJob
{
public static final String INSTALL_TOOLS_FLAG = "INSTALL_TOOLS_FLAG"; //$NON-NLS-1$

public ToolsActivationJob(IDFToolSet idfToolSet, String pythonExecutablePath, String gitExecutablePath)
{
super("Tools Activation Job", null, null);
Expand All @@ -55,12 +56,12 @@ protected IStatus run(IProgressMonitor monitor)
{
return Status.error("IDF Tool Set Cannot be null");
}

// verify with export script to test if everything is okay with installation

monitor.beginTask("Verifying if there are any changes to the installed tools", 5);
monitor.worked(1);

ExportIDFTools exportIDFTools = new ExportIDFTools();
IStatus status = exportIDFTools.getToolsExportOutputFromGivenIdfPath(idfToolSet.getSystemPythonExecutablePath(),
idfToolSet.getSystemGitExecutablePath(), console, errorConsoleStream, idfToolSet.getIdfLocation());
Expand All @@ -69,30 +70,31 @@ protected IStatus run(IProgressMonitor monitor)
return Status.error("INSTALL_AGAIN");
}
monitor.worked(1);

monitor.setTaskName("Exporting variables to eclipse");
processExportCmdOutput(status.getMessage());
setEnvVarsInEclipse();
monitor.worked(1);

monitor.setTaskName("Setting up toolchains and targets");
setUpToolChainsAndTargets();
monitor.worked(1);

// post export operations like copying openocd rules may also need to setup with the python dependencies here as well like websocket-client

// post export operations like copying openocd rules may also need to setup with the python dependencies here as
// well like websocket-client
monitor.setTaskName(Messages.InstallToolsHandler_InstallingWebscoketMsg);
handleWebSocketClientInstall();
monitor.worked(1);

monitor.setTaskName("Setting OpenOCD rules");
copyOpenOcdRules();
monitor.worked(1);

idfToolSet.setActive(true);

toolSetConfigurationManager.export(idfToolSet);
console.println("Tools Activated");

Preferences scopedPreferenceStore = InstanceScope.INSTANCE.getNode(UIPlugin.PLUGIN_ID);
scopedPreferenceStore.putBoolean(INSTALL_TOOLS_FLAG, true);
try
Expand All @@ -103,7 +105,7 @@ protected IStatus run(IProgressMonitor monitor)
{
Logger.log(e);
}

return Status.OK_STATUS;
}

Expand Down Expand Up @@ -167,7 +169,6 @@ public void run()
}
}


private void setUpToolChainsAndTargets()
{
IStatus status = loadTargetsAvailableFromIdfInCurrentToolSet();
Expand All @@ -176,7 +177,7 @@ private void setUpToolChainsAndTargets()
Logger.log("Unable to get IDF targets from current toolset");
return;
}

List<String> targets = extractTargets(status.getMessage());
ESPToolChainManager espToolChainManager = new ESPToolChainManager();
espToolChainManager.removeLaunchTargetsNotPresent(targets);
Expand All @@ -189,22 +190,19 @@ private void setEnvVarsInEclipse()
{
if (idfToolSet == null)
throw new RuntimeException("Tools Cannot be null");

IDFEnvironmentVariables idfEnvironmentVariables = new IDFEnvironmentVariables();
idfEnvironmentVariables.removeAllEnvVariables();
idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.ESP_IDF_VERSION, idfToolSet.getIdfVersion());
idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.GIT_PATH, idfToolSet.getSystemGitExecutablePath());
idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.IDF_COMPONENT_MANAGER, idfToolSet.getEnvVars().get(IDFEnvironmentVariables.IDF_COMPONENT_MANAGER));
idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.IDF_MAINTAINER, idfToolSet.getEnvVars().get(IDFEnvironmentVariables.IDF_MAINTAINER));
idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.IDF_PATH, idfToolSet.getIdfLocation());
idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.IDF_PYTHON_ENV_PATH, idfToolSet.getEnvVars().get(IDFEnvironmentVariables.IDF_PYTHON_ENV_PATH));
idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.OPENOCD_SCRIPTS, idfToolSet.getEnvVars().get(IDFEnvironmentVariables.OPENOCD_SCRIPTS));

idfToolSet.getEnvVars().forEach((key, value) -> {
if (value != null)
idfEnvironmentVariables.addEnvVariable(key, value);
});
String path = replacePathVariable(idfToolSet.getEnvVars().get(IDFEnvironmentVariables.PATH));

idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.PATH, path);
idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.PYTHON_EXE_PATH, idfToolSet.getSystemPythonExecutablePath());

idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.PYTHON_EXE_PATH,
idfToolSet.getSystemPythonExecutablePath());

idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.IDF_COMPONENT_MANAGER, "1");
// IDF_MAINTAINER=1 to be able to build with the clang toolchain
idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.IDF_MAINTAINER, "1");
Expand Down

0 comments on commit 1b584a3

Please sign in to comment.