metadata
3 years ago
src
3 years ago
.OwlBot.yaml
3 years ago
.repo-metadata.json
3 years ago
CODE_OF_CONDUCT.md
3 years ago
LICENSE
3 years ago
SECURITY.md
3 years ago
VERSION
3 years ago
composer.json
3 years ago
owlbot.py
3 years ago
owlbot.py
113 lines
| 1 | # Copyright 2020 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 | |
| 15 | """This script is used to synthesize generated parts of this library.""" |
| 16 | |
| 17 | import logging |
| 18 | from pathlib import Path |
| 19 | import subprocess |
| 20 | |
| 21 | import synthtool as s |
| 22 | from synthtool.languages import php |
| 23 | from synthtool import _tracked_paths |
| 24 | |
| 25 | logging.basicConfig(level=logging.DEBUG) |
| 26 | |
| 27 | src = Path(f"../{php.STAGING_DIR}/AnalyticsData").resolve() |
| 28 | dest = Path().resolve() |
| 29 | |
| 30 | # Added so that we can pass copy_excludes in the owlbot_main() call |
| 31 | _tracked_paths.add(src) |
| 32 | |
| 33 | php.owlbot_main( |
| 34 | src=src, |
| 35 | dest=dest, |
| 36 | copy_excludes=[ |
| 37 | src / "**/[A-Z]*_*.php" |
| 38 | ] |
| 39 | ) |
| 40 | |
| 41 | # remove class_alias code |
| 42 | s.replace( |
| 43 | "src/V*/**/*.php", |
| 44 | r"^// Adding a class alias for backwards compatibility with the previous class name.$" |
| 45 | + "\n" |
| 46 | + r"^class_alias\(.*\);$" |
| 47 | + "\n", |
| 48 | '') |
| 49 | |
| 50 | # document and utilize apiEndpoint instead of serviceAddress |
| 51 | s.replace( |
| 52 | "**/Gapic/*GapicClient.php", |
| 53 | r"'serviceAddress' =>", |
| 54 | r"'apiEndpoint' =>") |
| 55 | s.replace( |
| 56 | "**/Gapic/*GapicClient.php", |
| 57 | r"@type string \$serviceAddress\n\s+\*\s+The address", |
| 58 | r"""@type string $serviceAddress |
| 59 | * **Deprecated**. This option will be removed in a future major release. Please |
| 60 | * utilize the `$apiEndpoint` option instead. |
| 61 | * @type string $apiEndpoint |
| 62 | * The address""") |
| 63 | s.replace( |
| 64 | "**/Gapic/*GapicClient.php", |
| 65 | r"\$transportConfig, and any \$serviceAddress", |
| 66 | r"$transportConfig, and any `$apiEndpoint`") |
| 67 | |
| 68 | ### [START] protoc backwards compatibility fixes |
| 69 | |
| 70 | # roll back to private properties. |
| 71 | s.replace( |
| 72 | "src/**/V*/**/*.php", |
| 73 | r"Generated from protobuf field ([^\n]{0,})\n\s{5}\*/\n\s{4}protected \$", |
| 74 | r"""Generated from protobuf field \1 |
| 75 | */ |
| 76 | private $""") |
| 77 | |
| 78 | # prevent proto messages from being marked final |
| 79 | s.replace( |
| 80 | "src/**/V*/**/*.php", |
| 81 | r"final class", |
| 82 | r"class") |
| 83 | |
| 84 | # Replace "Unwrapped" with "Value" for method names. |
| 85 | s.replace( |
| 86 | "src/**/V*/**/*.php", |
| 87 | r"public function ([s|g]\w{3,})Unwrapped", |
| 88 | r"public function \1Value" |
| 89 | ) |
| 90 | |
| 91 | ### [END] protoc backwards compatibility fixes |
| 92 | |
| 93 | # fix relative cloud.google.com links |
| 94 | s.replace( |
| 95 | "src/**/V*/**/*.php", |
| 96 | r"(.{0,})\]\((/.{0,})\)", |
| 97 | r"\1](https://cloud.google.com\2)" |
| 98 | ) |
| 99 | |
| 100 | # format generated clients |
| 101 | subprocess.run([ |
| 102 | 'npm', |
| 103 | 'exec', |
| 104 | '--yes', |
| 105 | '--package=@prettier/plugin-php@^0.16', |
| 106 | '--', |
| 107 | 'prettier', |
| 108 | '**/Gapic/*', |
| 109 | '--write', |
| 110 | '--parser=php', |
| 111 | '--single-quote', |
| 112 | '--print-width=80']) |
| 113 |