lib: introduce GUESTFS_NO_DEPRECATED

Add a simple way to do not even provide prototypes of deprecated
functions in the C library: this way, users (like our tools) can build
against the library making sure to not use any deprecated function, not
even when compiler deprecation warnings are disabled.

Add it to the majority of our tools/internal libraries, and make sure
that it is not defined when building the API bridges of our bindings.
This commit is contained in:
Pino Toscano
2019-04-23 12:58:05 +02:00
parent 9d1fc91cca
commit d8d8c856a1
37 changed files with 62 additions and 1 deletions

View File

@@ -29,6 +29,7 @@ virt_alignment_scan_SOURCES = \
scan.c
virt_alignment_scan_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
-I$(top_srcdir)/lib -I$(top_builddir)/lib \

View File

@@ -36,6 +36,7 @@ virt_cat_SOURCES = \
cat.c
virt_cat_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
@@ -63,6 +64,7 @@ virt_filesystems_SOURCES = \
filesystems.c
virt_filesystems_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
@@ -90,6 +92,7 @@ virt_log_SOURCES = \
log.c
virt_log_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
@@ -116,6 +119,7 @@ virt_ls_SOURCES = \
ls.c
virt_ls_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
@@ -144,6 +148,7 @@ virt_tail_SOURCES = \
tail.c
virt_tail_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \

View File

@@ -25,6 +25,7 @@ libedit_la_SOURCES = \
file-edit.c \
file-edit.h
libedit_la_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/lib -I$(top_builddir)/lib
libedit_la_CFLAGS = \

View File

@@ -34,6 +34,7 @@ liboptions_la_SOURCES = \
uri.h \
uri.c
liboptions_la_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/lib -I$(top_builddir)/lib \
-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib

View File

@@ -30,6 +30,7 @@ libparallel_la_SOURCES = \
parallel.c \
parallel.h
libparallel_la_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/lib -I$(top_builddir)/lib \
-I$(top_srcdir)/common/options -I$(top_builddir)/common/options \

View File

@@ -25,6 +25,7 @@ libprogress_la_SOURCES = \
progress.c \
progress.h
libprogress_la_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/lib -I$(top_builddir)/lib
libprogress_la_CFLAGS = \

View File

@@ -35,6 +35,7 @@ libstructs_la_SOURCES = \
../../lib/guestfs.h \
$(BUILT_SOURCES)
libstructs_la_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-DGUESTFS_PRIVATE=1 \
-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
-I$(top_srcdir)/lib -I$(top_builddir)/lib

View File

@@ -29,6 +29,7 @@ libutils_la_SOURCES = \
libxml2-writer-macros.h \
utils.c
libutils_la_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-DGUESTFS_PRIVATE=1 \
-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
-I$(top_srcdir)/lib -I$(top_builddir)/lib

View File

@@ -23,6 +23,7 @@ libvisit_la_SOURCES = \
visit.c \
visit.h
libvisit_la_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-DGUESTFS_PRIVATE=1 \
-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
-I$(top_srcdir)/lib -I$(top_builddir)/lib \

View File

@@ -25,6 +25,7 @@ libwindows_la_SOURCES = \
windows.c \
windows.h
libwindows_la_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/lib -I$(top_builddir)/lib \
-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib

View File

@@ -33,6 +33,7 @@ virt_df_SOURCES = \
output.c
virt_df_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \

View File

@@ -28,6 +28,7 @@ virt_diff_SOURCES = \
diff.c
virt_diff_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/lib -I$(top_builddir)/lib \

View File

@@ -28,6 +28,7 @@ virt_edit_SOURCES = \
edit.c
virt_edit_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/lib -I$(top_builddir)/lib \

View File

@@ -43,6 +43,7 @@ endif
if HAVE_LIBVIRT
copy_over_SOURCES = copy-over.c
copy_over_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-I$(top_srcdir)/lib -I$(top_builddir)/lib
copy_over_CFLAGS = \
$(LIBVIRT_CFLAGS) \
@@ -54,6 +55,7 @@ copy_over_LDADD = \
libvirt_auth_SOURCES = libvirt-auth.c
libvirt_auth_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-I$(top_srcdir)/lib -I$(top_builddir)/lib
libvirt_auth_CFLAGS = \
$(LIBVIRT_CFLAGS) \
@@ -66,6 +68,7 @@ endif
create_disk_SOURCES = create-disk.c
create_disk_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-I$(top_srcdir)/lib -I$(top_builddir)/lib
create_disk_CFLAGS = \
$(WARN_CFLAGS) $(WERROR_CFLAGS)
@@ -74,6 +77,7 @@ create_disk_LDADD = \
debug_logging_SOURCES = debug-logging.c
debug_logging_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-I$(top_srcdir)/lib -I$(top_builddir)/lib
debug_logging_CFLAGS = \
$(WARN_CFLAGS) $(WERROR_CFLAGS)
@@ -82,6 +86,7 @@ debug_logging_LDADD = \
display_icon_SOURCES = display-icon.c
display_icon_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-I$(top_srcdir)/lib -I$(top_builddir)/lib
display_icon_CFLAGS = \
$(WARN_CFLAGS) $(WERROR_CFLAGS)
@@ -90,6 +95,7 @@ display_icon_LDADD = \
inspect_vm_SOURCES = inspect-vm.c
inspect_vm_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-I$(top_srcdir)/lib -I$(top_builddir)/lib
inspect_vm_CFLAGS = \
$(WARN_CFLAGS) $(WERROR_CFLAGS)
@@ -99,6 +105,7 @@ inspect_vm_LDADD = \
if HAVE_FUSE
mount_local_SOURCES = mount-local.c
mount_local_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-I$(top_srcdir)/lib -I$(top_builddir)/lib
mount_local_CFLAGS = \
-I$(top_srcdir)/lib -I$(top_builddir)/lib \
@@ -112,6 +119,7 @@ endif
if HAVE_HIVEX
virt_dhcp_address_SOURCES = virt-dhcp-address.c
virt_dhcp_address_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-I$(top_srcdir)/lib -I$(top_builddir)/lib
virt_dhcp_address_CFLAGS = \
$(WARN_CFLAGS) $(WERROR_CFLAGS)

