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