Skip to content

Commit d3cc73d

Browse files
committed
Enhance source code preparation logic to automatically download and extract from various sources
1 parent 2f46f2a commit d3cc73d

File tree

1 file changed

+141
-56
lines changed

1 file changed

+141
-56
lines changed

assets/build

Lines changed: 141 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -129,71 +129,156 @@ build_package() {
129129
return 0
130130
fi
131131

132-
# Check if this package requires special setup
133-
echo "Checking for setup.sh in $(pwd)..."
134-
if [[ -f "setup.sh" ]]; then
135-
echo "Found setup.sh, running setup script for ${source_dir}..."
136-
echo "Current directory before setup.sh: $(pwd)"
137-
echo "Directory contents before setup.sh:"
138-
ls -la
139-
chmod +x setup.sh
140-
./setup.sh || {
141-
echo "Failed to run setup script for ${source_dir}."
142-
return 1
143-
}
144-
echo "Current directory after setup.sh: $(pwd)"
145-
echo "Directory contents after setup.sh:"
146-
ls -la
147-
else
148-
echo "No setup.sh found in $(pwd)"
149-
echo "Directory contents:"
150-
ls -la
132+
# Automatically download and prepare source code if needed
133+
if [[ -f "debmacros" ]]; then
134+
echo "Found debmacros, checking for source code..."
151135

152-
# Try to automatically extract source code if needed
153-
if [[ -f "debmacros" ]]; then
154-
echo "Found debmacros, checking for source code..."
136+
# Read version from debmacros
137+
VERSION=""
138+
if grep -q "%lastversion_version" debmacros; then
139+
VERSION=$(grep "%lastversion_version" debmacros | awk '{print $2}')
140+
elif grep -q "%version" debmacros; then
141+
VERSION=$(grep "%version" debmacros | awk '{print $2}')
142+
elif grep -q "VERSION" debmacros; then
143+
VERSION=$(grep "VERSION" debmacros | awk '{print $2}')
144+
fi
145+
146+
if [[ -n "${VERSION}" ]]; then
147+
echo "Detected version: ${VERSION}"
155148

156-
# Read version from debmacros
157-
VERSION=""
158-
if grep -q "%lastversion_version" debmacros; then
159-
VERSION=$(grep "%lastversion_version" debmacros | awk '{print $2}')
160-
elif grep -q "%version" debmacros; then
161-
VERSION=$(grep "%version" debmacros | awk '{print $2}')
162-
elif grep -q "VERSION" debmacros; then
163-
VERSION=$(grep "VERSION" debmacros | awk '{print $2}')
149+
# Try to determine package name from debian/control or directory name
150+
PACKAGE=""
151+
if [[ -f "debian/control" ]]; then
152+
PACKAGE=$(grep "^Source:" debian/control | awk '{print $2}')
153+
fi
154+
if [[ -z "${PACKAGE}" ]]; then
155+
# Fallback to directory name
156+
PACKAGE=$(basename "$(pwd)")
164157
fi
158+
echo "Detected package name: ${PACKAGE}"
165159

166-
if [[ -n "${VERSION}" ]]; then
167-
echo "Detected version: ${VERSION}"
168-
169-
# Try to determine package name from debian/control or directory name
170-
PACKAGE=""
171-
if [[ -f "debian/control" ]]; then
172-
PACKAGE=$(grep "^Source:" debian/control | awk '{print $2}')
173-
fi
174-
if [[ -z "${PACKAGE}" ]]; then
175-
# Fallback to directory name
176-
PACKAGE=$(basename "$(pwd)")
177-
fi
178-
echo "Detected package name: ${PACKAGE}"
179-
180-
# Check if source is already extracted
181-
if [[ -d "${PACKAGE}-${VERSION}" ]]; then
182-
echo "Source already extracted in ${PACKAGE}-${VERSION}/"
160+
# Check if source is already prepared
161+
if [[ -d "${PACKAGE}-${VERSION}" ]] && [[ -f "${PACKAGE}-${VERSION}/setup.py" ]]; then
162+
echo "Source already prepared in ${PACKAGE}-${VERSION}/"
163+
else
164+
# Look for .orig.tar.gz file first
165+
ORIG_TARBALL=$(find . -name "*.orig.tar.gz" | head -1)
166+
if [[ -n "${ORIG_TARBALL}" ]]; then
167+
echo "Found source tarball: ${ORIG_TARBALL}"
168+
echo "Extracting source code..."
169+
tar -xzf "${ORIG_TARBALL}" || {
170+
echo "Failed to extract source tarball"
171+
return 1
172+
}
173+
echo "Source extracted successfully"
183174
else
184-
# Look for .orig.tar.gz file
185-
ORIG_TARBALL=$(find . -name "*.orig.tar.gz" | head -1)
186-
if [[ -n "${ORIG_TARBALL}" ]]; then
187-
echo "Found source tarball: ${ORIG_TARBALL}"
188-
echo "Extracting source code..."
189-
tar -xzf "${ORIG_TARBALL}" || {
190-
echo "Failed to extract source tarball"
175+
# Try to download source from debian files
176+
echo "No .orig.tar.gz found, attempting to discover source URL..."
177+
178+
# Discover source URL from debian files
179+
SOURCE_URL=""
180+
181+
# Try to get source URL from debian/copyright
182+
if [[ -f "debian/copyright" ]]; then
183+
SOURCE_URL=$(grep "^Source:" debian/copyright | awk '{print $2}')
184+
if [[ -n "${SOURCE_URL}" ]]; then
185+
echo "Found source URL in debian/copyright: ${SOURCE_URL}"
186+
fi
187+
fi
188+
189+
# If not found in copyright, try debian/control
190+
if [[ -z "${SOURCE_URL}" ]] && [[ -f "debian/control" ]]; then
191+
# Try Homepage field
192+
SOURCE_URL=$(grep "^Homepage:" debian/control | awk '{print $2}')
193+
if [[ -n "${SOURCE_URL}" ]]; then
194+
echo "Found source URL in debian/control Homepage: ${SOURCE_URL}"
195+
fi
196+
fi
197+
198+
# If still not found, try Vcs-Git field
199+
if [[ -z "${SOURCE_URL}" ]] && [[ -f "debian/control" ]]; then
200+
VCS_GIT=$(grep "^Vcs-Git:" debian/control | awk '{print $2}')
201+
if [[ -n "${VCS_GIT}" ]]; then
202+
# Convert git URL to archive URL
203+
if [[ "${VCS_GIT}" =~ ^https://github.com/([^/]+)/([^/]+)\.git$ ]]; then
204+
SOURCE_URL="https://github.com/${BASH_REMATCH[1]}/${BASH_REMATCH[2]}"
205+
echo "Converted Vcs-Git to source URL: ${SOURCE_URL}"
206+
fi
207+
fi
208+
fi
209+
210+
# If we found a source URL, try to download from it
211+
if [[ -n "${SOURCE_URL}" ]]; then
212+
# Try different archive URL patterns
213+
ARCHIVE_URLS=(
214+
"${SOURCE_URL}/archive/v${VERSION}.tar.gz"
215+
"${SOURCE_URL}/archive/${VERSION}.tar.gz"
216+
"${SOURCE_URL}/archive/refs/tags/v${VERSION}.tar.gz"
217+
"${SOURCE_URL}/archive/refs/tags/${VERSION}.tar.gz"
218+
)
219+
220+
SOURCE_DOWNLOADED=false
221+
for ARCHIVE_URL in "${ARCHIVE_URLS[@]}"; do
222+
echo "Trying to download from: ${ARCHIVE_URL}"
223+
if curl -fsSL -o "${PACKAGE}-${VERSION}.tar.gz" "${ARCHIVE_URL}"; then
224+
echo "Successfully downloaded source from ${ARCHIVE_URL}"
225+
SOURCE_DOWNLOADED=true
226+
break
227+
fi
228+
done
229+
else
230+
echo "Could not discover source URL from debian files"
231+
echo "Available files:"
232+
ls -la
233+
return 1
234+
fi
235+
236+
if [[ "${SOURCE_DOWNLOADED}" == "true" ]]; then
237+
echo "Extracting downloaded source..."
238+
tar -xzf "${PACKAGE}-${VERSION}.tar.gz" || {
239+
echo "Failed to extract downloaded source"
191240
return 1
192241
}
193-
echo "Source extracted successfully"
242+
243+
# Move extracted content to the expected directory structure
244+
if [[ -d "${PACKAGE}-${VERSION}" ]]; then
245+
# If the extracted directory has the same name, move its contents up
246+
if [[ -d "${PACKAGE}-${VERSION}/${PACKAGE}-${VERSION}" ]]; then
247+
mv "${PACKAGE}-${VERSION}/${PACKAGE}-${VERSION}"/* "${PACKAGE}-${VERSION}/"
248+
rmdir "${PACKAGE}-${VERSION}/${PACKAGE}-${VERSION}"
249+
fi
250+
fi
251+
252+
echo "Source prepared successfully"
194253
else
195-
echo "No .orig.tar.gz found, checking if source is already in subdirectory..."
254+
echo "Failed to download source from any URL pattern"
255+
echo "Available files:"
256+
ls -la
257+
return 1
258+
fi
259+
fi
260+
261+
# Apply common patches if source was downloaded/extracted
262+
if [[ -f "${PACKAGE}-${VERSION}/setup.py" ]]; then
263+
echo "Applying common patches..."
264+
cd "${PACKAGE}-${VERSION}"
265+
266+
# Apply patches based on package type
267+
if [[ "${PACKAGE}" == "lastversion" ]]; then
268+
# Fix requests dependency as done in RPM spec
269+
if grep -q '"requests>=2\.6\.1"' setup.py; then
270+
echo "Applying lastversion-specific patch..."
271+
perl -pi -e 's/"requests>=2\.6\.1"/"requests"/' setup.py
272+
fi
273+
fi
274+
275+
# Copy debian directory if it exists in parent
276+
if [[ -d "../debian" ]]; then
277+
echo "Copying debian packaging files..."
278+
cp -r ../debian .
196279
fi
280+
281+
cd ..
197282
fi
198283
fi
199284
fi

0 commit comments

Comments
 (0)