incremental code generation
This commit is contained in:
parent
a09484f492
commit
5588e8e323
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// generated by ConfigDefinition.jar tool based on rusefi_config.txt
|
||||
// was generated automatically by ConfigDefinition.jar based on integration\rusefi_config.txt
|
||||
//
|
||||
|
||||
#define accelerometerSpiDevice_offset 2736
|
||||
|
|
|
@ -5,7 +5,14 @@ rem the storage section of rusefi.ini is updated as well
|
|||
rem lazy is broken - TS input is not considered a change
|
||||
rm build/config.gen
|
||||
|
||||
java -jar ../java_tools/ConfigDefinition.jar -definition integration\rusefi_config.txt -romraider integration -ts_destination tunerstudio -c_defines controllers\algo\rusefi_generated.h -c_destination controllers\algo\engine_configuration_generated_structures.h -java_destination ../java_console -skip build/config.gen
|
||||
java -Drusefi.generator.lazyfile.enabled=true ^
|
||||
-jar ../java_tools/ConfigDefinition.jar ^
|
||||
-definition integration\rusefi_config.txt ^
|
||||
-romraider integration ^
|
||||
-ts_destination tunerstudio ^
|
||||
-c_defines controllers\algo\rusefi_generated.h ^
|
||||
-c_destination controllers\algo\engine_configuration_generated_structures.h ^
|
||||
-java_destination ../java_console -skip build/config.gen
|
||||
|
||||
|
||||
rem This would automatically copy latest file to 'dev' TS project
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<roms>
|
||||
|
||||
<!-- Generated by ConfigDefinition utility on Fri Feb 22 22:08:31 EST 2019 -->
|
||||
<!-- was generated automatically by ConfigDefinition.jar based on Sat Jun 01 16:45:56 EDT 2019 -->
|
||||
|
||||
<rom>
|
||||
<romid>
|
||||
|
|
Binary file not shown.
|
@ -2,7 +2,8 @@
|
|||
<configuration default="false" name="ConfigDefinition" type="Application" factoryName="Application" nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="com.rusefi.ConfigDefinition" />
|
||||
<module name="configuration_definition" />
|
||||
<option name="PROGRAM_PARAMETERS" value="-definition ../../firmware/integration/rusefi_config.txt -ts_destination ../../firmware/tunerstudio -c_destination ../../firmware/controllers\algo\engine_configuration_generated_structures.h -java_destination ../../java_console -skip lastMd5" />
|
||||
<option name="PROGRAM_PARAMETERS" value="-definition ../../firmware/integration/rusefi_config.txt -ts_destination ../../firmware/tunerstudio -c_destination ../../firmware/controllers\algo\engine_configuration_generated_structures.h -java_destination ../../java_console" />
|
||||
<option name="VM_PARAMETERS" value="-Drusefi.generator.lazyfile.enabled=true" />
|
||||
<RunnerSettings RunnerId="Debug">
|
||||
<option name="DEBUG_PORT" value="" />
|
||||
<option name="TRANSPORT" value="0" />
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.rusefi.output.CHeaderConsumer;
|
|||
import com.rusefi.output.ConfigurationConsumer;
|
||||
import com.rusefi.output.JavaFieldsConsumer;
|
||||
import com.rusefi.output.TSProjectConsumer;
|
||||
import com.rusefi.util.LazyFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.math.BigInteger;
|
||||
|
@ -20,6 +21,7 @@ import java.util.List;
|
|||
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
||||
public class ConfigDefinition {
|
||||
public static final String EOL = "\n";
|
||||
public static final String GENERATED_AUTOMATICALLY_TAG = "was generated automatically by ConfigDefinition.jar based on ";
|
||||
public static String MESSAGE;
|
||||
|
||||
private static final String ROM_RAIDER_XML_TEMPLATE = "rusefi_template.xml";
|
||||
|
@ -32,6 +34,7 @@ public class ConfigDefinition {
|
|||
private static final String KEY_CONSOLE_DESTINATION = "-java_destination";
|
||||
private static final String KEY_PREPEND = "-prepend";
|
||||
private static final String KEY_SKIP = "-skip";
|
||||
public static String definitionInputFile = null;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
if (args.length < 2) {
|
||||
|
@ -44,7 +47,6 @@ public class ConfigDefinition {
|
|||
return;
|
||||
}
|
||||
|
||||
String definitionInputFile = null;
|
||||
String tsPath = null;
|
||||
String destCHeader = null;
|
||||
String destCDefines = null;
|
||||
|
@ -76,7 +78,7 @@ public class ConfigDefinition {
|
|||
}
|
||||
}
|
||||
|
||||
MESSAGE = "was generated automatically by ConfigDefinition.jar based on " + definitionInputFile + " " + new Date();
|
||||
MESSAGE = GENERATED_AUTOMATICALLY_TAG + definitionInputFile + " " + new Date();
|
||||
|
||||
System.out.println("Reading from " + definitionInputFile);
|
||||
|
||||
|
@ -169,13 +171,12 @@ public class ConfigDefinition {
|
|||
System.out.println("Reading from " + inputFileName);
|
||||
System.out.println("Writing to " + outputFileName);
|
||||
|
||||
VariableRegistry.INSTANCE.put("generator_message", "Generated by ConfigDefinition utility on " + new Date());
|
||||
VariableRegistry.INSTANCE.put("generator_message", ConfigDefinition.GENERATED_AUTOMATICALLY_TAG + new Date());
|
||||
|
||||
File inputFile = new File(inputFileName);
|
||||
|
||||
File outputFile = new File(outputFileName);
|
||||
BufferedReader fr = new BufferedReader(new FileReader(inputFile));
|
||||
FileWriter fw = new FileWriter(outputFile);
|
||||
LazyFile fw = new LazyFile(outputFileName);
|
||||
|
||||
String line;
|
||||
while ((line = fr.readLine()) != null) {
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.util.LazyFile;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
@ -96,9 +97,9 @@ public class VariableRegistry extends TreeMap<String, String> {
|
|||
|
||||
public void writeNumericsToFile(String fileName) throws IOException {
|
||||
System.out.println("Writing to " + fileName);
|
||||
BufferedWriter cHeader = new BufferedWriter(new FileWriter(fileName));
|
||||
LazyFile cHeader = new LazyFile(fileName);
|
||||
|
||||
cHeader.write("//\n// generated by ConfigDefinition.jar tool based on rusefi_config.txt\n//\n\n");
|
||||
cHeader.write("//\n// " + ConfigDefinition.GENERATED_AUTOMATICALLY_TAG + ConfigDefinition.definitionInputFile + "\n//\n\n");
|
||||
for (String value : cAllDefinitions.values())
|
||||
cHeader.write(value);
|
||||
cHeader.close();
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.rusefi.output;
|
|||
import com.rusefi.ConfigDefinition;
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ConfigStructure;
|
||||
import com.rusefi.util.LazyFile;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
|
@ -15,11 +16,11 @@ import static com.rusefi.ConfigDefinition.EOL;
|
|||
*/
|
||||
public class CHeaderConsumer implements ConfigurationConsumer {
|
||||
public static final String BOOLEAN_TYPE = "bool";
|
||||
private final BufferedWriter cHeader;
|
||||
private final LazyFile cHeader;
|
||||
|
||||
public CHeaderConsumer(String destCHeader) throws IOException {
|
||||
System.out.println("Writing C header to " + destCHeader);
|
||||
cHeader = new BufferedWriter(new FileWriter(destCHeader));
|
||||
cHeader = new LazyFile(destCHeader);
|
||||
cHeader.write("// this section " + ConfigDefinition.MESSAGE + EOL);
|
||||
cHeader.write("// begin" + EOL);
|
||||
String id = destCHeader.replaceAll("[\\\\\\.\\/]", "_").toUpperCase();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.*;
|
||||
import com.rusefi.util.LazyFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.HashSet;
|
||||
|
@ -20,14 +21,14 @@ public class JavaFieldsConsumer implements ConfigurationConsumer {
|
|||
private final CharArrayWriter javaFieldsWriter;
|
||||
private final ReaderState state;
|
||||
private final String javaConsolePath;
|
||||
private final BufferedWriter javaFields;
|
||||
private final LazyFile javaFields;
|
||||
|
||||
public JavaFieldsConsumer(CharArrayWriter javaFieldsWriter, ReaderState state, String javaConsolePath) throws IOException {
|
||||
this.javaFieldsWriter = javaFieldsWriter;
|
||||
this.state = state;
|
||||
this.javaConsolePath = javaConsolePath;
|
||||
|
||||
javaFields = new BufferedWriter(new FileWriter(javaConsolePath + File.separator + JAVA_SOURCE_CODE_FILE_NAME));
|
||||
javaFields = new LazyFile(javaConsolePath + File.separator + JAVA_SOURCE_CODE_FILE_NAME);
|
||||
}
|
||||
|
||||
public static int writeJavaFields(List<ConfigField> tsFields, ReaderState state, String prefix, Writer javaFieldsWriter, int tsPosition) throws IOException {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.*;
|
||||
import com.rusefi.util.LazyFile;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
|
@ -99,7 +100,7 @@ public class TSProjectConsumer implements ConfigurationConsumer {
|
|||
TsFileContent tsContent = readTsFile(tsPath);
|
||||
System.out.println("Got " + tsContent.getPrefix().length() + "/" + tsContent.getPostfix().length() + " of " + TS_FILE_INPUT_NAME);
|
||||
|
||||
BufferedWriter tsHeader = new BufferedWriter(new FileWriter(tsPath + File.separator + TS_FILE_OUTPUT_NAME));
|
||||
LazyFile tsHeader = new LazyFile(tsPath + File.separator + TS_FILE_OUTPUT_NAME);
|
||||
tsHeader.write(tsContent.getPrefix());
|
||||
|
||||
tsHeader.write("; " + CONFIG_DEFINITION_START + ConfigDefinition.EOL);
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
package com.rusefi.util;
|
||||
|
||||
import com.rusefi.ConfigDefinition;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Scanner;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* This file would override file content only of content has changed, disregarding the magic tag line.
|
||||
*/
|
||||
public class LazyFile {
|
||||
private static final String PROPERTY_NAME = "rusefi.generator.lazyfile.enabled";
|
||||
private static boolean ENABLED = Boolean.getBoolean(PROPERTY_NAME);
|
||||
|
||||
static {
|
||||
System.out.println(PROPERTY_NAME + "=" + ENABLED);
|
||||
}
|
||||
|
||||
private String filename;
|
||||
|
||||
private final StringBuffer content = new StringBuffer();
|
||||
private final StringBuffer contentWithoutTag = new StringBuffer();
|
||||
|
||||
public LazyFile(String filename) {
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
public void write(String line) {
|
||||
content.append(line);
|
||||
if (!line.contains(ConfigDefinition.GENERATED_AUTOMATICALLY_TAG))
|
||||
contentWithoutTag.append(line);
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
String fileContent = unifySpaces(readCurrentContent(filename));
|
||||
String newContent = unifySpaces(contentWithoutTag.toString().trim());
|
||||
if (fileContent.equals(newContent)) {
|
||||
System.out.println(getClass().getSimpleName() + ": Not updating " + filename + " since looks to be the same content");
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < Math.min(fileContent.length(), newContent.length()); i++) {
|
||||
if (fileContent.charAt(i) != newContent.charAt(i)) {
|
||||
System.out.println(getClass().getSimpleName() + " " + filename + ": Not same at " + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
FileWriter fw = new FileWriter(filename);
|
||||
fw.write(content.toString());
|
||||
fw.close();
|
||||
}
|
||||
|
||||
private static String unifySpaces(String line) {
|
||||
return line.replaceAll("\n[\n]*", "\n").trim();
|
||||
}
|
||||
|
||||
private String readCurrentContent(String filename) throws IOException {
|
||||
if (!new File(filename).exists())
|
||||
return "";
|
||||
BufferedReader br = new BufferedReader(new FileReader(filename));
|
||||
Scanner in = new Scanner(Paths.get(filename), "UTF-8");
|
||||
String line;
|
||||
Pattern pat = Pattern.compile(".*\\R|.+\\z");
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while ((line = in.findWithinHorizon(pat, 0)) != null) {
|
||||
if (!line.contains(ConfigDefinition.GENERATED_AUTOMATICALLY_TAG))
|
||||
sb.append(line);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue