aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2019-06-15 23:34:56 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2019-06-17 18:45:28 +0300
commit064b22135afaf701f7f689ef75136298b9a0d278 (patch)
tree0f09134db6c125eb33e848c79fadcd893b7b25d6
parentd2cc9eb93efbb34f5c88d672e04b126b0c422bb3 (diff)
Allow specifying pkg-args in bdep-init -A and -C forms
-rw-r--r--bdep/bdep.cxx59
-rw-r--r--bdep/config.cxx27
-rw-r--r--bdep/config.hxx2
-rw-r--r--bdep/init.cli11
-rw-r--r--bdep/init.cxx19
-rw-r--r--bdep/init.hxx2
-rw-r--r--bdep/new.cxx9
-rw-r--r--tests/init.testscript133
8 files changed, 182 insertions, 80 deletions
diff --git a/bdep/bdep.cxx b/bdep/bdep.cxx
index e02687d..5182647 100644
--- a/bdep/bdep.cxx
+++ b/bdep/bdep.cxx
@@ -93,6 +93,7 @@ static O
init (const common_options& co,
cli::group_scanner& scan,
strings& args,
+ bool keep_sep,
bool tmp)
{
O o;
@@ -111,7 +112,9 @@ init (const common_options& co,
//
if (strcmp (a, "--") == 0)
{
- scan.next ();
+ if (!keep_sep)
+ scan.next ();
+
opt = false;
continue;
}
@@ -242,7 +245,13 @@ try
const common_options& co (o);
if (o.help ())
- return help (init<help_options> (co, scan, argsv, false), "", nullptr);
+ return help (init<help_options> (co,
+ scan,
+ argsv,
+ false /* keep_sep */,
+ false /* tmp */),
+ "",
+ nullptr);
// The next argument should be a command.
//
@@ -257,7 +266,11 @@ try
if (h)
{
- ho = init<help_options> (co, scan, argsv, false);
+ ho = init<help_options> (co,
+ scan,
+ argsv,
+ false /* keep_sep */,
+ false /* tmp */);
if (args.more ())
{
@@ -296,38 +309,44 @@ try
// if (h)
// r = help (ho, "new", print_bdep_cmd_new_usage);
// else
- // r = cmd_new (init<cmd_new_options> (co, scan, argsv), args);
+ // r = cmd_new (init<cmd_new_options> (co,
+ // scan,
+ // argsv,
+ // false /* keep_sep */,
+ // true /* tmp */),
+ // args);
//
// break;
// }
//
-#define COMMAND_IMPL(ON, FN, SN, TMP) \
+#define COMMAND_IMPL(ON, FN, SN, SEP, TMP) \
if (cmd.ON ()) \
{ \
if (h) \
r = help (ho, SN, print_bdep_##FN##_usage); \
else \
- r = cmd_##FN (init<cmd_##FN##_options> (co, scan, argsv, TMP), args); \
+ r = cmd_##FN (init<cmd_##FN##_options> (co, scan, argsv, SEP, TMP), \
+ args); \
\
break; \
}
// Temp dir is initialized manually for these commands.
//
- COMMAND_IMPL (new_, new, "new", false);
- COMMAND_IMPL (sync, sync, "sync", false);
-
- COMMAND_IMPL (init, init, "init", true);
- COMMAND_IMPL (fetch, fetch, "fetch", true);
- COMMAND_IMPL (status, status, "status", true);
- COMMAND_IMPL (ci, ci, "ci", true);
- COMMAND_IMPL (release, release, "release", true);
- COMMAND_IMPL (publish, publish, "publish", true);
- COMMAND_IMPL (deinit, deinit, "deinit", true);
- COMMAND_IMPL (config, config, "config", true);
- COMMAND_IMPL (test, test, "test", true);
- COMMAND_IMPL (update, update, "update", true);
- COMMAND_IMPL (clean, clean, "clean", true);
+ COMMAND_IMPL (new_, new, "new", false, false);
+ COMMAND_IMPL (sync, sync, "sync", false, false);
+
+ COMMAND_IMPL (init, init, "init", true, true);
+ COMMAND_IMPL (fetch, fetch, "fetch", false, true);
+ COMMAND_IMPL (status, status, "status", false, true);
+ COMMAND_IMPL (ci, ci, "ci", false, true);
+ 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 (test, test, "test", false, true);
+ COMMAND_IMPL (update, update, "update", false, true);
+ COMMAND_IMPL (clean, clean, "clean", false, true);
assert (false);
fail << "unhandled command";
diff --git a/bdep/config.cxx b/bdep/config.cxx
index 7c9b45d..da7f5f4 100644
--- a/bdep/config.cxx
+++ b/bdep/config.cxx
@@ -264,7 +264,7 @@ namespace bdep
const package_locations& pkgs,
database& db,
dir_path path,
- cli::scanner& cfg_args,
+ const strings& args,
optional<string> name,
optional<uint64_t> id)
{
@@ -279,19 +279,13 @@ namespace bdep
// Call bpkg to create the configuration.
//
- {
- strings args;
- while (cfg_args.more ())
- args.push_back (cfg_args.next ());
-
- run_bpkg (2,
- co,
- "create",
- "-d", path,
- (ao.existing () ? "--existing" : nullptr),
- (ao.wipe () ? "--wipe" : nullptr),
- args);
- }
+ run_bpkg (2,
+ co,
+ "create",
+ "-d", path,
+ (ao.existing () ? "--existing" : nullptr),
+ (ao.wipe () ? "--wipe" : nullptr),
+ args);
return cmd_config_add (ao,
prj,
@@ -386,13 +380,16 @@ namespace bdep
dir_path prj (find_project (o));
database db (open (prj, trace));
+ strings cfg_args;
+ for (; args.more (); cfg_args.push_back (args.next ())) ;
+
cmd_config_create (o,
o,
prj,
load_packages (prj, true /* allow_empty */),
db,
move (path),
- args,
+ cfg_args,
move (name),
move (id));
return 0;
diff --git a/bdep/config.hxx b/bdep/config.hxx
index 1b9bc5a..0954850 100644
--- a/bdep/config.hxx
+++ b/bdep/config.hxx
@@ -30,7 +30,7 @@ namespace bdep
const package_locations&,
database&,
dir_path path,
- cli::scanner& args,
+ const strings& args,
optional<string> name,
optional<uint64_t> id = nullopt);
diff --git a/bdep/init.cli b/bdep/init.cli
index c57796e..cb9c9f8 100644
--- a/bdep/init.cli
+++ b/bdep/init.cli
@@ -23,8 +23,9 @@ namespace bdep
\c{\b{bdep init} [<options>] [<pkg-spec>] [<cfg-spec>] [<pkg-args>]\n
\b{bdep init} [<options>] [<prj-spec>] \b{--empty|-E}\n
\b{bdep init} [<options>] [<pkg-spec>] \b{--config-add|-A} <cfg-dir> [\b{@}<cfg-name>]\n
+ \ \ \ \ \ \ \ \ \ \ [<pkg-args>]\n
\b{bdep init} [<options>] [<pkg-spec>] \b{--config-create|-C} <cfg-dir> [\b{@}<cfg-name>]\n
- \ \ \ \ \ \ \ \ \ \ [<cfg-args>]}
+ \ \ \ \ \ \ \ \ \ \ [<cfg-args>] [\b{--} <pkg-args>]}
\c{<cfg-spec> = (\b{@}<cfg-name> | \b{--config}|\b{-c} <cfg-dir>)... | \b{--all}|\b{-a}\n
<pkg-spec> = (\b{--directory}|\b{-d} <pkg-dir>)... | <prj-spec>\n
@@ -59,7 +60,13 @@ namespace bdep
\cb{config add} or \cb{config create} commands (\l{bdep-config(1)}),
respectively, followed by the first form. Optional <cfg-args> in the
fourth form are the additional arguments to the underlying
- \l{bpkg-cfg-create(1)} command.
+ \l{bpkg-cfg-create(1)} command. Note that in this case to specify
+ <pkg-args> without specifying <cfg-args> you have to use two \cb{--}
+ separators, for example:
+
+ \
+ $ bdep init -C ../prj-gcc @gcc -- -- ?sys:libsqlite3/*
+ \
\h|EXAMPLES|
diff --git a/bdep/init.cxx b/bdep/init.cxx
index 782dfe0..30cabb2 100644
--- a/bdep/init.cxx
+++ b/bdep/init.cxx
@@ -23,7 +23,7 @@ namespace bdep
const package_locations& ps,
database& db,
const dir_path& cfg,
- cli::scanner& args,
+ const strings& args,
bool ca,
bool cc)
{
@@ -173,6 +173,11 @@ namespace bdep
return 0;
}
+ // Skip the first `--` separator, if any.
+ //
+ if (args.more () && args.peek () == string ("--"))
+ args.next ();
+
configurations cfgs;
{
// Make sure everyone refers to the same objects across all the
@@ -184,6 +189,16 @@ namespace bdep
//
if (ca || cc)
{
+ strings cfg_args;
+ if (cc)
+ {
+ // 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));
+ }
+
cfgs.push_back (
cmd_init_config (
o,
@@ -192,7 +207,7 @@ namespace bdep
load_packages (prj),
db,
ca ? o.config_add () : o.config_create (),
- args,
+ cfg_args,
ca,
cc));
}
diff --git a/bdep/init.hxx b/bdep/init.hxx
index bceb850..059f736 100644
--- a/bdep/init.hxx
+++ b/bdep/init.hxx
@@ -22,7 +22,7 @@ namespace bdep
const package_locations&,
database&,
const dir_path& cfg,
- cli::scanner& cfg_args,
+ const strings& cfg_args,
bool config_add_specified,
bool config_create_specified);
diff --git a/bdep/new.cxx b/bdep/new.cxx
index 37da2be..9bba9a7 100644
--- a/bdep/new.cxx
+++ b/bdep/new.cxx
@@ -1783,6 +1783,10 @@ namespace bdep
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,
@@ -1791,12 +1795,11 @@ namespace bdep
pkgs,
db,
ca ? o.config_add () : o.config_create (),
- args,
+ cfg_args,
ca,
cc)};
- if (!pkgs.empty ())
- cmd_init (o, prj, db, cfgs, pkgs, scan_arguments (args) /* pkg_args */);
+ cmd_init (o, prj, db, cfgs, pkgs, strings () /* pkg_args */);
}
return 0;
diff --git a/tests/init.testscript b/tests/init.testscript
index 002f2b2..6e336fc 100644
--- a/tests/init.testscript
+++ b/tests/init.testscript
@@ -14,43 +14,97 @@ deinit += -d prj
: create-cfg
:
-: Here we also test that the configuration variable is properly persisted and
-: the project is properly built in the source tree.
-:
{
- $clone_prj;
-
- $* -C @cfg $cxx 'config.cc.poptions=-DTEST' 2>>/~"%EOE%" &prj-cfg/***;
- initializing in project $~/prj/
- created configuration @cfg $~/prj-cfg/ 1 default,forwarded,auto-synchronized
- synchronizing:
- % new prj.+19700101000000%
- EOE
-
- sed -n -e 's/^config.cc.poptions = (.+)$/\1/p' prj-cfg/build/config.build \
- >'-DTEST';
-
- $status >'prj configured 0.1.0-a.0.19700101000000';
-
- $build prj/ 2>>~%EOE%;
- %(mkdir|c\+\+|ld|ln) .+%{4}
- EOE
-
- prj/prj/prj 'testscript' >'Hello, testscript!'; # Make sure is forwarded.
+ +$clone_prj
- $build prj-cfg/prj/ 2>>/EOE;
- info: prj-cfg/dir{prj/} is up to date
- EOE
-
- $build 'clean:' prj/ 2>>~%EOE%;
- %rm .+%{3}
- EOE
+ +cat <<EOI >+prj/manifest
+ depends: libprj
+ EOI
- $deinit 2>>/"EOE"
- deinitializing in project $~/prj/
- synchronizing:
- drop prj
- EOE
+ : cfg-pkg-args
+ :
+ {
+ $clone_prj;
+
+ $* -C @cfg $cxx 'config.cc.poptions=-DTEST' -- '?sys:libprj/*' 2>>/~"%EOE%" &prj-cfg/***;
+ initializing in project $~/prj/
+ created configuration @cfg $~/prj-cfg/ 1 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';
+
+ $status >'prj configured 0.1.0-a.0.19700101000000';
+
+ $build prj/ 2>>~%EOE%;
+ %(mkdir|c\+\+|ld|ln) .+%{4}
+ EOE
+
+ prj/prj/prj 'testscript' >'Hello, testscript!'; # Make sure is forwarded.
+
+ $build prj-cfg/prj/ 2>>/EOE;
+ info: prj-cfg/dir{prj/} is up to date
+ EOE
+
+ $build 'clean:' prj/ 2>>~%EOE%;
+ %rm .+%{3}
+ EOE
+
+ $deinit 2>>/"EOE"
+ deinitializing in project $~/prj/
+ synchronizing:
+ drop prj
+ drop libprj
+ EOE
+ }
+
+ : cfg-pkg-args-sep
+ :
+ {
+ $clone_prj;
+
+ $* -C @cfg -- $cxx 'config.cc.poptions=-DTEST' -- '?sys:libprj/*' 2>>/~"%EOE%" &prj-cfg/***;
+ initializing in project $~/prj/
+ created configuration @cfg $~/prj-cfg/ 1 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
+ }
+
+ : pkg-args
+ :
+ {
+ $clone_prj;
+
+ $* -C @cfg -- -- '?sys:libprj/*' 2>>/~"%EOE%" &prj-cfg/***;
+ initializing in project $~/prj/
+ created configuration @cfg $~/prj-cfg/ 1 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
+ }
}
: add-cfg
@@ -58,22 +112,28 @@ deinit += -d prj
{
$clone_prj;
+ cat <<EOI >+prj/manifest;
+ depends: libprj
+ EOI
+
# Pre-create configurations.
#
$new -C prj-cfg1 tmp $cxx 2>! &prj-cfg1/*** &tmp/***;
$init -C prj-cfg2 -d tmp $cxx 2>! &prj-cfg2/***;
- $* -A @cfg1 2>>/~"%EOE%";
+ $* -A @cfg1 '?sys:libprj/*' 2>>/~"%EOE%";
initializing in project $~/prj/
added configuration @cfg1 $~/prj-cfg1/ 1 default,forwarded,auto-synchronized
synchronizing:
+ % configure sys:libprj.*%
% new prj.+19700101000000%
EOE
- $* -A prj-cfg2 @cfg2 2>>/~"%EOE%";
+ $* -A prj-cfg2 @cfg2 '?sys:libprj/*' 2>>/~"%EOE%";
initializing in project $~/prj/
added configuration @cfg2 $~/prj-cfg2/ 2 auto-synchronized
synchronizing:
+ % configure sys:libprj.*%
% new prj.+19700101000000%
EOE
@@ -105,6 +165,7 @@ deinit += -d prj
deinitializing in project $~/prj/
synchronizing:
drop prj
+ drop libprj
EOE
}