diff options
-rw-r--r-- | bdep/new.cli | 2 | ||||
-rw-r--r-- | bdep/new.cxx | 120 | ||||
-rw-r--r-- | 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 (); - // <inc>/<stem>.h - // - open (out_inc / apih); - os << "#pragma once" << '\n' - << '\n' - << "#include <stdio.h>" << '\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 (); + // <inc>/<stem>.h + // + open (out_inc / apih); + os << "#pragma once" << '\n' + << '\n' + << "#include <stdio.h>" << '\n' + << "#include <errno.h>" << '\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 (); - // <src>/<stem>.c - // - open (out_src / s + ".c"); - os << "#include <" << ip << apih << ">" << '\n' - << '\n' - << "#include <errno.h>" << '\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; + // <inc>/<stem>.h + // + open (out_inc / apih); + os << "#pragma once" << '\n' + << '\n' + << "#include <stdio.h>" << '\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 (); + + // <src>/<stem>.c + // + open (out_src / s + ".c"); + os << "#include <" << ip << apih << ">" << '\n' + << '\n' + << "#include <errno.h>" << '\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 ()); - // <inc>/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 |