Skip to contentSkip to conversation

Makefile: add chmod before rm when cleaning.

PATCH New Louis des Landes 2 participants 5 messages Apr 17, 2019 – Apr 21, 2019 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Makefile: add chmod before rm when cleaning.

Some build systems (looking at you golang) create read only directories as caches.
As such rm -rf will actually fail, causing clean and <pkg>-dirclean to fail.

This patch will cause make clean to run chmod -R +w on the relevant directory first, which will allow rm -rf to work.

This may be resolved if https://github.com/golang/go/issues/31481 is resolved satisfactorily.

---
 Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
Makefile +6 -0
index 522c0b0606..fc2a82e074 100644
@@ -1060,6 +1060,12 @@ printvars:
 
 .PHONY: clean
 clean:
+	# Some build systems (looking at you golang) create read only directories
+	# As such rm -rf will actually fail, so brute force them all to writeable
+	# before removing them.
+	chmod -R u+w $(BASE_TARGET_DIR) $(BINARIES_DIR) $(HOST_DIR) $(HOST_DIR_SYMLINK) \
+		$(BUILD_DIR) $(BASE_DIR)/staging \
+		$(LEGAL_INFO_DIR) $(GRAPHS_DIR)
 	rm -rf $(BASE_TARGET_DIR) $(BINARIES_DIR) $(HOST_DIR) $(HOST_DIR_SYMLINK) \
 		$(BUILD_DIR) $(BASE_DIR)/staging \
 		$(LEGAL_INFO_DIR) $(GRAPHS_DIR)
Signature · 1 line
2.21.0
#1 lore raw

PATCH 2/2 package/pkg-generic: add chmod when cleaning.

Some build systems (looking at you golang) create read only directories as caches.
As such rm -rf will actually fail, causing clean and <pkg>-dirclean to fail.

This patch will cause make <pkg>-dirclean to force chmod -R +w on the relevant directory first, which will allow rm -rf to work.

This may be resolved if https://github.com/golang/go/issues/31481 is resolved satisfactorily.

---
 package/pkg-generic.mk | 4 ++++
 1 file changed, 4 insertions(+)
package/pkg-generic.mk +4 -0
index 67782138b4..fd72fc8cf5 100644
@@ -346,6 +346,10 @@ $(BUILD_DIR)/%/.stamp_target_installed:
 
 # Remove package sources
 $(BUILD_DIR)/%/.stamp_dircleaned:
+	# Some build systems (looking at you golang) create read only directories
+	# As such rm -rf will actually fail, so brute force them all to writeable
+	# before removing them.
+	chmod -R u+w $(@D)
 	rm -Rf $(@D)
 
 ################################################################################
Signature · 1 line
2.21.0
#2 lore raw

PATCH 1/2 Makefile: add chmod before rm when cleaning.

In reply to Louis des Landes
Quoted 9 lines · Louis des Landes

Some build systems (looking at you golang) create read only directories as caches.
As such rm -rf will actually fail, causing clean and <pkg>-dirclean to fail.

This patch will cause make clean to run chmod -R +w on the relevant directory first, which will allow rm -rf to work.

This may be resolved if https://github.com/golang/go/issues/31481 is resolved satisfactorily.

I don't like this very much - adding a go-specific workaround to the generic
infrastructure.

Would it be acceptable to instead do the chmod as a POST_BUILD_HOOK that is
added by golang-package?

I also don't understand that I haven't encountered this issue myself... Maybe I
don't build Go packages...

Regards,
Arnout

Quoted 24 lines
---
 Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
Makefile +6 -0
index 522c0b0606..fc2a82e074 100644
@@ -1060,6 +1060,12 @@ printvars:
 
 .PHONY: clean
 clean:
+	# Some build systems (looking at you golang) create read only directories
+	# As such rm -rf will actually fail, so brute force them all to writeable
+	# before removing them.
+	chmod -R u+w $(BASE_TARGET_DIR) $(BINARIES_DIR) $(HOST_DIR) $(HOST_DIR_SYMLINK) \
+		$(BUILD_DIR) $(BASE_DIR)/staging \
+		$(LEGAL_INFO_DIR) $(GRAPHS_DIR)
 	rm -rf $(BASE_TARGET_DIR) $(BINARIES_DIR) $(HOST_DIR) $(HOST_DIR_SYMLINK) \
 		$(BUILD_DIR) $(BASE_DIR)/staging \
 		$(LEGAL_INFO_DIR) $(GRAPHS_DIR)
#3 lore raw

PATCH 1/2 Makefile: add chmod before rm when cleaning.

Quoted 11 lines · Arnout Vandecappelle
Quoted 7 lines · Louis des Landes

