diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-03-17 15:55:51 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2017-03-17 15:55:51 +0200 |
commit | 36ebc1cd634dbd8d114a8b3f11b6935ac268526f (patch) | |
tree | fdceb7f6d8139fd25a6c6a7e1009615e448d2cf0 | |
parent | ce1b5f5d36a7651fd68c8985b8e1f2a748fa6e19 (diff) |
Reimplement create command to use build2 create meta-operation
-rw-r--r-- | bpkg/cfg-create.cli | 7 | ||||
-rw-r--r-- | bpkg/cfg-create.cxx | 104 |
2 files changed, 16 insertions, 95 deletions
diff --git a/bpkg/cfg-create.cli b/bpkg/cfg-create.cli index 45d4ea7..d7ad6f0 100644 --- a/bpkg/cfg-create.cli +++ b/bpkg/cfg-create.cli @@ -20,8 +20,11 @@ namespace bpkg \h|DESCRIPTION| The \cb{cfg-create} command creates a new \cb{bpkg} configuration with - the specified \cb{build2} modules and configuration variables. Unless - the \cb{--wipe} option is specified, \cb{cfg-create} expects the + the specified \cb{build2} modules and configuration variables. The + \cb{bpkg} configuration itself is a build system configuration; see the + \cb{build2} \cb{create} meta-operation for details. + + Unless the \cb{--wipe} option is specified, \cb{cfg-create} expects the configuration directory to be empty or to not exist (in which case it will be created). diff --git a/bpkg/cfg-create.cxx b/bpkg/cfg-create.cxx index b3d672b..9112871 100644 --- a/bpkg/cfg-create.cxx +++ b/bpkg/cfg-create.cxx @@ -27,8 +27,8 @@ namespace bpkg dir_path c (o.directory ()); l4 ([&]{trace << "creating configuration in " << c;}); - // If the directory already exists, make sure it is empty. - // Otherwise, create it. + // If the directory already exists, make sure it is empty. Otherwise + // create it. // if (exists (c)) { @@ -53,7 +53,7 @@ namespace bpkg // Sort arguments into modules and configuration variables. // - strings mods; + string mods; // build2 create meta-operation parameters. strings vars; while (args.more ()) @@ -66,104 +66,22 @@ namespace bpkg } else if (!a.empty ()) { - // Append .config unless the module name ends with '.', in which case - // strip it. - // - if (a.back () != '.') - a += ".config"; - else - a.pop_back (); - - mods.push_back (move (a)); + mods += mods.empty () ? ", " : " "; + mods += a; } else fail << "empty string as argument"; } - // Create build/. - // - dir_path b (c / dir_path ("build")); - mk (b); - - // Write build/bootstrap.build. - // - path f (b / path ("bootstrap.build")); - try - { - ofdstream ofs (f); - - ofs << "# Maintained automatically by bpkg. Edit if you know what " << - "you are doing." << endl - << "#" << endl - << "project =" << endl - << "amalgamation =" << endl - << endl - << "using config" << endl - << "using test" << endl - << "using install" << endl; - - ofs.close (); - } - catch (const io_error& e) - { - fail << "unable to write to " << f << ": " << e; - } - - // Write build/root.build. - // - f = b / path ("root.build"); - try - { - ofdstream ofs (f); - - ofs << "# Maintained automatically by bpkg. Edit if you know what " << - "you are doing." << endl - << "#" << endl; - - // Load user-supplied modules. We don't really know whether they must - // be loaded in bootstrap. - // - for (const string& m: mods) - { - // If the module name start with '?', then use optional load. - // - if (m.front () != '?') - ofs << "using " << m << endl; - else - ofs << "using? " << m.c_str () + 1 << endl; - } - - ofs.close (); - } - catch (const io_error& e) - { - fail << "unable to write to " << f << ": " << e; - } - - // Write root buildfile. - // - f = c / path ("buildfile"); - try - { - ofdstream ofs (f); - - ofs << "# Maintained automatically by bpkg. Edit if you know what " << - "you are doing." << endl - << "#" << endl - << "./:" << endl; - - ofs.close (); - } - catch (const io_error& e) - { - fail << "unable to write to " << f << ": " << e; - } - - // Configure. + // Create and configure. // // Run quiet. Use path representation to get canonical trailing slash. // - run_b (o, c, "configure('" + c.representation () + "')", true, vars); + run_b (o, + c, + "create('" + c.representation () + "'" + mods + ")", + true, + vars); // Create .bpkg/. // |