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

Add bazel macros for protobuf_rules_gen #29

Merged
merged 9 commits into from
Nov 30, 2018

Conversation

ribrdb
Copy link
Contributor

@ribrdb ribrdb commented Nov 9, 2018

Here's a first stab at adding the BUILD rules.
I'm not sure if you'd want to update the integration test to build using these rules or keep it completely separate.

I didn't include using the firestore emulator here. There's two reasons for that:

Once the emulator jar is available I basically just use a jasmine_node_test and add this to start the emulator:

beforeAll(async () => {
  return new Promise((resolve) => {
    console.log('Starting firestore emulator...');
    const child = child_process.spawn('java', [
      '-jar',
      '../com_google_cloud_firestore_emulator/jar/cloud-firestore-emulator.jar'
    ]);
    child.stdout.on('data', (data) => {
      console.log(`emulator: ${data}`);
      if (/localhost:8080/.test(data)) {
        console.log('Emulator alive!');
        resolve();
      }
    });

    child.stderr.on('data', (data) => {
      console.error(`emulator: ${data}`);
    });
    emulator = child;
  });
});
afterAll(() => {
  emulator.kill();
});

@ribrdb
Copy link
Contributor Author

ribrdb commented Nov 9, 2018

Hmm, I guess the CI is using an even older version of Bazel than I am. Should I update the rules to work with Bazel 0.9.0, or update the CI to use a newer version?

@rockwotj rockwotj self-requested a review November 19, 2018 15:43
Copy link
Contributor

@rockwotj rockwotj left a comment

Choose a reason for hiding this comment

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

The emulators are versioned, check here: https://github.com/firebase/firebase-tools/blob/master/src/emulator/constants.js#L27 (although let's do that in another PR)

Can we also move all the *.bzl files into a bazel directory?

README.md Outdated Show resolved Hide resolved
- firestore_rules_binary combines multiple .rules files (e.g. the auto
generated rules with your ACLs that use them)
- firestore_rules_library wraps up one or more .rules files so that a
firestore_rules_binary can depend on it.
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this doesn't format nicely. Try s/-/*/?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ping - these still aren't printing nicely.

example/BUILD Show resolved Hide resolved
@ribrdb
Copy link
Contributor Author

ribrdb commented Nov 27, 2018

I've been trying to write a test using the firestore emulator, but I'm having lots of problems with it. It seems flaky. The same test case will sometimes pass, sometimes time out, or sometimes return a permission denied error.
I guess for now I'll just add a golden file test.

@rockwotj
Copy link
Contributor

rockwotj commented Nov 27, 2018

Happy to take a look at a version that your experiencing flakiness with.

The emulator should be robust!

- Move bazel definitions to a subdirectory.
- Update readme formatting.
@ribrdb
Copy link
Contributor Author

ribrdb commented Nov 27, 2018

Happy to take a look at a version that your experiencing flakiness with.

The emulator should be robust!

https://github.com/ribrdb/protobuf-rules-gen/blob/emulator/example/rules_test.js

Copy link
Contributor

@rockwotj rockwotj left a comment

Choose a reason for hiding this comment

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

Looking good! A few comments mostly on style. I'll try playing with the emulator tests when I can - hopefully after we merge this PR.

Last nit: can you add newlines to all these files you've added?

WORKSPACE Outdated
@@ -1,17 +1,5 @@
workspace(name = "proto_gen_firebase_rules")

protobuf_commit = "099d99759101c295244c24d8954ec85b8ac65ce3"
load(":bazel/repositories.bzl", "protobuf_rules_gen_repositories")
Copy link
Contributor

Choose a reason for hiding this comment

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

//bazel:repositories.bzl should work and be a more canonical style

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

@@ -37,5 +38,6 @@ cc_binary(

cc_proto_library(
name = "firebase_rules_options",
visibility = ["//visibility:public"],
Copy link
Contributor

Choose a reason for hiding this comment

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

Do this libraries need to be public? If anything this should be restricted to this project only.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is part of my workaround for #25

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you instead do: package(default_visibility = ["//visibility:public"])

url = "https://github.com/google/protobuf/archive/" + protobuf_commit + ".tar.gz",
)

native.new_http_archive(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed? Can we depend on we'll know protos from above?

If we can't please leave a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Weird I couldn't get that to work before, but it seems to be fine now.

"google/protobuf/wrappers.proto",
]

def protobuf_rules_gen_repositories():
Copy link
Contributor

Choose a reason for hiding this comment

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

Good pattern for deps is to allow someone to override them. See an example here: https://github.com/grpc/grpc/blob/master/bazel/grpc_deps.bzl

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

Copy link
Contributor

@rockwotj rockwotj left a comment

Choose a reason for hiding this comment

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

Looking good almost there! Thanks for working through this with me.

BUILD Outdated
"$(locations :testdata)",
],
data = [
"//example:testdata/golden.rules",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: "//example/testdata:golden.rules",

BUILD Outdated
@@ -15,9 +15,13 @@ py_test(
"$(location @com_google_protobuf//:protoc)",
"$(location //proto:firebase_rules_options_proto_file)",
"$(location @com_google_protobuf//:descriptor_proto)",
"$(location //example:example.rules)",
"$(location //example:testdata/golden.rules)",
Copy link
Contributor

Choose a reason for hiding this comment

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

"$(location //example/testdata:golden.rules)",

@@ -37,5 +38,6 @@ cc_binary(

cc_proto_library(
name = "firebase_rules_options",
visibility = ["//visibility:public"],
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you instead do: package(default_visibility = ["//visibility:public"])

- firestore_rules_binary combines multiple .rules files (e.g. the auto
generated rules with your ACLs that use them)
- firestore_rules_library wraps up one or more .rules files so that a
firestore_rules_binary can depend on it.
Copy link
Contributor

Choose a reason for hiding this comment

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

Ping - these still aren't printing nicely.

@rockwotj
Copy link
Contributor

Thank you for your contribution!

@rockwotj rockwotj merged commit 62ff446 into FirebaseExtended:master Nov 30, 2018
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.

2 participants