Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable generation with postprocessing of multiple service versions #2342

Merged
merged 219 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
219 commits
Select commit Hold shift + click to select a range
1394f1c
use local synthtool and owlbot
diegomarquezp Nov 9, 2023
bf80792
remove unused files
diegomarquezp Nov 9, 2023
ce3e9a2
remove more unused files
diegomarquezp Nov 9, 2023
76d4892
remove cache files in owlbot
diegomarquezp Nov 9, 2023
bd00a72
use java 11 for it
diegomarquezp Nov 9, 2023
988132e
remove kokoro files
diegomarquezp Nov 9, 2023
5b1b70e
use glob in owlbot entrypoint
diegomarquezp Nov 9, 2023
5340c39
remove unused files
diegomarquezp Nov 9, 2023
c62a373
do not do post-process IT on mac
diegomarquezp Nov 9, 2023
3f28553
concise entrypoint logic
diegomarquezp Nov 13, 2023
46a0c89
cleanup i
diegomarquezp Nov 13, 2023
ddf202e
cleanup ii
diegomarquezp Nov 13, 2023
7cfbd6f
cleanup iii
diegomarquezp Nov 13, 2023
a2b843d
cleanup iv
diegomarquezp Nov 13, 2023
35b7916
remove templates
diegomarquezp Nov 13, 2023
81d4d60
remove protos folder
diegomarquezp Nov 13, 2023
1e9a788
remove synthtool
diegomarquezp Nov 17, 2023
d99e0ae
connect image to owlbot entrypoint
diegomarquezp Nov 17, 2023
b1baed7
simplify synthtool docker run command
diegomarquezp Nov 17, 2023
860c45b
install synthtool locally
diegomarquezp Dec 1, 2023
6755cd1
install synthtool only once
diegomarquezp Dec 1, 2023
6ecef4e
Merge remote-tracking branch 'origin/main' into local-owlbot-java-owl…
diegomarquezp Dec 1, 2023
558118d
use virtualenvs to run python scripts
diegomarquezp Dec 1, 2023
f8183f8
install pyenv in action
diegomarquezp Dec 1, 2023
bdb6cd0
remove jar from history
diegomarquezp Dec 1, 2023
e42fc0f
download google-java-format
diegomarquezp Dec 1, 2023
4c489e6
fix pyenv init
diegomarquezp Dec 1, 2023
d125c9d
attempt to fix pyenv installation in gh action
diegomarquezp Dec 5, 2023
40c5d24
fix manual pyenv installation
diegomarquezp Dec 5, 2023
60075b3
install pyenv in profile
diegomarquezp Dec 5, 2023
e956f4f
install pyenv in bashrc as well
diegomarquezp Dec 5, 2023
0d1c466
use bash shell explicitly in gh action
diegomarquezp Dec 5, 2023
0e6d547
install pyenv in same step as IT
diegomarquezp Dec 5, 2023
7604f3c
do not restart shell
diegomarquezp Dec 5, 2023
5cce976
set pyenv path manually
diegomarquezp Dec 5, 2023
30392b8
install pyenv in its own step
diegomarquezp Dec 5, 2023
29291a7
propagate environment variables to other steps
diegomarquezp Dec 5, 2023
ecd3b13
fix global env var setup
diegomarquezp Dec 5, 2023
87ac0ab
remove wrong env settings
diegomarquezp Dec 5, 2023
91d5be6
explain usage of pyenv in README
diegomarquezp Dec 5, 2023
9d4a54c
simplify pyenv setup
diegomarquezp Dec 5, 2023
f923b65
add comment to owlbot entrypoint
diegomarquezp Dec 5, 2023
6bda94a
rename destination_path to preprocessed_libraries_path
diegomarquezp Dec 6, 2023
e27a402
infer scripts_root in postprocess_library.sh
diegomarquezp Dec 6, 2023
182c111
use temporary folder for preprocess step
diegomarquezp Dec 6, 2023
d0db9a0
use owlbot files from workspace
diegomarquezp Dec 6, 2023
4516ba4
get rid of output_folder argument
diegomarquezp Dec 7, 2023
d59e65c
use common temp dir to clone synthtool into
diegomarquezp Dec 7, 2023
d0915f3
lock synthtool to a specific commitish
diegomarquezp Dec 7, 2023
e7ea3b1
fix file transfer
diegomarquezp Dec 7, 2023
8ab96e1
fix owl-bot-staging unpacking
diegomarquezp Dec 7, 2023
b140e08
remove unnecessary workspace variable
diegomarquezp Dec 10, 2023
60736ae
rename workspace to postprocessing_target
diegomarquezp Dec 10, 2023
39c3156
remove owlbot sha logic
diegomarquezp Dec 10, 2023
ba561c2
remove repository_root variable
diegomarquezp Dec 10, 2023
86e6a3f
cleanup
diegomarquezp Dec 10, 2023
c98ba18
correct pyenv comment
diegomarquezp Dec 10, 2023
b453c47
clean temp sources folder on each run
diegomarquezp Dec 10, 2023
65f0090
safety checks for get_proto_path_from_preprocessed_sources
diegomarquezp Dec 10, 2023
143534a
fix integration test
diegomarquezp Dec 12, 2023
57e81fa
Merge remote-tracking branch 'origin/main' into move-java-owlbot
diegomarquezp Dec 12, 2023
91fd696
disable compute and asset/v1p2beta1 temporarily
diegomarquezp Dec 12, 2023
33e268a
fix unit tests
diegomarquezp Dec 13, 2023
ae3e577
correct comment
diegomarquezp Dec 13, 2023
b37cc0d
do not install docker for macos
diegomarquezp Dec 13, 2023
1d25e77
fix owlbot files check
diegomarquezp Dec 13, 2023
f0ec962
fix license headers
diegomarquezp Dec 13, 2023
a179552
remove unnecessary owlbot_sha
diegomarquezp Dec 13, 2023
3c20c45
add explanation on why are there no macos + postprocess ITs
diegomarquezp Dec 14, 2023
a38efb0
use `fmt:format` instead of google formatter
diegomarquezp Dec 15, 2023
1d97cdf
clean templates
diegomarquezp Dec 15, 2023
747560f
remove more unnecessary elements
diegomarquezp Dec 15, 2023
f2c937d
add README entry explaining owlbot maintenance
diegomarquezp Dec 18, 2023
5bc7c7f
remove unnecessary java format version
diegomarquezp Dec 18, 2023
8d64968
wip: create generate_composed_library.sh
diegomarquezp Dec 13, 2023
d02d9dc
initial implementation of generate_composed_library.sh
diegomarquezp Dec 13, 2023
b1ac128
partial implementation of scripts
diegomarquezp Dec 14, 2023
6638c62
wip: fixes after main changes
diegomarquezp Dec 15, 2023
db38d50
partial implementation of scripts ii
diegomarquezp Jan 2, 2024
d75e7eb
correct arg parsing
diegomarquezp Jan 3, 2024
791e3e5
fixes in python utils
diegomarquezp Jan 3, 2024
32fc6c9
fix generate_library call
diegomarquezp Jan 3, 2024
e31cf7f
correct argument preparation
diegomarquezp Jan 3, 2024
e645fbb
add gapic generatior version arg check
diegomarquezp Jan 3, 2024
bcd9b24
call generate_library successfully
diegomarquezp Jan 3, 2024
94f0c81
fix postprocessing step in generate_composed
diegomarquezp Jan 3, 2024
87fb4a7
IT working for all libraries
diegomarquezp Jan 5, 2024
db6098c
add unit tests
diegomarquezp Jan 5, 2024
bd6090a
Merge remote-tracking branch 'origin/main' into postprocess-hw-libs
diegomarquezp Jan 5, 2024
a0147ce
fix comments in generate_composed_lib
diegomarquezp Jan 5, 2024
ea9cd50
remove commented code
diegomarquezp Jan 5, 2024
01a52f3
prepare tests without postprocessing
diegomarquezp Jan 5, 2024
729ec8d
restore test functions
diegomarquezp Jan 5, 2024
405c9ef
fix rename utility for building owlbot folder
diegomarquezp Jan 5, 2024
2a4a9c1
correct linter problems
diegomarquezp Jan 5, 2024
cad820d
install realpath on macos
diegomarquezp Jan 5, 2024
d394480
install utils also in unit tests
diegomarquezp Jan 5, 2024
64eb6a9
include utilities.sh in showcase scripts
diegomarquezp Jan 5, 2024
293bdca
comment py_util
diegomarquezp Jan 5, 2024
74a1423
Update library_generation/generate_composed_library.sh
diegomarquezp Jan 5, 2024
5465802
add comment explaining usage of coreutils in macos workflow
diegomarquezp Jan 8, 2024
16e0f27
explain that entrypoint.sh can be used for HW libraries
diegomarquezp Jan 8, 2024
ff33eb8
use real world example for generate_composed_library.sh
diegomarquezp Jan 8, 2024
d321a97
improve versions.txt explanation in generate_composed_library
diegomarquezp Jan 8, 2024
39f9342
add return type in python utils
diegomarquezp Jan 8, 2024
05d90cc
Merge remote-tracking branch 'refs/remotes/origin/postprocess-hw-libs…
diegomarquezp Jan 8, 2024
d4becd3
fix versions file inference
diegomarquezp Jan 8, 2024
129b51e
Merge remote-tracking branch 'origin/main' into postprocess-hw-libs
diegomarquezp Jan 8, 2024
201fe3c
use ggj 2.29 to fix ITs temporarily
diegomarquezp Jan 8, 2024
845c489
disable asset due to licence year mismatch
diegomarquezp Jan 8, 2024
da0063d
improve commment in generate_composed_library
diegomarquezp Jan 8, 2024
315bb3e
restore latest generator
diegomarquezp Jan 8, 2024
29789a9
remove wrong WORKSPACE comment
diegomarquezp Jan 9, 2024
c6f03b1
improve composed_library input comment
diegomarquezp Jan 9, 2024
482e35c
Update library_generation/utilities.py
diegomarquezp Jan 10, 2024
9dbeb9b
remove postprocessing logic in generate_library
diegomarquezp Jan 10, 2024
10d0102
add generated_composed_library.py
diegomarquezp Jan 10, 2024
d6873f8
use python script in IT
diegomarquezp Jan 10, 2024
22ee199
iterative fixes
diegomarquezp Jan 10, 2024
4ccebae
ignore python cache
diegomarquezp Jan 10, 2024
899f781
iterative fixes ii
diegomarquezp Jan 10, 2024
eefe8d5
Merge remote-tracking branch 'refs/remotes/origin/postprocess-hw-libs…
diegomarquezp Jan 10, 2024
c05865a
Update library_generation/generate_composed_library.py
diegomarquezp Jan 11, 2024
c490e69
Update library_generation/utilities.py
diegomarquezp Jan 11, 2024
265b446
Update library_generation/generate_composed_library.py
diegomarquezp Jan 11, 2024
0cd5167
Merge remote-tracking branch 'origin/main' into postprocess-hw-libs
diegomarquezp Jan 12, 2024
6f5de37
use underscores in configuration yaml
diegomarquezp Jan 12, 2024
38306dd
initial model for gapic config yaml
diegomarquezp Jan 12, 2024
b691273
add requirements file
diegomarquezp Jan 15, 2024
ebcb4d0
introduce yaml parsing logic
diegomarquezp Jan 15, 2024
53be45f
move parse logic to GenerationConfig
diegomarquezp Jan 15, 2024
c4b937f
adapt composed_library script
diegomarquezp Jan 15, 2024
781effb
fixes i
diegomarquezp Jan 15, 2024
ba21ba2
set IT to dummy mode
diegomarquezp Jan 15, 2024
9c54df4
Merge remote-tracking branch 'refs/remotes/origin/postprocess-hw-libs…
diegomarquezp Jan 15, 2024
dd1ded0
pass BUILD parse utils to production utils
diegomarquezp Jan 16, 2024
d340731
fixes ii - constructor calls and composed_library arguments
diegomarquezp Jan 16, 2024
4ee3ece
Merge remote-tracking branch 'origin/main' into postprocess-hw-libs
diegomarquezp Jan 17, 2024
68ea9ae
fix destination path for partial generations
diegomarquezp Jan 17, 2024
25669bc
adapt IT to process individual libraries
diegomarquezp Jan 17, 2024
cf17afd
use proper versions in configuration yaml
diegomarquezp Jan 18, 2024
1e18a5d
add rest of the libraries to integration test
diegomarquezp Jan 18, 2024
9101a2f
add library_type to config yaml
diegomarquezp Jan 18, 2024
78b604a
reference to parent directory in compare_poms
diegomarquezp Jan 18, 2024
965e3ed
handle script failures
diegomarquezp Jan 19, 2024
7d23fba
use library-specific googleapis_commitish
diegomarquezp Jan 19, 2024
06df744
fix protobuf version
diegomarquezp Jan 19, 2024
e79196c
install python reqs in Github Action
diegomarquezp Jan 19, 2024
e3ebd4e
fix python version path logic
diegomarquezp Jan 19, 2024
2c20ee7
add python unit tests
diegomarquezp Jan 19, 2024
9150cac
remove obsolete py_util tests
diegomarquezp Jan 19, 2024
45bd0e7
add python unit tests in workflow
diegomarquezp Jan 19, 2024
5f93c0a
correct type hinting for Library
diegomarquezp Jan 19, 2024
4608fb2
fix comments
diegomarquezp Jan 22, 2024
76c75b1
set enable_postprocessing input to main.py to boolean
diegomarquezp Jan 22, 2024
1c6c413
add explanation on library_type
diegomarquezp Jan 22, 2024
65ca5d9
remove old proto_path_list
diegomarquezp Jan 22, 2024
ca8ad9e
fix comments in IT
diegomarquezp Jan 22, 2024
32c9f26
remove WORKSPACE file usage
diegomarquezp Jan 22, 2024
d8d5712
Merge remote-tracking branch 'origin/main' into postprocess-hw-libs
diegomarquezp Jan 22, 2024
69341d7
add IT configuration yaml for java-bigtable
diegomarquezp Jan 22, 2024
1ccdce8
fix config yaml for bigtable
diegomarquezp Jan 22, 2024
ac63e21
finish tests for HW bigtable
diegomarquezp Jan 22, 2024
7aab0a5
install python in gh action, lint fix
diegomarquezp Jan 22, 2024
35c1ace
update ggj to 2.32.0
diegomarquezp Jan 22, 2024
acf07a5
fix showcase test
diegomarquezp Jan 22, 2024
0ada730
remove commented line
diegomarquezp Jan 22, 2024
215fed3
use owlbot cli sha from config yaml
diegomarquezp Jan 23, 2024
e5d065b
use python version from config yaml
diegomarquezp Jan 23, 2024
594f44d
use synthtool commitish from config yaml
diegomarquezp Jan 23, 2024
6b5a0d6
add repository_path option
diegomarquezp Jan 23, 2024
54fa240
make destination_path required
diegomarquezp Jan 23, 2024
c11f0da
add typing
diegomarquezp Jan 23, 2024
e94f5e9
use python version from config yaml
diegomarquezp Jan 23, 2024
c146d26
correct workflow indentation
diegomarquezp Jan 23, 2024
95e9766
fix workflow syntax
diegomarquezp Jan 23, 2024
0630bc8
use repository_path when postprocessing
diegomarquezp Jan 23, 2024
4af6821
correct runs-on in workflow
diegomarquezp Jan 23, 2024
21d13ec
use full path to repo in workflow
diegomarquezp Jan 23, 2024
d699173
add debug output in workflow
diegomarquezp Jan 23, 2024
94e3024
decompose steps to compute python version
diegomarquezp Jan 23, 2024
c073437
checout code in workflow
diegomarquezp Jan 23, 2024
88c2243
fix function name in workflow
diegomarquezp Jan 23, 2024
92b77bd
use full path to obtain python version from yaml
diegomarquezp Jan 23, 2024
42fe78b
use correct path in python version workflow
diegomarquezp Jan 23, 2024
c7aca9f
use set-output to share python version
diegomarquezp Jan 23, 2024
cea015c
fix set-output call
diegomarquezp Jan 23, 2024
c62c8e9
fix output setting in workflow
diegomarquezp Jan 23, 2024
6bc566a
correct python version letter case
diegomarquezp Jan 24, 2024
83e7ab2
remove pyenv setup
diegomarquezp Jan 24, 2024
6e83e05
fix repository_path
diegomarquezp Jan 24, 2024
f1e5a46
fix speech proto_path
diegomarquezp Jan 24, 2024
5a7418c
do not wipe out google-cloud-java in IT
diegomarquezp Jan 24, 2024
6f2d868
ensure correct version of python compares the poms
diegomarquezp Jan 24, 2024
1bf473a
fix diff check
diegomarquezp Jan 24, 2024
3665940
add return type for GenerationCOnfig.from_yaml
diegomarquezp Jan 24, 2024
bfa1344
add missing python unit tests
diegomarquezp Jan 24, 2024
73dc71f
use default values for enable_postprocessing
diegomarquezp Jan 24, 2024
f0b26ef
use is_monorepo var, constant for google-coud-java
diegomarquezp Jan 24, 2024
b1d0cbc
fixes for local run
diegomarquezp Jan 26, 2024
90e731e
compute monorepo variable heuristically
diegomarquezp Jan 26, 2024
8acc122
update generation configs
diegomarquezp Jan 26, 2024
97b14c7
remove python version
diegomarquezp Jan 26, 2024
5e02b03
rename Library to LibraryConfig
diegomarquezp Jan 26, 2024
fbd3111
rename GAPIC to GapicConfig
diegomarquezp Jan 26, 2024
7f43113
Merge remote-tracking branch 'origin/main' into postprocess-hw-libs
diegomarquezp Jan 26, 2024
797a841
remove quotes from grpc version
diegomarquezp Jan 26, 2024
14164e8
move ClientInputs to model folder
diegomarquezp Jan 26, 2024
e3aaac2
parse BUILD file using ClientInputs
diegomarquezp Jan 26, 2024
04c98b1
add unit tests for ClientInputs
diegomarquezp Jan 26, 2024
7059654
fix CLientInputs typo
diegomarquezp Jan 26, 2024
2b82a39
fix synthtool version
diegomarquezp Jan 26, 2024
2ad5408
disable compute test
diegomarquezp Jan 26, 2024
51051bf
fix unit test
diegomarquezp Jan 27, 2024
cd90663
fix compute test
diegomarquezp Jan 29, 2024
9a5708b
fix unit tests
diegomarquezp Jan 29, 2024
f236240
remove BUILD parsing shell utilities
diegomarquezp Jan 29, 2024
f2c8532
update monorepo special treatment comment
diegomarquezp Jan 29, 2024
3bff22a
fix typo in shebang
diegomarquezp Jan 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions .github/workflows/verify_library_generation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
cache: maven
- uses: actions/setup-python@v4
with:
python-version: '3.11'
python-version: 3.11
- name: install pyenv
shell: bash
run: |
Expand All @@ -36,10 +36,23 @@ jobs:
export PATH="$PYENV_ROOT/bin:$PATH"
echo "PYENV_ROOT=${PYENV_ROOT}" >> $GITHUB_ENV
echo "PATH=${PATH}" >> $GITHUB_ENV
# init pyenv
eval "$(pyenv init --path)"
eval "$(pyenv init -)"

