Skip to content

Commit

Permalink
feat: initial skeleton for fullstory_android_binary rule
Browse files Browse the repository at this point in the history
  • Loading branch information
vpanta committed Oct 29, 2024
1 parent 2c5a8f2 commit 55e0fe2
Show file tree
Hide file tree
Showing 11 changed files with 567 additions and 1,513 deletions.
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ common --check_direct_dependencies=off
build --repository_cache=.cache/bazel/repo
build --disk_cache=.cache/bazel/actions

# Settings required for bazelbuild/rules_android
common --experimental_google_legacy_api
common --experimental_enable_android_migration_apis

# Load any settings specific to the current user.
# .bazelrc.user should appear in .gitignore so that settings are not shared with team members
# This needs to be last statement in this
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/release_prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ http_archive(
strip_prefix = "${PREFIX}",
url = "https://github.com/fullstorydev/rules_android/releases/download/${TAG}/${ARCHIVE}",
)
load("@fullstory_rules_android//android:dependencies.bzl", fullstory_rules_android_dependencies = "rules_android_dependencies")
fullstory_rules_android_dependencies()
# Set up bazelbuild/rules_android requirements, if you haven't already.
load("@rules_android//:prereqs.bzl", "rules_android_prereqs")
rules_android_prereqs()
load("@rules_android//:defs.bzl", "rules_android_workspace")
rules_android_workspace()
EOF

awk 'f;/--SNIP--/{f=1}' e2e/smoke/WORKSPACE.bazel
Expand Down
2 changes: 2 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ bazel_dep(name = "gazelle", version = "0.39.1", dev_dependency = True, repo_name
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.7.1", dev_dependency = True)
bazel_dep(name = "aspect_bazel_lib", version = "2.9.3", dev_dependency = True)
bazel_dep(name = "buildifier_prebuilt", version = "7.3.1", dev_dependency = True)

bazel_dep(name = "rules_android", version = "0.5.1")
1,950 changes: 458 additions & 1,492 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Bazel rules for Fullstory + Android

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)
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)

## Installation

Expand All @@ -13,3 +14,34 @@ This is available at [the Bazel Central Registry as `fullstory_rules_android`](h
From the release you wish to use:
<https://github.com/fullstorydev/rules_android/releases>
copy the WORKSPACE snippet into your `WORKSPACE` file.

## Usage

### Prerequisites

- This library depends on [`bazelbuild/rules_android`](https://github.com/bazelbuild/rules_android),
and the current version requires the `--experimental_google_legacy_api` and
`--experimental_enable_android_migration_apis` flags to be set. We suggest
setting them in your `.bazelrc` as such:

```bazelrc
common --experimental_google_legacy_api
common --experimental_enable_android_migration_apis
```

### Integrating the SDK

To integrate your APK with the Fullstory SDK, you can use the `fullstory_android_binary`
rule:

```starlark
load("@fullstory_rules_android//android:defs.bzl", "fullstory_android_binary")

fullstory_android_binary(
name = "app_with_fs",
app = "//package:android_buinary_target",
)
```

This will take the unsigned APK generated by the given target, integrate it with
the Fullstory SDK, and generate new signed and unsigned APKs.
18 changes: 9 additions & 9 deletions android/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
exports_files(["defs.bzl"])

bzl_library(
name = "repositories",
srcs = ["repositories.bzl"],
name = "defs",
srcs = ["defs.bzl"],
visibility = ["//visibility:public"],
deps = [
"//android/private:versions",
"@bazel_tools//tools/build_defs/repo:http.bzl",
"@bazel_tools//tools/build_defs/repo:utils.bzl",
],
deps = ["//android/private:fullstory_android_binary"],
)

bzl_library(
name = "defs",
srcs = ["defs.bzl"],
name = "dependencies",
srcs = ["dependencies.bzl"],
visibility = ["//visibility:public"],
deps = [
"@bazel_tools//tools/build_defs/repo:http.bzl",
"@bazel_tools//tools/build_defs/repo:utils.bzl",
],
)
6 changes: 3 additions & 3 deletions android/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"Public API re-exports"

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

fullstory_android_binary = _fullstory_android_binary
12 changes: 6 additions & 6 deletions android/repositories.bzl → android/dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def http_archive(name, **kwargs):
# This is all fixed by bzlmod, so we just tolerate it for now.
def rules_android_dependencies():
# The minimal version of bazel_skylib we require
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazel_skylib",
sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f",
urls = [
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
],
name = "rules_android",
sha256 = "b1599e4604c1594a1b0754184c5e50f895a68f444d1a5a82b688b2370d990ba0",
strip_prefix = "rules_android-0.5.1",
url = "https://github.com/bazelbuild/rules_android/releases/download/v0.5.1/rules_android-v0.5.1.tar.gz",
)
7 changes: 7 additions & 0 deletions android/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

bzl_library(
name = "fullstory_android_binary",
srcs = ["fullstory_android_binary.bzl"],
visibility = ["//android:__subpackages__"],
deps = ["@rules_android//rules:rules.bzl"],
)

bzl_library(
name = "versions",
srcs = ["versions.bzl"],
Expand Down
33 changes: 33 additions & 0 deletions android/private/fullstory_android_binary.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"implementation of fullstory_android_binary rule"

load("@rules_android//rules:rules.bzl", "ApkInfo")

def _impl(ctx):
return [
DefaultInfo(
files = depset(),
),
ctx.attr.apk[ApkInfo],
]

fullstory_android_binary = rule(
implementation = _impl,
attrs = {
"apk": attr.label(
mandatory = True,
providers = [ApkInfo],
),
},
doc = """Integrate the Android Fullstory SDK into an Android application.
Example:
```starlark
load("@rullstory_rules_android//android:defs.bzl", "fullstory_android_binary")
fullstory_android_binary(
name = "example",
apk = "//package:android_binary_target",
)
```
""",
)
4 changes: 2 additions & 2 deletions e2e/smoke/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ local_repository(
# you should fetch it *before* calling this.
# Alternatively, you can skip calling this function, so long as you've
# already fetched all the dependencies.
load("@fullstory_rules_android//android:repositories.bzl", "rules_android_dependencies")
load("@fullstory_rules_android//android:dependencies.bzl", fullstory_rules_android_dependencies = "rules_android_dependencies")

rules_android_dependencies()
fullstory_rules_android_dependencies()

0 comments on commit 55e0fe2

Please sign in to comment.