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

Support optional merge function during copy #21

Merged
merged 4 commits into from
Jul 31, 2018

Conversation

dazuma
Copy link
Member

@dazuma dazuma commented Jul 30, 2018

Feature request for synthtool. During file copy, allows the result to be a "merge" of the contents of the source and the existing destination file. The merge function itself is provided as an optional argument to transforms.move.

One use case supported by this feature the ruby gemspec. This file specifies, among other things, the gem version, and the library dependencies. The former is updated during the release process (i.e. GAPIC does not know what version the gem currently is, so it cannot generate that part of the file correctly). The latter should be controlled by GAPIC (e.g. only GAPIC knows what version of google-gax its generated code depends on). Thus, the final gemspec output by synth must include the current version from the existing gemspec, and the dependency information from the freshly gapic-generated gemspec.

Open question: currently the merge function takes two arguments: the contents of the source (i.e. from-gapic) file, and the contents of the existing destination file. This is sufficient for my current use case, in which I am issuing a transforms.copy for a single file. However, maybe the merge function should also be passed the file path, so it has more information if it is invoked during a directory copy that includes multiple files? (And if so, should it be passed the source file path or the destination file path, or both?)

@dazuma dazuma requested a review from theacodes July 30, 2018 23:11
@theacodes
Copy link
Contributor

However, maybe the merge function should also be passed the file path, so it has more information if it is invoked during a directory copy that includes multiple files? (And if so, should it be passed the source file path or the destination file path, or both?)

The path should be the same relative path, right?

@dazuma
Copy link
Member Author

dazuma commented Jul 30, 2018

Yes, it should be the same relative path. Although I'm not entirely clear how to get the "common" relative path.

@theacodes
Copy link
Contributor

I think you can use the _tracked_paths wizardry: https://github.com/GoogleCloudPlatform/synthtool/pull/21/files#diff-cb9e5e9cfb56e43da6d7c82738c747c2L116

Another option would be to compute all of the common parts between the src and dst (.parts works well for this).

@dazuma
Copy link
Member Author

dazuma commented Jul 30, 2018

I decided to pass the (canonical) destination path as-is to the merge function, since it is the actual file being operated on. By default it's already a relative path anyway.

Change-Id: I9c78ded0108423b67f71308540fc31f918779b01
Change-Id: If3d727c9b76058532ebd5b91d313731f9157238e
@theacodes
Copy link
Contributor

@dazuma I made a few changes and I think everything still works, can you confirm?

@dazuma
Copy link
Member Author

dazuma commented Jul 31, 2018

@theacodes Yes, my synth using the new feature still works. Thanks for the fixes. Sometime can you point me to how to run the linter/typechecker/whatever tools you're using? I totally missed a bunch of those type issues.

@theacodes
Copy link
Contributor

nox -s lint, you'll need to pip install nox-automation first.

@theacodes theacodes merged commit d80526c into googleapis:master Jul 31, 2018
@dazuma dazuma deleted the merge-copy branch July 31, 2018 17:06
@JustinBeckwith
Copy link
Contributor

👋 Sorry for getting to this late. @dazuma can you make sure this is documented in the README?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants