Skip to contentSkip to conversation

distribute_license: added class to copy license files

PATCH Superseded Chase Maupin 6 participants 7 messages Jul 29, 2010 – Aug 2, 2010

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 distribute_license: added class to copy license files

* This class can be used to copy license files from package sources into the deploy directory so they can be distributed.
* By default it searches the top-level source directory for files matching COPYING* or LICENSE*
* Search depth and pattern can be modified using the LICENSE_SEARCH_DEPTH and LICENSE_FILES variables respectively.

---
 classes/distribute_license.bbclass |   56 ++++++++++++++++++++++++++++++++++++
 1 files changed, 56 insertions(+), 0 deletions(-)
 create mode 100644 classes/distribute_license.bbclass
classes/distribute_license.bbclass new file +56 -0
new file mode 100644
index 0000000..795a404
@@ -0,0 +1,56 @@
+# distribute-license.bbclass will search the sources of a package to
+# a given depth looking for a match to the specified pattern and if
+# found will copy the matching file(s) to the deploy directory.
+#
+# This class is used to collect license files such as COPYING or
+# LICENSE where they are found and save them per package.
+#
+# This package uses the following variables to control its operations:
+#   - LICENSE_FILES         = Pattern of license files to be searched for.
+#                             By default this is COPYING* and LICENSE* but
+#                             this can be changed per package.
+#   - LICENSE_SEARCH_DEPTH  = The maximum depth to search in the package
+#                             sources for files matching the LICENSE_FILES
+#                             pattern.
+
+
+# Files to copy for the licensing.  By default this is looking for
+# files following the patters COPYING* or LICENSING* in the top
+# level sources directory.
+LICENSE_FILES ?= "COPYING* LICENSE*"
+
+# Maximum depth to look for license files
+LICENSE_SEARCH_DEPTH ?= "1"
+
+distribute_license_do_copy_license() {
+    # Change directory to source directory
+    cd ${S}
+
+    # Turn of globbing so that wildcards are not expanded in for loop
+    set -f
+
+    # Check if LICENSE_FILES exist.  If so copy them to DEPLOY_DIR
+    for lic in ${LICENSE_FILES}
+    do
+        res=""
+        res=`find . -maxdepth ${LICENSE_SEARCH_DEPTH} -name "$lic"`
+        if [ "$res" != "" ]
+        then
+            mkdir -p ${DEPLOY_DIR}/licenses/${PN}
+            cp $res ${DEPLOY_DIR}/licenses/${PN}
+        fi
+    done
+
+    # Turn globbing back on
+    set +f
+
+    # Just to be clean change directory back to where we started from.
+    cd -
+}
+
+EXPORT_FUNCTIONS do_copy_license
+
+# Put after do_patch in case a patch adds the license files
+do_copy_license[deptask] = "do_patch"
+
+addtask copy_license after do_patch before do_configure
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 39 lines · Chase Maupin

* This class can be used to copy license files from package sources into the deploy directory so they can be distributed.
* By default it searches the top-level source directory for files matching COPYING* or LICENSE*
* Search depth and pattern can be modified using the LICENSE_SEARCH_DEPTH and LICENSE_FILES variables respectively.

---
classes/distribute_license.bbclass | 56 ++++++++++++++++++++++++++++++++++++

1 files changed, 56 insertions(+), 0 deletions(-)

create mode 100644 classes/distribute_license.bbclass

classes/distribute_license.bbclass new file +19 -0
new file mode 100644
index 0000000..795a404
@@ -0,0 +1,56 @@
+# distribute-license.bbclass will search the sources of a package to
+# a given depth looking for a match to the specified pattern and if
+# found will copy the matching file(s) to the deploy directory.
+#
+# This class is used to collect license files such as COPYING or
+# LICENSE where they are found and save them per package.
+#
+# This package uses the following variables to control its operations:
+#   - LICENSE_FILES         = Pattern of license files to be searched for.
+#                             By default this is COPYING* and LICENSE* but
+#                             this can be changed per package.
+#   - LICENSE_SEARCH_DEPTH  = The maximum depth to search in the package
+#                             sources for files matching the LICENSE_FILES
+#                             pattern.
+
+
+# Files to copy for the licensing.  By default this is looking for
+# files following the patters COPYING* or LICENSING* in the top
+# level sources directory.

classes/distribute_license.bbclass line 29

