Skip to contentSkip to conversation

pkg-generic: Strip all but leading comments from C files used as license.

PATCH New Peter Rosin 3 participants 4 messages Nov 17, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pkg-generic: Strip all but leading comments from C files used as license.

From: Peter Rosin <[email protected]>

---
 package/pkg-utils.mk |   28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)
package/pkg-utils.mk +25 -3
index 44bd2c9..1497eb2 100644
@@ -145,8 +145,30 @@ endef
 
 define legal-license-file # pkg, filename, file-fullpath, {HOST|TARGET}
 	$(call legal-license-header,$(1),$(2) file,$(4)) && \
-	cat $(3) >>$(LEGAL_LICENSES_TXT_$(4)) && \
-	echo >>$(LEGAL_LICENSES_TXT_$(4)) && \
 	mkdir -p $(LICENSE_FILES_DIR_$(4))/$(1)/$(dir $(2)) && \
-	cp $(3) $(LICENSE_FILES_DIR_$(4))/$(1)/$(2)
+	case $(3) in \
+	*.c|*.h) \
+	  sed -e '\
+x;\
+/^$$/{\
+  x;\
+  /^[ \t]*$$/b;\
+  /^[ \t]*\/\//b;\
+  /^[ \t]*\/\*.*\*\//b;\
+  /^[ \t]*\/\*/h;\
+  //b;\
+  s/.*//;\
+  q\
+};\
+x;\
+/\*\//{\
+  x;\
+  s/.*//;\
+  x\
+}' < $(3) > $(LICENSE_FILES_DIR_$(4))/$(1)/$(2) \
+	;; \
+	*) cp $(3) $(LICENSE_FILES_DIR_$(4))/$(1)/$(2);; \
+	esac && \
+	cat $(LICENSE_FILES_DIR_$(4))/$(1)/$(2) >>$(LEGAL_LICENSES_TXT_$(4)) && \
+	echo >>$(LEGAL_LICENSES_TXT_$(4))
 endef
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/1 pkg-generic: Strip all but leading comments from C files used as license.

Dear Peter Rosin,

Quoted 3 lines · Peter Rosin

From: Peter Rosin <[email protected]>

Thanks for your contribution. Could you explain what is the problem with keeping a complete source file as legal information?

Quoted 22 lines
package/pkg-utils.mk +10 -3
index 44bd2c9..1497eb2 100644
@@ -145,8 +145,30 @@ endef
 
 define legal-license-file # pkg, filename, file-fullpath, {HOST|TARGET}
 	$(call legal-license-header,$(1),$(2) file,$(4)) && \
-	cat $(3) >>$(LEGAL_LICENSES_TXT_$(4)) && \
-	echo >>$(LEGAL_LICENSES_TXT_$(4)) && \
 	mkdir -p $(LICENSE_FILES_DIR_$(4))/$(1)/$(dir $(2)) && \
-	cp $(3) $(LICENSE_FILES_DIR_$(4))/$(1)/$(2)
+	case $(3) in \
+	*.c|*.h) \
+	  sed -e '\
+x;\
+/^$$/{\
+  x;\
+  /^[ \t]*$$/b;\
+  /^[ \t]*\/\//b;\
+  /^[ \t]*\/\*.*\*\//b;\
+  /^[ \t]*\/\*/h;\

package/pkg-utils.mk endef · line 168

Quoted 10 lines
package/pkg-utils.mk +10 -0
+  //b;\
+  s/.*//;\
+  q\
+};\
+x;\
+/\*\//{\
+  x;\
+  s/.*//;\
+  x\
+}' < $(3) > $(LICENSE_FILES_DIR_$(4))/$(1)/$(2) \

We quickly discussed your proposal on the #buildroot IRC, and the conclusion is that we generally don't like this, for at least two reasons:

1/ The sed expression is awfully complicated.

2/ There is absolutely no guarantee that the license part is inside
the leading comment and that the complicated sed expression will actually keep the relevant part of the file.

We generally try to use a fairly short source code file as the license text, so that keeping the entire file should not be a problem. If it remains a problem, then I would suggest that you work with the upstream project and ask them to include a separate license file that we can use.

Another possibility would be to do something like:

<pkg>_LICENSE_FILES = foo.c-23+42

to indicate that the license text is from line 23 to line 42. But it is again not very foolproof, and it doesn't give much benefits.

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#2 lore raw

PATCH 1/1 pkg-generic: Strip all but leading comments from C files used as license.

