Skip to content

Commit

Permalink
Merge pull request #184 from FNALssi/gartung-glib-meson-dep-upstream
Browse files Browse the repository at this point in the history
Cherry-pick glib changes from upstream develop.
  • Loading branch information
gartung authored Sep 20, 2023
2 parents b22ed4d + 8221eaa commit 15218d2
Showing 1 changed file with 97 additions and 107 deletions.
204 changes: 97 additions & 107 deletions var/spack/repos/builtin/packages/glib/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from spack.util.environment import is_system_path


class Glib(Package):
class Glib(MesonPackage, AutotoolsPackage):
"""GLib provides the core application building blocks for
libraries and applications written in C.
Expand All @@ -26,6 +26,8 @@ class Glib(Package):

maintainers("michaelkuhn")

version("2.76.3", sha256="c0be444e403d7c3184d1f394f89f0b644710b5e9331b54fa4e8b5037813ad32a")
version("2.76.2", sha256="24f3847857b1d8674cdb0389a36edec0f13c666cd3ce727ecd340eb9da8aca9e")
version("2.76.1", sha256="43dc0f6a126958f5b454136c4398eab420249c16171a769784486e25f2fda19f")
version("2.74.7", sha256="196ab86c27127a61b7a70c3ba6af7b97bdc01c07cd3b21abd5e778b955eccb1b")
version("2.74.6", sha256="069cf7e51cd261eb163aaf06c8d1754c6835f31252180aff5814e5afc7757fbc")
Expand Down Expand Up @@ -119,10 +121,17 @@ class Glib(Package):
description="Enable tracing support",
)

depends_on("[email protected]:", when="@2.76.1:", type="build")
depends_on("[email protected]:", when="@2.61.2:", type="build")
depends_on("[email protected]:", when="@2.58.0:", type="build")
depends_on("ninja", when="@2.58.0:", type="build")
build_system(
conditional("meson", when="@2.58:"),
conditional("autotools", when="@:2.57"),
default="meson",
)

with when("build_system=meson"):
depends_on("[email protected]:", when="@2.73:", type="build")
depends_on("[email protected]:", when="@2.71:2.72", type="build")
depends_on("[email protected]:", when="@2.61.2:2.70", type="build")
depends_on("[email protected]:", when="@:2.61.1", type="build")

depends_on("pkgconfig", type="build")
depends_on("libffi")
Expand Down Expand Up @@ -181,6 +190,88 @@ def patch(self):
def libs(self):
return find_libraries(["libglib*"], root=self.prefix, recursive=True)


class BaseBuilder(metaclass=spack.builder.PhaseCallbacksMeta):
@property
def dtrace_copy_path(self):
return join_path(self.stage.source_path, "dtrace-copy")

@run_before("install")
def fix_python_path(self):
if not self.spec.satisfies("@2.53.4:"):
return

files = ["gobject/glib-genmarshal.in", "gobject/glib-mkenums.in"]

filter_file(
"^#!/usr/bin/env @PYTHON@",
"#!/usr/bin/env {0}".format(os.path.basename(self.spec["python"].command.path)),
*files,
)

@run_before("install")
def fix_dtrace_usr_bin_path(self):
if "tracing=dtrace" not in self.spec:
return

# dtrace may cause glib build to fail because it uses
# '/usr/bin/python' in the shebang. To work around that
# we copy the original script into a temporary folder, and
# change the shebang to '/usr/bin/env python'
dtrace = which("dtrace").path
dtrace_copy = join_path(self.dtrace_copy_path, "dtrace")

with working_dir(self.dtrace_copy_path, create=True):
copy(dtrace, dtrace_copy)
filter_file(
"^#!/usr/bin/python",
"#!/usr/bin/env {0}".format(os.path.basename(self.spec["python"].command.path)),
dtrace_copy,
)

# To have our own copy of dtrace in PATH, we need to
# prepend to PATH the temporary folder where it resides
env["PATH"] = ":".join([self.dtrace_copy_path] + env["PATH"].split(":"))

@run_after("install")
def filter_sbang(self):
# Revert sbang, so Spack's sbang hook can fix it up (we have to do
# this after install because otherwise the install target will try
# to rebuild files as filter_file updates the timestamps)
if self.spec.satisfies("@2.53.4:"):
pattern = "^#!/usr/bin/env {0}".format(
os.path.basename(self.spec["python"].command.path)
)
repl = "#!{0}".format(self.spec["python"].command.path)
files = ["glib-genmarshal", "glib-mkenums"]
else:
pattern = "^#! /usr/bin/perl"
repl = "#!{0}".format(self.spec["perl"].command.path)
files = ["glib-mkenums"]

files = [join_path(self.prefix.bin, file) for file in files]
filter_file(pattern, repl, *files, backup=False)

@run_after("install")
def gettext_libdir(self):
# Packages that link to glib were also picking up -lintl from glib's
# glib-2.0.pc file. However, packages such as py-pygobject were
# bypassing spack's compiler wrapper for linking and thus not finding
# the gettext library directory. The patch below explicitly adds the
# appropriate -L path.
spec = self.spec
if (
spec.satisfies("@2.0:2")
and "intl" in self.spec["gettext"].libs.names
and not is_system_path(spec["gettext"].prefix)
):
pattern = "Libs:"
repl = "Libs: -L{0} -Wl,-rpath={0} ".format(spec["gettext"].libs.directories[0])
myfile = join_path(self.spec["glib"].libs.directories[0], "pkgconfig", "glib-2.0.pc")
filter_file(pattern, repl, myfile, backup=False)


class MesonBuilder(BaseBuilder, spack.build_systems.meson.MesonBuilder):
def meson_args(self):
args = []
if self.spec.satisfies("@2.63.5:"):
Expand Down Expand Up @@ -221,21 +312,8 @@ def meson_args(self):
args.append("-Diconv=gnu")
return args

def install(self, spec, prefix):
with working_dir("spack-build", create=True):
# We cannot simply do
# meson('..', *std_meson_args, *self.meson_args())
# because that is not Python 2 compatible. Instead, collect
# arguments into a temporary buffer first.
args = []
args.extend(std_meson_args)
args.extend(self.meson_args())
meson("..", *args)
ninja("-v")
if self.run_tests:
ninja("test")
ninja("install")

class AutotoolsBuilder(BaseBuilder, spack.build_systems.autotools.AutotoolsBuilder):
def configure_args(self):
args = []
if "+libmount" in self.spec:
Expand Down Expand Up @@ -276,91 +354,3 @@ def configure_args(self):
args.append("GTKDOC_MKPDF={0}".format(true))
args.append("GTKDOC_REBASE={0}".format(true))
return args

@when("@:2.57")
def install(self, spec, prefix):
configure("--prefix={0}".format(prefix), *self.configure_args())
make()
if self.run_tests:
make("check")
make("install")
if self.run_tests:
make("installcheck")

@property
def dtrace_copy_path(self):
return join_path(self.stage.source_path, "dtrace-copy")

@run_before("install")
def fix_python_path(self):
if not self.spec.satisfies("@2.53.4:"):
return

files = ["gobject/glib-genmarshal.in", "gobject/glib-mkenums.in"]

filter_file(
"^#!/usr/bin/env @PYTHON@",
"#!/usr/bin/env {0}".format(os.path.basename(self.spec["python"].command.path)),
*files,
)

@run_before("install")
def fix_dtrace_usr_bin_path(self):
if "tracing=dtrace" not in self.spec:
return

# dtrace may cause glib build to fail because it uses
# '/usr/bin/python' in the shebang. To work around that
# we copy the original script into a temporary folder, and
# change the shebang to '/usr/bin/env python'
dtrace = which("dtrace").path
dtrace_copy = join_path(self.dtrace_copy_path, "dtrace")

with working_dir(self.dtrace_copy_path, create=True):
copy(dtrace, dtrace_copy)
filter_file(
"^#!/usr/bin/python",
"#!/usr/bin/env {0}".format(os.path.basename(self.spec["python"].command.path)),
dtrace_copy,
)

# To have our own copy of dtrace in PATH, we need to
# prepend to PATH the temporary folder where it resides
env["PATH"] = ":".join([self.dtrace_copy_path] + env["PATH"].split(":"))

@run_after("install")
def filter_sbang(self):
# Revert sbang, so Spack's sbang hook can fix it up (we have to do
# this after install because otherwise the install target will try
# to rebuild files as filter_file updates the timestamps)
if self.spec.satisfies("@2.53.4:"):
pattern = "^#!/usr/bin/env {0}".format(
os.path.basename(self.spec["python"].command.path)
)
repl = "#!{0}".format(self.spec["python"].command.path)
files = ["glib-genmarshal", "glib-mkenums"]
else:
pattern = "^#! /usr/bin/perl"
repl = "#!{0}".format(self.spec["perl"].command.path)
files = ["glib-mkenums"]

files = [join_path(self.prefix.bin, file) for file in files]
filter_file(pattern, repl, *files, backup=False)

@run_after("install")
def gettext_libdir(self):
# Packages that link to glib were also picking up -lintl from glib's
# glib-2.0.pc file. However, packages such as py-pygobject were
# bypassing spack's compiler wrapper for linking and thus not finding
# the gettext library directory. The patch below explicitly adds the
# appropriate -L path.
spec = self.spec
if (
spec.satisfies("@2.0:2")
and "intl" in self.spec["gettext"].libs.names
and not is_system_path(spec["gettext"].prefix)
):
pattern = "Libs:"
repl = "Libs: -L{0} -Wl,-rpath={0} ".format(spec["gettext"].libs.directories[0])
myfile = join_path(self.spec["glib"].libs.directories[0], "pkgconfig", "glib-2.0.pc")
filter_file(pattern, repl, myfile, backup=False)

0 comments on commit 15218d2

Please sign in to comment.