Skip to content

Commit 7532c65

Browse files
author
jan
committed
Pre and post build commands working in internal builder
MakeBuilkder still needs to be done
1 parent cc742c8 commit 7532c65

File tree

10 files changed

+148
-47
lines changed

10 files changed

+148
-47
lines changed

io.sloeber.autoBuild.ui/src/io/sloeber/autoBuild/ui/internal/messages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ NewConfiguration_error_invalidName=Special characters are not allowed in the nam
249249
BuildToolManagerTab_BuildTools=Build tools
250250
BuildToolManagerTab_EnvironmentVars=Environment Vars:
251251
BuildToolManagerTab_MyID=my ID
252-
BuildToolManagerTab_BuildToolManagerTab_NoBuildToolSelected=No build tool selected
253252
BuildToolManagerTab_NoEnvironmentVarsProvided=No environment Vars provided
254253
BuildToolManagerTab_NoToolVarsProvided=No Tool Vars provided
255254
BuildToolManagerTab_Path=Path
@@ -393,3 +392,4 @@ NewProjectSourceLocationPage_PutCodeInSrcFolder=put code in the src folder
393392
NewProjectSourceLocationPage_SelectLocation=select the location of the source code in the project.
394393
NewProjectSourceLocationPage_SeperateSourceCodeFromTheRest=You can seperate the source code from the rest of the project content by putting it in a source folder.
395394
NewProjectSourceLocationPage_YouMustProvideText=You must provide a text in the text field that matches a valid folder name
395+
BuildToolManagerTab_NoBuildToolSelected=No build tool Selected

io.sloeber.autoBuild/src/io/sloeber/autoBuild/api/AutoBuildConfigurationExtensionDescription.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.sloeber.autoBuild.api;
22

33
import java.util.Set;
4+
import java.util.TreeMap;
45

56
import io.sloeber.autoBuild.helpers.api.KeyValueTree;
67

@@ -112,4 +113,8 @@ public String getDiscoveryCommand(String languageId) {
112113

113114
public abstract boolean equals(AutoBuildConfigurationExtensionDescription base);
114115

116+
public abstract TreeMap< String, String> getPrebuildSteps();
117+
118+
public abstract TreeMap<String, String> getPostbuildSteps() ;
119+
115120
}

io.sloeber.autoBuild/src/io/sloeber/autoBuild/api/IAutoBuildConfigurationDescription.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,5 +438,20 @@ public static ICSourceEntry[] getResolvedSourceEntries(IAutoBuildConfigurationDe
438438

439439
public String getName();
440440

441+
/**
442+
* Give all the commands that need to be called before the build
443+
* This is different from getPrebuildStep
444+
* getPrebuildStep provides the command as provided by the user in the project properties
445+
* getPrebuildSteps returns getPrebuildStep and possibly more commands provided by extensions
446+
* @return
447+
*/
448+
public TreeMap<String,String> getPrebuildSteps();
449+
450+
/**
451+
* Same thing as getPrebuildSteps but for post Build
452+
* @return
453+
*/
454+
public TreeMap<String, String> getPostbuildSteps();
455+
441456

442457
}

