- Christian Gudrian
- 08/04/11
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
- Evgeny Schepotiev
- 08/19/11
You can set them in "mapping configuration"
- Evgeny Gryaznov
- 09/15/11
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
2. Use parameters in generator.
a. add parameter reference into mapping configuration, parameters section
b. use them in queries: genContext.<parameter_name>
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:
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.
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)
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>
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
Properties: string customJavaLocation;
b. Create make.properties file in the module's folder.
{languageName}.{facetName}.{facetTarget}.customJavaLocation=/bin/java
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)
