Skip to content

Commit eb4eee9

Browse files
author
Mihail Slavchev
committed
use custom cache for static binding generator
1 parent d81045c commit eb4eee9

3 files changed

Lines changed: 81 additions & 66 deletions

File tree

build/project-template-gradle/build-tools/android-static-binding-generator/build.gradle

Lines changed: 71 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,88 +4,95 @@
44

55
def isWinOs = System.properties['os.name'].toLowerCase().contains('windows')
66

7-
def bgRootDir = "$rootDir/build-tools/android-static-binding-generator"
8-
def astParserDir = "$bgRootDir/ast-parser"
9-
def interfaceNamesFilePath = "$bgRootDir/interfaces-names.txt"
10-
def bindingsFilePath = "$bgRootDir/bindings.txt"
11-
def cachedJarsFilePath = "$bgRootDir/cached.dat"
7+
def astParserDir = "$projectDir/ast-parser"
8+
def interfaceNamesFilePath = "$projectDir/interfaces-names.txt"
9+
def bindingsFilePath = "$projectDir/bindings.txt"
10+
def cachedJarsFilePath = "$projectDir/cached.txt"
1211

13-
def absoluteOutDir = "$rootDir/$project.outDir"
14-
def absoluteJsCodeDir = "$rootDir/$project.jsCodeDir"
12+
def shouldRun = true
13+
def absoluteOutDir = project.outDir
14+
def absoluteJsCodeDir = project.jsCodeDir
1515

1616
// depends on passed jars and generated interface-names
17-
task generateInterfaceNamesList(type: JavaExec) {
18-
def cachedJars = new File(cachedJarsFilePath)
19-
20-
inputs.file(cachedJars)
21-
outputs.files(interfaceNamesFilePath)
22-
17+
task generateInterfaceNamesList() {
2318
doFirst {
24-
main "-jar"
25-
26-
def jarsAsStr = rootProject.jarFiles.toString();
27-
def jarsArr = jarsAsStr.replaceAll(/[\[\]]/, "").split(", ")
28-
29-
def str = new LinkedList <String> ();
30-
str.add("interfacenamegenerator.jar")
31-
str.addAll(jarsArr)
19+
def current = project.jarFiles
20+
def cache = new File(cachedJarsFilePath)
21+
def utf8 = java.nio.charset.StandardCharsets.UTF_8
22+
if (cache.exists()) {
23+
def contents = new String(java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(cachedJarsFilePath)), utf8).trim()
24+
shouldRun = !contents.equals(current.toString())
25+
}
26+
27+
if (shouldRun) {
28+
javaexec {
29+
main "-jar"
30+
31+
def jarsAsStr = current.toString();
32+
def jarsArr = jarsAsStr.replaceAll(/[\[\]]/, "").split(", ")
33+
34+
def str = new LinkedList <String> ();
35+
str.add("interfacenamegenerator.jar")
36+
str.addAll(jarsArr)
3237

33-
args str.toArray()
34-
35-
cachedJars.text = jarsAsStr
38+
args str.toArray()
39+
}
40+
java.nio.file.Files.write(java.nio.file.Paths.get(cachedJarsFilePath), [current.toString()], utf8)
41+
}
3642
}
3743
}
3844

3945
// won't run if node_modules are installed
40-
task runNpmInstallForAstParser (type: Exec) {
41-
42-
//check this way so it doesn't slow down the build by snapshot-ing the node_modules
43-
outputs.upToDateWhen {
44-
(new File("$astParserDir/node_modules")).exists()
45-
}
46+
task runNpmInstallForAstParser () {
47+
doFirst {
48+
if (shouldRun) {
49+
exec {
50+
workingDir astParserDir
4651

47-
workingDir astParserDir
48-
49-
if(isWinOs) {
50-
commandLine "cmd", "/c", "npm", "install"
51-
}
52-
else {
53-
commandLine "npm", "install"
52+
if(isWinOs) {
53+
commandLine "cmd", "/c", "npm", "install"
54+
}
55+
else {
56+
commandLine "npm", "install"
57+
}
58+
}
59+
}
5460
}
5561
}
5662

5763
// if there are new dependencies the parser will run again
58-
task runAstParser (type: Exec) {
59-
60-
inputs.files fileTree(dir: absoluteJsCodeDir)
61-
outputs.files(bindingsFilePath)
62-
63-
workingDir astParserDir
64-
65-
if(isWinOs) {
66-
commandLine "cmd", "/c", "node", "js_parser.js" , absoluteJsCodeDir, "../bindings.txt"
67-
}
68-
else {
69-
commandLine "node", "js_parser.js", absoluteJsCodeDir, "../bindings.txt"
64+
task runAstParser () {
65+
doFirst {
66+
if (shouldRun) {
67+
exec {
68+
workingDir astParserDir
69+
70+
if(isWinOs) {
71+
commandLine "cmd", "/c", "node", "js_parser.js" , absoluteJsCodeDir, "../bindings.txt"
72+
}
73+
else {
74+
commandLine "node", "js_parser.js", absoluteJsCodeDir, "../bindings.txt"
75+
}
76+
}
77+
}
7078
}
7179
}
72-
7380
// run the static binding generator
74-
task generateBindings(type: JavaExec) {
75-
76-
inputs.files(bindingsFilePath)
77-
outputs.dir(absoluteOutDir)
78-
81+
task generateBindings() {
7982
doFirst {
80-
main "-jar"
81-
82-
def str = new LinkedList <String> ();
83-
str.add("staticbindinggenerator.jar")
84-
str.add(bindingsFilePath)
85-
str.add(absoluteOutDir)
86-
str.addAll(project.jarFiles)
87-
88-
args str.toArray()
83+
if (shouldRun) {
84+
javaexec {
85+
main "-jar"
86+
87+
def str = new LinkedList <String> ();
88+
str.add("staticbindinggenerator.jar")
89+
str.add(bindingsFilePath)
90+
str.add(absoluteOutDir)
91+
str.addAll(project.jarFiles)
92+
93+
args str.toArray()
94+
}
95+
}
8996
}
9097
}
9198

build/project-template-gradle/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ def libDir = "$projectDir/../../lib/Android/"
3939
def pluginNames = new ArrayList<String>()
4040
def configDir = file(configurationsDir)
4141

42+
def asbgProject = project(":asbg")
43+
asbgProject.ext.outDir = new File("$projectDir", "src/main/java")
44+
asbgProject.ext.jsCodeDir = new File("$projectDir", "src/main/assets/app")
45+
4246
def compiteCompileSdkVersion () {
4347
if(project.hasProperty("compileSdk")) {
4448
return compileSdk
@@ -363,9 +367,15 @@ task collectAllJars {
363367

364368
metadataParams.add("metadata-generator.jar")
365369
metadataParams.add("$projectDir/metadata/output/assets/metadata")
370+
def jars = new LinkedList<File>()
366371
for(def i = 0; i < allJarPaths.size(); i++) {
367372
metadataParams.add(allJarPaths.get(i));
373+
def f = new File(allJarPaths.get(i))
374+
if (f.getName().endsWith(".jar")) {
375+
jars.add(f)
376+
}
368377
}
378+
asbgProject.ext.jarFiles = jars
369379
}
370380
}
371381

build/project-template-gradle/gradle.properties

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)