Fix: ensure archive files do not carry object files from prior builds

This is the corresponding change to the one on main NuttX repo. In this
case this involves splitting the build of libapps.a into: a) building
all applications (which is safely parallelizable), b) adding each
application's object files to the archive in turns (serial by nature).

This removes the need for the flock used to protect the parallel build.
This commit is contained in:
Matias N 2020-09-12 00:36:23 -03:00 committed by Xiang Xiao
parent 52b28ed484
commit 18137c0fec
5 changed files with 19 additions and 17 deletions

2
.gitignore vendored
View File

@ -15,10 +15,8 @@
*.swp
*.sym
*~
.built
.depend
.kconfig
/*.lock
/bin
/boot_romfsimg.h
/external

View File

@ -95,7 +95,7 @@ VPATH += :.
# Targets follow
all:: .built
all:: $(OBJS)
.PHONY: clean depend distclean
.PRECIOUS: $(BIN)
@ -131,13 +131,12 @@ $(CXXOBJS): %$(SUFFIX)$(OBJEXT): %$(CXXEXT)
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CXXELFFLAGS)), \
$(call ELFCOMPILEXX, $<, $@), $(call COMPILEXX, $<, $@))
.built: $(OBJS)
archive:
ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
$(call ARLOCK, "${shell cygpath -w $(BIN)}", $^)
$(call ARCHIVE_ADD, "${shell cygpath -w $(BIN)}", $(OBJS))
else
$(call ARLOCK, $(BIN), $^)
$(call ARCHIVE_ADD, $(BIN), $(OBJS))
endif
$(Q) touch $@
ifeq ($(BUILD_MODULE),y)
@ -234,7 +233,6 @@ endif
depend:: .depend
clean::
$(call DELFILE, .built)
$(call CLEAN)
distclean:: clean

View File

@ -39,7 +39,6 @@ include $(APPDIR)/Make.defs
SUBDIRS := $(dir $(wildcard *$(DELIM)Makefile))
CONFIGSUBDIRS := $(filter-out $(dir $(wildcard *$(DELIM)Kconfig)),$(SUBDIRS))
CLEANSUBDIRS := $(dir $(wildcard *$(DELIM).built))
CLEANSUBDIRS += $(dir $(wildcard *$(DELIM).depend))
CLEANSUBDIRS += $(dir $(wildcard *$(DELIM).kconfig))
CLEANSUBDIRS := $(sort $(CLEANSUBDIRS))

View File

@ -108,10 +108,6 @@ define REGISTER
$(Q) touch "$(BUILTIN_REGISTRY)$(DELIM).updated"
endef
define ARLOCK
$(Q) flock $1.lock $(call ARCHIVE, $1, $(2))
endef
# Standard include path
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(APPDIR)$(DELIM)include"}

View File

@ -45,7 +45,13 @@ SYMTABOBJ = $(SYMTABSRC:.c=$(OBJEXT))
# Build targets
all: $(BIN)
# We first remove libapps.a before letting the other rules add objects to it
# so that we ensure libapps.a does not contain objects from prior build
all:
$(RM) $(BIN)
$(MAKE) $(BIN)
.PHONY: import install dirlinks context context_serialize clean_context context_rest export .depdirs preconfig depend clean distclean
.PRECIOUS: $(BIN)
@ -87,10 +93,16 @@ else
ifeq ($(CONFIG_BUILD_LOADABLE),)
$(BIN): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all)
$(Q) for app in ${CONFIGURED_APPS}; do \
$(MAKE) -C "$${app}" archive TOPDIR="${TOPDIR}" APPDIR="${APPDIR}" ; \
done
else
$(SYMTABSRC): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all)
$(Q) for app in ${CONFIGURED_APPS}; do \
$(MAKE) -C "$${app}" archive TOPDIR="${TOPDIR}" APPDIR="${APPDIR}" ; \
done
$(Q) $(MAKE) install TOPDIR="$(TOPDIR)"
$(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(BINDIR) >$@.tmp
$(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@)
@ -100,9 +112,9 @@ $(SYMTABOBJ): %$(OBJEXT): %.c
$(BIN): $(SYMTABOBJ)
ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
$(call ARLOCK, "${shell cygpath -w $(BIN)}", $^)
$(call ARCHIVE_ADD, "${shell cygpath -w $(BIN)}", $^)
else
$(call ARLOCK, $(BIN), $^)
$(call ARCHIVE_ADD, $(BIN), $^)
endif
endif # !CONFIG_BUILD_LOADABLE
@ -198,7 +210,6 @@ else
fi; \
)
endif
$(call DELFILE, *.lock)
$(call DELFILE, .depend)
$(call DELFILE, $(SYMTABSRC))
$(call DELFILE, $(SYMTABOBJ))