Most distros already ship copies of pci.ids/usb.ids. This commit allows to make use of these rather than the ones shipped with libosinfo. This is achieved through the use of --with-usb-ids-path and --with-pci-ids-path configure flags. --- configure.ac | 24 ++++++++++++++++++++++++ data/Makefile.am | 25 ++++++++++++++----------- libosinfo.spec.in | 2 +- osinfo/osinfo_loader.c | 45 +++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 80 insertions(+), 16 deletions(-) diff --git a/configure.ac b/configure.ac index cf46f4d..5a54192 100644 --- a/configure.ac +++ b/configure.ac @@ -171,6 +171,30 @@ fi AC_SUBST(COVERAGE_CFLAGS) AC_SUBST(COVERAGE_LDFLAGS) +# Path to the usb.ids file -- to know if we use one shipped with another +# package, or an internal file +AC_ARG_WITH(usb-ids-path, + [AC_HELP_STRING([--with-usb-ids-path], + [Specify the path to usb.ids @<:@default=(internal)@:>@])],, + [with_usb_ids_path="\${usb_databasedir}/usb.ids"]) + +AM_CONDITIONAL(USE_INTERNAL_USB_IDS, test "x$with_usb_ids_path" = "x\${usb_databasedir}/usb.ids") +if test "x$with_usb_ids_path" != "x\${usb_databasedir}/usb.ids"; then + AC_DEFINE_UNQUOTED([USB_IDS], ["$with_usb_ids_path"], [Path to the usb.ids file]) +fi + +# Path to the pci.ids file -- to know if we use one shipped with another +# package, or an internal file +AC_ARG_WITH(pci-ids-path, + [AC_HELP_STRING([--with-pci-ids-path], + [Specify the path to pci.ids @<:@default=(internal)@:>@])],, + [with_pci_ids_path="\${pci_databasedir}/pci.ids"]) + +AM_CONDITIONAL(USE_INTERNAL_PCI_IDS, test "x$with_pci_ids_path" = "x\${pci_databasedir}/pci.ids") +if test "x$with_pci_ids_path" != "x\${pci_databasedir}/pci.ids"; then + AC_DEFINE_UNQUOTED([PCI_IDS], ["$with_pci_ids_path"], [Path to the pci.ids file]) +fi + # Setup GLIB_MKENUMS to use glib-mkenums even if GLib is uninstalled. GLIB_MKENUMS=`$PKG_CONFIG --variable=glib_mkenums glib-2.0` AC_SUBST(GLIB_MKENUMS) diff --git a/data/Makefile.am b/data/Makefile.am index 747f0e9..e88afa6 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1,10 +1,21 @@ SUBDIRS = datamaps devices oses hypervisors install-scripts schemas - EXTRA_DIST = usb.ids pci.ids 95-osinfo.rules.in +CLEANFILES = usb.ids pci.ids -databasedir = $(pkgdatadir)/db/ -database_DATA = usb.ids pci.ids +if USE_INTERNAL_USB_IDS +usb_database_DATA = usb.ids +usb_databasedir = $(pkgdatadir)/db/ +usb.ids: + -wget -q -O $@ http://www.linux-usb.org/usb.ids +endif + +if USE_INTERNAL_PCI_IDS +pci_database_DATA = pci.ids +pci_databasedir = $(pkgdatadir)/db/ +pci.ids: + -wget -q -O $@ http://pciids.sourceforge.net/v2.2/pci.ids +endif if WITH_UDEV BUILT_SOURCES = 95-osinfo.rules @@ -17,11 +28,3 @@ install-data-hook: 95-osinfo.rules $(INSTALL) -m 0644 95-osinfo.rules $(DESTDIR)$(UDEV_RULESDIR) endif - -CLEANFILES = usb.ids pci.ids - -usb.ids: - -wget -q -O $@ http://www.linux-usb.org/usb.ids - -pci.ids: - -wget -q -O $@ http://pciids.sourceforge.net/v2.2/pci.ids diff --git a/libosinfo.spec.in b/libosinfo.spec.in index 4e59504..0d5a3d5 100644 --- a/libosinfo.spec.in +++ b/libosinfo.spec.in @@ -84,7 +84,7 @@ This package provides the Vala bindings for libosinfo library. %define udev_arg --enable-udev=no %endif -%configure %{gir_arg} %{udev_arg} --enable-vala=yes +%configure %{gir_arg} %{udev_arg} --enable-vala=yes --with-usb-ids-path=/usr/share/hwdata/usb.ids --with-pci-ids-path=/usr/share/hwdata/pci.ids %__make %{?_smp_mflags} V=1 chmod a-x examples/*.js examples/*.py diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c index 76e9bc2..ec8c94c 100644 --- a/osinfo/osinfo_loader.c +++ b/osinfo/osinfo_loader.c @@ -1653,10 +1653,26 @@ osinfo_loader_process_file(OsinfoLoader *loader, case G_FILE_TYPE_REGULAR: if (g_str_has_suffix(name, ".xml")) osinfo_loader_process_file_reg_xml(loader, file, info, &error); - else if (strcmp(name, "usb.ids") == 0) - osinfo_loader_process_file_reg_usb(loader, file, info, &error); - else if (strcmp(name, "pci.ids") == 0) - osinfo_loader_process_file_reg_pci(loader, file, info, &error); + else { + gchar *pci_ids_filename; + gchar *usb_ids_filename; +#if defined(PCI_IDS) + pci_ids_filename = g_path_get_basename(PCI_IDS); +#else + pci_ids_filename = g_strdup("pci.ids"); +#endif +#if defined(USB_IDS) + usb_ids_filename = g_path_get_basename(USB_IDS); +#else + usb_ids_filename = g_strdup("usb.ids"); +#endif + if (strcmp(name, pci_ids_filename) == 0) + osinfo_loader_process_file_reg_pci(loader, file, info, &error); + else if (strcmp(name, usb_ids_filename) == 0) + osinfo_loader_process_file_reg_usb(loader, file, info, &error); + g_free(pci_ids_filename); + g_free(usb_ids_filename); + } break; case G_FILE_TYPE_DIRECTORY: @@ -1782,6 +1798,27 @@ void osinfo_loader_process_system_path(OsinfoLoader *loader, FALSE, err); g_object_unref(file); + if (error_is_set(err)) + return; + +#ifdef PCI_IDS + /* Load external pci.ids file */ + file = g_file_new_for_path(PCI_IDS); + osinfo_loader_process_file(loader, file, FALSE, err); + g_object_unref(file); + if (error_is_set(err)) + return; +#endif + +#ifdef USB_IDS + /* Load external usb.ids file */ + file = g_file_new_for_path(USB_IDS); + osinfo_loader_process_file(loader, file, FALSE, err); + g_object_unref(file); + if (error_is_set(err)) + return; +#endif + } void osinfo_loader_process_local_path(OsinfoLoader *loader, GError **err) -- 1.8.1.2 _______________________________________________ Libosinfo mailing list Libosinfo@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libosinfo