11/*
2- * The android static binding generator will generate bindings for some javascript code you specify.
3- * The passed output directory will be created if necessary
4- * to run:
5- * gradle generatebindings -PjsCodeDir=[js_code_dir] -PjarsDir=[jars_dir] -PoutDir=[out_dir]
2+ * The android static binding generator will generate bindings for the Javascript code you specify.
63*/
74
85def isWinOs = System . properties[' os.name' ]. toLowerCase(). contains(' windows' )
96
10- def isJsCodePathPassed = project. hasProperty(" jsCodeDir" )
11- def isOutDirPassed = project. hasProperty(" outDir" )
12-
137def bgRootDir = " $rootDir /build-tools/android-static-binding-generator"
148def astParserDir = " $bgRootDir /ast-parser"
159def interfaceNamesFilePath = " $bgRootDir /interfaces-names.txt"
1610def bindingsFilePath = " $bgRootDir /bindings.txt"
11+ def cachedJarsFilePath = " $bgRootDir /cached.dat"
12+
13+ def absoluteOutDir = " $rootDir /$project . outDir "
14+ def absoluteJsCodeDir = " $rootDir /$project . jsCodeDir "
1715
16+ // depends on passed jars and generated interface-names
1817task generateInterfaceNamesList (type : JavaExec ) {
19- outputs. upToDateWhen {
20- (new File (interfaceNamesFilePath)). exists()
21- }
18+ def cachedJars = new File (cachedJarsFilePath)
19+
20+ inputs. file(cachedJars)
21+ outputs. files(interfaceNamesFilePath)
2222
23- doFirst {
23+ doFirst {
2424 main " -jar"
25-
26- // todo: for test (remove later)
27- // def ll = new LinkedList<String>();
28- // ll.add("D:/work/nativescript-cli/scratch/buildtoolstest/platforms/android/libs/nativescript.jar")
29- // ll.add("D:/tools/android_sdk/extras/android/m2repository/com/android/support/support-annotations/23.2.1/support-annotations-23.2.1.jar")
30- // ll.add("D:/tools/android_sdk/platforms/android-23/android.jar")
31- // ll.add("D:/work/nativescript-cli/scratch/buildtoolstest/platforms/android/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/23.2.1/jars/classes.jar")
32- // ll.add("D:/work/nativescript-cli/scratch/buildtoolstest/platforms/android/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.2.1/jars/classes.jar")
33- // ll.add("D:/work/nativescript-cli/scratch/buildtoolstest/platforms/android/build/intermediates/exploded-aar/com.android.support/support-v4/23.2.1/jars/classes.jar")
34- // ll.add("D:/work/nativescript-cli/scratch/buildtoolstest/platforms/android/build/intermediates/exploded-aar/com.android.support/support-v4/23.2.1/jars/libs/internal_impl-23.2.1.jar")
35- // ll.add("D:/work/nativescript-cli/scratch/buildtoolstest/platforms/android/build/intermediates/exploded-aar/com.android.support/support-vector-drawable/23.2.1/jars/classes.jar")
36- // ll.add("D:/work/nativescript-cli/scratch/buildtoolstest/platforms/android/build/intermediates/exploded-aar/widgets-release/jars/classes.jar")
37- // project.jarFiles = ll;
3825
39- def jarsArr = rootProject. jarFiles. toString(). replaceAll(/ [\[\] ]/ , " " ). split(" , " )
26+ def jarsAsStr = rootProject. jarFiles. toString();
27+ def jarsArr = jarsAsStr. replaceAll(/ [\[\] ]/ , " " ). split(" , " )
4028
4129 def str = new LinkedList <String > ();
4230 str. add(" interfacenamegenerator.jar" )
4331 str. addAll(jarsArr)
4432
4533 args str. toArray()
34+
35+ cachedJars. text = jarsAsStr
4636 }
4737}
4838
39+ // won't run if node_modules are installed
4940task runNpmInstallForAstParser (type : Exec ) {
50- workingDir astParserDir
5141
42+ // check this way so it doesn't slow down the build by snapshot-ing the node_modules
5243 outputs. upToDateWhen {
5344 (new File (" $astParserDir /node_modules" )). exists()
5445 }
5546
47+ workingDir astParserDir
48+
5649 if (isWinOs) {
5750 commandLine " cmd" , " /c" , " npm" , " install"
5851 }
@@ -61,34 +54,35 @@ task runNpmInstallForAstParser (type: Exec) {
6154 }
6255}
6356
57+ // if there are new dependencies the parser will run again
6458task runAstParser (type : Exec ) {
65- workingDir astParserDir
66-
59+
60+ inputs . files fileTree( dir : absoluteJsCodeDir)
6761 outputs. files(bindingsFilePath)
68- outputs. upToDateWhen {
69- ! generateInterfaceNamesList. didWork
70- }
71-
62+
63+ workingDir astParserDir
64+
7265 if (isWinOs) {
73- commandLine " cmd" , " /c" , " node" , " js_parser.js" , project . jsCodeDir , " ../bindings.txt"
66+ commandLine " cmd" , " /c" , " node" , " js_parser.js" , absoluteJsCodeDir , " ../bindings.txt"
7467 }
7568 else {
76- commandLine " node" , " js_parser.js" , project . jsCodeDir , " ../bindings.txt"
69+ commandLine " node" , " js_parser.js" , absoluteJsCodeDir , " ../bindings.txt"
7770 }
7871}
7972
73+ // run the static binding generator
8074task generateBindings (type : JavaExec ) {
8175
8276 inputs. files(bindingsFilePath)
83- outputs. dir(project . outDir )
77+ outputs. dir(absoluteOutDir )
8478
8579 doFirst {
8680 main " -jar"
8781
8882 def str = new LinkedList <String > ();
8983 str. add(" staticbindinggenerator.jar" )
9084 str. add(bindingsFilePath)
91- str. add(project . outDir )
85+ str. add(absoluteOutDir )
9286 str. addAll(project. jarFiles)
9387
9488 args str. toArray()
0 commit comments