Do not allow package with missing version
e.g. android.hardware.foo::IFoo is not allowed.
Also, the regex rules in hidl-gen_l.ll and in FQName.cpp
was not consistent (optional version in hidl-gen_l.ll but
only minor version is optional in hidl-gen_y.yy). Hence
android.hardware.foo::IFoo has always been not allowed.
Still, the "?" is removed in both to make the rules consistent,
and there are explict checks in FQName::setTo and
FQName::applyDefaults to prevent this.
Test: compiles with mma
Change-Id: I9fd0a474c0313ab7c86c37f58f081a2c5a9b559c
diff --git a/FQName.cpp b/FQName.cpp
index 07eb219..99e9f9a 100644
--- a/FQName.cpp
+++ b/FQName.cpp
@@ -27,16 +27,25 @@
#define RE_MAJOR "[0-9]+"
#define RE_MINOR "[0-9]+"
-static const std::regex kRE1("(" RE_PATH ")@(" RE_MAJOR ")[.](" RE_MINOR ")?::(" RE_PATH ")");
+// android.hardware.foo@1.0::IFoo.Type
+static const std::regex kRE1("(" RE_PATH ")@(" RE_MAJOR ")[.](" RE_MINOR ")::(" RE_PATH ")");
+// @1.0::IFoo.Type
static const std::regex kRE2("@(" RE_MAJOR ")[.](" RE_MINOR ")::(" RE_PATH ")");
+// android.hardware.foo@1.0 (for package declaration and whole package import)
static const std::regex kRE3("(" RE_PATH ")@(" RE_MAJOR ")[.](" RE_MINOR ")");
+// IFoo.Type
static const std::regex kRE4("(" RE_COMPONENT ")([.]" RE_COMPONENT ")+");
+// Type (a plain identifier)
static const std::regex kRE5("(" RE_COMPONENT ")");
-static const std::regex kRE6("(" RE_PATH ")@(" RE_MAJOR ")[.](" RE_MINOR ")?::(" RE_PATH "):(" RE_COMPONENT ")");
+// android.hardware.foo@1.0::IFoo.Type:MY_ENUM_VALUE
+static const std::regex kRE6("(" RE_PATH ")@(" RE_MAJOR ")[.](" RE_MINOR ")::(" RE_PATH "):(" RE_COMPONENT ")");
+// @1.0::IFoo.Type:MY_ENUM_VALUE
static const std::regex kRE7("@(" RE_MAJOR ")[.](" RE_MINOR ")::(" RE_PATH "):(" RE_COMPONENT ")");
+// IFoo.Type:MY_ENUM_VALUE
static const std::regex kRE8("(" RE_PATH "):(" RE_COMPONENT ")");
+// 1.0
static const std::regex kREVer("(" RE_MAJOR ")[.](" RE_MINOR ")");
namespace android {
@@ -156,9 +165,10 @@
}
// mValueName must go with mName.
- if (!mValueName.empty()) {
- CHECK(!mName.empty());
- }
+ CHECK(mValueName.empty() || !mName.empty());
+
+ // package without version is not allowed.
+ CHECK(mPackage.empty() || !version().empty());
return isValid();
}
@@ -230,6 +240,10 @@
void FQName::applyDefaults(
const std::string &defaultPackage,
const std::string &defaultVersion) {
+
+ // package without version is not allowed.
+ CHECK(mPackage.empty() || !version().empty());
+
if (mPackage.empty()) {
mPackage = defaultPackage;
}