set +ex
- name: install python dependencies
shell: bash
run: |
set -ex
pushd library_generation
pip install -r requirements.in
popd

- name: install utils (macos)
if: matrix.os == 'macos-12'
shell: bash
run: |
brew update --preinstall
# we need the `realpath` command to be available
brew install coreutils
suztomo marked this conversation as resolved.
Show resolved Hide resolved
- name: install docker (ubuntu)
if: matrix.os == 'ubuntu-22.04'
shell: bash
Expand Down Expand Up @@ -69,10 +82,30 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Run unit tests
- name: install utils (macos)
if: matrix.os == 'macos-12'
shell: bash
run: |
brew update --preinstall
brew install coreutils
- uses: actions/setup-python@v4
with:
python-version: 3.11
- name: install python dependencies
shell: bash
run: |
set -ex
pushd library_generation
pip install -r requirements.in
popd
- name: Run shell unit tests
run: |
set -x
library_generation/test/generate_library_unit_tests.sh
- name: Run python unit tests
run: |
set -x
python -m unittest library_generation/test/unit_tests.py
lint:
runs-on: ubuntu-22.04
steps:
Expand Down
1 change: 1 addition & 0 deletions library_generation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
141 changes: 141 additions & 0 deletions library_generation/generate_composed_library.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
"""
This script allows generation of libraries that are composed of more than one
service version. It is achieved by calling `generate_library.sh` without
postprocessing for all service versions and then calling
postprocess_library.sh at the end, once all libraries are ready.

Prerequisites
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the caller need to run "git clone" for the repository this script creates a commit in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is optional. If the user specifies --repository_path in main.py, then the generated source code will be sent to such path. If not specified, the composed_library script will download the repository into output_folder and send the generated sources there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also added a small explanation

- repository_path: path to the repository where the generated files will be
sent. If not specified, it will be downloaded. The versions file will be inferred from this folder

- Needs a folder named `output` in current working directory. This folder
is automatically detected by `generate_library.sh` and this script ensures it
contains the necessary folders and files, specifically:
- A "google" folder found in the googleapis/googleapis repository
- A "grafeas" folder found in the googleapis/googleapis repository
Note: googleapis repo is found in https://github.com/googleapis/googleapis.
"""

