|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# This source code is licensed under the BSD-style license found in the |
| 6 | +# LICENSE file in the root directory of this source tree. |
| 7 | + |
| 8 | +# This script verifies that all headers that are installed under |
| 9 | +# cmake-out/include/executorch are exported_headers of some Buck |
| 10 | +# target. (It does *not* verify the reverse, namely that all |
| 11 | +# exported_headers of every Buck target that should have been built |
| 12 | +# when that directory was installed are actually installed.) |
| 13 | +# |
| 14 | +# Ideally, "some Buck target" would include any target in the whole |
| 15 | +# repo, but we cannot yet buck query the whole repo. (See |
| 16 | +# .ci/scripts/unittest-buck2.sh.) Instead, we query a manually-curated |
| 17 | +# list of targets. |
| 18 | + |
| 19 | +set -euxo pipefail |
| 20 | + |
| 21 | +BUCK_HEADERS_TEMPFILE=$(mktemp /tmp/check_private_headers_buck.txt.XXXXXX) |
| 22 | +ACTUAL_HEADERS_TEMPFILE=$(mktemp /tmp/check_private_headers_installed.txt.XXXXXX) |
| 23 | +SOURCE_ROOT_DIR=$(git rev-parse --show-toplevel) |
| 24 | +BUCK2=$(python3 "${SOURCE_ROOT_DIR}/tools/cmake/resolve_buck.py" --cache_dir="${SOURCE_ROOT_DIR}/buck2-bin") |
| 25 | +if [[ "$BUCK2" == "buck2" ]]; then |
| 26 | + BUCK2=$(command -v buck2) |
| 27 | +fi |
| 28 | + |
| 29 | +"${SOURCE_ROOT_DIR}/scripts/print_exported_headers.py" \ |
| 30 | + --buck2=$(realpath "$BUCK2") --targets \ |
| 31 | + //extension/data_loader: //extension/evalue_util: \ |
| 32 | + //extension/flat_tensor: //extension/llm/runner: //extension/kernel_util: //extension/module: \ |
| 33 | + //extension/runner_util: //extension/tensor: //extension/threadpool: \ |
| 34 | + | sort > "${BUCK_HEADERS_TEMPFILE}" |
| 35 | +find "${SOURCE_ROOT_DIR}/cmake-out/include/executorch" -name '*.h' | \ |
| 36 | + sed -e "s|${SOURCE_ROOT_DIR}/cmake-out/include/executorch/||" | \ |
| 37 | + # Don't complain about generated Functions.h \ |
| 38 | + grep -E -v 'Functions.h$' | sort > "${ACTUAL_HEADERS_TEMPFILE}" |
| 39 | +ACTUAL_HEADERS_NOT_EXPORTED_IN_BUCK=$(comm -13 "${BUCK_HEADERS_TEMPFILE}" "${ACTUAL_HEADERS_TEMPFILE}") |
| 40 | +if [[ -n "${ACTUAL_HEADERS_NOT_EXPORTED_IN_BUCK}" ]]; then |
| 41 | + >&2 echo "The following non-exported headers were installed: |
| 42 | +${ACTUAL_HEADERS_NOT_EXPORTED_IN_BUCK}" |
| 43 | + exit 1 |
| 44 | +fi |
0 commit comments