1# 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") {
24  if (current_toolchain == host_toolchain) {
25    executable(target_name) {
26      if (defined(invoker.configs)) {
27        configs += invoker.configs
28      }
29      forward_variables_from(invoker, "*", [ "configs" ])
30    }
31  } else {
32    not_needed(invoker, "*", [ "testonly" ])
33    _host_target = ":$target_name($host_toolchain)"
34    _testonly = defined(invoker.testonly) && invoker.testonly
35    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).
40      group(target_name) {
41        testonly = _testonly
42        deps = [ _host_target ]
43      }
44    } else {
45      copy(target_name) {
46        testonly = _testonly
47        deps = [ _host_target ]
48        _host_out_dir = get_label_info(_host_target, "root_out_dir")
49        _extension = ""
50        if (host_os == "win") {
51          _extension = ".exe"
52        }
53        sources = [ "$_host_out_dir/$target_name${_extension}" ]
54        outputs = [ "$root_out_dir/$target_name${_extension}" ]
55      }
56    }
57  }
58}
59