Quoted 10 lines
classes/distribute_license.bbclass new file +10 -0
+LICENSE_FILES ?= "COPYING* LICENSE*"
+
+# Maximum depth to look for license files
+LICENSE_SEARCH_DEPTH ?= "1"
+
+distribute_license_do_copy_license() {
+    # Change directory to source directory
+    cd ${S}
+
+    # Turn of globbing so that wildcards are not expanded in for loop

/s/of/off/

classes/distribute_license.bbclass line 30

Quoted 1 line
classes/distribute_license.bbclass new file +1 -0
+    set -f

hush: set: -f: invalid option

classes/distribute_license.bbclass line 35

Quoted 5 lines
classes/distribute_license.bbclass new file +5 -0
+
+    # Check if LICENSE_FILES exist.  If so copy them to DEPLOY_DIR
+    for lic in ${LICENSE_FILES}
+    do
+        res=""

superfluous

classes/distribute_license.bbclass line 37

Quoted 2 lines
classes/distribute_license.bbclass new file +2 -0
+        res=`find . -maxdepth ${LICENSE_SEARCH_DEPTH} -name "$lic"`
+        if [ "$res" != "" ]

breaks on older test(1) impls that don't handle empty strings properly. Could be that this one is moot by now though.

classes/distribute_license.bbclass line 40

Quoted 3 lines
classes/distribute_license.bbclass new file +3 -0
+        then
+            mkdir -p ${DEPLOY_DIR}/licenses/${PN}
+            cp $res ${DEPLOY_DIR}/licenses/${PN}

install -D ${DEPLOY_DIR}/licenses/${PN} ${DEPLOY_DIR}/licenses/${PN}

classes/distribute_license.bbclass line 45

Quoted 5 lines
classes/distribute_license.bbclass new file +5 -0
+        fi
+    done
+
+    # Turn globbing back on
+    set +f

hush: set: +f: invalid option

classes/distribute_license.bbclass line 49

Quoted 4 lines
classes/distribute_license.bbclass new file +4 -0
+
+    # Just to be clean change directory back to where we started from.
+    cd -
+}

What's the reason you don't do that in python instead? Just curious as it would save quite some potential hazzle..

Quoted 9 lines
classes/distribute_license.bbclass new file +7 -0
+
+EXPORT_FUNCTIONS do_copy_license
+
+# Put after do_patch in case a patch adds the license files
+do_copy_license[deptask] = "do_patch"
+
+addtask copy_license after do_patch before do_configure
Signature · 1 line
1.7.0.4

someone should bump git to 1.7.2, a BBCLASSEXTENDEDed version seems to work for me ...

#2 lore raw
Quoted 58 lines

-----Original Message-----
From: Bernhard Reutner-Fischer [mailto:[email protected]]
Sent: Thursday, July 29, 2010 3:55 PM
To: [email protected]
Cc: Maupin, Chase
Subject: Re: [oe] [PATCH 1/1] distribute_license: added class to copy license files

Quoted 11 lines · Chase Maupin

* This class can be used to copy license files from package sources into the deploy directory so they can be distributed.
* By default it searches the top-level source directory for files matching COPYING* or LICENSE*
* Search depth and pattern can be modified using the LICENSE_SEARCH_DEPTH and LICENSE_FILES variables respectively.

---
classes/distribute_license.bbclass | 56

++++++++++++++++++++++++++++++++++++

Review

Quoted 4 lines
1 files changed, 56 insertions(+), 0 deletions(-)

create mode 100644 classes/distribute_license.bbclass

(quoted diff) +0 -0

b/classes/distribute_license.bbclass

Quoted 5 lines

new file mode 100644
index 0000000..795a404

classes/distribute_license.bbclass line 9

Quoted 9 lines
classes/distribute_license.bbclass new file +9 -0
@@ -0,0 +1,56 @@
+# distribute-license.bbclass will search the sources of a package to
+# a given depth looking for a match to the specified pattern and if
+# found will copy the matching file(s) to the deploy directory.
+#
+# This class is used to collect license files such as COPYING or
+# LICENSE where they are found and save them per package.
+#
+# This package uses the following variables to control its operations:
+#   - LICENSE_FILES         = Pattern of license files to be searched

for.

classes/distribute_license.bbclass line 10

Quoted 1 line
classes/distribute_license.bbclass new file +1 -0
+#                             By default this is COPYING* and LICENSE*

but

classes/distribute_license.bbclass

Quoted 3 lines
classes/distribute_license.bbclass new file +3 -0
+#                             this can be changed per package.
+#   - LICENSE_SEARCH_DEPTH  = The maximum depth to search in the package
+#                             sources for files matching the

LICENSE_FILES

