diff options
Diffstat (limited to 'chromeos-dbus-bindings')
-rw-r--r-- | chromeos-dbus-bindings/generate_chromeos_dbus_bindings.cc | 13 | ||||
-rw-r--r-- | chromeos-dbus-bindings/proxy_generator.cc | 73 | ||||
-rw-r--r-- | chromeos-dbus-bindings/proxy_generator.h | 3 | ||||
-rw-r--r-- | chromeos-dbus-bindings/proxy_generator_mock_unittest.cc | 2 |
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 |