Skip to content

Commit cf8fd8f

Browse files
committed
compilation database: added LoadCompilationDatabase method
1 parent 355dd3e commit cf8fd8f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Diff for: arduino/builder/compilation_database.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ type CompilationDatabase struct {
3333
// CompilationCommand keeps track of a single run of a compile command
3434
type CompilationCommand struct {
3535
Directory string `json:"directory"`
36-
Arguments []string `json:"arguments"`
36+
Command string `json:"command,omitempty"`
37+
Arguments []string `json:"arguments,omitempty"`
3738
File string `json:"file"`
3839
}
3940

@@ -44,6 +45,19 @@ func NewCompilationDatabase(filename *paths.Path) *CompilationDatabase {
4445
}
4546
}
4647

48+
// LoadCompilationDatabase reads a compilation database from a file
49+
func LoadCompilationDatabase(file *paths.Path) (*CompilationDatabase, error) {
50+
f, err := file.ReadFile()
51+
if err != nil {
52+
return nil, err
53+
}
54+
res := &CompilationDatabase{
55+
File: file,
56+
Contents: []CompilationCommand{},
57+
}
58+
return res, json.Unmarshal(f, &res.Contents)
59+
}
60+
4761
// SaveToFile save the CompilationDatabase to file as a clangd-compatible compile_commands.json,
4862
// see https://clang.llvm.org/docs/JSONCompilationDatabase.html
4963
func (db *CompilationDatabase) SaveToFile() {

0 commit comments

Comments
 (0)