Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

diff_asm.go 3.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* Copyright (c) 2016, 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. package main
  15. import (
  16. "flag"
  17. "fmt"
  18. "os"
  19. "os/exec"
  20. "path/filepath"
  21. "strings"
  22. "syscall"
  23. )
  24. var (
  25. boringsslDir = flag.String("boringssl", ".", "The path to the BoringSSL checkout.")
  26. opensslDir = flag.String("openssl", filepath.Join("..", "openssl"), "The path to the OpenSSL checkout.")
  27. )
  28. func mapName(path string) string {
  29. switch filepath.ToSlash(path) {
  30. case "crypto/rand/asm/rdrand-x86_64.pl":
  31. return ""
  32. case "crypto/ec/asm/p256-x86_64-asm.pl":
  33. return filepath.FromSlash("crypto/ec/asm/ecp_nistz256-x86_64.pl")
  34. }
  35. return path
  36. }
  37. func diff(from, to string) error {
  38. cmd := exec.Command("diff", "-u", "--", from, to)
  39. cmd.Stdout = os.Stdout
  40. cmd.Stderr = os.Stderr
  41. err := cmd.Run()
  42. // diff returns exit code 1 if the files differ but it was otherwise
  43. // successful.
  44. if exitError, ok := err.(*exec.ExitError); ok && exitError.Sys().(syscall.WaitStatus).ExitStatus() == 1 {
  45. return nil
  46. }
  47. return err
  48. }
  49. func main() {
  50. flag.Usage = func() {
  51. fmt.Fprintf(os.Stderr, "Usage: diff_asm [flag...] [filter...]\n")
  52. fmt.Fprintf(os.Stderr, "Filter arguments limit to assembly files which match arguments.\n")
  53. fmt.Fprintf(os.Stderr, "If not using a filter, piping to `diffstat` may be useful.\n\n")
  54. flag.PrintDefaults()
  55. }
  56. flag.Parse()
  57. // Find all the assembly files.
  58. var files []string
  59. err := filepath.Walk(*boringsslDir, func(path string, info os.FileInfo, err error) error {
  60. if err != nil {
  61. return nil
  62. }
  63. path, err = filepath.Rel(*boringsslDir, path)
  64. if err != nil {
  65. return err
  66. }
  67. dir := filepath.Base(filepath.Dir(path))
  68. if !info.IsDir() && (dir == "asm" || dir == "perlasm") && strings.HasSuffix(filepath.Base(path), ".pl") {
  69. files = append(files, path)
  70. }
  71. return nil
  72. })
  73. if err != nil {
  74. fmt.Fprintf(os.Stderr, "Error finding assembly: %s\n", err)
  75. os.Exit(1)
  76. }
  77. for _, file := range files {
  78. opensslFile := mapName(file)
  79. if len(opensslFile) == 0 {
  80. continue
  81. }
  82. if flag.NArg() > 0 {
  83. var found bool
  84. for _, arg := range flag.Args() {
  85. if strings.Contains(file, arg) {
  86. found = true
  87. break
  88. }
  89. }
  90. if !found {
  91. continue
  92. }
  93. }
  94. if err := diff(filepath.Join(*opensslDir, opensslFile), filepath.Join(*boringsslDir, file)); err != nil {
  95. fmt.Fprintf(os.Stderr, "Error comparing %s: %s\n", file, err)
  96. os.Exit(1)
  97. }
  98. }
  99. }