scripts: Fix to not skip some option parameters for rpi4 fusing script
[platform/kernel/u-boot.git] / scripts / make_pip.sh
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
24 set -xe
25
26 # Repo to upload to
27 repo="--repository testpypi"
28
29 # Non-empty to do the actual upload
30 upload=1
31
32 tool="$1"
33 shift
34 flags="$*"
35
36 if [[ "${tool}" =~ ^(patman|buildman|dtoc|binman|u_boot_pylib)$ ]]; then
37         echo "Building dist package for tool ${tool}"
38 else
39         echo "Unknown tool ${tool}: use patman, buildman, dtoc or binman"
40         exit 1
41 fi
42
43 for 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
52 done
53
54 if [ -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
59 fi
60
61 # Create a temp dir to work in
62 dir=$(mktemp -d)
63
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.*"
68
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})
72
73 # Copy the top-level Python and doc files
74 dest=${dir}/src/${tool}
75 mkdir -p ${dest}
76 cp -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
80 pushd tools/${tool}
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}
86 done
87 popd
88
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 \;
92
93 # Remove test files
94 rm -rf ${dest}/*test*
95
96 mkdir ${dir}/tests
97 cd ${dir}
98
99 # Make sure the tools are up to date
100 python3 -m pip install --upgrade build
101 python3 -m pip install --upgrade twine
102
103 # Build the PyPi package
104 python3 -m build
105
106 echo "Completed build of ${tool}"
107
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}"
113 fi
114
115 rm -rf "${dir}"
116
117 echo -e "done\n\n"