Skip to content

exclude man pages from jdk-lib - #389

Closed
skhal wants to merge 1 commit into
bazelbuild:masterfrom
skhal:jdk-lib-exclude-manuals
Closed

skhal wants to merge 1 commit into
bazelbuild:masterfrom
skhal:jdk-lib-exclude-manuals

Conversation

@skhal

@skhal skhal commented Oct 23, 2026

Copy link
Copy Markdown

jdk-lib generates a recursive fileset of library files from <prefix>/lib.

The <prefix>/lib may hold files that are not dynamic libraries such as man page archives, e.g.:

% find /usr/local/lib -type d -name man
/usr/local/lib/perl5/5.42/perl/man
/usr/local/lib/perl5/site_perl/man
/usr/local/lib/node_modules/npm/node_modules/cssesc/man
/usr/local/lib/node_modules/npm/man

% find /usr/local/lib/perl5/5.42/perl/man -type f -name \*.so\*

% find /usr/local/lib/perl5/5.42/perl/man -type f -name \*.gz | head -3
/usr/local/lib/perl5/5.42/perl/man/man1/perlcygwin.1.gz
/usr/local/lib/perl5/5.42/perl/man/man1/perlform.1.gz
/usr/local/lib/perl5/5.42/perl/man/man1/perlnumber.1.gz

One of the problems is that perl5 uses colon in man pages:

% find /usr/local/lib/perl5/5.42/perl/man -type f -name \*.gz | grep : | head -3
/usr/local/lib/perl5/5.42/perl/man/man3/Encode::JP.3.gz
/usr/local/lib/perl5/5.42/perl/man/man3/Test2::Event::Plan.3.gz
/usr/local/lib/perl5/5.42/perl/man/man3/Test::Builder.3.gz

Bazel target names (including files in the fileset) does not allow columns, leading to errors like this:

ERROR: /home/user/.cache/bazel/_bazel_example/2edd7b3f68d10f544e2471e3b7360f76/external/rules_java++toolchains+local_jdk/BUILD.bazel:51:10: @@rules_java++toolchains+local_jdk//:jdk-lib: invalid label 'lib/perl5/5.42/perl/man/man3/App::Cpan.3.gz' in element 14608 of attribute 'srcs' of 'filegroup': invalid target name ':Cpan.3.gz': target names may not contain ':'

