-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.sh
More file actions
153 lines (133 loc) · 6.54 KB
/
Copy pathbuild.sh
File metadata and controls
153 lines (133 loc) · 6.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
set -e
# Enable debug output
#set -x
# Color output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}R36S Android Build Environment${NC}"
echo -e "${GREEN}========================================${NC}"
# Set default values
REPO_SYNC_JOBS="${REPO_SYNC_JOBS:-4}"
BUILD_JOBS="${BUILD_JOBS:-$(nproc)}"
BUILD_TARGET="${BUILD_TARGET:-lineage_r36s-userdebug}"
LOCAL_MANIFESTS_BRANCH="${LOCAL_MANIFESTS_BRANCH:-main}"
WORKDIR="/build"
echo -e "${BLUE}Config: repo_jobs=${REPO_SYNC_JOBS}, build_jobs=${BUILD_JOBS}, target=${BUILD_TARGET}, branch=${LOCAL_MANIFESTS_BRANCH}${NC}"
cd "$WORKDIR"
# Check if .repo directory exists and is initialized
echo -e "${BLUE}[DEBUG] Checking for .repo/manifests directory...${NC}"
if [ ! -d ".repo/manifests" ]; then
echo -e "${YELLOW}Initializing repo...${NC}"
echo -e "${BLUE}[DEBUG] Running: repo init -u https://github.com/andr36oid/android.git -b lineage-18.1 --git-lfs${NC}"
repo init -u https://github.com/andr36oid/android.git -b lineage-18.1 --git-lfs
echo -e "${BLUE}[DEBUG] Repo init completed${NC}"
else
echo -e "${GREEN}Repo already initialized, skipping...${NC}"
fi
# Always ensure local manifests are present and valid
echo -e "${BLUE}[DEBUG] Checking for .repo/local_manifests directory...${NC}"
if [ ! -d ".repo/local_manifests" ]; then
echo -e "${YELLOW}Cloning local manifests (branch: ${LOCAL_MANIFESTS_BRANCH})...${NC}"
echo -e "${BLUE}[DEBUG] Running: git clone -b ${LOCAL_MANIFESTS_BRANCH} https://github.com/andr36oid/local_manifests .repo/local_manifests${NC}"
git clone -b "${LOCAL_MANIFESTS_BRANCH}" https://github.com/andr36oid/local_manifests .repo/local_manifests
echo -e "${BLUE}[DEBUG] Local manifests cloned${NC}"
else
echo -e "${GREEN}Local manifests directory exists, checking contents...${NC}"
echo -e "${BLUE}[DEBUG] Contents of .repo/local_manifests:${NC}"
ls -la .repo/local_manifests/
# Check if directory is empty or has no XML files
if [ ! -f ".repo/local_manifests/local_manifests.xml" ]; then
echo -e "${YELLOW}Local manifests directory is empty or invalid, re-cloning...${NC}"
echo -e "${BLUE}[DEBUG] Removing broken local_manifests directory${NC}"
rm -rf .repo/local_manifests
echo -e "${BLUE}[DEBUG] Running: git clone -b ${LOCAL_MANIFESTS_BRANCH} https://github.com/andr36oid/local_manifests .repo/local_manifests${NC}"
git clone -b "${LOCAL_MANIFESTS_BRANCH}" https://github.com/andr36oid/local_manifests .repo/local_manifests
echo -e "${GREEN}Local manifests re-cloned successfully${NC}"
ls -la .repo/local_manifests/
else
# Check if we're on the correct branch, and switch if needed
cd .repo/local_manifests
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo -e "${BLUE}[DEBUG] Current branch: ${CURRENT_BRANCH}, Target branch: ${LOCAL_MANIFESTS_BRANCH}${NC}"
if [ "${CURRENT_BRANCH}" != "${LOCAL_MANIFESTS_BRANCH}" ]; then
echo -e "${YELLOW}Switching local manifests to branch: ${LOCAL_MANIFESTS_BRANCH}${NC}"
git fetch origin
git checkout "${LOCAL_MANIFESTS_BRANCH}"
git pull origin "${LOCAL_MANIFESTS_BRANCH}"
echo -e "${GREEN}Switched to branch ${LOCAL_MANIFESTS_BRANCH}${NC}"
else
echo -e "${GREEN}Local manifests already on correct branch, updating...${NC}"
git pull origin "${LOCAL_MANIFESTS_BRANCH}"
fi
cd "$WORKDIR"
echo -e "${GREEN}Local manifests are valid${NC}"
fi
fi
# Upgrade repo to latest version
echo -e "${BLUE}[DEBUG] Checking for repo upgrade...${NC}"
if [ -f ".repo/repo/repo" ]; then
echo -e "${YELLOW}Upgrading repo to latest version...${NC}"
cp .repo/repo/repo /usr/bin/repo
echo -e "${GREEN}Repo upgraded successfully${NC}"
/usr/bin/repo version
fi
# Sync sources
echo -e "${YELLOW}Syncing repository (this may take a while on first run)...${NC}"
repo sync -j"${REPO_SYNC_JOBS}"
echo -e "${GREEN}Repository sync completed${NC}"
# Set up build environment
echo -e "${YELLOW}Setting up build environment...${NC}"
echo -e "${BLUE}[DEBUG] Sourcing build/envsetup.sh at $(date)${NC}"
source build/envsetup.sh
echo -e "${BLUE}[DEBUG] Build environment loaded${NC}"
# Check device tree exists
echo -e "${BLUE}[DEBUG] Checking if device tree exists...${NC}"
if [ -d "device/gameconsole/r36s" ]; then
echo -e "${GREEN}Device tree found at device/gameconsole/r36s${NC}"
ls -la device/gameconsole/r36s/
else
echo -e "${RED}ERROR: Device tree not found!${NC}"
exit 1
fi
# Select build target
echo -e "${YELLOW}Selecting build target: ${BUILD_TARGET}${NC}"
echo -e "${BLUE}[DEBUG] Running: lunch ${BUILD_TARGET}${NC}"
lunch "${BUILD_TARGET}"
echo -e "${BLUE}[DEBUG] Lunch completed successfully${NC}"
# Build boot and system images
echo -e "${YELLOW}Building bootimage and systemimage...${NC}"
echo -e "${BLUE}[DEBUG] Starting build at $(date)${NC}"
echo -e "${BLUE}[DEBUG] This will take a long time (1-3 hours)...${NC}"
echo -e "${BLUE}[DEBUG] Using ${BUILD_JOBS} parallel jobs${NC}"
mka -j${BUILD_JOBS} bootimage systemimage
echo -e "${BLUE}[DEBUG] Build completed at $(date)${NC}"
# Create final image
echo -e "${YELLOW}Creating final image...${NC}"
echo -e "${BLUE}[DEBUG] Changing to device/gameconsole/r36s${NC}"
cd device/gameconsole/r36s
echo -e "${BLUE}[DEBUG] Current directory: $(pwd)${NC}"
echo -e "${BLUE}[DEBUG] Running mkimg.sh...${NC}"
./mkimg.sh
echo -e "${BLUE}[DEBUG] mkimg.sh completed${NC}"
# Move results to output directory
echo -e "${YELLOW}Moving build artifacts to results directory...${NC}"
echo -e "${BLUE}[DEBUG] Creating results directory${NC}"
mkdir -p "$WORKDIR/results"
echo -e "${BLUE}[DEBUG] Looking for ZIP files in $(pwd)${NC}"
ls -lh *.zip 2>/dev/null || echo -e "${YELLOW}No ZIP files found yet${NC}"
mv *.zip "$WORKDIR/results/" 2>/dev/null && echo -e "${GREEN}ZIP files moved successfully${NC}" || echo -e "${YELLOW}No ZIP files found to move${NC}"
cd "$WORKDIR"
echo -e "${BLUE}[DEBUG] Returned to ${WORKDIR}${NC}"
# List results
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}Build completed successfully!${NC}"
echo -e "${GREEN}========================================${NC}"
echo -e "${BLUE}[DEBUG] Build finished at $(date)${NC}"
echo -e "${GREEN}Output files:${NC}"
ls -lh "$WORKDIR/results/"*.zip 2>/dev/null || echo -e "${RED}No ZIP files found in results directory${NC}"
echo -e "${GREEN}Build artifacts are available in the 'results' directory${NC}"