Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ private void runCmakeBuildCommand(IConsole console, IProgressMonitor monitor, IP
IDFCorePreferenceConstants.AUTOMATE_BUILD_HINTS_DEFAULT_STATUS, null);
IConsoleParser[] consoleParsers = buildHintsStatus
? new IConsoleParser[] { epm, new StatusParser(),
new EspIdfErrorParser(HintsUtil.getReHintsList(new File(HintsUtil.getHintsYmlPath()))) }
new EspIdfErrorParser(HintsUtil
.getReHintsList(HintsUtil.resolveHintsYmlFile(buildDir))) }
: new IConsoleParser[] { epm, new StatusParser() };
watchProcess(consoleParsers, monitor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ public static String getHintsYmlPath()
+ File.separator + "hints.yml"; //$NON-NLS-1$
}

public static File resolveHintsYmlFile(Path buildDirectory)
{
File legacy = new File(getHintsYmlPath());
if (buildDirectory != null)
{
File aggregated = buildDirectory.resolve("hints.yml").toFile(); //$NON-NLS-1$
if (aggregated.isFile())
{
return aggregated;
}
}
if (legacy.isFile())
{
return legacy;
}
return buildDirectory != null ? buildDirectory.resolve("hints.yml").toFile() : legacy; //$NON-NLS-1$
}

public static String getOpenocdHintsYmlPath()
{
String openOCDScriptPath = new IDFEnvironmentVariables().getEnvValue(IDFEnvironmentVariables.OPENOCD_SCRIPTS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,23 @@ public static boolean isFlashEncrypted()
return false;
}

public static java.nio.file.Path getActiveProjectBuildDirPath()
{
try
{
IProject project = getProjectFromActiveLaunchConfig();
if (project != null)
{
return Paths.get(getBuildDir(project));
}
}
catch (CoreException e)
{
Logger.log(e);
}
return null;
}

/**
* Returns the active project from the currently selected launch configuration.
*/
Expand Down Expand Up @@ -838,8 +855,7 @@ public static String getGitExecutablePathFromSystem()

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

IStatus status = processRunner.runInBackground(arguments, org.eclipse.core.runtime.Path.ROOT,
environment);
IStatus status = processRunner.runInBackground(arguments, Path.ROOT, environment);
if (status == null)
{
Logger.log(IDFCorePlugin.getPlugin(), IDFCorePlugin.errorStatus("Status can't be null", null)); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import com.espressif.idf.core.build.ReHintPair;
import com.espressif.idf.core.util.HintsUtil;
import com.espressif.idf.core.util.IDFUtil;
import com.espressif.idf.core.util.StringUtil;

public class BuildView extends ViewPart
Expand Down Expand Up @@ -64,9 +65,10 @@ public void createPartControl(Composite parent)
container.setLayout(layout);
if (reHintsPairs.isEmpty())
{
if (!new File(HintsUtil.getHintsYmlPath()).exists())
File hintsYml = HintsUtil.resolveHintsYmlFile(IDFUtil.getActiveProjectBuildDirPath());
if (!hintsYml.exists())
{
createNoHintsYmlLabel();
createNoHintsYmlLabel(hintsYml);
}
else
{
Expand All @@ -85,11 +87,11 @@ private void createNoAvailableHintsLabel()
infoField.setText(Messages.BuildView_NoAvailableHintsMsg);
}

private void createNoHintsYmlLabel()
private void createNoHintsYmlLabel(File hintsYml)
{
CLabel errorField = new CLabel(container, SWT.H_SCROLL);
errorField.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK));
errorField.setText(MessageFormat.format(Messages.HintsYmlNotFoundErrMsg, HintsUtil.getHintsYmlPath()));
errorField.setText(MessageFormat.format(Messages.HintsYmlNotFoundErrMsg, hintsYml.getPath()));
}

private void createHintsViewer(Composite container)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.io.File;
import java.text.MessageFormat;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand All @@ -32,6 +33,7 @@

import com.espressif.idf.core.build.ReHintPair;
import com.espressif.idf.core.util.HintsUtil;
import com.espressif.idf.core.util.IDFUtil;
import com.espressif.idf.core.util.StringUtil;

public class HintsView extends ViewPart
Expand All @@ -54,12 +56,14 @@ public void createPartControl(Composite parent)
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
GridLayout layout = new GridLayout(1, true);
container.setLayout(layout);
reHintsList = HintsUtil.getReHintsList(new File(HintsUtil.getHintsYmlPath()));
Path buildDir = IDFUtil.getActiveProjectBuildDirPath();
File hintsYml = HintsUtil.resolveHintsYmlFile(buildDir);
reHintsList = HintsUtil.getReHintsList(hintsYml);
if (reHintsList.isEmpty())
{
CLabel errorField = new CLabel(container, SWT.H_SCROLL);
errorField.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK));
errorField.setText(MessageFormat.format(Messages.HintsYmlNotFoundErrMsg, HintsUtil.getHintsYmlPath()));
errorField.setText(MessageFormat.format(Messages.HintsYmlNotFoundErrMsg, hintsYml.getPath()));
return;
}
createSearchField(container);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -96,4 +98,44 @@ void getReHintsList_returns_empty_array_when_not_existing_path_is_provided()
assertEquals(new ArrayList<>(), reHintsList);
}

@Test
void resolveHintsYmlFile_prefers_aggregated_hints_under_build_directory() throws IOException
{
File buildDir = Files.createTempDirectory("idf-build").toFile();
File aggregated = new File(buildDir, "hints.yml");
try (InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("hints.yml");
FileOutputStream fos = new FileOutputStream(aggregated))
{
fos.write(inputStream.readAllBytes());
}
File resolved = HintsUtil.resolveHintsYmlFile(buildDir.toPath());
assertEquals(aggregated.getCanonicalFile(), resolved.getCanonicalFile());
}

@Test
void resolveHintsYmlFile_falls_back_to_legacy_path_when_build_dir_has_no_hints() throws IOException
{
File buildDir = Files.createTempDirectory("idf-build-empty").toFile();
File legacy = new File(HintsUtil.getHintsYmlPath());
if (!legacy.isFile())
{
return;
}
File resolved = HintsUtil.resolveHintsYmlFile(buildDir.toPath());
assertEquals(legacy.getCanonicalFile(), resolved.getCanonicalFile());
}

@Test
void resolveHintsYmlFile_without_build_dir_matches_legacy_when_present() throws IOException
{
File legacy = new File(HintsUtil.getHintsYmlPath());
if (!legacy.isFile())
{
return;
}
File resolved = HintsUtil.resolveHintsYmlFile(null);
assertTrue(resolved.isFile());
assertEquals(legacy.getCanonicalFile(), resolved.getCanonicalFile());
}

}
Loading