diff options
Diffstat (limited to 'scripts/lib/recipetool/create.py')
-rw-r--r-- | scripts/lib/recipetool/create.py | 115 |
1 files changed, 77 insertions, 38 deletions
diff --git a/scripts/lib/recipetool/create.py b/scripts/lib/recipetool/create.py index 40bd3c820b..26011451dd 100644 --- a/scripts/lib/recipetool/create.py +++ b/scripts/lib/recipetool/create.py | |||
@@ -618,9 +618,10 @@ def create_recipe(args): | |||
618 | # We need a blank line here so that patch_recipe_lines can rewind before the LICENSE comments | 618 | # We need a blank line here so that patch_recipe_lines can rewind before the LICENSE comments |
619 | lines_before.append('') | 619 | lines_before.append('') |
620 | 620 | ||
621 | handled = [] | 621 | # We'll come back and replace this later in handle_license_vars() |
622 | licvalues = handle_license_vars(srctree_use, lines_before, handled, extravalues, tinfoil.config_data) | 622 | lines_before.append('##LICENSE_PLACEHOLDER##') |
623 | 623 | ||
624 | handled = [] | ||
624 | classes = [] | 625 | classes = [] |
625 | 626 | ||
626 | # FIXME This is kind of a hack, we probably ought to be using bitbake to do this | 627 | # FIXME This is kind of a hack, we probably ought to be using bitbake to do this |
@@ -751,6 +752,8 @@ def create_recipe(args): | |||
751 | if name_pv and not realpv: | 752 | if name_pv and not realpv: |
752 | realpv = name_pv | 753 | realpv = name_pv |
753 | 754 | ||
755 | licvalues = handle_license_vars(srctree_use, lines_before, handled, extravalues, tinfoil.config_data) | ||
756 | |||
754 | if not outfile: | 757 | if not outfile: |
755 | if not pn: | 758 | if not pn: |
756 | log_error_cond('Unable to determine short program name from source tree - please specify name with -N/--name or output file name with -o/--outfile', args.devtool) | 759 | log_error_cond('Unable to determine short program name from source tree - please specify name with -N/--name or output file name with -o/--outfile', args.devtool) |
@@ -843,9 +846,6 @@ def create_recipe(args): | |||
843 | outlines.extend(lines_after) | 846 | outlines.extend(lines_after) |
844 | 847 | ||
845 | if extravalues: | 848 | if extravalues: |
846 | if 'LICENSE' in extravalues and not licvalues: | ||
847 | # Don't blow away 'CLOSED' value that comments say we set | ||
848 | del extravalues['LICENSE'] | ||
849 | _, outlines = oe.recipeutils.patch_recipe_lines(outlines, extravalues, trailing_newline=False) | 849 | _, outlines = oe.recipeutils.patch_recipe_lines(outlines, extravalues, trailing_newline=False) |
850 | 850 | ||
851 | if args.extract_to: | 851 | if args.extract_to: |
@@ -889,55 +889,94 @@ def check_single_file(fn, fetchuri): | |||
889 | logger.error('Fetching "%s" returned a single HTML page - check the URL is correct and functional' % fetchuri) | 889 | logger.error('Fetching "%s" returned a single HTML page - check the URL is correct and functional' % fetchuri) |
890 | sys.exit(1) | 890 | sys.exit(1) |
891 | 891 | ||
892 | def split_value(value): | ||
893 | if isinstance(value, str): | ||
894 | return value.split() | ||
895 | else: | ||
896 | return value | ||
892 | 897 | ||
893 | def handle_license_vars(srctree, lines_before, handled, extravalues, d): | 898 | def handle_license_vars(srctree, lines_before, handled, extravalues, d): |
899 | lichandled = [x for x in handled if x[0] == 'license'] | ||
900 | if lichandled: | ||
901 | # Someone else has already handled the license vars, just return their value | ||
902 | return lichandled[0][1] | ||
903 | |||
894 | licvalues = guess_license(srctree, d) | 904 | licvalues = guess_license(srctree, d) |
905 | licenses = [] | ||
895 | lic_files_chksum = [] | 906 | lic_files_chksum = [] |
896 | lic_unknown = [] | 907 | lic_unknown = [] |
908 | lines = [] | ||
897 | if licvalues: | 909 | if licvalues: |
898 | licenses = [] | ||
899 | for licvalue in licvalues: | 910 | for licvalue in licvalues: |
900 | if not licvalue[0] in licenses: | 911 | if not licvalue[0] in licenses: |
901 | licenses.append(licvalue[0]) | 912 | licenses.append(licvalue[0]) |
902 | lic_files_chksum.append('file://%s;md5=%s' % (licvalue[1], licvalue[2])) | 913 | lic_files_chksum.append('file://%s;md5=%s' % (licvalue[1], licvalue[2])) |
903 | if licvalue[0] == 'Unknown': | 914 | if licvalue[0] == 'Unknown': |
904 | lic_unknown.append(licvalue[1]) | 915 | lic_unknown.append(licvalue[1]) |
905 | lines_before.append('# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is') | ||
906 | lines_before.append('# your responsibility to verify that the values are complete and correct.') | ||
907 | if len(licvalues) > 1: | ||
908 | lines_before.append('#') | ||
909 | lines_before.append('# NOTE: multiple licenses have been detected; they have been separated with &') | ||
910 | lines_before.append('# in the LICENSE value for now since it is a reasonable assumption that all') | ||
911 | lines_before.append('# of the licenses apply. If instead there is a choice between the multiple') | ||
912 | lines_before.append('# licenses then you should change the value to separate the licenses with |') | ||
913 | lines_before.append('# instead of &. If there is any doubt, check the accompanying documentation') | ||
914 | lines_before.append('# to determine which situation is applicable.') | ||
915 | if lic_unknown: | 916 | if lic_unknown: |
916 | lines_before.append('#') | 917 | lines.append('#') |
917 | lines_before.append('# The following license files were not able to be identified and are') | 918 | lines.append('# The following license files were not able to be identified and are') |
918 | lines_before.append('# represented as "Unknown" below, you will need to check them yourself:') | 919 | lines.append('# represented as "Unknown" below, you will need to check them yourself:') |
919 | for licfile in lic_unknown: | 920 | for licfile in lic_unknown: |
920 | lines_before.append('# %s' % licfile) | 921 | lines.append('# %s' % licfile) |
921 | lines_before.append('#') | 922 | |
922 | else: | 923 | extra_license = split_value(extravalues.pop('LICENSE', [])) |
923 | lines_before.append('# Unable to find any files that looked like license statements. Check the accompanying') | 924 | if '&' in extra_license: |
924 | lines_before.append('# documentation and source headers and set LICENSE and LIC_FILES_CHKSUM accordingly.') | 925 | extra_license.remove('&') |
925 | lines_before.append('#') | 926 | if extra_license: |
926 | lines_before.append('# NOTE: LICENSE is being set to "CLOSED" to allow you to at least start building - if') | ||
927 | lines_before.append('# this is not accurate with respect to the licensing of the software being built (it') | ||
928 | lines_before.append('# will not be in most cases) you must specify the correct value before using this') | ||
929 | lines_before.append('# recipe for anything other than initial testing/development!') | ||
930 | licenses = ['CLOSED'] | ||
931 | pkg_license = extravalues.pop('LICENSE', None) | ||
932 | if pkg_license: | ||
933 | if licenses == ['Unknown']: | 927 | if licenses == ['Unknown']: |
934 | lines_before.append('# NOTE: The following LICENSE value was determined from the original package metadata') | 928 | licenses = extra_license |
935 | licenses = [pkg_license] | ||
936 | else: | 929 | else: |
937 | lines_before.append('# NOTE: Original package metadata indicates license is: %s' % pkg_license) | 930 | for item in extra_license: |
938 | lines_before.append('LICENSE = "%s"' % ' & '.join(licenses)) | 931 | if item not in licenses: |
939 | lines_before.append('LIC_FILES_CHKSUM = "%s"' % ' \\\n '.join(lic_files_chksum)) | 932 | licenses.append(item) |
940 | lines_before.append('') | 933 | extra_lic_files_chksum = split_value(extravalues.pop('LIC_FILES_CHKSUM', [])) |
934 | for item in extra_lic_files_chksum: | ||
935 | if item not in lic_files_chksum: | ||
936 | lic_files_chksum.append(item) | ||
937 | |||
938 | if lic_files_chksum: | ||
939 | # We are going to set the vars, so prepend the standard disclaimer | ||
940 | lines.insert(0, '# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is') | ||
941 | lines.insert(1, '# your responsibility to verify that the values are complete and correct.') | ||
942 | else: | ||
943 | # Without LIC_FILES_CHKSUM we set LICENSE = "CLOSED" to allow the | ||
944 | # user to get started easily | ||
945 | lines.append('# Unable to find any files that looked like license statements. Check the accompanying') | ||
946 | lines.append('# documentation and source headers and set LICENSE and LIC_FILES_CHKSUM accordingly.') | ||
947 | lines.append('#') | ||
948 | lines.append('# NOTE: LICENSE is being set to "CLOSED" to allow you to at least start building - if') | ||
949 | lines.append('# this is not accurate with respect to the licensing of the software being built (it') | ||
950 | lines.append('# will not be in most cases) you must specify the correct value before using this') | ||
951 | lines.append('# recipe for anything other than initial testing/development!') | ||
952 | licenses = ['CLOSED'] | ||
953 | |||
954 | if extra_license and sorted(licenses) != sorted(extra_license): | ||
955 | lines.append('# NOTE: Original package / source metadata indicates license is: %s' % ' & '.join(extra_license)) | ||
956 | |||
957 | if len(licenses) > 1: | ||
958 | lines.append('#') | ||
959 | lines.append('# NOTE: multiple licenses have been detected; they have been separated with &') | ||
960 | lines.append('# in the LICENSE value for now since it is a reasonable assumption that all') | ||
961 | lines.append('# of the licenses apply. If instead there is a choice between the multiple') | ||
962 | lines.append('# licenses then you should change the value to separate the licenses with |') | ||
963 | lines.append('# instead of &. If there is any doubt, check the accompanying documentation') | ||
964 | lines.append('# to determine which situation is applicable.') | ||
965 | |||
966 | lines.append('LICENSE = "%s"' % ' & '.join(licenses)) | ||
967 | lines.append('LIC_FILES_CHKSUM = "%s"' % ' \\\n '.join(lic_files_chksum)) | ||
968 | lines.append('') | ||
969 | |||
970 | # Replace the placeholder so we get the values in the right place in the recipe file | ||
971 | try: | ||
972 | pos = lines_before.index('##LICENSE_PLACEHOLDER##') | ||
973 | except ValueError: | ||
974 | pos = -1 | ||
975 | if pos == -1: | ||
976 | lines_before.extend(lines) | ||
977 | else: | ||
978 | lines_before[pos:pos+1] = lines | ||
979 | |||
941 | handled.append(('license', licvalues)) | 980 | handled.append(('license', licvalues)) |
942 | return licvalues | 981 | return licvalues |
943 | 982 | ||