import click
import utilities as util
import os
import sys
import subprocess
import json
from model.GenerationConfig import GenerationConfig
from model.LibraryConfig import LibraryConfig
from model.ClientInputs import parse as parse_build_file

script_dir = os.path.dirname(os.path.realpath(__file__))

"""
Main function in charge of generating libraries composed of more than one
service or service version.
Arguments
- config: a GenerationConfig object representing a parsed configuration
yaml
- library: a LibraryConfig object contained inside config, passed here for
convenience and to prevent all libraries to be processed
- enable_postprocessing: true if postprocessing should be done on the generated
libraries
- repository_path: path to the repository where the generated files will be
sent. If not specified, it will default to the one defined in the configuration yaml
and will be downloaded. The versions file will be inferred from this folder
"""
def generate_composed_library(
config: GenerationConfig,
library: LibraryConfig,
repository_path: str,
enable_postprocessing: bool = True,
) -> None:
output_folder = util.sh_util('get_output_folder')

print(f'output_folder: {output_folder}')
print('library: ', library)
os.makedirs(output_folder, exist_ok=True)

googleapis_commitish = config.googleapis_commitish
if library.googleapis_commitish is not None:
googleapis_commitish = library.googleapis_commitish
print('using library-specific googleapis commitish: ' + googleapis_commitish)
else:
print('using common googleapis_commitish')

