assemble_vintf_main.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright (C) 2017 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. #include <getopt.h>
  17. #include <iostream>
  18. #include <android-base/strings.h>
  19. #include <vintf/AssembleVintf.h>
  20. #include "utils.h"
  21. void help() {
  22. std::cerr << "assemble_vintf: Checks if a given manifest / matrix file is valid and \n"
  23. " fill in build-time flags into the given file.\n"
  24. "assemble_vintf -h\n"
  25. " Display this help text.\n"
  26. "assemble_vintf -i <input file>[:<input file>[...]] [-o <output file>] [-m]\n"
  27. " [-c [<check file>]]\n"
  28. " Fill in build-time flags into the given file.\n"
  29. " -i <input file>[:<input file>[...]]\n"
  30. " A list of input files. Format is automatically detected for the\n"
  31. " first file, and the remaining files must have the same format.\n"
  32. " Files other than the first file should only have <hal> defined;\n"
  33. " other entries are ignored. Argument may also be specified\n"
  34. " multiple times.\n"
  35. " -o <output file>\n"
  36. " Optional output file. If not specified, write to stdout.\n"
  37. " -m\n"
  38. " a compatible compatibility matrix is\n"
  39. " generated instead; for example, given a device manifest,\n"
  40. " a framework compatibility matrix is generated. This flag\n"
  41. " is ignored when input is a compatibility matrix.\n"
  42. " -c [<check file>]\n"
  43. " The path of the \"check file\"; for example, this is the path\n"
  44. " of the device manifest for framework compatibility matrix.\n"
  45. " After writing the output file, the program checks against\n"
  46. " the \"check file\", depending on environment variables.\n"
  47. " - PRODUCT_ENFORCE_VINTF_MANIFEST=true: check compatibility\n"
  48. " - VINTF_ENFORCE_NO_UNUSED_HALS =true: check unused HALs\n"
  49. " If any check fails, an error message is written to stderr.\n"
  50. " Return 1.\n"
  51. " --kernel=<version>:<android-base.config>[:<android-base-arch.config>[...]]\n"
  52. " Add a kernel entry to framework compatibility matrix or device\n"
  53. " manifest. Ignored for other input format.\n"
  54. " There can be any number of --kernel for framework compatibility\n"
  55. " matrix, but at most one --kernel and at most one config file for\n"
  56. " device manifest.\n"
  57. " <version> has format: 3.18.0\n"
  58. " <android-base.config> is the location of android-base.config\n"
  59. " <android-base-arch.config> is the location of an optional\n"
  60. " arch-specific config fragment, more than one may be specified\n"
  61. " -l, --hals-only\n"
  62. " Output has only <hal> entries. Cannot be used with -n.\n"
  63. " -n, --no-hals\n"
  64. " Output has no <hal> entries (but all other entries).\n"
  65. " Cannot be used with -l.\n"
  66. " --no-kernel-requirements\n"
  67. " Output has no <config> entries in <kernel>, and kernel minor\n"
  68. " version is set to zero. (For example, 3.18.0).\n";
  69. }
  70. int main(int argc, char** argv) {
  71. using namespace ::android::vintf;
  72. const struct option longopts[] = {{"kernel", required_argument, NULL, 'k'},
  73. {"hals-only", no_argument, NULL, 'l'},
  74. {"no-hals", no_argument, NULL, 'n'},
  75. {"no-kernel-requirements", no_argument, NULL, 'K'},
  76. {0, 0, 0, 0}};
  77. std::string outFilePath;
  78. auto assembleVintf = AssembleVintf::newInstance();
  79. int res;
  80. int optind;
  81. while ((res = getopt_long(argc, argv, "hi:o:mc:nl", longopts, &optind)) >= 0) {
  82. switch (res) {
  83. case 'i': {
  84. for (const auto& inFilePath : ::android::base::Split(optarg, ":")) {
  85. if (!assembleVintf->openInFile(inFilePath.c_str())) {
  86. std::cerr << "Failed to open " << inFilePath << std::endl;
  87. return 1;
  88. }
  89. }
  90. } break;
  91. case 'o': {
  92. outFilePath = optarg;
  93. if (!assembleVintf->openOutFile(optarg)) {
  94. std::cerr << "Failed to open " << optarg << std::endl;
  95. return 1;
  96. }
  97. } break;
  98. case 'm': {
  99. assembleVintf->setOutputMatrix();
  100. } break;
  101. case 'c': {
  102. if (!assembleVintf->openCheckFile(optarg)) {
  103. std::cerr << "Failed to open " << optarg << std::endl;
  104. return 1;
  105. }
  106. } break;
  107. case 'k': {
  108. if (!assembleVintf->addKernel(optarg)) {
  109. std::cerr << "ERROR: Unrecognized --kernel argument." << std::endl;
  110. return 1;
  111. }
  112. } break;
  113. case 'l': {
  114. if (!assembleVintf->setHalsOnly()) {
  115. return 1;
  116. }
  117. } break;
  118. case 'n': {
  119. if (!assembleVintf->setNoHals()) {
  120. return 1;
  121. }
  122. } break;
  123. case 'K': {
  124. if (!assembleVintf->setNoKernelRequirements()) {
  125. return 1;
  126. }
  127. } break;
  128. case 'h':
  129. default: {
  130. help();
  131. return 1;
  132. } break;
  133. }
  134. }
  135. bool success = assembleVintf->assemble();
  136. return success ? 0 : 1;
  137. }