summaryrefslogtreecommitdiff
path: root/tools/aapt2/configuration/ConfigurationParser.cpp
diff options
context:
space:
mode:
authorShane Farmer <safarmer@google.com>2017-06-14 09:10:28 -0700
committerShane Farmer <safarmer@google.com>2017-06-19 12:49:48 -0700
commitb102727771b9ac3d28d4f9b0a4a54b98bd1af958 (patch)
tree0a964992d176fcb03183d78376a85f66cf90d0d0 /tools/aapt2/configuration/ConfigurationParser.cpp
parent71d3509c2ff4ad304843b2c2f1851b24248c7d08 (diff)
AAPT2: Read config from disk
Implement the todo left from last change to read the contents of the configuration file from disk. Since this is an operation that may fail the API was changed to take return a Maybe to indicate errors reading the file. Test: unit test for error condition Test: ran aapt2 optimize with the new code path wired in Change-Id: I93d532b4a57af9520231225eee4fc5f2b1a046b9
Diffstat (limited to 'tools/aapt2/configuration/ConfigurationParser.cpp')
-rw-r--r--tools/aapt2/configuration/ConfigurationParser.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/tools/aapt2/configuration/ConfigurationParser.cpp b/tools/aapt2/configuration/ConfigurationParser.cpp
index 89618d3a4676..303a809fbaa9 100644
--- a/tools/aapt2/configuration/ConfigurationParser.cpp
+++ b/tools/aapt2/configuration/ConfigurationParser.cpp
@@ -21,10 +21,13 @@
#include <memory>
#include <utility>
+#include <android-base/file.h>
#include <android-base/logging.h>
#include "ConfigDescription.h"
#include "Diagnostics.h"
+#include "io/File.h"
+#include "io/FileSystem.h"
#include "util/Util.h"
#include "xml/XmlActionExecutor.h"
#include "xml/XmlDom.h"
@@ -42,6 +45,8 @@ using ::aapt::configuration::Configuration;
using ::aapt::configuration::GlTexture;
using ::aapt::configuration::Group;
using ::aapt::configuration::Locale;
+using ::aapt::io::IFile;
+using ::aapt::io::RegularFile;
using ::aapt::util::TrimWhitespace;
using ::aapt::xml::Element;
using ::aapt::xml::FindRootElement;
@@ -49,6 +54,7 @@ using ::aapt::xml::NodeCast;
using ::aapt::xml::XmlActionExecutor;
using ::aapt::xml::XmlActionExecutorPolicy;
using ::aapt::xml::XmlNodeAction;
+using ::android::base::ReadFileToString;
const std::unordered_map<std::string, Abi> kAbiMap = {
{"armeabi", Abi::kArmeV6},
@@ -96,6 +102,17 @@ class NamespaceVisitor : public xml::Visitor {
} // namespace
+
+
+/** Returns a ConfigurationParser for the file located at the provided path. */
+Maybe<ConfigurationParser> ConfigurationParser::ForPath(const std::string& path) {
+ std::string contents;
+ if (!ReadFileToString(path, &contents, true)) {
+ return {};
+ }
+ return ConfigurationParser(contents);
+}
+
ConfigurationParser::ConfigurationParser(std::string contents)
: contents_(std::move(contents)),
diag_(&noop_) {