Skip to content

Commit b78b47f

Browse files
committed
add developer scripts
1 parent d1c987c commit b78b47f

File tree

5 files changed

+139
-0
lines changed

5 files changed

+139
-0
lines changed

common.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
readonly branch=15-qpr2
2+
#readonly tag=
3+
readonly developer_port_branch=port-to-16
24
readonly aosp_tag_old=android-15.0.0_r30
35
readonly aosp_tag=android-15.0.0_r30
46

developer-scripts/manage.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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"
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 == "fork-all-graphene" ]]; then
14+
repo forall -v -e -p -c "${script_dir}/repo-fork-all-graphene.sh"
15+
elif [[ $action == "rebase-all-graphene" ]]; then
16+
repo forall -v -e -p -c "${script_dir}/repo-rebase-all-graphene.sh"
17+
else
18+
user_error "unrecognized action, expected add-aosp-remotes|fork-all-graphene|rebase-all-graphene"
19+
fi
20+
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 "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+
# TODO: Handle grapheneos-gitlab remote.
5+
# TODO: `gh repo fork` will silently ignore `--remote-name` if an existing remote exists. We should handle this,
6+
# TODO: otherwise it shows up as an error when repo-rebase-all-graphene.sh looks for my-fork remote.
7+
8+
set -o errexit -o nounset -o pipefail
9+
source "$(dirname ${BASH_SOURCE[0]})/../common.sh"
10+
11+
if [[ "${REPO_REMOTE}" == "grapheneos" ]]; then
12+
if [[ -z "${GH_TOKEN:-}" ]]; then
13+
user_error "expected GH_TOKEN environment variable to be set"
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 "fail, probably because the remote repository does not exist"
24+
exit 1
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 "fail"
31+
exit 1
32+
fi
33+
34+
echo "success"
35+
exit 0
36+
fi
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
# TODO: Write better bash.
4+
# TODO: Handle grapheneos-gitlab remote.
5+
# TODO: Add `repo sync --tags -j8 --force-checkout --force-sync` to this?
6+
7+
set -o errexit -o nounset -o pipefail
8+
source "$(dirname ${BASH_SOURCE[0]})/../common.sh"
9+
10+
rebase() {
11+
git fetch -q --tags --all
12+
13+
# Allows us to run this script multiple times if something went wrong.
14+
git rebase --abort &>/dev/null || true
15+
16+
git checkout -q -B "${developer_port_branch}" "${tag}"
17+
git_exit=0
18+
git rebase -q --onto $aosp_tag $aosp_tag_old &>/dev/null || git_exit=$?
19+
if [[ "${git_exit}" == 1 ]]; then
20+
echo "success, but requires manual conflict resolution"
21+
return 0
22+
elif [[ "${git_exit}" != 0 ]]; then
23+
# If the rebase never begins due to bad tags then git exits with 128.
24+
echo "fail, unexpected error during rebase"
25+
exit 1
26+
fi
27+
28+
if [[ "${REPO_REMOTE}" == "grapheneos" ]]; then
29+
if ! git push -q -f my-fork $developer_port_branch &>/dev/null
30+
then
31+
echo "fail, unexpected error during push"
32+
exit 2
33+
fi
34+
echo "success"
35+
else
36+
echo "success, but can't push due to hosted on GitLab"
37+
fi
38+
}
39+
40+
# We can't just check if $REPO_REMOTE == "grapheneos" because not all of our repos are AOSP forks. `repo` project groups
41+
# would allow us to simplify this so that we could just run `repo forall -g aosp-forks`.
42+
for graphene_repo in "${aosp_forks[@]}"; do
43+
if [[ "${graphene_repo}" == "${REPO_PROJECT}" ]] ; then
44+
rebase "${graphene_repo}"
45+
exit 0
46+
fi
47+
done

0 commit comments

Comments
 (0)