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

Commit92fae9c

Browse files
authored
On compile command: implemented--quiet flag / removed libraries recap on default verbosity level. (#2820)
* Made builder logger verbosity an explicit type* Compile with --quiet flag set will not output final stats* Suppress size output if --quiet is specified* Added -q shortcut to --quiet flag in compile command* Compile recap is hidden also on a successful compile with default verbosity* Made --quiet and --verbose mutually exclusive* Output 'ctags' command line to stdout instead of stderr* Do not output empty lines if the message is empty* Added integration tests* Use internal function to check for arguments exclusivityBecause it has a better error message than the cobra-provided one: Can't use the following flags together: --quiet, --verboseInstead of: Error: if any flags in the group [quiet verbose] are set none of the others can be; [quiet verbose] were all set
1 parentc5cfe4a commit92fae9c

File tree

16 files changed

+209
-68
lines changed

16 files changed

+209
-68
lines changed

‎commands/service_compile.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/arduino/arduino-cli/commands/cmderrors"
2929
"github.com/arduino/arduino-cli/commands/internal/instances"
3030
"github.com/arduino/arduino-cli/internal/arduino/builder"
31+
"github.com/arduino/arduino-cli/internal/arduino/builder/logger"
3132
"github.com/arduino/arduino-cli/internal/arduino/libraries/librariesmanager"
3233
"github.com/arduino/arduino-cli/internal/arduino/sketch"
3334
"github.com/arduino/arduino-cli/internal/arduino/utils"
@@ -244,6 +245,13 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
244245
Message:&rpc.CompileResponse_Progress{Progress:p},
245246
})
246247
}
248+
varverbosity logger.Verbosity=logger.VerbosityNormal
249+
ifreq.GetQuiet() {
250+
verbosity=logger.VerbosityQuiet
251+
}
252+
ifreq.GetVerbose() {
253+
verbosity=logger.VerbosityVerbose
254+
}
247255
sketchBuilder,err:=builder.NewBuilder(
248256
ctx,
249257
sk,
@@ -265,7 +273,7 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
265273
req.GetSkipLibrariesDiscovery(),
266274
libsManager,
267275
paths.NewPathList(req.GetLibrary()...),
268-
outStream,errStream,req.GetVerbose(),req.GetWarnings(),
276+
outStream,errStream,verbosity,req.GetWarnings(),
269277
progressCB,
270278
pme.GetEnvVarsForSpawnedProcess(),
271279
)

‎internal/arduino/builder/archive_compiled_files.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
package builder
1717

1818
import (
19+
"github.com/arduino/arduino-cli/internal/arduino/builder/logger"
1920
"github.com/arduino/arduino-cli/internal/i18n"
2021
"github.com/arduino/go-paths-helper"
2122
)
2223

2324
// ArchiveCompiledFiles fixdoc
2425
func (b*Builder)archiveCompiledFiles(archiveFilePath*paths.Path,objectFilesToArchive paths.PathList) (*paths.Path,error) {
2526
ifb.onlyUpdateCompilationDatabase {
26-
ifb.logger.Verbose() {
27+
ifb.logger.VerbosityLevel()==logger.VerbosityVerbose {
2728
b.logger.Info(i18n.Tr("Skipping archive creation of: %[1]s",archiveFilePath))
2829
}
2930
returnarchiveFilePath,nil
@@ -46,7 +47,7 @@ func (b *Builder) archiveCompiledFiles(archiveFilePath *paths.Path, objectFilesT
4647
returnnil,err
4748
}
4849
}else {
49-
ifb.logger.Verbose() {
50+
ifb.logger.VerbosityLevel()==logger.VerbosityVerbose {
5051
b.logger.Info(i18n.Tr("Using previously compiled file: %[1]s",archiveFilePath))
5152
}
5253
returnarchiveFilePath,nil

‎internal/arduino/builder/builder.go‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import (
2727
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/compilation"
2828
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/detector"
2929
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/diagnostics"
30-
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/logger"
3130
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/progress"
3231
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/utils"
32+
"github.com/arduino/arduino-cli/internal/arduino/builder/logger"
3333
"github.com/arduino/arduino-cli/internal/arduino/cores"
3434
"github.com/arduino/arduino-cli/internal/arduino/libraries"
3535
"github.com/arduino/arduino-cli/internal/arduino/libraries/librariesmanager"
@@ -136,7 +136,7 @@ func NewBuilder(
136136
useCachedLibrariesResolutionbool,
137137
librariesManager*librariesmanager.LibrariesManager,
138138
libraryDirs paths.PathList,
139-
stdout,stderr io.Writer,verbosebool,warningsLevelstring,
139+
stdout,stderr io.Writer,verbosity logger.Verbosity,warningsLevelstring,
140140
progresCB rpc.TaskProgressCB,
141141
toolEnv []string,
142142
) (*Builder,error) {
@@ -189,7 +189,7 @@ func NewBuilder(
189189
returnnil,ErrSketchCannotBeLocatedInBuildPath
190190
}
191191

192-
logger:=logger.New(stdout,stderr,verbose,warningsLevel)
192+
log:=logger.New(stdout,stderr,verbosity,warningsLevel)
193193
libsManager,libsResolver,verboseOut,err:=detector.LibrariesLoader(
194194
useCachedLibrariesResolution,librariesManager,
195195
builtInLibrariesDirs,libraryDirs,otherLibrariesDirs,
@@ -198,8 +198,8 @@ func NewBuilder(
198198
iferr!=nil {
199199
returnnil,err
200200
}
201-
iflogger.Verbose() {
202-
logger.Warn(string(verboseOut))
201+
iflog.VerbosityLevel()==logger.VerbosityVerbose {
202+
log.Warn(string(verboseOut))
203203
}
204204

205205
diagnosticStore:=diagnostics.NewStore()
@@ -215,7 +215,7 @@ func NewBuilder(
215215
customBuildProperties:customBuildPropertiesArgs,
216216
coreBuildCachePath:coreBuildCachePath,
217217
extraCoreBuildCachePaths:extraCoreBuildCachePaths,
218-
logger:logger,
218+
logger:log,
219219
clean:clean,
220220
sourceOverrides:sourceOverrides,
221221
onlyUpdateCompilationDatabase:onlyUpdateCompilationDatabase,
@@ -242,7 +242,7 @@ func NewBuilder(
242242
libsManager,libsResolver,
243243
useCachedLibrariesResolution,
244244
onlyUpdateCompilationDatabase,
245-
logger,
245+
log,
246246
diagnosticStore,
247247
),
248248
}
@@ -341,7 +341,7 @@ func (b *Builder) preprocess() error {
341341
}
342342

343343
func (b*Builder)logIfVerbose(warnbool,msgstring) {
344-
if!b.logger.Verbose() {
344+
ifb.logger.VerbosityLevel()!=logger.VerbosityVerbose {
345345
return
346346
}
347347
ifwarn {
@@ -526,7 +526,7 @@ func (b *Builder) prepareCommandForRecipe(buildProperties *properties.Map, recip
526526
}
527527

528528
func (b*Builder)execCommand(command*paths.Process)error {
529-
ifb.logger.Verbose() {
529+
ifb.logger.VerbosityLevel()==logger.VerbosityVerbose {
530530
b.logger.Info(utils.PrintableCommand(command.GetArgs()))
531531
command.RedirectStdoutTo(b.logger.Stdout())
532532
}

‎internal/arduino/builder/compilation.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"sync"
2424

2525
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/utils"
26+
"github.com/arduino/arduino-cli/internal/arduino/builder/logger"
2627
"github.com/arduino/arduino-cli/internal/arduino/globals"
2728
"github.com/arduino/arduino-cli/internal/i18n"
2829
"github.com/arduino/go-paths-helper"
@@ -152,7 +153,7 @@ func (b *Builder) compileFileWithRecipe(
152153
command.RedirectStdoutTo(commandStdout)
153154
command.RedirectStderrTo(commandStderr)
154155

155-
ifb.logger.Verbose() {
156+
ifb.logger.VerbosityLevel()==logger.VerbosityVerbose {
156157
b.logger.Info(utils.PrintableCommand(command.GetArgs()))
157158
}
158159
// Since this compile could be multithreaded, we first capture the command output
@@ -161,7 +162,7 @@ func (b *Builder) compileFileWithRecipe(
161162
}
162163
err:=command.Wait()
163164
// and transfer all at once at the end...
164-
ifb.logger.Verbose() {
165+
ifb.logger.VerbosityLevel()==logger.VerbosityVerbose {
165166
b.logger.WriteStdout(commandStdout.Bytes())
166167
}
167168
b.logger.WriteStderr(commandStderr.Bytes())
@@ -176,7 +177,7 @@ func (b *Builder) compileFileWithRecipe(
176177
iferr!=nil {
177178
returnnil,err
178179
}
179-
}elseifb.logger.Verbose() {
180+
}elseifb.logger.VerbosityLevel()==logger.VerbosityVerbose {
180181
ifobjIsUpToDate {
181182
b.logger.Info(i18n.Tr("Using previously compiled file: %[1]s",objectFile))
182183
}else {

‎internal/arduino/builder/core.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/arduino/arduino-cli/internal/arduino/builder/cpp"
2626
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/utils"
27+
"github.com/arduino/arduino-cli/internal/arduino/builder/logger"
2728
"github.com/arduino/arduino-cli/internal/buildcache"
2829
"github.com/arduino/arduino-cli/internal/i18n"
2930
"github.com/arduino/go-paths-helper"
@@ -116,7 +117,7 @@ func (b *Builder) compileCore() (*paths.Path, paths.PathList, error) {
116117
returnnil,nil,errors.New(i18n.Tr("creating core cache folder: %s",err))
117118
}
118119
// use archived core
119-
ifb.logger.Verbose() {
120+
ifb.logger.VerbosityLevel()==logger.VerbosityVerbose {
120121
b.logger.Info(i18n.Tr("Using precompiled core: %[1]s",targetArchivedCore))
121122
}
122123
returntargetArchivedCore,variantObjectFiles,nil
@@ -128,7 +129,7 @@ func (b *Builder) compileCore() (*paths.Path, paths.PathList, error) {
128129
extraTargetArchivedCore:=extraCoreBuildCachePath.Join(archivedCoreName,"core.a")
129130
ifcanUseArchivedCore(extraTargetArchivedCore) {
130131
// use archived core
131-
ifb.logger.Verbose() {
132+
ifb.logger.VerbosityLevel()==logger.VerbosityVerbose {
132133
b.logger.Info(i18n.Tr("Using precompiled core: %[1]s",extraTargetArchivedCore))
133134
}
134135
returnextraTargetArchivedCore,variantObjectFiles,nil
@@ -158,7 +159,7 @@ func (b *Builder) compileCore() (*paths.Path, paths.PathList, error) {
158159
// archive core.a
159160
iftargetArchivedCore!=nil&&!b.onlyUpdateCompilationDatabase {
160161
err:=archiveFile.CopyTo(targetArchivedCore)
161-
ifb.logger.Verbose() {
162+
ifb.logger.VerbosityLevel()==logger.VerbosityVerbose {
162163
iferr==nil {
163164
b.logger.Info(i18n.Tr("Archiving built core (caching) in: %[1]s",targetArchivedCore))
164165
}elseifos.IsNotExist(err) {

‎internal/arduino/builder/internal/detector/detector.go‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import (
2828
"time"
2929

3030
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/diagnostics"
31-
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/logger"
3231
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/preprocessor"
3332
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/utils"
33+
"github.com/arduino/arduino-cli/internal/arduino/builder/logger"
3434
"github.com/arduino/arduino-cli/internal/arduino/cores"
3535
"github.com/arduino/arduino-cli/internal/arduino/globals"
3636
"github.com/arduino/arduino-cli/internal/arduino/libraries"
@@ -87,7 +87,7 @@ func (l *SketchLibrariesDetector) resolveLibrary(header, platformArch string) *l
8787
importedLibraries:=l.importedLibraries
8888
candidates:=l.librariesResolver.AlternativesFor(header)
8989

90-
ifl.logger.Verbose() {
90+
ifl.logger.VerbosityLevel()==logger.VerbosityVerbose {
9191
l.logger.Info(i18n.Tr("Alternatives for %[1]s: %[2]s",header,candidates))
9292
l.logger.Info(fmt.Sprintf("ResolveLibrary(%s)",header))
9393
l.logger.Info(fmt.Sprintf(" -> %s: %s",i18n.Tr("candidates"),candidates))
@@ -144,7 +144,7 @@ func (l *SketchLibrariesDetector) PrintUsedAndNotUsedLibraries(sketchError bool)
144144
// - as warning, when the sketch didn't compile
145145
// - as info, when verbose is on
146146
// - otherwise, output nothing
147-
if!sketchError&&!l.logger.Verbose() {
147+
if!sketchError&&l.logger.VerbosityLevel()!=logger.VerbosityVerbose {
148148
return
149149
}
150150

@@ -239,7 +239,7 @@ func (l *SketchLibrariesDetector) findIncludes(
239239
iferr:=json.Unmarshal(d,&l.includeFolders);err!=nil {
240240
returnerr
241241
}
242-
ifl.logger.Verbose() {
242+
ifl.logger.VerbosityLevel()==logger.VerbosityVerbose {
243243
l.logger.Info("Using cached library discovery: "+librariesResolutionCache.String())
244244
}
245245
returnnil
@@ -347,12 +347,12 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
347347
varmissingIncludeHstring
348348
ifunchanged&&cache.valid {
349349
missingIncludeH=cache.Next().Include
350-
iffirst&&l.logger.Verbose() {
350+
iffirst&&l.logger.VerbosityLevel()==logger.VerbosityVerbose {
351351
l.logger.Info(i18n.Tr("Using cached library dependencies for file: %[1]s",sourcePath))
352352
}
353353
}else {
354354
preprocFirstResult,preprocErr=preprocessor.GCC(ctx,sourcePath,targetFilePath,includeFolders,buildProperties)
355-
ifl.logger.Verbose() {
355+
ifl.logger.VerbosityLevel()==logger.VerbosityVerbose {
356356
l.logger.WriteStdout(preprocFirstResult.Stdout())
357357
}
358358
// Unwrap error and see if it is an ExitError.
@@ -365,7 +365,7 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
365365
returnpreprocErr
366366
}else {
367367
missingIncludeH=IncludesFinderWithRegExp(string(preprocFirstResult.Stderr()))
368-
ifmissingIncludeH==""&&l.logger.Verbose() {
368+
ifmissingIncludeH==""&&l.logger.VerbosityLevel()==logger.VerbosityVerbose {
369369
l.logger.Info(i18n.Tr("Error while detecting libraries included by %[1]s",sourcePath))
370370
}
371371
}
@@ -383,7 +383,7 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
383383
ifpreprocErr==nil||preprocFirstResult.Stderr()==nil {
384384
// Filename came from cache, so run preprocessor to obtain error to show
385385
result,err:=preprocessor.GCC(ctx,sourcePath,targetFilePath,includeFolders,buildProperties)
386-
ifl.logger.Verbose() {
386+
ifl.logger.VerbosityLevel()==logger.VerbosityVerbose {
387387
l.logger.WriteStdout(result.Stdout())
388388
}
389389
iferr==nil {
@@ -410,7 +410,7 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
410410

411411
iflibrary.Precompiled&&library.PrecompiledWithSources {
412412
// Fully precompiled libraries should have no dependencies to avoid ABI breakage
413-
ifl.logger.Verbose() {
413+
ifl.logger.VerbosityLevel()==logger.VerbosityVerbose {
414414
l.logger.Info(i18n.Tr("Skipping dependencies detection for precompiled library %[1]s",library.Name))
415415
}
416416
}else {

‎internal/arduino/builder/internal/preprocessor/ctags.go‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ func PreprocessSketchWithCtags(
8383
}
8484

8585
// Run CTags on gcc-preprocessed source
86-
ctagsOutput,ctagsStdErr,err:=RunCTags(ctx,ctagsTarget,buildProperties)
86+
ctagsOutput,ctagsStdErr,ctagsCmdLine,err:=RunCTags(ctx,ctagsTarget,buildProperties)
8787
ifverbose {
88+
stdout.Write([]byte(ctagsCmdLine+"\n"))
8889
stderr.Write(ctagsStdErr)
8990
}
9091
iferr!=nil {
@@ -178,7 +179,7 @@ func isFirstFunctionOutsideOfSource(firstFunctionLine int, sourceRows []string)
178179
}
179180

180181
// RunCTags performs a run of ctags on the given source file. Returns the ctags output and the stderr contents.
181-
funcRunCTags(ctx context.Context,sourceFile*paths.Path,buildProperties*properties.Map) ([]byte, []byte,error) {
182+
funcRunCTags(ctx context.Context,sourceFile*paths.Path,buildProperties*properties.Map) ([]byte, []byte,string,error) {
182183
ctagsBuildProperties:=properties.NewMap()
183184
ctagsBuildProperties.Set("tools.ctags.path","{runtime.tools.ctags.path}")
184185
ctagsBuildProperties.Set("tools.ctags.cmd.path","{path}/ctags")
@@ -189,24 +190,22 @@ func RunCTags(ctx context.Context, sourceFile *paths.Path, buildProperties *prop
189190

190191
pattern:=ctagsBuildProperties.Get("pattern")
191192
ifpattern=="" {
192-
returnnil,nil,errors.New(i18n.Tr("%s pattern is missing","ctags"))
193+
returnnil,nil,"",errors.New(i18n.Tr("%s pattern is missing","ctags"))
193194
}
194195

195196
commandLine:=ctagsBuildProperties.ExpandPropsInString(pattern)
196197
parts,err:=properties.SplitQuotedString(commandLine,`"'`,false)
197198
iferr!=nil {
198-
returnnil,nil,err
199+
returnnil,nil,"",err
199200
}
200201
proc,err:=paths.NewProcess(nil,parts...)
201202
iferr!=nil {
202-
returnnil,nil,err
203+
returnnil,nil,"",err
203204
}
204205
stdout,stderr,err:=proc.RunAndCaptureOutput(ctx)
205206

206-
// Append ctags arguments to stderr
207207
args:=fmt.Sprintln(strings.Join(parts," "))
208-
stderr=append([]byte(args),stderr...)
209-
returnstdout,stderr,err
208+
returnstdout,stderr,args,err
210209
}
211210

212211
funcfilterSketchSource(sketch*sketch.Sketch,source io.Reader,removeLineMarkersbool)string {

‎internal/arduino/builder/libraries.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"time"
2222

2323
"github.com/arduino/arduino-cli/internal/arduino/builder/cpp"
24+
"github.com/arduino/arduino-cli/internal/arduino/builder/logger"
2425
"github.com/arduino/arduino-cli/internal/arduino/libraries"
2526
"github.com/arduino/arduino-cli/internal/i18n"
2627
"github.com/arduino/go-paths-helper"
@@ -129,7 +130,7 @@ func (b *Builder) compileLibraries(libraries libraries.List, includes []string)
129130
}
130131

131132
func (b*Builder)compileLibrary(library*libraries.Library,includes []string) (paths.PathList,error) {
132-
ifb.logger.Verbose() {
133+
ifb.logger.VerbosityLevel()==logger.VerbosityVerbose {
133134
b.logger.Info(i18n.Tr(`Compiling library "%[1]s"`,library.Name))
134135
}
135136
libraryBuildPath:=b.librariesBuildPath.Join(library.DirName)
@@ -292,7 +293,7 @@ func (b *Builder) warnAboutArchIncompatibleLibraries(importedLibraries libraries
292293
// TODO here we can completly remove this part as it's duplicated in what we can
293294
// read in the gRPC response
294295
func (b*Builder)printUsedLibraries(importedLibraries libraries.List) {
295-
if!b.logger.Verbose()||len(importedLibraries)==0 {
296+
ifb.logger.VerbosityLevel()!=logger.VerbosityVerbose||len(importedLibraries)==0 {
296297
return
297298
}
298299

‎internal/arduino/builder/linker.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package builder
1818
import (
1919
"strings"
2020

21+
"github.com/arduino/arduino-cli/internal/arduino/builder/logger"
2122
"github.com/arduino/arduino-cli/internal/i18n"
2223
"github.com/arduino/go-paths-helper"
2324
"go.bug.st/f"
@@ -26,7 +27,7 @@ import (
2627
// link fixdoc
2728
func (b*Builder)link()error {
2829
ifb.onlyUpdateCompilationDatabase {
29-
ifb.logger.Verbose() {
30+
ifb.logger.VerbosityLevel()==logger.VerbosityVerbose {
3031
b.logger.Info(i18n.Tr("Skip linking of final executable."))
3132
}
3233
returnnil

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp