Skip to content

Commit 01f0031

Browse files
committed
add developer scripts
1 parent 66160c0 commit 01f0031

File tree

7 files changed

+225
-0
lines changed

7 files changed

+225
-0
lines changed

common.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@ readonly branch=15-qpr2
22
readonly aosp_tag_old=android-15.0.0_r36
33
readonly aosp_tag=android-15.0.0_r36
44

5+
# The reference (branch/tag) containing the Graphene code of interest. Typically this will be the same as branch, but
6+
# might not be when handling a device released on old code. For tags, just specifying the tag is fine. For branches,
7+
# specifying the remote is needed (e.g. remotes/grapheneos/15-qpr2).
8+
readonly graphene_ref=remotes/grapheneos/15-qpr2
9+
readonly developer_port_branch=port-to-15-qpr2
10+
511
user_error() {
612
echo $1 >&2
713
exit 1
814
}
915

16+
echo_red() {
17+
echo "$(tput setaf 1)$1$(tput setaf 0)"
18+
}
19+
1020
readonly aosp_forks=(
1121
device_common
1222
device_generic_goldfish

developer-scripts/manage.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
set -o errexit -o nounset -o pipefail
4+
source "$(dirname ${BASH_SOURCE[0]})/../common.sh"
5+
6+
readonly script_dir=$(dirname "$(realpath ${BASH_SOURCE[0]})")
7+
8+
[[ ! $# -eq 1 ]] && user_error "expected 1 argument, add-aosp-remotes|fetch-aosp-tags|fork-all-graphene|rebase-all-graphene|get-all-graphene-paths"
9+
readonly action=$1
10+
11+
if [[ $action == "add-aosp-remotes" ]]; then
12+
repo forall -v -e -p -c "${script_dir}/repo-add-aosp-remotes.sh"
13+
elif [[ $action == "fetch-aosp-tags" ]]; then
14+
repo forall -v -e -p -c "${script_dir}/repo-fetch-aosp-tags.sh"
15+
elif [[ $action == "fork-all-graphene" ]]; then
16+
repo forall -v -e -p -c "${script_dir}/repo-fork-all-graphene.sh"
17+
elif [[ $action == "rebase-all-graphene" ]]; then
18+
repo forall -v -e -p -c "${script_dir}/repo-rebase-all-graphene.sh"
19+
elif [[ $action == "get-all-graphene-paths" ]]; then
20+
repo forall -v -e -c "${script_dir}/repo-get-all-graphene-paths.sh"
21+
else
22+
user_error "unrecognized action, expected add-aosp-remotes|fetch-aosp-tags|fork-all-graphene|rebase-all-graphene|get-all-graphene-paths"
23+
fi
24+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
# TODO: Write better bash.
4+
5+
set -o errexit -o nounset -o pipefail
6+
source "$(dirname ${BASH_SOURCE[0]})/../common.sh"
7+
8+
readonly aosp_repo_base="https://android.googlesource.com/"
9+
10+
add_remote() {
11+
aosp_repo="${1//_/\/}"
12+
aosp_remote="${aosp_repo_base}${aosp_repo}"
13+
14+
git_exit=0
15+
git remote add upstream $aosp_remote &>/dev/null || git_exit=$?
16+
if [[ "${git_exit}" == 3 ]]; then
17+
echo "success, already exists"
18+
elif [[ "${git_exit}" != 0 ]]; then
19+
echo_red "fail"
20+
exit 1
21+
else
22+
echo "success"
23+
fi
24+
}
25+
26+
# We can't just check if $REPO_REMOTE == "grapheneos" because not all of our repos are AOSP forks. `repo` project groups
27+
# would allow us to simplify this so that we could just run `repo forall -g aosp-forks`.
28+
for graphene_repo in "${aosp_forks[@]}"; do
29+
if [[ "${graphene_repo}" == "${REPO_PROJECT}" ]] ; then
30+
add_remote "${graphene_repo}"
31+
exit 0
32+
fi
33+
done
34+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# TODO: Write better bash.
4+
5+
set -o errexit -o nounset -o pipefail
6+
source "$(dirname ${BASH_SOURCE[0]})/../common.sh"
7+
8+
fetch_aosp_tags() {
9+
# If clone-depth="1" is set in manifest then the commit will be grafted. Don't fetch tags. These are typically
10+
# prebuilts where our additions need to be handled manually. Even if they aren't prebuilt, we don' want to rebase
11+
# without full history.
12+
if git log -1 --oneline --decorate | grep grafted
13+
then
14+
echo "success, but skipping as repository has clone-depth set"
15+
exit 0
16+
fi
17+
18+
git_exit=0
19+
if ! git fetch upstream --tags &>/dev/null
20+
then
21+
echo_red "fail"
22+
exit 1
23+
else
24+
echo "success"
25+
fi
26+
}
27+
28+
# We can't just check if $REPO_REMOTE == "grapheneos" because not all of our repos are AOSP forks. `repo` project groups
29+
# would allow us to simplify this so that we could just run `repo forall -g aosp-forks`.
30+
for graphene_repo in "${aosp_forks[@]}"; do
31+
if [[ "${graphene_repo}" == "${REPO_PROJECT}" ]] ; then
32+
fetch_aosp_tags "${graphene_repo}"
33+
exit 0
34+
fi
35+
done
36+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# TODO: Write better bash.
4+
# TODO: `gh repo fork` will silently ignore `--remote-name` if an existing remote exists. We should handle this,
5+
# otherwise it shows up as an error when repo-rebase-all-graphene.sh looks for my-fork remote.
6+
7+
set -o errexit -o nounset -o pipefail
8+
source "$(dirname ${BASH_SOURCE[0]})/../common.sh"
9+
10+
if [[ "${REPO_REMOTE}" == "grapheneos" ]]; then
11+
if [[ -z "${GH_TOKEN:-}" ]]; then
12+
echo_red "fail, expected GH_TOKEN environment variable to be set"
13+
exit 1
14+
fi
15+
16+
# Without this, `repo fork` will complain about GrapheneOS repos that are GitHub forks themselves.
17+
# Example: platform_development.
18+
if ! gh repo set-default GrapheneOS/"${REPO_PROJECT}" &>/dev/null
19+
then
20+
# This will happen if repository doesn't exist in GrapheneOS GitHub. Unlikely to occur unless using an old tag, in
21+
# which case temporarily update this branch to exit 0. The reason `repo sync` still works is because Graphene
22+
# redirects the URL to an archive.
23+
echo_red "fail, probably because the remote repository does not exist"
24+
exit 2
25+
fi
26+
27+
# This will add my-fork remote and exit with 0 even if the fork already exists.
28+
if ! gh repo fork --remote --remote-name my-fork &>/dev/null
29+
then
30+
echo_red "fail"
31+
exit 3
32+
fi
33+
34+
echo "success"
35+
exit 0
36+
fi
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
# TODO: Write better bash.
4+
5+
set -o errexit -o nounset -o pipefail
6+
7+
if [[ "${REPO_REMOTE}" == "grapheneos" || "${REPO_REMOTE}" == "grapheneos-gitlab" ]]; then
8+
echo "\"${REPO_PATH}\","
9+
fi
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
3+
# TODO: Write better bash.
4+
# TODO: Rename this to rebase-all-aosp-forks
5+
6+
set -o errexit -o nounset -o pipefail
7+
source "$(dirname ${BASH_SOURCE[0]})/../common.sh"
8+
9+
rebase() {
10+
# See repo-fetch-aosp-tags.
11+
if git log -1 --oneline --decorate | grep grafted
12+
then
13+
echo "success, but requires manual handling as clone-depth is set"
14+
# Create a file so that repo status alerts on this repository.
15+
touch "temporary-repo-status-marker"
16+
exit 0
17+
fi
18+
19+
# Allows us to run this script multiple times if something went wrong.
20+
git rebase --abort &>/dev/null || true
21+
22+
git checkout -q -B "${developer_port_branch}" "${graphene_ref}"
23+
git_exit=0
24+
git rebase -q --onto $aosp_tag $aosp_tag_old &>/dev/null || git_exit=$?
25+
if [[ "${git_exit}" == 1 ]]; then
26+
echo "success, but requires manual conflict resolution"
27+
return 0
28+
elif [[ "${git_exit}" != 0 ]]; then
29+
# If the rebase never begins due to bad tags then git exits with 128.
30+
echo_red "fail, unexpected error during rebase"
31+
exit 1
32+
fi
33+
34+
if [[ "${REPO_REMOTE}" == "grapheneos" ]]; then
35+
if ! git push -q -f my-fork $developer_port_branch &>/dev/null
36+
then
37+
echo_red "fail, unexpected error during push"
38+
exit 2
39+
fi
40+
echo "success"
41+
else
42+
echo "success, but can't push due to hosted on GitLab"
43+
fi
44+
}
45+
46+
create_developer_port_branch() {
47+
if ! git checkout -q -B "${developer_port_branch}" "${graphene_ref}"
48+
then
49+
# Most likely a repo was introduced during the manifest port and it did not exist for the previous release. A new
50+
# kernel, for example.
51+
echo_red "fail, developer port branch target does not exist"
52+
exit 3
53+
fi
54+
if ! git push -q -f my-fork $developer_port_branch &>/dev/null
55+
then
56+
echo_red "fail, unexpected error during push"
57+
exit 2
58+
fi
59+
echo "success"
60+
}
61+
62+
# We can't just check if $REPO_REMOTE == "grapheneos" because not all of our repos are AOSP forks. `repo` project groups
63+
# would allow us to simplify this so that we could just run `repo forall -g aosp-forks`.
64+
for graphene_repo in "${aosp_forks[@]}"; do
65+
if [[ "${graphene_repo}" == "${REPO_PROJECT}" ]] ; then
66+
rebase "${graphene_repo}"
67+
exit 0
68+
fi
69+
done
70+
71+
# If it's not an aosp_fork but its remote is grapheneos then create a branch such that we can update the grapheneos
72+
# remote in the platform manifest to point to a branch in our own repository.
73+
if [[ "${REPO_REMOTE}" == "grapheneos" ]]; then
74+
create_developer_port_branch
75+
exit 0
76+
fi

0 commit comments

Comments
 (0)