diff --git a/BUILD.gn b/BUILD.gn index d5eb8c49c91669690296af0183af15dbc26d18b0..f5627a4f5d4250099b2553b4e2b5762f0cebcc97 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -47,102 +47,103 @@ group("libxml2") { public_deps = [ ":xml2" ] } -ohos_shared_library("xml2") { - sources = [ - "DOCBparser.c", - "HTMLparser.c", - "HTMLtree.c", - "SAX.c", - "SAX2.c", - "buf.c", - "c14n.c", - "catalog.c", - "chvalid.c", - "debugXML.c", - "dict.c", - "encoding.c", - "entities.c", - "error.c", - "globals.c", - "hash.c", - "include/libxml/DOCBparser.h", - "include/libxml/HTMLparser.h", - "include/libxml/HTMLtree.h", - "include/libxml/SAX.h", - "include/libxml/SAX2.h", - "include/libxml/c14n.h", - "include/libxml/catalog.h", - "include/libxml/chvalid.h", - "include/libxml/debugXML.h", - "include/libxml/dict.h", - "include/libxml/encoding.h", - "include/libxml/entities.h", - "include/libxml/globals.h", - "include/libxml/hash.h", - "include/libxml/list.h", - "include/libxml/nanoftp.h", - "include/libxml/nanohttp.h", - "include/libxml/parser.h", - "include/libxml/parserInternals.h", - "include/libxml/pattern.h", - "include/libxml/relaxng.h", - "include/libxml/schemasInternals.h", - "include/libxml/schematron.h", - "include/libxml/threads.h", - "include/libxml/tree.h", - "include/libxml/uri.h", - "include/libxml/valid.h", - "include/libxml/xinclude.h", - "include/libxml/xlink.h", - "include/libxml/xmlIO.h", - "include/libxml/xmlautomata.h", - "include/libxml/xmlerror.h", - "include/libxml/xmlexports.h", - "include/libxml/xmlmemory.h", - "include/libxml/xmlmodule.h", - "include/libxml/xmlreader.h", - "include/libxml/xmlregexp.h", - "include/libxml/xmlsave.h", - "include/libxml/xmlschemas.h", - "include/libxml/xmlschemastypes.h", - "include/libxml/xmlstring.h", - "include/libxml/xmlunicode.h", - "include/libxml/xmlversion.h", - "include/libxml/xmlwriter.h", - "include/libxml/xpath.h", - "include/libxml/xpathInternals.h", - "include/libxml/xpointer.h", - "legacy.c", - "list.c", - "nanoftp.c", - "nanohttp.c", - "parser.c", - "parserInternals.c", - "pattern.c", - "relaxng.c", - "schematron.c", - "threads.c", - "tree.c", - "uri.c", - "valid.c", - "xinclude.c", - "xlink.c", - "xmlIO.c", - "xmlmemory.c", - "xmlmodule.c", - "xmlreader.c", - "xmlregexp.c", - "xmlsave.c", - "xmlschemas.c", - "xmlschemastypes.c", - "xmlstring.c", - "xmlunicode.c", - "xmlwriter.c", - "xpath.c", - "xpointer.c", - "xzlib.c", - ] +manager_sources = [ + "DOCBparser.c", + "HTMLparser.c", + "HTMLtree.c", + "SAX.c", + "SAX2.c", + "buf.c", + "c14n.c", + "catalog.c", + "chvalid.c", + "debugXML.c", + "dict.c", + "encoding.c", + "entities.c", + "error.c", + "globals.c", + "hash.c", + "include/libxml/DOCBparser.h", + "include/libxml/HTMLparser.h", + "include/libxml/HTMLtree.h", + "include/libxml/SAX.h", + "include/libxml/SAX2.h", + "include/libxml/c14n.h", + "include/libxml/catalog.h", + "include/libxml/chvalid.h", + "include/libxml/debugXML.h", + "include/libxml/dict.h", + "include/libxml/encoding.h", + "include/libxml/entities.h", + "include/libxml/globals.h", + "include/libxml/hash.h", + "include/libxml/list.h", + "include/libxml/nanoftp.h", + "include/libxml/nanohttp.h", + "include/libxml/parser.h", + "include/libxml/parserInternals.h", + "include/libxml/pattern.h", + "include/libxml/relaxng.h", + "include/libxml/schemasInternals.h", + "include/libxml/schematron.h", + "include/libxml/threads.h", + "include/libxml/tree.h", + "include/libxml/uri.h", + "include/libxml/valid.h", + "include/libxml/xinclude.h", + "include/libxml/xlink.h", + "include/libxml/xmlIO.h", + "include/libxml/xmlautomata.h", + "include/libxml/xmlerror.h", + "include/libxml/xmlexports.h", + "include/libxml/xmlmemory.h", + "include/libxml/xmlmodule.h", + "include/libxml/xmlreader.h", + "include/libxml/xmlregexp.h", + "include/libxml/xmlsave.h", + "include/libxml/xmlschemas.h", + "include/libxml/xmlschemastypes.h", + "include/libxml/xmlstring.h", + "include/libxml/xmlunicode.h", + "include/libxml/xmlversion.h", + "include/libxml/xmlwriter.h", + "include/libxml/xpath.h", + "include/libxml/xpathInternals.h", + "include/libxml/xpointer.h", + "legacy.c", + "list.c", + "nanoftp.c", + "nanohttp.c", + "parser.c", + "parserInternals.c", + "pattern.c", + "relaxng.c", + "schematron.c", + "threads.c", + "tree.c", + "uri.c", + "valid.c", + "xinclude.c", + "xlink.c", + "xmlIO.c", + "xmlmemory.c", + "xmlmodule.c", + "xmlreader.c", + "xmlregexp.c", + "xmlsave.c", + "xmlschemas.c", + "xmlschemastypes.c", + "xmlstring.c", + "xmlunicode.c", + "xmlwriter.c", + "xpath.c", + "xpointer.c", + "xzlib.c", +] +ohos_shared_library("xml2") { + sources = manager_sources public_configs = [ ":libxml2_config" ] configs = [ ":libxml2_private_config" ] @@ -155,3 +156,77 @@ ohos_shared_library("xml2") { part_name = "libxml2" subsystem_name = "thirdparty" } + +config("libxml2_static_config") { + cflags = [ + "-Wno-implicit-fallthrough", + "-Wno-implicit-function-declaration", + "-Wno-int-conversion", + "-Wno-uninitialized", + "-Wno-sometimes-uninitialized", + ] + + include_dirs = [] + if (is_mingw) { + defines = [ "LIBXML_STATIC" ] + include_dirs += [ get_label_info(":libxml2_generate_header", + "target_out_dir") + "/include" ] + } else if (is_mac) { + defines = [ "LIBXML_THREAD_ENABLED" ] + } else if (is_linux) { + include_dirs += [ get_label_info(":libxml2_generate_header", + "target_out_dir") + "/include" ] + } + + include_dirs += [ "include" ] + cflags_cc = [ "-std=c++17" ] +} + +ohos_static_library("static_libxml2") { + sources = manager_sources + public_configs = [ ":libxml2_static_config" ] + deps = [ ":libxml2_generate_header" ] + subsystem_name = "thirdparty" + part_name = "libxml2" +} + +action("libxml2_generate_header") { + script = "generate_header.py" + inputs = [ + "config.h.cmake.in", + "include/libxml/xmlversion.h.in", + ] + + config_json_path = "config_linux.json" + xml_version_json_path = "xml_version.json" + if (is_mingw) { + config_json_path = "config_win.json" + } + inputs += [ config_json_path ] + inputs += [ xml_version_json_path ] + + config_path = get_label_info(":libxml2_generate_header", "target_out_dir") + + "/include/config.h" + xmlversion_path = + get_label_info(":libxml2_generate_header", "target_out_dir") + + "/include/libxml/xmlversion.h" + outputs = [ + config_path, + xmlversion_path, + ] + + args = [ + "--config-input-path", + rebase_path("config.h.cmake.in", root_build_dir), + "--config-path", + rebase_path(config_path, root_build_dir), + "--xmlversion-input-path", + rebase_path("include/libxml/xmlversion.h.in", root_build_dir), + "--xmlversion-path", + rebase_path(xmlversion_path, root_build_dir), + "--config-json", + rebase_path(config_json_path, root_build_dir), + "--xmlversion-json", + rebase_path(xml_version_json_path, root_build_dir), + ] +} diff --git a/config_linux.json b/config_linux.json new file mode 100755 index 0000000000000000000000000000000000000000..6242b7a9f8af391e82806b1a38d25ffbd86424af --- /dev/null +++ b/config_linux.json @@ -0,0 +1,76 @@ +{ + "ATTRIBUTE_DESTRUCTOR":"1", + "GETHOSTBYNAME_ARG_CAST":"(char *)", + "HAVE_CTYPE_H":"1", + "HAVE_DIRENT_H":"1", + "HAVE_ERRNO_H":"1", + "HAVE_FCNTL_H":"1", + "HAVE_FLOAT_H":"1", + "HAVE_FPRINTF":"1", + "HAVE_FTIME":"1", + "HAVE_GETTIMEOFDAY":"1", + "HAVE_INTTYPES_H":"1", + "HAVE_ISASCII":"1", + "HAVE_ISNAN":"1", + "HAVE_LIBPTHREAD":"1", + "HAVE_LIMITS_H":"1", + "HAVE_LOCALTIME":"1", + "HAVE_MALLOC_H":"1", + "HAVE_MATH_H":"1", + "HAVE_MEMORY_H":"1", + "HAVE_PRINTF":"1", + "HAVE_PTHREAD_H":"1", + "HAVE_PUTENV":"1", + "HAVE_RAND":"1", + "HAVE_SIGNAL":"1", + "HAVE_SIGNAL_H":"1", + "HAVE_SNPRINTF":"1", + "HAVE_SPRINTF":"1", + "HAVE_SRAND":"1", + "HAVE_SSCANF":"1", + "HAVE_STAT":"1", + "HAVE_STDARG_H":"1", + "HAVE_STDINT_H":"1", + "HAVE_STDLIB_H":"1", + "HAVE_STRFTIME":"1", + "HAVE_STRINGS_H":"1", + "HAVE_STRING_H":"1", + "HAVE_SYS_STAT_H":"1", + "HAVE_SYS_TIMEB_H":"1", + "HAVE_SYS_TIME_H":"1", + "HAVE_SYS_TYPES_H":"1", + "HAVE_TIME":"1", + "HAVE_TIME_H":"1", + "HAVE_UNISTD_H":"1", + "HAVE_VFPRINTF":"1", + "HAVE_VSNPRINTF":"1", + "HAVE_VSPRINTF":"1", + "ICONV_CONST":"const", + "PACKAGE":"libxml2", + "PACKAGE_BUGREPORT":"xml@gnome.org", + "PACKAGE_NAME":"libxml2", + "PACKAGE_STRING":"libxml2 2.9.13", + "PACKAGE_TARNAME":"libxml2", + "PACKAGE_URL":"http://www.xmlsoft.org/", + "PACKAGE_VERSION":"2.9.13", + "SEND_ARG2_CAST":"", + "STDC_HEADERS":"1", + "VA_LIST_IS_ARRAY":"1", + "VERSION":"2.9.13", + "XML_SOCKLEN_T":"socklen_t", + "HAVE_ARPA_INET_H":"1", + "HAVE_ARPA_NAMESER_H":1, + "HAVE_DLFCN_H":"1", + "HAVE_DLOPEN":"1", + "HAVE_GETADDRINFO":"1", + "HAVE_ISINF":"1", + "HAVE_MMAP":"1", + "HAVE_NETDB_H":"1", + "HAVE_NETINET_IN_H":"1", + "HAVE_POLL_H":"1", + "HAVE_RAND_R":"1", + "HAVE_RESOLV_H":"1", + "HAVE_SYS_MMAN_H":"1", + "HAVE_SYS_SELECT_H":"1", + "HAVE_SYS_SOCKET_H":"1" +} \ No newline at end of file diff --git a/config_win.json b/config_win.json new file mode 100755 index 0000000000000000000000000000000000000000..1d5408381861dcd568594249357eede3a5007fbd --- /dev/null +++ b/config_win.json @@ -0,0 +1,61 @@ +{ + "ATTRIBUTE_DESTRUCTOR":"1", + "GETHOSTBYNAME_ARG_CAST":"(char *)", + "HAVE_CTYPE_H":"1", + "HAVE_DIRENT_H":"1", + "HAVE_ERRNO_H":"1", + "HAVE_FCNTL_H":"1", + "HAVE_FLOAT_H":"1", + "HAVE_FPRINTF":"1", + "HAVE_FTIME":"1", + "HAVE_GETTIMEOFDAY":"1", + "HAVE_INTTYPES_H":"1", + "HAVE_ISASCII":"1", + "HAVE_ISNAN":"1", + "HAVE_LIBPTHREAD":"1", + "HAVE_LIMITS_H":"1", + "HAVE_LOCALTIME":"1", + "HAVE_MALLOC_H":"1", + "HAVE_MATH_H":"1", + "HAVE_MEMORY_H":"1", + "HAVE_PRINTF":"1", + "HAVE_PTHREAD_H":"1", + "HAVE_PUTENV":"1", + "HAVE_RAND":"1", + "HAVE_SIGNAL":"1", + "HAVE_SIGNAL_H":"1", + "HAVE_SNPRINTF":"1", + "HAVE_SPRINTF":"1", + "HAVE_SRAND":"1", + "HAVE_SSCANF":"1", + "HAVE_STAT":"1", + "HAVE_STDARG_H":"1", + "HAVE_STDINT_H":"1", + "HAVE_STDLIB_H":"1", + "HAVE_STRFTIME":"1", + "HAVE_STRINGS_H":"1", + "HAVE_STRING_H":"1", + "HAVE_SYS_STAT_H":"1", + "HAVE_SYS_TIMEB_H":"1", + "HAVE_SYS_TIME_H":"1", + "HAVE_SYS_TYPES_H":"1", + "HAVE_TIME":"1", + "HAVE_TIME_H":"1", + "HAVE_UNISTD_H":"1", + "HAVE_VFPRINTF":"1", + "HAVE_VSNPRINTF":"1", + "HAVE_VSPRINTF":"1", + "ICONV_CONST":"", + "PACKAGE":"libxml2", + "PACKAGE_BUGREPORT":"xml@gnome.org", + "PACKAGE_NAME":"libxml2", + "PACKAGE_STRING":"libxml2 2.9.13", + "PACKAGE_TARNAME":"libxml2", + "PACKAGE_URL":"http://www.xmlsoft.org/", + "PACKAGE_VERSION":"2.9.13", + "SEND_ARG2_CAST":"(char*)", + "STDC_HEADERS":"1", + "VA_LIST_IS_ARRAY":"1", + "VERSION":"2.9.13", + "XML_SOCKLEN_T":"int" +} \ No newline at end of file diff --git a/generate_header.py b/generate_header.py new file mode 100755 index 0000000000000000000000000000000000000000..fb2420c0308a72ae7e6bdddf266590e824400af3 --- /dev/null +++ b/generate_header.py @@ -0,0 +1,119 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import argparse +import json +import os +import re + + +class ConfigHeader: + + def __init__(self, config_json_path): + self.read_buffer = [] + self.write_buffer = [] + with os.fdopen(os.open(config_json_path, os.O_RDONLY, 0o755), 'r') as file: + self.configs = json.load(file) + + def parse_file(self, file_path): + with os.fdopen(os.open(file_path, os.O_RDONLY, 0o755), 'r') as file: + self.read_buffer = file.readlines() + for item in self.read_buffer: + if not item.startswith("#cmakedefine") and not item.startswith("#define"): + self.write_buffer.append(item) + continue + + value = item + if item.startswith("#cmakedefine"): + value = item.replace("#cmakedefine", "#define") + match_object = re.search(r' \w+ ', value) + if match_object is None: + self.write_buffer.append("/* " + item + " */") + continue + key = match_object.group() + key_index = key.replace(" ", "") + if key_index not in self.configs: + self.write_buffer.append("/* " + item + " */") + continue + + match_object = re.search(r'@\w+@', value) + if match_object is None: + self.write_buffer.append(value) + continue + key = match_object.group() + key_index = key.replace("@", "") + if key_index not in self.configs: + self.write_buffer.append("/* " + item + " */") + continue + value = value.replace(key, self.configs[key_index]) + self.write_buffer.append(value) + + def write_file(self, file_path): + with os.fdopen(os.open(file_path, os.O_WRONLY | os.O_CREAT, 0o755), 'w') as file: + file.writelines(self.write_buffer) + + +class XmlVersionHeader: + + def __init__(self, xmlversion_json_path): + self.read_buffer = [] + self.write_buffer = [] + with os.fdopen(os.open(xmlversion_json_path, os.O_RDONLY, 0o755), 'r') as file: + self.configs = json.load(file) + + def parse_file(self, file_path): + with os.fdopen(os.open(file_path, os.O_RDONLY, 0o755), 'r') as file: + self.read_buffer = file.readlines() + for item in self.read_buffer: + if not item.startswith("#if") and not item.startswith("#define"): + self.write_buffer.append(item) + continue + + match_object = re.search(r'@\w+@', item) + if match_object is None: + self.write_buffer.append(item) + continue + key = match_object.group() + index_key = key.replace("@", "") + value = "" + if index_key in self.configs: + value = item.replace(key, self.configs[index_key]) + else: + value = item.replace(key, "0") + self.write_buffer.append(value) + + def write_file(self, file_path): + with os.fdopen(os.open(file_path, os.O_WRONLY | os.O_CREAT, 0o755), 'w') as file: + file.writelines(self.write_buffer) + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('--config-input-path', help='input path to config.h') + parser.add_argument('--config-path', help='output path to config.h') + parser.add_argument('--xmlversion-input-path', help='input path to xmlversion.h') + parser.add_argument('--xmlversion-path', help='output path to xmlversion.h') + parser.add_argument('--config-json', help='config value for config.h') + parser.add_argument('--xmlversion-json', help='config value for xmlversion.h') + options = parser.parse_args() + config_header = ConfigHeader(options.config_json) + config_header.parse_file(options.config_input_path) + config_header.write_file(options.config_path) + + xmlversion_header = XmlVersionHeader(options.xmlversion_json) + xmlversion_header.parse_file(options.xmlversion_input_path) + xmlversion_header.write_file(options.xmlversion_path) diff --git a/xml_version.json b/xml_version.json new file mode 100755 index 0000000000000000000000000000000000000000..0f8114f571c12e13151fb5a605a6336db43f4670 --- /dev/null +++ b/xml_version.json @@ -0,0 +1,31 @@ +{ + "VERSION":"2.9.13", + "LIBXML_VERSION_NUMBER":"209013", + "LIBXML_VERSION_EXTRA":"", + "WITH_THREADS":"1", + "WITH_TREE":"1", + "WITH_OUTPUT":"1", + "WITH_PUSH":"1", + "WITH_READER":"1", + "WITH_PATTERN":"1", + "WITH_WRITER":"1", + "WITH_SAX1":"1", + "WITH_FTP":"1", + "WITH_HTTP":"1", + "WITH_VALID":"1", + "WITH_HTML":"1", + "WITH_LEGACY":"1", + "WITH_C14N":"1", + "WITH_CATALOG":"1", + "WITH_DOCB":"1", + "WITH_XPATH":"1", + "WITH_XPTR":"1", + "WITH_XINCLUDE":"1", + "WITH_ISO8859X":"1", + "WITH_DEBUG":"1", + "WITH_REGEXPS":"1", + "WITH_SCHEMAS":"1", + "WITH_SCHEMATRON":"1", + "WITH_MODULES":"1", + "MODULE_EXTENSION":".so" +} \ No newline at end of file