Some build systems (looking at you golang) create read only directories as caches.
As such rm -rf will actually fail, causing clean and <pkg>-dirclean to fail.

This patch will cause make clean to run chmod -R +w on the relevant directory first, which will allow rm -rf to work.

Quoted 8 lines
Quoted 2 lines

This may be resolved if https://github.com/golang/go/issues/31481 is resolved satisfactorily.

I don't like this very much - adding a go-specific workaround to the generic
infrastructure.

Would it be acceptable to instead do the chmod as a POST_BUILD_HOOK that is
added by golang-package?

I kind of agree, and this is somewhat of a hack. POST_BUILD_HOOK doesn't get triggered if the build fails (AFAIK) so
a failed build would still leave this directory lying around without being chmod'd. Might still be a good addition though.

Quoted 3 lines

I also don't understand that I haven't encountered this issue myself... Maybe I
don't build Go packages...

This 'feature' was introduced with 'module' support (
https://github.com/golang/go/wiki/Modules )
Previously there was no official dependency management, so unless you're building recent go packages you won't encounter this issue. In most other ways this module support is great. In this particular respect it's annoying for build systems.

Quoted 27 lines

Regards,
Arnout

Quoted 24 lines
---
 Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
Makefile +6 -0
index 522c0b0606..fc2a82e074 100644
@@ -1060,6 +1060,12 @@ printvars:
 
 .PHONY: clean
 clean:
+     # Some build systems (looking at you golang) create read only directories
+     # As such rm -rf will actually fail, so brute force them all to writeable
+     # before removing them.
+     chmod -R u+w $(BASE_TARGET_DIR) $(BINARIES_DIR) $(HOST_DIR) $(HOST_DIR_SYMLINK) \
+             $(BUILD_DIR) $(BASE_DIR)/staging \
+             $(LEGAL_INFO_DIR) $(GRAPHS_DIR)
      rm -rf $(BASE_TARGET_DIR) $(BINARIES_DIR) $(HOST_DIR) $(HOST_DIR_SYMLINK) \
              $(BUILD_DIR) $(BASE_DIR)/staging \
              $(LEGAL_INFO_DIR) $(GRAPHS_DIR)
#4 lore raw

PATCH 1/2 Makefile: add chmod before rm when cleaning.

Quoted 18 lines · Louis des Landes
Quoted 17 lines · Arnout Vandecappelle
Quoted 9 lines · Louis des Landes

Some build systems (looking at you golang) create read only directories as caches.
As such rm -rf will actually fail, causing clean and <pkg>-dirclean to fail.

This patch will cause make clean to run chmod -R +w on the relevant directory first, which will allow rm -rf to work.

This may be resolved if https://github.com/golang/go/issues/31481 is resolved satisfactorily.

I don't like this very much - adding a go-specific workaround to the generic
infrastructure.

Quoted 6 lines
Quoted 2 lines

Would it be acceptable to instead do the chmod as a POST_BUILD_HOOK that is
added by golang-package?

I kind of agree, and this is somewhat of a hack. POST_BUILD_HOOK doesn't get triggered if the build fails (AFAIK) so
a failed build would still leave this directory lying around without being chmod'd. Might still be a good addition though.

Yeah, better yet would be to patch go to remove that "feature". Long-term
that's anyway what we expect, right? That the go tool learns some option to not do the chmod?

Regards,
Arnout

Quoted 38 lines
Quoted 4 lines

I also don't understand that I haven't encountered this issue myself... Maybe I
don't build Go packages...

This 'feature' was introduced with 'module' support (
https://github.com/golang/go/wiki/Modules )
Previously there was no official dependency management, so unless you're building recent go packages you won't encounter this issue. In most other ways this module support is great. In this particular respect it's annoying for build systems.

Quoted 27 lines

Regards,
Arnout

Quoted 24 lines
---
 Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
Makefile +6 -0
index 522c0b0606..fc2a82e074 100644
@@ -1060,6 +1060,12 @@ printvars:
 
 .PHONY: clean
 clean:
+     # Some build systems (looking at you golang) create read only directories
+     # As such rm -rf will actually fail, so brute force them all to writeable
+     # before removing them.
+     chmod -R u+w $(BASE_TARGET_DIR) $(BINARIES_DIR) $(HOST_DIR) $(HOST_DIR_SYMLINK) \
+             $(BUILD_DIR) $(BASE_DIR)/staging \
+             $(LEGAL_INFO_DIR) $(GRAPHS_DIR)
      rm -rf $(BASE_TARGET_DIR) $(BINARIES_DIR) $(HOST_DIR) $(HOST_DIR_SYMLINK) \
              $(BUILD_DIR) $(BASE_DIR)/staging \
              $(LEGAL_INFO_DIR) $(GRAPHS_DIR)