Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Commit b749e0f

Browse files
committed
Clean up clean script by reusing code
The only user-visible change should be that this causes the list of targets to be the same between the build scripts and the clean script. Internally the `_common.sh` script is reused to avoid duplicating logic. To achieve this, that script now defines only environment variables and functions but does not do anything actively. All the build initialization has been moved to a function `build_setup` to which calls are added where needed.
1 parent bc41ce5 commit b749e0f

File tree

5 files changed

+34
-65
lines changed

5 files changed

+34
-65
lines changed

build.sh

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ CREATE_PACKAGE="${CREATE_PACKAGE:-1}"
5757

5858
. scripts/_common.sh $1
5959

60+
build_setup
61+
6062
if [ $BUNDLE_PYTHON == "1" ]; then
6163
print ">> Bundle Python"
6264
. $WORK_DIR/scripts/bundle_python.sh

build_bba.sh

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ INSTALL_DEPS="${INSTALL_DEPS:-1}"
1414
export VERSION=nightly
1515
. scripts/_common.sh linux_x86_64
1616

17+
build_setup
18+
1719
print ">> Compile nextpnr-ecp5-bba"
1820
. $WORK_DIR/scripts/compile_nextpnr_ecp5_bba.sh
1921

clean.sh

+1-42
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,12 @@
55

66
set -e
77

8-
# -- Target architectures
9-
ARCH=$1
10-
TARGET_ARCHS="linux_x86_64 linux_i686 linux_armv7l linux_aarch64 windows_x86 windows_amd64 darwin"
11-
12-
# -- Store current dir
13-
WORK_DIR=$PWD
14-
# -- Folder for building the source code
15-
BUILDS_DIR=$WORK_DIR/_builds
16-
# -- Folder for storing the generated packages
17-
PACKAGES_DIR=$WORK_DIR/_packages
18-
19-
UPSTREAM_DIR=$WORK_DIR/_upstream
20-
21-
# -- Check ARCH
22-
if [[ $# > 1 ]]; then
23-
echo ""
24-
echo "Error: too many arguments"
25-
exit 1
26-
fi
27-
28-
if [[ $# < 1 ]]; then
29-
echo ""
30-
echo "Usage: bash clean.sh TARGET"
31-
echo ""
32-
echo "Targets: $TARGET_ARCHS"
33-
exit 1
34-
fi
35-
36-
if [[ $ARCH =~ [[:space:]] || ! $TARGET_ARCHS =~ (^|[[:space:]])$ARCH([[:space:]]|$) ]]; then
37-
echo ""
38-
echo ">>> WRONG ARCHITECTURE \"$ARCH\""
39-
exit 1
40-
fi
41-
42-
echo ""
43-
echo ">>> ARCHITECTURE \"$ARCH\""
8+
. scripts/_common.sh $1
449

4510
printf "Are you sure? [y/N]: "
4611
read RESP
4712
case "$RESP" in
4813
[yY][eE][sS]|[yY])
49-
# -- Directory for compiling the tools
50-
BUILD_DIR=$BUILDS_DIR/build_$ARCH
51-
52-
# -- Directory for installation the target files
53-
PACKAGE_DIR=$PACKAGES_DIR/build_$ARCH
54-
5514
# -- Remove the package dir
5615
rm -r -f $PACKAGE_DIR
5716

scripts/_common.sh

+26-23
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,12 @@ export PACKAGES_DIR=$WORK_DIR/_packages
2626
# -- Folder for storing the source code from github
2727
export UPSTREAM_DIR=$WORK_DIR/_upstream
2828

29-
# -- Create the build directory
30-
mkdir -p $BUILDS_DIR
31-
# -- Create the packages directory
32-
mkdir -p $PACKAGES_DIR
33-
# -- Create the upstream directory and enter into it
34-
mkdir -p $UPSTREAM_DIR
35-
3629
# -- Directory for compiling the tools
3730
export BUILD_DIR=$BUILDS_DIR/build_$ARCH
3831

3932
# -- Directory for installation the target files
4033
export PACKAGE_DIR=$PACKAGES_DIR/build_$ARCH
4134

42-
# -- Create the build dir
43-
mkdir -p $BUILD_DIR
44-
45-
# -- Create the package folders
46-
mkdir -p $PACKAGE_DIR/$NAME/{bin,lib,share}
47-
mkdir -p $PACKAGE_DIR/${NAME}_symbols/{bin,lib}
48-
mkdir -p $PACKAGE_DIR/${NAME}-progtools/bin
49-
5035
# -- Test script function
5136
function test_bin {
5237
. $WORK_DIR/scripts/test_bin.sh $1
@@ -167,6 +152,32 @@ function wget_retry {
167152
done
168153
}
169154

155+
# -- Initial setup for the build tree
156+
function build_setup {
157+
# -- Create the build directory
158+
mkdir -p $BUILDS_DIR
159+
# -- Create the packages directory
160+
mkdir -p $PACKAGES_DIR
161+
# -- Create the upstream directory
162+
mkdir -p $UPSTREAM_DIR
163+
164+
# -- Create the build dir
165+
mkdir -p $BUILD_DIR
166+
167+
# -- Create the package folders
168+
mkdir -p $PACKAGE_DIR/$NAME/{bin,lib,share}
169+
mkdir -p $PACKAGE_DIR/${NAME}_symbols/{bin,lib}
170+
mkdir -p $PACKAGE_DIR/${NAME}-progtools/bin
171+
172+
if [ $INSTALL_DEPS == "1" ]; then
173+
print ">> Install dependencies"
174+
. $WORK_DIR/scripts/install_dependencies.sh
175+
fi
176+
177+
print ">> Set build flags"
178+
. $WORK_DIR/scripts/build_setup.sh
179+
}
180+
170181
# -- Check ARCH
171182
if [[ $# > 1 ]]; then
172183
echo ""
@@ -190,11 +201,3 @@ fi
190201

191202
echo ""
192203
echo ">>> ARCHITECTURE \"$ARCH\""
193-
194-
if [ $INSTALL_DEPS == "1" ]; then
195-
print ">> Install dependencies"
196-
. $WORK_DIR/scripts/install_dependencies.sh
197-
fi
198-
199-
print ">> Set build flags"
200-
. $WORK_DIR/scripts/build_setup.sh

scripts/test/run_tests.sh

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ TEST_NEXTPNR_PYTHON="${TEST_NEXTPNR_PYTHON:-1}"
1717
TEST_SBY="${TEST_SBY:-1}"
1818

1919
. scripts/_common.sh $1
20+
21+
build_setup
22+
2023
. $WORK_DIR/scripts/test/install_toolchain.sh
2124

2225
if [ $TEST_BINARIES_EXECUTE == "1" ]; then

0 commit comments

Comments
 (0)