Link lib/ against libpriv/, use it to share sack loading function

On the plus side, we share some code between the library and the
binary now.  On the downside, because `librpmostreepriv.la` is a
noinst library, its code text is duplicated between the shared library
and binary, at least until we either:

 - Have the binary solely use the public shared library (like ostree does)
 - Install `librpmostreepriv.so` to e.g. `/usr/lib64/rpm-ostree/librpmostreepriv.so`
   without the headers being public
This commit is contained in:
Colin Walters 2015-04-17 14:03:24 -04:00
parent f3600e922e
commit 7b45f13a62
9 changed files with 83 additions and 99 deletions

View File

@ -34,7 +34,7 @@ librpmostree_1_la_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/libglnx -I$(srcdir)/src/libp
-fvisibility=hidden '-D_RPMOSTREE_EXTERN=__attribute((visibility("default"))) extern' \
$(PKGDEP_RPMOSTREE_CFLAGS)
librpmostree_1_la_LDFLAGS = -version-number 1:0:0 -Bsymbolic-functions
librpmostree_1_la_LIBADD = libglnx.la $(PKGDEP_RPMOSTREE_LIBS)
librpmostree_1_la_LIBADD = $(PKGDEP_RPMOSTREE_LIBS) librpmostreepriv.la
if BUILDOPT_INTROSPECTION
RpmOstree-1.0.gir: librpmostree-1.la Makefile

36
Makefile-libpriv.am Normal file
View File

@ -0,0 +1,36 @@
# Copyright (C) 2015 Colin Walters <walters@verbum.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
noinst_LTLIBRARIES += librpmostreepriv.la
librpmostreepriv_la_SOURCES = \
src/libpriv/rpmostree-postprocess.c \
src/libpriv/rpmostree-postprocess.h \
src/libpriv/rpmostree-json-parsing.c \
src/libpriv/rpmostree-json-parsing.h \
src/libpriv/rpmostree-util.c \
src/libpriv/rpmostree-util.h \
src/libpriv/rpmostree-passwd-util.c \
src/libpriv/rpmostree-passwd-util.h \
src/libpriv/rpmostree-cleanup.h \
src/libpriv/rpmostree-rpm-util.c \
src/libpriv/rpmostree-rpm-util.h \
src/libpriv/rpmostree-treepkgdiff.c \
src/libpriv/rpmostree-treepkgdiff.h \
$(NULL)
librpmostreepriv_la_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/libpriv -I$(libglnx_srcpath) -DPKGLIBDIR=\"$(pkglibdir)\" $(PKGDEP_RPMOSTREE_CFLAGS)
librpmostreepriv_la_LIBADD = $(AM_LDFLAGS) $(PKGDEP_RPMOSTREE_LIBS) libglnx.la $(CAP_LIBS)

View File

@ -1,50 +0,0 @@
# Makefile for C source code
#
# Copyright (C) 2015 Colin Walters <walters@verbum.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
include Makefile-lib-defines.am
privlib_LTLIBRARIES += librpmostreepriv.la
librpmostree_1_la_SOURCES = \
librpmostree-priv/rpmostree-cleanup.h \
librpmostree-priv/rpmostree-cleanup.c \
$(NULL)
librpmostreepriv_la_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/libglnx -I$(srcdir)/librpmostree-priv \
$(PKGDEP_RPMOSTREE_CFLAGS)
librpmostreepriv_la_LDFLAGS = -Bsymbolic-functions -export-symbols-regex '^rpmostreepriv_'
librpmostree_priv_la_LIBADD = libglnx.la $(PKGDEP_RPMOSTREE_LIBS)
if BUILDOPT_INTROSPECTION
RpmOstree-1.0.gir: libostree-1.la Makefile
RpmOstree_1_0_gir_EXPORT_PACKAGES = rpm-ostree-1
RpmOstree_1_0_gir_INCLUDES = OSTree-1 Gio-2.0
RpmOstree_1_0_gir_CFLAGS = $(librpmostree_1_la_CFLAGS)
RpmOstree_1_0_gir_LIBS = librpmostree-1.la
RpmOstree_1_0_gir_SCANNERFLAGS = --warn-all --identifier-prefix=RpmOstree --symbol-prefix=rpmostree
RpmOstree_1_0_gir_FILES = $(librpmostreeinclude_HEADERS) $(filter-out %-private.h,$(librpmostree_1_la_SOURCES))
INTROSPECTION_GIRS += RpmOstree-1.0.gir
gir_DATA += RpmOstree-1.0.gir
typelib_DATA += RpmOstree-1.0.typelib
CLEANFILES += $(gir_DATA) $(typelib_DATA)
endif
pkgconfig_DATA += librpmostree/rpm-ostree-1.pc

View File

