check_filenames.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (c) 2018, Google Inc.
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. // check_filenames.go checks that filenames are unique. Some of our consumers do
  15. // not support multiple files with the same name in the same build target, even
  16. // if they are in different directories.
  17. package main
  18. import (
  19. "fmt"
  20. "os"
  21. "path/filepath"
  22. "strings"
  23. )
  24. func isSourceFile(in string) bool {
  25. return strings.HasSuffix(in, ".c") || strings.HasSuffix(in, ".cc")
  26. }
  27. func main() {
  28. var roots = []string{
  29. "crypto",
  30. filepath.Join("third_party", "fiat"),
  31. "ssl",
  32. }
  33. names := make(map[string]string)
  34. var foundCollisions bool
  35. for _, root := range roots {
  36. err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
  37. if err != nil {
  38. return err
  39. }
  40. if info.IsDir() {
  41. return nil
  42. }
  43. name := strings.ToLower(info.Name()) // Windows and macOS are case-insensitive.
  44. if isSourceFile(name) {
  45. if oldPath, ok := names[name]; ok {
  46. fmt.Printf("Filename collision found: %s and %s\n", path, oldPath)
  47. foundCollisions = true
  48. } else {
  49. names[name] = path
  50. }
  51. }
  52. return nil
  53. })
  54. if err != nil {
  55. fmt.Printf("Error traversing %s: %s\n", root, err)
  56. os.Exit(1)
  57. }
  58. }
  59. if foundCollisions {
  60. os.Exit(1)
  61. }
  62. }