blob: 978c25cb4ca308d1dfb565ce146db8b4ca3b5eac [file] [log] [blame]
commit-queue@webkit.org026ee042018-01-04 07:18:18 +00001#!/usr/bin/env perl
darind63e9d92005-06-12 22:48:34 +00002
ddkilzer@apple.coma88371b2021-03-28 18:31:55 +00003# Copyright (C) 2005-2021 Apple Inc. All rights reserved.
darind63e9d92005-06-12 22:48:34 +00004#
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.com92047332014-03-15 04:08:27 +000014# 3. Neither the name of Apple Inc. ("Apple") nor the names of
darind63e9d92005-06-12 22:48:34 +000015# 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
29use strict;
commit-queue@webkit.org026ee042018-01-04 07:18:18 +000030use warnings;
emw@apple.com3ab0cce2022-04-12 23:02:14 +000031use File::Path qw(make_path);
ddkilzer@apple.com467ae4f2020-09-16 02:53:36 +000032use File::Spec;
darind63e9d92005-06-12 22:48:34 +000033use FindBin;
34use lib $FindBin::Bin;
35use webkitdirs;
36
mrowe@apple.com307ffb62009-03-14 06:17:16 +000037my $programName = basename($0);
38my $usage = <<EOF;
39Usage: $programName [options]
mark.lam@apple.comba405212020-01-06 20:58:44 +000040 --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.com467ae4f2020-09-16 02:53:36 +000043 --[no-]tsan Enable or disable clang thread sanitizer
ddkilzer@apple.coma88371b2021-03-28 18:31:55 +000044 --[no-]ubsan Enable or disable clang undefined behavior sanitizer
ddkilzer@apple.come09f5dc2021-04-06 18:02:25 +000045 --[no-]coverage Enable or disable LLVM Source-based Code Coverage
mark.lam@apple.comba405212020-01-06 20:58:44 +000046 --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.com3ab0cce2022-04-12 23:02:14 +000051 -h, --help Show this message and exit
mrowe@apple.com307ffb62009-03-14 06:17:16 +000052EOF
53
ddkilzer@apple.come09f5dc2021-04-06 18:02:25 +000054sub printCurrentSettings();
55sub printUsage();
ddkilzer@apple.com71cf9fc2021-04-08 23:04:46 +000056sub updateOrDeleteConfigurationFile($$$);
ddkilzer@apple.come09f5dc2021-04-06 18:02:25 +000057
darind63e9d92005-06-12 22:48:34 +000058my $configuration = passedConfiguration();
mrowe@apple.com307ffb62009-03-14 06:17:16 +000059my $architecture = passedArchitecture();
ap@apple.com224b70f2014-12-24 00:13:16 +000060my $enableASAN = checkForArgumentAndRemoveFromARGV("--asan");
61my $disableASAN = checkForArgumentAndRemoveFromARGV("--no-asan");
ddkilzer@apple.com467ae4f2020-09-16 02:53:36 +000062my $enableTSAN = checkForArgumentAndRemoveFromARGV("--tsan");
63my $disableTSAN = checkForArgumentAndRemoveFromARGV("--no-tsan");
ddkilzer@apple.coma88371b2021-03-28 18:31:55 +000064my $enableUBSAN = checkForArgumentAndRemoveFromARGV("--ubsan");
65my $disableUBSAN = checkForArgumentAndRemoveFromARGV("--no-ubsan");
ddkilzer@apple.come09f5dc2021-04-06 18:02:25 +000066my $enableCoverage = checkForArgumentAndRemoveFromARGV("--coverage");
67my $disableCoverage = checkForArgumentAndRemoveFromARGV("--no-coverage");
krollin@apple.com2ba23ff2018-08-27 17:16:17 +000068my $ltoMode;
69if (!checkForArgumentAndRemoveFromARGVGettingValue("--lto-mode", \$ltoMode)) {
70 $ltoMode="";
71}
mark.lam@apple.comba405212020-01-06 20:58:44 +000072my $forceOptimizationLevel;
mark.lam@apple.com87bdd5d2020-01-08 22:20:24 +000073if (!checkForArgumentAndRemoveFromARGVGettingValue("--force-optimization-level", \$forceOptimizationLevel)
74 && !checkForArgumentAndRemoveFromARGVGettingValue("--force-opt", \$forceOptimizationLevel)) {
mark.lam@apple.comba405212020-01-06 20:58:44 +000075 $forceOptimizationLevel="";
76}
mrowe@apple.com307ffb62009-03-14 06:17:16 +000077
emw@apple.com3ab0cce2022-04-12 23:02:14 +000078if (checkForArgumentAndRemoveFromARGV("-h") || checkForArgumentAndRemoveFromARGV("--help")) {
79 printUsage();
80 exit 1;
81}
82
mrowe@apple.com307ffb62009-03-14 06:17:16 +000083if (!$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.orgfe7ce2b2014-03-18 17:54:53 +000094my $baseProductDir = baseProductDir();
emw@apple.com3ab0cce2022-04-12 23:02:14 +000095if (isAppleCocoaWebKit() && !isCMakeBuild()) {
96 markBaseProductDirectoryAsCreatedByXcodeBuildSystem();
97} else {
98 make_path($baseProductDir);
99}
commit-queue@webkit.orgfe7ce2b2014-03-18 17:54:53 +0000100
101if (checkForArgumentAndRemoveFromARGV("--reset")) {
ddkilzer@apple.coma88371b2021-03-28 18:31:55 +0000102 for my $fileName (qw(Architecture ASan Configuration Coverage ForceOptimizationLevel LTO TSan UBSan)) {
103 unlink File::Spec->catfile($baseProductDir, $fileName);
104 }
ddkilzer@apple.come09f5dc2021-04-06 18:02:25 +0000105 printCurrentSettings();
commit-queue@webkit.orgfe7ce2b2014-03-18 17:54:53 +0000106 exit 0;
107}
108
ddkilzer@apple.coma88371b2021-03-28 18:31:55 +0000109if ($enableASAN && $enableTSAN) {
110 print STDERR "ERROR: Address Sanitizer and Thread Sanitzer can't be enabled together.\n";
ddkilzer@apple.come09f5dc2021-04-06 18:02:25 +0000111 printUsage();
ddkilzer@apple.coma88371b2021-03-28 18:31:55 +0000112 exit 1;
113}
114
krollin@apple.com2ba23ff2018-08-27 17:16:17 +0000115if ($ltoMode && $ltoMode ne "full" && $ltoMode ne "thin" && $ltoMode ne "none") {
ddkilzer@apple.come09f5dc2021-04-06 18:02:25 +0000116 printUsage();
mrowe@apple.com307ffb62009-03-14 06:17:16 +0000117 exit 1;
118}
darind63e9d92005-06-12 22:48:34 +0000119
mark.lam@apple.comba405212020-01-06 20:58:44 +0000120if ($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.come09f5dc2021-04-06 18:02:25 +0000129 printUsage();
mark.lam@apple.comba405212020-01-06 20:58:44 +0000130 exit 1;
131}
132
ddkilzer@apple.com7ed8b542021-03-31 20:36:11 +0000133if ($configuration) {
134 open CONFIGURATION, ">", "$baseProductDir/Configuration" or die;
135 print CONFIGURATION $configuration;
136 close CONFIGURATION;
137}
138
139if ($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.com71cf9fc2021-04-08 23:04:46 +0000149updateOrDeleteConfigurationFile("ASan", $enableASAN, $disableASAN);
150updateOrDeleteConfigurationFile("Coverage", $enableCoverage, $disableCoverage);
151updateOrDeleteConfigurationFile("TSan", $enableTSAN, $disableTSAN);
152updateOrDeleteConfigurationFile("UBSan", $enableUBSAN, $disableUBSAN);
ddkilzer@apple.com7ed8b542021-03-31 20:36:11 +0000153
154if ($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
162if ($ltoMode) {
163 open LTO, ">", "$baseProductDir/LTO" or die;
164 print LTO "$ltoMode";
165 close LTO;
166}
ddkilzer@apple.come09f5dc2021-04-06 18:02:25 +0000167
168printCurrentSettings();
169
170exit 0;
171
172sub 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
187sub printUsage()
188{
189 print STDERR $usage, "\n";
190 printCurrentSettings();
191}
ddkilzer@apple.com71cf9fc2021-04-08 23:04:46 +0000192
193sub 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}