Skip to content

Commit b1414a7

Browse files
authored
Merge pull request #300 from per1234/platform-pluggable-monitor-support
Add pluggable monitor support for platform projects
2 parents 9eeaf76 + 2d263ad commit b1414a7

File tree

21 files changed

+908
-34
lines changed

21 files changed

+908
-34
lines changed

Diff for: etc/schemas/arduino-platform-txt-definitions-schema.json

+194-1
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@
877877
"type": "string"
878878
},
879879
{
880-
"pattern": "^.+:.+$"
880+
"$ref": "#/definitions/patternObjects/resourceReference"
881881
}
882882
]
883883
}
@@ -910,6 +910,194 @@
910910
}
911911
}
912912
},
913+
"pluggableMonitorPattern": {
914+
"base": {
915+
"object": {
916+
"allOf": [
917+
{
918+
"type": "object"
919+
}
920+
]
921+
}
922+
},
923+
"permissive": {
924+
"object": {
925+
"allOf": [
926+
{
927+
"$ref": "#/definitions/propertiesObjects/pluggableMonitorPattern/base/object"
928+
},
929+
{
930+
"additionalProperties": {
931+
"$ref": "#/definitions/propertiesObjects/pluggableMonitorPatternProtocol/permissive/object"
932+
}
933+
}
934+
]
935+
}
936+
},
937+
"specification": {
938+
"object": {
939+
"allOf": [
940+
{
941+
"$ref": "#/definitions/propertiesObjects/pluggableMonitorPattern/base/object"
942+
},
943+
{
944+
"additionalProperties": {
945+
"$ref": "#/definitions/propertiesObjects/pluggableMonitorPatternProtocol/specification/object"
946+
}
947+
}
948+
]
949+
}
950+
},
951+
"strict": {
952+
"object": {
953+
"allOf": [
954+
{
955+
"$ref": "#/definitions/propertiesObjects/pluggableMonitorPattern/base/object"
956+
},
957+
{
958+
"additionalProperties": {
959+
"$ref": "#/definitions/propertiesObjects/pluggableMonitorPatternProtocol/strict/object"
960+
}
961+
}
962+
]
963+
}
964+
}
965+
},
966+
"pluggableMonitorPatternProtocol": {
967+
"base": {
968+
"object": {
969+
"allOf": [
970+
{
971+
"type": "string"
972+
},
973+
{
974+
"minLength": 1
975+
}
976+
]
977+
}
978+
},
979+
"permissive": {
980+
"object": {
981+
"allOf": [
982+
{
983+
"$ref": "#/definitions/propertiesObjects/pluggableMonitorPatternProtocol/base/object"
984+
}
985+
]
986+
}
987+
},
988+
"specification": {
989+
"object": {
990+
"allOf": [
991+
{
992+
"$ref": "#/definitions/propertiesObjects/pluggableMonitorPatternProtocol/base/object"
993+
}
994+
]
995+
}
996+
},
997+
"strict": {
998+
"object": {
999+
"allOf": [
1000+
{
1001+
"$ref": "#/definitions/propertiesObjects/pluggableMonitorPatternProtocol/base/object"
1002+
}
1003+
]
1004+
}
1005+
}
1006+
},
1007+
"pluggableMonitorRequired": {
1008+
"base": {
1009+
"object": {
1010+
"allOf": [
1011+
{
1012+
"type": "object"
1013+
}
1014+
]
1015+
}
1016+
},
1017+
"permissive": {
1018+
"object": {
1019+
"allOf": [
1020+
{
1021+
"$ref": "#/definitions/propertiesObjects/pluggableMonitorRequired/base/object"
1022+
},
1023+
{
1024+
"additionalProperties": {
1025+
"$ref": "#/definitions/propertiesObjects/pluggableMonitorRequiredProtocol/permissive/object"
1026+
}
1027+
}
1028+
]
1029+
}
1030+
},
1031+
"specification": {
1032+
"object": {
1033+
"allOf": [
1034+
{
1035+
"$ref": "#/definitions/propertiesObjects/pluggableMonitorRequired/base/object"
1036+
},
1037+
{
1038+
"additionalProperties": {
1039+
"$ref": "#/definitions/propertiesObjects/pluggableMonitorRequiredProtocol/specification/object"
1040+
}
1041+
}
1042+
]
1043+
}
1044+
},
1045+
"strict": {
1046+
"object": {
1047+
"allOf": [
1048+
{
1049+
"$ref": "#/definitions/propertiesObjects/pluggableMonitorRequired/base/object"
1050+
},
1051+
{
1052+
"additionalProperties": {
1053+
"$ref": "#/definitions/propertiesObjects/pluggableMonitorRequiredProtocol/strict/object"
1054+
}
1055+
}
1056+
]
1057+
}
1058+
}
1059+
},
1060+
"pluggableMonitorRequiredProtocol": {
1061+
"base": {
1062+
"object": {
1063+
"allOf": [
1064+
{
1065+
"type": "string"
1066+
},
1067+
{
1068+
"$ref": "#/definitions/patternObjects/resourceReference"
1069+
}
1070+
]
1071+
}
1072+
},
1073+
"permissive": {
1074+
"object": {
1075+
"allOf": [
1076+
{
1077+
"$ref": "#/definitions/propertiesObjects/pluggableMonitorRequiredProtocol/base/object"
1078+
}
1079+
]
1080+
}
1081+
},
1082+
"specification": {
1083+
"object": {
1084+
"allOf": [
1085+
{
1086+
"$ref": "#/definitions/propertiesObjects/pluggableMonitorRequiredProtocol/base/object"
1087+
}
1088+
]
1089+
}
1090+
},
1091+
"strict": {
1092+
"object": {
1093+
"allOf": [
1094+
{
1095+
"$ref": "#/definitions/propertiesObjects/pluggableMonitorRequiredProtocol/base/object"
1096+
}
1097+
]
1098+
}
1099+
}
1100+
},
9131101
"tools": {
9141102
"base": {
9151103
"object": {
@@ -1571,6 +1759,11 @@
15711759
}
15721760
}
15731761
},
1762+
"patternObjects": {
1763+
"resourceReference": {
1764+
"pattern": "^.+:.+$"
1765+
}
1766+
},
15741767
"requiredObjects": {
15751768
"root": {
15761769
"base": {

Diff for: etc/schemas/arduino-platform-txt-permissive-schema.json

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
"pluggable_discovery": {
5858
"$ref": "arduino-platform-txt-definitions-schema.json#/definitions/propertiesObjects/pluggableDiscovery/permissive/object"
5959
},
60+
"pluggable_monitor.pattern": {
61+
"$ref": "arduino-platform-txt-definitions-schema.json#/definitions/propertiesObjects/pluggableMonitorPattern/permissive/object"
62+
},
63+
"pluggable_monitor.required": {
64+
"$ref": "arduino-platform-txt-definitions-schema.json#/definitions/propertiesObjects/pluggableMonitorRequired/permissive/object"
65+
},
6066
"tools": {
6167
"$ref": "arduino-platform-txt-definitions-schema.json#/definitions/propertiesObjects/tools/permissive/object"
6268
}

Diff for: etc/schemas/arduino-platform-txt-schema.json

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
"pluggable_discovery": {
5858
"$ref": "arduino-platform-txt-definitions-schema.json#/definitions/propertiesObjects/pluggableDiscovery/specification/object"
5959
},
60+
"pluggable_monitor.pattern": {
61+
"$ref": "arduino-platform-txt-definitions-schema.json#/definitions/propertiesObjects/pluggableMonitorPattern/specification/object"
62+
},
63+
"pluggable_monitor.required": {
64+
"$ref": "arduino-platform-txt-definitions-schema.json#/definitions/propertiesObjects/pluggableMonitorRequired/specification/object"
65+
},
6066
"tools": {
6167
"$ref": "arduino-platform-txt-definitions-schema.json#/definitions/propertiesObjects/tools/specification/object"
6268
}

Diff for: etc/schemas/arduino-platform-txt-strict-schema.json

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
"pluggable_discovery": {
5858
"$ref": "arduino-platform-txt-definitions-schema.json#/definitions/propertiesObjects/pluggableDiscovery/strict/object"
5959
},
60+
"pluggable_monitor.pattern": {
61+
"$ref": "arduino-platform-txt-definitions-schema.json#/definitions/propertiesObjects/pluggableMonitorPattern/strict/object"
62+
},
63+
"pluggable_monitor.required": {
64+
"$ref": "arduino-platform-txt-definitions-schema.json#/definitions/propertiesObjects/pluggableMonitorRequired/strict/object"
65+
},
6066
"tools": {
6167
"$ref": "arduino-platform-txt-definitions-schema.json#/definitions/propertiesObjects/tools/strict/object"
6268
}

Diff for: internal/project/platform/platformtxt/platformtxt.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ func Validate(platformTxt *properties.Map) map[compliancelevel.Type]schema.Valid
5959
validation package.
6060
Even though platform.txt has a multi-level nested data structure, the format has the odd characteristic of allowing
6161
a key to be both an object and a string simultaneously, which is not compatible with Golang maps or JSON. So the
62-
data structure used is a selective map, using a flat map except for the tools and pluggable_discovery keys, which
63-
can contain any number of arbitrary subproperties which must be linted.
62+
data structure used is a selective map, using a flat map except for the tools, pluggable_discovery, and
63+
pluggable_monitor keys, which can contain any number of arbitrary subproperties which must be linted.
6464
*/
6565
platformTxtInterface := make(map[string]interface{})
6666
keys := platformTxt.Keys()
@@ -72,6 +72,10 @@ func Validate(platformTxt *properties.Map) map[compliancelevel.Type]schema.Valid
7272
// It is a pluggable_discovery.DISCOVERY_ID property.
7373
platformTxtInterface["pluggable_discovery"] = general.PropertiesToMap(platformTxt.SubTree("pluggable_discovery"), 2)
7474
}
75+
} else if strings.HasPrefix(key, "pluggable_monitor.pattern.") {
76+
platformTxtInterface["pluggable_monitor.pattern"] = general.PropertiesToMap(platformTxt.SubTree("pluggable_monitor.pattern"), 1)
77+
} else if strings.HasPrefix(key, "pluggable_monitor.required.") {
78+
platformTxtInterface["pluggable_monitor.required"] = general.PropertiesToMap(platformTxt.SubTree("pluggable_monitor.required"), 1)
7579
} else if strings.HasPrefix(key, "tools.") {
7680
platformTxtInterface["tools"] = general.PropertiesToMap(platformTxt.SubTree("tools"), 4)
7781
} else {

Diff for: internal/project/platform/platformtxt/platformtxt_test.go

+32-30
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,38 @@ func init() {
3939
testDataPath = workingDirectory.Join("testdata")
4040

4141
validPlatformTxtMap = map[string]string{
42-
"name": "Arduino AVR Boards",
43-
"version": "1.8.3",
44-
"compiler.warning_flags.none": "asdf",
45-
"compiler.warning_flags.default": "asdf",
46-
"compiler.warning_flags.more": "asdf",
47-
"compiler.warning_flags.all": "asdf",
48-
"compiler.c.extra_flags": "",
49-
"compiler.c.elf.extra_flags": "",
50-
"compiler.S.extra_flags": "",
51-
"compiler.cpp.extra_flags": "",
52-
"compiler.ar.extra_flags": "",
53-
"compiler.objcopy.eep.extra_flags": "",
54-
"compiler.elf2hex.extra_flags": "",
55-
"recipe.c.o.pattern": "asdf {compiler.c.extra_flags}",
56-
"recipe.cpp.o.pattern": "asdf {compiler.cpp.extra_flags}",
57-
"recipe.S.o.pattern": "asdf {compiler.S.extra_flags}",
58-
"recipe.ar.pattern": "asdf {compiler.ar.extra_flags}",
59-
"recipe.c.combine.pattern": "asdf {compiler.c.elf.extra_flags}",
60-
"recipe.objcopy.eep.pattern": "asdf",
61-
"recipe.objcopy.hex.pattern": "asdf",
62-
"recipe.output.tmp_file": "asdf",
63-
"recipe.output.save_file": "asdf",
64-
"recipe.size.pattern": "asdf",
65-
"recipe.size.regex": "asdf",
66-
"recipe.size.regex.data": "asdf",
67-
"pluggable_discovery.required.0": "builtin:serial-discovery",
68-
"pluggable_discovery.required.1": "builtin:mdns-discovery",
69-
"tools.avrdude.upload.params.verbose": "-v",
70-
"tools.avrdude.upload.params.quiet": "-q -q",
71-
"tools.avrdude.upload.pattern": "asdf",
42+
"name": "Arduino AVR Boards",
43+
"version": "1.8.3",
44+
"compiler.warning_flags.none": "asdf",
45+
"compiler.warning_flags.default": "asdf",
46+
"compiler.warning_flags.more": "asdf",
47+
"compiler.warning_flags.all": "asdf",
48+
"compiler.c.extra_flags": "",
49+
"compiler.c.elf.extra_flags": "",
50+
"compiler.S.extra_flags": "",
51+
"compiler.cpp.extra_flags": "",
52+
"compiler.ar.extra_flags": "",
53+
"compiler.objcopy.eep.extra_flags": "",
54+
"compiler.elf2hex.extra_flags": "",
55+
"recipe.c.o.pattern": "asdf {compiler.c.extra_flags}",
56+
"recipe.cpp.o.pattern": "asdf {compiler.cpp.extra_flags}",
57+
"recipe.S.o.pattern": "asdf {compiler.S.extra_flags}",
58+
"recipe.ar.pattern": "asdf {compiler.ar.extra_flags}",
59+
"recipe.c.combine.pattern": "asdf {compiler.c.elf.extra_flags}",
60+
"recipe.objcopy.eep.pattern": "asdf",
61+
"recipe.objcopy.hex.pattern": "asdf",
62+
"recipe.output.tmp_file": "asdf",
63+
"recipe.output.save_file": "asdf",
64+
"recipe.size.pattern": "asdf",
65+
"recipe.size.regex": "asdf",
66+
"recipe.size.regex.data": "asdf",
67+
"pluggable_discovery.required.0": "builtin:serial-discovery",
68+
"pluggable_discovery.required.1": "builtin:mdns-discovery",
69+
"pluggable_monitor.required.carrier-pigeon": "coop:coo",
70+
"pluggable_monitor.required.network": "foo:network-monitor",
71+
"tools.avrdude.upload.params.verbose": "-v",
72+
"tools.avrdude.upload.params.quiet": "-q -q",
73+
"tools.avrdude.upload.pattern": "asdf",
7274
}
7375
}
7476

Diff for: internal/project/platform/platformtxt/platformtxtschema_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ func TestMinLength(t *testing.T) {
124124
{"recipe.preproc.macros", "recipe\\.preproc\\.macros", 1, compliancelevel.Permissive},
125125
{"recipe.preproc.macros", "recipe\\.preproc\\.macros", 1, compliancelevel.Specification},
126126
{"recipe.preproc.macros", "recipe\\.preproc\\.macros", 1, compliancelevel.Strict},
127+
128+
{"pluggable_monitor.pattern.foo", "pluggable_monitor\\.pattern/foo", 1, compliancelevel.Permissive},
129+
{"pluggable_monitor.pattern.foo", "pluggable_monitor\\.pattern/foo", 1, compliancelevel.Specification},
130+
{"pluggable_monitor.pattern.foo", "pluggable_monitor\\.pattern/foo", 1, compliancelevel.Strict},
127131
}
128132

129133
// Test schema validation results with value length < minimum.
@@ -453,6 +457,13 @@ func TestPattern(t *testing.T) {
453457
{"pluggable_discovery.required.1", "pluggable_discovery/required", "foo", compliancelevel.Permissive, assert.True},
454458
{"pluggable_discovery.required.1", "pluggable_discovery/required", "foo", compliancelevel.Specification, assert.True},
455459
{"pluggable_discovery.required.1", "pluggable_discovery/required", "foo", compliancelevel.Strict, assert.True},
460+
461+
{"pluggable_monitor.required.foo", "pluggable_monitor\\.required/foo", "bar:baz", compliancelevel.Permissive, assert.False},
462+
{"pluggable_monitor.required.foo", "pluggable_monitor\\.required/foo", "bar:baz", compliancelevel.Specification, assert.False},
463+
{"pluggable_monitor.required.foo", "pluggable_monitor\\.required/foo", "bar:baz", compliancelevel.Strict, assert.False},
464+
{"pluggable_monitor.required.foo", "pluggable_monitor\\.required/foo", "bar", compliancelevel.Permissive, assert.True},
465+
{"pluggable_monitor.required.foo", "pluggable_monitor\\.required/foo", "bar", compliancelevel.Specification, assert.True},
466+
{"pluggable_monitor.required.foo", "pluggable_monitor\\.required/foo", "bar", compliancelevel.Strict, assert.True},
456467
}
457468

458469
for _, testTable := range testTables {

Diff for: internal/project/platform/platformtxt/testdata/valid/platform.txt

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ recipe.size.regex=asdf
2525
recipe.size.regex.data=asdf
2626
pluggable_discovery.required.0=builtin:serial-discovery
2727
pluggable_discovery.required.1=builtin:mdns-discovery
28+
pluggable_monitor.required.carrier-pigeon=coop:coo
29+
pluggable_monitor.required.network=foo:network-monitor
2830
tools.avrdude.upload.params.verbose=-v
2931
tools.avrdude.upload.params.quiet=-q -q
3032
tools.avrdude.upload.pattern=asdf

0 commit comments

Comments
 (0)