@ -17,28 +17,6 @@
bin_PROGRAMS += rpm-ostree
noinst_LTLIBRARIES += librpmostree.la
librpmostree_la_SOURCES = \
src/libpriv/rpmostree-postprocess.c \
src/libpriv/rpmostree-postprocess.h \
src/libpriv/rpmostree-json-parsing.c \
src/libpriv/rpmostree-json-parsing.h \
src/libpriv/rpmostree-util.c \
src/libpriv/rpmostree-util.h \
src/libpriv/rpmostree-passwd-util.c \
src/libpriv/rpmostree-passwd-util.h \
src/libpriv/rpmostree-cleanup.h \
src/libpriv/rpmostree-treepkgdiff.c \
src/libpriv/rpmostree-treepkgdiff.h \
src/libpriv/rpmostree-rpm-util.c \
src/libpriv/rpmostree-rpm-util.h \
src/libpriv/rpmostree-treepkgdiff.c \
src/libpriv/rpmostree-treepkgdiff.h \
$(NULL)
librpmostree_la_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/libpriv -I$(libglnx_srcpath) -DPKGLIBDIR=\"$(pkglibdir)\" $(PKGDEP_RPMOSTREE_CFLAGS)
librpmostree_la_LIBADD = $(AM_LDFLAGS) $(PKGDEP_RPMOSTREE_LIBS) libglnx.la $(CAP_LIBS)
rpm_ostree_SOURCES = src/app/main.c \
src/app/rpmostree-builtins.h \
src/app/rpmostree-db-builtins.h \
@ -62,7 +40,7 @@ rpm_ostree_SOURCES += \
endif
rpm_ostree_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/app -I$(srcdir)/src/libpriv -I$(libglnx_srcpath) -DPKGLIBDIR=\"$(pkglibdir)\" $(PKGDEP_RPMOSTREE_CFLAGS)
rpm_ostree_LDADD = $(AM_LDFLAGS) $(PKGDEP_RPMOSTREE_LIBS) libglnx.la librpmostree.la
rpm_ostree_LDADD = $(AM_LDFLAGS) $(PKGDEP_RPMOSTREE_LIBS) librpmostreepriv.la
privdatadir=$(pkglibdir)
privdata_DATA = src/app/tmpfiles-ostree-integration.conf

View File

@ -22,7 +22,7 @@ tests/compose/test-repo.repo: tests/compose/test-repo.repo.in tests/compose/yum/
tests_jsonutil_CPPFLAGS = -I $(srcdir)/src/libpriv
tests_jsonutil_CFLAGS = $(PKGDEP_RPMOSTREE_CFLAGS)
tests_jsonutil_LDADD = $(PKGDEP_RPMOSTREE_LIBS) librpmostree.la
tests_jsonutil_LDADD = $(PKGDEP_RPMOSTREE_LIBS) librpmostreepriv.la
tests/test-compose.sh: tests/compose/test-repo.repo

View File

@ -46,6 +46,7 @@ TYPELIBS = $(GIRS:.gir=.typelib)
include libglnx/Makefile-libglnx.am
noinst_LTLIBRARIES += libglnx.la
include Makefile-libpriv.am
include Makefile-lib.am
include Makefile-rpm-ostree.am
include Makefile-tests.am

View File

@ -25,6 +25,7 @@
#include "rpmostree-db.h"
#include "rpmostree-priv.h"
#include "rpmostree-cleanup.h"
#include "rpmostree-treepkgdiff.h"
/**
* SECTION:librpmostree-dbquery
@ -98,22 +99,10 @@ rpm_ostree_db_query (OstreeRepo *repo,
{
HySack hsack;
#if BUILDOPT_HAWKEY_SACK_CREATE2
hsack = hy_sack_create (NULL, NULL,
rpmdb_tempdir,
NULL,
0);
#else
hsack = hy_sack_create (NULL, NULL,
rpmdb_tempdir,
0);
#endif
if (hsack == NULL)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Failed to create sack cache");
if (!rpmostree_get_sack_for_root (tempdir_dfd, ".",
&hsack, cancellable, error))
goto out;
}
sack = _rpm_ostree_refsack_new (hsack);
}

View File

@ -26,20 +26,19 @@
#include "rpmostree-cleanup.h"
gboolean
rpmostree_get_pkglist_for_root (int dfd,
rpmostree_get_sack_for_root (int dfd,
const char *path,
HySack *out_sack,
HyPackageList *out_pkglist,
GCancellable *cancellable,
GError **error)
{
gboolean ret = FALSE;
int rc;
_cleanup_hysack_ HySack sack = NULL;
_cleanup_hyquery_ HyQuery query = NULL;
_cleanup_hypackagelist_ HyPackageList pkglist = NULL;
g_autofree char *fullpath = glnx_fdrel_abspath (dfd, path);
g_return_val_if_fail (out_sack != NULL, FALSE);
#if BUILDOPT_HAWKEY_SACK_CREATE2
sack = hy_sack_create (NULL, NULL,
fullpath,
@ -63,6 +62,30 @@ rpmostree_get_pkglist_for_root (int dfd,
g_prefix_error (error, "Failed to load system repo: ");
goto out;
}
ret = TRUE;
*out_sack = g_steal_pointer (&sack);
out:
return ret;
}
gboolean
rpmostree_get_pkglist_for_root (int dfd,
const char *path,
HySack *out_sack,
HyPackageList *out_pkglist,
GCancellable *cancellable,
GError **error)
{
gboolean ret = FALSE;
_cleanup_hysack_ HySack sack = NULL;
_cleanup_hyquery_ HyQuery query = NULL;
_cleanup_hypackagelist_ HyPackageList pkglist = NULL;
g_autofree char *fullpath = glnx_fdrel_abspath (dfd, path);
if (!rpmostree_get_sack_for_root (dfd, path, &sack, cancellable, error))
goto out;
query = hy_query_create (sack);
hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME);
pkglist = hy_query_run (query);

View File

@ -23,6 +23,13 @@
#include <ostree.h>
#include "rpmostree-cleanup.h"
gboolean
rpmostree_get_sack_for_root (int dfd,
const char *path,
HySack *out_sack,
GCancellable *cancellable,
GError **error);
gboolean
rpmostree_get_pkglist_for_root (int dfd,
const char *path,