18
18
package com.spotify.ruler.cli
19
19
20
20
import com.github.ajalt.clikt.core.CliktCommand
21
+ import com.github.ajalt.clikt.parameters.options.default
22
+ import com.github.ajalt.clikt.parameters.options.flag
21
23
import com.github.ajalt.clikt.parameters.options.multiple
22
24
import com.github.ajalt.clikt.parameters.options.option
23
25
import com.github.ajalt.clikt.parameters.options.required
24
26
import com.github.ajalt.clikt.parameters.types.file
25
27
import com.spotify.ruler.common.BaseRulerTask
26
28
import com.spotify.ruler.common.FEATURE_NAME
27
29
import com.spotify.ruler.common.apk.ApkCreator
30
+ import com.spotify.ruler.common.apk.ApkEntry
28
31
import com.spotify.ruler.common.apk.InjectedToolApkCreator
29
32
import com.spotify.ruler.common.apk.parseSplitApkDirectory
30
33
import com.spotify.ruler.common.apk.unzipFile
@@ -49,7 +52,6 @@ import java.util.logging.Logger
49
52
class RulerCli : CliktCommand (), BaseRulerTask {
50
53
private val logger = Logger .getLogger(" Ruler" )
51
54
private val dependencyMap by option().file().required()
52
- private val rulerConfigJson by option().file().required()
53
55
private val apkFile by option().file()
54
56
private val bundleFile by option().file()
55
57
private val reportDir by option().file(canBeDir = true ).required()
@@ -58,6 +60,15 @@ class RulerCli : CliktCommand(), BaseRulerTask {
58
60
private val unstrippedNativeFiles: List <File > by option().file().multiple()
59
61
private val aapt2Tool: File ? by option().file()
60
62
private val bloatyTool: File ? by option().file()
63
+ private val defaultOwner by option().default(" unknown" )
64
+ private val staticComponentsFile by option().file()
65
+ private val ownershipFile by option().file()
66
+ private val omitFileBreakdown by option().flag()
67
+ private val projectPath by option().required()
68
+ private val deviceSpecFile by option().file()
69
+ private val appInfoFile by option().file().required()
70
+ private val additionalEntriesFile by option().file()
71
+ private val ignoreFile by option().multiple()
61
72
62
73
override fun print (content : String ) = echo(content)
63
74
@@ -70,17 +81,26 @@ class RulerCli : CliktCommand(), BaseRulerTask {
70
81
override fun provideBloatyPath () = bloatyTool?.path
71
82
72
83
private val config: RulerConfig by lazy {
73
- val json = Json .decodeFromStream<JsonRulerConfig >(rulerConfigJson.inputStream())
84
+ val deviceSpec = deviceSpecFile?.let {
85
+ Json .decodeFromStream<DeviceSpec >(it.inputStream())
86
+ }
87
+ val appInfo = Json .decodeFromStream<AppInfo >(appInfoFile.inputStream())
88
+
89
+ val additionalEntries =
90
+ additionalEntriesFile?.let { Json .decodeFromStream<List <ApkEntry .Default >>(it.inputStream()) }
91
+ logger.log(Level .INFO , " Got ${additionalEntries?.size} additional entries" )
74
92
RulerConfig (
75
- projectPath = json. projectPath,
76
- apkFilesMap = apkFiles(config = json ),
93
+ projectPath = projectPath,
94
+ apkFilesMap = apkFiles(projectPath, deviceSpec ),
77
95
reportDir = reportDir,
78
- ownershipFile = json.ownershipFile?.let { File (it) },
79
- staticDependenciesFile = json.staticComponentsPath?.let { File (it) },
80
- appInfo = json.appInfo,
81
- deviceSpec = json.deviceSpec,
82
- defaultOwner = json.defaultOwner,
83
- omitFileBreakdown = json.omitFileBreakdown
96
+ ownershipFile = ownershipFile,
97
+ staticDependenciesFile = staticComponentsFile,
98
+ appInfo = appInfo,
99
+ deviceSpec = deviceSpec,
100
+ defaultOwner = defaultOwner,
101
+ omitFileBreakdown = omitFileBreakdown,
102
+ additionalEntries = additionalEntries,
103
+ ignoredFiles = ignoreFile
84
104
)
85
105
}
86
106
@@ -110,7 +130,7 @@ class RulerCli : CliktCommand(), BaseRulerTask {
110
130
dependencySanitizer.sanitize(entries)
111
131
}
112
132
113
- private fun apkFiles (config : JsonRulerConfig ): Map <String , List <File >> {
133
+ private fun apkFiles (projectPath : String , deviceSpec : DeviceSpec ? ): Map <String , List <File >> {
114
134
return if (apkFile != null ) {
115
135
if (apkFile!! .extension == " apk" ) {
116
136
logger.log(Level .INFO , " Using APK file ${apkFile?.path} " )
@@ -122,20 +142,21 @@ class RulerCli : CliktCommand(), BaseRulerTask {
122
142
parseSplitApkDirectory(directory.toFile())
123
143
}
124
144
} else if (bundleFile != null ) {
125
- with (if (aapt2Tool != null ) {
145
+ with (
146
+ if (aapt2Tool != null ) {
126
147
logger.log(
127
148
Level .INFO ,
128
149
" Creating InjectedToolApkCreator with ${aapt2Tool?.path} "
129
150
)
130
151
InjectedToolApkCreator (aapt2Tool!! .toPath())
131
152
} else {
132
- ApkCreator (File (config. projectPath))
153
+ ApkCreator (File (projectPath))
133
154
}
134
155
) {
135
156
createSplitApks(
136
157
bundleFile!! ,
137
- config. deviceSpec!! ,
138
- File (config. projectPath).resolve(File (" tmp" )).apply {
158
+ deviceSpec!! ,
159
+ File (projectPath).resolve(File (" tmp" )).apply {
139
160
mkdir()
140
161
}
141
162
)
@@ -148,33 +169,25 @@ class RulerCli : CliktCommand(), BaseRulerTask {
148
169
override fun provideDependencies (): Map <String , List <DependencyComponent >> = dependencies
149
170
150
171
override fun run () {
151
- logger.log(Level .INFO , """
172
+
173
+ logger.log(
174
+ Level .INFO , """
152
175
~~~~~ Starting Ruler ~~~~~
176
+
153
177
Using Dependency Map: ${dependencyMap.path}
154
- Using Ruler Config: ${rulerConfigJson.path}
155
178
Using APK File: ${apkFile?.path}
156
179
Using Bundle File: ${bundleFile?.path}
157
180
Using Proguard Mapping File: ${mappingFile?.path}
158
181
Using Resource Mapping File: ${resourceMappingFile?.path}
159
182
Using AAPT2: ${aapt2Tool?.path}
160
183
Using Bloaty: ${bloatyTool?.path}
161
184
Writing reports to: ${reportDir.path}
162
- """ .trimIndent())
185
+ """ .trimIndent()
186
+ )
163
187
super .run ()
164
188
}
165
189
}
166
190
167
- @Serializable
168
- data class JsonRulerConfig (
169
- val projectPath : String ,
170
- val ownershipFile : String? = null ,
171
- val staticComponentsPath : String? = null ,
172
- val appInfo : AppInfo ,
173
- val deviceSpec : DeviceSpec ? = null ,
174
- val defaultOwner : String ,
175
- val omitFileBreakdown : Boolean
176
- )
177
-
178
191
@Serializable
179
192
data class ModuleMap (
180
193
val assets : List <Asset >,
0 commit comments