Skip to content

Commit 3942bd2

Browse files
committed
chore: sync with microG unofficial installer
Signed-off-by: ale5000 <15793015+ale5000-git@users.noreply.github.com>
1 parent b55c615 commit 3942bd2

File tree

3 files changed

+164
-67
lines changed

3 files changed

+164
-67
lines changed

build.gradle

Lines changed: 158 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def moduleProps = providers.fileContents(layout.projectDirectory.file('zip-conte
2424
//def moduleProps = providers.properties(layout.projectDirectory.file('zip-content/module.prop'))
2525

2626
configure(project) {
27-
layout.buildDirectory = 'output'
2827
defaultTasks 'tasks'
2928

3029
ext {
@@ -40,37 +39,6 @@ configure(project) {
4039
}
4140
}
4241

43-
/* ===HEADER=== */
44-
45-
interface HeaderParams extends ValueSourceParameters {
46-
@Input Property<String> getProjectName()
47-
@Input Property<String> getVersion()
48-
@Input Property<String> getOsName()
49-
}
50-
51-
abstract class HeaderPrinter implements ValueSource<String, HeaderParams> {
52-
private static final log = Logging.getLogger(HeaderPrinter)
53-
54-
@Override String obtain() {
55-
log.lifecycle '=' * 36
56-
log.lifecycle "Project: ${parameters.projectName.get()}"
57-
log.lifecycle "Version: ${parameters.version.get()}"
58-
log.lifecycle "OS: ${parameters.osName.get()}"
59-
log.lifecycle '=' * 36
60-
''
61-
}
62-
}
63-
64-
def headerTrigger = providers.of(HeaderPrinter) {
65-
parameters.projectName.set project.name
66-
parameters.version.set ext.lazyVersion
67-
parameters.osName.set ext.lazyOsName
68-
}
69-
70-
gradle.taskGraph.whenReady {
71-
{ headerTrigger.get() }
72-
}
73-
7442
/* ===FUNCTIONS=== */
7543

7644
private Provider<String> getScriptExt() {
@@ -137,6 +105,28 @@ private Provider<String> getZipName(String variant = '*') {
137105
android.buildTypes.release.signingConfig android.signingConfigs.config
138106
}*/
139107

108+
/* ===CLASSES=== */
109+
110+
import groovy.transform.PackageScope
111+
112+
@PackageScope
113+
final class Bridge {
114+
private static MavenPublication mavenPub
115+
116+
private Bridge() {}
117+
118+
private static void init(Project project) {
119+
if(this.mavenPub == null) {
120+
this.mavenPub = project.publishing.publications.maven
121+
}
122+
}
123+
124+
@PackageScope
125+
static MavenPublication getMavenPub() {
126+
return this.mavenPub
127+
}
128+
}
129+
140130
/* ===BLOCKS=== */
141131

142132
base {
@@ -164,6 +154,8 @@ project.afterEvaluate {
164154
}
165155
}
166156
}
157+
158+
//Bridge.init(project)
167159
}
168160

169161
/* ===TASKS=== */
@@ -205,17 +197,18 @@ tasks.register('distClean') {
205197
tasks.register('buildOta', Exec) {
206198
group = '- Flashable ZIP'
207199
description = 'Build the flashable zip [Full edition].'
200+
outputs.cacheIf('Avoid caching large binary artifacts to save disk space and network bandwidth.') { false }
208201

209202
['LICENSES', 'conf', 'docs', 'lib', 'zip-content'].each { folder ->
210-
inputs.dir(layout.projectDirectory.dir(folder)).withPropertyName("inputDir_${folder}")
203+
inputs.dir(layout.projectDirectory.dir(folder)).withPropertyName("buildInputDir_${folder}")
211204
}
212205
inputs.files(
213206
layout.projectDirectory.dir('tools').asFileTree.matching { include '*.jar' },
214207
layout.projectDirectory.files('CHANGELOG.rst', 'build.sh'),
215208
layout.projectDirectory.asFileTree.matching { include 'LICENSE*.rst' }
216-
).withPropertyName('inputFiles')
209+
).withPropertyName('buildInputFiles')
217210

218-
outputs.file(layout.buildDirectory.file(getZipName('full')))
211+
outputs.file(layout.buildDirectory.file(getZipName('full'))).withPropertyName('buildOutputFileFull')
219212

220213
workingDir = layout.projectDirectory
221214
executable = "${-> layout.projectDirectory.file("build${getScriptExt().get()}") }"
@@ -233,17 +226,18 @@ tasks.register('buildOta', Exec) {
233226
tasks.register('buildOtaOSS', Exec) {
234227
group = '- Flashable ZIP'
235228
description = 'Build the flashable zip [OSS edition].'
229+
outputs.cacheIf('Avoid caching large binary artifacts to save disk space and network bandwidth.') { false }
236230

237231
['LICENSES', 'conf', 'docs', 'lib', 'zip-content'].each { folder ->
238-
inputs.dir(layout.projectDirectory.dir(folder)).withPropertyName("inputDir_${folder}")
232+
inputs.dir(layout.projectDirectory.dir(folder)).withPropertyName("buildInputDir_${folder}")
239233
}
240234
inputs.files(
241235
layout.projectDirectory.dir('tools').asFileTree.matching { include '*.jar' },
242236
layout.projectDirectory.files('CHANGELOG.rst', 'build.sh'),
243237
layout.projectDirectory.asFileTree.matching { include 'LICENSE*.rst' }
244-
).withPropertyName('inputFiles')
238+
).withPropertyName('buildInputFiles')
245239

246-
outputs.file(layout.buildDirectory.file(getZipName('oss')))
240+
outputs.file(layout.buildDirectory.file(getZipName('oss'))).withPropertyName('buildOutputFileOss')
247241

248242
workingDir = layout.projectDirectory
249243
executable = "${-> layout.projectDirectory.file("build${getScriptExt().get()}") }"
@@ -275,7 +269,7 @@ tasks.register('installTest', Exec) {
275269
description = 'Test the flashable zip in a simulated Android recovery environment on your PC.'
276270

277271
doNotTrackState('Force task execution by disabling up-to-date checks.')
278-
mustRunAfter build, buildOta, buildOtaOSS
272+
mustRunAfter buildOta, buildOtaOSS
279273

280274
doFirst {
281275
environment LIVE_SETUP_ALLOWED: 'false' /* Live setup doesn't work when executed through Gradle */
@@ -291,45 +285,144 @@ tasks.register('test') {
291285
}
292286

293287
tasks.named('wrapper') {
294-
gradleVersion = gradleVersionTarget
295-
distributionSha256Sum = gradleSha256Sum
288+
gradleVersion = "${-> targetGradleVersion}"
289+
distributionSha256Sum = "${-> targetGradleSha256Sum}"
296290

297291
doFirst {
298-
logger.lifecycle "Gradle: ${gradleVersionTarget}"
292+
logger.lifecycle 'Gradle wrapper update status:'
293+
logger.lifecycle "- Current version: ${-> gradle.gradleVersion}"
294+
logger.lifecycle "- Target version: ${-> targetGradleVersion}"
299295
}
300296
}
301297

302-
tasks.withType(PublishToMavenLocal).configureEach {
303-
notCompatibleWithConfigurationCache('Not yet compatible with CC.')
304-
// Ensure builds run before this task
305-
mustRunAfter 'build', 'buildOta', 'buildOtaOSS'
298+
/* === PUBLISHING === */
306299

307-
doFirst {
308-
def zipFiles = layout.buildDirectory.asFileTree.matching {
309-
include getZipName().get()
300+
final Closure<String> getMemoizedZipName = { getZipName().get() }.memoize()
301+
final Provider<FileTree> zipFilesTree = layout.buildDirectory.map { dir -> dir.asFileTree.matching { include getMemoizedZipName() } }
302+
303+
/*abstract class DynamicArtifactSource implements ValueSource<Integer, DynamicArtifactParams> {
304+
private static final List<String> artifactTypes = ['oss', 'full'].asImmutable()
305+
306+
interface DynamicArtifactParams extends ValueSourceParameters {
307+
@InputFiles ConfigurableFileCollection getZipFiles()
308+
}
309+
310+
@Override
311+
Integer obtain() {
312+
final HashSet<String> seen = []
313+
final MavenPublication mavenPub = Bridge.getMavenPub()
314+
parameters.zipFiles.files.each { foundFile ->
315+
String type = artifactTypes.find { foundFile.name.contains("-${it}-") } ?: { throw new GradleException("Publishing failed: File ${foundFile.name} is missing a valid build type.") }()
316+
if(!seen.add(type)) throw new GradleException("Publishing failed: The type '${type}' already exists.")
317+
mavenPub.artifact(foundFile) { extension = 'zip'; classifier = (type == 'oss' ? null : type); builtBy 'collectArtifacts' }
310318
}
319+
if(seen.isEmpty()) throw new GradleException("Publishing failed: No artifact found. Check if build tasks were executed.")
320+
seen.size()
321+
}
322+
}
323+
324+
final Provider<Integer> artifactsProcessor = providers.of(DynamicArtifactSource) {
325+
parameters.zipFiles.setFrom zipFilesTree
326+
}*/
327+
328+
Integer processArtifacts(parameters, mavenPub)
329+
{
330+
final List<String> artifactTypes = ['oss', 'full'].asImmutable()
331+
final HashSet<String> seen = []
332+
parameters.zipFiles.files.each { foundFile ->
333+
String type = artifactTypes.find { foundFile.name.contains("-${it}-") } ?: { throw new GradleException("Publishing failed: File ${foundFile.name} is missing a valid build type.") }()
334+
if(!seen.add(type)) throw new GradleException("Publishing failed: The type '${type}' already exists.")
335+
mavenPub.artifact(foundFile) { extension = 'zip'; classifier = (type == 'oss' ? null : type); builtBy 'collectArtifacts' }
336+
}
337+
if(seen.isEmpty()) throw new GradleException("Publishing failed: No artifact found. Check if build tasks were executed.")
338+
seen.size()
339+
}
340+
341+
tasks.register('collectArtifacts') {
342+
notCompatibleWithConfigurationCache('Dynamic artifact insertion is not compatible with Configuration Cache.')
343+
outputs.cacheIf('Task is collection-only; caching is disabled.') { false }
311344

312-
def count = zipFiles.size()
313-
if(count !in 1..2) {
314-
throw new GradleException("Publishing failed: Expected 1 or 2 artifacts, but found ${count}. Check if build tasks were executed.")
345+
mustRunAfter 'buildOta', 'buildOtaOSS'
346+
347+
inputs.files(zipFilesTree).withPropertyName('collectedZips')
348+
outputs.upToDateWhen { false }
349+
350+
/*doFirst {
351+
if(zipFilesTree.get().isEmpty()) {
352+
throw new GradleException("Publishing failed: No artifact found. Run build tasks first.")
315353
}
354+
}*/
316355

317-
// Add artifacts to the publication just before execution
318-
def mavenPub = project.publishing.publications.maven
319-
zipFiles.each { foundFile ->
320-
def isFull = foundFile.name.contains('-full-')
321-
def isOss = foundFile.name.contains('-oss-')
356+
doLast {
357+
//final Integer count = artifactsProcessor.get()
322358

323-
if(!isFull && !isOss) {
324-
throw new GradleException("Publishing failed: File ${foundFile.name} missing a valid build type.")
359+
final Map<String, Object> parameters = [
360+
zipFiles: objects.fileCollection().tap {
361+
setFrom( getZipName().map { name -> layout.buildDirectory.asFileTree.matching { include name } } )
325362
}
363+
].asImmutable()
364+
final Integer count = processArtifacts(parameters, publishing.publications.maven)
326365

327-
mavenPub.artifact(foundFile) {
328-
if(isFull) {
329-
classifier = 'full'
330-
}
331-
extension = 'zip'
332-
}
366+
logger.lifecycle "Successfully registered ${count} artifact(s)."
367+
}
368+
}
369+
370+
tasks.register('showPublishedArtifacts') {
371+
outputs.upToDateWhen { false }
372+
373+
def artifactData = provider {
374+
publishing.publications.collectMany { pub ->
375+
pub.artifacts?.collect { "Pub: ${pub.name} | File: ${it.file.name} | Ext: ${it.extension}${it.classifier ? " | Classifier: ${it.classifier}" : ""}" } ?: []
333376
}
334377
}
378+
379+
inputs.property('data', artifactData)
380+
381+
doLast {
382+
artifactData.get().each { logger.lifecycle it }
383+
}
384+
}
385+
386+
tasks.withType(GenerateMavenPom).configureEach {
387+
dependsOn 'collectArtifacts'
388+
}
389+
390+
[PublishToMavenRepository, PublishToMavenLocal].each { type ->
391+
tasks.withType(type).configureEach {
392+
dependsOn 'collectArtifacts'
393+
394+
finalizedBy 'showPublishedArtifacts'
395+
}
396+
}
397+
398+
/* ===HEADER=== */
399+
400+
abstract class HeaderPrinter implements ValueSource<Boolean, HeaderParams> {
401+
private static final log = Logging.getLogger(HeaderPrinter)
402+
403+
interface HeaderParams extends ValueSourceParameters {
404+
@Input Property<String> getProjectName()
405+
@Input Property<String> getVersion()
406+
@Input Property<String> getOsName()
407+
}
408+
409+
@Override
410+
Boolean obtain() {
411+
log.lifecycle '=' * 36
412+
log.lifecycle "Project: ${parameters.projectName.get()}"
413+
log.lifecycle "Version: ${parameters.version.get()}"
414+
log.lifecycle "OS: ${parameters.osName.get()}"
415+
log.lifecycle '=' * 36
416+
true
417+
}
418+
}
419+
420+
def headerTrigger = providers.of(HeaderPrinter) {
421+
parameters.projectName.set provider { project.name }
422+
parameters.version.set ext.lazyVersion
423+
parameters.osName.set ext.lazyOsName
424+
}
425+
426+
gradle.taskGraph.whenReady {
427+
{ headerTrigger.get() }
335428
}

dependencies.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
ext {
55
/* ===GRADLE=== (https://gradle.org/release-checksums/) */
6-
gradleVersionTarget = '8.11.1'
7-
gradleSha256Sum = 'f397b287023acdba1e9f6fc5ea72d22dd63669d59ed4a289a29b1a76eee151c6'
6+
targetGradleVersion = '8.11.1'
7+
targetGradleSha256Sum = 'f397b287023acdba1e9f6fc5ea72d22dd63669d59ed4a289a29b1a76eee151c6'
88

99
/* ===DEPENDENCIES=== */
1010
develocityPluginVersion = '4.4.0'

settings.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ plugins { id 'com.gradle.develocity' }
1010
1111
rootProject.name = 'Google sync add-on'
1212
13+
gradle.rootProject { project ->
14+
project.layout.buildDirectory.set project.layout.projectDirectory.dir('output')
15+
}
16+
1317
// Initialize the provider early to ensure compatibility with the Gradle configuration cache
1418
providers.environmentVariable('UPLOAD_BUILD_SCAN').with { uploadBuildScan ->
1519
develocity.buildScan {

0 commit comments

Comments
 (0)