[view-compiler] Add layout validation
Layout validation walks over a layout resource and verifies that the layout only
uses features the layout compiler supports.
Currently this means we reject layouts that use any of the following tags:
* include
* fragment
* merge
* view
In the future, we will extend the layout compiler to handle these, but for now
we want to be liberal in what we reject.
Bug: 111895153
Test: atest view-compiler-tests
Change-Id: I8dca30c035a83b6763497a36fc60c68438fa1b0c
diff --git a/startop/view_compiler/main.cc b/startop/view_compiler/main.cc
index 7d791c2..9351dc3 100644
--- a/startop/view_compiler/main.cc
+++ b/startop/view_compiler/main.cc
@@ -18,6 +18,7 @@
#include "dex_builder.h"
#include "java_lang_builder.h"
+#include "tinyxml_layout_parser.h"
#include "util.h"
#include "tinyxml2.h"
@@ -100,6 +101,12 @@
XMLDocument xml;
xml.LoadFile(filename);
+ string message{};
+ if (!startop::CanCompileLayout(xml, &message)) {
+ LOG(ERROR) << "Layout not supported: " << message;
+ return 1;
+ }
+
std::ofstream outfile;
if (FLAGS_out != kStdoutFilename) {
outfile.open(FLAGS_out);