Skip to content

Commit 06c66e7

Browse files
committed
Added some documentation to SourceFile struct and methods
1 parent 1da2a07 commit 06c66e7

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
@@ -446,6 +446,8 @@ func (f *CppIncludesFinder) queueSourceFilesFromFolder(srcDir, buildDir *paths.P
446446
return nil
447447
}
448448

449+
// SourceFile represent a source file, it keeps a reference to the root source
450+
// directory and the corresponding build root directory.
449451
type SourceFile struct {
450452
// SourceRoot is the path to the source code root directory
451453
SourceRoot *paths.Path
@@ -463,26 +465,30 @@ func (f SourceFile) String() string {
463465
}
464466

465467
// 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
471474
} else {
472475
return SourceFile{}, err
473476
}
474477
}
475-
return SourceFile{SourceRoot: sourceRoot, BuildRoot: buildRoot, RelativePath: path}, nil
478+
return SourceFile{SourceRoot: sourceRoot, BuildRoot: buildRoot, RelativePath: srcPath}, nil
476479
}
477480

481+
// SourcePath returns the path to the source file
478482
func (f *SourceFile) SourcePath() *paths.Path {
479483
return f.SourceRoot.JoinPath(f.RelativePath)
480484
}
481485

486+
// ObjectPath returns the path to the object file (.o)
482487
func (f *SourceFile) ObjectPath() *paths.Path {
483488
return f.BuildRoot.Join(f.RelativePath.String() + ".o")
484489
}
485490

491+
// DepfilePath returns the path to the dependencies file (.d)
486492
func (f *SourceFile) DepfilePath() *paths.Path {
487493
return f.BuildRoot.Join(f.RelativePath.String() + ".d")
488494
}

0 commit comments

Comments
 (0)