Skip to content

Commit a26162f

Browse files
fix(hints): Handle merged hints.yml with the esp-idf v6.0 (#1419)
* ci(macos): switch to release-sign action for code signing * fix(hints): Handle merged hints.yml with the esp-idf v6.0 * ci: restore ci.yml from master * fix: address test failure case
1 parent 6ac03d4 commit a26162f

6 files changed

Lines changed: 92 additions & 9 deletions

File tree

bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ private void runCmakeBuildCommand(IConsole console, IProgressMonitor monitor, IP
397397
IDFCorePreferenceConstants.AUTOMATE_BUILD_HINTS_DEFAULT_STATUS, null);
398398
IConsoleParser[] consoleParsers = buildHintsStatus
399399
? new IConsoleParser[] { epm, new StatusParser(),
400-
new EspIdfErrorParser(HintsUtil.getReHintsList(new File(HintsUtil.getHintsYmlPath()))) }
400+
new EspIdfErrorParser(HintsUtil
401+
.getReHintsList(HintsUtil.resolveHintsYmlFile(buildDir))) }
401402
: new IConsoleParser[] { epm, new StatusParser() };
402403
watchProcess(consoleParsers, monitor);
403404

bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/HintsUtil.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ public static String getHintsYmlPath()
6464
+ File.separator + "hints.yml"; //$NON-NLS-1$
6565
}
6666

67+
public static File resolveHintsYmlFile(Path buildDirectory)
68+
{
69+
File legacy = new File(getHintsYmlPath());
70+
if (buildDirectory != null)
71+
{
72+
File aggregated = buildDirectory.resolve("hints.yml").toFile(); //$NON-NLS-1$
73+
if (aggregated.isFile())
74+
{
75+
return aggregated;
76+
}
77+
}
78+
if (legacy.isFile())
79+
{
80+
return legacy;
81+
}
82+
return buildDirectory != null ? buildDirectory.resolve("hints.yml").toFile() : legacy; //$NON-NLS-1$
83+
}
84+
6785
public static String getOpenocdHintsYmlPath()
6886
{
6987
String openOCDScriptPath = new IDFEnvironmentVariables().getEnvValue(IDFEnvironmentVariables.OPENOCD_SCRIPTS);

bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IDFUtil.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,23 @@ public static boolean isFlashEncrypted()
743743
return false;
744744
}
745745

746+
public static java.nio.file.Path getActiveProjectBuildDirPath()
747+
{
748+
try
749+
{
750+
IProject project = getProjectFromActiveLaunchConfig();
751+
if (project != null)
752+
{
753+
return Paths.get(getBuildDir(project));
754+
}
755+
}
756+
catch (CoreException e)
757+
{
758+
Logger.log(e);
759+
}
760+
return null;
761+
}
762+
746763
/**
747764
* Returns the active project from the currently selected launch configuration.
748765
*/
@@ -823,8 +840,7 @@ public static String getGitExecutablePathFromSystem()
823840

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

826-
IStatus status = processRunner.runInBackground(arguments, org.eclipse.core.runtime.Path.ROOT,
827-
environment);
843+
IStatus status = processRunner.runInBackground(arguments, Path.ROOT, environment);
828844
if (status == null)
829845
{
830846
Logger.log(IDFCorePlugin.getPlugin(), IDFCorePlugin.errorStatus("Status can't be null", null)); //$NON-NLS-1$

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/BuildView.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import com.espressif.idf.core.build.ReHintPair;
3333
import com.espressif.idf.core.util.HintsUtil;
34+
import com.espressif.idf.core.util.IDFUtil;
3435
import com.espressif.idf.core.util.StringUtil;
3536

3637
public class BuildView extends ViewPart
@@ -64,9 +65,10 @@ public void createPartControl(Composite parent)
6465
container.setLayout(layout);
6566
if (reHintsPairs.isEmpty())
6667
{
67-
if (!new File(HintsUtil.getHintsYmlPath()).exists())
68+
File hintsYml = HintsUtil.resolveHintsYmlFile(IDFUtil.getActiveProjectBuildDirPath());
69+
if (!hintsYml.exists())
6870
{
69-
createNoHintsYmlLabel();
71+
createNoHintsYmlLabel(hintsYml);
7072
}
7173
else
7274
{
@@ -85,11 +87,11 @@ private void createNoAvailableHintsLabel()
8587
infoField.setText(Messages.BuildView_NoAvailableHintsMsg);
8688
}
8789

88-
private void createNoHintsYmlLabel()
90+
private void createNoHintsYmlLabel(File hintsYml)
8991
{
9092
CLabel errorField = new CLabel(container, SWT.H_SCROLL);
9193
errorField.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK));
92-
errorField.setText(MessageFormat.format(Messages.HintsYmlNotFoundErrMsg, HintsUtil.getHintsYmlPath()));
94+
errorField.setText(MessageFormat.format(Messages.HintsYmlNotFoundErrMsg, hintsYml.getPath()));
9395
}
9496

