• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 
17 #include <iostream>
18 #include <vector>
19 
20 #include "androidfw/StringPiece.h"
21 
22 #include "Diagnostics.h"
23 
24 namespace aapt {
25 
26 // DO NOT UPDATE, this is more of a marketing version.
27 static const char* sMajorVersion = "2";
28 
29 // Update minor version whenever a feature or flag is added.
30 static const char* sMinorVersion = "16";
31 
PrintVersion()32 int PrintVersion() {
33   std::cerr << "Android Asset Packaging Tool (aapt) " << sMajorVersion << "."
34             << sMinorVersion << std::endl;
35   return 0;
36 }
37 
38 extern int Compile(const std::vector<android::StringPiece>& args, IDiagnostics* diagnostics);
39 extern int Link(const std::vector<android::StringPiece>& args, IDiagnostics* diagnostics);
40 extern int Dump(const std::vector<android::StringPiece>& args);
41 extern int Diff(const std::vector<android::StringPiece>& args);
42 extern int Optimize(const std::vector<android::StringPiece>& args);
43 
44 }  // namespace aapt
45 
main(int argc,char ** argv)46 int main(int argc, char** argv) {
47   if (argc >= 2) {
48     argv += 1;
49     argc -= 1;
50 
51     std::vector<android::StringPiece> args;
52     for (int i = 1; i < argc; i++) {
53       args.push_back(argv[i]);
54     }
55 
56     android::StringPiece command(argv[0]);
57     if (command == "compile" || command == "c") {
58       aapt::StdErrDiagnostics diagnostics;
59       return aapt::Compile(args, &diagnostics);
60     } else if (command == "link" || command == "l") {
61       aapt::StdErrDiagnostics diagnostics;
62       return aapt::Link(args, &diagnostics);
63     } else if (command == "dump" || command == "d") {
64       return aapt::Dump(args);
65     } else if (command == "diff") {
66       return aapt::Diff(args);
67     } else if (command == "optimize") {
68       return aapt::Optimize(args);
69     } else if (command == "version") {
70       return aapt::PrintVersion();
71     }
72     std::cerr << "unknown command '" << command << "'\n";
73   } else {
74     std::cerr << "no command specified\n";
75   }
76 
77   std::cerr << "\nusage: aapt2 [compile|link|dump|diff|optimize|version] ..."
78             << std::endl;
79   return 1;
80 }
81