diff options
-rw-r--r-- | bdep/new.cli | 38 | ||||
-rw-r--r-- | bdep/new.cxx | 48 | ||||
-rw-r--r-- | tests/new.testscript | 16 |
3 files changed, 76 insertions, 26 deletions
diff --git a/bdep/new.cli b/bdep/new.cli index 6462f8c..9e4b3e3 100644 --- a/bdep/new.cli +++ b/bdep/new.cli @@ -391,14 +391,17 @@ namespace bdep Alternative source subdirectory relative to header/source prefix.| - \li|\n\ \ \ \cb{no-subdir} + \li|\n\ \ \ \cb{no-subdir-include} - Omit the source subdirectory.| + Omit the source subdirectory relative to the header prefix.| \li|\n\ \ \ \cb{no-subdir-source} - Omit the source subdirectory relative to the source prefix but still - create it relative to the header prefix.| + Omit the source subdirectory relative to the source prefix.| + + \li|\n\ \ \ \cb{no-subdir} + + Shortcut for \cb{no-subdir-include,no-subdir-source}.| \li|\n\ \ \ \c{\b{license=}\i{name}}| @@ -613,13 +616,14 @@ namespace bdep bool no-version; bool no-symexport; bool auto-symexport; - dir_path prefix-source; dir_path prefix-include; + dir_path prefix-source; dir_path prefix; bool split; dir_path subdir; - bool no-subdir; + bool no-subdir-include; bool no-subdir-source; + bool no-subdir; string license = "other: proprietary"; bool no-readme; bool alt-naming; @@ -977,6 +981,28 @@ namespace bdep └── hello.cxx \ + Similarly, we can also omit the source subdirectory but only in the header + prefix of the split layout by specifying the \cb{no-subdir-include} + sub-option (we also have to disable the generated version header that is + not supported in this layout): + + \ + # libhello/{include,src/hello}/ + + $ bdep new \ + -l c++ \ + -t lib,split,subdir=hello,no-subdir-include,no-version \ + libhello + + $ tree libhello/ + libhello/ + ├── include/ + │ └── hello.hxx + └── src/ + └── hello/ + └── hello.cxx + \ + To achieve the split layout where the \cb{include/} directory is inside \cb{src/}: diff --git a/bdep/new.cxx b/bdep/new.cxx index 5488aa5..80eef7a 100644 --- a/bdep/new.cxx +++ b/bdep/new.cxx @@ -507,37 +507,50 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args) bool sub_inc; // false if the header subdirectory is omitted. bool sub_src; // false if the source subdirectory is omitted. { + bool no_subdir_inc (t == type::lib && t.lib_opt.no_subdir_include ()); + bool no_subdir_src (t == type::lib && t.lib_opt.no_subdir_source ()); + + if (no_subdir_inc && no_subdir_src) + { + if (subdir != nullptr) + fail << "both --type|-t,subdir and --type|-t,no-subdir-include," + << "no-subdir-source specified"; + } + bool no_subdir (t == type::exe ? t.exe_opt.no_subdir () : t == type::lib ? t.lib_opt.no_subdir () : false); - bool no_subdir_src (t == type::lib && t.lib_opt.no_subdir_source ()); - if (no_subdir) { if (subdir != nullptr) fail << "both --type|-t,subdir and --type|-t,no-subdir specified"; + if (no_subdir_inc) + fail << "both --type|-t,no-subdir and --type|-t,no-subdir-include " + << "specified"; + if (no_subdir_src) fail << "both --type|-t,no-subdir and --type|-t,no-subdir-source " << "specified"; + no_subdir_inc = no_subdir_src = true; + } + + if (no_subdir_inc) + { // Note that the generated header machinery requires the source // subdirectory as a prefix for #include directive. Thus, the version - // header generation needs if no-subdir. + // header generation needs to be disabled if no-subdir-include is + // specified. // if (t == type::lib && !t.lib_opt.no_version ()) fail << "generated version header is not supported in this layout" << info << "specify --type|-t,no-version explicitly"; } - sub_inc = !no_subdir; - sub_src = !no_subdir && !no_subdir_src; - - // The header subdirectory can only be omited together with the source - // subdirectory. - // - assert (sub_inc || !sub_src); + sub_inc = !no_subdir_inc; + sub_src = !no_subdir_src; } if (subdir != nullptr && subdir->absolute ()) @@ -855,9 +868,9 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args) subdir, sub_inc, sub_src] (const string& n) { - sub = (subdir != nullptr ? *subdir : - sub_inc ? dir_path (n) : // Note: no need to check for - dir_path ()); // sub_src (see above). + sub = (subdir != nullptr ? *subdir : + sub_inc || sub_src ? dir_path (n) : + dir_path ()); out_inc = out / pfx_inc / (sub_inc ? sub : dir_path ()); out_src = out / pfx_src / (sub_src ? sub : dir_path ()); @@ -994,10 +1007,8 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args) // Here we treat out as subdirectory unless instructed otherwise in // which case we treat it as a prefix. // - // Note: no need to check for sub_src (see above). - // dir_path s (out_src.leaf (prj)); - if (sub_inc) + if (sub_inc || sub_src) sub = move (s); else pfx_inc = pfx_src = move (s); @@ -2206,10 +2217,7 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args) { // Include prefix. // - // Note: if sub is not empty, then there is no need to check if - // sub_inc is true (see above). - // - string ip (sub.posix_representation ()); + string ip (sub_inc ? sub.posix_representation () : ""); // Macro prefix. // diff --git a/tests/new.testscript b/tests/new.testscript index 49f43b1..d8c0b9c 100644 --- a/tests/new.testscript +++ b/tests/new.testscript @@ -1937,6 +1937,22 @@ status += -d prj EOE } + : split-no-subdir-include + : + { + $* -l c++ -t lib,split,subdir=hello,no-subdir-include,no-version libhello 2>>/"EOE" &libhello/***; + created new library project libhello in $~/libhello/ + EOE + + $build libhello/ $config_cxx 2>>~%EOE%; + %(c\+\+|ld|ar) .+%{6} + EOE + + $t libhello/ $config_cxx 2>>~%EOE% + %test .+% + EOE + } + : include-in-src : { |