Quoted 10 lines
classes/distribute_license.bbclass new file +10 -0
+#                             pattern.
+
+
+# Files to copy for the licensing.  By default this is looking for
+# files following the patters COPYING* or LICENSING* in the top
+# level sources directory.
+LICENSE_FILES ?= "COPYING* LICENSE*"
+
+# Maximum depth to look for license files
+LICENSE_SEARCH_DEPTH ?= "1"
Quoted 8 lines

classes/distribute_license.bbclass line 29

Quoted 6 lines
classes/distribute_license.bbclass new file +6 -0
+
+distribute_license_do_copy_license() {
+    # Change directory to source directory
+    cd ${S}
+
+    # Turn of globbing so that wildcards are not expanded in for loop

/s/of/off/

I'll update this

Quoted 4 lines

classes/distribute_license.bbclass line 30

Quoted 2 lines
classes/distribute_license.bbclass new file +1 -0
+    set -f

hush: set: -f: invalid option

I thought bash was the standard shell for working with OE. Is that wrong?

Quoted 8 lines

classes/distribute_license.bbclass line 35

Quoted 6 lines
classes/distribute_license.bbclass new file +5 -0
+
+    # Check if LICENSE_FILES exist.  If so copy them to DEPLOY_DIR
+    for lic in ${LICENSE_FILES}
+    do
+        res=""

superfluous

True, I'll go ahead and remove it.

Quoted 6 lines

classes/distribute_license.bbclass line 37

Quoted 3 lines
classes/distribute_license.bbclass new file +2 -0
+        res=`find . -maxdepth ${LICENSE_SEARCH_DEPTH} -name "$lic"`
+        if [ "$res" != "" ]

breaks on older test(1) impls that don't handle empty strings properly. Could be that this one is moot by now though.

So did this break for you? I've never seen this issue.

Quoted 6 lines

classes/distribute_license.bbclass line 40

Quoted 4 lines
classes/distribute_license.bbclass new file +3 -0
+        then
+            mkdir -p ${DEPLOY_DIR}/licenses/${PN}
+            cp $res ${DEPLOY_DIR}/licenses/${PN}

install -D ${DEPLOY_DIR}/licenses/${PN} ${DEPLOY_DIR}/licenses/${PN}

I'll change this

Quoted 8 lines

classes/distribute_license.bbclass line 45

Quoted 6 lines
classes/distribute_license.bbclass new file +5 -0
+        fi
+    done
+
+    # Turn globbing back on
+    set +f

hush: set: +f: invalid option

Same question as above

Quoted 8 lines

classes/distribute_license.bbclass line 49

Quoted 5 lines
classes/distribute_license.bbclass new file +4 -0
+
+    # Just to be clean change directory back to where we started from.
+    cd -
+}

What's the reason you don't do that in python instead? Just curious as it would save quite some potential hazzle..

I know shell and not python, it's as simple as that. If you want to rewrite this in python with the same functionality that's OK with me :)

Quoted 13 lines
Quoted 10 lines
classes/distribute_license.bbclass new file +7 -1
+
+EXPORT_FUNCTIONS do_copy_license
+
+# Put after do_patch in case a patch adds the license files
+do_copy_license[deptask] = "do_patch"
+
+addtask copy_license after do_patch before do_configure
--

1.7.0.4

someone should bump git to 1.7.2, a BBCLASSEXTENDEDed version seems to work for me ...

Sorry, I don't understand what my git version has to do with BBCLASSEXTEND.

#3 lore raw
Quoted 5 lines · Chase
Quoted 3 lines
Quoted 1 line

+ set -f

hush: set: -f: invalid option

I thought bash was the standard shell for working with OE. Is that wrong?

You're right, it is (and -f is a mandatory flag so disregard this, sorry)

Quoted 7 lines
Quoted 5 lines

classes/distribute_license.bbclass line 37

Quoted 2 lines
classes/distribute_license.bbclass new file +2 -0
+        res=`find . -maxdepth ${LICENSE_SEARCH_DEPTH} -name "$lic"`
+        if [ "$res" != "" ]

breaks on older test(1) impls that don't handle empty strings properly. Could be that this one is moot by now though.

So did this break for you? I've never seen this issue.

[ -n "$res" ]

Quoted 9 lines
Quoted 7 lines

classes/distribute_license.bbclass line 40

Quoted 5 lines
classes/distribute_license.bbclass new file +3 -0
+        then
+            mkdir -p ${DEPLOY_DIR}/licenses/${PN}
+            cp $res ${DEPLOY_DIR}/licenses/${PN}

install -D ${DEPLOY_DIR}/licenses/${PN} ${DEPLOY_DIR}/licenses/${PN}

