@@ -520,19 +520,30 @@ def use_llvm_tool(
520
520
self .lit_config .note ("using {}: {}" .format (name , tool ))
521
521
return tool
522
522
523
- def use_clang (
523
+ def _get_clang_paths (self , additional_tool_dirs ):
524
+ # Put Clang first to avoid LLVM from overriding out-of-tree clang
525
+ # builds.
526
+ exe_dir_props = [
527
+ self .config .name .lower () + "_tools_dir" ,
528
+ "clang_tools_dir" ,
529
+ "llvm_tools_dir" ,
530
+ ]
531
+ paths = [
532
+ getattr (self .config , pp )
533
+ for pp in exe_dir_props
534
+ if getattr (self .config , pp , None )
535
+ ]
536
+ paths = additional_tool_dirs + paths
537
+ return paths
538
+
539
+ def clang_setup (
524
540
self ,
525
541
additional_tool_dirs = [],
526
- additional_flags = [],
527
- required = True ,
528
- use_installed = False ,
529
542
):
530
- """Configure the test suite to be able to invoke clang.
531
-
532
- Sets up some environment variables important to clang, locates a
533
- just-built or optionally an installed clang, and add a set of standard
534
- substitutions useful to any test suite that makes use of clang.
543
+ """Perform the setup needed to be able to invoke clang.
535
544
545
+ This function performs all the necessary setup to execute clang (or
546
+ tooling based on clang) but does not actually add clang as a tool.
536
547
"""
537
548
# Clear some environment variables that might affect Clang.
538
549
#
@@ -573,20 +584,9 @@ def use_clang(
573
584
self .clear_environment (possibly_dangerous_env_vars )
574
585
575
586
# Tweak the PATH to include the tools dir and the scripts dir.
576
- # Put Clang first to avoid LLVM from overriding out-of-tree clang
577
- # builds.
578
- exe_dir_props = [
579
- self .config .name .lower () + "_tools_dir" ,
580
- "clang_tools_dir" ,
581
- "llvm_tools_dir" ,
582
- ]
583
- paths = [
584
- getattr (self .config , pp )
585
- for pp in exe_dir_props
586
- if getattr (self .config , pp , None )
587
- ]
588
- paths = additional_tool_dirs + paths
589
- self .with_environment ("PATH" , paths , append_path = True )
587
+ self .with_environment (
588
+ "PATH" , self ._get_clang_paths (additional_tool_dirs ), append_path = True
589
+ )
590
590
591
591
lib_dir_props = [
592
592
self .config .name .lower () + "_libs_dir" ,
@@ -611,63 +611,6 @@ def use_clang(
611
611
if pext :
612
612
self .config .substitutions .append (("%pluginext" , pext ))
613
613
614
- # Discover the 'clang' and 'clangcc' to use.
615
- self .config .clang = self .use_llvm_tool (
616
- "clang" ,
617
- search_env = "CLANG" ,
618
- required = required ,
619
- search_paths = paths ,
620
- use_installed = use_installed ,
621
- )
622
- if self .config .clang :
623
- self .config .available_features .add ("clang" )
624
- builtin_include_dir = self .get_clang_builtin_include_dir (self .config .clang )
625
- tool_substitutions = [
626
- ToolSubst (
627
- "%clang" , command = self .config .clang , extra_args = additional_flags
628
- ),
629
- ToolSubst (
630
- "%clang_analyze_cc1" ,
631
- command = "%clang_cc1" ,
632
- # -setup-static-analyzer ensures that __clang_analyzer__ is defined
633
- extra_args = ["-analyze" , "-setup-static-analyzer" ]
634
- + additional_flags ,
635
- ),
636
- ToolSubst (
637
- "%clang_cc1" ,
638
- command = self .config .clang ,
639
- extra_args = [
640
- "-cc1" ,
641
- "-internal-isystem" ,
642
- builtin_include_dir ,
643
- "-nostdsysteminc" ,
644
- ]
645
- + additional_flags ,
646
- ),
647
- ToolSubst (
648
- "%clang_cpp" ,
649
- command = self .config .clang ,
650
- extra_args = ["--driver-mode=cpp" ] + additional_flags ,
651
- ),
652
- ToolSubst (
653
- "%clang_cl" ,
654
- command = self .config .clang ,
655
- extra_args = ["--driver-mode=cl" ] + additional_flags ,
656
- ),
657
- ToolSubst (
658
- "%clang_dxc" ,
659
- command = self .config .clang ,
660
- extra_args = ["--driver-mode=dxc" ] + additional_flags ,
661
- ),
662
- ToolSubst (
663
- "%clangxx" ,
664
- command = self .config .clang ,
665
- extra_args = ["--driver-mode=g++" ] + additional_flags ,
666
- ),
667
- ]
668
- self .add_tool_substitutions (tool_substitutions )
669
- self .config .substitutions .append (("%resource_dir" , builtin_include_dir ))
670
-
671
614
# There will be no default target triple if one was not specifically
672
615
# set, and the host's architecture is not an enabled target.
673
616
if self .config .target_triple :
@@ -729,6 +672,81 @@ def add_std_cxx(s):
729
672
add_std_cxx ("%std_cxx20-" )
730
673
add_std_cxx ("%std_cxx23-" )
731
674
675
+ def use_clang (
676
+ self ,
677
+ additional_tool_dirs = [],
678
+ additional_flags = [],
679
+ required = True ,
680
+ use_installed = False ,
681
+ ):
682
+ """Configure the test suite to be able to invoke clang.
683
+
684
+ Sets up some environment variables important to clang, locates a
685
+ just-built or optionally an installed clang, and add a set of standard
686
+ substitutions useful to any test suite that makes use of clang.
687
+
688
+ """
689
+ self .clang_setup (additional_tool_dirs )
690
+
691
+ paths = self ._get_clang_paths (additional_tool_dirs )
692
+
693
+ # Discover the 'clang' and 'clangcc' to use.
694
+ self .config .clang = self .use_llvm_tool (
695
+ "clang" ,
696
+ search_env = "CLANG" ,
697
+ required = required ,
698
+ search_paths = paths ,
699
+ use_installed = use_installed ,
700
+ )
701
+ if self .config .clang :
702
+ self .config .available_features .add ("clang" )
703
+ builtin_include_dir = self .get_clang_builtin_include_dir (self .config .clang )
704
+ tool_substitutions = [
705
+ ToolSubst (
706
+ "%clang" , command = self .config .clang , extra_args = additional_flags
707
+ ),
708
+ ToolSubst (
709
+ "%clang_analyze_cc1" ,
710
+ command = "%clang_cc1" ,
711
+ # -setup-static-analyzer ensures that __clang_analyzer__ is defined
712
+ extra_args = ["-analyze" , "-setup-static-analyzer" ]
713
+ + additional_flags ,
714
+ ),
715
+ ToolSubst (
716
+ "%clang_cc1" ,
717
+ command = self .config .clang ,
718
+ extra_args = [
719
+ "-cc1" ,
720
+ "-internal-isystem" ,
721
+ builtin_include_dir ,
722
+ "-nostdsysteminc" ,
723
+ ]
724
+ + additional_flags ,
725
+ ),
726
+ ToolSubst (
727
+ "%clang_cpp" ,
728
+ command = self .config .clang ,
729
+ extra_args = ["--driver-mode=cpp" ] + additional_flags ,
730
+ ),
731
+ ToolSubst (
732
+ "%clang_cl" ,
733
+ command = self .config .clang ,
734
+ extra_args = ["--driver-mode=cl" ] + additional_flags ,
735
+ ),
736
+ ToolSubst (
737
+ "%clang_dxc" ,
738
+ command = self .config .clang ,
739
+ extra_args = ["--driver-mode=dxc" ] + additional_flags ,
740
+ ),
741
+ ToolSubst (
742
+ "%clangxx" ,
743
+ command = self .config .clang ,
744
+ extra_args = ["--driver-mode=g++" ] + additional_flags ,
745
+ ),
746
+ ]
747
+ self .add_tool_substitutions (tool_substitutions )
748
+ self .config .substitutions .append (("%resource_dir" , builtin_include_dir ))
749
+
732
750
# FIXME: Find nicer way to prohibit this.
733
751
def prefer (this , to ):
734
752
return '''\" *** Do not use '%s' in tests, use '%s'. ***\" ''' % (to , this )
0 commit comments