-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
281 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
filegroup( | ||
name = "bzl_srcs", | ||
srcs = ["//tools/java/runfiles:bzl_srcs"], | ||
visibility = ["//tools:__pkg__"], | ||
) | ||
|
||
exports_files(["java_stub_template.txt"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2017 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Automatically generated by the java_current_repository target: | ||
// __LABEL__ | ||
|
||
package com.google.devtools.build.runfiles; | ||
|
||
public final class RunfilesConstants { | ||
public static final String CURRENT_REPOSITORY = "__CURRENT_REPOSITORY__"; | ||
private RunfilesConstants() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright 2022 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
def _java_current_repository_impl(ctx): | ||
java_file = ctx.actions.declare_file("_java_current_repository/RunfilesConstants.java") | ||
ctx.actions.expand_template( | ||
template = ctx.file._template, | ||
output = java_file, | ||
substitutions = { | ||
"__LABEL__": str(ctx.label), | ||
"__CURRENT_REPOSITORY__": ctx.label.workspace_name, | ||
}, | ||
) | ||
|
||
jar_file = ctx.actions.declare_file("_java_current_repository/runfiles_constants.jar") | ||
java_info = java_common.compile( | ||
ctx, | ||
java_toolchain = ctx.toolchains["@bazel_tools//tools/jdk:toolchain_type"].java, | ||
# The JLS guarantees that constants are inlined. Since the generated code only contains | ||
# constants, we can remove it from the runtime classpath. This also serves to prevent | ||
# confusion as different repositories will compile against different versions of the | ||
# generated class, with an essentially arbitrary one appearing on the runtime classpath. | ||
neverlink = True, | ||
output = jar_file, | ||
source_files = [java_file], | ||
) | ||
|
||
return [ | ||
DefaultInfo(files = depset([jar_file])), | ||
java_info, | ||
] | ||
|
||
_java_current_repository = rule( | ||
attrs = { | ||
"_template": attr.label( | ||
default = "RunfilesConstants.java.tpl", | ||
allow_single_file = True, | ||
), | ||
}, | ||
implementation = _java_current_repository_impl, | ||
provides = [JavaInfo], | ||
fragments = ["java"], | ||
toolchains = [config_common.toolchain_type("@bazel_tools//tools/jdk:toolchain_type", mandatory = True)], | ||
) | ||
|
||
def java_current_repository(name, visibility = None, **kwargs): | ||
if visibility: | ||
fail("java_current_repository targets are automatically visible in all subpackages and should not be used from other repositories.", attr = "visibility") | ||
|
||
_java_current_repository( | ||
name = name, | ||
visibility = [":__subpackages__"], | ||
**kwargs | ||
) |