Skip to content

Commit

Permalink
Support building from aosp-main
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme committed Jun 14, 2024
1 parent 9b3d137 commit d3abc4d
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 33 deletions.
45 changes: 24 additions & 21 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,42 @@ jobs:
fail-fast: false
matrix:
include:
- type: aosp_aarch64
- arch: aarch64
target: aosp_arm64
link: https://dl.google.com/developers/android/udc/images/gsi/aosp_arm64-exp-UP1A.231005.007-10754064-68dd726a.zip
- type: aosp_x86_64
- arch: x86_64
target: aosp_x86_64
link: https://dl.google.com/developers/android/udc/images/gsi/aosp_x86_64-exp-UP1A.231005.007-10754064-84570261.zip

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download GSI
- name: Download Image
run: |
curl -fsSLo ${{ matrix.type }}.zip ${{ matrix.link }}
curl -fsSLo ${{ matrix.target }}.zip ${{ matrix.link }}
- name: Mount GSI
- name: Mount system.img
run: |
unzip ${{ matrix.type }}.zip
mkdir sysroot
sudo mount -o loop,ro system.img sysroot
mkdir SYSTEM
unzip ${{ matrix.target }}.zip
sudo mount -o loop,ro system.img SYSTEM
- name: List GSI Contents
- name: List Contents
run: |
cd sysroot
sudo find . -print0 | xargs -0 sudo ls -dl
cd SYSTEM
sudo find . -ls
- name: Archive
run: |
cd sysroot
sudo ../libexec/ls-files | sudo tar -cvzf ../${{ matrix.type }}.tar.gz -T-
cd SYSTEM
sudo ../libexec/ls-files | sudo tar -cvzf ../${{ matrix.arch }}.tar.gz --no-recursion -T-
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.type }}
path: ${{ matrix.type }}.tar.gz
name: build-${{ matrix.arch }}
path: ${{ matrix.arch }}.tar.gz
if-no-files-found: error
compression-level: 0

Expand All @@ -73,13 +75,12 @@ jobs:

- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: aosp_aarch64

- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: aosp_x86_64
- name: Prepare
id: prepare
run: |
mkdir build
mv build-*/* build
- name: Docker Metadata
id: docker-metadata
Expand All @@ -96,6 +97,8 @@ jobs:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:master # need qemu >=8.2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand Down
176 changes: 176 additions & 0 deletions .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
name: schedule

on:
push:
branches:
- '**'
tags-ignore:
- '**'
pull_request:
branches:
- '**'
schedule:
- cron: '0 0 * * 0'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
archive:
runs-on: ubuntu-24.04

strategy:
fail-fast: false
matrix:
include:
- arch: aarch64
target: aosp_arm64
- arch: x86_64
target: aosp_x86_64
- arch: riscv64
target: aosp_cf_riscv64_phone

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install dependencies
if: contains(matrix.target, '_cf_')
run: |
sudo apt-get update
sudo apt-get install -y linux-modules-extra-$(uname -r) erofs-utils erofsfuse
sudo modprobe erofs
- name: Install cuttlefish
if: contains(matrix.target, '_cf_')
run: |
ID=$(curl -fsSL https://ci.android.com/builds/branches/aosp-main/status.json | yq '.targets[] | select(.name == "aosp_cf_x86_64_phone-trunk_staging-userdebug") | .last_known_good_build')
ARTIFACT_URL=$(node <<EOF
$(curl -fsSL "https://ci.android.com/builds/submitted/$ID/aosp_cf_x86_64_phone-trunk_staging-userdebug/latest/cvd-host_package.tar.gz" | grep 'var JSVariables = ')
console.log(JSVariables['artifactUrl'])
EOF
)
curl -fsSLo cvd-host_package.tar.gz "$ARTIFACT_URL"
sudo mkdir /opt/android-cuttlefish
sudo tar -xzC /opt/android-cuttlefish -f cvd-host_package.tar.gz
echo /opt/android-cuttlefish/bin | tee -a "$GITHUB_PATH"
- name: Download Image
run: |
ID=$(curl -fsSL https://ci.android.com/builds/branches/aosp-main/status.json | yq '.targets[] | select(.name == "${{ matrix.target }}-trunk_staging-userdebug") | .last_known_good_build')
ARTIFACT_URL=$(node <<EOF
$(curl -fsSL "https://ci.android.com/builds/submitted/$ID/${{ matrix.target }}-trunk_staging-userdebug/latest/${{ matrix.target }}-img-$ID.zip" | grep 'var JSVariables = ')
console.log(JSVariables['artifactUrl'])
EOF
)
curl -fsSLo ${{ matrix.target }}.zip "$ARTIFACT_URL"
- name: Mount system.img
run: |
mkdir SYSTEM
unzip ${{ matrix.target }}.zip
if test -f super.img; then
simg2img super.img unsparsed.img
lpunpack unsparsed.img
if [ "$(blkid -o value -s TYPE system_a.img)" = "erofs" ]; then
sudo erofsfuse -o allow_other system_a.img SYSTEM
else
sudo mount -o loop,ro system_a.img SYSTEM
fi
else
sudo mount -o loop,ro system.img SYSTEM
fi
- name: Mount com.android.runtime.apex
run: |
SYSTEM_EXT=SYSTEM/system_ext
if test -L $SYSTEM_EXT; then
SYSTEM_EXT=SYSTEM/system/system_ext
fi
if ! test -d $SYSTEM_EXT/apex/com.android.runtime; then
mkdir com.android.runtime
unzip -d com.android.runtime SYSTEM/system/apex/com.android.runtime.apex
sudo mount -t tmpfs tmpfs $SYSTEM_EXT
mkdir -p $SYSTEM_EXT/apex/com.android.runtime
sudo mount -o loop,ro com.android.runtime/apex_payload.img $SYSTEM_EXT/apex/com.android.runtime
fi
- name: List Contents
run: |
cd SYSTEM
sudo find . -ls
- name: Archive
run: |
cd SYSTEM
sudo ../libexec/ls-files | sudo tar -cvzf ../${{ matrix.arch }}.tar.gz --no-recursion -T-
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: build-${{ matrix.arch }}
path: ${{ matrix.arch }}.tar.gz
if-no-files-found: error
compression-level: 0

build:
needs: [archive]

runs-on: ubuntu-latest

permissions:
packages: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download Artifact
uses: actions/download-artifact@v4

- name: Prepare
id: prepare
run: |
mkdir build
mv build-*/* build
- name: Docker Metadata
id: docker-metadata
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository }}
tags: |
type=edge
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=schedule
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:master # need qemu >=8.2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64 # ,linux/riscv64
push: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
tags: ${{ steps.docker-metadata.outputs.tags }}
labels: ${{ steps.docker-metadata.outputs.labels }}
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
FROM docker.io/library/alpine AS builder

