Skip to content

Commit 6991d7e

Browse files
committed
update fixtures to remove pref-key in favor of pref
1 parent b6284c5 commit 6991d7e

File tree

17 files changed

+134
-85
lines changed

17 files changed

+134
-85
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
## 🦊 What's Changed 🦊
2121

22+
### Nimbus FML ⛅️🔬🔭🔧
23+
- Updated Nimbus FML to support pref key+branch being set on feature properties (#[6788](https://github.com/mozilla/application-services/pull/6788)).
24+
2225
### Context ID
2326
- The `ContextIDComponent` constructor no longer throws an error. This is not a breaking change since neither iOS or Android implement this yet.
2427
- The `ContextIDComponent` constructor can now synchronously invoke the rotation callback when it receives an invalid timestamp from callers; in such cases, it falls back to the current timestamp and forces an ID rotation.

components/nimbus/android/src/main/java/org/mozilla/experiments/nimbus/internal/FeatureManifestInterface.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ package org.mozilla.experiments.nimbus.internal
66

77
import org.mozilla.experiments.nimbus.FeaturesInterface
88

9+
data class GeckoPref(
10+
val pref: String,
11+
val branch: String,
12+
)
13+
914
interface FeatureManifestInterface<T> {
1015
/**
1116
* This method should be called as early in the startup sequence of the app as possible.
@@ -44,7 +49,5 @@ interface FeatureManifestInterface<T> {
4449

4550
fun getCoenrollingFeatureIds(): List<String>
4651

47-
fun prefsToBranchesMap(): Map<String, String>
48-
49-
fun prefsToFeatureIdsMap(): Map<String, String>
52+
fun geckoPrefsMap(): Map<String, Map<String, GeckoPref>>
5053
}

components/support/nimbus-fml/fixtures/fe/browser-with-prefs.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ features:
102102
pref-string:
103103
description: Test of pref string
104104
type: String
105-
pref:
106-
key: "my.pref.key.string"
105+
gecko-pref:
106+
pref: "my.pref.key.string"
107107
branch: "default"
108108
default: ""
109109
pref-bool:
110110
description: Test of pref bool
111111
type: Boolean
112-
pref:
113-
key: "my.pref.key.bool"
112+
gecko-pref:
113+
pref: "my.pref.key.bool"
114114
branch: "user"
115115
default: false
116116
search-term-groups:

components/support/nimbus-fml/fixtures/fe/misc-features.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ channels:
1111
- debug
1212
features:
1313
onboarding:
14-
description: A feature containing a field with pref-key
14+
description: A feature containing a field with pref
1515
variables:
1616
enabled:
1717
description: If true, enable new style onboarding.
1818
type: Boolean
19-
pref-key: enrollment_enabled
19+
pref:
20+
key: enrollment_enabled
21+
branch: default
2022
default: false
2123
messaging:
2224
description: A feature allowing coenrollment

components/support/nimbus-fml/fixtures/fe/pref_overrides.fml.yaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,28 @@ features:
1616
my-boolean:
1717
type: Boolean
1818
description: A boolean
19-
pref-key: my-boolean-pref-key
19+
pref:
20+
key: my-boolean-pref-key
21+
branch: default
2022
default: false
2123
my-int:
2224
type: Int
2325
description: An Int
24-
pref-key: my-int-pref-key
26+
pref:
27+
key: my-int-pref-key
28+
branch: default
2529
default: 0
2630
my-string:
2731
type: String
2832
description: A String
29-
pref-key: my-string-pref-key
33+
pref:
34+
key: my-string-pref-key
35+
branch: default
3036
default: from manifest
3137
my-text:
3238
type: Text
3339
description: A Text
34-
pref-key: my-text-pref-key
40+
pref:
41+
key: my-text-pref-key
42+
branch: default
3543
default: from manifest

components/support/nimbus-fml/src/backends/frontend_manifest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ impl From<PropDef> for FieldBody {
140140
}
141141

142142
impl From<PropDef> for FeatureFieldBody {
143-
#[allow(deprecated)]
144143
fn from(value: PropDef) -> Self {
145144
Self {
146-
pref: value.pref.clone(),
145+
pref_key: value.pref_key.clone(),
146+
gecko_pref: value.gecko_pref.clone(),
147147
string_alias: value.string_alias.as_ref().map(TypeRef::to_string),
148148
field: value.into(),
149149
}

components/support/nimbus-fml/src/backends/kotlin/gen_structs/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::collections::HashSet;
88
use crate::intermediate_representation::PropDef;
99
use crate::{
1010
backends::{CodeDeclaration, CodeOracle, CodeType, TypeIdentifier},
11-
intermediate_representation::{FeatureDef, FeatureManifest, PrefDef, TypeFinder},
11+
intermediate_representation::{FeatureDef, FeatureManifest, GeckoPrefDef, TypeFinder},
1212
};
1313

1414
mod bundled;
@@ -78,13 +78,13 @@ impl<'a> FeatureManifestDeclaration<'a> {
7878
}
7979

8080
#[allow(unused)]
81-
pub fn iter_prefs(&self) -> Vec<&PrefDef> {
82-
self.fm.iter_prefs().collect::<_>()
81+
pub fn iter_gecko_prefs(&self) -> Vec<&GeckoPrefDef> {
82+
self.fm.iter_gecko_prefs().collect::<_>()
8383
}
8484

8585
#[allow(unused)]
86-
pub fn iter_prefs_with_feature(&self) -> Vec<(&PrefDef, String)> {
87-
self.fm.iter_prefs_with_feature().collect::<_>()
86+
pub fn iter_features_with_prefs(&self) -> Vec<(String, Vec<(String, &GeckoPrefDef)>)> {
87+
self.fm.iter_features_with_prefs().collect::<_>()
8888
}
8989

9090
pub fn initialization_code(&self) -> Vec<String> {
@@ -126,6 +126,7 @@ impl<'a> FeatureManifestDeclaration<'a> {
126126
"org.mozilla.experiments.nimbus.Variables".to_string(),
127127
"org.mozilla.experiments.nimbus.internal.FeatureHolder".to_string(),
128128
"org.mozilla.experiments.nimbus.internal.FeatureManifestInterface".to_string(),
129+
"org.mozilla.experiments.nimbus.internal.GeckoPref".to_string(),
129130
"org.mozilla.experiments.nimbus.FeaturesInterface".to_string(),
130131
"org.json.JSONObject".to_string(),
131132
"android.content.SharedPreferences".to_string(),

components/support/nimbus-fml/src/backends/kotlin/templates/FeatureManifestTemplate.kt

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,18 @@ object {{ nimbus_object }} : FeatureManifestInterface<{{ nimbus_object }}.Featur
105105
{%- if !loop.last %}, {% endif %}
106106
{%- endfor %})
107107

108-
/**
109-
* Get a map of prefs to their respective branches.
110-
*/
111-
override fun prefsToBranchesMap(): Map<String, String> =
112-
mapOf(
113-
{%- for f in self.fm.iter_prefs() %}
114-
{{ f.branch()|quoted }} to {{ f.key()|quoted }}
115-
{%- if !loop.last %},{% endif -%}
116-
{% endfor %}
117-
)
118-
119108
/**
120109
* Get a map of prefs to their repective feature IDs.
121110
*/
122-
override fun prefsToFeatureIdsMap(): Map<String, String> =
111+
override fun geckoPrefsMap(): Map<String, Map<String, GeckoPref>> =
123112
mapOf(
124-
{%- for f in self.fm.iter_prefs_with_feature() %}
125-
{{ f.1|quoted }} to {{ f.0.key()|quoted }}
113+
{%- for f in self.fm.iter_features_with_prefs() %}
114+
{{ f.0|quoted }} to mapOf(
115+
{%- for p in f.1.iter() %}
116+
{{ p.0|quoted }} to GeckoPref({{ p.1.pref()|quoted }}, {{ p.1.branch()|quoted }})
117+
{%- if !loop.last %},{% endif -%}
118+
{% endfor %}
119+
)
126120
{%- if !loop.last %},{% endif -%}
127121
{% endfor %}
128122
)

components/support/nimbus-fml/src/backends/kotlin/templates/FeatureTemplate.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ public class {{ inner.name()|class_name }} {% call kt::render_constructor() %}
1111
listOf(
1212
{%- for p in inner.props() %}
1313
{%- if p.has_prefs() %}
14-
{{ p.pref().unwrap().key()|quoted }},
14+
{{ p.pref_key().unwrap()|quoted }},
15+
{%- endif %}
16+
{%- if p.has_gecko_prefs() %}
17+
{{ p.gecko_pref().unwrap().pref()|quoted }},
1518
{%- endif %}
1619
{%- endfor %}
1720
).any { prefs.contains(it) }

components/support/nimbus-fml/src/backends/kotlin/templates/macros.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private constructor(
5555
val {{ prop_kt }}: {{ type_kt }}
5656
get() =
5757
{%- let prefs = "it" %}
58-
{%- let key = p.pref().unwrap().key() %}
58+
{%- let key = p.pref_key().unwrap() %}
5959
{% call prefs() %}?.let {
6060
if ({{ prefs }}.contains({{ key|quoted }})) {
6161
try {

0 commit comments

Comments
 (0)