owlbot.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Copyright 2022 Google LLC
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """This script is used to synthesize generated parts of this library."""
  15. import logging
  16. from pathlib import Path
  17. import shutil
  18. import subprocess
  19. import os
  20. import synthtool as s
  21. from synthtool.languages import php
  22. from synthtool import _tracked_paths
  23. logging.basicConfig(level=logging.DEBUG)
  24. # (dirname, version)
  25. protos = [
  26. ("api", "api"),
  27. ("extendedoperations", "cloud"),
  28. ("location", "cloud"),
  29. ("logging", "google"), # for the metadata
  30. ("logging", "cloud"),
  31. ("iam", "google"), # for the metadata
  32. ("iam", "cloud"),
  33. ("iamlogging", "iam"),
  34. ("rpc", "rpc"),
  35. ("type", "type"),
  36. ]
  37. dest = Path().resolve()
  38. for proto in protos:
  39. src = Path(f"{php.STAGING_DIR}/{proto[0]}").resolve()
  40. # Added so that we can pass copy_excludes in the owlbot_main() call
  41. _tracked_paths.add(src)
  42. # use owlbot_copy_version instead of owlbot_main and set "version_string"
  43. # manually because common protos do not have a version
  44. php.owlbot_copy_version(
  45. src=src,
  46. dest=dest,
  47. version_string=proto[1],
  48. copy_excludes=[
  49. src / "**/[A-Z]*_*.php"
  50. ],
  51. )
  52. # move metadata to more specific directories (owlbot isnt smart enough to do this)
  53. s.move("metadata/Google/Iam/V1", "metadata/Iam/V1")
  54. s.move("metadata/Google/Logging/Type", "metadata/Logging/Type")
  55. # remove owl-bot-staging dir
  56. if os.path.exists(php.STAGING_DIR):
  57. shutil.rmtree(Path(php.STAGING_DIR))
  58. # remove the metadata/Google files that we copied
  59. if os.path.exists("metadata/Google"):
  60. shutil.rmtree(Path("metadata/Google"))
  61. s.replace(
  62. "src/**/*.php",
  63. r"^// Adding a class alias for backwards compatibility with the previous class name.$"
  64. + "\n"
  65. + r"^class_alias\(.*\);$"
  66. + "\n",
  67. '')