-
-
Notifications
You must be signed in to change notification settings - Fork 256
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
WIP: License lookup - a better version #692
Draft
aiuto
wants to merge
5
commits into
bazel-contrib:master
Choose a base branch
from
aiuto:license_lookup
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# lookup_license: Returns the license information for a maven it. | ||
# The dependency parser calls this while generating the @maven/BUILD file. | ||
# This is a no-op fallback, that will be overwritten by the patch command | ||
# use_license_classifier.sh. | ||
|
||
def lookup_license(url=None, sha256=None, maven_id=None): | ||
return None |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
|
||
java_library( | ||
name = "my_lib", | ||
srcs = ["MyLib.java"], | ||
deps = [ | ||
"@maven//:junit_junit", | ||
], | ||
) |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* | ||
*/ | ||
final class MyLib { | ||
|
||
public MyLib() { | ||
} | ||
|
||
int foo() { return 1; } | ||
} |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Copyright 2022 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
workspace(name = "demo") | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
http_archive( | ||
name = "rules_license", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/rules_license/releases/download/0.0.1/rules_license-0.0.1.tar.gz", | ||
], | ||
sha256 = "4865059254da674e3d18ab242e21c17f7e3e8c6b1f1421fffa4c5070f82e98b5", | ||
) | ||
|
||
# You must expose your own license declarations as a repository so the rules | ||
# generated in @maven can point to them. Otherwise you would have to generate | ||
# the declarations in @maven. | ||
local_repository( | ||
name = "my_compliance", | ||
path = "compliance", | ||
) | ||
|
||
|
||
# Point to parent for testing. You would use http_archive in real life. | ||
http_archive( | ||
name = "rules_jvm_external", | ||
# path = "..", | ||
urls = ["file:///tmp/rje.tar"], | ||
patch_cmds = [ | ||
"/bin/pwd >/tmp/toast.pwd", | ||
"./use_license_classifier.sh my_compliance", | ||
# "/usr/local/google/home/aiuto/ws/rules_jvm_external/license_demo/splice_lc.sh", | ||
], | ||
) | ||
|
||
load("@rules_jvm_external//:defs.bzl", "maven_install") | ||
|
||
maven_install( | ||
artifacts = [ | ||
"junit:junit:4.12", | ||
"com.google.guava:guava:28.0-jre", | ||
], | ||
fetch_sources = True, | ||
repositories = [ | ||
"http://uk.maven.org/maven2", | ||
"https://jcenter.bintray.com/", | ||
], | ||
) |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Organization local compliance rules go here | ||
|
||
load("@rules_license//rules:license.bzl", "license") | ||
|
||
package( | ||
default_applicable_licenses = [":license"], | ||
default_visibility = ["//visibility:public"], | ||
) | ||
|
||
license( | ||
name = "apache", | ||
license_kinds = [ | ||
"@rules_license//licenses/spdx:Apache-2.0" | ||
], | ||
license_text = "LICENSE_apache.txt", | ||
) |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
apache license |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"""Users will provider their own. | ||
|
||
This is a respository rule. | ||
""" | ||
|
||
|
||
def lookup_license(url=None, sha256=None, maven_id=None): | ||
print("==================================== yes") | ||
return "@my_compliance//:apache" |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash -e | ||
# | ||
# Replace the no-op fallback license classifier with one implemented in | ||
# a repository of our choosing | ||
|
||
|
||
if [[ $# != 1 ]] ; then | ||
echo 'usage: use_license_classifier.sh REPOSITORY_NAME' | ||
exit 1 | ||
fi | ||
|
||
cat >license_classifier.bzl <<INP | ||
# This file is generated by the patch command "use_license_classifier.sh". | ||
# It overwrites the default license_classifier.bzl | ||
|
||
load("@${1}//:license_classifier.bzl", _ll = "lookup_license") | ||
|
||
def lookup_license(url=None, sha256=None, maven_id=None): | ||
return _ll(url=url, sha256=sha256, maven_id=maven_id) | ||
INP |
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.
How did you generate this
.tar
? I ended up just usinggit_repository()
workspace rule pointing at this branch as a work-aroundThere 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.
Tar from the command line. This is just to get something to demo, not what we would really do.