aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2023-02-17 21:07:54 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2023-02-20 16:49:14 +0300
commitbe7238c1d687aee8c50d87c628197f787e433f08 (patch)
tree28beeb13ea0cb07b7787d6aa9208db74d2e49498
parent17a84035997c0e9aef7c784dc81e84a591a83177 (diff)
Add type and language values to newly created package manifest in bdep-new
-rw-r--r--bdep/new.cxx73
-rw-r--r--tests/new.testscript85
-rw-r--r--tests/release.testscript6
3 files changed, 156 insertions, 8 deletions
diff --git a/bdep/new.cxx b/bdep/new.cxx
index 04cf3ca..d423849 100644
--- a/bdep/new.cxx
+++ b/bdep/new.cxx
@@ -652,10 +652,11 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args)
// base name for inner filesystem directories and preprocessor macros, while
// the (sanitized) stem for modules, namespaces, etc.
//
- const string& n (pkgn.string ()); // Full name.
- const string& b (pkgn.base ()); // Base name.
- const string& v (pkgn.variable ()); // Variable name.
- string s (b); // Name stem.
+ const string& n (pkgn.string ()); // Full name.
+ const string& b (pkgn.base ()); // Base name.
+ const string& e (pkgn.extension ()); // Name extension.
+ const string& v (pkgn.variable ()); // Variable name.
+ string s (b); // Name stem.
{
// Warn about the lib prefix unless we are creating a source subdirectory,
// in which case the project is probably not meant to be a package anyway.
@@ -1478,6 +1479,68 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args)
os << ": 1" << '\n'
<< "name: " << n << '\n'
<< "version: 0.1.0-a.0.z" << '\n';
+
+ // Add the type value unless the package type is implied by the package
+ // name, that is, the type lib and the package name starts with lib or
+ // the type is exe and the name doesn't start with lib.
+ //
+ switch (t)
+ {
+ case type::exe:
+ {
+ if (n.size () > 3 && n.compare (0, 3, "lib") == 0 )
+ os << "type: exe" << '\n';
+ break;
+ }
+ case type::lib:
+ {
+ if (!(n.size () > 3 && n.compare (0, 3, "lib") == 0))
+ os << "type: lib" << '\n';
+ break;
+ }
+ case type::bare:
+ {
+ os << "type: other" << '\n';
+ break;
+ }
+ case type::empty:
+ {
+ assert (false);
+ }
+ }
+
+ // Add the language value(s) unless one language is used and it's
+ // implied by the package name, that is it matches the package name
+ // extension.
+ //
+ // @@ TODO: add support for --lang c,c++=impl
+ //
+ switch (l)
+ {
+ case lang::c:
+ {
+ bool cpp (l.c_opt.cpp ());
+ if (cpp || e != "c")
+ {
+ os << "language: c" << '\n';
+ if (cpp)
+ os << "language: c++" << '\n';
+ }
+ break;
+ }
+ case lang::cxx:
+ {
+ bool c (l.cxx_opt.c ());
+ if (c || e != "c++")
+ {
+ os << "language: c++" << '\n';
+ if (c)
+ os << "language: c" << '\n';
+ }
+ break;
+ }
+ }
+
if (pn)
os << "project: " << *pn << '\n';
if (readme_e && !readme_e->empty ())
@@ -1489,7 +1552,7 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args)
else
os << "license: " << license << " ; " << ln << "." << '\n';
if (readme_f)
- os << "description-file: " << readme_f->leaf (out).posix_representation () << '\n';
+ os << "description-file: " << readme_f->leaf (out).posix_representation () << '\n';
os << "url: https://example.org/" << (pn ? pn->string () : n) << '\n'
<< "email: " << pe << '\n'
<< "#build-error-email: " << pe << '\n'
diff --git a/tests/new.testscript b/tests/new.testscript
index 8b63103..a55ef0b 100644
--- a/tests/new.testscript
+++ b/tests/new.testscript
@@ -28,11 +28,43 @@ status += -d prj
created new executable project prj-foo in $~/prj-foo/
EOE
+ sed -n -e 's/^(type: .+)$/\1/p' prj-foo/manifest >:'';
+ sed -n -e 's/^language: (.+)$/\1/p' prj-foo/manifest >'c++';
+
$build prj-foo/ $config_cxx 2>>~%EOE%
%(c\+\+|ld) .+%{2}
EOE
}
+ : exe-lib-prefix
+ :
+ {
+ $* -t exe -l c++ libprj-foo 2>>/"EOE" &libprj-foo/***;
+ warning: executable name starts with 'lib'
+ created new executable project libprj-foo in $~/libprj-foo/
+ EOE
+
+ sed -n -e 's/^type: (.+)$/\1/p' libprj-foo/manifest >'exe';
+
+ $build libprj-foo/ $config_cxx 2>>~%EOE%
+ %(c\+\+|ld) .+%{2}
+ EOE
+ }
+
+ : exe-c++-suffix
+ :
+ {
+ $* -t exe -l c++ foo.c++ 2>>/"EOE" &foo.c++/***;
+ created new executable project foo.c++ in $~/foo.c++/
+ EOE
+
+ sed -n -e 's/^(language: .+)$/\1/p' foo.c++/manifest >:'';
+
+ $build foo.c++/ $config_cxx 2>>~%EOE%
+ %(c\+\+|ld) .+%{2}
+ EOE
+ }
+
: exe-c++-c
:
{
@@ -40,6 +72,11 @@ status += -d prj
created new executable project foo in $~/foo/
EOE
+ sed -n -e 's/^language: (.+)$/\1/p' foo/manifest >>EOO;
+ c++
+ c
+ EOO
+
touch foo/foo/bar.h;
cat <<EOI >=foo/foo/bar.c;
@@ -59,11 +96,28 @@ status += -d prj
created new library project libprj-foo in $~/libprj-foo/
EOE
+ sed -n -e 's/^(type: .+)$/\1/p' libprj-foo/manifest >:'';
+
$build libprj-foo/ $config_cxx 2>>~%EOE%
%(version|c\+\+|ar|ld) .+%{7}
EOE
}
+ : lib-no-lib-prefix
+ :
+ {
+ $* -t lib -l c++ prj-foo 2>>/"EOE" &prj-foo/***;
+ warning: library name does not start with 'lib'
+ created new library project prj-foo in $~/prj-foo/
+ EOE
+
+ sed -n -e 's/^type: (.+)$/\1/p' prj-foo/manifest >'lib';
+
+ $build prj-foo/ $config_cxx 2>>~%EOE%
+ %(version|c\+\+|ar|ld) .+%{7}
+ EOE
+ }
+
: lib-c++-c
:
{
@@ -90,6 +144,16 @@ status += -d prj
EOE
}
+ : bare
+ :
+ {
+ $* -t bare prj 2>>/"EOE" &prj/***;
+ created new bare project prj in $~/prj/
+ EOE
+
+ sed -n -e 's/^type: (.+)$/\1/p' prj/manifest >'other'
+ }
+
: exe-prefix
:
{
@@ -403,11 +467,27 @@ status += -d prj
created new executable project prj-foo in $~/prj-foo/
EOE
+ sed -n -e 's/^language: (.+)$/\1/p' prj-foo/manifest >'c';
+
$build prj-foo/ $config_c 2>>~%EOE%
%(c|ld) .+%{2}
EOE
}
+ : exe-c-suffix
+ :
+ {
+ $* -t exe -l c foo.c 2>>/"EOE" &foo.c/***;
+ created new executable project foo.c in $~/foo.c/
+ EOE
+
+ sed -n -e 's/^(language: .+)$/\1/p' foo.c/manifest >:'';
+
+ $build foo.c/ $config_c 2>>~%EOE%
+ %(c|ld) .+%{2}
+ EOE
+ }
+
: exe-c-c++
:
{
@@ -415,6 +495,11 @@ status += -d prj
created new executable project foo in $~/foo/
EOE
+ sed -n -e 's/^language: (.+)$/\1/p' foo/manifest >>EOO;
+ c
+ c++
+ EOO
+
touch foo/foo/bar.hxx;
cat <<EOI >=foo/foo/bar.cxx;
diff --git a/tests/release.testscript b/tests/release.testscript
index 60f55a6..1140161 100644
--- a/tests/release.testscript
+++ b/tests/release.testscript
@@ -88,7 +88,7 @@ log2 = [cmdline] $gp2 log '--pretty=format:"%d %s"'
%.*
name: prj
version: 0.2.0-a.0.z
- summary: prj C++ executable
+ language: c++
%.*
EOO
}
@@ -1139,7 +1139,7 @@ log2 = [cmdline] $gp2 log '--pretty=format:"%d %s"'
%.*
name: prj
version: 0.2.0-a.0.z
- summary: prj C++ executable
+ language: c++
%.*
EOO
@@ -1147,7 +1147,7 @@ log2 = [cmdline] $gp2 log '--pretty=format:"%d %s"'
%.*
name: libprj
version: 0.2.0-a.0.z
- project: prj
+ language: c++
%.*
EOO
}