chromium68: Add explicitly bison-native dependency
[AGL/meta-agl-devel.git] / meta-html5-framework / recipes-wam / chromium / gn-utils.inc
1 # Permission is hereby granted, free of charge, to any person obtaining a copy
2 # of this software and associated documentation files (the "Software"), to deal
3 # in the Software without restriction, including without limitation the rights
4 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5 # copies of the Software, and to permit persons to whom the Software is
6 # furnished to do so, subject to the following conditions:
7 #
8 # The above copyright notice and this permission notice shall be included in
9 # all copies or substantial portions of the Software.
10 #
11 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
17 # THE SOFTWARE.
18
19 def gn_arch_name(yocto_arch):
20     """Translates between Yocto's architecture values and the corresponding
21     ones used by GN."""
22     translation_table = {
23         'aarch64': 'arm64',
24         'arm': 'arm',
25         'i586': 'x86',
26         'x86_64': 'x64',
27     }
28     try:
29         return translation_table[yocto_arch]
30     except KeyError:
31         bb.msg.fatal('"%s" is not a supported architecture.' % yocto_arch)
32
33
34 def write_toolchain_file(d, file_path):
35     """Creates a complete GN toolchain file in |file_path|."""
36     import string
37     gcc_toolchain_tmpl = string.Template(
38         'gcc_toolchain("${toolchain_name}") {\n'
39         '  cc = "${cc}"\n'
40         '  cxx = "${cxx}"\n'
41         '  ar = "${ar}"\n'
42         '  ld = cxx  # GN expects a compiler, not a linker.\n'
43         '  nm = "${nm}"\n'
44         '  readelf = "${readelf}"\n'
45         '  extra_cflags = "${extra_cflags}"\n'
46         '  extra_cppflags = "${extra_cppflags}"\n'
47         '  extra_cxxflags = "${extra_cxxflags}"\n'
48         '  extra_ldflags = "${extra_ldflags}"\n'
49         '  toolchain_args = {\n'
50         '    current_cpu = "${current_cpu}"\n'
51         '    current_os = "linux"\n'
52         '    is_clang = false\n'
53         '  }\n'
54         '}\n'
55     )
56     clang_toolchain_tmpl = string.Template(
57         'clang_toolchain("clang_${toolchain_name}") {\n'
58         '  extra_cflags = "${extra_cflags}"\n'
59         '  extra_cppflags = "${extra_cppflags}"\n'
60         '  extra_cxxflags = "${extra_cxxflags}"\n'
61         '  extra_ldflags = "${extra_ldflags}"\n'
62         '  toolchain_args = {\n'
63         '    current_cpu = "${current_cpu}"\n'
64         '    current_os = "linux"\n'
65         '    is_clang = true\n'
66         '    use_gold = true\n'
67         '  }\n'
68         '}\n'
69     )
70
71     native_toolchain = {
72         'toolchain_name': 'yocto_native',
73         'current_cpu': gn_arch_name(d.getVar('BUILD_ARCH', True)),
74         'cc': d.expand('${BUILD_CC}'),
75         'cxx': d.expand('${BUILD_CXX}'),
76         'ar': d.expand('${BUILD_AR}'),
77         'nm': d.expand('${BUILD_NM}'),
78         'readelf': d.expand('${BUILD_PREFIX}readelf'),
79         'extra_cflags': d.expand('${BUILD_CFLAGS}'),
80         'extra_cppflags': d.expand('${BUILD_CPPFLAGS}'),
81         'extra_cxxflags': d.expand('${BUILD_CXXFLAGS}'),
82         'extra_ldflags': d.expand('${BUILD_LDFLAGS}'),
83     }
84     target_toolchain = {
85         'toolchain_name': 'yocto_target',
86         'current_cpu': gn_arch_name(d.getVar('TUNE_ARCH', True)),
87         'cc': d.expand('${CC}'),
88         'cxx': d.expand('${CXX}'),
89         'ar': d.expand('${AR}'),
90         'nm': d.expand('${NM}'),
91         'readelf': d.expand('${TARGET_PREFIX}readelf'),
92         'extra_cflags': d.expand('${TARGET_CFLAGS}'),
93         'extra_cppflags': d.expand('${TARGET_CPPFLAGS}'),
94         'extra_cxxflags': d.expand('${TARGET_CXXFLAGS}'),
95         'extra_ldflags': d.expand('${TARGET_LDFLAGS}'),
96         'strip': '',
97     }
98
99     with open(file_path, 'w') as toolchain_file:
100         toolchain_file.write(
101             '# This file has been generated automatically.\n'
102             '\n'
103             'import("//build/config/sysroot.gni")\n'
104             'import("//build/toolchain/gcc_toolchain.gni")\n'
105             '\n'
106         )
107         toolchain_file.write(gcc_toolchain_tmpl.substitute(native_toolchain))
108         toolchain_file.write(gcc_toolchain_tmpl.substitute(target_toolchain))
109         toolchain_file.write(clang_toolchain_tmpl.substitute(native_toolchain))
110         toolchain_file.write(clang_toolchain_tmpl.substitute(target_toolchain))