Skip to content

Commit

Permalink
Create list-versions.py and download-and-unpackage.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsmith committed Jul 17, 2023
1 parent 0248a57 commit d19a4c8
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 28 deletions.
50 changes: 22 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,41 @@ jobs:
steps:
- uses: actions/checkout@v3.5.3

# TODO: generate versions from Common.java
- name: List Python versions
id: python-versions
run: |
cd target
for mode in short long; do
echo "$mode=$(./list-versions.py --$mode)" >> $GITHUB_OUTPUT
done
- uses: actions/setup-python@v4.6.1
with:
python-version: |
3.8
3.9
3.10
3.11
python-version: ${{ steps.python-versions.outputs.short }}

# TODO: build these in CI as well
- name: Download target Python builds
run: |
cd target
for version in ${{ steps.python-versions.outputs.long }}; do
./download-and-unpackage.sh prefix $version
done
- name: Install Python requirements
run: pip install -r product/runtime/requirements-build.txt

# TODO: move versions to a single location used by both CI and
# runtime/build.gradle.
# runtime/build.gradle. COMPILE_SDK_VERSION can then be removed from Common.java,
# since it's not used anywhere else.
- name: Set up Android SDK
run: "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager
'cmake;3.22.1' 'ndk;22.1.7171670' 'platforms;android-30'"

- name: Unpackage target
run: |
target_dir=$(pwd)/maven/com/chaquo/python/target
mkdir -p $target_dir
cd $target_dir
# TODO: generate versions from Common.java
for version in 3.8.16-0 3.9.13-1 3.10.6-1 3.11.0-2; do
mkdir $target_dir/$version
cd $target_dir/$version
target_url=https://repo.maven.apache.org/maven2/com/chaquo/python/target
wget -r -l1 -nd -A .zip -e robots=off -U Mozilla/5.0 $base_url/$version
cd $GITHUB_WORKSPACE/target
./unpackage-target.sh ./prefix $target_dir/$version
done
- name: Create local.properties
run: |
for version in 8 11; do
java_home=${!JAVA_HOME_${version}_X64}
echo chaquopy.java.home.$version=$java_home >> product/local.properties
done
for version in 8 11 17; do
echo chaquopy.java.home.$version=${!JAVA_HOME_${version}_X64}
done > product/local.properties
- name: Build
run: |
Expand Down
23 changes: 23 additions & 0 deletions target/download-and-unpackage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -eu

# Positional arguments:
# * `prefix` directory to unpack into
# * Version to download, including build number

this_dir=$(cd $(dirname $0) && pwd)
prefix_dir=$(cd ${1:?} && pwd)
version=${2:?}

tmp_dir="/tmp/download-and-unpackage-$$"
version_dir=$tmp_dir/$version
mkdir -p $version_dir
cd $version_dir
wget -r -l1 --no-directories --accept .zip -e robots=off --user-agent Mozilla/5.0 \
https://repo.maven.apache.org/maven2/com/chaquo/python/target/$version

echo
echo Unpacking:
$this_dir/unpackage-target.sh $prefix_dir $version_dir

rm -rf $tmp_dir
24 changes: 24 additions & 0 deletions target/list-versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3

import argparse
from os.path import abspath, dirname
import re

parser = argparse.ArgumentParser()
mode_group = parser.add_mutually_exclusive_group(required=True)
mode_group.add_argument("--short", action="store_true")
mode_group.add_argument("--long", action="store_true")
args = parser.parse_args()

product_dir = abspath(f"{dirname(__file__)}/../product")
for line in open(f"{product_dir}/buildSrc/src/main/java/com/chaquo/python/Common.java"):
match = re.search(r'PYTHON_VERSIONS.put\("(\d+)\.(\d+)\.(\d+)", "(\d+)"\)', line)
if match:
major, minor, micro, build = match.groups()
if args.short:
print(f"{major}.{minor}")
elif args.long:
print(f"{major}.{minor}.{micro}-{build}")
else:
raise AssertionError()

1 change: 1 addition & 0 deletions target/unpackage-target.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -eu
# Positional arguments (order is the same as package-target.sh):
# * `prefix` directory to unpack into.
# * Maven directory to unpack from, e.g. /path/to/com/chaquo/python/target/3.10.6-3.
# Must end in a version number.

mkdir -p "${1:?}"
prefix_dir=$(cd ${1:?} && pwd)
Expand Down

0 comments on commit d19a4c8

Please sign in to comment.