2017-03-24 10:26:09 -07:00
|
|
|
package com.rusefi;
|
|
|
|
|
2023-06-17 11:07:21 -07:00
|
|
|
import com.rusefi.newparse.DefinitionsState;
|
2019-09-10 19:55:58 -07:00
|
|
|
import com.rusefi.output.*;
|
2023-02-11 11:29:17 -08:00
|
|
|
import com.rusefi.pinout.PinoutLogic;
|
2022-04-03 11:06:22 -07:00
|
|
|
import com.rusefi.trigger.TriggerWheelTSLogic;
|
2023-07-02 21:56:19 -07:00
|
|
|
import com.rusefi.util.LazyFile;
|
2021-07-02 10:11:11 -07:00
|
|
|
import com.rusefi.util.SystemOut;
|
2019-05-18 14:10:28 -07:00
|
|
|
|
2017-03-24 10:26:09 -07:00
|
|
|
import java.io.*;
|
2023-06-17 11:54:53 -07:00
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Paths;
|
2020-07-02 13:28:07 -07:00
|
|
|
import java.util.*;
|
2017-03-24 10:26:09 -07:00
|
|
|
|
|
|
|
/**
|
2020-06-09 17:08:16 -07:00
|
|
|
* Andrey Belomutskiy, (c) 2013-2020
|
2017-03-24 10:26:09 -07:00
|
|
|
* 1/12/15
|
2021-07-02 10:11:11 -07:00
|
|
|
*
|
2021-04-26 14:51:29 -07:00
|
|
|
* @see ConfigurationConsumer
|
2017-03-24 10:26:09 -07:00
|
|
|
*/
|
|
|
|
public class ConfigDefinition {
|
2022-01-04 22:10:02 -08:00
|
|
|
public static final String SIGNATURE_HASH = "SIGNATURE_HASH";
|
2019-05-26 17:54:44 -07:00
|
|
|
|
2022-04-15 18:57:08 -07:00
|
|
|
private static final String KEY_DEFINITION = "-definition";
|
2024-03-21 13:52:47 -07:00
|
|
|
private static final String KEY_TS_TEMPLATE = "-ts_template";
|
2022-04-15 18:57:08 -07:00
|
|
|
private static final String KEY_C_DESTINATION = "-c_destination";
|
2019-05-27 14:44:10 -07:00
|
|
|
private static final String KEY_C_DEFINES = "-c_defines";
|
2022-04-14 12:46:01 -07:00
|
|
|
public static final String KEY_WITH_C_DEFINES = "-with_c_defines";
|
2022-04-15 18:57:08 -07:00
|
|
|
private static final String KEY_JAVA_DESTINATION = "-java_destination";
|
2020-05-04 20:54:28 -07:00
|
|
|
private static final String KEY_FIRING = "-firing_order";
|
2022-04-14 12:46:01 -07:00
|
|
|
public static final String KEY_PREPEND = "-prepend";
|
2022-01-04 20:34:32 -08:00
|
|
|
private static final String KEY_SIGNATURE = "-signature";
|
|
|
|
private static final String KEY_SIGNATURE_DESTINATION = "-signature_destination";
|
2019-06-15 12:54:58 -07:00
|
|
|
private static final String KEY_ZERO_INIT = "-initialize_to_zero";
|
2021-01-22 09:03:14 -08:00
|
|
|
private static final String KEY_BOARD_NAME = "-board";
|
2023-06-17 16:28:42 -07:00
|
|
|
public static final String CONFIG_PATH = "java_tools/configuration_definition/src/main/resources/config_definition.options";
|
2017-03-24 10:26:09 -07:00
|
|
|
|
2020-08-14 12:38:56 -07:00
|
|
|
public static void main(String[] args) {
|
2019-06-10 20:13:32 -07:00
|
|
|
try {
|
2023-06-17 16:28:42 -07:00
|
|
|
List<String> options = Files.readAllLines(Paths.get("../" + CONFIG_PATH));
|
2023-06-17 11:54:53 -07:00
|
|
|
options.addAll(Arrays.asList(args));
|
|
|
|
String[] totalArgs = options.toArray(new String[0]);
|
2023-06-17 13:51:11 -07:00
|
|
|
if (totalArgs.length < 2) {
|
|
|
|
SystemOut.println("Please specify\r\n"
|
|
|
|
+ KEY_DEFINITION + " x\r\n"
|
2024-03-21 13:52:47 -07:00
|
|
|
+ KEY_TS_TEMPLATE + " x\r\n"
|
2023-06-17 13:51:11 -07:00
|
|
|
+ KEY_C_DESTINATION + " x\r\n"
|
|
|
|
+ KEY_JAVA_DESTINATION + " x\r\n"
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2023-06-17 11:54:53 -07:00
|
|
|
doJob(totalArgs, new ReaderStateImpl());
|
2019-06-10 20:13:32 -07:00
|
|
|
} catch (Throwable e) {
|
2019-06-17 17:21:32 -07:00
|
|
|
SystemOut.println(e);
|
2019-06-10 20:13:32 -07:00
|
|
|
e.printStackTrace();
|
|
|
|
System.exit(-1);
|
2023-06-17 10:51:46 -07:00
|
|
|
} finally {
|
|
|
|
SystemOut.close();
|
2019-06-10 20:13:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-17 16:28:42 -07:00
|
|
|
public static void doJob(String[] args, ReaderStateImpl state) throws IOException {
|
2021-07-13 06:01:08 -07:00
|
|
|
SystemOut.println(ConfigDefinition.class + " Invoked with " + Arrays.toString(args));
|
2020-05-04 20:54:28 -07:00
|
|
|
|
2024-03-21 13:52:47 -07:00
|
|
|
String tsTemplateFile = null;
|
2023-06-17 11:07:21 -07:00
|
|
|
|
|
|
|
DefinitionsState parseState = state.getEnumsReader().parseState;
|
2020-07-02 09:33:31 -07:00
|
|
|
String signatureDestination = null;
|
|
|
|
String signaturePrependFile = null;
|
2021-05-30 16:24:52 -07:00
|
|
|
List<String> enumInputFiles = new ArrayList<>();
|
2022-02-03 09:14:47 -08:00
|
|
|
PinoutLogic pinoutLogic = null;
|
2020-08-14 12:56:59 -07:00
|
|
|
|
2019-05-26 15:37:53 -07:00
|
|
|
for (int i = 0; i < args.length - 1; i += 2) {
|
|
|
|
String key = args[i];
|
2020-08-14 12:56:59 -07:00
|
|
|
switch (key) {
|
|
|
|
case "-tool":
|
2022-04-11 08:43:35 -07:00
|
|
|
// lame: order of command line arguments is important
|
2021-10-23 19:34:08 -07:00
|
|
|
ToolUtil.TOOL = args[i + 1];
|
2020-08-14 12:56:59 -07:00
|
|
|
break;
|
|
|
|
case KEY_DEFINITION:
|
2022-04-13 14:55:31 -07:00
|
|
|
// lame: order of command line arguments is important, these arguments should be AFTER '-tool' argument
|
2022-04-15 18:41:52 -07:00
|
|
|
state.setDefinitionInputFile(args[i + 1]);
|
2020-08-14 12:56:59 -07:00
|
|
|
break;
|
2024-03-21 13:52:47 -07:00
|
|
|
case KEY_TS_TEMPLATE:
|
|
|
|
tsTemplateFile = args[i + 1];
|
2021-11-26 20:48:23 -08:00
|
|
|
break;
|
2020-08-14 12:56:59 -07:00
|
|
|
case KEY_C_DESTINATION:
|
2022-04-15 18:57:08 -07:00
|
|
|
state.addCHeaderDestination(args[i + 1]);
|
2020-08-14 12:56:59 -07:00
|
|
|
break;
|
|
|
|
case KEY_ZERO_INIT:
|
2023-06-17 18:50:42 -07:00
|
|
|
BaseCHeaderConsumer.needZeroInit = Boolean.parseBoolean(args[i + 1]);
|
2020-08-14 12:56:59 -07:00
|
|
|
break;
|
|
|
|
case KEY_WITH_C_DEFINES:
|
2023-01-06 07:30:26 -08:00
|
|
|
state.setWithC_Defines(Boolean.parseBoolean(args[i + 1]));
|
2020-08-14 12:56:59 -07:00
|
|
|
break;
|
|
|
|
case KEY_C_DEFINES:
|
2023-06-17 11:07:21 -07:00
|
|
|
state.destCDefinesFileName = args[i + 1];
|
2020-08-14 12:56:59 -07:00
|
|
|
break;
|
|
|
|
case KEY_JAVA_DESTINATION:
|
2022-04-15 18:57:08 -07:00
|
|
|
state.addJavaDestination(args[i + 1]);
|
2020-08-14 12:56:59 -07:00
|
|
|
break;
|
2022-12-20 08:42:34 -08:00
|
|
|
case "-field_lookup_file": {
|
|
|
|
String cppFile = args[i + 1];
|
|
|
|
String mdFile = args[i + 2];
|
|
|
|
i++;
|
2023-07-02 21:56:19 -07:00
|
|
|
state.addDestination(new GetConfigValueConsumer(cppFile, mdFile, LazyFile.REAL));
|
2022-12-20 08:42:34 -08:00
|
|
|
}
|
2021-12-15 16:43:31 -08:00
|
|
|
break;
|
2021-11-28 14:55:33 -08:00
|
|
|
case "-readfile":
|
|
|
|
String keyName = args[i + 1];
|
|
|
|
// yes, we take three parameters here thus pre-increment!
|
|
|
|
String fileName = args[++i + 1];
|
2022-04-18 09:22:50 -07:00
|
|
|
try {
|
2023-01-06 07:42:44 -08:00
|
|
|
state.getVariableRegistry().register(keyName, IoUtil2.readFile(fileName));
|
2022-04-18 09:22:50 -07:00
|
|
|
} catch (RuntimeException e) {
|
|
|
|
throw new IllegalStateException("While processing " + fileName, e);
|
|
|
|
}
|
2023-01-06 07:35:07 -08:00
|
|
|
state.addInputFile(fileName);
|
2023-06-17 11:49:03 -07:00
|
|
|
break;
|
2023-06-17 11:07:21 -07:00
|
|
|
case KEY_FIRING: {
|
|
|
|
String firingEnumFileName = args[i + 1];
|
|
|
|
ExtraUtil.handleFiringOrder(firingEnumFileName, state.getVariableRegistry(), parseState);
|
2023-01-06 07:35:07 -08:00
|
|
|
state.addInputFile(firingEnumFileName);
|
2023-06-17 11:07:21 -07:00
|
|
|
}
|
2020-08-14 12:56:59 -07:00
|
|
|
break;
|
2023-06-17 11:07:21 -07:00
|
|
|
case "-triggerInputFolder": {
|
|
|
|
String triggersInputFolder = args[i + 1];
|
|
|
|
new TriggerWheelTSLogic().execute(triggersInputFolder, state.getVariableRegistry());
|
|
|
|
}
|
2022-04-03 11:06:22 -07:00
|
|
|
break;
|
2020-08-14 12:56:59 -07:00
|
|
|
case KEY_PREPEND:
|
2022-04-15 18:57:08 -07:00
|
|
|
state.addPrepend(args[i + 1].trim());
|
2020-08-14 12:56:59 -07:00
|
|
|
break;
|
|
|
|
case KEY_SIGNATURE:
|
|
|
|
signaturePrependFile = args[i + 1];
|
2023-01-06 07:42:44 -08:00
|
|
|
state.getPrependFiles().add(args[i + 1]);
|
2020-08-14 12:56:59 -07:00
|
|
|
// don't add this file to the 'inputFiles'
|
|
|
|
break;
|
|
|
|
case KEY_SIGNATURE_DESTINATION:
|
|
|
|
signatureDestination = args[i + 1];
|
|
|
|
break;
|
2023-06-17 13:51:11 -07:00
|
|
|
case EnumToString.KEY_ENUM_INPUT_FILE: {
|
|
|
|
String enumInputFile = args[i + 1];
|
|
|
|
enumInputFiles.add(enumInputFile);
|
2024-03-09 18:39:55 -08:00
|
|
|
File file = new File(RootHolder.ROOT + enumInputFile);
|
|
|
|
try (Reader r = new FileReader(file)) {
|
|
|
|
state.read(r);
|
|
|
|
} catch (Throwable e) {
|
|
|
|
throw new IllegalStateException("Reading " + file.getAbsolutePath(), e);
|
|
|
|
}
|
2023-06-17 13:51:11 -07:00
|
|
|
}
|
2020-08-14 12:56:59 -07:00
|
|
|
break;
|
|
|
|
case "-ts_output_name":
|
2023-01-06 07:42:44 -08:00
|
|
|
state.setTsFileOutputName(args[i + 1]);
|
2020-08-14 12:56:59 -07:00
|
|
|
break;
|
2021-01-22 09:03:14 -08:00
|
|
|
case KEY_BOARD_NAME:
|
|
|
|
String boardName = args[i + 1];
|
2023-02-06 04:37:17 -08:00
|
|
|
pinoutLogic = PinoutLogic.create(boardName);
|
2023-02-11 12:20:10 -08:00
|
|
|
for (String inputFile : pinoutLogic.getInputFiles())
|
|
|
|
state.addInputFile(inputFile);
|
2021-01-22 09:03:14 -08:00
|
|
|
break;
|
2019-05-26 15:37:53 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-21 13:52:47 -07:00
|
|
|
if (tsTemplateFile != null) {
|
2021-04-29 19:26:20 -07:00
|
|
|
// used to update .ini files
|
2024-03-21 13:52:47 -07:00
|
|
|
state.addInputFile(tsTemplateFile);
|
2020-06-27 11:23:51 -07:00
|
|
|
}
|
|
|
|
|
2023-06-17 13:51:11 -07:00
|
|
|
SystemOut.println(state.getEnumsReader().getEnums().size() + " total enumsReader");
|
2021-05-30 16:24:52 -07:00
|
|
|
|
2021-11-06 15:17:03 -07:00
|
|
|
// Add the variable for the config signature
|
2023-01-06 07:35:07 -08:00
|
|
|
FirmwareVersion uniqueId = new FirmwareVersion(IoUtil2.getCrc32(state.getInputFiles()));
|
2024-03-21 13:52:47 -07:00
|
|
|
SignatureConsumer.storeUniqueBuildId(state, parseState, tsTemplateFile, uniqueId);
|
2021-04-29 18:15:08 -07:00
|
|
|
|
2022-04-03 11:06:22 -07:00
|
|
|
|
2022-06-18 14:24:50 -07:00
|
|
|
if (pinoutLogic != null) {
|
2023-02-11 12:12:55 -08:00
|
|
|
pinoutLogic.registerBoardSpecificPinNames(state.getVariableRegistry(), parseState, state.getEnumsReader());
|
2022-06-18 14:24:50 -07:00
|
|
|
}
|
|
|
|
|
2024-03-21 13:52:47 -07:00
|
|
|
if (tsTemplateFile != null) {
|
|
|
|
state.addDestination(new TSProjectConsumer(tsTemplateFile, state));
|
2020-07-02 09:33:31 -07:00
|
|
|
|
|
|
|
VariableRegistry tmpRegistry = new VariableRegistry();
|
2020-07-02 11:19:35 -07:00
|
|
|
// store the CRC32 as a built-in variable
|
2022-10-27 19:12:39 -07:00
|
|
|
tmpRegistry.register(SIGNATURE_HASH, uniqueId.encode());
|
2021-10-23 19:34:08 -07:00
|
|
|
tmpRegistry.readPrependValues(signaturePrependFile);
|
2023-01-06 07:42:44 -08:00
|
|
|
state.addDestination(new SignatureConsumer(signatureDestination, tmpRegistry));
|
2019-05-26 15:37:53 -07:00
|
|
|
}
|
2021-12-01 20:00:54 -08:00
|
|
|
|
2022-04-16 10:57:16 -07:00
|
|
|
state.doJob();
|
2019-05-26 15:37:53 -07:00
|
|
|
}
|
2017-03-24 10:26:09 -07:00
|
|
|
}
|