Skip to contentSkip to conversation

package/pkg-generic.mk: create folder before cd'ing in step_pkg_size_before

PATCH New Thomas Petazzoni 1 participant 1 message Mar 10, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/pkg-generic.mk: create folder before cd'ing in step_pkg_size_before

Commit 0e2be4db8ab01d479177a3a187c22525752195ae ("package/pkg-generic:
make file list logic parallel build compatible"), the logic to create the list of files installed by a particular package was significantly reworked to be compatible with top-level parallel build.

Before this commit, there was only a after-install step of listing the files in HOST_DIR/TARGET_DIR/STAGING_DIR. But after this commit, we now have a before-install logic and an after-install logic.

It turns out that when the before-install logic is called for the very first host package, $(HOST_DIR) doesn't exist yet, and therefore the cd $(2) fails, with an error message:

/bin/sh: line 0: cd: /home/thomas/buildroot/output/host: No such file or directory

In addition, due to the code using ";" instead of "&&" to separate the 'cd' from the 'find', we go ahead and continue listing all files in the current directory, which is obviously very wrong.

We fix this by simply creating the directory we are going to cd into in step_pkg_size_before. It is simpler than testing if the directory exists, and if it doesn't, create an empty .files-list$(3).before file.

While at it, we also turn the 'cd $(2); find' into 'cd $(2) && find'.

---
 package/pkg-generic.mk | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
package/pkg-generic.mk +3 -2
index c1b9fe2e59..26bcabe3d9 100644
@@ -61,7 +61,8 @@ GLOBAL_INSTRUMENTATION_HOOKS += step_time
 # $(2): base directory to search in
 # $(3): suffix of file (optional)
 define step_pkg_size_before
-	cd $(2); \
+	mkdir -p $(2)
+	cd $(2) && \
 	LC_ALL=C find . \( -type f -o -type l \) -printf '%T@:%i:%#m:%y:%s,%p\n' \
 		| LC_ALL=C sort > $($(PKG)_BUILDDIR)/.files-list$(3).before
 endef
@@ -70,7 +71,7 @@ endef
 # $(2): base directory to search in
 # $(3): suffix of file (optional)
 define step_pkg_size_after
-	cd $(2); \
+	cd $(2) && \
 	LC_ALL=C find . \( -type f -o -type l \) -printf '%T@:%i:%#m:%y:%s,%p\n' \
 		| LC_ALL=C sort > $($(PKG)_BUILDDIR)/.files-list$(3).after
 	LC_ALL=C comm -13 \
Signature · 1 line
2.24.1