From f4e192564a6e048eef14f21ab4d269874b6bfba3 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 23 May 2018 18:30:01 +0300 Subject: Adapt to inventing package_name type --- bdep/build.txx | 4 ++-- bdep/deinit.cxx | 4 ++-- bdep/new.cxx | 18 +++++++++-------- bdep/odb.sh | 1 + bdep/project.cxx | 9 +++++---- bdep/project.hxx | 14 ++++++++++--- bdep/project.xml | 2 +- bdep/status.cxx | 4 ++-- bdep/sync.cxx | 4 ++-- bdep/value-traits.hxx | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 90 insertions(+), 24 deletions(-) create mode 100644 bdep/value-traits.hxx diff --git a/bdep/build.txx b/bdep/build.txx index 804d590..a1690b4 100644 --- a/bdep/build.txx +++ b/bdep/build.txx @@ -65,7 +65,7 @@ namespace bdep if (!all) { for (const package_location& p: pp.packages) - pkgs.push_back (p.name.c_str ()); + pkgs.push_back (p.name.string ().c_str ()); } // Build in each configuration skipping empty ones. @@ -88,7 +88,7 @@ namespace bdep pkgs.clear (); for (const package_state& p: c->packages) - pkgs.push_back (p.name.c_str ()); + pkgs.push_back (p.name.string ().c_str ()); } // If we are printing multiple configurations, separate them with a diff --git a/bdep/deinit.cxx b/bdep/deinit.cxx index 87f478f..40c13a4 100644 --- a/bdep/deinit.cxx +++ b/bdep/deinit.cxx @@ -134,7 +134,7 @@ namespace bdep if (!all) { for (const package_location& p: pp.packages) - pkgs.push_back (p.name); + pkgs.push_back (p.name.string ()); } // Deinitialize in each configuration skipping empty ones. @@ -173,7 +173,7 @@ namespace bdep pkgs.clear (); for (const package_state& p: c->packages) - pkgs.push_back (p.name); + pkgs.push_back (p.name.string ()); } c->packages.erase ( diff --git a/bdep/new.cxx b/bdep/new.cxx index e5f4329..505ed96 100644 --- a/bdep/new.cxx +++ b/bdep/new.cxx @@ -4,8 +4,6 @@ #include -#include // validate_package_name() - #include #include #include @@ -86,23 +84,27 @@ namespace bdep // Validate argument. // - string n (args.more () ? args.next () : ""); - if (n.empty ()) + string a (args.more () ? args.next () : ""); + if (a.empty ()) fail << "project name argument expected"; // If the project type is not empty then the project name is also a package - // name, so let's validate it as such. + // name. // + bpkg::package_name pn; + if (t != type::empty) try { - bpkg::validate_package_name (n); + pn = bpkg::package_name (move (a)); } catch (const invalid_argument& e) { fail << "invalid package name: " << e; } + const string& n (t != type::empty ? pn.string () : a); + // Full name vs the name stem (e.g, 'hello' in 'libhello'). // // We use the full name for filesystem directories and preprocessor macros @@ -998,8 +1000,8 @@ namespace bdep { package_locations pkgs; - if (t != type::empty) - pkgs.push_back (package_location {n, dir_path ()}); // prj == pkg + if (t != type::empty) // prj == pkg + pkgs.push_back (package_location {move (pn), dir_path ()}); configurations cfgs { cmd_init_config ( diff --git a/bdep/odb.sh b/bdep/odb.sh index 07c744a..a2596e3 100755 --- a/bdep/odb.sh +++ b/bdep/odb.sh @@ -14,6 +14,7 @@ $odb $lib -I.. -I../../libbpkg -I../../libbutl \ -d sqlite --std c++14 --generate-query \ --odb-epilogue '#include ' \ --hxx-prologue '#include ' \ + --hxx-prologue '#include ' \ --include-with-brackets --include-prefix bdep --guard-prefix BDEP \ --sqlite-override-null project.hxx diff --git a/bdep/project.cxx b/bdep/project.cxx index 59ba21e..ec323cb 100644 --- a/bdep/project.cxx +++ b/bdep/project.cxx @@ -233,11 +233,11 @@ namespace bdep dir_path d (path_cast (move (*m.location))); d.normalize (false /* actualize */, true /* cur_empty */); - pls.push_back (package_location {string (), move (d)}); + pls.push_back (package_location {package_name (), move (d)}); } } else if (exists (prj / manifest_file)) - pls.push_back (package_location {string (), dir_path ()}); + pls.push_back (package_location {package_name (), dir_path ()}); else if (!allow_empty) fail << "no packages in project " << prj; @@ -305,7 +305,8 @@ namespace bdep { // Name is to be extracted later. // - r.packages.push_back (package_location {"", move (*p.package)}); + r.packages.push_back ( + package_location {package_name (), move (*p.package)}); } } } @@ -320,7 +321,7 @@ namespace bdep { // Name is to be extracted later. // - r.packages.push_back (package_location {"", *p.package}); + r.packages.push_back (package_location {package_name (), *p.package}); } } diff --git a/bdep/project.hxx b/bdep/project.hxx index 20d3cf7..612897d 100644 --- a/bdep/project.hxx +++ b/bdep/project.hxx @@ -7,6 +7,8 @@ #include +#include + #include #include @@ -38,6 +40,12 @@ namespace bdep to((?) ? (?)->string () : bdep::optional_string ()) \ from((?) ? bdep::dir_path (*(?)) : bdep::optional_dir_path ()) + // package_name + // + using bpkg::package_name; + + #pragma db value(package_name) type("TEXT") options("COLLATE NOCASE") + // State of a package in a configuration. // // Pretty much everything about the package can change (including location @@ -51,7 +59,7 @@ namespace bdep #pragma db value struct package_state { - string name; + package_name name; }; // Configuration associated with a project. @@ -162,8 +170,8 @@ namespace bdep // struct package_location { - string name; - dir_path path; + package_name name; + dir_path path; }; using package_locations = vector; diff --git a/bdep/project.xml b/bdep/project.xml index b9da262..e69af8b 100644 --- a/bdep/project.xml +++ b/bdep/project.xml @@ -21,7 +21,7 @@ - + diff --git a/bdep/status.cxx b/bdep/status.cxx index c9f62d0..080e970 100644 --- a/bdep/status.cxx +++ b/bdep/status.cxx @@ -68,12 +68,12 @@ namespace bdep if (ps.empty ()) { for (const package_state& p: c->packages) - pkgs.push_back (p.name); + pkgs.push_back (p.name.string ()); } else { for (const package_location& p: ps) - pkgs.push_back (p.name); + pkgs.push_back (p.name.string ()); } cmd_status (o, prj, c->path, pkgs, fetch); diff --git a/bdep/sync.cxx b/bdep/sync.cxx index b1589ad..84cb715 100644 --- a/bdep/sync.cxx +++ b/bdep/sync.cxx @@ -254,7 +254,7 @@ namespace bdep // since there is no guarantee a higher version isn't available from // another repository. // - args.push_back (pkg.name + '@' + prj.path.string ()); + args.push_back (pkg.name.string () + '@' + prj.path.string ()); } } @@ -402,7 +402,7 @@ namespace bdep if (o != nullptr) { - dir_path out (dir_path (cfg) /= pkg.name); + dir_path out (dir_path (cfg) /= pkg.name.string ()); run_b (co, o, src.representation () + '@' + out.representation () + diff --git a/bdep/value-traits.hxx b/bdep/value-traits.hxx new file mode 100644 index 0000000..9984bae --- /dev/null +++ b/bdep/value-traits.hxx @@ -0,0 +1,54 @@ +// file : bdep/value-traits.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BDEP_VALUE_TRAITS_HXX +#define BDEP_VALUE_TRAITS_HXX + +#include +#include // size_t +#include // move() + +#include + +#include + +namespace odb +{ + namespace sqlite + { + template <> + class value_traits: + value_traits + { + public: + using value_type = bpkg::package_name; + using query_type = bpkg::package_name; + using image_type = details::buffer; + + using base_type = value_traits; + + static void + set_value (value_type& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + std::string s; + base_type::set_value (s, b, n, is_null); + v = !s.empty () ? value_type (std::move (s)) : value_type (); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const value_type& v) + { + base_type::set_image (b, n, is_null, v.string ()); + } + }; + }; +} + +#endif // BDEP_WRAPPER_TRAITS_HXX -- cgit v1.1