[bazel] Add a license check rule.

Signed-off-by: Chris Frantz <cfrantz@google.com>
diff --git a/BUILD b/BUILD
index 3aeffe6..7c7cea3 100644
--- a/BUILD
+++ b/BUILD
@@ -3,6 +3,7 @@
 # SPDX-License-Identifier: Apache-2.0
 
 load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
+load("//rules:quality.bzl", "license_check")
 
 package(default_visibility = ["//visibility:public"])
 
@@ -10,3 +11,7 @@
     name = "buildifier",
     exclude_patterns = ["./**/vendor/**"],
 )
+
+license_check(
+    name = "license_check",
+)
diff --git a/rules/quality.bzl b/rules/quality.bzl
new file mode 100644
index 0000000..2ca8c3e
--- /dev/null
+++ b/rules/quality.bzl
@@ -0,0 +1,55 @@
+# Copyright lowRISC contributors.
+# Licensed under the Apache License, Version 2.0, see LICENSE for details.
+# SPDX-License-Identifier: Apache-2.0
+
+"""Quality check rules for OpenTitan.
+"""
+
+load("@bazel_skylib//lib:shell.bzl", "shell")
+
+def _license_test_impl(ctx):
+    args = [
+        "--config={}".format(ctx.file.config.path),
+        ".",
+    ]
+
+    out_file = ctx.actions.declare_file(ctx.label.name + ".bash")
+    substitutions = {
+        "@@ARGS@@": shell.array_literal(args),
+        "@@LICENSE_CHECK@@": shell.quote(ctx.executable.license_check.short_path),
+    }
+    ctx.actions.expand_template(
+        template = ctx.file._runner,
+        output = out_file,
+        substitutions = substitutions,
+        is_executable = True,
+    )
+
+    return DefaultInfo(
+        files = depset([out_file]),
+        runfiles = ctx.runfiles(files = [ctx.executable.license_check]),
+        executable = out_file,
+    )
+
+license_check = rule(
+    implementation = _license_test_impl,
+    attrs = {
+        "config": attr.label(
+            default = "//util:licence-checker.hjson",
+            allow_single_file = True,
+            doc = "Configuration file for the license checker",
+        ),
+        "license_check": attr.label(
+            default = "//util/lowrisc_misc-linters/licence-checker:licence-checker.py",
+            allow_single_file = True,
+            cfg = "host",
+            executable = True,
+            doc = "The license checker executable",
+        ),
+        "_runner": attr.label(
+            default = "//rules/scripts:license_check.bash.template",
+            allow_single_file = True,
+        ),
+    },
+    executable = True,
+)
diff --git a/rules/scripts/BUILD b/rules/scripts/BUILD
new file mode 100644
index 0000000..c7802ec
--- /dev/null
+++ b/rules/scripts/BUILD
@@ -0,0 +1,7 @@
+# Copyright lowRISC contributors.
+# Licensed under the Apache License, Version 2.0, see LICENSE for details.
+# SPDX-License-Identifier: Apache-2.0
+
+package(default_visibility = ["//visibility:public"])
+
+exports_files(glob(["**"]))
diff --git a/rules/scripts/license_check.bash.template b/rules/scripts/license_check.bash.template
new file mode 100644
index 0000000..c6ec568
--- /dev/null
+++ b/rules/scripts/license_check.bash.template
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+
+LICENSE_CHECK=@@LICENSE_CHECK@@
+ARGS=@@ARGS@@
+
+license_check=$(readlink "$LICENSE_CHECK")
+
+if ! cd "$BUILD_WORKSPACE_DIRECTORY"; then
+    echo "Unable to change to workspace (BUILD_WORKSPACE_DIRECTORY: ${BUILD_WORKSPACE_DIRECTORY})"
+    exit 1
+fi
+
+"$license_check" "${ARGS[@]}"
diff --git a/util/lowrisc_misc-linters/licence-checker/BUILD b/util/lowrisc_misc-linters/licence-checker/BUILD
new file mode 100644
index 0000000..c7802ec
--- /dev/null
+++ b/util/lowrisc_misc-linters/licence-checker/BUILD
@@ -0,0 +1,7 @@
+# Copyright lowRISC contributors.
+# Licensed under the Apache License, Version 2.0, see LICENSE for details.
+# SPDX-License-Identifier: Apache-2.0
+
+package(default_visibility = ["//visibility:public"])
+
+exports_files(glob(["**"]))