Skip to content

Commit ff018e2

Browse files
gautamvasudevannetfs
authored andcommitted
Add git hash for version metadata of model server and add tags for dev and nightly builds.
PiperOrigin-RevId: 217403451 (cherry picked from commit 5c7740f)
1 parent 02a6fc1 commit ff018e2

File tree

6 files changed

+96
-12
lines changed

6 files changed

+96
-12
lines changed

tensorflow_serving/model_servers/BUILD

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,10 @@ cc_library(
330330
srcs = [
331331
"main.cc",
332332
],
333-
hdrs = ["version.h"],
333+
hdrs = [
334+
"version.h",
335+
],
336+
linkstamp = "version.cc",
334337
visibility = [
335338
":tensorflow_model_server_custom_op_clients",
336339
"//tensorflow_serving:internal",
@@ -347,6 +350,7 @@ cc_library(
347350

348351
cc_binary(
349352
name = "tensorflow_model_server",
353+
stamp = 1,
350354
visibility = ["//tensorflow_serving:internal"],
351355
deps = [
352356
":tensorflow_model_server_main_lib",

tensorflow_serving/model_servers/main.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ int main(int argc, char** argv) {
158158
}
159159

160160
if (display_version) {
161-
std::cout << "TensorFlow ModelServer: " << TF_MODELSERVER_VERSION_STRING
162-
<< "\n"
161+
std::cout << "TensorFlow ModelServer: " << TF_Serving_Version() << "\n"
163162
<< "TensorFlow Library: " << TF_Version() << "\n";
164163
return 0;
165164
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* Copyright 2018 Google Inc. All Rights Reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
==============================================================================*/
15+
16+
#include "tensorflow_serving/model_servers/version.h"
17+
18+
const char kTFS_SCM_Revision[] = TF_MODELSERVER_VERSION_STRING;
19+
20+
extern "C" {
21+
const char* TF_Serving_Version() { return kTFS_SCM_Revision; }
22+
}

tensorflow_serving/model_servers/version.h

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,43 @@ limitations under the License.
1616
#ifndef TENSORFLOW_SERVING_MODEL_SERVERS_VERSION_H_
1717
#define TENSORFLOW_SERVING_MODEL_SERVERS_VERSION_H_
1818

19-
// TF Serving Model Server uses semantic versioning, see http://semver.org/.
19+
// TF Serving Model Server uses semantic versioning for releases
20+
// - see http://semver.org/. For nightlies, a git hash is used to track the
21+
// build via linkstamping
22+
#define TF_MODELSERVER_STR_HELPER(x) #x
23+
#define TF_MODELSERVER_STR(x) TF_MODELSERVER_STR_HELPER(x)
2024

2125
#define TF_MODELSERVER_MAJOR_VERSION 1
2226
#define TF_MODELSERVER_MINOR_VERSION 11
2327
#define TF_MODELSERVER_PATCH_VERSION 0
24-
2528
// TF_MODELSERVER_VERSION_SUFFIX is non-empty for pre-releases
2629
// (e.g. "-alpha", "-alpha.1", "-beta", "-rc", "-rc.1")
2730
#define TF_MODELSERVER_VERSION_SUFFIX ""
2831

29-
#define TF_MODELSERVER_STR_HELPER(x) #x
30-
#define TF_MODELSERVER_STR(x) TF_MODELSERVER_STR_HELPER(x)
31-
32-
// e.g. "0.5.0" or "0.6.0-alpha".
32+
#ifndef TF_MODELSERVER_VERSION_NO_META
33+
// TF_MODELSERVER_BUILD_TAG can be set to be nightly for nightly builds
34+
#ifndef TF_MODELSERVER_BUILD_TAG
35+
#define TF_MODELSERVER_META_TAG "+dev"
36+
#else
37+
#define TF_MODELSERVER_META_TAG "+" TF_MODELSERVER_STR(TF_MODELSERVER_BUILD_TAG)
38+
#endif
39+
#define TF_MODELSERVER_META_SCM_HASH ".sha." BUILD_SCM_REVISION
40+
#else
41+
#define TF_MODELSERVER_META_TAG ""
42+
#define TF_MODELSERVER_META_SCM_HASH ""
43+
#endif
44+
45+
// e.g. "0.5.0+nightly.sha.a1b2c3d" or "0.6.0-rc1".
3346
// clang-format off
3447
#define TF_MODELSERVER_VERSION_STRING \
3548
(TF_MODELSERVER_STR(TF_MODELSERVER_MAJOR_VERSION) "." TF_MODELSERVER_STR( \
36-
TF_MODELSERVER_MINOR_VERSION) "." TF_MODELSERVER_STR( \
37-
TF_MODELSERVER_PATCH_VERSION) TF_MODELSERVER_VERSION_SUFFIX)
49+
TF_MODELSERVER_MINOR_VERSION) "." TF_MODELSERVER_STR( \
50+
TF_MODELSERVER_PATCH_VERSION) TF_MODELSERVER_VERSION_SUFFIX \
51+
TF_MODELSERVER_META_TAG TF_MODELSERVER_META_SCM_HASH)
3852
// clang-format on
3953

54+
extern "C" {
55+
const char* TF_Serving_Version();
56+
}
57+
4058
#endif // TENSORFLOW_SERVING_MODEL_SERVERS_VERSION_H_

tools/bazel.rc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ build -c opt
3333
# Adding --cxxopt=-D_GLIBCXX_USE_CXX11_ABI=0" creates parity with TF
3434
# compilation options. It also addresses memory use due to
3535
# copy-on-write semantics of std::strings of the older ABI.
36-
build --cxxopt=-D_GLIBCXX_USE_CXX11_ABI=0
36+
build --cxxopt=-D_GLIBCXX_USE_CXX11_ABI=0
37+
38+
build --workspace_status_command=/proc/self/cwd/tools/gen_status_stamp.sh

tools/gen_status_stamp.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
# Copyright 2018 The TensorFlow Authors. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ==============================================================================
16+
17+
# This script will be run by the building process to generate key-value
18+
# information that represents the status of the workspace. The output should be
19+
# in the format:
20+
#
21+
# KEY1 VALUE1
22+
# KEY2 VALUE2
23+
#
24+
# If the script exits with non-zero code, it's considered as a failure
25+
# and the output will be discarded.
26+
27+
# if we're inside a git tree
28+
if [ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1; then
29+
git_rev=$(git rev-parse --short HEAD)
30+
if [[ $? != 0 ]];
31+
then
32+
exit 1
33+
fi
34+
echo "BUILD_SCM_REVISION ${git_rev}"
35+
else
36+
echo "BUILD_SCM_REVISION no_git"
37+
fi;
38+
39+

0 commit comments

Comments
 (0)