From 433b444f0aa7829663465c5dd59fb02880694e9d Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 21 Feb 2020 11:25:21 +0900 Subject: [PATCH 1/3] Revert "build: Use flock to serialize ar steps as workaround" This reverts commit 6707bfae86aff8a3bae74f6bbafaca54d1315480. --- .gitignore | 1 - Application.mk | 4 ++-- Make.defs | 6 +----- Makefile | 5 ++--- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 668630512c9..722303bd5ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -.arlock .depend Make.dep *.o diff --git a/Application.mk b/Application.mk index 641e89b85e2..25af1926e42 100644 --- a/Application.mk +++ b/Application.mk @@ -130,9 +130,9 @@ $(CXXOBJS): %$(SUFFIX)$(OBJEXT): %$(CXXEXT) .built: $(OBJS) ifeq ($(WINTOOL),y) - $(call ARLOCK, "${shell cygpath -w $(BIN)}", $(OBJS)) + $(call ARCHIVE, "${shell cygpath -w $(BIN)}", $(OBJS)) else - $(call ARLOCK, $(BIN), $(OBJS)) + $(call ARCHIVE, $(BIN), $(OBJS)) endif $(Q) touch $@ diff --git a/Make.defs b/Make.defs index 89a649b39c0..77b0c82751b 100644 --- a/Make.defs +++ b/Make.defs @@ -52,7 +52,7 @@ CLEANDIRS := $(dir $(wildcard $(APPDIR)$(DELIM)*$(DELIM)Makefile)) CONFIGURED_APPS := define Add_Application - include $(1)Make.defs + include $(1)Make.defs endef $(foreach BDIR, $(BUILDIRS), $(eval $(call Add_Application,$(BDIR)))) @@ -99,10 +99,6 @@ define REGISTER endef endif -define ARLOCK - $(Q) flock .arlock $(call ARCHIVE, $1, $(2)) -endef - # Tools ifeq ($(DIRLINK),) diff --git a/Makefile b/Makefile index dfb9da882df..e0ad31f1cfb 100644 --- a/Makefile +++ b/Makefile @@ -117,9 +117,9 @@ $(SYMTABOBJ): %$(OBJEXT): %.c $(BIN): $(SYMTABOBJ) ifeq ($(WINTOOL),y) - $(call ARLOCK, "${shell cygpath -w $(BIN)}", $^) + $(call ARCHIVE, "${shell cygpath -w $(BIN)}", $^) else - $(call ARLOCK, $(BIN), $^) + $(call ARCHIVE, $(BIN), $^) endif endif # !CONFIG_BUILD_LOADABLE @@ -198,7 +198,6 @@ else fi; \ ) endif - $(call DELFILE, .arlock) $(call DELFILE, .depend) $(call DELFILE, $(SYMTABSRC)) $(call DELFILE, $(SYMTABOBJ)) From ee4aad7f90c2746e18dfcc29ebcd65eb8a76ae54 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 21 Feb 2020 11:28:51 +0900 Subject: [PATCH 2/3] Use flock to serialize AR --- .gitignore | 1 + Make.defs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 722303bd5ca..7ff6bb2f442 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ cscope.out /Kconfig /bin /external +/.arlock /.context /.config /.depend diff --git a/Make.defs b/Make.defs index 77b0c82751b..805d6af1907 100644 --- a/Make.defs +++ b/Make.defs @@ -99,6 +99,9 @@ define REGISTER endef endif +# Workaround for concurrent execution to the same library (libapps) +AR := flock $(APPDIR)/.arlock $(AR) + # Tools ifeq ($(DIRLINK),) From 218c7a9d64e0673fccc248cb8611f3f4ec70971e Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 21 Feb 2020 11:30:20 +0900 Subject: [PATCH 3/3] Use shlock instead of flock on macOS Because macOS doesn't have flock. --- Make.defs | 5 +++++ tools/flock.sh | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100755 tools/flock.sh diff --git a/Make.defs b/Make.defs index 805d6af1907..3d58155d4be 100644 --- a/Make.defs +++ b/Make.defs @@ -100,7 +100,12 @@ endef endif # Workaround for concurrent execution to the same library (libapps) +ifeq ($(CONFIG_HOST_MACOS),y) +# macOS doesn't have flock. Use shlock instead. +AR := $(APPDIR)/tools/flock.sh $(APPDIR)/.arlock $(AR) +else AR := flock $(APPDIR)/.arlock $(AR) +endif # Tools diff --git a/tools/flock.sh b/tools/flock.sh new file mode 100755 index 00000000000..e20c1050cfd --- /dev/null +++ b/tools/flock.sh @@ -0,0 +1,36 @@ +#! /bin/sh + +# apps/tools/flock.sh +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# This script tries to mimic flock using shlock +# +# NOTE: It just aims to be enough for our usage in libapps build. +# Not intended to be a full replacement of flock. + +LOCKFILE=$1 +shift + +while ! shlock -f ${LOCKFILE} -p $$; do + sleep 1 +done + +set -e +$@ +STATUS=$? +rm -f ${LOCKFILE} || : +exit ${STATUS}