-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·266 lines (226 loc) · 7.97 KB
/
build.sh
File metadata and controls
executable file
·266 lines (226 loc) · 7.97 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
#!/bin/bash
# Root-level build script for ad-blocking repository
# Builds all projects or specific ones with debug/release profiles
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# 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
BUILD_PROFILE="debug"
BUILD_ALL=false
BUILD_RUST=false
BUILD_DOTNET=false
BUILD_TYPESCRIPT=false
BUILD_PYTHON=false
# Function to print usage
usage() {
cat << EOF
Usage: $0 [OPTIONS]
Build all projects or specific ones with debug/release profiles.
OPTIONS:
--all Build all projects (default if no specific project selected)
--rust Build Rust projects
--dotnet Build .NET projects
--typescript Build TypeScript/Deno projects
--python Build Python projects
--debug Use debug profile (default)
--release Use release profile
-h, --help Show this help message
EXAMPLES:
$0 # Build all projects in debug mode
$0 --rust # Build only Rust projects in debug mode
$0 --dotnet --release # Build only .NET projects in release mode
$0 --all --release # Build all projects in release mode
EOF
exit "${1:-0}"
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--all)
BUILD_ALL=true
shift
;;
--rust)
BUILD_RUST=true
shift
;;
--dotnet)
BUILD_DOTNET=true
shift
;;
--typescript)
BUILD_TYPESCRIPT=true
shift
;;
--python)
BUILD_PYTHON=true
shift
;;
--debug)
BUILD_PROFILE="debug"
shift
;;
--release)
BUILD_PROFILE="release"
shift
;;
-h|--help)
usage 0
;;
*)
echo -e "${RED}Unknown option: $1${NC}"
usage 1
;;
esac
done
# If no specific project selected, build all
if [[ "$BUILD_ALL" == false ]] && [[ "$BUILD_RUST" == false ]] && [[ "$BUILD_DOTNET" == false ]] && [[ "$BUILD_TYPESCRIPT" == false ]] && [[ "$BUILD_PYTHON" == false ]]; then
BUILD_ALL=true
fi
# If --all is specified, enable all projects
if [[ "$BUILD_ALL" == true ]]; then
BUILD_RUST=true
BUILD_DOTNET=true
BUILD_TYPESCRIPT=true
BUILD_PYTHON=true
fi
echo "╔═══════════════════════════════════════════════════════════╗"
echo "║ Ad-Blocking Repository Build Script ║"
echo "╚═══════════════════════════════════════════════════════════╝"
echo ""
echo -e "${BLUE}Build Profile: ${BUILD_PROFILE}${NC}"
echo ""
BUILD_FAILED=false
# Function to build Rust projects
build_rust() {
echo -e "${BLUE}Building Rust projects...${NC}"
local cargo_flags=""
if [[ "$BUILD_PROFILE" == "release" ]]; then
cargo_flags="--release"
fi
# Build the entire workspace
echo "→ Building Rust workspace..."
if [[ "$BUILD_PROFILE" == "release" ]]; then
cargo build --release --workspace
else
cargo build --workspace
fi
if [[ $? -eq 0 ]]; then
echo -e "${GREEN}✓ Rust workspace built successfully${NC}"
else
echo -e "${RED}✗ Rust workspace build failed${NC}"
BUILD_FAILED=true
return 1
fi
echo ""
}
# Function to build .NET projects
build_dotnet() {
echo -e "${BLUE}Building .NET projects...${NC}"
local configuration="Debug"
if [[ "$BUILD_PROFILE" == "release" ]]; then
configuration="Release"
fi
# Build AdGuard API Client
echo "→ Building AdGuard API Client (.NET)..."
if (cd src/adguard-api-dotnet && dotnet restore AdGuard.ApiClient.slnx && dotnet build AdGuard.ApiClient.slnx --no-restore --configuration $configuration); then
echo -e "${GREEN}✓ AdGuard API Client built successfully${NC}"
else
echo -e "${RED}✗ AdGuard API Client build failed${NC}"
BUILD_FAILED=true
fi
# Build Rules Compiler .NET
echo "→ Building Rules Compiler (.NET)..."
if (cd src/rules-compiler-dotnet && dotnet restore RulesCompiler.slnx && dotnet build RulesCompiler.slnx --no-restore --configuration $configuration); then
echo -e "${GREEN}✓ Rules Compiler (.NET) built successfully${NC}"
else
echo -e "${RED}✗ Rules Compiler (.NET) build failed${NC}"
BUILD_FAILED=true
fi
echo ""
}
# Function to build TypeScript/Deno projects
build_typescript() {
echo -e "${BLUE}Building TypeScript/Deno projects...${NC}"
# Check if Deno is installed
if ! command -v deno &> /dev/null; then
echo -e "${RED}✗ Deno is not installed. Please install Deno to build TypeScript projects.${NC}"
BUILD_FAILED=true
return 1
fi
# Build Rules Compiler TypeScript
echo "→ Building Rules Compiler (TypeScript)..."
if (cd src/rules-compiler-typescript && deno task generate:types && deno task check); then
echo -e "${GREEN}✓ Rules Compiler (TypeScript) built successfully${NC}"
else
echo -e "${RED}✗ Rules Compiler (TypeScript) build failed${NC}"
BUILD_FAILED=true
fi
# Build AdGuard API TypeScript
echo "→ Building AdGuard API Client (TypeScript)..."
if (cd src/adguard-api-typescript && deno task generate:types && deno task check); then
echo -e "${GREEN}✓ AdGuard API Client (TypeScript) built successfully${NC}"
else
echo -e "${RED}✗ AdGuard API Client (TypeScript) build failed${NC}"
BUILD_FAILED=true
fi
# Build Linear tool
echo "→ Building Linear Import Tool (TypeScript)..."
if (cd src/linear && deno task generate:types && deno task check); then
echo -e "${GREEN}✓ Linear Import Tool built successfully${NC}"
else
echo -e "${RED}✗ Linear Import Tool build failed${NC}"
BUILD_FAILED=true
fi
echo ""
}
# Function to build Python projects
build_python() {
echo -e "${BLUE}Building Python projects...${NC}"
# Check if Python is installed
if ! command -v python3 &> /dev/null; then
echo -e "${RED}✗ Python 3 is not installed. Please install Python 3 to build Python projects.${NC}"
BUILD_FAILED=true
return 1
fi
# Build Rules Compiler Python
echo "→ Building Rules Compiler (Python)..."
if (cd src/rules-compiler-python && python3 -m pip install --quiet -e ".[dev]" && python3 -m mypy rules_compiler/); then
echo -e "${GREEN}✓ Rules Compiler (Python) built successfully${NC}"
else
echo -e "${RED}✗ Rules Compiler (Python) build failed${NC}"
BUILD_FAILED=true
fi
echo ""
}
# Build projects based on flags
if [[ "$BUILD_RUST" == true ]]; then
build_rust
fi
if [[ "$BUILD_DOTNET" == true ]]; then
build_dotnet
fi
if [[ "$BUILD_TYPESCRIPT" == true ]]; then
build_typescript
fi
if [[ "$BUILD_PYTHON" == true ]]; then
build_python
fi
# Summary
echo "╔═══════════════════════════════════════════════════════════╗"
echo "║ Build Summary ║"
echo "╚═══════════════════════════════════════════════════════════╝"
echo ""
if [[ "$BUILD_FAILED" == true ]]; then
echo -e "${RED}✗ Some builds failed. Please check the output above.${NC}"
exit 1
else
echo -e "${GREEN}✓ All builds completed successfully!${NC}"
exit 0
fi