add -W<warning>/-Werror CLI options
-Weverything: enable all diagnotics
-Wfoo: enable "foo"
-Wno-foo: disable "foo"
-Werror: turn diagnostic warnings into errors
-Wno-error=foo: turn "foo" into a warning
For now, only -Winterface-name is available, which checks if interface
names start with "I".
Bug: 168028537
Test: aidl_unittests
Change-Id: I31516b337dd80b9833205bf769af40e49f88d15d
diff --git a/options.h b/options.h
index 554d1cd..08f0fdf 100644
--- a/options.h
+++ b/options.h
@@ -15,11 +15,14 @@
#pragma once
+#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
+#include "diagnostics.h"
+
namespace android {
namespace aidl {
@@ -57,6 +60,26 @@
}
};
+class WarningOptions {
+ public:
+ std::vector<const char*> Parse(int argc, const char* const argv[], ErrorMessage& error_message);
+ DiagnosticSeverity Severity(DiagnosticID id) const;
+
+ private:
+ bool as_errors_ = false; // -Werror
+ bool enable_all_ = false; // -Weverything
+ bool disable_all_ = false; // -w
+ std::set<std::string> enabled_; // -Wfoo
+ std::set<std::string> disabled_; // -Wno-foo
+ std::set<std::string> no_errors_; // -Wno-error=foo
+
+ struct Mapping {
+ std::string name;
+ DiagnosticSeverity severity;
+ };
+ std::map<DiagnosticID, Mapping> mapping_;
+};
+
class Options final {
public:
enum class Language { UNSPECIFIED, JAVA, CPP, NDK, RUST };
@@ -135,6 +158,8 @@
static const string LanguageToString(Language language);
+ const WarningOptions& GetWarningOptions() const { return warning_options_; }
+
// The following are for testability, but cannot be influenced on the command line.
// Threshold of interface methods to enable outlining of onTransact cases.
size_t onTransact_outline_threshold_{275u};
@@ -166,6 +191,7 @@
string hash_ = "";
bool gen_log_ = false;
ErrorMessage error_message_;
+ WarningOptions warning_options_;
};
} // namespace aidl