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

Added option to okBuck to configure rule overrides compatible with skylark #752

Merged
merged 2 commits into from
Nov 7, 2018

Conversation

romanoid
Copy link
Contributor

@romanoid romanoid commented Nov 6, 2018

Now instead of having to define java_library in DEFS one can tell okBuck to load and use my_java_library in //defs/my_defs.bzl like:

okbuck {
    ruleOverrides {
        override {
            nativeRuleName = "java_library"
            importLocation = "//defs/my_defs.bzl"
            newRuleName = "my_java_library"
        }
    }
}

with this config specified, generates files look like this:

load('//defs/my_defs.bzl', 'my_java_library')

my_java_library(
...

Description:

Related issue(s):

Copy link
Contributor

@kageiit kageiit left a comment

Choose a reason for hiding this comment

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

Lets chat about a different api for this. Not a fan of the current verbosity

* Specify override for the rule, for example:
* override {
* nativeRuleName="java_library"
* bzlFile="tooling/defs/my_defs.bzl"
Copy link
Collaborator

Choose a reason for hiding this comment

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

should probably be importLocation="//tooling/defs:my_defs.bzl.

nit: we should probably validate the file structure and also that new new rule name is all snake case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. re-written documentation with full example instead of just single section

Multimap<String, String> loadStatements =
createLoadStatements(visibilityExtension, hasVisibilityFile);

Map<String, RuleOverridesExtension.OverrideSetting> overrides =
overridesExtension.getOverrides();
for (Rule rule : rules) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can use streams

also, exported file rules append to buck files. Might have to consider creating a singleton which keeps track of all rules and writes them down in the end (similar to how dependencies are managed by DependencyManager)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack

@@ -43,6 +43,10 @@ public T ruleType(String ruleType) {
return (T) this;
}

public String ruleType() {
return ruleType;
Copy link
Collaborator

Choose a reason for hiding this comment

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

some one off rules/buck files don't respect this rule type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you for letting me know, will have to identify these and update them in the breaking change.


private void validateExtension() {
Set<String> usedOverrideKeys = new HashSet<>();
for (OverrideSetting setting : overrides) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can use streams.

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 don't like throwing exceptions from the streams, stack traces tend to look strange.

});
}

private void validateExtension() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

might be a good idea to have these extensions implement an interface which initializes the extension. that can then be called by the base extension to validate & setup?

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 good idea, will not do it yet, since there is only 2 precedents.

task -> BuckFileGenerator.generate(
bp,
okbuckExt.getVisibilityExtension(),
okbuckExt.getRuleOverridesExtension()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

could probably just pass the okbuckExt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good.

protected void override(Closure<OverrideSetting> action) {
OverrideSetting setting = new OverrideSetting();
action.setDelegate(setting);
action.call(setting);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author