From db0ebe3650e2a43a10dd14b6fa0cdd3efd14b4b0 Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Thu, 25 Jul 2019 07:36:34 -0700 Subject: [PATCH] Support empty package names in filewrapper tool PiperOrigin-RevId: 259943587 Change-Id: I14d95dcd7d839903ebd12f4032e05e29bca17204 --- sandboxed_api/bazel/filewrapper.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sandboxed_api/bazel/filewrapper.cc b/sandboxed_api/bazel/filewrapper.cc index 814759b..f78b026 100644 --- a/sandboxed_api/bazel/filewrapper.cc +++ b/sandboxed_api/bazel/filewrapper.cc @@ -150,9 +150,9 @@ constexpr const char kHFileFooterFmt[] = // Format literals for generating the .cc file out of the input files. constexpr const char kCcFileHeaderFmt[] = - R"(// Automatically generated by sapi_cc_embed_data() Bazel rule + R"(// Automatically generated by sapi_cc_embed_data() build rule -#include "%s/%s.h" +#include "%s.h" #include "absl/base/macros.h" #include "absl/strings/string_view.h" @@ -198,7 +198,7 @@ int main(int argc, char* argv[]) { // We're not aiming for human usability here, as this tool is always run as // part of the build. absl::FPrintF(stderr, - "%s PACKAGE NAME NAMESPACE OUTPUT_H OUTPUT_CC INPUT...", + "%s PACKAGE NAME NAMESPACE OUTPUT_H OUTPUT_CC INPUT...\n", argv[0]); return EXIT_FAILURE; } @@ -238,7 +238,12 @@ int main(int argc, char* argv[]) { File out_cc(*arg++, "wb"); --argc; - absl::FPrintF(out_cc.get(), kCcFileHeaderFmt, package, name); + std::string package_name = package; + if (!package_name.empty()) { + absl::StrAppend(&package_name, "/"); + } + absl::StrAppend(&package_name, name); + absl::FPrintF(out_cc.get(), kCcFileHeaderFmt, package_name); if (have_ns) { absl::FPrintF(out_cc.get(), kCcNamespaceBeginFmt, ns); }