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
27 repo="--repository testpypi"
29 # Non-empty to do the actual upload
36 if [[ "${tool}" =~ ^(patman|buildman|dtoc|binman|u_boot_pylib)$ ]]; then
37 echo "Building dist package for tool ${tool}"
39 echo "Unknown tool ${tool}: use patman, buildman, dtoc or binman"
43 for flag in "${flags}"; do
44 if [ "${flag}" == "--real" ]; then
45 echo "Using real server"
48 if [ "${flag}" == "-n" ]; then
54 if [ -n "${upload}" ]; then
55 if [ -z "${TWINE_PASSWORD}" ]; then
56 echo "Please set TWINE_PASSWORD to your password and retry"
61 # Create a temp dir to work in
64 # Copy in some basic files
65 cp -v tools/${tool}/pyproject.toml ${dir}
66 cp -v Licenses/gpl-2.0.txt ${dir}/LICENSE
67 readme="tools/${tool}/README.*"
69 # Copy in the README, dropping some Sphinx constructs that PyPi doesn't like
70 cat ${readme} | sed -E 's/:(doc|ref):`.*`//; /sectionauthor/d; /toctree::/d' \
71 > ${dir}/$(basename ${readme})
73 # Copy the top-level Python and doc files
74 dest=${dir}/src/${tool}
76 cp -v tools/$tool/{*.py,*.rst} ${dest}
78 # Copy over the subdirectories, including any sub files. Drop any cache files
79 # and other such things
81 for 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}
89 # Remove cache files that accidentally made it through
90 find ${dest} -name __pycache__ -type f -exec rm {} \;
91 find ${dest} -depth -name __pycache__ -exec rmdir 112 \;
99 # Make sure the tools are up to date
100 python3 -m pip install --upgrade build
101 python3 -m pip install --upgrade twine
103 # Build the PyPi package
106 echo "Completed build of ${tool}"
108 # Use --skip-existing to work even if the version is already present
109 if [ -n "${upload}" ]; then
110 echo "Uploading from ${dir}"
111 python3 -m twine upload ${repo} -u __token__ dist/*
112 echo "Completed upload of ${tool}"