Skip to content

Commit

Permalink
fix: fixing esp-idf terminal and idf.py reconfigure not working on wi…
Browse files Browse the repository at this point in the history
…ndows
  • Loading branch information
sigmaaa committed Nov 11, 2024
1 parent 989243c commit 167642b
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 140 deletions.
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,4 +63,5 @@ Bundle-ClassPath: .,
lib/commons-compress-1.21.jar,
lib/xz-1.9.jar
Import-Package: org.eclipse.embedcdt.core,
org.eclipse.launchbar.ui.target
org.eclipse.launchbar.ui.target,
org.eclipse.ui.console
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public Process run(List<String> commands, IPath workingDirectory, Map<String, St
if (environment != null && !environment.isEmpty())
{
processBuilder.environment().putAll(environment);
// Removing Path, because we are using PATH
processBuilder.environment().remove("Path"); //$NON-NLS-1$
}
// let's merge the error stream with the standard output

processBuilder.redirectErrorStream(true);
return processBuilder.start();
}
Expand All @@ -46,8 +48,7 @@ public IStatus runInBackground(List<String> commands, IPath workingDirectory, Ma
throws IOException
{
Process process = run(commands, workingDirectory, environment);
return processData(process.getInputStream(), process.getErrorStream(), process.getOutputStream(),
process);
return processData(process.getInputStream(), process.getErrorStream(), process.getOutputStream(), process);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright 2024 Espressif Systems (Shanghai) PTE LTD. All rights reserved.
* Use is subject to license terms.
*******************************************************************************/

package com.espressif.idf.core.util;

import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.MessageConsole;

public class ConsoleManager
{

private ConsoleManager()
{
}

public static MessageConsole getConsole(String consoleName)
{
MessageConsole console = findConsole(consoleName);
if (console == null)
{
console = new MessageConsole(consoleName, null);
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console });
}
ConsolePlugin.getDefault().getConsoleManager().showConsoleView(console);
return console;
}

private static MessageConsole findConsole(String consoleName)
{
for (IConsole existing : ConsolePlugin.getDefault().getConsoleManager().getConsoles())
{
if (consoleName.equals(existing.getName()))
{
return (MessageConsole) existing;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*******************************************************************************
* Copyright 2021 Espressif Systems (Shanghai) PTE LTD. All rights reserved.
* Use is subject to license terms.
*******************************************************************************/

package com.espressif.idf.core.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;

import com.espressif.idf.core.IDFCorePlugin;
import com.espressif.idf.core.IDFEnvironmentVariables;
import com.espressif.idf.core.ProcessBuilderFactory;
import com.espressif.idf.core.logging.Logger;

public class IdfCommandExecutor
{

private final String target;
private final MessageConsole console;

public IdfCommandExecutor(String target, MessageConsole console)
{
this.target = target;
this.console = console;
}

public IStatus executeReconfigure(IProject project)
{
console.activate();
return runIdfReconfigureCommand(project);
}

private IStatus runIdfReconfigureCommand(IProject project)
{
ProcessBuilderFactory processRunner = new ProcessBuilderFactory();
List<String> arguments = prepareArguments();
Map<String, String> environment = new HashMap<>(new IDFEnvironmentVariables().getEnvMap());

try (MessageConsoleStream messageConsoleStream = console.newMessageStream())
{
return runProcess(arguments, environment, processRunner, project, messageConsoleStream);
}
catch (IOException e1)
{
Logger.log(e1);
return IDFCorePlugin.errorStatus(e1.getMessage(), e1);
}
}

private List<String> prepareArguments()
{
List<String> arguments = new ArrayList<>();
arguments.add(IDFUtil.getIDFPythonEnvPath());
arguments.add(IDFUtil.getIDFPythonScriptFile().getAbsolutePath());
arguments.add("-DIDF_TARGET=" + target); //$NON-NLS-1$
arguments.add("reconfigure"); //$NON-NLS-1$
return arguments;
}

private IStatus runProcess(List<String> arguments, Map<String, String> environment,
ProcessBuilderFactory processRunner, IProject project, MessageConsoleStream messageConsoleStream)
{
StringBuilder output = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
processRunner.run(arguments, project.getLocation(), environment).getInputStream())))
{
String line;
while ((line = reader.readLine()) != null)
{
output.append(line).append(System.lineSeparator());
messageConsoleStream.println(line);
}
return new Status(IStatus.OK, IDFCorePlugin.PLUGIN_ID, output.toString());
}
catch (Exception e)
{
Logger.log(e);
return IDFCorePlugin.errorStatus(e.getMessage(), e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -380,25 +380,24 @@ public ITerminalConnector createTerminalConnector(Map<String, Object> properties
if (envKey.equals("PATH")) //$NON-NLS-1$
{
String idfExtraPaths = IDFUtil.getIDFExtraPaths();
if(!StringUtil.isEmpty(idfExtraPaths))
{
if (!StringUtil.isEmpty(idfExtraPaths)) {
envValue = envValue + ":" + idfExtraPaths; //$NON-NLS-1$
}
}
envpList.add(envKey + "=" + envValue); //$NON-NLS-1$
}

//Removing path, since we are using PATH
envMap.remove("Path"); //$NON-NLS-1$
// Convert back into a string array
envp = envpList.toArray(new String[envpList.size()]);

Assert.isTrue(image != null || process != null);

String terminalWrkDir = getWorkingDir();
if (StringUtil.isEmpty(terminalWrkDir))
{
if (StringUtil.isEmpty(terminalWrkDir)) {
terminalWrkDir = workingDir;
}

// Construct the terminal settings store
ISettingsStore store = new SettingsStore();

Expand Down Expand Up @@ -435,7 +434,7 @@ public ITerminalConnector createTerminalConnector(Map<String, Object> properties

return connector;
}

protected String getWorkingDir() {
Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$
if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* @author Kondal Kolipaka <[email protected]>
*
*/
public class Messages extends NLS {
public class Messages extends NLS
{
private static final String BUNDLE_NAME = "com.espressif.idf.ui.wizard.messages"; //$NON-NLS-1$
public static String ImportIDFProjectWizard_0;
public static String ImportIDFProjectWizardPage_0;
Expand Down Expand Up @@ -41,12 +42,15 @@ public class Messages extends NLS {
public static String NewComponentWizardPage_CantCreateCompErr;
public static String NewComponentWizardPage_ProjectDoesntExistErr;
public static String NewComponentWizardPage_ProjectNameLbl;

static {
public static String IdfReconfigureJobName;

static
{
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}

private Messages() {
private Messages()
{
}
}
Loading

0 comments on commit 167642b

Please sign in to comment.