mllib, v2v: Split out OCaml utils bindings ‘common/mlutils’.

Create a module ‘C_utils’ containing functions like ‘drive_name’ and
‘shell_unquote’ which come from the C utilities.

The new directory ‘common/mlutils’ also contains the ‘Unix_utils’
wrappers around POSIX functions missing from the OCaml stdlib.
This commit is contained in:
Richard W.M. Jones
2017-06-09 09:15:30 +01:00
parent 5efebd8c7e
commit 8be72935dc
30 changed files with 366 additions and 97 deletions

3
.gitignore vendored
View File

@@ -129,6 +129,9 @@ Makefile.in
/common/mlstdutils/libdir.ml
/common/mlstdutils/oUnit-*
/common/mlstdutils/std_utils_tests
/common/mlutils/.depend
/common/mlutils/c_utils_unit_tests
/common/mlutils/oUnit-*
/common/mlvisit/.depend
/common/mlvisit/visit_tests
/common/mlxml/.depend

View File

@@ -155,18 +155,18 @@ SUBDIRS += csharp
# OCaml tools. Note 'common/ml*', 'mllib' and 'customize' contain
# shared code used by other OCaml tools, so these must come first.
if HAVE_OCAML
SUBDIRS += \
common/mlprogress \
common/mlvisit \
common/mlxml \
mllib \
customize \
builder builder/templates \
get-kernel \
resize \
sparsify \
sysprep \
v2v
SUBDIRS += common/mlutils
SUBDIRS += common/mlprogress
SUBDIRS += common/mlvisit
SUBDIRS += common/mlxml
SUBDIRS += mllib
SUBDIRS += customize
SUBDIRS += builder builder/templates
SUBDIRS += get-kernel
SUBDIRS += resize
SUBDIRS += sparsify
SUBDIRS += sysprep
SUBDIRS += v2v
if HAVE_OCAML_PKG_LIBVIRT
SUBDIRS += v2v/test-harness
endif

View File

