Merge pull request #1639 from sigma/pr/fix-legal-sources

prune: Fix handling of "legal" source files
This commit is contained in:
sam boyer 2018-07-01 23:25:57 -04:00 коммит произвёл GitHub
Родитель bacd8dc5ba 03ec624619
Коммит a545e3a9ce
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 38 добавлений и 25 удалений

Просмотреть файл

@ -260,6 +260,37 @@ func collectUnusedPackagesFiles(fsState filesystemState, unusedPackages map[stri
return files
}
func isSourceFile(path string) bool {
ext := fileExt(path)
// Refer to: https://github.com/golang/go/blob/release-branch.go1.9/src/go/build/build.go#L750
switch ext {
case ".go":
return true
case ".c":
return true
case ".cc", ".cpp", ".cxx":
return true
case ".m":
return true
case ".h", ".hh", ".hpp", ".hxx":
return true
case ".f", ".F", ".for", ".f90":
return true
case ".s":
return true
case ".S":
return true
case ".swig":
return true
case ".swigcxx":
return true
case ".syso":
return true
}
return false
}
// pruneNonGoFiles delete all non-Go files existing in fsState.
//
// Files matching licenseFilePrefixes and legalFileSubstrings are not pruned.
@ -267,31 +298,7 @@ func pruneNonGoFiles(fsState filesystemState) error {
toDelete := make([]string, 0, len(fsState.files)/4)
for _, path := range fsState.files {
ext := fileExt(path)
// Refer to: https://github.com/golang/go/blob/release-branch.go1.9/src/go/build/build.go#L750
switch ext {
case ".go":
continue
case ".c":
continue
case ".cc", ".cpp", ".cxx":
continue
case ".m":
continue
case ".h", ".hh", ".hpp", ".hxx":
continue
case ".f", ".F", ".for", ".f90":
continue
case ".s":
continue
case ".S":
continue
case ".swig":
continue
case ".swigcxx":
continue
case ".syso":
if isSourceFile(path) {
continue
}
@ -314,7 +321,12 @@ func pruneNonGoFiles(fsState filesystemState) error {
// isPreservedFile checks if the file name indicates that the file should be
// preserved based on licenseFilePrefixes or legalFileSubstrings.
// This applies only to non-source files.
func isPreservedFile(name string) bool {
if isSourceFile(name) {
return false
}
name = strings.ToLower(name)
for _, prefix := range licenseFilePrefixes {

Просмотреть файл

@ -213,6 +213,7 @@ func TestPruneUnusedPackages(t *testing.T) {
"COPYING",
"pkg/main.go",
"pkg/nestedpkg/main.go",
"pkg/nestedpkg/legal.go",
"pkg/nestedpkg/PATENT.md",
"pkg/nestedpkg/otherpkg/main.go",
},