[Lldb-commits] [lldb] bf68bcb - [lldb/Host] Use Host/Config.h for LibXML2 instead of a global define

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Wed Dec 11 14:13:51 PST 2019


Author: Jonas Devlieghere
Date: 2019-12-11T14:13:41-08:00
New Revision: bf68bcb920ffdac5da8b82cd06535cec5dc5a56b

URL: https://github.com/llvm/llvm-project/commit/bf68bcb920ffdac5da8b82cd06535cec5dc5a56b
DIFF: https://github.com/llvm/llvm-project/commit/bf68bcb920ffdac5da8b82cd06535cec5dc5a56b.diff

LOG: [lldb/Host] Use Host/Config.h for LibXML2 instead of a global define

Rename LIBXML2_DEFINED to LLDB_ENABLE_LIBXML2 and pass it through
Config.h instead of a global define.

Added: 
    

Modified: 
    lldb/cmake/modules/LLDBConfig.cmake
    lldb/include/lldb/Host/Config.h.cmake
    lldb/include/lldb/Host/XML.h
    lldb/source/Host/common/XML.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake
index f1763f5b8bb2..8eb72ba44114 100644
--- a/lldb/cmake/modules/LLDBConfig.cmake
+++ b/lldb/cmake/modules/LLDBConfig.cmake
@@ -443,8 +443,7 @@ if (APPLE)
   find_library(FOUNDATION_LIBRARY Foundation)
   find_library(CORE_FOUNDATION_LIBRARY CoreFoundation)
   find_library(SECURITY_LIBRARY Security)
-
-  add_definitions( -DLIBXML2_DEFINED )
+  set(LLDB_ENABLE_LIBXML2 ON)
   list(APPEND system_libs xml2
        ${CURSES_LIBRARIES}
        ${FOUNDATION_LIBRARY}
@@ -454,7 +453,7 @@ if (APPLE)
        ${DEBUG_SYMBOLS_LIBRARY})
   include_directories(${LIBXML2_INCLUDE_DIR})
 elseif(LIBXML2_FOUND AND LIBXML2_VERSION_STRING VERSION_GREATER 2.8)
-  add_definitions( -DLIBXML2_DEFINED )
+  set(LLDB_ENABLE_LIBXML2 ON)
   list(APPEND system_libs ${LIBXML2_LIBRARIES})
   include_directories(${LIBXML2_INCLUDE_DIR})
 endif()

diff  --git a/lldb/include/lldb/Host/Config.h.cmake b/lldb/include/lldb/Host/Config.h.cmake
index cd2cdf00af46..80e415239764 100644
--- a/lldb/include/lldb/Host/Config.h.cmake
+++ b/lldb/include/lldb/Host/Config.h.cmake
@@ -35,6 +35,8 @@
 
 #cmakedefine01 LLDB_ENABLE_LZMA
 
+#cmakedefine LLDB_ENABLE_LIBXML2
+
 #cmakedefine LLDB_DISABLE_CURSES
 
 #cmakedefine LLDB_DISABLE_LIBEDIT

diff  --git a/lldb/include/lldb/Host/XML.h b/lldb/include/lldb/Host/XML.h
index 625cf4381286..38754539d5a4 100644
--- a/lldb/include/lldb/Host/XML.h
+++ b/lldb/include/lldb/Host/XML.h
@@ -9,7 +9,9 @@
 #ifndef liblldb_XML_h_
 #define liblldb_XML_h_
 
-#if defined(LIBXML2_DEFINED)
+#include "lldb/Host/Config.h"
+
+#if defined(LLDB_ENABLE_LIBXML2)
 #include <libxml/xmlreader.h>
 #endif
 
