blob: d0b0969438eb1d8ccc924918613debf4bae18416 [file] [log] [blame]
David Ostrovskyb81b4f72016-05-21 19:55:01 +02001# Copyright (C) 2016 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# Syntactic sugar for native genrule() rule:
16# expose ROOT shell variable
17# expose TMP shell variable
David Ostrovskyb81b4f72016-05-21 19:55:01 +020018
Han-Wen Nienhuys29cced52016-10-27 11:57:01 +020019def genrule2(cmd, **kwargs):
Han-Wen Nienhuysb6a40482018-07-10 11:51:36 +020020 cmd = " && ".join([
21 "ROOT=$$PWD",
22 "TMP=$$(mktemp -d || mktemp -d -t bazel-tmp)",
23 "(" + cmd + ")",
David Ostrovskydf038952019-10-31 23:43:47 +010024 "rm -rf $$TMP",
Han-Wen Nienhuysb6a40482018-07-10 11:51:36 +020025 ])
26 native.genrule(
27 cmd = cmd,
28 **kwargs
29 )