Where to set generator parameters
Hi!
I have declared a couple of parameters in my mapping configuration. I may be blind, but: where can I set them?
Christian
I have declared a couple of parameters in my mapping configuration. I may be blind, but: where can I set them?
Christian
Please sign in to leave a comment.
The default facets workflow looks like that:
Generate -> TextGen -> JavaCompile -> Make (`the end of make marker')
Note: JavaCompile facet is provided by j.m.baseLanguage, it won't be invoked if your code doesn't contain java
Generate step consists of the following targets:
configure (init generator) -> preloadModels -> generate (generates models)
To be able to push parameters you need to insert your target somewhere between configure and generate.
1. Declare parameters in a separate model.
right click on your language -> New -> Model -> call it <name_of_the_language>.parameters
model settings:
Advanced -> Do not generate
Common -> Used languages -> add j.m.lang.generator.generationParameters
create root "generation parameters"
declare parameters with types
2. Use parameters in generator.
a. add parameter reference into mapping configuration, parameters section
b. use them in queries: genContext.<parameter_name>
parameters: pathToJava : string is applicable: (genContext)->boolean { if (genContext.pathToJava == null || genContext.pathToJava.length() < 4) { genContext.show error "cannot generate without java location" -> <node>; } true; }3. Declare facet.
Create plugin aspect in your language. Import two languages: j.m.make.facet and j.m.lang.generator.generationParameters.
Create root 'Facet'. Add target:
target detectJavaLocation overrides <none> { resources policy: pass through Dependencies: after configure before generate (input)->void { // default settings for all modules report info "detecting java location"; configure.parametersProvider.addParameter(genParameter<javaArgs>.pathToJava, "/usr/bin/java"); }4. Advanced topic: introducing per-module settings
Make allows to declare per-module parameters in a special make.properties file, which should be placed in the same folder as module file.
a. declare property in your facet's target
b. Create make.properties file in the module's folder.
{languageName}.{facetName}.{facetTarget}.customJavaLocation=/bin/javac. Handle custom parameters:
Projects to play with:
For MPS 2.0.1: runJava_201.zip (74KB)
For MPS 2.0: runJava_20.zip (73KB)