Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
package(default_visibility = ["//visibility:public"])
load(
":build_defs.bzl",
"FEATURES",
"IGNITION_ROOT",
"IGNITION_VISIBILITY",
)

package(
default_visibility = IGNITION_VISIBILITY,
features = FEATURES,
)

licenses(["notice"])

exports_files(["LICENSE"])

py_binary(
name = "cmake_configure_file",
srcs = ["cmake_configure_file.py"],
visibility = ["//visibility:public"],
python_version = "PY3",
srcs_version = "PY2AND3",
)

cc_library(
name = "utilities",
srcs = ["ignition/utilities/SuppressWarning.hh",
"ignition/utilities/detail/SuppressWarning.hh"],
srcs = [
"ignition/utilities/SuppressWarning.hh",
"ignition/utilities/detail/SuppressWarning.hh",
],
includes = ["."],
visibility = ["//visibility:public"],
)

py_binary(
name = "embed_sdf",
srcs = ["embed_sdf.py"],
visibility = ["//visibility:public"],
python_version = "PY3",
srcs_version = "PY2AND3",
)
59 changes: 59 additions & 0 deletions build_defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
General variables and rules for facilitating builds of ignition.
"""

load(
":cmake_configure_file.bzl",
_cmake_configure_file = "cmake_configure_file",
)
load(
":generate_include_header.bzl",
_generate_include_header = "generate_include_header",
)
load(
":generate_file.bzl",
_generate_file = "generate_file",
)
load(
"ign_config_header.bzl",
_ign_config_header = "ign_config_header",
)
load(
"ign_export_header.bzl",
_ign_export_header = "ign_export_header",
)
load(
"generate_yaml.bzl",
_generate_yaml = "generate_yaml",
)
load(
"qt.bzl",
_qt_cc_binary = "qt_cc_binary",
_qt_cc_library = "qt_cc_library",
)

cmake_configure_file = _cmake_configure_file
generate_include_header = _generate_include_header
generate_file = _generate_file
ign_config_header = _ign_config_header
ign_export_header = _ign_export_header
generate_yaml = _generate_yaml
qt_cc_binary = _qt_cc_binary
qt_cc_library = _qt_cc_library

IGNITION_ROOT = "//"

IGNITION_VISIBILITY = [
"//:__subpackages__",
"//experimental:__subpackages__",
]

FEATURES = [
"-parse_headers",
"-use_header_modules",
"-layering_check",
]

DEFAULT_COPTS = [
"-fexceptions",
]
23 changes: 13 additions & 10 deletions example/BUILD.example
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
licenses(["notice"])

exports_files(["LICENSE"])

load(
"//ign_bazel:cmake_configure_file.bzl",
"//ign_bazel:build_defs.bzl",
"FEATURES",
"IGNITION_ROOT",
"IGNITION_VISIBILITY",
"cmake_configure_file",
)
load(
"//ign_bazel:generate_include_header.bzl",
"generate_include_header",
)
load(
"//ign_bazel:generate_file.bzl",
"generate_file",
"generate_include_header",
)

package(default_visibility = ["//visibility:public"])

package(
default_visibility = IGNITION_VISIBILITY,
features = FEATURES,
)
1 change: 0 additions & 1 deletion generate_file.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copied from the Drake project
# https://github.com/RobotLocomotion/drake/blob/17423f8fb6f292b4af0b4cf3c6c0f157273af501/tools/workspace/generate_file.bzl


def _generate_file_impl(ctx):
out = ctx.actions.declare_file(ctx.label.name)
ctx.actions.write(out, ctx.attr.content, ctx.attr.is_executable)
Expand Down
10 changes: 5 additions & 5 deletions generate_include_header.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copied from the drake project
# https://github.com/RobotLocomotion/drake/blob/17423f8fb6f292b4af0b4cf3c6c0f157273af501/tools/workspace/generate_include_header.bzl

load("//ign_bazel:pathutils.bzl", "output_path")
load(":pathutils.bzl", "output_path")

# Generate a header that includes a set of other headers
def _generate_include_header_impl(ctx):
Expand All @@ -27,15 +27,15 @@ generate_include_header = rule(
output_to_genfiles = True,
implementation = _generate_include_header_impl,
)

"""Generate a header that includes a set of other headers.