@@ -25,7 +27,7 @@
 
 namespace lldb_private {
 
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
 typedef xmlNodePtr XMLNodeImpl;
 typedef xmlDocPtr XMLDocumentImpl;
 #else

diff  --git a/lldb/source/Host/common/XML.cpp b/lldb/source/Host/common/XML.cpp
index cb23ac17ef53..4289117ff932 100644
--- a/lldb/source/Host/common/XML.cpp
+++ b/lldb/source/Host/common/XML.cpp
@@ -8,6 +8,7 @@
 
 #include <stdlib.h> /* atof */
 
+#include "lldb/Host/Config.h"
 #include "lldb/Host/StringConvert.h"
 #include "lldb/Host/XML.h"
 
@@ -21,7 +22,7 @@ XMLDocument::XMLDocument() : m_document(nullptr) {}
 XMLDocument::~XMLDocument() { Clear(); }
 
 void XMLDocument::Clear() {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
   if (m_document) {
     xmlDocPtr doc = m_document;
     m_document = nullptr;
@@ -42,7 +43,7 @@ void XMLDocument::ErrorCallback(void *ctx, const char *format, ...) {
 }
 
 bool XMLDocument::ParseFile(const char *path) {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
   Clear();
   xmlSetGenericErrorFunc((void *)this, XMLDocument::ErrorCallback);
   m_document = xmlParseFile(path);
@@ -53,7 +54,7 @@ bool XMLDocument::ParseFile(const char *path) {
 
 bool XMLDocument::ParseMemory(const char *xml, size_t xml_length,
                               const char *url) {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
   Clear();
   xmlSetGenericErrorFunc((void *)this, XMLDocument::ErrorCallback);
   m_document = xmlReadMemory(xml, (int)xml_length, url, nullptr, 0);
@@ -63,7 +64,7 @@ bool XMLDocument::ParseMemory(const char *xml, size_t xml_length,
 }
 
 XMLNode XMLDocument::GetRootElement(const char *required_name) {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
   if (IsValid()) {
     XMLNode root_node(xmlDocGetRootElement(m_document));
     if (required_name) {
@@ -81,7 +82,7 @@ XMLNode XMLDocument::GetRootElement(const char *required_name) {
 llvm::StringRef XMLDocument::GetErrors() const { return m_errors.GetString(); }
 
 bool XMLDocument::XMLEnabled() {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
   return true;
 #else
   return false;
@@ -99,7 +100,7 @@ XMLNode::~XMLNode() {}
 void XMLNode::Clear() { m_node = nullptr; }
 
 XMLNode XMLNode::GetParent() const {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
   if (IsValid())
     return XMLNode(m_node->parent);
   else
@@ -110,7 +111,7 @@ XMLNode XMLNode::GetParent() const {
 }
 
 XMLNode XMLNode::GetSibling() const {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
   if (IsValid())
     return XMLNode(m_node->next);
   else
@@ -121,7 +122,7 @@ XMLNode XMLNode::GetSibling() const {
 }
 
 XMLNode XMLNode::GetChild() const {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
 
   if (IsValid())
     return XMLNode(m_node->children);
@@ -135,7 +136,7 @@ XMLNode XMLNode::GetChild() const {
 llvm::StringRef XMLNode::GetAttributeValue(const char *name,
                                            const char *fail_value) const {
   const char *attr_value = nullptr;
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
 
   if (IsValid())
     attr_value = (const char *)xmlGetProp(m_node, (const xmlChar *)name);
@@ -152,7 +153,7 @@ llvm::StringRef XMLNode::GetAttributeValue(const char *name,
 
 bool XMLNode::GetAttributeValueAsUnsigned(const char *name, uint64_t &value,
                                           uint64_t fail_value, int base) const {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
   llvm::StringRef str_value = GetAttributeValue(name, "");
 #else
   llvm::StringRef str_value;
@@ -163,14 +164,14 @@ bool XMLNode::GetAttributeValueAsUnsigned(const char *name, uint64_t &value,
 }
 
 void XMLNode::ForEachChildNode(NodeCallback const &callback) const {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
   if (IsValid())
     GetChild().ForEachSiblingNode(callback);
 #endif
 }
 
 void XMLNode::ForEachChildElement(NodeCallback const &callback) const {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
   XMLNode child = GetChild();
   if (child)
     child.ForEachSiblingElement(callback);
@@ -179,7 +180,7 @@ void XMLNode::ForEachChildElement(NodeCallback const &callback) const {
 
 void XMLNode::ForEachChildElementWithName(const char *name,
                                           NodeCallback const &callback) const {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
   XMLNode child = GetChild();
   if (child)
     child.ForEachSiblingElementWithName(name, callback);
@@ -187,7 +188,7 @@ void XMLNode::ForEachChildElementWithName(const char *name,
 }
 
 void XMLNode::ForEachAttribute(AttributeCallback const &callback) const {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
 
   if (IsValid()) {
     for (xmlAttrPtr attr = m_node->properties; attr != nullptr;
@@ -210,7 +211,7 @@ void XMLNode::ForEachAttribute(AttributeCallback const &callback) const {
 }
 
 void XMLNode::ForEachSiblingNode(NodeCallback const &callback) const {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
 
   if (IsValid()) {
     // iterate through all siblings
@@ -223,7 +224,7 @@ void XMLNode::ForEachSiblingNode(NodeCallback const &callback) const {
 }
 
 void XMLNode::ForEachSiblingElement(NodeCallback const &callback) const {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
 
   if (IsValid()) {
     // iterate through all siblings
@@ -241,7 +242,7 @@ void XMLNode::ForEachSiblingElement(NodeCallback const &callback) const {
 
 void XMLNode::ForEachSiblingElementWithName(
     const char *name, NodeCallback const &callback) const {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
 
   if (IsValid()) {
     // iterate through all siblings
@@ -269,7 +270,7 @@ void XMLNode::ForEachSiblingElementWithName(
 }
 
 llvm::StringRef XMLNode::GetName() const {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
   if (IsValid()) {
     if (m_node->name)
       return llvm::StringRef((const char *)m_node->name);
@@ -280,7 +281,7 @@ llvm::StringRef XMLNode::GetName() const {
 
 bool XMLNode::GetElementText(std::string &text) const {
   text.clear();
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
   if (IsValid()) {
     bool success = false;
     if (m_node->type == XML_ELEMENT_NODE) {
@@ -302,7 +303,7 @@ bool XMLNode::GetElementText(std::string &text) const {
 bool XMLNode::GetElementTextAsUnsigned(uint64_t &value, uint64_t fail_value,
                                        int base) const {
   bool success = false;
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
   if (IsValid()) {
     std::string text;
     if (GetElementText(text))
@@ -316,7 +317,7 @@ bool XMLNode::GetElementTextAsUnsigned(uint64_t &value, uint64_t fail_value,
 
 bool XMLNode::GetElementTextAsFloat(double &value, double fail_value) const {
   bool success = false;
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
   if (IsValid()) {
     std::string text;
     if (GetElementText(text)) {
@@ -331,7 +332,7 @@ bool XMLNode::GetElementTextAsFloat(double &value, double fail_value) const {
 }
 
 bool XMLNode::NameIs(const char *name) const {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
 
   if (IsValid()) {
     // In case we are looking for a nullptr name or an exact pointer match
@@ -347,7 +348,7 @@ bool XMLNode::NameIs(const char *name) const {
 XMLNode XMLNode::FindFirstChildElementWithName(const char *name) const {
   XMLNode result_node;
 
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
   ForEachChildElementWithName(
       name, [&result_node](const XMLNode &node) -> bool {
         result_node = node;
@@ -362,7 +363,7 @@ XMLNode XMLNode::FindFirstChildElementWithName(const char *name) const {
 bool XMLNode::IsValid() const { return m_node != nullptr; }
 
 bool XMLNode::IsElement() const {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
   if (IsValid())
     return m_node->type == XML_ELEMENT_NODE;
 #endif
@@ -370,7 +371,7 @@ bool XMLNode::IsElement() const {
 }
 
 XMLNode XMLNode::GetElementForPath(const NamePath &path) {
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
 
   if (IsValid()) {
     if (path.empty())
@@ -430,7 +431,7 @@ bool ApplePropertyList::GetValueAsString(const char *key,
 
 XMLNode ApplePropertyList::GetValueNode(const char *key) const {
   XMLNode value_node;
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
 
   if (IsValid()) {
     m_dict_node.ForEachChildElementWithName(
@@ -454,7 +455,7 @@ XMLNode ApplePropertyList::GetValueNode(const char *key) const {
 bool ApplePropertyList::ExtractStringFromValueNode(const XMLNode &node,
                                                    std::string &value) {
   value.clear();
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
   if (node.IsValid()) {
     llvm::StringRef element_name = node.GetName();
     if (element_name == "true" || element_name == "false") {
@@ -470,7 +471,7 @@ bool ApplePropertyList::ExtractStringFromValueNode(const XMLNode &node,
   return false;
 }
 
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
 
 namespace {
 
@@ -532,7 +533,7 @@ StructuredData::ObjectSP CreatePlistValue(XMLNode node) {
 
 StructuredData::ObjectSP ApplePropertyList::GetStructuredData() {
   StructuredData::ObjectSP root_sp;
-#if defined(LIBXML2_DEFINED)
+#if defined(LLDB_ENABLE_LIBXML2)
   if (IsValid()) {
     return CreatePlistValue(m_dict_node);
   }


        


More information about the lldb-commits mailing list