You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+97-5Lines changed: 97 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,13 @@
2
2
3
3
`mx` is a command line based tool for managing the development of (primarily) Java code. It includes a mechanism for specifying the dependencies as well as making it simple to build, test, run, update, etc the code and built artifacts. `mx` contains support for developing code spread across multiple source repositories. `mx` is written in Python (version 2.7) and is extensible.
4
4
5
-
The organizing principle of `mx` is a _suite_. A _suite_ is a directory containing one or more _projects_ and also under the control of a version control system. A suite may import one or more dependent suites. One suite is designated as the primary suite. This is normally the suite in whose directory `mx` is executed. The set of suites that are reachable from the primary suite by transitive closure of the imports relation form the set that `mx` operates on. The set of suites implicitly defines the set of projects. The action of building a suite is to compile the code in the projects and generate one or more distributions which are 'jar' files containing the compiled classes and related metadata.
5
+
The organizing principle of `mx` is a _suite_. A _suite_ is both a directory and the container for the components of the suite.
6
+
A suite component is either a _project_, _library_ or _distribution_. There are various flavors of each of these.
7
+
A suite may import and depend on other suites. For an execution of mx, exactly one suite is the primary suite.
8
+
This is either the suite in whose directory `mx` is executed or the value of the global `-p` mx option.
9
+
The set of suites reachable from the primary suite by transitive closure of the imports relation form the set that `mx` operates on.
6
10
7
-
### Running mx ###
11
+
### Running mx
8
12
9
13
`mx` can be run directly (i.e., `python2.7 mx/mx.py ...`), but is more commonly invoked via the `mx/mx` bash script (which includes a Python version check). Adding the `mx/` directory to your PATH simplifies executing `mx`. The `mx/mx.cmd` script should be used on Windows.
10
14
@@ -21,6 +25,55 @@ For an example of `mx` usage, see the [README][1] for the Graal project.
21
25
Note: There is a Bash completion script for global options and commands, located in `bash_completion` directory. Install it for example by `source`ing this script in your `~/.bashrc` file. If used, a temporary file `/tmp/mx-bash-completion-<project-path-hash>` is created and used for better performance. This should be OK since the `/tmp` directory is usually cleaned on every system startup.
22
26
[mx-honey](https://github.com/mukel/mx-honey) provides richer completions for `zsh` users.
23
27
28
+
### Suites
29
+
30
+
The definition of a suite and its components is in a file named `suite.py` in the _mx metadata directory_ of the
31
+
primary suite. This is the directory named `mx.<suite name>` in the suite's top level directory. For example,
32
+
for the `compiler` suite, it is `mx.compiler`. The format of `suite.py` is JSON with the following extensions:
33
+
* Python multi-line and single-quoted strings are supported
34
+
* Python hash comments are supported
35
+
36
+
### Java projects
37
+
38
+
Java source code is contained in a `project`. Here's an example of two [Graal compiler projects](https://github.com/oracle/graal/blob/b95d8827609d8b28993bb4468f5daa128a614e52/compiler/mx.compiler/suite.py#L129-L147):
The `javaCompliance` attribute can be a single number (e.g. `8`), the lower bound of a range (e.g. `8+`) or a fixed range (e.g. `9..11`).
62
+
This attribute specifies the following information:
63
+
* The maximum Java language level used by the project. This is the lower bound in a range. It is also used at the value for the `-source`
64
+
and `-target` javac options when compiling the project.
65
+
* The JDKs providing any internal JDK API used by the project. A project that does not use any internal JDK API should specify an
66
+
open range (e.g. `8+`). Otherwise, a JDK matching the exact version or range is required to compile the project.
67
+
68
+
Specifying JDKs to mx is done via the `--java-home` and `--extra-java-homes` options or
69
+
via the `JAVA_HOME` and `EXTRA_JAVA_HOMES` environment variables.
70
+
An option has precedence over the corresponding environment variable.
71
+
Mx comes with a `select_jdk` helper function for various shells that simplifies
72
+
switching between different values for `JAVA_HOME` and `EXTRA_JAVA_HOMES`. The
73
+
function definition is in a shell specific file next to `mx.py` (e.g. `select_jdk.bash`[select_jdk.bash]).
74
+
75
+
The `multiReleaseJarVersion` attribute is explained in the "Versioning sources for different JDK releases" section below.
76
+
24
77
### Unit testing with Junit <aname="junit"></a>
25
78
26
79
The `unittest` command supports running Junit tests in `mx` suites.
@@ -60,7 +113,46 @@ public @interface AddExports {
60
113
}
61
114
```
62
115
63
-
### URL rewriting ###
116
+
### Versioning sources for different JDK releases
117
+
118
+
Mx includes support for multiple versions of a Java source file that is heavily inspired
119
+
by [multi-release jars](https://docs.oracle.com/javase/10/docs/specs/jar/jar.html#multi-release-jar-files).
120
+
A versioned Java source has a base copy and one or more versioned copies. The signature of each
121
+
copy (i.e., methods and fields accessed from outside the source file) must be identical.
122
+
A versioned copy must be in a project whose Java compliance is greater than the project
123
+
containing the base copy. For example, the base copy of [GraalServices.java](https://github.com/oracle/graal/blob/1bc9e1c762c85303d1388f98149bb9bb402f0cff/compiler/src/org.graalvm.compiler.serviceprovider/src/org/graalvm/compiler/serviceprovider/GraalServices.java)
124
+
is in a [project with Java compliance of 8](https://github.com/oracle/graal/blob/1bc9e1c762c85303d1388f98149bb9bb402f0cff/compiler/mx.compiler/suite.py#L134).
125
+
There is a [GraalServices.java](https://github.com/oracle/graal/blob/1bc9e1c762c85303d1388f98149bb9bb402f0cff/compiler/src/org.graalvm.compiler.serviceprovider.jdk9/src/org/graalvm/compiler/serviceprovider/GraalServices.java)
126
+
source file that _presides over_ the base copy when running on JDK 9 or later.
127
+
The project containing the latter [uses](https://github.com/oracle/graal/blob/1bc9e1c762c85303d1388f98149bb9bb402f0cff/compiler/mx.compiler/suite.py#L144-L145)
128
+
the `multiReleaseJarVersion` attribute to denote that it contains classes to be packaged in
129
+
a versioned jar directory. It also specifies the earliest Java version for which it is valid.
130
+
131
+
When these projects are combined into the same mx distribution, mx will put these class files into the distribution
132
+
jar according to the multi-release jar format:
133
+
```
134
+
> jar tvf mxbuild/dists/graal.jar | grep GraalServices
135
+
1562 Tue May 22 22:19:02 CEST 2018 org/graalvm/compiler/serviceprovider/GraalServices$JMXService.class
136
+
6546 Tue May 22 22:19:02 CEST 2018 org/graalvm/compiler/serviceprovider/GraalServices.class
137
+
1146 Tue May 22 22:19:02 CEST 2018 META-INF/versions/9/org/graalvm/compiler/serviceprovider/GraalServices$1.class
138
+
1435 Tue May 22 22:19:02 CEST 2018 META-INF/versions/9/org/graalvm/compiler/serviceprovider/GraalServices$1$1.class
139
+
932 Tue May 22 22:19:02 CEST 2018 META-INF/versions/9/org/graalvm/compiler/serviceprovider/GraalServices$JMXService.class
140
+
6933 Tue May 22 22:19:02 CEST 2018 META-INF/versions/9/org/graalvm/compiler/serviceprovider/GraalServices.class
141
+
```
142
+
Resolving classes to the right version is done by the VM at runtime as explained in the JAR specification.
143
+
144
+
When a distribution also defines a module (e.g., [GRAAL](https://github.com/oracle/graal/blob/1bc9e1c762c85303d1388f98149bb9bb402f0cff/compiler/mx.compiler/suite.py#L1662)),
145
+
the versions are _flattened_ when creating the modular jar. That is, the modular jar contains only the class
146
+
files that would be resolved at runtime:
147
+
```
148
+
> jar tvf mxbuild/modules/jdk.internal.vm.compiler.jar | grep GraalServices
149
+
1146 Tue May 22 22:19:12 CEST 2018 org/graalvm/compiler/serviceprovider/GraalServices$1.class
150
+
1435 Tue May 22 22:19:12 CEST 2018 org/graalvm/compiler/serviceprovider/GraalServices$1$1.class
151
+
932 Tue May 22 22:19:12 CEST 2018 org/graalvm/compiler/serviceprovider/GraalServices$JMXService.class
152
+
6933 Tue May 22 22:19:12 CEST 2018 org/graalvm/compiler/serviceprovider/GraalServices.class
153
+
```
154
+
155
+
### URL rewriting
64
156
65
157
Mx includes support for the primary suite to be able to override the source URLs of imported suites.
66
158
The suite level `urlrewrites` attribute allows regular expression URL rewriting. For example:
@@ -85,7 +177,7 @@ Rewrite rules can also be specified by the `MX_URLREWRITES` environment variable
85
177
The value of this variable must either be a JSON object describing a single rewrite rule, a JSON array describing a list of rewrite rules or a file containing one of these JSON values.
86
178
Rewrites rules specified by `MX_URLREWRITES` are applied after rules specified by the primary suite.
87
179
88
-
### Environment variable processing ###
180
+
### Environment variable processing
89
181
90
182
Suites might require various environment variables to be defined for
91
183
the suite to work and mx provides `env` files to cache this
@@ -106,7 +198,7 @@ and override any value provided by the shell environment.
106
198
107
199
The `-v` option to `mx` will show the loading of `env` files during suite parsing.
108
200
109
-
### Multiple suites per repository ###
201
+
### Multiple suites per repository
110
202
111
203
Sometimes it might be convenient to group multiple suites inside a single repository.
112
204
In particular, this helps ensure that all these suites are synchronized and tested together.
0 commit comments