print('removing old googleapis folders and files')
util.delete_if_exists(f'{output_folder}/google')
util.delete_if_exists(f'{output_folder}/grafeas')

print('downloading googleapis')
util.sh_util(f'download_googleapis_files_and_folders "{output_folder}" "{googleapis_commitish}"')

is_monorepo = len(config.libraries) > 1

base_arguments = []
base_arguments += util.create_argument('gapic_generator_version', config)
base_arguments += util.create_argument('grpc_version', config)
base_arguments += util.create_argument('protobuf_version', config)

library_name = f'java-{library.api_shortname}'
library_path = None

versions_file = ''
if is_monorepo:
print('this is a monorepo library')
destination_path = config.destination_path + '/' + library_name
library_folder = destination_path.split('/')[-1]
if repository_path is None:
print(f'sparse_cloning monorepo with {library_name}')
repository_path = f'{output_folder}/{config.destination_path}'
clone_out = util.sh_util(f'sparse_clone "https://github.com/googleapis/{MONOREPO_NAME}.git" "{library_folder} google-cloud-pom-parent google-cloud-jar-parent versions.txt .github"', cwd=output_folder)
print(clone_out)
library_path = f'{repository_path}/{library_name}'
versions_file = f'{repository_path}/versions.txt'
else:
print('this is a HW library')
diegomarquezp marked this conversation as resolved.
Show resolved Hide resolved
destination_path = library_name
if repository_path is None:
repository_path = f'{output_folder}/{destination_path}'
util.delete_if_exists(f'{output_folder}/{destination_path}')
clone_out = util.sh_util(f'git clone "https://github.com/googleapis/{destination_path}.git"', cwd=output_folder)
print(clone_out)
library_path = f'{repository_path}'
versions_file = f'{repository_path}/versions.txt'

