16
16
package builder
17
17
18
18
import (
19
- "bytes"
20
19
"strings"
21
20
22
- "github.com/arduino/arduino-cli/arduino/builder/logger"
23
21
"github.com/arduino/arduino-cli/arduino/builder/utils"
24
22
f "github.com/arduino/arduino-cli/internal/algorithms"
25
23
"github.com/arduino/go-paths-helper"
26
- "github.com/arduino/go-properties-orderedmap"
27
24
"github.com/pkg/errors"
28
25
)
29
26
30
- // Linker fixdoc
31
- func Linker (
27
+ // Link fixdoc
28
+ func ( b * Builder ) Link (
32
29
onlyUpdateCompilationDatabase bool ,
33
30
sketchObjectFiles , librariesObjectFiles , coreObjectsFiles paths.PathList ,
34
- coreArchiveFilePath , buildPath * paths.Path ,
35
- buildProperties * properties.Map ,
36
- builderLogger * logger.BuilderLogger ,
37
- ) ([]byte , error ) {
38
- verboseInfo := & bytes.Buffer {}
31
+ coreArchiveFilePath * paths.Path ,
32
+ ) error {
39
33
if onlyUpdateCompilationDatabase {
40
- if builderLogger .Verbose () {
41
- verboseInfo . WriteString (tr ("Skip linking of final executable." ))
34
+ if b . logger .Verbose () {
35
+ b . logger . Info (tr ("Skip linking of final executable." ))
42
36
}
43
- return verboseInfo . Bytes (), nil
37
+ return nil
44
38
}
45
39
40
+ // TODO can we remove this multiple assignations?
46
41
objectFilesSketch := sketchObjectFiles
47
42
objectFilesLibraries := librariesObjectFiles
48
43
objectFilesCore := coreObjectsFiles
@@ -52,25 +47,19 @@ func Linker(
52
47
objectFiles .AddAll (objectFilesLibraries )
53
48
objectFiles .AddAll (objectFilesCore )
54
49
55
- coreDotARelPath , err := buildPath .RelTo (coreArchiveFilePath )
50
+ coreDotARelPath , err := b . buildPath .RelTo (coreArchiveFilePath )
56
51
if err != nil {
57
- return nil , errors .WithStack (err )
52
+ return errors .WithStack (err )
58
53
}
59
54
60
- verboseInfoOut , err := link (objectFiles , coreDotARelPath , coreArchiveFilePath , buildProperties , builderLogger )
61
- verboseInfo .Write (verboseInfoOut )
62
- if err != nil {
63
- return verboseInfo .Bytes (), errors .WithStack (err )
55
+ if err := b .link (objectFiles , coreDotARelPath , coreArchiveFilePath ); err != nil {
56
+ return errors .WithStack (err )
64
57
}
65
58
66
- return verboseInfo . Bytes (), nil
59
+ return nil
67
60
}
68
61
69
- func link (
70
- objectFiles paths.PathList , coreDotARelPath * paths.Path , coreArchiveFilePath * paths.Path , buildProperties * properties.Map ,
71
- builderLogger * logger.BuilderLogger ,
72
- ) ([]byte , error ) {
73
- verboseBuffer := & bytes.Buffer {}
62
+ func (b * Builder ) link (objectFiles paths.PathList , coreDotARelPath * paths.Path , coreArchiveFilePath * paths.Path ) error {
74
63
wrapWithDoubleQuotes := func (value string ) string { return "\" " + value + "\" " }
75
64
objectFileList := strings .Join (f .Map (objectFiles .AsStrings (), wrapWithDoubleQuotes ), " " )
76
65
@@ -83,7 +72,7 @@ func link(
83
72
// it may happen that a subdir/spi.o inside the archive may be overwritten by a anotherdir/spi.o
84
73
// because thery are both named spi.o.
85
74
86
- properties := buildProperties .Clone ()
75
+ properties := b . buildProperties .Clone ()
87
76
archives := paths .NewPathList ()
88
77
for _ , object := range objectFiles {
89
78
if object .HasSuffix (".a" ) {
@@ -102,36 +91,36 @@ func link(
102
91
103
92
command , err := utils .PrepareCommandForRecipe (properties , "recipe.ar.pattern" , false )
104
93
if err != nil {
105
- return nil , errors .WithStack (err )
94
+ return errors .WithStack (err )
106
95
}
107
96
108
- if verboseInfo , _ , _ , err := utils .ExecCommand (builderLogger . Verbose (), builderLogger . Stdout (), builderLogger .Stderr (), command , utils .ShowIfVerbose /* stdout */ , utils .Show /* stderr */ ); err != nil {
109
- if builderLogger .Verbose () {
110
- verboseBuffer . WriteString (string (verboseInfo ))
97
+ if verboseInfo , _ , _ , err := utils .ExecCommand (b . logger . Verbose (), b . logger . Stdout (), b . logger .Stderr (), command , utils .ShowIfVerbose /* stdout */ , utils .Show /* stderr */ ); err != nil {
98
+ if b . logger .Verbose () {
99
+ b . logger . Info (string (verboseInfo ))
111
100
}
112
- return verboseBuffer . Bytes (), errors .WithStack (err )
101
+ return errors .WithStack (err )
113
102
}
114
103
}
115
104
116
105
objectFileList = strings .Join (f .Map (archives .AsStrings (), wrapWithDoubleQuotes ), " " )
117
106
objectFileList = "-Wl,--whole-archive " + objectFileList + " -Wl,--no-whole-archive"
118
107
}
119
108
120
- properties := buildProperties .Clone ()
109
+ properties := b . buildProperties .Clone ()
121
110
properties .Set ("compiler.c.elf.flags" , properties .Get ("compiler.c.elf.flags" ))
122
- properties .Set ("compiler.warning_flags" , properties .Get ("compiler.warning_flags." + builderLogger .WarningsLevel ()))
111
+ properties .Set ("compiler.warning_flags" , properties .Get ("compiler.warning_flags." + b . logger .WarningsLevel ()))
123
112
properties .Set ("archive_file" , coreDotARelPath .String ())
124
113
properties .Set ("archive_file_path" , coreArchiveFilePath .String ())
125
114
properties .Set ("object_files" , objectFileList )
126
115
127
116
command , err := utils .PrepareCommandForRecipe (properties , "recipe.c.combine.pattern" , false )
128
117
if err != nil {
129
- return verboseBuffer . Bytes (), err
118
+ return err
130
119
}
131
120
132
- verboseInfo , _ , _ , err := utils .ExecCommand (builderLogger . Verbose (), builderLogger . Stdout (), builderLogger .Stderr (), command , utils .ShowIfVerbose /* stdout */ , utils .Show /* stderr */ )
133
- if builderLogger .Verbose () {
134
- verboseBuffer . WriteString (string (verboseInfo ))
121
+ verboseInfo , _ , _ , err := utils .ExecCommand (b . logger . Verbose (), b . logger . Stdout (), b . logger .Stderr (), command , utils .ShowIfVerbose /* stdout */ , utils .Show /* stderr */ )
122
+ if b . logger .Verbose () {
123
+ b . logger . Info (string (verboseInfo ))
135
124
}
136
- return verboseBuffer . Bytes (), err
125
+ return err
137
126
}
0 commit comments