|
| 1 | +--- |
| 2 | +title: Compile Mojo |
| 3 | +keywords: |
| 4 | + - compile |
| 5 | + - maven |
| 6 | + - goal |
| 7 | + - "rascal:compile" |
| 8 | +--- |
| 9 | + |
| 10 | +#### Synopsis |
| 11 | + |
| 12 | +Basic project configuration for Rascal projects, checking, compilation and running. |
| 13 | + |
| 14 | +#### Decription |
| 15 | + |
| 16 | +The `compile` mojo calls the Rascal static checker and compiler on the source code in a Rascal project. Also it uses information from the libraries the current project depends on (including the standard library). The configuration here is also the core of the configuration for the other maven plugins. |
| 17 | + |
| 18 | +All Rascal projects are assumed to be configured via a Maven `pom.xml` file. To use the Rascal compiler via the `mvn rascal:compile` goal: |
| 19 | +1. The Rascal compiler is made available to the project via adding a proper `<plugin>` tag for the `rascal-maven-plugin`. |
| 20 | +1. Dependencies on other Rascal or JVM-based projects are declared in with `<dependency>` tags. |
| 21 | +1. Running `mvn compile` or `mvn package` or `mvn install` will trigger the compiler, reporting errors, warnings and other information on the go. |
| 22 | +1. Other compilers, such as the Java compiler are also triggered, such that code that interacts between Rascal and Java can be loaded and executed later. |
| 23 | +1. All binary target files end up in the `./target/classes` folder |
| 24 | +1. With `mvn package` and `mvn install` the ((PackageMojo)) finally stores all target code in a `.jar` file. |
| 25 | +1. Repeated executions of `mvn compile` make sure to check and compile only the changed Rascal modules. |
| 26 | +1. `mvn clean` cleans the target folders to make sure everything is checked and compiled from scratch. |
| 27 | + |
| 28 | +#### Input/output behavior |
| 29 | + |
| 30 | +| *Input* | *Output* | *Description* | |
| 31 | +| ------- | -------- | ------------ | |
| 32 | +| Module.rsc | Module.tpl | "TModel" that encodes the binary interface of a compiled module. | |
| 33 | +| " | Module.constants | Constant values which are references by generated bytecode. | |
| 34 | +| " | $Module.java | Java source code that implements a Rascal module. | |
| 35 | +| " | $Module.parsers | Pre-generated parsers as used by `$Module.java` | |
| 36 | +| " | $ModuleTests.java | (Parametrized) JUnit tests extracted from `Module.rsc` | |
| 37 | + |
| 38 | +Next to these files the compiler outputs messages and their origin location: |
| 39 | +* `[ERROR]` messages report on mistakes made in `Module.rsc` that prevent the proper execution of (a part of) a `Module.rsc`. Erroneous code is not executable. |
| 40 | +* `[WARNING]` messages report on likely issues in `Module.rsc`; for example likely to be incomplete and throw an exception, or likely to never match and be dead, etc. |
| 41 | +* `[INFO]` messages provide information useful for understanding advanced features of Rascal or hint at to be deprecated behavior that a programmer might prepare themselves for. |
| 42 | + |
| 43 | +The configuration tags for the compile mojo are an extended subset of the standard fields of ((data:PathConfig)). |
| 44 | +The defaults are chosen such that you hardly have to use these tags. |
| 45 | + |
| 46 | +| *Configuration tag* | *Default* | *Description* | |
| 47 | +| ------------------- | ----------| ------------- | |
| 48 | +| `<srcs>` | `<src>./src/main/rascal</src>` | list of directories where `.rsc` files can be found | |
| 49 | +| `<libs>` | filled with `<dependencies>` | list of jar files or directories for the library dependencies | |
| 50 | +| `<ignores>` | empty | list of folders and files to skip while compiling | |
| 51 | +| `<generatedSources>` | `./target/generated-sources` | where the compiler stores intermediate Java code | |
| 52 | +| `<bin>` | `./target/classes` | where the binary output of the compiler is staged before it goes into the jar file | |
| 53 | +| `<logPathConfig>` | false | write the pathConfig to the log before compiling | |
| 54 | +| `<logImports>` | false | write imports and extends of each module to the log during compilation | |
| 55 | +| `<logWrittenFiles>` | false | log every file written including timestamp during compilation | |
| 56 | +| `<warnUnused>` | true | warn about unused declarations | |
| 57 | +| `<warnedUnusedFormals>` | true | warn about unused formal parameters (pattern variables of function signatures) | |
| 58 | +| `<warnUnusedPatternFormals>` | true | warn about unused variables in patterns | |
| 59 | +| `<errorsAsWarnings>` | false | with this the compiler never reports failure in the presence of errors | |
| 60 | +| `<warningsAsErrors>` | false | with this the compiler reports failure even if there are only warnings and no errors. Can not be true at the same time with `errorsAsWarnings` | |
| 61 | +| `<parallel>` | false | enables parallel compilation of a large group of `.rsc` source files | |
| 62 | +| `<parallelMax>` | `5` | restricts the number of parallel compiler processes. The mojo otherwises |
| 63 | +computes an estimate based on the number of processors and the available memory | |
| 64 | +| `<parallelPrechecks>` | empty | a list of files reachable from `<srcs>` that will be compiled before the |
| 65 | +other processes start. | |
| 66 | +| `<verbose>` | enables internal debugging prints of the compiler | |
| 67 | + |
| 68 | +#### Examples |
| 69 | + |
| 70 | +The compiler is configured in `pom.xml` in three locations: |
| 71 | +* `<dependencies>...</dependencies>` - each dependency leads to a compile-time library path entry, and a run-time JVM classpath entry. |
| 72 | +* the general `<configuration>...</configuration>` tags for Rascal mojos: |
| 73 | +```xml |
| 74 | +<plugins> |
| 75 | + <plugin> |
| 76 | + <groupId>org.rascalmpl</groupId> |
| 77 | + <artifactId>rascal-maven-plugin</artifactId> |
| 78 | + <version>${rascal-maven-plugin.version}</version> |
| 79 | + <configuration> |
| 80 | + ...configuration tags go here... |
| 81 | + </configuration> |
| 82 | + </plugin> |
| 83 | +</plugins> |
| 84 | +``` |
| 85 | +* and finally the specific `<configuration>...</configuration>` tag for the `compile` goal. |
| 86 | +```xml |
| 87 | + <plugin> |
| 88 | + <groupId>org.rascalmpl</groupId> |
| 89 | + <artifactId>rascal-maven-plugin</artifactId> |
| 90 | + <version>${rascal-maven-plugin.version}</version> |
| 91 | + <executions> |
| 92 | + <execution> |
| 93 | + <!-- "default-compile" works best, "default-cli" only if used only once --> |
| 94 | + <id>default-compile</id> |
| 95 | + <phase>compile</phase> |
| 96 | + <goals> |
| 97 | + <!-- it is possible to bind to other goals, but not recommended> --> |
| 98 | + <goal>compile</goal> |
| 99 | + </goals> |
| 100 | + <configuration> |
| 101 | + .... configuration tags go here .... |
| 102 | + </configuration> |
| 103 | + </execution> |
| 104 | + </executions> |
| 105 | +</plugin> |
| 106 | +``` |
| 107 | +* The latter overwrites the first, tag-by-tag |
| 108 | + |
| 109 | +Maven is typically executed on the Un*x or Windows commandline like so: |
| 110 | +```bash |
| 111 | +# Typically runs the compiler and the tests before packaging everything |
| 112 | +# in a jar file, and copying it to your local Maven repository: |
| 113 | +mvn install |
| 114 | + |
| 115 | +# like `install` but without copying to the Maven repository; |
| 116 | +mvn package |
| 117 | + |
| 118 | +# If configured as above in an `<execution>` This will run only the Rascal compiler |
| 119 | +mvn rascal:compile |
| 120 | + |
| 121 | +# runs everything _except the Rascal compiler_ |
| 122 | +mvn install -Drascal.compile.skip |
| 123 | +``` |
| 124 | + |
| 125 | +#### Benefits |
| 126 | + |
| 127 | +* The Maven configuration, including the dependencies listed in `pom.xml` enable reuse of other Rascal programs as libraries or development tools. |
| 128 | +* The Maven configuration, with the dependencies listed in `pom.xml` enable reuse of other JVM-based projects in the Maven Grand Central, or other repositories listed in the `pom.xml` |
| 129 | +* The rascal:compile mojo works find with multi-module Maven projects and parent projects. |
| 130 | + |
| 131 | +#### Pitfalls |
| 132 | + |
| 133 | +* The current rascal:compile mojo executes the static checker and generates a `.tpl` TModel for every Rascal `.rsc` source file. The`.tpl` file enables modular checking against the "binary" interface of other imported and extended modules. _The JVM bytecode generator is not active yet._ |
| 134 | +* The rascal:compile mojo is fully configured from the pom.xml. Other sources of configuration |
| 135 | +may still uses the `Sources` fields in `RASCAL.MF`. This discrepancy will be resolved in the coming months. |
| 136 | +* ((getProjectPathConfig)) may produce different configurations for source folders for the same reason. |
0 commit comments