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