@@ -125,6 +125,7 @@ OCAMLPACKAGES = \
-I $(top_builddir)/gnulib/lib/.libs \
-I $(top_builddir)/ocaml \
-I $(top_builddir)/common/mlstdutils \
-I $(top_builddir)/common/mlutils \
-I $(top_builddir)/mllib \
-I $(top_builddir)/customize
OCAMLPACKAGES_TESTS =
@@ -157,6 +158,7 @@ endif
OCAMLLINKFLAGS = \
mlstdutils.$(MLARCHIVE) \
mlguestfs.$(MLARCHIVE) \
mlcutils.$(MLARCHIVE) \
mllib.$(MLARCHIVE) \
customize.$(MLARCHIVE) \
$(LINK_CUSTOM_OCAMLC_ONLY)
@@ -164,6 +166,7 @@ OCAMLLINKFLAGS = \
virt_builder_DEPENDENCIES = \
$(OBJECTS) \
../common/mlstdutils/mlstdutils.$(MLARCHIVE) \
../common/mlutils/mlcutils.$(MLARCHIVE) \
../mllib/mllib.$(MLARCHIVE) \
../customize/customize.$(MLARCHIVE) \
$(top_srcdir)/ocaml-link.sh
@@ -236,6 +239,7 @@ endif
yajl_tests_DEPENDENCIES = \
$(yajl_tests_THEOBJECTS) \
../common/mlstdutils/mlstdutils.$(MLARCHIVE) \
../common/mlutils/mlcutils.$(MLARCHIVE) \
../mllib/mllib.$(MLARCHIVE) \
../customize/customize.$(MLARCHIVE) \
$(top_srcdir)/ocaml-link.sh
@@ -307,7 +311,7 @@ depend: .depend
.depend: $(wildcard $(abs_srcdir)/*.mli) $(wildcard $(abs_srcdir)/*.ml)
rm -f $@ $@-t
$(OCAMLFIND) ocamldep -I ../ocaml -I $(abs_srcdir) -I $(abs_top_builddir)/mlstdutils -I $(abs_top_builddir)/mllib -I $(abs_top_builddir)/customize $^ | \
$(OCAMLFIND) ocamldep -I ../ocaml -I $(abs_srcdir) -I $(abs_top_builddir)/mlstdutils -I $(abs_top_builddir)/mlutils -I $(abs_top_builddir)/mllib -I $(abs_top_builddir)/customize $^ | \
$(SED) 's/ *$$//' | \
$(SED) -e :a -e '/ *\\$$/N; s/ *\\\n */ /; ta' | \
$(SED) -e 's,$(abs_srcdir)/,$(builddir)/,g' | \

154
common/mlutils/Makefile.am Normal file
View File

@@ -0,0 +1,154 @@
# libguestfs OCaml tools common code
# Copyright (C) 2011-2017 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)
SOURCES_MLI = \
c_utils.mli \
unix_utils.mli
SOURCES_ML = \
c_utils.ml \
unix_utils.ml
SOURCES_C = \
c_utils-c.c \
unix_utils-c.c
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 = libmlcutils.a
if !HAVE_OCAMLOPT
MLCUTILS_CMA = mlcutils.cma
else
MLCUTILS_CMA = mlcutils.cmxa
endif
noinst_DATA = $(MLCUTILS_CMA)
# lib/guestfs-internal-all.h header is used here. It probably
# shouldn't be located under lib. XXX
libmlcutils_a_SOURCES = $(SOURCES_C)
libmlcutils_a_CPPFLAGS = \
-I. \
-I$(top_builddir) \
-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/lib -I$(top_builddir)/lib \
-I$(shell $(OCAMLC) -where)
libmlcutils_a_CFLAGS = \
$(WARN_CFLAGS) $(WERROR_CFLAGS) \
-fPIC
BOBJECTS = $(SOURCES_ML:.ml=.cmo)
XOBJECTS = $(BOBJECTS:.cmo=.cmx)
OCAMLPACKAGES = \
-package str,unix \
-I $(top_builddir)/gnulib/lib/.libs \
-I $(top_builddir)/common/utils/.libs \
-I $(top_builddir)/common/mlstdutils \
-I $(builddir)
OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR)
if !HAVE_OCAMLOPT
OBJECTS = $(BOBJECTS)
else
OBJECTS = $(XOBJECTS)
endif
libmlcutils_a_DEPENDENCIES = $(OBJECTS)
$(MLCUTILS_CMA): $(OBJECTS) libmlcutils.a
$(OCAMLFIND) mklib $(OCAMLPACKAGES) \
$(OBJECTS) $(libmlcutils_a_OBJECTS) \
-cclib -lutils \
-o mlcutils
# Tests.
TESTS =
check_PROGRAMS =
if HAVE_OCAML_PKG_OUNIT
TESTS += c_utils_unit_tests
check_PROGRAMS += c_utils_unit_tests
endif
c_utils_unit_tests_BOBJECTS = \
c_utils_unit_tests.cmo
c_utils_unit_tests_XOBJECTS = $(c_utils_unit_tests_BOBJECTS:.cmo=.cmx)
c_utils_unit_tests_SOURCES = dummy.c
c_utils_unit_tests_CPPFLAGS = $(libmlcutils_a_CPPFLAGS)
c_utils_unit_tests_CFLAGS = $(libmlcutils_a_CFLAGS)
if !HAVE_OCAMLOPT
# Can't call this c_utils_unit_tests_OBJECTS because automake gets confused.
c_utils_unit_tests_THEOBJECTS = $(c_utils_unit_tests_BOBJECTS)
c_utils_unit_tests.cmo: OCAMLPACKAGES += -package oUnit
else
c_utils_unit_tests_THEOBJECTS = $(c_utils_unit_tests_XOBJECTS)
c_utils_unit_tests.cmx: OCAMLPACKAGES += -package oUnit
endif
OCAMLLINKFLAGS = \
mlstdutils.$(MLARCHIVE) \
mlcutils.$(MLARCHIVE) \
$(LINK_CUSTOM_OCAMLC_ONLY)
c_utils_unit_tests_DEPENDENCIES = \
$(c_utils_unit_tests_THEOBJECTS) \
../mlstdutils/mlstdutils.$(MLARCHIVE) \
mlcutils.$(MLARCHIVE) \
$(top_srcdir)/ocaml-link.sh
c_utils_unit_tests_LINK = \
$(top_srcdir)/ocaml-link.sh -cclib '-lutils -lgnu' -- \
$(OCAMLFIND) $(BEST) $(OCAMLFLAGS) \
$(OCAMLPACKAGES) -package oUnit \
$(OCAMLLINKFLAGS) \
$(c_utils_unit_tests_THEOBJECTS) -o $@
# Dependencies.
depend: .depend
.depend: $(wildcard $(abs_srcdir)/*.mli) $(wildcard $(abs_srcdir)/*.ml)
rm -f $@ $@-t
$(OCAMLFIND) ocamldep -I $(abs_srcdir) $^ | \
$(SED) 's/ *$$//' | \
$(SED) -e :a -e '/ *\\$$/N; s/ *\\\n */ /; ta' | \
$(SED) -e 's,$(abs_srcdir)/,$(builddir)/,g' | \
sort > $@-t
mv $@-t $@
-include .depend
endif
.PHONY: depend docs

View File

@@ -41,7 +41,7 @@ extern void unix_error (int errcode, char * cmdname, value arg) Noreturn;
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
value
v2v_utils_drive_name (value indexv)
guestfs_int_mlutils_drive_name (value indexv)
{
CAMLparam1 (indexv);
CAMLlocal1 (namev);
@@ -54,7 +54,7 @@ v2v_utils_drive_name (value indexv)
}
value
v2v_utils_drive_index (value strv)
guestfs_int_mlutils_drive_index (value strv)
{
CAMLparam1 (strv);
ssize_t r;
@@ -67,7 +67,7 @@ v2v_utils_drive_index (value strv)
}
value
v2v_utils_shell_unquote (value strv)
guestfs_int_mlutils_shell_unquote (value strv)
{
CAMLparam1 (strv);
CAMLlocal1 (retv);

26
common/mlutils/c_utils.ml Normal file
View File

@@ -0,0 +1,26 @@
(* virt-v2v
* Copyright (C) 2009-2017 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.
*)
(* OCaml bindings for C utility functions in [common/utils]. *)
open Printf
external drive_name : int -> string = "guestfs_int_mlutils_drive_name"
external drive_index : string -> int = "guestfs_int_mlutils_drive_index"
external shell_unquote : string -> string = "guestfs_int_mlutils_shell_unquote"

View File

@@ -0,0 +1,30 @@
(* virt-v2v
* Copyright (C) 2009-2017 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.
*)
(** OCaml bindings for C utility functions in [common/utils]. *)
val drive_name : int -> string
val drive_index : string -> int
val shell_unquote : string -> string
(** If the string looks like a shell quoted string, then attempt to
unquote it.
This is just intended to deal with quoting in configuration files
(like ones under /etc/sysconfig), and it doesn't deal with some
situations such as $variable interpolation. *)

View File

@@ -0,0 +1,81 @@
(* virt-v2v
* Copyright (C) 2011-2017 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.
*)
(* This file tests individual OCaml bindings for C utility functions. *)
open Printf
open OUnit2
open Std_utils
open C_utils
let test_drive_name ctx =
let printer = identity in
assert_equal ~printer "a" (drive_name 0);
assert_equal ~printer "z" (drive_name 25);
assert_equal ~printer "aa" (drive_name 26);
assert_equal ~printer "ab" (drive_name 27);
assert_equal ~printer "az" (drive_name 51);
assert_equal ~printer "ba" (drive_name 52);
assert_equal ~printer "zz" (drive_name 701);
assert_equal ~printer "aaa" (drive_name 702);
assert_equal ~printer "zzz" (drive_name 18277)
let test_drive_index ctx =
let printer = string_of_int in
assert_equal ~printer 0 (drive_index "a");
assert_equal ~printer 25 (drive_index "z");
assert_equal ~printer 26 (drive_index "aa");
assert_equal ~printer 27 (drive_index "ab");
assert_equal ~printer 51 (drive_index "az");
assert_equal ~printer 52 (drive_index "ba");
assert_equal ~printer 701 (drive_index "zz");
assert_equal ~printer 702 (drive_index "aaa");
assert_equal ~printer 18277 (drive_index "zzz");
let exn = Invalid_argument "drive_index: invalid parameter" in
assert_raises exn (fun () -> drive_index "");
assert_raises exn (fun () -> drive_index "abc123");
assert_raises exn (fun () -> drive_index "123");
assert_raises exn (fun () -> drive_index "Z");
assert_raises exn (fun () -> drive_index "aB")
let test_shell_unquote ctx =
let printer = identity in
assert_equal ~printer "a" (shell_unquote "a");
assert_equal ~printer "b" (shell_unquote "'b'");
assert_equal ~printer "c" (shell_unquote "\"c\"");
assert_equal ~printer "dd" (shell_unquote "\"dd\"");
assert_equal ~printer "e\\e" (shell_unquote "\"e\\\\e\"");
assert_equal ~printer "f\\" (shell_unquote "\"f\\\\\"");
assert_equal ~printer "\\g" (shell_unquote "\"\\\\g\"");
assert_equal ~printer "h\\-h" (shell_unquote "\"h\\-h\"");
assert_equal ~printer "i`" (shell_unquote "\"i\\`\"");
assert_equal ~printer "j\"" (shell_unquote "\"j\\\"\"")
(* Suites declaration. *)
let suite =
"C_utils" >:::
[
"C_utils.drive_name" >:: test_drive_name;
"C_utils.drive_index" >:: test_drive_index;
"C_utils.shell_unquote" >:: test_shell_unquote;
]
let () =
run_test_tt_main suite

2
common/mlutils/dummy.c Normal file
View File

@@ -0,0 +1,2 @@
/* Dummy source, to be used for OCaml-based tools with no C sources. */
enum { foo = 1 };

View File

@@ -199,6 +199,7 @@ AC_CONFIG_FILES([Makefile
common/mlprogress/Makefile
common/mlstdutils/Makefile
common/mlstdutils/guestfs_config.ml
common/mlutils/Makefile
common/mlvisit/Makefile
common/mlxml/Makefile
common/options/Makefile

View File

@@ -124,6 +124,7 @@ OCAMLPACKAGES = \
-I $(top_builddir)/gnulib/lib/.libs \
-I $(top_builddir)/ocaml \
-I $(top_builddir)/common/mlstdutils \
-I $(top_builddir)/common/mlutils \
-I $(top_builddir)/mllib \
-I $(builddir)
if HAVE_OCAML_PKG_GETTEXT
@@ -153,6 +154,7 @@ endif
OCAMLLINKFLAGS = \
mlstdutils.$(MLARCHIVE) \
mlguestfs.$(MLARCHIVE) \
mlcutils.$(MLARCHIVE) \
mllib.$(MLARCHIVE) \
customize.$(MLARCHIVE) \
$(LINK_CUSTOM_OCAMLC_ONLY)
@@ -172,6 +174,7 @@ virt_customize_DEPENDENCIES = \
$(top_srcdir)/ocaml-link.sh \
$(CUSTOMIZE_THEOBJECTS) \
$(CUSTOMIZE_CMA) \
../common/mlutils/mlcutils.$(MLARCHIVE) \
../mllib/mllib.$(MLARCHIVE)
virt_customize_LINK = \
$(top_srcdir)/ocaml-link.sh -cclib '$(OCAMLCLIBS)' -- \
@@ -304,7 +307,7 @@ depend: .depend
.depend: $(wildcard $(abs_srcdir)/*.mli) $(wildcard $(abs_srcdir)/*.ml)
rm -f $@ $@-t
$(OCAMLFIND) ocamldep -I ../ocaml -I $(abs_srcdir) -I $(abs_top_builddir)/mllib $^ | \
$(OCAMLFIND) ocamldep -I ../ocaml -I $(abs_srcdir) -I $(abs_top_builddir)/common/mlutils -I $(abs_top_builddir)/mllib $^ | \
$(SED) 's/ *$$//' | \
$(SED) -e :a -e '/ *\\$$/N; s/ *\\\n */ /; ta' | \
$(SED) -e 's,$(abs_srcdir)/,$(builddir)/,g' | \

View File

@@ -80,6 +80,7 @@ OCAMLPACKAGES = \
-I $(top_builddir)/gnulib/lib/.libs \
-I $(top_builddir)/ocaml \
-I $(top_builddir)/common/mlstdutils \
-I $(top_builddir)/common/mlutils \
-I $(top_builddir)/mllib
if HAVE_OCAML_PKG_GETTEXT
OCAMLPACKAGES += -package gettext-stub
@@ -103,12 +104,14 @@ endif
OCAMLLINKFLAGS = \
mlstdutils.$(MLARCHIVE) \
mlguestfs.$(MLARCHIVE) \
mlcutils.$(MLARCHIVE) \
mllib.$(MLARCHIVE) \
$(LINK_CUSTOM_OCAMLC_ONLY)
virt_dib_DEPENDENCIES = \
$(OBJECTS) \
../common/mlstdutils/mlstdutils.$(MLARCHIVE) \
../common/mlutils/mlcutils.$(MLARCHIVE) \
../mllib/mllib.$(MLARCHIVE) \
$(top_srcdir)/ocaml-link.sh
virt_dib_LINK = \
@@ -144,7 +147,7 @@ depend: .depend
.depend: $(wildcard $(abs_srcdir)/*.mli) $(wildcard $(abs_srcdir)/*.ml)
rm -f $@ $@-t
$(OCAMLFIND) ocamldep -I ../ocaml -I $(abs_srcdir) -I $(abs_top_builddir)/common/mlstdutils -I $(abs_top_builddir)/mllib $^ | \
$(OCAMLFIND) ocamldep -I ../ocaml -I $(abs_srcdir) -I $(abs_top_builddir)/common/mlstdutils -I $(abs_top_builddir)/common/mlutils -I $(abs_top_builddir)/mllib $^ | \
$(SED) 's/ *$$//' | \
$(SED) -e :a -e '/ *\\$$/N; s/ *\\\n */ /; ta' | \
$(SED) -e 's,$(abs_srcdir)/,$(builddir)/,g' | \

View File

@@ -17,6 +17,9 @@ common/miniexpect/miniexpect.c
common/miniexpect/miniexpect.h
common/mlprogress/progress-c.c
common/mlstdutils/dummy.c
common/mlutils/c_utils-c.c
common/mlutils/dummy.c
common/mlutils/unix_utils-c.c
common/mlvisit/dummy.c
common/mlvisit/visit-c.c
common/mlxml/xml-c.c
@@ -344,7 +347,6 @@ make-fs/make-fs.c
mllib/common_utils-c.c
mllib/dummy.c
mllib/getopt-c.c
mllib/unix_utils-c.c
mllib/uri-c.c
ocaml/guestfs-c-actions.c
ocaml/guestfs-c-errnos.c
@@ -410,4 +412,3 @@ utils/qemu-speed-test/qemu-speed-test.c
v2v/libvirt_utils-c.c
v2v/qemuopts-c.c
v2v/test-harness/dummy.c
v2v/utils-c.c

View File

@@ -108,6 +108,11 @@ A library of pure OCaml utility functions used in many places.
OCaml bindings for the progress bar functions (see F<common/progress>).
=item F<common/mlutils>
OCaml bindings for C functions in C<common/utils>, and some POSIX
bindings which are missing from the OCaml stdlib.
=item F<common/mlvisit>
OCaml bindings for the visit functions (see F<common/visit>).

View File

@@ -64,6 +64,7 @@ OCAMLPACKAGES = \
-I $(top_builddir)/gnulib/lib/.libs \
-I $(top_builddir)/ocaml \
-I $(top_builddir)/common/mlstdutils \
-I $(top_builddir)/common/mlutils \
-I $(top_builddir)/mllib
if HAVE_OCAML_PKG_GETTEXT
OCAMLPACKAGES += -package gettext-stub
@@ -87,12 +88,14 @@ endif
OCAMLLINKFLAGS = \
mlstdutils.$(MLARCHIVE) \
mlguestfs.$(MLARCHIVE) \
mlcutils.$(MLARCHIVE) \
mllib.$(MLARCHIVE) \
$(LINK_CUSTOM_OCAMLC_ONLY)
virt_get_kernel_DEPENDENCIES = \
$(OBJECTS) \
../common/mlstdutils/mlstdutils.$(MLARCHIVE) \
../common/mlutils/mlcutils.$(MLARCHIVE) \
../mllib/mllib.$(MLARCHIVE) \
$(top_srcdir)/ocaml-link.sh
virt_get_kernel_LINK = \
@@ -127,7 +130,7 @@ depend: .depend
.depend: $(wildcard $(abs_srcdir)/*.mli) $(wildcard $(abs_srcdir)/*.ml)
rm -f $@ $@-t
$(OCAMLFIND) ocamldep -I ../ocaml -I $(abs_srcdir) -I $(abs_top_builddir)/common/mlstdutils -I $(abs_top_builddir)/mllib $^ | \
$(OCAMLFIND) ocamldep -I ../ocaml -I $(abs_srcdir) -I $(abs_top_builddir)/common/mlstdutils -I $(abs_top_builddir)/common/mlutils -I $(abs_top_builddir)/mllib $^ | \
$(SED) 's/ *$$//' | \
$(SED) -e :a -e '/ *\\$$/N; s/ *\\\n */ /; ta' | \
$(SED) -e 's,$(abs_srcdir)/,$(builddir)/,g' | \

View File

@@ -28,7 +28,6 @@ EXTRA_DIST = \
SOURCES_MLI = \
checksums.mli \
unix_utils.mli \
common_utils.mli \
curl.mli \
getopt.mli \
@@ -43,7 +42,6 @@ SOURCES_ML = \
$(OCAML_BYTES_COMPAT_ML) \
common_gettext.ml \
getopt.ml \
unix_utils.ml \
common_utils.ml \
URI.ml \
planner.ml \
@@ -60,7 +58,6 @@ SOURCES_C = \
../common/options/uri.c \
common_utils-c.c \
getopt-c.c \
unix_utils-c.c \
uri-c.c
if HAVE_OCAML
@@ -90,7 +87,8 @@ libmllib_a_CPPFLAGS = \
-I$(top_srcdir)/lib \
-I$(top_srcdir)/common/options \
-I$(top_srcdir)/common/mlxml \
-I$(top_srcdir)/common/mlstdutils
-I$(top_srcdir)/common/mlstdutils \
-I$(top_srcdir)/common/mlutils
libmllib_a_CFLAGS = \
$(WARN_CFLAGS) $(WERROR_CFLAGS) \
$(LIBVIRT_CFLAGS) $(LIBXML2_CFLAGS) \
@@ -110,6 +108,7 @@ OCAMLPACKAGES = \
-I $(top_builddir)/ocaml \
-I $(top_builddir)/common/mlxml \
-I $(top_builddir)/common/mlstdutils \
-I $(top_builddir)/common/mlutils \
-I $(builddir)
OCAMLPACKAGES_TESTS = $(MLLIB_CMA)
if HAVE_OCAML_PKG_GETTEXT
@@ -189,6 +188,7 @@ endif
OCAMLLINKFLAGS = \
mlstdutils.$(MLARCHIVE) \
mlcutils.$(MLARCHIVE) \
mlguestfs.$(MLARCHIVE) \
$(LINK_CUSTOM_OCAMLC_ONLY)

View File

@@ -63,6 +63,7 @@ OCAMLPACKAGES = \
-I $(top_builddir)/ocaml \
-I $(top_builddir)/common/mlstdutils \
-I $(top_builddir)/common/mlprogress \
-I $(top_builddir)/common/mlutils \
-I $(top_builddir)/mllib
if HAVE_OCAML_PKG_GETTEXT
OCAMLPACKAGES += -package gettext-stub
@@ -88,12 +89,14 @@ OCAMLLINKFLAGS = \
mlstdutils.$(MLARCHIVE) \
mlguestfs.$(MLARCHIVE) \
mlprogress.$(MLARCHIVE) \
mlcutils.$(MLARCHIVE) \
mllib.$(MLARCHIVE) \
$(LINK_CUSTOM_OCAMLC_ONLY)
virt_resize_DEPENDENCIES = \
$(OBJECTS) \
../common/mlstdutils/mlstdutils.$(MLARCHIVE) \
../common/mlutils/mlcutils.$(MLARCHIVE) \
../mllib/mllib.$(MLARCHIVE) \
$(top_srcdir)/ocaml-link.sh
virt_resize_LINK = \
@@ -138,7 +141,7 @@ depend: .depend
.depend: $(wildcard $(abs_srcdir)/*.mli) $(wildcard $(abs_srcdir)/*.ml)
rm -f $@ $@-t
$(OCAMLFIND) ocamldep -I ../ocaml -I $(abs_srcdir) -I $(abs_top_builddir)/mlstdutils -I $(abs_top_builddir)/mllib $^ | \
$(OCAMLFIND) ocamldep -I ../ocaml -I $(abs_srcdir) -I $(abs_top_builddir)/common/mlstdutils -I $(abs_top_builddir)/common/mlutils -I $(abs_top_builddir)/mllib $^ | \
$(SED) 's/ *$$//' | \
$(SED) -e :a -e '/ *\\$$/N; s/ *\\\n */ /; ta' | \
$(SED) -e 's,$(abs_srcdir)/,$(builddir)/,g' | \

View File

@@ -68,6 +68,7 @@ OCAMLPACKAGES = \
-I $(top_builddir)/ocaml \
-I $(top_builddir)/common/mlstdutils \
-I $(top_builddir)/common/mlprogress \
-I $(top_builddir)/common/mlutils \
-I $(top_builddir)/mllib
if HAVE_OCAML_PKG_GETTEXT
OCAMLPACKAGES += -package gettext-stub
@@ -93,12 +94,14 @@ OCAMLLINKFLAGS = \
mlstdutils.$(MLARCHIVE) \
mlguestfs.$(MLARCHIVE) \
mlprogress.$(MLARCHIVE) \
mlcutils.$(MLARCHIVE) \
mllib.$(MLARCHIVE) \
$(LINK_CUSTOM_OCAMLC_ONLY)
virt_sparsify_DEPENDENCIES = \
$(OBJECTS) \
../common/mlstdutils/mlstdutils.$(MLARCHIVE) \
../common/mlutils/mlcutils.$(MLARCHIVE) \
../mllib/mllib.$(MLARCHIVE) \
$(top_srcdir)/ocaml-link.sh
virt_sparsify_LINK = \
@@ -145,7 +148,7 @@ depend: .depend
.depend: $(wildcard $(abs_srcdir)/*.mli) $(wildcard $(abs_srcdir)/*.ml)
rm -f $@ $@-t
$(OCAMLFIND) ocamldep -I ../ocaml -I $(abs_srcdir) -I $(abs_top_builddir)/common/mlstdutils -I $(abs_top_builddir)/mllib $^ | \
$(OCAMLFIND) ocamldep -I ../ocaml -I $(abs_srcdir) -I $(abs_top_builddir)/common/mlstdutils -I $(abs_top_builddir)/common/mlutils -I $(abs_top_builddir)/mllib $^ | \
$(SED) 's/ *$$//' | \
$(SED) -e :a -e '/ *\\$$/N; s/ *\\\n */ /; ta' | \
$(SED) -e 's,$(abs_srcdir)/,$(builddir)/,g' | \

View File

@@ -114,6 +114,7 @@ OCAMLPACKAGES = \
-I $(top_builddir)/ocaml \
-I $(top_builddir)/common/visit/.libs \
-I $(top_builddir)/common/mlstdutils \
-I $(top_builddir)/common/mlutils \
-I $(top_builddir)/common/mlvisit \
-I $(top_builddir)/mllib \
-I $(top_builddir)/customize
@@ -142,6 +143,7 @@ endif
OCAMLLINKFLAGS = \
mlstdutils.$(MLARCHIVE) \
mlguestfs.$(MLARCHIVE) \
mlcutils.$(MLARCHIVE) \
mllib.$(MLARCHIVE) \
mlvisit.$(MLARCHIVE) \
customize.$(MLARCHIVE) \
@@ -150,6 +152,7 @@ OCAMLLINKFLAGS = \
virt_sysprep_DEPENDENCIES = \
$(OBJECTS) \
../common/mlstdutils/mlstdutils.$(MLARCHIVE) \
../common/mlutils/mlcutils.$(MLARCHIVE) \
../mllib/mllib.$(MLARCHIVE) \
../customize/customize.$(MLARCHIVE) \
$(top_srcdir)/ocaml-link.sh
@@ -218,7 +221,7 @@ depend: .depend
.depend: $(wildcard $(abs_srcdir)/*.mli) $(wildcard $(abs_srcdir)/*.ml)
rm -f $@ $@-t
$(OCAMLFIND) ocamldep -I ../ocaml -I $(abs_srcdir) -I $(abs_top_builddir)/mlstdutils -I $(abs_top_builddir)/mllib -I $(abs_top_builddir)/customize $^ | \
$(OCAMLFIND) ocamldep -I ../ocaml -I $(abs_srcdir) -I $(abs_top_builddir)/common/mlstdutils -I $(abs_top_builddir)/common/mlutils -I $(abs_top_builddir)/mllib -I $(abs_top_builddir)/customize $^ | \
$(SED) 's/ *$$//' | \
$(SED) -e :a -e '/ *\\$$/N; s/ *\\\n */ /; ta' | \
$(SED) -e 's,$(abs_srcdir)/,$(builddir)/,g' | \

View File

@@ -111,8 +111,7 @@ SOURCES_ML = \
SOURCES_C = \
libvirt_utils-c.c \
qemuopts-c.c \
utils-c.c
qemuopts-c.c
if HAVE_OCAML
@@ -147,6 +146,7 @@ OCAMLPACKAGES = \
-I $(top_builddir)/gnulib/lib/.libs \
-I $(top_builddir)/ocaml \
-I $(top_builddir)/common/mlstdutils \
-I $(top_builddir)/common/mlutils \
-I $(top_builddir)/common/mlxml \
-I $(top_builddir)/mllib \
-I $(top_builddir)/customize
@@ -174,6 +174,7 @@ OCAMLLINKFLAGS = \
mlstdutils.$(MLARCHIVE) \
mlguestfs.$(MLARCHIVE) \
mlxml.$(MLARCHIVE) \
mlcutils.$(MLARCHIVE) \
mllib.$(MLARCHIVE) \
$(LINK_CUSTOM_OCAMLC_ONLY)
@@ -184,8 +185,7 @@ virt_v2v_LINK = \
$(OBJECTS) -o $@
virt_v2v_copy_to_local_SOURCES = \
libvirt_utils-c.c \
utils-c.c
libvirt_utils-c.c
virt_v2v_copy_to_local_CPPFLAGS = \
-I. \
-I$(top_builddir) \
@@ -214,6 +214,7 @@ virt_v2v_copy_to_local_DEPENDENCIES = \
$(COPY_TO_LOCAL_OBJECTS) \
../common/mlstdutils/mlstdutils.$(MLARCHIVE) \
../common/mlxml/mlxml.$(MLARCHIVE) \
../common/mlutils/mlcutils.$(MLARCHIVE) \
../mllib/mllib.$(MLARCHIVE) \
$(top_srcdir)/ocaml-link.sh
virt_v2v_copy_to_local_LINK = \
@@ -500,6 +501,7 @@ v2v_unit_tests_DEPENDENCIES = \
$(v2v_unit_tests_THEOBJECTS) \
../common/mlstdutils/mlstdutils.$(MLARCHIVE) \
../common/mlxml/mlxml.$(MLARCHIVE) \
../common/mlutils/mlcutils.$(MLARCHIVE) \
../mllib/mllib.$(MLARCHIVE) \
$(top_srcdir)/ocaml-link.sh
v2v_unit_tests_LINK = \
@@ -514,7 +516,7 @@ depend: .depend
.depend: $(wildcard $(abs_srcdir)/*.mli) $(wildcard $(abs_srcdir)/*.ml)
rm -f $@ $@-t
$(OCAMLFIND) ocamldep -I ../ocaml -I $(abs_srcdir) -I $(abs_top_builddir)/common/mlstdutils -I $(abs_top_builddir)/common/mlxml -I $(abs_top_builddir)/mllib -I $(abs_top_builddir)/customize $^ | \
$(OCAMLFIND) ocamldep -I ../ocaml -I $(abs_srcdir) -I $(abs_top_builddir)/common/mlstdutils -I $(abs_top_builddir)/common/mlutils -I $(abs_top_builddir)/common/mlxml -I $(abs_top_builddir)/mllib -I $(abs_top_builddir)/customize $^ | \
$(SED) 's/ *$$//' | \
$(SED) -e :a -e '/ *\\$$/N; s/ *\\\n */ /; ta' | \
$(SED) -e 's,$(abs_srcdir)/,$(builddir)/,g' | \

View File

@@ -28,6 +28,7 @@
open Printf
open C_utils
open Std_utils
open Common_utils
open Common_gettext.Gettext
@@ -186,7 +187,7 @@ let rec convert (g : G.guestfs) inspect source output rcaps =
fun line ->
if Str.string_match rex line 0 then (
let path = Str.matched_group 1 line in
let path = Utils.shell_unquote path in
let path = shell_unquote path in
if String.length path >= 1 && path.[0] = '/' then (
let vboxuninstall = path ^ "/uninstall.sh" in
Some vboxuninstall

View File

@@ -19,6 +19,7 @@
open Printf
open Std_utils
open C_utils
open Common_utils
open Common_gettext.Gettext

View File

@@ -18,6 +18,7 @@
open Printf
open C_utils
open Std_utils
open Common_utils
open Common_gettext.Gettext
@@ -40,7 +41,7 @@ and parsed_source =
*)
let get_drive_slot str offset =
let name = String.sub str offset (String.length str - offset) in
try Some (Utils.drive_index name)
try Some (drive_index name)
with Invalid_argument _ ->
warning (f_"could not parse device name %s from the source libvirt XML") str;
None

View File

@@ -24,11 +24,6 @@ open Std_utils
open Common_utils
open Common_gettext.Gettext
external drive_name : int -> string = "v2v_utils_drive_name"
external drive_index : string -> int = "v2v_utils_drive_index"
external shell_unquote : string -> string = "v2v_utils_shell_unquote"
(* URI quoting. *)
let uri_quote str =
let len = String.length str in

View File

@@ -18,17 +18,6 @@
(** Utilities used in virt-v2v only. *)
val drive_name : int -> string
val drive_index : string -> int
val shell_unquote : string -> string
(** If the string looks like a shell quoted string, then attempt to
unquote it.
This is just intended to deal with quoting in configuration files
(like ones under /etc/sysconfig), and it doesn't deal with some
situations such as $variable interpolation. *)
val uri_quote : string -> string
(** Take a string and perform %xx escaping as used in some parts of URLs. *)

View File

@@ -19,6 +19,7 @@
open Unix
open Printf
open C_utils
open Std_utils
open Common_utils
open Unix_utils

View File

@@ -110,36 +110,6 @@ let test_get_ostype ctx =
i_product_variant = "Server";
i_arch = "x86_64" })
let test_drive_name ctx =
let printer = identity in
assert_equal ~printer "a" (Utils.drive_name 0);
assert_equal ~printer "z" (Utils.drive_name 25);
assert_equal ~printer "aa" (Utils.drive_name 26);
assert_equal ~printer "ab" (Utils.drive_name 27);
assert_equal ~printer "az" (Utils.drive_name 51);
assert_equal ~printer "ba" (Utils.drive_name 52);
assert_equal ~printer "zz" (Utils.drive_name 701);
assert_equal ~printer "aaa" (Utils.drive_name 702);
assert_equal ~printer "zzz" (Utils.drive_name 18277)
let test_drive_index ctx =
let printer = string_of_int in
assert_equal ~printer 0 (Utils.drive_index "a");
assert_equal ~printer 25 (Utils.drive_index "z");
assert_equal ~printer 26 (Utils.drive_index "aa");
assert_equal ~printer 27 (Utils.drive_index "ab");
assert_equal ~printer 51 (Utils.drive_index "az");
assert_equal ~printer 52 (Utils.drive_index "ba");
assert_equal ~printer 701 (Utils.drive_index "zz");
assert_equal ~printer 702 (Utils.drive_index "aaa");
assert_equal ~printer 18277 (Utils.drive_index "zzz");
let exn = Invalid_argument "drive_index: invalid parameter" in
assert_raises exn (fun () -> Utils.drive_index "");
assert_raises exn (fun () -> Utils.drive_index "abc123");
assert_raises exn (fun () -> Utils.drive_index "123");
assert_raises exn (fun () -> Utils.drive_index "Z");
assert_raises exn (fun () -> Utils.drive_index "aB")
let test_virtio_iso_path_matches_guest_os ctx =
(* Windows OSes fake inspection data. *)
let make_win name major minor variant arch = {
@@ -779,19 +749,6 @@ let test_virtio_iso_path_matches_guest_os ctx =
) all_windows
) paths
let test_shell_unquote ctx =
let printer = identity in
assert_equal ~printer "a" (Utils.shell_unquote "a");
assert_equal ~printer "b" (Utils.shell_unquote "'b'");
assert_equal ~printer "c" (Utils.shell_unquote "\"c\"");
assert_equal ~printer "dd" (Utils.shell_unquote "\"dd\"");
assert_equal ~printer "e\\e" (Utils.shell_unquote "\"e\\\\e\"");
assert_equal ~printer "f\\" (Utils.shell_unquote "\"f\\\\\"");
assert_equal ~printer "\\g" (Utils.shell_unquote "\"\\\\g\"");
assert_equal ~printer "h\\-h" (Utils.shell_unquote "\"h\\-h\"");
assert_equal ~printer "i`" (Utils.shell_unquote "\"i\\`\"");
assert_equal ~printer "j\"" (Utils.shell_unquote "\"j\\\"\"")
let test_qemu_img_supports ctx =
(* No assertion here, we don't know if qemu-img supports the
* feature, so just run the code and make sure it doesn't crash.
@@ -945,11 +902,8 @@ let suite =
"virt-v2v" >:::
[
"Create_ovf.get_ostype" >:: test_get_ostype;
"Utils.drive_name" >:: test_drive_name;
"Utils.drive_index" >:: test_drive_index;
"Windows_virtio.virtio_iso_path_matches_guest_os" >::
test_virtio_iso_path_matches_guest_os;
"Utils.shell_unquote" >:: test_shell_unquote;
"Utils.qemu_img_supports" >:: test_qemu_img_supports;
"Parse_vmx.parse_string" >::test_vmx_parse_string;
]