Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-cli
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-cli
Commits
01de174c
Commit
01de174c
authored
Jan 24, 2024
by
Cristian Maglie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed an extremely rare race-condition during compile (#2512)
parent
5edfa984
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
13 deletions
+19
-13
arduino/builder/internal/compilation/database.go
arduino/builder/internal/compilation/database.go
+14
-8
arduino/builder/internal/compilation/database_test.go
arduino/builder/internal/compilation/database_test.go
+5
-5
No files found.
arduino/builder/internal/compilation/database.go
View file @
01de174c
...
...
@@ -19,6 +19,7 @@ import (
"encoding/json"
"fmt"
"os"
"sync"
"github.com/arduino/arduino-cli/executils"
"github.com/arduino/arduino-cli/i18n"
...
...
@@ -29,8 +30,9 @@ var tr = i18n.Tr
// Database keeps track of all the compile commands run by the builder
type
Database
struct
{
Contents
[]
Command
File
*
paths
.
Path
lock
sync
.
Mutex
contents
[]
Command
file
*
paths
.
Path
}
// Command keeps track of a single run of a compile command
...
...
@@ -44,8 +46,8 @@ type Command struct {
// NewDatabase creates an empty CompilationDatabase
func
NewDatabase
(
filename
*
paths
.
Path
)
*
Database
{
return
&
Database
{
F
ile
:
filename
,
C
ontents
:
[]
Command
{},
f
ile
:
filename
,
c
ontents
:
[]
Command
{},
}
}
...
...
@@ -56,16 +58,18 @@ func LoadDatabase(file *paths.Path) (*Database, error) {
return
nil
,
err
}
res
:=
NewDatabase
(
file
)
return
res
,
json
.
Unmarshal
(
f
,
&
res
.
C
ontents
)
return
res
,
json
.
Unmarshal
(
f
,
&
res
.
c
ontents
)
}
// SaveToFile save the CompilationDatabase to file as a clangd-compatible compile_commands.json,
// see https://clang.llvm.org/docs/JSONCompilationDatabase.html
func
(
db
*
Database
)
SaveToFile
()
{
if
jsonContents
,
err
:=
json
.
MarshalIndent
(
db
.
Contents
,
""
,
" "
);
err
!=
nil
{
db
.
lock
.
Lock
()
defer
db
.
lock
.
Unlock
()
if
jsonContents
,
err
:=
json
.
MarshalIndent
(
db
.
contents
,
""
,
" "
);
err
!=
nil
{
fmt
.
Println
(
tr
(
"Error serializing compilation database: %s"
,
err
))
return
}
else
if
err
:=
db
.
F
ile
.
WriteFile
(
jsonContents
);
err
!=
nil
{
}
else
if
err
:=
db
.
f
ile
.
WriteFile
(
jsonContents
);
err
!=
nil
{
fmt
.
Println
(
tr
(
"Error writing compilation database: %s"
,
err
))
}
}
...
...
@@ -89,5 +93,7 @@ func (db *Database) Add(target *paths.Path, command *executils.Process) {
File
:
target
.
String
(),
}
db
.
Contents
=
append
(
db
.
Contents
,
entry
)
db
.
lock
.
Lock
()
db
.
contents
=
append
(
db
.
contents
,
entry
)
db
.
lock
.
Unlock
()
}
arduino/builder/internal/compilation/database_test.go
View file @
01de174c
...
...
@@ -37,11 +37,11 @@ func TestCompilationDatabase(t *testing.T) {
db2
,
err
:=
LoadDatabase
(
tmpfile
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
db
,
db2
)
require
.
Len
(
t
,
db2
.
C
ontents
,
1
)
require
.
Equal
(
t
,
db2
.
C
ontents
[
0
]
.
File
,
"test"
)
require
.
Equal
(
t
,
db2
.
C
ontents
[
0
]
.
Command
,
""
)
require
.
Equal
(
t
,
db2
.
C
ontents
[
0
]
.
Arguments
,
[]
string
{
"gcc"
,
"arg1"
,
"arg2"
})
require
.
Len
(
t
,
db2
.
c
ontents
,
1
)
require
.
Equal
(
t
,
db2
.
c
ontents
[
0
]
.
File
,
"test"
)
require
.
Equal
(
t
,
db2
.
c
ontents
[
0
]
.
Command
,
""
)
require
.
Equal
(
t
,
db2
.
c
ontents
[
0
]
.
Arguments
,
[]
string
{
"gcc"
,
"arg1"
,
"arg2"
})
cwd
,
err
:=
paths
.
Getwd
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
db2
.
C
ontents
[
0
]
.
Directory
,
cwd
.
String
())
require
.
Equal
(
t
,
db2
.
c
ontents
[
0
]
.
Directory
,
cwd
.
String
())
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment