aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/platform
diff options
context:
space:
mode:
authorGravatar Gunhan Gulsoy <gunan@google.com>2018-10-03 10:58:53 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-10-03 11:04:57 -0700
commitb25ef3877da28b7ec31d0bd69a7a6268f5e8a4b4 (patch)
treebdcc0cba08c143b5f8188b6565c8e2e52d362392 /tensorflow/core/platform
parent0796d711f17c8c981d19461c9edd0e16837c8ab7 (diff)
Add a new GetRunFilesDir function to Env.
PiperOrigin-RevId: 215590440
Diffstat (limited to 'tensorflow/core/platform')
-rw-r--r--tensorflow/core/platform/env.h6
-rw-r--r--tensorflow/core/platform/posix/env.cc11
-rw-r--r--tensorflow/core/platform/windows/env.cc11
3 files changed, 28 insertions, 0 deletions
diff --git a/tensorflow/core/platform/env.h b/tensorflow/core/platform/env.h
index 5b237c4736..5732271f15 100644
--- a/tensorflow/core/platform/env.h
+++ b/tensorflow/core/platform/env.h
@@ -228,6 +228,10 @@ class Env {
/// |suffix|. Returns true if success.
bool CreateUniqueFileName(string* prefix, const string& suffix);
+ /// \brief Return the runfiles directory if running under bazel. Returns
+ /// the directory the executable is located in if not running under bazel.
+ virtual string GetRunfilesDir() = 0;
+
// TODO(jeff,sanjay): Add back thread/thread-pool support if needed.
// TODO(jeff,sanjay): if needed, tighten spec so relative to epoch, or
// provide a routine to get the absolute time.
@@ -360,6 +364,8 @@ class EnvWrapper : public Env {
return target_->FormatLibraryFileName(name, version);
}
+ string GetRunfilesDir() override { return target_->GetRunfilesDir(); }
+
private:
void GetLocalTempDirectories(std::vector<string>* list) override {
target_->GetLocalTempDirectories(list);
diff --git a/tensorflow/core/platform/posix/env.cc b/tensorflow/core/platform/posix/env.cc
index 418874d340..af95d8201e 100644
--- a/tensorflow/core/platform/posix/env.cc
+++ b/tensorflow/core/platform/posix/env.cc
@@ -119,6 +119,17 @@ class PosixEnv : public Env {
return tensorflow::internal::FormatLibraryFileName(name, version);
}
+ string GetRunfilesDir() override {
+ string bin_path = this->GetExecutablePath();
+ string runfiles_path = bin_path + ".runfiles/org_tensorflow";
+ Status s = this->IsDirectory(runfiles_path);
+ if (!s.ok()) {
+ return runfiles_path;
+ } else {
+ return bin_path.substr(0, bin_path.find_last_of("/\\"));
+ }
+ }
+
private:
void GetLocalTempDirectories(std::vector<string>* list) override;
};
diff --git a/tensorflow/core/platform/windows/env.cc b/tensorflow/core/platform/windows/env.cc
index 68ee3595a2..f26ccd1662 100644
--- a/tensorflow/core/platform/windows/env.cc
+++ b/tensorflow/core/platform/windows/env.cc
@@ -160,6 +160,17 @@ class WindowsEnv : public Env {
return filename;
}
+ string GetRunfilesDir() override {
+ string bin_path = this->GetExecutablePath();
+ string runfiles_path = bin_path + ".runfiles\\org_tensorflow";
+ Status s = this->IsDirectory(runfiles_path);
+ if (!s.ok()) {
+ return runfiles_path;
+ } else {
+ return bin_path.substr(0, bin_path.find_last_of("/\\"));
+ }
+ }
+
private:
void GetLocalTempDirectories(std::vector<string>* list) override;