-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibxml2.rb
119 lines (101 loc) · 4.02 KB
/
libxml2.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
class Libxml2 < Formula
desc "GNOME XML library"
homepage "http://xmlsoft.org/"
url "https://download.gnome.org/sources/libxml2/2.12/libxml2-2.12.8.tar.xz"
sha256 "43ad877b018bc63deb2468d71f95219c2fac196876ef36d1bee51d226173ec93"
license "MIT"
# We use a common regex because libxml2 doesn't use GNOME's "even-numbered
# minor is stable" version scheme.
livecheck do
url :stable
regex(/libxml2[._-]v?(\d+(?:\.\d+)+)\.t/i)
end
bottle do
sha256 cellar: :any, arm64_sonoma: "0615b18f4e0089dbc3a350d5e2c56bbd87052c17386128500413b857ce0b1f88"
sha256 cellar: :any, arm64_ventura: "95fc101400de6205dd55127c67a035127cd74ae3374e157fff8ae8159c22b429"
sha256 cellar: :any, arm64_monterey: "1e3c987fb48b4e15f129ed713aa0808b8774bf36584c358a2f5b7627ff54c2a7"
sha256 cellar: :any, sonoma: "15583249513a6844e95a41a9126bd9bfc0e18a1e1b2fb5520ea85904ac202c01"
sha256 cellar: :any, ventura: "53ce0db80ca3161b27f238a2516e78237f43bc5d1d1191bf8591ee838427fb19"
sha256 cellar: :any, monterey: "5d61a00a0694e8be7aebe53de8a4b9744b6ca68fedefa6f6b06ba0363eacb772"
sha256 cellar: :any_skip_relocation, x86_64_linux: "fb5cd905b75c9bed36f3deb284e6a6f4c3338f78368cff9f52356b48590897a7"
end
head do
url "https://gitlab.gnome.org/GNOME/libxml2.git", branch: "master"
depends_on "autoconf" => :build
depends_on "automake" => :build
depends_on "libtool" => :build
depends_on "pkg-config" => :build
end
keg_only :provided_by_macos
depends_on "python-setuptools" => :build
depends_on "[email protected]" => [:build, :test]
depends_on "[email protected]" => [:build, :test]
depends_on "pkg-config" => :test
depends_on "icu4c"
depends_on "readline"
uses_from_macos "zlib"
def pythons
deps.map(&:to_formula)
.select { |f| f.name.match?(/^python@\d\.\d+$/) }
.map { |f| f.opt_libexec/"bin/python" }
end
def install
system "autoreconf", "--force", "--install", "--verbose" if build.head?
system "./configure", *std_configure_args,
"--sysconfdir=#{etc}",
"--disable-silent-rules",
"--with-history",
"--with-icu",
"--without-python",
"--without-lzma"
system "make", "install"
cd "python" do
sdk_include = if OS.mac?
sdk = MacOS.sdk_path_if_needed
sdk/"usr/include" if sdk
else
HOMEBREW_PREFIX/"include"
end
includes = [include, sdk_include].compact.map do |inc|
"'#{inc}',"
end.join(" ")
# We need to insert our include dir first
inreplace "setup.py", "includes_dir = [",
"includes_dir = [#{includes}"
# Needed for Python 3.12+.
# https://github.com/Homebrew/homebrew-core/pull/154551#issuecomment-1820102786
with_env(PYTHONPATH: buildpath/"python") do
pythons.each do |python|
system python, "-m", "pip", "install", *std_pip_args, "."
end
end
end
end
test do
(testpath/"test.c").write <<~EOS
#include <libxml/tree.h>
int main()
{
xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
xmlNodePtr root_node = xmlNewNode(NULL, BAD_CAST "root");
xmlDocSetRootElement(doc, root_node);
xmlFreeDoc(doc);
return 0;
}
EOS
# Test build with xml2-config
args = shell_output("#{bin}/xml2-config --cflags --libs").split
system ENV.cc, "test.c", "-o", "test", *args
system "./test"
# Test build with pkg-config
ENV.append "PKG_CONFIG_PATH", lib/"pkgconfig"
args = shell_output("#{Formula["pkg-config"].opt_bin}/pkg-config --cflags --libs libxml-2.0").split
system ENV.cc, "test.c", "-o", "test", *args
system "./test"
pythons.each do |python|
with_env(PYTHONPATH: prefix/Language::Python.site_packages(python)) do
system python, "-c", "import libxml2"
end
end
end
end