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

closure_library.BUILD can't be referenced across repositories #9

Closed
wolfgangmeyers opened this issue Mar 23, 2016 · 40 comments
Closed

Comments

@wolfgangmeyers
Copy link
Contributor

When trying to build a closure_js_binary target, I'm now seeing this error:

ERROR: /home/wolfgang/.cache/bazel/_bazel_wolfgang/b53da5dfcf8e186eb6c4fd823f36a680/external/io_bazel_rules_closure/closure/compiler/jschecker/BUILD:17:1: no such package '@closure_library//': In new_http_archive rule //external:closure_library the 'build_file' attribute does not specify an existing file (/home/wolfgang/example-project/closure/library/closure_library.BUILD does not exist) and referenced by '@io_bazel_rules_closure//closure/compiler/jschecker:jschecker'.
ERROR: Loading failed; build aborted.
INFO: Elapsed time: 0.080s
@jart
Copy link
Contributor

jart commented Mar 23, 2016

Assuming you've correctly included the repositories.bzl file, I'm not sure what would be causing that at first glance. Would you mind troubleshooting that for us?

@wolfgangmeyers
Copy link
Contributor Author

Sure. I'll let you know what I find out.

@wolfgangmeyers
Copy link
Contributor Author

It seems to be related to this entry in closure/repositories.bzl:

  native.new_http_archive(
      name = "closure_library",
      url = "https://github.com/google/closure-library/archive/20160208.zip",
      sha256 = "8f610300e4930190137505a574a54d12346426f2a7b4f179026e41674e452a86",
      strip_prefix = "closure-library-20160208",
      build_file = "closure/library/closure_library.BUILD",
  )

I've run into this problem before when including files from other projects as a repository. I suspect the problem is that bazel is looking for the build file in my project workspace instead of the io_bazel_rules_closure repository that I specified in my workspace file. I should be able to create a minimal setup to reproduce the issue and file it there.

As a workaround I can copy the closure/library/closure_library.BUILD into my own repository.

@jart
Copy link
Contributor

jart commented Mar 23, 2016

Yes definitely file an upstream bug for this, and have it reference this issue.

@aproxs
Copy link

aproxs commented Mar 23, 2016

Where are you copying the closure_library.BUILD file? I tried copying under %workspace%/closure/library/closure_library.BUILD but now I'm getting a cascade of BUILD files not found

i.e.: every time I add one it complains about a new one.

