Skip to content

Commit 1c4adb1

Browse files
committed
[GR-10004] Make --strict-compliance default and the only supported mode.
PullRequest: mx/663
2 parents ee4fb11 + 50ba266 commit 1c4adb1

File tree

10 files changed

+540
-909
lines changed

10 files changed

+540
-909
lines changed

README.md

Lines changed: 97 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
`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.
44

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

7-
### Running mx ###
11+
### Running mx
812

913
`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.
1014

@@ -21,6 +25,55 @@ For an example of `mx` usage, see the [README][1] for the Graal project.
2125
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.
2226
[mx-honey](https://github.com/mukel/mx-honey) provides richer completions for `zsh` users.
2327

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):
39+
```python
40+
"org.graalvm.compiler.serviceprovider" : {
41+
"subDir" : "src",
42+
"sourceDirs" : ["src"],
43+
"dependencies" : ["JVMCI_SERVICES"],
44+
"checkstyle" : "org.graalvm.compiler.graph",
45+
"javaCompliance" : "8",
46+
"workingSets" : "API,Graal",
47+
},
48+
49+
"org.graalvm.compiler.serviceprovider.jdk9" : {
50+
"subDir" : "src",
51+
"sourceDirs" : ["src"],
52+
"dependencies" : ["org.graalvm.compiler.serviceprovider"],
53+
"uses" : ["org.graalvm.compiler.serviceprovider.GraalServices.JMXService"],
54+
"checkstyle" : "org.graalvm.compiler.graph",
55+
"javaCompliance" : "9+",
56+
"multiReleaseJarVersion" : "9",
57+
"workingSets" : "API,Graal",
58+
},
59+
```
60+
61+
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+
2477
### Unit testing with Junit <a name="junit"></a>
2578

2679
The `unittest` command supports running Junit tests in `mx` suites.
@@ -60,7 +113,46 @@ public @interface AddExports {
60113
}
61114
```
62115

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
64156

65157
Mx includes support for the primary suite to be able to override the source URLs of imported suites.
66158
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
85177
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.
86178
Rewrites rules specified by `MX_URLREWRITES` are applied after rules specified by the primary suite.
87179

88-
### Environment variable processing ###
180+
### Environment variable processing
89181

90182
Suites might require various environment variables to be defined for
91183
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.
106198

107199
The `-v` option to `mx` will show the loading of `env` files during suite parsing.
108200

109-
### Multiple suites per repository ###
201+
### Multiple suites per repository
110202

111203
Sometimes it might be convenient to group multiple suites inside a single repository.
112204
In particular, this helps ensure that all these suites are synchronized and tested together.

ci.hocon

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ overlay = b1fe46376e38f11fb6f9024110dc21b389063d71
33

44
# These are used in the overlay
55
java7 : {name : oraclejdk, version : "7", platformspecific: true}
6-
java8 : {name : labsjdk, version : "8u161-jvmci-0.42", platformspecific: true}
6+
java8 : {name : labsjdk, version : "8u171-jvmci-0.43", platformspecific: true}
77
java9 : {name : oraclejdk, version : "9.0.4+11", platformspecific: true}
88

99
downloads.java : {
10-
JAVA_HOME : {name : oraclejdk, version : "8u161", platformspecific: true}
10+
JAVA_HOME : {name : oraclejdk, version : "8u171", platformspecific: true}
1111
}
1212

1313
gate : {
@@ -30,6 +30,7 @@ gate : {
3030
}
3131

3232
bench-test : {
33+
downloads : ${downloads.java}
3334
run: [
3435
["./mx", "benchmark", "--results-file", "bench-results.json", "--ignore-suite-commit-info=mx", "test"]
3536
]

java/Signal.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

java/SignalHandler.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)