owlbot_cli_source_folder = util.sh_util('mktemp -d')
for gapic in library.gapic_configs:

effective_arguments = list(base_arguments)
effective_arguments += util.create_argument('proto_path', gapic)

build_file_folder = f'{output_folder}/{gapic.proto_path}'
print(f'build_file_folder: {build_file_folder}')
client_inputs = parse_build_file(build_file_folder, gapic.proto_path)
effective_arguments += [
'--proto_only', client_inputs.proto_only,
'--gapic_additional_protos', client_inputs.additional_protos,
'--transport', client_inputs.transport,
'--rest_numeric_enums', client_inputs.rest_numeric_enum,
'--gapic_yaml', client_inputs.gapic_yaml,
'--service_config', client_inputs.service_config,
'--service_yaml', client_inputs.service_yaml,
'--include_samples', client_inputs.include_samples,
]
service_version = gapic.proto_path.split('/')[-1]
temp_destination_path = f'java-{library.api_shortname}-{service_version}'
effective_arguments += [ '--destination_path', temp_destination_path ]
print('arguments: ')
print(effective_arguments)
print(f'Generating library from {gapic.proto_path} to {destination_path}...')
util.run_process_and_print_output(['bash', '-x', f'{script_dir}/generate_library.sh',
*effective_arguments], 'Library generation')


