提交 1da56680 编写于 作者: S storypku

Build: local_config_vtk and no longer needed WORKSPACE.in

上级 fbf32a31
# Bazel
bazel-*
WORKSPACE
# Temporary files
*.pyc
......
......@@ -4,11 +4,14 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//tools/gpus:cuda_configure.bzl", "cuda_configure")
load("//tools/tensorrt:tensorrt_configure.bzl", "tensorrt_configure")
load("//third_party:vtk_configure.bzl", "vtk_configure")
cuda_configure(name = "local_config_cuda")
tensorrt_configure(name = "local_config_tensorrt")
vtk_configure(name = "local_config_vtk")
maybe(
http_archive,
name = "bazel_skylib",
......@@ -192,20 +195,11 @@ new_local_repository(
# build_file = "third_party/opengl.BUILD",
# path = "/usr/include",
#)
#
#new_local_repository(
# name = "glfw",
# build_file = "third_party/glfw.BUILD",
# path = "/usr/include",
#)
#
# FIXME(all): hide vtk version from end users
new_local_repository(
name = "vtk",
build_file = "external/vtk.BUILD",
#path = "/opt/apollo/sysroot/include/vtk-VTK_VERSION",
path = "/opt/apollo/sysroot/include/vtk-8.2",
)
# Caffe
new_local_repository(
......
......@@ -59,11 +59,6 @@ function check_machine_arch() {
fail "Machine architecture $MACHINE_ARCH currently not supported yet."
exit 1
fi
#TODO(ALL): checks whether still in use
#setup vtk folder name for different systems.
VTK_VERSION=$(find /usr/include/ -type d -name "vtk-*" | tail -n1 | cut -d '-' -f 2)
sed "s/VTK_VERSION/${VTK_VERSION}/g" WORKSPACE.in > WORKSPACE
}
function check_esd_files() {
......
load("@rules_cc//cc:defs.bzl", "cc_library")
licenses(["notice"])
package(default_visibility = ["//visibility:public"])
# FIXME(all): hide vtk version from end users
cc_library(
name = "vtk",
includes = ["."],
linkopts = [
"-L/opt/apollo/sysroot/lib",
"-lvtkCommonCore-8.2",
],
)
......@@ -39,8 +39,8 @@ cc_library(
"//modules/perception/lidar/lib/segmentation/ncut/common:flood_fill",
"//modules/perception/lidar/lib/segmentation/ncut/common:lr_classifier",
"//modules/perception/lidar/lib/segmentation/ncut/proto:ncut_param_cc_proto",
"@local_config_vtk//:vtk",
"@pcl",
"@vtk",
],
)
......
......@@ -30,8 +30,8 @@ cc_library(
"//modules/common/util",
"@com_google_absl//absl/strings",
"@eigen",
"@local_config_vtk//:vtk",
"@pcl",
"@vtk",
],
)
......
package(default_visibility = ["//visibility:public"])
cc_library(
name = "vtk_headers",
hdrs = [
":vtk_include"
],
# include_prefix = "third_party/vtk",
strip_include_prefix = "vtk/include",
)
cc_library(
name = "vtk",
srcs = [":vtk_lib"],
linkstatic = 1,
deps = [
":vtk_headers",
],
)
%{copy_rules}
load("//tools/platform:common.bzl", "execute", "make_copy_dir_rule", "make_copy_files_rule")
_APOLLO_SYSROOT_DIR = "APOLLO_SYSROOT_DIR"
_APOLLO_VTK_LIBS = [
"vtkCommonDataModel",
"vtkCommonCore",
"vtkCommonMath",
"vtkCommonSystem",
"vtkCommonMisc",
"vtkCommonTransforms",
"vtksys",
]
def _vtk_solib_name(basename, version = None):
"""Constructs Linux-specific name of vtk libraries"""
version = "" if not version else "-" + version
return "lib{}{}.so".format(basename, version)
def find_sysroot_dir(repository_ctx):
if _APOLLO_SYSROOT_DIR in repository_ctx.os.environ:
return repository_ctx.os.environ[_APOLLO_SYSROOT_DIR].strip()
return None
# fail("Environment variable APOLLO_SYSROOT_DIR was not specified." +
# "Re-run ./apollo6.sh configure")
# Ref: bazel-skylib@lib/paths.bzl
def _basename(p):
"""Returns the basename (i.e., the file portion) of a path.
Note that if `p` ends with a slash, this function returns an empty string.
This matches the behavior of Python's `os.path.basename`, but differs from
the Unix `basename` command (which would return the path segment preceding
the final slash).
Args:
p: The path whose basename should be returned.
Returns:
The basename of the path, which includes the extension.
"""
return p.rpartition("/")[-1]
def _dirname(p):
"""Returns the dirname of a path.
The dirname is the portion of `p` up to but not including the file portion
(i.e., the basename). Any slashes immediately preceding the basename are not
included, unless omitting them would make the dirname empty.
Args:
p: The path whose dirname should be returned.
Returns:
The dirname of the path.
"""
prefix, sep, _ = p.rpartition("/")
if not prefix:
return sep
else:
# If there are multiple consecutive slashes, strip them all out as Python's
# os.path.dirname does.
return prefix.rstrip("/")
def _vtk_version_from_incl_path(incl_path):
return _basename(incl_path).strip("vtk-")
def _create_local_vtk_repository(repository_ctx):
sysroot_dir = find_sysroot_dir(repository_ctx)
result = _vtk_match_version(repository_ctx, sysroot_dir)
if result == None:
fail("Oops, Package vtk not found.")
(version, incl_dir, lib_path) = result
# Copy the library and header files.
libraries = [_vtk_solib_name(lib, version) for lib in _APOLLO_VTK_LIBS]
_lib_path = lib_path + "/"
# headers = _get_vtk_headers(incl_dir)
_incl_dir = incl_dir + "/"
copy_rules = [
make_copy_files_rule(
repository_ctx,
name = "vtk_lib",
srcs = [_lib_path + lib for lib in libraries],
outs = ["vtk/lib/" + lib for lib in libraries],
),
make_copy_dir_rule(
repository_ctx,
name = "vtk_include",
src_dir = incl_dir,
out_dir = "vtk/include",
),
]
# Set up BUILD file.
build_tpl = repository_ctx.path(Label("//third_party/vtk:BUILD.tpl"))
repository_ctx.template("BUILD", build_tpl, {
"%{copy_rules}": "\n".join(copy_rules),
})
def _vtk_match_version(repository_ctx, sysroot_dir = None):
cmd = """ldconfig -p | awk -F'=>' '/libvtkCommonCore-.*.so$/ {print $2}'"""
lib_result = execute(
repository_ctx,
["sh", "-c", cmd],
empty_stdout_fine = False,
).stdout.strip()
libdict = {}
for solib in lib_result.split("\n"):
libpath = _dirname(solib)
version = _basename(solib).rstrip(".so").split("-")[-1]
prefix = solib[:solib.find("/lib/")]
libdict[solib] = (libpath, version, prefix)
prefix_dirs = ["/usr", "/usr/local"]
if sysroot_dir:
prefix_dirs.append(sysroot_dir)
for prefix in reversed(prefix_dirs):
cmd = """ls -d {}/include/vtk-* 2>/dev/null""".format(prefix)
incl_dir = execute(
repository_ctx,
["sh", "-c", cmd],
empty_stdout_fine = True,
).stdout.strip()
if not incl_dir:
continue
version = _vtk_version_from_incl_path(incl_dir)
for k in libdict:
(lib_path, lib_version, lib_prefix) = libdict[k]
if lib_version == version and lib_prefix == prefix:
return (version, incl_dir, lib_path)
return None
def _vtk_configure_impl(repository_ctx):
# Room for _create_remote_vtk_repository
_create_local_vtk_repository(repository_ctx)
vtk_configure = repository_rule(
implementation = _vtk_configure_impl,
environ = [],
)
"""Detects and configures the local vtk library.
Add the following to your WORKSPACE FILE:
```python
vtk_configure(name = "local_config_vtk")
```
Args:
name: A unique name for this workspace rule.
"""
......@@ -34,8 +34,6 @@ fi
echo "/opt/apollo/pkgs/caffe/lib" | sudo tee -a /etc/ld.so.conf.d/apollo.conf
sudo ldconfig
cp WORKSPACE.in WORKSPACE
# Fail on first failure.
set -e
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册