Skip to content

Commit fb57a52

Browse files
committed
Set builtin libraries dir by default when running as a daemon
1 parent 79702f8 commit fb57a52

File tree

3 files changed

+34
-30
lines changed

3 files changed

+34
-30
lines changed

Diff for: cli/daemon/daemon.go

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ func NewCommand() *cobra.Command {
7272
func runDaemonCommand(cmd *cobra.Command, args []string) {
7373
logrus.Info("Executing `arduino-cli daemon`")
7474

75+
// Bundled libraries support is enabled by default when running as a daemon
76+
configuration.Settings.SetDefault("directories.builtin.Libraries", configuration.GetDefaultBuiltinLibrariesDir())
77+
7578
port := configuration.Settings.GetString("daemon.port")
7679
gRPCOptions := []grpc.ServerOption{}
7780
if debugFile != "" {

Diff for: configuration/configuration.go

+5
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ func getDefaultUserDir() string {
131131
}
132132
}
133133

134+
// GetDefaultBuiltinLibrariesDir returns the full path to the default builtin libraries dir
135+
func GetDefaultBuiltinLibrariesDir() string {
136+
return filepath.Join(getDefaultArduinoDataDir(), "libraries")
137+
}
138+
134139
// FindConfigFileInArgsOrWorkingDirectory returns the config file path using the
135140
// argument '--config-file' (if specified) or looking in the current working dir
136141
func FindConfigFileInArgsOrWorkingDirectory(args []string) string {

Diff for: internal/integrationtest/daemon/daemon_lib_install_test.go

+26-30
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package daemon_test
1717

1818
import (
1919
"context"
20-
"encoding/json"
2120
"fmt"
2221
"io"
2322
"testing"
@@ -35,35 +34,6 @@ func TestDaemonBundleLibInstall(t *testing.T) {
3534
fmt.Printf("INIT> %v\n", ir.GetMessage())
3635
}))
3736

38-
// Install libraries in bundled dir (should fail)
39-
{
40-
instCl, err := grpcInst.LibraryInstall(context.Background(), "Arduino_BuiltIn", "", false, false, true)
41-
require.NoError(t, err)
42-
for {
43-
msg, err := instCl.Recv()
44-
if err == io.EOF {
45-
require.FailNow(t, "LibraryInstall is supposed to fail because builtin libraries directory is not set")
46-
}
47-
if err != nil {
48-
fmt.Println("LIB INSTALL ERROR:", err)
49-
break
50-
}
51-
fmt.Printf("LIB INSTALL> %+v\n", msg)
52-
}
53-
}
54-
55-
// Set builtin libraries dir
56-
builtinLibsDir := cli.DataDir().Join("libraries")
57-
jsonBuiltinLibsDir, err := json.Marshal(builtinLibsDir)
58-
require.NoError(t, err)
59-
err = cli.SetValue("directories.builtin.libraries", string(jsonBuiltinLibsDir))
60-
require.NoError(t, err)
61-
62-
// Re-init
63-
require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) {
64-
fmt.Printf("INIT> %v\n", ir.GetMessage())
65-
}))
66-
6737
// Install libraries in bundled dir
6838
{
6939
instCl, err := grpcInst.LibraryInstall(context.Background(), "Arduino_BuiltIn", "", false, false, true)
@@ -123,4 +93,30 @@ func TestDaemonBundleLibInstall(t *testing.T) {
12393
require.Equal(t, libsAndLocation["SD"], commands.LibraryLocation_LIBRARY_LOCATION_BUILTIN)
12494
require.Equal(t, libsAndLocation["Firmata"], commands.LibraryLocation_LIBRARY_LOCATION_BUILTIN)
12595
}
96+
97+
// Un-Set builtin libraries dir
98+
err := cli.SetValue("directories.builtin.libraries", `""`)
99+
require.NoError(t, err)
100+
101+
// Re-init
102+
require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) {
103+
fmt.Printf("INIT> %v\n", ir.GetMessage())
104+
}))
105+
106+
// Install libraries in bundled dir (should now fail)
107+
{
108+
instCl, err := grpcInst.LibraryInstall(context.Background(), "Arduino_BuiltIn", "", false, false, true)
109+
require.NoError(t, err)
110+
for {
111+
msg, err := instCl.Recv()
112+
if err == io.EOF {
113+
require.FailNow(t, "LibraryInstall is supposed to fail because builtin libraries directory is not set")
114+
}
115+
if err != nil {
116+
fmt.Println("LIB INSTALL ERROR:", err)
117+
break
118+
}
119+
fmt.Printf("LIB INSTALL> %+v\n", msg)
120+
}
121+
}
126122
}

0 commit comments

Comments
 (0)