Skip to content

Commit

Permalink
fix: resolve merge confilict in CMakeMainTab2
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmaaa committed Aug 5, 2024
2 parents 0074f19 + 43a06e0 commit 00146d9
Show file tree
Hide file tree
Showing 33 changed files with 484 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;

import com.espressif.idf.core.util.IDFUtil;

/**
* @author Kondal Kolipaka
*
Expand All @@ -31,6 +34,10 @@ public class IDFCorePreferenceConstants
public static final String IDF_GITHUB_ASSETS_DEFAULT = "dl.espressif.com/github_assets"; //$NON-NLS-1$
public static final String PIP_EXTRA_INDEX_URL = "PIP_EXTRA_INDEX_URL"; //$NON-NLS-1$
public static final String PIP_EXTRA_INDEX_URL_DEFAULT = "https://dl.espressif.com/pypi"; //$NON-NLS-1$
public static final String IDF_TOOLS_PATH = "IDF_TOOLS_PATH"; //$NON-NLS-1$
public static final String IDF_TOOLS_PATH_DEFAULT = Platform.getOS().equals(Platform.OS_WIN32)
? IDFUtil.resolveEnvVariable("%USERPROFILE%\\.espressif") //$NON-NLS-1$
: IDFUtil.resolveEnvVariable("$HOME/.espressif"); //$NON-NLS-1$
/**
* Returns the node in the preference in the given context.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;

import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.core.util.IDFUtil;
import com.espressif.idf.core.util.StringUtil;

/**
* @author Kondal Kolipaka <[email protected]>
*
*/
@SuppressWarnings("restriction") //$NON-NLS-1$
@SuppressWarnings("restriction")
public class IDFEnvironmentVariables
{
/**
Expand Down Expand Up @@ -127,17 +128,21 @@ public Map<String, String> getSystemEnvMap()
IEnvironmentVariableManager buildEnvironmentManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
IEnvironmentVariable[] variables = buildEnvironmentManager.getVariables((ICConfigurationDescription) null,
true);
Map<String, String> envMap = new HashMap<>();
Map<String, String> envMap = IDFUtil.getSystemEnv();
if (variables != null)
{
for (IEnvironmentVariable iEnvironmentVariable : variables)
{
String key = iEnvironmentVariable.getName();
if (key.equals(IDFCorePreferenceConstants.IDF_TOOLS_PATH))
{
continue;
}
String value = iEnvironmentVariable.getValue();
envMap.put(key, value);
}
}

return envMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public interface ILSPConstants
{
String CLANGD_EXECUTABLE = "clangd"; //$NON-NLS-1$
String CLANGD_CONFIG_FILE = ".clangd"; //$NON-NLS-1$
String CLANG_FORMAT_FILE = ".clang-format"; //$NON-NLS-1$
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.debug.core.DebugPlugin;
Expand All @@ -86,6 +85,7 @@
import com.espressif.idf.core.internal.CMakeConsoleWrapper;
import com.espressif.idf.core.internal.CMakeErrorParser;
import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.core.util.ClangFormatFileHandler;
import com.espressif.idf.core.util.ClangdConfigFileHandler;
import com.espressif.idf.core.util.DfuCommandsUtil;
import com.espressif.idf.core.util.HintsUtil;
Expand Down Expand Up @@ -181,13 +181,19 @@ private boolean hasCustomBuild()
{
String userArgs = getProperty(CMAKE_ARGUMENTS);
// Custom build directory
int buildDirIndex = userArgs.indexOf("-B"); //$NON-NLS-1$
customBuildDir = buildDirIndex == -1 ? StringUtil.EMPTY
: userArgs.replaceFirst("-B", StringUtil.EMPTY).stripLeading(); //$NON-NLS-1$
String[] cmakeArgumentsArr = userArgs.split(" "); //$NON-NLS-1$
customBuildDir = StringUtil.EMPTY;
for (int i = 0; i < cmakeArgumentsArr.length; i++)
{
if (cmakeArgumentsArr[i].equals("-B")) //$NON-NLS-1$
{
customBuildDir = cmakeArgumentsArr[i + 1];
break;
}
}
try
{
getProject().setPersistentProperty(
new QualifiedName(IDFCorePlugin.PLUGIN_ID, IDFConstants.BUILD_DIR_PROPERTY), customBuildDir);
IDFUtil.setBuildDir(getProject(), customBuildDir);
}
catch (CoreException e)
{
Expand Down Expand Up @@ -340,6 +346,7 @@ public IProject[] build(int kind, Map<String, String> args, IConsole console, IP
}
runCmakeBuildCommand(console, monitor, project, start, generator, infoStream, buildDir);
new ClangdConfigFileHandler().update(project);
new ClangFormatFileHandler(project).update();
return new IProject[] { project };
}
catch (Exception e)
Expand Down Expand Up @@ -414,7 +421,10 @@ private void runCmakeBuildCommand(IConsole console, IProgressMonitor monitor, IP
}
}
}


envVars.add(new EnvironmentVariable(IDFCorePreferenceConstants.IDF_TOOLS_PATH,
IDFUtil.getIDFToolsPathFromPreferences()));

String buildCommand = getProperty(BUILD_COMMAND);
if (buildCommand.isBlank())
{
Expand Down Expand Up @@ -517,7 +527,7 @@ private void runCmakeCommand(IConsole console, IProgressMonitor monitor, IProjec
{
command.add("-DIDF_TOOLCHAIN=clang"); //$NON-NLS-1$
}

String userArgs = getProperty(CMAKE_ARGUMENTS);
if (userArgs != null && !userArgs.isBlank())
{
Expand All @@ -535,8 +545,9 @@ private void runCmakeCommand(IConsole console, IProgressMonitor monitor, IProjec
// Set PYTHONUNBUFFERED to 1/TRUE to dump the messages back immediately without
// buffering
IEnvironmentVariable bufferEnvVar = new EnvironmentVariable("PYTHONUNBUFFERED", "1"); //$NON-NLS-1$ //$NON-NLS-2$
IEnvironmentVariable idfToolsPathEnvVar = new EnvironmentVariable(IDFCorePreferenceConstants.IDF_TOOLS_PATH, IDFUtil.getIDFToolsPathFromPreferences());

Process p = startBuildProcess(command, new IEnvironmentVariable[] { bufferEnvVar }, workingDir, errConsole,
Process p = startBuildProcess(command, new IEnvironmentVariable[] { bufferEnvVar, idfToolsPathEnvVar }, workingDir, errConsole,
monitor);
if (p == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public final class IDFLaunchConstants
public static final String ATTR_JTAG_FLASH_ARGUMENTS = "com.espressif.idf.debug.gdbjtag.openocd.jtagFlashArguments"; //$NON-NLS-1$
public static final String ATTR_LAUNCH_CONFIGURATION_NAME = "com.espressif.idf.debug.gdbjtag.openocd.launchConfigurationName"; //$NON-NLS-1$
public static final String IDF_TARGET_TYPE = "com.espressif.idf.launch.serial.core.serialFlashTarget"; //$NON-NLS-1$
public static final String OPEN_SERIAL_MONITOR = "OPEN_SERIAL_MONITOR"; //$NON-NLS-1$
public static final String SERIAL_MONITOR_ENCODING = "SERIAL_MONITOR_ENCODING"; //$NON-NLS-1$
}
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ protected String getIdfToolsExportPath()
Logger.log(commands.toString());

IStatus idfToolsExportStatus = new ProcessBuilderFactory().runInBackground(commands,
org.eclipse.core.runtime.Path.ROOT, System.getenv());
org.eclipse.core.runtime.Path.ROOT, IDFUtil.getSystemEnv());
if (idfToolsExportStatus != null && idfToolsExportStatus.isOK())
{
String message = idfToolsExportStatus.getMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.espressif.idf.core.tools.ToolsSystemWrapper;
import com.espressif.idf.core.tools.vo.ToolsVO;
import com.espressif.idf.core.util.FileUtil;
import com.espressif.idf.core.util.IDFUtil;
import com.espressif.idf.core.util.StringUtil;

/**
Expand Down Expand Up @@ -318,7 +319,7 @@ public static IPath findAbsoluteToolPath(String toolName, String path)
{
if (StringUtil.isEmpty(path))
{
Map<String, String> env = System.getenv();
Map<String, String> env = IDFUtil.getSystemEnv();
if (env.containsKey(IDFEnvironmentVariables.PATH))
path = env.get(IDFEnvironmentVariables.PATH);
else
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# We'll use defaults from the LLVM style, but with some modifications so that it's close to the CDT K&R style.
BasedOnStyle: LLVM
UseTab: Always
IndentWidth: 4
TabWidth: 4
PackConstructorInitializers: NextLineOnly
BreakConstructorInitializers: AfterColon
IndentAccessModifiers: false
AccessModifierOffset: -4
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 java.io.IOException;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;

import com.espressif.idf.core.ILSPConstants;

public class ClangFormatFileHandler
{
private final IFile clangFormatFile;

public ClangFormatFileHandler(IProject project) throws CoreException
{
this.clangFormatFile = project.getFile(ILSPConstants.CLANG_FORMAT_FILE);
}

/**
* Updates the .clang-format file. If the file does not exist, it is created and initialized with default settings.
*
* @throws IOException if an I/O error occurs during file creation or writing
* @throws CoreException if an error occurs while refreshing the project
*/
public void update() throws IOException, CoreException
{
if (clangFormatFile.exists())
{
return;
}
try (final var source = getClass().getResourceAsStream(".clang-format-project");) //$NON-NLS-1$
{
clangFormatFile.create(source, true, new NullProgressMonitor());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,27 @@ public class EspToolCommands
public Process chipInformation(String port) throws Exception
{
destroyAnyChipInfoProcess();
chipInfoProcess = new ProcessBuilder(getChipInfoCommand(port)).start();
ProcessBuilder processBuilder = new ProcessBuilder(getChipInfoCommand(port));
processBuilder.environment().putAll(IDFUtil.getSystemEnv());
chipInfoProcess = processBuilder.start();
return chipInfoProcess;
}

public Process eraseFlash(String port) throws Exception
{
destroyAnyChipInfoProcess();
flashEraseProcess = new ProcessBuilder(getFlashEraseCommand(port)).start();
ProcessBuilder processBuilder = new ProcessBuilder(getFlashEraseCommand(port));
processBuilder.environment().putAll(IDFUtil.getSystemEnv());
flashEraseProcess = processBuilder.start();
return flashEraseProcess;
}

public Process writeFlash(String port, String path, String offset) throws IOException
{
destroyAnyChipInfoProcess();
writeFlashProcess = new ProcessBuilder(getWriteFlashCommand(port, path, offset)).start();
ProcessBuilder processBuilder = new ProcessBuilder(getWriteFlashCommand(port, path, offset));
processBuilder.environment().putAll(IDFUtil.getSystemEnv());
writeFlashProcess = processBuilder.start();
return writeFlashProcess;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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.LaunchBarTargetConstants;
import com.espressif.idf.core.ProcessBuilderFactory;
Expand Down Expand Up @@ -542,6 +543,19 @@ public static String getBuildDir(IProject project) throws CoreException
return buildDirectory;
}

/**
* Sets project build directory
*
* @param project
* @param pathToBuildDir
* @throws CoreException
*/
public static void setBuildDir(IProject project, String pathToBuildDir) throws CoreException
{
project.setPersistentProperty(new QualifiedName(IDFCorePlugin.PLUGIN_ID, IDFConstants.BUILD_DIR_PROPERTY),
pathToBuildDir);
}

/**
* Project .map file path
*
Expand Down Expand Up @@ -715,7 +729,7 @@ public static String getGitExecutablePathFromSystem()
arguments.add("whereis"); //$NON-NLS-1$
arguments.add("git"); //$NON-NLS-1$

Map<String, String> environment = new HashMap<>(System.getenv());
Map<String, String> environment = new HashMap<>(getSystemEnv());

IStatus status = processRunner.runInBackground(arguments, org.eclipse.core.runtime.Path.ROOT,
environment);
Expand Down Expand Up @@ -747,4 +761,56 @@ public static boolean isReparseTag(File file)
}
return false;
}

public static String resolveEnvVariable(String path)
{
Pattern winEnvPattern = Pattern.compile("%(\\w+)%"); //$NON-NLS-1$
Pattern unixEnvPattern = Pattern.compile("\\$(\\w+)"); //$NON-NLS-1$
Matcher matcher;
if (Platform.getOS().equals(Platform.OS_WIN32))
{
matcher = winEnvPattern.matcher(path);
}
else
{
matcher = unixEnvPattern.matcher(path);
}

StringBuffer resolvedPath = new StringBuffer();
while (matcher.find())
{
String envVarName = matcher.group(1);
String envVarValue = System.getenv(envVarName);

if (envVarValue != null)
{
matcher.appendReplacement(resolvedPath, envVarValue.replace("\\", "\\\\")); //$NON-NLS-1$ //$NON-NLS-2$
}
else
{
// If the environment variable is not found, keep the original
matcher.appendReplacement(resolvedPath, matcher.group(0));
}
}
matcher.appendTail(resolvedPath);

return resolvedPath.toString();

}

public static Map<String, String> getSystemEnv()
{
Map<String, String> env = new HashMap<String, String>(System.getenv());
String idfToolsPath = Platform.getPreferencesService().getString(IDFCorePlugin.PLUGIN_ID,
IDFCorePreferenceConstants.IDF_TOOLS_PATH, IDFCorePreferenceConstants.IDF_TOOLS_PATH_DEFAULT, null);
env.put(IDFCorePreferenceConstants.IDF_TOOLS_PATH, idfToolsPath);
return env;
}

public static String getIDFToolsPathFromPreferences()
{
String idfToolsPath = Platform.getPreferencesService().getString(IDFCorePlugin.PLUGIN_ID,
IDFCorePreferenceConstants.IDF_TOOLS_PATH, IDFCorePreferenceConstants.IDF_TOOLS_PATH_DEFAULT, null);
return idfToolsPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,4 @@ public void updateLspQueryDrivers()
metadata.queryDriver().defaultValue());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.13.0",
com.espressif.idf.ui,
com.espressif.idf.terminal.connector.serial,
org.eclipse.launchbar.ui,
org.eclipse.embedcdt.core
org.eclipse.embedcdt.core,
org.eclipse.tm.terminal.view.core
Export-Package: com.espressif.idf.launch.serial,
com.espressif.idf.launch.serial.core,
com.espressif.idf.launch.serial.internal,
com.espressif.idf.launch.serial.util
Bundle-Activator: com.espressif.idf.launch.serial.internal.Activator
Bundle-ActivationPolicy: lazy
Automatic-Module-Name: org.eclipse.cdt.launch.serial.core
Import-Package: org.eclipse.cdt.dsf.gdb
Import-Package: org.eclipse.cdt.dsf.gdb,
org.eclipse.tm.terminal.view.core,
org.eclipse.tm.terminal.view.ui.launcher
Loading

0 comments on commit 00146d9

Please sign in to comment.