summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Wiley <wiley@google.com>2015-08-03 19:37:03 -0700
committerChristopher Wiley <wiley@google.com>2015-08-12 12:28:04 -0700
commita30e09dde8bde67a44a2275b58d3f9d058207e57 (patch)
tree90d0373df776417105219f2de31157cbbb1f892e
parent464405e052175cd0421742a917d0a69cab46a89d (diff)
downloaddbus-binding-generator-a30e09dde8bde67a44a2275b58d3f9d058207e57.tar.gz
chromeos-dbus-bindings: Literal proxy includes for mocks
(cherry-pick of platform2 5b6ba1c6b8140d3d4e069d9afcdabdfb3a5669ce) Change the DBus binding generator to accept a flag --proxy-path-in-mocks which takes the literal path to include the proxy header at. This works around some behavior where the generator would attempt to infer this path by constructing a relative path from the mock path to the proxy file path. This breaks when we install the mock headers to the build root, rather than using them from where they were generated. BUG=chromium:516514 TEST=unittests, trybots Change-Id: I96c7429cc4344bd9a3764efb09b2f014dd2420ac Reviewed-on: https://chromium-review.googlesource.com/290448 Reviewed-by: Alex Vakulenko <avakulenko@chromium.org> Tested-by: Christopher Wiley <wiley@chromium.org> Commit-Queue: Christopher Wiley <wiley@chromium.org>
-rw-r--r--chromeos-dbus-bindings/generate_chromeos_dbus_bindings.cc13
-rw-r--r--chromeos-dbus-bindings/proxy_generator.cc73
-rw-r--r--chromeos-dbus-bindings/proxy_generator.h3
-rw-r--r--chromeos-dbus-bindings/proxy_generator_mock_unittest.cc2
4 files changed, 55 insertions, 36 deletions
diff --git a/chromeos-dbus-bindings/generate_chromeos_dbus_bindings.cc b/chromeos-dbus-bindings/generate_chromeos_dbus_bindings.cc
index dd67a3c..8789b82 100644
--- a/chromeos-dbus-bindings/generate_chromeos_dbus_bindings.cc
+++ b/chromeos-dbus-bindings/generate_chromeos_dbus_bindings.cc
@@ -31,6 +31,7 @@ static const char kMethodNames[] = "method-names";
static const char kAdaptor[] = "adaptor";
static const char kProxy[] = "proxy";
static const char kMock[] = "mock";
+static const char kProxyPathForMocks[] = "proxy-path-in-mocks";
static const char kServiceConfig[] = "service-config";
static const char kHelpMessage[] = "\n"
"generate-chromeos-dbus-bindings itf1.xml [itf2.xml...] [switches]\n"
@@ -199,13 +200,23 @@ int main(int argc, char** argv) {
}
}
+ base::FilePath proxy_include_path = proxy_path;
+ bool use_literal_include_path = false;
+ if (cl->HasSwitch(switches::kProxyPathForMocks)) {
+ std::string proxy_file_in_mocks =
+ cl->GetSwitchValueASCII(switches::kProxyPathForMocks);
+ proxy_include_path = RemoveQuotes(proxy_file_in_mocks);
+ use_literal_include_path = true;
+ }
+
if (cl->HasSwitch(switches::kMock)) {
std::string mock_file = cl->GetSwitchValueASCII(switches::kMock);
base::FilePath mock_path = RemoveQuotes(mock_file);
base::NormalizeFilePath(mock_path, &mock_path);
VLOG(1) << "Outputting mock to " << mock_path.value();
if (!ProxyGenerator::GenerateMocks(config, parser.interfaces(), mock_path,
- proxy_path)) {
+ proxy_include_path,
+ use_literal_include_path)) {
LOG(ERROR) << "Failed to output mock.";
return 1;
}
diff --git a/chromeos-dbus-bindings/proxy_generator.cc b/chromeos-dbus-bindings/proxy_generator.cc
index b40aabd..717740d 100644
--- a/chromeos-dbus-bindings/proxy_generator.cc
+++ b/chromeos-dbus-bindings/proxy_generator.cc
@@ -102,7 +102,8 @@ bool ProxyGenerator::GenerateProxies(
bool ProxyGenerator::GenerateMocks(const ServiceConfig& config,
const std::vector<Interface>& interfaces,
const base::FilePath& mock_file,
- const base::FilePath& proxy_file) {
+ const base::FilePath& proxy_file,
+ bool use_literal_proxy_file) {
IndentedText text;
text.AddLine("// Automatic generation of D-Bus interface mock proxies for:");
@@ -127,38 +128,44 @@ bool ProxyGenerator::GenerateMocks(const ServiceConfig& config,
if (!proxy_file.empty()) {
// If we have a proxy header file, it would have the proxy interfaces we
// need to base our mocks on, so we need to include that header file.
- // Generate a relative path from |mock_file| to |proxy_file|.
-
- // First, get the path components for both source and destination paths.
- std::vector<base::FilePath::StringType> src_components;
- mock_file.DirName().GetComponents(&src_components);
- std::vector<base::FilePath::StringType> dest_components;
- proxy_file.DirName().GetComponents(&dest_components);
-
- // Find the common root.
-
- // I wish we had C++14 and its 4-parameter version of std::mismatch()...
- auto src_end = src_components.end();
- if (src_components.size() > dest_components.size())
- src_end = src_components.begin() + dest_components.size();
-
- auto mismatch_pair =
- std::mismatch(src_components.begin(), src_end, dest_components.begin());
-
- // For each remaining components in the |src_components|, generate the
- // parent directory references ("..").
- size_t src_count = std::distance(mismatch_pair.first, src_components.end());
- std::vector<base::FilePath::StringType> components{
- src_count, base::FilePath::kParentDirectory};
- // Append the remaining components from |dest_components|.
- components.insert(components.end(),
- mismatch_pair.second, dest_components.end());
- // Finally, add the base name of the target file name.
- components.push_back(proxy_file.BaseName().value());
- // Now reconstruct the relative path.
- base::FilePath relative_path{base::FilePath::kCurrentDirectory};
- for (const auto& component : components)
- relative_path = relative_path.Append(component);
+ base::FilePath relative_path;
+ if (use_literal_proxy_file) {
+ relative_path = proxy_file;
+ } else {
+ // Generate a relative path from |mock_file| to |proxy_file|.
+
+ // First, get the path components for both source and destination paths.
+ std::vector<base::FilePath::StringType> src_components;
+ mock_file.DirName().GetComponents(&src_components);
+ std::vector<base::FilePath::StringType> dest_components;
+ proxy_file.DirName().GetComponents(&dest_components);
+
+ // Find the common root.
+
+ // I wish we had C++14 and its 4-parameter version of std::mismatch()...
+ auto src_end = src_components.end();
+ if (src_components.size() > dest_components.size())
+ src_end = src_components.begin() + dest_components.size();
+
+ auto mismatch_pair = std::mismatch(src_components.begin(), src_end,
+ dest_components.begin());
+
+ // For each remaining components in the |src_components|, generate the
+ // parent directory references ("..").
+ size_t src_count = std::distance(mismatch_pair.first,
+ src_components.end());
+ std::vector<base::FilePath::StringType> components{
+ src_count, base::FilePath::kParentDirectory};
+ // Append the remaining components from |dest_components|.
+ components.insert(components.end(),
+ mismatch_pair.second, dest_components.end());
+ // Finally, add the base name of the target file name.
+ components.push_back(proxy_file.BaseName().value());
+ // Now reconstruct the relative path.
+ relative_path = base::FilePath{base::FilePath::kCurrentDirectory};
+ for (const auto& component : components)
+ relative_path = relative_path.Append(component);
+ }
text.AddLine(StringPrintf("#include \"%s\"",
relative_path.value().c_str()));
text.AddBlankLine();
diff --git a/chromeos-dbus-bindings/proxy_generator.h b/chromeos-dbus-bindings/proxy_generator.h
index 56fce06..d6cfbaf 100644
--- a/chromeos-dbus-bindings/proxy_generator.h
+++ b/chromeos-dbus-bindings/proxy_generator.h
@@ -34,7 +34,8 @@ class ProxyGenerator : public HeaderGenerator {
static bool GenerateMocks(const ServiceConfig& config,
const std::vector<Interface>& interfaces,
const base::FilePath& mock_file,
- const base::FilePath& proxy_file);
+ const base::FilePath& proxy_file,
+ bool use_literal_proxy_file);
private:
friend class ProxyGeneratorTest;
diff --git a/chromeos-dbus-bindings/proxy_generator_mock_unittest.cc b/chromeos-dbus-bindings/proxy_generator_mock_unittest.cc
index 6ff4a24..541b827 100644
--- a/chromeos-dbus-bindings/proxy_generator_mock_unittest.cc
+++ b/chromeos-dbus-bindings/proxy_generator_mock_unittest.cc
@@ -229,7 +229,7 @@ TEST_F(ProxyGeneratorMockTest, GenerateMocks) {
base::FilePath proxy_path = temp_dir_.path().Append("proxies.h");
ServiceConfig config;
EXPECT_TRUE(ProxyGenerator::GenerateMocks(config, interfaces, output_path,
- proxy_path));
+ proxy_path, false));
string contents;
EXPECT_TRUE(base::ReadFileToString(output_path, &contents));
// The header guards contain the (temporary) filename, so we search for