1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0+ 3 4# Packages a U-Boot tool 5# 6# Usage: make_pip.sh <tool_name> [--real] 7# 8# Where tool_name is one of patman, buildman, dtoc, binman, u_boot_pylib 9# 10# and --real means to upload to the real server (otherwise the test one is used) 11# 12# The username for upload is always __token__ so set TWINE_PASSWORD to your 13# password before running this script: 14# 15# export TWINE_PASSWORD=pypi-xxx 16# 17# To test your new packages: 18# 19# pip install -i https://test.pypi.org/simple/ <tool_name> 20# 21 22# DO NOT use patman or binman 23 24set -xe 25 26# Repo to upload to 27repo="--repository testpypi" 28 29# Non-empty to do the actual upload 30upload=1 31 32tool="$1" 33shift 34flags="$*" 35 36if [[ "${tool}" =~ ^(patman|buildman|dtoc|binman|u_boot_pylib)$ ]]; then 37 echo "Building dist package for tool ${tool}" 38else 39 echo "Unknown tool ${tool}: use patman, buildman, dtoc or binman" 40 exit 1 41fi 42 43for flag in "${flags}"; do 44 if [ "${flag}" == "--real" ]; then 45 echo "Using real server" 46 repo= 47 fi 48 if [ "${flag}" == "-n" ]; then 49 echo "Doing dry run" 50 upload= 51 fi 52done 53 54if [ -n "${upload}" ]; then 55 if [ -z "${TWINE_PASSWORD}" ]; then 56 echo "Please set TWINE_PASSWORD to your password and retry" 57 exit 1 58 fi 59fi 60 61# Create a temp dir to work in 62dir=$(mktemp -d) 63 64# Copy in some basic files 65cp -v tools/${tool}/pyproject.toml ${dir} 66cp -v Licenses/gpl-2.0.txt ${dir}/LICENSE 67readme="tools/${tool}/README.*" 68 69# Copy in the README, dropping some Sphinx constructs that PyPi doesn't like 70cat ${readme} | sed -E 's/:(doc|ref):`.*`//; /sectionauthor/d; /toctree::/d' \ 71 > ${dir}/$(basename ${readme}) 72 73# Copy the top-level Python and doc files 74dest=${dir}/src/${tool} 75mkdir -p ${dest} 76cp -v tools/$tool/{*.py,*.rst} ${dest} 77 78# Copy over the subdirectories, including any sub files. Drop any cache files 79# and other such things 80pushd tools/${tool} 81for subdir in $(find . -maxdepth 1 -type d | \ 82 grep -vE "(__pycache__|home|usr|scratch|\.$|pyproject)"); do 83 pathname="${dest}/${subdir}" 84 echo "Copy ${pathname}" 85 cp -a ${subdir} ${pathname} 86done 87popd 88 89# Remove cache files that accidentally made it through 90find ${dest} -name __pycache__ -type f -exec rm {} \; 91find ${dest} -depth -name __pycache__ -exec rmdir 112 \; 92 93# Remove test files 94rm -rf ${dest}/*test* 95 96mkdir ${dir}/tests 97cd ${dir} 98 99# Make sure the tools are up to date 100python3 -m pip install --upgrade build 101python3 -m pip install --upgrade twine 102 103# Build the PyPi package 104python3 -m build 105 106echo "Completed build of ${tool}" 107 108# Use --skip-existing to work even if the version is already present 109if [ -n "${upload}" ]; then 110 echo "Uploading from ${dir}" 111 python3 -m twine upload ${repo} -u __token__ dist/* 112 echo "Completed upload of ${tool}" 113fi 114 115rm -rf "${dir}" 116 117echo -e "done\n\n" 118