summaryrefslogtreecommitdiffstats
path: root/edify
diff options
context:
space:
mode:
authorEthan Yonker <dees_troy@teamw.in>2018-08-24 18:17:36 +0200
committerEthan Yonker <dees_troy@teamw.in>2018-08-24 18:17:39 +0200
commit58f2132bc3954fc704787d477500a209eedb8e29 (patch)
treeeb0f79aacd68724b0c0c091018384ef924380f47 /edify
parentRemove remaining pieces of supersu (diff)
parentSnap for 4745538 from 723056a83f8c8b15af02d9c302862dbb2304ea8c to pi-release (diff)
downloadandroid_bootable_recovery-58f2132bc3954fc704787d477500a209eedb8e29.tar
android_bootable_recovery-58f2132bc3954fc704787d477500a209eedb8e29.tar.gz
android_bootable_recovery-58f2132bc3954fc704787d477500a209eedb8e29.tar.bz2
android_bootable_recovery-58f2132bc3954fc704787d477500a209eedb8e29.tar.lz
android_bootable_recovery-58f2132bc3954fc704787d477500a209eedb8e29.tar.xz
android_bootable_recovery-58f2132bc3954fc704787d477500a209eedb8e29.tar.zst
android_bootable_recovery-58f2132bc3954fc704787d477500a209eedb8e29.zip
Diffstat (limited to 'edify')
-rw-r--r--edify/Android.bp45
-rw-r--r--edify/edify_parser.cpp79
-rw-r--r--edify/expr.cpp30
-rw-r--r--edify/include/edify/expr.h (renamed from edify/expr.h)38
-rw-r--r--edify/lexer.ll4
-rw-r--r--edify/parser.yy2
6 files changed, 85 insertions, 113 deletions
diff --git a/edify/Android.bp b/edify/Android.bp
new file mode 100644
index 000000000..42947eb4e
--- /dev/null
+++ b/edify/Android.bp
@@ -0,0 +1,45 @@
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_library_static {
+ name: "libedify",
+
+ host_supported: true,
+
+ srcs: [
+ "expr.cpp",
+ "lexer.ll",
+ "parser.yy",
+ ],
+
+ cflags: [
+ "-Wall",
+ "-Werror",
+ "-Wno-deprecated-register",
+ "-Wno-unused-parameter",
+ ],
+
+ export_include_dirs: [
+ "include",
+ ],
+
+ local_include_dirs: [
+ "include",
+ ],
+
+ static_libs: [
+ "libbase",
+ "libotautil",
+ ],
+}
diff --git a/edify/edify_parser.cpp b/edify/edify_parser.cpp
deleted file mode 100644
index f1b56284c..000000000
--- a/edify/edify_parser.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * This is a host-side tool for validating a given edify script file.
- *
- * We used to have edify test cases here, which have been moved to
- * tests/component/edify_test.cpp.
- *
- * Caveat: It doesn't recognize functions defined through updater, which
- * makes the tool less useful. We should either extend the tool or remove it.
- */
-
-#include <errno.h>
-#include <stdio.h>
-
-#include <memory>
-#include <string>
-
-#include <android-base/file.h>
-
-#include "expr.h"
-
-static void ExprDump(int depth, const std::unique_ptr<Expr>& n, const std::string& script) {
- printf("%*s", depth*2, "");
- printf("%s %p (%d-%d) \"%s\"\n",
- n->name.c_str(), n->fn, n->start, n->end,
- script.substr(n->start, n->end - n->start).c_str());
- for (size_t i = 0; i < n->argv.size(); ++i) {
- ExprDump(depth+1, n->argv[i], script);
- }
-}
-
-int main(int argc, char** argv) {
- RegisterBuiltins();
-
- if (argc != 2) {
- printf("Usage: %s <edify script>\n", argv[0]);
- return 1;
- }
-
- std::string buffer;
- if (!android::base::ReadFileToString(argv[1], &buffer)) {
- printf("%s: failed to read %s: %s\n", argv[0], argv[1], strerror(errno));
- return 1;
- }
-
- std::unique_ptr<Expr> root;
- int error_count = 0;
- int error = parse_string(buffer.data(), &root, &error_count);
- printf("parse returned %d; %d errors encountered\n", error, error_count);
- if (error == 0 || error_count > 0) {
-
- ExprDump(0, root, buffer);
-
- State state(buffer, nullptr);
- std::string result;
- if (!Evaluate(&state, root, &result)) {
- printf("result was NULL, message is: %s\n",
- (state.errmsg.empty() ? "(NULL)" : state.errmsg.c_str()));
- } else {
- printf("result is [%s]\n", result.c_str());
- }
- }
- return 0;
-}
diff --git a/edify/expr.cpp b/edify/expr.cpp
index 54ab3325c..6823b7339 100644
--- a/edify/expr.cpp
+++ b/edify/expr.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "expr.h"
+#include "edify/expr.h"
#include <stdarg.h>
#include <stdio.h>
@@ -31,6 +31,8 @@
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
+#include "otautil/error_code.h"
+
// Functions should:
//
// - return a malloc()'d string
@@ -112,9 +114,9 @@ Value* IfElseFn(const char* name, State* state, const std::vector<std::unique_pt
Value* AbortFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) {
std::string msg;
if (!argv.empty() && Evaluate(state, argv[0], &msg)) {
- state->errmsg = msg;
+ state->errmsg += msg;
} else {
- state->errmsg = "called abort()";
+ state->errmsg += "called abort()";
}
return nullptr;
}
@@ -408,16 +410,16 @@ Value* ErrorAbort(State* state, const char* format, ...) {
}
Value* ErrorAbort(State* state, CauseCode cause_code, const char* format, ...) {
- va_list ap;
- va_start(ap, format);
- android::base::StringAppendV(&state->errmsg, format, ap);
- va_end(ap);
- state->cause_code = cause_code;
- return nullptr;
-}
-
-State::State(const std::string& script, void* cookie) :
- script(script),
- cookie(cookie) {
+ std::string err_message;
+ va_list ap;
+ va_start(ap, format);
+ android::base::StringAppendV(&err_message, format, ap);
+ va_end(ap);
+ // Ensure that there's exactly one line break at the end of the error message.
+ state->errmsg = android::base::Trim(err_message) + "\n";
+ state->cause_code = cause_code;
+ return nullptr;
}
+State::State(const std::string& script, void* cookie)
+ : script(script), cookie(cookie), error_code(kNoError), cause_code(kNoCause) {}
diff --git a/edify/expr.h b/edify/include/edify/expr.h
index 4838d20c0..770d1cf0d 100644
--- a/edify/expr.h
+++ b/edify/include/edify/expr.h
@@ -23,32 +23,34 @@
#include <string>
#include <vector>
-#include "error_code.h"
+// Forward declaration to avoid including "otautil/error_code.h".
+enum ErrorCode : int;
+enum CauseCode : int;
struct State {
- State(const std::string& script, void* cookie);
+ State(const std::string& script, void* cookie);
- // The source of the original script.
- const std::string& script;
+ // The source of the original script.
+ const std::string& script;
- // Optional pointer to app-specific data; the core of edify never
- // uses this value.
- void* cookie;
+ // Optional pointer to app-specific data; the core of edify never
+ // uses this value.
+ void* cookie;
- // The error message (if any) returned if the evaluation aborts.
- // Should be empty initially, will be either empty or a string that
- // Evaluate() returns.
- std::string errmsg;
+ // The error message (if any) returned if the evaluation aborts.
+ // Should be empty initially, will be either empty or a string that
+ // Evaluate() returns.
+ std::string errmsg;
- // error code indicates the type of failure (e.g. failure to update system image)
- // during the OTA process.
- ErrorCode error_code = kNoError;
+ // error code indicates the type of failure (e.g. failure to update system image)
+ // during the OTA process.
+ ErrorCode error_code;
- // cause code provides more detailed reason of an OTA failure (e.g. fsync error)
- // in addition to the error code.
- CauseCode cause_code = kNoCause;
+ // cause code provides more detailed reason of an OTA failure (e.g. fsync error)
+ // in addition to the error code.
+ CauseCode cause_code;
- bool is_retry = false;
+ bool is_retry = false;
};
enum ValueType {
diff --git a/edify/lexer.ll b/edify/lexer.ll
index b764d1699..4e04003b1 100644
--- a/edify/lexer.ll
+++ b/edify/lexer.ll
@@ -18,7 +18,7 @@
#include <string.h>
#include <string>
-#include "expr.h"
+#include "edify/expr.h"
#include "yydefs.h"
#include "parser.h"
@@ -35,6 +35,8 @@ std::string string_buffer;
%x STR
+%option noinput
+%option nounput
%option noyywrap
%%
diff --git a/edify/parser.yy b/edify/parser.yy
index b1685eb1f..bd2e0105f 100644
--- a/edify/parser.yy
+++ b/edify/parser.yy
@@ -25,7 +25,7 @@
#include <android-base/macros.h>
-#include "expr.h"
+#include "edify/expr.h"
#include "yydefs.h"
#include "parser.h"