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
34 changes: 22 additions & 12 deletions bazel/proto.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,25 @@ GO_WELL_KNOWN_PROTOS = {
"any_proto": "@org_golang_google_protobuf//types/known/anypb:go_default_library",
}

def fhir_proto_library(proto_library_prefix, srcs = [], proto_deps = [], **kwargs):
def fhir_proto_library(
name = None,
proto_library_prefix = None,
srcs = [],
proto_deps = [],
**kwargs):
"""Generates proto_library target, as well as {cc,java,go}_proto_library targets.

Args:
proto_library_prefix: Name prefix to be added to various proto libraries.
name: Name prefix to be added to various proto libraries.
proto_library_prefix: Deprecated name prefix to be added to various proto libraries.
srcs: Srcs for the proto library.
proto_deps: Deps by the proto_library.
**kwargs: varargs. Passed through to proto rules.
"""
prefix = name or proto_library_prefix
if not prefix:
fail("Either name or proto_library_prefix must be specified.")

cc_deps = []
go_deps = []
has_well_known_dep = False
Expand All @@ -35,21 +45,21 @@ def fhir_proto_library(proto_library_prefix, srcs = [], proto_deps = [], **kwarg
go_deps.append(x[:-6] + "_go_proto")

proto_library(
name = proto_library_prefix + "_proto",
name = prefix + "_proto",
srcs = srcs,
deps = proto_deps,
**kwargs
)

cc_proto_library(
name = proto_library_prefix + "_cc_proto",
deps = [proto_library_prefix + "_proto"],
name = prefix + "_cc_proto",
deps = [prefix + "_proto"],
)

native.java_proto_library(
name = proto_library_prefix + "_java_proto",
name = prefix + "_java_proto",
deps = [
":" + proto_library_prefix + "_proto",
":" + prefix + "_proto",
],
**kwargs
)
Expand All @@ -59,19 +69,19 @@ def fhir_proto_library(proto_library_prefix, srcs = [], proto_deps = [], **kwarg
importpath_prefix = "github.com/google/fhir/"

go_proto_library(
name = proto_library_prefix + "_go_proto",
name = prefix + "_go_proto",
deps = go_deps,
proto = ":" + proto_library_prefix + "_proto",
importpath = importpath_prefix + native.package_name() + "/" + proto_library_prefix + "_go_proto",
proto = ":" + prefix + "_proto",
importpath = importpath_prefix + native.package_name() + "/" + prefix + "_go_proto",
**kwargs
)

def _fhir_individual_resource_rules(resource_files, deps):
for resource_file in resource_files:
fhir_proto_library(
name = resource_file[:-6],
srcs = [resource_file],
proto_deps = deps,
proto_library_prefix = resource_file[:-6],
)

def fhir_resource_rules(resource_files, deps):
Expand All @@ -82,9 +92,9 @@ def fhir_resource_rules(resource_files, deps):
resources_as_dep = [":" + file[:-6] + "_proto" for file in resource_files]

fhir_proto_library(
name = "bundle_and_contained_resource",
srcs = ["bundle_and_contained_resource.proto"],
proto_deps = deps + resources_as_dep,
proto_library_prefix = "bundle_and_contained_resource",
)

def fhir_profile_rules(resource_files, deps):
Expand Down
2 changes: 1 addition & 1 deletion examples/profiles/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ gen_fhir_definitions_and_protos(
)

fhir_proto_library(
name = "demo", # buildifier: disable=duplicated-name
srcs = [
"demo.proto",
],
Expand All @@ -32,5 +33,4 @@ fhir_proto_library(
"//proto/google/fhir/proto/r4/core:datatypes_proto",
"//proto/google/fhir/proto/r4/core:extensions_proto",
],
proto_library_prefix = "demo",
)
8 changes: 4 additions & 4 deletions proto/google/fhir/proto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ package(default_visibility = ["//visibility:public"])
licenses(["notice"])

fhir_proto_library(
name = "annotations",
srcs = ["annotations.proto"],
proto_deps = [
"@com_google_protobuf//:descriptor_proto",
],
proto_library_prefix = "annotations",
)

fhir_proto_library(
name = "protogenerator_annotations",
srcs = ["protogenerator_annotations.proto"],
proto_deps = [
"@com_google_protobuf//:descriptor_proto",
],
proto_library_prefix = "protogenerator_annotations",
)

fhir_proto_library(
name = "profile_config",
srcs = [
"profile_config.proto",
],
Expand All @@ -29,10 +30,9 @@ fhir_proto_library(
"//proto/google/fhir/proto/r4/core:codes_proto",
"//proto/google/fhir/proto/r4/core:datatypes_proto",
],
proto_library_prefix = "profile_config",
)

fhir_proto_library(
name = "fhirpath_replacement_list",
srcs = ["fhirpath_replacement_list.proto"],
proto_library_prefix = "fhirpath_replacement_list",
)
12 changes: 6 additions & 6 deletions proto/google/fhir/proto/r4/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ licenses(["notice"])
exports_files(["version_config.textproto"])

fhir_proto_library(
name = "fhirproto",
srcs = [
"fhirproto.proto",
],
Expand All @@ -17,10 +18,10 @@ fhir_proto_library(
"//proto/google/fhir/proto/r4/core:codes_proto",
"//proto/google/fhir/proto/r4/core:datatypes_proto",
],
proto_library_prefix = "fhirproto",
)

fhir_proto_library(
name = "fhirproto_extensions",
srcs = [
"fhirproto_extensions.proto",
],
Expand All @@ -29,10 +30,10 @@ fhir_proto_library(
"//proto/google/fhir/proto/r4/core:codes_proto",
"//proto/google/fhir/proto/r4/core:datatypes_proto",
],
proto_library_prefix = "fhirproto_extensions",
)

fhir_proto_library(
name = "ml_extensions",
srcs = [
"ml_extensions.proto",
],
Expand All @@ -41,7 +42,6 @@ fhir_proto_library(
"//proto/google/fhir/proto/r4/core:codes_proto",
"//proto/google/fhir/proto/r4/core:datatypes_proto",
],
proto_library_prefix = "ml_extensions",
)

gen_fhir_protos(
Expand All @@ -51,6 +51,7 @@ gen_fhir_protos(
)

fhir_proto_library(
name = "uscore", # buildifier: disable=duplicated-name
srcs = [
"uscore.proto",
],
Expand All @@ -62,24 +63,23 @@ fhir_proto_library(
"//proto/google/fhir/proto/r4/core:datatypes_proto",
"//proto/google/fhir/proto/r4/core:valuesets_proto",
],
proto_library_prefix = "uscore",
)

fhir_proto_library(
name = "uscore_codes",
srcs = [
"uscore_codes.proto",
],
proto_deps = [
"//proto/google/fhir/proto:annotations_proto",
"//proto/google/fhir/proto/r4/core:datatypes_proto",
],
proto_library_prefix = "uscore_codes",
)

fhir_proto_library(
name = "primitive_test_suite",
srcs = ["primitive_test_suite.proto"],
proto_deps = [
"//proto/google/fhir/proto/r4/core:datatypes_proto",
],
proto_library_prefix = "primitive_test_suite",
)
8 changes: 4 additions & 4 deletions proto/google/fhir/proto/r4/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,33 @@ package(default_visibility = ["//visibility:public"])
licenses(["notice"])

fhir_proto_library(
name = "datatypes",
srcs = ["datatypes.proto"],
proto_deps = [
":codes_proto",
":valuesets_proto",
"//proto/google/fhir/proto:annotations_proto",
],
proto_library_prefix = "datatypes",
)

fhir_proto_library(
name = "codes",
srcs = ["codes.proto"],
proto_deps = [
"//proto/google/fhir/proto:annotations_proto",
],
proto_library_prefix = "codes",
)

fhir_proto_library(
name = "valuesets",
srcs = ["valuesets.proto"],
proto_deps = [
"//proto/google/fhir/proto:annotations_proto",
],
proto_library_prefix = "valuesets",
)

fhir_proto_library(
name = "extensions",
srcs = [
"extensions.proto",
],
Expand All @@ -40,7 +41,6 @@ fhir_proto_library(
":valuesets_proto",
"//proto/google/fhir/proto:annotations_proto",
],
proto_library_prefix = "extensions",
)

# We also make the .proto files readable for testing.
Expand Down
Loading
Loading