Skip to content
This repository has been archived by the owner on Mar 4, 2022. It is now read-only.

Allow only one prototool.yaml file #139

Merged
merged 6 commits into from
Jul 10, 2018
Merged

Allow only one prototool.yaml file #139

merged 6 commits into from
Jul 10, 2018

Conversation

bufdev
Copy link
Contributor

@bufdev bufdev commented Jul 9, 2018

Per #10 and #93, this change does the bare minimum to enforce only one prototool.yaml file per command. There is further refactoring that can be done after this, but this propagates the changes through the codebase while retaining the multiple prototool.yaml file support in the implementation for now. Putting this up for discussion, it also helps simplify the logic for #131.

@codecov-io
Copy link

codecov-io commented Jul 9, 2018

Codecov Report

Merging #139 into dev will decrease coverage by 0.22%.
The diff coverage is 44.18%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #139      +/-   ##
==========================================
- Coverage   68.06%   67.84%   -0.23%     
==========================================
  Files          72       72              
  Lines        3786     3800      +14     
==========================================
+ Hits         2577     2578       +1     
- Misses        866      878      +12     
- Partials      343      344       +1
Impacted Files Coverage Δ
internal/file/file.go 62.5% <ø> (ø) ⬆️
internal/protoc/protoc.go 39.47% <ø> (ø) ⬆️
internal/lint/lint.go 72.22% <ø> (ø) ⬆️
internal/protoc/compiler.go 47.91% <28.57%> (-0.17%) ⬇️
internal/file/proto_set_provider.go 63.87% <40%> (-4.84%) ⬇️
internal/lint/runner.go 71.42% <50%> (+1.42%) ⬆️
internal/exec/runner.go 45.04% <59.25%> (-0.12%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7a6ad65...19a0e94. Read the comment docs.

Copy link
Contributor

@amckinney amckinney left a comment

Choose a reason for hiding this comment

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

Nice, looks good! Just want to verify that the error behavior is what we want.

```

Everything under `a/d` will use `a/d/prototool.yaml`, everything under `b`, `b/g/h` will use `b/prototool.yaml`, and everything under `a`, `a/e`, `a/f`, `c`, `c/i` will use `prototool.yaml`. See [internal/file/testdata](internal/file/testdata) for the most current example.
If multiple `prototool.yaml` files are found that match the input directory or files, an error will be returned. We have an ongoing discussion about whether to allow multiple `prototool.yaml` files, see [this issue](https://github.com/uber/prototool/issues/10) for more details.
Copy link
Contributor

Choose a reason for hiding this comment

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

What does it mean for prototool.yaml files to match the input directory or files?

Seeing as you cannot have more than one prototool.yaml file in a given directory, could we simply just use the prototool.yaml file that corresponds to where the command was run, and ignore all others? For example, in your removed tree example, running prototool <cmd> in b/g should just use the prototool.yaml found there (and not the one included in the root). Similarly, running the same command at the root would use the root prototool.yaml and ignore all others.

Let me know if this isn't what you meant - just trying to determine when an error would occur and whether or not it's necessary.

func (c *compiler) ProtocCommands(protoSet *file.ProtoSet) ([]string, error) {
// we end up calling the logic that creates temporary files for file descriptor sets
// anyways, so we need to clean them up with cleanCmdMetas
// this logic could be simplified to have a "dry run" option, but ProtocCommands
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Now that this uses the dry-run flag, could we remove this comment? My fault for not handling in #135

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't remove this yet, needs some refactoring, this still creates temporary files.

Copy link
Contributor

@peats-bond peats-bond left a comment

Choose a reason for hiding this comment

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

just a nit about the error message for readability

for _, protoSet := range protoSets {
configDirPaths = append(configDirPaths, protoSet.Config.DirPath)
}
return nil, fmt.Errorf("multiple configuration files found in directories %v for proto files found for dirPath %q but expected exactly one configuration file", configDirPaths, dirPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

These are absolute paths if i'm not mistaken, so it may be more readable to reword the error message to have the directories listed last

eg:

return nil, fmt.Errorf("expected exactly one configuration file for dirPath %q, but found multiple in directories: %v", dirPath, configDirPaths)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

for _, protoSet := range protoSets {
configDirPaths = append(configDirPaths, protoSet.Config.DirPath)
}
return nil, fmt.Errorf("multiple configuration files found in directories %v for proto files found for filePaths %v but expected exactly one configuration file", configDirPaths, filePaths)
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@bufdev bufdev merged commit 480cf31 into dev Jul 10, 2018
@bufdev bufdev deleted the single-config-file branch July 10, 2018 09:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants