• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021 Huawei Device Co., Ltd.
2#   Licensed under the Apache License, Version 2.0 (the "License");
3#   you may not use this file except in compliance with the License.
4#   You may obtain a copy of the License at
5#
6#       http://www.apache.org/licenses/LICENSE-2.0
7#
8#   Unless required by applicable law or agreed to in writing, software
9#   distributed under the License is distributed on an "AS IS" BASIS,
10#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11#   See the License for the specific language governing permissions and
12#   limitations under the License.
13import("//build/config/config.gni")
14import("//build/ohos.gni")
15
16# Execute the script and extract libxml2
17action("libxml2_install_action") {
18  script = "//third_party/libxml2/install.py"
19  outputs = [
20    "${target_gen_dir}/libxml2-2.14.0/config.h.cmake.in",
21    "${target_gen_dir}/libxml2-2.14.0/include/libxml/xmlversion.h.in",
22    "${target_gen_dir}/libxml2-2.14.0/HTMLparser.c",
23    "${target_gen_dir}/libxml2-2.14.0/HTMLtree.c",
24    "${target_gen_dir}/libxml2-2.14.0/SAX2.c",
25    "${target_gen_dir}/libxml2-2.14.0/buf.c",
26    "${target_gen_dir}/libxml2-2.14.0/c14n.c",
27    "${target_gen_dir}/libxml2-2.14.0/catalog.c",
28    "${target_gen_dir}/libxml2-2.14.0/chvalid.c",
29    "${target_gen_dir}/libxml2-2.14.0/debugXML.c",
30    "${target_gen_dir}/libxml2-2.14.0/dict.c",
31    "${target_gen_dir}/libxml2-2.14.0/encoding.c",
32    "${target_gen_dir}/libxml2-2.14.0/entities.c",
33    "${target_gen_dir}/libxml2-2.14.0/error.c",
34    "${target_gen_dir}/libxml2-2.14.0/globals.c",
35    "${target_gen_dir}/libxml2-2.14.0/hash.c",
36    "${target_gen_dir}/libxml2-2.14.0/list.c",
37    "${target_gen_dir}/libxml2-2.14.0/nanohttp.c",
38    "${target_gen_dir}/libxml2-2.14.0/parser.c",
39    "${target_gen_dir}/libxml2-2.14.0/parserInternals.c",
40    "${target_gen_dir}/libxml2-2.14.0/pattern.c",
41    "${target_gen_dir}/libxml2-2.14.0/relaxng.c",
42    "${target_gen_dir}/libxml2-2.14.0/schematron.c",
43    "${target_gen_dir}/libxml2-2.14.0/threads.c",
44    "${target_gen_dir}/libxml2-2.14.0/tree.c",
45    "${target_gen_dir}/libxml2-2.14.0/uri.c",
46    "${target_gen_dir}/libxml2-2.14.0/valid.c",
47    "${target_gen_dir}/libxml2-2.14.0/xinclude.c",
48    "${target_gen_dir}/libxml2-2.14.0/xlink.c",
49    "${target_gen_dir}/libxml2-2.14.0/xmlIO.c",
50    "${target_gen_dir}/libxml2-2.14.0/xmlmemory.c",
51    "${target_gen_dir}/libxml2-2.14.0/xmlmodule.c",
52    "${target_gen_dir}/libxml2-2.14.0/xmlreader.c",
53    "${target_gen_dir}/libxml2-2.14.0/xmlregexp.c",
54    "${target_gen_dir}/libxml2-2.14.0/xmlsave.c",
55    "${target_gen_dir}/libxml2-2.14.0/xmlschemas.c",
56    "${target_gen_dir}/libxml2-2.14.0/xmlschemastypes.c",
57    "${target_gen_dir}/libxml2-2.14.0/xmlstring.c",
58    "${target_gen_dir}/libxml2-2.14.0/xmlunicode.c",
59    "${target_gen_dir}/libxml2-2.14.0/xmlwriter.c",
60    "${target_gen_dir}/libxml2-2.14.0/xpath.c",
61    "${target_gen_dir}/libxml2-2.14.0/xpointer.c",
62    "${target_gen_dir}/libxml2-2.14.0/xzlib.c",
63    "${target_gen_dir}/libxml2-2.14.0/shell.c",
64    "${target_gen_dir}/libxml2-2.14.0/xmllint.c",
65  ]
66
67  inputs = [ "//third_party/libxml2/libxml2-2.14.0.tar.xz" ]
68  inputs += [
69    "Backport-CVE-2025-32414-python-Read-at-most-len-4-ch-c.patch",
70    "Backport-CVE-2025-32415-schemas-Fix-heap-buffer-over-c.patch",
71    "Fix_XML_PARSE_NOBLANKS_dropping_non-whitespace_text.patch",
72    "Backport-CVE-2025-6021-tree-Fix-integer-overflow-in-xmlBuildQName-c.patch",
73    "Fix-relaxng-is-parsed-to-an-infinite-attrs-next-loop.patch",
74    "Backport-CVE-2025-6170-Fix-potential-buffer-overflow-of-interactive-shell.patch",
75    "Fix-CVE-2025-49794-CVE-2025-49796-memory-safety-issues-in-xmlSchematronReportOutput.patch",
76    "Fix-CVE-2025-49795-null-pointer-dereference-leading-to-DoS.patch",
77  ]
78
79  args = [
80    "--gen-dir",
81    rebase_path("${target_gen_dir}", root_build_dir),
82    "--source-file",
83    rebase_path("//third_party/libxml2"),
84  ]
85}
86
87# This is the configuration needed to use libxml2.
88config("libxml2_config") {
89  include_dirs = [
90    get_label_info(":libxml2_generate_header", "target_out_dir") + "/include",
91    get_label_info(":libxml2_install_action", "target_gen_dir") +
92        "/libxml2-2.14.0/include",
93  ]
94}
95
96# This is the configuration used to build libxml2 itself. It should not be needed outside of this
97# library.
98#
99# This has to be a config instead of flags directly specified on the libxml2 target so the -Wno-*
100# flags are ordered after the -Werror flags from the default configs.
101config("libxml2_private_config") {
102  visibility = [ ":*" ]
103  cflags = [
104    "-Wno-empty-body",
105    "-Wno-incompatible-pointer-types",
106    "-Wno-missing-field-initializers",
107    "-Wno-self-assign",
108    "-Wno-sign-compare",
109    "-Wno-tautological-pointer-compare",
110    "-Wno-unused-function",
111    "-Wno-enum-compare",
112    "-Wno-int-conversion",
113    "-Wno-uninitialized",
114    "-Wno-implicit-fallthrough",
115  ]
116  defines = [
117    "HAVE_CONFIG_H",
118    "_REENTRANT",
119  ]
120  if (is_linux) {
121    defines += [ "_GNU_SOURCE" ]
122  }
123}
124
125# This is the configuration needed to use static libxml2.
126config("libxml2_static_config") {
127  include_dirs = [
128    get_label_info(":libxml2_generate_header", "target_out_dir") + "/include",
129    get_label_info(":libxml2_install_action", "target_gen_dir") +
130        "/libxml2-2.14.0/include",
131  ]
132  if (is_mingw) {
133    defines = [ "LIBXML_STATIC" ]
134  } else {
135    defines = [
136      "HAVE_CONFIG_H",
137      "_REENTRANT",
138    ]
139  }
140}
141
142config("libxml2_static_private_config") {
143  cflags = [
144    "-Wno-implicit-fallthrough",
145    "-Wno-implicit-function-declaration",
146    "-Wno-int-conversion",
147    "-Wno-uninitialized",
148    "-Wno-sometimes-uninitialized",
149  ]
150  cflags_cc = [ "-std=c++17" ]
151}
152
153ohos_shared_library("libxml2") {
154  branch_protector_ret = "pac_ret"
155  output_values = get_target_outputs(":libxml2_install_action")
156  sources = filter_exclude(output_values,
157                           [
158                             "*.h.cmake.in",
159                             "*.h.in",
160                           ])
161  public_configs = [ ":libxml2_config" ]
162  configs = [ ":libxml2_private_config" ]
163
164  if (is_linux) {
165    libs = [ "dl" ]
166  }
167
168if (is_mingw) {
169    libs = [
170      "bcrypt",
171      "ws2_32",
172    ]
173  }
174
175  if (current_os == "ios") {
176    ldflags = [
177      "-Wl",
178      "-install_name",
179      "@rpath/libxml2_shared.framework/libxml2_shared",
180    ]
181    output_name = "xml2_shared"
182  }
183  deps = [
184    ":libxml2_generate_header",
185    ":libxml2_install_action",
186  ]
187  innerapi_tags = [
188    "chipsetsdk",
189    "platformsdk",
190    "sasdk",
191  ]
192  install_images = [
193    "updater",
194    "system",
195  ]
196  part_name = "libxml2"
197  subsystem_name = "thirdparty"
198}
199
200if (current_os == "ios") {
201  ohos_combine_darwin_framework("libxml2_shared") {
202    deps = [ ":libxml2" ]
203    subsystem_name = "thirdparty"
204    part_name = "libxml2"
205  }
206}
207
208ohos_static_library("static_libxml2") {
209  output_values = get_target_outputs(":libxml2_install_action")
210  sources = filter_exclude(output_values,
211                           [
212                             "*.h.cmake.in",
213                             "*.h.in",
214                           ])
215  public_configs = [ ":libxml2_static_config" ]
216  configs = [ ":libxml2_static_private_config" ]
217
218if (is_mingw) {
219    libs = [
220      "bcrypt",
221      "ws2_32",
222    ]
223  }
224
225  deps = [
226    ":libxml2_generate_header",
227    ":libxml2_install_action",
228  ]
229  part_name = "libxml2"
230  subsystem_name = "thirdparty"
231}
232
233action("libxml2_generate_header") {
234  script = "generate_header.py"
235
236  config_in_path = get_label_info(":libxml2_install_action", "target_gen_dir") +
237                   "/libxml2-2.14.0/config.h.cmake.in"
238  xmlversion_in_path =
239      get_label_info(":libxml2_install_action", "target_gen_dir") +
240      "/libxml2-2.14.0/include/libxml/xmlversion.h.in"
241  config_json_path = "config_linux.json"
242  xml_version_json_path = "xml_version.json"
243  if (is_mingw) {
244    config_json_path = "config_win.json"
245  }
246
247  inputs = [
248    config_in_path,
249    xmlversion_in_path,
250    config_json_path,
251    xml_version_json_path,
252  ]
253
254  config_path = get_label_info(":libxml2_generate_header", "target_out_dir") +
255                "/include/config.h"
256  xmlversion_path =
257      get_label_info(":libxml2_generate_header", "target_out_dir") +
258      "/include/libxml/xmlversion.h"
259
260  outputs = [
261    config_path,
262    xmlversion_path,
263  ]
264
265  args = [
266    "--config-input-path",
267    rebase_path(config_in_path, root_build_dir),
268    "--config-path",
269    rebase_path(config_path, root_build_dir),
270    "--xmlversion-input-path",
271    rebase_path(xmlversion_in_path, root_build_dir),
272    "--xmlversion-path",
273    rebase_path(xmlversion_path, root_build_dir),
274    "--config-json",
275    rebase_path(config_json_path, root_build_dir),
276    "--xmlversion-json",
277    rebase_path(xml_version_json_path, root_build_dir),
278  ]
279
280  deps = [ ":libxml2_install_action" ]
281}
282