From 3a2dc484b51ea438dfcbedde742963d9e0314253 Mon Sep 17 00:00:00 2001 From: Patrick Maslana <79757486+pmaslana@users.noreply.github.com> Date: Wed, 21 Jun 2023 14:51:05 -0700 Subject: [PATCH] Generate a license directory that contains licenses missing from the installers (#15146) * Add scripts to build a tree of licenses that are missing from the installers * Add a line that was accidentally removed * add steps in the build_license_directory script to install pip-licenses and license-checker * Pip install pip-license * Added commands to check the working dir in the build_license_direcotory.sh * Fix the path for the npm commands * Copy the library dir over * Add a line to cd back to the previous dir in the build_licenses_directory.sh file * Fix path to go back to "build_scripts" * Fixing a typo with a path in the build_license_directory.sh file * Troubleshoot path * Change word from library to licenses * Add a command to list contents of "dist/$CLI_DEB_BASE/opt/chia/" for troubleshooting * Copy the license file to the "GUI" directory * Fix the last for loop * Move the step to change directory back to build scripts in the build_license_directory.sh file * Add some more steps to troubleshoot the path and license-checker usage * Fix a typo * Add an "npm install ." before running the license-checker * Fix a typo * Change back to the build_scripts dir before the first loop in build_license_directory.sh file * Revert "Change back to the build_scripts dir before the first loop in build_license_directory.sh file" This reverts commit a3e88a258377f9f12cbc815245d5912e8a6f6258. * Fix the path for moving the license file * Change the first loop for printing licenses from npm license-checker * Add steps to copy the license file over to the builds and comment out the "npm install ." step out of the build_license_firectory script * Add npm ci to the build_license_directory file * Adding a dir for troubleshooting * Fix errors in the scripts * Fix a path to the licenses file * Remove a dir from the windows installer script * Remove a copy command * Remove a few more copy commands * Adding a ps1 script for usage in the windows installer build script * Replace the powershell script * Made a couple changes to the ps1 script for building the license directory * Remove the ps1 script for building the license dir * Add a new script for the windows installer to build the license dir * Fix issues with the code for windows * Remove the -1 from NF * Changing the script for windows to test * Remove filename=$(basename "$i") * Remove some ls command lines * Add "cp -r dist/daemon ../chia-blockchain-gui/packages/gui" to the RPM installer script * Remove "|| 'exit" or "cd' || return" from when CD'ing in the license creation scripts * Remove extra set of || --- build_scripts/build_license_directory.sh | 55 ++++++++++++++++++++ build_scripts/build_linux_deb-2-installer.sh | 7 +++ build_scripts/build_linux_rpm-2-installer.sh | 8 ++- build_scripts/build_macos-2-installer.sh | 8 ++- build_scripts/build_win_license_dir.sh | 54 +++++++++++++++++++ build_scripts/build_windows-2-installer.ps1 | 5 ++ 6 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 build_scripts/build_license_directory.sh create mode 100644 build_scripts/build_win_license_dir.sh diff --git a/build_scripts/build_license_directory.sh b/build_scripts/build_license_directory.sh new file mode 100644 index 000000000000..7650696ad56e --- /dev/null +++ b/build_scripts/build_license_directory.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# PULL IN LICENSES USING NPM - LICENSE CHECKER +npm install -g license-checker + +cd ../chia-blockchain-gui || exit 1 + +npm ci + +sum=$(license-checker --summary) +printf "%s\n" "$sum" + +license_list=$(license-checker --json | jq -r '.[].licenseFile' | grep -v null) + +# Split the license list by newline character into an array +IFS=$'\n' read -rd '' -a licenses_array <<< "$license_list" + +#print the contents of the array +printf '%s\n' "${licenses_array[@]}" + +for i in "${licenses_array[@]}"; do + dirname="licenses/$(dirname "$i" | awk -F'/' '{print $NF}')" + mkdir -p "$dirname" + echo "$dirname" + cp "$i" "$dirname" +done + +mv licenses/ ../build_scripts/dist/daemon +cd ../build_scripts || exit 1 + + +# PULL IN THE LICENSES FROM PIP-LICENSE +pip install pip-licenses || pip3 install pip-licenses + +# capture the output of the command in a variable +output=$(pip-licenses -l -f json | jq -r '.[].LicenseFile' | grep -v UNKNOWN) + +# initialize an empty array +license_path_array=() + +# read the output line by line into the array +while IFS= read -r line; do + license_path_array+=("$line") +done <<< "$output" + +# create a dir for each license and copy the license file over +for i in "${license_path_array[@]}"; do + dirname="dist/daemon/licenses/$(dirname "$i" | awk -F'/' '{print $NF}')" + echo "$dirname" + mkdir -p "$dirname" + cp "$i" "$dirname" + echo "$i" +done + +ls -lah dist/daemon diff --git a/build_scripts/build_linux_deb-2-installer.sh b/build_scripts/build_linux_deb-2-installer.sh index 12da93a0f6d2..de62de714ad7 100644 --- a/build_scripts/build_linux_deb-2-installer.sh +++ b/build_scripts/build_linux_deb-2-installer.sh @@ -44,6 +44,12 @@ if [ "$LAST_EXIT_CODE" -ne 0 ]; then exit $LAST_EXIT_CODE fi +# Creates a directory of licenses +echo "Building pip and NPM license directory" +pwd +bash ./build_license_directory.sh + + # Builds CLI only .deb # need j2 for templating the control file pip install j2cli @@ -53,6 +59,7 @@ mkdir -p "dist/$CLI_DEB_BASE/usr/bin" mkdir -p "dist/$CLI_DEB_BASE/DEBIAN" j2 -o "dist/$CLI_DEB_BASE/DEBIAN/control" assets/deb/control.j2 cp -r dist/daemon/* "dist/$CLI_DEB_BASE/opt/chia/" + ln -s ../../opt/chia/chia "dist/$CLI_DEB_BASE/usr/bin/chia" dpkg-deb --build --root-owner-group "dist/$CLI_DEB_BASE" # CLI only .deb done diff --git a/build_scripts/build_linux_rpm-2-installer.sh b/build_scripts/build_linux_rpm-2-installer.sh index f820a79766ce..77f6a0bee3d4 100644 --- a/build_scripts/build_linux_rpm-2-installer.sh +++ b/build_scripts/build_linux_rpm-2-installer.sh @@ -42,11 +42,17 @@ if [ "$LAST_EXIT_CODE" -ne 0 ]; then exit $LAST_EXIT_CODE fi +# Creates a directory of licenses +echo "Building pip and NPM license directory" +pwd +bash ./build_license_directory.sh + # Builds CLI only rpm CLI_RPM_BASE="chia-blockchain-cli-$CHIA_INSTALLER_VERSION-1.$REDHAT_PLATFORM" mkdir -p "dist/$CLI_RPM_BASE/opt/chia" mkdir -p "dist/$CLI_RPM_BASE/usr/bin" cp -r dist/daemon/* "dist/$CLI_RPM_BASE/opt/chia/" + ln -s ../../opt/chia/chia "dist/$CLI_RPM_BASE/usr/bin/chia" # This is built into the base build image # shellcheck disable=SC1091 @@ -66,9 +72,7 @@ fpm -s dir -t rpm \ --depends /usr/lib64/libcrypt.so.1 \ . # CLI only rpm done - cp -r dist/daemon ../chia-blockchain-gui/packages/gui - # Change to the gui package cd ../chia-blockchain-gui/packages/gui || exit 1 diff --git a/build_scripts/build_macos-2-installer.sh b/build_scripts/build_macos-2-installer.sh index a827e0f811c6..a8f30ce50d16 100644 --- a/build_scripts/build_macos-2-installer.sh +++ b/build_scripts/build_macos-2-installer.sh @@ -32,8 +32,14 @@ if [ "$LAST_EXIT_CODE" -ne 0 ]; then echo >&2 "pyinstaller failed!" exit $LAST_EXIT_CODE fi -cp -r dist/daemon ../chia-blockchain-gui/packages/gui + +# Creates a directory of licenses +echo "Building pip and NPM license directory" +pwd +bash ./build_license_directory.sh + +cp -r dist/daemon ../chia-blockchain-gui/packages/gui # Change to the gui package cd ../chia-blockchain-gui/packages/gui || exit 1 diff --git a/build_scripts/build_win_license_dir.sh b/build_scripts/build_win_license_dir.sh new file mode 100644 index 000000000000..1c59d4ac42fe --- /dev/null +++ b/build_scripts/build_win_license_dir.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +# PULL IN LICENSES USING NPM - LICENSE CHECKER +npm install -g license-checker + +cd ../chia-blockchain-gui || exit 1 + +npm ci + +sum=$(license-checker --summary) +printf "%s\n" "$sum" + +license_list=$(license-checker --json | jq -r '.[].licenseFile' | grep -v null) + +# Split the license list by newline character into an array +IFS=$'\n' read -rd '' -a licenses_array <<< "$license_list" + +#print the contents of the array +printf '%s\n' "${licenses_array[@]}" + +for i in "${licenses_array[@]}"; do + dirname="licenses/$(basename "$(dirname "$i")")" + echo "$dirname" + mkdir -p "$dirname" + cp "$i" "$dirname" +done + +mv licenses/ ../build_scripts/dist/daemon +cd ../build_scripts || exit 1 + +# PULL IN THE LICENSES FROM PIP-LICENSE +pip install pip-licenses || pip3 install pip-licenses + +# capture the output of the command in a variable +output=$(pip-licenses -l -f json | jq -r '.[].LicenseFile' | grep -v UNKNOWN) + +# initialize an empty array +license_path_array=() + +# read the output line by line into the array +while IFS= read -r line; do + license_path_array+=("$line") +done <<< "$output" + +# create a dir for each license and copy the license file over +for i in "${license_path_array[@]}"; do + dirname="dist/daemon/licenses/$(basename "$(dirname "$i")")" + echo "$dirname" + mkdir -p "$dirname" + cp "$i" "$dirname" + echo "$i" +done + +ls -lah dist/daemon diff --git a/build_scripts/build_windows-2-installer.ps1 b/build_scripts/build_windows-2-installer.ps1 index f6a8d9f56245..e4d86884f4a0 100644 --- a/build_scripts/build_windows-2-installer.ps1 +++ b/build_scripts/build_windows-2-installer.ps1 @@ -20,6 +20,11 @@ Write-Output " ---" $SPEC_FILE = (python -c 'import chia; print(chia.PYINSTALLER_SPEC_PATH)') -join "`n" pyinstaller --log-level INFO $SPEC_FILE +Write-Output " ---" +Write-Output "Creating a directory of licenses from pip and npm packages" +Write-Output " ---" +bash ./build_win_license_dir.sh + Write-Output " ---" Write-Output "Copy chia executables to chia-blockchain-gui\" Write-Output " ---"