(it is possible that I'm doing something wrong too... pretty new to bazel myself)

@wolfgangmeyers
Copy link
Contributor Author

That's odd. When I copied it over, it continued complaining that the file didn't exist. I ran bazel clean and tried again, and the error went away.

@jart
Copy link
Contributor

jart commented Mar 23, 2016

If you needed to run bazel clean, that's probably a bug. In theory, bazel should never ever require clean, because it's just that good. So if Bazel isn't being perfect, I'd advise filing a bug.

@wolfgangmeyers
Copy link
Contributor Author

opened bazelbuild/bazel#1075

@wolfgangmeyers
Copy link
Contributor Author

@jart agreed. But that's a different bug from the one I just filed.

@wolfgangmeyers
Copy link
Contributor Author

opened bazelbuild/bazel#1076 for the necessary clean after copying build file.

@wolfgangmeyers
Copy link
Contributor Author

Looks like the suggested workaround for this issue is to use build_file_content instead of build_file.

@wolfgangmeyers
Copy link
Contributor Author

Also this is a known problem: bazelbuild/bazel#855

@jart
Copy link
Contributor

jart commented Mar 23, 2016

Yeah closure_library.BUILD is 1,032 LOC; there's a 0% chance we're using build_file_content 😛

@wolfgangmeyers
Copy link
Contributor Author

Should we update the readme with a workaround and reference to bazelbuild/bazel#855 then?

@jart jart changed the title Build error - missing closure library? closure_library.BUILD can't be referenced across repositories Mar 23, 2016
@jart jart added P0 P1 and removed P0 labels Mar 23, 2016
@jart
Copy link
Contributor

jart commented Mar 23, 2016

@wolfgangmeyers I've updated the readme with a link to all "launch blocker" issues.

@damienmg
Copy link
Contributor

damienmg commented Apr 1, 2016

FYI I fixed bazelbuild/bazel#855 yesterday

@wolfgangmeyers
Copy link
Contributor Author

I'll pull bazel from head and test

@wolfgangmeyers
Copy link
Contributor Author

Ok, I pulled the latest bazel from head and completely removed closure/* from my source tree. When building my closure_js_binary, getting a slightly different error now:

ERROR: /home/wolfgang/.cache/bazel/_bazel_wolfgang/b53da5dfcf8e186eb6c4fd823f36a680/external/io_bazel_rules_closure/closure/compiler/jschecker/BUILD:17:1: no such package '@closure_library//': BUILD file not found on package path and referenced by '@io_bazel_rules_closure//closure/compiler/jschecker:jschecker'.
ERROR: Loading failed; build aborted.

Let me know if a reproduction project would help with this.

@damienmg
Copy link
Contributor

damienmg commented Apr 1, 2016

no, the source of the closure library needs to be changed so I guess you need to wait for the next release of Bazel to include that change. Because to work, you have to use labels

@wolfgangmeyers
Copy link
Contributor Author

@damienmg @jart I think that would be a change in rules_closure, right? Correct me if I'm wrong but the closure library source that's pulled in doesn't have any bazel-related files. The latest changes (fix for bazelbuild/bazel#855) are in the master branch of Bazel, right?

@damienmg
Copy link
Contributor

damienmg commented Apr 1, 2016

Sorry I meant the source of the closure rules repositories. Basically you have to use str(Label("//closure/library:closure_library.BUILD")) instead of "/closure/library/closure_library.BUILD".

@wolfgangmeyers
Copy link
Contributor Author

So the definition in repositories.bzl looks like this currently:

native.new_http_archive(
      name = "closure_library",
      url = "https://github.com/google/closure-library/archive/20160208.zip",
      sha256 = "8f610300e4930190137505a574a54d12346426f2a7b4f179026e41674e452a86",
      strip_prefix = "closure-library-20160208",
      build_file = "closure/library/closure_library.BUILD",
  )

When I update the build_file to use Label:
build_file = str(Label("closure/library/closure_library.BUILD")),
I see this error when running tests:

Illegal absolute label syntax: closure/library/closure_library.BUILD.

I also tried build_file = str(Label("//closure/library/closure_library.BUILD")),, which yielded a different error:

ERROR: package contains errors: closure.
ERROR: no such package 'external': Package 'external' contains errors.

Are there any other changes required other than updating the build_file to use a label?

@damienmg
Copy link
Contributor

damienmg commented Apr 1, 2016

should be build_file = str(Label("//closure/library:closure_library.BUILD"))

@wolfgangmeyers
Copy link
Contributor Author

Awesome, thanks. New error, may be something needing refactoring?

rules_closure/closure/compiler/test/BUILD:106:1: Sanity checking 1 JS files in //closure/compiler/test:es6arrow_lib failed: namespace-sandbox failed: error executing command /home/wolfgang/.cache/bazel/_bazel_wolfgang/c1a616f49fda0138127982ab342b5825/rules_closure/_bin/namespace-sandbox ... (remaining 6 argument(s) skipped).
Traceback (most recent call last):
  File "/home/wolfgang/.cache/bazel/_bazel_wolfgang/c1a616f49fda0138127982ab342b5825/rules_closure/bazel-out/local-fastbuild/bin/closure/compiler/jschecker/jschecker.runfiles/io_bazel_rules_closure/closure/compiler/jschecker/jschecker.py", line 47, in <module>
    from external.closure_library.closure.bin.build import source
ImportError: No module named external.closure_library.closure.bin.build

py_binary declaration for jschecker.py:

py_binary(
    name = "jschecker",
    srcs = ["jschecker.py"],
    deps = [
        "@closure_library//:build_source",
        "@closure_library//:build_treescan",
    ],
)

@damienmg
Copy link
Contributor

damienmg commented Apr 1, 2016

This one is another error I am tracking down (see #32)

@damienmg
Copy link
Contributor

damienmg commented Apr 1, 2016

btw there is a trick to use that feature from 0.2.1: create a custom skylark repository that use Label, it would also allow multiple build files in the repo and fix the issue described in the comment of the closure_library.BUILD file.

@robfig
Copy link
Contributor

robfig commented Apr 13, 2016

To confirm: there is no reasonable workaround to allow building closure js binaries with bazel right now, and I should just wait for this issue to be resolved? Is there an ETA?

Not trying to be annoying, just excited to use it! Thanks

@jart
Copy link
Contributor

jart commented Apr 13, 2016

As far as I know, there's no reasonable workaround to using the Closure Rules at the moment, aside from copying the entire project into your source tree. I'm holding off on developing it until the launch blockers are fixed.

@damienmg
Copy link
Contributor

fwiw I am cutting a canary tomorrow for 0.2.2. There should be the label
fix in it.

On Wed, Apr 13, 2016 at 8:20 PM Justine Tunney [email protected]
wrote:

As far as I know, there's no reasonable workaround to using the Closure
Rules at the moment, aside from copying the entire project into your source
tree. I'm holding off on developing it until the launch blockers are fixed.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#9 (comment)

@wolfgangmeyers
Copy link
Contributor Author

Will the label fix help to resolve #32 ?

@damienmg
Copy link
Contributor

#32 is fixed, isn't it?

@wolfgangmeyers
Copy link
Contributor Author

Looks like I forgot to subscribe to it :) - I'll test when I have time.

@robfig
Copy link
Contributor

robfig commented Apr 15, 2016

I tried copying this project into my source tree, but it still didn't do it for me.

WORKSPACE

load("//closure:defs.bzl", "closure_repositories")
closure_repositories()

BUILD

closure_template_js_library(
    name = "coffeerun_soy",
    srcs = ["index.soy"],
     deps = [
        "//closure/templates",
    ],
)

ERROR with 0.2.2 bazel

$ ~/bazel/output/bazel build :coffeerun_soy
ERROR: /Users/robfig/closure-tools-server/BUILD:53:1: in deps attribute of closure_js_library rule //:coffeerun_soy: '//closure/templates:templates' does not have mandatory provider ['js_language', 'js_exports', 'js_provided', 'transitive_js_srcs', 'transitive_js_externs']. Since this rule was created by the macro 'closure_template_js_library', the error might have been caused by the macro implementation in /Users/robfig/closure-tools-server/closure/templates/closure_template_js_library.bzl:66:14.

I have no idea what the error means.

(If it's expected that copying into my project would not work, then feel free to disregard!)

@wolfgangmeyers
Copy link
Contributor Author

@robfig Can you try this instead?

closure_template_js_library(
    name = "coffeerun_soy",
    srcs = ["index.soy"],
     deps = [
        "@io_bazel_rules_closure//closure/library",
    ],
)

Also note that I only had to copy the closure/ subdirectory of rules_closure into my project to get it working.

@robfig
Copy link
Contributor

robfig commented Apr 15, 2016

Ah, I stripped the @io_bazel_rules_closure from everywhere since that would reference the remote repo instead of the rules that I copied into my source tree. The version that references @io_bazel_rules_closure had the same error and looks like this:

WORKSPACE

git_repository(
    name = "io_bazel_rules_closure",
    remote = "https://github.com/bazelbuild/rules_closure.git",
    tag = "0.0.1",
)
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")
closure_repositories()

BUILD

load("@io_bazel_rules_closure//closure:defs.bzl", "closure_template_js_library")

closure_template_js_library(
    name = "coffeerun_soy",
    srcs = ["index.soy"],
     deps = [
        "@io_bazel_rules_closure//closure/templates",
    ],
)

ERROR

$ ~/bazel/output/bazel build :coffeerun_soy
ERROR: /Users/robfig/closure-tools-server/BUILD:53:1: in deps attribute of closure_js_library rule //:coffeerun_soy: '@io_bazel_rules_closure//closure/templates:templates' does not have mandatory provider ['js_language', 'js_exports', 'js_provided', 'transitive_js_srcs', 'transitive_js_externs']. Since this rule was created by the macro 'closure_template_js_library', the error might have been caused by the macro implementation in /private/var/tmp/_bazel_robfig/4812a82d908a70e0c140a19567e732cb/external/io_bazel_rules_closure/closure/templates/closure_template_js_library.bzl:66:14.

@wolfgangmeyers
Copy link
Contributor Author

wolfgangmeyers commented Apr 15, 2016

Did you make sure to build bazel from HEAD? (I'm currently at bazelbuild/bazel@653869e)

Also try using "@io_bazel_rules_closure//closure/library" in your deps instead.

@robfig
Copy link
Contributor

robfig commented Apr 15, 2016

I was using release-0.2.2 -- I just built it at 653869e and it didn't change the outcome.

If it helps, here is a snapshot of my workspace:
https://github.com/robfig/undertow-bazel-closure-tools

@wolfgangmeyers
Copy link
Contributor Author

wolfgangmeyers commented Apr 15, 2016

@robfig
Copy link
Contributor

robfig commented Apr 15, 2016

Hah, thank you! now all of the individual targets build except the closure_template_java_library rule, which fails with

$ ~/bazel/output/bazel build :coffeerun_soy_java
ERROR: /Users/robfig/closure-tools-server/BUILD:60:1: no such package 'java/com/google/common/collect': BUILD file not found on package path and referenced by '//:coffeerun_soy_java'.

even after adding Guava to the deps. Anyway, it seems to be unrelated to this issue, so sorry for the noise and thanks for the assistance!

@jart
Copy link
Contributor

jart commented May 2, 2016

Fix committed in #43

@jart jart closed this as completed May 2, 2016
ptmphuong pushed a commit to ptmphuong/rules_closure that referenced this issue Dec 9, 2022
Upgrade travis builds to use bazel 0.2.2b.

Update project paths to use str(Label(...)) fix documented in
Issue bazelbuild#9.

Implement missing should_generate_js_doc support.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants