Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita77f39c

Browse files
committed
Added support for git-libraries in profiles
1 parentb1f3a84 commita77f39c

File tree

4 files changed

+112
-10
lines changed

4 files changed

+112
-10
lines changed

‎commands/instances.go‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,39 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
388388
continue
389389
}
390390

391+
iflibraryRef.GitURL!=nil {
392+
uid:=libraryRef.InternalUniqueIdentifier()
393+
libRoot:=s.settings.ProfilesCacheDir().Join(uid)
394+
libDir:=libRoot.Join(libraryRef.Library)
395+
396+
if!libDir.IsDir() {
397+
// Clone repo and install
398+
tmpDir,err:=librariesmanager.CloneLibraryGitRepository(ctx,libraryRef.GitURL.String())
399+
iferr!=nil {
400+
taskCallback(&rpc.TaskProgress{Name:i18n.Tr("Error downloading library %s",libraryRef)})
401+
e:=&cmderrors.FailedLibraryInstallError{Cause:err}
402+
responseError(e.GRPCStatus())
403+
continue
404+
}
405+
defertmpDir.RemoveAll()
406+
407+
// Install library into profile cache
408+
iferr:=tmpDir.CopyDirTo(libDir);err!=nil {
409+
taskCallback(&rpc.TaskProgress{Name:i18n.Tr("Error installing library %s",libraryRef)})
410+
e:=&cmderrors.FailedLibraryInstallError{Cause:fmt.Errorf("copying library to profile cache: %w",err)}
411+
responseError(e.GRPCStatus())
412+
continue
413+
}
414+
}
415+
416+
lmb.AddLibrariesDir(librariesmanager.LibrariesDir{
417+
Path:libDir,
418+
Location:libraries.Profile,
419+
IsSingleLibrary:true,
420+
})
421+
continue
422+
}
423+
391424
uid:=libraryRef.InternalUniqueIdentifier()
392425
libRoot:=s.settings.ProfilesCacheDir().Join(uid)
393426
libDir:=libRoot.Join(libraryRef.Library)

‎internal/arduino/sketch/profiles.go‎

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"errors"
2222
"fmt"
2323
"net/url"
24+
"path/filepath"
2425
"regexp"
2526
"strings"
2627

