@@ -99,7 +99,6 @@ import (
99
99
"os/exec"
100
100
"time"
101
101
102
- "github.com/arduino/arduino-cli/arduino/libraries"
103
102
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
104
103
"github.com/arduino/arduino-cli/legacy/builder/constants"
105
104
"github.com/arduino/arduino-cli/legacy/builder/types"
@@ -147,17 +146,17 @@ func (f *CppIncludesFinder) DetectLibraries() error {
147
146
f .appendIncludeFolder (nil , "" , f .ctx .BuildProperties .GetPath ("build.variant.path" ))
148
147
}
149
148
150
- mergedfile , err := MakeSourceFile (f .ctx , nil , paths .New (f .sketch .MainFile .Name .Base ()+ ".cpp" ))
149
+ mergedfile , err := MakeSourceFile (f .ctx . SketchBuildPath , f . ctx . SketchBuildPath , paths .New (f .sketch .MainFile .Name .Base ()+ ".cpp" ))
151
150
if err != nil {
152
151
return errors .WithStack (err )
153
152
}
154
153
f .log .Debugf ("Queueing merged sketch: %s" , mergedfile )
155
154
f .queue .Push (mergedfile )
156
155
157
- f .queueSourceFilesFromFolder (nil , f .ctx .SketchBuildPath , false /* recurse */ )
156
+ f .queueSourceFilesFromFolder (f . ctx . SketchBuildPath , f .ctx .SketchBuildPath , false /* recurse */ )
158
157
srcSubfolderPath := f .ctx .SketchBuildPath .Join ("src" )
159
158
if srcSubfolderPath .IsDir () {
160
- f .queueSourceFilesFromFolder (nil , srcSubfolderPath , true /* recurse */ )
159
+ f .queueSourceFilesFromFolder (srcSubfolderPath , f . ctx . SketchBuildPath , true /* recurse */ )
161
160
}
162
161
163
162
for ! f .queue .Empty () {
@@ -309,10 +308,10 @@ func (cache *includeCache) WriteToFile() error {
309
308
}
310
309
311
310
func (f * CppIncludesFinder ) findIncludesUntilDone (sourceFile SourceFile ) error {
312
- sourcePath := sourceFile .SourcePath (f . ctx )
311
+ sourcePath := sourceFile .SourcePath ()
313
312
targetFilePath := paths .NullPath ()
314
- depPath := sourceFile .DepfilePath (f . ctx )
315
- objPath := sourceFile .ObjectPath (f . ctx )
313
+ depPath := sourceFile .DepfilePath ()
314
+ objPath := sourceFile .ObjectPath ()
316
315
317
316
// TODO: This should perhaps also compare against the
318
317
// include.cache file timestamp. Now, it only checks if the file
@@ -333,11 +332,11 @@ func (f *CppIncludesFinder) findIncludesUntilDone(sourceFile SourceFile) error {
333
332
334
333
first := true
335
334
for {
336
- var include string
337
335
f .cache .ExpectFile (sourcePath )
338
336
339
337
var preprocErr error
340
338
var preprocStderr []byte
339
+ var include string
341
340
if unchanged && f .cache .valid {
342
341
include = f .cache .Next ().Include
343
342
if first && f .ctx .Verbose {
@@ -399,24 +398,25 @@ func (f *CppIncludesFinder) findIncludesUntilDone(sourceFile SourceFile) error {
399
398
f .ctx .IncludeFolders = append (f .ctx .IncludeFolders , library .UtilityDir )
400
399
}
401
400
sourceDirs := library .SourceDirs ()
401
+ buildDir := f .ctx .LibrariesBuildPath .Join (library .Name )
402
402
for _ , sourceDir := range sourceDirs {
403
- f .queueSourceFilesFromFolder (library , sourceDir .Dir , sourceDir .Recurse )
403
+ f .queueSourceFilesFromFolder (buildDir , sourceDir .Dir , sourceDir .Recurse )
404
404
}
405
405
first = false
406
406
}
407
407
}
408
408
409
- func (f * CppIncludesFinder ) queueSourceFilesFromFolder (lib * libraries. Library , folder * paths.Path , recurse bool ) error {
409
+ func (f * CppIncludesFinder ) queueSourceFilesFromFolder (srcDir , buildDir * paths.Path , recurse bool ) error {
410
410
extensions := func (ext string ) bool { return ADDITIONAL_FILE_VALID_EXTENSIONS_NO_HEADERS [ext ] }
411
- f .log .Debugf (" Queueing source files from %s (recurse %v)" , folder , recurse )
411
+ f .log .Debugf (" Queueing source files from %s (recurse %v)" , srcDir , recurse )
412
412
filePaths := []string {}
413
- err := utils .FindFilesInFolder (& filePaths , folder .String (), extensions , recurse )
413
+ err := utils .FindFilesInFolder (& filePaths , srcDir .String (), extensions , recurse )
414
414
if err != nil {
415
415
return errors .WithStack (err )
416
416
}
417
417
418
418
for _ , filePath := range filePaths {
419
- sourceFile , err := MakeSourceFile (f . ctx , lib , paths .New (filePath ))
419
+ sourceFile , err := MakeSourceFile (srcDir , buildDir , paths .New (filePath ))
420
420
if err != nil {
421
421
return errors .WithStack (err )
422
422
}
@@ -428,64 +428,44 @@ func (f *CppIncludesFinder) queueSourceFilesFromFolder(lib *libraries.Library, f
428
428
}
429
429
430
430
type SourceFile struct {
431
- // Library pointer that this source file lives in or nil if not part of a library
432
- Library * libraries.Library
431
+ // SourceRoot is the path to the source code root directory
432
+ SourceRoot * paths.Path
433
+
434
+ // BuildRoot is the path to the build root directory
435
+ BuildRoot * paths.Path
433
436
434
437
// Path to the source file within the sketch/library root folder
435
438
RelativePath * paths.Path
436
-
437
- ctx * types.Context
438
439
}
439
440
440
441
func (f SourceFile ) String () string {
441
442
return fmt .Sprintf ("Root: %s - Path: %s - BuildPath: %s" ,
442
- sourceRoot ( f . ctx , f .Library ), f . RelativePath , buildRoot ( f . ctx , f . Library ) )
443
+ f . SourceRoot , f .RelativePath , f . BuildRoot )
443
444
}
444
445
445
- // Create a SourceFile containing the given source file path within the
446
- // given origin. The given path can be absolute, or relative within the
447
- // origin's root source folder
448
- func MakeSourceFile (ctx * types.Context , lib * libraries.Library , path * paths.Path ) (SourceFile , error ) {
446
+ // MakeSourceFile creates a SourceFile containing the given source file path
447
+ // within the given sourceRoot.
448
+ func MakeSourceFile (sourceRoot , buildRoot , path * paths.Path ) (SourceFile , error ) {
449
449
if path .IsAbs () {
450
- var err error
451
- path , err = sourceRoot ( ctx , lib ). RelTo ( path )
452
- if err != nil {
450
+ if relPath , err := sourceRoot . RelTo ( path ); err == nil {
451
+ path = relPath
452
+ } else {
453
453
return SourceFile {}, err
454
454
}
455
455
}
456
- return SourceFile {Library : lib , RelativePath : path , ctx : ctx }, nil
457
- }
458
-
459
- // Return the build root for the given origin, where build products will
460
- // be placed. Any directories inside SourceFile.RelativePath will be
461
- // appended here.
462
- func buildRoot (ctx * types.Context , lib * libraries.Library ) * paths.Path {
463
- if lib == nil {
464
- return ctx .SketchBuildPath
465
- }
466
- return ctx .LibrariesBuildPath .Join (lib .Name )
467
- }
468
-
469
- // Return the source root for the given origin, where its source files
470
- // can be found. Prepending this to SourceFile.RelativePath will give
471
- // the full path to that source file.
472
- func sourceRoot (ctx * types.Context , lib * libraries.Library ) * paths.Path {
473
- if lib == nil {
474
- return ctx .SketchBuildPath
475
- }
476
- return lib .SourceDir
456
+ return SourceFile {SourceRoot : sourceRoot , BuildRoot : buildRoot , RelativePath : path }, nil
477
457
}
478
458
479
- func (f * SourceFile ) SourcePath (ctx * types. Context ) * paths.Path {
480
- return sourceRoot ( ctx , f . Library ) .JoinPath (f .RelativePath )
459
+ func (f * SourceFile ) SourcePath () * paths.Path {
460
+ return f . SourceRoot .JoinPath (f .RelativePath )
481
461
}
482
462
483
- func (f * SourceFile ) ObjectPath (ctx * types. Context ) * paths.Path {
484
- return buildRoot ( ctx , f . Library ) .Join (f .RelativePath .String () + ".o" )
463
+ func (f * SourceFile ) ObjectPath () * paths.Path {
464
+ return f . BuildRoot .Join (f .RelativePath .String () + ".o" )
485
465
}
486
466
487
- func (f * SourceFile ) DepfilePath (ctx * types. Context ) * paths.Path {
488
- return buildRoot ( ctx , f . Library ) .Join (f .RelativePath .String () + ".d" )
467
+ func (f * SourceFile ) DepfilePath () * paths.Path {
468
+ return f . BuildRoot .Join (f .RelativePath .String () + ".d" )
489
469
}
490
470
491
471
type UniqueSourceFileQueue struct {
@@ -515,7 +495,9 @@ func (q *UniqueSourceFileQueue) Empty() bool {
515
495
516
496
func (q * UniqueSourceFileQueue ) Contains (target SourceFile ) bool {
517
497
for _ , elem := range q .queue {
518
- if elem .Library == target .Library && elem .RelativePath .EqualsTo (target .RelativePath ) {
498
+ if elem .BuildRoot .EqualsTo (target .BuildRoot ) &&
499
+ elem .SourceRoot .EqualsTo (target .SourceRoot ) &&
500
+ elem .RelativePath .EqualsTo (target .RelativePath ) {
519
501
return true
520
502
}
521
503
}
0 commit comments