Skip to content

Commit

Permalink
Migrate out of the old action API in Bazel (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentlb authored and nlopezgi committed Dec 14, 2018
1 parent 91ef088 commit f6664b6
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion container/flatten.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _impl(ctx):
diff_id_args = ["--diff_id=%s" % f.path for f in diff_ids]
config_arg = "--config=%s" % image["config"].path

ctx.action(
ctx.actions.run(
executable = ctx.executable._flattener,
arguments = legacy_base_arg + digest_args + layer_args + diff_id_args +
uncompressed_layer_args + [
Expand Down
6 changes: 3 additions & 3 deletions container/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def _image_config(
null_entrypoint = False,
null_cmd = False):
"""Create the configuration for a new container image."""
config = ctx.new_file(name + "." + layer_name + ".config")
manifest = ctx.new_file(name + "." + layer_name + ".manifest")
config = ctx.actions.declare_file(name + "." + layer_name + ".config")
manifest = ctx.actions.declare_file(name + "." + layer_name + ".manifest")

label_file_dict = _string_to_label(
ctx.files.label_files,
Expand Down Expand Up @@ -186,7 +186,7 @@ def _image_config(
args += ["--stamp-info-file=%s" % f.path for f in stamp_inputs]
inputs += stamp_inputs

ctx.action(
ctx.actions.run(
executable = ctx.executable.create_image_config,
arguments = args,
inputs = inputs,
Expand Down
6 changes: 3 additions & 3 deletions container/layer.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ def build_layer(
if ":" in k:
fail("The source of a symlink cannot container ':', got: %s" % k)
args += ["--link=%s:%s" % (k, symlinks[k]) for k in symlinks]
arg_file = ctx.new_file(name + "-layer.args")
ctx.file_action(arg_file, "\n".join(args))
ctx.action(
arg_file = ctx.actions.declare_file(name + "-layer.args")
ctx.actions.write(arg_file, "\n".join(args))
ctx.actions.run(
executable = build_layer_exec,
arguments = ["--flagfile=" + arg_file.path],
inputs = files + file_map.values() + tars + debs + [arg_file],
Expand Down
12 changes: 6 additions & 6 deletions container/layer_tools.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ load(
)

def _extract_layers(ctx, name, artifact):
config_file = ctx.new_file(name + "." + artifact.basename + ".config")
manifest_file = ctx.new_file(name + "." + artifact.basename + ".manifest")
ctx.action(
config_file = ctx.actions.declare_file(name + "." + artifact.basename + ".config")
manifest_file = ctx.actions.declare_file(name + "." + artifact.basename + ".manifest")
ctx.actions.run(
executable = ctx.executable.extract_config,
arguments = [
"--tarball",
Expand Down Expand Up @@ -99,7 +99,7 @@ def assemble(ctx, images, output, stamp = False):
if stamp:
args += ["--stamp-info-file=%s" % f.path for f in (ctx.info_file, ctx.version_file)]
inputs += [ctx.info_file, ctx.version_file]
ctx.action(
ctx.actions.run(
executable = ctx.executable.join_layers,
arguments = args,
inputs = inputs,
Expand Down Expand Up @@ -178,7 +178,7 @@ def incremental_load(
"docker run %s %s" % (run_flags, tag_reference),
]

ctx.template_action(
ctx.actions.expand_template(
template = ctx.file.incremental_load_template,
substitutions = {
"%{docker_tool_path}": toolchain_info.tool_path,
Expand All @@ -194,7 +194,7 @@ def incremental_load(
"%{run_statements}": "\n".join(run_statements),
},
output = output,
executable = True,
is_executable = True,
)

tools = {
Expand Down
4 changes: 2 additions & 2 deletions container/push.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ def _impl(ctx):
if toolchain_info.client_config != "":
pusher_args += [" --client-config-dir {}".format(toolchain_info.client_config)]

ctx.template_action(
ctx.actions.expand_template(
template = ctx.file._tag_tpl,
substitutions = {
"%{args}": " ".join(pusher_args),
"%{container_pusher}": _get_runfile_path(ctx, ctx.executable._pusher),
},
output = ctx.outputs.executable,
executable = True,
is_executable = True,
)
runfiles = ctx.runfiles(files = [ctx.executable._pusher] + image_files + stamp_inputs)
runfiles = runfiles.merge(ctx.attr._pusher.default_runfiles)
Expand Down
10 changes: 5 additions & 5 deletions contrib/push-all.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def _impl(ctx):

runfiles += [image["config"]] + blobsums + blobs

out = ctx.new_file("%s.%d.push" % (ctx.label.name, index))
ctx.template_action(
out = ctx.actions.declare_file("%s.%d.push" % (ctx.label.name, index))
ctx.actions.expand_template(
template = ctx.file._tag_tpl,
substitutions = {
"%{stamp}": stamp_arg,
Expand All @@ -76,13 +76,13 @@ def _impl(ctx):
"%{container_pusher}": _get_runfile_path(ctx, ctx.executable._pusher),
},
output = out,
executable = True,
is_executable = True,
)

scripts += [out]
runfiles += [out]

ctx.template_action(
ctx.actions.expand_template(
template = ctx.file._all_tpl,
substitutions = {
"%{push_statements}": "\n".join([
Expand All @@ -91,7 +91,7 @@ def _impl(ctx):
]),
},
output = ctx.outputs.executable,
executable = True,
is_executable = True,
)

return struct(runfiles = ctx.runfiles(files = [
Expand Down
2 changes: 1 addition & 1 deletion java/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def _jar_app_layer_impl(ctx):
# Classpaths can grow long and there is a limit on the length of a
# command line, so mitigate this by always writing the classpath out
# to a file instead.
classpath_file = ctx.new_file(ctx.attr.name + ".classpath")
classpath_file = ctx.actions.declare_file(ctx.attr.name + ".classpath")
ctx.actions.write(classpath_file, classpath)

binary_path = layer_file_path(ctx, ctx.files.binary[0])
Expand Down
8 changes: 4 additions & 4 deletions skylib/zip.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

def gzip(ctx, artifact):
"""Create an action to compute the gzipped artifact."""
out = ctx.new_file(artifact.basename + ".gz")
ctx.action(
out = ctx.actions.declare_file(artifact.basename + ".gz")
ctx.actions.run_shell(
command = "%s -n < %s > %s" % (ctx.executable.gzip.path, artifact.path, out.path),
inputs = [artifact, ctx.executable.gzip],
outputs = [out],
Expand All @@ -27,8 +27,8 @@ def gzip(ctx, artifact):

def gunzip(ctx, artifact):
"""Create an action to compute the gunzipped artifact."""
out = ctx.new_file(artifact.basename + ".nogz")
ctx.action(
out = ctx.actions.declare_file(artifact.basename + ".nogz")
ctx.actions.run_shell(
command = "%s -d < %s > %s" % (ctx.executable.gzip.path, artifact.path, out.path),
inputs = [artifact, ctx.executable.gzip],
outputs = [out],
Expand Down

0 comments on commit f6664b6

Please sign in to comment.