@@ -325,23 +326,39 @@ func (p *ProfilePlatformReference) UnmarshalYAML(unmarshal func(interface{}) err
325326
// ProfileLibraryReference is a reference to a library
326327
typeProfileLibraryReferencestruct {
327328
Librarystring
328-
InstallDir*paths.Path
329329
Version*semver.Version
330+
InstallDir*paths.Path
331+
GitURL*url.URL
330332
}
331333

332334
// UnmarshalYAML decodes a ProfileLibraryReference from YAML source.
333335
func (l*ProfileLibraryReference)UnmarshalYAML(unmarshalfunc(interface{})error)error {
334336
vardataMapmap[string]any
335337
iferr:=unmarshal(&dataMap);err==nil {
336-
ifinstallDir,ok:=dataMap["dir"];!ok {
337-
returnerrors.New(i18n.Tr("invalid library reference: %s",dataMap))
338-
}elseifinstallDir,ok:=installDir.(string);!ok {
339-
returnfmt.Errorf("%s: %s",i18n.Tr("invalid library reference: %s"),dataMap)
340-
}else {
341-
l.InstallDir=paths.New(installDir)
342-
l.Library=l.InstallDir.Base()
343-
returnnil
338+
ifinstallDir,ok:=dataMap["dir"];ok {
339+
ifinstallDir,ok:=installDir.(string);!ok {
340+
returnfmt.Errorf("%s: %s",i18n.Tr("invalid library reference: %s"),dataMap)
341+
}else {
342+
l.InstallDir=paths.New(installDir)
343+
l.Library=l.InstallDir.Base()
344+
returnnil
345+
}
346+
}
347+
ifgitUrl,ok:=dataMap["git"];ok {
348+
ifgitUrlStr,ok:=gitUrl.(string);!ok {
349+
returnfmt.Errorf("%s: %s",i18n.Tr("invalid git library reference: %s"),dataMap)
350+
}elseifparsedUrl,err:=url.Parse(gitUrlStr);err!=nil {
351+
returnfmt.Errorf("%s: %w",i18n.Tr("invalid git library URL:"),err)
352+
}else {
353+
l.GitURL=parsedUrl
354+
ifl.Library=filepath.Base(parsedUrl.Path);l.Library=="" {
355+
l.Library="lib"
356+
}
357+
l.Library=strings.TrimSuffix(l.Library,".git")
358+
returnnil
359+
}
344360
}
361+
returnerrors.New(i18n.Tr("invalid library reference: %s",dataMap))
345362
}
346363

347364
vardatastring
@@ -364,12 +381,18 @@ func (l *ProfileLibraryReference) AsYaml() string {
364381
ifl.InstallDir!=nil {
365382
returnfmt.Sprintf(" - dir: %s\n",l.InstallDir)
366383
}
384+
ifl.GitURL!=nil {
385+
returnfmt.Sprintf(" - git: %s\n",l.GitURL)
386+
}
367387
returnfmt.Sprintf(" - %s (%s)\n",l.Library,l.Version)
368388
}
369389

370390
func (l*ProfileLibraryReference)String()string {
371391
ifl.InstallDir!=nil {
372-
returnfmt.Sprintf("%s@dir:%s",l.Library,l.InstallDir)
392+
return"@dir:"+l.InstallDir.String()
393+
}
394+
ifl.GitURL!=nil {
395+
return"@git:"+l.GitURL.String()
373396
}
374397
returnfmt.Sprintf("%s@%s",l.Library,l.Version)
375398
}
@@ -378,6 +401,16 @@ func (l *ProfileLibraryReference) String() string {
378401
func (l*ProfileLibraryReference)InternalUniqueIdentifier()string {
379402
f.Assert(l.InstallDir==nil,
380403
"InternalUniqueIdentifier should not be called for library references with an install directory")
404+
405+
ifl.GitURL!=nil {
406+
id:="git-"+utils.SanitizeName(l.GitURL.Host+l.GitURL.Path+"#"+l.GitURL.Fragment)
407+
iflen(id)>50 {
408+
id=id[:50]
409+
}
410+
h:=sha256.Sum256([]byte(l.GitURL.String()))
411+
returnid+"-"+hex.EncodeToString(h[:])[:8]
412+
}
413+
381414
id:=l.String()
382415
h:=sha256.Sum256([]byte(id))
383416
res:=fmt.Sprintf("%s_%s",id,hex.EncodeToString(h[:])[:16])

‎internal/arduino/sketch/profiles_test.go‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,26 @@ func TestProjectFileLoading(t *testing.T) {
5353
require.Error(t,err)
5454
}
5555
}
56+
57+
funcTestProjectFileLibraries(t*testing.T) {
58+
sketchProj:=paths.New("testdata","profiles","profile_with_libraries.yml")
59+
proj,err:=LoadProjectFile(sketchProj)
60+
require.NoError(t,err)
61+
require.Len(t,proj.Profiles,1)
62+
prof:=proj.Profiles[0]
63+
require.Len(t,prof.Libraries,5)
64+
require.Equal(t,"FlashStorage@1.2.3",prof.Libraries[0].String())
65+
require.Equal(t,"@dir:/path/to/system/lib",prof.Libraries[1].String())
66+
require.Equal(t,"@dir:path/to/sketch/lib",prof.Libraries[2].String())
67+
require.Equal(t,"@git:https://github.com/username/HelloWorld.git#v2.13",prof.Libraries[3].String())
68+
require.Equal(t,"@git:https://github.com/username/HelloWorld.git#v2.14",prof.Libraries[4].String())
69+
require.Equal(t,"FlashStorage_1.2.3_e525d7c96b27788f",prof.Libraries[0].InternalUniqueIdentifier())
70+
require.Panics(t,func() {prof.Libraries[1].InternalUniqueIdentifier() })
71+
require.Panics(t,func() {prof.Libraries[2].InternalUniqueIdentifier() })
72+
require.Equal(t,"git-github.com_username_HelloWorld.git_v2.13-0c146203",prof.Libraries[3].InternalUniqueIdentifier())
73+
require.Equal(t,"git-github.com_username_HelloWorld.git_v2.14-49f5df7f",prof.Libraries[4].InternalUniqueIdentifier())
74+
75+
orig,err:=sketchProj.ReadFile()
76+
require.NoError(t,err)
77+
require.Equal(t,string(orig),proj.AsYaml())
78+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
profiles:
2+
giga:
3+
fqbn:arduino:mbed_giga:giga
4+
platforms:
5+
-platform:arduino:mbed_giga (4.3.1)
6+
libraries:
7+
-FlashStorage (1.2.3)
8+
-dir:/path/to/system/lib
9+
-dir:path/to/sketch/lib
10+
-git:https://github.com/username/HelloWorld.git#v2.13
11+
-git:https://github.com/username/HelloWorld.git#v2.14
12+
13+
default_profile:giga_any

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp