Debian Codegraph @

build/moz.configure/clang_plugin.configure

raw
1 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7
8 @depends(host_library_name_info, build_environment, when="--enable-clang-plugin")
9 def clang_plugin_path(library_name_info, build_env):
10 topobjdir = build_env.topobjdir
11 if topobjdir.endswith("/js/src"):
12 topobjdir = topobjdir[:-7]
13 return os.path.abspath(
14 os.path.join(
15 topobjdir,
16 "build",
17 "clang-plugin",
18 "%sclang-plugin%s"
19 % (library_name_info.dll.prefix, library_name_info.dll.suffix),
20 )
21 )
22
23
24 set_config("CLANG_PLUGIN", clang_plugin_path)
25
26 option(
27 "--enable-clang-plugin-alpha",
28 env="ENABLE_CLANG_PLUGIN_ALPHA",
29 help="Enable static analysis with clang-plugin alpha checks",
30 when="--enable-clang-plugin",
31 )
32
33
34 set_config("ENABLE_CLANG_PLUGIN_ALPHA", True, when="--enable-clang-plugin-alpha")
35 set_define("MOZ_CLANG_PLUGIN_ALPHA", True, when="--enable-clang-plugin-alpha")
36
37
38 option(
39 "--enable-mozsearch-plugin",
40 env="ENABLE_MOZSEARCH_PLUGIN",
41 help="Enable building with the mozsearch indexer plugin",
42 when="--enable-clang-plugin",
43 )
44
45
46 set_config("ENABLE_MOZSEARCH_PLUGIN", True, when="--enable-mozsearch-plugin")
47
48
49 @depends(
50 clang_plugin_path,
51 host,
52 llvm_config,
53 "--enable-mozsearch-plugin",
54 build_environment,
55 when="--enable-clang-plugin",
56 )
57 def clang_plugin_flags(
58 clang_plugin,
59 host,
60 llvm_config,
61 enable_mozsearch_plugin,
62 build_environment,
63 ):
64 llvm_cxxflags = check_cmd_output(llvm_config, "--cxxflags").split()
65 llvm_ldflags = check_cmd_output(llvm_config, "--ldflags").replace("\n", " ").split()
66
67 if host.kernel == "WINNT":
68 # Replace any backslashes from paths with forward slash.
69 llvm_cxxflags = [arg.replace("\\", "/") for arg in llvm_cxxflags]
70 llvm_ldflags = [arg.replace("\\", "/") for arg in llvm_ldflags]
71
72 clang_plugin_flags = [
73 "-Xclang",
74 "-load",
75 "-Xclang",
76 clang_plugin,
77 "-Xclang",
78 "-add-plugin",
79 "-Xclang",
80 "moz-check",
81 ]
82
83 if enable_mozsearch_plugin:
84 clang_plugin_flags.extend(
85 ["-Xclang", "-add-plugin", "-Xclang", "mozsearch-index"]
86 )
87 # Parameters are: srcdir, outdir (path where output JSON is stored), objdir.
88 parameters = [
89 build_environment.topsrcdir,
90 os.path.join(build_environment.topobjdir, "mozsearch_index"),
91 build_environment.topobjdir,
92 ]
93 for parameter in parameters:
94 clang_plugin_flags.extend(
95 ["-Xclang", "-plugin-arg-mozsearch-index", "-Xclang", parameter]
96 )
97
98 return namespace(
99 plugin_flags=clang_plugin_flags,
100 llvm_cxxflags=llvm_cxxflags,
101 llvm_ldflags=llvm_ldflags,
102 )
103
104
105 set_config(
106 "CLANG_PLUGIN_FLAGS",
107 depends(clang_plugin_flags)(lambda plugin: plugin.plugin_flags if plugin else []),
108 )
109 set_config(
110 "LLVM_CXXFLAGS",
111 depends(clang_plugin_flags)(lambda plugin: plugin.llvm_cxxflags if plugin else []),
112 )
113 set_config(
114 "LLVM_LDFLAGS",
115 depends(clang_plugin_flags)(lambda plugin: plugin.llvm_ldflags if plugin else []),
116 )