-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_project_02.sh
More file actions
292 lines (240 loc) · 7.84 KB
/
setup_project_02.sh
File metadata and controls
292 lines (240 loc) · 7.84 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/bin/bash
# Check if project name is provided
if [ -z "$1" ]; then
echo "Usage: $0 <project_name>"
exit 1
fi
PROJECT_NAME=$1
# Define RISC-V Docker image/container names
DOCKER_IMAGE_RISCV="${PROJECT_NAME}_riscv"
DOCKER_CONTAINER_RISCV="${PROJECT_NAME}_riscv_container"
# Define ARM Docker image/container names
DOCKER_IMAGE_ARM="${PROJECT_NAME}_arm"
DOCKER_CONTAINER_ARM="${PROJECT_NAME}_arm_container"
# Create and move into the project directory
mkdir -p "$PROJECT_NAME"
cd "$PROJECT_NAME" || { echo "Error: Failed to enter project directory"; exit 1; }
echo "Setting up project: $PROJECT_NAME"
# 1. Clone fresh repository
echo "Cloning repository..."
git clone https://github.com/celine-lee/transpile.git .
if [ $? -ne 0 ]; then
echo "Error: Failed to clone repository"
exit 1
fi
echo "Repository cloned successfully."
# 2. Install pip
echo "Installing pip..."
# Download get-pip.py and check if successful
curl -s https://bootstrap.pypa.io/get-pip.py -o get-pip.py
if [ $? -ne 0 ]; then
echo "Error: Failed to download get-pip.py"
exit 1
fi
# Install pip and check if successful
python3 get-pip.py --user
if [ $? -ne 0 ]; then
echo "Error: Failed to install pip"
exit 1
fi
# Add pip to PATH
export PATH=$HOME/.local/bin:$PATH
if [ $? -ne 0 ]; then
echo "Error: Failed to update PATH"
exit 1
fi
# Upgrade pip
pip install --upgrade pip
if [ $? -ne 0 ]; then
echo "Error: Failed to upgrade pip"
exit 1
fi
# Verify installation
pip --version &>/dev/null
if [ $? -ne 0 ]; then
echo "Error: Pip installation verification failed"
exit 1
fi
python3 --version &>/dev/null
if [ $? -ne 0 ]; then
echo "Error: Python installation verification failed"
exit 1
fi
echo "Pip installed and upgraded successfully."
# 3. Install virtualenv
echo "Installing virtualenv..."
pip install --user virtualenv
if [ $? -ne 0 ]; then
echo "Error: Failed to install virtualenv"
exit 1
fi
# Create virtual environment
~/.local/bin/virtualenv venv
if [ $? -ne 0 ]; then
echo "Error: Failed to create virtual environment"
exit 1
fi
# Activate virtual environment
source venv/bin/activate
if [ $? -ne 0 ]; then
echo "Error: Failed to activate virtual environment"
exit 1
fi
echo "Virtual environment created and activated."
# 4. Install dependencies
echo "Installing dependencies..."
pip install -r requirements.txt
if [ $? -ne 0 ]; then
echo "Error: Failed to install required packages"
exit 1
fi
pip install -Ue .
if [ $? -ne 0 ]; then
echo "Error: Failed to install project in editable mode"
exit 1
fi
python setup.py install
if [ $? -ne 0 ]; then
echo "Error: Failed to run setup.py install"
exit 1
fi
echo "Dependencies installed successfully."
# 5. Unzip RISC-V Verification Image
echo "Unzipping verification image..."
unzip -q verification_image.zip
if [ $? -ne 0 ]; then
echo "Error: Failed to unzip verification image"
exit 1
fi
# Move into verification_image directory
cd verification_image || { echo "Error: Failed to enter verification_image directory"; exit 1; }
# 6. Build the verification image
echo "Building verification image..."
bash build.sh
if [ $? -ne 0 ]; then
echo "Error: Failed to build verification image"
exit 1
fi
echo "Verification image built successfully."
# 7. Build the RISC-V Docker Image
echo "Building RISC-V Docker image..."
docker rmi -f "$DOCKER_IMAGE_RISCV" &>/dev/null
docker build -t "$DOCKER_IMAGE_RISCV" .
if [ $? -ne 0 ]; then
echo "Error: Failed to build Docker image $DOCKER_IMAGE_RISCV"
exit 1
fi
echo "RISC-V Docker image $DOCKER_IMAGE_RISCV built successfully."
# 8. Run the RISC-V Container and Compile the C program
docker rm -f "$DOCKER_CONTAINER_RISCV" &>/dev/null
docker run --name "$DOCKER_CONTAINER_RISCV" -it "$DOCKER_IMAGE_RISCV" bash -c "
echo 'Downloading C program...';
wget -q https://raw.githubusercontent.com/celine-lee/transpile/refs/heads/main/data/project-euler-c/original_c/problem12.c;
if [ \$? -ne 0 ]; then
echo 'Error: Failed to download C program inside container.';
exit 1;
fi;
echo 'C program downloaded.';
echo 'Compiling C program...';
riscv64-unknown-linux-gnu-gcc -S problem12.c -o problem12.s;
riscv64-unknown-linux-gnu-gcc problem12.c -o problem12;
if [ \$? -ne 0 ]; then
echo 'Error: Compilation failed.';
exit 1;
fi;
ls;
echo 'C program compiled successfully.';
echo 'Running compiled program using QEMU...';
qemu-riscv64 ./problem12;
if [ \$? -ne 0 ]; then
echo 'Error: Execution failed.';
exit 1;
fi;
echo 'Execution complete.';
"
if [ $? -ne 0 ]; then
echo "Error: Failed to start container $DOCKER_CONTAINER_RISCV."
exit 1
fi
echo "RISC-V program executed successfully."
# Stop and save RISC-V container
echo "Stopping and committing the RISC-V container..."
docker stop "$DOCKER_CONTAINER_RISCV" &>/dev/null
docker commit "$DOCKER_CONTAINER_RISCV" "$DOCKER_IMAGE_RISCV":latest &>/dev/null
docker rm "$DOCKER_CONTAINER_RISCV" &>/dev/null
echo "RISC-V container stopped and removed."
# 9. Build the ARM Docker Image
echo "Building ARM Docker image..."
docker rmi -f "$DOCKER_IMAGE_ARM" &>/dev/null
docker build -t "$DOCKER_IMAGE_ARM" -<<EOF
FROM ubuntu:22.04
# Set non-interactive mode for apt
ENV DEBIAN_FRONTEND=noninteractive
# Update and install required dependencies
RUN apt-get update && apt-get install -y \
gcc-aarch64-linux-gnu \
wget \
vim \
build-essential \
ninja-build \
python3-pip \
libglib2.0-dev \
libpixman-1-dev \
flex \
bison \
xz-utils
# Download and extract QEMU
RUN wget -q https://download.qemu.org/qemu-8.1.2.tar.xz && \
tar xvJf qemu-8.1.2.tar.xz && \
cd qemu-8.1.2 && \
./configure --enable-plugins && \
make -j\$(nproc)
# Set working directory
WORKDIR /workspace
EOF
if [ $? -ne 0 ]; then
echo "Error: Failed to build Docker image $DOCKER_IMAGE_ARM"
exit 1
fi
echo "ARM Docker image $DOCKER_IMAGE_ARM built successfully."
# 10. Run the ARM Container and Compile the C program
docker rm -f "$DOCKER_CONTAINER_ARM" &>/dev/null
docker run --name "$DOCKER_CONTAINER_ARM" -it "$DOCKER_IMAGE_ARM" bash -c "
echo 'Downloading C program...';
wget -q https://raw.githubusercontent.com/celine-lee/transpile/refs/heads/main/data/project-euler-c/original_c/problem12.c;
if [ \$? -ne 0 ]; then
echo 'Error: Failed to download C program inside container.';
exit 1;
fi;
echo 'C program downloaded.';
echo 'Compiling C program for ARM...';
aarch64-linux-gnu-gcc -S problem12.c -o problem12.s;
aarch64-linux-gnu-gcc problem12.c -o problem12;
if [ \$? -ne 0 ]; then
echo 'Error: Compilation failed.';
exit 1;
fi;
ls;
echo 'C program compiled successfully.';
echo 'Checking dynamic linker path...';
find / -name \"ld-linux-aarch64.so.1\" 2>/dev/null;
echo 'Running compiled ARM program using QEMU...';
./qemu-8.1.2/build/qemu-aarch64 -L /usr/aarch64-linux-gnu problem12;
if [ \$? -ne 0 ]; then
echo 'Error: Execution failed.';
exit 1;
fi;
echo 'Execution complete.';
"
if [ $? -ne 0 ]; then
echo "Error: Failed to start ARM container $DOCKER_CONTAINER_ARM."
exit 1
fi
echo "ARM program executed successfully."
# Stop and save ARM container
echo "Stopping and committing the ARM container..."
docker stop "$DOCKER_CONTAINER_ARM" &>/dev/null
docker commit "$DOCKER_CONTAINER_ARM" "$DOCKER_IMAGE_ARM":latest &>/dev/null
docker rm "$DOCKER_CONTAINER_ARM" &>/dev/null
echo "ARM container stopped and removed."
echo "Setup complete for both RISC-V and ARM."