mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Improve submitted analytics data
- Use default `custom-prefix` label on macOS ARM (as `/usr/local` is not the default). - Add architecture (or Rosetta) to analytics event label. - Don't send minor versions on Big Sur. - Remove defunct `HOMEBREW_OSX_VERSION` reference.
This commit is contained in:
parent
dad7dc6a14
commit
8af4895479
@ -313,7 +313,6 @@ then
|
|||||||
HOMEBREW_SYSTEM="Macintosh"
|
HOMEBREW_SYSTEM="Macintosh"
|
||||||
[[ "$HOMEBREW_PROCESSOR" = "x86_64" ]] && HOMEBREW_PROCESSOR="Intel"
|
[[ "$HOMEBREW_PROCESSOR" = "x86_64" ]] && HOMEBREW_PROCESSOR="Intel"
|
||||||
HOMEBREW_MACOS_VERSION="$(/usr/bin/sw_vers -productVersion)"
|
HOMEBREW_MACOS_VERSION="$(/usr/bin/sw_vers -productVersion)"
|
||||||
HOMEBREW_OS_VERSION="macOS $HOMEBREW_MACOS_VERSION"
|
|
||||||
# Don't change this from Mac OS X to match what macOS itself does in Safari on 10.12
|
# Don't change this from Mac OS X to match what macOS itself does in Safari on 10.12
|
||||||
HOMEBREW_OS_USER_AGENT_VERSION="Mac OS X $HOMEBREW_MACOS_VERSION"
|
HOMEBREW_OS_USER_AGENT_VERSION="Mac OS X $HOMEBREW_MACOS_VERSION"
|
||||||
|
|
||||||
@ -321,6 +320,14 @@ then
|
|||||||
# shellcheck disable=SC2086,SC2183
|
# shellcheck disable=SC2086,SC2183
|
||||||
printf -v HOMEBREW_MACOS_VERSION_NUMERIC "%02d%02d%02d" ${HOMEBREW_MACOS_VERSION//./ }
|
printf -v HOMEBREW_MACOS_VERSION_NUMERIC "%02d%02d%02d" ${HOMEBREW_MACOS_VERSION//./ }
|
||||||
|
|
||||||
|
# Don't include minor versions for Big Sur and later.
|
||||||
|
if [[ "$HOMEBREW_MACOS_VERSION_NUMERIC" -gt "110000" ]]
|
||||||
|
then
|
||||||
|
HOMEBREW_OS_VERSION="macOS ${HOMEBREW_MACOS_VERSION%.*}"
|
||||||
|
else
|
||||||
|
HOMEBREW_OS_VERSION="macOS $HOMEBREW_MACOS_VERSION"
|
||||||
|
fi
|
||||||
|
|
||||||
# Refuse to run on pre-Yosemite
|
# Refuse to run on pre-Yosemite
|
||||||
if [[ "$HOMEBREW_MACOS_VERSION_NUMERIC" -lt "101000" ]]
|
if [[ "$HOMEBREW_MACOS_VERSION_NUMERIC" -lt "101000" ]]
|
||||||
then
|
then
|
||||||
|
@ -5,10 +5,24 @@ module Utils
|
|||||||
module Analytics
|
module Analytics
|
||||||
class << self
|
class << self
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def custom_prefix_label
|
def custom_prefix_label
|
||||||
|
return generic_custom_prefix_label if Hardware::CPU.arm?
|
||||||
|
|
||||||
"non-/usr/local"
|
"non-/usr/local"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(String) }
|
||||||
|
def arch_label
|
||||||
|
if Hardware::CPU.arm?
|
||||||
|
"ARM"
|
||||||
|
elsif Hardware::CPU.in_rosetta2?
|
||||||
|
"Rosetta"
|
||||||
|
else
|
||||||
|
""
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -31,7 +31,7 @@ module OS
|
|||||||
# This can be compared to numerics, strings, or symbols
|
# This can be compared to numerics, strings, or symbols
|
||||||
# using the standard Ruby Comparable methods.
|
# using the standard Ruby Comparable methods.
|
||||||
def full_version
|
def full_version
|
||||||
@full_version ||= Version.new((ENV["HOMEBREW_MACOS_VERSION"] || ENV["HOMEBREW_OSX_VERSION"]).chomp)
|
@full_version ||= Version.new((ENV["HOMEBREW_MACOS_VERSION"]).chomp)
|
||||||
end
|
end
|
||||||
|
|
||||||
def full_version=(version)
|
def full_version=(version)
|
||||||
|
@ -5,24 +5,24 @@ require "utils/analytics"
|
|||||||
require "formula_installer"
|
require "formula_installer"
|
||||||
|
|
||||||
describe Utils::Analytics do
|
describe Utils::Analytics do
|
||||||
describe "::os_prefix_ci" do
|
describe "::os_arch_prefix_ci" do
|
||||||
context "when os_prefix_ci is not set" do
|
context "when os_arch_prefix_ci is not set" do
|
||||||
before do
|
before do
|
||||||
described_class.clear_os_prefix_ci
|
described_class.clear_os_arch_prefix_ci
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is a custom prefix" do
|
it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is a custom prefix" do
|
||||||
allow(Homebrew).to receive(:default_prefix?).and_return(false)
|
allow(Homebrew).to receive(:default_prefix?).and_return(false)
|
||||||
expect(described_class.os_prefix_ci).to include("#{OS_VERSION}, #{described_class.custom_prefix_label}")
|
expect(described_class.os_arch_prefix_ci).to include("#{OS_VERSION}, #{described_class.custom_prefix_label}")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not include prefix when HOMEBREW_PREFIX is the default prefix" do
|
it "does not include prefix when HOMEBREW_PREFIX is the default prefix" do
|
||||||
expect(described_class.os_prefix_ci).not_to include(described_class.custom_prefix_label)
|
expect(described_class.os_arch_prefix_ci).not_to include(described_class.custom_prefix_label)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "includes CI when ENV['CI'] is set" do
|
it "includes CI when ENV['CI'] is set" do
|
||||||
ENV["CI"] = "true"
|
ENV["CI"] = "true"
|
||||||
expect(described_class.os_prefix_ci).to include("CI")
|
expect(described_class.os_arch_prefix_ci).to include("CI")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -62,7 +62,7 @@ module Utils
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def report_event(category, action, label = os_prefix_ci, value = nil)
|
def report_event(category, action, label = os_arch_prefix_ci, value = nil)
|
||||||
report(:event,
|
report(:event,
|
||||||
ec: category,
|
ec: category,
|
||||||
ea: action,
|
ea: action,
|
||||||
@ -198,19 +198,30 @@ module Utils
|
|||||||
def custom_prefix_label
|
def custom_prefix_label
|
||||||
"custom-prefix"
|
"custom-prefix"
|
||||||
end
|
end
|
||||||
|
alias generic_custom_prefix_label custom_prefix_label
|
||||||
|
|
||||||
def clear_os_prefix_ci
|
sig { returns(String) }
|
||||||
return unless instance_variable_defined?(:@os_prefix_ci)
|
def arch_label
|
||||||
|
if Hardware::CPU.arm?
|
||||||
remove_instance_variable(:@os_prefix_ci)
|
"ARM"
|
||||||
|
else
|
||||||
|
""
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def os_prefix_ci
|
def clear_os_arch_prefix_ci
|
||||||
@os_prefix_ci ||= begin
|
return unless instance_variable_defined?(:@os_arch_prefix_ci)
|
||||||
|
|
||||||
|
remove_instance_variable(:@os_arch_prefix_ci)
|
||||||
|
end
|
||||||
|
|
||||||
|
def os_arch_prefix_ci
|
||||||
|
@os_arch_prefix_ci ||= begin
|
||||||
os = OS_VERSION
|
os = OS_VERSION
|
||||||
|
arch = ", #{arch_label}" if arch_label.present?
|
||||||
prefix = ", #{custom_prefix_label}" unless Homebrew.default_prefix?
|
prefix = ", #{custom_prefix_label}" unless Homebrew.default_prefix?
|
||||||
ci = ", CI" if ENV["CI"]
|
ci = ", CI" if ENV["CI"]
|
||||||
"#{os}#{prefix}#{ci}"
|
"#{os}#{arch}#{prefix}#{ci}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user