blob: b36cc142cf74df13a4e527c85fa292d5aff9f223 [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):
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 # Action to call the script.
22 ctx.action(
23 inputs=ctx.files.srcs,
24 outputs=[ctx.outputs.out],
25 arguments=[ctx.outputs.out.path, args_file.path],
26 progress_message="Creating embedded tools: %s" % ctx.outputs.out.short_path,
27 executable=ctx.executable.tool)
28
29embedded_tools = rule(
30 implementation=_embedded_tools,
31 attrs={
32 "srcs": attr.label_list(allow_files=True),
33 "out": attr.output(mandatory=True),
34 "tool": attr.label(executable=True, cfg="host", allow_files=True,
35 default=Label("//src:create_embedded_tools_sh"))
36 }
37)
38
39def _srcsfile(ctx):
40 ctx.file_action(
41 output=ctx.outputs.out,
42 content="\n".join([f.path for f in ctx.files.srcs]))
43
44srcsfile = rule(
45 implementation=_srcsfile,
46 attrs={
47 "srcs": attr.label_list(allow_files=True),
48 "out": attr.output(mandatory=True),
49 }
50)