Jim Flynn | 7852b2d | 2022-08-02 22:44:08 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright © 2022 Arm Ltd and Contributors. All rights reserved. |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
| 7 | # |
| 8 | # Script which uses the reuse license compliance tool: https://reuse.software/ |
| 9 | # to do the following: |
| 10 | # (a) check armnn for compliance |
| 11 | # (b) generate an SPDX file |
| 12 | # (c) insert into the SPDX file before the individual files section, SPDX files for |
| 13 | # all the third-party header only source libraries used by Arm NN |
| 14 | # to create a comprehensive LICENSE.spdx file for the armnn source code distribution |
| 15 | # |
| 16 | # Note to run correctly the script has to be run from the armnn root directory like so: |
| 17 | # |
| 18 | # ./scripts/generate_spdx.sh |
| 19 | # |
| 20 | |
| 21 | # Check if the parent directory name is armnn |
| 22 | # Get the name of the current directory |
| 23 | result=${PWD##*/} # to assign to a variable |
| 24 | result=${result:-/} # to correct for the case where PWD=/ |
| 25 | |
| 26 | if [[ $result != "armnn" ]] |
| 27 | then |
| 28 | echo "not running from armnn directory" |
| 29 | exit -2 |
| 30 | fi |
| 31 | |
| 32 | # Check that the third-party subdirectory exists |
| 33 | if [ ! -d "third-party" ]; then |
| 34 | echo "third-party directory does not exist." |
| 35 | exit -3 |
| 36 | fi |
| 37 | |
| 38 | # Check that armnn is compliant with version 3.0 of the REUSE Specification |
| 39 | reuse lint |
| 40 | if [[ $? -ne 0 ]] |
| 41 | then |
| 42 | echo " " |
| 43 | echo "please make armnn compliant with version 3.0 of the REUSE Specification before re-running" |
| 44 | exit -4 |
| 45 | fi |
| 46 | |
| 47 | # generate the SPDX file for the overall armnn package |
| 48 | reuse spdx > LICENSE.spdx |
| 49 | if [[ $? -ne 0 ]] |
| 50 | then |
| 51 | echo "generation of LICENSE.spdx file failed" |
| 52 | exit -5 |
| 53 | else |
| 54 | echo " " |
| 55 | echo "LICENSE.spdx file generated" |
| 56 | echo " " |
| 57 | fi |
| 58 | |
| 59 | # Add the license info for the third-party packages |
| 60 | # NOTE: they will be added before the first individual file entry |
| 61 | # which currently is './Android.bp' |
| 62 | |
| 63 | # insert header comment before the line: FileName: ./Android.bp |
| 64 | sed -i '/FileName: \.\/Android.bp/i \ |
| 65 | ##### Source dependencies \ |
| 66 | # Header only libraries from the armnn source repository third-party folder \ |
| 67 | # NOTE: fmt has a small .cc file that needs to be compiled in order to work hence the libfmt.a below in the static dependencies \ |
| 68 | ' LICENSE.spdx |
| 69 | |
| 70 | # iterate over the LICENSE.spdx files in the third-party directory and |
| 71 | # put their contents into the top level LICENSE.spdx file |
| 72 | # before the line: FileName: ./Android.bp |
| 73 | |
| 74 | for i in ./third-party/**/LICENSE.spdx; |
| 75 | do |
| 76 | echo "inserting license $i" |
| 77 | sed -i "/FileName: \.\/Android.bp/e cat $i" LICENSE.spdx |
| 78 | sed -i '/FileName: \.\/Android.bp/i \ |
| 79 | ' LICENSE.spdx |
| 80 | done |
| 81 | |
| 82 | # Mark the start of the individual files section of the file with a comment |
| 83 | sed -i '/FileName: \.\/Android.bp/i \ |
| 84 | ##### Individual Files \ |
| 85 | ' LICENSE.spdx |