-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskia_build.ps1
135 lines (97 loc) · 4.82 KB
/
skia_build.ps1
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
$cur_dir = $PSScriptRoot
$ver = 'm106' # skia 版本
$full_mode = $true # 是否编译完整版本,带 skia shaper 和 pdf 支持
$enable_pdf = $(If ($full_mode) { "true" } Else { "false" })
$ver_name = "1.$($ver.Substring(1)).1"
$ver_code = "$($ver.Substring(1))01"
$depot_dir = "${cur_dir}/depot_tools"
$skia_args_1 = 'is_official_build=true is_debug=false skia_use_vulkan=true ndk_api=26 '
$skia_args_2 = 'skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false '
$skia_args_3 = 'skia_use_expat=true skia_use_system_expat=false skia_use_x11=false skia_use_dng_sdk=false skia_use_harfbuzz=true skia_use_system_harfbuzz=false '
$skia_args_4 = 'skia_use_system_freetype2=false skia_enable_fontmgr_android=true skia_gl_standard=\"gles\" '
$skia_args_5 = 'skia_use_icu=true skia_use_system_icu=false skia_use_wuffs=true '
$skia_args_pdf = "skia_use_sfntly=$enable_pdf skia_pdf_subset_harfbuzz=$enable_pdf skia_enable_pdf=$enable_pdf "
$skia_args_ndk = "ndk=\`"$($args[0])\`""
$skia_args_ext = 'skia_enable_skshaper=true skia_enable_skparagraph=true'
$skia_args = "${skia_args_1}${skia_args_2}${skia_args_3}${skia_args_4}${skia_args_5}${skia_args_pdf} ${skia_args_ndk}"
$skia_args = $(If ($full_mode) { "${skia_args} ${skia_args_ext}" } Else { $skia_args })
function Write-HashFile {
Param ($path, $algorithm)
$hash = Get-FileHash $path -Algorithm $algorithm
$name = ($algorithm).ToLower()
$hash_code = ($hash.Hash).ToLower()
# PowerShell 6+
# $hash_code | Out-File "${path}.$name" -Force -NoNewline -Encoding utf8NoBOM
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
[System.IO.File]::WriteAllText("${path}.$name", $hash_code, $Utf8NoBomEncoding)
}
Write-Output "检查环境..."
If (-not (Test-Path -Path $depot_dir)) {
Write-Output "下载编译工具..."
git clone 'https://chromium.googlesource.com/chromium/tools/depot_tools.git'
}
If (-not (Test-Path -Path "${cur_dir}/skia")) {
Write-Output "下载 Skia ..."
git clone -b chrome/$ver 'https://skia.googlesource.com/skia.git'
}
$env:Path += ";${cur_dir}/depot_tools"
Set-Location "${cur_dir}/skia"
Write-Output "检查并同步依赖..."
python tools/git-sync-deps
Write-Output "准备构建arm64位组件..."
gn gen out/arm64-v8a --args="${skia_args} target_cpu=\`"arm64\`""
Write-Output "开始构建arm64位组件"
ninja -C out/arm64-v8a
If ($LASTEXITCODE -ne 0) { Throw "Build Skia Failed." }
Write-Output "准备构建x86_64位组件..."
gn gen out/x86_64 --args="${skia_args} target_cpu=\`"x64\`""
Write-Output "开始构建x86_64位组件"
ninja -C out/x86_64
If ($LASTEXITCODE -ne 0) { Throw "Build Skia Failed." }
# 创建文件夹参数和库名
$out_dir = "${cur_dir}/skia/out/"
$output_dir = "${cur_dir}/skia-$ver_name"
$output_lib = "${output_dir}/prefab/modules/skia/libs"
$output_header = "${output_dir}/prefab/modules/skia/include"
$maven_dir = "${cur_dir}/out/$ver_name"
$lib_skia = "libskia.a"
Write-Output "开始整合库..."
Set-Location $cur_dir
If (-not (Test-Path -Path $output_dir)) {
Copy-Item -Path "$cur_dir/prefab/skia-VERSION" -Destination "$output_dir" -Recurse
$json_path = "$output_dir/prefab/prefab.json"
(Get-Content $json_path).replace("VERSION", $ver_name) | Set-Content $json_path
$xml_path = "$output_dir/AndroidManifest.xml"
(Get-Content $xml_path).replace("VER_NAME", $ver_name).replace("VER_CODE", $ver_code) | Set-Content $xml_path
}
If (-not (Test-Path -Path $output_header)) {
Copy-Item -Force -Recurse "${cur_dir}/skia/include" "$output_header/include"
$image_priv = "$output_header/include/core/SkImagePriv.h"
Copy-Item "${cur_dir}/skia/src/core/SkImagePriv.h" $image_priv
}
$abis = @("x86_64", "arm64-v8a")
Foreach ($abi in $abis) {
Write-Output "Copying the ${abi} library"
$destination = "$output_lib/android.$abi"
Copy-Item -Force "${out_dir}$abi/$lib_skia" $destination
If ($LASTEXITCODE -ne 0) { Throw "Copy Library Failed." }
}
Write-Output "构建AAR..."
# Compress-Archive -Path $output_dir/* -DestinationPath skia.zip -Force
# Move-Item "skia.zip" "skia-${ver_name}.aar" -Force
jar cfM skia-${ver_name}.aar -C $output_dir ./
Write-Output "构建完成。"
Write-Output "构建文件..."
If (-not (Test-Path -Path $maven_dir)) {
New-Item $maven_dir -Type Directory
}
$pom_path = "${maven_dir}/skia-${ver_name}.pom"
$aar_path = "${maven_dir}/skia-${ver_name}.aar"
Move-Item -Force "${cur_dir}/skia-${ver_name}.aar" $aar_path
Copy-Item -Force "${cur_dir}/skia.pom" $pom_path
(Get-Content $pom_path).replace("VER_NAME", $ver_name) | Set-Content $pom_path
Write-HashFile -Path $aar_path -Algorithm SHA1
Write-HashFile -Path $aar_path -Algorithm MD5
Write-HashFile -Path $pom_path -Algorithm SHA1
Write-HashFile -Path $pom_path -Algorithm MD5
Write-Output "构建完成。"