if enable_postprocessing:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why checks enable_postprocessing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, because the body of that if statement prepares a special folder to be consumed by the postprocessing script.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this special folder unique to each library? If not, you can move this part to line 130 (the next if statement).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The folder is not unique but we need to know the temp_destination_path of each library to build this folder after it's generated

util.sh_util(f'build_owlbot_cli_source_folder "{library_path}"'
+ f' "{owlbot_cli_source_folder}" "{output_folder}/{temp_destination_path}"'
+ f' "{gapic.proto_path}"',
cwd=output_folder)

if enable_postprocessing:
# call postprocess library
util.run_process_and_print_output([f'{script_dir}/postprocess_library.sh',
f'{library_path}', '', versions_file, owlbot_cli_source_folder,
config.owlbot_cli_image, config.synthtool_commitish, str(is_monorepo).lower()], 'Library postprocessing')

50 changes: 8 additions & 42 deletions library_generation/generate_library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,10 @@ case $key in
include_samples="$2"
shift
;;
--enable_postprocessing)
enable_postprocessing="$2"
shift
;;
--os_architecture)
os_architecture="$2"
shift
;;
--versions_file)
versions_file="$2"
shift
;;
*)
echo "Invalid option: [$1]"
exit 1
Expand All @@ -85,6 +77,11 @@ script_dir=$(dirname "$(readlink -f "$0")")
source "${script_dir}"/utilities.sh
output_folder="$(get_output_folder)"

