Skip to content

Commit

Permalink
language proto build defs should already know what language they are …
Browse files Browse the repository at this point in the history
…for (#9)

* language proto build defs should already know what language they are for

* set version and add to changelog

* adding python plugin repo and target

---------

Co-authored-by: rgodden <[email protected]>
  • Loading branch information
goddenrich and goddenrich authored Jan 27, 2023
1 parent 6ddb635 commit 6cf0e2e
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 25 deletions.
3 changes: 1 addition & 2 deletions .plzconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LanguageDef = //build_defs/languages:py
[Plugin "python"]
ModuleDir = third_party.python
WheelRepo = https://get.please.build/third_party/python/py3
Target = //:python

[FeatureFlags]
ExcludeProtoRules = true
Expand Down Expand Up @@ -40,5 +41,3 @@ DefaultValue = //third_party/python:protobuf
[PluginConfig "python_grpc_dep"]
ConfigKey = PythonGrpcDep
DefaultValue = //third_party/python:grpc


7 changes: 3 additions & 4 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
github_repo(
plugin_repo(
name = "python",
repo = "please-build/python-rules",
revision = "e6695ab08b3890bbdb3ccb8435848564dd6df5c8",
)
revision = "v1.2.0",
)
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Version 0.2.0
-------------
* Language protos build_defs should know what language they are for so
removing language from the arguments


Version 0.1.1
-------------
* Fix the version
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ The build definitions for each proto or grpc language.

```
[Plugin "proto"]
Definition = ///python-proto//build_defs:py
Definition = ///java-proto//build_defs:java
Definition = ///go-proto//build_defs:go
LanguageDef = ///python_proto//build_defs:py
LanguageDef = ///java_proto//build_defs:java
LanguageDef = ///go_proto//build_defs:go
```

## ProtocFlag (repeatable str)
Expand Down Expand Up @@ -220,7 +220,7 @@ proto_build_defs(
The final step is to configure this in the repo that will be using it:
```
[Plugin "proto"]
Definitions = ///foo-proto//build_defs:foo
LanguageDef = ///foo_proto//build_defs:foo
```

The `proto_library()` and `grpc_library()` rules will then provide your `foo_library()` to any rules that depends on them
Expand All @@ -235,7 +235,7 @@ build rule:
```python
protoc_plugins(
name = "grpc_gateway_languages",
build_defs = ["///foo-proto//build_defs:foo"],
build_defs = ["///foo_proto//build_defs:foo"],
type = "grpc_language",
)
```
Expand Down Expand Up @@ -290,4 +290,4 @@ def grpc_gateway_library(name:str, srcs:list, deps:list=None, visibility:list=No
root_dir = root_dir,
protoc_flags = protoc_flags,
)
```
```
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.1
0.2.0
8 changes: 4 additions & 4 deletions build_defs/languages/js.build_defs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
subinclude("//build_defs/sdk")

def js_proto_library(name:str, language:str, srcs:list, deps:list=[], visibility:list=None, labels:list&features&tags=[],
def js_proto_library(name:str, srcs:list, deps:list=[], visibility:list=None, labels:list&features&tags=[],
test_only:bool&testonly=False, root_dir:str='', protoc_flags:list=[], additional_context:dict=None):
protoc = protoc_rule(
name = name,
srcs = srcs,
language = language,
language = "js",
protoc_flags = protoc_flags,
plugin_flags = ['--js_out=import_style=commonjs,binary:"$OUT_DIR"'],
labels = labels,
Expand All @@ -16,7 +16,7 @@ def js_proto_library(name:str, language:str, srcs:list, deps:list=[], visibility
)

return filegroup(
name = f"_{name}#{language}",
name = f"_{name}#js",
srcs = [protoc],
deps = deps,
test_only = test_only,
Expand All @@ -35,4 +35,4 @@ def js_proto_language():
return proto_language(
language = "js",
build_def = js_proto_library,
)
)
14 changes: 7 additions & 7 deletions build_defs/languages/py.build_defs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
subinclude("//build_defs/sdk", "@python//build_defs:python")

def py_proto_library(name:str, language:str, srcs:list, deps:list=[], visibility:list=None, labels:list&features&tags=[],
def py_proto_library(name:str, srcs:list, deps:list=[], visibility:list=None, labels:list&features&tags=[],
test_only:bool&testonly=False, root_dir:str='', protoc_flags:list=[], additional_context:dict=None):
deps += [CONFIG.PROTO.PYTHON_DEP]
protoc = protoc_rule(
name = name,
srcs = srcs,
language = language,
language = "py",
protoc_flags = protoc_flags,
plugin_flags = ['--python_out="$OUT_DIR"'],
labels = labels,
Expand All @@ -17,15 +17,15 @@ def py_proto_library(name:str, language:str, srcs:list, deps:list=[], visibility
)

return python_library(
name = f"_{name}#{language}",
name = f"_{name}#py",
srcs = [protoc],
deps = deps,
test_only = test_only,
labels = labels,
visibility = visibility,
)

def py_grpc_library(name:str, language:str, srcs:list, deps:list=[], visibility:list=None, labels:list&features&tags=[],
def py_grpc_library(name:str, srcs:list, deps:list=[], visibility:list=None, labels:list&features&tags=[],
test_only:bool&testonly=False, root_dir:str='', protoc_flags:list=[], additional_context:dict=None):
deps += [CONFIG.PROTO.PYTHON_DEP, CONFIG.PROTO.PYTHON_GRPC_DEP]
tools = {'py': [CONFIG.PROTO.PYTHON_GRPC_PLUGIN]}
Expand All @@ -36,7 +36,7 @@ def py_grpc_library(name:str, language:str, srcs:list, deps:list=[], visibility:
protoc = protoc_rule(
name = name,
srcs = srcs,
language = language,
language = "py",
tools = tools,
protoc_flags = protoc_flags,
plugin_flags = [
Expand All @@ -52,7 +52,7 @@ def py_grpc_library(name:str, language:str, srcs:list, deps:list=[], visibility:
)

return python_library(
name = f"_{name}#{language}",
name = f"_{name}#py",
srcs = [protoc],
deps = deps,
test_only = test_only,
Expand All @@ -70,4 +70,4 @@ def py_proto_language():
return proto_language(
language = "py",
build_def = py_proto_library,
)
)
1 change: 0 additions & 1 deletion build_defs/proto.build_defs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def proto_library(name:str, srcs:list, deps:list=[], visibility:list=None, label
for language, plugin in lang_plugins:
provides[language] = plugin['build_def'](
name = name,
language = language,
srcs = srcs,
deps = deps,
visibility = visibility,
Expand Down

0 comments on commit 6cf0e2e

Please sign in to comment.