Where to set generator parameters


I have declared a couple of parameters in my mapping configuration. I may be blind, but: where can I set them?

Evgenii Schepotiev
Comment actions Permalink
You can set them in "mapping configuration"
Comment actions Permalink
The only way to pass parameters into generator is to create your own facet and participate in MPS make process. When you press Ctrl-F9, or click on the "Make project" button, MPS tries to figure out how to build the selected modules. First, it looks through all used languages in the selected scope and collects facets from them (if there are any). Facets consist of targets. All targets are ordered according to their dependencies and executed one by one.

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

parameter definitions javaArgs

pathToJava : string

2. Use parameters in generator.

a. add parameter reference into mapping configuration, parameters section
b. use them in queries: genContext.<parameter_name>

  pathToJava : string

is applicable:
  (genContext)->boolean {
  if (genContext.pathToJava == null || genContext.pathToJava.length() < 4) {
    genContext.show error "cannot generate without java location" -> <node>;

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
        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

   string customJavaLocation;

b. Create make.properties file in the module's folder.


c. Handle custom parameters:


Projects to play with:

For MPS 2.0.1: runJava_201.zip (74KB)
For MPS 2.0:   runJava_20.zip (73KB)

Please sign in to leave a comment.