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