gen_config: add rusefi_config_custom.txt to override #defines #727
This commit is contained in:
parent
f41ff3cc61
commit
b863a673ef
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="false" project-jdk-name="1.8_32" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="svn" />
|
||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
</project>
|
|
@ -11,8 +11,8 @@ import java.util.Date;
|
|||
public class ConfigDefinition {
|
||||
public static final String EOL = "\n";
|
||||
private static final String INPUT_FILE_NAME = "rusefi_config.txt";
|
||||
public static final String MESSAGE = "was generated automatically by ConfigDefinition.jar based on " + INPUT_FILE_NAME + " " + new Date();
|
||||
public static final String TS_FILE_INPUT_NAME = "rusefi.input";
|
||||
static final String MESSAGE = "was generated automatically by ConfigDefinition.jar based on " + INPUT_FILE_NAME + " " + new Date();
|
||||
static final String TS_FILE_INPUT_NAME = "rusefi.input";
|
||||
private static final String STRUCT_NO_PREFIX = "struct_no_prefix ";
|
||||
private static final String STRUCT = "struct ";
|
||||
private static final String END_STRUCT = "end_struct";
|
||||
|
@ -26,9 +26,9 @@ public class ConfigDefinition {
|
|||
public static StringBuilder settingContextHelp = new StringBuilder();
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
if (args.length != 4) {
|
||||
if (args.length != 4 && args.length != 5) {
|
||||
System.out.println("Please specify path to '" + INPUT_FILE_NAME + "' file, path to " + TS_FILE_INPUT_NAME +
|
||||
" and destination folder");
|
||||
", destination folder and [optional] file name of custom prepend file");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -36,14 +36,18 @@ public class ConfigDefinition {
|
|||
String tsPath = args[1];
|
||||
String headerDestinationFolder = args[2];
|
||||
String javaConsolePath = args[3];
|
||||
String prependFile = args.length == 5 ? args[4] : null;
|
||||
String fullFileName = definitionInputPath + File.separator + INPUT_FILE_NAME;
|
||||
System.out.println("Reading from " + fullFileName);
|
||||
String destCHeader = headerDestinationFolder + File.separator + ENGINE_CONFIGURATION_GENERATED_STRUCTURES_H;
|
||||
System.out.println("Writing C header to " + destCHeader);
|
||||
|
||||
if (prependFile != null)
|
||||
readPrependValues(prependFile);
|
||||
|
||||
BufferedWriter cHeader = new BufferedWriter(new FileWriter(destCHeader));
|
||||
|
||||
BufferedReader br = new BufferedReader(new FileReader(fullFileName));
|
||||
BufferedReader definitionReader = new BufferedReader(new FileReader(fullFileName));
|
||||
|
||||
CharArrayWriter tsWriter = new CharArrayWriter();
|
||||
|
||||
|
@ -56,7 +60,7 @@ public class ConfigDefinition {
|
|||
ConfigurationConsumer tsProjectConsumer = new TSProjectConsumer(tsWriter, tsPath, state);
|
||||
ConfigurationConsumer javaFieldsConsumer = new JavaFieldsConsumer(javaFieldsWriter, state, javaConsolePath);
|
||||
|
||||
processFile(state, br, cHeaderConsumer, tsProjectConsumer, javaFieldsConsumer);
|
||||
processFile(state, definitionReader, cHeaderConsumer, tsProjectConsumer, javaFieldsConsumer);
|
||||
|
||||
state.ensureEmptyAfterProcessing();
|
||||
|
||||
|
@ -70,6 +74,23 @@ public class ConfigDefinition {
|
|||
processTextTemplate(inputFileName, outputFileName);
|
||||
}
|
||||
|
||||
private static void readPrependValues(String prependFile) throws IOException {
|
||||
BufferedReader definitionReader = new BufferedReader(new FileReader(prependFile));
|
||||
String line;
|
||||
while ((line = definitionReader.readLine()) != null) {
|
||||
line = trimLine(line);
|
||||
/**
|
||||
* we should ignore empty lines and comments
|
||||
*/
|
||||
if (isEmptyDefinitionLine(line))
|
||||
continue;
|
||||
if (startsWithToken(line, DEFINE)) {
|
||||
processDefine(line.substring(DEFINE.length()).trim());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void processTextTemplate(String inputFileName, String outputFileName) throws IOException {
|
||||
System.out.println("Reading from " + inputFileName);
|
||||
System.out.println("Writing to " + outputFileName);
|
||||
|
@ -90,7 +111,7 @@ public class ConfigDefinition {
|
|||
fw.close();
|
||||
}
|
||||
|
||||
private static void processFile(ReaderState state, BufferedReader br,
|
||||
private static void processFile(ReaderState state, BufferedReader definitionReader,
|
||||
ConfigurationConsumer cHeaderConsumer,
|
||||
ConfigurationConsumer tsProjectConsumer,
|
||||
ConfigurationConsumer javaFieldsConcumer) throws IOException {
|
||||
|
@ -98,13 +119,12 @@ public class ConfigDefinition {
|
|||
|
||||
cHeaderConsumer.startFile();
|
||||
|
||||
while ((line = br.readLine()) != null) {
|
||||
line = line.trim();
|
||||
line = line.replaceAll("\\s+", " ");
|
||||
while ((line = definitionReader.readLine()) != null) {
|
||||
line = trimLine(line);
|
||||
/**
|
||||
* we should ignore empty lines and comments
|
||||
*/
|
||||
if (line.length() == 0 || line.startsWith("!"))
|
||||
if (isEmptyDefinitionLine(line))
|
||||
continue;
|
||||
|
||||
if (line.startsWith(STRUCT)) {
|
||||
|
@ -134,6 +154,16 @@ public class ConfigDefinition {
|
|||
javaFieldsConcumer.endFile();
|
||||
}
|
||||
|
||||
private static boolean isEmptyDefinitionLine(String line) {
|
||||
return line.length() == 0 || line.startsWith("!");
|
||||
}
|
||||
|
||||
private static String trimLine(String line) {
|
||||
line = line.trim();
|
||||
line = line.replaceAll("\\s+", " ");
|
||||
return line;
|
||||
}
|
||||
|
||||
private static void handleCustomLine(ReaderState state, String line) {
|
||||
line = line.substring(CUSTOM.length() + 1).trim();
|
||||
int index = line.indexOf(' ');
|
||||
|
@ -222,7 +252,7 @@ public class ConfigDefinition {
|
|||
if (cf.isIterate) {
|
||||
structure.addC(cf);
|
||||
for (int i = 1; i <= cf.arraySize; i++) {
|
||||
ConfigField element = new ConfigField(state,cf.name + i, cf.comment, false, null,
|
||||
ConfigField element = new ConfigField(state, cf.name + i, cf.comment, false, null,
|
||||
cf.type, 1, cf.tsInfo, false);
|
||||
structure.addTs(element);
|
||||
}
|
||||
|
@ -248,8 +278,10 @@ public class ConfigDefinition {
|
|||
}
|
||||
|
||||
public static int getSize(String s) {
|
||||
if (VariableRegistry.INSTANCE.intValues.containsKey(s))
|
||||
if (VariableRegistry.INSTANCE.intValues.containsKey(s)) {
|
||||
VariableRegistry.INSTANCE.usedValues.add(s);
|
||||
return VariableRegistry.INSTANCE.intValues.get(s);
|
||||
}
|
||||
return Integer.parseInt(s);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,7 @@ import java.io.BufferedWriter;
|
|||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -21,10 +19,10 @@ public class VariableRegistry extends TreeMap<String, String> {
|
|||
private final Pattern VAR = Pattern.compile("(@@(.*?)@@)");
|
||||
|
||||
public Map<String, Integer> intValues = new HashMap<>();
|
||||
public Set<String> usedValues = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
private final StringBuilder cAllDefinitions = new StringBuilder("//\n// generated by ConfigDefinition.jar tool based on rusefi_config.txt\n//\n\n");
|
||||
private final StringBuilder javaNumbericDefinitions = new StringBuilder();
|
||||
private final StringBuilder javaStringDefinitions = new StringBuilder();
|
||||
private final Map<String, String> cAllDefinitions = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
private final Map<String, String> javaDefinitions = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
private VariableRegistry() {
|
||||
super(String.CASE_INSENSITIVE_ORDER);
|
||||
|
@ -54,7 +52,7 @@ public class VariableRegistry extends TreeMap<String, String> {
|
|||
System.out.println("Registering " + var + " as " + value);
|
||||
put(var, value);
|
||||
|
||||
cAllDefinitions.append("#define " + var + " " + value + EOL);
|
||||
cAllDefinitions.put(var, "#define " + var + " " + value + EOL);
|
||||
tryToRegisterAsInteger(var, value);
|
||||
}
|
||||
|
||||
|
@ -63,16 +61,16 @@ public class VariableRegistry extends TreeMap<String, String> {
|
|||
try {
|
||||
int intValue = Integer.parseInt(value);
|
||||
System.out.println("key [" + var + "] value: " + intValue);
|
||||
if (intValues.containsKey(var))
|
||||
throw new IllegalStateException("Not allowed to redefine: " + var);
|
||||
if (usedValues.contains(var))
|
||||
throw new IllegalStateException("Not allowed to redefine after value was used: " + var);
|
||||
intValues.put(var, intValue);
|
||||
javaNumbericDefinitions.append("\tpublic static final int " + var + " = " + intValue + ";" + EOL);
|
||||
javaDefinitions.put(var, "\tpublic static final int " + var + " = " + intValue + ";" + EOL);
|
||||
} catch (NumberFormatException e) {
|
||||
System.out.println("Not an integer: " + value);
|
||||
|
||||
if (isQuoted(value) && !var.trim().endsWith(ConfigField.ENUM_SUFFIX)) {
|
||||
// quoted and not with enum suffix means plain string define statement
|
||||
javaStringDefinitions.append("\tpublic static final String " + var + " = " + value + ";" + EOL);
|
||||
javaDefinitions.put(var, "\tpublic static final String " + var + " = " + value + ";" + EOL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,11 +94,16 @@ public class VariableRegistry extends TreeMap<String, String> {
|
|||
System.out.println("Writing to " + fileName);
|
||||
BufferedWriter cHeader = new BufferedWriter(new FileWriter(fileName));
|
||||
|
||||
cHeader.write(cAllDefinitions.toString());
|
||||
cHeader.write("//\n// generated by ConfigDefinition.jar tool based on rusefi_config.txt\n//\n\n");
|
||||
for (String value : cAllDefinitions.values())
|
||||
cHeader.write(value);
|
||||
cHeader.close();
|
||||
}
|
||||
|
||||
public String getJavaConstants() {
|
||||
return javaNumbericDefinitions.toString() + javaStringDefinitions.toString();
|
||||
StringBuffer result = new StringBuffer();
|
||||
for (String value : javaDefinitions.values())
|
||||
result.append(value);
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue