aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/tools/git
diff options
context:
space:
mode:
authorGravatar Yifei Feng <yifeif@google.com>2018-04-23 21:19:14 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-04-23 21:21:38 -0700
commit22f3a97b8b089202f60bb0c7697feb0c8e0713cc (patch)
treed16f95826e4be15bbb3b0f22bed0ca25d3eb5897 /tensorflow/tools/git
parent24b7c9a800ab5086d45a7d83ebcd6218424dc9e3 (diff)
Merge changes from github.
PiperOrigin-RevId: 194031845
Diffstat (limited to 'tensorflow/tools/git')
-rwxr-xr-xtensorflow/tools/git/gen_git_source.py56
-rwxr-xr-xtensorflow/tools/git/gen_git_source.sh10
2 files changed, 57 insertions, 9 deletions
diff --git a/tensorflow/tools/git/gen_git_source.py b/tensorflow/tools/git/gen_git_source.py
index 78d511969e..73dee98bae 100755
--- a/tensorflow/tools/git/gen_git_source.py
+++ b/tensorflow/tools/git/gen_git_source.py
@@ -139,7 +139,7 @@ def configure(src_base_path, gen_path, debug=False):
print("gen_git_source.py: spec is %r" % spec)
-def get_git_version(git_base_path):
+def get_git_version(git_base_path, git_tag_override):
"""Get the git version from the repository.
This function runs `git describe ...` in the path given as `git_base_path`.
@@ -152,6 +152,9 @@ def get_git_version(git_base_path):
Args:
git_base_path: where the .git directory is located
+ git_tag_override: Override the value for the git tag. This is useful for
+ releases where we want to build the release before the git tag is
+ created.
Returns:
A bytestring representing the git version
"""
@@ -161,6 +164,14 @@ def get_git_version(git_base_path):
"git", str("--git-dir=%s/.git" % git_base_path),
str("--work-tree=" + git_base_path), "describe", "--long", "--tags"
]).strip())
+ if git_tag_override:
+ split_val = val.split("-")
+ if len(split_val) != 3:
+ raise Exception(
+ ("Expected git version in format 'TAG-COMMITS AFTER TAG-HASH' "
+ "but got '%s'") % val)
+ split_val[0] = git_tag_override
+ val = bytes("-".join(split_val))
return val if val else unknown_label
except (subprocess.CalledProcessError, OSError):
return unknown_label
@@ -178,7 +189,15 @@ def write_version_info(filename, git_version):
contents = """/* Generated by gen_git_source.py */
#include <string>
const char* tf_git_version() {return "%s";}
-const char* tf_compiler_version() {return __VERSION__;}
+const char* tf_compiler_version() {
+#ifdef _MSC_VER
+#define STRINGIFY(x) #x
+#define TOSTRING(x) STRINGIFY(x)
+ return "MSVC " TOSTRING(_MSC_FULL_VER);
+#else
+ return __VERSION__;
+#endif
+}
const int tf_cxx11_abi_flag() {
#ifdef _GLIBCXX_USE_CXX11_ABI
return _GLIBCXX_USE_CXX11_ABI;
@@ -197,7 +216,7 @@ const int tf_monolithic_build() {
open(filename, "w").write(contents)
-def generate(arglist):
+def generate(arglist, git_tag_override=None):
"""Generate version_info.cc as given `destination_file`.
Args:
@@ -217,6 +236,10 @@ def generate(arglist):
`ref_symlink` is unused in this script but passed, because the build
system uses that file to detect when commits happen.
+ git_tag_override: Override the value for the git tag. This is useful for
+ releases where we want to build the release before the git tag is
+ created.
+
Raises:
RuntimeError: If ./configure needs to be run, RuntimeError will be raised.
"""
@@ -234,11 +257,11 @@ def generate(arglist):
raise RuntimeError(
"Run ./configure again, branch was '%s' but is now '%s'" %
(old_branch, new_branch))
- git_version = get_git_version(data["path"])
+ git_version = get_git_version(data["path"], git_tag_override)
write_version_info(dest_file, git_version)
-def raw_generate(output_file):
+def raw_generate(output_file, source_dir, git_tag_override=None):
"""Simple generator used for cmake/make build systems.
This does not create any symlinks. It requires the build system
@@ -246,9 +269,13 @@ def raw_generate(output_file):
Args:
output_file: Output filename for the version info cc
+ source_dir: Base path of the source code
+ git_tag_override: Override the value for the git tag. This is useful for
+ releases where we want to build the release before the git tag is
+ created.
"""
- git_version = get_git_version(".")
+ git_version = get_git_version(source_dir, git_tag_override)
write_version_info(output_file, git_version)
@@ -271,6 +298,11 @@ parser.add_argument(
help="Root path to place generated git files (created by --configure).")
parser.add_argument(
+ "--git_tag_override", type=str,
+ help="Override git tag value in the __git_version__ string. Useful when "
+ "creating release builds before the release tag is created.")
+
+parser.add_argument(
"--generate",
type=str,
help="Generate given spec-file, HEAD-symlink-file, ref-symlink-file",
@@ -281,6 +313,11 @@ parser.add_argument(
type=str,
help="Generate version_info.cc (simpler version used for cmake/make)")
+parser.add_argument(
+ "--source_dir",
+ type=str,
+ help="Base path of the source code (used for cmake/make)")
+
args = parser.parse_args()
if args.configure is not None:
@@ -288,9 +325,12 @@ if args.configure is not None:
raise RuntimeError("Must pass --gen_root_path arg when running --configure")
configure(args.configure, args.gen_root_path, debug=args.debug)
elif args.generate is not None:
- generate(args.generate)
+ generate(args.generate, args.git_tag_override)
elif args.raw_generate is not None:
- raw_generate(args.raw_generate)
+ source_path = "."
+ if args.source_dir is not None:
+ source_path = args.source_dir
+ raw_generate(args.raw_generate, source_path, args.git_tag_override)
else:
raise RuntimeError("--configure or --generate or --raw_generate "
"must be used")
diff --git a/tensorflow/tools/git/gen_git_source.sh b/tensorflow/tools/git/gen_git_source.sh
index db20bb00e8..cd128af6b3 100755
--- a/tensorflow/tools/git/gen_git_source.sh
+++ b/tensorflow/tools/git/gen_git_source.sh
@@ -28,7 +28,15 @@ fi
cat <<EOF > ${OUTPUT_FILENAME}
#include <string>
const char* tf_git_version() {return "${GIT_VERSION}";}
-const char* tf_compiler_version() {return __VERSION__;}
+const char* tf_compiler_version() {
+#ifdef _MSC_VER
+#define STRINGIFY(x) #x
+#define TOSTRING(x) STRINGIFY(x)
+ return "MSVC " TOSTRING(_MSC_FULL_VER);
+#else
+ return __VERSION__;
+#endif
+}
const int tf_cxx11_abi_flag() {
#ifdef _GLIBCXX_USE_CXX11_ABI
return _GLIBCXX_USE_CXX11_ABI;