From 602b71ed970b8ca9fea19c0103be7a977179d50d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 15 May 2018 16:47:05 +0200 Subject: Implement support for empty project type --- bdep/new-parsers.cxx | 5 +++ bdep/new-types.hxx | 22 ++++++---- bdep/new.cli | 21 ++++++--- bdep/new.cxx | 117 ++++++++++++++++++++++++++++----------------------- 4 files changed, 98 insertions(+), 67 deletions(-) diff --git a/bdep/new-parsers.cxx b/bdep/new-parsers.cxx index effa2a7..97e319c 100644 --- a/bdep/new-parsers.cxx +++ b/bdep/new-parsers.cxx @@ -78,6 +78,11 @@ namespace bdep r.type = type::bare; r.bare_opt = parse_options (o, v, i); } + else if (l == "empty") + { + r.type = type::empty; + r.empty_opt = parse_options (o, v, i); + } else throw invalid_value (o, l); diff --git a/bdep/new-types.hxx b/bdep/new-types.hxx index 616b87e..1b31027 100644 --- a/bdep/new-types.hxx +++ b/bdep/new-types.hxx @@ -18,13 +18,15 @@ namespace bdep class cmd_new_exe_options; class cmd_new_lib_options; class cmd_new_bare_options; + class cmd_new_empty_options; - template + template struct cmd_new_type_template { - enum type_type {exe, lib, bare} type; + enum type_type {exe, lib, bare, empty} type; operator type_type () const {return type;} @@ -32,12 +34,13 @@ namespace bdep { EXE exe_opt; LIB lib_opt; - BARE bare_opt; + BARE bare_opt; + EMPTY empty_opt; }; // Default is exe with no options. // - cmd_new_type_template (): type (exe) {bare_opt = BARE ();} + cmd_new_type_template (): type (exe) {exe_opt = EXE ();} friend ostream& operator<< (ostream& os, const cmd_new_type_template& t) @@ -46,9 +49,10 @@ namespace bdep switch (t) { - case type::exe: return os << "executable"; - case type::lib: return os << "library"; - case type::bare: return os << "bare"; + case type::exe: return os << "executable"; + case type::lib: return os << "library"; + case type::bare: return os << "bare"; + case type::empty: return os << "empty"; } return os; diff --git a/bdep/new.cli b/bdep/new.cli index b0e7662..09c7a3e 100644 --- a/bdep/new.cli +++ b/bdep/new.cli @@ -29,7 +29,7 @@ namespace bdep \b{bdep new} [] \b{--package} [] } \c{ \ \ \ \ = [] [] []\n - \ \ \ \ = \b{--type}|\b{-t} (\b{exe}|\b{lib}|\b{bare})[\b{,}...]\n + \ \ \ \ = \b{--type}|\b{-t} (\b{exe}|\b{lib}|\b{bare}|\b{empty})[\b{,}...]\n \ \ \ \ = \b{--lang}|\b{-l} (\b{c}|\b{c++})[\b{,}...]\n \ \ \ \ \ = \b{--vcs}|\b{-s} \ (\b{git}|\b{none})[\b{,}...]\n = \b{--directory}|\b{-d} \n @@ -89,7 +89,13 @@ namespace bdep A project without any source code. Recognized bare project options: \cb{no-tests} \- Don't add support for functional/integration testing. - || + | + + \li|\cb{empty} + + An empty project that can be filled with packages (see + \cb{--package}). Note that the project language is ignored for + this project type.|| The project language can be specified with the \c{\b{--lang}|\b{-l}} option. Valid values for this option and their semantics are described @@ -146,6 +152,10 @@ namespace bdep bool no-tests; }; + class cmd_new_empty_options + { + }; + // --lang options // class cmd_new_c_options @@ -199,9 +209,10 @@ namespace bdep { "[,...]", "Specify project type and options. Valid values for are \cb{exe} - (executable project, default), \cb{lib} (library project), and - \cb{bare} (bare project without any source code). Valid values for - are type-specific." + (executable project, default), \cb{lib} (library project), \cb{bare} + (bare project without any source code), and \cb{empty} (empty project + ready to be filled with packages). Valid values for are + type-specific." } cmd_new_lang --lang|-l diff --git a/bdep/new.cxx b/bdep/new.cxx index 7b579fa..11b312e 100644 --- a/bdep/new.cxx +++ b/bdep/new.cxx @@ -154,25 +154,45 @@ namespace bdep } } - path f; // File currently being written. + for (path f;;) // Breakout loop with file currently being written. try { ofdstream os; - // manifest + // .gitignore // - os.open (f = out / "manifest"); - os << ": 1" << endl - << "name: " << n << endl - << "version: 0.1.0-a.0.z" << endl - << "summary: " << s << " " << t << " project" << endl - << "license: proprietary" << endl - << "url: https://example.org/" << n << endl - << "email: you@example.org" << endl - << "depends: * build2 >= 0.7.0-" << endl - << "depends: * bpkg >= 0.7.0-" << endl - << "#depends: libhello ^1.0.0" << endl; - os.close (); + // See also tests/.gitignore below. + // + if (v == vcs::git) + { + // Use POSIX directory separators here. + // + os.open (f = out / ".gitignore"); + if (!pkg) + os << bdep_dir.string () << '/' << endl + << endl; + if (t != type::empty) + os << "# Compiler/linker output." << endl + << "#" << endl + << "*.d" << endl + << "*.t" << endl + << "*.i" << endl + << "*.ii" << endl + << "*.o" << endl + << "*.obj" << endl + << "*.so" << endl + << "*.dll" << endl + << "*.a" << endl + << "*.lib" << endl + << "*.exp" << endl + << "*.pdb" << endl + << "*.ilk" << endl + << "*.exe" << endl + << "*.exe.dlls/" << endl + << "*.exe.manifest" << endl + << "*.pc" << endl; + os.close (); + } // repositories.manifest // @@ -203,6 +223,24 @@ namespace bdep os.close (); } + if (t == type::empty) + break; + + // manifest + // + os.open (f = out / "manifest"); + os << ": 1" << endl + << "name: " << n << endl + << "version: 0.1.0-a.0.z" << endl + << "summary: " << s << " " << t << endl + << "license: proprietary" << endl + << "url: https://example.org/" << n << endl + << "email: you@example.org" << endl + << "depends: * build2 >= 0.7.0-" << endl + << "depends: * bpkg >= 0.7.0-" << endl + << "#depends: libhello ^1.0.0" << endl; + os.close (); + // build/ // dir_path bd (dir_path (out) /= "build"); @@ -284,45 +322,13 @@ namespace bdep << "tests/: install = false" << endl; os.close (); - // .gitignore - // - // See also tests/.gitignore below. - // - if (v == vcs::git) - { - // Use POSIX directory separators here. - // - os.open (f = out / ".gitignore"); - os << bdep_dir.string () << '/' << endl - << endl - << "# Compiler/linker output." << endl - << "#" << endl - << "*.d" << endl - << "*.t" << endl - << "*.i" << endl - << "*.ii" << endl - << "*.o" << endl - << "*.obj" << endl - << "*.so" << endl - << "*.dll" << endl - << "*.a" << endl - << "*.lib" << endl - << "*.exp" << endl - << "*.pdb" << endl - << "*.ilk" << endl - << "*.exe" << endl - << "*.exe.dlls/" << endl - << "*.exe.manifest" << endl - << "*.pc" << endl; - os.close (); - } + if (t == type::bare) + break; // / (source subdirectory). // dir_path sd (dir_path (out) /= n); - - if (t != type::bare) - mk (sd); + mk (sd); switch (t) { @@ -946,10 +952,13 @@ namespace bdep break; } case type::bare: + case type::empty: { - break; + assert (false); } } + + break; } catch (const io_error& e) { @@ -986,9 +995,11 @@ namespace bdep ca, cc)}; - package_locations pkgs {{n, dir_path ()}}; // project == package - - cmd_init (o, prj, db, cfgs, pkgs, scan_arguments (args) /* pkg_args */); + if (t != type::empty) + { + package_locations pkgs {{n, dir_path ()}}; // project == package + cmd_init (o, prj, db, cfgs, pkgs, scan_arguments (args) /* pkg_args */); + } } return 0; -- cgit v1.1