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

Invalid License Error While Running bazel build #5157

Closed
cagrigider opened this issue May 4, 2018 · 36 comments
Closed

Invalid License Error While Running bazel build #5157

cagrigider opened this issue May 4, 2018 · 36 comments

Comments

@cagrigider
Copy link

I am trying to compile tensorflow for Macbook, but every time when I use bazel build, I am getting same error.

When I Run this command

bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package

I get this error

/private/var/tmp/_bazel_cagrigider/2c548436011ab6b7308cd0cc70a91ed3/external/bazel_tools/tools/cpp/BUILD:3:1: invalid license type: 'notice'

Full Output Of Terminal

Mac OS 10.13.3

Xcode version = 9.2

Tensorflow version = 1.8

Bazel version = 0.13.0

Thanks.

@RNabel
Copy link
Contributor

RNabel commented May 4, 2018

It looks like this is an error with tensorflow. Did you try building another project with bazel (for example the bazel repo)?

If you can build the bazel repo without a problem, I'd recommend you open an issue against TensorFlow.

@cagrigider
Copy link
Author

I tried bazel example projects and I got same error
I tried this examples examples

@RNabel
Copy link
Contributor

RNabel commented May 4, 2018

My guess is that your bazel is setup incorrectly. How did you install it? Are you sure that it is version 0.13.0?

@cagrigider
Copy link
Author

cagrigider commented May 4, 2018 via email

@cagrigider
Copy link
Author

cagrigider commented May 7, 2018 via email

@jin
Copy link
Member

jin commented May 7, 2018

I tried bazel example projects and I got same error
I tried this examples examples

This is odd - could you please elaborate more on the steps you took to point of this error with the examples repository?

@cagrigider
Copy link
Author

I ran these commands

cd Documents/examples/cpp-tutorial/stage1/
bazel build //main:hello-world

then I got this error.

ERROR: /private/var/tmp/_bazel_cagrigider/4c2d107b81f30b45f844673a09f76011/external/bazel_tools/tools/cpp/BUILD:17:1: invalid license type: 'notice'
ERROR: /private/var/tmp/_bazel_cagrigider/4c2d107b81f30b45f844673a09f76011/external/bazel_tools/tools/cpp/BUILD:61:1: Target '@bazel_tools//tools/cpp:grep-includes.sh' contains an error and its package is in error and referenced by '@bazel_tools//tools/cpp:grep-includes'
ERROR: /Users/cagrigider/Documents/examples/cpp-tutorial/stage1/main/BUILD:1:1: every rule of type cc_binary implicitly depends upon the target '@bazel_tools//tools/cpp:malloc', but this target could not be found because of: Target '@bazel_tools//tools/cpp:malloc' contains an error and its package is in error
ERROR: /Users/cagrigider/Documents/examples/cpp-tutorial/stage1/main/BUILD:1:1: every rule of type cc_binary implicitly depends upon the target '@bazel_tools//tools/cpp:grep-includes', but this target could not be found because of: Target '@bazel_tools//tools/cpp:grep-includes' contains an error and its package is in error
ERROR: /Users/cagrigider/Documents/examples/cpp-tutorial/stage1/main/BUILD:1:1: every rule of type cc_binary implicitly depends upon the target '@bazel_tools//tools/cpp:stl', but this target could not be found because of: Target '@bazel_tools//tools/cpp:stl' contains an error and its package is in error
ERROR: /Users/cagrigider/Documents/examples/cpp-tutorial/stage1/main/BUILD:1:1: every rule of type cc_binary implicitly depends upon the target '@bazel_tools//tools/cpp:stl', but this target could not be found because of: Target '@bazel_tools//tools/cpp:stl' contains an error and its package is in error
ERROR: Analysis of target '//main:hello-world' failed; build aborted: Loading failed

@jin
Copy link
Member

jin commented May 7, 2018

