New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prefactor package hashing #4816
Changes from 1 commit
d835690
c760457
4720f40
4b1fd4f
be50d8e
2b7e154
7bb65aa
57cd58e
8258d86
a55c004
a5f3b1b
5f3bcbe
269e49b
2df5983
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,7 +78,7 @@ func safeCompileIgnoreFile(filepath turbopath.AbsoluteSystemPath) (*gitignore.Gi | |
return gitignore.CompileIgnoreLines([]string{}...), nil | ||
} | ||
|
||
func GetPackageFileHashesFromProcessingGitIgnore(rootPath turbopath.AbsoluteSystemPath, packagePath turbopath.AnchoredSystemPath, inputs []string) (map[turbopath.AnchoredUnixPath]string, error) { | ||
func getPackageFileHashesFromProcessingGitIgnore(rootPath turbopath.AbsoluteSystemPath, packagePath turbopath.AnchoredSystemPath, inputs []string) (map[turbopath.AnchoredUnixPath]string, error) { | ||
result := make(map[turbopath.AnchoredUnixPath]string) | ||
absolutePackagePath := packagePath.RestoreAnchor(rootPath) | ||
|
||
|
@@ -224,12 +224,28 @@ func getPackageFileHashesFromInputs(rootPath turbopath.AbsoluteSystemPath, packa | |
return result, nil | ||
} | ||
|
||
// GetPackageDeps Builds an object containing git hashes for the files under the specified `packagePath` folder. | ||
func GetPackageDeps(rootPath turbopath.AbsoluteSystemPath, p *PackageDepsOptions) (map[turbopath.AnchoredUnixPath]string, error) { | ||
if len(p.InputPatterns) == 0 { | ||
return getPackageFileHashesFromGitIndex(rootPath, p.PackagePath) | ||
// GetPackageFileHashes Builds an object containing git hashes for the files under the specified `packagePath` folder. | ||
func GetPackageFileHashes(rootPath turbopath.AbsoluteSystemPath, packagePath turbopath.AnchoredSystemPath, inputs []string) map[turbopath.AnchoredUnixPath]string { | ||
if len(inputs) == 0 { | ||
result, err := getPackageFileHashesFromGitIndex(rootPath, packagePath) | ||
if err != nil { | ||
result, err := getPackageFileHashesFromProcessingGitIgnore(rootPath, packagePath, nil) | ||
if err != nil { | ||
return make(map[turbopath.AnchoredUnixPath]string) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
after carefully stepping through commits I realize this is the thing that you're trying to get to in the first place 🤣 |
||
} | ||
return result | ||
} | ||
return result | ||
} else { | ||
return getPackageFileHashesFromInputs(rootPath, p.PackagePath, p.InputPatterns) | ||
result, err := getPackageFileHashesFromInputs(rootPath, packagePath, inputs) | ||
if err != nil { | ||
result, err := getPackageFileHashesFromProcessingGitIgnore(rootPath, packagePath, inputs) | ||
if err != nil { | ||
return make(map[turbopath.AnchoredUnixPath]string) | ||
} | ||
return result | ||
} | ||
return result | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't fix the bug about not propagating the error yet. Right now I just faithfully migrate the bug into the new location. You can simply look at this method and tell that there are going to be numerous issues in how we process things. Our fallbacks are definitely not consistent. |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,19 +85,7 @@ func (pfs packageFileSpec) ToKey() packageFileHashKey { | |
} | ||
|
||
func (pfs *packageFileSpec) getHashObject(pkg *fs.PackageJSON, repoRoot turbopath.AbsoluteSystemPath) map[turbopath.AnchoredUnixPath]string { | ||
hashObject, pkgDepsErr := hashing.GetPackageDeps(repoRoot, &hashing.PackageDepsOptions{ | ||
PackagePath: pkg.Dir, | ||
InputPatterns: pfs.inputs, | ||
}) | ||
if pkgDepsErr != nil { | ||
manualHashObject, err := manuallyHashPackage(pkg, pfs.inputs, repoRoot) | ||
if err != nil { | ||
return make(map[turbopath.AnchoredUnixPath]string) | ||
} | ||
Comment on lines
-104
to
-106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bug that needs to get fixed. |
||
hashObject = manualHashObject | ||
} | ||
|
||
return hashObject | ||
return hashing.GetPackageFileHashes(repoRoot, pkg.Dir, pfs.inputs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is to push the fallback behavior into the hashing module itself, not at the consumption location. |
||
} | ||
|
||
func (pfs *packageFileSpec) hash(hashObject map[turbopath.AnchoredUnixPath]string) (string, error) { | ||
|
@@ -108,10 +96,6 @@ func (pfs *packageFileSpec) hash(hashObject map[turbopath.AnchoredUnixPath]strin | |
return hashOfFiles, nil | ||
} | ||
|
||
func manuallyHashPackage(pkg *fs.PackageJSON, inputs []string, rootPath turbopath.AbsoluteSystemPath) (map[turbopath.AnchoredUnixPath]string, error) { | ||
return hashing.GetPackageFileHashesFromProcessingGitIgnore(rootPath, pkg.Dir, inputs) | ||
} | ||
|
||
// packageFileHashes is a map from a package and optional input globs to the hash of | ||
// the matched files in the package. | ||
type packageFileHashes map[packageFileHashKey]string | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the actual difference between
getPackageFileHashesFromGitIndex
andgetPackageFileHashesFromProcessingGitIgnore
? And is it intentional?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know yet! I copy/pasted the implementations. Those three code paths should probably be just one.