Restore most of pull request #8606

Pull request #8606 added str(Label(...)) for most dependencies in
tensorflow.bzl, allowing most functions to be used from repositories which
include TensorFlow as a submodule.  Unfortunately, it broke when pulled into
Google and was removed in cl/152200430.  This CL restores the change, except
for two Android-only functions; these were the only problematic bits.
Change: 152297413
This commit is contained in:
Geoffrey Irving 2017-04-05 12:26:32 -08:00 committed by TensorFlower Gardener
parent 0b1aee350e
commit c699e5fa03

View File

@ -41,76 +41,82 @@ def tf_android_core_proto_headers(core_proto_sources_relative):
])
# Sanitize a dependency so that it works correctly from code that includes
# TensorFlow as a submodule.
def clean_dep(dep):
return str(Label(dep))
def if_android_x86(a):
return select({
"//tensorflow:android_x86": a,
"//tensorflow:android_x86_64": a,
clean_dep("//tensorflow:android_x86"): a,
clean_dep("//tensorflow:android_x86_64"): a,
"//conditions:default": [],
})
def if_android_arm(a):
return select({
"//tensorflow:android_arm": a,
clean_dep("//tensorflow:android_arm"): a,
"//conditions:default": [],
})
def if_android_arm64(a):
return select({
"//tensorflow:android_arm64": a,
clean_dep("//tensorflow:android_arm64"): a,
"//conditions:default": [],
})
def if_not_android(a):
return select({
"//tensorflow:android": [],
clean_dep("//tensorflow:android"): [],
"//conditions:default": a,
})
def if_android(a):
return select({
"//tensorflow:android": a,
clean_dep("//tensorflow:android"): a,
"//conditions:default": [],
})
def if_ios(a):
return select({
"//tensorflow:ios": a,
clean_dep("//tensorflow:ios"): a,
"//conditions:default": [],
})
def if_mobile(a):
return select({
"//tensorflow:android": a,
"//tensorflow:ios": a,
clean_dep("//tensorflow:android"): a,
clean_dep("//tensorflow:ios"): a,
"//conditions:default": [],
})
def if_not_mobile(a):
return select({
"//tensorflow:android": [],
"//tensorflow:ios": [],
clean_dep("//tensorflow:android"): [],
clean_dep("//tensorflow:ios"): [],
"//conditions:default": a,
})
def if_not_windows(a):
return select({
"//tensorflow:windows": [],
clean_dep("//tensorflow:windows"): [],
"//conditions:default": a,
})
def if_x86(a):
return select({
"//tensorflow:linux_x86_64": a,
"//tensorflow:windows": a,
clean_dep("//tensorflow:linux_x86_64"): a,
clean_dep("//tensorflow:windows"): a,
"//conditions:default": [],
})
@ -124,13 +130,13 @@ def tf_copts():
"-fno-exceptions",
] + if_cuda(["-DGOOGLE_CUDA=1"]) + if_mkl(["-DINTEL_MKL=1"]) + if_android_arm(
["-mfpu=neon"]) + if_x86(["-msse3"]) + select({
"//tensorflow:android": [
clean_dep("//tensorflow:android"): [
"-std=c++11",
"-DTF_LEAN_BINARY",
"-O2",
],
"//tensorflow:darwin": [],
"//tensorflow:windows": [
clean_dep("//tensorflow:darwin"): [],
clean_dep("//tensorflow:windows"): [
"/DLANG_CXX11",
"/D__VERSION__=\\\"MSVC\\\"",
"/DPLATFORM_WINDOWS",
@ -138,7 +144,7 @@ def tf_copts():
"/DEIGEN_HAS_C99_MATH",
"/DTENSORFLOW_USE_EIGEN_THREADPOOL",
],
"//tensorflow:ios": ["-std=c++11"],
clean_dep("//tensorflow:ios"): ["-std=c++11"],
"//conditions:default": ["-pthread"]
}))
@ -166,7 +172,7 @@ def tf_gen_op_libs(op_lib_names, deps=None):
name=n + "_op_lib",
copts=tf_copts(),
srcs=["ops/" + n + ".cc"],
deps=deps + ["//tensorflow/core:framework"],
deps=deps + [clean_dep("//tensorflow/core:framework")],
visibility=["//visibility:public"],
alwayslink=1,
linkstatic=1,)
@ -175,7 +181,7 @@ def tf_gen_op_libs(op_lib_names, deps=None):
def tf_gen_op_wrapper_cc(name,
out_ops_file,
pkg="",
op_gen="//tensorflow/cc:cc_op_gen_main",
op_gen=clean_dep("//tensorflow/cc:cc_op_gen_main"),
deps=None,
override_file=None,
include_internal_ops=0):
@ -242,11 +248,11 @@ def tf_gen_op_wrappers_cc(name,
other_hdrs=[],
pkg="",
deps=[
"//tensorflow/cc:ops",
"//tensorflow/cc:scope",
"//tensorflow/cc:const_op",
clean_dep("//tensorflow/cc:ops"),
clean_dep("//tensorflow/cc:scope"),
clean_dep("//tensorflow/cc:const_op"),
],
op_gen="//tensorflow/cc:cc_op_gen_main",
op_gen=clean_dep("//tensorflow/cc:cc_op_gen_main"),
override_file=None,
include_internal_ops=0,
visibility=None):
@ -272,12 +278,12 @@ def tf_gen_op_wrappers_cc(name,
srcs=subsrcs,
hdrs=subhdrs,
deps=deps + if_not_android([
"//tensorflow/core:core_cpu",
"//tensorflow/core:framework",
"//tensorflow/core:lib",
"//tensorflow/core:protos_all_cc",
clean_dep("//tensorflow/core:core_cpu"),
clean_dep("//tensorflow/core:framework"),
clean_dep("//tensorflow/core:lib"),
clean_dep("//tensorflow/core:protos_all_cc"),
]) + if_android([
"//tensorflow/core:android_tensorflow_lib",
clean_dep("//tensorflow/core:android_tensorflow_lib"),
]),
copts=tf_copts(),
alwayslink=1,
@ -287,16 +293,16 @@ def tf_gen_op_wrappers_cc(name,
srcs=internalsrcs,
hdrs=internalhdrs,
deps=deps + if_not_android([
"//tensorflow/core:core_cpu",
"//tensorflow/core:framework",
"//tensorflow/core:lib",
"//tensorflow/core:protos_all_cc",
clean_dep("//tensorflow/core:core_cpu"),
clean_dep("//tensorflow/core:framework"),
clean_dep("//tensorflow/core:lib"),
clean_dep("//tensorflow/core:protos_all_cc"),
]) + if_android([
"//tensorflow/core:android_tensorflow_lib",
clean_dep("//tensorflow/core:android_tensorflow_lib"),
]),
copts=tf_copts(),
alwayslink=1,
visibility=["//tensorflow:internal"])
visibility=[clean_dep("//tensorflow:internal")])
# Invoke this rule in .../tensorflow/python to build the wrapper library.
@ -311,17 +317,17 @@ def tf_gen_op_wrapper_py(name,
# Construct a cc_binary containing the specified ops.
tool_name = "gen_" + name + "_py_wrappers_cc"
if not deps:
deps = ["//tensorflow/core:" + name + "_op_lib"]
deps = [str(Label("//tensorflow/core:" + name + "_op_lib"))]
native.cc_binary(
name=tool_name,
linkopts=["-lm"],
copts=tf_copts(),
linkstatic=1, # Faster to link this one-time-use binary dynamically
deps=([
"//tensorflow/core:framework",
"//tensorflow/python:python_op_gen_main"
clean_dep("//tensorflow/core:framework"),
clean_dep("//tensorflow/python:python_op_gen_main")
] + deps),
visibility=["//tensorflow:internal"],)
visibility=[clean_dep("//tensorflow:internal")],)
# Invoke the previous cc_binary to generate a python file.
if not out:
@ -363,7 +369,7 @@ def tf_gen_op_wrapper_py(name,
srcs_version="PY2AND3",
visibility=visibility,
deps=[
"//tensorflow/python:framework_for_generated_wrappers_v2",
clean_dep("//tensorflow/python:framework_for_generated_wrappers_v2"),
],)
@ -439,7 +445,7 @@ def tf_cuda_cc_test(name,
name=name,
srcs=srcs,
suffix="_gpu",
deps=deps + if_cuda(["//tensorflow/core:gpu_runtime"]),
deps=deps + if_cuda([clean_dep("//tensorflow/core:gpu_runtime")]),
linkstatic=if_cuda(1, 0),
tags=tags + tf_cuda_tests_tags(),
data=data,
@ -547,8 +553,8 @@ def tf_gpu_kernel_library(srcs,
hdrs=hdrs,
copts=copts,
deps=deps + if_cuda([
"//tensorflow/core:cuda",
"//tensorflow/core:gpu_lib",
clean_dep("//tensorflow/core:cuda"),
clean_dep("//tensorflow/core:gpu_lib"),
]),
alwayslink=1,
**kwargs)
@ -579,7 +585,7 @@ def tf_cuda_library(deps=None, cuda_deps=None, copts=None, **kwargs):
native.cc_library(
deps=deps + if_cuda(cuda_deps + [
"//tensorflow/core:cuda",
clean_dep("//tensorflow/core:cuda"),
"@local_config_cuda//cuda:cuda_headers"
]),
copts=copts + if_cuda(["-DGOOGLE_CUDA=1"]) + if_mkl(["-DINTEL_MKL=1"]),
@ -634,7 +640,7 @@ def tf_kernel_library(name,
hdrs = hdrs + native.glob(
[prefix + "*.h"], exclude=[prefix + "*test*", prefix + "*.cu.h"])
cuda_deps = ["//tensorflow/core:gpu_lib"]
cuda_deps = [clean_dep("//tensorflow/core:gpu_lib")]
if gpu_srcs:
for gpu_src in gpu_srcs:
if gpu_src.endswith(".cc") and not gpu_src.endswith(".cu.cc"):
@ -810,8 +816,8 @@ def cc_header_only_library(name, deps=[], **kwargs):
def tf_custom_op_library_additional_deps():
return [
"@protobuf//:protobuf_headers",
"//third_party/eigen3",
"//tensorflow/core:framework_headers_lib",
clean_dep("//third_party/eigen3"),
clean_dep("//tensorflow/core:framework_headers_lib"),
]
@ -871,7 +877,7 @@ check_deps = rule(
# implementations of custom ops and kernels.
def tf_custom_op_library(name, srcs=[], gpu_srcs=[], deps=[]):
cuda_deps = [
"//tensorflow/core:stream_executor_headers_lib",
clean_dep("//tensorflow/core:stream_executor_headers_lib"),
"@local_config_cuda//cuda:cudart_static",
]
deps = deps + tf_custom_op_library_additional_deps()
@ -888,8 +894,8 @@ def tf_custom_op_library(name, srcs=[], gpu_srcs=[], deps=[]):
name=name + "_check_deps",
deps=deps + if_cuda(cuda_deps),
disallowed_deps=[
"//tensorflow/core:framework",
"//tensorflow/core:lib"
clean_dep("//tensorflow/core:framework"),
clean_dep("//tensorflow/core:lib")
])
native.cc_binary(
@ -903,7 +909,7 @@ def tf_custom_op_library(name, srcs=[], gpu_srcs=[], deps=[]):
"//conditions:default": [
"-lm",
],
"//tensorflow:darwin": [],
clean_dep("//tensorflow:darwin"): [],
}),)
@ -956,21 +962,21 @@ def tf_py_wrap_cc(name,
extra_linkopts = select({
"@local_config_cuda//cuda:darwin": [
"-Wl,-exported_symbols_list",
"//tensorflow:tf_exported_symbols.lds"
clean_dep("//tensorflow:tf_exported_symbols.lds")
],
str(Label("//tensorflow:windows")): [],
clean_dep("//tensorflow:windows"): [],
"//conditions:default": [
"-Wl,--version-script",
"//tensorflow:tf_version_script.lds"
clean_dep("//tensorflow:tf_version_script.lds")
]
})
extra_deps += select({
"@local_config_cuda//cuda:darwin": [
"//tensorflow:tf_exported_symbols.lds"
clean_dep("//tensorflow:tf_exported_symbols.lds")
],
"//tensorflow:windows": [],
clean_dep("//tensorflow:windows"): [],
"//conditions:default": [
"//tensorflow:tf_version_script.lds"
clean_dep("//tensorflow:tf_version_script.lds")
]
})
@ -994,7 +1000,7 @@ def tf_py_wrap_cc(name,
srcs=[":" + name + ".py"],
srcs_version="PY2AND3",
data=select({
"//tensorflow:windows": [":" + cc_library_pyd_name],
clean_dep("//tensorflow:windows"): [":" + cc_library_pyd_name],
"//conditions:default": [":" + cc_library_name],
}))
@ -1003,7 +1009,7 @@ def py_test(deps=[], **kwargs):
native.py_test(
deps=select({
"//conditions:default": deps,
"//tensorflow:no_tensorflow_py_deps": []
clean_dep("//tensorflow:no_tensorflow_py_deps"): []
}),
**kwargs)
@ -1028,15 +1034,15 @@ def tf_py_test(name,
main=main,
args=args,
tags=tags,
visibility=["//tensorflow:internal"],
visibility=[clean_dep("//tensorflow:internal")],
shard_count=shard_count,
data=data,
deps=select({
"//conditions:default": [
"//tensorflow/python:extra_py_tests_deps",
"//tensorflow/python:gradient_checker",
clean_dep("//tensorflow/python:extra_py_tests_deps"),
clean_dep("//tensorflow/python:gradient_checker"),
] + additional_deps,
"//tensorflow:no_tensorflow_py_deps": []
clean_dep("//tensorflow:no_tensorflow_py_deps"): []
}),
flaky=flaky,
srcs_version="PY2AND3")
@ -1153,13 +1159,13 @@ def tf_generate_proto_text_sources(name, srcs_relative_dir, srcs):
out_srcs = [p.replace(".proto", ".pb_text.cc") for p in srcs]
native.genrule(
name=name,
srcs=srcs + ["//tensorflow/tools/proto_text:placeholder.txt"],
srcs=srcs + [clean_dep("//tensorflow/tools/proto_text:placeholder.txt")],
outs=out_hdrs + out_srcs,
cmd=
"$(location //tensorflow/tools/proto_text:gen_proto_text_functions) "
+ "$(@D) " + srcs_relative_dir + " $(SRCS)",
tools=[
"//tensorflow/tools/proto_text:gen_proto_text_functions"
clean_dep("//tensorflow/tools/proto_text:gen_proto_text_functions")
],)
return struct(hdrs=out_hdrs, srcs=out_srcs)
@ -1173,15 +1179,15 @@ def tf_version_info_genrule():
native.genrule(
name="version_info_gen",
srcs=[
"//tensorflow/tools/git:gen/spec.json",
"//tensorflow/tools/git:gen/head",
"//tensorflow/tools/git:gen/branch_ref",
clean_dep("//tensorflow/tools/git:gen/spec.json"),
clean_dep("//tensorflow/tools/git:gen/head"),
clean_dep("//tensorflow/tools/git:gen/branch_ref"),
],
outs=["util/version_info.cc"],
cmd=
"$(location //tensorflow/tools/git:gen_git_source.py) --generate $(SRCS) \"$@\"",
local=1,
tools=["//tensorflow/tools/git:gen_git_source.py"],)
tools=[clean_dep("//tensorflow/tools/git:gen_git_source.py")],)
def cc_library_with_android_deps(deps,