View File

@@ -123,6 +123,7 @@ cmds-gperf.c: cmds-gperf.gperf
mv $@-t $@
guestfish_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \

View File

@@ -28,6 +28,7 @@ virt_format_SOURCES = \
format.c
virt_format_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/lib -I$(top_builddir)/lib \

View File

@@ -36,6 +36,7 @@ guestmount_SOURCES = \
guestmount.c
guestmount_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/lib -I$(top_builddir)/lib \
@@ -65,6 +66,7 @@ guestunmount_SOURCES = \
guestunmount.c
guestunmount_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/lib -I$(top_builddir)/lib \

View File

@@ -695,6 +695,7 @@ let generate_gobject_session_source () =
pr "
/* It is safe to call deprecated functions from this file. */
#define GUESTFS_NO_WARN_DEPRECATED
#undef GUESTFS_NO_DEPRECATED
#include <glib.h>
#include <glib-object.h>

View File

@@ -414,6 +414,7 @@ and generate_ocaml_c () =
/* It is safe to call deprecated functions from this file. */
#define GUESTFS_NO_WARN_DEPRECATED
#undef GUESTFS_NO_DEPRECATED
#include <stdio.h>
#include <stdlib.h>

View File

@@ -559,6 +559,7 @@ typedef void (*guestfs_close_cb) (guestfs_h *g, void *opaque);
typedef void (*guestfs_progress_cb) (guestfs_h *g, void *opaque, int proc_nr, int serial, uint64_t position, uint64_t total);
#endif
#ifndef GUESTFS_NO_DEPRECATED
extern GUESTFS_DLL_PUBLIC void guestfs_set_log_message_callback (guestfs_h *g, guestfs_log_message_cb cb, void *opaque)
GUESTFS_DEPRECATED_REPLACED_BY(\"set_event_callback\");
extern GUESTFS_DLL_PUBLIC void guestfs_set_subprocess_quit_callback (guestfs_h *g, guestfs_subprocess_quit_cb cb, void *opaque)
@@ -571,6 +572,7 @@ extern GUESTFS_DLL_PUBLIC void guestfs_set_close_callback (guestfs_h *g, guestfs
#define GUESTFS_HAVE_SET_PROGRESS_CALLBACK 1
extern GUESTFS_DLL_PUBLIC void guestfs_set_progress_callback (guestfs_h *g, guestfs_progress_cb cb, void *opaque)
GUESTFS_DEPRECATED_REPLACED_BY(\"set_event_callback\");
#endif /* !GUESTFS_NO_DEPRECATED */
/* Private data area. */
#define GUESTFS_HAVE_SET_PRIVATE 1
@@ -657,6 +659,13 @@ extern GUESTFS_DLL_PUBLIC void *guestfs_next_private (guestfs_h *g, const char *
) optargs;
);
let deprecated =
match deprecated_by with
| Not_deprecated -> false
| Replaced_by _ | Deprecated_no_replacement -> true in
if deprecated then
pr "#ifndef GUESTFS_NO_DEPRECATED\n";
generate_prototype ~single_line:true ~semicolon:false ~dll_public:true
~handle:"g" ~prefix:"guestfs_" shortname style;
(match deprecated_by with
@@ -667,6 +676,8 @@ extern GUESTFS_DLL_PUBLIC void *guestfs_next_private (guestfs_h *g, const char *
| Deprecated_no_replacement ->
pr "\n GUESTFS_DEPRECATED_NO_REPLACEMENT;\n"
);
if deprecated then
pr "#endif /* !GUESTFS_NO_DEPRECATED */\n";
if optargs <> [] then (
generate_prototype ~single_line:true ~newline:true ~handle:"g"
@@ -1332,6 +1343,9 @@ and generate_client_actions actions () =
pr "\
#include <config.h>
/* It is safe to call deprecated functions from this file. */
#undef GUESTFS_NO_DEPRECATED
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

View File

@@ -333,6 +333,7 @@ and generate_erlang_actions actions () =
/* It is safe to call deprecated functions from this file. */
#define GUESTFS_NO_WARN_DEPRECATED
#undef GUESTFS_NO_DEPRECATED
#include <stdio.h>
#include <stdlib.h>

View File

@@ -86,6 +86,7 @@ let generate_fish_run_cmds actions () =
pr "\n";
pr "/* It is safe to call deprecated functions from this file. */\n";
pr "#define GUESTFS_NO_WARN_DEPRECATED\n";
pr "#undef GUESTFS_NO_DEPRECATED\n";
pr "\n";
pr "#include <stdio.h>\n";
pr "#include <stdlib.h>\n";

View File

@@ -40,7 +40,7 @@ let generate_golang_go () =
package guestfs
/*
#cgo CFLAGS: -DGUESTFS_PRIVATE=1 -DGUESTFS_NO_WARN_DEPRECATED
#cgo CFLAGS: -DGUESTFS_PRIVATE=1 -DGUESTFS_NO_WARN_DEPRECATED -UGUESTFS_NO_DEPRECATED
#cgo LDFLAGS: -lguestfs
#include <stdio.h>
#include <stdlib.h>

View File

@@ -580,6 +580,7 @@ and generate_java_c actions () =
/* It is safe to call deprecated functions from this file. */
#define GUESTFS_NO_WARN_DEPRECATED
#undef GUESTFS_NO_DEPRECATED
#include <stdio.h>
#include <stdlib.h>

View File

@@ -41,6 +41,7 @@ let generate_lua_c () =
/* It is safe to call deprecated functions from this file. */
#define GUESTFS_NO_WARN_DEPRECATED
#undef GUESTFS_NO_DEPRECATED
#include <stdio.h>
#include <stdlib.h>

View File

@@ -42,6 +42,7 @@ let rec generate_perl_xs () =
/* It is safe to call deprecated functions from this file. */
#define GUESTFS_NO_WARN_DEPRECATED
#undef GUESTFS_NO_DEPRECATED
#include <stdio.h>
#include <stdlib.h>

View File

@@ -85,6 +85,7 @@ and generate_php_c () =
/* It is safe to call deprecated functions from this file. */
#define GUESTFS_NO_WARN_DEPRECATED
#undef GUESTFS_NO_DEPRECATED
#include <stdio.h>
#include <stdlib.h>

View File

@@ -282,6 +282,7 @@ and generate_python_actions actions () =
/* It is safe to call deprecated functions from this file. */
#define GUESTFS_NO_WARN_DEPRECATED
#undef GUESTFS_NO_DEPRECATED
#include <stdio.h>
#include <stdlib.h>

View File

@@ -113,6 +113,7 @@ and generate_ruby_c actions () =
/* It is safe to call deprecated functions from this file. */
#define GUESTFS_NO_WARN_DEPRECATED
#undef GUESTFS_NO_DEPRECATED
#include <stdio.h>
#include <stdlib.h>

View File

@@ -40,6 +40,7 @@ let rec generate_c_api_tests () =
/* It is safe to call deprecated functions from this file. */
#define GUESTFS_NO_WARN_DEPRECATED
#undef GUESTFS_NO_DEPRECATED
#include <stdio.h>
#include <stdlib.h>

View File

@@ -49,6 +49,7 @@ virt_inspector_SOURCES = \
inspector.c
virt_inspector_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \

View File

@@ -28,6 +28,7 @@ virt_make_fs_SOURCES = \
make-fs.c
virt_make_fs_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \

View File

@@ -32,6 +32,7 @@ virt_rescue_SOURCES = \
suggest.c
virt_rescue_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-DGUESTFS_PRIVATE=1 \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \

View File

@@ -33,6 +33,7 @@ libguestfs_test_tool_CPPFLAGS = \
-I$(top_srcdir)/lib -I$(top_builddir)/lib \
-I$(top_srcdir)/common/options -I$(top_builddir)/common/options \
-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
-DGUESTFS_NO_DEPRECATED=1 \
-DLOCALEBASEDIR=\""$(datadir)/locale"\"
libguestfs_test_tool_CFLAGS = \

View File

@@ -29,6 +29,7 @@ check_PROGRAMS = $(TESTS)
test_parallel_mount_local_SOURCES = \
test-parallel-mount-local.c
test_parallel_mount_local_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-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 \

View File

@@ -27,6 +27,7 @@ check_PROGRAMS = test-internal-parse-mountable
test_internal_parse_mountable_SOURCES = test-internal-parse-mountable.c
test_internal_parse_mountable_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-DGUESTFS_PRIVATE=1 \
-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
-I$(top_srcdir)/lib -I$(top_builddir)/lib

View File

@@ -26,6 +26,7 @@ check_PROGRAMS = test-parallel
test_parallel_SOURCES = test-parallel.c
test_parallel_CPPFLAGS = \
-DGUESTFS_NO_DEPRECATED=1 \
-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