blob: 097fb426e5768b801a0a81c07cd72f502d4050b3 [file] [log] [blame]
Philipp Wollermann4c558982017-07-27 18:01:12 +02001# 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
17def _embedded_tools(ctx):
vladmos20a042f2018-06-01 04:51:21 -070018 # 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 Wollermann4c558982017-07-27 18:01:12 +020030
31embedded_tools = rule(
vladmos20a042f2018-06-01 04:51:21 -070032 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 Wollermann4c558982017-07-27 18:01:12 +020043)
44
45def _srcsfile(ctx):
vladmos20a042f2018-06-01 04:51:21 -070046 ctx.file_action(
47 output = ctx.outputs.out,
48 content = "\n".join([f.path for f in ctx.files.srcs]),
49 )
Philipp Wollermann4c558982017-07-27 18:01:12 +020050
51srcsfile = rule(
vladmos20a042f2018-06-01 04:51:21 -070052 implementation = _srcsfile,
53 attrs = {
54 "srcs": attr.label_list(allow_files = True),
55 "out": attr.output(mandatory = True),
56 },
Philipp Wollermann4c558982017-07-27 18:01:12 +020057)