Skip to content

Commit e308701

Browse files
author
jantje
committed
#1268 upgrade 1 config works but build fails due to #1278
1 parent 48c779c commit e308701

File tree

3 files changed

+90
-69
lines changed

3 files changed

+90
-69
lines changed

io.sloeber.core/src/io/sloeber/core/api/BoardDescription.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ public static BoardDescription getFromCDT(ICConfigurationDescription confDesc) {
11041104
ret.myTxtFile = new BoardTxtFile(ret.myreferencingBoardsFile);
11051105
String optinconcat = getOldWayEnvVar(confDesc, "JANTJE.menu");
11061106
ret.myOptions = KeyValue.makeMap(optinconcat);
1107-
return null;
1107+
return ret;
11081108
}
11091109

11101110
}

io.sloeber.core/src/io/sloeber/core/api/CompileDescription.java

+35-21
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
package io.sloeber.core.api;
22

3+
import static io.sloeber.core.common.Common.getOldWayEnvVar;
4+
import static io.sloeber.core.common.Common.makeEnvironmentVar;
5+
import static io.sloeber.core.common.Const.EMPTY;
6+
import static io.sloeber.core.common.Const.ENV_KEY_JANTJE_START;
7+
import static io.sloeber.core.common.Const.ERASE_START;
8+
import static io.sloeber.core.common.Const.RECIPE_SIZE;
9+
import static io.sloeber.core.common.Const.TRUE;
10+
311
import java.util.HashMap;
412
import java.util.Map;
513

614
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
715

8-
import io.sloeber.core.common.Common;
9-
import io.sloeber.core.common.Const;
1016
import io.sloeber.core.txt.KeyValueTree;
1117
import io.sloeber.core.txt.TxtFile;
1218

