From 5e5e334b3beacd56004310514bd565cd0a40d92a Mon Sep 17 00:00:00 2001 From: Lennart Wieboldt Date: Tue, 25 Jul 2017 21:48:39 +0200 Subject: Remove LOCAL_CLANG clang is the default compiler since Android nougat Change-Id: I930bba431dc49970cb4491ed5fcf44b5e00e97df Signed-off-by: Lennart Wieboldt --- edify/Android.mk | 2 -- 1 file changed, 2 deletions(-) (limited to 'edify') diff --git a/edify/Android.mk b/edify/Android.mk index d8058c16f..ffd54c208 100644 --- a/edify/Android.mk +++ b/edify/Android.mk @@ -34,7 +34,6 @@ LOCAL_MODULE := edify_parser LOCAL_YACCFLAGS := -v LOCAL_CPPFLAGS += -Wno-unused-parameter LOCAL_CPPFLAGS += -Wno-deprecated-register -LOCAL_CLANG := true LOCAL_C_INCLUDES += $(LOCAL_PATH)/.. LOCAL_STATIC_LIBRARIES += libbase @@ -51,7 +50,6 @@ LOCAL_CFLAGS := -Werror LOCAL_CPPFLAGS := -Wno-unused-parameter LOCAL_CPPFLAGS += -Wno-deprecated-register LOCAL_MODULE := libedify -LOCAL_CLANG := true LOCAL_C_INCLUDES += $(LOCAL_PATH)/.. LOCAL_STATIC_LIBRARIES += libbase -- cgit v1.2.3 From c7cd918c156c752cea22b315a1f53363bf264975 Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Tue, 29 Aug 2017 12:06:02 -0700 Subject: Turn on -Wall for libedify Bug: 64939312 Test: mma Change-Id: Ia4afc6241b1f11ce261be6840f21a793b23014a6 --- edify/Android.mk | 4 ++-- edify/lexer.ll | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'edify') diff --git a/edify/Android.mk b/edify/Android.mk index ffd54c208..baf4dd21d 100644 --- a/edify/Android.mk +++ b/edify/Android.mk @@ -28,7 +28,7 @@ LOCAL_SRC_FILES := \ $(edify_src_files) \ edify_parser.cpp -LOCAL_CFLAGS := -Werror +LOCAL_CFLAGS := -Wall -Werror LOCAL_CPPFLAGS := -g -O0 LOCAL_MODULE := edify_parser LOCAL_YACCFLAGS := -v @@ -46,7 +46,7 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := $(edify_src_files) -LOCAL_CFLAGS := -Werror +LOCAL_CFLAGS := -Wall -Werror LOCAL_CPPFLAGS := -Wno-unused-parameter LOCAL_CPPFLAGS += -Wno-deprecated-register LOCAL_MODULE := libedify diff --git a/edify/lexer.ll b/edify/lexer.ll index b764d1699..cb4594371 100644 --- a/edify/lexer.ll +++ b/edify/lexer.ll @@ -35,6 +35,8 @@ std::string string_buffer; %x STR +%option noinput +%option nounput %option noyywrap %% -- cgit v1.2.3 From 6e4a9ae51acca00134d7771b53571b4d6bc185b3 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Tue, 3 Oct 2017 14:49:32 -0700 Subject: edify: Remove edify_parser. It used to be containing some unit tests for basic edify syntax, which has been moved into recovery_component_test (commit d770d2e7afd8a909156447c2b79d8739228279d7). The edify_parser host tool supports edify built-in functions only, but doesn't recognize the ones defined in updater. This makes it much less useful to do any real analyzing work. Test: mmma bootable/recovery Change-Id: I3c12f5402d2d6698e0ef5ac6c2e7804c0fbba78a --- edify/Android.mk | 20 ------------- edify/edify_parser.cpp | 79 -------------------------------------------------- 2 files changed, 99 deletions(-) delete mode 100644 edify/edify_parser.cpp (limited to 'edify') diff --git a/edify/Android.mk b/edify/Android.mk index baf4dd21d..cec65f42a 100644 --- a/edify/Android.mk +++ b/edify/Android.mk @@ -19,26 +19,6 @@ edify_src_files := \ parser.yy \ expr.cpp -# -# Build the host-side command line tool (host executable) -# -include $(CLEAR_VARS) - -LOCAL_SRC_FILES := \ - $(edify_src_files) \ - edify_parser.cpp - -LOCAL_CFLAGS := -Wall -Werror -LOCAL_CPPFLAGS := -g -O0 -LOCAL_MODULE := edify_parser -LOCAL_YACCFLAGS := -v -LOCAL_CPPFLAGS += -Wno-unused-parameter -LOCAL_CPPFLAGS += -Wno-deprecated-register -LOCAL_C_INCLUDES += $(LOCAL_PATH)/.. -LOCAL_STATIC_LIBRARIES += libbase - -include $(BUILD_HOST_EXECUTABLE) - # # Build the device-side library (static library) # 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 -#include - -#include -#include - -#include - -#include "expr.h" - -static void ExprDump(int depth, const std::unique_ptr& 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 \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 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; -} -- cgit v1.2.3 From 623fe7e701d5d0fb17082d1ced14498af1b44e5b Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 2 Oct 2017 16:28:06 -0700 Subject: Move error_code.h into otautil. This way it stops requiring relative path ".." in LOCAL_C_INCLUDES (uncrypt and edify). Soong doesn't accept non-local ".." in "local_include_dirs". Test: mmma bootable/recovery Change-Id: Ia4649789cef2aaeb2785483660e9ea5a8b389c62 --- edify/Android.mk | 5 +++-- edify/expr.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'edify') diff --git a/edify/Android.mk b/edify/Android.mk index cec65f42a..db7b5b6b5 100644 --- a/edify/Android.mk +++ b/edify/Android.mk @@ -30,7 +30,8 @@ LOCAL_CFLAGS := -Wall -Werror LOCAL_CPPFLAGS := -Wno-unused-parameter LOCAL_CPPFLAGS += -Wno-deprecated-register LOCAL_MODULE := libedify -LOCAL_C_INCLUDES += $(LOCAL_PATH)/.. -LOCAL_STATIC_LIBRARIES += libbase +LOCAL_STATIC_LIBRARIES += \ + libotautil \ + libbase include $(BUILD_STATIC_LIBRARY) diff --git a/edify/expr.h b/edify/expr.h index 4838d20c0..f2a4d6dcf 100644 --- a/edify/expr.h +++ b/edify/expr.h @@ -23,7 +23,7 @@ #include #include -#include "error_code.h" +#include "otautil/error_code.h" struct State { State(const std::string& script, void* cookie); -- cgit v1.2.3 From 26436d6d6010d5323349af7e119ff8f34f85c40c Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Thu, 5 Oct 2017 17:16:31 +0000 Subject: Revert "Move error_code.h into otautil." This reverts commit 623fe7e701d5d0fb17082d1ced14498af1b44e5b. Reason for revert: Need to address device-specific modules. Change-Id: Ib7a4191e7f193dfff49b02d3de76dda856800251 --- edify/Android.mk | 5 ++--- edify/expr.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'edify') diff --git a/edify/Android.mk b/edify/Android.mk index db7b5b6b5..cec65f42a 100644 --- a/edify/Android.mk +++ b/edify/Android.mk @@ -30,8 +30,7 @@ LOCAL_CFLAGS := -Wall -Werror LOCAL_CPPFLAGS := -Wno-unused-parameter LOCAL_CPPFLAGS += -Wno-deprecated-register LOCAL_MODULE := libedify -LOCAL_STATIC_LIBRARIES += \ - libotautil \ - libbase +LOCAL_C_INCLUDES += $(LOCAL_PATH)/.. +LOCAL_STATIC_LIBRARIES += libbase include $(BUILD_STATIC_LIBRARY) diff --git a/edify/expr.h b/edify/expr.h index f2a4d6dcf..4838d20c0 100644 --- a/edify/expr.h +++ b/edify/expr.h @@ -23,7 +23,7 @@ #include #include -#include "otautil/error_code.h" +#include "error_code.h" struct State { State(const std::string& script, void* cookie); -- cgit v1.2.3 From 0bf20d51336aef08850d0152a6e1501f4b733cf6 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Thu, 5 Oct 2017 12:06:49 -0700 Subject: Don't include "error_code.h" in edify/expr.h. Use forward declartion to avoid pull in the module that contains error_code.h (trying to move it into libotautil). Otherwise all the modules that include "edify/expr.h" need to depend on the module that exports error_code.h. .cpp sources should include "error_code.h" explicitly to use the enums. Test: lunch aosp_{angler,bullhead,dragon,fugu,sailfish}-userdebug; mmma bootable/recovery Change-Id: Ic82db2746c7deb866e8cdfb3c57e0b1ecc71c4dc --- edify/expr.cpp | 9 ++++----- edify/expr.h | 38 ++++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 23 deletions(-) (limited to 'edify') diff --git a/edify/expr.cpp b/edify/expr.cpp index 54ab3325c..403162d6d 100644 --- a/edify/expr.cpp +++ b/edify/expr.cpp @@ -31,6 +31,8 @@ #include #include +#include "error_code.h" + // Functions should: // // - return a malloc()'d string @@ -416,8 +418,5 @@ Value* ErrorAbort(State* state, CauseCode cause_code, const char* format, ...) { return nullptr; } -State::State(const std::string& script, void* cookie) : - script(script), - cookie(cookie) { -} - +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/expr.h index 4838d20c0..32828028a 100644 --- a/edify/expr.h +++ b/edify/expr.h @@ -23,32 +23,34 @@ #include #include -#include "error_code.h" +// Forward declaration to avoid including "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 { -- cgit v1.2.3 From 38d78d19b9482e7bbad756f0cdbf533cbb52a8f8 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 9 Oct 2017 11:03:38 -0700 Subject: applypatch: Forward declare struct Value. And move '#include "edify/expr.h"' into .cpp files. This breaks the transitive dependency on libedify. Modules that include "applypatch/applypatch.h" don't need to add libedify into their dependency list, unless they really need anything from libedify. Build libedify static library for host, which is needed by libimgpatch. Test: mmma bootable/recovery Change-Id: Ibb53d322579fcbf593438d058d9bcee240625941 --- edify/Android.mk | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'edify') diff --git a/edify/Android.mk b/edify/Android.mk index cec65f42a..fbf2b1b06 100644 --- a/edify/Android.mk +++ b/edify/Android.mk @@ -34,3 +34,19 @@ LOCAL_C_INCLUDES += $(LOCAL_PATH)/.. LOCAL_STATIC_LIBRARIES += libbase include $(BUILD_STATIC_LIBRARY) + +# +# Build the host-side library (static library) +# +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := $(edify_src_files) + +LOCAL_CFLAGS := -Wall -Werror +LOCAL_CPPFLAGS := -Wno-unused-parameter +LOCAL_CPPFLAGS += -Wno-deprecated-register +LOCAL_MODULE := libedify +LOCAL_C_INCLUDES += $(LOCAL_PATH)/.. +LOCAL_STATIC_LIBRARIES += libbase + +include $(BUILD_HOST_STATIC_LIBRARY) -- cgit v1.2.3 From 1fc5bf353a8719d16fd9ba29a661d211bad4038f Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Fri, 6 Oct 2017 07:43:41 -0700 Subject: Revert "Revert "Move error_code.h into otautil."" This reverts commit 26436d6d6010d5323349af7e119ff8f34f85c40c to re-land "Move error_code.h into otautil.". This way it stops requiring relative path ".." in LOCAL_C_INCLUDES (uncrypt and edify). Soong doesn't accept non-local ".." in "local_include_dirs". This CL needs to land with device-specific module changes (e.g. adding the dependency on libotautil). Test: lunch aosp_{angler,bullhead,dragon,fugu,sailfish}-userdebug; mmma bootable/recovery Change-Id: If193241801af2dae73eccd31ce57cd2b81c9fd96 --- edify/Android.mk | 5 +++-- edify/expr.cpp | 2 +- edify/expr.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'edify') diff --git a/edify/Android.mk b/edify/Android.mk index fbf2b1b06..527698e68 100644 --- a/edify/Android.mk +++ b/edify/Android.mk @@ -30,8 +30,9 @@ LOCAL_CFLAGS := -Wall -Werror LOCAL_CPPFLAGS := -Wno-unused-parameter LOCAL_CPPFLAGS += -Wno-deprecated-register LOCAL_MODULE := libedify -LOCAL_C_INCLUDES += $(LOCAL_PATH)/.. -LOCAL_STATIC_LIBRARIES += libbase +LOCAL_STATIC_LIBRARIES += \ + libotautil \ + libbase include $(BUILD_STATIC_LIBRARY) diff --git a/edify/expr.cpp b/edify/expr.cpp index 403162d6d..104c0fd90 100644 --- a/edify/expr.cpp +++ b/edify/expr.cpp @@ -31,7 +31,7 @@ #include #include -#include "error_code.h" +#include "otautil/error_code.h" // Functions should: // diff --git a/edify/expr.h b/edify/expr.h index 32828028a..770d1cf0d 100644 --- a/edify/expr.h +++ b/edify/expr.h @@ -23,7 +23,7 @@ #include #include -// Forward declaration to avoid including "error_code.h". +// Forward declaration to avoid including "otautil/error_code.h". enum ErrorCode : int; enum CauseCode : int; -- cgit v1.2.3 From e6f7f95d3493b47514a6104e11d206a455a6433e Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Wed, 4 Oct 2017 09:33:01 -0700 Subject: edify: Export the header and move to Soong. Also make matching changes to applypatch modules which include edify/expr.h. Test: mmma bootable/recovery Change-Id: Ia72be3caa010d7f56a70add2da345e631b306378 --- edify/Android.bp | 45 +++++++++++++ edify/Android.mk | 53 --------------- edify/expr.cpp | 2 +- edify/expr.h | 161 --------------------------------------------- edify/include/edify/expr.h | 161 +++++++++++++++++++++++++++++++++++++++++++++ edify/lexer.ll | 2 +- edify/parser.yy | 2 +- 7 files changed, 209 insertions(+), 217 deletions(-) create mode 100644 edify/Android.bp delete mode 100644 edify/Android.mk delete mode 100644 edify/expr.h create mode 100644 edify/include/edify/expr.h (limited to 'edify') 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/Android.mk b/edify/Android.mk deleted file mode 100644 index 527698e68..000000000 --- a/edify/Android.mk +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright 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. - -LOCAL_PATH := $(call my-dir) - -edify_src_files := \ - lexer.ll \ - parser.yy \ - expr.cpp - -# -# Build the device-side library (static library) -# -include $(CLEAR_VARS) - -LOCAL_SRC_FILES := $(edify_src_files) - -LOCAL_CFLAGS := -Wall -Werror -LOCAL_CPPFLAGS := -Wno-unused-parameter -LOCAL_CPPFLAGS += -Wno-deprecated-register -LOCAL_MODULE := libedify -LOCAL_STATIC_LIBRARIES += \ - libotautil \ - libbase - -include $(BUILD_STATIC_LIBRARY) - -# -# Build the host-side library (static library) -# -include $(CLEAR_VARS) - -LOCAL_SRC_FILES := $(edify_src_files) - -LOCAL_CFLAGS := -Wall -Werror -LOCAL_CPPFLAGS := -Wno-unused-parameter -LOCAL_CPPFLAGS += -Wno-deprecated-register -LOCAL_MODULE := libedify -LOCAL_C_INCLUDES += $(LOCAL_PATH)/.. -LOCAL_STATIC_LIBRARIES += libbase - -include $(BUILD_HOST_STATIC_LIBRARY) diff --git a/edify/expr.cpp b/edify/expr.cpp index 104c0fd90..1b8623f03 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 #include diff --git a/edify/expr.h b/edify/expr.h deleted file mode 100644 index 770d1cf0d..000000000 --- a/edify/expr.h +++ /dev/null @@ -1,161 +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. - */ - -#ifndef _EXPRESSION_H -#define _EXPRESSION_H - -#include - -#include -#include -#include - -// Forward declaration to avoid including "otautil/error_code.h". -enum ErrorCode : int; -enum CauseCode : int; - -struct State { - State(const std::string& script, void* cookie); - - // 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; - - // 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; - - // 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; -}; - -enum ValueType { - VAL_INVALID = -1, - VAL_STRING = 1, - VAL_BLOB = 2, -}; - -struct Value { - ValueType type; - std::string data; - - Value(ValueType type, const std::string& str) : - type(type), - data(str) {} -}; - -struct Expr; - -using Function = Value* (*)(const char* name, State* state, - const std::vector>& argv); - -struct Expr { - Function fn; - std::string name; - std::vector> argv; - int start, end; - - Expr(Function fn, const std::string& name, int start, int end) : - fn(fn), - name(name), - start(start), - end(end) {} -}; - -// Evaluate the input expr, return the resulting Value. -Value* EvaluateValue(State* state, const std::unique_ptr& expr); - -// Evaluate the input expr, assert that it is a string, and update the result parameter. This -// function returns true if the evaluation succeeds. This is a convenience function for older -// functions that want to deal only with strings. -bool Evaluate(State* state, const std::unique_ptr& expr, std::string* result); - -// Glue to make an Expr out of a literal. -Value* Literal(const char* name, State* state, const std::vector>& argv); - -// Functions corresponding to various syntactic sugar operators. -// ("concat" is also available as a builtin function, to concatenate -// more than two strings.) -Value* ConcatFn(const char* name, State* state, const std::vector>& argv); -Value* LogicalAndFn(const char* name, State* state, const std::vector>& argv); -Value* LogicalOrFn(const char* name, State* state, const std::vector>& argv); -Value* LogicalNotFn(const char* name, State* state, const std::vector>& argv); -Value* SubstringFn(const char* name, State* state, const std::vector>& argv); -Value* EqualityFn(const char* name, State* state, const std::vector>& argv); -Value* InequalityFn(const char* name, State* state, const std::vector>& argv); -Value* SequenceFn(const char* name, State* state, const std::vector>& argv); - -// Global builtins, registered by RegisterBuiltins(). -Value* IfElseFn(const char* name, State* state, const std::vector>& argv); -Value* AssertFn(const char* name, State* state, const std::vector>& argv); -Value* AbortFn(const char* name, State* state, const std::vector>& argv); - -// Register a new function. The same Function may be registered under -// multiple names, but a given name should only be used once. -void RegisterFunction(const std::string& name, Function fn); - -// Register all the builtins. -void RegisterBuiltins(); - -// Find the Function for a given name; return NULL if no such function -// exists. -Function FindFunction(const std::string& name); - -// --- convenience functions for use in functions --- - -// Evaluate the expressions in argv, and put the results of strings in args. If any expression -// evaluates to nullptr, return false. Return true on success. -bool ReadArgs(State* state, const std::vector>& argv, - std::vector* args); -bool ReadArgs(State* state, const std::vector>& argv, - std::vector* args, size_t start, size_t len); - -// Evaluate the expressions in argv, and put the results of Value* in args. If any -// expression evaluate to nullptr, return false. Return true on success. -bool ReadValueArgs(State* state, const std::vector>& argv, - std::vector>* args); -bool ReadValueArgs(State* state, const std::vector>& argv, - std::vector>* args, size_t start, size_t len); - -// Use printf-style arguments to compose an error message to put into -// *state. Returns NULL. -Value* ErrorAbort(State* state, const char* format, ...) - __attribute__((format(printf, 2, 3), deprecated)); - -// ErrorAbort has an optional (but recommended) argument 'cause_code'. If the cause code -// is set, it will be logged into last_install and provides reason of OTA failures. -Value* ErrorAbort(State* state, CauseCode cause_code, const char* format, ...) - __attribute__((format(printf, 3, 4))); - -// Copying the string into a Value. -Value* StringValue(const char* str); - -Value* StringValue(const std::string& str); - -int parse_string(const char* str, std::unique_ptr* root, int* error_count); - -#endif // _EXPRESSION_H diff --git a/edify/include/edify/expr.h b/edify/include/edify/expr.h new file mode 100644 index 000000000..770d1cf0d --- /dev/null +++ b/edify/include/edify/expr.h @@ -0,0 +1,161 @@ +/* + * 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. + */ + +#ifndef _EXPRESSION_H +#define _EXPRESSION_H + +#include + +#include +#include +#include + +// Forward declaration to avoid including "otautil/error_code.h". +enum ErrorCode : int; +enum CauseCode : int; + +struct State { + State(const std::string& script, void* cookie); + + // 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; + + // 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; + + // 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; +}; + +enum ValueType { + VAL_INVALID = -1, + VAL_STRING = 1, + VAL_BLOB = 2, +}; + +struct Value { + ValueType type; + std::string data; + + Value(ValueType type, const std::string& str) : + type(type), + data(str) {} +}; + +struct Expr; + +using Function = Value* (*)(const char* name, State* state, + const std::vector>& argv); + +struct Expr { + Function fn; + std::string name; + std::vector> argv; + int start, end; + + Expr(Function fn, const std::string& name, int start, int end) : + fn(fn), + name(name), + start(start), + end(end) {} +}; + +// Evaluate the input expr, return the resulting Value. +Value* EvaluateValue(State* state, const std::unique_ptr& expr); + +// Evaluate the input expr, assert that it is a string, and update the result parameter. This +// function returns true if the evaluation succeeds. This is a convenience function for older +// functions that want to deal only with strings. +bool Evaluate(State* state, const std::unique_ptr& expr, std::string* result); + +// Glue to make an Expr out of a literal. +Value* Literal(const char* name, State* state, const std::vector>& argv); + +// Functions corresponding to various syntactic sugar operators. +// ("concat" is also available as a builtin function, to concatenate +// more than two strings.) +Value* ConcatFn(const char* name, State* state, const std::vector>& argv); +Value* LogicalAndFn(const char* name, State* state, const std::vector>& argv); +Value* LogicalOrFn(const char* name, State* state, const std::vector>& argv); +Value* LogicalNotFn(const char* name, State* state, const std::vector>& argv); +Value* SubstringFn(const char* name, State* state, const std::vector>& argv); +Value* EqualityFn(const char* name, State* state, const std::vector>& argv); +Value* InequalityFn(const char* name, State* state, const std::vector>& argv); +Value* SequenceFn(const char* name, State* state, const std::vector>& argv); + +// Global builtins, registered by RegisterBuiltins(). +Value* IfElseFn(const char* name, State* state, const std::vector>& argv); +Value* AssertFn(const char* name, State* state, const std::vector>& argv); +Value* AbortFn(const char* name, State* state, const std::vector>& argv); + +// Register a new function. The same Function may be registered under +// multiple names, but a given name should only be used once. +void RegisterFunction(const std::string& name, Function fn); + +// Register all the builtins. +void RegisterBuiltins(); + +// Find the Function for a given name; return NULL if no such function +// exists. +Function FindFunction(const std::string& name); + +// --- convenience functions for use in functions --- + +// Evaluate the expressions in argv, and put the results of strings in args. If any expression +// evaluates to nullptr, return false. Return true on success. +bool ReadArgs(State* state, const std::vector>& argv, + std::vector* args); +bool ReadArgs(State* state, const std::vector>& argv, + std::vector* args, size_t start, size_t len); + +// Evaluate the expressions in argv, and put the results of Value* in args. If any +// expression evaluate to nullptr, return false. Return true on success. +bool ReadValueArgs(State* state, const std::vector>& argv, + std::vector>* args); +bool ReadValueArgs(State* state, const std::vector>& argv, + std::vector>* args, size_t start, size_t len); + +// Use printf-style arguments to compose an error message to put into +// *state. Returns NULL. +Value* ErrorAbort(State* state, const char* format, ...) + __attribute__((format(printf, 2, 3), deprecated)); + +// ErrorAbort has an optional (but recommended) argument 'cause_code'. If the cause code +// is set, it will be logged into last_install and provides reason of OTA failures. +Value* ErrorAbort(State* state, CauseCode cause_code, const char* format, ...) + __attribute__((format(printf, 3, 4))); + +// Copying the string into a Value. +Value* StringValue(const char* str); + +Value* StringValue(const std::string& str); + +int parse_string(const char* str, std::unique_ptr* root, int* error_count); + +#endif // _EXPRESSION_H diff --git a/edify/lexer.ll b/edify/lexer.ll index cb4594371..4e04003b1 100644 --- a/edify/lexer.ll +++ b/edify/lexer.ll @@ -18,7 +18,7 @@ #include #include -#include "expr.h" +#include "edify/expr.h" #include "yydefs.h" #include "parser.h" 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 -#include "expr.h" +#include "edify/expr.h" #include "yydefs.h" #include "parser.h" -- cgit v1.2.3 From 5ad802839d84f7bcdfbb8aa5c48cb56b303ce5f0 Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Sun, 28 Jan 2018 15:37:48 -0800 Subject: Avoid overwrite of the error message in AbortFn The AbortFn() used to overwrite the error message, hiding the real failure reported in ErrorAbort(). And we will miss the failure in the script patterns like 'blockimageupdate() || abort()' We will ensure there's one line break at the end of ErrorAbort's error message; and append to the existing error message when calling abort(). Test: Message from ErrorAbort shows up in the log Change-Id: I3aebd06629c5129330250c7fe5e8cdead2ae85bc --- edify/expr.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'edify') diff --git a/edify/expr.cpp b/edify/expr.cpp index 1b8623f03..6823b7339 100644 --- a/edify/expr.cpp +++ b/edify/expr.cpp @@ -114,9 +114,9 @@ Value* IfElseFn(const char* name, State* state, const std::vector>& 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; } @@ -410,12 +410,15 @@ 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; + 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) -- cgit v1.2.3