From 4ec685f2a641ac4ef8834a0d28e56b20283bc4d7 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Sun, 20 Sep 2026 11:08:53 -0700 Subject: [PATCH] feat: Validate file extensions on devicetree source attributes Replace `allow_files = True` with explicit extension allowlists so that misplaced files are rejected at analysis time instead of producing a confusing dtc failure (or, for `dtb_composite`, silently feeding a non-FDT input to fdtoverlay): devicetree_library.hdrs .dts .dtsi .dtso .h dtb.srcs .dts .dtsi .h dtbo.srcs .dtsi .dtso .h dtb_composite.base .dtb dtb_composite.overlays .dtbo --- devicetree/private/devicetree_library.bzl | 2 +- devicetree/private/dtb.bzl | 4 +-- devicetree/private/dtb_composite.bzl | 4 +-- .../srcs_include_test/BUILD.bazel | 35 +++++++++++++++++++ .../srcs_include_test/srcs_include.dts | 7 ++++ .../srcs_include_test/sub/dt-bindings.h | 1 + .../srcs_include_test/sub/srcs_include.dtsi | 3 ++ 7 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 e2e/smoke/include_test/srcs_include_test/BUILD.bazel create mode 100644 e2e/smoke/include_test/srcs_include_test/srcs_include.dts create mode 100644 e2e/smoke/include_test/srcs_include_test/sub/dt-bindings.h create mode 100644 e2e/smoke/include_test/srcs_include_test/sub/srcs_include.dtsi diff --git a/devicetree/private/devicetree_library.bzl b/devicetree/private/devicetree_library.bzl index f28d123..91ff1c0 100644 --- a/devicetree/private/devicetree_library.bzl +++ b/devicetree/private/devicetree_library.bzl @@ -50,7 +50,7 @@ devicetree_library = rule( providers = [DevicetreeLibraryInfo], ), "hdrs": attr.label_list( - allow_files = True, + allow_files = [".h", ".dtsi", ".dts", ".dtso"], doc = """List of exported included files (`.h`, `.dtsi`). These files are visible to all targets that transitively depend diff --git a/devicetree/private/dtb.bzl b/devicetree/private/dtb.bzl index 55be38b..bdd00ff 100644 --- a/devicetree/private/dtb.bzl +++ b/devicetree/private/dtb.bzl @@ -360,7 +360,7 @@ dtb = rule( [`devicetree_library()`](devicetree_library.md#devicetree_library) and add them to [`deps`](#dtb-deps). """, - allow_files = True, + allow_files = [".dts", ".dtsi", ".h"], ), }, toolchains = [ @@ -452,7 +452,7 @@ dtbo = rule( [`devicetree_library()`](devicetree_library.md#devicetree_library) and add them to [`deps`](#dtb-deps). """, - allow_files = True, + allow_files = [".dtso", ".dtsi", ".h"], ), }, toolchains = [ diff --git a/devicetree/private/dtb_composite.bzl b/devicetree/private/dtb_composite.bzl index 91fbb78..64b669f 100644 --- a/devicetree/private/dtb_composite.bzl +++ b/devicetree/private/dtb_composite.bzl @@ -60,7 +60,7 @@ dtb_composite = rule( doc = "Builds a composite dtb by applying overlays on a base dtb.", attrs = { "base": attr.label( - allow_single_file = True, + allow_single_file = [".dtb"], doc = """Base `.dtb` to apply overlays on. This usually comes from a `dtb()` target with @@ -74,7 +74,7 @@ dtb_composite = rule( Default is `name + ".dtb"` if missing extension, otherwise `name`.""", ), "overlays": attr.label_list( - allow_files = True, + allow_files = [".dtbo"], doc = "List of `.dtbo` overlays to apply.", ), }, diff --git a/e2e/smoke/include_test/srcs_include_test/BUILD.bazel b/e2e/smoke/include_test/srcs_include_test/BUILD.bazel new file mode 100644 index 0000000..f2e9db3 --- /dev/null +++ b/e2e/smoke/include_test/srcs_include_test/BUILD.bazel @@ -0,0 +1,35 @@ +# Copyright (C) 2026 Google LLC +# +# 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. + +"""Test that `.dtsi` and `.h` files may be listed directly in `srcs`.""" + +load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@rules_devicetree//devicetree:dtb.bzl", "dtb") + +dtb( + name = "srcs_include", + srcs = [ + "srcs_include.dts", + "sub/dt-bindings.h", + "sub/srcs_include.dtsi", + ], +) + +build_test( + name = "srcs_include_test", + targets = [ + # keep sorted + ":srcs_include", + ], +) diff --git a/e2e/smoke/include_test/srcs_include_test/srcs_include.dts b/e2e/smoke/include_test/srcs_include_test/srcs_include.dts new file mode 100644 index 0000000..034a82b --- /dev/null +++ b/e2e/smoke/include_test/srcs_include_test/srcs_include.dts @@ -0,0 +1,7 @@ +/dts-v1/; + +#include "sub/dt-bindings.h" +#include "sub/srcs_include.dtsi" + +/ { +}; diff --git a/e2e/smoke/include_test/srcs_include_test/sub/dt-bindings.h b/e2e/smoke/include_test/srcs_include_test/sub/dt-bindings.h new file mode 100644 index 0000000..8b65572 --- /dev/null +++ b/e2e/smoke/include_test/srcs_include_test/sub/dt-bindings.h @@ -0,0 +1 @@ +#define SRCS_INCLUDE_VALUE 1 diff --git a/e2e/smoke/include_test/srcs_include_test/sub/srcs_include.dtsi b/e2e/smoke/include_test/srcs_include_test/sub/srcs_include.dtsi new file mode 100644 index 0000000..308f669 --- /dev/null +++ b/e2e/smoke/include_test/srcs_include_test/sub/srcs_include.dtsi @@ -0,0 +1,3 @@ +/ { + srcs-include-value = ; +};