Refactor Options to support multiple inputs
Now, the single executable 'aidl' supports both Java and C++ as target
languages. The language is set via --lang={java|cpp} option. The old
'aidl-cpp' is still supported for backwards compatibility reason. When
invoked with --lang option, 'aidl' behaves as before, i.e. compile an
AIDL file into a Java file.
When --lang option is specified, one can provide multiple AIDL files as
inputs.
aidl --lang=java -o out_dir IFoo.aidl IBar.aidl
This command creates IFoo.java and IBar.java under out_dir.
aidl --lang=cpp -o out_dir -h header_dir IFoo.aidl IBar.aidl
This command creates IFoo.cpp and IBar.cpp under out_dir and the header
files under header_dir.
The input AIDL files are automatically included to the import path, so
there is no need to explicitly set include path for them.
Internally, JavaOptions and CppOptions are unified into the single
Options class, where parsing is done using getopt(3) in order to better
support long/short options, for example, include path can be set via
either of -IDIR, -I DIR, --include=DIR, and --include DIR.
Bug: 110967839
Test: runtests.py
Change-Id: I0b2f9d6b53e99f821ec04b053996f43378065437
diff --git a/main_cpp.cpp b/main_cpp.cpp
index e904a92..3454eca 100644
--- a/main_cpp.cpp
+++ b/main_cpp.cpp
@@ -14,29 +14,31 @@
* limitations under the License.
*/
-#include <memory>
-
#include "aidl.h"
#include "io_delegate.h"
#include "logging.h"
#include "options.h"
-using android::aidl::CppOptions;
+#include <iostream>
+
+using android::aidl::Options;
// aidl is leaky. Turn off LeakSanitizer by default. b/37749857
extern "C" const char *__asan_default_options() {
return "detect_leaks=0";
}
-int main(int argc, char** argv) {
+int main(int argc, char* argv[]) {
android::base::InitLogging(argv);
LOG(DEBUG) << "aidl starting";
- std::unique_ptr<CppOptions> options = CppOptions::Parse(argc, argv);
- if (!options) {
+ Options options(argc, argv, Options::Language::CPP);
+ if (!options.Ok()) {
+ std::cerr << options.GetErrorMessage();
+ std::cerr << options.GetUsage();
return 1;
}
android::aidl::IoDelegate io_delegate;
- return android::aidl::compile_aidl_to_cpp(*options, io_delegate);
+ return android::aidl::compile_aidl_to_cpp(options, io_delegate);
}