blob: 59cd6819c577dd8ea10329f9a0fb163e0513b252 [file] [log] [blame]
Primiano Tucciec590132020-11-16 14:16:44 +01001# Copyright (C) 2020 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# This action generates a perfetto_version.gen.h which exposes some
16# PERFETTO_VERSION_xxx() macros that contains the git revision and release
17# number from the CHANGELOG.
18# This template is used only in two places: in //base (for C++ code) and in
19# //ui. This teamplate exists only to keep the logic consistent and avoid that
20# base's and ui's logic diverge.
21
22import("perfetto.gni")
23
Primiano Tuccidc77d722021-10-15 13:17:52 +010024_ver_script = "${perfetto_root_path}tools/write_version_header.py"
25_has_git = false
26if (perfetto_enable_git_rev_version_header) {
27 _has_git = "1" == exec_script(_ver_script, [ "--check_git" ], "trim string")
28}
29
Primiano Tucciec590132020-11-16 14:16:44 +010030template("gen_perfetto_version_header") {
31 action(target_name) {
Primiano Tuccidc77d722021-10-15 13:17:52 +010032 script = _ver_script
Primiano Tuccif0ed1d42020-11-18 16:30:18 +010033 changelog = "${perfetto_root_path}CHANGELOG"
34 inputs = [ changelog ]
Primiano Tucciec590132020-11-16 14:16:44 +010035 outputs = []
36 args = []
Primiano Tuccidc77d722021-10-15 13:17:52 +010037 if (_has_git) {
Primiano Tucciec590132020-11-16 14:16:44 +010038 inputs += [ "${perfetto_root_path}.git/HEAD" ]
39 }
40
41 if (defined(invoker.cpp_out)) {
42 args += [
Primiano Tuccif0ed1d42020-11-18 16:30:18 +010043 "--changelog",
44 rebase_path(changelog, root_build_dir),
Primiano Tucciec590132020-11-16 14:16:44 +010045 "--cpp_out",
46 rebase_path(invoker.cpp_out, root_build_dir),
47 ]
48 outputs += [ invoker.cpp_out ]
49 }
50 if (defined(invoker.ts_out)) {
51 args += [
52 "--ts_out",
53 rebase_path(invoker.ts_out, root_build_dir),
54 ]
55 outputs += [ invoker.ts_out ]
56 }
Primiano Tuccidc77d722021-10-15 13:17:52 +010057 if (!_has_git) {
Florian Mayer89516832021-04-21 16:37:00 +010058 args += [ "--no_git" ]
59 }
Primiano Tucciec590132020-11-16 14:16:44 +010060 }
61}