Skip to content

Commit bf68bcb

Browse files
committed
[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.
1 parent 786b6db commit bf68bcb

File tree

4 files changed

+38
-34
lines changed

4 files changed

+38
-34
lines changed

lldb/cmake/modules/LLDBConfig.cmake

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,7 @@ if (APPLE)
443443
find_library(FOUNDATION_LIBRARY Foundation)
444444
find_library(CORE_FOUNDATION_LIBRARY CoreFoundation)
445445
find_library(SECURITY_LIBRARY Security)
446-
447-
add_definitions( -DLIBXML2_DEFINED )
446+
set(LLDB_ENABLE_LIBXML2 ON)
448447
list(APPEND system_libs xml2
449448
${CURSES_LIBRARIES}
450449
${FOUNDATION_LIBRARY}
@@ -454,7 +453,7 @@ if (APPLE)
454453
${DEBUG_SYMBOLS_LIBRARY})
455454
include_directories(${LIBXML2_INCLUDE_DIR})
456455
elseif(LIBXML2_FOUND AND LIBXML2_VERSION_STRING VERSION_GREATER 2.8)
457-
add_definitions( -DLIBXML2_DEFINED )
456+
set(LLDB_ENABLE_LIBXML2 ON)
458457
list(APPEND system_libs ${LIBXML2_LIBRARIES})
459458
include_directories(${LIBXML2_INCLUDE_DIR})
460459
endif()

lldb/include/lldb/Host/Config.h.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
#cmakedefine01 LLDB_ENABLE_LZMA
3737

38+
#cmakedefine LLDB_ENABLE_LIBXML2
39+
3840
#cmakedefine LLDB_DISABLE_CURSES
3941

4042
#cmakedefine LLDB_DISABLE_LIBEDIT

lldb/include/lldb/Host/XML.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#ifndef liblldb_XML_h_
1010
#define liblldb_XML_h_
1111

12-
#if defined(LIBXML2_DEFINED)
12+
#include "lldb/Host/Config.h"
13+
14+
#if defined(LLDB_ENABLE_LIBXML2)
1315
#include <libxml/xmlreader.h>
1416
#endif
1517

@@ -25,7 +27,7 @@
2527

2628
namespace lldb_private {
2729

28-
#if defined(LIBXML2_DEFINED)
30+
#if defined(LLDB_ENABLE_LIBXML2)
2931
typedef xmlNodePtr XMLNodeImpl;
3032
typedef xmlDocPtr XMLDocumentImpl;
3133
#else

lldb/source/Host/common/XML.cpp

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <stdlib.h> /* atof */
1010

11+
#include "lldb/Host/Config.h"
1112
#include "lldb/Host/StringConvert.h"
1213
#include "lldb/Host/XML.h"
1314

@@ -21,7 +22,7 @@ XMLDocument::XMLDocument() : m_document(nullptr) {}
2122
XMLDocument::~XMLDocument() { Clear(); }
2223

2324
void XMLDocument::Clear() {
24-
#if defined(LIBXML2_DEFINED)
25+
#if defined(LLDB_ENABLE_LIBXML2)
2526
if (m_document) {
2627
xmlDocPtr doc = m_document;
2728
m_document = nullptr;
@@ -42,7 +43,7 @@ void XMLDocument::ErrorCallback(void *ctx, const char *format, ...) {
4243
}
4344

4445
bool XMLDocument::ParseFile(const char *path) {
45-
#if defined(LIBXML2_DEFINED)
46+
#if defined(LLDB_ENABLE_LIBXML2)
4647
Clear();
4748
xmlSetGenericErrorFunc((void *)this, XMLDocument::ErrorCallback);
4849
m_document = xmlParseFile(path);
@@ -53,7 +54,7 @@ bool XMLDocument::ParseFile(const char *path) {
5354

5455
bool XMLDocument::ParseMemory(const char *xml, size_t xml_length,
5556
const char *url) {
56-
#if defined(LIBXML2_DEFINED)
57+
#if defined(LLDB_ENABLE_LIBXML2)
5758
Clear();
5859
xmlSetGenericErrorFunc((void *)this, XMLDocument::ErrorCallback);
5960
m_document = xmlReadMemory(xml, (int)xml_length, url, nullptr, 0);
@@ -63,7 +64,7 @@ bool XMLDocument::ParseMemory(const char *xml, size_t xml_length,
6364
}
6465

6566
XMLNode XMLDocument::GetRootElement(const char *required_name) {
66-
#if defined(LIBXML2_DEFINED)
67+
#if defined(LLDB_ENABLE_LIBXML2)
6768
if (IsValid()) {
6869
XMLNode root_node(xmlDocGetRootElement(m_document));
6970
if (required_name) {
@@ -81,7 +82,7 @@ XMLNode XMLDocument::GetRootElement(const char *required_name) {
8182
llvm::StringRef XMLDocument::GetErrors() const { return m_errors.GetString(); }
8283

8384
bool XMLDocument::XMLEnabled() {
84-
#if defined(LIBXML2_DEFINED)
85+
#if defined(LLDB_ENABLE_LIBXML2)
8586
return true;
8687
#else
8788
return false;
@@ -99,7 +100,7 @@ XMLNode::~XMLNode() {}
99100
void XMLNode::Clear() { m_node = nullptr; }
100101

101102
XMLNode XMLNode::GetParent() const {
102-
#if defined(LIBXML2_DEFINED)
103+
#if defined(LLDB_ENABLE_LIBXML2)
103104
if (IsValid())
104105
return XMLNode(m_node->parent);
105106
else
@@ -110,7 +111,7 @@ XMLNode XMLNode::GetParent() const {
110111
}
111112

112113
XMLNode XMLNode::GetSibling() const {
113-
#if defined(LIBXML2_DEFINED)
114+
#if defined(LLDB_ENABLE_LIBXML2)
114115
if (IsValid())
115116
return XMLNode(m_node->next);
116117
else
@@ -121,7 +122,7 @@ XMLNode XMLNode::GetSibling() const {
121122
}
122123

123124
XMLNode XMLNode::GetChild() const {
124-
#if defined(LIBXML2_DEFINED)
125+
#if defined(LLDB_ENABLE_LIBXML2)
125126

126127
if (IsValid())
127128
return XMLNode(m_node->children);
@@ -135,7 +136,7 @@ XMLNode XMLNode::GetChild() const {
135136
llvm::StringRef XMLNode::GetAttributeValue(const char *name,
136137
const char *fail_value) const {
137138
const char *attr_value = nullptr;
138-
#if defined(LIBXML2_DEFINED)
139+
#if defined(LLDB_ENABLE_LIBXML2)
139140

140141
if (IsValid())
141142
attr_value = (const char *)xmlGetProp(m_node, (const xmlChar *)name);
@@ -152,7 +153,7 @@ llvm::StringRef XMLNode::GetAttributeValue(const char *name,
152153

153154
bool XMLNode::GetAttributeValueAsUnsigned(const char *name, uint64_t &value,
154155
uint64_t fail_value, int base) const {
155-
#if defined(LIBXML2_DEFINED)
156+
#if defined(LLDB_ENABLE_LIBXML2)
156157
llvm::StringRef str_value = GetAttributeValue(name, "");
157158
#else
158159
llvm::StringRef str_value;
@@ -163,14 +164,14 @@ bool XMLNode::GetAttributeValueAsUnsigned(const char *name, uint64_t &value,
163164
}
164165

165166
void XMLNode::ForEachChildNode(NodeCallback const &callback) const {
166-
#if defined(LIBXML2_DEFINED)
167+
#if defined(LLDB_ENABLE_LIBXML2)
167168
if (IsValid())
168169
GetChild().ForEachSiblingNode(callback);
169170
#endif
170171
}
171172

172173
void XMLNode::ForEachChildElement(NodeCallback const &callback) const {
173-
#if defined(LIBXML2_DEFINED)
174+
#if defined(LLDB_ENABLE_LIBXML2)
174175
XMLNode child = GetChild();
175176
if (child)
176177
child.ForEachSiblingElement(callback);
@@ -179,15 +180,15 @@ void XMLNode::ForEachChildElement(NodeCallback const &callback) const {
179180

180181
void XMLNode::ForEachChildElementWithName(const char *name,
181182
NodeCallback const &callback) const {
182-
#if defined(LIBXML2_DEFINED)
183+
#if defined(LLDB_ENABLE_LIBXML2)
183184
XMLNode child = GetChild();
184185
if (child)
185186
child.ForEachSiblingElementWithName(name, callback);
186187
#endif
187188
}
188189

189190
void XMLNode::ForEachAttribute(AttributeCallback const &callback) const {
190-
#if defined(LIBXML2_DEFINED)
191+
#if defined(LLDB_ENABLE_LIBXML2)
191192

192193
if (IsValid()) {
193194
for (xmlAttrPtr attr = m_node->properties; attr != nullptr;
@@ -210,7 +211,7 @@ void XMLNode::ForEachAttribute(AttributeCallback const &callback) const {
210211
}
211212

212213
void XMLNode::ForEachSiblingNode(NodeCallback const &callback) const {
213-
#if defined(LIBXML2_DEFINED)
214+
#if defined(LLDB_ENABLE_LIBXML2)
214215

215216
if (IsValid()) {
216217
// iterate through all siblings
@@ -223,7 +224,7 @@ void XMLNode::ForEachSiblingNode(NodeCallback const &callback) const {
223224
}
224225

225226
void XMLNode::ForEachSiblingElement(NodeCallback const &callback) const {
226-
#if defined(LIBXML2_DEFINED)
227+
#if defined(LLDB_ENABLE_LIBXML2)
227228

228229
if (IsValid()) {
229230
// iterate through all siblings
@@ -241,7 +242,7 @@ void XMLNode::ForEachSiblingElement(NodeCallback const &callback) const {
241242

242243
void XMLNode::ForEachSiblingElementWithName(
243244
const char *name, NodeCallback const &callback) const {
244-
#if defined(LIBXML2_DEFINED)
245+
#if defined(LLDB_ENABLE_LIBXML2)
245246

246247
if (IsValid()) {
247248
// iterate through all siblings
@@ -269,7 +270,7 @@ void XMLNode::ForEachSiblingElementWithName(
269270
}
270271

271272
llvm::StringRef XMLNode::GetName() const {
272-
#if defined(LIBXML2_DEFINED)
273+
#if defined(LLDB_ENABLE_LIBXML2)
273274
if (IsValid()) {
274275
if (m_node->name)
275276
return llvm::StringRef((const char *)m_node->name);
@@ -280,7 +281,7 @@ llvm::StringRef XMLNode::GetName() const {
280281

281282
bool XMLNode::GetElementText(std::string &text) const {
282283
text.clear();
283-
#if defined(LIBXML2_DEFINED)
284+
#if defined(LLDB_ENABLE_LIBXML2)
284285
if (IsValid()) {
285286
bool success = false;
286287
if (m_node->type == XML_ELEMENT_NODE) {
@@ -302,7 +303,7 @@ bool XMLNode::GetElementText(std::string &text) const {
302303
bool XMLNode::GetElementTextAsUnsigned(uint64_t &value, uint64_t fail_value,
303304
int base) const {
304305
bool success = false;
305-
#if defined(LIBXML2_DEFINED)
306+
#if defined(LLDB_ENABLE_LIBXML2)
306307
if (IsValid()) {
307308
std::string text;
308309
if (GetElementText(text))
@@ -316,7 +317,7 @@ bool XMLNode::GetElementTextAsUnsigned(uint64_t &value, uint64_t fail_value,
316317

317318
bool XMLNode::GetElementTextAsFloat(double &value, double fail_value) const {
318319
bool success = false;
319-
#if defined(LIBXML2_DEFINED)
320+
#if defined(LLDB_ENABLE_LIBXML2)
320321
if (IsValid()) {
321322
std::string text;
322323
if (GetElementText(text)) {
@@ -331,7 +332,7 @@ bool XMLNode::GetElementTextAsFloat(double &value, double fail_value) const {
331332
}
332333

333334
bool XMLNode::NameIs(const char *name) const {
334-
#if defined(LIBXML2_DEFINED)
335+
#if defined(LLDB_ENABLE_LIBXML2)
335336

336337
if (IsValid()) {
337338
// 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 {
347348
XMLNode XMLNode::FindFirstChildElementWithName(const char *name) const {
348349
XMLNode result_node;
349350

350-
#if defined(LIBXML2_DEFINED)
351+
#if defined(LLDB_ENABLE_LIBXML2)
351352
ForEachChildElementWithName(
352353
name, [&result_node](const XMLNode &node) -> bool {
353354
result_node = node;
@@ -362,15 +363,15 @@ XMLNode XMLNode::FindFirstChildElementWithName(const char *name) const {
362363
bool XMLNode::IsValid() const { return m_node != nullptr; }
363364

364365
bool XMLNode::IsElement() const {
365-
#if defined(LIBXML2_DEFINED)
366+
#if defined(LLDB_ENABLE_LIBXML2)
366367
if (IsValid())
367368
return m_node->type == XML_ELEMENT_NODE;
368369
#endif
369370
return false;
370371
}
371372

372373
XMLNode XMLNode::GetElementForPath(const NamePath &path) {
373-
#if defined(LIBXML2_DEFINED)
374+
#if defined(LLDB_ENABLE_LIBXML2)
374375

375376
if (IsValid()) {
376377
if (path.empty())
@@ -430,7 +431,7 @@ bool ApplePropertyList::GetValueAsString(const char *key,
430431

431432
XMLNode ApplePropertyList::GetValueNode(const char *key) const {
432433
XMLNode value_node;
433-
#if defined(LIBXML2_DEFINED)
434+
#if defined(LLDB_ENABLE_LIBXML2)
434435

435436
if (IsValid()) {
436437
m_dict_node.ForEachChildElementWithName(
@@ -454,7 +455,7 @@ XMLNode ApplePropertyList::GetValueNode(const char *key) const {
454455
bool ApplePropertyList::ExtractStringFromValueNode(const XMLNode &node,
455456
std::string &value) {
456457
value.clear();
457-
#if defined(LIBXML2_DEFINED)
458+
#if defined(LLDB_ENABLE_LIBXML2)
458459
if (node.IsValid()) {
459460
llvm::StringRef element_name = node.GetName();
460461
if (element_name == "true" || element_name == "false") {
@@ -470,7 +471,7 @@ bool ApplePropertyList::ExtractStringFromValueNode(const XMLNode &node,
470471
return false;
471472
}
472473

473-
#if defined(LIBXML2_DEFINED)
474+
#if defined(LLDB_ENABLE_LIBXML2)
474475

475476
namespace {
476477

@@ -532,7 +533,7 @@ StructuredData::ObjectSP CreatePlistValue(XMLNode node) {
532533

533534
StructuredData::ObjectSP ApplePropertyList::GetStructuredData() {
534535
StructuredData::ObjectSP root_sp;
535-
#if defined(LIBXML2_DEFINED)
536+
#if defined(LLDB_ENABLE_LIBXML2)
536537
if (IsValid()) {
537538
return CreatePlistValue(m_dict_node);
538539
}

0 commit comments

Comments
 (0)