@@ -446,6 +446,8 @@ func (f *CppIncludesFinder) queueSourceFilesFromFolder(srcDir, buildDir *paths.P
446
446
return nil
447
447
}
448
448
449
+ // SourceFile represent a source file, it keeps a reference to the root source
450
+ // directory and the corresponding build root directory.
449
451
type SourceFile struct {
450
452
// SourceRoot is the path to the source code root directory
451
453
SourceRoot * paths.Path
@@ -463,26 +465,30 @@ func (f SourceFile) String() string {
463
465
}
464
466
465
467
// 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
- if path .IsAbs () {
469
- if relPath , err := sourceRoot .RelTo (path ); err == nil {
470
- path = relPath
468
+ // within the given sourceRoot. If srcPath is absolute it is transformed to
469
+ // relative to sourceRoot.
470
+ func MakeSourceFile (sourceRoot , buildRoot , srcPath * paths.Path ) (SourceFile , error ) {
471
+ if srcPath .IsAbs () {
472
+ if relPath , err := sourceRoot .RelTo (srcPath ); err == nil {
473
+ srcPath = relPath
471
474
} else {
472
475
return SourceFile {}, err
473
476
}
474
477
}
475
- return SourceFile {SourceRoot : sourceRoot , BuildRoot : buildRoot , RelativePath : path }, nil
478
+ return SourceFile {SourceRoot : sourceRoot , BuildRoot : buildRoot , RelativePath : srcPath }, nil
476
479
}
477
480
481
+ // SourcePath returns the path to the source file
478
482
func (f * SourceFile ) SourcePath () * paths.Path {
479
483
return f .SourceRoot .JoinPath (f .RelativePath )
480
484
}
481
485
486
+ // ObjectPath returns the path to the object file (.o)
482
487
func (f * SourceFile ) ObjectPath () * paths.Path {
483
488
return f .BuildRoot .Join (f .RelativePath .String () + ".o" )
484
489
}
485
490
491
+ // DepfilePath returns the path to the dependencies file (.d)
486
492
func (f * SourceFile ) DepfilePath () * paths.Path {
487
493
return f .BuildRoot .Join (f .RelativePath .String () + ".d" )
488
494
}
0 commit comments