From ccd21c6fb3d0ba12c278df0cd8fe0e5ed971c46c Mon Sep 17 00:00:00 2001 From: Vasilios Pantazopoulos Date: Wed, 4 Dec 2024 13:39:20 -0500 Subject: [PATCH] feat: initial integration with `FullstoryInjector` (#5) feat: initial integration with `FullstoryInjector --- MODULE.bazel | 29 +++- MODULE.bazel.lock | 55 +++++--- README.md | 6 + android/private/BUILD.bazel | 18 ++- android/private/fullstory_android_binary.bzl | 127 +++++++++++++++++- android/private/versions.bzl | 14 -- android/tests/BUILD.bazel | 3 - android/tests/versions_test.bzl | 18 --- docs/rules.md | 8 +- maven_install.json | 38 ++++++ .../rules_android/rules_bzl_lib.patch | 54 ++++---- 11 files changed, 275 insertions(+), 95 deletions(-) delete mode 100644 android/private/versions.bzl delete mode 100644 android/tests/BUILD.bazel delete mode 100644 android/tests/versions_test.bzl create mode 100755 maven_install.json diff --git a/MODULE.bazel b/MODULE.bazel index f2aaae9..9778b8e 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -9,14 +9,31 @@ module( bazel_dep(name = "bazel_skylib", version = "1.7.1") bazel_dep(name = "platforms", version = "0.0.10") bazel_dep(name = "rules_android", version = "0.5.1") - -bazel_dep(name = "gazelle", version = "0.39.1", dev_dependency = True, repo_name = "bazel_gazelle") -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) - single_version_override( module_name = "rules_android", patch_strip = 1, patches = ["//:patches/bazelbuild/rules_android/rules_bzl_lib.patch"], ) + +bazel_dep(name = "rules_java", version = "7.7.0") +bazel_dep(name = "rules_jvm_external", version = "6.5") + +maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") +maven.install( + name = "fs_maven", + artifacts = [ + "com.fullstory:instrumentation-full:1.55.0-bazel0", + ], + lock_file = "//:maven_install.json", + repositories = [ + "m2Local", + "https://repo1.maven.org/maven2", + ], +) +use_repo(maven, "fs_maven") + +# Dev dependencies +bazel_dep(name = "gazelle", version = "0.39.1", dev_dependency = True, repo_name = "bazel_gazelle") +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) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 8df01e7..0fb363c 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -4,7 +4,9 @@ "https://bcr.bazel.build/bazel_registry.json": "8a28e4aff06ee60aed2a8c281907fb8bcbf3b753c91fb5a5c57da3215d5b3497", "https://bcr.bazel.build/modules/abseil-cpp/20210324.2/MODULE.bazel": "7cd0312e064fde87c8d1cd79ba06c876bd23630c83466e9500321be55c96ace2", "https://bcr.bazel.build/modules/abseil-cpp/20211102.0/MODULE.bazel": "70390338f7a5106231d20620712f7cccb659cd0e9d073d1991c038eb9fc57589", - "https://bcr.bazel.build/modules/abseil-cpp/20211102.0/source.json": "7e3a9adf473e9af076ae485ed649d5641ad50ec5c11718103f34de03170d94ad", + "https://bcr.bazel.build/modules/abseil-cpp/20230125.1/MODULE.bazel": "89047429cb0207707b2dface14ba7f8df85273d484c2572755be4bab7ce9c3a0", + "https://bcr.bazel.build/modules/abseil-cpp/20230802.1/MODULE.bazel": "fa92e2eb41a04df73cdabeec37107316f7e5272650f81d6cc096418fe647b915", + "https://bcr.bazel.build/modules/abseil-cpp/20230802.1/source.json": "035b6f1911e17340db722bbc9158f830ee6d5dedba4cb3bcb9e25e590808a32c", "https://bcr.bazel.build/modules/abseil-py/1.4.0/MODULE.bazel": "783459847ea946f3c8e81d6a2bf539f15bd733c009dfbe29fc2e6ebad2260fb5", "https://bcr.bazel.build/modules/abseil-py/1.4.0/source.json": "3ef2776fe7e9aea15253a3df67690692bce8b6931bc204267884dc6550fac25f", "https://bcr.bazel.build/modules/apple_support/1.5.0/MODULE.bazel": "50341a62efbc483e8a2a6aec30994a58749bd7b885e18dd96aa8c33031e558ef", @@ -15,7 +17,8 @@ "https://bcr.bazel.build/modules/bazel_features/1.1.1/MODULE.bazel": "27b8c79ef57efe08efccbd9dd6ef70d61b4798320b8d3c134fd571f78963dbcd", "https://bcr.bazel.build/modules/bazel_features/1.11.0/MODULE.bazel": "f9382337dd5a474c3b7d334c2f83e50b6eaedc284253334cf823044a26de03e8", "https://bcr.bazel.build/modules/bazel_features/1.13.0/MODULE.bazel": "c14c33c7c3c730612bdbe14ebbb5e61936b6f11322ea95a6e91cd1ba962f94df", - "https://bcr.bazel.build/modules/bazel_features/1.13.0/source.json": "b01f6aaaf93527ff4267421ef416debbd89b3166b70af5c89400c6a95a89c133", + "https://bcr.bazel.build/modules/bazel_features/1.17.0/MODULE.bazel": "039de32d21b816b47bd42c778e0454217e9c9caac4a3cf8e15c7231ee3ddee4d", + "https://bcr.bazel.build/modules/bazel_features/1.17.0/source.json": "4b0f9407970b57adb203bd6c23d6361cbcc8ab3273456ad06ca75675b1648b41", "https://bcr.bazel.build/modules/bazel_features/1.4.1/MODULE.bazel": "e45b6bb2350aff3e442ae1111c555e27eac1d915e77775f6fdc4b351b758b5d7", "https://bcr.bazel.build/modules/bazel_features/1.9.1/MODULE.bazel": "8f679097876a9b609ad1f60249c49d68bfab783dd9be012faf9d82547b14815a", "https://bcr.bazel.build/modules/bazel_skylib/1.0.3/MODULE.bazel": "bcb0fd896384802d1ad283b4e4eb4d718eebd8cb820b0a2c3a347fb971afd9d8", @@ -44,7 +47,8 @@ "https://bcr.bazel.build/modules/gazelle/0.39.1/MODULE.bazel": "1fa3fefad240e535066fd0e6950dfccd627d36dc699ee0034645e51dbde3980f", "https://bcr.bazel.build/modules/gazelle/0.39.1/source.json": "f2facfa8c8c9a4d2ebf613754023054c2eb793b88675082216c6be0419eb20a1", "https://bcr.bazel.build/modules/googletest/1.11.0/MODULE.bazel": "3a83f095183f66345ca86aa13c58b59f9f94a2f81999c093d4eeaa2d262d12f4", - "https://bcr.bazel.build/modules/googletest/1.11.0/source.json": "c73d9ef4268c91bd0c1cd88f1f9dfa08e814b1dbe89b5f594a9f08ba0244d206", + "https://bcr.bazel.build/modules/googletest/1.14.0/MODULE.bazel": "cfbcbf3e6eac06ef9d85900f64424708cc08687d1b527f0ef65aa7517af8118f", + "https://bcr.bazel.build/modules/googletest/1.14.0/source.json": "2478949479000fdd7de9a3d0107ba2c85bb5f961c3ecb1aa448f52549ce310b5", "https://bcr.bazel.build/modules/platforms/0.0.10/MODULE.bazel": "8cb8efaf200bdeb2150d93e162c40f388529a25852b332cec879373771e48ed5", "https://bcr.bazel.build/modules/platforms/0.0.10/source.json": "f22828ff4cf021a6b577f1bf6341cb9dcd7965092a439f64fc1bb3b7a5ae4bd5", "https://bcr.bazel.build/modules/platforms/0.0.4/MODULE.bazel": "9b328e31ee156f53f3c416a64f8491f7eb731742655a47c9eec4703a71644aee", @@ -61,10 +65,12 @@ "https://bcr.bazel.build/modules/rules_android/0.5.1/MODULE.bazel": "a3898eb6ec2815687d43fcb4808f242fd8e9678760d2a03299860dd81f0bd50e", "https://bcr.bazel.build/modules/rules_android/0.5.1/source.json": "33b2dfc3b89c330644b7609cea96b5ed008e9c8f3c2ffb9c1320b406b81a968a", "https://bcr.bazel.build/modules/rules_cc/0.0.1/MODULE.bazel": "cb2aa0747f84c6c3a78dad4e2049c154f08ab9d166b1273835a8174940365647", + "https://bcr.bazel.build/modules/rules_cc/0.0.10/MODULE.bazel": "ec1705118f7eaedd6e118508d3d26deba2a4e76476ada7e0e3965211be012002", + "https://bcr.bazel.build/modules/rules_cc/0.0.10/source.json": "90310b16e0e7df0cf40f8d1dccd7d373360f42419a6bfbbf5bb013182dd70e84", "https://bcr.bazel.build/modules/rules_cc/0.0.2/MODULE.bazel": "6915987c90970493ab97393024c156ea8fb9f3bea953b2f3ec05c34f19b5695c", + "https://bcr.bazel.build/modules/rules_cc/0.0.6/MODULE.bazel": "abf360251023dfe3efcef65ab9d56beefa8394d4176dd29529750e1c57eaa33f", "https://bcr.bazel.build/modules/rules_cc/0.0.8/MODULE.bazel": "964c85c82cfeb6f3855e6a07054fdb159aced38e99a5eecf7bce9d53990afa3e", "https://bcr.bazel.build/modules/rules_cc/0.0.9/MODULE.bazel": "836e76439f354b89afe6a911a7adf59a6b2518fafb174483ad78a2a2fde7b1c5", - "https://bcr.bazel.build/modules/rules_cc/0.0.9/source.json": "1f1ba6fea244b616de4a554a0f4983c91a9301640c8fe0dd1d410254115c8430", "https://bcr.bazel.build/modules/rules_go/0.33.0/MODULE.bazel": "a2b11b64cd24bf94f57454f53288a5dacfe6cb86453eee7761b7637728c1910c", "https://bcr.bazel.build/modules/rules_go/0.35.0/MODULE.bazel": "2e9ef0abff7025c3d27b35d3713354634b98795e0c630b8d47b1799e4588fb9c", "https://bcr.bazel.build/modules/rules_go/0.37.0/MODULE.bazel": "7639dae065f071efebbe73c03dc8330c3293206cf073af7c7084add4e0120aba", @@ -77,17 +83,20 @@ "https://bcr.bazel.build/modules/rules_java/4.0.0/MODULE.bazel": "5a78a7ae82cd1a33cef56dc578c7d2a46ed0dca12643ee45edbb8417899e6f74", "https://bcr.bazel.build/modules/rules_java/6.3.0/MODULE.bazel": "a97c7678c19f236a956ad260d59c86e10a463badb7eb2eda787490f4c969b963", "https://bcr.bazel.build/modules/rules_java/7.0.6/MODULE.bazel": "6ddb07d9857a1a3accc9f6d005f20c969c4659c7710e6269a51db3527e0ea969", + "https://bcr.bazel.build/modules/rules_java/7.12.2/MODULE.bazel": "579c505165ee757a4280ef83cda0150eea193eed3bef50b1004ba88b99da6de6", + "https://bcr.bazel.build/modules/rules_java/7.12.2/source.json": "b0890f9cda8ff1b8e691a3ac6037b5c14b7fd4134765a3946b89f31ea02e5884", "https://bcr.bazel.build/modules/rules_java/7.2.0/MODULE.bazel": "06c0334c9be61e6cef2c8c84a7800cef502063269a5af25ceb100b192453d4ab", "https://bcr.bazel.build/modules/rules_java/7.4.0/MODULE.bazel": "a592852f8a3dd539e82ee6542013bf2cadfc4c6946be8941e189d224500a8934", "https://bcr.bazel.build/modules/rules_java/7.6.1/MODULE.bazel": "2f14b7e8a1aa2f67ae92bc69d1ec0fa8d9f827c4e17ff5e5f02e91caa3b2d0fe", "https://bcr.bazel.build/modules/rules_java/7.7.0/MODULE.bazel": "93a198f955574cdbb0e0b089faa3d3a76b6bfffc553c13bd8a96e162e179ac87", - "https://bcr.bazel.build/modules/rules_java/7.7.0/source.json": "529d8a0496f2fb3ca5d120011e66fb17bdc09017d95bed893768c98ff48c8bba", "https://bcr.bazel.build/modules/rules_jvm_external/4.4.2/MODULE.bazel": "a56b85e418c83eb1839819f0b515c431010160383306d13ec21959ac412d2fe7", "https://bcr.bazel.build/modules/rules_jvm_external/5.2/MODULE.bazel": "d9351ba35217ad0de03816ef3ed63f89d411349353077348a45348b096615036", "https://bcr.bazel.build/modules/rules_jvm_external/6.2/MODULE.bazel": "36a6e52487a855f33cb960724eb56547fa87e2c98a0474c3acad94339d7f8e99", - "https://bcr.bazel.build/modules/rules_jvm_external/6.2/source.json": "7f4c0095f17d1b65f943169e1d4f5f831a7133d205179e7b1b515ffcb39a5aa4", + "https://bcr.bazel.build/modules/rules_jvm_external/6.5/MODULE.bazel": "54f3e81ae9b57ede5916c9a48add664dc30a5ce3855376b51ae7d6f23405daf8", + "https://bcr.bazel.build/modules/rules_jvm_external/6.5/source.json": "5b8bed439771269d9c0af57cf4326cbfd2462e49ebb11230499aaa11fe70f3db", "https://bcr.bazel.build/modules/rules_kotlin/1.9.5/MODULE.bazel": "043a16a572f610558ec2030db3ff0c9938574e7dd9f58bded1bb07c0192ef025", - "https://bcr.bazel.build/modules/rules_kotlin/1.9.5/source.json": "4ea6e867a7db5ef01187a07636070110db267f94ed038367bec7bbd3aea5e612", + "https://bcr.bazel.build/modules/rules_kotlin/1.9.6/MODULE.bazel": "d269a01a18ee74d0335450b10f62c9ed81f2321d7958a2934e44272fe82dcef3", + "https://bcr.bazel.build/modules/rules_kotlin/1.9.6/source.json": "2faa4794364282db7c06600b7e5e34867a564ae91bda7cae7c29c64e9466b7d5", "https://bcr.bazel.build/modules/rules_license/0.0.3/MODULE.bazel": "627e9ab0247f7d1e05736b59dbb1b6871373de5ad31c3011880b4133cafd4bd0", "https://bcr.bazel.build/modules/rules_license/0.0.4/MODULE.bazel": "6a88dd22800cf1f9f79ba32cacad0d3a423ed28efa2c2ed5582eaa78dd3ac1e5", "https://bcr.bazel.build/modules/rules_license/0.0.7/MODULE.bazel": "088fbeb0b6a419005b89cf93fe62d9517c0a2b8bb56af3244af65ecfe37e7d5d", @@ -98,7 +107,8 @@ "https://bcr.bazel.build/modules/rules_proto/4.0.0/MODULE.bazel": "a7a7b6ce9bee418c1a760b3d84f83a299ad6952f9903c67f19e4edd964894e06", "https://bcr.bazel.build/modules/rules_proto/5.3.0-21.7/MODULE.bazel": "e8dff86b0971688790ae75528fe1813f71809b5afd57facb44dad9e8eca631b7", "https://bcr.bazel.build/modules/rules_proto/6.0.0/MODULE.bazel": "b531d7f09f58dce456cd61b4579ce8c86b38544da75184eadaf0a7cb7966453f", - "https://bcr.bazel.build/modules/rules_proto/6.0.0/source.json": "de77e10ff0ab16acbf54e6b46eecd37a99c5b290468ea1aee6e95eb1affdaed7", + "https://bcr.bazel.build/modules/rules_proto/6.0.2/MODULE.bazel": "ce916b775a62b90b61888052a416ccdda405212b6aaeb39522f7dc53431a5e73", + "https://bcr.bazel.build/modules/rules_proto/6.0.2/source.json": "17a2e195f56cb28d6bbf763e49973d13890487c6945311ed141e196fb660426d", "https://bcr.bazel.build/modules/rules_python/0.10.2/MODULE.bazel": "cc82bc96f2997baa545ab3ce73f196d040ffb8756fd2d66125a530031cd90e5f", "https://bcr.bazel.build/modules/rules_python/0.22.1/MODULE.bazel": "26114f0c0b5e93018c0c066d6673f1a2c3737c7e90af95eff30cfee38d0bbac7", "https://bcr.bazel.build/modules/rules_python/0.23.1/MODULE.bazel": "49ffccf0511cb8414de28321f5fcf2a31312b47c40cc21577144b7447f2bf300", @@ -828,8 +838,8 @@ }, "@@rules_kotlin~//src/main/starlark/core/repositories:bzlmod_setup.bzl%rules_kotlin_extensions": { "general": { - "bzlTransitiveDigest": "kZ+9OOxWkWt07Jni1BKXITpFDZRZoYjB0LCALFyjGkc=", - "usagesDigest": "K+i+NLBtqsvNSdO+8wYj1BOGr0DAXxBxW8myZpWViyc=", + "bzlTransitiveDigest": "l//eFZVgEUHSUfuQ1zQw9uxmcJku8ikraA2fv/2Pyh0=", + "usagesDigest": "NXmdQOmIAdsAdtLv3dhkX8UQ+0st9iQ0EkR28lUNdHc=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, @@ -849,22 +859,29 @@ "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_file", "attributes": { - "sha256": "2b3f6f674a944d25bb8d283c3539947bbe86074793012909a55de4b771f74bcc", + "sha256": "01b2e0ef893383a50dbeb13970fe7fa3be36ca3e83259e01649945b09d736985", "urls": [ - "https://github.com/pinterest/ktlint/releases/download/0.49.1/ktlint" + "https://github.com/pinterest/ktlint/releases/download/1.3.0/ktlint" ], "executable": true } }, "com_github_jetbrains_kotlin": { "bzlFile": "@@rules_kotlin~//src/main/starlark/core/repositories:compiler.bzl", - "ruleClassName": "kotlin_compiler_repository", + "ruleClassName": "kotlin_capabilities_repository", + "attributes": { + "git_repository_name": "com_github_jetbrains_kotlin_git", + "compiler_version": "1.9.23" + } + }, + "com_github_jetbrains_kotlin_git": { + "bzlFile": "@@rules_kotlin~//src/main/starlark/core/repositories:compiler.bzl", + "ruleClassName": "kotlin_compiler_git_repository", "attributes": { "urls": [ - "https://github.com/JetBrains/kotlin/releases/download/v1.9.22/kotlin-compiler-1.9.22.zip" + "https://github.com/JetBrains/kotlin/releases/download/v1.9.23/kotlin-compiler-1.9.23.zip" ], - "sha256": "88b39213506532c816ff56348c07bbeefe0c8d18943bffbad11063cf97cac3e6", - "compiler_version": "1.9.22" + "sha256": "93137d3aab9afa9b27cb06a824c2324195c6b6f6179d8a8653f440f5bd58be88" } }, "com_github_google_ksp": { @@ -872,10 +889,10 @@ "ruleClassName": "ksp_compiler_plugin_repository", "attributes": { "urls": [ - "https://github.com/google/ksp/releases/download/1.9.22-1.0.17/artifacts.zip" + "https://github.com/google/ksp/releases/download/1.9.23-1.0.20/artifacts.zip" ], - "sha256": "b39b373e09e5edefe700fef628572f71be7d49e6396dec0ea52eb10c16ead39e", - "strip_version": "1.9.22-1.0.17" + "sha256": "ee0618755913ef7fd6511288a232e8fad24838b9af6ea73972a76e81053c8c2d", + "strip_version": "1.9.23-1.0.20" } } }, diff --git a/README.md b/README.md index fd967a0..9a28fbd 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,15 @@ # Bazel rules for Fullstory + Android +> ## ⚠️ This is an experimental ruleset and not ready for usage ⚠️ + 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 +Not available yet + + ## Usage diff --git a/android/private/BUILD.bazel b/android/private/BUILD.bazel index 402b90a..58a786b 100644 --- a/android/private/BUILD.bazel +++ b/android/private/BUILD.bazel @@ -1,14 +1,18 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +load("@rules_java//java:defs.bzl", "java_binary") -bzl_library( - name = "fullstory_android_binary", - srcs = ["fullstory_android_binary.bzl"], - visibility = ["//android:__subpackages__"], - deps = ["@rules_android//android:rules"], +java_binary( + name = "FullstoryInjector", + main_class = "com.fullstory.FullstoryInjector", + runtime_deps = ["@fs_maven//:com_fullstory_instrumentation_full"], ) bzl_library( - name = "versions", - srcs = ["versions.bzl"], + name = "fullstory_android_binary", + srcs = ["fullstory_android_binary.bzl"], visibility = ["//android:__subpackages__"], + deps = [ + "@rules_android//rules", + "@rules_android//rules:utils", + ], ) diff --git a/android/private/fullstory_android_binary.bzl b/android/private/fullstory_android_binary.bzl index 02ef673..a08154f 100644 --- a/android/private/fullstory_android_binary.bzl +++ b/android/private/fullstory_android_binary.bzl @@ -1,15 +1,123 @@ "implementation of fullstory_android_binary rule" -load("@rules_android//android:rules.bzl", "ApkInfo") +load("@rules_android//rules:rules.bzl", "ApkInfo") +load("@rules_android//rules:utils.bzl", "get_android_sdk") def _impl(ctx): + apk_info = ctx.attr.apk[ApkInfo] + out_apk = ctx.actions.declare_file(ctx.label.name + ".apk") + unsigned_apk = ctx.actions.declare_file(ctx.label.name + "_unsigned.apk") + + args = ctx.actions.args() + args.add("--in", apk_info.unsigned_apk.path) + args.add("--applicationClass", ctx.attr.application_class) + args.add("--minSdkVersion", ctx.attr.min_sdk_version) + args.add("--org", ctx.attr.org_id) + args.add("--out", unsigned_apk.path) + + ctx.actions.run( + outputs = [unsigned_apk], + inputs = [apk_info.unsigned_apk], + arguments = [args], + executable = ctx.executable._fullstory_injector, + ) + + _sign_apk( + ctx, + out_apk = out_apk, + in_apk = unsigned_apk, + signing_keys = apk_info.signing_keys, + deterministic_signing = False, + signing_lineage = apk_info.signing_lineage, + signing_key_rotation_min_sdk = ctx.attr.min_sdk_version, + v4_signature_file = None, + ) + return [ DefaultInfo( - files = depset(), + files = depset([ + out_apk, + ]), + ), + ApkInfo( + unsigned_apk = unsigned_apk, + signed_apk = out_apk, + signing_keys = apk_info.signing_keys, + signing_lineage = apk_info.signing_lineage, + signing_min_v3_rotation_api_version = apk_info.signing_min_v3_rotation_api_version, + # The rest are copied from the incoming source for now. + deploy_jar = apk_info.deploy_jar, + coverage_metadata = apk_info.coverage_metadata, + merged_manifest = apk_info.deploy_jar, # cannot access merged_manifest, so just drop a file here. ), - ctx.attr.apk[ApkInfo], ] +# This is mostly borrowed from the internal signing function in rules_android- +# https://github.com/bazelbuild/rules_android/blob/4d719e1b1a9db31c2ea18dc966dbe8be05550b05/rules/apk_packaging.bzl#L312 +def _sign_apk( + ctx, + out_apk, + in_apk, + signing_keys = [], + deterministic_signing = True, + signing_lineage = None, + signing_key_rotation_min_sdk = None, + v4_signature_file = None, + toolchain_type = None): + """Signs an apk.""" + outputs = [out_apk] + inputs = [in_apk] + signing_keys + apk_signer = get_android_sdk(ctx).apk_signer + + args = ctx.actions.args() + args.add("sign") + + if signing_lineage: + inputs.append(signing_lineage) + args.add("--lineage", signing_lineage) + if deterministic_signing: + # Enable deterministic DSA signing to keep the output of apksigner deterministic. + # This requires including BouncyCastleProvider as a Security provider, since the standard + # JDK Security providers do not include support for deterministic DSA signing. + # Since this adds BouncyCastleProvider to the end of the Provider list, any non-DSA signing + # algorithms (such as RSA) invoked by apksigner will still use the standard JDK + # implementations and not Bouncy Castle. + args.add("--deterministic-dsa-signing", "true") + args.add("--provider-class", "org.bouncycastle.jce.provider.BouncyCastleProvider") + + for i in range(len(signing_keys)): + if i > 0: + args.add("--next-signer") + args.add("--ks", signing_keys[i]) + args.add("--ks-pass", "pass:android") + + args.add("--v1-signing-enabled", ctx.fragments.android.apk_signing_method_v1) + args.add("--v1-signer-name", "CERT") + args.add("--v2-signing-enabled", ctx.fragments.android.apk_signing_method_v2) + + # If the v4 flag is unset, it should not be passed to apk signer. This extra level of control is + # needed to support environments where older build tools may be used. + if ctx.fragments.android.apk_signing_method_v4 != None: + args.add("--v4-signing-enabled", ctx.fragments.android.apk_signing_method_v4) + if v4_signature_file: + outputs.append(v4_signature_file) + + if signing_key_rotation_min_sdk: + args.add("--rotation-min-sdk-version", signing_key_rotation_min_sdk) + + args.add("--out", out_apk) + args.add(in_apk) + + ctx.actions.run( + executable = apk_signer, + outputs = outputs, + inputs = inputs, + arguments = [args], + mnemonic = "ApkSignerTool", + progress_message = "Signing apk", + toolchain = toolchain_type, + ) + fullstory_android_binary = rule( implementation = _impl, attrs = { @@ -17,7 +125,16 @@ fullstory_android_binary = rule( mandatory = True, providers = [ApkInfo], ), + "application_class": attr.string(mandatory = True), + "org_id": attr.string(mandatory = True), + "min_sdk_version": attr.int(default = 19), + "_fullstory_injector": attr.label( + default = "//android/private:FullstoryInjector", + executable = True, + cfg = "exec", + ), }, + toolchains = ["@rules_android//toolchains/android:toolchain_type", "@rules_android//toolchains/android_sdk:toolchain_type"], doc = """Integrate the Android Fullstory SDK into an Android application. Example: @@ -27,7 +144,11 @@ load("@rullstory_rules_android//android:defs.bzl", "fullstory_android_binary") fullstory_android_binary( name = "example", apk = "//package:android_binary_target", + application_class = "com.example.App", + org_id = "YourOrganizationId", + min_sdk_version = 19, ) ``` """, + fragments = ["android"], ) diff --git a/android/private/versions.bzl b/android/private/versions.bzl deleted file mode 100644 index 7f6c5bd..0000000 --- a/android/private/versions.bzl +++ /dev/null @@ -1,14 +0,0 @@ -"""Mirror of release info - -TODO: generate this file from GitHub API""" - -# The integrity hashes can be computed with -# shasum -b -a 384 [downloaded file] | awk '{ print $1 }' | xxd -r -p | base64 -TOOL_VERSIONS = { - "1.14.2": { - "x86_64-apple-darwin": "sha384-ws4+rANvv0YxM1SgIBUXSG9jT8dKw83nls6R5qYkEKzPUB+viBIEozSsyq2e6i+f", - "aarch64-apple-darwin": "sha384-HcvJbxoJtGSavkGu0e7CyD00cBlmDb0TBWJ4JSaNa70zuU3N7XlMOYm3bbQcAv2U", - "x86_64-pc-windows-msvc": "sha384-35YN6TKpT0L9qyRBmq48NucvyXEtHnkeC+txf2YZmmJTmOzrAKREA74BA0EZvpar", - "x86_64-unknown-linux-gnu": "sha384-QgGOwTaetxY0h5HWCKc/3ZtBs4N/fgaaORthn7UcEv++Idm9W+ntCCZRwvBdwHPD", - }, -} diff --git a/android/tests/BUILD.bazel b/android/tests/BUILD.bazel deleted file mode 100644 index 93eae3c..0000000 --- a/android/tests/BUILD.bazel +++ /dev/null @@ -1,3 +0,0 @@ -load(":versions_test.bzl", "versions_test_suite") - -versions_test_suite(name = "versions_test") diff --git a/android/tests/versions_test.bzl b/android/tests/versions_test.bzl deleted file mode 100644 index 8851b7a..0000000 --- a/android/tests/versions_test.bzl +++ /dev/null @@ -1,18 +0,0 @@ -"""Unit tests for starlark helpers -See https://bazel.build/rules/testing#testing-starlark-utilities -""" - -load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") -load("//android/private:versions.bzl", "TOOL_VERSIONS") - -def _smoke_test_impl(ctx): - env = unittest.begin(ctx) - asserts.equals(env, "1.14.2", TOOL_VERSIONS.keys()[0]) - return unittest.end(env) - -# The unittest library requires that we export the test cases as named test rules, -# but their names are arbitrary and don't appear anywhere. -_t0_test = unittest.make(_smoke_test_impl) - -def versions_test_suite(name): - unittest.suite(name, _t0_test) diff --git a/docs/rules.md b/docs/rules.md index 7058a01..3619036 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -9,7 +9,7 @@ Public API re-exports
 load("@fullstory_rules_android//android:defs.bzl", "fullstory_android_binary")
 
-fullstory_android_binary(name, apk)
+fullstory_android_binary(name, apk, application_class, min_sdk_version, org_id)
 
Integrate the Android Fullstory SDK into an Android application. @@ -21,6 +21,9 @@ load("@rullstory_rules_android//android:defs.bzl", "fullstory_android_binary") fullstory_android_binary( name = "example", apk = "//package:android_binary_target", + application_class = "com.example.App", + org_id = "YourOrganizationId", + min_sdk_version = 19, ) ``` @@ -31,5 +34,8 @@ fullstory_android_binary( | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | apk | - | Label | required | | +| application_class | - | String | required | | +| min_sdk_version | - | Integer | optional | `19` | +| org_id | - | String | required | | diff --git a/maven_install.json b/maven_install.json new file mode 100755 index 0000000..06e948e --- /dev/null +++ b/maven_install.json @@ -0,0 +1,38 @@ +{ + "__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL", + "__INPUT_ARTIFACTS_HASH": -2125837068, + "__RESOLVED_ARTIFACTS_HASH": 1301770192, + "artifacts": { + "com.fullstory:instrumentation-full": { + "shasums": { + "jar": "9a8de8e70449c68189d30b59db75ff076a334088fab79eb6311aecf3fe9cdc00" + }, + "version": "1.55.0-bazel0" + } + }, + "dependencies": {}, + "m2local": true, + "packages": { + "com.fullstory:instrumentation-full": [ + "com.fullstory", + "com.fullstory.dexmunger", + "com.fullstory.dexmunger.compose", + "com.fullstory.instrumentation", + "com.fullstory.shared", + "fs", + "fs.kotlin.metadata" + ] + }, + "repositories": { + "m2Local/": [], + "https://repo1.maven.org/maven2/": [] + }, + "services": { + "com.fullstory:instrumentation-full": { + "fs.kotlin.metadata.MetadataExtensions": [ + "fs.kotlin.metadata.JvmMetadataExtensions" + ] + } + }, + "version": "2" +} diff --git a/patches/bazelbuild/rules_android/rules_bzl_lib.patch b/patches/bazelbuild/rules_android/rules_bzl_lib.patch index 9a5f281..24e0d77 100644 --- a/patches/bazelbuild/rules_android/rules_bzl_lib.patch +++ b/patches/bazelbuild/rules_android/rules_bzl_lib.patch @@ -1,14 +1,14 @@ -diff --git a/android/BUILD b/android/BUILD -index 4db0c10..d7ee91b 100644 ---- a/android/BUILD -+++ b/android/BUILD -@@ -16,3 +16,16 @@ - Package used for redirecting Starlark rules from //android/rules.bzl to //rules/rules.bzl. - Used for easier migration to a new branch due to directory differences. - """ -+ -+load("@bazel_skylib//:bzl_library.bzl", "bzl_library") -+ +diff --git a/rules/BUILD b/rules/BUILD +index c8b565d..7ba659c 100644 +--- a/rules/BUILD ++++ b/rules/BUILD +@@ -118,6 +118,34 @@ bzl_library( + ], + ) + ++# Publicly-visible single-file `rules.bzl` target, for users of ++# `bazelbuild/bazel-skylib`'s `bazel_skylib_gazelle_plugin`: ++# https://registry.bazel.build/modules/bazel_skylib_gazelle_plugin +bzl_library( + name = "rules", + srcs = ["rules.bzl"], @@ -16,18 +16,24 @@ index 4db0c10..d7ee91b 100644 + "//visibility:public", + ], + deps = [ -+ "//rules:bzl", ++ ":bzl", + ], +) -diff --git a/rules/BUILD b/rules/BUILD -index c8b565d..b1a560b 100644 ---- a/rules/BUILD -+++ b/rules/BUILD -@@ -115,6 +115,7 @@ bzl_library( - "rules.bzl", - ], - visibility = [ -+ "//android:__pkg__", - "//mobile_install:__pkg__", - "//stardoc:__pkg__", - ], ++ ++bzl_library( ++ name = "utils", ++ srcs = [ ++ "utils.bzl", ++ ], ++ visibility = [ ++ "//visibility:public", ++ ], ++ deps = [ ++ ":common_bzl", ++ ":visibility_bzl", ++ ], ++) ++ + bzl_library( + name = "min_sdk_version_bzl", + srcs = ["min_sdk_version.bzl"],