Skip to content

Use cmake to find perl executable #91275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 8, 2024
Merged

Use cmake to find perl executable #91275

merged 7 commits into from
May 8, 2024

Conversation

MatzeB
Copy link
Contributor

@MatzeB MatzeB commented May 6, 2024

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.

@MatzeB
Copy link
Contributor Author

MatzeB commented May 6, 2024

I checked clang/test/Analyzer/scan-build with this change:

  • tests run fine by default on my machine.
  • tests are skipped when using cmake -DCMAKE_DISABLE_FIND_PACKAGE_Perl=ON ....

@MatzeB MatzeB marked this pull request as ready for review May 6, 2024 22:35
@llvmbot llvmbot added the clang Clang issues not falling into any other category label May 6, 2024
@llvmbot
Copy link
Member

llvmbot commented May 6, 2024

@llvm/pr-subscribers-clang

Author: Matthias Braun (MatzeB)

Changes

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_DISBALE_FIND_PACKAGE_Perl=ON to manually disable perl and the tests.


Full diff: https://github.com/llvm/llvm-project/pull/91275.diff

13 Files Affected:

  • (modified) clang/CMakeLists.txt (+2)
  • (modified) clang/test/Analysis/scan-build/cxx-name.test (+1-1)
  • (modified) clang/test/Analysis/scan-build/deduplication.test (+1-2)
  • (modified) clang/test/Analysis/scan-build/exclude_directories.test (+1-2)
  • (modified) clang/test/Analysis/scan-build/help.test (+1-2)
  • (modified) clang/test/Analysis/scan-build/html_output.test (+1-2)
  • (modified) clang/test/Analysis/scan-build/lit.local.cfg (+2-1)
  • (modified) clang/test/Analysis/scan-build/plist_html_output.test (+1-2)
  • (modified) clang/test/Analysis/scan-build/plist_output.test (+1-2)
  • (modified) clang/test/Analysis/scan-build/rebuild_index/rebuild_index.test (+1-2)
  • (modified) clang/test/Analysis/scan-build/silence-core-checkers.test (+1-2)
  • (modified) clang/test/lit.cfg.py (+3)
  • (modified) clang/test/lit.site.cfg.py.in (+1)
diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index cf97e3c6e851ae..c20ce47a12abbd 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -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
diff --git a/clang/test/Analysis/scan-build/cxx-name.test b/clang/test/Analysis/scan-build/cxx-name.test
index 483762d619d178..789f7e0ac197c6 100644
--- a/clang/test/Analysis/scan-build/cxx-name.test
+++ b/clang/test/Analysis/scan-build/cxx-name.test
@@ -1,4 +1,4 @@
-REQUIRES: shell
+REQUIRES: perl
 
 RUN: %scan-build sh -c 'echo "CLANG_CXX=/$(basename "$CLANG_CXX")/"' | FileCheck %s
 
diff --git a/clang/test/Analysis/scan-build/deduplication.test b/clang/test/Analysis/scan-build/deduplication.test
index 56d888e5fc12a2..62375d9aadfa85 100644
--- a/clang/test/Analysis/scan-build/deduplication.test
+++ b/clang/test/Analysis/scan-build/deduplication.test
@@ -1,5 +1,4 @@
-// FIXME: Actually, "perl".
-REQUIRES: shell
+REQUIRES: perl
 
 RUN: rm -rf %t.output_dir && mkdir %t.output_dir
 RUN: %scan-build -o %t.output_dir \
diff --git a/clang/test/Analysis/scan-build/exclude_directories.test b/clang/test/Analysis/scan-build/exclude_directories.test
index c161e51b6d26c5..c15568f0b6bb9e 100644
--- a/clang/test/Analysis/scan-build/exclude_directories.test
+++ b/clang/test/Analysis/scan-build/exclude_directories.test
@@ -1,5 +1,4 @@
-// FIXME: Actually, "perl".
-REQUIRES: shell
+REQUIRES: perl
 
 RUN: rm -rf %t.output_dir && mkdir %t.output_dir
 RUN: %scan-build -o %t.output_dir %clang -S \
diff --git a/clang/test/Analysis/scan-build/help.test b/clang/test/Analysis/scan-build/help.test
index 61915d32609439..2966507b6080cd 100644
--- a/clang/test/Analysis/scan-build/help.test
+++ b/clang/test/Analysis/scan-build/help.test
@@ -1,5 +1,4 @@
-// FIXME: Actually, "perl".
-REQUIRES: shell
+REQUIRES: perl
 
 RUN: %scan-build -h | FileCheck %s
 RUN: %scan-build --help | FileCheck %s
diff --git a/clang/test/Analysis/scan-build/html_output.test b/clang/test/Analysis/scan-build/html_output.test
index add35d83b95887..2d5c001e83960d 100644
--- a/clang/test/Analysis/scan-build/html_output.test
+++ b/clang/test/Analysis/scan-build/html_output.test
@@ -1,5 +1,4 @@
-// FIXME: Actually, "perl".
-REQUIRES: shell
+REQUIRES: perl
 
 RUN: rm -rf %t.output_dir && mkdir %t.output_dir
 RUN: %scan-build -o %t.output_dir %clang -S %S/Inputs/single_null_dereference.c \