could you please paste the contents of the file /private/var/tmp/_bazel_cagrigider/4c2d107b81f30b45f844673a09f76011/external/bazel_tools/tools/cpp/BUILD here? at least for line 17.

@jin
Copy link
Member

jin commented May 7, 2018

the error is raised in this method: https://source.bazel.build/bazel/+/master:src/main/java/com/google/devtools/build/lib/packages/License.java;l=200

try {
     licenseTypes.add(LicenseType.valueOf(str.toUpperCase()));
} catch (IllegalArgumentException e) {
     throw new LicenseParsingException("invalid license type: '" + str + "'")
}

Enum#valueOf threw the IllegalArgumentException, which suggests that the value of str.toUpperCase() is not in LicenseType:

  public enum LicenseType {
    BY_EXCEPTION_ONLY,
    RESTRICTED,
    RESTRICTED_IF_STATICALLY_LINKED,
    RECIPROCAL,
    NOTICE,
    PERMISSIVE,
    UNENCUMBERED,
    NONE
  }

@cagrigider
Copy link
Author

cd /private/var/tmp/_bazel_cagrigider/4c2d107b81f30b45f844673a09f76011/external/bazel_tools/tools/cpp/

ls

Result :

output

@jin
Copy link
Member

jin commented May 7, 2018

could you please paste line 17 of the BUILD file in that directory?

@cagrigider
Copy link
Author

licenses(["notice"]) # Apache 2.0

@jin
Copy link
Member

jin commented May 7, 2018

Ok, I'm quite stumped here. Could you please run bazel clean --expunge and try a clean build?

@cagrigider
Copy link
Author

After bazel clean --expunge It only says
INFO: Starting clean.

After that when I run :
bazel build //main:hello-world

It gives, same invalid license type error.

/private/var/tmp/_bazel_cagrigider/4c2d107b81f30b45f844673a09f76011/external/bazel_tools/tools/cpp/BUILD:17:1: invalid license type: 'notice'

@RNabel
Copy link
Contributor

RNabel commented May 7, 2018

Something else worth trying is to check whether you are using the bazel that homebrew provides, using which bazel and whether bazel version returns bazel 0.13.0-homebrew. My homebrew bazel is located at /usr/local/bin/bazel.
Just in case you have a corrupt bazel installation...

@cagrigider
Copy link
Author

which bazel
returns :
/usr/local/bin/bazel

And bazel version returns

Build label: 0.13.0-homebrew
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar

@jin
Copy link
Member

jin commented May 7, 2018

Could this be an encoding/parsing issue? + @laurentlb for Skylark

@jin
Copy link
Member

jin commented May 7, 2018

It could be that "notice".toUpperCase() on your system locale does not convert it to "NOTICE".

@cagrigider
Copy link
Author

Is there anything I can do to fix this error?

@davido
Copy link
Contributor

davido commented May 9, 2018

Is there anything I can do to fix this error?

Sure, attach the debugger and check what is going on here https://source.bazel.build/bazel/+/master:src/main/java/com/google/devtools/build/lib/packages/License.java;l=200:

    licenseTypes.add(LicenseType.valueOf(str.toUpperCase()));

@cagrigider
Copy link
Author

How can I attach the debugger on this code ?

@davido
Copy link
Contributor

davido commented May 9, 2018

See https://bazel.build/contributing.html, particularly "Debugging Bazel" section. Basically, you need to set up IntelliJ IDEA project, call Bazel with: bazel --host_jvm_debug build foo and attach remote debugger from the IDE to the specified port.

@cagrigider
Copy link
Author

After I did this step when preparing IntelliJ IDEA install it from within the IDE (Settings > Plugins > Install > Browse Repositories, and search for 'Bazel').

I can't see that, Preferences > Other Settings > Bazel Settings on macOS IntelliJ IDEA

@cagrigider
Copy link
Author

When I am did this install it from within the IDE (Settings > Plugins > Install > Browse Repositories, and search for 'Bazel'
I found only 'Bazel Build Formatter' plugin, Is that right one ?

@cagrigider
Copy link
Author

And also, before creating project it wants me to build bazel .

cd bazel
bazel build //src:bazel
This will produce a working Bazel binary in bazel-bin/src/bazel.
If everything works fine, feel free to configure your favorite IDE in the following steps.

@RNabel
Copy link
Contributor

RNabel commented May 9, 2018

@cagrigider The IntelliJ plugin appears to only be supported in 2017.x versions (issue on their repo: bazelbuild/intellij#290), so you are going to have to rollback to 2017.3.5 which is the last 2017 release. If you don't already, you may want to use the JetBrains Toolbox App which makes installing and upgrading to specific IntelliJ versions really easy.

@cagrigider
Copy link
Author

It says Set the path to the Bazel binary in the plugin preferences

but bazel build //src:bazel is not working, so I don't have binary files. Am I right ?

@RNabel
Copy link
Contributor

RNabel commented May 9, 2018

Yes. You need to go to your Bazel settings (just type that into the box that pops up when you press Cmd+ Shift + A), there's a text box in the settings menu which you're taken to which says Bazel binary location -> paste whatever path which bazel returns in a shell. For me this path is /usr/local/bin/bazel. Then try again.

@cagrigider
Copy link
Author

It says :
Start creating a debug configuration for both C++ and Java in your .bazelrc with the following:

build:debug -c dbg
build:debug --javacopt="-g"
build:debug --copt="-g"
build:debug --strip="never"

Then you can rebuild Bazel with bazel build --config debug //src:bazel and use your favorite debugger to start debugging.

So I should open my bazel.bazelrc file as a text file and paste these lines into it. Then rebuild ?

@cagrigider
Copy link
Author

Now my .bazelrc file is empty

@jin
Copy link
Member

jin commented May 9, 2018

Could you please try passing the flag --host_jvm_args=-Duser.language=en to your bazel build command?

@RNabel
Copy link
Contributor

RNabel commented May 9, 2018

@cagrigider adding --config some_config to your execution of bazel is the same as adding all flags specific in the config into the command line, i.e. bazel build -c debug --javacopt="-g" --copt="-g" --strip="never" //src:bazel for the debug build.

As @jin indicated, it would also be good to try setting user.language: bazel --host_jvm_args=-Duser.language=en build //src:bazel. Then run your build with the resulting binary.

@cagrigider
Copy link
Author

I m trying this now bazel --host_jvm_args=-Duser.language=en build //src:bazel and it s looking like working. It didn't give any license error.
If it finish successfully, it means it will work without any problem because of this flag settings ?

@jin
Copy link
Member

jin commented May 9, 2018

Yeah, it looks like the problem is with your system's locale setting. No worries, we should force the Locale to be en while performing str.toUpperCase in the code. I'll send in a fix.

If it finish successfully, it means it will work without any problem because of this flag settings ?

Yes, for now, you should run any bazel build command with the --host_jvm_args=-Duser.language=en. You can also add it into your project's .bazelrc file like this to not have to specify it every time:

# In $PROJECT/.bazelrc
startup --host_jvm_args=-Duser.language=en

@cagrigider
Copy link
Author

It is working now.

Thank you so much.

@jin
Copy link
Member

jin commented May 9, 2018

Good to hear :-)

luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this issue Sep 4, 2022
    Fixes bazelbuild/bazel#5157

    If a user's default system locale is not `en`, `en_US` or `en_UK`, there may be a chance that `String#toUpperCase` will result in a string that does not exist in the Enum declaration. This is the case in #5157.

    To fix this, it's either

    1) setting the Locale in the individual `toUpperCase` calls or
    2) set Locale to English by default from `Bazel.java`.

    I chose the first because it seemed less intrusive, but I'm open to suggestions.

    Closes #5184.

    PiperOrigin-RevId: 196261078
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants