Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libglib: split libraries from glib #103366

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 46 additions & 54 deletions Formula/glib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Glib < Formula
url "https://download.gnome.org/sources/glib/2.72/glib-2.72.2.tar.xz"
sha256 "78d599a133dba7fe2036dfa8db8fb6131ab9642783fc9578b07a20995252d2de"
license "LGPL-2.1-or-later"
revision 1

bottle do
sha256 arm64_monterey: "dd94ffde0318591e91b826353d83387839c57b4455bd79243c7227a2ad83b677"
Expand All @@ -18,16 +19,11 @@ class Glib < Formula

depends_on "meson" => :build
depends_on "ninja" => :build
depends_on "pcre" => :build
depends_on "pkg-config" => :build
depends_on "gettext"
depends_on "libffi"
depends_on "pcre"
depends_on "libglib"
depends_on "python@3.9"

on_linux do
depends_on "util-linux"
end

# replace several hardcoded paths with homebrew counterparts
patch do
url "https://github.com/raw/Homebrew/formula-patches/43467fd8dfc0e8954892ecc08fab131242dca025/glib/hardcoded-paths.diff"
Expand All @@ -38,8 +34,21 @@ def install
inreplace %w[gio/xdgmime/xdgmime.c glib/gutils.c],
"@@HOMEBREW_PREFIX@@", HOMEBREW_PREFIX

# Point the headers and libraries to `libglib`.
# The headers and libraries will be removed later because they are provided by `libglib`.
libglib = Formula["libglib"]
args = std_meson_args.delete_if do |arg|
arg.start_with?("--prefix=", "--includedir=", "--libdir=")
end
args += %W[
--prefix=#{prefix}
--includedir=#{libglib.opt_include}
--libdir=#{libglib.opt_lib}
]

