Skip to content

Commit fac45da

Browse files
sharmaharisamcopybara-github
authored andcommitted
Internal Change
PiperOrigin-RevId: 799008040 Change-Id: I5a69690026c7bac324840ae1b7ba46daa01474ae
1 parent 0a48e6e commit fac45da

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

tools/defs.bzl

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
load("@rules_pkg//pkg:mappings.bzl", "pkg_mklink")
44
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
5+
load("@bazel_skylib//rules:write_file.bzl", "write_file")
56

67
def buildpack(name, executables, prefix, version, api = "0.9", srcs = None, extension = "tgz", strip_prefix = ".", visibility = None):
78
"""Macro to create a single buildpack as a tgz or tar archive.
@@ -63,6 +64,101 @@ def buildpack(name, executables, prefix, version, api = "0.9", srcs = None, exte
6364
visibility = visibility,
6465
)
6566

67+
def buildpack_using_runner(
68+
name,
69+
prefix,
70+
version,
71+
buildpack_id,
72+
api = "0.9",
73+
srcs = None,
74+
extension = "tgz",
75+
strip_prefix = ".",
76+
visibility = None):
77+
"""Macro to create a single buildpack as a tgz or tar archive.
78+
79+
The result is a tar or tgz archive with a buildpack descriptor
80+
(`buildpack.toml`) and interface scripts (bin/detect, bin/build).
81+
82+
As this is a macro, the actual target name for the buildpack is `name_using_runner.extension`.
83+
The builder.toml spec allows either tar or tgz archives.
84+
85+
Args:
86+
name: Base name for the targets.
87+
prefix: Namespace prefix.
88+
version: Buildpack version.
89+
buildpack_id: The full unique ID of the buildpack (e.g., google.nodejs.runtime).
90+
api: Buildpacks API version.
91+
srcs: Additional files to include.
92+
extension: Archive extension ("tgz" or "tar").
93+
strip_prefix: Prefix to strip from srcs.
94+
visibility: Target visibility.
95+
"""
96+
descriptor_target_name = name + "_using_runner.descriptor"
97+
descriptor_output_filename = name + "_using_runner.buildpack.toml"
98+
99+
_buildpack_descriptor(
100+
name = descriptor_target_name,
101+
api = api,
102+
version = version,
103+
prefix = prefix,
104+
bp_name = name,
105+
output = descriptor_output_filename,
106+
)
107+
108+
if not srcs:
109+
srcs = []
110+
111+
detect_script_name = name + "_detect_script"
112+
write_file(
113+
name = detect_script_name,
114+
out = "detect.sh",
115+
content = ["""#!/usr/bin/env bash
116+
/usr/local/bin/runner -buildpack="{id}" -phase="detect" "$@"
117+
""".format(id = buildpack_id)],
118+
is_executable = True,
119+
)
120+
121+
build_script_name = name + "_build_script"
122+
write_file(
123+
name = build_script_name,
124+
out = "build.sh",
125+
content = ["""#!/usr/bin/env bash
126+
/usr/local/bin/runner -buildpack="{id}" -phase="build" "$@"
127+
""".format(id = buildpack_id)],
128+
is_executable = True,
129+
)
130+
131+
pkg_mklink(
132+
name = name + "_detect_link",
133+
link_name = "bin/detect",
134+
target = "../detect.sh",
135+
)
136+
137+
pkg_mklink(
138+
name = name + "_build_link",
139+
link_name = "bin/build",
140+
target = "../build.sh",
141+
)
142+
143+
pkg_tar(
144+
name = name + "_using_runner",
145+
extension = extension,
146+
srcs = [
147+
descriptor_target_name,
148+
detect_script_name,
149+
build_script_name,
150+
name + "_detect_link",
151+
name + "_build_link",
152+
] + srcs,
153+
files = {
154+
":" + descriptor_output_filename: "buildpack.toml",
155+
},
156+
mode = "0755",
157+
package_dir = "/",
158+
strip_prefix = strip_prefix,
159+
visibility = visibility,
160+
)
161+
66162
def _buildpack_descriptor_impl(ctx):
67163
ctx.actions.expand_template(
68164
output = ctx.outputs.output,

0 commit comments

Comments
 (0)