Quoted 8 lines · Thomas Petazzoni

Dear Peter Rosin,

Quoted 3 lines · Peter Rosin

From: Peter Rosin <[email protected]>

Thanks for your contribution. Could you explain what is the problem with keeping a complete source file as legal information?

It's not a big deal, but source code certainly looked out of place when I first scanned through licenses.txt. I guess you old-timers have just gotten used to having it there...

Quoted 38 lines
Quoted 22 lines
package/pkg-utils.mk +10 -3
index 44bd2c9..1497eb2 100644
@@ -145,8 +145,30 @@ endef
 
 define legal-license-file # pkg, filename, file-fullpath, {HOST|TARGET}
 	$(call legal-license-header,$(1),$(2) file,$(4)) && \
-	cat $(3) >>$(LEGAL_LICENSES_TXT_$(4)) && \
-	echo >>$(LEGAL_LICENSES_TXT_$(4)) && \
 	mkdir -p $(LICENSE_FILES_DIR_$(4))/$(1)/$(dir $(2)) && \
-	cp $(3) $(LICENSE_FILES_DIR_$(4))/$(1)/$(2)
+	case $(3) in \
+	*.c|*.h) \
+	  sed -e '\
+x;\
+/^$$/{\
+  x;\
+  /^[ \t]*$$/b;\
+  /^[ \t]*\/\//b;\
+  /^[ \t]*\/\*.*\*\//b;\
+  /^[ \t]*\/\*/h;\

package/pkg-utils.mk endef · line 168

Quoted 10 lines
package/pkg-utils.mk +10 -0
+  //b;\
+  s/.*//;\
+  q\
+};\
+x;\
+/\*\//{\
+  x;\
+  s/.*//;\
+  x\
+}' < $(3) > $(LICENSE_FILES_DIR_$(4))/$(1)/$(2) \

We quickly discussed your proposal on the #buildroot IRC, and the conclusion is that we generally don't like this, for at least two reasons:

1/ The sed expression is awfully complicated.

Quoted 8 lines

2/ There is absolutely no guarantee that the license part is inside
the leading comment and that the complicated sed expression will actually keep the relevant part of the file.

We generally try to use a fairly short source code file as the license text, so that keeping the entire file should not be a problem. If it remains a problem, then I would suggest that you work with the upstream project and ask them to include a separate license file that we can use.

I wouldn't call it a sed expression, it's a sed program really, but it's not very complicated once you get through the sed syntax. But I see your points. I just had a bit of fun writing it, no big deal if it gets thrown away here. I'll just run the same thing locally instead...

Quoted 7 lines

Another possibility would be to do something like:

<pkg>_LICENSE_FILES = foo.c-23+42

to indicate that the license text is from line 23 to line 42. But it is again not very foolproof, and it doesn't give much benefits.

Right, and that approach would require more care on version bumps...

Cheers,
Peter

#3 lore raw

PATCH 1/1 pkg-generic: Strip all but leading comments from C files used as license.

In reply to Peter Rosin
Quoted 19 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Peter" == Peter Rosin <[email protected]> writes:

From: Peter Rosin <[email protected]>

---
 package/pkg-utils.mk |   28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)
package/pkg-utils.mk +0 -2
index 44bd2c9..1497eb2 100644
@@ -145,8 +145,30 @@ endef
 
 define legal-license-file # pkg, filename, file-fullpath, {HOST|TARGET}
 	$(call legal-license-header,$(1),$(2) file,$(4)) && \
-	cat $(3) >>$(LEGAL_LICENSES_TXT_$(4)) && \
-	echo >>$(LEGAL_LICENSES_TXT_$(4)) && \
 	mkdir -p $(LICENSE_FILES_DIR_$(4))/$(1)/$(dir $(2)) && \

package/pkg-utils.mk endef · line 157

Quoted 10 lines
package/pkg-utils.mk +9 -1
-	cp $(3) $(LICENSE_FILES_DIR_$(4))/$(1)/$(2)
+	case $(3) in \
+	*.c|*.h) \
+	  sed -e '\
+x;\
+/^$$/{\
+  x;\
+  /^[ \t]*$$/b;\
+  /^[ \t]*\/\//b;\
+  /^[ \t]*\/\*.*\*\//b;\

Hmm, I don't think we want to fiddle with the content of the legal statements. Is there any real problem with having the complete .c / .h file? That's still helping people but not risking that we screw up anything.

Signature · 1 line
Bye, Peter Korsgaard