Skip to content

Should scala_import return jar output file provider (in addition to java_common provider)? #476

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

Open
natansil opened this issue Apr 9, 2018 · 9 comments
Assignees

Comments

@natansil
Copy link
Contributor

natansil commented Apr 9, 2018

During work on this PR I've noticed that location expansion of jars exposed by scala_import fails:
For example
$(location @com_google_guava_guava_21_0//jar) fails with label '@com_google_guava_guava_21_0//jar:jar' in $(location) expression expands to no files. when the jar target is of type rules_scala

So it seems that scala_import is missing a feature for exposing jar output files.

@lberki are bazel rules idiomatically expected to output files?

@lberki
Copy link
Contributor

lberki commented Apr 11, 2018

$(location <target>) expands to the files to build (i.e. DefaultInfo(files=) of the rule in question. Apparently, scala_import doesn't have that?

@natansil
Copy link
Contributor Author

@lberki
It does not have it explicitly,
From the documentation it seems that scala_import should have it implicitly, no?

@lberki
Copy link
Contributor

lberki commented Apr 11, 2018

Sorry for being vague; What I meant is that scala_import probably doesn't put the right files into the files field of DefaultInfo.

@natansil
Copy link
Contributor Author

@lberki,
Let me see if I understand,

This is the relevant code from scala_import:

def _scala_import_impl(ctx):
...
    return struct(
        scala = struct(
          outputs = struct (
              jars = intellij_metadata
          ),
        ),
        jars_to_labels = jars2labels,
        providers = [
            _create_provider(current_jars, transitive_runtime_jars, jars, exports)
        ],
    )

def _create_provider(current_target_compile_jars, transitive_runtime_jars, jars, exports):
  test_provider = java_common.create_provider()
  if hasattr(test_provider, "full_compile_jars"):
      return java_common.create_provider(
          use_ijar = False,
          compile_time_jars = depset(transitive = [current_target_compile_jars, exports.compile_jars]),
          transitive_compile_time_jars = depset(transitive = [jars.transitive_compile_jars, current_target_compile_jars, exports.transitive_compile_jars]) ,
          transitive_runtime_jars = depset(transitive = [transitive_runtime_jars, jars.transitive_runtime_jars, current_target_compile_jars, exports.transitive_runtime_jars]) ,
      )
  else:
      return java_common.create_provider(
          compile_time_jars = current_target_compile_jars,
          runtime_jars = transitive_runtime_jars + jars.transitive_runtime_jars,
          transitive_compile_time_jars = jars.transitive_compile_jars + current_target_compile_jars,
          transitive_runtime_jars = transitive_runtime_jars + jars.transitive_runtime_jars + current_target_compile_jars,
      )

Do you suggest to return another provider (DefaultInfo) in addition to java_common, and assign the jars to the its files field?

@lberki
Copy link
Contributor

lberki commented Apr 12, 2018

Yep. That would also help with Bazel doing something useful if e.g. a scala_import rule ends up in the srcs of a genrule. (i.e. then the imported jars would be there)

jjudd pushed a commit to lucidsoftware/rules_scala_bazelbuild that referenced this issue Apr 13, 2018
jjudd pushed a commit to lucidsoftware/rules_scala_bazelbuild that referenced this issue Apr 13, 2018
@jjudd
Copy link
Contributor

jjudd commented Apr 13, 2018

I ran into this issue and noticed #477 to refactor scala_import. I opened a PR to #477's branch to add a DefaultInfo with files: https://github.com/andyscott/rules_scala/pull/1

There's no test. I can add one. I'm interested in getting people's feedback, considering I'm not very familiar with DefaultInfo and that the documentation is a bit sparse.

@ittaiz
Copy link
Contributor

ittaiz commented Apr 13, 2018 via email

@jjudd
Copy link
Contributor

jjudd commented Apr 13, 2018

I perhaps incorrectly assumed that #477 was close to being merged, so I added a PR there in an effort to avoid merge conflicts. I did not intend to make things more difficult :)

I'm happy to close my PR to #477 and wait to open another PR for this issue until #477 is merged.

It does solve a problem for us, but I have this fix on our fork, so I have no problem with waiting.

@natansil
Copy link
Contributor Author

Thank you @jjudd for writing this PR.
This change probably means that com_google_guava_guava_21_0_with_file can be removed in favor of com_google_guava_guava_21_0.

It would be nice to remove this duplication

jjudd pushed a commit to lucidsoftware/rules_scala_bazelbuild that referenced this issue Apr 16, 2018
jjudd pushed a commit to lucidsoftware/rules_scala_bazelbuild that referenced this issue Apr 20, 2018
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

5 participants