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

Use protobuf instead of dot to communicate between parsers and core #13

Merged
merged 6 commits into from
Oct 8, 2017

Conversation

cgrushko
Copy link
Contributor

@cgrushko cgrushko commented Oct 6, 2017

that is, between the language-specific parsers and the language-agnostic core.

Copy link
Member

@petroseskinder petroseskinder left a comment

Choose a reason for hiding this comment

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

I asked for a few small changes. Mostly nits

That said, let me understand the context. You have moved entirely away from using jdeps for obtaining the class dependency graph? That was why we previously used the dot/graphviz format for representing the class graph.

@@ -108,6 +111,7 @@ private void run(String[] args) throws Exception {
cmdLineParser.parseArgument(args);

List<String> dotFile = readDotFileFromStdIn();
Copy link
Member

Choose a reason for hiding this comment

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

Do you need this (or line 223) anymore?
If so, in what context will both exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, didn't do a good job cleaning up. Removed.

// In the Java case, we have (u, v) if 'u' mentions [1] 'v'.
// [1] - By mention, we mean either imports or references in code, either as a fully qualified
// name, or an implied same-package name.
map<string, Strings> class_to_class = 1;
Copy link
Member

Choose a reason for hiding this comment

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

can you rename to class_dependencies.
getClassDependencyMap() is much clearer than getClassToClassMap()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"dependencies" can mean several things, I think that "class to class" describes it more precisely.
There are soon going to be additional fields (class_to_file, file_to_rule_kind) which will be consistent with the new name.
What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

There are soon going to be additional fields (class_to_file, file_to_rule_kind) which will be consistent with the new name.

This is the portion that is unclear to me, the future direction. Can you expand on when and how these additional fields would be used? How would you obtain these file_to_rule dependencies?

That aside, from my limited vantage point, these are all dependency graphs. The nodes, (i.e. type of dependency) may differ but at their core, they are dependencies. For example, an edge between a file and another rule indicates a dependency between that file and that rule. Consequently, I am curious why not define something like

message ParserOutput {
    map<Deps, Deps> dependency_map = 1;
}

message Dep {
     string name;
     string type;
}

message Deps {
    repeated Dep deps;
}

Copy link
Member

Choose a reason for hiding this comment

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

Note, the main takeaway you should get out of my message is not the specific proto I defined. It's that I don't understand what the direction is.

Copy link
Member

Choose a reason for hiding this comment

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

I concede on this

map<string, Strings> class_to_class = 1;
}

