diff --git a/.gitignore b/.gitignore index 14d33613a..657ebdb8c 100644 --- a/.gitignore +++ b/.gitignore @@ -127,6 +127,8 @@ Makefile.in /common/errnostring/errnostring-gperf.gperf /common/errnostring/errnostring.h /common/mlaugeas/.depend +/common/mlcustomize/.depend +/common/mlcustomize/test-firstboot-*.sh /common/mlgettext/.depend /common/mlgettext/common_gettext.ml /common/mllibvirt/.depend @@ -178,7 +180,6 @@ Makefile.in /customize/customize-options.pod /customize/customize-synopsis.pod /customize/stamp-virt-customize.pod -/customize/test-firstboot-*.sh /customize/test-password-*.sh /customize/test-settings-*.sh /customize/virt-customize diff --git a/Makefile.am b/Makefile.am index e5a28d70c..b5d5dcd6b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -163,6 +163,7 @@ SUBDIRS += common/mlprogress SUBDIRS += common/mlvisit SUBDIRS += common/mlxml SUBDIRS += common/mltools +SUBDIRS += common/mlcustomize if HAVE_LIBVIRT SUBDIRS += common/mllibvirt endif diff --git a/builder/Makefile.am b/builder/Makefile.am index c7caec5cb..7b4c3a59e 100644 --- a/builder/Makefile.am +++ b/builder/Makefile.am @@ -188,6 +188,7 @@ OCAMLPACKAGES = \ -I $(top_builddir)/common/mlgettext \ -I $(top_builddir)/common/mlpcre \ -I $(top_builddir)/common/mltools \ + -I $(top_builddir)/common/mlcustomize \ -I $(top_builddir)/customize OCAMLPACKAGES_TESTS = if HAVE_OCAML_PKG_GETTEXT @@ -226,6 +227,7 @@ OCAMLLINKFLAGS = \ mlguestfs.$(MLARCHIVE) \ mlcutils.$(MLARCHIVE) \ mltools.$(MLARCHIVE) \ + mlcustomize.$(MLARCHIVE) \ customize.$(MLARCHIVE) \ $(LINK_CUSTOM_OCAMLC_ONLY) @@ -236,6 +238,7 @@ virt_builder_DEPENDENCIES = \ ../common/mlstdutils/mlstdutils.$(MLARCHIVE) \ ../common/mlutils/mlcutils.$(MLARCHIVE) \ ../common/mltools/mltools.$(MLARCHIVE) \ + ../common/mlcustomize/mlcustomize.$(MLARCHIVE) \ ../customize/customize.$(MLARCHIVE) \ $(top_srcdir)/ocaml-link.sh virt_builder_LINK = \ diff --git a/common/mlcustomize/Makefile.am b/common/mlcustomize/Makefile.am new file mode 100644 index 000000000..293a9d394 --- /dev/null +++ b/common/mlcustomize/Makefile.am @@ -0,0 +1,172 @@ +# libguestfs OCaml virt-customize common code +# Copyright (C) 2011-2019 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +include $(top_srcdir)/subdir-rules.mk + +EXTRA_DIST = \ + $(SOURCES_MLI) \ + $(SOURCES_ML) \ + $(SOURCES_C) \ + test-firstboot.sh \ + test-selinuxrelabel.sh + +SOURCES_MLI = \ + firstboot.mli \ + SELinux_relabel.mli + +SOURCES_ML = \ + firstboot.ml \ + SELinux_relabel.ml + +if HAVE_OCAML + +# We pretend that we're building a C library. automake handles the +# compilation of the C sources for us. At the end we take the C +# objects and OCaml objects and link them into the OCaml library. +# This C library is never used. + +noinst_LIBRARIES = libmlcustomize.a + +if !HAVE_OCAMLOPT +MLCUSTOMIZE_CMA = mlcustomize.cma +else +MLCUSTOMIZE_CMA = mlcustomize.cmxa +endif + +noinst_DATA = $(MLCUSTOMIZE_CMA) + +libmlcustomize_a_SOURCES = dummy.c +libmlcustomize_a_CPPFLAGS = \ + -DCAML_NAME_SPACE \ + -I. \ + -I$(top_builddir) \ + -I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \ + -I$(shell $(OCAMLC) -where) \ + -I$(top_srcdir)/common/utils \ + -I$(top_srcdir)/lib \ + -I$(top_srcdir)/common/mlstdutils \ + -I$(top_srcdir)/common/mlgettext \ + -I$(top_srcdir)/common/mlpcre \ + -I$(top_srcdir)/common/mltools +libmlcustomize_a_CFLAGS = \ + $(WARN_CFLAGS) $(WERROR_CFLAGS) \ + -fPIC + +BOBJECTS = $(SOURCES_ML:.ml=.cmo) +XOBJECTS = $(BOBJECTS:.cmo=.cmx) + +# -I $(top_builddir)/lib/.libs is a hack which forces corresponding -L +# option to be passed to gcc, so we don't try linking against an +# installed copy of libguestfs. +OCAMLPACKAGES = \ + -package str,unix \ + -I $(top_builddir)/common/utils/.libs \ + -I $(top_builddir)/lib/.libs \ + -I $(top_builddir)/gnulib/lib/.libs \ + -I $(top_builddir)/ocaml \ + -I $(top_builddir)/common/mlstdutils \ + -I $(top_builddir)/common/mlgettext \ + -I $(top_builddir)/common/mlpcre \ + -I $(top_builddir)/common/mltools \ + -I $(builddir) +OCAMLPACKAGES_TESTS = $(MLCUSTOMIZE_CMA) +if HAVE_OCAML_PKG_GETTEXT +OCAMLPACKAGES += -package gettext-stub +endif + +OCAMLCLIBS = \ + -lutils \ + $(LIBINTL) \ + -lgnu + +OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR) -ccopt '$(CFLAGS)' + +if !HAVE_OCAMLOPT +OBJECTS = $(BOBJECTS) +else +OBJECTS = $(XOBJECTS) +endif + +libmlcustomize_a_DEPENDENCIES = $(OBJECTS) + +$(MLCUSTOMIZE_CMA): $(OBJECTS) libmlcustomize.a + $(OCAMLFIND) mklib $(OCAMLPACKAGES) \ + $(OBJECTS) $(libmlcustomize_a_OBJECTS) -o mlcustomize + +# Tests. + +TESTS_ENVIRONMENT = $(top_builddir)/run --test + +TESTS = + +if ENABLE_APPLIANCE +TESTS += \ + $(SLOW_TESTS) +endif + +check-valgrind: + $(MAKE) VG="@VG@" check + +# Slow tests of virt-customize functionality in real guests. + +SLOW_TESTS = \ + $(firstboot_test_scripts) \ + test-selinuxrelabel.sh + +check-slow: + $(MAKE) check TESTS="$(SLOW_TESTS)" SLOW=1 + +firstboot_test_scripts := \ + test-firstboot-rhel-4.9.sh \ + test-firstboot-rhel-5.11.sh \ + test-firstboot-rhel-6.8.sh \ + test-firstboot-rhel-7.2.sh \ + test-firstboot-debian-6.sh \ + test-firstboot-debian-7.sh \ + test-firstboot-debian-8.sh \ + test-firstboot-fedora-26.sh \ + test-firstboot-fedora-27.sh \ + test-firstboot-ubuntu-10.04.sh \ + test-firstboot-ubuntu-12.04.sh \ + test-firstboot-ubuntu-14.04.sh \ + test-firstboot-ubuntu-16.04.sh \ + test-firstboot-ubuntu-18.04.sh \ + test-firstboot-windows-6.2-server.sh \ + test-firstboot-windows-6.3-server.sh \ + test-firstboot-windows-10.0-server.sh +# Firstboot is known-broken on RHEL 3: +# test-firstboot-rhel-3.9.sh + +test-firstboot-%.sh: + rm -f $@ $@-t + f=`echo "$@" | $(SED) 's/test-firstboot-\(.*\).sh/\1/'`; \ + echo 'script=$@ exec $$srcdir/test-firstboot.sh' "$$f" > $@-t + chmod 0755 $@-t + mv $@-t $@ + +CLEANFILES += \ + $(firstboot_test_scripts) \ + firstboot-*.img + +# Dependencies. +.depend: $(srcdir)/*.mli $(srcdir)/*.ml + $(top_builddir)/ocaml-dep.sh $^ +-include .depend + +endif + +.PHONY: docs diff --git a/customize/SELinux_relabel.ml b/common/mlcustomize/SELinux_relabel.ml similarity index 100% rename from customize/SELinux_relabel.ml rename to common/mlcustomize/SELinux_relabel.ml diff --git a/customize/SELinux_relabel.mli b/common/mlcustomize/SELinux_relabel.mli similarity index 100% rename from customize/SELinux_relabel.mli rename to common/mlcustomize/SELinux_relabel.mli diff --git a/common/mlcustomize/dummy.c b/common/mlcustomize/dummy.c new file mode 100644 index 000000000..ebab6198c --- /dev/null +++ b/common/mlcustomize/dummy.c @@ -0,0 +1,2 @@ +/* Dummy source, to be used for OCaml-based tools with no C sources. */ +enum { foo = 1 }; diff --git a/customize/firstboot.ml b/common/mlcustomize/firstboot.ml similarity index 100% rename from customize/firstboot.ml rename to common/mlcustomize/firstboot.ml diff --git a/customize/firstboot.mli b/common/mlcustomize/firstboot.mli similarity index 100% rename from customize/firstboot.mli rename to common/mlcustomize/firstboot.mli diff --git a/customize/test-firstboot.sh b/common/mlcustomize/test-firstboot.sh similarity index 100% rename from customize/test-firstboot.sh rename to common/mlcustomize/test-firstboot.sh diff --git a/customize/test-selinuxrelabel.sh b/common/mlcustomize/test-selinuxrelabel.sh similarity index 100% rename from customize/test-selinuxrelabel.sh rename to common/mlcustomize/test-selinuxrelabel.sh diff --git a/configure.ac b/configure.ac index f8a613df3..ff3dc5e99 100644 --- a/configure.ac +++ b/configure.ac @@ -237,6 +237,7 @@ AC_CONFIG_FILES([Makefile common/errnostring/Makefile common/edit/Makefile common/mlaugeas/Makefile + common/mlcustomize/Makefile common/mlgettext/Makefile common/mllibvirt/Makefile common/mlpcre/Makefile diff --git a/customize/Makefile.am b/customize/Makefile.am index 4c246b417..181cba2b4 100644 --- a/customize/Makefile.am +++ b/customize/Makefile.am @@ -21,9 +21,7 @@ EXTRA_DIST = \ $(generator_built) \ $(SOURCES_MLI) $(SOURCES_ML) $(SOURCES_C) \ customize_main.ml \ - test-firstboot.sh \ test-password.pl \ - test-selinuxrelabel.sh \ test-settings.sh \ test-virt-customize.sh \ test-virt-customize-docs.sh \ @@ -41,12 +39,10 @@ SOURCES_MLI = \ customize_cmdline.mli \ customize_main.mli \ customize_run.mli \ - firstboot.mli \ hostname.mli \ password.mli \ perl_edit.mli \ random_seed.mli \ - SELinux_relabel.mli \ ssh_key.mli \ subscription_manager.mli \ timezone.mli @@ -55,12 +51,10 @@ SOURCES_MLI = \ SOURCES_ML = \ append_line.ml \ crypt.ml \ - firstboot.ml \ hostname.ml \ password.ml \ perl_edit.ml \ random_seed.ml \ - SELinux_relabel.ml \ ssh_key.ml \ subscription_manager.ml \ timezone.ml \ @@ -130,6 +124,7 @@ OCAMLPACKAGES = \ -I $(top_builddir)/common/mlgettext \ -I $(top_builddir)/common/mlpcre \ -I $(top_builddir)/common/mltools \ + -I $(top_builddir)/common/mlcustomize \ -I $(builddir) if HAVE_OCAML_PKG_GETTEXT OCAMLPACKAGES += -package gettext-stub @@ -162,6 +157,7 @@ OCAMLLINKFLAGS = \ mlpcre.$(MLARCHIVE) \ mlcutils.$(MLARCHIVE) \ mltools.$(MLARCHIVE) \ + mlcustomize.$(MLARCHIVE) \ customize.$(MLARCHIVE) \ $(LINK_CUSTOM_OCAMLC_ONLY) @@ -180,10 +176,12 @@ virt_customize_DEPENDENCIES = \ $(top_srcdir)/ocaml-link.sh \ $(CUSTOMIZE_THEOBJECTS) \ $(CUSTOMIZE_CMA) \ + ../common/mlcustomize/mlcustomize.$(MLARCHIVE) \ ../common/mlutils/mlcutils.$(MLARCHIVE) \ ../common/mlgettext/mlgettext.$(MLARCHIVE) \ ../common/mlpcre/mlpcre.$(MLARCHIVE) \ - ../common/mltools/mltools.$(MLARCHIVE) + ../common/mltools/mltools.$(MLARCHIVE) \ + ../common/mlcustomize/mlcustomize.$(MLARCHIVE) virt_customize_LINK = \ $(top_srcdir)/ocaml-link.sh -cclib '$(OCAMLCLIBS)' -- \ $(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLPACKAGES) $(OCAMLLINKFLAGS) \ @@ -225,42 +223,12 @@ check-valgrind: # Slow tests of virt-customize functionality in real guests. SLOW_TESTS = \ - $(firstboot_test_scripts) \ $(password_test_scripts) \ - test-selinuxrelabel.sh \ $(settings_test_scripts) check-slow: $(MAKE) check TESTS="$(SLOW_TESTS)" SLOW=1 -firstboot_test_scripts := \ - test-firstboot-rhel-4.9.sh \ - test-firstboot-rhel-5.11.sh \ - test-firstboot-rhel-6.8.sh \ - test-firstboot-rhel-7.2.sh \ - test-firstboot-debian-6.sh \ - test-firstboot-debian-7.sh \ - test-firstboot-debian-8.sh \ - test-firstboot-fedora-26.sh \ - test-firstboot-fedora-27.sh \ - test-firstboot-ubuntu-10.04.sh \ - test-firstboot-ubuntu-12.04.sh \ - test-firstboot-ubuntu-14.04.sh \ - test-firstboot-ubuntu-16.04.sh \ - test-firstboot-ubuntu-18.04.sh \ - test-firstboot-windows-6.2-server.sh \ - test-firstboot-windows-6.3-server.sh \ - test-firstboot-windows-10.0-server.sh -# Firstboot is known-broken on RHEL 3: -# test-firstboot-rhel-3.9.sh - -test-firstboot-%.sh: - rm -f $@ $@-t - f=`echo "$@" | $(SED) 's/test-firstboot-\(.*\).sh/\1/'`; \ - echo 'script=$@ exec $$srcdir/test-firstboot.sh' "$$f" > $@-t - chmod 0755 $@-t - mv $@-t $@ - password_test_scripts := \ test-password-centos-7.2.sh \ test-password-debian-6.sh \ @@ -310,10 +278,8 @@ test-settings-%.sh: mv $@-t $@ CLEANFILES += \ - $(firstboot_test_scripts) \ $(password_test_scripts) \ $(settings_test_scripts) \ - firstboot-*.img \ password-*.img \ password-*.log \ settings-*.img diff --git a/docs/guestfs-hacking.pod b/docs/guestfs-hacking.pod index 2efa7a9a7..42035fdb6 100644 --- a/docs/guestfs-hacking.pod +++ b/docs/guestfs-hacking.pod @@ -99,6 +99,11 @@ handled by this library. Bindings for the Augeas library. These come from the ocaml-augeas library L +=item F + +Library code associated with C but also used in other +tools. + =item F Small, generated wrapper which allows libguestfs to be compiled with diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am index e8afb45f9..434645dee 100644 --- a/sysprep/Makefile.am +++ b/sysprep/Makefile.am @@ -120,6 +120,7 @@ OCAMLPACKAGES = \ -I $(top_builddir)/common/mlpcre \ -I $(top_builddir)/common/mlvisit \ -I $(top_builddir)/common/mltools \ + -I $(top_builddir)/common/mlcustomize \ -I $(top_builddir)/customize if HAVE_OCAML_PKG_GETTEXT OCAMLPACKAGES += -package gettext-stub @@ -151,6 +152,7 @@ OCAMLLINKFLAGS = \ mlcutils.$(MLARCHIVE) \ mltools.$(MLARCHIVE) \ mlvisit.$(MLARCHIVE) \ + mlcustomize.$(MLARCHIVE) \ customize.$(MLARCHIVE) \ $(LINK_CUSTOM_OCAMLC_ONLY) @@ -161,6 +163,7 @@ virt_sysprep_DEPENDENCIES = \ ../common/mlgettext/mlgettext.$(MLARCHIVE) \ ../common/mlpcre/mlpcre.$(MLARCHIVE) \ ../common/mltools/mltools.$(MLARCHIVE) \ + ../common/mlcustomize/mlcustomize.$(MLARCHIVE) \ ../customize/customize.$(MLARCHIVE) \ $(top_srcdir)/ocaml-link.sh virt_sysprep_LINK = \ diff --git a/v2v/Makefile.am b/v2v/Makefile.am index c803808a3..d79b6f487 100644 --- a/v2v/Makefile.am +++ b/v2v/Makefile.am @@ -206,8 +206,8 @@ virt_v2v_CFLAGS = \ $(LIBVIRT_CFLAGS) BOBJECTS = \ - $(top_builddir)/customize/firstboot.cmo \ - $(top_builddir)/customize/SELinux_relabel.cmo \ + $(top_builddir)/common/mlcustomize/firstboot.cmo \ + $(top_builddir)/common/mlcustomize/SELinux_relabel.cmo \ $(SOURCES_ML:.ml=.cmo) XOBJECTS = $(BOBJECTS:.cmo=.cmx) @@ -228,7 +228,7 @@ OCAMLPACKAGES = \ -I $(top_builddir)/common/mlxml \ -I $(top_builddir)/common/mltools \ -I $(top_builddir)/common/mllibvirt \ - -I $(top_builddir)/customize + -I $(top_builddir)/common/mlcustomize if HAVE_OCAML_PKG_GETTEXT OCAMLPACKAGES += -package gettext-stub endif @@ -259,6 +259,7 @@ OCAMLLINKFLAGS = \ mlcutils.$(MLARCHIVE) \ mltools.$(MLARCHIVE) \ mllibvirt.$(MLARCHIVE) \ + mlcustomize.$(MLARCHIVE) \ $(LINK_CUSTOM_OCAMLC_ONLY) virt_v2v_DEPENDENCIES = $(OBJECTS) $(top_srcdir)/ocaml-link.sh @@ -305,6 +306,7 @@ virt_v2v_copy_to_local_DEPENDENCIES = \ ../common/mlutils/mlcutils.$(MLARCHIVE) \ ../common/mltools/mltools.$(MLARCHIVE) \ ../common/mllibvirt/mllibvirt.$(MLARCHIVE) \ + ../common/mlcustomize/mlcustomize.$(MLARCHIVE) \ $(top_srcdir)/ocaml-link.sh virt_v2v_copy_to_local_LINK = \ $(top_srcdir)/ocaml-link.sh -cclib '$(OCAMLCLIBS)' -- \ @@ -678,7 +680,6 @@ check_PROGRAMS += v2v_unit_tests var_expander_tests endif v2v_unit_tests_BOBJECTS = \ - $(top_builddir)/customize/firstboot.cmo \ types.cmo \ uefi.cmo \ utils.cmo \ @@ -727,6 +728,7 @@ v2v_unit_tests_DEPENDENCIES = \ ../common/mlpcre/mlpcre.$(MLARCHIVE) \ ../common/mlutils/mlcutils.$(MLARCHIVE) \ ../common/mltools/mltools.$(MLARCHIVE) \ + ../common/mlcustomize/mlcustomize.$(MLARCHIVE) \ $(top_srcdir)/ocaml-link.sh v2v_unit_tests_LINK = \ $(top_srcdir)/ocaml-link.sh -cclib '$(OCAMLCLIBS)' -- \