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

Strict deps infraction passes when it should fail- regression in 0.12.0-RC1 #4846

Closed
ittaiz opened this issue Mar 14, 2018 · 18 comments
Closed
Assignees

Comments

@ittaiz
Copy link
Member

ittaiz commented Mar 14, 2018

Description of the problem / feature request:

Bazel 0.12.0-RC1 (built from b33e5af) passes a strict deps infraction using rules_scala scala_import when it correctly fails it on 0.11.1

BUILD.bazel:

package(default_visibility = ["//visibility:public"])
load(
    "@io_bazel_rules_scala//scala:scala_import.bzl",
    "scala_import",
)

java_library(
    name = "leaf",
    srcs = ["Leaf.java"],
    deps = [":scala_import_transitive"],
)

#failure only on 0.11.1 bazel
java_import(
    name = "scala_import_transitive",
    jars = [],
    deps = [
        ":logback_scala_import",
    ],
)

scala_import(
    name = "logback_scala_import",
    jars = [
        "logback-classic-1.1.11.jar",
    ],
)

#failure on both 0.11.1 bazel and 0.12.0-rc1
java_import(
    name = "java_import_transitive",
    jars = [],
    deps = [":logback_java_import"],
)

java_import(
    name = "logback_java_import",
    jars = [
        "logback-classic-1.1.11.jar",
    ],
)

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

run bazel build on this [repo](repro: https://github.com/ittaiz/strict-deps-false-positive/tree/master
) with 0.11.1 and see it fail, then run it with the above bazel binary and see it pass

What operating system are you running Bazel on?

mac os

Any other information, logs, or outputs that you want to share?

I haven't been able to drill down and figure out if this is a scala_import issue or a java-skylark issue.
Might be relevant to add I'm also witnessing false negative issues with strict deps where it prints out warnings for direct dependencies. Still working on an isolated repro for that

@ittaiz
Copy link
Member Author

ittaiz commented Mar 14, 2018

cc @dslomov this is the issue we talked about

@buchgr
Copy link
Contributor

buchgr commented Mar 14, 2018

cc: @philwo

@cushon
Copy link
Contributor

cushon commented Mar 14, 2018

@tomlu fyi, see also b/74765278

@ittaiz
Copy link
Member Author

ittaiz commented Mar 15, 2018

This is crucial to our work, any chance a test will be added for this?
@cushon (and cc @iirina) this sounds related to #4584 in the sense that the current SJD behavior is very optimistic but breaks for many cases in the wild (maven jars and exports IMHO)

@ittaiz
Copy link
Member Author

ittaiz commented Mar 15, 2018

ok, I've tested out the commit but it doesn't restore the previous condition.
in 0.11.1 we had incorrect messages which we could tranform (via a script) to understand the real dependencies.
in 0.12.0-RC1 we have no messages
given this commit we have error messages but they are partial and somewhat misleading:

** Please add the following dependencies:
    to //some/path
 ** You can use the following buildozer command:
buildozer 'add deps  ' //some/path

