From 4c49b27e9f6be02b8e63b508b60535426bd0291a Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 14 Feb 2018 11:25:12 +0100 Subject: [PATCH] Always invoke gradle except as root The custom target used to invoke Gradle from Meson should always be built, otherwise, the server would not be rebuilt on source changes. However, when enabling "build_always", gradle is invoked as root on "sudo ninja install" after "ninja", so it downloads the whole Gradle world into /root/.gradle. To avoid the problem, just do not call gradle if the effective user id is 0. --- server/meson.build | 6 +----- server/scripts/build-wrapper.sh | 10 ++++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/server/meson.build b/server/meson.build index fa5dc727..7be2c8fd 100644 --- a/server/meson.build +++ b/server/meson.build @@ -1,9 +1,5 @@ -project('scrcpy-server', 'c') # not really c, but meson expects something - -# does not track dependencies, so meson does not guarantees that server is up to date -# call "touch server" or "ninja -t clean server/scrcpy-server.jar" before to rebuild custom_target('scrcpy-server', - build_always: false, # do not enable, otherwise "sudo ninja install" will execute gradle! + build_always: true, # gradle is responsible for tracking source changes input: '.', output: 'scrcpy-server.jar', command: [find_program('./scripts/build-wrapper.sh'), '@INPUT@', '@OUTPUT@', get_option('buildtype')], diff --git a/server/scripts/build-wrapper.sh b/server/scripts/build-wrapper.sh index c21e946f..f55e1ea4 100755 --- a/server/scripts/build-wrapper.sh +++ b/server/scripts/build-wrapper.sh @@ -2,6 +2,16 @@ # Wrapper script to invoke gradle from meson set -e +# Do not execute gradle when ninja is called as root (it would download the +# whole gradle world in /root/.gradle). +# This is typically useful for calling "sudo ninja install" after a "ninja +# install" +if [[ "$EUID" == 0 ]] +then + echo "(not invoking gradle, since we are root)" >&2 + exit 0 +fi + PROJECT_ROOT="$1" OUTPUT="$2" BUILDTYPE="$3"