This change excludes **/man/** folders from jdk-lib.

NO_ISSUE

jdk-lib generates a recursive fileset of library files from
`<prefix>/lib`.

The `<prefix>/lib` may hold files that are not dynamic libraries such as
man page archives, e.g.:

    % find /usr/local/lib -type d -name man
    /usr/local/lib/perl5/5.42/perl/man
    /usr/local/lib/perl5/site_perl/man
    /usr/local/lib/node_modules/npm/node_modules/cssesc/man
    /usr/local/lib/node_modules/npm/man

    % find /usr/local/lib/perl5/5.42/perl/man -type f -name \*.so\*

    % find /usr/local/lib/perl5/5.42/perl/man -type f -name \*.gz | head -3
    /usr/local/lib/perl5/5.42/perl/man/man1/perlcygwin.1.gz
    /usr/local/lib/perl5/5.42/perl/man/man1/perlform.1.gz
    /usr/local/lib/perl5/5.42/perl/man/man1/perlnumber.1.gz

One of the problems is that perl5 uses colon in man pages:

    % find /usr/local/lib/perl5/5.42/perl/man -type f -name \*.gz | grep : | head -3
    /usr/local/lib/perl5/5.42/perl/man/man3/Encode::JP.3.gz
    /usr/local/lib/perl5/5.42/perl/man/man3/Test2::Event::Plan.3.gz
    /usr/local/lib/perl5/5.42/perl/man/man3/Test::Builder.3.gz

Bazel target names (including files in the fileset) does not allow
columns, leading to errors like this:

    ERROR: /home/user/.cache/bazel/_bazel_example/2edd7b3f68d10f544e2471e3b7360f76/external/rules_java++toolchains+local_jdk/BUILD.bazel:51:10: @@rules_java++toolchains+local_jdk//:jdk-lib: invalid label 'lib/perl5/5.42/perl/man/man3/App::Cpan.3.gz' in element 14608 of attribute 'srcs' of 'filegroup': invalid target name ':Cpan.3.gz': target names may not contain ':'

This change excludes `**/man/**` folders from jdk-lib.

NO_ISSUE
@skhal
skhal requested review from a team and hvadehra as code owners October 23, 2026 20:06
@google-cla

google-cla Bot commented Oct 23, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@skhal

skhal commented Oct 23, 2026

Copy link
Copy Markdown
Author

Signed CLA

@fmeum

fmeum commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Wouldn't this only match if you set JAVA_HOME to /use/lib, which seems very problematic to begin with? Where is your local JDK installed?

@skhal

skhal commented Oct 24, 2026

Copy link
Copy Markdown
Author

I don't have JAVA_HOME configured in my environment:

% printenv | grep -i java
[rc: 1]

It runs on FreeBSD 15.1:

% uname -a
FreeBSD bsd.lab.net 15.1-RELEASE-p5 FreeBSD 15.1-RELEASE-p5 releng/15.1-n283639-893c7c99b60d GENERIC amd64

Bazel 9.3.0 is installed using pkg(8) and it picks up openjdk21:

% pkg info -d bazel9
bazel9-9.3.0_1:
        openjdk21-21.0.12+8.2_1
        python312-3.12.15
        FreeBSD-clibs-15.1p4 (libc++.so.1)
        FreeBSD-clibs-15.1p4 (libc.so.7)
        FreeBSD-clibs-15.1p4 (libcxxrt.so.1)
        FreeBSD-clibs-15.1p4 (libgcc_s.so.1)
        gcc12-12.5.0 (libgcc_s.so.1)
        gcc13-devel-13.4.1.s20260902 (libgcc_s.so.1)
        gcc14-14.2.0_7 (libgcc_s.so.1)
        gcc15-15.2.0_4 (libgcc_s.so.1)
        gcc16-16.1.0_3 (libgcc_s.so.1)
        gcc17-devel-17.0.0.s20261004 (libgcc_s.so.1)
        FreeBSD-clibs-15.1p4 (libm.so.5)
        FreeBSD-utilities-15.1p4 (libprocstat.so.1)
        FreeBSD-clibs-15.1p4 (libthr.so.3)

These packages install under /usr/local/ prefix, e.g.:

% pkg info openjdk21 | grep -i prefix
Prefix         : /usr/local

@skhal

skhal commented Oct 25, 2026

Copy link
Copy Markdown
Author

Bazel state:

% bazel info | grep 'java.*:'
java-home: /usr/local/openjdk21
java-runtime: OpenJDK Runtime Environment (build 21.0.12+8-2) by OpenJDK BSD Porting Team
java-vm: OpenJDK 64-Bit Server VM (build 21.0.12+8-2, mixed mode, sharing) by OpenJDK BSD Porting Team

@fmeum

fmeum commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

I'm not familiar with FreeBSD, but it looks like even with this PR Bazel would still glob and potentially digest all of /usr/local/lib. This should probably be avoided with a more extensive fix.

@hvadehra

Copy link
Copy Markdown
Member

I imagine what's happening is which javac is resolving to /usr/local/bin/javac which ordinarily would be a symlink but isn't in your case (and so /usr/local is assumed to be the java home).

I would recommend not using the local jdk (set --java_runtime_version=remotejdk_VERSION in your .bazelrc).

If that's not an option, either put the jdk bin directory earlier in your PATH or set JAVA_HOME.

@hvadehra hvadehra closed this Oct 26, 2026
@hvadehra hvadehra added the P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) label Oct 26, 2026
@skhal

skhal commented Oct 26, 2026

Copy link
Copy Markdown
Author

I'm not familiar with FreeBSD, but it looks like even with this PR Bazel would still glob and potentially digest all of /usr/local/lib. This should probably be avoided with a more extensive fix.

Indeed, it does glob everything from /usr/local/lib, well beyond Java and I was confused about that. my expectation is that it should selectively glob only Java part

I imagine what's happening is which javac is resolving to /usr/local/bin/javac which ordinarily would be a symlink but isn't in your case (and so /usr/local is assumed to be the java home).

I would recommend not using the local jdk (set --java_runtime_version=remotejdk_VERSION in your .bazelrc).

If that's not an option, either put the jdk bin directory earlier in your PATH or set JAVA_HOME.

I believe you refer to hermetic builds that are controlled via -java_runtime_version=remotejdk_${JAVA_VERION}:

https://bazel.build/docs/bazel-and-java#hermetic-testing

This PR attempts to fix non-hermetic builds, which is fine to use in certain setups.

As of java setup:

% which javac
/usr/local/bin/javac

% ls -l /usr/local/bin/javac
lrwxr-xr-x  1 root wheel 21 Oct 23 09:21 /usr/local/bin/javac -> /usr/local/bin/javavm

% ls -l /usr/local/bin/java*
lrwxr-xr-x  1 root wheel    21 Oct 23 09:21 /usr/local/bin/java -> /usr/local/bin/javavm
lrwxr-xr-x  1 root wheel    21 Oct 23 09:21 /usr/local/bin/javac -> /usr/local/bin/javavm
lrwxr-xr-x  1 root wheel    21 Oct 23 09:21 /usr/local/bin/javadoc -> /usr/local/bin/javavm
lrwxr-xr-x  1 root wheel    21 Oct 23 09:21 /usr/local/bin/javap -> /usr/local/bin/javavm
-r-xr-xr-x  1 root wheel 21018 Oct 14 20:03 /usr/local/bin/javavm

A bit more elaborate Java configuration info:

% java -XshowSettings:properties -version
Property settings:
    file.encoding = UTF-8
    file.separator = /
    java.class.path = 
    java.class.version = 65.0
    java.home = /usr/local/openjdk21
    java.io.tmpdir = /tmp/
    java.library.path = /usr/java/packages/lib/amd64
        /usr/lib
        /usr/local/lib
    java.runtime.name = OpenJDK Runtime Environment
    java.runtime.version = 21.0.12+8-2
    java.specification.name = Java Platform API Specification
    java.specification.vendor = Oracle Corporation
    java.specification.version = 21
    java.vendor = OpenJDK BSD Porting Team
    java.vendor.url = https://github.com/battleblow/jdk21u/
    java.vendor.url.bug = https://bugs.freebsd.org/bugzilla/enter_bug.cgi?product=Ports%20%26%20Packages&component=Individual%20Port(s)&short_desc=java/openjdk21%3A%20
    java.version = 21.0.12
    java.version.date = 2026-07-21
    java.vm.compressedOopsMode = Non-zero based
    java.vm.info = mixed mode, sharing
    java.vm.name = OpenJDK 64-Bit Server VM
    java.vm.specification.name = Java Virtual Machine Specification
    java.vm.specification.vendor = Oracle Corporation
    java.vm.specification.version = 21
    java.vm.vendor = OpenJDK BSD Porting Team
    java.vm.version = 21.0.12+8-2
    jdk.debug = release
    line.separator = \n 
    native.encoding = UTF-8
    os.arch = amd64
    os.name = FreeBSD
    os.version = 15.1-RELEASE-p5
    path.separator = :
    stderr.encoding = UTF-8
    stdout.encoding = UTF-8
    sun.arch.data.model = 64
    sun.boot.library.path = /usr/local/openjdk21/lib
    sun.cpu.endian = little
    sun.io.unicode.encoding = UnicodeLittle
    sun.java.launcher = SUN_STANDARD
    sun.jnu.encoding = UTF-8
    sun.management.compiler = HotSpot 64-Bit Tiered Compilers
    user.dir = /home/skhal/github/skhal/lab
    user.home = /home/skhal
    user.language = en
    user.name = skhal

openjdk version "21.0.12" 2026-07-21
OpenJDK Runtime Environment (build 21.0.12+8-2)
OpenJDK 64-Bit Server VM (build 21.0.12+8-2, mixed mode, sharing)

I suspect java.library.path is the reason for /usr/lib glob?

@hvadehra

Copy link
Copy Markdown
Member

The problem is the presence of the javavm wrapper.

You'll want to set the JAVA_HOME env var to /usr/local/openjdk21 or prepend that to your PATH env var.

@skhal

skhal commented Oct 27, 2026

Copy link
Copy Markdown
Author

Thanks for the tip. Indeed, Bazel now works:

$ env JAVA_HOME=/usr/local/openjdk21 bazel ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants