0

The process in context here is 'android build environment'. To timeout normal tasks, one would do

#Timeout command 'do_task' in 10 seconds
timeout 10s do_task

However, when I try the same with android build environment, it doesn't seem to work. This is what happens instead:

box@boxputer:/media/box/backup/cr81x$ source build/envsetup.sh
box@boxputer:/media/box/backup/cr81x$ lunch aosp_arm-eng
Trying dependencies-only mode on a non-existing device tree?

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=12
TARGET_DEVICE=generic
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=generic
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.13.0-44-generic-x86_64-Zorin-OS-16.1
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=SQ3A.220605.009.A1
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/generic/goldfish device/generic/goldfish-opengl hardware/google/camera hardware/google/camera/devices/EmulatedCamera device/generic/goldfish device/generic/goldfish-opengl
============================================
box@boxputer:/media/box/backup/cr81x$ timeout 10s mka bacon
timeout: failed to run command ‘mka’: No such file or directory

Here, 'mka bacon' is the build command, 'make' or 'm' could also be used, but they all result in the same error as mentioned above.

What I've tried additionally includes

# Spawn a child process:
(dosmth) & pid=$!
# in the background, sleep for 10 secs then kill that process
(sleep 10 && kill -9 $pid) &
( cmdpid=$BASHPID; 
    (sleep 10; kill $cmdpid) \
   & while ! ping -w 1 www.goooooogle.com 
     do 
         echo crap; 
     done )

and other answers from This Particular Stackoverflow thread.

I've also tried another solution on a related thread

while one gave me success, it introduced a problem of its own(code below)

mka bacon &
sleep 10s

This however ensures that the process isn't terminated until 10 seconds have passed. Say I finish the build in 5 seconds. The process still won't exit. It won't exit till 10 seconds have passed, which isn't a desirable situation when a build produces an error.

And when I try the other answers from This Particular Stackoverflow thread, The process terminates after 10 seconds, but the entire terminal glitches, and the build still runs(at this stage even Ctrl+C doesn't work) My guess is that the build environment spawns its own child-processes with different PID's for the build?

If incase you're wondering what envsetup.sh is, Here's its paste

  • what does `which mka` outputs (after loading the environment)? – Fravadona Jun 15 '22 at 19:17
  • ```which mka``` outputs nothing, as it's not a binary. Its loaded when I execute ```source build/envsetup.sh```. Its more of a function I suppose. – Evan Ferrao Jun 15 '22 at 19:29
  • what's the output of `type mka` ? – Diego Torres Milano Jun 15 '22 at 19:30
  • You can find out *exactly* what it is by running `command -v mka` or `type mka`. – pjh Jun 15 '22 at 19:30
  • If `mka` is a function then you need to `export -f mka` and run `timeout 10s bash -c 'mka bacon'` – Fravadona Jun 15 '22 at 19:38
  • ```export -f mka``` returns the error ```export: invalid option(s) ``` I've attached the file too(envsetup.sh) https://katb.in/ajufewufowa – Evan Ferrao Jun 15 '22 at 20:02
  • This error means that you're not running bash as your shell. Where's `mka` defined in envsetup.sh? I can't see it – Fravadona Jun 16 '22 at 05:17
  • @fravadona yes, I wasn't using bash. It was zsh. Regarding ```mka```, I'm a bit confused myself, but it seems an alias of ```m```. I've attached a snippet of my terminal below: ```box@boxputer:/media/box/backup/cr81x$ which mka mka not found box@boxputer:/media/box/backup/cr81x$ source build/envsetup.sh ccache enabled and CCACHE_EXEC has been set to : /usr/bin/ccache box@boxputer:/media/box/backup/cr81x$ which mka mka () { m "$@" }``` Perhaphs envsetup.sh sources more files? but I see no source command within it. – Evan Ferrao Jun 16 '22 at 06:07
  • @fravadona your previous approach worked, although ```export -f mka``` didn't. What I did was: ```timeout 10s bash -c "source build/envsetup.sh; lunch aosp_arm-eng; mka bacon"``` Thanks a lot! – Evan Ferrao Jun 16 '22 at 06:11

1 Answers1

0

Timeout needs a binary to execute. Based on your hint

Here, 'mka bacon' is the build command, 'make' or 'm' could also be used

I assume, that mka is just an alias or function. You can find out, what it is and does with type mka. When you found it, use that instead as arguments for timeout.

entropie
  • 31
  • 3