-
Notifications
You must be signed in to change notification settings - Fork 694
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
Fix Bazel incompatible issues. #648
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
696f9fd
Fix Bazel incompatible issues.
xingao267 3c5f16d
Fix some tests and buildifier.
xingao267 5cfd02c
Inputs that can be executable should be in tools attribute.
xingao267 6fa82b5
buildifier
xingao267 eb21e86
Merge branch 'master' into fix
nlopezgi b060de6
Merge branch 'master' into fix
xingao267 5bbc701
Merge branch 'master' into fix
xingao267 6936027
Merge branch 'master' into fix
xingao267 5127355
Fix tests.
xingao267 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ The signature of java_image is compatible with java_binary. | |
The signature of war_image is compatible with java_library. | ||
""" | ||
|
||
load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external") | ||
load( | ||
"//container:container.bzl", | ||
"container_pull", | ||
|
@@ -75,9 +76,12 @@ def repositories(): | |
digest = _JETTY_DIGESTS["debug"], | ||
) | ||
if "javax_servlet_api" not in excludes: | ||
native.maven_jar( | ||
jvm_maven_import_external( | ||
name = "javax_servlet_api", | ||
artifact = "javax.servlet:javax.servlet-api:3.0.1", | ||
artifact_sha256 = "377d8bde87ac6bc7f83f27df8e02456d5870bb78c832dac656ceacc28b016e56", | ||
server_urls = ["http://central.maven.org/maven2"], | ||
licenses = ["notice"], # Apache 2.0 | ||
) | ||
|
||
DEFAULT_JAVA_BASE = select({ | ||
|
@@ -98,15 +102,15 @@ def java_files(f): | |
files = [] | ||
if java_common.provider in f: | ||
java_provider = f[java_common.provider] | ||
files += list(java_provider.transitive_runtime_jars) | ||
files += java_provider.transitive_runtime_jars.to_list() | ||
if hasattr(f, "files"): # a jar file | ||
files += list(f.files) | ||
files += f.files.to_list() | ||
return files | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better to have
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion. I'll do do that in a separate PR. |
||
|
||
def java_files_with_data(f): | ||
files = java_files(f) | ||
if hasattr(f, "data_runfiles"): | ||
files += list(f.data_runfiles.files) | ||
files += f.data_runfiles.files.to_list() | ||
return files | ||
|
||
def _jar_dep_layer_impl(ctx): | ||
|
@@ -150,28 +154,24 @@ jar_dep_layer = rule( | |
def _jar_app_layer_impl(ctx): | ||
"""Appends the app layer with all remaining runfiles.""" | ||
|
||
available = depset() | ||
for jar in ctx.attr.jar_layers: | ||
available += java_files(jar) # layers don't include runfiles | ||
# layers don't include runfiles | ||
available = depset(transitive = [depset(java_files(jar)) for jar in ctx.attr.jar_layers]) | ||
|
||
# We compute the set of unavailable stuff by walking deps | ||
# in the same way, adding in our binary and then subtracting | ||
# out what it available. | ||
unavailable = depset() | ||
for jar in ctx.attr.deps + ctx.attr.runtime_deps: | ||
unavailable += java_files_with_data(jar) | ||
|
||
unavailable += java_files_with_data(ctx.attr.binary) | ||
unavailable = [x for x in unavailable if x not in available] | ||
unavailable = depset(transitive = [depset(java_files_with_data(jar)) for jar in ctx.attr.deps + ctx.attr.runtime_deps]) | ||
unavailable = depset(transitive = [unavailable, depset(java_files_with_data(ctx.attr.binary))]) | ||
unavailable = [x for x in unavailable.to_list() if x not in available.to_list()] | ||
|
||
# Remove files that are provided by the JDK from the unavailable set, | ||
# as these will be provided by the Java image. | ||
jdk_files = depset(list(ctx.files._jdk)) | ||
jdk_files = depset(ctx.files._jdk) | ||
unavailable = [x for x in unavailable if x not in ctx.files._jdk] | ||
|
||
classpath = ":".join([ | ||
layer_file_path(ctx, x) | ||
for x in available + unavailable | ||
for x in depset(transitive = [available, depset(unavailable)]).to_list() | ||
]) | ||
|
||
# Classpaths can grow long and there is a limit on the length of a | ||
|
@@ -349,19 +349,15 @@ _war_dep_layer = rule( | |
def _war_app_layer_impl(ctx): | ||
"""Appends the app layer with all remaining runfiles.""" | ||
|
||
available = depset() | ||
for jar in ctx.attr.jar_layers: | ||
available += java_files(jar) | ||
available = depset(transitive = [depset(java_files(jar)) for jar in ctx.attr.jar_layers]) | ||
|
||
# This is based on rules_appengine's WAR rules. | ||
transitive_deps = depset() | ||
transitive_deps += java_files(ctx.attr.library) | ||
|
||
transitive_deps = depset(java_files(ctx.attr.library)) | ||
# TODO(mattmoor): Handle data files. | ||
|
||
# If we start putting libs in servlet-agnostic paths, | ||
# then consider adding symlinks here. | ||
files = [d for d in transitive_deps if d not in available] | ||
files = [d for d in transitive_deps.to_list() if d not in available.to_list()] | ||
|
||
return _container.image.implementation(ctx, files = files) | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xingao267 what is the reason for this change? Just trying to understand. I thought
tools
is for "tools" that are used to perform the action and theinputs
are for inputs i.e. files that are processed by the tools. Here all these things are inputs, not files, I think. Same in other files below.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I think I made that change because Bazel complains that some of these files were executable, so I put them into tools according to https://docs.bazel.build/versions/master/skylark/backward-compatibility.html#disallow-tools-in-action-inputs. Let me try to change it back to inputs to see if the CI complains about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why they are executable... From that page:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea. I was surprising too. I sent https://github.com/bazelbuild/rules_docker/pull/716/files to changed it back and I think it's fine. Maybe I mistakenly changed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing out!