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

dash: Integrate DASH tool in Bazel build #155

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
test --test_output=errors

build --java_language_version=17
build --tool_java_language_version=17
build --java_runtime_version=remotejdk_17
build --tool_java_runtime_version=remotejdk_17
30 changes: 30 additions & 0 deletions .github/workflows/license_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# *******************************************************************************
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

name: License Check
on:
pull_request:
types: [opened, reopened, synchronize]
merge_group:
types: [checks_requested]
jobs:
license-check:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/[email protected]
- name: Setup Bazel
uses: bazel-contrib/[email protected]
- name: Run license checks
run: |
bazel run //:license.check.python
7 changes: 7 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# *******************************************************************************

load("//tools/cr_checker:cr_checker.bzl", "copyright_checker")
load("//tools/dash:dash.bzl", "dash_license_checker")

test_suite(
name = "format.check",
Expand All @@ -35,6 +36,12 @@ copyright_checker(
visibility = ["//visibility:public"],
)

dash_license_checker(
name = "python",
src = "//docs:requirements_lock",
visibility = ["//visibility:public"],
)

exports_files([
"MODULE.bazel",
"BUILD",
Expand Down
24 changes: 24 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,27 @@ bazel_dep(name = "buildifier_prebuilt", version = "7.3.1")
#
###############################################################################
bazel_dep(name = "aspect_rules_lint", version = "1.0.3")

###############################################################################
#
# Java version
#
###############################################################################
bazel_dep(name = "rules_java", version = "8.6.3")

###############################################################################
#
# HTTP Jar rule deps
#
###############################################################################
http_jar = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_jar")

DASH_VERSION = "1.1.0"

http_jar(
name = "dash_license_tool",
sha256 = "ba4e84e1981f0e51f92a42ec8fc8b9668dabb08d1279afde46b8414e11752b06",
urls = [
"https://repo.eclipse.org/content/repositories/dash-licenses/org/eclipse/dash/org.eclipse.dash.licenses/{version}/org.eclipse.dash.licenses-{version}.jar".format(version = DASH_VERSION),
],
)
9 changes: 9 additions & 0 deletions docs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,12 @@ py_venv(
# Until release of esbonio 1.x, we need to install it ourselves so the VS Code extension can find it.
deps = sphinx_requirements + [requirement("esbonio")],
)

# Needed for Dash tool to check python dependency licenses.
filegroup(
name = "requirements_lock",
srcs = [
"_tooling/requirements_lock.txt",
],
visibility = ["//visibility:public"],
)
Empty file added tools/dash/BUILD
Empty file.
55 changes: 55 additions & 0 deletions tools/dash/dash.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# *******************************************************************************
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

load("@rules_java//java:java_binary.bzl", "java_binary")
load("//tools/dash/formatters:dash_format_converter.bzl", "dash_format_converter")

def dash_license_checker(
name,
src,
visibility):
"""
Defines a Bazel macro for creating a `java_binary` target that integrates the DASH license checker.

Args:
name (str):
The name of the `java_binary` target to be created. This will serve as the identifier
for the generated Bazel target.
src (str):
The path to the dependency list file required by the DASH license checker.
This file should specify the dependencies to be validated.
visibility (list[str]):
A list defining the visibility of the created target. It determines which packages
can depend on this target.

This macro simplifies the process of setting up the DASH license checker by creating a reusable
`java_binary` target that adheres to the Bazel build rules and supports consistent license
validation across projects.
"""
dash_format_converter(
name = "formatted_deps",
requirement_file = src,
)

java_binary(
name = "license.check.{}".format(name),
main_class = "org.eclipse.dash.licenses.cli.Main",
runtime_deps = [
"@dash_license_tool//jar",
],
args = ["$(location :formatted_deps)"],
data = [
":formatted_deps",
],
visibility = ["//visibility:public"],
)
20 changes: 20 additions & 0 deletions tools/dash/formatters/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# *******************************************************************************
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

py_binary(
name = "dash_format_converter",
srcs = [
"dash_format_converter.py",
],
visibility = ["//visibility:public"],
)
51 changes: 51 additions & 0 deletions tools/dash/formatters/dash_format_converter.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# *******************************************************************************
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

""" Bazel rule for generating dash formatted requirements file
"""

def _impl(ctx):
""" The implementation function of the rule.
"""

output = ctx.actions.declare_file("formatted.txt")
args = ctx.actions.args()
args.add("-i", ctx.file.requirement_file)
args.add("-o", output)

ctx.actions.run(
inputs = [ctx.file.requirement_file],
outputs = [output],
arguments = [args],
progress_message = "Generating Dash formatted dependency file ...",
mnemonic = "DashFormat",
executable = ctx.executable._tool,
)
return DefaultInfo(files = depset([output]))

dash_format_converter = rule(
implementation = _impl,
attrs = {
"requirement_file": attr.label(
mandatory = True,
allow_single_file = True,
doc = "The requirement (requirement_lock.txt) input file which holds deps",
),
"_tool": attr.label(
default = Label("//tools/dash/formatters:dash_format_converter"),
executable = True,
cfg = "exec",
doc = "",
),
},
)
Loading
Loading