@@ -5,13 +5,16 @@
CUDA_VERSION = "13.1".freeze
CUDA_FORMULA = "cuda@#{CUDA_VERSION}".freeze
COVERAGE_BUILDPATH_FILE = "coverage-buildpath.txt".freeze
COVERAGE_LCOV = "coverage.lcov".freeze
COVERAGE_PROFDATA = "coverage.profdata".freeze
COVERAGE_XML = "coverage.xml".freeze
GCOV_PREFIX_STRIP_FILE = "gcov-prefix-strip.txt".freeze
GCC_VERSION = "14".freeze
GCC_FORMULA = "gcc@#{GCC_VERSION}".freeze
LLVM_PROFILE_FILE_ENV = "LLVM_PROFILE_FILE".freeze
TEST_BINARY = "test_sunshine".freeze
TEST_RESULTS_XML = "tests/test_results.xml".freeze
IS_UPSTREAM_REPO = ENV.fetch("GITHUB_REPOSITORY", "") == "LizardByte/Sunshine"
desc "@PROJECT_DESCRIPTION@"
@@ -46,6 +49,9 @@
option "with-docs", "Enable docs build"
option "with-static-boost", "Enable static link of Boost libraries"
option "without-static-boost", "Disable static link of Boost libraries" # default option
# Keep coverage instrumentation in the test binary after test-bot rebuilds the formula from its bottle.
skip_clean "bin/#{TEST_BINARY}" if IS_UPSTREAM_REPO
depends_on "cmake" => :build
depends_on "doxygen" => :build if build.with? "docs"
@@ -180,7 +186,17 @@
def add_test_args(args)
if IS_UPSTREAM_REPO
args << "-DBUILD_TESTS=ON"
args << "-DSUNSHINE_LLVM_COVERAGE=ON" if OS.mac?
test_runtime = opt_libexec/"tests"
args << "-DSUNSHINE_TEST_SOURCE_DIR=#{test_runtime}"
args << "-DSUNSHINE_TEST_RUNTIME_DIR=#{test_runtime}"
coverage_arg = if OS.mac?
"-DSUNSHINE_LLVM_COVERAGE=ON"
else
# gcovr writes intermediate files next to the mapped sources, so use Homebrew's writable temp tree.
coverage_runtime = HOMEBREW_TEMP/"coverage"
"-DSUNSHINE_TEST_GCOV_ROOT=#{coverage_runtime}"
end
args << coverage_arg
ohai "Building tests: enabled"
else
args << "-DBUILD_TESTS=OFF"
@@ -260,7 +276,7 @@
def run_test_suite(artifact_dir)
mkdir_p artifact_dir/"tests"
test_results = artifact_dir/"tests/test_results.xml"
test_results = artifact_dir/TEST_RESULTS_XML
if OS.mac?
with_llvm_profile_file(artifact_dir) do
@@ -345,7 +361,7 @@
def generate_gcov_coverage_report(coverage_report, coverage_buildpath)
cd "#{coverage_buildpath}/build" do
system "gcovr", ".",
system "gcovr", "tests/CMakeFiles/#{TEST_BINARY}.dir/__/src",
"-r", "../src",
*coverage_gcov_options,
*coverage_common_options(coverage_report)
@@ -355,9 +371,8 @@
end
def coverage_source_prefixes(coverage_buildpath)
coverage_buildpath = Pathname.new(coverage_buildpath.to_s)
paths = [coverage_buildpath.to_s]
paths = [
coverage_buildpath.to_s,
Pathname.new(coverage_buildpath.to_s).realpath.to_s,
]
paths << coverage_buildpath.realpath.to_s if coverage_buildpath.exist?
paths.uniq.map { |path| "#{path}/src/" }
end
@@ -405,8 +420,9 @@
return unless IS_UPSTREAM_REPO
return unless artifact_dir
run_test_suite artifact_dir
generate_coverage_report artifact_dir, buildpath
coverage_buildpath = OS.mac? ? buildpath.realpath : HOMEBREW_TEMP/"coverage"
mkdir_p artifact_dir
(artifact_dir/COVERAGE_BUILDPATH_FILE).write coverage_buildpath.to_s
end
def build_cmake_args
@@ -428,7 +444,29 @@
end
def install_platform_specific_files
if IS_UPSTREAM_REPO
bin.install "build/tests/#{TEST_BINARY}"
test_runtime = libexec/"tests"
%w[docs src src_assets test_assets].each do |directory|
test_runtime.install "build/tests/#{directory}"
end
test_runtime.install "sunshine.png"
bin.install "build/tests/#{TEST_BINARY}" if IS_UPSTREAM_REPO
(test_runtime/"tests/unit").install "tests/unit/test_video.cpp"
if OS.linux?
coverage_runtime = test_runtime/"coverage"
coverage_runtime.install "src"
(test_runtime/GCOV_PREFIX_STRIP_FILE).write "#{buildpath.each_filename.count}\n"
coverage_notes = buildpath.glob("build/**/*.gcno")
odie "No gcov notes were created" if coverage_notes.empty?
coverage_notes.each do |coverage_note|
relative_note = coverage_note.relative_path_from(buildpath)
(coverage_runtime/relative_note.dirname).install coverage_note
end
end
end
# codesign the binary on intel macs
system "codesign", "-s", "-", "--force", "--deep", bin/"sunshine" if OS.mac? && Hardware::CPU.intel?
@@ -484,8 +522,27 @@
if IS_UPSTREAM_REPO
artifact_dir = release_homebrew_testpath
if artifact_dir
coverage_buildpath = artifact_dir/COVERAGE_BUILDPATH_FILE
test_runtime = opt_libexec/"tests"
assert_path_exists coverage_buildpath
assert_path_exists bin/TEST_BINARY
assert_path_exists test_runtime/"docs/getting_started.md"
assert_path_exists test_runtime/"src/config.cpp"
assert_path_exists test_runtime/"src_assets/common/assets/web/public/assets/locale/en.json"
assert_path_exists test_runtime/"test_assets/web/images/logo-sunshine.svg"
assert_path_exists test_runtime/"tests/unit/test_video.cpp"
if OS.linux?
assert_path_exists test_runtime/"coverage/src/config.cpp"
assert_path_exists test_runtime/GCOV_PREFIX_STRIP_FILE
source_notes = test_runtime.glob("coverage/build/tests/CMakeFiles/#{TEST_BINARY}.dir/__/src/**/*.gcno")
assert_path_exists artifact_dir/"tests/test_results.xml"
assert_path_exists coverage_report_path(artifact_dir)
assert source_notes.any?, "No installed source gcov notes were found"
end
if (artifact_dir/TEST_RESULTS_XML).exist?
assert_path_exists artifact_dir/TEST_RESULTS_XML
generate_coverage_report artifact_dir, coverage_buildpath.read.strip
assert_path_exists coverage_report_path(artifact_dir)
end
elsif ENV.fetch("HOMEBREW_BOTTLE_BUILD", "false") != "true"
run_test_suite testpath
generate_coverage_report testpath, ENV.fetch("HOMEBREW_BUILDPATH", "")
@@ -526,6 +583,19 @@
end_of_record
LCOV
assert_equal expected_lcov, lcov_for_source_files(lcov, testpath)
missing_buildpath = testpath/"missing-buildpath"
missing_path_lcov = <<~LCOV
SF:#{missing_buildpath}/src/missing.cpp
DA:1,1
end_of_record
LCOV
expected_missing_path_lcov = <<~LCOV
SF:src/missing.cpp
DA:1,1
end_of_record
LCOV
assert_equal expected_missing_path_lcov, lcov_for_source_files(missing_path_lcov, missing_buildpath)
end
end
end