io.sloeber.autoBuild/src/io/sloeber/autoBuild/core/Messages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ public class Messages extends NLS {
150150
public static String AbstractBuiltinSpecsDetector_SerializingResults;
151151
public static String ExternalBuilderName;
152152
public static String InternalBuilderName;
153+
154+
public static String InternalBuildRunner_NoNeedToRun;
153155
static {
154156
// initialize resource bundle
155157
NLS.initializeMessages(BUNDLE_NAME, Messages.class);

io.sloeber.autoBuild/src/io/sloeber/autoBuild/core/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,4 @@ AbstractBuiltinSpecsDetector_SerializingResults=Serializing results
184184

185185
ExternalBuilderName=Make builder
186186
InternalBuilderName=Internal builder
187+
InternalBuildRunner_NoNeedToRun=No need to run

io.sloeber.autoBuild/src/io/sloeber/autoBuild/extensionPoint/providers/InternalBuildRunner.java

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
import java.util.ArrayList;
2727
import java.util.Arrays;
2828
import java.util.List;
29+
import java.util.Map.Entry;
2930
import java.util.Set;
31+
import java.util.TreeMap;
3032
import java.util.concurrent.ExecutorService;
3133
import java.util.concurrent.Executors;
3234
import java.util.concurrent.TimeUnit;
@@ -142,20 +144,22 @@ public boolean invokeBuild(int kind, String targetName, IAutoBuildConfigurationD
142144
boolean lastSequenceID = true;
143145

144146
// Run preBuildStep if existing
145-
String preBuildStep = autoData.getPrebuildStep();
146-
preBuildStep = resolve(preBuildStep, EMPTY_STRING, WHITESPACE, autoData);
147-
if (!preBuildStep.isEmpty()) {
148-
String announcement = autoData.getPreBuildAnouncement();
147+
TreeMap<String,String> preBuildSteps = autoData.getPrebuildSteps();
148+
for (Entry<String, String> preBuildStep:preBuildSteps.entrySet()) {
149+
String announcement = preBuildStep.getKey();
150+
String command = preBuildStep.getValue();
151+
149152
if (!announcement.isEmpty()) {
150153
buildRunnerHelper.toConsole(announcement);
151154
}
152-
buildRunnerHelper.toConsole(preBuildStep);
153-
if (launchCommand(preBuildStep, autoData, monitor, buildRunnerHelper) != 0) {
155+
buildRunnerHelper.toConsole(command);
156+
if (launchCommand(command, autoData, monitor, buildRunnerHelper) != 0) {
154157
if (autoData.stopOnFirstBuildError()) {
155158
return false;
156159
}
157160
}
158161
}
162+
159163
myHasBuildError = false;
160164
do {
161165
sequenceID++;
@@ -176,7 +180,7 @@ public boolean invokeBuild(int kind, String targetName, IAutoBuildConfigurationD
176180
lastSequenceID = false;
177181
//buildRunnerHelper.toConsole("Adding to executor " + curRule.getAnnouncement());
178182
if (!curRule.needsExecuting(buildRoot)) {
179-
buildRunnerHelper.toConsole("No need to run " + curRule.getAnnouncement());
183+
buildRunnerHelper.toConsole(Messages.InternalBuildRunner_NoNeedToRun + curRule.getAnnouncement());
180184
continue;
181185
}
182186

@@ -222,6 +226,24 @@ public boolean invokeBuild(int kind, String targetName, IAutoBuildConfigurationD
222226
}
223227
} while (!(lastSequenceID || myHasBuildError));
224228
// Run postBuildStep if existing
229+
230+
TreeMap<String,String> postBuildSteps = autoData.getPostbuildSteps();
231+
for (Entry<String, String> step:postBuildSteps.entrySet()) {
232+
String announcement = step.getKey();
233+
String command = step.getValue();
234+
235+
if (!announcement.isEmpty()) {
236+
buildRunnerHelper.toConsole(announcement);
237+
}
238+
buildRunnerHelper.toConsole(command);
239+
if (launchCommand(command, autoData, monitor, buildRunnerHelper) != 0) {
240+
if (autoData.stopOnFirstBuildError()) {
241+
return false;
242+
}
243+
}
244+
}
245+
246+
225247
String postBuildStep = autoData.getPostbuildStep();
226248
postBuildStep = resolve(postBuildStep, EMPTY_STRING, WHITESPACE, autoData);
227249
if (!postBuildStep.isEmpty()) {

io.sloeber.autoBuild/src/io/sloeber/autoBuild/integration/AutoBuildConfigurationDescription.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.sloeber.autoBuild.integration;
22

33
import static io.sloeber.autoBuild.helpers.api.AutoBuildConstants.*;
4+
import static io.sloeber.autoBuild.api.AutoBuildCommon.*;
45

56
import java.io.File;
67
import java.io.IOException;
@@ -1341,4 +1342,35 @@ public boolean equals(IAutoBuildConfigurationDescription other) {
13411342
}
13421343
return false;
13431344
}
1345+
1346+
@Override
1347+
public TreeMap<String, String> getPrebuildSteps() {
1348+
TreeMap<String, String> ret=new TreeMap<>();
1349+
1350+
String preBuildStep = resolve(getPrebuildStep(), EMPTY_STRING, WHITESPACE, this);
1351+
if (!preBuildStep.isEmpty()) {
1352+
String announcement = getPreBuildAnouncement();
1353+
ret.put(announcement,preBuildStep);
1354+
}
1355+
if(myAutoBuildCfgExtDes!=null) {
1356+
ret.putAll(myAutoBuildCfgExtDes.getPrebuildSteps());
1357+
}
1358+
return ret;
1359+
}
1360+
1361+
@Override
1362+
public TreeMap<String, String> getPostbuildSteps() {
1363+
TreeMap<String, String> ret=new TreeMap<>();
1364+
1365+
if(myAutoBuildCfgExtDes!=null) {
1366+
ret.putAll(myAutoBuildCfgExtDes.getPostbuildSteps());
1367+
}
1368+
1369+
String postBuildStep = resolve(getPostbuildStep(), EMPTY_STRING, WHITESPACE, this);
1370+
if (!postBuildStep.isEmpty()) {
1371+
String announcement = getPostBuildAnouncement();
1372+
ret.put(announcement,postBuildStep);
1373+
}
1374+
return ret;
1375+
}
13441376
}

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

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import static io.sloeber.core.Messages.*;
44
import static io.sloeber.core.api.Common.*;
55
import static io.sloeber.core.api.Const.*;
6+
import static io.sloeber.autoBuild.api.AutoBuildCommon.*;
67

78
import java.io.File;
9+
import java.io.IOException;
810
import java.util.ArrayList;
911
import java.util.Collections;
1012
import java.util.HashMap;
@@ -21,6 +23,7 @@
2123
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
2224
import org.eclipse.core.runtime.preferences.InstanceScope;
2325

26+
import io.sloeber.autoBuild.api.IAutoBuildConfigurationDescription;
2427
import io.sloeber.autoBuild.helpers.api.KeyValueTree;
2528
import io.sloeber.core.api.Json.ArduinoPlatform;
2629
import io.sloeber.core.api.Json.ArduinoPlatformTooldDependency;
@@ -1013,18 +1016,6 @@ private Map<String, String> getEnvVarsPostProcessing(Map<String, String> vars) {
10131016
Collections.sort(objcopyCommand);
10141017
extraVars.put(SLOEBER_OBJCOPY, StringUtil.join(objcopyCommand, NEWLINE));
10151018

1016-
// handle the hooks
1017-
extraVars.putAll(getEnvVarsHookBuild(vars, "sloeber.pre.link", //$NON-NLS-1$
1018-
"recipe.hooks.linking.prelink.XX.pattern", false)); //$NON-NLS-1$
1019-
extraVars.putAll(getEnvVarsHookBuild(vars, "sloeber.post.link", //$NON-NLS-1$
1020-
"recipe.hooks.linking.postlink.XX.pattern", true)); //$NON-NLS-1$
1021-
extraVars.putAll(getEnvVarsHookBuild(vars, "sloeber.prebuild", "recipe.hooks.prebuild.XX.pattern", //$NON-NLS-1$ //$NON-NLS-2$
1022-
false));
1023-
extraVars.putAll(getEnvVarsHookBuild(vars, "sloeber.sketch.prebuild", //$NON-NLS-1$
1024-
"recipe.hooks.sketch.prebuild.XX.pattern", false)); //$NON-NLS-1$
1025-
extraVars.putAll(getEnvVarsHookBuild(vars, "sloeber.sketch.postbuild", //$NON-NLS-1$
1026-
"recipe.hooks.sketch.postbuild.XX.pattern", false)); //$NON-NLS-1$
1027-
10281019
// add -relax for mega boards; the arduino ide way
10291020
String buildMCU = vars.get(ENV_KEY_BUILD_MCU);
10301021
if ("atmega2560".equalsIgnoreCase(buildMCU)) { //$NON-NLS-1$
@@ -1034,33 +1025,48 @@ private Map<String, String> getEnvVarsPostProcessing(Map<String, String> vars) {
10341025
return extraVars;
10351026
}
10361027

1037-
private static Map<String, String> getEnvVarsHookBuild(Map<String, String> vars, String varName, String hookName,
1038-
boolean post) {
1039-
Map<String, String> extraVars = new HashMap<>();
1040-
String envVarString = new String();
1041-
String searchString = "XX"; //$NON-NLS-1$
1042-
String postSeparator = VARIABLE_SUFFIX+NEWLINE;
1043-
String preSeparator = VARIABLE_PREFIX;
1044-
if (post) {
1045-
postSeparator =VARIABLE_PREFIX;
1046-
preSeparator = VARIABLE_SUFFIX+NEWLINE;
1047-
}
1048-
for (int numDigits = 1; numDigits <= 2; numDigits++) {
1049-
String formatter = "%0" + Integer.toString(numDigits) + "d"; //$NON-NLS-1$ //$NON-NLS-2$
1050-
int max = 10;
1051-
for (int counter = 1; counter < max; counter++) {
1052-
String hookVarName = hookName.replace(searchString, String.format(formatter, Integer.valueOf(counter)));
1053-
if (null != vars.get(hookVarName)) { // $NON-NLS-1$
1054-
envVarString = envVarString + preSeparator + hookVarName + postSeparator;
1055-
}
1056-
}
1057-
max = 100;
1058-
}
1059-
if (!envVarString.isEmpty()) {
1060-
extraVars.put(varName, envVarString);
1061-
}
1062-
return extraVars;
1063-
}
1028+
public TreeMap<String, String> getHookSteps(String hookName,IAutoBuildConfigurationDescription autoData) {
1029+
TreeMap<String, String> hookSteps = new TreeMap<>();
1030+
KeyValueTree keyValueTree = KeyValueTree.createRoot();
1031+
1032+
PlatformTxtFile referencedPlatfromFile = getreferencedCorePlatformFile();
1033+
// process the platform file referenced by the boards.txt
1034+
if (referencedPlatfromFile != null) {
1035+
try {
1036+
keyValueTree.mergeFile(referencedPlatfromFile.getLoadedFile());
1037+
} catch (IOException e) {
1038+
// TODO Auto-generated catch block
1039+
e.printStackTrace();
1040+
}
1041+
}
1042+
PlatformTxtFile referencingPlatfromFile = getReferencingPlatformFile();
1043+
// process the platform file next to the selected boards.txt
1044+
if (referencingPlatfromFile != null) {
1045+
try {
1046+
keyValueTree.mergeFile(referencingPlatfromFile.getLoadedFile());
1047+
} catch (IOException e) {
1048+
// TODO Auto-generated catch block
1049+
e.printStackTrace();
1050+
}
1051+
}
1052+
1053+
KeyValueTree hooks = keyValueTree.getChild(RECIPE).getChild(HOOKS).getChild(hookName);
1054+
1055+
// Try to find the nums from 1 to 10 in order
1056+
// that is 01 1 02 2
1057+
for (int hoookNum = 1; hoookNum < 10; hoookNum++) {
1058+
for (int numDigits = 1; numDigits <= 2; numDigits++) {
1059+
String formatter = "%0" + Integer.toString(numDigits) + "d"; //$NON-NLS-1$ //$NON-NLS-2$
1060+
String curKey = String.format(formatter, Integer.valueOf(hoookNum));
1061+
KeyValueTree curHook = hooks.getChild(curKey).getChild(PATTERN);
1062+
if (curHook.getValue() != null) {
1063+
String cmd=resolve(curHook.getValue(), EMPTY_STRING, WHITESPACE, autoData);
1064+
hookSteps.put(curKey, cmd);
1065+
}
1066+
}
1067+
}
1068+
return hookSteps;
1069+
}
10641070

10651071
public boolean isValid() {
10661072
if (!myUserSelectedBoardsTxtFile.exists()) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public class Const extends AutoBuildConstants {
5252
public static final String PORT = "port";
5353
public static final String AUTH = "auth";
5454
public static final String RECIPE = "recipe";
55+
public static final String HOOKS = "hooks";
56+
5557
public static final String BUILD = "build";
5658
public static final String SYSTEM = "system";
5759
public static final String COM_PORT = "com_port";

io.sloeber.core/src/io/sloeber/core/internal/SloeberConfiguration.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.util.Map;
77
import java.util.Map.Entry;
88
import java.util.Set;
9+
import java.util.TreeMap;
10+
911
import static io.sloeber.core.api.Common.*;
1012
import static io.sloeber.core.api.Const.*;
1113

@@ -575,4 +577,18 @@ public boolean equals(AutoBuildConfigurationExtensionDescription base) {
575577
return false;
576578
}
577579

580+
@Override
581+
public TreeMap<String, String> getPrebuildSteps() {
582+
TreeMap<String, String> ret=new TreeMap<>();
583+
ret.putAll(myBoardDescription.getHookSteps("prebuild",getAutoBuildDescription())); //$NON-NLS-1$
584+
return ret;
585+
}
586+
587+
@Override
588+
public TreeMap<String, String> getPostbuildSteps() {
589+
TreeMap<String, String> ret=new TreeMap<>();
590+
ret.putAll(myBoardDescription.getHookSteps("postbuild",getAutoBuildDescription())); //$NON-NLS-1$
591+
return ret;
592+
}
593+
578594
}

0 commit comments

Comments
 (0)