Skip to content

Commit

Permalink
CAD-2839 workbench: factor profile management somewhat
Browse files Browse the repository at this point in the history
  • Loading branch information
deepfire committed May 13, 2021
1 parent e3d76d0 commit 0151ad6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
37 changes: 30 additions & 7 deletions nix/workbench/profile.sh
Expand Up @@ -27,15 +27,26 @@ case "${op}" in
;;

all-profiles | generate-all | all )
(cd "$global_basedir/profiles";
with_era_profiles '
map (profiles(.; null; null; []))
| add
';;

jq --argjson eras "$(to_jsonlist ${global_profile_eras[*]})" --null-input '
include "profiles";
all-profile-names | names | all-names )
with_era_profiles '
map (profile_names(.; null; null; []))
| add
';;

has-profile )
local usage="USAGE: wb profile has-profile NAME"
local name=${1:?$usage}

$eras
| map(profiles(.; null; null; []))
| add
');;
with_era_profiles '
map (has_profile(.; null; null; []; $name))
| any
' --exit-status --arg name "$name" >/dev/null
;;

compose )
local profile_names="$@"
Expand Down Expand Up @@ -118,3 +129,15 @@ case "${op}" in

* ) usage_profile;; esac
}

with_era_profiles() {
local usage="USAGE: wb profile with-profiles JQEXP"
local jqexp=${1:?$usage}; shift

jq -L "$global_basedir/profiles" \
--argjson eras "$(to_jsonlist ${global_profile_eras[*]})" \
--null-input '
include "profiles";
$eras | '"$jqexp" "$@"
}
4 changes: 2 additions & 2 deletions nix/workbench/profiles/derived.jq
@@ -1,5 +1,5 @@
include "defaults" { search: "." };
include "cli-args" { search: "." };
include "defaults";
include "cli-args";

def may_attr($attr; $dict; $defdict; $scale; $suf):
if ($dict[$attr] //
Expand Down
31 changes: 21 additions & 10 deletions nix/workbench/profiles/profiles.jq
Expand Up @@ -57,13 +57,13 @@
## ..which simply calls ./profiles.nix with {} params.
##

include "topology" { search: "." };
include "defaults" { search: "." };
include "adhoc" { search: "." };
include "variants" { search: "." };
include "derived" { search: "." };
include "topology";
include "defaults";
include "adhoc";
include "variants";
include "derived";

def profiles($era; $mcompo; $topo; $extra_profiles):
def compute_profiles($era; $mcompo; $topo; $extra_profiles):
($mcompo // topology_composition($topo // {}) // {}) as $compo

## Profiles are variants + custom (or aux) profiles:
Expand All @@ -77,10 +77,21 @@ def profiles($era; $mcompo; $topo; $extra_profiles):

## Compute the derived params.
| add_derived_params
);

## Finally, assembly into a dictionary..
| { "\(.name)":
def profiles($era; $mcompo; $topo; $extra_profiles):
compute_profiles($era; $mcompo; $topo; $extra_profiles)
| map (## Assemble into a dictionary..
{ "\(.name)":
## ..and cleanup:
. | delpaths ([["generator", "epochs"]])}
)
. | delpaths ([["generator", "epochs"]])})
| add;

def profile_names($era; $mcompo; $topo; $extra_profiles):
compute_profiles($era; $mcompo; $topo; $extra_profiles)
| map (.name);

def has_profile($era; $mcompo; $topo; $extra_profiles; $name):
compute_profiles($era; $mcompo; $topo; $extra_profiles)
| map (.name == $name)
| any;

0 comments on commit 0151ad6

Please sign in to comment.