Skip to content

Commit c836534

Browse files
committed
Added some documentation to SourceFile struct and methods
1 parent c3a46e0 commit c836534

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

legacy/builder/container_find_includes.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ func (f *CppIncludesFinder) queueSourceFilesFromFolder(srcDir, buildDir *paths.P
427427
return nil
428428
}
429429

430+
// SourceFile represent a source file, it keeps a reference to the root source
431+
// directory and the corresponding build root directory.
430432
type SourceFile struct {
431433
// SourceRoot is the path to the source code root directory
432434
SourceRoot *paths.Path
@@ -444,26 +446,30 @@ func (f SourceFile) String() string {
444446
}
445447

446448
// 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
452455
} else {
453456
return SourceFile{}, err
454457
}
455458
}
456-
return SourceFile{SourceRoot: sourceRoot, BuildRoot: buildRoot, RelativePath: path}, nil
459+
return SourceFile{SourceRoot: sourceRoot, BuildRoot: buildRoot, RelativePath: srcPath}, nil
457460
}
458461

462+
// SourcePath returns the path to the source file
459463
func (f *SourceFile) SourcePath() *paths.Path {
460464
return f.SourceRoot.JoinPath(f.RelativePath)
461465
}
462466

467+
// ObjectPath returns the path to the object file (.o)
463468
func (f *SourceFile) ObjectPath() *paths.Path {
464469
return f.BuildRoot.Join(f.RelativePath.String() + ".o")
465470
}
466471

472+
// DepfilePath returns the path to the dependencies file (.d)
467473
func (f *SourceFile) DepfilePath() *paths.Path {
468474
return f.BuildRoot.Join(f.RelativePath.String() + ".d")
469475
}

0 commit comments

Comments
 (0)