Read placement from a layer's Placement, never from its config values (issue 651)
ADR 0348 clause 11: places, accesses and kept networks are placement, not config. Today's mergeable files still take them as said, so nothing composes differently. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -34,6 +34,69 @@ const PlacesSetting = "places"
|
||||
// AccessesSetting is the settings key that says where a module's accesses are on this node, by id.
|
||||
const AccessesSetting = "accesses"
|
||||
|
||||
// **Placement is not config** (novox/hq ADR 0348 clause 11, issue 651). `places`, `accesses` and
|
||||
// `networks` are facts of an assignment the controller decides, held beside the assignment and apart
|
||||
// from its settings: a Layer carries them in Placement, never in Values, and only Places, AccessPlaces
|
||||
// and KeptNetworks read them. A person still says them as keys of a layer through `settings`; LayerOf
|
||||
// splits such a layer, so what they type is routed to the placement and nothing they do changes.
|
||||
|
||||
// placementKeys are the keys of a layer that are placement, not config.
|
||||
var placementKeys = map[string]bool{PlacesSetting: true, AccessesSetting: true, NetworksSetting: true}
|
||||
|
||||
// SplitPlacement divides a layer as a person says it into its config values and its placement. Each is
|
||||
// nil when it holds nothing; the values themselves are not copied.
|
||||
func SplitPlacement(values map[string]any) (config, placement map[string]any) {
|
||||
for key, value := range values {
|
||||
if placementKeys[key] {
|
||||
if placement == nil {
|
||||
placement = map[string]any{}
|
||||
}
|
||||
placement[key] = value
|
||||
continue
|
||||
}
|
||||
if config == nil {
|
||||
config = map[string]any{}
|
||||
}
|
||||
config[key] = value
|
||||
}
|
||||
return config, placement
|
||||
}
|
||||
|
||||
// LayerOf is a layer as a person says it — config values and placement in one map — split into the two.
|
||||
func LayerOf(from string, values map[string]any) Layer {
|
||||
config, placement := SplitPlacement(values)
|
||||
if config == nil {
|
||||
config = map[string]any{}
|
||||
}
|
||||
return Layer{From: from, Values: config, Placement: placement}
|
||||
}
|
||||
|
||||
// Whole is the layer as a person says it: its values and its placement in one map, a new map.
|
||||
func (l Layer) Whole() map[string]any {
|
||||
out := make(map[string]any, len(l.Values)+len(l.Placement))
|
||||
for k, v := range l.Values {
|
||||
out[k] = v
|
||||
}
|
||||
for k, v := range l.Placement {
|
||||
out[k] = v
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// asSaid is the layers with placement folded back into the values, for what reads a layer whole as it
|
||||
// did while placement was kept in it: today's mergeable file, which takes every key (ADR 0326 §3), and
|
||||
// the judgement that no value holds a line end.
|
||||
func asSaid(layers []Layer) []Layer {
|
||||
out := make([]Layer, len(layers))
|
||||
for i, l := range layers {
|
||||
out[i] = l
|
||||
if len(l.Placement) > 0 {
|
||||
out[i] = Layer{From: l.From, Values: l.Whole(), Default: l.Default}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Placement is what an assignment says about one of a module's directories.
|
||||
type Placement struct {
|
||||
// Path is where the directory is on this machine. Absolute.
|
||||
@@ -208,7 +271,7 @@ func Places(m Manifest, layers []Layer) (map[string]Placement, error) {
|
||||
}
|
||||
out := map[string]Placement{}
|
||||
for _, layer := range layers {
|
||||
raw, ok := layer.Values[PlacesSetting]
|
||||
raw, ok := layer.Placement[PlacesSetting]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
@@ -278,7 +341,7 @@ func AccessPlaces(m Manifest, layers []Layer) (map[string]string, error) {
|
||||
}
|
||||
out := map[string]string{}
|
||||
for _, layer := range layers {
|
||||
raw, ok := layer.Values[AccessesSetting]
|
||||
raw, ok := layer.Placement[AccessesSetting]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user