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
32 # Non-empty to delete files used for testing
39 if [[ "${tool}" =~ ^
(patman|buildman|dtoc|binman|u_boot_pylib
)$
]]; then
40 echo "Building dist package for tool ${tool}"
42 echo "Unknown tool ${tool}: use u_boot_pylib, patman, buildman, dtoc or binman"
46 for flag
in "${flags}"; do
47 if [ "${flag}" == "--real" ]; then
48 echo "Using real server"
51 if [ "${flag}" == "-n" ]; then
57 if [ -n "${upload}" ]; then
58 if [ -z "${TWINE_PASSWORD}" ]; then
59 echo "Please set TWINE_PASSWORD to your password and retry"
64 if [[ "${tool}" =~ ^
(patman|u_boot_pylib
)$
]]; then
65 # Leave test_util.py and patman test files alone
69 # Create a temp dir to work in
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}
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
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}
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 \
;
102 if [ -n "${delete_testfiles}" ]; then
103 rm -rfv ${dest}/*test*
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
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}"