Skip to content

Commit 758b59f

Browse files
committed
Add check_for_installed_private_headers_in_cmake_out
This adds a test that will run in CI to make sure that we don't install private headers. I fixed the existing places where we were installing private headers; reviewers, please confirm that we are OK with this technical break of source-level backward compatibility. ghstack-source-id: 733e1e5 ghstack-comment-id: 3198151825 Pull-Request: #13485
1 parent 3a4a859 commit 758b59f

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

.ci/scripts/unittest-macos-cmake.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ ${CONDA_RUN} pytest -n auto --cov=./ --cov-report=xml
1111
# Run gtest
1212
LLVM_PROFDATA="xcrun llvm-profdata" LLVM_COV="xcrun llvm-cov" \
1313
${CONDA_RUN} test/run_oss_cpp_tests.sh
14+
${CONDA_RUN} test/check_for_installed_private_headers_in_cmake_out.sh

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,24 +485,29 @@ install(
485485
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/runtime/core
486486
FILES_MATCHING
487487
PATTERN "*.h"
488+
PATTERN "testing_util" EXCLUDE
488489
)
489490
install(
490491
DIRECTORY runtime/executor/
491492
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/runtime/executor
492493
FILES_MATCHING
493494
PATTERN "*.h"
495+
PATTERN "test" EXCLUDE
496+
PATTERN "platform_memory_allocator.h" EXCLUDE
494497
)
495498
install(
496499
DIRECTORY runtime/kernel/
497500
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/runtime/kernel
498501
FILES_MATCHING
499502
PATTERN "*.h"
503+
PATTERN "test" EXCLUDE
500504
)
501505
install(
502506
DIRECTORY runtime/platform/
503507
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/runtime/platform
504508
FILES_MATCHING
505509
PATTERN "*.h"
510+
PATTERN "test" EXCLUDE
506511
)
507512
install(
508513
DIRECTORY extension/kernel_util/
@@ -587,11 +592,15 @@ endif()
587592

588593
if(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER)
589594
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/data_loader)
595+
if(NOT WIN32)
596+
set(data_loader_exclude_pattern "*mman_windows.h")
597+
endif()
590598
install(
591599
DIRECTORY extension/data_loader/
592600
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/data_loader
593601
FILES_MATCHING
594602
PATTERN "*.h"
603+
PATTERN ${data_loader_exclude_pattern} EXCLUDE
595604
)
596605
list(APPEND _executorch_extensions extension_data_loader)
597606
endif()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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

Comments
 (0)