| # Copyright 2024 The Pigweed Authors |
| # |
| # 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 |
| # |
| # https://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. |
| |
| """KiCad Bazel Rules.""" |
| |
| load("@bazel_skylib//rules:native_binary.bzl", "native_test") |
| |
| def kicad_project(name, project, sym_lib_table, fp_lib_table, schematic_root, schematic_srcs, data): |
| kicad_schematic_pdf(name = name + "_sch", root = schematic_root, srcs = schematic_srcs, data = data + [project, sym_lib_table]) |
| kicad_schematic_test(name = name + "_test", root = schematic_root, srcs = schematic_srcs, data = data + [project, sym_lib_table]) |
| |
| def kicad_schematic_test(name, root, srcs, data): |
| args = ["sch", "erc", "--exit-code-violations", "$(rootpath " + root + " )"] |
| |
| native_test( |
| name = name, |
| src = str(Label("//build:kicad_cli_test")), |
| args = args, |
| data = srcs + data + [root], |
| # Note: out is mandatory in older bazel-skylib versions. |
| out = name + ".exe", |
| ) |
| |
| def _kicad_schematic_pdf_impl(ctx): |
| pdf_file = ctx.actions.declare_file(ctx.label.name + ".pdf") |
| |
| args = ["sch", "export", "pdf", "--output", pdf_file.path, ctx.file.root.path] |
| |
| ctx.actions.run( |
| inputs = ctx.files.srcs + [ctx.file.root], |
| outputs = [pdf_file], |
| arguments = args, |
| use_default_shell_env = True, |
| progress_message = "running ERC on %s" % ctx.attr.name, |
| executable = ctx.executable._kicad_cli, |
| ) |
| |
| return [ |
| DefaultInfo(files = depset([pdf_file])), |
| ] |
| |
| kicad_schematic_pdf = rule( |
| implementation = _kicad_schematic_pdf_impl, |
| attrs = { |
| "srcs": attr.label_list(allow_files = [".kicad_sch"]), |
| "root": attr.label( |
| allow_single_file = [".kicad_sch"], |
| mandatory = True, |
| ), |
| "data": attr.label_list(allow_files = True), |
| "_kicad_cli": attr.label( |
| executable = True, |
| cfg = "exec", |
| allow_files = True, |
| default = Label("//build:kicad_cli"), |
| ), |
| }, |
| ) |