|
1 | | -def pre(lang, ctx, gendir, args, srcs, requires, provides): |
| 1 | +load("//bzl:base/rules.bzl", "proto_library") |
| 2 | +load("//bzl:protoc.bzl", "implement") |
| 3 | +load("//bzl:ruby/class.bzl", RUBY = "CLASS") |
2 | 4 |
|
3 | | - if (lang.plugin_outdir_hook): |
4 | | - outdir = lang.plugin_out_hook(lang, ctx, gendir) |
5 | | - else: |
6 | | - outdir = gendir |
| 5 | +SPEC = [RUBY] |
7 | 6 |
|
8 | | - # Default language options |
9 | | - plugin_args = lang.plugin_args |
| 7 | +ruby_proto_compile = implement(SPEC) |
10 | 8 |
|
11 | | - # Options specified in context |
12 | | - plugin_args += getattr(ctx.attr, "gen_" + lang + "_args") |
13 | | - |
14 | | - # if opts: |
15 | | - # plugin_args = ",".join(opts) + ":" + plugin_args |
16 | | - |
17 | | - # Configure plugin definition if defined |
18 | | - if lang.plugin_binary: |
19 | | - plugin_exe_name = "gen_" + lang.name + "_plugin" |
20 | | - plugin_exe = getattr(ctx.attr, plugin_exe_name) |
21 | | - if not plugin_exe: |
22 | | - fail("Undefined plugin executable", plugin_exe_name) |
23 | | - args += ["--plugin=%s=%s" % (lang.plugin_name, lang.plugin_exe.path)] |
24 | | - |
25 | | - # Configure plugin for this language |
26 | | - args += ["--%s_out=%s:%s" % (lang.name, lang.plugin_name, plugin_args, outdir.path)] |
27 | | - |
28 | | - for srcfile in ctx.files.srcs: |
29 | | - basename = srcfile.basename |
30 | | - filename = basename[:-len('.proto')] + lang.file_extension |
31 | | - pbfile = ctx.new_file(filename) |
32 | | - srcs += [srcfile.path] |
33 | | - requires += [srcfile] |
34 | | - provides += [pbfile] |
35 | | - |
36 | | - return (args, srcs, requires, provides) |
37 | | - |
38 | | - |
39 | | -def post(ctx, requires, provides): |
40 | | - return (requires, provides) |
41 | | - |
42 | | -py_proto_compile = _compile([ LANGUAGE.get("python") ]) |
43 | | - |
44 | | -#def py_proto_compile(**kwargs): |
45 | | -# pass |
46 | | - #rule = _compile([ LANGUAGE.get("python") ]) |
47 | | - #_rule(gen_py = True) |
| 9 | +def ruby_proto_library(name, **kwargs): |
| 10 | + proto_library(name, |
| 11 | + proto_compile = ruby_proto_compile, |
| 12 | + spec = SPEC, |
| 13 | + **kwargs) |
0 commit comments