xref: /aosp_15_r20/external/perfetto/gn/perfetto_host_executable.gni (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1*6dbdd20aSAndroid Build Coastguard Worker# Copyright (C) 2019 The Android Open Source Project
2*6dbdd20aSAndroid Build Coastguard Worker#
3*6dbdd20aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
4*6dbdd20aSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
5*6dbdd20aSAndroid Build Coastguard Worker# You may obtain a copy of the License at
6*6dbdd20aSAndroid Build Coastguard Worker#
7*6dbdd20aSAndroid Build Coastguard Worker#      http://www.apache.org/licenses/LICENSE-2.0
8*6dbdd20aSAndroid Build Coastguard Worker#
9*6dbdd20aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
10*6dbdd20aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
11*6dbdd20aSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*6dbdd20aSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
13*6dbdd20aSAndroid Build Coastguard Worker# limitations under the License.
14*6dbdd20aSAndroid Build Coastguard Worker
15*6dbdd20aSAndroid Build Coastguard Workerimport("perfetto.gni")
16*6dbdd20aSAndroid Build Coastguard Worker
17*6dbdd20aSAndroid Build Coastguard Worker# A template to make host tools handier. The main problem it solves is that when
18*6dbdd20aSAndroid Build Coastguard Worker# building host toolchain tools on an Android build, the executables end up in
19*6dbdd20aSAndroid Build Coastguard Worker# out/xxx/gcc_like_host, which is an inconvenient location. Our developers
20*6dbdd20aSAndroid Build Coastguard Worker# (and also some of our scripts) expect them to live in out/xxx/.
21*6dbdd20aSAndroid Build Coastguard Worker# This template takes care takes care of building the target only on the host
22*6dbdd20aSAndroid Build Coastguard Worker# toolchain and copy it over in the root build directory.
23*6dbdd20aSAndroid Build Coastguard Workertemplate("perfetto_host_executable") {
24*6dbdd20aSAndroid Build Coastguard Worker  if (current_toolchain == host_toolchain) {
25*6dbdd20aSAndroid Build Coastguard Worker    executable(target_name) {
26*6dbdd20aSAndroid Build Coastguard Worker      if (defined(invoker.configs)) {
27*6dbdd20aSAndroid Build Coastguard Worker        configs += invoker.configs
28*6dbdd20aSAndroid Build Coastguard Worker      }
29*6dbdd20aSAndroid Build Coastguard Worker      forward_variables_from(invoker, "*", [ "configs" ])
30*6dbdd20aSAndroid Build Coastguard Worker    }
31*6dbdd20aSAndroid Build Coastguard Worker  } else {
32*6dbdd20aSAndroid Build Coastguard Worker    not_needed(invoker, "*", [ "testonly" ])
33*6dbdd20aSAndroid Build Coastguard Worker    _host_target = ":$target_name($host_toolchain)"
34*6dbdd20aSAndroid Build Coastguard Worker    _testonly = defined(invoker.testonly) && invoker.testonly
35*6dbdd20aSAndroid Build Coastguard Worker    if ((perfetto_build_with_embedder && !build_with_chromium) ||
36*6dbdd20aSAndroid Build Coastguard Worker        is_perfetto_build_generator) {
37*6dbdd20aSAndroid Build Coastguard Worker      # Don't copy anything in V8 and other GN embedder builds, just add a
38*6dbdd20aSAndroid Build Coastguard Worker      # dependency to the host target. This causes problems on some bots.
39*6dbdd20aSAndroid Build Coastguard Worker      # (See crbug.com/1002599).
40*6dbdd20aSAndroid Build Coastguard Worker      group(target_name) {
41*6dbdd20aSAndroid Build Coastguard Worker        testonly = _testonly
42*6dbdd20aSAndroid Build Coastguard Worker        deps = [ _host_target ]
43*6dbdd20aSAndroid Build Coastguard Worker      }
44*6dbdd20aSAndroid Build Coastguard Worker    } else {
45*6dbdd20aSAndroid Build Coastguard Worker      copy(target_name) {
46*6dbdd20aSAndroid Build Coastguard Worker        testonly = _testonly
47*6dbdd20aSAndroid Build Coastguard Worker        deps = [ _host_target ]
48*6dbdd20aSAndroid Build Coastguard Worker        _host_out_dir = get_label_info(_host_target, "root_out_dir")
49*6dbdd20aSAndroid Build Coastguard Worker        _extension = ""
50*6dbdd20aSAndroid Build Coastguard Worker        if (host_os == "win") {
51*6dbdd20aSAndroid Build Coastguard Worker          _extension = ".exe"
52*6dbdd20aSAndroid Build Coastguard Worker        }
53*6dbdd20aSAndroid Build Coastguard Worker        sources = [ "$_host_out_dir/$target_name${_extension}" ]
54*6dbdd20aSAndroid Build Coastguard Worker        outputs = [ "$root_out_dir/$target_name${_extension}" ]
55*6dbdd20aSAndroid Build Coastguard Worker      }
56*6dbdd20aSAndroid Build Coastguard Worker    }
57*6dbdd20aSAndroid Build Coastguard Worker  }
58*6dbdd20aSAndroid Build Coastguard Worker}
59