CopyrightFixup.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/sh
  2. set -eu
  3. readonly DevToolsDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
  4. readonly RootDir="${DevToolsDir}/.."
  5. cd "${RootDir}"
  6. for f in `find . -name '*.swift' -o -name '*.cc' | sed -e 's|./||' | grep -v '.pb.swift'`; do
  7. if head -n 4 $f | grep 'DO NOT EDIT' > /dev/null; then
  8. # If the first lines contain 'DO NOT EDIT', then
  9. # this is a generated file and we should not
  10. # try to check or edit the copyright message.
  11. # But: print the filename; all such files should be .pb.swift
  12. # files that we're not even looking at here.
  13. echo "DO NOT EDIT: $f"
  14. else
  15. tmp=$f~
  16. mv $f $tmp
  17. if head -n 10 $tmp | grep 'Copyright.*Apple' > /dev/null; then
  18. # This has a copyright message, update it
  19. # Edit the first line to have the correct filename
  20. head -n 1 $tmp | sed "s|// [^-]* - \(.*\)|// $f - \1|" >$f
  21. # Followed by the current copyright text:
  22. cat <<EOF >>$f
  23. //
  24. // Copyright (c) 2014 - 2016 Apple Inc. and the project authors
  25. // Licensed under Apache License v2.0 with Runtime Library Exception
  26. //
  27. // See LICENSE.txt for license information:
  28. // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt
  29. EOF
  30. # Followed by the body of the file
  31. # The copyright message ends at the first blank comment line after
  32. # the first line containing "LICENSE.txt":
  33. cat $tmp | sed -n '/LICENSE.txt/,$ p' | sed -n '/^\/\/$/,$ p' >> $f
  34. rm $tmp
  35. else
  36. # This does not have a copyright message, insert one
  37. echo "Inserting copyright >> $f"
  38. cat <<EOF >>$f
  39. // $f - description
  40. //
  41. // Copyright (c) 2014 - 2017 Apple Inc. and the project authors
  42. // Licensed under Apache License v2.0 with Runtime Library Exception
  43. //
  44. // See LICENSE.txt for license information:
  45. // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt
  46. //
  47. EOF
  48. cat $tmp >> $f
  49. fi
  50. fi
  51. done