From 3dca6c1c2c51b3ddd466e2e2e9fd71f4cdf497ed Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 23 Sep 2021 10:42:09 +0200 Subject: Add sync --disfigure option to force from-scratch reconfiguration --- bdep/sync.cli | 16 ++++++--- bdep/sync.cxx | 89 ++++++++++++++++++++++++++++++++++++--------------- tests/sync.testscript | 56 ++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 31 deletions(-) diff --git a/bdep/sync.cli b/bdep/sync.cli index c25cd7d..60254a1 100644 --- a/bdep/sync.cli +++ b/bdep/sync.cli @@ -204,6 +204,17 @@ namespace bdep "Also upgrade or patch all dependencies, recursively." } + bool --yes|-y + { + "Don't prompt for confirmation when up/down-grading dependencies." + } + + bool --disfigure + { + "Disfigure project packages during synchronization effectively causing + their from-scratch reconfiguration." + } + bool --fetch|-f { "Perform the \cb{fetch} command prior to synchronization." @@ -214,11 +225,6 @@ namespace bdep "Perform the \cb{fetch --full} command prior to synchronization." } - bool --yes|-y - { - "Don't prompt for confirmation when up/down-grading dependencies." - } - bool --create-host-config { "Create a configuration for build-time dependencies without prompt." diff --git a/bdep/sync.cxx b/bdep/sync.cxx index d03f18a..b7cf01b 100644 --- a/bdep/sync.cxx +++ b/bdep/sync.cxx @@ -830,6 +830,7 @@ namespace bdep bool name_cfg, optional upgrade, // true - upgrade, false - patch optional recursive, // true - recursive, false - immediate + bool disfigure, const package_locations& prj_pkgs, const strings& dep_pkgs, bool create_host_config, @@ -1052,19 +1053,65 @@ namespace bdep for (const package_state& pkg: cfg->packages) { + // Return true if this package is part of the list specified + // explicitly or, if none are specified, init'ed in the origin + // project. + // + // @@ Feels like cfg.origin should be enough for the latter case? + // + auto origin_pkg = [origin, + &origin_cfgs, + &prj_pkgs, + &pkg, + r = optional ()] () mutable + { + if (!r) + { + auto contains = [] (const auto& pkgs, const package_state& pkg) + { + return find_if (pkgs.begin (), pkgs.end (), + [&pkg] (const auto& p) + { + return p.name == pkg.name; + }) != pkgs.end (); + }; + + if (prj_pkgs.empty ()) + { + r = false; + if (origin) + { + for (const sync_config& cfg: origin_cfgs) + if ((r = contains (cfg->packages, pkg))) + break; + } + } + else + r = contains (prj_pkgs, pkg); + } + + return *r; + }; + + // See if we need to pass --disfigure. We only do this for the + // origin packages. + // + bool disf (disfigure && origin_pkg ()); + // See if we need to pass config..develop=true. We only do // this if: // // 1. It's an explicit sync (init is explicit). // - // 2. This is a from-scratch configuration of this package. + // 2. This is a from-scratch (re)configuration of this package. // // 3. The user did not specify custom develop value in pkg_args. // optional dev; if (!cfg.implicit && - !exists (dir_path (cfg->path) /= pkg.name.string (), - path ("config.build"))) + (disf || + !exists (dir_path (cfg->path) /= pkg.name.string (), + path ("config.build")))) { dev = "config." + pkg.name.variable () + ".develop"; @@ -1091,7 +1138,7 @@ namespace bdep bool vars (origin_vars && cfg.origin); - bool g (multi_cfg || vars || dev); + bool g (multi_cfg || vars || dev || disf); if (g) args.push_back ("{"); @@ -1099,33 +1146,16 @@ namespace bdep args.push_back ("--config-uuid=" + linked_cfgs.find (cfg->path)->uuid.string ()); + if (disf) + args.push_back ("--disfigure"); + if (upgrade && dep_pkgs.empty () && !cfg.implicit) { // We synchronize all the init'ed packages, including those from // other projects. But if the dependencies are not specified, we - // only upgrade dependencies of the packages specified explicitly - // or init'ed in the origin project. + // only upgrade dependencies of the origin packages. // - auto contains = [] (const auto& pkgs, const package_state& pkg) - { - return find_if (pkgs.begin (), pkgs.end (), - [&pkg] (const auto& p) - { - return p.name == pkg.name; - }) != pkgs.end (); - }; - - bool c (false); - if (prj_pkgs.empty () && origin) - { - for (const sync_config& cfg: origin_cfgs) - if ((c = contains (cfg->packages, pkg))) - break; - } - else - c = contains (prj_pkgs, pkg); - - if (c) + if (origin_pkg ()) { // The project package itself must always be upgraded to the // latest version/iteration. So we have to translate to @@ -2041,6 +2071,7 @@ namespace bdep name_cfg, nullopt /* upgrade */, nullopt /* recursive */, + false /* disfigure */, package_locations () /* prj_pkgs */, strings () /* dep_pkgs */, create_host_config, @@ -2115,6 +2146,7 @@ namespace bdep name_cfg, nullopt /* upgrade */, nullopt /* recursive */, + false /* disfigure */, package_locations () /* prj_pkgs */, strings () /* dep_pkgs */, create_host_config, @@ -2159,6 +2191,7 @@ namespace bdep name_cfg, nullopt /* upgrade */, nullopt /* recursive */, + false /* disfigure */, package_locations () /* prj_pkgs */, strings () /* dep_pkgs */, create_host_config, @@ -2224,6 +2257,7 @@ namespace bdep name_cfg, nullopt /* upgrade */, nullopt /* recursive */, + false /* disfigure */, package_locations () /* prj_pkgs */, strings () /* dep_pkgs */, create_host_config, @@ -2570,6 +2604,7 @@ namespace bdep !o.patch (), // Upgrade by default unless patch requested. (o.recursive () ? optional (true) : o.immediate () ? optional (false) : nullopt), + o.disfigure (), package_locations () /* prj_pkgs */, dep_pkgs, o.create_host_config (), @@ -2591,6 +2626,7 @@ namespace bdep false /* name_cfg */, o.upgrade (), o.recursive (), + o.disfigure (), prj_pkgs, strings () /* dep_pkgs */, o.create_host_config (), @@ -2614,6 +2650,7 @@ namespace bdep o.implicit () /* name_cfg */, nullopt /* upgrade */, nullopt /* recursive */, + o.disfigure (), package_locations () /* prj_pkgs */, strings () /* dep_pkgs */, o.create_host_config (), diff --git a/tests/sync.testscript b/tests/sync.testscript index a9fac5c..d03907f 100644 --- a/tests/sync.testscript +++ b/tests/sync.testscript @@ -205,6 +205,62 @@ deinit += -d prj EOE } +: config-vars +: +{ + $new prj &prj/***; + + cat <+prj/build/root.build; + config [bool] config.prj.develop ?= false + config [bool] config.prj.extra ?= true + + text "develop=$config.prj.develop" + text "extra=$config.prj.extra" + EOI + + $init -d prj -C @cfg $config_cxx &prj-cfg/*** 2>>~/EOE/; + /.*/+ + /.*: develop=true/ + /.*: extra=true/ + EOE + + # Reconfigure. + # + $* -d prj config.prj.develop=false config.prj.extra=false 2>>~/EOE/; + /.*/+ + /.*: develop=false/ + /.*: extra=false/ + EOE + + # Make sure the configuration is by default preserved on reconfiguration. + # + cat <+prj/manifest; + tags: c++ + EOI + + $* -d prj config.prj.develop=false config.prj.extra=false 2>>~/EOE/; + /.*/+ + /.*: develop=false/ + /.*: extra=false/ + EOE + + # Make sure --disfigure causes a from-scratch reconfiguration. + # + $* -d prj --disfigure config.prj.extra=false 2>>~/EOE/; + /.*/+ + /.*: develop=true/ + /.*: extra=false/ + EOE + + # Make sure --disfigure alone triggers reconfiguration. + # + $* -d prj --disfigure 2>>~/EOE/ + /.*/+ + /.*: develop=true/ + /.*: extra=true/ + EOE +} + : dependency-config : { -- cgit v1.1