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

Commitea0038f

Browse files
committed
Fixed algorithm for determination of required deps
1 parented87b28 commitea0038f

File tree

2 files changed

+178
-10
lines changed

2 files changed

+178
-10
lines changed

‎commands/service_profile_lib_remove.go‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ func (s *arduinoCoreServerImpl) ProfileLibRemove(ctx context.Context, req *rpc.P
8282

8383
// Get all the dependencies required by the profile excluding the removed library
8484
requiredDeps:=map[string]bool{}
85-
requiredDeps[libToRemove.String()]=true
8685
for_,profLib:=rangeprofile.Libraries {
8786
ifprofLib.IsDependency {
8887
continue
@@ -95,24 +94,21 @@ func (s *arduinoCoreServerImpl) ProfileLibRemove(ctx context.Context, req *rpc.P
9594
returnnil,&cmderrors.InvalidArgumentError{Cause:err,Message:"cannot resolve dependencies for installed libraries"}
9695
}
9796
for_,dep:=rangedeps {
98-
requiredDeps[dep.String()]=true
97+
requiredDeps[dep.Library.Name]=true
9998
}
10099
}
101100

102-
depsOfLibToRemove,err:=libraryResolveDependencies(li,libToRemove.Library,libToRemove.Version.String(),nil)
101+
candidateDepsToRemove,err:=libraryResolveDependencies(li,libToRemove.Library,libToRemove.Version.String(),nil)
103102
iferr!=nil {
104103
returnnil,&cmderrors.InvalidArgumentError{Cause:err,Message:"cannot resolve dependencies for installed libraries"}
105104
}
106105
// sort to make the output order deterministic
107-
slices.SortFunc(depsOfLibToRemove,librariesindex.ReleaseCompare)
108-
// deps contains the main library as well, so we skip it when removing dependencies
109-
for_,depToRemove:=rangedepsOfLibToRemove {
110-
ifrequiredDeps[depToRemove.String()] {
106+
slices.SortFunc(candidateDepsToRemove,librariesindex.ReleaseCompare)
107+
for_,depToRemove:=rangecandidateDepsToRemove {
108+
ifrequiredDeps[depToRemove.Library.Name] {
111109
continue
112110
}
113-
iferr:=remove(&sketch.ProfileLibraryReference{Library:depToRemove.Library.Name,Version:depToRemove.Version});err!=nil {
114-
returnnil,err
115-
}
111+
_=remove(&sketch.ProfileLibraryReference{Library:depToRemove.Library.Name,Version:depToRemove.Version})
116112
}
117113
}
118114

‎internal/integrationtest/daemon/profile_lib_commands_test.go‎

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,175 @@ default_profile: test
309309
`)
310310
}
311311
}
312+
313+
funcTestProfileLibRemoveWithDeps(t*testing.T) {
314+
env,cli:=integrationtest.CreateEnvForDaemon(t)
315+
t.Cleanup(env.CleanUp)
316+
317+
_,_,err:=cli.Run("core","update-index")
318+
require.NoError(t,err)
319+
_,_,err=cli.Run("core","install","arduino:avr")
320+
require.NoError(t,err)
321+
322+
tmp,err:=paths.MkTempDir("","")
323+
require.NoError(t,err)
324+
t.Cleanup(func() {tmp.RemoveAll() })
325+
sk:=tmp.Join("sketch")
326+
327+
// Create a new sketch
328+
_,_,err=cli.Run("sketch","new",sk.String())
329+
require.NoError(t,err)
330+
331+
grpcInst:=cli.Create()
332+
require.NoError(t,grpcInst.Init("","",func(ir*commands.InitResponse) {
333+
fmt.Printf("INIT> %v\n",ir.GetMessage())
334+
}))
335+
336+
// Create a new profile
337+
resp,err:=grpcInst.ProfileCreate(t.Context(),"test",sk.String(),"arduino:avr:uno",true)
338+
require.NoError(t,err)
339+
projectFile:=paths.New(resp.GetProjectFilePath())
340+
341+
expect:=func(expectedstring) {
342+
p,_:=projectFile.ReadFile()
343+
require.Equal(t,strings.TrimSpace(expected),strings.TrimSpace(string(p)))
344+
}
345+
expect(`
346+
profiles:
347+
test:
348+
fqbn: arduino:avr:uno
349+
platforms:
350+
- platform: arduino:avr (1.8.6)
351+
352+
default_profile: test
353+
`)
354+
355+
// Add a library to the profile
356+
{
357+
addresp,err:=grpcInst.ProfileLibAdd(t.Context(),sk.String(),"test",indexLib("Arduino_RouterBridge","0.2.2"),true,false)
358+
require.NoError(t,err)
359+
require.Equal(t,indexLibArray(
360+
indexLib("Arduino_RPClite","0.2.0",true),
361+
indexLib("Arduino_RouterBridge","0.2.2"),
362+
indexLib("ArxContainer","0.7.0",true),
363+
indexLib("ArxTypeTraits","0.3.2",true),
364+
indexLib("DebugLog","0.8.4",true),
365+
indexLib("MsgPack","0.4.2",true),
366+
),addresp.GetAddedLibraries())
367+
expect(`
368+
profiles:
369+
test:
370+
fqbn: arduino:avr:uno
371+
platforms:
372+
- platform: arduino:avr (1.8.6)
373+
libraries:
374+
- dependency: Arduino_RPClite (0.2.0)
375+
- Arduino_RouterBridge (0.2.2)
376+
- dependency: ArxContainer (0.7.0)
377+
- dependency: ArxTypeTraits (0.3.2)
378+
- dependency: DebugLog (0.8.4)
379+
- dependency: MsgPack (0.4.2)
380+
381+
default_profile: test
382+
`)
383+
}
384+
385+
// Remove the library (without indicating the version) and the dependencies
386+
{
387+
remresp,err:=grpcInst.ProfileLibRemove(t.Context(),sk.String(),"test",indexLib("Arduino_RouterBridge",""),true)
388+
require.NoError(t,err)
389+
require.Equal(t,indexLibArray(
390+
indexLib("Arduino_RouterBridge","0.2.2"),
391+
indexLib("Arduino_RPClite","0.2.0",true),
392+
indexLib("ArxContainer","0.7.0",true),
393+
indexLib("ArxTypeTraits","0.3.2",true),
394+
indexLib("DebugLog","0.8.4",true),
395+
indexLib("MsgPack","0.4.2",true),
396+
),remresp.GetRemovedLibraries())
397+
expect(`
398+
profiles:
399+
test:
400+
fqbn: arduino:avr:uno
401+
platforms:
402+
- platform: arduino:avr (1.8.6)
403+
404+
default_profile: test
405+
`)
406+
}
407+
408+
// Re-add the library to the profile
409+
{
410+
addresp,err:=grpcInst.ProfileLibAdd(t.Context(),sk.String(),"test",indexLib("Arduino_RouterBridge","0.2.2"),true,false)
411+
require.NoError(t,err)
412+
require.Equal(t,indexLibArray(
413+
indexLib("Arduino_RPClite","0.2.0",true),
414+
indexLib("Arduino_RouterBridge","0.2.2"),
415+
indexLib("ArxContainer","0.7.0",true),
416+
indexLib("ArxTypeTraits","0.3.2",true),
417+
indexLib("DebugLog","0.8.4",true),
418+
indexLib("MsgPack","0.4.2",true),
419+
),addresp.GetAddedLibraries())
420+
expect(`
421+
profiles:
422+
test:
423+
fqbn: arduino:avr:uno
424+
platforms:
425+
- platform: arduino:avr (1.8.6)
426+
libraries:
427+
- dependency: Arduino_RPClite (0.2.0)
428+
- Arduino_RouterBridge (0.2.2)
429+
- dependency: ArxContainer (0.7.0)
430+
- dependency: ArxTypeTraits (0.3.2)
431+
- dependency: DebugLog (0.8.4)
432+
- dependency: MsgPack (0.4.2)
433+
434+
default_profile: test
435+
`)
436+
}
437+
438+
// Remove one dep library (without indicating the version)
439+
{
440+
_,err:=grpcInst.ProfileLibRemove(t.Context(),sk.String(),"test",indexLib("Arduino_RPClite",""),true)
441+
require.NoError(t,err)
442+
// require.Equal(t, indexLibArray(
443+
// indexLib("Arduino_RPClite", "0.2.0", true),
444+
// ), remresp.GetRemovedLibraries())
445+
expect(`
446+
profiles:
447+
test:
448+
fqbn: arduino:avr:uno
449+
platforms:
450+
- platform: arduino:avr (1.8.6)
451+
libraries:
452+
- Arduino_RouterBridge (0.2.2)
453+
- dependency: ArxContainer (0.7.0)
454+
- dependency: ArxTypeTraits (0.3.2)
455+
- dependency: DebugLog (0.8.4)
456+
- dependency: MsgPack (0.4.2)
457+
458+
default_profile: test
459+
`)
460+
}
461+
462+
// Remove the library (without indicating the version) and all the dependencies
463+
{
464+
remresp,err:=grpcInst.ProfileLibRemove(t.Context(),sk.String(),"test",indexLib("Arduino_RouterBridge",""),true)
465+
require.NoError(t,err)
466+
require.Equal(t,indexLibArray(
467+
indexLib("Arduino_RouterBridge","0.2.2"),
468+
indexLib("ArxContainer","0.7.0",true),
469+
indexLib("ArxTypeTraits","0.3.2",true),
470+
indexLib("DebugLog","0.8.4",true),
471+
indexLib("MsgPack","0.4.2",true),
472+
),remresp.GetRemovedLibraries())
473+
expect(`
474+
profiles:
475+
test:
476+
fqbn: arduino:avr:uno
477+
platforms:
478+
- platform: arduino:avr (1.8.6)
479+
480+
default_profile: test
481+
`)
482+
}
483+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp