From 36157ed155517926a9d56cb29f55ca862727c57c Mon Sep 17 00:00:00 2001 From: Laszlo Csomor Date: Thu, 11 Jul 2019 14:37:25 +0200 Subject: [PATCH] C++ runfiles library test: cut unwanted dependency Fixes https://github.com/bazelbuild/bazel/issues/8862 --- tools/cpp/runfiles/BUILD | 1 - tools/cpp/runfiles/runfiles_test.cc | 24 +++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/tools/cpp/runfiles/BUILD b/tools/cpp/runfiles/BUILD index f41e2e951ce93a..6a3589b29d2adb 100644 --- a/tools/cpp/runfiles/BUILD +++ b/tools/cpp/runfiles/BUILD @@ -63,7 +63,6 @@ cc_test( visibility = ["//visibility:public"], deps = [ ":runfiles", - "//src/main/cpp/util:filesystem", "@com_google_googletest//:gtest_main", ], ) diff --git a/tools/cpp/runfiles/runfiles_test.cc b/tools/cpp/runfiles/runfiles_test.cc index e5a4eeaaeaba91..21c60b5cb88bbc 100644 --- a/tools/cpp/runfiles/runfiles_test.cc +++ b/tools/cpp/runfiles/runfiles_test.cc @@ -24,8 +24,6 @@ #include #include "gtest/gtest.h" -#include "src/main/cpp/util/file.h" -#include "src/main/cpp/util/path.h" #define RUNFILES_TEST_TOSTRING_HELPER(x) #x #define RUNFILES_TEST_TOSTRING(x) RUNFILES_TEST_TOSTRING_HELPER(x) @@ -99,14 +97,14 @@ string RunfilesTest::GetTemp() { #ifdef _WIN32 DWORD size = ::GetEnvironmentVariableA("TEST_TMPDIR", NULL, 0); if (size == 0) { - return std::move(string()); // unset or empty envvar + return string(); // unset or empty envvar } unique_ptr value(new char[size]); ::GetEnvironmentVariableA("TEST_TMPDIR", value.get(), size); - return std::move(string(value.get())); + return value.get(); #else char* result = getenv("TEST_TMPDIR"); - return result != NULL ? std::move(string(result)) : std::move(string()); + return result != NULL ? string(result) : string(); #endif } @@ -122,18 +120,22 @@ RunfilesTest::MockFile* RunfilesTest::MockFile::Create( return nullptr; } - string tmp(std::move(RunfilesTest::GetTemp())); + string tmp(RunfilesTest::GetTemp()); if (tmp.empty()) { cerr << "WARNING: " << __FILE__ << "(" << __LINE__ << "): $TEST_TMPDIR is empty" << endl; return nullptr; } string path(tmp + "/" + name); - string dirname = blaze_util::Dirname(path); - if (!blaze_util::MakeDirectories(dirname, 0777)) { - cerr << "WARNING: " << __FILE__ << "(" << __LINE__ << "): MakeDirectories(" - << dirname << ") failed" << endl; - return nullptr; + + string::size_type i = 0; + while ((i = name.find_first_of("/\\", i + 1)) != string::npos) { + string d = tmp + "\\" + name.substr(0, i); + if (!CreateDirectoryA(d.c_str(), NULL)) { + cerr << "ERROR: " << __FILE__ << "(" << __LINE__ + << "): failed to create directory \"" << d << "\"" << endl; + return nullptr; + } } auto stm = std::ofstream(path);