Skip to content

Commit 68c66b1

Browse files
committed
Added some documentation to SourceFile struct and methods
1 parent e1073d4 commit 68c66b1

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
@@ -428,6 +428,8 @@ func (f *CppIncludesFinder) queueSourceFilesFromFolder(srcDir, buildDir *paths.P
428428
return nil
429429
}
430430

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

447449
// 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
453456
} else {
454457
return SourceFile{}, err
455458
}
456459
}
457-
return SourceFile{SourceRoot: sourceRoot, BuildRoot: buildRoot, RelativePath: path}, nil
460+
return SourceFile{SourceRoot: sourceRoot, BuildRoot: buildRoot, RelativePath: srcPath}, nil
458461
}
459462

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

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

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

0 commit comments

Comments
 (0)