adds more configurability of output

This commit is contained in:
Eyck Jentzsch 2022-10-26 10:30:44 +02:00
parent 1d2384257e
commit 26fc38b7ee
7 changed files with 32 additions and 62 deletions

View File

@ -27,6 +27,7 @@ class RdlPreferencePage extends FieldEditorPreferencePage implements IWorkbenchP
addField(new ComboFieldEditor(PreferenceConstants.P_FILETYPES_TO_GENERATE, "File types to generate", #[#["All","all"], #["FW only","fw"], #["SC components","sc-comp"]], getFieldEditorParent()))
addField(new StringFieldEditor(PreferenceConstants.P_COMPONENT_PATH, "relative path for SystemC files", 30, getFieldEditorParent()))
addField(new StringFieldEditor(PreferenceConstants.P_FIRMWARE_PATH, "relative path for FW files", 30, getFieldEditorParent()))
addField(new StringFieldEditor(PreferenceConstants.P_COPYRIGHT_HEADER, "Copyright header", 40, 5, StringFieldEditor.VALIDATE_ON_KEY_STROKE, getFieldEditorParent()))
}
override init(IWorkbench workbench) {

View File

@ -59,44 +59,47 @@ class Main {
def run(String[] args) {
val opt = new Options(args, 0, Integer.MAX_VALUE);
opt.getSet().addOption("h", Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("v", Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("f", Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("n", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("o", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("I", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("fw", Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("sc", Multiplicity.ZERO_OR_ONE);
val optionSet = opt.getSet()
optionSet.addOption("h", Multiplicity.ZERO_OR_ONE);
optionSet.addOption("v", Multiplicity.ZERO_OR_ONE);
optionSet.addOption("f", Multiplicity.ZERO_OR_ONE);
optionSet.addOption("n", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
optionSet.addOption("o", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
optionSet.addOption("I", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
optionSet.addOption("fw", Multiplicity.ZERO_OR_ONE);
optionSet.addOption("sc", Multiplicity.ZERO_OR_ONE);
optionSet.addOption("sc-dir", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
optionSet.addOption("fw-dir", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
if (!opt.check(false, false)) { // Print usage hints
System.err.println("Usage is: " + USAGE_STR);
throw new MalformedParametersException(opt.getCheckErrors());
}
// Normal processing
if (opt.getSet().isSet("h")) {
if (optionSet.isSet("h")) {
println("Usage: " + USAGE_STR);
return
}
val verbose = if(opt.getSet().isSet("v")) true else false;
val verbose = if(optionSet.isSet("v")) true else false;
val setup = new StandaloneSetup()
if (opt.getSet().isSet("I")) {
if (optionSet.isSet("I")) {
val projectMapping = new ProjectMapping
projectMapping.projectName = "RDL Repository"
projectMapping.path = new File(opt.getSet().getOption("I").getResultValue(0)).canonicalFile.absolutePath
projectMapping.path = new File(optionSet.getOption("I").getResultValue(0)).canonicalFile.absolutePath
setup.addProjectMapping(projectMapping)
}
// Configure and start the generator
fileAccess.outputPath = 'src-gen/'
if(opt.getSet().isSet('o')){
fileAccess.outputPath = opt.getSet().getOption('o').getResultValue(0)
if(optionSet.isSet('o')){
fileAccess.outputPath = optionSet.getOption('o').getResultValue(0)
fileAccess.outputConfigurations.get(IFileSystemAccess.DEFAULT_OUTPUT)?.setOverrideExistingResources(true)
}
val context = new RdlGeneratorContext => [cancelIndicator = CancelIndicator.NullImpl]
context.forceOverwrite= opt.getSet().isSet('f')
if(opt.getSet().isSet('n'))
context.namespace=opt.getSet().getOption('n').getResultValue(0)
context.generateFw=opt.getSet().isSet('fw')
context.generateSc=opt.getSet().isSet('sc')
opt.getSet().getData().forEach [ String fileName |
context.forceOverwrite= optionSet.isSet('f')
if(optionSet.isSet('n'))
context.namespace=optionSet.getOption('n').getResultValue(0)
context.generateFw=optionSet.isSet('fw')
context.generateSc=optionSet.isSet('sc')
optionSet.getData().forEach [ String fileName |
if(verbose) println("Processing " + fileName);
// Load the resource
val resourceSet = resourceSetProvider.get as XtextResourceSet

View File

@ -1,6 +1,7 @@
package com.minres.rdl.generator;
/**
* see also https://www.infoworld.com/article/2074849/processing-command-line-arguments-in-java--case-closed.html
* The central class for option processing. Sets are identified by their name, but there is also
* an anonymous default set, which is very convenient if an application requieres only one set.
*/

View File

@ -24,12 +24,12 @@ class RDLGenerator extends AbstractGenerator {
if((p1=='fw' && genFW) || (p1!='fw' && genSC)) {
val header = gen.generateHeader(namespace)
val prefix = if(p1=="fw") 'fw-' else 'sc-'
val inclFileName = p1+'/'+it.effectiveName+'.h'
val inclFileName = (if(p1=="gen") p1 else '.') + '/'+it.effectiveName+'.h'
val inclCfg = fsa.outputConfig(prefix+'incl-out')
if((force || !fsa.isFile(inclFileName, inclCfg) || gen.overwrite) && header!==null && header.length>0)
fsa.generateFile(inclFileName, inclCfg, header)
val source = gen.generateSource(namespace)
val srcFileName = p1+'/'+it.effectiveName+'.cpp'
val srcFileName = (if(p1=="gen") p1 else '.') + '/'+it.effectiveName+'.cpp'
val srcCfg = fsa.outputConfig(prefix+'src-out')
if((force || !fsa.isFile(srcFileName, srcCfg) || gen.overwrite) && source!==null && source.length>0)
fsa.generateFile(srcFileName, srcCfg, source)

View File

@ -22,4 +22,6 @@ public class PreferenceConstants {
public static final String P_COMPONENT_PATH = "componentPath";
public static final String P_FIRMWARE_PATH = "firmwarePath";
public static final String P_COPYRIGHT_HEADER = "copyrightHeader";
}

View File

@ -5,6 +5,7 @@ import java.util.HashSet;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
/**
* Class used to initialize default preference values.
@ -19,7 +20,7 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer {
* initializeDefaultPreferences()
*/
public void initializeDefaultPreferences() {
IEclipsePreferences store = RdlPreferences.getPreferenceStore();
IEclipsePreferences store = InstanceScope.INSTANCE.getNode(PreferenceConstants.SCOPE_NAME);
store.putBoolean(PreferenceConstants.P_GENERATE_CSV, true);
String value = System.getProperty(PreferenceConstants.ADDRESSUNIT_PROP);
if(valid_addrunit_types.contains(value)){
@ -33,6 +34,7 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer {
store.put(PreferenceConstants.P_FILETYPES_TO_GENERATE, "all");
store.put(PreferenceConstants.P_COMPONENT_PATH, "");
store.put(PreferenceConstants.P_FIRMWARE_PATH, "");
store.put(PreferenceConstants.P_COPYRIGHT_HEADER, "Copyright (c) 2019 -2022 MINRES Technologies GmbH\n\nSPDX-License-Identifier: Apache-2.0");
}
}

View File

@ -1,39 +0,0 @@
package com.minres.rdl.preferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
public class RdlPreferences {
public static IEclipsePreferences getPreferenceStore() {
return InstanceScope.INSTANCE.getNode(PreferenceConstants.SCOPE_NAME);
}
public static boolean getGenerateCsv() {
return getPreferenceStore().getBoolean(PreferenceConstants.P_GENERATE_CSV, true);
}
public static String getAddrUnit() {
return getPreferenceStore().get(PreferenceConstants.P_ADDRESSUNIT, System.getProperty(PreferenceConstants.ADDRESSUNIT_PROP));
}
public static String getNamespace() {
return getPreferenceStore().get(PreferenceConstants.P_NAMESPACE, "sysc");
}
public static boolean getOverwriteStubs() {
return getPreferenceStore().getBoolean(PreferenceConstants.P_OVERWRITE_STUBS, false);
}
public static int getFielTypesToGenerate() {
return getPreferenceStore().getInt(PreferenceConstants.P_FILETYPES_TO_GENERATE, 3);
}
public static String getComponentPath() {
return getPreferenceStore().get(PreferenceConstants.P_COMPONENT_PATH, "");
}
public static String getFirmwarePath() {
return getPreferenceStore().get(PreferenceConstants.P_FIRMWARE_PATH, "");
}
}