# Disable dtrace; see https://trac.macports.org/ticket/30413
args = std_meson_args + %W[
# and https://gitlab.gnome.org/GNOME/glib/-/issues/653
args += %W[
--default-library=both
--localstatedir=#{var}
-Diconv=auto
Expand All @@ -51,63 +60,46 @@ def install
mkdir "build" do
system "meson", *args, ".."
system "ninja", "-v"
system "ninja", "install", "-v"
rewrite_shebang detected_python_shebang, *bin.children
end

# ensure giomoduledir contains prefix, as this pkgconfig variable will be
# used by glib-networking and glib-openssl to determine where to install
# their modules
inreplace lib/"pkgconfig/gio-2.0.pc",
"giomoduledir=#{HOMEBREW_PREFIX}/lib/gio/modules",
"giomoduledir=${libdir}/gio/modules"

if OS.mac?
# `pkg-config --libs glib-2.0` includes -lintl, and gettext itself does not
# have a pkgconfig file, so we add gettext lib and include paths here.
gettext = Formula["gettext"].opt_prefix
inreplace lib+"pkgconfig/glib-2.0.pc" do |s|
s.gsub! "Libs: -L${libdir} -lglib-2.0 -lintl",
"Libs: -L${libdir} -lglib-2.0 -L#{gettext}/lib -lintl"
s.gsub! "Cflags: -I${includedir}/glib-2.0 -I${libdir}/glib-2.0/include",
"Cflags: -I${includedir}/glib-2.0 -I${libdir}/glib-2.0/include -I#{gettext}/include"
# Skip files already in libglib
Formula["meson"].opt_libexec.cd do
system "bin/python3", "-c", pyscript
end
end

# `pkg-config --print-requires-private gobject-2.0` includes libffi,
# but that package is keg-only so it needs to look for the pkgconfig file
# in libffi's opt path.
libffi = Formula["libffi"].opt_prefix
inreplace lib+"pkgconfig/gobject-2.0.pc" do |s|
s.gsub! "Requires.private: libffi",
"Requires.private: #{libffi}/lib/pkgconfig/libffi.pc"
system "ninja", "install", "-v"
rewrite_shebang detected_python_shebang, *bin.children
end

bash_completion.install Dir["gio/completion/*"]
end

def post_install
(HOMEBREW_PREFIX/"lib/gio/modules").mkpath
# TODO: remove these symlinks when the libglib migration is done
libglib = Formula["libglib"]
include.make_relative_symlink(libglib.opt_include) unless include.exist?
lib.make_relative_symlink(libglib.opt_lib) unless lib.exist?
end

test do
(testpath/"test.c").write <<~EOS
#include <string.h>
#include <glib.h>

int main(void)
{
gchar *result_1, *result_2;
char *str = "string";

result_1 = g_convert(str, strlen(str), "ASCII", "UTF-8", NULL, NULL, NULL);
result_2 = g_convert(result_1, strlen(result_1), "UTF-8", "ASCII", NULL, NULL, NULL);

return (strcmp(str, result_2) == 0) ? 0 : 1;
}
def pyscript
libglib = Formula["libglib"]
<<~EOS
import os
import pickle as pkl
from mesonbuild.minstall import load_install_data
filename = os.path.join('#{buildpath}', 'build', 'meson-private', 'install.dat')
installdata = load_install_data(filename)
for attrname in ('data', 'emptydir', 'headers', 'install_scripts', 'install_subdirs', 'man', 'symlinks', 'targets'):
attr = getattr(installdata, attrname)
attr[:] = list(filter(lambda data: all('#{libglib.opt_prefix}' not in dataattr
for dataattr in vars(data).values()
if isinstance(dataattr, str)),
attr))
with open(filename, mode='wb') as file:
pkl.dump(installdata, file)
EOS
system ENV.cc, "-o", "test", "test.c", "-I#{include}/glib-2.0",
"-I#{lib}/glib-2.0/include", "-L#{lib}", "-lglib-2.0"
system "./test"
end

test do
system "#{bin}/glib-compile-schemas", "--version"
end
end
103 changes: 103 additions & 0 deletions Formula/libglib.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
class Libglib < Formula
desc "Core application library for C"
homepage "https://developer.gnome.org/glib/"
url "https://download.gnome.org/sources/glib/2.72/glib-2.72.2.tar.xz"
sha256 "78d599a133dba7fe2036dfa8db8fb6131ab9642783fc9578b07a20995252d2de"
license "LGPL-2.1-or-later"

livecheck do
formula "glib"
end

depends_on "meson" => :build
depends_on "ninja" => :build
depends_on "pkg-config" => :build
depends_on "python@3.10" => :build
depends_on "gettext"
depends_on "pcre"

uses_from_macos "libffi"

on_linux do
depends_on "util-linux"
end

def install
# TODO: This is a workaround for `brew audit --new-formula`.
# Use `patch` rather than `inreplace` (see also `glib`).
# replace several hardcoded paths with homebrew counterparts
Comment on lines +26 to +28
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't work around the audits. They are there for a reason.

inreplace "gio/xdgmime/xdgmime.c",
'xdg_data_dirs = "/usr/local/share/:/usr/share/";',
"xdg_data_dirs = \"#{HOMEBREW_PREFIX}/share/:/usr/local/share/:/usr/share/\";"
inreplace "glib/gutils.c",
'data_dirs = "/usr/local/share/:/usr/share/";',
"data_dirs = \"#{HOMEBREW_PREFIX}/share/:/usr/local/share/:/usr/share/\";"

# Disable dtrace; see https://trac.macports.org/ticket/30413
XuehaiPan marked this conversation as resolved.
Show resolved Hide resolved
# and https://gitlab.gnome.org/GNOME/glib/-/issues/653
args = std_meson_args + %W[
--default-library=both
--localstatedir=#{var}
-Diconv=auto
-Dgio_module_dir=lib/gio/modules
-Dbsymbolic_functions=false
-Ddtrace=false
]

mkdir "build" do
system "meson", *args, ".."
system "ninja", "-v"
system "ninja", "install", "-v"
end

if OS.mac?
# `pkg-config --libs glib-2.0` includes -lintl, and gettext itself does not
# have a pkgconfig file, so we add gettext lib and include paths here.
gettext = Formula["gettext"]
inreplace lib+"pkgconfig/glib-2.0.pc" do |s|
s.gsub! "Libs: -L${libdir} -lglib-2.0 -lintl",
"Libs: -L${libdir} -lglib-2.0 -L#{gettext.opt_lib} -lintl"
s.gsub! "Cflags: -I${includedir}/glib-2.0 -I${libdir}/glib-2.0/include",
"Cflags: -I${includedir}/glib-2.0 -I${libdir}/glib-2.0/include -I#{gettext.opt_include}"
end
end

# `pkg-config --print-requires-private gobject-2.0` includes libffi,
# but that package is keg-only so it needs to look for the pkgconfig file
# in libffi's opt path.
libffi = Formula["libffi"]
inreplace lib+"pkgconfig/gobject-2.0.pc" do |s|
s.gsub! "Requires.private: libffi",
"Requires.private: #{libffi.opt_lib}/pkgconfig/libffi.pc"
end

# These are provided by `glib`.
rm_rf bin
rm_rf share
end

def post_install
(HOMEBREW_PREFIX/"lib/gio/modules").mkpath
end

test do
(testpath/"test.c").write <<~EOS
#include <string.h>
#include <glib.h>

int main(void)
{
gchar *result_1, *result_2;
char *str = "string";

result_1 = g_convert(str, strlen(str), "ASCII", "UTF-8", NULL, NULL, NULL);
result_2 = g_convert(result_1, strlen(result_1), "UTF-8", "ASCII", NULL, NULL, NULL);

return (strcmp(str, result_2) == 0) ? 0 : 1;
}
EOS
system ENV.cc, "-o", "test", "test.c", "-I#{include}/glib-2.0",
"-I#{lib}/glib-2.0/include", "-L#{lib}", "-lglib-2.0"
system "./test"
end
end
1 change: 1 addition & 0 deletions synced_versions_formulae.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
["hdf5", "hdf5-mpi"],
["ilmbase", "openexr@2"],
["libexosip", "libosip"],
["libglib", "glib"],
["libnetworkit", "networkit"],
["libnghttp2", "nghttp2"],
["libngspice", "ngspice"],
Expand Down