@@ -428,6 +428,8 @@ func (f *CppIncludesFinder) queueSourceFilesFromFolder(srcDir, buildDir *paths.P
428
428
return nil
429
429
}
430
430
431
+ // SourceFile represent a source file, it keeps a reference to the root source
432
+ // directory and the corresponding build root directory.
431
433
type SourceFile struct {
432
434
// SourceRoot is the path to the source code root directory
433
435
SourceRoot * paths.Path
@@ -445,26 +447,30 @@ func (f SourceFile) String() string {
445
447
}
446
448
447
449
// MakeSourceFile creates a SourceFile containing the given source file path
448
- // within the given sourceRoot.
449
- func MakeSourceFile (sourceRoot , buildRoot , path * paths.Path ) (SourceFile , error ) {
450
- if path .IsAbs () {
451
- if relPath , err := sourceRoot .RelTo (path ); err == nil {
452
- path = relPath
450
+ // within the given sourceRoot. If srcPath is absolute it is transformed to
451
+ // relative to sourceRoot.
452
+ func MakeSourceFile (sourceRoot , buildRoot , srcPath * paths.Path ) (SourceFile , error ) {
453
+ if srcPath .IsAbs () {
454
+ if relPath , err := sourceRoot .RelTo (srcPath ); err == nil {
455
+ srcPath = relPath
453
456
} else {
454
457
return SourceFile {}, err
455
458
}
456
459
}
457
- return SourceFile {SourceRoot : sourceRoot , BuildRoot : buildRoot , RelativePath : path }, nil
460
+ return SourceFile {SourceRoot : sourceRoot , BuildRoot : buildRoot , RelativePath : srcPath }, nil
458
461
}
459
462
463
+ // SourcePath returns the path to the source file
460
464
func (f * SourceFile ) SourcePath () * paths.Path {
461
465
return f .SourceRoot .JoinPath (f .RelativePath )
462
466
}
463
467
468
+ // ObjectPath returns the path to the object file (.o)
464
469
func (f * SourceFile ) ObjectPath () * paths.Path {
465
470
return f .BuildRoot .Join (f .RelativePath .String () + ".o" )
466
471
}
467
472
473
+ // DepfilePath returns the path to the dependencies file (.d)
468
474
func (f * SourceFile ) DepfilePath () * paths.Path {
469
475
return f .BuildRoot .Join (f .RelativePath .String () + ".d" )
470
476
}
0 commit comments