aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorBilly O'Neal <bion@microsoft.com>2021-01-13 14:06:06 -0800
committerGitHub <noreply@github.com>2021-01-13 14:06:06 -0800
commit8414e15973097e70fe40149e922c402799804b3d (patch)
treeca46f3f317f0eef7924f3b76828868d51bb249cf /scripts
parent4da47f758fb5e02fc017047e014d15174b85a848 (diff)
downloadvcpkg-8414e15973097e70fe40149e922c402799804b3d.tar.gz
vcpkg-8414e15973097e70fe40149e922c402799804b3d.zip
[vcpkg] Use a tag file rather than conditional compilation to permanently disable metrics. (#15470)
Diffstat (limited to 'scripts')
-rw-r--r--scripts/azure-pipelines/end-to-end-tests-dir/disable-metrics.ps161
-rw-r--r--scripts/azure-pipelines/end-to-end-tests-prelude.ps112
-rw-r--r--scripts/bootstrap.ps19
-rw-r--r--scripts/bootstrap.sh8
4 files changed, 84 insertions, 6 deletions
diff --git a/scripts/azure-pipelines/end-to-end-tests-dir/disable-metrics.ps1 b/scripts/azure-pipelines/end-to-end-tests-dir/disable-metrics.ps1
new file mode 100644
index 000000000..efec472b4
--- /dev/null
+++ b/scripts/azure-pipelines/end-to-end-tests-dir/disable-metrics.ps1
@@ -0,0 +1,61 @@
+. $PSScriptRoot/../end-to-end-tests-prelude.ps1
+
+# Test that metrics are on by default
+$metricsTagName = 'vcpkg.disable-metrics'
+$metricsAreDisabledMessage = 'Warning: passed --sendmetrics, but metrics are disabled.'
+
+function Test-Metrics-Enabled() {
+ Param(
+ [Parameter(ValueFromRemainingArguments)]
+ [string[]]$TestArgs
+ )
+
+ $actualArgs = @('version', '--sendmetrics')
+ if ($TestArgs.Length -ne 0) {
+ $actualArgs += $TestArgs
+ }
+
+ $vcpkgOutput = Run-Vcpkg $actualArgs
+ if ($vcpkgOutput -contains $metricsAreDisabledMessage) {
+ Write-Host 'Metrics are disabled'
+ return $false
+ }
+
+ Write-Host 'Metrics are enabled'
+ return $true
+}
+
+# By default, metrics are enabled.
+Require-FileNotExists $metricsTagName
+if (-Not (Test-Metrics-Enabled)) {
+ throw "Metrics were not on by default."
+}
+
+if (Test-Metrics-Enabled '--disable-metrics') {
+ throw "Metrics were not disabled by switch."
+}
+
+$env:VCPKG_DISABLE_METRICS = 'ON'
+try {
+ if (Test-Metrics-Enabled) {
+ throw "Environment variable did not disable metrics."
+ }
+
+ if (-Not (Test-Metrics-Enabled '--no-disable-metrics')) {
+ throw "Environment variable to disable metrics could not be overridden by switch."
+ }
+} finally {
+ Remove-Item env:VCPKG_DISABLE_METRICS
+}
+
+# If the disable-metrics tag file exists, metrics are disabled even if attempted to be enabled on
+# the command line.
+Set-Content -Path $metricsTagName -Value ""
+try {
+ if (Test-Metrics-Enabled '--disable-metrics') {
+ throw "Metrics were not force-disabled by the disable-metrics tag file."
+ }
+}
+finally {
+ Remove-Item $metricsTagName
+}
diff --git a/scripts/azure-pipelines/end-to-end-tests-prelude.ps1 b/scripts/azure-pipelines/end-to-end-tests-prelude.ps1
index 0c675e9bf..1e340eff7 100644
--- a/scripts/azure-pipelines/end-to-end-tests-prelude.ps1
+++ b/scripts/azure-pipelines/end-to-end-tests-prelude.ps1
@@ -59,9 +59,17 @@ function Run-Vcpkg {
[Parameter(ValueFromRemainingArguments)]
[string[]]$TestArgs
)
- $Script:CurrentTest = "./vcpkg $($testArgs -join ' ')"
+
+ if ($IsWindows) {
+ $vcpkgName = 'vcpkg.exe'
+ } else {
+ $vcpkgName = 'vcpkg'
+ }
+
+ $Script:CurrentTest = "./$vcpkgName $($testArgs -join ' ')"
Write-Host $Script:CurrentTest
- ./vcpkg @testArgs
+ & "./$vcpkgName" @testArgs | Tee-Object -Variable 'ConsoleOutput'
+ return $ConsoleOutput
}
Refresh-TestRoot
diff --git a/scripts/bootstrap.ps1 b/scripts/bootstrap.ps1
index 67a4bbbef..018ba3f99 100644
--- a/scripts/bootstrap.ps1
+++ b/scripts/bootstrap.ps1
@@ -370,7 +370,6 @@ else
$arguments = (
"`"/p:VCPKG_VERSION=-unknownhash`"",
-"`"/p:DISABLE_METRICS=$disableMetricsValue`"",
"/p:Configuration=Release",
"/p:Platform=$platform",
"/p:PlatformToolset=$platformToolset",
@@ -413,8 +412,14 @@ if ($ec -ne 0)
Write-Host "`nBuilding vcpkg.exe... done.`n"
-if (-not $disableMetrics)
+if ($disableMetrics)
+{
+ Set-Content -Value "" -Path "$vcpkgRootDir\vcpkg.disable-metrics" -Force
+}
+elseif (-Not (Test-Path "$vcpkgRootDir\vcpkg.disable-metrics"))
{
+ # Note that we intentionally leave any existing vcpkg.disable-metrics; once a user has
+ # opted out they should stay opted out.
Write-Host @"
Telemetry
---------
diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh
index fa1a64622..ba76f4f63 100644
--- a/scripts/bootstrap.sh
+++ b/scripts/bootstrap.sh
@@ -280,13 +280,17 @@ buildDir="$vcpkgRootDir/toolsrc/build.rel"
rm -rf "$buildDir"
mkdir -p "$buildDir"
-(cd "$buildDir" && CXX="$CXX" "$cmakeExe" .. -DCMAKE_BUILD_TYPE=Release -G "Ninja" "-DCMAKE_MAKE_PROGRAM=$ninjaExe" "-DBUILD_TESTING=$vcpkgBuildTests" "-DVCPKG_DEVELOPMENT_WARNINGS=OFF" "-DVCPKG_DISABLE_METRICS=$vcpkgDisableMetrics" "-DVCPKG_ALLOW_APPLE_CLANG=$vcpkgAllowAppleClang") || exit 1
+(cd "$buildDir" && CXX="$CXX" "$cmakeExe" .. -DCMAKE_BUILD_TYPE=Release -G "Ninja" "-DCMAKE_MAKE_PROGRAM=$ninjaExe" "-DBUILD_TESTING=$vcpkgBuildTests" "-DVCPKG_DEVELOPMENT_WARNINGS=OFF" "-DVCPKG_ALLOW_APPLE_CLANG=$vcpkgAllowAppleClang") || exit 1
(cd "$buildDir" && "$cmakeExe" --build .) || exit 1
rm -rf "$vcpkgRootDir/vcpkg"
cp "$buildDir/vcpkg" "$vcpkgRootDir/"
-if ! [ "$vcpkgDisableMetrics" = "ON" ]; then
+if [ "$vcpkgDisableMetrics" = "ON" ]; then
+ touch "$vcpkgRootDir/vcpkg.disable-metrics"
+elif ! [ -f "$vcpkgRootDir/vcpkg.disable-metrics" ]; then
+ # Note that we intentionally leave any existing vcpkg.disable-metrics; once a user has
+ # opted out they should stay opted out.
cat <<EOF
Telemetry
---------