this tool was not properly using LazyFile

This commit is contained in:
rusefi 2020-05-14 18:23:38 -04:00
parent 4e5a69891d
commit 53863dfea8
4 changed files with 19 additions and 9 deletions

Binary file not shown.

View File

@ -72,6 +72,7 @@ public class EnumToString {
headerFileContent.append("#endif /*_A_H_HEADER_ */\r\n");
new File(outputPath).mkdirs();
writeCppAndHeaderFiles(outputPath + File.separator + "auto_generated_enums");
SystemOut.close();
}
@ -88,7 +89,7 @@ public class EnumToString {
private static void consumeFile(String inputPath, String inFileName) throws IOException {
File f = new File(inputPath + File.separator + inFileName);
SystemOut.println("Reading from " + inFileName);
SystemOut.println("Reading enums from " + inFileName);
String simpleFileName = f.getName();
bothFilesHeader.insert(0, "// " +
@ -99,11 +100,14 @@ public class EnumToString {
}
public static void outputData() {
SystemOut.println("Preparing output for " + EnumsReader.enums.size() + " enums\r\n");
for (Map.Entry<String, Map<String, Value>> e : EnumsReader.enums.entrySet()) {
String enumName = e.getKey();
cppFileContent.append(makeCode(enumName, e.getValue().values()));
EnumToString.headerFileContent.append(getMethodSignature(enumName) + ";\r\n");
headerFileContent.append(getMethodSignature(enumName) + ";\r\n");
}
SystemOut.println("EnumToString: " + headerFileContent.length() + " bytes of content\r\n");
}
public static void clear() {

View File

@ -22,13 +22,13 @@ public class EnumsReader {
line = removeSpaces(line);
if (line.startsWith("typedefenum{") || line.startsWith("typedefenum__attribute__")) {
SystemOut.println("Entering enum");
SystemOut.println(" EnumsReader: Entering enum");
currentValues.clear();
isInsideEnum = true;
} else if (line.startsWith("}") && line.endsWith(";")) {
isInsideEnum = false;
line = line.substring(1, line.length() - 1);
SystemOut.println("Ending enum " + line);
SystemOut.println(" EnumsReader: Ending enum " + line + " found " + currentValues.size() + " values");
enums.put(line, new TreeMap<>(currentValues));
} else {
line = line.replaceAll("//.+", "");
@ -41,7 +41,7 @@ public class EnumsReader {
value = line.substring(index + 1);
line = line.substring(0, index);
}
SystemOut.println("Line " + line);
SystemOut.println(" EnumsReader: Line " + line);
currentValues.put(line, new Value(line, value));
}
}

View File

@ -29,8 +29,12 @@ public class LazyFile implements Output {
@Override
public void write(String line) {
content.append(line);
if (!line.contains(LAZY_FILE_TAG))
contentWithoutTag.append(line);
String lines[] = line.split("\\r?\\n");
for (String subLine : lines) {
if (!subLine.contains(LAZY_FILE_TAG)) {
contentWithoutTag.append(subLine);
}
}
}
@Override
@ -38,7 +42,7 @@ public class LazyFile implements Output {
String fileContent = unifySpaces(readCurrentContent(filename));
String newContent = unifySpaces(contentWithoutTag.toString().trim());
if (fileContent.equals(newContent)) {
SystemOut.println(getClass().getSimpleName() + ": Not updating " + filename + " since looks to be the same content");
SystemOut.println(getClass().getSimpleName() + ": Not updating " + filename + " since looks to be the same content, new content size=" + contentWithoutTag.length());
return;
}
for (int i = 0; i < Math.min(fileContent.length(), newContent.length()); i++) {
@ -62,8 +66,10 @@ public class LazyFile implements Output {
}
private String readCurrentContent(String filename) throws IOException {
if (!new File(filename).exists())
if (!new File(filename).exists()) {
SystemOut.println(filename + " does not exist considering empty current content");
return "";
}
Scanner in = new Scanner(Paths.get(filename), IoUtils.CHARSET.name());
Pattern pat = Pattern.compile(".*\\R|.+\\z");
String line;