Skip to content

Commit 85650ea

Browse files
authored
feat: initial skeleton for fullstory_android_binary rule (#3)
1 parent 67a51d9 commit 85650ea

15 files changed

+1081
-2789
lines changed

.bazelrc

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ common --check_direct_dependencies=off
1010
build --repository_cache=.cache/bazel/repo
1111
build --disk_cache=.cache/bazel/actions
1212

13+
# Settings required for bazelbuild/rules_android
14+
common --experimental_google_legacy_api
15+
common --experimental_enable_android_migration_apis
16+
1317
# Load any settings specific to the current user.
1418
# .bazelrc.user should appear in .gitignore so that settings are not shared with team members
1519
# This needs to be last statement in this

.github/workflows/release_prep.sh

+10
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ http_archive(
3636
strip_prefix = "${PREFIX}",
3737
url = "https://github.com/fullstorydev/rules_android/releases/download/${TAG}/${ARCHIVE}",
3838
)
39+
40+
load("@fullstory_rules_android//android:dependencies.bzl", fullstory_rules_android_dependencies = "rules_android_dependencies")
41+
fullstory_rules_android_dependencies()
42+
43+
# Set up bazelbuild/rules_android requirements, if you haven't already.
44+
load("@rules_android//:prereqs.bzl", "rules_android_prereqs")
45+
rules_android_prereqs()
46+
47+
load("@rules_android//:defs.bzl", "rules_android_workspace")
48+
rules_android_workspace()
3949
EOF
4050

4151
awk 'f;/--SNIP--/{f=1}' e2e/smoke/WORKSPACE.bazel

MODULE.bazel

+7
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ module(
88

99
bazel_dep(name = "bazel_skylib", version = "1.7.1")
1010
bazel_dep(name = "platforms", version = "0.0.10")
11+
bazel_dep(name = "rules_android", version = "0.5.1")
1112

1213
bazel_dep(name = "gazelle", version = "0.39.1", dev_dependency = True, repo_name = "bazel_gazelle")
1314
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.7.1", dev_dependency = True)
1415
bazel_dep(name = "aspect_bazel_lib", version = "2.9.3", dev_dependency = True)
1516
bazel_dep(name = "buildifier_prebuilt", version = "7.3.1", dev_dependency = True)
17+
18+
single_version_override(
19+
module_name = "rules_android",
20+
patch_strip = 1,
21+
patches = ["//:patches/bazelbuild/rules_android/rules_bzl_lib.patch"],
22+
)

MODULE.bazel.lock

+458-1,492
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Bazel rules for Fullstory + Android
22

3-
The rules provided here can be used to integrate the Fullstory SDK into APKs generated by [`bazelbuild/rules_android`](https://github.com/bazelbuild/rules_android)
3+
The rules provided here can be used to integrate the Fullstory SDK into APKs
4+
generated by [`bazelbuild/rules_android`](https://github.com/bazelbuild/rules_android)
45

56
## Installation
67

@@ -13,3 +14,34 @@ This is available at [the Bazel Central Registry as `fullstory_rules_android`](h
1314
From the release you wish to use:
1415
<https://github.com/fullstorydev/rules_android/releases>
1516
copy the WORKSPACE snippet into your `WORKSPACE` file.
17+
18+
## Usage
19+
20+
### Prerequisites
21+
22+
- This library depends on [`bazelbuild/rules_android`](https://github.com/bazelbuild/rules_android),
23+
and the current version requires the `--experimental_google_legacy_api` and
24+
`--experimental_enable_android_migration_apis` flags to be set. We suggest
25+
setting them in your `.bazelrc` as such:
26+
27+
```bazelrc
28+
common --experimental_google_legacy_api
29+
common --experimental_enable_android_migration_apis
30+
```
31+
32+
### Integrating the SDK
33+
34+
To integrate your APK with the Fullstory SDK, you can use the `fullstory_android_binary`
35+
rule:
36+
37+
```starlark
38+
load("@fullstory_rules_android//android:defs.bzl", "fullstory_android_binary")
39+
40+
fullstory_android_binary(
41+
name = "app_with_fs",
42+
app = "//package:android_buinary_target",
43+
)
44+
```
45+
46+
This will take the unsigned APK generated by the given target, integrate it with
47+
the Fullstory SDK, and generate new signed and unsigned APKs.

WORKSPACE.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# Marker that this is the root of a Bazel workspace.
1+
workspace(name = "rules_android")

android/BUILD.bazel

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
44
exports_files(["defs.bzl"])
55

66
bzl_library(
7-
name = "repositories",
8-
srcs = ["repositories.bzl"],
7+
name = "defs",
8+
srcs = ["defs.bzl"],
99
visibility = ["//visibility:public"],
10-
deps = [
11-
"//android/private:versions",
12-
"@bazel_tools//tools/build_defs/repo:http.bzl",
13-
"@bazel_tools//tools/build_defs/repo:utils.bzl",
14-
],
10+
deps = ["//android/private:fullstory_android_binary"],
1511
)
1612

1713
bzl_library(
18-
name = "defs",
19-
srcs = ["defs.bzl"],
14+
name = "dependencies",
15+
srcs = ["dependencies.bzl"],
2016
visibility = ["//visibility:public"],
17+
deps = [
18+
"@bazel_tools//tools/build_defs/repo:http.bzl",
19+
"@bazel_tools//tools/build_defs/repo:utils.bzl",
20+
],
2121
)

android/defs.bzl

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"Public API re-exports"
22

3-
def example():
4-
"""This is an example"""
5-
pass
3+
load("//android/private:fullstory_android_binary.bzl", _fullstory_android_binary = "fullstory_android_binary")
4+
5+
fullstory_android_binary = _fullstory_android_binary

android/repositories.bzl android/dependencies.bzl

+6-7
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ def http_archive(name, **kwargs):
1818
# and released only in semver majors.
1919
# This is all fixed by bzlmod, so we just tolerate it for now.
2020
def rules_android_dependencies():
21-
# The minimal version of bazel_skylib we require
2221
http_archive(
23-
name = "bazel_skylib",
24-
sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f",
25-
urls = [
26-
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
27-
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
28-
],
22+
name = "rules_android",
23+
sha256 = "b1599e4604c1594a1b0754184c5e50f895a68f444d1a5a82b688b2370d990ba0",
24+
strip_prefix = "rules_android-0.5.1",
25+
url = "https://github.com/bazelbuild/rules_android/releases/download/v0.5.1/rules_android-v0.5.1.tar.gz",
26+
patch_args = ["-p1"],
27+
patches = ["@fullstory_rules_android//:patches/bazelbuild/rules_android/rules_bzl_lib.patch"],
2928
)

android/private/BUILD.bazel

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
22

3+
bzl_library(
4+
name = "fullstory_android_binary",
5+
srcs = ["fullstory_android_binary.bzl"],
6+
visibility = ["//android:__subpackages__"],
7+
deps = ["@rules_android//android:rules"],
8+
)
9+
310
bzl_library(
411
name = "versions",
512
srcs = ["versions.bzl"],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"implementation of fullstory_android_binary rule"
2+
3+
load("@rules_android//android:rules.bzl", "ApkInfo")
4+
5+
def _impl(ctx):
6+
return [
7+
DefaultInfo(
8+
files = depset(),
9+
),
10+
ctx.attr.apk[ApkInfo],
11+
]
12+
13+
fullstory_android_binary = rule(
14+
implementation = _impl,
15+
attrs = {
16+
"apk": attr.label(
17+
mandatory = True,
18+
providers = [ApkInfo],
19+
),
20+
},
21+
doc = """Integrate the Android Fullstory SDK into an Android application.
22+
23+
Example:
24+
```starlark
25+
load("@rullstory_rules_android//android:defs.bzl", "fullstory_android_binary")
26+
27+
fullstory_android_binary(
28+
name = "example",
29+
apk = "//package:android_binary_target",
30+
)
31+
```
32+
""",
33+
)

docs/rules.md

+23-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)