From f6664b6b5c7f4fac031883a7ec9fa6b8bab0ab98 Mon Sep 17 00:00:00 2001 From: Laurent Le Brun Date: Fri, 14 Dec 2018 23:08:28 +0100 Subject: [PATCH] Migrate out of the old action API in Bazel (#623) --- container/flatten.bzl | 2 +- container/image.bzl | 6 +++--- container/layer.bzl | 6 +++--- container/layer_tools.bzl | 12 ++++++------ container/push.bzl | 4 ++-- contrib/push-all.bzl | 10 +++++----- java/image.bzl | 2 +- skylib/zip.bzl | 8 ++++---- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/container/flatten.bzl b/container/flatten.bzl index a3ddd8e39..e2502bdf8 100644 --- a/container/flatten.bzl +++ b/container/flatten.bzl @@ -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 + [ diff --git a/container/image.bzl b/container/image.bzl index fb5207528..110d0e8f0 100644 --- a/container/image.bzl +++ b/container/image.bzl @@ -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, @@ -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, diff --git a/container/layer.bzl b/container/layer.bzl index 8f55ad363..f2b20d068 100644 --- a/container/layer.bzl +++ b/container/layer.bzl @@ -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], diff --git a/container/layer_tools.bzl b/container/layer_tools.bzl index 279f1214a..ffdef222a 100644 --- a/container/layer_tools.bzl +++ b/container/layer_tools.bzl @@ -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", @@ -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, @@ -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, @@ -194,7 +194,7 @@ def incremental_load( "%{run_statements}": "\n".join(run_statements), }, output = output, - executable = True, + is_executable = True, ) tools = { diff --git a/container/push.bzl b/container/push.bzl index 8e0a87981..3523d963a 100644 --- a/container/push.bzl +++ b/container/push.bzl @@ -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) diff --git a/contrib/push-all.bzl b/contrib/push-all.bzl index fd3f16999..2536a0384 100644 --- a/contrib/push-all.bzl +++ b/contrib/push-all.bzl @@ -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, @@ -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([ @@ -91,7 +91,7 @@ def _impl(ctx): ]), }, output = ctx.outputs.executable, - executable = True, + is_executable = True, ) return struct(runfiles = ctx.runfiles(files = [ diff --git a/java/image.bzl b/java/image.bzl index b86402b01..f84f6c666 100644 --- a/java/image.bzl +++ b/java/image.bzl @@ -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]) diff --git a/skylib/zip.bzl b/skylib/zip.bzl index 14c15fded..d9471db89 100644 --- a/skylib/zip.bzl +++ b/skylib/zip.bzl @@ -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], @@ -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],