blob: abcb761d62a9677bf5f2b53b7795dcf05b3d4b20 [file] [log] [blame]
Primiano Tucci02c11762019-08-30 00:57:59 +02001# Copyright (C) 2019 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
15import("perfetto.gni")
16
17# A template to make host tools handier. The main problem it solves is that when
18# building host toolchain tools on an Android build, the executables end up in
19# out/xxx/gcc_like_host, which is an inconvenient location. Our developers
20# (and also some of our scripts) expect them to live in out/xxx/.
21# This template takes care takes care of building the target only on the host
22# toolchain and copy it over in the root build directory.
23template("perfetto_host_executable") {
Primiano Tuccif0d7ef82019-10-04 15:35:24 +010024 if (current_toolchain == host_toolchain) {
Primiano Tucci02c11762019-08-30 00:57:59 +020025 executable(target_name) {
Primiano Tucci5cbeadf2020-04-03 22:28:40 +010026 if (defined(invoker.configs)) {
27 configs += invoker.configs
28 }
29 forward_variables_from(invoker, "*", [ "configs" ])
Primiano Tucci02c11762019-08-30 00:57:59 +020030 }
31 } else {
Primiano Tuccif0d7ef82019-10-04 15:35:24 +010032 not_needed(invoker, "*", [ "testonly" ])
33 _host_target = ":$target_name($host_toolchain)"
34 _testonly = defined(invoker.testonly) && invoker.testonly
Mikhail Khokhlov78668722019-12-20 10:26:19 +000035 if ((perfetto_build_with_embedder && !build_with_chromium) ||
36 is_perfetto_build_generator) {
37 # Don't copy anything in V8 and other GN embedder builds, just add a
38 # dependency to the host target. This causes problems on some bots.
39 # (See crbug.com/1002599).
Primiano Tuccif0d7ef82019-10-04 15:35:24 +010040 group(target_name) {
41 testonly = _testonly
Primiano Tucci2925e9d2020-01-27 10:15:58 +000042 deps = [ _host_target ]
Primiano Tucci02c11762019-08-30 00:57:59 +020043 }
44 } else {
Primiano Tuccif0d7ef82019-10-04 15:35:24 +010045 copy(target_name) {
46 testonly = _testonly
Primiano Tucci2925e9d2020-01-27 10:15:58 +000047 deps = [ _host_target ]
Primiano Tuccif0d7ef82019-10-04 15:35:24 +010048 _host_out_dir = get_label_info(_host_target, "root_out_dir")
Mikhail Khokhlov78668722019-12-20 10:26:19 +000049 _extension = ""
50 if (host_os == "win") {
51 _extension = ".exe"
52 }
Primiano Tucci2925e9d2020-01-27 10:15:58 +000053 sources = [ "$_host_out_dir/$target_name${_extension}" ]
54 outputs = [ "$root_out_dir/$target_name${_extension}" ]
Primiano Tucci02c11762019-08-30 00:57:59 +020055 }
Primiano Tucci02c11762019-08-30 00:57:59 +020056 }
Primiano Tuccif0d7ef82019-10-04 15:35:24 +010057 }
Primiano Tucci02c11762019-08-30 00:57:59 +020058}