Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5ae4433e authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

Setup build CI for cromite

parent a5899a9e
Loading
Loading
Loading
Loading

.gitignore

0 → 100644
+7 −0
Original line number Diff line number Diff line
/temp
src/
apks/
_gclient_src*/
.ccache/
.gclient*
depot_tools/

.gitlab-ci.yml

0 → 100644
+43 −0
Original line number Diff line number Diff line
stages:
  - prepare
  - build

variables:
  CONTAINER_IMAGE: registry.gitlab.e.foundation:5000/$CI_PROJECT_PATH
  GIT_SUBMODULE_STRATEGY: recursive

build-docker:
  image: docker:19-git
  stage: prepare
  tags:
    - generic_privileged
  variables:
    DOCKER_DRIVER: overlay2
  services:
    - docker:19-dind
  script:
    - echo "$CI_JOB_TOKEN" | docker login registry.gitlab.e.foundation:5000 -u gitlab-ci-token --password-stdin
    - docker pull $CONTAINER_IMAGE:latest || true
    - docker build --cache-from $CONTAINER_IMAGE:latest --tag $CONTAINER_IMAGE:latest ${CI_PROJECT_DIR}
    - docker push $CONTAINER_IMAGE:latest

.build-cromite:
  image: $CONTAINER_IMAGE
  tags:
    - build-browser
  artifacts:
    name: "$CI_JOB_NAME"
    paths:
      - apks/*

build-cromite-arm64:
  stage: build
  extends: .build-cromite
  script:
    - $CI_PROJECT_DIR/build.sh -c -s -a arm64

build-cromite-x64:
  stage: build
  extends: .build-cromite
  script:
    - $CI_PROJECT_DIR/build.sh -c -s -a x64

.gitmodules

0 → 100644
+3 −0
Original line number Diff line number Diff line
[submodule "cromite"]
	path = cromite
	url = https://github.com/uazo/cromite.git

Dockerfile

0 → 100644
+49 −0
Original line number Diff line number Diff line
FROM ubuntu:18.04

ENV CHROMIUM_DIR "/srv/chromium"
ENV DEBIAN_FRONTEND noninteractive

# Enable foreign architectures support
RUN dpkg --print-architecture && \
	dpkg --print-foreign-architectures

RUN dpkg --add-architecture i386 && \
	dpkg --print-foreign-architectures

# Install required packages
COPY packages.txt /packages.txt

RUN apt-get -qq update && \
    cat /packages.txt | xargs apt-get install -qqy

RUN rm /packages.txt

# Install and setup python 3.10 as default
RUN add-apt-repository -y ppa:deadsnakes/ppa

RUN apt-get -qq update && \
    apt-get install -qqy --no-install-recommends \
    python3.8 lib32z1 lighttpd xvfb libncurses5:i386 libstdc++6:i386 zlib1g:i386 ccache

RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
RUN update-alternatives  --set python3 /usr/bin/python3.8

# Install chromium build dependencies
RUN curl -s https://raw.githubusercontent.com/chromium/chromium/main/build/install-build-deps.py \
    | python3 - --no-syms --lib32 --no-arm --no-chromeos-fonts --no-nacl --no-prompt

RUN apt-get -f install

# Setup locale
RUN localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.UTF-8

RUN git config --global user.name "John Doe"
RUN git config --global user.email "johndoe@example.com"

RUN mkdir ${CHROMIUM_DIR}

WORKDIR ${CHROMIUM_DIR}

ENTRYPOINT /bin/bash

build.sh

0 → 100755
+191 −0
Original line number Diff line number Diff line
#!/bin/bash

set -e

chromium_dir="${chromium_dir:-/srv/chromium}"
root_dir=$(dirname "$(readlink -f "$0")")
if [ ! -d "$chromium_dir" ]; then
    chromium_dir=$root_dir
fi
chromium_version=$(head -n 1 "${root_dir}/cromite/build/RELEASE")
chromium_code=$(echo "$chromium_version" | tr -d '.' | cut -c5-)
clean=0
gsync=0
history=1
arch=""

usage() {
    echo "Usage:"
    echo "  $(basename $(readlink -nf $0)) [ options ]"
    echo
    echo "  Options:"
    echo "    -a <arch> Build specified arch"
    echo "    -c Clean"
    echo "    -h Show this message"
    echo "    -s Sync without history"
    echo
    exit 1
}

build() {
    echo ">> [$(date)] Head commit: $(git show -s --format=%s)"
    apks="ChromePublic"
    build_args="$(cat "${root_dir}"/cromite/build/bromite.gn_args) target_cpu=\"${1}\" "
    add_args=(
        "generate_linker_map=true"
        "use_relative_vtables_abi=false"
        "cc_wrapper=\"ccache\""
    )

    # Add to build_args
    for var in "${add_args[@]}"; do
        build_args+=" $var"
    done

    code=$chromium_code
    if [ $1 '==' "arm" ]; then
        code+=00
    elif [ $1 '==' "arm64" ]; then
        code+=50
    elif [ $1 '==' "x86" ]; then
        code+=10
    elif [ $1 '==' "x64" ]; then
        code+=60
    fi
    build_args+=' android_default_version_name="'$chromium_version'"'
    build_args+=' android_default_version_code="'$code'"'

    if [ $clean -eq 1 ] && [ -d "out/$1" ]; then
        rm -rf "out/$1"
    fi

    echo ">> [$(date)] Building chromium $chromium_version for $1"
    gn gen "out/$1" --args="$build_args"
    ninja -C out/$1 chrome_public_apk

    for apk in $apks; do
        if [ -f "out/${1}/apks/$apk.apk" ]; then
            echo ">> [$(date)] Moving $apk for ${1} to output folder"
            if [[ "$apk.apk" == ChromePublic.apk ]]; then
                if [ "$1" = "x64" ]; then
                    mv "out/${1}/apks/ChromePublic.apk" "${root_dir}/apks/x86_64/ChromePublic.apk"
                else
                    mv "out/${1}/apks/ChromePublic.apk" "${root_dir}/apks/${1}/ChromePublic.apk"
                fi
            fi
        fi
    done
}

setup_ccache() {
    echo ">> [$(date)] Settings up ccache"
    export USE_CCACHE=1
    export CCACHE_EXEC=$(command -v ccache)
    export PATH=$chromium_dir/src/third_party/llvm-build/Release+Asserts/bin:$PATH
    export CCACHE_CPP2=yes
    export CCACHE_SLOPPINESS=time_macros
    export CCACHE_DIR=$chromium_dir/.ccache
    ccache -M 200G
}

patch() {
    cd $chromium_dir/src
    echo ">> [$(date)] Applying bromite patches"

    patches_list=$(cat "${root_dir}/cromite/build/bromite_patches_list.txt")
    for file in $patches_list; do
        git am -3 --ignore-whitespace "${root_dir}/cromite/build/patches/$file"
    done
}

sync() {
    echo ">> [$(date)] Syncing chromium $chromium_version"
    cd $chromium_dir
    if [ $history -eq 1 ]; then
        yes | gclient sync -D -R -r $chromium_version
    else
        yes | gclient sync --no-history -D -R -r $chromium_version
    fi
    patch
}

init_repo(){
    echo ">> [$(date)] Init chromium $chromium_version"
    cd $chromium_dir
    rm -rf .gclient*
    if [ $history -eq 1 ]; then
        fetch android
    else
        fetch --no-history android
    fi
}

while getopts ":a:chr:s" opt; do
    case $opt in
    a) arch="$OPTARG" ;;
    c) clean=1 ;;
    h) usage ;;
    s) gsync=1 && history=0 ;;
    :)
        echo "Option -$OPTARG requires an argument"
        echo
        usage
        ;;
    \?)
        echo "Invalid option:-$OPTARG"
        echo
        usage
        ;;
    esac
done
shift $((OPTIND - 1))

# Add depot_tools to PATH
if [ ! -d "$chromium_dir/depot_tools" ]; then
    git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git "$chromium_dir/depot_tools"
fi
export PATH="$chromium_dir/depot_tools:$PATH"

if [ $clean -eq 1 ]; then
    echo ">> [$(date)] Cleaning chromium source code"
    if [ -d "$chromium_dir/src" ]; then
        cd $chromium_dir/src
        git reset --hard && git clean -xfdf
    fi
fi

if [ ! -d "$chromium_dir/src" ]; then
    init_repo
    sync
fi

if [ $gsync -eq 1 ]; then
    if [ -d "$chromium_dir/src/.git/rebase-apply" ]; then
        rm -fr "$chromium_dir/src/.git/rebase-apply"
    fi
    find "$chromium_dir/src/.git" -name "*.lock" -delete
    if [ ! -z $(find $chromium_dir/src/.git -name "*.lock") ]; then
        rm -fr $chromium_dir/src
        init_repo
    fi
    sync
fi

mkdir -p "${root_dir}/apks/x86_64" "${root_dir}/apks/arm64" "${root_dir}/apks/x86" "${root_dir}/apks/arm"

cd $chromium_dir/src
. build/android/envsetup.sh
setup_ccache

if [ ! -z "$arch" ]; then
    build $arch
else
    build arm
    build arm64
    build x86
    build x64
fi

if [ -d "${root_dir}/apks" ]; then
    find "${root_dir}/apks" -empty -type d -delete
fi
Loading