@@ -6,13 +6,40 @@ FIRECRACKER_REPO_URL="https://github.com/e2b-dev/firecracker.git"
66
77function build_version {
88 local version=$1
9- echo " Starting build for Firecracker commit: $version "
109
11- echo " Checking out repo for Firecracker at commit: $version "
12- git checkout " ${version} "
10+ # Detect if the version is of the form tag_shorthash (e.g., v1.12.1_abcdef12)
11+ if [[ " $version " =~ ^([^_]+)_([0-9a-fA-F]+)$ ]]; then
12+ local tag=" ${BASH_REMATCH[1]} "
13+ local shorthash=" ${BASH_REMATCH[2]} "
14+ echo " Starting build for Firecracker tag: $tag and shorthash: $shorthash "
15+
16+ echo " Checking out repo at tag: $tag "
17+ git checkout " $tag "
18+
19+ # Find full hash from shorthash
20+ fullhash=$( git rev-parse --verify " $shorthash ^{commit}" 2> /dev/null || true)
21+ if [[ -z " $fullhash " ]]; then
22+ echo " Error: Could not resolve hash $shorthash "
23+ exit 1
24+ fi
25+
26+ # Ensure that $fullhash is a descendant of $tag
27+ if git merge-base --is-ancestor " $tag " " $fullhash " ; then
28+ echo " Shorthash $shorthash is AFTER tag $tag -- proceeding"
29+ git checkout " $fullhash "
30+ else
31+ echo " Error: shorthash $shorthash is not a descendant of tag $tag "
32+ exit 1
33+ fi
34+ version_name=" ${tag} _$shorthash "
35+ else
36+ echo " Starting build for Firecracker at commit: $version "
37+ echo " Checking out repo for Firecracker at commit: $version "
38+ git checkout " ${version} "
39+ # The format will be: latest_tag_latest_commit_hash — v1.7.0-dev_g8bb88311
40+ version_name=$( git describe --tags --abbrev=0 " $( git rev-parse HEAD) " ) _$( git rev-parse --short HEAD)
41+ fi
1342
14- # The format will be: latest_tag_latest_commit_hash — v1.7.0-dev_g8bb88311
15- version_name=$( git describe --tags --abbrev=0 $( git rev-parse HEAD) ) _$( git rev-parse --short HEAD)
1643 echo " Version name: $version_name "
1744
1845 echo " Building Firecracker version: $version_name "
@@ -23,11 +50,19 @@ function build_version {
2350 cp build/cargo_target/x86_64-unknown-linux-musl/release/firecracker " ../builds/${version_name} /firecracker"
2451}
2552
53+ # If a version is passed as argument, build only that version
54+ # Otherwise, build all versions from firecracker_versions.txt
55+ if [[ $# -ge 1 ]]; then
56+ versions=(" $@ " )
57+ else
58+ mapfile -t versions < <( grep -v ' ^ *#' firecracker_versions.txt | grep -v ' ^$' )
59+ fi
60+
2661echo " Cloning the Firecracker repository"
2762git clone $FIRECRACKER_REPO_URL firecracker
2863cd firecracker
2964
30- grep -v ' ^ *# ' < ../firecracker_versions.txt | while IFS= read -r version ; do
65+ for version in " ${versions[@]} " ; do
3166 build_version " $version "
3267done
3368
0 commit comments