@@ -25,21 +31,19 @@ public class CompileDescription {
2531

2632
private static final String ENV_KEY_WARNING_LEVEL_OFF = "A.compiler.warning_flags"; //$NON-NLS-1$
2733
private static final String ENV_KEY_WARNING_LEVEL_ON = "${A.compiler.warning_flags_all}"; //$NON-NLS-1$
28-
private static final String ENV_KEY_JANTJE_ADDITIONAL_COMPILE_OPTIONS = Const.ENV_KEY_JANTJE_START
34+
private static final String ENV_KEY_JANTJE_ADDITIONAL_COMPILE_OPTIONS = ENV_KEY_JANTJE_START
2935
+ "extra.compile"; //$NON-NLS-1$
30-
private static final String ENV_KEY_JANTJE_ADDITIONAL_C_COMPILE_OPTIONS = Const.ENV_KEY_JANTJE_START
36+
private static final String ENV_KEY_JANTJE_ADDITIONAL_C_COMPILE_OPTIONS = ENV_KEY_JANTJE_START
3137
+ "extra.c.compile"; //$NON-NLS-1$
32-
private static final String ENV_KEY_JANTJE_ADDITIONAL_CPP_COMPILE_OPTIONS = Const.ENV_KEY_JANTJE_START
38+
private static final String ENV_KEY_JANTJE_ADDITIONAL_CPP_COMPILE_OPTIONS = ENV_KEY_JANTJE_START
3339
+ "extra.cpp.compile"; //$NON-NLS-1$
34-
private static final String ENV_KEY_JANTJE_WARNING_LEVEL = Const.ENV_KEY_JANTJE_START + "warning_level"; //$NON-NLS-1$
35-
private static final String ENV_KEY_JANTJE_SIZE_COMMAND = Const.ERASE_START + "alt_size_command"; //$NON-NLS-1$
36-
private static final String ENV_KEY_JANTJE_SIZE_SWITCH = Const.ENV_KEY_JANTJE_START + "size.switch"; //$NON-NLS-1$
37-
private static final String ENV_KEY_JANTJE_ASSEMBLY_COMPILE_OPTIONS = Const.ENV_KEY_JANTJE_START + "extra.assembly"; //$NON-NLS-1$
38-
private static final String ENV_KEY_JANTJE_ARCHIVE_COMPILE_OPTIONS = Const.ENV_KEY_JANTJE_START + "extra.archive"; //$NON-NLS-1$
39-
private static final String ENV_KEY_JANTJE_LINK_COMPILE_OPTIONS = Const.ENV_KEY_JANTJE_START + "extra.link"; //$NON-NLS-1$
40-
private static final String ENV_KEY_JANTJE_ALL_COMPILE_OPTIONS = Const.ENV_KEY_JANTJE_START + "extra.all"; //$NON-NLS-1$
41-
42-
40+
private static final String ENV_KEY_JANTJE_WARNING_LEVEL = ENV_KEY_JANTJE_START + "warning_level"; //$NON-NLS-1$
41+
private static final String ENV_KEY_JANTJE_SIZE_COMMAND = ERASE_START + "alt_size_command"; //$NON-NLS-1$
42+
private static final String ENV_KEY_JANTJE_SIZE_SWITCH = ENV_KEY_JANTJE_START + "size.switch"; //$NON-NLS-1$
43+
private static final String ENV_KEY_JANTJE_ASSEMBLY_COMPILE_OPTIONS = ENV_KEY_JANTJE_START + "extra.assembly"; //$NON-NLS-1$
44+
private static final String ENV_KEY_JANTJE_ARCHIVE_COMPILE_OPTIONS = ENV_KEY_JANTJE_START + "extra.archive"; //$NON-NLS-1$
45+
private static final String ENV_KEY_JANTJE_LINK_COMPILE_OPTIONS = ENV_KEY_JANTJE_START + "extra.link"; //$NON-NLS-1$
46+
private static final String ENV_KEY_JANTJE_ALL_COMPILE_OPTIONS = ENV_KEY_JANTJE_START + "extra.all"; //$NON-NLS-1$
4347

4448
public boolean isWarningLevel() {
4549
return this.myWarningLevel;
@@ -128,15 +132,15 @@ public void set_All_CompileOptions(String my_All_CompileOptions) {
128132
* must be a valid configuration description
129133
*/
130134
public Map<String, String> getEnvVars() {
131-
Map<String, String> ret = getEnvVarsConfig(Const.EMPTY);
135+
Map<String, String> ret = getEnvVarsConfig(EMPTY);
132136

133137
if (this.isWarningLevel()) {
134138
ret.put(ENV_KEY_WARNING_LEVEL_OFF, ENV_KEY_WARNING_LEVEL_ON);
135139
}
136140
if (this.myAlternativeSizeCommand) {
137-
ret.put(ENV_KEY_JANTJE_SIZE_SWITCH, Common.makeEnvironmentVar(ENV_KEY_JANTJE_SIZE_COMMAND));
141+
ret.put(ENV_KEY_JANTJE_SIZE_SWITCH, makeEnvironmentVar(ENV_KEY_JANTJE_SIZE_COMMAND));
138142
} else {
139-
ret.put(ENV_KEY_JANTJE_SIZE_SWITCH, Common.makeEnvironmentVar(Const.RECIPE_SIZE));
143+
ret.put(ENV_KEY_JANTJE_SIZE_SWITCH, makeEnvironmentVar(RECIPE_SIZE));
140144
}
141145

142146
return ret;
@@ -194,8 +198,8 @@ public CompileDescription(TxtFile configFile, String prefix) {
194198
my_Archive_CompileOptions = section.getValue(ENV_KEY_JANTJE_ARCHIVE_COMPILE_OPTIONS);
195199
my_Link_CompileOptions = section.getValue(ENV_KEY_JANTJE_LINK_COMPILE_OPTIONS);
196200
my_All_CompileOptions = section.getValue(ENV_KEY_JANTJE_ALL_COMPILE_OPTIONS);
197-
myWarningLevel = Const.TRUE.equalsIgnoreCase(section.getValue(ENV_KEY_JANTJE_WARNING_LEVEL));
198-
myAlternativeSizeCommand = Const.TRUE.equalsIgnoreCase(section.getValue(ENV_KEY_JANTJE_SIZE_SWITCH));
201+
myWarningLevel = TRUE.equalsIgnoreCase(section.getValue(ENV_KEY_JANTJE_WARNING_LEVEL));
202+
myAlternativeSizeCommand = TRUE.equalsIgnoreCase(section.getValue(ENV_KEY_JANTJE_SIZE_SWITCH));
199203

200204
}
201205

@@ -246,8 +250,18 @@ private boolean equalCompileOptions(CompileDescription other) {
246250
&& (my_All_CompileOptions.equals(other.my_All_CompileOptions));
247251
}
248252

253+
@SuppressWarnings("nls")
249254
public static CompileDescription getFromCDT(ICConfigurationDescription confDesc) {
250-
// TODO Auto-generated method stub
251-
return null;
255+
CompileDescription ret = new CompileDescription();
256+
ret.my_C_andCPP_CompileOptions = getOldWayEnvVar(confDesc, "JANTJE.extra.compile");
257+
ret.my_CPP_CompileOptions = getOldWayEnvVar(confDesc, "JANTJE.extra.cpp.compile");
258+
ret.my_C_CompileOptions = getOldWayEnvVar(confDesc, "JANTJE.extra.c.compile");
259+
ret.my_Assembly_CompileOptions = getOldWayEnvVar(confDesc, "JANTJE.extra.assembly");
260+
ret.my_Archive_CompileOptions = getOldWayEnvVar(confDesc, "JANTJE.extra.archive");
261+
ret.my_Link_CompileOptions = getOldWayEnvVar(confDesc, "JANTJE.extra.link");
262+
ret.my_All_CompileOptions = getOldWayEnvVar(confDesc, "JANTJE.extra.all");
263+
ret.myWarningLevel = TRUE.equalsIgnoreCase(getOldWayEnvVar(confDesc, "JANTJE.warning_level"));
264+
ret.myAlternativeSizeCommand = TRUE.equalsIgnoreCase(getOldWayEnvVar(confDesc, "JANTJE.size.switch"));
265+
return ret;
252266
}
253267
}

io.sloeber.core/src/io/sloeber/core/api/SloeberProject.java

+54-47
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class SloeberProject extends Common {
5858
private IProject myProject = null;
5959
private boolean isConfigured = false;
6060
private boolean isDirty = false; // if anything has changed
61+
private boolean myNeedsClean = false; // is there old sloeber data that needs cleaning
6162

6263
private static final String ENV_KEY_BUILD_SOURCE_PATH = ERASE_START + "build.source.path"; //$NON-NLS-1$
6364
private static final String ENV_KEY_BUILD_GENERIC_PATH = ERASE_START + "build.generic.path"; //$NON-NLS-1$
@@ -75,7 +76,7 @@ private SloeberProject(IProject project, boolean isProjectCreating) {
7576
if (isProjectCreating) {
7677
return;
7778
}
78-
configureUpdateProject();
79+
configureProject();
7980

8081
}
8182

@@ -105,8 +106,9 @@ public static IProject createArduinoProject(String projectName, URI projectURI,
105106
IProgressMonitor monitor) {
106107

107108
String realProjectName = Common.MakeNameCompileSafe(projectName);
108-
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
109+
109110
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
111+
IWorkspaceRoot root = workspace.getRoot();
110112
ICoreRunnable runnable = new ICoreRunnable() {
111113
@Override
112114
public void run(IProgressMonitor internalMonitor) throws CoreException {
@@ -176,7 +178,6 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
176178
}
177179

178180
arduinoProjDesc.createSloeberConfigFiles(prjCDesc);
179-
;
180181
SubMonitor refreshMonitor = SubMonitor.convert(internalMonitor, 3);
181182
newProjectHandle.open(refreshMonitor);
182183
newProjectHandle.refreshLocal(IResource.DEPTH_INFINITE, refreshMonitor);
@@ -244,39 +245,57 @@ private HashMap<String, String> getEnvVars(ICConfigurationDescription confDesc)
244245
return allVars;
245246
}
246247

247-
private void configureUpdateProject() {
248+
private void configureProject() {
248249

249250
CCorePlugin cCorePlugin = CCorePlugin.getDefault();
250251
ICProjectDescription prjCDesc = cCorePlugin.getProjectDescription(myProject);
251-
if (configureUpdateProject(prjCDesc)) {
252-
try {
253-
cCorePlugin.setProjectDescription(myProject, prjCDesc, true, null);
254-
} catch (CoreException e) {
255-
// TODO Auto-generated catch block
256-
e.printStackTrace();
257-
}
258-
}
252+
configureProject(prjCDesc, false);
259253
}
260254

261-
private boolean configureUpdateProject(ICProjectDescription prjCDesc) {
262-
boolean prjDescChanged = false;
255+
private void configureProject(ICProjectDescription prjCDesc, boolean prjDescWritable) {
263256
if (isConfigured) {
264257
if (isDirty) {
265258
createSloeberConfigFiles(prjCDesc);
266-
267-
setActiveConfig(prjCDesc.getActiveConfiguration());
268-
prjDescChanged = true;
269-
isDirty = false;
270259
}
271-
return prjDescChanged;
260+
if (prjDescWritable && myNeedsClean) {
261+
cleanOldData(prjCDesc);
262+
}
263+
return;
272264
}
273-
readSloeberConfig(prjCDesc);
274-
if (isDirty) {
265+
// first configuration of the sloeber project
266+
if (readSloeberConfig(prjCDesc)) {
267+
// we migrated from a previous sloeber configuration
268+
myNeedsClean = true;
275269
createSloeberConfigFiles(prjCDesc);
276-
isDirty = false;
270+
// we need a writable project description to clean the old sloeber data
271+
if (prjDescWritable) {
272+
cleanOldData(prjCDesc);
273+
}
277274
}
278275
isConfigured = true;
279-
return true;
276+
}
277+
278+
/**
279+
* remove environment variables from the old sloeber way
280+
*
281+
* @param prjCDesc
282+
* @return
283+
*/
284+
private void cleanOldData(ICProjectDescription prjCDesc) {
285+
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
286+
IContributedEnvironment contribEnv = envManager.getContributedEnvironment();
287+
for (ICConfigurationDescription confDesc : prjCDesc.getConfigurations()) {
288+
IEnvironmentVariable[] CurVariables = contribEnv.getVariables(confDesc);
289+
for (int i = (CurVariables.length - 1); i > 0; i--) {
290+
if (CurVariables[i].getName().startsWith("A.")) {
291+
contribEnv.removeVariable(CurVariables[i].getName(), confDesc);
292+
}
293+
if (CurVariables[i].getName().startsWith("JANTJE.")) {
294+
contribEnv.removeVariable(CurVariables[i].getName(), confDesc);
295+
}
296+
}
297+
}
298+
myNeedsClean = false;
280299
}
281300

282301
/**
@@ -287,7 +306,9 @@ private boolean configureUpdateProject(ICProjectDescription prjCDesc) {
287306
* @param confDesc
288307
* returns true if the config needs saving otherwise false
289308
*/
290-
private void readSloeberConfig(ICProjectDescription prjCDesc) {
309+
@SuppressWarnings("nls")
310+
private boolean readSloeberConfig(final ICProjectDescription prjCDesc) {
311+
boolean needToCreateConfigFiles = false;
291312
IFile file = getConfigLocalFile();
292313
if (file.exists()) {
293314
myCfgFile = new TxtFile(file.getLocation().toFile());
@@ -312,7 +333,7 @@ private void readSloeberConfig(ICProjectDescription prjCDesc) {
312333
} else {
313334
// Maybe this is a old Sloeber project with the data in the eclipse build
314335
// environment variables
315-
isDirty = true;
336+
needToCreateConfigFiles = true;
316337
for (ICConfigurationDescription confDesc : prjCDesc.getConfigurations()) {
317338

318339
BoardDescription boardDesc = BoardDescription.getFromCDT(confDesc);
@@ -322,23 +343,10 @@ private void readSloeberConfig(ICProjectDescription prjCDesc) {
322343
myCompileDescriptions.put(confDesc.getId(), compileDescription);
323344
myOtherDescriptions.put(confDesc.getId(), otherDesc);
324345
}
325-
// remove environment variables from the old sloeber way
326-
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
327-
IContributedEnvironment contribEnv = envManager.getContributedEnvironment();
328-
for (ICConfigurationDescription confDesc : prjCDesc.getConfigurations()) {
329-
IEnvironmentVariable[] CurVariables = contribEnv.getVariables(confDesc);
330-
for (int i = (CurVariables.length - 1); i > 0; i--) {
331-
if (CurVariables[i].getName().startsWith(Const.ERASE_START)) {
332-
contribEnv.removeVariable(CurVariables[i].getName(), confDesc);
333-
}
334-
if (CurVariables[i].getName().startsWith(Const.ENV_KEY_JANTJE_START)) {
335-
contribEnv.removeVariable(CurVariables[i].getName(), confDesc);
336-
}
337-
}
338-
}
346+
339347
}
340348
}
341-
setActiveConfig(prjCDesc.getActiveConfiguration());
349+
return needToCreateConfigFiles;
342350
}
343351

344352
private void setActiveConfig(ICConfigurationDescription confDesc) {
@@ -372,7 +380,7 @@ private void setActiveConfig(ICConfigurationDescription confDesc) {
372380
* @param project
373381
* the project to store the data for
374382
*/
375-
private void createSloeberConfigFiles(ICProjectDescription prjCDesc) {
383+
private void createSloeberConfigFiles(final ICProjectDescription prjCDesc) {
376384

377385
Map<String, String> configVars = new TreeMap<>();
378386
Map<String, String> versionVars = new TreeMap<>();
@@ -400,6 +408,7 @@ private void createSloeberConfigFiles(ICProjectDescription prjCDesc) {
400408
try {
401409
storeConfigurationFile(getConfigVersionFile(), versionVars);
402410
storeConfigurationFile(getConfigLocalFile(), configVars);
411+
isDirty = false;
403412
} catch (CoreException e) {
404413
Common.log(new Status(IStatus.ERROR, io.sloeber.core.Activator.getId(),
405414
"failed to save the sloeber config files", e)); //$NON-NLS-1$
@@ -535,22 +544,22 @@ public void setOtherDescription(ICConfigurationDescription confDesc, OtherDescri
535544
*/
536545
public BoardDescription getBoardDescription(ICConfigurationDescription confDesc, boolean allowNull) {
537546
if (!allowNull) {
538-
configureUpdateProject();
547+
configureProject();
539548
}
540549
return myBoardDescriptions.get(confDesc.getId());
541550
}
542551

543552
public CompileDescription getCompileDescription(ICConfigurationDescription confDesc, boolean allowNull) {
544553
if (!allowNull) {
545-
configureUpdateProject();
554+
configureProject();
546555
}
547556
return myCompileDescriptions.get(confDesc.getId());
548557
}
549558

550559

551560
public OtherDescription getOtherDescription(ICConfigurationDescription confDesc, boolean allowNull) {
552561
if (!allowNull) {
553-
configureUpdateProject();
562+
configureProject();
554563
}
555564
return myOtherDescriptions.get(confDesc.getId());
556565
}
@@ -597,11 +606,9 @@ private IFile getConfigLocalFile() {
597606
public void configChangeAboutToApply(ICProjectDescription newProjDesc, ICProjectDescription oldProjDesc) {
598607
ICConfigurationDescription newActiveConfig = newProjDesc.getActiveConfiguration();
599608
ICConfigurationDescription oldActiveConfig = oldProjDesc.getActiveConfiguration();
609+
configureProject(newProjDesc, true);
600610
if (!newActiveConfig.getName().equals(oldActiveConfig.getName())) {
601-
configureUpdateProject(newProjDesc);
602611
setActiveConfig(newActiveConfig);
603-
} else {
604-
configureUpdateProject(newProjDesc);
605612
}
606613

607614
}

0 commit comments

Comments
 (0)