Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying Java with --java-bin-dirs or PATH #1030

Merged
merged 1 commit into from
Jan 29, 2021
Merged

Conversation

RyanGlScott
Copy link
Contributor

@RyanGlScott RyanGlScott commented Jan 21, 2021

Most of the action happens in:

  • The new SAWScript.JavaTools module, which exports functionality for locating a Java executable and finding its system properties.
  • SAWScript.Options, which now exposes a new --java-bin-dirs flag. (Alternatively, one can use the PATH.) The processEnv function now performs additional post-processing based on whether --java-bin-dirs/PATH are set.

Fixes #1022, and paves the way to #861.

doc/manual/manual.md Outdated Show resolved Hide resolved
@RyanGlScott RyanGlScott mentioned this pull request Jan 25, 2021
RyanGlScott added a commit that referenced this pull request Jan 27, 2021
This allows SAW to deal with JDK 9 or later, which packages its standard
library not in a JAR file, but in a JIMAGE file. Extracting `.class` files
from JIMAGE files proves to be surprisingly tricky, and I've carefully
documented the intricacies of doing so in
`Note [Loading classes from JIMAGE files]` in `SAWScript.JavaCodebase`.
This fixes #861.

This depends on #1030 to work.

Remaining tasks:

* Ideally, the code in `SAWScript.JavaCodebase` would be upstreamed to
  `crucible-jvm`, where the all-important `Codebase` data type lives.
  Unfortunately, some parts of SAW (e.g., `java_verify` still rely on
  the `jvm-verifier` library, which defines a separate `Codebase` type. SAW is
  in the process of phasing out the use of `jvm-verifier` in favor of
  `crucible-jvm` (see #993), but until that happens, I needed to introduce
  some ugly hacks in order to make everything typecheck.

  In particular, the (hopefully temporary) `SAWScript.JavaCodebase` module
  defines a shim version of `Codebase` that puts the experimental new things
  that I added in an `ExperimentalCodebase` constructor, but preserving the
  ability to use the `jvm-verifier` version of `Codebase` in the
  `LegacyCodebase` constructor. If JDK 8 or earlier is used, then
  `LegacyCodebase` is chosen, and if JDK 9 or later is used, then
  `ExperimentalCodebase` is chosen.

* Unfortunately, `java_verify` doesn't work with `ExperimentalCodebase`. Nor
  would we necessarily want to make this happen, as that would require
  upstreaming changes to `jvm-verifier`, which we are in the process of phasing
  out. As a result, this is blocked on #993.

* The CI should be updated to test more versions of the JDK than just 8.

Other things:

* I removed the dependency on the `xdg-basedir`, as it was unused. This
  dependency was likely added quite some time ago, and it appears that
  `saw-script` switched over to using XDG-related functionality from the
  `directory` library since then. I opted to use `directory` to find the
  `.cache` directory as well, so I have made that clear in the `.cabal` file.
Most of the action happens in:

* The new `SAWScript.JavaTools` module, which exports functionality for
  locating a Java executable and finding its system properties.
* `SAWScript.Options`, which now exposes a new `--java-bin-dirs` flag.
  (Alternatively, one can use the `PATH`.) The `processEnv` function now
  performs additional post-processing based on whether `--java-bin-dirs`/`PATH`
  are set.

Fixes #1022, and paves the way to a better user experience for #861.

Other things:

* I ended up cargo-culting some `process`-related code from
  `SAWScript.Builtins` for use in `SAWScript.JavaTools`. To avoid blatant
  code duplication (and because I end up needing the exact same code later in
  another patch), I factored out this code into the new
  `SAWScript.ProcessUtils` module. I considered putting it in the existing
  `SAWScript.Utils` module, but that would have led to import cycles. Sigh.
doc/manual/manual.md Outdated Show resolved Hide resolved
src/SAWScript/JavaTools.hs Outdated Show resolved Hide resolved
@RyanGlScott
Copy link
Contributor Author

I've rebased and resolved the TODOs. Barring any other review comments, this should be ready to go.

@RyanGlScott RyanGlScott marked this pull request as ready for review January 29, 2021 20:58
Copy link
Contributor

@atomb atomb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks great to me. Thanks!

@atomb
Copy link
Contributor

atomb commented Jan 29, 2021

I've added the next-to-merge tag to suggest that no one else merges anything else until this one is merged. Feel free to merge it as soon as CI completes.

@RyanGlScott RyanGlScott merged commit 50e325f into master Jan 29, 2021
@RyanGlScott RyanGlScott deleted the wip/T1022 branch January 29, 2021 22:55
RyanGlScott added a commit to GaloisInc/crucible that referenced this pull request Feb 3, 2021
This mirrors a similar recent change introduced to SAW in
GaloisInc/saw-script#1030.

While I was in town, I updated the two `crucible-jvm`–related test suites
to use the `PATH` instead of the `-j` flag. I can't exactly confirm via CI
if these changes work (see #634), but they appear to do the right thing
locally.

Fixes #633.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use java to detect standard JAR/JIMAGE paths
2 participants