aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2022-07-19 20:20:47 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2022-07-20 13:48:26 +0300
commitddafa0f3475fe532a66879b807b0a8f47ecb201e (patch)
tree569a72699c810c9157c7ba1a6465d1af839017f1
parent03cb180e90129ef3435dc8ad81deff1810a5c5bf (diff)
Fail if no module specified for being created configuration
-rw-r--r--bdep/bdep.cxx4
-rw-r--r--bdep/config.cli2
-rw-r--r--bdep/config.cxx56
-rw-r--r--bdep/init.cli2
-rw-r--r--bdep/init.cxx36
-rw-r--r--bdep/new.cli2
-rw-r--r--bdep/new.cxx55
-rw-r--r--tests/config.testscript20
-rw-r--r--tests/init.testscript159
-rw-r--r--tests/new.testscript20
-rw-r--r--tests/status.testscript2
-rw-r--r--tests/sync.testscript6
12 files changed, 283 insertions, 81 deletions
diff --git a/bdep/bdep.cxx b/bdep/bdep.cxx
index 9731aaa..3061650 100644
--- a/bdep/bdep.cxx
+++ b/bdep/bdep.cxx
@@ -530,7 +530,7 @@ try
// Temp dir is initialized manually for these commands.
//
- COMMAND_IMPL (new_, new, "new", false, false);
+ COMMAND_IMPL (new_, new, "new", true, false);
COMMAND_IMPL (sync, sync, "sync", false, false);
COMMAND_IMPL (init, init, "init", true, true);
@@ -540,7 +540,7 @@ try
COMMAND_IMPL (release, release, "release", false, true);
COMMAND_IMPL (publish, publish, "publish", false, true);
COMMAND_IMPL (deinit, deinit, "deinit", false, true);
- COMMAND_IMPL (config, config, "config", false, true);
+ COMMAND_IMPL (config, config, "config", true, true);
COMMAND_IMPL (test, test, "test", false, true);
COMMAND_IMPL (update, update, "update", false, true);
COMMAND_IMPL (clean, clean, "clean", false, true);
diff --git a/bdep/config.cli b/bdep/config.cli
index b5b7225..261115c 100644
--- a/bdep/config.cli
+++ b/bdep/config.cli
@@ -32,7 +32,7 @@ namespace bdep
\c{<cfg-spec> = \b{@}<cfg-name> | \b{--config}|\b{-c} <cfg-dir>\n
<prj-spec> = \b{--directory}|\b{-d} <prj-dir>\n
- <cfg-args> = [\b{--} <bpkg-options>] [\b{--existing}|\b{-e} | (<module> | <cfg-var>)...]}
+ <cfg-args> = [\b{--} [<bpkg-options>]] [\b{--existing}|\b{-e} | (<module> | <cfg-var>)...]}
\h|DESCRIPTION|
diff --git a/bdep/config.cxx b/bdep/config.cxx
index 38888e1..0960909 100644
--- a/bdep/config.cxx
+++ b/bdep/config.cxx
@@ -660,12 +660,36 @@ namespace bdep
optional<uint64_t> id;
cmd_config_validate_add (o, "config create", name, id);
+ // Skip `--` which separates the directory argument, if any, as for
+ // example in:
+ //
+ // $ bdep config create -- @gcc cc config.cxx=g++
+ //
+ bool sep (false);
+ if (args.more () && args.peek () == string ("--"))
+ {
+ sep = true;
+ args.next ();
+ }
+
// Note that the shortcut will only work if there are no cfg-args which
// is not very likely. Oh, well.
//
string arg;
if (args.more ())
+ {
arg = args.next ();
+
+ // Skip `--` which separates the bpkg options, if any, as for example in:
+ //
+ // $ bdep config create ../foo-gcc -- -v cc config.cxx=g++
+ //
+ if (args.more () && args.peek () == string ("--"))
+ {
+ sep = true;
+ args.next ();
+ }
+ }
else if (name)
{
// Reverse into the shortcut form expected by translate_path_name().
@@ -689,8 +713,38 @@ namespace bdep
dir_path prj (find_project (o));
database db (open (prj, trace));
+ // Read the configuration arguments.
+ //
+ // Also make sure that at least one module is specified, unless the `--`
+ // separator is specified (in which case we assume that the user knows
+ // what they are doing).
+ //
strings cfg_args;
- for (; args.more (); cfg_args.push_back (args.next ())) ;
+ bool module (false);
+
+ while (args.more ())
+ {
+ string a (args.next ());
+
+ // Assume the argument is a module unless it is a variable (note that it
+ // can't be --existing|-e since no --).
+ //
+ // Note: the arguments can't be bpkg options if unseparated.
+ //
+ if (!sep)
+ {
+ if (a.find ('=') == string::npos)
+ module = true;
+ }
+
+ cfg_args.push_back (move (a));
+ }
+
+ if (!sep && !module)
+ fail << "no module(s) specified for configuration to be created" <<
+ info << "for example, for C/C++ configuration specify 'cc'" <<
+ info << "use '--' to create configuration without modules" <<
+ info << "for example: bdep config create ... --";
cmd_config_create (o,
o,
diff --git a/bdep/init.cli b/bdep/init.cli
index 9ca9a44..ed44efa 100644
--- a/bdep/init.cli
+++ b/bdep/init.cli
@@ -30,7 +30,7 @@ namespace bdep
<pkg-spec> = (\b{--directory}|\b{-d} <pkg-dir>)... | <prj-spec>\n
<prj-spec> = \b{--directory}|\b{-d} <prj-dir>\n
<pkg-args> = (\b{?}<pkg> | <cfg-var>)...\n
- <cfg-args> = [\b{--} <bpkg-options>] [\b{--existing}|\b{-e} | (<module> | <cfg-var>)...]}
+ <cfg-args> = [\b{--} [<bpkg-options>]] [\b{--existing}|\b{-e} | (<module> | <cfg-var>)...]}
\h|DESCRIPTION|
diff --git a/bdep/init.cxx b/bdep/init.cxx
index 7533b4d..4599628 100644
--- a/bdep/init.cxx
+++ b/bdep/init.cxx
@@ -359,8 +359,12 @@ namespace bdep
// Skip the first `--` separator, if any.
//
+ bool sep (false);
if (args.more () && args.peek () == string ("--"))
+ {
+ sep = true;
args.next ();
+ }
configurations cfgs;
{
@@ -374,8 +378,36 @@ namespace bdep
// Read the configuration arguments until we reach the second `--`
// separator or eos.
//
- for (string a; args.more () && (a = args.next ()) != "--"; )
- cfg_args.push_back (move (a));
+ // Also make sure that there is at least one module unless the `--`
+ // separator is specified (see cmd_config_create() for details).
+ //
+ bool module (false);
+ while (args.more ())
+ {
+ string a (args.next ());
+
+ if (a == "--")
+ {
+ sep = true;
+ break;
+ }
+ else
+ {
+ if (!sep)
+ {
+ if (a.find ('=') == string::npos)
+ module = true;
+ }
+
+ cfg_args.push_back (move (a));
+ }
+ }
+
+ if (!sep && !module)
+ fail << "no module(s) specified for configuration to be created" <<
+ info << "for example, for C/C++ configuration specify 'cc'" <<
+ info << "use '--' to create configuration without modules" <<
+ info << "for example: bdep init -C ... --";
}
cfgs.push_back (
diff --git a/bdep/new.cli b/bdep/new.cli
index cdc84c3..8f3b094 100644
--- a/bdep/new.cli
+++ b/bdep/new.cli
@@ -33,7 +33,7 @@ namespace bdep
<type> \ \ \ \ = \b{--type}|\b{-t} (\b{exe}|\b{lib}|\b{bare}|\b{empty})[\b{,}<type-opt>...]\n
<vcs> \ \ \ \ \ = \b{--vcs}|\b{-s} \ (\b{git}|\b{none})[\b{,}<vcs-opt>...]\n
<prj-spec> = \b{--directory}|\b{-d} <prj-dir>\n
- <cfg-args> = [\b{--} <bpkg-options>] [\b{--existing}|\b{-e} | (<module> | <cfg-var>)...]}
+ <cfg-args> = [\b{--} [<bpkg-options>]] [\b{--existing}|\b{-e} | (<module> | <cfg-var>)...]}
\h|DESCRIPTION|
diff --git a/bdep/new.cxx b/bdep/new.cxx
index ad267b8..8f0c836 100644
--- a/bdep/new.cxx
+++ b/bdep/new.cxx
@@ -519,6 +519,17 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args)
vcs vc (o.vcs ());
bool vc_o (o.vcs_specified ());
+ // Skip `--` which separates the name argument, if any, as for example in:
+ //
+ // $ bdep new -- hello
+ //
+ bool sep (false);
+ if (args.more () && args.peek () == string ("--"))
+ {
+ sep = true;
+ args.next ();
+ }
+
// Check if we have the argument (name). If not, then we use the specified
// output or current working directory name.
//
@@ -527,6 +538,16 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args)
{
a = args.next ();
+ // Skip `--` which separates the bpkg options, if any, as for example in:
+ //
+ // $ bdep new -C @cfg hello -- -v cc config.cxx=g++
+ //
+ if (args.more () && args.peek () == string ("--"))
+ {
+ sep = true;
+ args.next ();
+ }
+
// Reduce name with a directory component to the simple name with
// --output-dir case.
//
@@ -593,6 +614,36 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args)
<< " name: " << e;
}
+ strings cfg_args;
+ if (cc)
+ {
+ // Read the configuration arguments.
+ //
+ // Also make sure that there is at least one module unless the `--`
+ // separator is specified (see cmd_config_create() for details).
+ //
+ bool module (false);
+
+ while (args.more ())
+ {
+ string a (args.next ());
+
+ if (!sep)
+ {
+ if (a.find ('=') == string::npos)
+ module = true;
+ }
+
+ cfg_args.push_back (move (a));
+ }
+
+ if (!sep && !module)
+ fail << "no module(s) specified for configuration to be created" <<
+ info << "for example, for C/C++ configuration specify 'cc'" <<
+ info << "use '--' to create configuration without modules" <<
+ info << "for example: bdep new -C ... --";
+ }
+
// Full package name vs base name (e.g., libhello in libhello.bash) vs the
// name stem (e.g, hello in libhello).
//
@@ -3231,10 +3282,6 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args)
if (t != type::empty) // prj == pkg
pkgs.push_back (package_location {move (pkgn), nullopt, dir_path ()});
- strings cfg_args;
- if (cc)
- for (; args.more (); cfg_args.push_back (args.next ())) ;
-
configurations cfgs {
cmd_init_config (
o,
diff --git a/tests/config.testscript b/tests/config.testscript
index b02a2b2..17cfcb1 100644
--- a/tests/config.testscript
+++ b/tests/config.testscript
@@ -184,6 +184,22 @@ deinit += -d prj
created configuration $~/cfg/ 1 target default,forwarded,auto-synchronized
EOE
}
+
+ : no-module
+ {
+ $clone_root_prj;
+
+ $* create @cfg 2>>EOE != 0;
+ error: no module(s) specified for configuration to be created
+ info: for example, for C/C++ configuration specify 'cc'
+ info: use '--' to create configuration without modules
+ info: for example: bdep config create ... --
+ EOE
+
+ $* create @cfg -- 2>>/"EOE" &prj-cfg/***
+ created configuration @cfg $~/prj-cfg/ 1 target default,forwarded,auto-synchronized
+ EOE
+ }
}
: add
@@ -257,8 +273,8 @@ deinit += -d prj
{
$clone_root_prj;
- $* create @cfg &prj-cfg/*** 2>!;
- $* create --config-type host @host-cfg &prj-host-cfg/*** 2>!;
+ $* create @cfg -- &prj-cfg/*** 2>!;
+ $* create --config-type host @host-cfg -- &prj-host-cfg/*** 2>!;
$* link @cfg @host-cfg 2>!;
diff --git a/tests/init.testscript b/tests/init.testscript
index 593d265..6cba76d 100644
--- a/tests/init.testscript
+++ b/tests/init.testscript
@@ -16,92 +16,126 @@ deinit += -d prj
{
+$clone_prj
- +cat <<EOI >+prj/manifest
- depends: libprj
- EOI
-
- : cfg-pkg-args
+ : with-dependency
:
{
- $clone_prj;
+ +$clone_prj
- $* -C @cfg $config_cxx 'config.cc.poptions=-DTEST' -- '?sys:libprj/*' 2>>/~"%EOE%" &prj-cfg/***;
- initializing in project $~/prj/
- created configuration @cfg $~/prj-cfg/ 1 target default,forwarded,auto-synchronized
- synchronizing:
- % configure sys:libprj.*%
- % new prj.+19700101000000%
- EOE
+ +cat <<EOI >+prj/manifest
+ depends: libprj
+ EOI
- sed -n -e 's/^config.cc.poptions = (.+)$/\1/p' prj-cfg/build/config.build \
- >'-DTEST';
+ : cfg-pkg-args
+ :
+ {
+ $clone_prj;
- $status >'prj configured 0.1.0-a.0.19700101000000';
+ $* -C @cfg $config_cxx 'config.cc.poptions=-DTEST' -- '?sys:libprj/*' 2>>/~"%EOE%" &prj-cfg/***;
+ initializing in project $~/prj/
+ created configuration @cfg $~/prj-cfg/ 1 target default,forwarded,auto-synchronized
+ synchronizing:
+ % configure sys:libprj.*%
+ % new prj.+19700101000000%
+ EOE
- $build prj/ 2>>~%EOE%;
- %(mkdir|c\+\+|ld|ln) .+%{4}
- EOE
+ sed -n -e 's/^config.cc.poptions = (.+)$/\1/p' prj-cfg/build/config.build \
+ >'-DTEST';
- prj/prj/prj 'testscript' >'Hello, testscript!'; # Make sure is forwarded.
+ $status >'prj configured 0.1.0-a.0.19700101000000';
- $build prj-cfg/prj/ 2>>/EOE;
- info: prj-cfg/dir{prj/} is up to date
- EOE
+ $build prj/ 2>>~%EOE%;
+ %(mkdir|c\+\+|ld|ln) .+%{4}
+ EOE
- $build 'clean:' prj/ 2>>~%EOE%;
- %rm .+%{3}
- EOE
+ prj/prj/prj 'testscript' >'Hello, testscript!'; # Make sure is forwarded.
- $deinit 2>>/"EOE"
- deinitializing in project $~/prj/
- synchronizing:
- drop prj
- drop libprj
- EOE
- }
+ $build prj-cfg/prj/ 2>>/EOE;
+ info: prj-cfg/dir{prj/} is up to date
+ EOE
- : cfg-pkg-args-sep
- :
- {
- $clone_prj;
+ $build 'clean:' prj/ 2>>~%EOE%;
+ %rm .+%{3}
+ EOE
- $* -C @cfg -- $config_cxx 'config.cc.poptions=-DTEST' -- '?sys:libprj/*' 2>>/~"%EOE%" &prj-cfg/***;
- initializing in project $~/prj/
- created configuration @cfg $~/prj-cfg/ 1 target default,forwarded,auto-synchronized
- synchronizing:
- % configure sys:libprj.*%
- % new prj.+19700101000000%
- EOE
+ $deinit 2>>/"EOE"
+ deinitializing in project $~/prj/
+ synchronizing:
+ drop prj
+ drop libprj
+ EOE
+ }
- sed -n -e 's/^config.cc.poptions = (.+)$/\1/p' prj-cfg/build/config.build \
- >'-DTEST';
+ : cfg-pkg-args-sep
+ :
+ {
+ $clone_prj;
+
+ $* -C @cfg -- $config_cxx 'config.cc.poptions=-DTEST' -- '?sys:libprj/*' 2>>/~"%EOE%" &prj-cfg/***;
+ initializing in project $~/prj/
+ created configuration @cfg $~/prj-cfg/ 1 target default,forwarded,auto-synchronized
+ synchronizing:
+ % configure sys:libprj.*%
+ % new prj.+19700101000000%
+ EOE
+
+ sed -n -e 's/^config.cc.poptions = (.+)$/\1/p' prj-cfg/build/config.build \
+ >'-DTEST';
+
+ $deinit 2>>/"EOE"
+ deinitializing in project $~/prj/
+ synchronizing:
+ drop prj
+ drop libprj
+ EOE
+ }
- $deinit 2>>/"EOE"
- deinitializing in project $~/prj/
- synchronizing:
- drop prj
- drop libprj
- EOE
+ : pkg-args
+ :
+ {
+ $clone_prj;
+
+ # Note that not passing the C++ configuration arguments (see above) for
+ # the sake of testing, we may end up with the 'not built with default C++
+ # compiler' error. To avoid this, we just make sure this is not a C++
+ # project.
+ #
+ echo '' >=prj/build/root.build;
+ echo './: prj.cxx' >=prj/prj/buildfile;
+
+ $* -C @cfg -- -- '?sys:libprj/*' 2>>/~"%EOE%" &prj-cfg/***;
+ initializing in project $~/prj/
+ created configuration @cfg $~/prj-cfg/ 1 target default,forwarded,auto-synchronized
+ synchronizing:
+ % configure sys:libprj.*%
+ % new prj.+19700101000000%
+ EOE
+
+ $deinit 2>>/"EOE"
+ deinitializing in project $~/prj/
+ synchronizing:
+ drop prj
+ drop libprj
+ EOE
+ }
}
- : pkg-args
+ : no-module
:
{
$clone_prj;
- # Note that not passing the C++ configuration arguments (see above) for
- # the sake of testing, we may end up with the 'not built with default C++
- # compiler' error. To avoid this, we just make sure this is not a C++
- # project.
- #
- echo '' >=prj/build/root.build;
- echo './: prj.cxx' >=prj/prj/buildfile;
+ $* -C @cfg 2>>~%EOE% != 0;
+ %initializing in project .+%
+ error: no module(s) specified for configuration to be created
+ info: for example, for C/C++ configuration specify 'cc'
+ info: use '--' to create configuration without modules
+ info: for example: bdep init -C ... --
+ EOE
- $* -C @cfg -- -- '?sys:libprj/*' 2>>/~"%EOE%" &prj-cfg/***;
+ $* -C @cfg -- 2>>/~"%EOE%" &prj-cfg/***;
initializing in project $~/prj/
created configuration @cfg $~/prj-cfg/ 1 target default,forwarded,auto-synchronized
synchronizing:
- % configure sys:libprj.*%
% new prj.+19700101000000%
EOE
@@ -109,7 +143,6 @@ deinit += -d prj
deinitializing in project $~/prj/
synchronizing:
drop prj
- drop libprj
EOE
}
}
diff --git a/tests/new.testscript b/tests/new.testscript
index 9f7db17..b3cdae4 100644
--- a/tests/new.testscript
+++ b/tests/new.testscript
@@ -1869,4 +1869,24 @@ subdir=hello,no-subdir-source \
%(mkdir|c\+\+|ld|ln) .+%{4}
EOE
}
+
+ : no-module
+ :
+ {
+ $* -C -@cfg prj 2>>EOE != 0;
+ error: no module(s) specified for configuration to be created
+ info: for example, for C/C++ configuration specify 'cc'
+ info: use '--' to create configuration without modules
+ info: for example: bdep new -C ... --
+ EOE
+
+ $* -C -@cfg prj -- 2>>/~"%EOE%" &prj/*** &prj-cfg/***;
+ created new executable project prj in $~/prj/
+ created configuration @cfg $~/prj-cfg/ 1 target default,forwarded,auto-synchronized
+ synchronizing:
+ % new prj.+19700101000000%
+ EOE
+
+ $status >'prj configured 0.1.0-a.0.19700101000000'
+ }
}
diff --git a/tests/status.testscript b/tests/status.testscript
index 941bc14..10480ac 100644
--- a/tests/status.testscript
+++ b/tests/status.testscript
@@ -84,7 +84,7 @@ config += -d prj 2>!
{
$new -t empty prj &prj/***;
- $config create @cfg &prj-cfg/***;
+ $config create @cfg -- &prj-cfg/***;
$* 2>>~%EOE% != 0;
%error: no packages in project .+%
diff --git a/tests/sync.testscript b/tests/sync.testscript
index 8fabf3b..463fa75 100644
--- a/tests/sync.testscript
+++ b/tests/sync.testscript
@@ -322,8 +322,8 @@ deinit += -d prj
cp -rp ../libfix ./;
cp -rp ../bar ./;
- $config create -d libfoo @cfg libfoo-cfg &libfoo-cfg/***;
- $config create -d libfoo --config-type host @host host &host/***;
+ $config create -d libfoo @cfg libfoo-cfg -- &libfoo-cfg/***;
+ $config create -d libfoo --config-type host @host host -- &host/***;
$config link -d libfoo @cfg @host;
@@ -359,7 +359,7 @@ deinit += -d prj
depends: * libbuild2-baz
EOI
- $config create -d libfoo @cfg libfoo-cfg &libfoo-cfg/***;
+ $config create -d libfoo @cfg libfoo-cfg -- &libfoo-cfg/***;
# Convert specific errors to infos as we expect them to appear. Not doing
# so, makes bbot logs quite confusing.