From 7cc7c74bcff6e4e433ced3902f0b019e9c080b64 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 18 Mar 2021 18:33:53 +0300 Subject: Add support for binless C libraries to bdep-new --- bdep/new.cli | 2 +- bdep/new.cxx | 120 ++++++++++++++++++++++++++++++++------------------- tests/new.testscript | 48 +++++++++++++++++++++ 3 files changed, 125 insertions(+), 45 deletions(-) diff --git a/bdep/new.cli b/bdep/new.cli index 6b15840..f9bdfc6 100644 --- a/bdep/new.cli +++ b/bdep/new.cli @@ -330,7 +330,7 @@ namespace bdep \li|\n\ \ \ \cb{binless} - Create a header-only C++ library.| + Create a header-only library.| \li|\n\ \ \ \cb{no-tests} diff --git a/bdep/new.cxx b/bdep/new.cxx index b531242..9e800ed 100644 --- a/bdep/new.cxx +++ b/bdep/new.cxx @@ -361,9 +361,6 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args) } case type::lib: { - if (t.lib_opt.binless () && l != lang::cxx) - fail << "--type|-t,binless is only valid for C++ libraries"; - readme = !t.lib_opt.no_readme () && !src; altn = t.lib_opt.alt_naming (); itest = !t.lib_opt.no_tests () && !src; @@ -1868,54 +1865,91 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args) string exph; // Export header name (empty if binless). string verh; // Version header name. + bool binless (t.lib_opt.binless ()); + switch (l) { case lang::c: { - apih = s + ".h"; - exph = "export.h"; - verh = ver ? "version.h" : string (); + if (binless) + { + apih = s + ".h"; + verh = ver ? "version.h" : string (); - // /.h - // - open (out_inc / apih); - os << "#pragma once" << '\n' - << '\n' - << "#include " << '\n' - << '\n' - << "#include <" << ip << exph << ">" << '\n' - << '\n' - << "/* Print a greeting for the specified name into the specified" << '\n' - << " * stream. On success, return the number of characters printed." << '\n' - << " * On failure, set errno and return a negative value." << '\n' - << " */" << '\n' - << mp << "_SYMEXPORT int" << '\n' - << "say_hello (FILE *, const char *name);" << '\n'; - os.close (); + // /.h + // + open (out_inc / apih); + os << "#pragma once" << '\n' + << '\n' + << "#include " << '\n' + << "#include " << '\n' + << '\n' + << "/* Print a greeting for the specified name into the specified" << '\n' + << " * stream. On success, return the number of characters printed." << '\n' + << " * On failure, set errno and return a negative value." << '\n' + << " */" << '\n' + << "static inline int" << '\n' + << "say_hello (FILE *f, const char* name)" << '\n' + << "{" << '\n' + << " if (f == NULL || name == NULL || *name == '\\0')" << '\n' + << " {" << '\n' + << " errno = EINVAL;" << '\n' + << " return -1;" << '\n' + << " }" << '\n' + << '\n' + << " return fprintf (f, \"Hello, %s!\\n\", name);" << '\n' + << "}" << '\n'; + os.close (); - // /.c - // - open (out_src / s + ".c"); - os << "#include <" << ip << apih << ">" << '\n' - << '\n' - << "#include " << '\n' - << '\n' - << "int say_hello (FILE *f, const char* n)" << '\n' - << "{" << '\n' - << " if (f == NULL || n == NULL || *n == '\\0')" << '\n' - << " {" << '\n' - << " errno = EINVAL;" << '\n' - << " return -1;" << '\n' - << " }" << '\n' - << '\n' - << " return fprintf (f, \"Hello, %s!\\n\", n);" << '\n' - << "}" << '\n'; - os.close (); + break; + } + else + { + apih = s + ".h"; + exph = "export.h"; + verh = ver ? "version.h" : string (); - break; + // /.h + // + open (out_inc / apih); + os << "#pragma once" << '\n' + << '\n' + << "#include " << '\n' + << '\n' + << "#include <" << ip << exph << ">" << '\n' + << '\n' + << "/* Print a greeting for the specified name into the specified" << '\n' + << " * stream. On success, return the number of characters printed." << '\n' + << " * On failure, set errno and return a negative value." << '\n' + << " */" << '\n' + << mp << "_SYMEXPORT int" << '\n' + << "say_hello (FILE *, const char *name);" << '\n'; + os.close (); + + // /.c + // + open (out_src / s + ".c"); + os << "#include <" << ip << apih << ">" << '\n' + << '\n' + << "#include " << '\n' + << '\n' + << "int say_hello (FILE *f, const char* n)" << '\n' + << "{" << '\n' + << " if (f == NULL || n == NULL || *n == '\\0')" << '\n' + << " {" << '\n' + << " errno = EINVAL;" << '\n' + << " return -1;" << '\n' + << " }" << '\n' + << '\n' + << " return fprintf (f, \"Hello, %s!\\n\", n);" << '\n' + << "}" << '\n'; + os.close (); + + break; + } } case lang::cxx: - if (t.lib_opt.binless ()) + if (binless) { apih = s + he; verh = ver ? "version" + he : string (); @@ -2094,8 +2128,6 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args) os.close (); } - bool binless (t.lib_opt.binless ()); - // /buildfile // if (split) diff --git a/tests/new.testscript b/tests/new.testscript index 6fc0b93..1f5947d 100644 --- a/tests/new.testscript +++ b/tests/new.testscript @@ -295,6 +295,18 @@ status += -d prj EOE } + : lib-c-binless + : + { + $* -t lib,binless -l c libprj-foo 2>>/"EOE" &libprj-foo/***; + created new library project libprj-foo in $~/libprj-foo/ + EOE + + $build libprj-foo/ $config_c 2>>~%EOE% + %(version\.in|c|ar|ld) .+%{3} + EOE + } + : lib-c-prefix : { @@ -319,6 +331,30 @@ status += -d prj EOE } + : lib-c-split-binless + : + { + $* -t lib,split,binless -l c libprj-foo 2>>/"EOE" &libprj-foo/***; + created new library project libprj-foo in $~/libprj-foo/ + EOE + + $build libprj-foo/ $config_c 2>>~%EOE% + %(version\.in|c|ld) .+%{3} + EOE + } + + : lib-c-split-binless-unit-tests + : + { + $* -t lib,split,binless,unit-tests -l c libfoo 2>>/"EOE" &libfoo/***; + created new library project libfoo in $~/libfoo/ + EOE + + $build libfoo/ $config_c 2>>~%EOE% + %(version\.in|c|ar|ld) .+%{5} + EOE + } + : lib-c-unit-tests : { @@ -331,6 +367,18 @@ status += -d prj EOE } + : lib-c-binless-unit-tests + : + { + $* -t lib,binless,unit-tests -l c libfoo 2>>/"EOE" &libfoo/***; + created new library project libfoo in $~/libfoo/ + EOE + + $build libfoo/ $config_c 2>>~%EOE% + %(version\.in|c|ld) .+%{5} + EOE + } + # Test create-from-existing functionality. # : exist -- cgit v1.1