COPY aosp_aarch64.tar.gz /build/aosp_aarch64.tar.gz
COPY aosp_x86_64.tar.gz /build/aosp_x86_64.tar.gz
COPY build/ /build/

RUN mkdir /sysroot \
&& tar -xf /build/aosp_$(uname -m).tar.gz -C /sysroot \
&& ln -s /system/system_ext/apex/com.android.runtime /sysroot/apex/com.android.runtime \
&& tar -xf /build/$(uname -m).tar.gz -C /sysroot \
&& ln -s /system_ext/apex/com.android.runtime /sysroot/apex/com.android.runtime \
&& touch /sysroot/linkerconfig/ld.config.txt

FROM scratch AS toybox
Expand Down
19 changes: 11 additions & 8 deletions libexec/ls-files
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ find apex
find bin
find data
find etc
find system_ext
find linkerconfig
find system_ext
find system/system_ext

find system/system_ext/apex/com.android.runtime
find system/system_ext/apex/com.android.runtime/bin -type f | xargs -n 1 -- basename | xargs -n 1 -- find system/bin -mindepth 1 -maxdepth 1 -name
find system/system_ext/apex/com.android.runtime/etc -type f | xargs -n 1 -- basename | xargs -n 1 -- find system/etc -mindepth 1 -maxdepth 1 -name
for LIB in lib64 lib; do
find system/system_ext/apex/com.android.runtime/${LIB} \( -type f -o -type l \) | xargs -n 1 -- basename | xargs -n 1 -- find system/${LIB} -mindepth 1 -maxdepth 1 -name
for SYSTEM_EXT in system_ext system/system_ext; do
find ${SYSTEM_EXT}/apex/com.android.runtime -not -name lost+found
find ${SYSTEM_EXT}/apex/com.android.runtime/bin -type f | xargs -r -n 1 -- basename | xargs -r -n 1 -- find system/bin -mindepth 1 -maxdepth 1 -name
find ${SYSTEM_EXT}/apex/com.android.runtime/etc -type f | xargs -r -n 1 -- basename | xargs -r -n 1 -- find system/etc -mindepth 1 -maxdepth 1 -name
for LIB in lib64 lib; do
find ${SYSTEM_EXT}/apex/com.android.runtime/${LIB} \( -type f -o -type l \) | xargs -r -n 1 -- basename | xargs -r -n 1 -- find system/${LIB} -mindepth 1 -maxdepth 1 -name
done
done

xargs -n 1 -- find system/bin -mindepth 1 -maxdepth 1 -name <<'EOF'
xargs -r -n 1 -- find system/bin -mindepth 1 -maxdepth 1 -name <<'EOF'
awk
bc
bunzip2
Expand All @@ -27,7 +30,7 @@ sh
toybox
EOF
for LIB in lib64 lib; do
xargs -n 1 -- find system/${LIB} -mindepth 1 -maxdepth 1 -name <<'EOF'
xargs -r -n 1 -- find system/${LIB} -mindepth 1 -maxdepth 1 -name <<'EOF'
libbase.so
libcgrouprc.so
libcrypto.so
Expand Down

0 comments on commit d3abc4d

Please sign in to comment.