if [ -z "${gapic_generator_version}" ]; then
echo 'missing required argument --gapic_generator_version'
exit 1
fi

if [ -z "${protobuf_version}" ]; then
protobuf_version=$(get_protobuf_version "${gapic_generator_version}")
fi
Expand Down Expand Up @@ -125,10 +122,6 @@ if [ -z "${include_samples}" ]; then
include_samples="true"
fi

if [ -z "$enable_postprocessing" ]; then
enable_postprocessing="true"
fi

if [ -z "${os_architecture}" ]; then
os_architecture=$(detect_os_architecture)
fi
Expand Down Expand Up @@ -305,34 +298,7 @@ popd # output_folder
pushd "${temp_destination_path}"
rm -rf java_gapic_srcjar java_gapic_srcjar_raw.srcjar.zip java_grpc.jar java_proto.jar temp-codegen.srcjar
popd # destination path
##################### Section 5 #####################
# post-processing
#####################################################
if [ "${enable_postprocessing}" != "true" ];
then
echo "post processing is disabled"
cp -r ${temp_destination_path}/* "${output_folder}/${destination_path}"
rm -rdf "${temp_destination_path}"
exit 0
fi
if [ -z "${versions_file}" ];then
echo "no versions.txt argument provided. Please provide one in order to enable post-processing"
exit 1
fi
workspace="${output_folder}/workspace"
if [ -d "${workspace}" ]; then
rm -rdf "${workspace}"
fi

mkdir -p "${workspace}"

# if destination_path is not empty, it will be used as a starting workspace for
# postprocessing
if [[ $(find "${output_folder}/${destination_path}" -mindepth 1 -maxdepth 1 -type d,f | wc -l) -gt 0 ]];then
workspace="${output_folder}/${destination_path}"
fi

bash -x "${script_dir}/postprocess_library.sh" "${workspace}" \
"${temp_destination_path}" \
"${versions_file}"

cp -r ${temp_destination_path}/* "${output_folder}/${destination_path}"
rm -rdf "${temp_destination_path}"
exit 0
77 changes: 77 additions & 0 deletions library_generation/main.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably name this file in a more meaningful way. But since this file is used only by tests, and @JoeWang1127 will probably merge the responsibility of it to generate_repo.py, I think this is fine for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. This main.py can be used as a standalone script, shown in the PR description

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""
Parses a config yaml and generates libraries via generate_composed_library.py
"""

import click
from generate_composed_library import generate_composed_library
from typing import Dict
from model.GenerationConfig import GenerationConfig
from collections.abc import Sequence
from absl import app

@click.group(invoke_without_command=False)
@click.pass_context
@click.version_option(message="%(version)s")
def main(ctx):
pass

@main.command()
@click.option(
"--generation-config-yaml",
required=True,
type=str,
help="""
Path to generation_config.yaml that contains the metadata about library generation
"""
)
@click.option(
"--enable-postprocessing",
required=False,
default=True,
type=bool,
help="""
Path to repository where generated files will be merged into, via owlbot copy-code.
Specifying this option enables postprocessing
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if I set repository-location and set enable-postprocessing to False?

Copy link
Contributor Author

@diegomarquezp diegomarquezp Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this option (commit upcoming) since we can infer repository path from the configuration yaml

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified the behavior. We will always have a repository downloaded, either passed via --repository-path or automatically downloaded if not specified. enable_postprocessing will be safe in case --repository-path is not specified/set-to-false.

"""
)
@click.option(
"--target-library-api-shortname",
required=False,
type=str,
diegomarquezp marked this conversation as resolved.
Show resolved Hide resolved
help="""
If specified, only the `library` with api_shortname = target-library-api-shortname will
be generated. If not specified, all libraries in the configuration yaml will be generated
"""
)
@click.option(
"--repository-path",
required=False,
type=str,
help="""
If specified, the generated files will be sent to this location. If not specified, the
repository will be pulled into output_folder and move the generated files there
"""
)
def generate_from_yaml(
generation_config_yaml: str,
enable_postprocessing: bool,
target_library_api_shortname: str,
repository_path: str
) -> None:
config = GenerationConfig.from_yaml(generation_config_yaml)
target_libraries = config.libraries
if target_library_api_shortname is not None:
target_libraries = [library for library in config.libraries
if library.api_shortname == target_library_api_shortname]
for library in target_libraries:
print(f'generating library {library.api_shortname}')
generate_composed_library(
config, library, repository_path, enable_postprocessing
)





if __name__ == "__main__":
main()
Loading
Loading