I'll change this

typo of mine: the first non-option argument should have been $res, of course.

essentially you mean (if you say it in sh)
set -f
for lic in ${LICENSE_FILES}
do

  find ${S} -maxdepth ${LICENSE_SEARCH_DEPTH} -name "$lic" | \
    while read f
    do
      bn=$(basename $f)
      if [ -r ${DEPLOY_DIR}/licenses/${PN}/$bn ]; then
        # we could have used $d.$bn for per-dir licenses
        # d=$(echo $f | sed -e "s|${S}||" -e normalize-and-convert-slashes-to-underscore)
        echo "ERROR: possibly conflicting licenses"
        exit 1
      fi
      install -D $f ${DEPLOY_DIR}/licenses/${PN}/$bn
    done

done
set +f

This leaves you with just one non-standard hunk: -maxdepth Given that both findutils as well as busybox support -maxdepth i would not bother much.
Just a thought.. your initial version may be sufficient for most practical reasons.

cheers,

#4 lore raw
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+ set -f

hush: set: -f: invalid option

I thought bash was the standard shell for working with OE. Is that wrong?

You're right, it is (and -f is a mandatory flag so disregard this, sorry)

Just yesterday I was spanked on IRC for wanting to use bashisms. I was told OE should work with any reasonable posix-compliant shell.

Regards,

David

#5 lore raw
In reply to Bernhard Reutner-Fischer

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 53 lines · Bernhard Reutner-Fischer
Quoted 39 lines · Chase Maupin

* This class can be used to copy license files from package sources into the deploy directory so they can be distributed.
* By default it searches the top-level source directory for files matching COPYING* or LICENSE*
* Search depth and pattern can be modified using the LICENSE_SEARCH_DEPTH and LICENSE_FILES variables respectively.

---
classes/distribute_license.bbclass | 56 ++++++++++++++++++++++++++++++++++++

1 files changed, 56 insertions(+), 0 deletions(-)

create mode 100644 classes/distribute_license.bbclass

classes/distribute_license.bbclass new file +19 -0
new file mode 100644
index 0000000..795a404
@@ -0,0 +1,56 @@
+# distribute-license.bbclass will search the sources of a package to
+# a given depth looking for a match to the specified pattern and if
+# found will copy the matching file(s) to the deploy directory.
+#
+# This class is used to collect license files such as COPYING or
+# LICENSE where they are found and save them per package.
+#
+# This package uses the following variables to control its operations:
+#   - LICENSE_FILES         = Pattern of license files to be searched for.
+#                             By default this is COPYING* and LICENSE* but
+#                             this can be changed per package.
+#   - LICENSE_SEARCH_DEPTH  = The maximum depth to search in the package
+#                             sources for files matching the LICENSE_FILES
+#                             pattern.
+
+
+# Files to copy for the licensing.  By default this is looking for
+# files following the patters COPYING* or LICENSING* in the top
+# level sources directory.

classes/distribute_license.bbclass line 29

Quoted 10 lines
classes/distribute_license.bbclass new file +10 -0
+LICENSE_FILES ?= "COPYING* LICENSE*"
+
+# Maximum depth to look for license files
+LICENSE_SEARCH_DEPTH ?= "1"
+
+distribute_license_do_copy_license() {
+    # Change directory to source directory
+    cd ${S}
+
+    # Turn of globbing so that wildcards are not expanded in for loop

/s/of/off/

Quoted 3 lines

classes/distribute_license.bbclass line 30

Quoted 1 line
classes/distribute_license.bbclass new file +1 -0
+    set -f

hush: set: -f: invalid option

I don't think we realistically support something different than bash. Having said that, adding hashisms is bad, do you have a suggestion for a more portable approach?

regards,

Koen
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)

iD8DBQFMUnWrMkyGM64RGpERAi/2AKCGmm0kgEu54YytOloQwn5r54WH/ACfbw2+ 4wUfIALobrMrVMin2tcloyU=
=wG8e
-----END PGP SIGNATURE-----

#6 lore raw
Quoted 5 lines · Koen Kooi
Quoted 1 line

hush: set: -f: invalid option

I don't think we realistically support something different than bash. Having said that, adding hashisms is bad, do you have a suggestion for a more portable approach?

I've been building with dash as /bin/sh with no problems for almost 2 years now. Not many gtk packages though. Anyway, I do not see any reason to introduce bashisms, but if you do not know how to do it "properly" in a portable way, you can always specificaly run bash to run certain scripts, as adding bash to OE's prerequisites is less intrusive than requiring /bin/sh to be bash.

Marc