Skip to content

Commit

Permalink
Use cmake to find perl executable (#91275)
Browse files Browse the repository at this point in the history
`clang/tools/scan-build` is implemented in `perl`. However given `perl`
is not mentioned as a required dependency in `GettingStarted.rst` we
should make this optional.

This adds a `find_package(Perl)` check to cmake and disables the
`scan-build` tests when no perl executable is found.

Ideally we would also check if dependent perl modules like `Hash::Util`
are present on the system, but I don't see any pre-existing cmake macros
to easily test this. So for now I go with a plain check for the `perl`
package, at least this allows to use `cmake
-DCMAKE_DISABLE_FIND_PACKAGE_Perl=ON` to manually disable `perl` and the
tests.
  • Loading branch information
MatzeB authored May 8, 2024
1 parent 2475efa commit 2868e26
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 21 deletions.
2 changes: 2 additions & 0 deletions clang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@ endif()


if( CLANG_INCLUDE_TESTS )
find_package(Perl)

add_subdirectory(unittests)
list(APPEND CLANG_TEST_DEPS ClangUnitTests)
list(APPEND CLANG_TEST_PARAMS
Expand Down
1 change: 0 additions & 1 deletion clang/test/Analysis/scan-build/deduplication.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// FIXME: Actually, "perl".
REQUIRES: shell

RUN: rm -rf %t.output_dir && mkdir %t.output_dir
Expand Down
3 changes: 0 additions & 3 deletions clang/test/Analysis/scan-build/exclude_directories.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// FIXME: Actually, "perl".
REQUIRES: shell

RUN: rm -rf %t.output_dir && mkdir %t.output_dir
RUN: %scan-build -o %t.output_dir %clang -S \
RUN: %S/Inputs/multidirectory_project/directory1/file1.c \
Expand Down
3 changes: 0 additions & 3 deletions clang/test/Analysis/scan-build/help.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// FIXME: Actually, "perl".
REQUIRES: shell

RUN: %scan-build -h | FileCheck %s
RUN: %scan-build --help | FileCheck %s

Expand Down
1 change: 0 additions & 1 deletion clang/test/Analysis/scan-build/html_output.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// FIXME: Actually, "perl".
REQUIRES: shell

RUN: rm -rf %t.output_dir && mkdir %t.output_dir
Expand Down
13 changes: 8 additions & 5 deletions clang/test/Analysis/scan-build/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- Python -*-

import lit.util
import lit.formats
import os
import platform

use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
config.test_format = lit.formats.ShTest(use_lit_shell == "0")
Expand All @@ -12,13 +12,16 @@ clang_path = config.clang if config.have_llvm_driver else os.path.realpath(confi
config.substitutions.append(
(
"%scan-build",
"'%s' --use-analyzer=%s "
"'%s' '%s' --use-analyzer=%s "
% (
lit.util.which(
"scan-build",
os.path.join(config.clang_src_dir, "tools", "scan-build", "bin"),
config.perl_executable,
os.path.join(
config.clang_src_dir, "tools", "scan-build", "bin", "scan-build"
),
clang_path,
),
)
)

if not config.perl_executable or platform.system() == "Windows":
config.unsupported = True
1 change: 0 additions & 1 deletion clang/test/Analysis/scan-build/plist_html_output.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// FIXME: Actually, "perl".
REQUIRES: shell

RUN: rm -rf %t.output_dir && mkdir %t.output_dir
Expand Down
1 change: 0 additions & 1 deletion clang/test/Analysis/scan-build/plist_output.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// FIXME: Actually, "perl".
REQUIRES: shell

RUN: rm -rf %t.output_dir && mkdir %t.output_dir
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// FIXME: Actually, "perl".
REQUIRES: shell

RUN: rm -rf %t.output_dir && mkdir %t.output_dir
RUN: cp %S/report-1.html %t.output_dir
RUN: cp %S/report-2.html %t.output_dir
Expand Down
3 changes: 0 additions & 3 deletions clang/test/Analysis/scan-build/silence-core-checkers.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// FIXME: Actually, "perl".
REQUIRES: shell

RUN: rm -rf %t.output_dir && mkdir %t.output_dir
RUN: %scan-build -o %t.output_dir \
RUN: %clang -S %S/Inputs/null_dereference_and_division_by_zero.c \
Expand Down
1 change: 1 addition & 0 deletions clang/test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ config.enable_backtrace = @ENABLE_BACKTRACES@
config.enable_threads = @LLVM_ENABLE_THREADS@
config.reverse_iteration = @LLVM_ENABLE_REVERSE_ITERATION@
config.host_arch = "@HOST_ARCH@"
config.perl_executable = "@PERL_EXECUTABLE@"
config.python_executable = "@Python3_EXECUTABLE@"
config.use_z3_solver = lit_config.params.get('USE_Z3_SOLVER', "@USE_Z3_SOLVER@")
config.has_plugins = @CLANG_PLUGIN_SUPPORT@
Expand Down

0 comments on commit 2868e26

Please sign in to comment.