aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2018-02-28 08:25:37 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2018-02-28 08:25:37 +0000
commit17da287661100ee95f6f7b16c86afbdd78243dc5 (patch)
tree50dc0ba49533e72d89b1976e4db885c1262af993
parent9993f4594d5f8508bc883192bd741f78d8b68589 (diff)
parentec7c40a97a07acadd78d93dd8d9f2c8d361513ef (diff)
downloadkati-pie-s2-release.tar.gz
Snap for 4625912 from ec7c40a97a07acadd78d93dd8d9f2c8d361513ef to pi-releaseandroid-wear-9.0.0_r9android-wear-9.0.0_r8android-wear-9.0.0_r7android-wear-9.0.0_r6android-wear-9.0.0_r5android-wear-9.0.0_r4android-wear-9.0.0_r34android-wear-9.0.0_r33android-wear-9.0.0_r32android-wear-9.0.0_r31android-wear-9.0.0_r30android-wear-9.0.0_r3android-wear-9.0.0_r29android-wear-9.0.0_r28android-wear-9.0.0_r27android-wear-9.0.0_r26android-wear-9.0.0_r25android-wear-9.0.0_r24android-wear-9.0.0_r23android-wear-9.0.0_r22android-wear-9.0.0_r21android-wear-9.0.0_r20android-wear-9.0.0_r2android-wear-9.0.0_r19android-wear-9.0.0_r18android-wear-9.0.0_r17android-wear-9.0.0_r16android-wear-9.0.0_r15android-wear-9.0.0_r14android-wear-9.0.0_r13android-wear-9.0.0_r12android-wear-9.0.0_r11android-wear-9.0.0_r10android-wear-9.0.0_r1android-vts-9.0_r9android-vts-9.0_r8android-vts-9.0_r7android-vts-9.0_r6android-vts-9.0_r5android-vts-9.0_r4android-vts-9.0_r19android-vts-9.0_r18android-vts-9.0_r17android-vts-9.0_r16android-vts-9.0_r15android-vts-9.0_r14android-vts-9.0_r13android-vts-9.0_r12android-vts-9.0_r11android-vts-9.0_r10android-security-9.0.0_r76android-security-9.0.0_r75android-security-9.0.0_r74android-security-9.0.0_r73android-security-9.0.0_r72android-security-9.0.0_r71android-security-9.0.0_r70android-security-9.0.0_r69android-security-9.0.0_r68android-security-9.0.0_r67android-security-9.0.0_r66android-security-9.0.0_r65android-security-9.0.0_r64android-security-9.0.0_r63android-security-9.0.0_r62android-cts-9.0_r9android-cts-9.0_r8android-cts-9.0_r7android-cts-9.0_r6android-cts-9.0_r5android-cts-9.0_r4android-cts-9.0_r3android-cts-9.0_r20android-cts-9.0_r2android-cts-9.0_r19android-cts-9.0_r18android-cts-9.0_r17android-cts-9.0_r16android-cts-9.0_r15android-cts-9.0_r14android-cts-9.0_r13android-cts-9.0_r12android-cts-9.0_r11android-cts-9.0_r10android-cts-9.0_r1android-9.0.0_r9android-9.0.0_r8android-9.0.0_r7android-9.0.0_r61android-9.0.0_r60android-9.0.0_r6android-9.0.0_r59android-9.0.0_r58android-9.0.0_r57android-9.0.0_r56android-9.0.0_r55android-9.0.0_r54android-9.0.0_r53android-9.0.0_r52android-9.0.0_r51android-9.0.0_r50android-9.0.0_r5android-9.0.0_r49android-9.0.0_r48android-9.0.0_r3android-9.0.0_r2android-9.0.0_r18android-9.0.0_r17android-9.0.0_r10android-9.0.0_r1security-pi-releasepie-vts-releasepie-security-releasepie-s2-releasepie-release-2pie-releasepie-r2-s2-releasepie-r2-s1-releasepie-r2-releasepie-cts-release
Change-Id: Id765db19513c222ef36fb5b16bd3277612fc53b4
-rw-r--r--eval.cc24
-rw-r--r--eval.h14
-rw-r--r--func.cc32
-rw-r--r--testcase/deprecated_export.mk21
-rw-r--r--testcase/err_obsolete_export.mk7
5 files changed, 95 insertions, 3 deletions
diff --git a/eval.cc b/eval.cc
index cf3f859..fa7bebb 100644
--- a/eval.cc
+++ b/eval.cc
@@ -38,6 +38,7 @@ Evaluator::Evaluator()
eval_depth_(0),
posix_sym_(Intern(".POSIX")),
is_posix_(false),
+ export_error_(false),
kati_readonly_(Intern(".KATI_READONLY")) {
#if defined(__APPLE__)
stack_size_ = pthread_get_stacksize_np(pthread_self());
@@ -358,18 +359,35 @@ void Evaluator::EvalExport(const ExportStmt* stmt) {
const string&& exports = stmt->expr->Eval(this);
for (StringPiece tok : WordScanner(exports)) {
size_t equal_index = tok.find('=');
+ StringPiece lhs;
if (equal_index == string::npos) {
- exports_[Intern(tok)] = stmt->is_export;
+ lhs = tok;
} else if (equal_index == 0 ||
(equal_index == 1 &&
(tok[0] == ':' || tok[0] == '?' || tok[0] == '+'))) {
// Do not export tokens after an assignment.
break;
} else {
- StringPiece lhs, rhs;
+ StringPiece rhs;
AssignOp op;
ParseAssignStatement(tok, equal_index, &lhs, &rhs, &op);
- exports_[Intern(lhs)] = stmt->is_export;
+ }
+ Symbol sym = Intern(lhs);
+ exports_[sym] = stmt->is_export;
+
+ if (export_message_) {
+ const char* prefix = "";
+ if (!stmt->is_export) {
+ prefix = "un";
+ }
+
+ if (export_error_) {
+ Error(StringPrintf("*** %s: %sexport is obsolete%s.", sym.c_str(),
+ prefix, export_message_->c_str()));
+ } else {
+ WARN_LOC(loc(), "%s: %sexport has been deprecated%s.", sym.c_str(),
+ prefix, export_message_->c_str());
+ }
}
}
}
diff --git a/eval.h b/eval.h
index e588f7e..4fb5f05 100644
--- a/eval.h
+++ b/eval.h
@@ -15,6 +15,7 @@
#ifndef EVAL_H_
#define EVAL_H_
+#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <vector>
@@ -98,6 +99,16 @@ class Evaluator {
}
void DumpStackStats() const;
+ bool ExportDeprecated() const { return export_message_ && !export_error_; };
+ bool ExportObsolete() const { return export_error_; };
+ void SetExportDeprecated(StringPiece msg) {
+ export_message_.reset(new string(msg.as_string()));
+ }
+ void SetExportObsolete(StringPiece msg) {
+ export_message_.reset(new string(msg.as_string()));
+ export_error_ = true;
+ }
+
private:
Var* EvalRHS(Symbol lhs,
Value* rhs,
@@ -139,6 +150,9 @@ class Evaluator {
void* lowest_stack_;
Loc lowest_loc_;
+ unique_ptr<string> export_message_;
+ bool export_error_;
+
static unordered_set<Symbol> used_undefined_vars_;
Symbol kati_readonly_;
diff --git a/func.cc b/func.cc
index 1dea7bb..c033d3b 100644
--- a/func.cc
+++ b/func.cc
@@ -892,6 +892,36 @@ void ObsoleteVarFunc(const vector<Value*>& args, Evaluator* ev, string*) {
}
}
+void DeprecateExportFunc(const vector<Value*>& args, Evaluator* ev, string*) {
+ string msg = ". " + args[0]->Eval(ev);
+
+ if (ev->avoid_io()) {
+ ev->Error("*** $(KATI_deprecate_export) is not supported in rules.");
+ }
+
+ if (ev->ExportObsolete()) {
+ ev->Error("*** Export is already obsolete.");
+ } else if (ev->ExportDeprecated()) {
+ ev->Error("*** Export is already deprecated.");
+ }
+
+ ev->SetExportDeprecated(msg);
+}
+
+void ObsoleteExportFunc(const vector<Value*>& args, Evaluator* ev, string*) {
+ string msg = ". " + args[0]->Eval(ev);
+
+ if (ev->avoid_io()) {
+ ev->Error("*** $(KATI_obsolete_export) is not supported in rules.");
+ }
+
+ if (ev->ExportObsolete()) {
+ ev->Error("*** Export is already obsolete.");
+ }
+
+ ev->SetExportObsolete(msg);
+}
+
FuncInfo g_func_infos[] = {
{"patsubst", &PatsubstFunc, 3, 3, false, false},
{"strip", &StripFunc, 1, 1, false, false},
@@ -939,6 +969,8 @@ FuncInfo g_func_infos[] = {
/* Kati custom extension functions */
{"KATI_deprecated_var", &DeprecatedVarFunc, 2, 1, false, false},
{"KATI_obsolete_var", &ObsoleteVarFunc, 2, 1, false, false},
+ {"KATI_deprecate_export", &DeprecateExportFunc, 1, 1, false, false},
+ {"KATI_obsolete_export", &ObsoleteExportFunc, 1, 1, false, false},
};
unordered_map<StringPiece, FuncInfo*>* g_func_info_map;
diff --git a/testcase/deprecated_export.mk b/testcase/deprecated_export.mk
new file mode 100644
index 0000000..3744f70
--- /dev/null
+++ b/testcase/deprecated_export.mk
@@ -0,0 +1,21 @@
+# TODO(go): not implemented
+
+A := 1
+B := 2
+export A B
+
+$(KATI_deprecate_export Message)
+
+export C := ok
+unexport B
+
+ifndef KATI
+$(info Makefile:9: C: export has been deprecated. Message.)
+$(info Makefile:10: B: unexport has been deprecated. Message.)
+endif
+
+test:
+ echo $$(A)
+ echo $$(B)
+ echo $$(C)
+ echo Done
diff --git a/testcase/err_obsolete_export.mk b/testcase/err_obsolete_export.mk
new file mode 100644
index 0000000..bf78dc3
--- /dev/null
+++ b/testcase/err_obsolete_export.mk
@@ -0,0 +1,7 @@
+# TODO(go): not implemented
+
+export A := ok
+
+$(KATI_obsolete_export Message)
+
+export B := fail $(or $(KATI),$(error B: export is obsolete. Message))