-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·247 lines (209 loc) · 7.23 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·247 lines (209 loc) · 7.23 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
#!/usr/bin/env bash
# filepath: build.sh
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Default values
PRODUCTION=false
PIXEL_32BIT=false
CLEAN=false
JOBS=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to show usage
show_help() {
cat << EOF
Usage: $0 [OPTIONS]
Build script for Fast Feedback Service to manage development and production builds.
OPTIONS:
-p, --production Build for production (single build directory)
-3, --32bit Use 32-bit pixel data (only with --production)
-c, --clean Clean build directories before building
-j, --jobs N Number of parallel jobs (default: $(nproc 2>/dev/null || echo 4))
-h, --help Show this help message
DEVELOPMENT BUILD (default):
Creates both 'build' (16-bit) and 'build_32bit' (32-bit) directories for 16/32-bit pixel data.
Runs cmake and builds both configurations for testing.
PRODUCTION BUILD:
Creates only 'build' directory with specified configuration.
Removes 'build_32bit' if it exists.
Use --32bit flag to build with 32-bit pixel data support.
EXAMPLES:
$0 # Development build (both 16-bit and 32-bit)
$0 --production # Production build with 16-bit pixels
$0 --production --32bit # Production build with 32-bit pixels
$0 --clean # Clean and rebuild development builds
$0 --production --clean --32bit # Clean production build with 32-bit
EOF
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-p|--production)
PRODUCTION=true
shift
;;
-3|--32bit)
PIXEL_32BIT=true
shift
;;
-c|--clean)
CLEAN=true
shift
;;
-j|--jobs)
JOBS="$2"
shift 2
;;
-h|--help)
show_help
exit 0
;;
*)
print_error "Unknown option: $1"
show_help
exit 1
;;
esac
done
# Validate arguments
if [[ "$PIXEL_32BIT" == "true" && "$PRODUCTION" == "false" ]]; then
print_error "--32bit flag can only be used with --production"
exit 1
fi
# Detect build system preference
BUILD_SYSTEM="Unix Makefiles"
BUILD_CMD="make"
if command -v ninja >/dev/null 2>&1; then
BUILD_SYSTEM="Ninja"
BUILD_CMD="ninja"
print_status "Using Ninja build system"
else
print_status "Using Make build system"
fi
# Function to initialize git submodules
init_submodules() {
print_status "Checking git submodules..."
if [[ -f .gitmodules ]]; then
if [[ ! -f dx2/CMakeLists.txt ]]; then
print_status "Initializing git submodules..."
git submodule update --init --recursive
else
print_status "Git submodules already initialized"
fi
fi
}
# Function to configure and build a directory
build_directory() {
local build_dir="$1"
local cmake_args="$2"
local description="$3"
print_status "Building $description in $build_dir..."
# Clean if requested
if [[ "$CLEAN" == "true" && -d "$build_dir" ]]; then
print_status "Cleaning $build_dir..."
rm -rf "$build_dir"
fi
# Create build directory
mkdir -p "$build_dir"
# Configure with cmake
print_status "Configuring $description..."
(
cd "$build_dir"
cmake .. -G "$BUILD_SYSTEM" $cmake_args -DCMAKE_INSTALL_PREFIX="${CONDA_PREFIX}"
)
# Build
print_status "Compiling $description..."
(
cd "$build_dir"
if [[ "$BUILD_CMD" == "ninja" ]]; then
ninja
else
make -j"$JOBS"
fi
)
# Install
print_status "Installing $description..."
(
cd "$build_dir"
if [[ "$BUILD_CMD" == "ninja" ]]; then
ninja "install"
else
make "install" -j"$JOBS"
fi
)
print_success "Successfully built $description"
}
# Main build logic
main() {
print_status "Fast Feedback Service Build Script"
print_status "=================================="
# Check if we're in the right directory
if [[ ! -f CMakeLists.txt ]]; then
print_error "CMakeLists.txt not found. Please run this script from the project root."
exit 1
fi
# Require an active conda/mamba environment so installs go to the right prefix
if [[ -z "${CONDA_PREFIX:-}" ]]; then
print_error "No conda/mamba environment is active. Activate your environment first."
exit 1
fi
print_status "Installing into conda environment: ${CONDA_PREFIX}"
# Initialize submodules
init_submodules
if [[ "$PRODUCTION" == "true" ]]; then
print_status "Production build mode"
# Remove build_32bit if it exists
if [[ -d build_32bit ]]; then
print_status "Removing build_32bit directory for production build"
rm -rf build_32bit
fi
# Build production version
if [[ "$PIXEL_32BIT" == "true" ]]; then
build_directory "build" "-DPIXEL_DATA_32BIT=ON -DUSE_REDUCED_PRECISION=OFF -DCMAKE_BUILD_TYPE=Release" "production (32-bit, double precision)"
else
build_directory "build" "-DUSE_REDUCED_PRECISION=OFF -DCMAKE_BUILD_TYPE=Release" "production (16-bit, double precision)"
fi
else
print_status "Development build mode"
# Build both 16-bit and 32-bit versions
build_directory "build" "-DUSE_REDUCED_PRECISION=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo" "development (16-bit, double precision)"
build_directory "build_32bit" "-DPIXEL_DATA_32BIT=ON -DUSE_REDUCED_PRECISION=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo" "development (32-bit, double precision)"
fi
print_success "Build completed successfully!"
# Show build artifacts
print_status "Build artifacts:"
# 16-bit build artifacts
if [[ -d build/bin ]]; then
print_status "16-bit binaries (build/bin/):"
[[ -f build/bin/spotfinder ]] && echo -e " - ${GREEN}spotfinder${NC}"
[[ -f build/bin/baseline_indexer ]] && echo -e " - ${GREEN}baseline_indexer${NC}"
[[ -f build/bin/baseline_integrator ]] && echo -e " - ${GREEN}baseline_integrator${NC}"
[[ -f build/bin/integrator ]] && echo -e " - ${GREEN}integrator${NC}"
fi
# 32-bit build artifacts
if [[ -d build_32bit/bin ]]; then
print_status "32-bit binaries (build_32bit/bin/):"
[[ -f build_32bit/bin/spotfinder ]] && echo -e " - ${GREEN}spotfinder${NC}"
[[ -f build_32bit/bin/baseline_indexer ]] && echo -e " - ${GREEN}baseline_indexer${NC}"
[[ -f build_32bit/bin/baseline_integrator ]] && echo -e " - ${GREEN}baseline_integrator${NC}"
[[ -f build_32bit/bin/integrator ]] && echo -e " - ${GREEN}integrator${NC}"
fi
}
# Run main function
main "$@"