| @@ -1,15 +1,15 @@ | | | @@ -1,15 +1,15 @@ |
1 | #! @PYTHONBIN@ | | 1 | #! @PYTHONBIN@ |
2 | # $NetBSD: url2pkg.py,v 1.26 2019/11/14 20:03:47 rillig Exp $ | | 2 | # $NetBSD: url2pkg.py,v 1.27 2019/11/18 07:50:51 rillig Exp $ |
3 | | | 3 | |
4 | # Copyright (c) 2019 The NetBSD Foundation, Inc. | | 4 | # Copyright (c) 2019 The NetBSD Foundation, Inc. |
5 | # All rights reserved. | | 5 | # All rights reserved. |
6 | # | | 6 | # |
7 | # This code is derived from software contributed to The NetBSD Foundation | | 7 | # This code is derived from software contributed to The NetBSD Foundation |
8 | # by Roland Illig. | | 8 | # by Roland Illig. |
9 | # | | 9 | # |
10 | # Redistribution and use in source and binary forms, with or without | | 10 | # Redistribution and use in source and binary forms, with or without |
11 | # modification, are permitted provided that the following conditions | | 11 | # modification, are permitted provided that the following conditions |
12 | # are met: | | 12 | # are met: |
13 | # 1. Redistributions of source code must retain the above copyright | | 13 | # 1. Redistributions of source code must retain the above copyright |
14 | # notice, this list of conditions and the following disclaimer. | | 14 | # notice, this list of conditions and the following disclaimer. |
15 | # 2. Redistributions in binary form must reproduce the above copyright | | 15 | # 2. Redistributions in binary form must reproduce the above copyright |
| @@ -37,27 +37,27 @@ | | | @@ -37,27 +37,27 @@ |
37 | # This happens in two phases. Phase 1 is done by the Generator and generates | | 37 | # This happens in two phases. Phase 1 is done by the Generator and generates |
38 | # an initial Makefile, just enough to download the distfile. Phase 2 then | | 38 | # an initial Makefile, just enough to download the distfile. Phase 2 then |
39 | # takes the generated Makefile and applies various adjustments for different | | 39 | # takes the generated Makefile and applies various adjustments for different |
40 | # types of packages, such as Perl or Python modules. This is done by the | | 40 | # types of packages, such as Perl or Python modules. This is done by the |
41 | # Adjuster class. | | 41 | # Adjuster class. |
42 | | | 42 | |
43 | | | 43 | |
44 | import getopt | | 44 | import getopt |
45 | import os | | 45 | import os |
46 | import re | | 46 | import re |
47 | import subprocess | | 47 | import subprocess |
48 | import sys | | 48 | import sys |
49 | from pathlib import Path | | 49 | from pathlib import Path |
50 | from typing import Any, Callable, Dict, List, NamedTuple, Optional, Tuple, Union | | 50 | from typing import Any, Callable, Dict, List, NamedTuple, Optional, Set, Tuple, Union |
51 | | | 51 | |
52 | | | 52 | |
53 | class Var(NamedTuple): | | 53 | class Var(NamedTuple): |
54 | """ An abstract variable assignment for the package Makefile. """ | | 54 | """ An abstract variable assignment for the package Makefile. """ |
55 | name: str | | 55 | name: str |
56 | op: str | | 56 | op: str |
57 | value: str | | 57 | value: str |
58 | | | 58 | |
59 | | | 59 | |
60 | class Varassign(NamedTuple): | | 60 | class Varassign(NamedTuple): |
61 | """ A variable assignment including layout information. """ | | 61 | """ A variable assignment including layout information. """ |
62 | index: int | | 62 | index: int |
63 | varname: str | | 63 | varname: str |
| @@ -593,26 +593,29 @@ class Adjuster: | | | @@ -593,26 +593,29 @@ class Adjuster: |
593 | # "package>=version:../../category/package". | | 593 | # "package>=version:../../category/package". |
594 | depends: List[str] | | 594 | depends: List[str] |
595 | build_depends: List[str] | | 595 | build_depends: List[str] |
596 | test_depends: List[str] | | 596 | test_depends: List[str] |
597 | | | 597 | |
598 | # .include, interleaved with BUILDLINK3_API_DEPENDS. | | 598 | # .include, interleaved with BUILDLINK3_API_DEPENDS. |
599 | # These lines are added at the bottom of the Makefile. | | 599 | # These lines are added at the bottom of the Makefile. |
600 | bl3_lines: List[str] | | 600 | bl3_lines: List[str] |
601 | | | 601 | |
602 | # a list of pathnames relative to the package directory. | | 602 | # a list of pathnames relative to the package directory. |
603 | # All these files will be included at the bottom of the Makefile. | | 603 | # All these files will be included at the bottom of the Makefile. |
604 | includes: List[str] | | 604 | includes: List[str] |
605 | | | 605 | |
| | | 606 | # the tools for USE_TOOLS. Examples are sed, echo, printf, perl5. |
| | | 607 | tools: Set[str] |
| | | 608 | |
606 | # a list of variable assignments that will make up the fourth | | 609 | # a list of variable assignments that will make up the fourth |
607 | # paragraph of the package Makefile, where the build configuration | | 610 | # paragraph of the package Makefile, where the build configuration |
608 | # takes place. | | 611 | # takes place. |
609 | build_vars: List[Var] | | 612 | build_vars: List[Var] |
610 | | | 613 | |
611 | # similar to the @build_vars, but separated by an empty line in | | 614 | # similar to the @build_vars, but separated by an empty line in |
612 | # the Makefile, thereby forming the fifth paragraph. | | 615 | # the Makefile, thereby forming the fifth paragraph. |
613 | extra_vars: List[Var] | | 616 | extra_vars: List[Var] |
614 | | | 617 | |
615 | # these are inserted below the second paragraph in the Makefile. | | 618 | # these are inserted below the second paragraph in the Makefile. |
616 | todos: List[str] | | 619 | todos: List[str] |
617 | | | 620 | |
618 | # the package name is based on DISTNAME and modified by | | 621 | # the package name is based on DISTNAME and modified by |
| @@ -632,26 +635,27 @@ class Adjuster: | | | @@ -632,26 +635,27 @@ class Adjuster: |
632 | self.url = url | | 635 | self.url = url |
633 | self.initial_lines = initial_lines | | 636 | self.initial_lines = initial_lines |
634 | self.abs_wrkdir = Path('') | | 637 | self.abs_wrkdir = Path('') |
635 | self.abs_wrksrc = Path('') | | 638 | self.abs_wrksrc = Path('') |
636 | self.wrksrc_files = [] | | 639 | self.wrksrc_files = [] |
637 | self.wrksrc_dirs = [] | | 640 | self.wrksrc_dirs = [] |
638 | self.categories = [] | | 641 | self.categories = [] |
639 | self.depends = [] | | 642 | self.depends = [] |
640 | self.build_depends = [] | | 643 | self.build_depends = [] |
641 | self.test_depends = [] | | 644 | self.test_depends = [] |
642 | self.bl3_lines = [] | | 645 | self.bl3_lines = [] |
643 | self.includes = [] | | 646 | self.includes = [] |
644 | self.build_vars = [] | | 647 | self.build_vars = [] |
| | | 648 | self.tools = set() |
645 | self.extra_vars = [] | | 649 | self.extra_vars = [] |
646 | self.todos = [] | | 650 | self.todos = [] |
647 | self.pkgname_prefix = '' | | 651 | self.pkgname_prefix = '' |
648 | self.pkgname_transform = '' | | 652 | self.pkgname_transform = '' |
649 | self.makefile_lines = Lines() | | 653 | self.makefile_lines = Lines() |
650 | self.regenerate_distinfo = False | | 654 | self.regenerate_distinfo = False |
651 | self.descr_lines = [] | | 655 | self.descr_lines = [] |
652 | | | 656 | |
653 | def add_dependency(self, kind: str, pkgbase: str, constraint: str, dep_dir: str) -> None: | | 657 | def add_dependency(self, kind: str, pkgbase: str, constraint: str, dep_dir: str) -> None: |
654 | """ add_dependency('DEPENDS', 'package', '>=1', '../../category/package') """ | | 658 | """ add_dependency('DEPENDS', 'package', '>=1', '../../category/package') """ |
655 | | | 659 | |
656 | self.g.debug('add_dependency: {0} {1} {2} {3}', kind, pkgbase, constraint, dep_dir) | | 660 | self.g.debug('add_dependency: {0} {1} {2} {3}', kind, pkgbase, constraint, dep_dir) |
657 | | | 661 | |
| @@ -807,26 +811,30 @@ class Adjuster: | | | @@ -807,26 +811,30 @@ class Adjuster: |
807 | return | | 811 | return |
808 | | | 812 | |
809 | configures = self.wrksrc_find(r'(^|/)configure$') | | 813 | configures = self.wrksrc_find(r'(^|/)configure$') |
810 | if configures: | | 814 | if configures: |
811 | gnu = any(self.wrksrc_grep(configure, r'\b(Free Software Foundation|autoconf)\b') | | 815 | gnu = any(self.wrksrc_grep(configure, r'\b(Free Software Foundation|autoconf)\b') |
812 | for configure in configures) | | 816 | for configure in configures) |
813 | varname = 'GNU_CONFIGURE' if gnu else 'HAS_CONFIGURE' | | 817 | varname = 'GNU_CONFIGURE' if gnu else 'HAS_CONFIGURE' |
814 | self.build_vars.append(Var(varname, '=', 'yes')) | | 818 | self.build_vars.append(Var(varname, '=', 'yes')) |
815 | | | 819 | |
816 | def adjust_cmake(self): | | 820 | def adjust_cmake(self): |
817 | if self.wrksrc_isfile('CMakeLists.txt'): | | 821 | if self.wrksrc_isfile('CMakeLists.txt'): |
818 | self.build_vars.append(Var('USE_CMAKE', '=', 'yes')) | | 822 | self.build_vars.append(Var('USE_CMAKE', '=', 'yes')) |
819 | | | 823 | |
| | | 824 | def adjust_gnu_make(self): |
| | | 825 | if self.wrksrc_isfile('Makefile') and self.wrksrc_grep('Makefile', r'^(?:ifeq|ifdef)\b'): |
| | | 826 | self.tools.add('gmake') |
| | | 827 | |
820 | def adjust_meson(self): | | 828 | def adjust_meson(self): |
821 | if self.wrksrc_isfile('meson.build'): | | 829 | if self.wrksrc_isfile('meson.build'): |
822 | self.includes.append('../../devel/meson/build.mk') | | 830 | self.includes.append('../../devel/meson/build.mk') |
823 | | | 831 | |
824 | def adjust_gconf2_schemas(self): | | 832 | def adjust_gconf2_schemas(self): |
825 | gconf2_files = self.wrksrc_find(r'\.schemas(\.in)*$') | | 833 | gconf2_files = self.wrksrc_find(r'\.schemas(\.in)*$') |
826 | if gconf2_files: | | 834 | if gconf2_files: |
827 | self.includes.append('../../devel/GConf/schemas.mk') | | 835 | self.includes.append('../../devel/GConf/schemas.mk') |
828 | | | 836 | |
829 | for f in gconf2_files: | | 837 | for f in gconf2_files: |
830 | self.extra_vars.append(Var('GCONF_SCHEMAS', '+=', re.sub(r'(\.in)+$', '', f))) | | 838 | self.extra_vars.append(Var('GCONF_SCHEMAS', '+=', re.sub(r'(\.in)+$', '', f))) |
831 | | | 839 | |
832 | def adjust_libtool(self): | | 840 | def adjust_libtool(self): |
| @@ -1032,27 +1040,30 @@ class Adjuster: | | | @@ -1032,27 +1040,30 @@ class Adjuster: |
1032 | lines.lines.insert(distname_index + 1, pkgname_line) | | 1040 | lines.lines.insert(distname_index + 1, pkgname_line) |
1033 | | | 1041 | |
1034 | if self.todos: | | 1042 | if self.todos: |
1035 | for todo in self.todos: | | 1043 | for todo in self.todos: |
1036 | lines.add('# TODO: ' + todo) | | 1044 | lines.add('# TODO: ' + todo) |
1037 | lines.add('') | | 1045 | lines.add('') |
1038 | | | 1046 | |
1039 | depend_vars = [] | | 1047 | depend_vars = [] |
1040 | depend_vars.extend(Var('BUILD_DEPENDS', '+=', d) for d in self.build_depends) | | 1048 | depend_vars.extend(Var('BUILD_DEPENDS', '+=', d) for d in self.build_depends) |
1041 | depend_vars.extend(Var('DEPENDS', '+=', d) for d in self.depends) | | 1049 | depend_vars.extend(Var('DEPENDS', '+=', d) for d in self.depends) |
1042 | depend_vars.extend(Var('TEST_DEPENDS', '+=', d) for d in self.test_depends) | | 1050 | depend_vars.extend(Var('TEST_DEPENDS', '+=', d) for d in self.test_depends) |
1043 | lines.add_vars(*depend_vars) | | 1051 | lines.add_vars(*depend_vars) |
1044 | | | 1052 | |
1045 | lines.add_vars(*self.build_vars) | | 1053 | build_vars = self.build_vars |
| | | 1054 | if self.tools: |
| | | 1055 | build_vars.append(Var('USE_TOOLS', '+=', ' '.join(sorted(self.tools)))) |
| | | 1056 | lines.add_vars(*build_vars) |
1046 | lines.add_vars(*self.extra_vars) | | 1057 | lines.add_vars(*self.extra_vars) |
1047 | | | 1058 | |
1048 | lines.add(*self.bl3_lines) | | 1059 | lines.add(*self.bl3_lines) |
1049 | lines.add(*(f'.include "{include}"' for include in self.includes)) | | 1060 | lines.add(*(f'.include "{include}"' for include in self.includes)) |
1050 | | | 1061 | |
1051 | lines.add(*self.makefile_lines.lines[marker_index + 1:]) | | 1062 | lines.add(*self.makefile_lines.lines[marker_index + 1:]) |
1052 | | | 1063 | |
1053 | lines.append('CATEGORIES', ' '.join(self.categories)) | | 1064 | lines.append('CATEGORIES', ' '.join(self.categories)) |
1054 | | | 1065 | |
1055 | self.adjust_lines_python_module(lines) | | 1066 | self.adjust_lines_python_module(lines) |
1056 | | | 1067 | |
1057 | return lines | | 1068 | return lines |
1058 | | | 1069 | |
| @@ -1064,26 +1075,27 @@ class Adjuster: | | | @@ -1064,26 +1075,27 @@ class Adjuster: |
1064 | return list(sorted((f for f in relative if not f.startswith('.')))) | | 1075 | return list(sorted((f for f in relative if not f.startswith('.')))) |
1065 | | | 1076 | |
1066 | self.g.debug('Adjusting the Makefile') | | 1077 | self.g.debug('Adjusting the Makefile') |
1067 | self.makefile_lines = Lines.read_from(self.g.pkgdir / 'Makefile') | | 1078 | self.makefile_lines = Lines.read_from(self.g.pkgdir / 'Makefile') |
1068 | | | 1079 | |
1069 | self.abs_wrkdir = Path(self.g.show_var('WRKDIR')) | | 1080 | self.abs_wrkdir = Path(self.g.show_var('WRKDIR')) |
1070 | self.determine_wrksrc() | | 1081 | self.determine_wrksrc() |
1071 | self.wrksrc_dirs = scan(self.abs_wrksrc, Path.is_dir) | | 1082 | self.wrksrc_dirs = scan(self.abs_wrksrc, Path.is_dir) |
1072 | self.wrksrc_files = scan(self.abs_wrksrc, Path.is_file) | | 1083 | self.wrksrc_files = scan(self.abs_wrksrc, Path.is_file) |
1073 | | | 1084 | |
1074 | self.adjust_descr() | | 1085 | self.adjust_descr() |
1075 | self.adjust_configure() | | 1086 | self.adjust_configure() |
1076 | self.adjust_cmake() | | 1087 | self.adjust_cmake() |
| | | 1088 | self.adjust_gnu_make() |
1077 | self.adjust_meson() | | 1089 | self.adjust_meson() |
1078 | self.adjust_gconf2_schemas() | | 1090 | self.adjust_gconf2_schemas() |
1079 | self.adjust_libtool() | | 1091 | self.adjust_libtool() |
1080 | self.adjust_perl_module() | | 1092 | self.adjust_perl_module() |
1081 | self.adjust_python_module() | | 1093 | self.adjust_python_module() |
1082 | self.adjust_cargo() | | 1094 | self.adjust_cargo() |
1083 | self.adjust_pkg_config() | | 1095 | self.adjust_pkg_config() |
1084 | self.adjust_po() | | 1096 | self.adjust_po() |
1085 | self.adjust_use_languages() | | 1097 | self.adjust_use_languages() |
1086 | | | 1098 | |
1087 | self.generate_lines().write_to(self.g.pkgdir / 'Makefile') | | 1099 | self.generate_lines().write_to(self.g.pkgdir / 'Makefile') |
1088 | descr = (self.g.pkgdir / 'DESCR') | | 1100 | descr = (self.g.pkgdir / 'DESCR') |
1089 | descr.is_file() or Lines(*self.descr_lines).write_to(descr) | | 1101 | descr.is_file() or Lines(*self.descr_lines).write_to(descr) |