@@ -120,6 +120,11 @@ type Profile struct {
120
120
Libraries ProfileRequiredLibraries `yaml:"libraries"`
121
121
}
122
122
123
+ // UsesSystemPlatform checks if this profile requires a system installed platform.
124
+ func (p * Profile ) RequireSystemInstalledPlatform () bool {
125
+ return p .Platforms [0 ].RequireSystemInstalledPlatform ()
126
+ }
127
+
123
128
// ToRpc converts this Profile to an rpc.SketchProfile
124
129
func (p * Profile ) ToRpc () * rpc.SketchProfile {
125
130
var portConfig * rpc.MonitorPortConfiguration
@@ -206,6 +211,12 @@ type ProfilePlatformReference struct {
206
211
PlatformIndexURL * url.URL
207
212
}
208
213
214
+ // RequireSystemInstalledPlatform returns true if the platform reference
215
+ // does not specify a version, meaning it requires the system installed platform.
216
+ func (p * ProfilePlatformReference ) RequireSystemInstalledPlatform () bool {
217
+ return p .Version == nil
218
+ }
219
+
209
220
// InternalUniqueIdentifier returns the unique identifier for this object
210
221
func (p * ProfilePlatformReference ) InternalUniqueIdentifier () string {
211
222
id := p .String ()
@@ -224,20 +235,38 @@ func (p *ProfilePlatformReference) String() string {
224
235
225
236
// AsYaml outputs the platform reference as Yaml
226
237
func (p * ProfilePlatformReference ) AsYaml () string {
227
- res := fmt .Sprintf (" - platform: %s:%s (%s)\n " , p .Packager , p .Architecture , p .Version )
238
+ res := ""
239
+ if p .Version != nil {
240
+ res += fmt .Sprintf (" - platform: %s:%s (%s)\n " , p .Packager , p .Architecture , p .Version )
241
+ } else {
242
+ res += fmt .Sprintf (" - platform: %s:%s\n " , p .Packager , p .Architecture )
243
+ }
228
244
if p .PlatformIndexURL != nil {
229
245
res += fmt .Sprintf (" platform_index_url: %s\n " , p .PlatformIndexURL )
230
246
}
231
247
return res
232
248
}
233
249
234
250
func parseNameAndVersion (in string ) (string , string , bool ) {
235
- re := regexp .MustCompile (`^([a-zA-Z0-9.\-_ :]+) \((.+)\)$` )
236
- split := re .FindAllStringSubmatch (in , - 1 )
237
- if len (split ) != 1 || len (split [0 ]) != 3 {
238
- return "" , "" , false
251
+ {
252
+ // Try to parse the input string in the format "VENDOR:ARCH (VERSION)"
253
+ re := regexp .MustCompile (`^([a-zA-Z0-9.\-_ :]+) \((.+)\)$` )
254
+ split := re .FindAllStringSubmatch (in , - 1 )
255
+ if len (split ) == 1 && len (split [0 ]) == 3 {
256
+ return split [0 ][1 ], split [0 ][2 ], true
257
+ }
239
258
}
240
- return split [0 ][1 ], split [0 ][2 ], true
259
+
260
+ {
261
+ // Try to parse the input string in the format "VENDOR:ARCH"
262
+ re := regexp .MustCompile (`^([a-zA-Z0-9.\-_ :]+)$` )
263
+ split := re .FindAllStringSubmatch (in , - 1 )
264
+ if len (split ) == 1 && len (split [0 ]) == 2 {
265
+ return split [0 ][1 ], "" , true
266
+ }
267
+ }
268
+
269
+ return "" , "" , false
241
270
}
242
271
243
272
// UnmarshalYAML decodes a ProfilePlatformReference from YAML source.
@@ -250,14 +279,23 @@ func (p *ProfilePlatformReference) UnmarshalYAML(unmarshal func(interface{}) err
250
279
return errors .New (i18n .Tr ("missing '%s' directive" , "platform" ))
251
280
} else if platformID , platformVersion , ok := parseNameAndVersion (platformID ); ! ok {
252
281
return errors .New (i18n .Tr ("invalid '%s' directive" , "platform" ))
253
- } else if c , err := semver .Parse (platformVersion ); err != nil {
254
- return fmt .Errorf ("%s: %w" , i18n .Tr ("error parsing version constraints" ), err )
255
- } else if split := strings .SplitN (platformID , ":" , 2 ); len (split ) != 2 {
256
- return fmt .Errorf ("%s: %s" , i18n .Tr ("invalid platform identifier" ), platformID )
257
282
} else {
258
- p .Packager = split [0 ]
259
- p .Architecture = split [1 ]
260
- p .Version = c
283
+ var version * semver.Version
284
+ if platformVersion != "" {
285
+ if v , err := semver .Parse (platformVersion ); err != nil {
286
+ return fmt .Errorf ("%s: %w" , i18n .Tr ("error parsing version constraints" ), err )
287
+ } else {
288
+ version = v
289
+ }
290
+ }
291
+
292
+ if split := strings .SplitN (platformID , ":" , 2 ); len (split ) != 2 {
293
+ return fmt .Errorf ("%s: %s" , i18n .Tr ("invalid platform identifier" ), platformID )
294
+ } else {
295
+ p .Packager = split [0 ]
296
+ p .Architecture = split [1 ]
297
+ p .Version = version
298
+ }
261
299
}
262
300
263
301
if rawIndexURL , ok := data ["platform_index_url" ]; ok {
0 commit comments