1+ #! /bin/bash
2+ #
3+ # This script is used to "import" the application-services into mozilla-central/firefox-main and arrange
4+ # for a successful build.
5+ #
6+ # This script must be run with the current directory being a clean m-c/m-f/f-m/fml/ where you want patches applied.
7+ #
8+ # WARNING: This messes with git in the current directory.
9+ # It DOES NOT check it is being run in a clean environment or on the correct branch.
10+
11+ # While this script lives in app-services for convenience, it uses git to fetch app-services.
12+ # This script can be anywhere but it must be run with the correct cwd - see above.
13+ #
14+ # If this is successful, it will have created a number of git commits and should be able to build and run Fenix.
15+ set -ex
16+
17+ if [[ ! -d " $( pwd) /toolkit/components" ]]; then
18+ echo " ERROR: This script must be run from the root of mozilla-central/mozilla-firefox/firefox-main/whatever-we-are-calling-it"
19+ exit 1
20+ fi
21+
22+ # If this happens to be a jj repo things get strange
23+ export MOZ_AVOID_JJ_VCS=1
24+
25+ # existing patches against m-c
26+ # gradle
27+ moz-phab patch --apply-to=here --no-branch D245762
28+ # lint
29+ moz-phab patch --apply-to=here --no-branch D246875
30+
31+ # the import of app-services via a branch markh is maintaining while we work towards `main`
32+ git clone https://github.com/mozilla/application-services tmp-app-services
33+ cd tmp-app-services
34+ git co monorepo
35+
36+ # xxx - this show-ref confused me - why doesn't `HEAD` work in place of refs/heads/monorepo??
37+ commit=$( git show-ref refs/heads/monorepo | awk ' {print $1}' )
38+
39+ rm -rf .git .github
40+ rm CHANGELOG.md CODE_OF_CONDUCT.md LICENSE README.md COPYRIGHT version.txt
41+ rm Cargo.lock Cargo.toml clippy.toml
42+ rm gradlew gradlew.bat build.gradle gradle.properties
43+ rm -rf gradle
44+ rm proguard-rules-consumer-jna.pro
45+ rm install-nimbus-cli.sh
46+ rm rust-toolchain.toml
47+ rm -rf components/external
48+ rm -rf docs/shared
49+ # need a story for these generated deps - bug 1963617
50+ rm DEPENDENCIES.md megazords/full/android/dependency-licenses.xml megazords/full/DEPENDENCIES.md megazords/ios-rust/DEPENDENCIES.md megazords/ios-rust/focus/DEPENDENCIES.md
51+ # No Taskcluster for now, testing etc should come for free (or need tweaks to add the new components etc?)
52+ rm -rf taskcluster/app_services_taskgraph taskcluster
53+
54+ cd ..
55+
56+ mkdir -p services/app-services
57+ cp -r tmp-app-services/* services/app-services
58+ cp -r tmp-app-services/.buildconfig-android.yml services/app-services
59+
60+ rm -rf tmp-app-services
61+
62+ git add services/app-services
63+ git commit -m " Import application-services commit $commit "
64+
65+ # We've committed an app-services unmodified apart from removal of things we don't need.
66+ # Update Cargo.toml and re-vendor.
67+ sed -i ' ' \
68+ -e ' s|context_id = { git = .*$|context_id = { path = "services/app-services/components/context_id" }|' \
69+ -e ' s|filter_adult = { git = .*$|filter_adult = { path = "services/app-services/components/filter_adult" }|' \
70+ -e ' s|interrupt-support = { git = .*$|interrupt-support = { path = "services/app-services/components/support/interrupt" }|' \
71+ -e ' s|relevancy = { git = .*$|relevancy = { path = "services/app-services/components/relevancy" }|' \
72+ -e ' s|search = { git = .*$|search = { path = "services/app-services/components/search" }|' \
73+ -e ' s|sql-support = { git = .*$|sql-support = { path = "services/app-services/components/support/sql" }|' \
74+ -e ' s|suggest = { git = .*$|suggest = { path = "services/app-services/components/suggest" }|' \
75+ -e ' s|sync15 = { git = .*$|sync15 = { path = "services/app-services/components/sync15" }|' \
76+ -e ' s|tabs = { git = .*$|tabs = { path = "services/app-services/components/tabs" }|' \
77+ -e ' s|viaduct = { git = .*$|viaduct = { path = "services/app-services/components/viaduct" }|' \
78+ -e ' s|webext-storage = { git = .*$|webext-storage = { path = "services/app-services/components/webext-storage" }|' \
79+ Cargo.toml
80+
81+ ./mach vendor rust
82+ # This will create a commit with Cargo.lock changing just for these crates, and many `third_party/rust` directories removed.
83+ git commit -a -m " Re-vendor application-services from its new in-tree home"
84+
85+ # apply the final "patch" in the stack, which we do by abusing sed.
86+ # This is mildly (hah!) fragile.
87+
88+ # [dependencies] is conveniently at the end of these toml files
89+ printf ' mozilla-central-workspace-hack = { version = "0.1", features = ["megazord"], optional = true }\n' >> services/app-services/megazords/full/Cargo.toml
90+ printf ' mozilla-central-workspace-hack = { version = "0.1", features = ["embedded-uniffi-bindgen"], optional = true }\n' >> services/app-services/tools/embedded-uniffi-bindgen/Cargo.toml
91+ # We need to update the crate-type for the megazord
92+ sed -i ' ' -e ' s|crate-type = \["cdylib"\]|crate-type = \["staticlib"\]|' services/app-services/megazords/full/Cargo.toml
93+ # [features] is conveniently at the end of this toml
94+ printf ' megazord = []\nembedded-uniffi-bindgen = []\n' >> build/workspace-hack/Cargo.toml
95+ # and more hacks - sue me ;) In the short term these are more fragile in theory than practice.
96+
97+ # Add the 2 crates to the workspace which have binary targets
98+ sed -i ' ' \
99+ -e ' s| "security/mls/mls_gk",| "security/mls/mls_gk",\
100+ "services/app-services/megazords/full",\
101+ "services/app-services/tools/embedded-uniffi-bindgen",|' \
102+ Cargo.toml
103+
104+ # exclude all the app-services crates.
105+ sed -i ' ' \
106+ -e ' s| "intl/l10n/rust/l10nregistry-tests",| "intl/l10n/rust/l10nregistry-tests",\
107+ \
108+ # app-services excluded members, also to avoid dev dependencies.\
109+ "services/app-services/components/autofill",\
110+ "services/app-services/components/fxa-client",\
111+ "services/app-services/components/logins",\
112+ "services/app-services/components/nimbus",\
113+ "services/app-services/components/places",\
114+ "services/app-services/components/push",\
115+ "services/app-services/components/relevancy",\
116+ "services/app-services/components/remote_settings",\
117+ "services/app-services/components/search",\
118+ "services/app-services/components/suggest",\
119+ "services/app-services/components/support/guid",\
120+ "services/app-services/components/support/sql",\
121+ "services/app-services/components/sync15",\
122+ "services/app-services/components/tabs",\
123+ # app-services excluded members, for other reasons.\
124+ "services/app-services/megazords/ios-rust",|' \
125+ Cargo.toml
126+
127+ # Cargo.lock
128+ cargo update -p gkrust-shared
129+ git commit -a -m " Integrate app-services into the build system"
130+
131+ # XXX - Final vendor due to tracing-subscriber, hack for now
132+ ./mach vendor rust --force --ignore-modified
133+ git commit -a -m " TODO - fix tracing"
134+
135+ echo " Done!"
0 commit comments