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 23result=${PWD##*/} # to assign to a variable 24result=${result:-/} # to correct for the case where PWD=/ 25 26if [[ $result != "armnn" ]] 27then 28 echo "not running from armnn directory" 29 exit -2 30fi 31 32# Check that the third-party subdirectory exists 33if [ ! -d "third-party" ]; then 34 echo "third-party directory does not exist." 35 exit -3 36fi 37 38# Check that armnn is compliant with version 3.0 of the REUSE Specification 39reuse lint 40if [[ $? -ne 0 ]] 41then 42 echo " " 43 echo "please make armnn compliant with version 3.0 of the REUSE Specification before re-running" 44 exit -4 45fi 46 47# generate the SPDX file for the overall armnn package 48reuse spdx > LICENSE.spdx 49if [[ $? -ne 0 ]] 50then 51 echo "generation of LICENSE.spdx file failed" 52 exit -5 53else 54 echo " " 55 echo "LICENSE.spdx file generated" 56 echo " " 57fi 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 64sed -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 74for i in ./third-party/**/LICENSE.spdx; 75do 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 80done 81 82# Mark the start of the individual files section of the file with a comment 83sed -i '/FileName: \.\/Android.bp/i \ 84##### Individual Files \ 85 ' LICENSE.spdx 86