diff --git a/jsk_unitree_robot/cross/Makefile b/jsk_unitree_robot/cross/Makefile index e942246cf6..7a05f06953 100644 --- a/jsk_unitree_robot/cross/Makefile +++ b/jsk_unitree_robot/cross/Makefile @@ -20,6 +20,9 @@ user: install: ./install.sh +compress: + ./compress.sh + clean: rm -fr ${TARGET_MACHINE}_ws_* diff --git a/jsk_unitree_robot/cross/build_ros1.sh b/jsk_unitree_robot/cross/build_ros1.sh index e7d1cde8e0..c9ed426547 100755 --- a/jsk_unitree_robot/cross/build_ros1.sh +++ b/jsk_unitree_robot/cross/build_ros1.sh @@ -1,5 +1,6 @@ #!/bin/bash +IMAGE_NAME="${IMAGE_NAME:-ros1-unitree}" TARGET_MACHINE="${TARGET_MACHINE:-arm64v8}" HOST_INSTALL_ROOT="${BASE_ROOT:-${PWD}}/"${TARGET_MACHINE}_System INSTALL_ROOT=System @@ -31,9 +32,12 @@ mkdir -p ${SOURCE_ROOT}/src mkdir -p ${HOST_INSTALL_ROOT}/ros1_inst if [ ${UPDATE_SOURCE_ROOT} -eq 1 ]; then + vcs import --force --retry 10 --shallow ${SOURCE_ROOT}/src < repos/catkin_virtualenv.repos vcs import --force --retry 10 --shallow ${SOURCE_ROOT}/src < repos/roseus_no_window.repos for dir in euslisp jskeus; do ls ${SOURCE_ROOT}/src/$dir/patches/; rsync -avz ${SOURCE_ROOT}/src/$dir/patches/ ${SOURCE_ROOT}/src/$dir; done - sed -i s@:{version}@0.0.0@ ${SOURCE_ROOT}/src/euslisp/package.xml ${SOURCE_ROOT}/src/jskeus/package.xml + # linux can use sed -i'.bak' and latest mac also supports same syntax. + # https://stackoverflow.com/questions/4247068/sed-command-with-i-option-failing-on-mac-but-works-on-linux/14813278#14813278 + sed -i.bak s@:{version}@0.0.0@ ${SOURCE_ROOT}/src/euslisp/package.xml ${SOURCE_ROOT}/src/jskeus/package.xml fi wget https://patch-diff.githubusercontent.com/raw/PR2/pr2_mechanism/pull/346.diff -O ${SOURCE_ROOT}/pr2_mechanism-346.diff @@ -47,14 +51,16 @@ DIAGNOSTIC_AGGREGATOR="diagnostic_aggregator" # jsk_XXX_startup usually depends PR2EUS="pr2eus" docker run -it --rm \ - -u $(id -u $USER) \ + -e HOST_UID=$(id -u) -e HOST_GID=$(id -g) \ -e INSTALL_ROOT=${INSTALL_ROOT} \ -e MAKEFLAGS=${MAKEFLAGS} \ -v ${HOST_INSTALL_ROOT}/ros1_dependencies:/opt/jsk/${INSTALL_ROOT}/ros1_dependencies:ro \ -v ${HOST_INSTALL_ROOT}/ros1_dependencies_setup.bash:/opt/jsk/${INSTALL_ROOT}/ros1_dependencies_setup.bash:ro \ + -v ${PWD}/startup_scripts/usercustomize.py:/home/user/.local/lib/python2.7/site-packages/usercustomize.py:ro \ + -v ${PWD}/startup_scripts/usercustomize.py:/home/user/.local/lib/python3.6/site-packages/usercustomize.py:ro \ -v ${HOST_INSTALL_ROOT}/ros1_inst:/opt/jsk/${INSTALL_ROOT}/ros1_inst:rw \ -v ${PWD}/${SOURCE_ROOT}:/home/user/${SOURCE_ROOT}:rw \ - ros1-unitree:${TARGET_MACHINE} \ + ${IMAGE_NAME}:${TARGET_MACHINE} \ bash -c "\ source /opt/jsk/System/ros1_dependencies_setup.bash && \ source /opt/ros/melodic/setup.bash && \ @@ -70,4 +76,7 @@ docker run -it --rm \ -DEUSLISP_WITHOUT_DISPLAY=TRUE -DDISABLE_DOCUMENTATION=1 \ " 2>&1 | tee ${TARGET_MACHINE}_build_ros1.log -cp ${PWD}/startup_scripts/system_setup.bash ${HOST_INSTALL_ROOT}/ +for file in system_setup.bash usercustomize.py; do + [ -d ${HOST_INSTALL_ROOT}/$file ] && rmdir ${HOST_INSTALL_ROOT}/$file + cp ${PWD}/startup_scripts/$file ${HOST_INSTALL_ROOT}/ +done diff --git a/jsk_unitree_robot/cross/build_ros1_dependencies.sh b/jsk_unitree_robot/cross/build_ros1_dependencies.sh index 05f70d65ad..1a988ff417 100755 --- a/jsk_unitree_robot/cross/build_ros1_dependencies.sh +++ b/jsk_unitree_robot/cross/build_ros1_dependencies.sh @@ -1,5 +1,6 @@ #!/bin/bash +IMAGE_NAME="${IMAGE_NAME:-ros1-unitree}" TARGET_MACHINE="${TARGET_MACHINE:-arm64v8}" HOST_INSTALL_ROOT="${BASE_ROOT:-${PWD}}/"${TARGET_MACHINE}_System INSTALL_ROOT=System @@ -27,23 +28,24 @@ mkdir -p ${HOST_INSTALL_ROOT}/Python cp repos/go1_requirements.txt ${SOURCE_ROOT}/go1_requirements.txt docker run -it --rm \ - -u $(id -u $USER) \ + -e HOST_UID=$(id -u) -e HOST_GID=$(id -g) \ -e INSTALL_ROOT=${INSTALL_ROOT} \ -e MAKEFLAGS=${MAKEFLAGS} \ -v ${PWD}/ros1_dependencies_build_scripts:/home/user/ros1_dependencies_build_scripts:ro \ -v ${PWD}/${SOURCE_ROOT}:/home/user/ros1_dependencies_sources:rw \ -v ${HOST_INSTALL_ROOT}/ros1_dependencies:/opt/jsk//${INSTALL_ROOT}/ros1_dependencies:rw \ -v ${HOST_INSTALL_ROOT}/Python:/opt/jsk/${INSTALL_ROOT}/Python:rw \ - ros1-unitree:${TARGET_MACHINE} \ + ${IMAGE_NAME}:${TARGET_MACHINE} \ bash -c "\ set -xeuf -o pipefail && \ cd /home/user/ros1_dependencies_sources && \ vcs import --skip-existing --retry 10 --shallow src < ros1_dependencies.repos && \ for script_file in \$(ls /home/user/ros1_dependencies_build_scripts/|sort); do + [ -e /home/user/ros1_dependencies_sources/\$script_file.installed ] && continue; /home/user/ros1_dependencies_build_scripts/\$script_file || exit 1; + touch /home/user/ros1_dependencies_sources/\$script_file.installed; done && \ pip install -U --user pip && \ - export PYTHONPATH=\"/opt/jsk/System/ros1_dependencies/lib/python2.7/site-packages\" && \ export PKG_CONFIG_PATH=\"/opt/jsk/${INSTALL_ROOT}/ros1_dependencies/lib/pkgconfig\" && \ ~/.local/bin/pip install --prefix=/opt/jsk/${INSTALL_ROOT}/Python -r /home/user/ros1_dependencies_sources/go1_requirements.txt \ " 2>&1 | tee ${TARGET_MACHINE}_build_ros1_dependencies.log diff --git a/jsk_unitree_robot/cross/build_user.sh b/jsk_unitree_robot/cross/build_user.sh index f18831c411..2dcd963351 100755 --- a/jsk_unitree_robot/cross/build_user.sh +++ b/jsk_unitree_robot/cross/build_user.sh @@ -1,5 +1,6 @@ #!/bin/bash +IMAGE_NAME="${IMAGE_NAME:-ros1-unitree}" TARGET_MACHINE="${TARGET_MACHINE:-arm64v8}" HOST_INSTALL_ROOT="${BASE_ROOT:-${PWD}}/"${TARGET_MACHINE}_System INSTALL_ROOT=System @@ -39,20 +40,22 @@ done # check if /proc/sys/fs/binfmt_misc/qemu-* is updated # See https://github.com/k-okada/jsk_robot/issues/61 -docker run -it --rm ros1-unitree:${TARGET_MACHINE} bash -c 'exit' || docker run --rm --privileged multiarch/qemu-user-static --reset -p yes +docker run -it --rm -e HOST_UID=$(id -u) -e HOST_GID=$(id -g) ${IMAGE_NAME}:${TARGET_MACHINE} bash -c 'exit' || docker run --rm --privileged multiarch/qemu-user-static --reset -p yes # run on docker docker run -it --rm \ - -u $(id -u $USER) \ + -e HOST_UID=$(id -u) -e HOST_GID=$(id -g) \ -e INSTALL_ROOT=${INSTALL_ROOT} \ -v ${HOST_INSTALL_ROOT}/ros1_dependencies:/opt/jsk/${INSTALL_ROOT}/ros1_dependencies:ro \ -v ${HOST_INSTALL_ROOT}/Python:/opt/jsk/${INSTALL_ROOT}/Python:ro \ -v ${HOST_INSTALL_ROOT}/ros1_inst:/opt/jsk/${INSTALL_ROOT}/ros1_inst:ro \ -v ${HOST_INSTALL_ROOT}/ros1_dependencies_setup.bash:/opt/jsk/${INSTALL_ROOT}/ros1_dependencies_setup.bash:ro \ -v ${HOST_INSTALL_ROOT}/system_setup.bash:/opt/jsk/${INSTALL_ROOT}/system_setup.bash:ro \ + -v ${PWD}/startup_scripts/usercustomize.py:/home/user/.local/lib/python2.7/site-packages/usercustomize.py:ro \ + -v ${PWD}/startup_scripts/usercustomize.py:/home/user/.local/lib/python3.6/site-packages/usercustomize.py:ro \ -v ${PWD}/${SOURCE_ROOT}:/opt/jsk/User:rw \ -v ${PWD}/rosinstall_generator_unreleased.py:/home/user/rosinstall_generator_unreleased.py:ro \ - ros1-unitree:${TARGET_MACHINE} \ + ${IMAGE_NAME}:${TARGET_MACHINE} \ bash -c "\ source /opt/jsk/System/system_setup.bash && \ env && \ diff --git a/jsk_unitree_robot/cross/compress.sh b/jsk_unitree_robot/cross/compress.sh new file mode 100755 index 0000000000..e506ab71d8 --- /dev/null +++ b/jsk_unitree_robot/cross/compress.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +if [ -e "arm64v8_User" ]; then + if [ -e "arm64v8_User.tgz" ]; then + echo "WARNING: Compressed arm64v8_User.tgz is found." + read -p "WARNING: Are you sure to continue [y/N] ? " -n 1 -r + echo # (optional) move to a new line + if [[ $REPLY =~ ^[Yy]$ ]]; then + tar -zcvf arm64v8_User.tgz arm64v8_User + fi + else + tar -zcvf arm64v8_User.tgz arm64v8_User + fi +fi + +if [ -e "arm64v8_System" ]; then + if [ -e "arm64v8_System.tgz" ]; then + echo "WARNING: Compressed arm64v8_System.tgz is found." + read -p "WARNING: Are you sure to continue [y/N] ? " -n 1 -r + echo # (optional) move to a new line + if [[ $REPLY =~ ^[Yy]$ ]]; then + chmod 644 arm64v8_System/ros1_inst/share/pr2eus/*.l + tar -zcvf arm64v8_System.tgz arm64v8_System + fi + else + chmod 644 arm64v8_System/ros1_inst/share/pr2eus/*.l + tar -zcvf arm64v8_System.tgz arm64v8_System + fi +fi diff --git a/jsk_unitree_robot/cross/docker/Dockerfile_ros1 b/jsk_unitree_robot/cross/docker/Dockerfile_ros1 index 7de759b9d3..0936a7d68f 100644 --- a/jsk_unitree_robot/cross/docker/Dockerfile_ros1 +++ b/jsk_unitree_robot/cross/docker/Dockerfile_ros1 @@ -31,19 +31,18 @@ RUN git clone https://github.com/k-okada/rosinstall_generator /tmp/rosinstall_ge RUN pip install /tmp/rosinstall_generator RUN apt install -y python3-vcstool # -# Setup Users +# add tool for users # -ARG UID=1000 RUN apt-get install -y sudo -RUN useradd --uid $UID -ms /bin/bash -G sudo user -RUN newgrp -RUN echo user:user | chpasswd # # Remove packages is not found on 161 # RUN dpkg -r --force-depends cython gir1.2-gstreamer-1.0 libtinyxml-dev python-attr python-autobahn python-automat python-cbor python-concurrent.futures python-constantly python-constantly python-incremental python-lz4 python-nacl python-pyasn1 python-pyasn1-modules python-qrcode python-service-identity python-snappy python-trie python-trollius python-twisted-bin python-twisted-core python-twisted python-txaio python-ubjson python-u-msgpack python-wsaccel python-zope.interface # +# Add cython, which we need to compile packages with catkin_virtualenv, not sure why 1049-cython works... +RUN (cd /tmp; apt download cython && dpkg --force-depends -i cython_*.deb) # # -WORKDIR /home/user -USER user +ADD entrypoint.sh / +RUN chmod +x /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/jsk_unitree_robot/cross/docker/entrypoint.sh b/jsk_unitree_robot/cross/docker/entrypoint.sh new file mode 100644 index 0000000000..52e76e91f8 --- /dev/null +++ b/jsk_unitree_robot/cross/docker/entrypoint.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +function fail { + printf '\033[31m%s\033[0m\n' "$1" >&2 ## Send message to stderr. + exit "${2-1}" ## Return a code specified by $2, or 1 by default. +} +[ -z "${HOST_UID}" ] && fail "ERROR: HOST_UID is requried, add '-e HOST_UID=$(id -u)' to your docker commandline option" +[ -z "${HOST_GID}" ] && fail "ERROR: HOST_GID is requried, add '-e HOST_GID=$(id -g)' to your docker commandline option" + +# create user with same UID as the host user +# -g The numerical value of the group's ID. +groupadd -g $HOST_GID user +# -u The numerical value of the user's ID. +# -o Allow the creation of a user account with a duplicate (non-unique) UID. +# -m Create the user's home directory if it does not exist. +# -g The group name or number of the user's initial login group. +# -s The name of the user's login shell. +useradd -u $HOST_UID -o -m -g $HOST_GID -s /usr/bin user -G sudo +echo user:user | chpasswd +export HOME=/home/user +chown $HOST_UID:$HOST_GID $HOME +cd $HOME + +runuser -u user -- "$@" diff --git a/jsk_unitree_robot/cross/install.sh b/jsk_unitree_robot/cross/install.sh index 2ac8a123f4..4ef698f5af 100755 --- a/jsk_unitree_robot/cross/install.sh +++ b/jsk_unitree_robot/cross/install.sh @@ -54,7 +54,9 @@ function copy_data () { fi # Check if robot is reachable - reachability=$(LANG=C ping -c4 ${hostname} 2>/dev/null | awk '/---/,0' | grep -Po '[0-9]{1,3}(?=% packet loss)') + # Use perl instead of `grep -Po '[0-9]{1,3}(?=% packet loss)'` for Mac environment. + # See https://stackoverflow.com/questions/16658333/grep-p-no-longer-works-how-can-i-rewrite-my-searches/16658690#16658690 + reachability=$(LANG=C ping -c4 ${hostname} 2>/dev/null | awk '/---/,0' | perl -nle'print $& while m{[0-9]{1,3}(?=% packet loss)}g') if [ -z "$reachability" ] || [ "$reachability" == 100 ]; then echo "ERROR: ${hostname} unreachable" 1>&2 exit 2 @@ -64,6 +66,12 @@ function copy_data () { ssh-keygen -f "${HOME}/.ssh/known_hosts" -R "${hostname}" || echo "OK" sshpass -p $PASS ssh -o StrictHostKeyChecking=no ${user}@${hostname} exit + if [[ "${TARGET_DIRECTORY}" == "System" ]]; then + sshpass -p 123 scp ${TARGET_MACHINE}_${TARGET_DIRECTORY}/usercustomize.py ${user}@${hostname}:/tmp/usercustomize.py + sshpass -p $PASS ssh -t ${user}@${hostname} "mkdir -p ~/.local/lib/python2.7/site-packages/; cp -f /tmp/usercustomize.py .local/lib/python2.7/site-packages/" + sshpass -p $PASS ssh -t ${user}@${hostname} "mkdir -p ~/.local/lib/python3.6/site-packages/; cp -f /tmp/usercustomize.py .local/lib/python3.6/site-packages/" + fi + # cehck disk space echo "Copy ${TARGET_MACHINE}_${TARGET_DIRECTORY} ...." echo "===" @@ -108,15 +116,15 @@ function copy_data () { # update udev # respeaker_ros - sshpass -p $PASS ssh -t ${user}@${hostname} "source /opt/jsk/User/user_setup.bash; sudo cp -f \$(rospack find respeaker_ros)/config/60-respeaker.rules /etc/udev/rules.d/60-respeaker.rules" + sshpass -p $PASS ssh -t ${user}@${hostname} "source /opt/jsk/User/user_setup.bash; echo $PASS | sudo cp -f \$(rospack find respeaker_ros)/config/60-respeaker.rules /etc/udev/rules.d/60-respeaker.rules" # - sshpass -p $PASS ssh -t ${user}@${hostname} "ls -al /etc/udev/rules.d/; sudo systemctl restart udev" + sshpass -p $PASS ssh -t ${user}@${hostname} "ls -al /etc/udev/rules.d/; echo $PASS | sudo systemctl restart udev" fi # enable Internet with USB LTE module if [[ "${hostname}" == "192.168.123.161" ]]; then - sshpass -p $PASS ssh -t ${user}@${hostname} "source /opt/jsk/User/user_setup.bash; sudo cp -f \$(rospack find jsk_unitree_startup)/config/dhcpcd.conf /etc/dhcpcd.conf" - sshpass -p $PASS ssh -t ${user}@${hostname} "sudo systemctl restart dhcpcd" + sshpass -p $PASS ssh -t ${user}@${hostname} "export PATH=\$PATH:/sbin; source /opt/jsk/User/user_setup.bash; echo $PASS | sudo cp -f \$(rospack find jsk_unitree_startup)/config/dhcpcd.conf /etc/dhcpcd.conf" + sshpass -p $PASS ssh -t ${user}@${hostname} "echo $PASS | sudo systemctl restart dhcpcd" fi set +x } diff --git a/jsk_unitree_robot/cross/prepare_requirements_ros1.sh b/jsk_unitree_robot/cross/prepare_requirements_ros1.sh index 110d88651c..2aae00838c 100755 --- a/jsk_unitree_robot/cross/prepare_requirements_ros1.sh +++ b/jsk_unitree_robot/cross/prepare_requirements_ros1.sh @@ -1,5 +1,6 @@ #!/bin/bash +IMAGE_NAME="${IMAGE_NAME:-ros1-unitree}" TARGET_MACHINE="${TARGET_MACHINE:-arm64v8}" HOST_INSTALL_ROOT="${BASE_ROOT:-${PWD}}/"System INSTALL_ROOT=System @@ -14,4 +15,4 @@ if [ -e /proc/sys/fs/binfmt_misc/qemu-aarch64 ] && [ ! "$(docker images -q mult docker run --rm --privileged multiarch/qemu-user-static --reset -p yes fi -docker buildx build $@ --progress plain -t ros1-unitree:${TARGET_MACHINE} --build-arg TARGET_MACHINE=${TARGET_MACHINE} --build-arg UID=$(id -u $USER) -f docker/Dockerfile_ros1 docker/ 2>&1 | tee ${TARGET_MACHINE}_prepare_requirements_ros1.log +docker buildx build $@ --progress plain -t ${IMAGE_NAME}:${TARGET_MACHINE} --build-arg TARGET_MACHINE=${TARGET_MACHINE} --build-arg UID=$(id -u $USER) -f docker/Dockerfile_ros1 docker/ 2>&1 | tee ${TARGET_MACHINE}_prepare_requirements_ros1.log diff --git a/jsk_unitree_robot/cross/repos/catkin_virtualenv.repos b/jsk_unitree_robot/cross/repos/catkin_virtualenv.repos new file mode 100644 index 0000000000..1352315ced --- /dev/null +++ b/jsk_unitree_robot/cross/repos/catkin_virtualenv.repos @@ -0,0 +1,18 @@ +repositories: + catkin_virtualenv: + type: git + url: https://github.com/locusrobotics/catkin_virtualenv + version: 0.9.0 + # + # 0.9.0 contains following two patches, but not release on ROS1 + # catkin_virtualenv depends on python3-rospkg-modules (and others). It is installed in build_ros1_dependencies.sh + # + # At current, if we do a catkin build with CATKIN_ENABLE_TESTING=FALSE, + # we get the error 'Unknown CMake command "catkin_run_tests_target"' + # when calling catkin_generate_virtualenv. The following PR fixes this error. + # https://github.com/locusrobotics/catkin_virtualenv/pull/89 + # + # Some python environments may not have ensurepip installed. + # Also, some users may not be able to use sudo apt install to install python3-venv (sudo command), etc. + # The following PR will enable catkin_virtualenv in environments without ensurepip by doing get-pip.py within venv. + # https://github.com/locusrobotics/catkin_virtualenv/pull/90 diff --git a/jsk_unitree_robot/cross/repos/ros1_dependencies.repos b/jsk_unitree_robot/cross/repos/ros1_dependencies.repos index d69c626402..71648aaceb 100644 --- a/jsk_unitree_robot/cross/repos/ros1_dependencies.repos +++ b/jsk_unitree_robot/cross/repos/ros1_dependencies.repos @@ -262,3 +262,33 @@ repositories: type: tar url: http://archive.ubuntu.com/ubuntu/pool/universe/libc/libccd/libccd_2.0-1.debian.tar.xz # fcl depends on ccd + virtualenv: + type: tar + url: http://archive.ubuntu.com/ubuntu/ubuntu/pool/universe/p/python-virtualenv/python-virtualenv_15.1.0+ds.orig.tar.gz + virtualenv/debian: + type: tar + url: http://archive.ubuntu.com/ubuntu/ubuntu/pool/universe/p/python-virtualenv/python-virtualenv_15.1.0+ds-1.1.debian.tar.xz + python3-pyparsing: + type: tar + url: http://archive.ubuntu.com/ubuntu/pool/main/p/pyparsing/pyparsing_2.2.0+dfsg1.orig.tar.gz + python3-pyparsing/debian: + type: tar + url: http://archive.ubuntu.com/ubuntu/pool/main/p/pyparsing/pyparsing_2.2.0+dfsg1-2.debian.tar.xz + python3-catkin-pkg-modules: + type: tar + url: http://packages.ros.org/ros/ubuntu/pool/main/p/python3-catkin-pkg-modules/python3-catkin-pkg-modules_0.5.2.orig.tar.gz + python3-catkin-pkg-modules/debian: + type: tar + url: http://packages.ros.org/ros/ubuntu/pool/main/p/python3-catkin-pkg-modules/python3-catkin-pkg-modules_0.5.2-1.debian.tar.xz + python3-rospkg-modules: + type: tar + url: http://packages.ros.org/ros/ubuntu/pool/main/p/python3-rospkg-modules/python3-rospkg-modules_1.5.0.orig.tar.gz + python3-rospkg-modules/debian: + type: tar + url: http://packages.ros.org/ros/ubuntu/pool/main/p/python3-rospkg-modules/python3-rospkg-modules_1.5.0-1.debian.tar.xz + cython: + type: tar + url: http://archive.ubuntu.com/ubuntu/ubuntu/pool/universe/c/cython/cython_0.26.1.orig.tar.gz + cython/debian: + type: tar + url: http://archive.ubuntu.com/ubuntu/ubuntu/pool/universe/c/cython/cython_0.26.1-0.4.debian.tar.xz diff --git a/jsk_unitree_robot/cross/ros1_dependencies_build_scripts/1045-virtualenv b/jsk_unitree_robot/cross/ros1_dependencies_build_scripts/1045-virtualenv new file mode 100755 index 0000000000..6f2f02e50b --- /dev/null +++ b/jsk_unitree_robot/cross/ros1_dependencies_build_scripts/1045-virtualenv @@ -0,0 +1,21 @@ +#!/bin/bash +set -xeuf -o pipefail + +DEBIAN_DIR=/home/user/ros1_dependencies_sources/src/virtualenv/debian/debian +SOURCE_DIR=/home/user/ros1_dependencies_sources/src/virtualenv/virtualenv-15.1.0 + +cd ${DEBIAN_DIR}/patches +for patch_file in $(grep -v ^# series); do + OUT="$(patch -p1 --forward --directory ${SOURCE_DIR} < ${patch_file} | tee /dev/tty)" || echo "${OUT}" | grep "Skipping patch" -q || (echo "$OUT" && false) || echo "OK" +done + +cd ${SOURCE_DIR} + +mkdir -p /opt/jsk/${INSTALL_ROOT}/ros1_dependencies/lib/python3.6/site-packages/ +SKIP_PYTHON_SCRIPTS=1 \ +PYTHONPATH="/opt/jsk/${INSTALL_ROOT}/ros1_dependencies/lib/python3.6/site-packages" \ + python3 \ + setup.py install \ + --force --root=/opt/jsk/${INSTALL_ROOT}/ros1_dependencies \ + --no-compile -O0 --single-version-externally-managed --prefix=./ +# --prefix /opt/jsk/${INSTALL_ROOT}/ros1_dependencies diff --git a/jsk_unitree_robot/cross/ros1_dependencies_build_scripts/1046-python3-pyparsing b/jsk_unitree_robot/cross/ros1_dependencies_build_scripts/1046-python3-pyparsing new file mode 100755 index 0000000000..6ab82d8494 --- /dev/null +++ b/jsk_unitree_robot/cross/ros1_dependencies_build_scripts/1046-python3-pyparsing @@ -0,0 +1,21 @@ +#!/bin/bash +set -xeuf -o pipefail + +DEBIAN_DIR=/home/user/ros1_dependencies_sources/src/python3-pyparsing/debian/debian +SOURCE_DIR=/home/user/ros1_dependencies_sources/src/python3-pyparsing/pyparsing-2.2.0+dfsg1 + +# cd ${DEBIAN_DIR}/patches +# for patch_file in $(grep -v ^# series); do +# OUT="$(patch -p1 --forward --directory ${SOURCE_DIR} < ${patch_file} | tee /dev/tty)" || echo "${OUT}" | grep "Skipping patch" -q || (echo "$OUT" && false) || echo "OK" +# done + +cd ${SOURCE_DIR} + +mkdir -p /opt/jsk/${INSTALL_ROOT}/ros1_dependencies/lib/python3.6/site-packages/ +SKIP_PYTHON_SCRIPTS=1 \ +PYTHONPATH="/opt/jsk/${INSTALL_ROOT}/ros1_dependencies/lib/python3.6/site-packages" \ + python3 \ + setup.py install \ + --force --root=/opt/jsk/${INSTALL_ROOT}/ros1_dependencies \ + --no-compile -O0 --single-version-externally-managed --prefix=./ +# --prefix /opt/jsk/${INSTALL_ROOT}/ros1_dependencies diff --git a/jsk_unitree_robot/cross/ros1_dependencies_build_scripts/1047-python3-catkin-pkg-modules b/jsk_unitree_robot/cross/ros1_dependencies_build_scripts/1047-python3-catkin-pkg-modules new file mode 100755 index 0000000000..da470da7cd --- /dev/null +++ b/jsk_unitree_robot/cross/ros1_dependencies_build_scripts/1047-python3-catkin-pkg-modules @@ -0,0 +1,21 @@ +#!/bin/bash +set -xeuf -o pipefail + +DEBIAN_DIR=/home/user/ros1_dependencies_sources/src/python3-catkin-pkg-modules/debian/debian +SOURCE_DIR=/home/user/ros1_dependencies_sources/src/python3-catkin-pkg-modules/catkin_pkg_modules-0.5.2 + +# cd ${DEBIAN_DIR}/patches +# for patch_file in $(grep -v ^# series); do +# OUT="$(patch -p1 --forward --directory ${SOURCE_DIR} < ${patch_file} | tee /dev/tty)" || echo "${OUT}" | grep "Skipping patch" -q || (echo "$OUT" && false) || echo "OK" +# done + +cd ${SOURCE_DIR} + +mkdir -p /opt/jsk/${INSTALL_ROOT}/ros1_dependencies/lib/python3.6/site-packages/ +SKIP_PYTHON_SCRIPTS=1 \ +PYTHONPATH="/opt/jsk/${INSTALL_ROOT}/ros1_dependencies/lib/python3.6/site-packages" \ + python3 \ + setup.py install \ + --force --root=/opt/jsk/${INSTALL_ROOT}/ros1_dependencies \ + --no-compile -O0 --single-version-externally-managed --prefix=./ +# --prefix /opt/jsk/${INSTALL_ROOT}/ros1_dependencies diff --git a/jsk_unitree_robot/cross/ros1_dependencies_build_scripts/1048-python3-rospkg-modules b/jsk_unitree_robot/cross/ros1_dependencies_build_scripts/1048-python3-rospkg-modules new file mode 100755 index 0000000000..8af6e48c05 --- /dev/null +++ b/jsk_unitree_robot/cross/ros1_dependencies_build_scripts/1048-python3-rospkg-modules @@ -0,0 +1,21 @@ +#!/bin/bash +set -xeuf -o pipefail + +DEBIAN_DIR=/home/user/ros1_dependencies_sources/src/python3-rospkg-modules/debian/debian +SOURCE_DIR=/home/user/ros1_dependencies_sources/src/python3-rospkg-modules/rospkg_modules-1.5.0 + +# cd ${DEBIAN_DIR}/patches +# for patch_file in $(grep -v ^# series); do +# OUT="$(patch -p1 --forward --directory ${SOURCE_DIR} < ${patch_file} | tee /dev/tty)" || echo "${OUT}" | grep "Skipping patch" -q || (echo "$OUT" && false) || echo "OK" +# done + +cd ${SOURCE_DIR} + +mkdir -p /opt/jsk/${INSTALL_ROOT}/ros1_dependencies/lib/python3.6/site-packages/ +SKIP_PYTHON_SCRIPTS=1 \ +PYTHONPATH="/opt/jsk/${INSTALL_ROOT}/ros1_dependencies/lib/python3.6/site-packages" \ + python3 \ + setup.py install \ + --force --root=/opt/jsk/${INSTALL_ROOT}/ros1_dependencies \ + --no-compile -O0 --single-version-externally-managed --prefix=./ +# --prefix /opt/jsk/${INSTALL_ROOT}/ros1_dependencies \ diff --git a/jsk_unitree_robot/cross/ros1_dependencies_build_scripts/1049-cython b/jsk_unitree_robot/cross/ros1_dependencies_build_scripts/1049-cython new file mode 100755 index 0000000000..fd38c9c307 --- /dev/null +++ b/jsk_unitree_robot/cross/ros1_dependencies_build_scripts/1049-cython @@ -0,0 +1,46 @@ +#!/bin/bash +set -xeu -o pipefail + +DEBIAN_DIR=/home/user/ros1_dependencies_sources/src/cython/debian/debian +SOURCE_DIR=/home/user/ros1_dependencies_sources/src/cython/Cython-0.26.1 + +cd ${DEBIAN_DIR}/patches +for patch_file in $(grep -v ^# series); do + OUT="$(patch -p1 --forward --directory ${SOURCE_DIR} < ${patch_file} | tee /dev/tty)" || echo "${OUT}" | grep "Skipping patch" -q || (echo "$OUT" && false) || echo "OK" +done + +cd ${SOURCE_DIR} + +# mkdir -p /opt/jsk/${INSTALL_ROOT}/ros1_dependencies/lib/python2.7/site-packages/ +# PYTHONPATH="/opt/jsk/${INSTALL_ROOT}/ros1_dependencies/lib/python2.7/site-packages" \ +# python2 \ +# setup.py install \ +# --force --root=/opt/jsk/${INSTALL_ROOT}/ros1_dependencies \ +# --no-compile -O0 --single-version-externally-managed --prefix=./ + +# fix shebang +#sed -i -e '1 s,#!.*python.*,#!/usr/bin/python,' /opt/jsk/${INSTALL_ROOT}/ros1_dependencies/bin/cython +#sed -i -e '1 s,#!.*python.*,#!/usr/bin/python,' /opt/jsk/${INSTALL_ROOT}/ros1_dependencies/bin/cygdb +#sed -i -e '1 s,#!.*python.*,#!/usr/bin/python,' /opt/jsk/${INSTALL_ROOT}/ros1_dependencies/bin/cythonize + +### +### catkin_virtualenv failed with PyYAML, +### We still do not find the root couse but it fails with source install +### add following code in docker/Dockerfile_ros1, but it is exceptional. +### RUN (cd /tmp; apt download cython && dpkg --force-depends -i cython_*.deb) +### Dockerfile_ros1 is designed to reproduce dog's internal PC and we install cython just to pass build_ros1.sh + + # [ 20%] Lock input requirements if they don't exist [ 40%] Install requirements to /home/user/arm64v8_ws_system/build_isolated/test_catkin_virtualenv_python2/venv ERROR: Command errored out with exit status 1: command: /home/user/arm64v8_ws_system/build_isolated/test_catkin_virtualenv_python2/venv/bin/python /home/user/arm64v8_ws_system/build_isolated/test_catkin_virtualenv_python2/venv/local/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmplXEZlo cwd: /tmp/pip-install-YKwwFS/pyyaml + # Complete output (46 lines): running egg_info creating lib/PyYAML.egg-info + # writing lib/PyYAML.egg-info/PKG-INFO + # writing top-level names to lib/PyYAML.egg-info/top_level.txt + # writing dependency_links to lib/PyYAML.egg-info/dependency_links.txt + # writing manifest file 'lib/PyYAML.egg-info/SOURCES.txt' + # Traceback (most recent call last): File "/home/user/arm64v8_ws_system/build_isolated/test_catkin_virtualenv_python2/venv/local/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py", line 280, in main() + # File "/home/user/arm64v8_ws_system/build_isolated/test_catkin_virtualenv_python2/venv/local/lib/python2.7/site-packages/setuptools/command/py36compat.py", line 120, in _add_defaults_ext + # self.filelist.extend(build_ext.get_source_files()) File "setup.py", line 201, in get_source_files + # self.cython_sources(ext.sources, ext) + # File "/usr/lib/python2.7/distutils/cmd.py", line 105, in __getattr__ + # raise AttributeError, attr + # AttributeError: cython_sources + # ---------------------------------------- diff --git a/jsk_unitree_robot/cross/run_user.sh b/jsk_unitree_robot/cross/run_user.sh index 07c9f39652..e53cb068e0 100755 --- a/jsk_unitree_robot/cross/run_user.sh +++ b/jsk_unitree_robot/cross/run_user.sh @@ -1,5 +1,6 @@ #!/bin/bash +IMAGE_NAME="${IMAGE_NAME:-ros1-unitree}" TARGET_MACHINE="${TARGET_MACHINE:-arm64v8}" HOST_INSTALL_ROOT="${BASE_ROOT:-${PWD}}/"${TARGET_MACHINE}_System INSTALL_ROOT=System @@ -10,15 +11,17 @@ set -xeuf -o pipefail # -v ${PWD}/${TARGET_MACHINE}_ws_system:/home/user/${TARGET_MACHINE}_ws_system:rw \ # run on docker docker run -it --rm \ - -u $(id -u $USER) \ + -e HOST_UID=$(id -u) -e HOST_GID=$(id -g) \ -e INSTALL_ROOT=${INSTALL_ROOT} \ -v ${HOST_INSTALL_ROOT}/ros1_dependencies:/opt/jsk/${INSTALL_ROOT}/ros1_dependencies:ro \ -v ${HOST_INSTALL_ROOT}/Python:/opt/jsk/${INSTALL_ROOT}/Python:ro \ -v ${HOST_INSTALL_ROOT}/ros1_inst:/opt/jsk/${INSTALL_ROOT}/ros1_inst:ro \ -v ${HOST_INSTALL_ROOT}/ros1_dependencies_setup.bash:/opt/jsk/${INSTALL_ROOT}/ros1_dependencies_setup.bash:ro \ -v ${HOST_INSTALL_ROOT}/system_setup.bash:/opt/jsk/${INSTALL_ROOT}/system_setup.bash:ro \ + -v ${HOST_INSTALL_ROOT}/usercustomize.py:/home/user/.local/lib/python2.7/site-packages/usercustomize.py:ro \ + -v ${HOST_INSTALL_ROOT}/usercustomize.py:/home/user/.local/lib/python3.6/site-packages/usercustomize.py:ro \ -v ${PWD}/${SOURCE_ROOT}:/opt/jsk/User:rw \ - ros1-unitree:${TARGET_MACHINE} \ + ${IMAGE_NAME}:${TARGET_MACHINE} \ bash -c "echo 'source /opt/jsk/User/user_setup.bash; env; cd /opt/jsk/User' > ~/.bashrc; exec \"\$0\"" # https://stackoverflow.com/questions/59814742/docker-run-bash-init-file diff --git a/jsk_unitree_robot/cross/startup_scripts/ros1_dependencies_setup.bash b/jsk_unitree_robot/cross/startup_scripts/ros1_dependencies_setup.bash index bb83142ace..c03e083861 100755 --- a/jsk_unitree_robot/cross/startup_scripts/ros1_dependencies_setup.bash +++ b/jsk_unitree_robot/cross/startup_scripts/ros1_dependencies_setup.bash @@ -5,14 +5,17 @@ export CMAKE_PREFIX_PATH="/opt/jsk/System/ros1_dependencies:${CMAKE_PREFIX_PATH}" export PKG_CONFIG_PATH="/opt/jsk/System/ros1_dependencies/lib/pkgconfig:${PKG_CONFIG_PATH}" export LD_LIBRARY_PATH="/opt/jsk/System/ros1_dependencies/lib:${LD_LIBRARY_PATH}" -export PYTHONPATH="/opt/jsk/System/ros1_dependencies/lib/python2.7/site-packages:${PYTHONPATH}" +export PATH="/opt/jsk/System/ros1_dependencies/bin:${PATH}" +# Python's sys.path is automatically set in ~/.local/lib/python2.7/usercustomize.py +# export PYTHONPATH="/opt/jsk/System/ros1_dependencies/lib/python2.7/site-packages:${PYTHONPATH}" # GI : for gir1.2-gstreamer-1.0, which is installed by ros1_dependencies_build_scripts/0006-gstreamer export GI_TYPELIB_PATH="/opt/jsk/System/ros1_dependencies/lib/girepository-1.0" # Python export LD_LIBRARY_PATH="/opt/jsk/System/Python/lib:${LD_LIBRARY_PATH}" -export PYTHONPATH="/opt/jsk/System/Python/lib/python2.7/site-packages:${PYTHONPATH}" +# Python's sys.path is automatically set in ~/.local/lib/python2.7/usercustomize.py +# export PYTHONPATH="/opt/jsk/System/Python/lib/python2.7/site-packages:${PYTHONPATH}" export PATH="/opt/jsk/System/Python/bin:${PATH}" diff --git a/jsk_unitree_robot/cross/startup_scripts/usercustomize.py b/jsk_unitree_robot/cross/startup_scripts/usercustomize.py new file mode 100644 index 0000000000..b292e21a43 --- /dev/null +++ b/jsk_unitree_robot/cross/startup_scripts/usercustomize.py @@ -0,0 +1,42 @@ +import site +import sys +import os +import os.path as osp + +site.PREFIXES += [ + '/opt/jsk/System/Python/', + '/opt/jsk/System/ros1_dependencies/' +] + +# https://www.programcreek.com/python/?code=Pylons%2Fhupper%2Fhupper-master%2Fsrc%2Fhupper%2Fcompat.py +def get_site_packages(): + try: + paths = [] + for path in site.getsitepackages(): + if osp.exists(path): + paths.append(path) + site_package = osp.join(osp.dirname(path), 'site-packages') + if site_package != path and osp.exists(site_package): + paths.append(site_package) + + return paths + + # virtualenv does not ship with a getsitepackages impl so we fallback + # to using distutils if we can + # https://github.com/pypa/virtualenv/issues/355 + except Exception: + try: + paths = [] + for base_path in site.PREFIXES: + for python_path in ['lib/python{}'.format(sys.version_info[0]), + 'lib/python{}.{}'.format(sys.version_info[0], sys.version_info[1])]: + site_package = osp.join(base_path, python_path, 'site-packages') + if osp.exists(site_package): + paths.append(site_package) + return paths + + # just incase, don't fail here, it's not worth it + except Exception as e: + return [] + +sys.path.extend(get_site_packages())