summaryrefslogtreecommitdiffstats
path: root/scripts/lib/ptxd_make_world_license.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/ptxd_make_world_license.sh')
-rw-r--r--scripts/lib/ptxd_make_world_license.sh341
1 files changed, 317 insertions, 24 deletions
diff --git a/scripts/lib/ptxd_make_world_license.sh b/scripts/lib/ptxd_make_world_license.sh
index 5e590c204..a6743c134 100644
--- a/scripts/lib/ptxd_make_world_license.sh
+++ b/scripts/lib/ptxd_make_world_license.sh
@@ -27,9 +27,11 @@ ptxd_make_world_parse_license_files() {
unset orig_ifs
file=""
+ filename=""
startline="1"
endline="$"
md5=""
+ encoding=""
guess=""
while [ ${#} -ne 0 ]; do
@@ -40,6 +42,9 @@ ptxd_make_world_parse_license_files() {
"file://"*)
file="${arg##file://}"
;;
+ "encoding="*)
+ encoding="${arg##encoding=}"
+ ;;
"beginline="*)
startline="${arg##beginline=}"
;;
@@ -61,7 +66,14 @@ ptxd_make_world_parse_license_files() {
esac
done
- if [ ! -e "${pkg_dir}/${file}" ]; then
+ if [[ "${file}" == /* ]]; then
+ filename="$(basename "${file}")"
+ else
+ filename="${file}"
+ file="${pkg_dir}/${file}"
+ fi
+
+ if [ ! -e "${file}" ]; then
ptxd_bailout "
license file '$(ptxd_print_path "${file}")'
@@ -116,12 +128,22 @@ export -f ptxd_make_latex_escape
ptxd_make_world_license_write() {
local guess
local pkg_chapter="$(ptxd_make_latex_escape ${pkg_label})"
+ local packages_url="${pkg_url}"
+ local packages_md5="${pkg_md5}"
+ local -a flags=( "${!pkg_license_flags[@]}" )
+ local -a index=( "${!pkg_license_flags[@]}" )
+ flags=( "${flags[@]/#/\\nameref\{}" )
+ flags=( "${flags[@]/%/\}}" )
pkg_chapter="${pkg_chapter#host-}"
pkg_chapter="${pkg_chapter#cross-}"
+ index=( "${index[@]/#/\\index[}" )
+ index=( "${index[@]/%/]\{${pkg_chapter}\}}" )
case "${pkg_license}" in
*proprietary*)
pkg_chapter="${pkg_chapter} *** Proprietary License!"
+ packages_url="*not available*"
+ packages_md5="*not available*"
;;
*unknown*)
pkg_chapter="${pkg_chapter} *** Unknown License!"
@@ -136,69 +158,276 @@ ptxd_make_world_license_write() {
\chapter{${pkg_chapter}\label{${pkg_label}}}
\begin{description}
- \item[Package:] $(ptxd_make_latex_escape ${pkg_label}) $(ptxd_make_latex_escape ${pkg_version})
- \item[License:] $(ptxd_make_latex_escape ${pkg_license})
- \item[URL:] \begin{flushleft}$(ptxd_make_latex_escape ${pkg_url})\end{flushleft}
- \item[MD5:] {\ttfamily ${pkg_md5}}
+ \item[Package:] $(ptxd_make_latex_escape "${pkg_label}") $(ptxd_make_latex_escape "${pkg_version}")
+ \item[License:] $(ptxd_make_latex_escape "${pkg_license}")
+ \iflicensereport
+ ${index[*]}
+ \item[Flags:] $(ptxd_make_latex_escape "${flags[*]}")
+ \item[URL:] \begin{flushleft}$(ptxd_make_latex_escape "${packages_url}")\end{flushleft}
+ \item[MD5:] {\ttfamily ${packages_md5}}
+ \fi
\end{description}
EOF
if [ -n "${pkg_dot}" ]; then
cat <<- EOF
+ \iflicensereport
\begin{figure}[!ht]
\centering
\hspace*{-0.5in}\maxsizebox{0.9\paperwidth}{!}{
- \input{${pkg_tex}}}
- \caption{Dependency tree for $(ptxd_make_latex_escape ${pkg_label})}
+ \input{${pkg_tex#${ptx_report_dir}/}}}
+ \caption{Dependency tree for $(ptxd_make_latex_escape "${pkg_label}")}
\label{${pkg_label}-deps}
\end{figure}
+ \fi
EOF
fi
for license in "${pkg_license_texts[@]}" - "${pkg_license_texts_guessed[@]}"; do
if [ "${license}" = "-" ]; then
- guess=" [automatically found]"
+ guess="\iflicensereport [automatically found]\fi"
continue
fi
title="$(basename "${license}")"
cat <<- EOF
- \section{$(ptxd_make_latex_escape ${title})${guess}}
- \begin{lstlisting}
+ \section{$(ptxd_make_latex_escape "${title}")${guess}}
+ \begin{small}
+ \begin{spverbatim}
EOF
- cat "${license}" | sed -e 's/\f/\n/g'
+ if [ -f "${license}.utf-8" ]; then
+ cat "${license}.utf-8"
+ else
+ cat "${license}"
+ fi | sed -e 's/\f/\n/g'
+ check_pipe_status || return
cat <<- EOF
- \end{lstlisting}
+ \end{spverbatim}
+ \end{small}
EOF
done
}
export -f ptxd_make_world_license_write
+# Copy all patches according to the series file
+# $1 full path to the series file
+# $2 source directory
+# $3 destination directory
+#
+ptxd_make_world_copy_patch_files() {
+ local patch para junk
+
+ echo -n "Copy patches for package: '${pkg_label}'..."
+ while read patch para junk; do
+ local cat
+
+ case "${patch}" in
+ ""|"#"*) continue ;; # skip empty lines and comments
+ *) ;;
+ esac
+
+ cp ${2}/${patch} ${3} && check_pipe_status || return
+ pushd "${3}" > /dev/null &&
+ md5sum ${patch} >> MD5SUM 2>/dev/null &&
+ popd > /dev/null &&
+# copy only the plain content without the metadata
+ echo "${patch}" >> "${3}/series"
+ done < "${1}"
+ pushd "${3}" > /dev/null &&
+ md5sum series >> MD5SUM 2>/dev/null &&
+ popd > /dev/null &&
+ echo "done"
+
+ return 0
+}
+export -f ptxd_make_world_copy_patch_files
+
+#
+# If the package was patched, ensure the patches are part of the release report
+# $1 path to the extracted and patched sources [1]
+# $2 base directory where to copy the patches to (without the trailing 'patches')
+#
+# [1] assumed here is the existance of the '.ptxdist' directory which contains
+# the selected patch stack if any
+ptxd_make_world_copy_patches() {
+ local patches_directory=""
+ local series_file=""
+
+ if [ -d "${1}/.ptxdist" ]; then
+ if [ -d "${1}/.ptxdist/patches" ]; then
+ patches_directory=`readlink -n "${1}/.ptxdist/patches"`
+ series_file=`readlink -n "${1}/.ptxdist/series"`
+ if [ -d ${patches_directory} ]; then
+ mkdir -p "${2}/patches" &&
+ ptxd_make_world_copy_patch_files "${series_file}" "${patches_directory}" "${2}/patches" ||
+ ptxd_bailout "
+
+Failed to copy the required patches from '${patches_directory}' to '${2}/patches'.
+"
+ fi
+ else
+ ptxd_bailout "
+
+Patched sources do not follow the PTXdist style. '${1}/.ptxdist/patches' not found.
+"
+ fi
+ fi
+
+ return 0
+}
+export -f ptxd_make_world_copy_patches
+
+#
+# Define a section the license type falls in
+# $1 License string or list of license strings from the package's rule file
+#
+ptxd_create_section_from_license()
+{
+ local -A section
+ local orig_IFS="${IFS}"
+ IFS=$', '
+
+ for license in ${1}; do
+ local osi="false"
+ local exception="false"
+ # remove the 'or later' modifier
+ license="${license%+}"
+ if ptxd_make_spdx "${license}"; then
+ if [ "${osi}" == "true" ]; then
+ section[osi-conform]="true"
+ elif [ "${exception}" != "true" ]; then
+ section[misc]="true"
+ fi
+ continue;
+ fi
+ case "${license}" in
+ *proprietary*)
+ section[proprietary]="true"
+ ;;
+ *unknown*)
+ section[unknown]="true"
+ ;;
+ public_domain)
+ section[public_domain]="true"
+ ;;
+ ignore) # META packages
+ echo ignore
+ return 0
+ ;;
+ *)
+ section[other]="true"
+ ;;
+ esac
+ done
+
+ IFS="${orig_IFS}"
+
+ if [ ${#section[@]} -eq 1 ]; then
+ echo "${!section[@]}"
+ return 0
+ fi
+ if [ "${section[other]}" = "true" ]; then
+ echo "other"
+ else
+ echo "mixed"
+ fi
+ return 0
+}
+export -f ptxd_create_section_from_license
+
+ptxd_make_world_license_add_flag() {
+ local flag="${1}"
+
+ pkg_license_flags["${flag}"]="true"
+ shopt -s extglob
+ pkg_license="${pkg_license/*([, ])${flag}}"
+ shopt -u extglob
+}
+export -f ptxd_make_world_license_add_flag
+
+ptxd_make_world_license_flags() {
+ local orig_IFS="${IFS}"
+ IFS=$', '
+
+ for license in ${pkg_license}; do
+ case "${license}" in
+ *proprietary*)
+ ptxd_make_world_license_add_flag nosource
+ ptxd_make_world_license_add_flag nopatches
+ ;;
+ BSD-*-Clause*|MIT*|X11|Apache-*)
+ ptxd_make_world_license_add_flag attribution
+ ;;
+ nosource|nopatches|attribution)
+ ptxd_make_world_license_add_flag "${license}"
+ ;;
+ esac
+ done
+
+ IFS="${orig_IFS}"
+}
+export -f ptxd_make_world_license_flags
+
+ptxd_make_world_license_init() {
+ ptxd_make_world_init || return
+
+ local name
+
+ pkg_license="${pkg_license:-unknown}"
+
+ ptxd_make_world_license_flags || return
+
+ pkg_section="$(ptxd_create_section_from_license "${pkg_license}")"
+
+ name="${pkg_label#host-}"
+ name="${name#cross-}"
+
+ pkg_license_dir="${ptx_report_dir}/${pkg_section}/${pkg_label}"
+ pkg_release_dir="${ptx_release_dir}/${pkg_section}/${name}"
+}
+export -f ptxd_make_world_license_init
#
# extract and process all available license information
#
ptxd_make_world_license() {
- ptxd_make_world_init || return
+ declare -A pkg_license_flags
+ ptxd_make_world_license_init || return
local arg
- local -a ptxd_reply
local -a pkg_license_texts
local -a pkg_license_texts_guessed
- local pkg_dot=${pkg_license_dir}/graph.dot
- local pkg_tex=${pkg_license_dir}/graph.tex
- pkg_license="${pkg_license:-unknown}"
+ local pkg_dot
+ local pkg_tex
+ local pkg_dot="${pkg_license_dir}/graph.dot"
+ local pkg_tex="${pkg_license_dir}/graph.tex"
+
+
+ rm -rf "${pkg_license_dir}" || return
+
+ if [ "${pkg_section}" == "ignore" ]; then
+ echo "Package to be ignored: metapackage for example"
+ return 0
+ fi
- rm -rf "${pkg_license_dir}" &&
- mkdir -p "${pkg_license_dir}" &&
+ mkdir -p ${pkg_license_dir} &&
+ echo ${pkg_section}/${pkg_label} >> "${ptx_report_dir}/package.list" &&
- ptxd_make_world_license_expand
+ ptxd_make_world_license_expand &&
+ if [ -n "${pkg_license_files}" ]; then
+ mkdir -p "${pkg_license_dir}/license"
+ fi &&
+
+ echo "Copy licenses for package: '${pkg_section}/${pkg_label}'..." &&
for arg in ${pkg_license_files}; do
local file startline endline md5 guess
ptxd_make_world_parse_license_files "${arg}" &&
- local lic="${pkg_license_dir}/${file//\//_}" &&
- sed -n "${startline},${endline}p" "${pkg_dir}/${file}" > "${lic}" &&
+ local lic="${pkg_license_dir}/license/${filename//\//_}" &&
+ sed -n "${startline},${endline}p" "${file}" > "${lic}" &&
+ if [ -n "${encoding}" ]; then
+ iconv -f "${encoding}" -t "utf-8" -o "${lic}.utf-8" "${lic}"
+ fi &&
if ! echo "${md5} ${lic}" | md5sum --check > /dev/null 2>&1; then
ptxd_bailout "
@@ -207,16 +436,80 @@ checksum of license file '$(ptxd_print_path "${file}")'
changed: ${md5} -> $(md5sum "${lic}" | sed 's/ .*//')
"
fi &&
+ (
+ cd "${pkg_license_dir}/license" &&
+ md5sum `basename ${lic}` >> MD5SUM 2>/dev/null
+ ) &&
if [ -z "${guess}" ]; then
pkg_license_texts[${#pkg_license_texts[@]}]="${lic}"
else
pkg_license_texts_guessed[${#pkg_license_texts_guessed[@]}]="${lic}"
- fi
+ fi ||
+ ptxd_bailout "Failed to copy '$(ptxd_print_path "${file}")'"
done &&
ptxd_make_world_license_write | \
sed -e 's/%/\\%/g' > "${pkg_license_dir}/license-report.tex" &&
+ check_pipe_status &&
- echo "${pkg_license}" > "${pkg_license_dir}/license-name"
+ echo "${pkg_license}" > "${pkg_license_dir}/license-name" &&
+ if [ "${#pkg_license_flags[@]}" -gt 0 ]; then
+ echo "${!pkg_license_flags[@]}" > "${pkg_license_dir}/license-flags"
+ fi
}
export -f ptxd_make_world_license
+
+ptxd_make_world_release() {
+ declare -A pkg_license_flags
+ ptxd_make_world_license_init || return
+ local src
+
+ rm -rf "${pkg_release_dir}" || return
+
+ if [ "${pkg_license_flags[nosource]}" = "true" ]; then
+ echo "Package to be ignored: source release disabled"
+ echo
+ return
+ fi
+
+ mkdir -p ${pkg_release_dir} &&
+
+ # BSP local packages do not have ${pkg_srcs} filled
+ if [[ -z "${pkg_srcs}" && "${pkg_url}" =~ "file://${PTXDIST_WORKSPACE}" && -f "${pkg_url#file://}" ]]; then
+ # Use the URL for local archives
+ pkg_srcs="${pkg_url#file://}"
+ fi
+ if [ -z "${pkg_srcs}" ]; then
+ if [ -z "${pkg_url}" ]; then
+ # FIXME no sources! This is an error
+ # does not work, since some packages (udev for example, refer to systemd and has no own sources)
+ echo "Error: unable to detect source files/archives for package '${pkg_label}'" > "${pkg_release_dir}/source"
+ else
+ if [[ "${pkg_url}" =~ "file://${PTXDIST_WORKSPACE}" ]]; then
+ echo "Note: this package has BSP internal source code" > "${pkg_release_dir}/source"
+ else
+ if [[ "${pkg_url}" =~ "lndir://${PTXDIST_WORKSPACE}" ]]; then
+ echo "Note: this package has BSP internal source code" > "${pkg_release_dir}/source"
+ else
+ echo "Warning: direct/plain sources outside the BSP are unsupported!" > "${pkg_release_dir}/source"
+ fi
+ fi
+ fi
+ else
+ for src in ${pkg_srcs}; do
+ # copy only if required
+ echo -n "Copy sources for package: '${pkg_label}', source: '$(basename "${src}")'..." &&
+ mkdir -p "${pkg_release_dir}/source" &&
+ cp ${src} "${pkg_release_dir}/source" &&
+ (
+ cd "${pkg_release_dir}/source" &&
+ md5sum `basename "${src}"` >> MD5SUM
+ ) &&
+ echo " done" || break
+ done
+ if [ "${pkg_license_flags[nopatches]}" != "true" ]; then
+ ptxd_make_world_copy_patches "${pkg_dir}" "${pkg_release_dir}"
+ fi
+ fi
+}
+export -f ptxd_make_world_release