This creates a rule to generate a header that includes a list of other headers.
The generated file will be of the form::
#include <hdr>
#include <hdr>
Args:
hdrs (:obj:`str`): List of files or file labels of headers that the
generated header will include.
strip_prefix (:obj:`list` of :obj:`str`): List of prefixes to strip from
the header names when forming the ``#include`` directives.
generated header will include.
strip_prefix (:obj:`list` of :obj:`str`): List of prefixes to strip from
the header names when forming the ``#include`` directives.
"""
20 changes: 10 additions & 10 deletions generate_yaml.bzl
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
def _generate_yaml_impl(ctx):
ctx.actions.run_shell(
inputs = [ctx.file.ruby_target],
outputs = [ctx.outputs.source_file],
command = "\n".join([
"echo format: 1.0.0>> %s" % (ctx.outputs.source_file.path),
"echo library_name: \"%s\">> %s" % (ctx.attr.library_name, ctx.outputs.source_file.path),
"echo library_version: \"%s\">> %s" % (ctx.attr.library_version, ctx.outputs.source_file.path),
"echo library_path: $(realpath \"%s\")>> %s" % (ctx.file.ruby_target.path, ctx.outputs.source_file.path),
"echo commands:>> %s" % (ctx.outputs.source_file.path),
"echo \"%s\">> %s" % (ctx.attr.commands, ctx.outputs.source_file.path),
]),
inputs = [ctx.file.ruby_target],
outputs = [ctx.outputs.source_file],
command = "\n".join([
"echo format: 1.0.0>> %s" % (ctx.outputs.source_file.path),
"echo library_name: \"%s\">> %s" % (ctx.attr.library_name, ctx.outputs.source_file.path),
"echo library_version: \"%s\">> %s" % (ctx.attr.library_version, ctx.outputs.source_file.path),
"echo library_path: $(realpath \"%s\") >> %s" % (ctx.file.ruby_target.path, ctx.outputs.source_file.path),
"echo commands:>> %s" % (ctx.outputs.source_file.path),
"echo \"%s\">> %s" % (ctx.attr.commands, ctx.outputs.source_file.path),
]),
)

generate_yaml = rule(
Expand Down
36 changes: 36 additions & 0 deletions ign_config_header.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
load(
":cmake_configure_file.bzl",
"cmake_configure_file",
)

def ign_config_header(name, src, cmakelists, project_name, project_version):
out = src
idx = out.find(".in")
if (idx > 0):
out = out[0:idx]

PROJECT_NAME = project_name
IGN_DESIGNATION = project_name.split("-")[1]
PROJECT_MAJOR = project_version[0]
PROJECT_MINOR = project_version[1]
PROJECT_PATCH = project_version[2]

cmake_configure_file(
name = name,
src = src,
out = out,
cmakelists = cmakelists,
defines = [
"PROJECT_VERSION_MAJOR=%d" % PROJECT_MAJOR,
"PROJECT_VERSION_MINOR=%d" % PROJECT_MINOR,
"PROJECT_VERSION_PATCH=%d" % PROJECT_PATCH,
"PROJECT_MAJOR_VERSION=%d" % PROJECT_MAJOR,
"PROJECT_MINOR_VERSION=%d" % PROJECT_MINOR,
"PROJECT_PATCH_VERSION=%d" % PROJECT_PATCH,
"PROJECT_VERSION=%d.%d" % (PROJECT_MAJOR, PROJECT_MINOR),
"PROJECT_VERSION_FULL=%d.%d.%d" % (PROJECT_MAJOR, PROJECT_MINOR, PROJECT_PATCH), # noqa
"PROJECT_NAME_NO_VERSION=%s" % PROJECT_NAME,
"IGN_DESIGNATION=%s" % IGN_DESIGNATION,
],
visibility = ["//visibility:private"],
)
14 changes: 7 additions & 7 deletions ign_export_header.bzl
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
load(
"//ign_bazel:generate_file.bzl",
":generate_file.bzl",
"generate_file",
)


def ign_export_header(name, lib_name, export_base, visibility):
generate_file(
name = name,
visibility = visibility,
content = """
generate_file(
name = name,
visibility = visibility,
content = """
/*
* Copyright (C) 2017 Open Source Robotics Foundation
*
Expand Down Expand Up @@ -65,4 +64,5 @@ def ign_export_header(name, lib_name, export_base, visibility):
#endif

#endif
""".format(lib_name = lib_name, export_base = export_base))
""".format(lib_name = lib_name, export_base = export_base),
)
9 changes: 1 addition & 8 deletions pathutils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,7 @@ def output_path(ctx, input_file, strip_prefix, package_root = None):
# Determine base path of invoking context.
package_root = join_paths(ctx.label.workspace_root, ctx.label.package)

# Determine effective path by removing path of invoking context and any
# Bazel output-files path.
input_path = input_file.path
if input_file.is_source:
input_path = _remove_prefix(input_path, package_root)
else:
out_root = join_paths("bazel-out/*/*", package_root)
input_path = _remove_prefix(input_path, out_root)
input_path = input_file.short_path

# Deal with possible case of file outside the package root.
if input_path == None:
Expand Down
15 changes: 7 additions & 8 deletions qt.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ load("@rules_cc//cc:defs.bzl", "cc_binary")
def qt_moc(hdrs):
_moc_srcs = []
for hdr in hdrs:
header_path = "%s" % (hdr.replace("//", "").replace(":","/")) if len(native.package_name()) > 0 else hdr
header_path = "%s" % (hdr.replace("//", "").replace(":", "/")) if len(native.package_name()) > 0 else hdr
moc_name = "%s_moc" % hdr.replace(".", "_").replace("//", "").replace("/", "_").replace(":", "_")
native.genrule(
name = moc_name,
Expand All @@ -49,7 +49,7 @@ def qt_cc_binary(name, srcs, hdrs, linkopts, normal_hdrs = [], deps = None, **kw

_moc_srcs = []
for hdr in hdrs:
header_path = "%s" % (hdr.replace("//", "").replace(":","/")) if len(native.package_name()) > 0 else hdr
header_path = "%s" % (hdr.replace("//", "").replace(":", "/")) if len(native.package_name()) > 0 else hdr
moc_name = "%s_moc" % hdr.replace(".", "_").replace("//", "").replace("/", "_").replace(":", "_")
native.genrule(
name = moc_name,
Expand All @@ -61,7 +61,7 @@ def qt_cc_binary(name, srcs, hdrs, linkopts, normal_hdrs = [], deps = None, **kw
_moc_srcs.append(":" + moc_name)
cc_binary(
name = name,
srcs = srcs + _moc_srcs + hdrs + normal_hdrs,
srcs = srcs + _moc_srcs + hdrs + normal_hdrs,
linkopts = linkopts,
deps = deps,
**kwargs
Expand All @@ -81,11 +81,11 @@ def qt_cc_library(name, srcs, hdrs, linkopts, normal_hdrs = [], deps = None, **k

_moc_srcs = []
for hdr in hdrs:
header_path = "%s" % (hdr.replace("//", "").replace(":","/")) if len(native.package_name()) > 0 else hdr
header_path = "%s" % (hdr.replace("//", "").replace(":", "/")) if len(native.package_name()) > 0 else hdr
moc_name = "%s_moc" % hdr.replace(".", "_").replace("//", "").replace("/", "_").replace(":", "_")
print(hdr, '/'.join(header_path.split('/')[1:]))
print(hdr, "/".join(header_path.split("/")[1:]))

header_path = '/'.join(header_path.split('/')[1:])
header_path = "/".join(header_path.split("/")[1:])

native.genrule(
name = moc_name,
Expand All @@ -97,9 +97,8 @@ def qt_cc_library(name, srcs, hdrs, linkopts, normal_hdrs = [], deps = None, **k
_moc_srcs.append(":" + moc_name)
native.cc_library(
name = name,
srcs = srcs + _moc_srcs + hdrs + normal_hdrs,
srcs = srcs + _moc_srcs + hdrs + normal_hdrs,
linkopts = linkopts,
deps = deps,
**kwargs
)

Loading