aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/tools/build_info
diff options
context:
space:
mode:
authorGravatar Derek Murray <mrry@google.com>2017-09-12 17:03:13 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-09-12 17:07:07 -0700
commit59bdf598d2cf386507aab4e56c5ffffcaebcb880 (patch)
treeeeb18697247c02a09c70740e14d0028c4a746c1a /tensorflow/tools/build_info
parentc3b86347f2433b892e2eaab3516d463b379666f7 (diff)
Add an automatically-generated "tensorflow.python.platform.build_info" script.
The motivation for this script is to provide better tools for diagnosing load-time errors (such as the ones that plague the Windows build due to DLL issues). Note that the script is intended to be self-contained, so that it is possible to import it without loading the entire TensorFlow runtime. This generated script currently contains a single symbol, `is_cuda_build`, which records whether the build has GPU support or not. PiperOrigin-RevId: 168471034
Diffstat (limited to 'tensorflow/tools/build_info')
-rw-r--r--tensorflow/tools/build_info/BUILD26
-rwxr-xr-xtensorflow/tools/build_info/gen_build_info.py77
2 files changed, 103 insertions, 0 deletions
diff --git a/tensorflow/tools/build_info/BUILD b/tensorflow/tools/build_info/BUILD
new file mode 100644
index 0000000000..cdc47076ce
--- /dev/null
+++ b/tensorflow/tools/build_info/BUILD
@@ -0,0 +1,26 @@
+# Description:
+# Contains script to generate tensorflow/python/platform/build_info.py
+package(default_visibility = ["//tensorflow:internal"])
+
+licenses(["notice"]) # Apache 2.0
+
+exports_files(
+ glob(["gen/*"]) + [
+ "gen_build_info.py",
+ ],
+)
+
+# -----------------------------------------------------------------------------
+# Google-internal targets. These must be at the end for syncrepo.
+
+filegroup(
+ name = "all_files",
+ srcs = glob(
+ ["**/*"],
+ exclude = [
+ "**/METADATA",
+ "**/OWNERS",
+ ],
+ ),
+ visibility = ["//tensorflow:__subpackages__"],
+)
diff --git a/tensorflow/tools/build_info/gen_build_info.py b/tensorflow/tools/build_info/gen_build_info.py
new file mode 100755
index 0000000000..f59cdb0e1e
--- /dev/null
+++ b/tensorflow/tools/build_info/gen_build_info.py
@@ -0,0 +1,77 @@
+#!/usr/bin/env python
+# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==============================================================================
+"""Generates a Python module containing information about the build."""
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+import argparse
+
+
+def write_build_info(filename, build_config):
+ """Writes a Python that describes the build.
+
+ Args:
+ filename: filename to write to.
+ build_config: A string containinggit_version: the result of a git describe.
+ """
+ module_docstring = "\"\"\"Generates a Python module containing information "
+ module_docstring += "about the build.\"\"\""
+ if build_config == "cuda":
+ build_config_bool = "True"
+ else:
+ build_config_bool = "False"
+
+ contents = """
+# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==============================================================================
+%s
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+
+is_cuda_build = %s
+""" % (module_docstring, build_config_bool)
+ open(filename, "w").write(contents)
+
+
+parser = argparse.ArgumentParser(
+ description="""Build info injection into the PIP package.""")
+
+parser.add_argument(
+ "--build_config",
+ type=str,
+ help="Either 'cuda' for GPU builds or 'cpu' for CPU builds.")
+
+parser.add_argument("--raw_generate", type=str, help="Generate build_info.py")
+
+args = parser.parse_args()
+
+if args.raw_generate is not None and args.build_config is not None:
+ write_build_info(args.raw_generate, args.build_config)
+else:
+ raise RuntimeError("--raw_generate and --build_config must be used")