commit-queue@webkit.org | 026ee04 | 2018-01-04 07:18:18 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
darin | d63e9d9 | 2005-06-12 22:48:34 +0000 | [diff] [blame] | 2 | |
ddkilzer@apple.com | a88371b | 2021-03-28 18:31:55 +0000 | [diff] [blame] | 3 | # Copyright (C) 2005-2021 Apple Inc. All rights reserved. |
darin | d63e9d9 | 2005-06-12 22:48:34 +0000 | [diff] [blame] | 4 | # |
| 5 | # Redistribution and use in source and binary forms, with or without |
| 6 | # modification, are permitted provided that the following conditions |
| 7 | # are met: |
| 8 | # |
| 9 | # 1. Redistributions of source code must retain the above copyright |
| 10 | # notice, this list of conditions and the following disclaimer. |
| 11 | # 2. Redistributions in binary form must reproduce the above copyright |
| 12 | # notice, this list of conditions and the following disclaimer in the |
| 13 | # documentation and/or other materials provided with the distribution. |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 14 | # 3. Neither the name of Apple Inc. ("Apple") nor the names of |
darin | d63e9d9 | 2005-06-12 22:48:34 +0000 | [diff] [blame] | 15 | # its contributors may be used to endorse or promote products derived |
| 16 | # from this software without specific prior written permission. |
| 17 | # |
| 18 | # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 19 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 | # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 22 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 25 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | |
| 29 | use strict; |
commit-queue@webkit.org | 026ee04 | 2018-01-04 07:18:18 +0000 | [diff] [blame] | 30 | use warnings; |
emw@apple.com | 3ab0cce | 2022-04-12 23:02:14 +0000 | [diff] [blame] | 31 | use File::Path qw(make_path); |
ddkilzer@apple.com | 467ae4f | 2020-09-16 02:53:36 +0000 | [diff] [blame] | 32 | use File::Spec; |
darin | d63e9d9 | 2005-06-12 22:48:34 +0000 | [diff] [blame] | 33 | use FindBin; |
| 34 | use lib $FindBin::Bin; |
| 35 | use webkitdirs; |
| 36 | |
mrowe@apple.com | 307ffb6 | 2009-03-14 06:17:16 +0000 | [diff] [blame] | 37 | my $programName = basename($0); |
| 38 | my $usage = <<EOF; |
| 39 | Usage: $programName [options] |
mark.lam@apple.com | ba40521 | 2020-01-06 20:58:44 +0000 | [diff] [blame] | 40 | --32-bit Set the default architecture to 32-bit |
| 41 | --64-bit Set the default architecture to 64-bit |
| 42 | --[no-]asan Enable or disable clang address sanitizer |
ddkilzer@apple.com | 467ae4f | 2020-09-16 02:53:36 +0000 | [diff] [blame] | 43 | --[no-]tsan Enable or disable clang thread sanitizer |
ddkilzer@apple.com | a88371b | 2021-03-28 18:31:55 +0000 | [diff] [blame] | 44 | --[no-]ubsan Enable or disable clang undefined behavior sanitizer |
ddkilzer@apple.com | e09f5dc | 2021-04-06 18:02:25 +0000 | [diff] [blame] | 45 | --[no-]coverage Enable or disable LLVM Source-based Code Coverage |
mark.lam@apple.com | ba40521 | 2020-01-06 20:58:44 +0000 | [diff] [blame] | 46 | --force-optimization-level=<level> Optimization level: O3, O2, O1, O0, Os, Ofast, Og, or none |
| 47 | --lto-mode=<mode> Set LTO mode: full, thin, or none |
| 48 | --debug Set the default configuration to debug |
| 49 | --release Set the default configuration to release |
| 50 | --reset Reset configurations |
emw@apple.com | 3ab0cce | 2022-04-12 23:02:14 +0000 | [diff] [blame] | 51 | -h, --help Show this message and exit |
mrowe@apple.com | 307ffb6 | 2009-03-14 06:17:16 +0000 | [diff] [blame] | 52 | EOF |
| 53 | |
ddkilzer@apple.com | e09f5dc | 2021-04-06 18:02:25 +0000 | [diff] [blame] | 54 | sub printCurrentSettings(); |
| 55 | sub printUsage(); |
ddkilzer@apple.com | 71cf9fc | 2021-04-08 23:04:46 +0000 | [diff] [blame] | 56 | sub updateOrDeleteConfigurationFile($$$); |
ddkilzer@apple.com | e09f5dc | 2021-04-06 18:02:25 +0000 | [diff] [blame] | 57 | |
darin | d63e9d9 | 2005-06-12 22:48:34 +0000 | [diff] [blame] | 58 | my $configuration = passedConfiguration(); |
mrowe@apple.com | 307ffb6 | 2009-03-14 06:17:16 +0000 | [diff] [blame] | 59 | my $architecture = passedArchitecture(); |
ap@apple.com | 224b70f | 2014-12-24 00:13:16 +0000 | [diff] [blame] | 60 | my $enableASAN = checkForArgumentAndRemoveFromARGV("--asan"); |
| 61 | my $disableASAN = checkForArgumentAndRemoveFromARGV("--no-asan"); |
ddkilzer@apple.com | 467ae4f | 2020-09-16 02:53:36 +0000 | [diff] [blame] | 62 | my $enableTSAN = checkForArgumentAndRemoveFromARGV("--tsan"); |
| 63 | my $disableTSAN = checkForArgumentAndRemoveFromARGV("--no-tsan"); |
ddkilzer@apple.com | a88371b | 2021-03-28 18:31:55 +0000 | [diff] [blame] | 64 | my $enableUBSAN = checkForArgumentAndRemoveFromARGV("--ubsan"); |
| 65 | my $disableUBSAN = checkForArgumentAndRemoveFromARGV("--no-ubsan"); |
ddkilzer@apple.com | e09f5dc | 2021-04-06 18:02:25 +0000 | [diff] [blame] | 66 | my $enableCoverage = checkForArgumentAndRemoveFromARGV("--coverage"); |
| 67 | my $disableCoverage = checkForArgumentAndRemoveFromARGV("--no-coverage"); |
krollin@apple.com | 2ba23ff | 2018-08-27 17:16:17 +0000 | [diff] [blame] | 68 | my $ltoMode; |
| 69 | if (!checkForArgumentAndRemoveFromARGVGettingValue("--lto-mode", \$ltoMode)) { |
| 70 | $ltoMode=""; |
| 71 | } |
mark.lam@apple.com | ba40521 | 2020-01-06 20:58:44 +0000 | [diff] [blame] | 72 | my $forceOptimizationLevel; |
mark.lam@apple.com | 87bdd5d | 2020-01-08 22:20:24 +0000 | [diff] [blame] | 73 | if (!checkForArgumentAndRemoveFromARGVGettingValue("--force-optimization-level", \$forceOptimizationLevel) |
| 74 | && !checkForArgumentAndRemoveFromARGVGettingValue("--force-opt", \$forceOptimizationLevel)) { |
mark.lam@apple.com | ba40521 | 2020-01-06 20:58:44 +0000 | [diff] [blame] | 75 | $forceOptimizationLevel=""; |
| 76 | } |
mrowe@apple.com | 307ffb6 | 2009-03-14 06:17:16 +0000 | [diff] [blame] | 77 | |
emw@apple.com | 3ab0cce | 2022-04-12 23:02:14 +0000 | [diff] [blame] | 78 | if (checkForArgumentAndRemoveFromARGV("-h") || checkForArgumentAndRemoveFromARGV("--help")) { |
| 79 | printUsage(); |
| 80 | exit 1; |
| 81 | } |
| 82 | |
mrowe@apple.com | 307ffb6 | 2009-03-14 06:17:16 +0000 | [diff] [blame] | 83 | if (!$architecture) { |
| 84 | # Handle --64-bit explicitly here, as we don't want our other scripts to accept it |
| 85 | for my $i (0 .. $#ARGV) { |
| 86 | my $opt = $ARGV[$i]; |
| 87 | if ($opt =~ /^--64-bit$/i) { |
| 88 | splice(@ARGV, $i, 1); |
| 89 | $architecture = 'x86_64'; |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
commit-queue@webkit.org | fe7ce2b | 2014-03-18 17:54:53 +0000 | [diff] [blame] | 94 | my $baseProductDir = baseProductDir(); |
emw@apple.com | 3ab0cce | 2022-04-12 23:02:14 +0000 | [diff] [blame] | 95 | if (isAppleCocoaWebKit() && !isCMakeBuild()) { |
| 96 | markBaseProductDirectoryAsCreatedByXcodeBuildSystem(); |
| 97 | } else { |
| 98 | make_path($baseProductDir); |
| 99 | } |
commit-queue@webkit.org | fe7ce2b | 2014-03-18 17:54:53 +0000 | [diff] [blame] | 100 | |
| 101 | if (checkForArgumentAndRemoveFromARGV("--reset")) { |
ddkilzer@apple.com | a88371b | 2021-03-28 18:31:55 +0000 | [diff] [blame] | 102 | for my $fileName (qw(Architecture ASan Configuration Coverage ForceOptimizationLevel LTO TSan UBSan)) { |
| 103 | unlink File::Spec->catfile($baseProductDir, $fileName); |
| 104 | } |
ddkilzer@apple.com | e09f5dc | 2021-04-06 18:02:25 +0000 | [diff] [blame] | 105 | printCurrentSettings(); |
commit-queue@webkit.org | fe7ce2b | 2014-03-18 17:54:53 +0000 | [diff] [blame] | 106 | exit 0; |
| 107 | } |
| 108 | |
ddkilzer@apple.com | a88371b | 2021-03-28 18:31:55 +0000 | [diff] [blame] | 109 | if ($enableASAN && $enableTSAN) { |
| 110 | print STDERR "ERROR: Address Sanitizer and Thread Sanitzer can't be enabled together.\n"; |
ddkilzer@apple.com | e09f5dc | 2021-04-06 18:02:25 +0000 | [diff] [blame] | 111 | printUsage(); |
ddkilzer@apple.com | a88371b | 2021-03-28 18:31:55 +0000 | [diff] [blame] | 112 | exit 1; |
| 113 | } |
| 114 | |
krollin@apple.com | 2ba23ff | 2018-08-27 17:16:17 +0000 | [diff] [blame] | 115 | if ($ltoMode && $ltoMode ne "full" && $ltoMode ne "thin" && $ltoMode ne "none") { |
ddkilzer@apple.com | e09f5dc | 2021-04-06 18:02:25 +0000 | [diff] [blame] | 116 | printUsage(); |
mrowe@apple.com | 307ffb6 | 2009-03-14 06:17:16 +0000 | [diff] [blame] | 117 | exit 1; |
| 118 | } |
darin | d63e9d9 | 2005-06-12 22:48:34 +0000 | [diff] [blame] | 119 | |
mark.lam@apple.com | ba40521 | 2020-01-06 20:58:44 +0000 | [diff] [blame] | 120 | if ($forceOptimizationLevel |
| 121 | && $forceOptimizationLevel ne "none" |
| 122 | && $forceOptimizationLevel ne "O0" |
| 123 | && $forceOptimizationLevel ne "O1" |
| 124 | && $forceOptimizationLevel ne "O2" |
| 125 | && $forceOptimizationLevel ne "O3" |
| 126 | && $forceOptimizationLevel ne "Os" |
| 127 | && $forceOptimizationLevel ne "Ofast" |
| 128 | && $forceOptimizationLevel ne "Og") { |
ddkilzer@apple.com | e09f5dc | 2021-04-06 18:02:25 +0000 | [diff] [blame] | 129 | printUsage(); |
mark.lam@apple.com | ba40521 | 2020-01-06 20:58:44 +0000 | [diff] [blame] | 130 | exit 1; |
| 131 | } |
| 132 | |
ddkilzer@apple.com | 7ed8b54 | 2021-03-31 20:36:11 +0000 | [diff] [blame] | 133 | if ($configuration) { |
| 134 | open CONFIGURATION, ">", "$baseProductDir/Configuration" or die; |
| 135 | print CONFIGURATION $configuration; |
| 136 | close CONFIGURATION; |
| 137 | } |
| 138 | |
| 139 | if ($architecture) { |
| 140 | if ($architecture ne "x86_64") { |
| 141 | open ARCHITECTURE, ">", "$baseProductDir/Architecture" or die; |
| 142 | print ARCHITECTURE $architecture; |
| 143 | close ARCHITECTURE; |
| 144 | } else { |
| 145 | unlink "$baseProductDir/Architecture"; |
| 146 | } |
| 147 | } |
| 148 | |
ddkilzer@apple.com | 71cf9fc | 2021-04-08 23:04:46 +0000 | [diff] [blame] | 149 | updateOrDeleteConfigurationFile("ASan", $enableASAN, $disableASAN); |
| 150 | updateOrDeleteConfigurationFile("Coverage", $enableCoverage, $disableCoverage); |
| 151 | updateOrDeleteConfigurationFile("TSan", $enableTSAN, $disableTSAN); |
| 152 | updateOrDeleteConfigurationFile("UBSan", $enableUBSAN, $disableUBSAN); |
ddkilzer@apple.com | 7ed8b54 | 2021-03-31 20:36:11 +0000 | [diff] [blame] | 153 | |
| 154 | if ($forceOptimizationLevel && $forceOptimizationLevel eq "none") { |
| 155 | unlink "$baseProductDir/ForceOptimizationLevel"; |
| 156 | } elsif ($forceOptimizationLevel) { |
| 157 | open ForceOptimizationLevel, ">", "$baseProductDir/ForceOptimizationLevel" or die; |
| 158 | print ForceOptimizationLevel substr($forceOptimizationLevel, 1) . "\n"; |
| 159 | close ForceOptimizationLevel; |
| 160 | } |
| 161 | |
| 162 | if ($ltoMode) { |
| 163 | open LTO, ">", "$baseProductDir/LTO" or die; |
| 164 | print LTO "$ltoMode"; |
| 165 | close LTO; |
| 166 | } |
ddkilzer@apple.com | e09f5dc | 2021-04-06 18:02:25 +0000 | [diff] [blame] | 167 | |
| 168 | printCurrentSettings(); |
| 169 | |
| 170 | exit 0; |
| 171 | |
| 172 | sub printCurrentSettings() |
| 173 | { |
| 174 | my $result = "Current settings:"; |
| 175 | $result .= " Configuration:" . configuration(); |
| 176 | $result .= " Arch:" . architecture() if architecture(); |
| 177 | $result .= " ASan" if asanIsEnabled(); |
| 178 | $result .= " TSan" if tsanIsEnabled(); |
| 179 | $result .= " UBSan" if ubsanIsEnabled(); |
| 180 | $result .= " Coverage" if coverageIsEnabled(); |
| 181 | $result .= " LTOMode:" . ltoMode() if ltoMode(); |
| 182 | $result .= " ForceOptimizationLevel:O" . forceOptimizationLevel() if forceOptimizationLevel(); |
| 183 | |
| 184 | print STDERR $result, "\n"; |
| 185 | } |
| 186 | |
| 187 | sub printUsage() |
| 188 | { |
| 189 | print STDERR $usage, "\n"; |
| 190 | printCurrentSettings(); |
| 191 | } |
ddkilzer@apple.com | 71cf9fc | 2021-04-08 23:04:46 +0000 | [diff] [blame] | 192 | |
| 193 | sub updateOrDeleteConfigurationFile($$$) |
| 194 | { |
| 195 | my ($fileName, $shouldEnable, $shouldDisable) = @_; |
| 196 | my $filePath = File::Spec->catfile($baseProductDir, $fileName); |
| 197 | if ($shouldEnable) { |
| 198 | open FILE, ">", $filePath or die; |
| 199 | print FILE "YES"; |
| 200 | close FILE; |
| 201 | } elsif ($shouldDisable) { |
| 202 | unlink $filePath; |
| 203 | } |
| 204 | } |