Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-05 08:17:13

0001 #!/bin/bash
0002 
0003 # This file is part of the ACTS project.
0004 #
0005 # Copyright (C) 2016 CERN for the benefit of the ACTS project
0006 #
0007 # This Source Code Form is subject to the terms of the Mozilla Public
0008 # License, v. 2.0. If a copy of the MPL was not distributed with this
0009 # file, You can obtain one at https://mozilla.org/MPL/2.0/.
0010 
0011 # Build the ACTS source archive that ships with pre-generated code.
0012 #
0013 # The archive holds the tracked content of a revision plus a `prebuilt-codegen/`
0014 # directory, which cmake/ActsCodegen.cmake finds on its own. A build from the
0015 # unpacked archive therefore never runs the code generators, and never downloads
0016 # uv, a Python interpreter or the generator dependencies.
0017 #
0018 # Note that this is not the same as the source archive GitHub generates for a
0019 # tag: that one cannot carry the generated code. Only the archive attached to
0020 # the release as an asset does.
0021 #
0022 # Generate the code first, with CI/pregenerate_codegen.py.
0023 
0024 set -e
0025 set -u
0026 
0027 SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
0028 SOURCE_ROOT=$( dirname "$SCRIPT_DIR" )
0029 
0030 output=""
0031 prebuilt=""
0032 revision="HEAD"
0033 prefix=""
0034 
0035 usage() {
0036     cat <<EOF
0037 usage: $( basename "$0" ) --output <archive.tar.gz> --prebuilt <dir> [options]
0038 
0039   --output <path>     archive to write
0040   --prebuilt <dir>    pre-generated code, as produced by CI/pregenerate_codegen.py
0041   --revision <rev>    revision to take the tracked content from (default: HEAD)
0042   --prefix <name>     top-level directory inside the archive
0043                       (default: the output file name without .tar.gz)
0044 EOF
0045 }
0046 
0047 while [ $# -gt 0 ]; do
0048     case "$1" in
0049         --output) output="$2"; shift 2 ;;
0050         --prebuilt) prebuilt="$2"; shift 2 ;;
0051         --revision) revision="$2"; shift 2 ;;
0052         --prefix) prefix="$2"; shift 2 ;;
0053         -h|--help) usage; exit 0 ;;
0054         *) echo "error: unknown argument '$1'" >&2; usage >&2; exit 1 ;;
0055     esac
0056 done
0057 
0058 if [ -z "$output" ] || [ -z "$prebuilt" ]; then
0059     echo "error: --output and --prebuilt are required" >&2
0060     usage >&2
0061     exit 1
0062 fi
0063 
0064 if [ ! -d "$prebuilt" ]; then
0065     echo "error: '$prebuilt' is not a directory" >&2
0066     exit 1
0067 fi
0068 
0069 count=$( find "$prebuilt" -type f | wc -l | tr -d ' ' )
0070 if [ "$count" -eq 0 ]; then
0071     echo "error: '$prebuilt' holds no pre-generated files" >&2
0072     exit 1
0073 fi
0074 
0075 if [ -z "$prefix" ]; then
0076     prefix=$( basename "$output" )
0077     prefix=${prefix%.tar.gz}
0078     prefix=${prefix%.tgz}
0079 fi
0080 
0081 tmp=$( mktemp -d )
0082 trap 'rm -rf "$tmp"' EXIT
0083 
0084 # Tracked content only: a plain copy of the source directory would drag in build
0085 # directories and whatever else is lying around, and this also honours
0086 # `export-ignore` attributes. git archive puts it all under $prefix/ for us.
0087 git -C "$SOURCE_ROOT" archive \
0088     --format=tar \
0089     --prefix="$prefix/" \
0090     --output="$tmp/base.tar" \
0091     "$revision"
0092 
0093 # Append the generated code, laid out where ActsCodegen.cmake looks for it.
0094 # Appending rather than unpacking and repacking is why this stays uncompressed
0095 # until the end: tar can only extend an uncompressed archive.
0096 mkdir -p "$tmp/stage/$prefix"
0097 cp -R "$prebuilt" "$tmp/stage/$prefix/prebuilt-codegen"
0098 tar -rf "$tmp/base.tar" -C "$tmp/stage" "$prefix/prebuilt-codegen"
0099 
0100 gzip -c "$tmp/base.tar" > "$output"
0101 
0102 echo "Wrote $output from $revision with $count pre-generated files"