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