Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
146 lines (125 loc) · 7.55 KB
/
Copy pathMakefile
File metadata and controls
146 lines (125 loc) · 7.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
SHELL := /bin/bash
SOLUTION := PdfiumRaster.slnx
PROJECT := src/PdfiumRaster/PdfiumRaster.csproj
CONFIGURATION := Release
ARTIFACTS_DIR := artifacts
PACKAGE_VERSION := $(shell dotnet msbuild $(PROJECT) -getProperty:PackageVersion)
PACKAGE := $(ARTIFACTS_DIR)/PdfiumRaster.$(PACKAGE_VERSION).nupkg
COVERAGE_DIR := $(ARTIFACTS_DIR)/coverage
COVERAGE_MIN_LINE_RATE := 0.80
.PHONY: help restore build test test-local coverage pack inspect-package smoke-package benchmark benchmark-compare benchmark-session benchmark-encoding benchmark-dispatcher benchmark-bmp benchmark-pipeline benchmark-native-buffer benchmark-all-pages release-check clean
help:
@printf '%s\n' \
'Available targets:' \
' make restore Restore NuGet packages' \
' make build Build the solution in Release mode' \
' make test Run the test suite, excluding local-only tests' \
' make test-local Run local-only tests that use ignored assets' \
' make coverage Run tests and enforce the minimum line coverage' \
' make pack Create NuGet and symbol packages' \
' make inspect-package List package contents and nuspec metadata' \
' make smoke-package Install the local package in a fresh app and render a page' \
' make benchmark Run BenchmarkDotNet performance benchmarks' \
' make benchmark-compare Compare PdfiumRaster with PDFiumCore' \
' make benchmark-session Compare legacy and reusable session rendering' \
' make benchmark-encoding Compare PNG compression levels' \
' make benchmark-dispatcher Compare sequential and concurrent dispatcher batches' \
' make benchmark-bmp Compare row-based and contiguous BMP output' \
' make benchmark-pipeline Compare sequential and pipelined document export' \
' make benchmark-native-buffer Compare managed and PDFium-owned save buffers' \
' make benchmark-all-pages PDF=<path> Measure every page with managed and native buffers' \
' make release-check Run tests, pack, inspect, and package smoke test' \
' make clean Remove build and package outputs'
restore:
dotnet restore $(SOLUTION) --locked-mode
build:
dotnet build $(SOLUTION) -c $(CONFIGURATION) --no-restore
test:
dotnet test $(SOLUTION) --filter "Category!=Local"
test-local:
dotnet test $(SOLUTION) --filter "Category=Local"
coverage: restore
@set -euo pipefail; \
coverage_run_dir="$(COVERAGE_DIR)/$$(date +%Y%m%d%H%M%S)"; \
dotnet test tests/PdfiumRaster.Tests/PdfiumRaster.Tests.csproj -c $(CONFIGURATION) --no-restore --filter "Category!=Local" --collect:"XPlat Code Coverage" --results-directory "$$coverage_run_dir" -p:CoverageBuild=true; \
coverage_file="$$(find "$$coverage_run_dir" -type f -name coverage.cobertura.xml | head -n 1)"; \
if [[ -z "$$coverage_file" ]]; then printf '%s\n' 'Coverage report was not produced.' >&2; exit 1; fi; \
line_rate="$$(sed -n 's/.*line-rate="\([^"]*\)".*/\1/p' "$$coverage_file" | head -n 1)"; \
if [[ -z "$$line_rate" ]]; then printf '%s\n' 'Coverage report does not contain a line rate.' >&2; exit 1; fi; \
awk -v actual="$$line_rate" -v minimum="$(COVERAGE_MIN_LINE_RATE)" 'BEGIN { printf "Line coverage: %.2f%% (minimum %.2f%%)\n", actual * 100, minimum * 100; exit actual < minimum }'
pack:
dotnet pack $(PROJECT) -c $(CONFIGURATION) -o $(ARTIFACTS_DIR)
inspect-package: $(PACKAGE)
unzip -l $(PACKAGE)
unzip -p $(PACKAGE) PdfiumRaster.nuspec
smoke-package: $(PACKAGE)
set -euo pipefail; \
repo="$$(pwd -W 2>/dev/null || pwd)"; \
tmpdir="$$(mktemp -d)"; \
dotnet new console -n PdfiumRasterSmoke -o "$$tmpdir/PdfiumRasterSmoke" --framework net10.0 >/dev/null; \
cd "$$tmpdir/PdfiumRasterSmoke"; \
printf '%s\n' \
'<?xml version="1.0" encoding="utf-8"?>' \
'<configuration>' \
' <packageSources>' \
' <clear />' \
" <add key=\"local\" value=\"$$repo/$(ARTIFACTS_DIR)\" />" \
' <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />' \
' </packageSources>' \
' <config>' \
' <add key="globalPackagesFolder" value=".packages" />' \
' </config>' \
'</configuration>' > NuGet.config; \
dotnet add package PdfiumRaster --version $(PACKAGE_VERSION) >/dev/null; \
cp "$$repo/tests/PdfiumRaster.Tests/TestAssets/axf-annotation-1.pdf" ./input.pdf; \
printf '%s\n' \
'using PdfiumRaster;' \
'' \
'PdfImageConverter.SavePng("input.pdf", pageNumber: 1, "page.png");' \
'using var dispatcher = new PdfRenderDispatcher();' \
'await dispatcher.SavePageAsync("input.pdf", pageIndex: 0, "page-async.png", new PdfImageConversionOptions' \
'{' \
' Render = PdfPageRenderOptions.ScreenPreview,' \
' Format = PdfImageOutputFormat.Png,' \
' Encoding = PdfImageEncodingOptions.Fast,' \
'});' \
'await dispatcher.CompleteAsync();' \
'' \
'if (!File.Exists("page.png") || new FileInfo("page.png").Length == 0 ||' \
' !File.Exists("page-async.png") || new FileInfo("page-async.png").Length == 0)' \
'{' \
' throw new InvalidOperationException("Smoke test did not generate both page images.");' \
'}' > Program.cs; \
dotnet run --configuration Release
benchmark:
dotnet run -c Release --project benchmarks/PdfiumRaster.Benchmarks/PdfiumRaster.Benchmarks.csproj -- --artifacts BenchmarkDotNet.Artifacts --filter '*'
benchmark-compare:
dotnet run -c Release --project benchmarks/PdfiumRaster.Benchmarks/PdfiumRaster.Benchmarks.csproj -- --artifacts BenchmarkDotNet.Artifacts --filter '*PdfiumCore*ComparisonBenchmarks*'
benchmark-session:
dotnet run -c Release --project benchmarks/PdfiumRaster.Benchmarks/PdfiumRaster.Benchmarks.csproj -- --artifacts BenchmarkDotNet.Artifacts --filter '*PdfRenderSessionBenchmarks*'
benchmark-encoding:
dotnet run -c Release --project benchmarks/PdfiumRaster.Benchmarks/PdfiumRaster.Benchmarks.csproj -- --artifacts BenchmarkDotNet.Artifacts --filter '*PngEncodingBenchmarks*'
benchmark-dispatcher:
dotnet run -c Release --project benchmarks/PdfiumRaster.Benchmarks/PdfiumRaster.Benchmarks.csproj -- --artifacts BenchmarkDotNet.Artifacts --filter '*PdfRenderDispatcher*'
benchmark-bmp:
dotnet run -c Release --project benchmarks/PdfiumRaster.Benchmarks/PdfiumRaster.Benchmarks.csproj -- --artifacts BenchmarkDotNet.Artifacts --filter '*BmpWriterBenchmarks*'
benchmark-pipeline:
dotnet run -c Release --project benchmarks/PdfiumRaster.Benchmarks/PdfiumRaster.Benchmarks.csproj -- --artifacts BenchmarkDotNet.Artifacts --filter '*PdfDocumentPipelineBenchmarks*'
benchmark-native-buffer:
dotnet run -c Release --project benchmarks/PdfiumRaster.Benchmarks/PdfiumRaster.Benchmarks.csproj -- --artifacts BenchmarkDotNet.Artifacts --filter '*PdfNativeSaveBufferBenchmarks*'
benchmark-all-pages:
@if [[ -z "$(PDF)" ]]; then echo 'Usage: make benchmark-all-pages PDF=<pdf-path>' >&2; exit 2; fi
dotnet build benchmarks/PdfiumRaster.Benchmarks/PdfiumRaster.Benchmarks.csproj -c Release
@printf '%s\n' 'mode,dpi,format,pages,elapsed_ms,encoded_bytes,total_pixel_bytes,max_page_buffer_bytes,managed_allocated_bytes,peak_working_set_delta_bytes,gen0_collections,gen1_collections,gen2_collections'
@for dpi in 96 144 300; do \
for format in Bmp Png Jpeg Webp; do \
for mode in native managed; do \
dotnet benchmarks/PdfiumRaster.Benchmarks/bin/Release/net10.0/PdfiumRaster.Benchmarks.dll \
--all-pages-measure "$(PDF)" "$$mode" "$$dpi" "$$format"; \
done; \
done; \
done
release-check: test coverage pack inspect-package smoke-package
clean:
dotnet clean $(SOLUTION)
rm -rf $(ARTIFACTS_DIR) BenchmarkDotNet.Artifacts benchmarks/PdfiumRaster.Benchmarks/bin benchmarks/PdfiumRaster.Benchmarks/obj src/PdfiumRaster/bin src/PdfiumRaster/obj tests/PdfiumRaster.Tests/bin tests/PdfiumRaster.Tests/obj