If you try to apply these buildozer commands you get an error since no label is now being printed.
@iirina it sounds to me like @cushon also identify some of the problems we discussed (and led to #4584) but solved them in a way which is very problematic for existing users who worked around the problem.

@ittaiz
Copy link
Member Author

ittaiz commented Mar 15, 2018

IMHO the correct solution is to restore the previous condition and work on #4584 to resolve the problem in a more thorough manner.

@ittaiz
Copy link
Member Author

ittaiz commented Mar 15, 2018

I hope I'm not spamming this issue too much but the way we currently handle a missing label in rules scala is print:

Unknown label of file {jar_path} which came from {dependency_label}

This is not a good solution but I think it's better than not printing anything.
The ultimate solution IMHO is to have the JavaInfo contain a map of labels->jarPaths and pass that along to compiler plugins. That way all dependencies which stem from rules which output JavaInfo can be recognized and if you have a different one (filegroup for example) than print something like the above.

@cushon
Copy link
Contributor

cushon commented Mar 15, 2018

any chance a test will be added for this

it has test coverage, the test coverage is not open source. I don't know what Bazel team's plans are there, maybe @iirina does?

current SJD behavior is very optimistic but breaks for many cases in the wild (maven jars and exports IMHO)

I'm not sure what this means. Have bugs been filed for the cases where it breaks?

in 0.12.0-RC1 we have no messages

There are still messages, but the summary at the end with the add_dep command is broken.

This part is WAI:

Leaf.java:3: error: [strict] Using type ch.qos.logback.classic.Level from an indirect dependency (TOOL_INFO: "logback-classic-1.1.11.jar").

This part is incorrect:

buildozer 'add deps ' //:leaf 

The reason the add dep command is broken is that the information about the target label that produced the jar is now stored in the jar, and is added by ijar/JavaBuilder/turbine (e.g. support for this was added to ijar in 8a56b16).

If ijar is disabled, which scala_import does, then SJD doesn't know the label for the jar and can't provide an add_dep command. Maybe instead of java_common.create_provider(use_ijar) we should unconditionally use ijar (to ensure the label gets added to the manifest) but have a flag that to disable the regular ijar processing that removes the implementation (which scala can use). @iirina @tomlu WDYT?

@tomlu
Copy link
Contributor

tomlu commented Mar 15, 2018 via email

@ittaiz
Copy link
Member Author

ittaiz commented Mar 16, 2018 via email

@philwo
Copy link
Member

philwo commented Mar 16, 2018

Mandating ijar as well as deciding that is the interop mechanism instead of
command-line or providers should IMHO be discussed in the open.

I agree.

@philwo
Copy link
Member

philwo commented Mar 16, 2018

I'm not very knowledgeable about this part of Bazel, but I looked at the involved changes and it seems like this is impossible to rollback. Now, what do we do with Bazel 0.12.0?

@ittaiz I totally agree that this should have been discussed in the open. It's really not OK to break the work that our contributors do for Bazel. :(

@tomlu I think your answer is not really sufficient. You can't just break people's work, then not even apologize and then say "Oh, I don't have an opinion except that reverting my work is not an option". You're on the Bazel team, too - can you please follow up here and work with @ittaiz and @hsyed to find a good solution that works for everyone?

(FYI @ulfjack @davidstanke)

@tomlu
Copy link
Contributor

tomlu commented Mar 16, 2018 via email

@tomlu
Copy link
Contributor

tomlu commented Mar 19, 2018 via email

@philwo
Copy link
Member

philwo commented Mar 19, 2018

Thank you, @tomlu! :)

@tomlu
Copy link
Contributor

tomlu commented Mar 19, 2018 via email

@cushon
Copy link
Contributor

cushon commented Mar 19, 2018

As far as we understand it a macro implementation can call anything from the full compile time classpath, so we can't strip anything from the jar.

We can't strip anything from the jar or from any jars with methods that are reachable from the macro implementation. Macros seem to break the compile-time/runtime jar distinction in a way that I'm not sure is really fixable, unless we restrict ourselves to a subset of uses of macros. Keeping macro implementations on a separate classpath (similar to what is achieved for annotation processors by -processorpath and java_plugin) but I understand that's not how most real-world scala code is structured.

@ittaiz
Copy link
Member Author

ittaiz commented Mar 20, 2018

@philwo thank you, I appreciate it.

@tomlu @cushon thank your for your efforts; I think smarter people than me do have a few thoughts about how ijar can be fixed (IIUC you can classify macros and so tweak how much to strip given a macro but I might be wrong) over in #632 and if we can continue it there (even if just to finish the thought experiment and close that issue as won't fix) that would be valuable.

Concretely given the TOOL_INFO messages we were able to change our script to still find the relevant java_library <- scala_import bits and make them pass.
This means the usability has taken a somewhat significant regression blow for that use-case but I think we can say it's not a blocker.

I also suggest we continue the discussion about add_deps support and interoperability over in #4584

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

No branches or pull requests

6 participants