diff --git a/radio/util/Dockerfile b/radio/util/Dockerfile index 2360b18cf..507c175d0 100644 --- a/radio/util/Dockerfile +++ b/radio/util/Dockerfile @@ -20,7 +20,10 @@ RUN apt-get update && \ qttools5-dev-tools \ software-properties-common \ wget \ - zip + zip \ + python-pip + +RUN python -m pip install filelock RUN wget -q https://launchpad.net/gcc-arm-embedded/4.7/4.7-2013-q3-update/+download/gcc-arm-none-eabi-4_7-2013q3-20130916-linux.tar.bz2 && \ tar xjf gcc-arm-none-eabi-4_7-2013q3-20130916-linux.tar.bz2 && \ @@ -37,4 +40,3 @@ VOLUME ["/opentx"] ENV PATH $PATH:/opt/gcc-arm-none-eabi/bin:/opentx/code/radio/util ARG OPENTX_VERSION_SUFFIX= ENV OPENTX_VERSION_SUFFIX ${OPENTX_VERSION_SUFFIX} - diff --git a/radio/util/build-firmware.py b/radio/util/build-firmware.py index 798d40b37..3f51471ea 100755 --- a/radio/util/build-firmware.py +++ b/radio/util/build-firmware.py @@ -4,6 +4,7 @@ import os import sys import subprocess import shutil +import filelock from fwoptions import * # Error codes @@ -175,15 +176,13 @@ if not language: command_options["TRANSLATIONS"] = language.upper() filename += "-" + language + ext -srcdir = os.path.dirname(os.path.realpath(__file__)) + "/../.." path = os.path.join(directory, filename) -outpath = path + ".out" errpath = path + ".err" -if os.path.isfile(errpath): - exit(COMPILATION_ERROR) +def build_firmware(path): + srcdir = os.path.dirname(os.path.realpath(__file__)) + "/../.." + outpath = path + ".out" -if not os.path.isfile(path): # Launch CMake cmd = ["cmake"] for opt, value in command_options.items(): @@ -219,9 +218,20 @@ if not os.path.isfile(path): if size > maxsize: exit(FIRMWARE_SIZE_TOO_BIG) - # Copy binary to the binaries directory shutil.move(target, path) +if os.path.isfile(errpath): + exit(COMPILATION_ERROR) + +lockpath = path + ".lock" +lock = filelock.FileLock(lockpath) +try: + with lock.acquire(timeout = 60*60): + if not os.path.isfile(path): + build_firmware(path) +except filelock.Timeout: + exit(COMPILATION_ERROR) + print filename exit(0)