|
1 | 1 | <!-- TOC depthFrom:1 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 --> |
2 | 2 |
|
| 3 | +* [Rules Development Status](#rules-development-status) |
3 | 4 | * [Usage](#usage) |
4 | | - * [WORKSPACE File](#workspace-file) |
5 | | - * [BUILD.bazel files](#buildbazel-files) |
| 5 | + * [`WORKSPACE` File](#workspace-file) |
| 6 | + * [`BUILD.bazel` files](#buildbazel-files) |
6 | 7 | * [Rules](#rules) |
7 | | - * [ruby_library](#ruby_library) |
8 | | - * [ruby_binary](#ruby_binary) |
9 | | - * [ruby_test](#ruby_test) |
10 | | - * [ruby_bundle](#ruby_bundle) |
11 | | - * [ruby_gem](#rb_gem) |
| 8 | + * [`ruby_library`](#ruby_library) |
| 9 | + * [`ruby_binary`](#ruby_binary) |
| 10 | + * [`ruby_test`](#ruby_test) |
| 11 | + * [`ruby_bundle`](#ruby_bundle) |
| 12 | + * [Limitations](#limitations) |
| 13 | + * [Conventions](#conventions) |
| 14 | + * [Example: `WORKSPACE`:](#example-workspace) |
| 15 | + * [Example: `lib/BUILD.bazel`:](#example-libbuildbazel) |
| 16 | + * [`ruby_rspec`](#ruby_rspec) |
| 17 | + * [`ruby_gem`](#ruby_gem) |
12 | 18 | * [What's coming next](#whats-coming-next) |
13 | 19 | * [Contributing](#contributing) |
14 | 20 | * [Setup](#setup) |
|
27 | 33 |
|
28 | 34 | | Build | Status | |
29 | 35 | |---------: |--------------------------------------------------------------------------------------------------------------------------------------------------- | |
30 | | -| CircleCI Develop: | [](https://circleci.com/gh/bazelruby/rules_ruby/tree/develop) | |
31 | | -| CircleCI Default: | [](https://circleci.com/gh/bazelruby/rules_ruby) | |
32 | | -| Develop: | [](https://travis-ci.org/bazelruby/rules_ruby) | |
33 | | -| Master: | [](https://travis-ci.org/bazelruby/rules_ruby) | |
| 36 | +| CircleCI | [](https://circleci.com/gh/bazelruby/rules_ruby/tree/develop) | |
| 37 | +| TravisCI | [](https://travis-ci.org/bazelruby/rules_ruby) | |
34 | 38 |
|
35 | 39 |
|
36 | 40 | # Rules Ruby |
37 | 41 |
|
38 | | -Ruby rules for [Bazel](https://bazel.build). |
| 42 | +This is the README for Ruby Rules for the [Bazel Build](https://bazel.build) system. |
| 43 | + |
| 44 | +## Rules Development Status |
| 45 | + |
| 46 | +| **Readiness** | **Types of Applications** | |
| 47 | +|:-------------------------------------------------------------------------------| :----------| |
| 48 | +|  | ruby apps, ruby gems, micro-services, ideally in a mono-repo | |
| 49 | +|  | medium-sized Ruby on Rails apps, ideally in a mono-repo | |
| 50 | +|  | complex Ruby on Rails monoliths, single-repo | |
39 | 51 |
|
40 | | -** Current Status:** *Work in progress.* |
41 | 52 |
|
42 | 53 | Note: we have a short guide on [Building your first Ruby Project](https://github.com/bazelruby/rules_ruby/wiki/Build-your-ruby-project) on the Wiki. We encourage you to check it out. |
43 | 54 |
|
44 | 55 | ## Usage |
45 | 56 |
|
46 | 57 | ### `WORKSPACE` File |
47 | 58 |
|
48 | | -Add `ruby_rules_dependencies` and `ruby_register_toolchains` into your `WORKSPACE` file. |
| 59 | +Add `ruby_rules_dependencies` and `ruby_rules_toolchains` into your `WORKSPACE` file. |
49 | 60 |
|
50 | 61 | ```python |
51 | 62 | # To get the latest, grab the 'develop' branch. |
52 | 63 |
|
53 | 64 | git_repository( |
54 | | - name = "bazelruby_ruby_rules", |
| 65 | + name = "bazelruby_rules_ruby", |
55 | 66 | remote = "https://github.com/bazelruby/rules_ruby.git", |
56 | 67 | branch = "develop", |
57 | 68 | ) |
58 | 69 |
|
59 | 70 | load( |
60 | | - "@bazelruby_ruby_rules//ruby:deps.bzl", |
61 | | - "ruby_register_toolchains", |
| 71 | + "@bazelruby_rules_ruby//ruby:deps.bzl", |
| 72 | + "ruby_rules_toolchains", |
62 | 73 | "ruby_rules_dependencies", |
63 | 74 | ) |
64 | 75 |
|
65 | 76 | ruby_rules_dependencies() |
66 | 77 |
|
67 | | -ruby_register_toolchains() |
| 78 | +ruby_rules_toolchains() |
68 | 79 | ``` |
69 | 80 |
|
70 | 81 | Next, add any external Gem dependencies you may have via `ruby_bundle` command. |
@@ -98,7 +109,7 @@ Add `ruby_library`, `ruby_binary` or `ruby_test` into your `BUILD.bazel` files. |
98 | 109 |
|
99 | 110 | ```python |
100 | 111 | load( |
101 | | - "@bazelruby_ruby_rules//ruby:defs.bzl", |
| 112 | + "@bazelruby_rules_ruby//ruby:defs.bzl", |
102 | 113 | "ruby_binary", |
103 | 114 | "ruby_library", |
104 | 115 | "ruby_test", |
@@ -139,10 +150,13 @@ ruby_rspec( |
139 | 150 |
|
140 | 151 | ## Rules |
141 | 152 |
|
| 153 | +> NOTE: this diagram is slightly outdated. |
| 154 | + |
142 | 155 | The following diagram attempts to capture the implementation behind `ruby_library` that depends on the result of `bundle install`, and a `ruby_binary` that depends on both: |
143 | 156 |
|
144 | 157 |  |
145 | 158 |
|
| 159 | +---- |
146 | 160 |
|
147 | 161 | ### `ruby_library` |
148 | 162 |
|
@@ -219,6 +233,8 @@ ruby_library(name, deps, srcs, data, compatible_with, deprecation, distribs, fea |
219 | 233 | </tbody> |
220 | 234 | </table> |
221 | 235 |
|
| 236 | +---- |
| 237 | + |
222 | 238 | ### `ruby_binary` |
223 | 239 |
|
224 | 240 | <pre> |
@@ -300,6 +316,8 @@ ruby_binary(name, deps, srcs, data, main, compatible_with, deprecation, distribs |
300 | 316 | </tbody> |
301 | 317 | </table> |
302 | 318 |
|
| 319 | +---- |
| 320 | + |
303 | 321 | ### `ruby_test` |
304 | 322 |
|
305 | 323 | <pre> |
@@ -381,39 +399,57 @@ ruby_test(name, deps, srcs, data, main, compatible_with, deprecation, distribs, |
381 | 399 | </tbody> |
382 | 400 | </table> |
383 | 401 |
|
| 402 | +---- |
| 403 | + |
384 | 404 | ### `ruby_bundle` |
385 | 405 |
|
386 | | -Installs gems with Bundler, and make them available as a `ruby_library`. |
| 406 | +**NOTE: This is a repository rule, and can only be used in a `WORKSPACE` file.** |
| 407 | + |
| 408 | +This rule installs gems defined in a Gemfile using Bundler, and exports individual gems from the bundle, as well as the entire bundle, available as a `ruby_library` that can be depended upon from other targets. |
387 | 409 |
|
388 | | -Example: `WORKSPACE`: |
| 410 | +#### Limitations |
| 411 | + |
| 412 | +Installing using a `Gemfile` that uses the `gemspec` keyword is not currently supported. |
| 413 | + |
| 414 | +#### Conventions |
| 415 | + |
| 416 | +`ruby_bundle` creates several targets that can be used downstream. In the examples below we assume that your `ruby_bundle` has a name `app_bundle`: |
| 417 | + |
| 418 | + * `@app_bundle//:bundler` — references just the Bundler from the bundle. |
| 419 | + * `@app_bundle//:gems` — references *all* gems in the bundle (i.e. "the entire bundle"). |
| 420 | + * `@app_bundle//:gem-name` — references *just the specified* gem in the bundle, eg. `@app_bundle//:awesome_print`. |
| 421 | + * `@app_bundle//:bin` — references to all installed executables from this bundle, with individual executables accessible via eg. `@app_bundle//:bin/rubocop` |
| 422 | + |
| 423 | +##### Example: `WORKSPACE`: |
389 | 424 |
|
390 | 425 | ```python |
391 | 426 | git_repository( |
392 | | - name = "bazelruby_ruby_rules", |
| 427 | + name = "bazelruby_rules_ruby", |
393 | 428 | remote = "https://github.com/bazelruby/rules_ruby.git", |
394 | 429 | tag = "v0.1.0", |
395 | 430 | ) |
396 | 431 |
|
397 | 432 | load( |
398 | | - "@bazelruby_ruby_rules//ruby:deps.bzl", |
399 | | - "ruby_register_toolchains", |
| 433 | + "@bazelruby_rules_ruby//ruby:deps.bzl", |
| 434 | + "ruby_rules_toolchains", |
400 | 435 | "ruby_rules_dependencies", |
401 | 436 | ) |
402 | 437 |
|
403 | 438 | ruby_rules_dependencies() |
404 | 439 |
|
405 | | -ruby_register_toolchains() |
| 440 | +ruby_rules_toolchains() |
406 | 441 |
|
407 | | -load("@bazelruby_ruby_rules//ruby:defs.bzl", "ruby_bundle") |
| 442 | +load("@bazelruby_rules_ruby//ruby:defs.bzl", "ruby_bundle") |
408 | 443 |
|
409 | 444 | ruby_bundle( |
| 445 | + bundler_version = '2.1.2', |
410 | 446 | name = "gems", |
411 | 447 | gemfile = "//:Gemfile", |
412 | 448 | gemfile_lock = "//:Gemfile.lock", |
413 | 449 | ) |
414 | 450 | ``` |
415 | 451 |
|
416 | | -Example: `lib/BUILD.bazel`: |
| 452 | +##### Example: `lib/BUILD.bazel`: |
417 | 453 |
|
418 | 454 | ```python |
419 | 455 | ruby_library( |
@@ -484,11 +520,105 @@ ruby_bundle(name, gemfile, gemfile_lock, bundler_version = "2.1.2") |
484 | 520 | </tbody> |
485 | 521 | </table> |
486 | 522 |
|
487 | | -## rb_gem |
| 523 | +---- |
| 524 | + |
| 525 | +### `ruby_rspec` |
| 526 | + |
| 527 | +<pre> |
| 528 | +ruby_rspec(name, deps, srcs, data, main, rspec_args, bundle, compatible_with, deprecation, distribs, features, licenses, restricted_to, tags, testonly, toolchains, visibility, args, size, timeout, flaky, local, shard_count) |
| 529 | +</pre> |
| 530 | + |
| 531 | +<table class="table table-condensed table-bordered table-params"> |
| 532 | + <colgroup> |
| 533 | + <col class="col-param" /> |
| 534 | + <col class="param-description" /> |
| 535 | + </colgroup> |
| 536 | + <thead> |
| 537 | + <tr> |
| 538 | + <th colspan="2">Attributes</th> |
| 539 | + </tr> |
| 540 | + </thead> |
| 541 | + <tbody> |
| 542 | + <tr> |
| 543 | + <td><code>name</code></td> |
| 544 | + <td> |
| 545 | + <code>Name, required</code> |
| 546 | + <p>A unique name for this rule.</p> |
| 547 | + </td> |
| 548 | + </tr> |
| 549 | + <tr> |
| 550 | + <td><code>srcs</code></td> |
| 551 | + <td> |
| 552 | + <code>List of Labels, required</code> |
| 553 | + <p> |
| 554 | + List of <code>.rb</code> files. |
| 555 | + </p> |
| 556 | + </td> |
| 557 | + </tr> |
| 558 | + <tr> |
| 559 | + <td><code>deps</code></td> |
| 560 | + <td> |
| 561 | + <code>List of labels, optional</code> |
| 562 | + <p> |
| 563 | + List of targets that are required by the <code>srcs</code> Ruby |
| 564 | + files. |
| 565 | + </p> |
| 566 | + </td> |
| 567 | + </tr> |
| 568 | + <tr> |
| 569 | + <td><code>main</code></td> |
| 570 | + <td> |
| 571 | + <code>Label, optional</code> |
| 572 | + <p>The entrypoint file. It must be also in <code>srcs</code>.</p> |
| 573 | + <p>If not specified, <code><var>$(NAME)</var>.rb</code> where <code>$(NAME)</code> is the <code>name</code> of this rule.</p> |
| 574 | + </td> |
| 575 | + </tr> |
| 576 | + <tr> |
| 577 | + <td><code>rspec_args</code></td> |
| 578 | + <td> |
| 579 | + <code>List of strings, optional</code> |
| 580 | + <p>Command line arguments to the <code>rspec</code> binary, eg <code>["--progress", "-p2", "-b"]</code></p> |
| 581 | + <p>If not specified, the default arguments defined in `constants.bzl` are used: <code> --format=documentation --force-color</code>.</p> |
| 582 | + </td> |
| 583 | + </tr> |
| 584 | + <tr> |
| 585 | + <td><code>includes</code></td> |
| 586 | + <td> |
| 587 | + <code>List of strings, optional</code> |
| 588 | + <p> |
| 589 | + List of paths to be added to <code>$LOAD_PATH</code> at runtime. |
| 590 | + The paths must be relative to the the workspace which this rule belongs to. |
| 591 | + </p> |
| 592 | + </td> |
| 593 | + </tr> |
| 594 | + <tr> |
| 595 | + <td><code>rubyopt</code></td> |
| 596 | + <td> |
| 597 | + <code>List of strings, optional</code> |
| 598 | + <p> |
| 599 | + List of options to be passed to the Ruby interpreter at runtime. |
| 600 | + </p> |
| 601 | + <p> |
| 602 | + NOTE: <code>-I</code> option should usually go to <code>includes</code> attribute. |
| 603 | + </p> |
| 604 | + </td> |
| 605 | + </tr> |
| 606 | + </tbody> |
| 607 | + <tbody> |
| 608 | + <tr> |
| 609 | + <td colspan="2">And other <a href="https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes">common attributes</a></td> |
| 610 | + </tr> |
| 611 | + </tbody> |
| 612 | +</table> |
| 613 | + |
| 614 | +---- |
| 615 | + |
| 616 | +### `ruby_gem` |
| 617 | + |
488 | 618 | Used to generate a zipped gem containing its srcs, dependencies and a gemspec. |
489 | 619 |
|
490 | 620 | <pre> |
491 | | -rb_gem(name, gem_name, version, srcs, authors, deps, data, includes) |
| 621 | +ruby_gem(name, gem_name, gem_version, srcs, authors, deps, data, includes) |
492 | 622 | </pre> |
493 | 623 | <table class="table table-condensed table-bordered table-params"> |
494 | 624 | <colgroup> |
@@ -517,7 +647,7 @@ rb_gem(name, gem_name, version, srcs, authors, deps, data, includes) |
517 | 647 | </tr> |
518 | 648 | <tr> |
519 | 649 | <tr> |
520 | | - <td><code>version</code></td> |
| 650 | + <td><code>gem_version</code></td> |
521 | 651 | <td> |
522 | 652 | <code>Label, required</code> |
523 | 653 | <p> |
@@ -696,3 +826,5 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use |
696 | 826 |
|
697 | 827 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, |
698 | 828 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. |
| 829 | + |
| 830 | +<!-- @import "[TOC]" {cmd="toc" depthFrom=1 depthTo=6 orderedList=false} --> |
0 commit comments