|
| 1 | +--- |
| 2 | +title: Tutor Compilation |
| 3 | +keywords: |
| 4 | + - compilation |
| 5 | + - compiler |
| 6 | + - configuration |
| 7 | + - maven |
| 8 | + - deployment |
| 9 | + - incremental |
| 10 | + - dependency |
| 11 | + - dependencies |
| 12 | +--- |
| 13 | + |
| 14 | +After ((Authoring)) tutor files, they have to compiled down to plain docusaurus. The compiler implements features such as linking, screenshots, and executing code fragments. |
| 15 | +Most importantly, when there are linking errors (missing or ambiguous) or code execution errors, the compiler reports them such that they can be fixed before releasing the documentation. |
| 16 | + |
| 17 | +## Configuration |
| 18 | + |
| 19 | +The way to execute the rascal tutor compiler is via [rascal-maven-plugin](http://github.com/usethesource/rascal-maven-plugin). First it |
| 20 | +has to be configured for your project. |
| 21 | + |
| 22 | +Do configure the tutor, add the plugin to the pom.xml like so: |
| 23 | + |
| 24 | +```xml |
| 25 | +<plugins> |
| 26 | + <plugin> |
| 27 | + <groupId>org.rascalmpl</groupId> |
| 28 | + <artifactId>rascal-maven-plugin</artifactId> |
| 29 | + <version>0.16.0</version> |
| 30 | + <executions> |
| 31 | + <execution> |
| 32 | + <id>default-cli</id> |
| 33 | + <phase>compile</phase> |
| 34 | + <goals> |
| 35 | + <goal>tutor</goal> |
| 36 | + </goals> |
| 37 | + <configuration> |
| 38 | + <enableStandardLibrary>false</enableStandardLibrary> |
| 39 | + <errorsAsWarnings>false</errorsAsWarnings> |
| 40 | + <isPackageCourse>true</isPackageCourse> |
| 41 | + <bin>${project.build.outputDirectory}</bin> |
| 42 | + <srcs> |
| 43 | + <src>${project.basedir}/doc/Course1</src> |
| 44 | + <src>${project.basedir}/doc/Course2</src> |
| 45 | + <src>${project.basedir}/src/main/rascal</src> |
| 46 | + </srcs> |
| 47 | + <ignores> |
| 48 | + <ignore>${project.basedir}/src/main/rascal/experimental</ignore> |
| 49 | + </ignores> |
| 50 | + </configuration> |
| 51 | + </execution> |
| 52 | + </executions> |
| 53 | + </plugin> |
| 54 | +</plugins> |
| 55 | +``` |
| 56 | + |
| 57 | +1. `enableStandardLibrary` defines which library the links to standard library documentation refer to. Either the version of rascal that the rascal-maven-plugin depends on (`true`), or the version of rascal that the current project depends on (`false`). Also this defines which version of the library the code examples are executed against. |
| 58 | +2. `errorsAsWarnings` and `warningsAsError` define failure modes for the compiler. Maven will not fail if `errorsAsWarnings` is set to `true` even if there are errors. |
| 59 | +3. `isPackageCourse`, when set to `true` will nest all target documentation in `docs/Packages/projectName`, and rename `src/main/rascal` or `src` to `API`. All links will also be re-routed to these locations. Otherwise, when set to `false` all documentation ends up in `docs/Course1` and `docs/Course2`, etc. |
| 60 | +4. `bin` points to the place that defines the root of the resulting `jar` file. All generated files will endup in `bin/docs` and `bin/docs/assets`. This has to be the outputDirectory and if you forget to configure this, it will be set automatically anyway. The compiler also writes `bin/index.value` file after it is done, to store the entire linking index for future usage. This future use can be either the next run of the compiler, or a depending project downstream. |
| 61 | +5. `srcs` define root courses, some of which will be pure Concept hierarchies, and others could be the _root_ of Rascal source folders. Note that this also defines the search path for modules during code execution of `rascal-shell` blocks. |
| 62 | +6. `ignores` defines files or folders which are to be ignore. These could be folder names inside of Rascal source folders, or files of Rascal modules, or course concept folders, or course concept files. When a folder is ignored, this works transitively for the contents of that folder. |
| 63 | + |
| 64 | +## Dependencies |
| 65 | + |
| 66 | +If the current Maven project has dependencies then the `index.value` files in these jar files are located |
| 67 | +and imported in the current link index of the project. This allows you to refer to concepts in one of the |
| 68 | +projects you depend on, provided that project was also using the `rascal-maven-plugin` to run the tutor compiler. |
| 69 | + |
| 70 | +The dependency feature depends on the assumption that the `/docs` folders in the jar of the current project and the jars of the |
| 71 | +project it depends on are extracted into the `docs` folder of a Docusaurus project later, and that everything |
| 72 | +under `/docs/assets` in the same jars is copied to `static/assets`. The `rascal-website` project |
| 73 | +achieves this using the `resources` plugin `copy` commands. If you are running your own docusaurus site, |
| 74 | +then this should be re-implemented. |
| 75 | + |
| 76 | +## Execution |
| 77 | + |
| 78 | +Simply run the maven `compile` or `package` or `install` command to trigger the rascal tutor compiler: |
| 79 | + |
| 80 | +```bash |
| 81 | +$ mvn install |
| 82 | +``` |
| 83 | + |
| 84 | +However, to exclusively run the tutor you can try this: |
| 85 | + |
| 86 | +```bash |
| 87 | +$ mvn rascal:tutor |
| 88 | +``` |
| 89 | + |
| 90 | +If there are screenshots in the documentation, then selenium must be configured with the location of `chrome` and `chromedriver`: |
| 91 | + |
| 92 | +```bash |
| 93 | +$ mvn rascal:tutor -Dwebdriver.chrome.driver=`which chromedriver` -Dwebdriver.chrome.browser=`which chrome` |
| 94 | +``` |
| 95 | + |
| 96 | +Here we have used the bash feature to splice in the location of chromedrive and chrome using the `which` command. This requires both to |
| 97 | +be found on the system `PATH`. If this is not the case, provide the absolute path to the binaries of these two programs. Both on Mac |
| 98 | +and Windows the path to `Google Chrome`, for example, may contain many spaces and it is wise to wrap the path in double quotes. |
| 99 | + |
| 100 | +The tutor compiler is **incremental** in a certain way. Running the compile twice in a row, only the markdown files and Rascal modules that have been modified will be compiled again. The compiler |
| 101 | +reuses the output of the previous run, including error messages. All error messages and warnings, including those of unmodified files are |
| 102 | +always presented at the end. |
| 103 | + |
| 104 | +Simple run the tutor twice to recompile only what has changed: |
| 105 | + |
| 106 | +```bash |
| 107 | +mvn rascal:tutor |
| 108 | +mvn rascal:tutor |
| 109 | +``` |
| 110 | + |
| 111 | +:::warning |
| 112 | +When folders or files are renamed, the old output files remain in the `bin` folder as well as the old links to those in the link index file. |
| 113 | +This can lead to: |
| 114 | +* spurious link ambiguity; for example when `A/B.md` has moved to `C/B.md` both versions of `B` will be present in the link administration. |
| 115 | +* unreported missing links; for example when `A/B.md` has moved to A/C.md`, `B` will still be linked even though it is not present anymore. |
| 116 | + |
| 117 | +It is therefore always prudent to `mvn clean` such that the output directory including the `index.value` has been removed, when files or folder change name or location. |
| 118 | +::: |
| 119 | + |
| 120 | +## Deployment of documentation |
| 121 | + |
| 122 | +* When `mvn install` or `mvn package` is run with the correct configuration for the `bin` folder, then all markdown files and other assets (screenshots) end up in the `jar` file of the current project. |
0 commit comments