Skip to content

Commit f53b140

Browse files
committed
Bug 1957640 - Move Megazord.init code to initialize_rust_components
1 parent 40ae79e commit f53b140

File tree

10 files changed

+37
-35
lines changed

10 files changed

+37
-35
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# v140.0 (In progress)
22

3+
## ⚠️ Breaking Changes ⚠️
4+
5+
### Android
6+
- Added `RustComponentsInitializer.kt` to `init_rust_components`.
7+
8+
#### BREAKING CHANGE
9+
- Removed `Megazord.kt` and moved the contents to the new `RustComponentsInitializer.kt`.
10+
311
[Full Changelog](In progress)
412

513
# v139.0 (_2025-04-28_)

components/autofill/android/src/test/java/mozilla/appservices/autofill/AutofillTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import mozilla.appservices.Megazord
21
import mozilla.appservices.autofill.Store
32
import mozilla.appservices.syncmanager.SyncManager
43
import org.junit.Assert
@@ -17,7 +16,6 @@ class AutofillTest {
1716
val dbFolder = TemporaryFolder()
1817

1918
fun createTestStore(): Store {
20-
Megazord.init()
2119
val dbPath = dbFolder.newFile()
2220
return Store(dbpath = dbPath.absolutePath)
2321
}

components/init_rust_components/android/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ apply from: "$appServicesRootDir/publish.gradle"
33

44
android {
55
namespace 'org.mozilla.appservices.init_rust_components'
6+
7+
defaultConfig {
8+
buildConfigField("String", "LIBRARY_VERSION", "\"${config.componentsVersion}\"")
9+
}
610
}
711

812
ext.configureUniFFIBindgen("init_rust_components")
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
package mozilla.appservices
6+
7+
import mozilla.appservices.init_rust_components.initialize
8+
import org.mozilla.appservices.init_rust_components.BuildConfig
9+
10+
object RustComponentsInitializer {
11+
@JvmStatic
12+
fun init() {
13+
// Rust components must be initialized at the very beginning, before any other Rust call, ...
14+
initialize()
15+
16+
// This code was originally in the `Megazord.init` that was moved here to have the initialize
17+
// done in this particular sequence without needing to have the embedder have to do it within
18+
// the application layer.
19+
System.setProperty("mozilla.appservices.megazord.library", "megazord")
20+
System.setProperty("mozilla.appservices.megazord.version", BuildConfig.LIBRARY_VERSION)
21+
}
22+
}

components/logins/android/src/test/java/mozilla/appservices/logins/DatabaseLoginsStorageTest.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package mozilla.appservices.logins
55

66
import androidx.test.core.app.ApplicationProvider
7-
import mozilla.appservices.Megazord
7+
import mozilla.appservices.RustComponentsInitializer
88
import mozilla.appservices.syncmanager.SyncManager
99
import mozilla.telemetry.glean.testing.GleanTestRule
1010
import org.junit.Assert.assertEquals
@@ -20,7 +20,6 @@ import org.junit.rules.TemporaryFolder
2020
import org.junit.runner.RunWith
2121
import org.robolectric.RobolectricTestRunner
2222
import org.robolectric.annotation.Config
23-
import mozilla.appservices.init_rust_components.initialize as InitializeRustComponents
2423
import org.mozilla.appservices.logins.GleanMetrics.LoginsStore as LoginsStoreMetrics
2524

2625
@RunWith(RobolectricTestRunner::class)
@@ -34,8 +33,8 @@ class DatabaseLoginsStorageTest {
3433
val gleanRule = GleanTestRule(ApplicationProvider.getApplicationContext())
3534

3635
fun createTestStore(): DatabaseLoginsStorage {
37-
InitializeRustComponents()
38-
Megazord.init()
36+
RustComponentsInitializer.init()
37+
3938
val dbPath = dbFolder.newFile()
4039
val encryptionKey = createKey()
4140
val keyManager = createStaticKeyManager(key = encryptionKey)

components/places/android/src/test/java/mozilla/appservices/places/PlacesConnectionTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package mozilla.appservices.places
55

66
import androidx.test.core.app.ApplicationProvider
77
import kotlinx.coroutines.runBlocking
8-
import mozilla.appservices.Megazord
98
import mozilla.appservices.places.uniffi.BookmarkItem
109
import mozilla.appservices.places.uniffi.DocumentType
1110
import mozilla.appservices.places.uniffi.FrecencyThresholdOption
@@ -46,7 +45,6 @@ class PlacesConnectionTest {
4645

4746
@Before
4847
fun initAPI() {
49-
Megazord.init()
5048
api = PlacesApi(path = dbFolder.newFile().absolutePath)
5149
db = api.getWriter()
5250
}

components/tabs/android/src/test/java/mozilla/appservices/remotetabs/RemoteTabsTest.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package mozilla.appservices.remotetabs
22

3-
import mozilla.appservices.Megazord
43
import mozilla.appservices.syncmanager.SyncManager
54
import org.junit.Assert
6-
import org.junit.Before
75
import org.junit.Rule
86
import org.junit.Test
97
import org.junit.rules.TemporaryFolder
@@ -18,11 +16,6 @@ class RemoteTabsTest {
1816
@JvmField
1917
val dbFolder = TemporaryFolder()
2018

21-
@Before
22-
fun init() {
23-
Megazord.init()
24-
}
25-
2619
protected fun getTestStore(): TabsStore {
2720
return TabsStore(path = dbFolder.newFile().absolutePath)
2821
}

components/webext-storage/android/src/test/java/mozilla/appservices/webextstorage/WebExtStorageTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
package mozilla.appservices.webextstorage
55

6-
import mozilla.appservices.Megazord
76
import org.junit.Assert
87
import org.junit.Rule
98
import org.junit.Test
@@ -20,7 +19,6 @@ class WebExtStorageTest {
2019
val dbFolder = TemporaryFolder()
2120

2221
fun createTestStore(): WebExtStorageStore {
23-
Megazord.init()
2422
val dbPath = dbFolder.newFile()
2523
return WebExtStorageStore(path = dbPath.absolutePath)
2624
}

megazords/full/android/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ android {
1515
targetSdkVersion config.targetSdkVersion
1616

1717
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
18-
buildConfigField("String", "LIBRARY_VERSION", "\"${config.componentsVersion}\"")
1918
}
2019

2120
buildTypes {

megazords/full/android/src/main/java/mozilla/appservices/Megazord.kt

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)