blob: c8bf0a04b40088cf6264796d7d6da4faa23dc38b [file]
#!/bin/bash
# Copyright 2026 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# A Jiri hook used to extract the pathspec-py3 wheel file to
# a hard-coded destination directory to make it directly usable
# before the build.
set -e
# Where to find the source wheel file. Exact name is versioned and unknown here.
SOURCE_SUBDIR="prebuilt/third_party/pathspec-py3-wheel"
# Where to extract the wheel file.
DEST_SUBDIR="prebuilt/third_party/pathspec-py3"
function die {
echo >&2 "ERROR: $*"
exit 1
}
# Assume this script lives under //tools/build/scripts/
_SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
FUCHSIA_DIR="$(readlink -f "${_SCRIPT_DIR}/../../..")"
[[ -f "${FUCHSIA_DIR}/.jiri_manifest" ]] ||
die "Cannot locate proper FUCHSIA_DIR, got: ${FUCHSIA_DIR}"
# The source and destination directories are hard-coded here.
SOURCE_DIR="$FUCHSIA_DIR/$SOURCE_SUBDIR"
echo "Using source directory: $SOURCE_DIR"
# Locate the wheel file from the source directory.
SRC_FILE=$(ls "$SOURCE_DIR"/*.whl 2>/dev/null | head -n1)
[[ -n "$SRC_FILE" ]] || die "No .whl found in source directory: ${SOURCE_DIR}"
echo "Found wheel file: $SRC_FILE"
# Extract version number from the wheel file name, as this
# will be required for the README.fuchsia file.
SRC_FILENAME=$(basename "${SRC_FILE}")
SRC_VERSION=$(echo "${SRC_FILENAME}" | sed -E -e 's|pathspec-([0-9.]+)-py3-.*|\1|')
[[ -n "${SRC_VERSION}" ]] || die "Could not find version in filename: ${SRC_FILENAME}"
echo "Found version: [$SRC_VERSION]"
# A file used to verify that the extracted content is correct.
CHECK_FILE=pathspec/__init__.py
DEST_DIR="${FUCHSIA_DIR}/${DEST_SUBDIR}"
echo "Using destination directory: ${DEST_DIR}"
mkdir -p "${DEST_DIR}"
rm -rf "${DEST_DIR:?}"/*
echo "Extracting archive"
unzip -o -q "${SRC_FILE}" -d "${DEST_DIR}" || die "Could not unzip ${SRC_FILE}"
[[ -f "${DEST_DIR}/${CHECK_FILE}" ]] ||
die "Missing file from extracted archive: ${DEST_DIR}/${CHECK_FILE}"
echo "Generating BUILD.gn file"
(
cd "${DEST_DIR}"
cat <<EOF
# Copyright $(date +%Y) The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Auto-generated by tools/build/scripts/extract_pathspec_wheel.sh. DO NOT EDIT!
import("//build/python/python_library.gni")
python_library("pathspec-py3") {
library_name = "pathspec"
source_root = "pathspec"
enable_mypy = false
sources = [
EOF
# List all extracted python source files relative to pathspec/
find pathspec -type f -name "*.py" | sed -E 's|^pathspec/||' | sort | while read -r pyfile; do
echo " \"${pyfile}\","
done
cat <<EOF
]
}
EOF
) > "${DEST_DIR}/BUILD.gn"
echo "Writing README.fuchsia file"
cat > "${DEST_DIR}/README.fuchsia" <<EOF
Name: pathspec-py3
URL: https://chrome-infra-packages.appspot.com/p/infra/python/wheels/pathspec-py3
Version: ${SRC_VERSION}
Security Critical: no
License File: pathspec-${SRC_VERSION}.dist-info/licenses/LICENSE
-> License File Format: Single License
-> License Classifications: MPL-2.0
Description:
Utility library for gitignore style pattern matching of file paths.
This directory contains the extracted wheel file from CIPD package
infra/python/wheels/pathspec-py3.
The extraction script is in \$FUCHSIA_DIR/tools/build/scripts, and invoked
as a Jiri hook.
To update to a new version:
1) Modify the "version" attribute of the "<package>" element called
"pathspec-py3" in \$FUCHSIA_DIR/manifests/prebuilts
2) Run: \$FUCHSIA_DIR/manifests/update-lockfiles.sh
This verifies that the version exists and updates critical Jiri files.
3) Run: jiri update -local-manifest-project=fuchsia
This installs the new wheel file to \$FUCHSIA_DIR/${SOURCE_SUBDIR}
then runs a hook to update \$FUCHSIA_DIR/${DEST_SUBDIR}
4) Verify that everything works
5) Upload new CL to Gerrit with your modifications.
EOF
echo "Done"
exit 0