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

Report gapic generation to metadata #155

Merged
merged 1 commit into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions synthtool/gcp/gapic_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from synthtool import _tracked_paths
from synthtool import log
from synthtool import metadata
from synthtool.gcp import artman
from synthtool.sources import git

Expand Down Expand Up @@ -128,6 +129,15 @@ def _generate_code(

log.success(f"Generated code into {genfiles}.")

metadata.add_client_destination(
source="googleapis" if not private else "googleapis-private",
api_name=service,
api_version=version,
language=language,
generator="gapic",
config=str(config_path),
)

_tracked_paths.add(genfiles)
return genfiles

Expand Down
5 changes: 5 additions & 0 deletions synthtool/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def add_template_source(**kwargs) -> None:
_metadata.sources.add(template=metadata_pb2.TemplateSource(**kwargs))


def add_client_destination(**kwargs) -> None:
"""Adds a client library destination to the current metadata."""
_metadata.destinations.add(client=metadata_pb2.ClientDestination(**kwargs))


def write(outfile: str = "synth.metadata") -> None:
"""Writes out the metadata to a file."""
jsonified = google.protobuf.json_format.MessageToJson(_metadata)
Expand Down
13 changes: 9 additions & 4 deletions synthtool/protos/metadata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,17 @@ message Destination {
}

message ClientDestination {
string api_name = 1;
string api_version = 2;
string generator = 3;
string source = 4;
string source = 1;
string api_name = 2;
string api_version = 3;
string language = 4;
string generator = 5;
string config = 6;
}

// Currently unused as storing all file destination options will likely cause
// the metadata file to be too large and may cause autosynth trashing. We'll
// investigate using this in the future.
message FileSetDestination {
string source = 1;
repeated string files = 2;
Expand Down
60 changes: 48 additions & 12 deletions synthtool/protos/metadata_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,39 @@ def test_add_generator_source():
assert current.sources[0].generator.version == "1.2.3"


def test_add_template_source():
metadata.reset()

metadata.add_template_source(name="name", version="1.2.3")

current = metadata.get()

assert current.sources[0].template.name == "name"
assert current.sources[0].template.version == "1.2.3"


def test_add_client_destination():
metadata.reset()

metadata.add_client_destination(
source="source",
api_name="api",
api_version="v1",
language="py",
generator="gen",
config="config",
)

current = metadata.get()

assert current.destinations[0].client.source == "source"
assert current.destinations[0].client.api_name == "api"
assert current.destinations[0].client.api_version == "v1"
assert current.destinations[0].client.language == "py"
assert current.destinations[0].client.generator == "gen"
assert current.destinations[0].client.config == "config"


def test_write(tmpdir):
metadata.reset()

Expand Down