diff --git a/clang/test/Analysis/scan-build/lit.local.cfg b/clang/test/Analysis/scan-build/lit.local.cfg
index fab52b1c7bd679..e606243ea73a48 100644
--- a/clang/test/Analysis/scan-build/lit.local.cfg
+++ b/clang/test/Analysis/scan-build/lit.local.cfg
@@ -12,8 +12,9 @@ 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 "
         % (
+            config.perl_executable,
             lit.util.which(
                 "scan-build",
                 os.path.join(config.clang_src_dir, "tools", "scan-build", "bin"),
diff --git a/clang/test/Analysis/scan-build/plist_html_output.test b/clang/test/Analysis/scan-build/plist_html_output.test
index c07891e35fbf33..811bca22b07643 100644
--- a/clang/test/Analysis/scan-build/plist_html_output.test
+++ b/clang/test/Analysis/scan-build/plist_html_output.test
@@ -1,5 +1,4 @@
-// FIXME: Actually, "perl".
-REQUIRES: shell
+REQUIRES: perl
 
 RUN: rm -rf %t.output_dir && mkdir %t.output_dir
 RUN: %scan-build -plist-html -o %t.output_dir %clang -S %S/Inputs/single_null_dereference.c \
diff --git a/clang/test/Analysis/scan-build/plist_output.test b/clang/test/Analysis/scan-build/plist_output.test
index 0112e84630eda2..45c9dd0a5aa2e7 100644
--- a/clang/test/Analysis/scan-build/plist_output.test
+++ b/clang/test/Analysis/scan-build/plist_output.test
@@ -1,5 +1,4 @@
-// FIXME: Actually, "perl".
-REQUIRES: shell
+REQUIRES: perl
 
 RUN: rm -rf %t.output_dir && mkdir %t.output_dir
 RUN: %scan-build -plist -o %t.output_dir %clang -S %S/Inputs/single_null_dereference.c \
diff --git a/clang/test/Analysis/scan-build/rebuild_index/rebuild_index.test b/clang/test/Analysis/scan-build/rebuild_index/rebuild_index.test
index ab70435c60542f..5ce04e132f9fbc 100644
--- a/clang/test/Analysis/scan-build/rebuild_index/rebuild_index.test
+++ b/clang/test/Analysis/scan-build/rebuild_index/rebuild_index.test
@@ -1,5 +1,4 @@
-// FIXME: Actually, "perl".
-REQUIRES: shell
+REQUIRES: perl
 
 RUN: rm -rf %t.output_dir && mkdir %t.output_dir
 RUN: cp %S/report-1.html %t.output_dir
diff --git a/clang/test/Analysis/scan-build/silence-core-checkers.test b/clang/test/Analysis/scan-build/silence-core-checkers.test
index 6d9a3017fcd612..dae54cbfb6579c 100644
--- a/clang/test/Analysis/scan-build/silence-core-checkers.test
+++ b/clang/test/Analysis/scan-build/silence-core-checkers.test
@@ -1,5 +1,4 @@
-// FIXME: Actually, "perl".
-REQUIRES: shell
+REQUIRES: perl
 
 RUN: rm -rf %t.output_dir && mkdir %t.output_dir
 RUN: %scan-build -o %t.output_dir \
diff --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py
index e5630a07424c7c..f82981a0880f08 100644
--- a/clang/test/lit.cfg.py
+++ b/clang/test/lit.cfg.py
@@ -181,6 +181,9 @@ def have_host_clang_repl_cuda():
         )
     )
 
+if config.perl_executable:
+    config.available_features.add("perl")
+
 llvm_config.add_tool_substitutions(tools, tool_dirs)
 
 config.substitutions.append(
diff --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in
index 6641811c588395..24d9a64bcbf6a6 100644
--- a/clang/test/lit.site.cfg.py.in
+++ b/clang/test/lit.site.cfg.py.in
@@ -35,6 +35,7 @@ config.enable_threads = @LLVM_ENABLE_THREADS@
 config.reverse_iteration = @LLVM_ENABLE_REVERSE_ITERATION@
 config.host_arch = "@HOST_ARCH@"
 config.python_executable = "@Python3_EXECUTABLE@"
+config.perl_executable = "@PERL_EXECUTABLE@"
 config.use_z3_solver = lit_config.params.get('USE_Z3_SOLVER', "@USE_Z3_SOLVER@")
 config.has_plugins = @CLANG_PLUGIN_SUPPORT@
 config.clang_vendor_uti = "@CLANG_VENDOR_UTI@"

Copy link
Collaborator

@haoNoQ haoNoQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great thanks a lot!!

I can confirm that it works for me on a mac too.

@jroelofs's comment is on point.

@MatzeB
Copy link
Contributor Author

MatzeB commented May 7, 2024

Explicitly disabling the scan-build tests on windows now.

I think they weren't previously running there because of REQUIRES: shell anyway and as far as I can tell from the buildkite results it seems the scan-build does not work correctly on windows at the moment.

@MatzeB MatzeB merged commit 2868e26 into llvm:main May 8, 2024
@MatzeB MatzeB deleted the perl_check branch May 8, 2024 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants