================ @@ -51,63 +51,40 @@ sub silent_system { # Compiler command setup. ##===----------------------------------------------------------------------===## -# Search in the PATH if the compiler exists -sub SearchInPath { - my $file = shift; - foreach my $dir (split (':', $ENV{PATH})) { - if (-x "$dir/$file") { - return 1; - } - } - return 0; -} - -my $Compiler; -my $Clang; -my $DefaultCCompiler; -my $DefaultCXXCompiler; -my $IsCXX; -my $AnalyzerTarget; - -# If on OSX, use xcrun to determine the SDK root. -my $UseXCRUN = 0; - -if (`uname -s` =~ m/Darwin/) { - $DefaultCCompiler = 'clang'; - $DefaultCXXCompiler = 'clang++'; - # Older versions of OSX do not have xcrun to - # query the SDK location. - if (-x "/usr/bin/xcrun") { - $UseXCRUN = 1; - } -} elsif (`uname -s` =~ m/(FreeBSD|OpenBSD)/) { - $DefaultCCompiler = 'cc'; - $DefaultCXXCompiler = 'c++'; -} else { - $DefaultCCompiler = 'gcc'; - $DefaultCXXCompiler = 'g++'; -} - -if ($FindBin::Script =~ /c\+\+-analyzer/) { - $Compiler = $ENV{'CCC_CXX'}; - if (!defined $Compiler || (! -x $Compiler && ! SearchInPath($Compiler))) { $Compiler = $DefaultCXXCompiler; } - - $Clang = $ENV{'CLANG_CXX'}; - if (!defined $Clang || ! -x $Clang) { $Clang = 'clang++'; } - - $IsCXX = 1 +{ + my ($DefaultCCompiler, $DefaultCXXCompiler); + + my $os = `uname -s`; + if ($os =~ m/Darwin/) { + $DefaultCCompiler = 'clang'; + $DefaultCXXCompiler = 'clang++'; + } elsif ($os =~ m/(FreeBSD|OpenBSD)/) { + $DefaultCCompiler = 'cc'; + $DefaultCXXCompiler = 'c++'; + } else { + $DefaultCCompiler = 'gcc'; + $DefaultCXXCompiler = 'g++'; + } + + sub DetermineCompiler { + my ($is_cxx) = @_; + my $default = $is_cxx ? $DefaultCXXCompiler : $DefaultCCompiler; + my $opt = $ENV{$is_cxx ? 'CCC_CXX' : 'CCC_CC'}; + return defined $opt ? shellwords($opt) : $default; + } } -else { - $Compiler = $ENV{'CCC_CC'}; - if (!defined $Compiler || (! -x $Compiler && ! SearchInPath($Compiler))) { $Compiler = $DefaultCCompiler; } - - $Clang = $ENV{'CLANG'}; - if (!defined $Clang || ! -x $Clang) { $Clang = 'clang'; } - $IsCXX = 0 +sub DetermineClang { + my ($is_cxx) = @_; ---------------- rafl wrote:
I'm with you on the mix of different styles in this code being far from ideal. I did briefly consider cleaning those things up a bit, but decided to not extend the scope of this changeset further and to perhaps save those kinds of changes for a separate pull-request if there was any interest in that. Here's how I arrived at the names currently used in this pull-request: * Functions Almost all existing functions use UpperCamelCase, so I stuck with that even though it's not at all typical for the majority of modern(-ish) Perl code * Variables These were also quite inconsistent, but I stuck with common modern(-ish) practices, where most regular lexical variables use `$snake_case`, constants use `$ALL_CAPS`, and "globals" use `$UpperCamelCase` as per https://metacpan.org/dist/perl/view/pod/perlstyle.pod, the old Perl Best Practices book, and established community conventions. I'd find it much more jarring if a function was to potentially shadow a variable which reads like a `$Global` from a surrounding scope. I don't feel particularly strongly about it, and would appreciate your input on the following suggestions for how to best move forwards: 1. Just call the parameter `$IsCXX` in the functions as suggested. This defies the expectations of many Perl programmers when it comes to naming, but so does most of the rest of the program. 2. Keep things as they are. This is consistent with modern practices. 3. Call the local `$is_cxx` variable something else (but not `$IsCXX`), or rename the "global" `$IsCXX`. To not potentially confuse people unfamiliar with Perl or its current common practices. 4. Just use the "global" `$IsCXX` directly. Reducing some of the global state to make it slightly easier to reason about those individual functions seemed nice, but given how much of it there is anyway, maybe it doesn't even matter in this context. Thanks for your review and your feedback on the above! https://github.com/llvm/llvm-project/pull/131932 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits