-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild-ModulePackage.ps1
More file actions
153 lines (128 loc) · 5.68 KB
/
Build-ModulePackage.ps1
File metadata and controls
153 lines (128 loc) · 5.68 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
147
148
149
150
151
152
153
#!/usr/bin/env pwsh
# Copyright (c) 2025 Nicholas Bissell (TheFreeman193) MIT License: https://spdx.org/licenses/MIT.html
using namespace System.IO
using namespace System.Management.Automation
using namespace System.Collections.Generic
using namespace System.Text
[CmdletBinding()]
param(
[Parameter(Mandatory, ValueFromPipeline)]
[ValidateScript({ (Test-Path $_ -PathType Container) -and (Split-Path $_ -Leaf) -match 'SDK\d+_NDK\d+' })]
[string]$SourceDir,
[string]$OutDir = $(Join-Path $PSScriptRoot 'out'),
[string]$BuildSuffix = '',
[switch]$KeepStageDir
)
begin {
$ShouldContinue = $false
$NdkDataFile = Join-Path $PSScriptRoot 'NDKData.psd1'
if (-not (Test-Path $NdkDataFile -PathType Leaf)) {
$Err = [ErrorRecord]::new([FileNotFoundException]::new("NDK version map file '$NdkDataFile' not found."), 'FileNotFound', 'ObjectNotFound', $NdkDataFile)
$PSCmdlet.WriteError($Err)
return
}
$NdkData = Import-PowerShellDataFile $NdkDataFile
$NdkSupportedSdkMap = $NdkData.NDK_SDK
$SdkAndroidVersionMap = $NdkData.SDK_VERSION
$DelList = [List[string]]::new()
$ShouldContinue = $true
}
process {
if (-not $ShouldContinue) { return }
$SourceLeaf = Split-Path $SourceDir -Leaf
if ($SourceLeaf -notmatch 'SDK\d+_NDK(\d+)') { return }
$NDK = $Matches[1] -as [int]
$MinMax = $NdkSupportedSdkMap[$NDK] | Measure-Object -Maximum -Minimum
$Min = $MinMax.Minimum -as [int]
$Max = $MinMax.Maximum -as [int]
$FirstVer = $SdkAndroidVersionMap[$Min]
$LastVer = $SdkAndroidVersionMap[$Max]
$ModulePropFile = Join-Path (Split-Path $OutDir) 'module_template/module.prop'
$CustomiseScriptFile = Join-Path (Split-Path $OutDir) 'module_template/customize.sh'
$InstallScripts = Join-Path (Split-Path $OutDir) 'module_template/META-INF'
$ModuleProps = Get-Content $ModulePropFile -Raw | ConvertFrom-StringData
if (-not $?) { return }
if (-not [string]::IsNullOrWhiteSpace($BuildSuffix)) {
$ModuleProps.id = $ModuleProps.id, $BuildSuffix -join '-'
$ModuleProps.updateJson = $ModuleProps.updateJson -replace '\.json$', "-$BuildSuffix.json"
}
Write-Host -fo White "Packaging module for SQLite $($ModuleProps.version) SDK $FirstVer-$LastVer"
$StageDir = Join-Path $OutDir (New-Guid).Guid
$null = New-Item -ItemType Directory $StageDir
if (-not $?) { return }
$PSCmdlet.WriteVerbose("Staging dir: '$StageDir', Delete after: $(-not $KeepStageDir)")
Write-Host -fo White ' Create customize.sh script...'
$CustomiseScript = (Get-Content $CustomiseScriptFile -Raw) -f
$Min, $Max, "Android $FirstVer", "Android $LastVer", $ModuleProps.name, $ModuleProps.id
if (-not $?) { return }
Set-Content (Join-Path $StageDir 'customize.sh') $CustomiseScript -NoNewline
if (-not $?) { return }
Write-Host -fo White ' Create module.prop metadata...'
$ModulePropTarget = Join-Path $StageDir 'module.prop'
Set-Content $ModulePropTarget -Value @"
id=$($ModuleProps.id)
name=$($ModuleProps.name)
version=$($ModuleProps.version)
versionCode=$($ModuleProps.versionCode)
author=$($ModuleProps.author)
description=$($ModuleProps.description)
updateJson=$($ModuleProps.updateJson)
"@
if (-not $?) { return }
Write-Host -fo White ' Copy module installer scripts...'
Copy-Item $InstallScripts $StageDir -Recurse
if (-not $?) { return }
Write-Host -fo White ' Copy binaries...'
$BinDir = Join-Path $StageDir 'bin'
$null = New-Item -ItemType Directory $BinDir
if (-not $?) { return }
Get-ChildItem $SourceDir -Directory | Copy-Item -Destination $BinDir -Recurse
if (-not $?) { return }
Write-Host -fo White ' Create module archive...'
$ArchivePath = Join-Path $OutDir "SQLite3-$($ModuleProps.version)-Android-$FirstVer-To-$LastVer.zip"
Compress-Archive -Path "$StageDir/*" -DestinationPath $ArchivePath -CompressionLevel Optimal -Update
if (-not $?) { return }
if (-not $KeepStageDir) { $DelList.Add($StageDir) }
Write-Host -fo White " Module archive: $ArchivePath"
Write-Host -fo Green ' Success.'
}
end {
foreach ($Path in $DelList) {
if (-not [string]::IsNullOrWhiteSpace($Path) -and (Test-Path $Path)) {
Remove-Item $Path -Force -Recurse
}
}
}
<#
.SYNOPSIS
Creates SQLite3 Android modules from build artifacts
.DESCRIPTION
Creates SQLite3 Android module archives that can be installed with Magisk, KSU, or APatch manager.
.NOTES
This script determines the NDK and SDK versions using the directory name from $SourceDir. You should therefore
ensure that the artifact root name is in the form 'SDKx_NDKy' and is structured as follows:
SDKx_NDKy
arm64-v8a
sqlite3
armeabi-v7a
sqlite3
x86
sqlite3
...
.PARAMETER SourceDir
Specifies the location of the build artifacts produced by Build-SQLite.ps1.
This always ends in the format SKDx_NDKy.
.PARAMETER OutDir
Specifies where to save the complete module archive. Defaults to ./out relative to the script.
.PARAMETER KeepStageDir
Prevents the script from deleting the staging directory where module files are copied before compression.
Staging dirs are always a GUID/UUID e.g. 'a96d3ea2-b602-45f3-af67-d294a7871255'
.PARAMETER BuildSuffix
Changes the module updateJson URL target and module ID to include a suffix.
.LINK
https://github.com/TheFreeman193/sqlite3-android-module/blob/main/README.md
.EXAMPLE
./Build-ModulePackage.ps1 -SourceDir ./out/SDK35_NDK29
Creates an installable module ZIP archive from the build output stored in ./out/SDK35_NDK29. The resulting
module will be named "SQLite3-<version>-Android-5.0-To-16.zip".
#>