9597
private void createHintsViewer(Composite container)

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/HintsView.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import java.io.File;
88
import java.text.MessageFormat;
9+
import java.nio.file.Path;
910
import java.util.ArrayList;
1011
import java.util.List;
1112
import java.util.Optional;
@@ -32,6 +33,7 @@
3233

3334
import com.espressif.idf.core.build.ReHintPair;
3435
import com.espressif.idf.core.util.HintsUtil;
36+
import com.espressif.idf.core.util.IDFUtil;
3537
import com.espressif.idf.core.util.StringUtil;
3638

3739
public class HintsView extends ViewPart
@@ -54,12 +56,14 @@ public void createPartControl(Composite parent)
5456
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
5557
GridLayout layout = new GridLayout(1, true);
5658
container.setLayout(layout);
57-
reHintsList = HintsUtil.getReHintsList(new File(HintsUtil.getHintsYmlPath()));
59+
Path buildDir = IDFUtil.getActiveProjectBuildDirPath();
60+
File hintsYml = HintsUtil.resolveHintsYmlFile(buildDir);
61+
reHintsList = HintsUtil.getReHintsList(hintsYml);
5862
if (reHintsList.isEmpty())
5963
{
6064
CLabel errorField = new CLabel(container, SWT.H_SCROLL);
6165
errorField.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK));
62-
errorField.setText(MessageFormat.format(Messages.HintsYmlNotFoundErrMsg, HintsUtil.getHintsYmlPath()));
66+
errorField.setText(MessageFormat.format(Messages.HintsYmlNotFoundErrMsg, hintsYml.getPath()));
6367
return;
6468
}
6569
createSearchField(container);

tests/com.espressif.idf.core.test/src/com/espressif/idf/core/util/test/HintsUtilTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
import static org.junit.jupiter.api.Assertions.assertEquals;
88
import static org.junit.jupiter.api.Assertions.assertNotNull;
9+
import static org.junit.jupiter.api.Assertions.assertTrue;
910

1011
import java.io.File;
1112
import java.io.FileOutputStream;
1213
import java.io.IOException;
1314
import java.io.InputStream;
15+
import java.nio.file.Files;
1416
import java.util.ArrayList;
1517
import java.util.List;
1618

@@ -96,4 +98,44 @@ void getReHintsList_returns_empty_array_when_not_existing_path_is_provided()
9698
assertEquals(new ArrayList<>(), reHintsList);
9799
}
98100

101+
@Test
102+
void resolveHintsYmlFile_prefers_aggregated_hints_under_build_directory() throws IOException
103+
{
104+
File buildDir = Files.createTempDirectory("idf-build").toFile();
105+
File aggregated = new File(buildDir, "hints.yml");
106+
try (InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("hints.yml");
107+
FileOutputStream fos = new FileOutputStream(aggregated))
108+
{
109+
fos.write(inputStream.readAllBytes());
110+
}
111+
File resolved = HintsUtil.resolveHintsYmlFile(buildDir.toPath());
112+
assertEquals(aggregated.getCanonicalFile(), resolved.getCanonicalFile());
113+
}
114+
115+
@Test
116+
void resolveHintsYmlFile_falls_back_to_legacy_path_when_build_dir_has_no_hints() throws IOException
117+
{
118+
File buildDir = Files.createTempDirectory("idf-build-empty").toFile();
119+
File legacy = new File(HintsUtil.getHintsYmlPath());
120+
if (!legacy.isFile())
121+
{
122+
return;
123+
}
124+
File resolved = HintsUtil.resolveHintsYmlFile(buildDir.toPath());
125+
assertEquals(legacy.getCanonicalFile(), resolved.getCanonicalFile());
126+
}
127+
128+
@Test
129+
void resolveHintsYmlFile_without_build_dir_matches_legacy_when_present() throws IOException
130+
{
131+
File legacy = new File(HintsUtil.getHintsYmlPath());
132+
if (!legacy.isFile())
133+
{
134+
return;
135+
}
136+
File resolved = HintsUtil.resolveHintsYmlFile(null);
137+
assertTrue(resolved.isFile());
138+
assertEquals(legacy.getCanonicalFile(), resolved.getCanonicalFile());
139+
}
140+
99141
}

0 commit comments

Comments
 (0)