message Strings {
Copy link
Member

Choose a reason for hiding this comment

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

like above, can you make this some variant of dependency like deps or what have you?

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'm going to reuse this for other graphs (class_to_file, file_to_rule_kind) so "dependency" doesn't fit.
OTOH defining extra messages just for the name sounds wasteful.

Copy link
Member

Choose a reason for hiding this comment

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

I am fine accepting class_to_class, but Strings (and s) is... sketchy. It's overly broad.

OTOH defining extra messages just for the name sounds wasteful.

Understandable complaint. However, using overly broad or single letter variable names in Java is inappropriate and non-idiomatic. Perhaps it's not an issue when looking at the proto in isolation, but it's hard to argue the below is proper java code

private static HashMap<String, Bfg.Strings> writeGraphToProtoMap; 
// you defined your own special Strings class. Why???
...

adj.addAllS(graph.adjacentNodes(u));
// what is S???

I'm going to reuse this for other graphs (class_to_file, file_to_rule_kind)

there has to be some unifying quality about each of those, beyond Strings. Perhaps node.

As a side note, if we move to scala, i will be l

Copy link
Contributor Author

@cgrushko cgrushko Oct 7, 2017

Choose a reason for hiding this comment

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

How about repeated string elements instead of repeated string s?

Copy link
Member

Choose a reason for hiding this comment

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

That works

java_proto_library(
name = "bfg_java_proto"
, deps = [":bfg_proto" ],
)
Copy link
Member

Choose a reason for hiding this comment

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

nit: new line

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

@@ -108,6 +111,7 @@ private void run(String[] args) throws Exception {
cmdLineParser.parseArgument(args);

List<String> dotFile = readDotFileFromStdIn();
ParserOutput parserOutput = ParserOutput.parseFrom(System.in);
if (dotFile.isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

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

remove?

what arguments are you testing this against?
From what I understand of the change, there will be no more dotfiles, and also no more jdeps. Consequently, this should result in error.

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.

@@ -1,18 +1,6 @@
licenses(["notice"]) # Apache 2.0

java_test(
name = "DotFileParserTest",
Copy link
Member

Choose a reason for hiding this comment

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

is it customary to test protobuffs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you mean if's customary to test the proto parser?
the parser has tons of tests in its own codebase, so no.
That's one big reason to use other's well tested code, you don't need to test it yourself :)

Copy link
Member

@petroseskinder petroseskinder Oct 7, 2017

Choose a reason for hiding this comment

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

do you mean if's customary to test the proto parser?

Somewhat. What I was more concerned about was how we were unable to detect that dotfile.isEmpty() was not removed. Does bfg currently have e2e tests?

That's one big reason to use other's well tested code, you don't need to test it yourself :)

SGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, there are no e2e tests which would've caught it.
My approach is to hold off e2e tests as long as possible because they're really annoying to set up, at least inside Google. I think it's still fine to hold off, because there's little complexity in Bfg.java.

Copy link
Member

Choose a reason for hiding this comment

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

My approach is to hold off e2e tests as long as possible because they're really annoying to set up, at least inside Google. I think it's still fine to hold off, because there's little complexity in Bfg.java.

SGTM

that is, between the language-specific parsers and the language-agnostic core.
@cgrushko
Copy link
Contributor Author

cgrushko commented Oct 7, 2017

retest this please

@petroseskinder petroseskinder mentioned this pull request Oct 7, 2017
Copy link
Member

@petroseskinder petroseskinder left a comment

Choose a reason for hiding this comment

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

@cgrushko you're free to merge. :)
There was one nit that annoyed me. Can you make sure to change that.

map<string, Strings> class_to_class = 1;
}

message Strings {
Copy link
Member

Choose a reason for hiding this comment

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

I am fine accepting class_to_class, but Strings (and s) is... sketchy. It's overly broad.

OTOH defining extra messages just for the name sounds wasteful.

Understandable complaint. However, using overly broad or single letter variable names in Java is inappropriate and non-idiomatic. Perhaps it's not an issue when looking at the proto in isolation, but it's hard to argue the below is proper java code

private static HashMap<String, Bfg.Strings> writeGraphToProtoMap; 
// you defined your own special Strings class. Why???
...

adj.addAllS(graph.adjacentNodes(u));
// what is S???

I'm going to reuse this for other graphs (class_to_file, file_to_rule_kind)

there has to be some unifying quality about each of those, beyond Strings. Perhaps node.

As a side note, if we move to scala, i will be l

// In the Java case, we have (u, v) if 'u' mentions [1] 'v'.
// [1] - By mention, we mean either imports or references in code, either as a fully qualified
// name, or an implied same-package name.
map<string, Strings> class_to_class = 1;
Copy link
Member

Choose a reason for hiding this comment

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

I concede on this

@petroseskinder
Copy link
Member

test this please

@petroseskinder petroseskinder merged commit 1180218 into bazelbuild:master Oct 8, 2017
@cgrushko cgrushko deleted the proto branch October 8, 2017 14:31
cgrushko added a commit to cgrushko/BUILD_file_generator that referenced this pull request Oct 8, 2017
…azelbuild#13)

* Use protobuf instead of dot to communicate between parsers and core

that is, between the language-specific parsers and the language-agnostic core.

* Move .bazelrc to tools/ so ci.bazel.build will not override it

* Remove our .bazelrc until bazelbuild/continuous-integration#141 is resolved

* Revert "Remove our .bazelrc until bazelbuild/continuous-integration#141 is resolved"

This reverts commit 8ff7abe.

* Rename tools/.bazelrc to tools/bazel.rc

* Rename proto field to 'elements'
@cgrushko
Copy link
Contributor Author

Re commit message - I think it would be better to only use the initial commit message (e.g., without 'Revert "Remove out"...').
Unless things have considerably changed in the review, the commit message that's part of the PR should usually do.

@petroseskinder
Copy link
Member

Unless things have considerably changed in the review, the commit message that's part of the PR should usually do.

SGTM

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.

2 participants