@@ -98,7 +98,6 @@ import (
98
98
"os/exec"
99
99
"time"
100
100
101
- "github.com/arduino/arduino-cli/arduino/libraries"
102
101
"github.com/arduino/arduino-cli/arduino/sketch"
103
102
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
104
103
"github.com/arduino/arduino-cli/legacy/builder/types"
@@ -158,17 +157,17 @@ func (f *CppIncludesFinder) DetectLibraries() error {
158
157
f .appendIncludeFolder (nil , "" , f .ctx .BuildProperties .GetPath ("build.variant.path" ))
159
158
}
160
159
161
- mergedfile , err := MakeSourceFile (f .ctx , nil , paths .New (f .sketch .MainFile .Base ()+ ".cpp" ))
160
+ mergedfile , err := MakeSourceFile (f .ctx . SketchBuildPath , f . ctx . SketchBuildPath , paths .New (f .sketch .MainFile .Base ()+ ".cpp" ))
162
161
if err != nil {
163
162
return errors .WithStack (err )
164
163
}
165
164
f .log .Debugf ("Queueing merged sketch: %s" , mergedfile )
166
165
f .queue .Push (mergedfile )
167
166
168
- f .queueSourceFilesFromFolder (nil , f .ctx .SketchBuildPath , false /* recurse */ )
167
+ f .queueSourceFilesFromFolder (f . ctx . SketchBuildPath , f .ctx .SketchBuildPath , false /* recurse */ )
169
168
srcSubfolderPath := f .ctx .SketchBuildPath .Join ("src" )
170
169
if srcSubfolderPath .IsDir () {
171
- f .queueSourceFilesFromFolder (nil , srcSubfolderPath , true /* recurse */ )
170
+ f .queueSourceFilesFromFolder (srcSubfolderPath , f . ctx . SketchBuildPath , true /* recurse */ )
172
171
}
173
172
174
173
for ! f .queue .Empty () {
@@ -320,10 +319,10 @@ func (cache *includeCache) WriteToFile() error {
320
319
}
321
320
322
321
func (f * CppIncludesFinder ) findIncludesUntilDone (sourceFile SourceFile ) error {
323
- sourcePath := sourceFile .SourcePath (f . ctx )
322
+ sourcePath := sourceFile .SourcePath ()
324
323
targetFilePath := paths .NullPath ()
325
- depPath := sourceFile .DepfilePath (f . ctx )
326
- objPath := sourceFile .ObjectPath (f . ctx )
324
+ depPath := sourceFile .DepfilePath ()
325
+ objPath := sourceFile .ObjectPath ()
327
326
328
327
// TODO: This should perhaps also compare against the
329
328
// include.cache file timestamp. Now, it only checks if the file
@@ -344,11 +343,11 @@ func (f *CppIncludesFinder) findIncludesUntilDone(sourceFile SourceFile) error {
344
343
345
344
first := true
346
345
for {
347
- var include string
348
346
f .cache .ExpectFile (sourcePath )
349
347
350
348
var preprocErr error
351
349
var preprocStderr []byte
350
+ var include string
352
351
if unchanged && f .cache .valid {
353
352
include = f .cache .Next ().Include
354
353
if first && f .ctx .Verbose {
@@ -410,6 +409,7 @@ func (f *CppIncludesFinder) findIncludesUntilDone(sourceFile SourceFile) error {
410
409
f .ctx .IncludeFolders = append (f .ctx .IncludeFolders , library .UtilityDir )
411
410
}
412
411
sourceDirs := library .SourceDirs ()
412
+ buildDir := f .ctx .LibrariesBuildPath .Join (library .Name )
413
413
for _ , sourceDir := range sourceDirs {
414
414
if library .Precompiled && library .PrecompiledWithSources {
415
415
// Fully precompiled libraries should have no dependencies
@@ -418,24 +418,24 @@ func (f *CppIncludesFinder) findIncludesUntilDone(sourceFile SourceFile) error {
418
418
f .ctx .Info (tr ("Skipping dependencies detection for precompiled library %[1]s" , library .Name ))
419
419
}
420
420
} else {
421
- f .queueSourceFilesFromFolder (library , sourceDir .Dir , sourceDir .Recurse )
421
+ f .queueSourceFilesFromFolder (buildDir , sourceDir .Dir , sourceDir .Recurse )
422
422
}
423
423
}
424
424
first = false
425
425
}
426
426
}
427
427
428
- func (f * CppIncludesFinder ) queueSourceFilesFromFolder (lib * libraries. Library , folder * paths.Path , recurse bool ) error {
428
+ func (f * CppIncludesFinder ) queueSourceFilesFromFolder (srcDir , buildDir * paths.Path , recurse bool ) error {
429
429
extensions := func (ext string ) bool { return ADDITIONAL_FILE_VALID_EXTENSIONS_NO_HEADERS [ext ] }
430
- f .log .Debugf (" Queueing source files from %s (recurse %v)" , folder , recurse )
430
+ f .log .Debugf (" Queueing source files from %s (recurse %v)" , srcDir , recurse )
431
431
filePaths := []string {}
432
- err := utils .FindFilesInFolder (& filePaths , folder .String (), extensions , recurse )
432
+ err := utils .FindFilesInFolder (& filePaths , srcDir .String (), extensions , recurse )
433
433
if err != nil {
434
434
return errors .WithStack (err )
435
435
}
436
436
437
437
for _ , filePath := range filePaths {
438
- sourceFile , err := MakeSourceFile (f . ctx , lib , paths .New (filePath ))
438
+ sourceFile , err := MakeSourceFile (srcDir , buildDir , paths .New (filePath ))
439
439
if err != nil {
440
440
return errors .WithStack (err )
441
441
}
@@ -447,64 +447,44 @@ func (f *CppIncludesFinder) queueSourceFilesFromFolder(lib *libraries.Library, f
447
447
}
448
448
449
449
type SourceFile struct {
450
- // Library pointer that this source file lives in or nil if not part of a library
451
- Library * libraries.Library
450
+ // SourceRoot is the path to the source code root directory
451
+ SourceRoot * paths.Path
452
+
453
+ // BuildRoot is the path to the build root directory
454
+ BuildRoot * paths.Path
452
455
453
456
// Path to the source file within the sketch/library root folder
454
457
RelativePath * paths.Path
455
-
456
- ctx * types.Context
457
458
}
458
459
459
460
func (f SourceFile ) String () string {
460
461
return fmt .Sprintf ("Root: %s - Path: %s - BuildPath: %s" ,
461
- sourceRoot ( f . ctx , f .Library ), f . RelativePath , buildRoot ( f . ctx , f . Library ) )
462
+ f . SourceRoot , f .RelativePath , f . BuildRoot )
462
463
}
463
464
464
- // Create a SourceFile containing the given source file path within the
465
- // given origin. The given path can be absolute, or relative within the
466
- // origin's root source folder
467
- func MakeSourceFile (ctx * types.Context , lib * libraries.Library , path * paths.Path ) (SourceFile , error ) {
465
+ // MakeSourceFile creates a SourceFile containing the given source file path
466
+ // within the given sourceRoot.
467
+ func MakeSourceFile (sourceRoot , buildRoot , path * paths.Path ) (SourceFile , error ) {
468
468
if path .IsAbs () {
469
- var err error
470
- path , err = sourceRoot ( ctx , lib ). RelTo ( path )
471
- if err != nil {
469
+ if relPath , err := sourceRoot . RelTo ( path ); err == nil {
470
+ path = relPath
471
+ } else {
472
472
return SourceFile {}, err
473
473
}
474
474
}
475
- return SourceFile {Library : lib , RelativePath : path , ctx : ctx }, nil
476
- }
477
-
478
- // Return the build root for the given origin, where build products will
479
- // be placed. Any directories inside SourceFile.RelativePath will be
480
- // appended here.
481
- func buildRoot (ctx * types.Context , lib * libraries.Library ) * paths.Path {
482
- if lib == nil {
483
- return ctx .SketchBuildPath
484
- }
485
- return ctx .LibrariesBuildPath .Join (lib .Name )
486
- }
487
-
488
- // Return the source root for the given origin, where its source files
489
- // can be found. Prepending this to SourceFile.RelativePath will give
490
- // the full path to that source file.
491
- func sourceRoot (ctx * types.Context , lib * libraries.Library ) * paths.Path {
492
- if lib == nil {
493
- return ctx .SketchBuildPath
494
- }
495
- return lib .SourceDir
475
+ return SourceFile {SourceRoot : sourceRoot , BuildRoot : buildRoot , RelativePath : path }, nil
496
476
}
497
477
498
- func (f * SourceFile ) SourcePath (ctx * types. Context ) * paths.Path {
499
- return sourceRoot ( ctx , f . Library ) .JoinPath (f .RelativePath )
478
+ func (f * SourceFile ) SourcePath () * paths.Path {
479
+ return f . SourceRoot .JoinPath (f .RelativePath )
500
480
}
501
481
502
- func (f * SourceFile ) ObjectPath (ctx * types. Context ) * paths.Path {
503
- return buildRoot ( ctx , f . Library ) .Join (f .RelativePath .String () + ".o" )
482
+ func (f * SourceFile ) ObjectPath () * paths.Path {
483
+ return f . BuildRoot .Join (f .RelativePath .String () + ".o" )
504
484
}
505
485
506
- func (f * SourceFile ) DepfilePath (ctx * types. Context ) * paths.Path {
507
- return buildRoot ( ctx , f . Library ) .Join (f .RelativePath .String () + ".d" )
486
+ func (f * SourceFile ) DepfilePath () * paths.Path {
487
+ return f . BuildRoot .Join (f .RelativePath .String () + ".d" )
508
488
}
509
489
510
490
type UniqueSourceFileQueue struct {
@@ -534,7 +514,9 @@ func (q *UniqueSourceFileQueue) Empty() bool {
534
514
535
515
func (q * UniqueSourceFileQueue ) Contains (target SourceFile ) bool {
536
516
for _ , elem := range q .queue {
537
- if elem .Library == target .Library && elem .RelativePath .EqualsTo (target .RelativePath ) {
517
+ if elem .BuildRoot .EqualsTo (target .BuildRoot ) &&
518
+ elem .SourceRoot .EqualsTo (target .SourceRoot ) &&
519
+ elem .RelativePath .EqualsTo (target .RelativePath ) {
538
520
return true
539
521
}
540
522
}
0 commit comments