From 3789156a41cc4952a4a89f333d092d23b3eaa18d Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Wed, 3 May 2023 00:26:40 -0700 Subject: [PATCH] Internal change PiperOrigin-RevId: 529011480 --- .../port/drishti_proto_alias_rules.bzl | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 mediapipe/framework/port/drishti_proto_alias_rules.bzl diff --git a/mediapipe/framework/port/drishti_proto_alias_rules.bzl b/mediapipe/framework/port/drishti_proto_alias_rules.bzl new file mode 100644 index 000000000..7df141cbe --- /dev/null +++ b/mediapipe/framework/port/drishti_proto_alias_rules.bzl @@ -0,0 +1,31 @@ +"""Rules implementation for mediapipe_proto_alias.bzl, do not load directly.""" + +def _copy_header_impl(ctx): + source = ctx.attr.source.replace("//", "").replace(":", "/") + files = [] + for dep in ctx.attr.deps: + for header in dep[CcInfo].compilation_context.direct_headers: + if (header.short_path == source): + files.append(header) + if len(files) != 1: + fail("Expected exactly 1 source, got ", str(files)) + dest_file = ctx.actions.declare_file(ctx.attr.filename) + + # Use expand_template() with no substitutions as a simple copier. + ctx.actions.expand_template( + template = files[0], + output = dest_file, + substitutions = {}, + ) + return [DefaultInfo(files = depset([dest_file]))] + +copy_header = rule( + implementation = _copy_header_impl, + attrs = { + "filename": attr.string(), + "source": attr.string(), + "deps": attr.label_list(providers = [CcInfo]), + }, + output_to_genfiles = True, + outputs = {"out": "%{filename}"}, +)