Skip to content

Commit 52353a7

Browse files
anchaoxiaoxiang781216
authored andcommitted
apps/build: Restore ARLOCK to improve compile speed in incremental case
To solve the issue of carrying object files from previous builds, Matias changed the archiving process to re-archive libapps.a on every compilation, if libapps.a carries more object files, incremental compilation will waste too many time in re-archiving, compared with the previous implement, this is a degradation of the build system. Referring to mature engineering projects such as cmake, if there is configuration or source file changed, the best solution should be to reconfigure the environment. Revert this PR to ensure the compilation speed during incremental compilation. | commit 18137c0 | Author: Matias N <[email protected]> | Date: Sat Sep 12 00:36:23 2020 -0300 | | 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. Testing: sim:nsh ------------------------------- | Patched | Current ------------------------------- |$ time make | $ time make |real 0m1.270s | real 0m1.728s |user 0m0.971s | user 0m1.276s |sys 0m0.363s | sys 0m0.530s ------------------------------- Private project (20+ 3rd library needs archive to libapps.a) ------------------------------- | Patched | Current ------------------------------- |$ time make | $ time make |real 0m21.181s | real 0m39.721s |user 0m14.638s | user 0m24.837s |sys 0m6.919s | sys 0m14.394s ------------------------------- Signed-off-by: chao an <[email protected]>
1 parent bf4d873 commit 52353a7

File tree

5 files changed

+15
-17
lines changed

5 files changed

+15
-17
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
*.sym
2020
*.su
2121
*~
22+
.built
2223
.context
2324
.depend
2425
.kconfig
26+
/*.lock
2527
/bin
2628
/boot_romfsimg.h
2729
/external

Application.mk

+5-3
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ VPATH += :.
142142

143143
# Targets follow
144144

145-
all:: $(OBJS)
145+
all:: .built
146146
@:
147147
.PHONY: clean depend distclean
148148
.PRECIOUS: $(BIN)
@@ -208,11 +208,12 @@ $(ZIGOBJS): %$(ZIGEXT)$(SUFFIX)$(OBJEXT): %$(ZIGEXT)
208208
$(if $(and $(CONFIG_BUILD_LOADABLE), $(CELFFLAGS)), \
209209
$(call ELFCOMPILEZIG, $<, $@), $(call COMPILEZIG, $<, $@))
210210

211-
archive:
211+
.built: $(OBJS)
212212
$(call SPLITVARIABLE,ALL_OBJS,$(OBJS),100)
213213
$(foreach BATCH, $(ALL_OBJS_TOTAL), \
214-
$(call ARCHIVE_ADD, $(call CONVERT_PATH,$(BIN)), $(ALL_OBJS_$(BATCH))) \
214+
$(call ARLOCK, $(call CONVERT_PATH,$(BIN)), $(ALL_OBJS_$(BATCH))) \
215215
)
216+
$(Q) touch $@
216217

217218
ifeq ($(BUILD_MODULE),y)
218219

@@ -295,6 +296,7 @@ depend:: .depend
295296
@:
296297

297298
clean::
299+
$(call DELFILE, .built)
298300
$(call CLEAN)
299301

300302
distclean:: clean

Directory.mk

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ include $(APPDIR)/Make.defs
2424

2525
SUBDIRS := $(dir $(wildcard */Makefile))
2626
CONFIGSUBDIRS := $(filter-out $(dir $(wildcard */Kconfig)),$(SUBDIRS))
27+
CLEANSUBDIRS := $(dir $(wildcard *$(DELIM).built))
2728
CLEANSUBDIRS += $(dir $(wildcard */.depend))
2829
CLEANSUBDIRS += $(dir $(wildcard */.kconfig))
2930
CLEANSUBDIRS := $(sort $(CLEANSUBDIRS))

Make.defs

+4
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,7 @@ define SPLITVARIABLE
152152
$(eval $(PREFIX)_$(idx)=$(wordlist $(FROMINDEX), $(shell expr $(FROMINDEX) + $(BATCH_SIZE) - 1), $(2))) \
153153
)
154154
endef
155+
156+
define ARLOCK
157+
flock $1.lock $(call ARCHIVE, $1, $(2))
158+
endef

Makefile

+3-14
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ SYMTABOBJ = $(SYMTABSRC:.c=$(OBJEXT))
4242
# We first remove libapps.a before letting the other rules add objects to it
4343
# so that we ensure libapps.a does not contain objects from prior build
4444

45-
all:
46-
$(RM) $(BIN)
47-
$(MAKE) $(BIN)
45+
all: $(BIN)
4846

4947
.PHONY: import install dirlinks export .depdirs preconfig depend clean distclean
5048
.PHONY: context clean_context context_all register register_all
@@ -74,9 +72,6 @@ ifeq ($(CONFIG_BUILD_KERNEL),y)
7472
install: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_install)
7573

7674
$(BIN): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all)
77-
$(Q) for app in ${CONFIGURED_APPS}; do \
78-
$(MAKE) -C "$${app}" archive ; \
79-
done
8075

8176
.import: $(BIN)
8277
$(Q) install libapps.a $(APPDIR)$(DELIM)import$(DELIM)libs
@@ -96,21 +91,14 @@ else
9691
ifeq ($(CONFIG_BUILD_LOADABLE),)
9792
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
9893
$(BIN): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all)
99-
$(Q) for %%G in ($(CONFIGURED_APPS)) do ( $(MAKE) -C %%G archive )
10094
else
10195
$(BIN): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all)
102-
$(Q) for app in ${CONFIGURED_APPS}; do \
103-
$(MAKE) -C "$${app}" archive ; \
104-
done
10596
$(call LINK_WASM)
10697
endif
10798

10899
else
109100

110101
$(SYMTABSRC): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all)
111-
$(Q) for app in ${CONFIGURED_APPS}; do \
112-
$(MAKE) -C "$${app}" archive ; \
113-
done
114102
$(Q) $(MAKE) install
115103
$(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(BINDIR) >$@.tmp
116104
$(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@)
@@ -119,7 +107,7 @@ $(SYMTABOBJ): %$(OBJEXT): %.c
119107
$(call COMPILE, $<, $@, -fno-lto -fno-builtin)
120108

121109
$(BIN): $(SYMTABOBJ)
122-
$(call ARCHIVE_ADD, $(call CONVERT_PATH,$(BIN)), $^)
110+
$(call ARLOCK, $(call CONVERT_PATH,$(BIN)), $^)
123111
$(call LINK_WASM)
124112

125113
endif # !CONFIG_BUILD_LOADABLE
@@ -208,6 +196,7 @@ clean: $(foreach SDIR, $(CLEANDIRS), $(SDIR)_clean)
208196
$(call CLEAN)
209197

210198
distclean: $(foreach SDIR, $(CLEANDIRS), $(SDIR)_distclean)
199+
$(call DELFILE, *.lock)
211200
$(call DELFILE, .depend)
212201
$(call DELFILE, $(SYMTABSRC))
213202
$(call DELFILE, $(SYMTABOBJ))

0 commit comments

Comments
 (0)