establishing a bit of API
This commit is contained in:
parent
841b6469c2
commit
cbcce9d84a
|
@ -43,7 +43,7 @@ public class ConfigDefinition {
|
|||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
doJob(args);
|
||||
doJob(args, new ReaderState());
|
||||
} catch (Throwable e) {
|
||||
SystemOut.println(e);
|
||||
e.printStackTrace();
|
||||
|
@ -53,7 +53,7 @@ public class ConfigDefinition {
|
|||
SystemOut.close();
|
||||
}
|
||||
|
||||
private static void doJob(String[] args) throws IOException {
|
||||
public static void doJob(String[] args, ReaderState state) throws IOException {
|
||||
if (args.length < 2) {
|
||||
SystemOut.println("Please specify\r\n"
|
||||
+ KEY_DEFINITION + " x\r\n"
|
||||
|
@ -70,21 +70,17 @@ public class ConfigDefinition {
|
|||
String destCDefinesFileName = null;
|
||||
String romRaiderDestination = null;
|
||||
// we postpone reading so that in case of cache hit we do less work
|
||||
List<String> prependFiles = new ArrayList<>();
|
||||
String romRaiderInputFile = null;
|
||||
String firingEnumFileName = null;
|
||||
String triggersFolder = null;
|
||||
String signatureDestination = null;
|
||||
String signaturePrependFile = null;
|
||||
List<String> enumInputFiles = new ArrayList<>();
|
||||
boolean withC_Defines = true;
|
||||
PinoutLogic pinoutLogic = null;
|
||||
String tsOutputsDestination = null;
|
||||
String definitionInputFile = null;
|
||||
|
||||
|
||||
List<ConfigurationConsumer> destinations = new ArrayList<>();
|
||||
ReaderState state = new ReaderState();
|
||||
|
||||
for (int i = 0; i < args.length - 1; i += 2) {
|
||||
String key = args[i];
|
||||
|
@ -95,9 +91,7 @@ public class ConfigDefinition {
|
|||
break;
|
||||
case KEY_DEFINITION:
|
||||
// lame: order of command line arguments is important, these arguments should be AFTER '-tool' argument
|
||||
definitionInputFile = args[i + 1];
|
||||
state.headerMessage = ToolUtil.getGeneratedAutomaticallyTag() + definitionInputFile + " " + new Date();
|
||||
state.inputFiles.add(definitionInputFile);
|
||||
state.setDefinitionInputFile(args[i + 1]);
|
||||
break;
|
||||
case KEY_TS_DESTINATION:
|
||||
tsInputFileFolder = args[i + 1];
|
||||
|
@ -106,13 +100,13 @@ public class ConfigDefinition {
|
|||
tsOutputsDestination = args[i + 1];
|
||||
break;
|
||||
case KEY_C_DESTINATION:
|
||||
destinations.add(new CHeaderConsumer(state, args[i + 1], withC_Defines));
|
||||
destinations.add(new CHeaderConsumer(state, args[i + 1], state.withC_Defines));
|
||||
break;
|
||||
case KEY_ZERO_INIT:
|
||||
needZeroInit = Boolean.parseBoolean(args[i + 1]);
|
||||
break;
|
||||
case KEY_WITH_C_DEFINES:
|
||||
withC_Defines = Boolean.parseBoolean(args[i + 1]);
|
||||
state.withC_Defines = Boolean.parseBoolean(args[i + 1]);
|
||||
break;
|
||||
case KEY_C_DEFINES:
|
||||
destCDefinesFileName = args[i + 1];
|
||||
|
@ -147,14 +141,14 @@ public class ConfigDefinition {
|
|||
String value = args[i + 1];
|
||||
// see UsagesReader use-case with dynamic prepend usage
|
||||
if (!value.trim().isEmpty()) {
|
||||
prependFiles.add(value);
|
||||
state.prependFiles.add(value);
|
||||
state.inputFiles.add(value);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case KEY_SIGNATURE:
|
||||
signaturePrependFile = args[i + 1];
|
||||
prependFiles.add(args[i + 1]);
|
||||
state.prependFiles.add(args[i + 1]);
|
||||
// don't add this file to the 'inputFiles'
|
||||
break;
|
||||
case KEY_SIGNATURE_DESTINATION:
|
||||
|
@ -202,7 +196,7 @@ public class ConfigDefinition {
|
|||
new TriggerWheelTSLogic().execute(triggersFolder, state.variableRegistry);
|
||||
|
||||
|
||||
for (String prependFile : prependFiles)
|
||||
for (String prependFile : state.prependFiles)
|
||||
state.variableRegistry.readPrependValues(prependFile);
|
||||
|
||||
if (pinoutLogic != null) {
|
||||
|
@ -217,7 +211,7 @@ public class ConfigDefinition {
|
|||
// Ignore duplicates of definitions made during prepend phase
|
||||
parseState.setDefinitionPolicy(Definition.OverwritePolicy.IgnoreNew);
|
||||
|
||||
for (String prependFile : prependFiles) {
|
||||
for (String prependFile : state.prependFiles) {
|
||||
RusefiParseErrorStrategy.parseDefinitionFile(parseState.getListener(), prependFile);
|
||||
}
|
||||
}
|
||||
|
@ -226,7 +220,7 @@ public class ConfigDefinition {
|
|||
{
|
||||
// don't allow duplicates in the main file
|
||||
parseState.setDefinitionPolicy(Definition.OverwritePolicy.NotAllowed);
|
||||
RusefiParseErrorStrategy.parseDefinitionFile(parseState.getListener(), definitionInputFile);
|
||||
RusefiParseErrorStrategy.parseDefinitionFile(parseState.getListener(), state.definitionInputFile);
|
||||
}
|
||||
|
||||
// Write C structs
|
||||
|
@ -260,12 +254,12 @@ public class ConfigDefinition {
|
|||
* this is the most important invocation - here we read the primary input file and generated code into all
|
||||
* the destinations/writers
|
||||
*/
|
||||
SystemOut.println("Reading definition from " + definitionInputFile);
|
||||
BufferedReader definitionReader = new BufferedReader(new InputStreamReader(new FileInputStream(definitionInputFile), IoUtils.CHARSET.name()));
|
||||
SystemOut.println("Reading definition from " + state.definitionInputFile);
|
||||
BufferedReader definitionReader = new BufferedReader(new InputStreamReader(new FileInputStream(state.definitionInputFile), IoUtils.CHARSET.name()));
|
||||
state.readBufferedReader(definitionReader, destinations);
|
||||
|
||||
if (destCDefinesFileName != null) {
|
||||
ExtraUtil.writeDefinesToFile(state.variableRegistry, destCDefinesFileName, definitionInputFile);
|
||||
ExtraUtil.writeDefinesToFile(state.variableRegistry, destCDefinesFileName, state.definitionInputFile);
|
||||
}
|
||||
|
||||
if (romRaiderDestination != null && romRaiderInputFile != null) {
|
||||
|
|
|
@ -38,6 +38,9 @@ public class ReaderState {
|
|||
public final Map<String, String> tsCustomLine = new HashMap<>();
|
||||
public final Map<String, ConfigStructure> structures = new HashMap<>();
|
||||
public String headerMessage;
|
||||
String definitionInputFile = null;
|
||||
public boolean withC_Defines = true;
|
||||
List<String> prependFiles = new ArrayList<>();
|
||||
|
||||
public final EnumsReader enumsReader = new EnumsReader();
|
||||
public final VariableRegistry variableRegistry = new VariableRegistry();
|
||||
|
@ -292,4 +295,10 @@ public class ReaderState {
|
|||
throw new NullPointerException("No header message yet");
|
||||
return headerMessage;
|
||||
}
|
||||
|
||||
public void setDefinitionInputFile(String definitionInputFile) {
|
||||
this.definitionInputFile = definitionInputFile;
|
||||
headerMessage = ToolUtil.getGeneratedAutomaticallyTag() + definitionInputFile + " " + new Date();
|
||||
inputFiles.add(definitionInputFile);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.rusefi.ldmp;
|
||||
|
||||
import com.rusefi.ConfigDefinition;
|
||||
import com.rusefi.ReaderState;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -35,11 +36,11 @@ public class UsagesReader {
|
|||
|
||||
EntryHandler handler = new EntryHandler() {
|
||||
@Override
|
||||
public void onEntry(String name, List elements) {
|
||||
public void onEntry(String name, List elements) throws IOException {
|
||||
String javaName = (String) elements.get(0);
|
||||
String folder = (String) elements.get(1);
|
||||
|
||||
String withCDefines = "false";
|
||||
boolean withCDefines = false;
|
||||
String prepend = "";
|
||||
for (int i = 2; i < elements.size(); i++) {
|
||||
String keyValue = (String) elements.get(i);
|
||||
|
@ -47,7 +48,7 @@ public class UsagesReader {
|
|||
String key = pair[0];
|
||||
String value = pair[1];
|
||||
if (key.equals(ConfigDefinition.KEY_WITH_C_DEFINES)) {
|
||||
withCDefines = value;
|
||||
withCDefines = Boolean.valueOf(value);
|
||||
} else if (key.equals(ConfigDefinition.KEY_PREPEND)) {
|
||||
prepend = value;
|
||||
}
|
||||
|
@ -56,12 +57,11 @@ public class UsagesReader {
|
|||
// String macroName = elements.size() > 2 ? ((String)elements.get(2)).trim() : "";
|
||||
|
||||
|
||||
ConfigDefinition.main(new String[]{
|
||||
ConfigDefinition.KEY_DEFINITION,
|
||||
folder + File.separator + name + ".txt",
|
||||
ConfigDefinition.KEY_WITH_C_DEFINES,
|
||||
withCDefines,
|
||||
ReaderState state = new ReaderState();
|
||||
state.setDefinitionInputFile(folder + File.separator + name + ".txt");
|
||||
state.withC_Defines = withCDefines;
|
||||
|
||||
ConfigDefinition.doJob(new String[]{
|
||||
ConfigDefinition.KEY_PREPEND,
|
||||
prepend,
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class UsagesReader {
|
|||
|
||||
ConfigDefinition.KEY_C_DESTINATION,
|
||||
folder + File.separator + name + "_generated.h"
|
||||
});
|
||||
}, state);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -80,7 +80,7 @@ public class UsagesReader {
|
|||
}
|
||||
|
||||
interface EntryHandler {
|
||||
void onEntry(String name, List elements);
|
||||
void onEntry(String name, List elements) throws IOException;
|
||||
}
|
||||
|
||||
private void handleYaml(Map<String, Object> data, EntryHandler handler) throws IOException {
|
||||
|
|
Loading…
Reference in New Issue