1 /* 2 * Copyright (C) 2025 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.platform.test.ravenwood.ravenhelper.sourcemap 17 18 import com.android.hoststubgen.ArgumentsException 19 import com.android.hoststubgen.utils.ArgIterator 20 import com.android.hoststubgen.utils.BaseOptions 21 import com.android.hoststubgen.utils.SetOnce 22 import com.android.hoststubgen.utils.ensureFileExists 23 24 /** 25 * Options for the "ravenhelper map" subcommand. 26 */ 27 class MapOptions( 28 /** Source files or directories. */ 29 var sourceFilesOrDirectories: MutableList<String> = mutableListOf(), 30 31 /** Files containing target methods */ 32 var targetMethodFiles: MutableList<String> = mutableListOf(), 33 34 /** Output script file. */ 35 var outputScriptFile: SetOnce<String?> = SetOnce(null), 36 37 /** Text to insert. */ 38 var text: SetOnce<String?> = SetOnce(null), 39 ) : BaseOptions() { 40 parseOptionnull41 override fun parseOption(option: String, args: ArgIterator): Boolean { 42 fun nextArg(): String = args.nextArgRequired(option) 43 44 when (option) { 45 // TODO: Write help 46 "-h", "--help" -> TODO("Help is not implemented yet") 47 "-s", "--src" -> sourceFilesOrDirectories.add(nextArg().ensureFileExists()) 48 "-i", "--input" -> targetMethodFiles.add(nextArg().ensureFileExists()) 49 "-o", "--output-script" -> outputScriptFile.set(nextArg()) 50 "-t", "--text" -> text.set(nextArg()) 51 else -> return false 52 } 53 54 return true 55 } 56 checkArgsnull57 override fun checkArgs() { 58 if (sourceFilesOrDirectories.size == 0) { 59 throw ArgumentsException("Must specify at least one source path") 60 } 61 } 62 dumpFieldsnull63 override fun dumpFields(): String { 64 return """ 65 sourceFilesOrDirectories=$sourceFilesOrDirectories 66 targetMethods=$targetMethodFiles 67 outputScriptFile=$outputScriptFile 68 text=$text 69 """.trimIndent() 70 } 71 } 72