xref: /aosp_15_r20/external/google-smali/dexlib2/build.gradle (revision 37f5703ca959d1ce24046e7595880d209e15c133)
1/*
2 * Copyright 2012, Google LLC
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 *     * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *     * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 *     * Neither the name of Google LLC nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31ext.testAccessorOutputDir = file("${buildDir}/generated-src/accessorTest/java")
32ext.testAccessorOutputFile = file("${testAccessorOutputDir}/com/android/tools/smali/dexlib2/AccessorTypes.java")
33
34sourceSets {
35    main {
36        java {
37            srcDirs "${project.rootDir}/third_party/dexlib2/src/main/java"
38        }
39    }
40    accessorTest {
41        java {
42            srcDir testAccessorOutputDir
43        }
44    }
45}
46
47configurations {
48    accessorTestGenerator
49    dx
50}
51
52dependencies {
53    implementation depends.findbugs
54    implementation depends.guava
55
56    testImplementation depends.junit
57    testImplementation depends.mockito
58
59    accessorTestGenerator project('accessorTestGenerator')
60
61    dx depends.dx
62}
63
64// You must manually execute this task to regenerate SyntheticAccessorFSM.java, after modifying the ragel file
65// e.g. ./gradlew ragel
66task ragel(type:Exec) {
67    workingDir = 'src/main/ragel'
68
69    commandLine 'ragel', '-J', '-o', file('src/main/java/com/android/tools/smali/dexlib2/util/SyntheticAccessorFSM.java'),
70            'SyntheticAccessorFSM.rl'
71}
72
73task generateAccessorTestSource(type: JavaExec) {
74    file(testAccessorOutputFile.parent).mkdirs()
75    outputs.dir file(testAccessorOutputDir)
76
77    classpath = configurations.accessorTestGenerator
78    main = 'com.android.tools.smali.dexlib2.AccessorTestGenerator'
79    args testAccessorOutputFile
80}
81compileAccessorTestJava.dependsOn(generateAccessorTestSource)
82
83// You must manually execute this task to regenerate src/test/resources/accessorTest.dex
84task generateAccessorTestDex(type: JavaExec, dependsOn: compileAccessorTestJava) {
85    def outputDex = file('src/test/resources/accessorTest.dex')
86    file(outputDex.parent).mkdirs()
87
88    inputs.dir(project.sourceSets.accessorTest.output.classesDirs)
89    outputs.file outputDex
90
91    main 'com.android.dx.command.Main'
92    classpath = configurations.dx
93
94    args '--dex'
95    args '--no-strict'
96    args "--output=${outputDex}"
97    args sourceSets.accessorTest.output.classesDirs
98}
99
100publish {
101    publishing {
102        publications {
103            mavenJava(MavenPublication) {
104                pom {
105                    description = 'dexlib2 is a library for reading/modifying/writing Android dex files'
106                    scm {
107                        url = 'https://github.com/google/smali/tree/master/dexlib2'
108                    }
109                }
110            }
111        }
112    }
113}
114