[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
javacomp-script, javacomp: Add support for javac versions > 11
From: |
Bruno Haible |
Subject: |
javacomp-script, javacomp: Add support for javac versions > 11 |
Date: |
Sun, 11 Jun 2023 03:34:48 +0200 |
It was reported in <https://savannah.gnu.org/bugs/?63385> that Gnulib's
Java support does not work for javac versions 12..17.
At the time the 'javacomp-script' and 'javacomp' modules were written, each
major Java release required extra support code, so it was natural to limit
the support to the known versions. But nowadays, a new major Java release
occurs every 6 months [1], and the previous approach has three problems:
* After a new Java release is made, the time that elapses until
- support for it gets added to gnulib,
- a new gettext release is made that includes that support,
- the distros pull this new release,
- the user updates to this release and benefits from the support,
will most often be longer than 6 months, possibly two years or so.
That is, gettext will almost always be out-of-date.
* Adding new support to gnulib is a (small) manual effort, that includes
finding some piece of code that compiles with "javac -source N" but not
with "javac -source N-1".
* Bugs can be made in these code snippets. For example, I thought that
to detect '-source 11' as opposed to '-source 10', this code would work [2]:
class conftest { Readable r = (var b) -> 0; }
But it does not always work, namely in JDK 11 no error is shown for this:
$ jdk-10.0.2/bin/javac -d . -source 10 -target 10 conftest.java
conftest.java:1: error: 'var' is not allowed here
class conftest { Readable r = (var b) -> 0; }
^
1 error
$ jdk-11.0.2/bin/javac -d . -source 10 -target 10 conftest.java
warning: [options] bootstrap class path not set in conjunction with
-source 10
1 warning
$ jdk-12.0.2/bin/javac -d . -source 10 -target 10 conftest.java
warning: [options] bootstrap class path not set in conjunction with
-source 10
conftest.java:1: error: var syntax in implicit lambdas are not supported
in -source 10
class conftest { Readable r = (var b) -> 0; }
^
(use -source 11 or higher to enable var syntax in implicit lambdas)
1 error
1 warning
With these two patches, I'm adding support for the newer javac versions,
assuming
they follow the same patterns at seen in versions 11..20.
[1] https://en.wikipedia.org/wiki/Java_version_history
[2] https://en.wikipedia.org/wiki/Java_version_history#Java_11
2023-06-10 Bruno Haible <bruno@clisp.org>
javacomp-script, javacomp: Add support for javac versions > 11.
Reported by Adrian Bunk <bunk-gnu@fs.tum.de> in
<https://savannah.gnu.org/bugs/?63385>.
* m4/javacomp.m4 (gt_JAVACOMP): When the java version is > 11, use that
version as target_version, not 11. When the java version is > 17, don't
warn. Remove goodcode, failcode variables. Don't bail out if the
source-version argument or the target-version argument is in the range
12..99. Use a heuristic that works with javac versions 11..20 at least.
Update comments.
* lib/javacomp.h (compile_java_class): State that source-version and
target-version may be larger than 11.
* lib/javacomp.c (default_target_version): Accommodate versions up to
99.
(SOURCE_VERSION_BOUND): Increase to 94.
(source_version_index): Accept versions up to 99.
(get_goodcode_snippet, get_failcode_snippet): Remove functions.
(TARGET_VERSION_BOUND): Increase to 94.
(target_version_index): Accept versions up to 99.
(corresponding_classfile_version): Remove function.
(execute_and_read_line): New function, based on lib/javaversion.c.
(get_compiler_version): New function.
(is_envjavac_usable): Add parameters source_option_out,
target_option_out. Use a heuristic that works with javac versions 11..20
at least. Call cleanup_temp_dir.
(is_javac_usable): Likewise.
(compile_java_class): Update.
2023-06-10 Bruno Haible <bruno@clisp.org>
javacomp-script, javacomp: Remove support for javac versions < 1.6.
* m4/javacomp.m4 (gt_JAVACOMP): State that the minimum source_version
and the minimum target_version are 1.6. Map smaller values to 1.6.
Complain if the java version is < 1.6. Use 1.6 as default, instead of
1.1. Don't bother trying the -target option alone.
* lib/javacomp.h (compile_java_class): State that the minimum
source_version and the minimum target_version are 1.6.
* lib/javacomp.c (default_target_version): Complain if the java version
is < 1.6. Use 1.6 as default, instead of 1.1.
(SOURCE_VERSION_BOUND, source_version_index, get_goodcode_snippet,
get_failcode_snippet): Adjust to the new minimum source_version = 1.6.
(TARGET_VERSION_BOUND, target_version_index,
corresponding_classfile_version): Adjust to the new minimum
target_version = 1.6.
(get_source_version_for_javac): Remove function.
(is_envjavac_usable): Remove source_version_for_javac parameter. Don't
bother trying the -target option alone.
(is_javac_usable): Likewise.
(compile_java_class): Map source_version < 1.6 to 1.6. Map
target_version < 1.6 to 1.6. Use source_version instead of calling
get_source_version_for_javac.
0001-javacomp-script-javacomp-Remove-support-for-javac-ve.patch
Description: Text Data
0002-javacomp-script-javacomp-Add-support-for-javac-versi.patch
Description: Text Data
- javacomp-script, javacomp: Add support for javac versions > 11,
Bruno Haible <=