Philipp Wollermann | 4c55898 | 2017-07-27 18:01:12 +0200 | [diff] [blame] | 1 | # pylint: disable=g-bad-file-header |
| 2 | # Copyright 2017 The Bazel Authors. All rights reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http:#www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | """Contains Skylark rules used to build the embedded_tools.zip.""" |
| 16 | |
| 17 | def _embedded_tools(ctx): |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 18 | # The list of arguments we pass to the script. |
| 19 | args_file = ctx.new_file(ctx.label.name + ".params") |
| 20 | ctx.file_action(output = args_file, content = "\n".join([f.path for f in ctx.files.srcs])) |
| 21 | |
| 22 | # Action to call the script. |
| 23 | ctx.action( |
| 24 | inputs = ctx.files.srcs, |
| 25 | outputs = [ctx.outputs.out], |
| 26 | arguments = [ctx.outputs.out.path, args_file.path], |
| 27 | progress_message = "Creating embedded tools: %s" % ctx.outputs.out.short_path, |
| 28 | executable = ctx.executable.tool, |
| 29 | ) |
Philipp Wollermann | 4c55898 | 2017-07-27 18:01:12 +0200 | [diff] [blame] | 30 | |
| 31 | embedded_tools = rule( |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 32 | implementation = _embedded_tools, |
| 33 | attrs = { |
| 34 | "srcs": attr.label_list(allow_files = True), |
| 35 | "out": attr.output(mandatory = True), |
| 36 | "tool": attr.label( |
| 37 | executable = True, |
| 38 | cfg = "host", |
| 39 | allow_files = True, |
| 40 | default = Label("//src:create_embedded_tools_sh"), |
| 41 | ), |
| 42 | }, |
Philipp Wollermann | 4c55898 | 2017-07-27 18:01:12 +0200 | [diff] [blame] | 43 | ) |
| 44 | |
| 45 | def _srcsfile(ctx): |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 46 | ctx.file_action( |
| 47 | output = ctx.outputs.out, |
| 48 | content = "\n".join([f.path for f in ctx.files.srcs]), |
| 49 | ) |
Philipp Wollermann | 4c55898 | 2017-07-27 18:01:12 +0200 | [diff] [blame] | 50 | |
| 51 | srcsfile = rule( |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 52 | implementation = _srcsfile, |
| 53 | attrs = { |
| 54 | "srcs": attr.label_list(allow_files = True), |
| 55 | "out": attr.output(mandatory = True), |
| 56 | }, |
Philipp Wollermann | 4c55898 | 2017-07-27 18:01:12 +0200 | [diff] [blame] | 57 | ) |