From 5d761ecc6d337bceda68df38781589e2c11967b4 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 18 Apr 2017 23:06:07 +0200 Subject: Move the sha256 tool into its own directory, as it isn't specific to docker_build. PiperOrigin-RevId: 153508081 --- tools/BUILD | 1 + tools/build_defs/docker/BUILD | 6 ------ tools/build_defs/docker/build.bzl | 3 ++- tools/build_defs/docker/hash.bzl | 34 ---------------------------------- tools/build_defs/docker/sha256.py | 27 --------------------------- tools/build_defs/hash/BUILD | 18 ++++++++++++++++++ tools/build_defs/hash/hash.bzl | 34 ++++++++++++++++++++++++++++++++++ tools/build_defs/hash/sha256.py | 27 +++++++++++++++++++++++++++ 8 files changed, 82 insertions(+), 68 deletions(-) delete mode 100644 tools/build_defs/docker/hash.bzl delete mode 100644 tools/build_defs/docker/sha256.py create mode 100644 tools/build_defs/hash/BUILD create mode 100644 tools/build_defs/hash/hash.bzl create mode 100644 tools/build_defs/hash/sha256.py diff --git a/tools/BUILD b/tools/BUILD index 3923626a94..97b160e466 100644 --- a/tools/BUILD +++ b/tools/BUILD @@ -12,6 +12,7 @@ filegroup( "//tools/build_defs/apple:srcs", "//tools/build_defs/apple/test:srcs", "//tools/build_defs/docker:srcs", + "//tools/build_defs/hash:srcs", "//tools/build_defs/pkg:srcs", "//tools/build_defs/repo:srcs", "//tools/build_rules:srcs", diff --git a/tools/build_defs/docker/BUILD b/tools/build_defs/docker/BUILD index 4aa6b03414..1b45f0256f 100644 --- a/tools/build_defs/docker/BUILD +++ b/tools/build_defs/docker/BUILD @@ -114,12 +114,6 @@ py_test( ], ) -py_binary( - name = "sha256", - srcs = ["sha256.py"], - visibility = ["//visibility:public"], -) - py_binary( name = "create_image", srcs = ["create_image.py"], diff --git a/tools/build_defs/docker/build.bzl b/tools/build_defs/docker/build.bzl index 5dc38c8240..c969ac162b 100644 --- a/tools/build_defs/docker/build.bzl +++ b/tools/build_defs/docker/build.bzl @@ -17,7 +17,8 @@ load(":filetype.bzl", tar_filetype="tar", deb_filetype="deb", docker_filetype="docker") -load(":hash.bzl", _hash_tools="tools", _sha256="sha256") +load("//tools/build_defs/hash:hash.bzl", + _hash_tools="tools", _sha256="sha256") load(":label.bzl", _string_to_label="string_to_label") load(":layers.bzl", _assemble_image="assemble", diff --git a/tools/build_defs/docker/hash.bzl b/tools/build_defs/docker/hash.bzl deleted file mode 100644 index 5d3b52c568..0000000000 --- a/tools/build_defs/docker/hash.bzl +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -"""Functions for producing the hash of an artifact.""" - -def sha256(ctx, artifact): - """Create an action to compute the SHA-256 of an artifact.""" - out = ctx.new_file(artifact.basename + ".sha256") - ctx.action( - executable = ctx.executable.sha256, - arguments = [artifact.path, out.path], - inputs = [artifact], - outputs = [out], - mnemonic = "SHA256") - return out - - -tools = { - "sha256": attr.label( - default=Label("//tools/build_defs/docker:sha256"), - cfg="host", - executable=True, - allow_files=True) -} diff --git a/tools/build_defs/docker/sha256.py b/tools/build_defs/docker/sha256.py deleted file mode 100644 index b1e062436d..0000000000 --- a/tools/build_defs/docker/sha256.py +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2015 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -"""A wrapper to have a portable SHA-256 tool.""" - -# TODO(dmarting): instead of this tool we should make SHA-256 of artifacts -# available in Skylark. -import hashlib -import sys - -if __name__ == "__main__": - if len(sys.argv) != 3: - print "Usage: %s input output" % sys.argv[0] - sys.exit(-1) - with open(sys.argv[2], "w") as outputfile: - with open(sys.argv[1], "rb") as inputfile: - outputfile.write(hashlib.sha256(inputfile.read()).hexdigest()) diff --git a/tools/build_defs/hash/BUILD b/tools/build_defs/hash/BUILD new file mode 100644 index 0000000000..878ce002da --- /dev/null +++ b/tools/build_defs/hash/BUILD @@ -0,0 +1,18 @@ +licenses(["notice"]) # Apache 2.0 + +filegroup( + name = "srcs", + srcs = glob(["**"]), + visibility = ["//tools:__pkg__"], +) + +exports_files( + ["README.md"], + visibility = ["//site:__pkg__"], +) + +py_binary( + name = "sha256", + srcs = ["sha256.py"], + visibility = ["//visibility:public"], +) diff --git a/tools/build_defs/hash/hash.bzl b/tools/build_defs/hash/hash.bzl new file mode 100644 index 0000000000..62741540b2 --- /dev/null +++ b/tools/build_defs/hash/hash.bzl @@ -0,0 +1,34 @@ +# Copyright 2017 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Functions for producing the hash of an artifact.""" + +def sha256(ctx, artifact): + """Create an action to compute the SHA-256 of an artifact.""" + out = ctx.new_file(artifact.basename + ".sha256") + ctx.action( + executable = ctx.executable.sha256, + arguments = [artifact.path, out.path], + inputs = [artifact], + outputs = [out], + mnemonic = "SHA256") + return out + + +tools = { + "sha256": attr.label( + default=Label("//tools/build_defs/hash:sha256"), + cfg="host", + executable=True, + allow_files=True) +} diff --git a/tools/build_defs/hash/sha256.py b/tools/build_defs/hash/sha256.py new file mode 100644 index 0000000000..b1e062436d --- /dev/null +++ b/tools/build_defs/hash/sha256.py @@ -0,0 +1,27 @@ +# Copyright 2015 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""A wrapper to have a portable SHA-256 tool.""" + +# TODO(dmarting): instead of this tool we should make SHA-256 of artifacts +# available in Skylark. +import hashlib +import sys + +if __name__ == "__main__": + if len(sys.argv) != 3: + print "Usage: %s input output" % sys.argv[0] + sys.exit(-1) + with open(sys.argv[2], "w") as outputfile: + with open(sys.argv[1], "rb") as inputfile: + outputfile.write(hashlib.sha256(inputfile.read()).hexdigest()) -- cgit v1.2.3