| @@ -1,49 +1,49 @@ | | | @@ -1,49 +1,49 @@ |
1 | # $NetBSD: url2pkg_test.py,v 1.19 2019/10/12 17:28:44 rillig Exp $ | | 1 | # $NetBSD: url2pkg_test.py,v 1.20 2019/10/12 17:38:16 rillig Exp $ |
2 | | | 2 | |
3 | import pytest | | 3 | import pytest |
4 | from url2pkg import * | | 4 | from url2pkg import * |
5 | | | 5 | |
6 | mkcvsid = '# $''NetBSD$' | | 6 | mkcvsid = '# $''NetBSD$' |
7 | up: Url2Pkg | | 7 | g: Globals |
8 | prev_dir = Path.cwd() | | 8 | prev_dir = Path.cwd() |
9 | | | 9 | |
10 | | | 10 | |
11 | def setup_function(_): | | 11 | def setup_function(_): |
12 | global up | | 12 | global g |
13 | | | 13 | |
14 | up = Url2Pkg() | | 14 | g = Globals() |
15 | os.chdir(up.pkgsrcdir / 'pkgtools' / 'url2pkg') | | 15 | os.chdir(g.pkgsrcdir / 'pkgtools' / 'url2pkg') |
16 | | | 16 | |
17 | class Wr: | | 17 | class Wr: |
18 | def __init__(self) -> None: | | 18 | def __init__(self) -> None: |
19 | self.buf = '' | | 19 | self.buf = '' |
20 | | | 20 | |
21 | def write(self, s: str): | | 21 | def write(self, s: str): |
22 | self.buf += s | | 22 | self.buf += s |
23 | | | 23 | |
24 | def written(self) -> List[str]: | | 24 | def written(self) -> List[str]: |
25 | result = self.buf | | 25 | result = self.buf |
26 | self.buf = '' | | 26 | self.buf = '' |
27 | return result.splitlines() | | 27 | return result.splitlines() |
28 | | | 28 | |
29 | up.out = Wr() | | 29 | g.out = Wr() |
30 | up.err = Wr() | | 30 | g.err = Wr() |
31 | | | 31 | |
32 | | | 32 | |
33 | def teardown_function(_): | | 33 | def teardown_function(_): |
34 | os.chdir(prev_dir) | | 34 | os.chdir(prev_dir) |
35 | assert up.out.written() == [] | | 35 | assert g.out.written() == [] |
36 | assert up.err.written() == [] | | 36 | assert g.err.written() == [] |
37 | | | 37 | |
38 | | | 38 | |
39 | def str_vars(vars: List[Var]) -> List[str]: | | 39 | def str_vars(vars: List[Var]) -> List[str]: |
40 | def to_string(var): | | 40 | def to_string(var): |
41 | return var.name + var.op + var.value | | 41 | return var.name + var.op + var.value |
42 | | | 42 | |
43 | return list(map(to_string, vars)) | | 43 | return list(map(to_string, vars)) |
44 | | | 44 | |
45 | | | 45 | |
46 | def str_varassigns(varassigns: List[Varassign]) -> List[str]: | | 46 | def str_varassigns(varassigns: List[Varassign]) -> List[str]: |
47 | def to_string(v: Varassign) -> str: | | 47 | def to_string(v: Varassign) -> str: |
48 | return f'{v.varname}{v.op}{v.indent}' \ | | 48 | return f'{v.varname}{v.op}{v.indent}' \ |
49 | f'{v.value}{v.space_after_value}{v.comment}' | | 49 | f'{v.value}{v.space_after_value}{v.comment}' |
| @@ -56,49 +56,49 @@ def detab(lines: Lines) -> List[str]: | | | @@ -56,49 +56,49 @@ def detab(lines: Lines) -> List[str]: |
56 | | | 56 | |
57 | def detab_line(line: str) -> str: | | 57 | def detab_line(line: str) -> str: |
58 | detabbed = [] | | 58 | detabbed = [] |
59 | for ch in line: | | 59 | for ch in line: |
60 | if ch == '\t': | | 60 | if ch == '\t': |
61 | detabbed.append(' '[:8 - len(detabbed) % 8]) | | 61 | detabbed.append(' '[:8 - len(detabbed) % 8]) |
62 | else: | | 62 | else: |
63 | detabbed.append(ch) | | 63 | detabbed.append(ch) |
64 | return ''.join(detabbed) | | 64 | return ''.join(detabbed) |
65 | | | 65 | |
66 | return list(map(detab_line, lines.lines)) | | 66 | return list(map(detab_line, lines.lines)) |
67 | | | 67 | |
68 | | | 68 | |
69 | def test_Url2Pkg_debug(): | | 69 | def test_Global_debug(): |
70 | up.verbose = True | | 70 | g.verbose = True |
71 | | | 71 | |
72 | up.debug('plain message') | | 72 | g.debug('plain message') |
73 | up.debug('list {0}', [1, 2, 3]) | | 73 | g.debug('list {0}', [1, 2, 3]) |
74 | up.debug('tuple {0}', (1, 2, 3)) | | 74 | g.debug('tuple {0}', (1, 2, 3)) |
75 | up.debug('cwd {0} env {1} cmd {2}', 'directory', {'VAR': 'value'}, 'command') | | 75 | g.debug('cwd {0} env {1} cmd {2}', 'directory', {'VAR': 'value'}, 'command') |
76 | | | 76 | |
77 | assert up.err.written() == [ | | 77 | assert g.err.written() == [ |
78 | 'url2pkg: plain message', | | 78 | 'url2pkg: plain message', |
79 | 'url2pkg: list [1, 2, 3]', | | 79 | 'url2pkg: list [1, 2, 3]', |
80 | 'url2pkg: tuple (1, 2, 3)', | | 80 | 'url2pkg: tuple (1, 2, 3)', |
81 | 'url2pkg: cwd \'directory\' env {\'VAR\': \'value\'} cmd \'command\'', | | 81 | 'url2pkg: cwd \'directory\' env {\'VAR\': \'value\'} cmd \'command\'', |
82 | ] | | 82 | ] |
83 | | | 83 | |
84 | | | 84 | |
85 | def test_Url2Pkg_bmake(): | | 85 | def test_Global_bmake(): |
86 | up.verbose = True | | 86 | g.verbose = True |
87 | up.make = 'echo' | | 87 | g.make = 'echo' |
88 | | | 88 | |
89 | up.bmake('hello', 'world') | | 89 | g.bmake('hello', 'world') |
90 | | | 90 | |
91 | assert up.err.written() == [ | | 91 | assert g.err.written() == [ |
92 | 'url2pkg: running bmake (\'hello\', \'world\') in \'.\'', | | 92 | 'url2pkg: running bmake (\'hello\', \'world\') in \'.\'', |
93 | ] | | 93 | ] |
94 | | | 94 | |
95 | | | 95 | |
96 | def test_Lines__write_and_read(tmp_path: Path): | | 96 | def test_Lines__write_and_read(tmp_path: Path): |
97 | example = tmp_path / 'example' | | 97 | example = tmp_path / 'example' |
98 | | | 98 | |
99 | lines = Lines('1', '2', '3') | | 99 | lines = Lines('1', '2', '3') |
100 | | | 100 | |
101 | lines.write_to(example) | | 101 | lines.write_to(example) |
102 | | | 102 | |
103 | assert example.read_text() == '1\n2\n3\n' | | 103 | assert example.read_text() == '1\n2\n3\n' |
104 | | | 104 | |
| @@ -524,27 +524,27 @@ def test_Generator_adjust_site_from_site | | | @@ -524,27 +524,27 @@ def test_Generator_adjust_site_from_site |
524 | 'MASTER_SITES= ${MASTER_SITE_GNU:=cflow/}', | | 524 | 'MASTER_SITES= ${MASTER_SITE_GNU:=cflow/}', |
525 | '', | | 525 | '', |
526 | 'MAINTAINER= INSERT_YOUR_MAIL_ADDRESS_HERE # or use pkgsrc-users@NetBSD.org', | | 526 | 'MAINTAINER= INSERT_YOUR_MAIL_ADDRESS_HERE # or use pkgsrc-users@NetBSD.org', |
527 | 'HOMEPAGE= https://www.gnu.org/software/cflow/', | | 527 | 'HOMEPAGE= https://www.gnu.org/software/cflow/', |
528 | 'COMMENT= TODO: Short description of the package', | | 528 | 'COMMENT= TODO: Short description of the package', |
529 | '#LICENSE= # TODO: (see mk/license.mk)', | | 529 | '#LICENSE= # TODO: (see mk/license.mk)', |
530 | '', | | 530 | '', |
531 | '# url2pkg-marker (please do not remove this line.)', | | 531 | '# url2pkg-marker (please do not remove this line.)', |
532 | '.include "../../mk/bsd.pkg.mk"', | | 532 | '.include "../../mk/bsd.pkg.mk"', |
533 | ] | | 533 | ] |
534 | | | 534 | |
535 | | | 535 | |
536 | def test_Generator_adjust_site_from_sites_mk__R(tmp_path: Path): | | 536 | def test_Generator_adjust_site_from_sites_mk__R(tmp_path: Path): |
537 | up.pkgdir = tmp_path | | 537 | g.pkgdir = tmp_path |
538 | url = 'http://cran.r-project.org/src/contrib/forecast_8.7.tar.gz' | | 538 | url = 'http://cran.r-project.org/src/contrib/forecast_8.7.tar.gz' |
539 | generator = Generator(url) | | 539 | generator = Generator(url) |
540 | | | 540 | |
541 | with pytest.raises(SystemExit, match='^url2pkg: to create R packages, use pkgtools/R2pkg instead$'): | | 541 | with pytest.raises(SystemExit, match='^url2pkg: to create R packages, use pkgtools/R2pkg instead$'): |
542 | generator.generate_Makefile() | | 542 | generator.generate_Makefile() |
543 | | | 543 | |
544 | assert list(tmp_path.glob('*')) == [] | | 544 | assert list(tmp_path.glob('*')) == [] |
545 | | | 545 | |
546 | | | 546 | |
547 | def test_Generator_adjust_site_other__malformed_URL(): | | 547 | def test_Generator_adjust_site_other__malformed_URL(): |
548 | # This error is supposed to be handled by the URL check in main. | | 548 | # This error is supposed to be handled by the URL check in main. |
549 | | | 549 | |
550 | error = "'NoneType' object has no attribute 'groups'" | | 550 | error = "'NoneType' object has no attribute 'groups'" |
| @@ -615,58 +615,58 @@ def test_Generator_adjust_everything_els | | | @@ -615,58 +615,58 @@ def test_Generator_adjust_everything_els |
615 | '', | | 615 | '', |
616 | 'MAINTAINER= INSERT_YOUR_MAIL_ADDRESS_HERE # or use pkgsrc-users@NetBSD.org', | | 616 | 'MAINTAINER= INSERT_YOUR_MAIL_ADDRESS_HERE # or use pkgsrc-users@NetBSD.org', |
617 | 'HOMEPAGE= https://example.org/', | | 617 | 'HOMEPAGE= https://example.org/', |
618 | 'COMMENT= TODO: Short description of the package', | | 618 | 'COMMENT= TODO: Short description of the package', |
619 | '#LICENSE= # TODO: (see mk/license.mk)', | | 619 | '#LICENSE= # TODO: (see mk/license.mk)', |
620 | '', | | 620 | '', |
621 | '# url2pkg-marker (please do not remove this line.)', | | 621 | '# url2pkg-marker (please do not remove this line.)', |
622 | '.include "../../mk/bsd.pkg.mk"', | | 622 | '.include "../../mk/bsd.pkg.mk"', |
623 | ] | | 623 | ] |
624 | | | 624 | |
625 | | | 625 | |
626 | def test_Generator_generate_package(tmp_path: Path): | | 626 | def test_Generator_generate_package(tmp_path: Path): |
627 | url = 'https://ftp.gnu.org/pub/gnu/cflow/cflow-1.6.tar.gz' | | 627 | url = 'https://ftp.gnu.org/pub/gnu/cflow/cflow-1.6.tar.gz' |
628 | up.editor = 'true' # the shell command | | 628 | g.editor = 'true' # the shell command |
629 | up.make = 'true' # the shell command | | 629 | g.make = 'true' # the shell command |
630 | up.pkgdir = tmp_path | | 630 | g.pkgdir = tmp_path |
631 | | | 631 | |
632 | Generator(url).generate_package(up) | | 632 | Generator(url).generate_package(g) |
633 | | | 633 | |
634 | assert (tmp_path / 'DESCR').read_text() == '' | | 634 | assert (tmp_path / 'DESCR').read_text() == '' |
635 | assert len((tmp_path / 'Makefile').read_text().splitlines()) == 13 | | 635 | assert len((tmp_path / 'Makefile').read_text().splitlines()) == 13 |
636 | assert (tmp_path / 'PLIST').read_text() == '@comment $''NetBSD$\n' | | 636 | assert (tmp_path / 'PLIST').read_text() == '@comment $''NetBSD$\n' |
637 | | | 637 | |
638 | # Since bmake is only fake in this test, the distinfo file is not created. | | 638 | # Since bmake is only fake in this test, the distinfo file is not created. |
639 | expected_files = ['DESCR', 'Makefile', 'PLIST'] | | 639 | expected_files = ['DESCR', 'Makefile', 'PLIST'] |
640 | assert sorted([f.name for f in tmp_path.glob("*")]) == expected_files | | 640 | assert sorted([f.name for f in tmp_path.glob("*")]) == expected_files |
641 | | | 641 | |
642 | | | 642 | |
643 | def test_Adjuster_read_dependencies(): | | 643 | def test_Adjuster_read_dependencies(): |
644 | child_process_output = [ | | 644 | child_process_output = [ |
645 | 'DEPENDS\tpackage>=112.0:../../pkgtools/pkglint', | | 645 | 'DEPENDS\tpackage>=112.0:../../pkgtools/pkglint', |
646 | 'DEPENDS\tpackage>=120.0:../../pkgtools/x11-links', | | 646 | 'DEPENDS\tpackage>=120.0:../../pkgtools/x11-links', |
647 | 'BUILD_DEPENDS\turl2pkg>=1.0', | | 647 | 'BUILD_DEPENDS\turl2pkg>=1.0', |
648 | 'BUILD_DEPENDS\tdoes-not-exist>=1.0', | | 648 | 'BUILD_DEPENDS\tdoes-not-exist>=1.0', |
649 | 'TEST_DEPENDS\tpkglint', | | 649 | 'TEST_DEPENDS\tpkglint', |
650 | 'A line that is not a dependency at all', | | 650 | 'A line that is not a dependency at all', |
651 | '', | | 651 | '', |
652 | 'var\tHOMEPAGE\thttps://homepage.example.org/', | | 652 | 'var\tHOMEPAGE\thttps://homepage.example.org/', |
653 | 'var\t#LICENSE\tBSD # TODO: too unspecific', | | 653 | 'var\t#LICENSE\tBSD # TODO: too unspecific', |
654 | '' | | 654 | '' |
655 | ] | | 655 | ] |
656 | env = {'URL2PKG_DEPENDENCIES': '\n'.join(child_process_output)} | | 656 | env = {'URL2PKG_DEPENDENCIES': '\n'.join(child_process_output)} |
657 | cmd = "printf '%s\n' \"$URL2PKG_DEPENDENCIES\"" | | 657 | cmd = "printf '%s\n' \"$URL2PKG_DEPENDENCIES\"" |
658 | | | 658 | |
659 | adjuster = Adjuster(up, '', Lines()) | | 659 | adjuster = Adjuster(g, '', Lines()) |
660 | adjuster.read_dependencies(cmd, env, '.', '') | | 660 | adjuster.read_dependencies(cmd, env, '.', '') |
661 | | | 661 | |
662 | assert os.getenv('URL2PKG_DEPENDENCIES') is None | | 662 | assert os.getenv('URL2PKG_DEPENDENCIES') is None |
663 | assert adjuster.depends == ['package>=112.0:../../pkgtools/pkglint'] | | 663 | assert adjuster.depends == ['package>=112.0:../../pkgtools/pkglint'] |
664 | assert adjuster.bl3_lines == [ | | 664 | assert adjuster.bl3_lines == [ |
665 | 'BUILDLINK_API_DEPENDS.x11-links+=\tx11-links>=120.0', | | 665 | 'BUILDLINK_API_DEPENDS.x11-links+=\tx11-links>=120.0', |
666 | ".include \"../../pkgtools/x11-links/buildlink3.mk\"", | | 666 | ".include \"../../pkgtools/x11-links/buildlink3.mk\"", |
667 | ] | | 667 | ] |
668 | assert adjuster.build_depends == [ | | 668 | assert adjuster.build_depends == [ |
669 | 'url2pkg>=1.0:../../pkgtools/url2pkg', | | 669 | 'url2pkg>=1.0:../../pkgtools/url2pkg', |
670 | '# TODO: does-not-exist>=1.0', | | 670 | '# TODO: does-not-exist>=1.0', |
671 | ] | | 671 | ] |
672 | assert adjuster.test_depends == ['pkglint>=0:../../pkgtools/pkglint'] | | 672 | assert adjuster.test_depends == ['pkglint>=0:../../pkgtools/pkglint'] |
| @@ -674,71 +674,71 @@ def test_Adjuster_read_dependencies(): | | | @@ -674,71 +674,71 @@ def test_Adjuster_read_dependencies(): |
674 | 'HOMEPAGE': 'https://homepage.example.org/', | | 674 | 'HOMEPAGE': 'https://homepage.example.org/', |
675 | '#LICENSE': 'BSD # TODO: too unspecific', | | 675 | '#LICENSE': 'BSD # TODO: too unspecific', |
676 | } | | 676 | } |
677 | | | 677 | |
678 | | | 678 | |
679 | def test_Adjuster_read_dependencies__lookup_with_prefix(): | | 679 | def test_Adjuster_read_dependencies__lookup_with_prefix(): |
680 | child_process_output = [ | | 680 | child_process_output = [ |
681 | 'DEPENDS\tpyobjc-framework-Quartz>=0', | | 681 | 'DEPENDS\tpyobjc-framework-Quartz>=0', |
682 | '' | | 682 | '' |
683 | ] | | 683 | ] |
684 | env = {'URL2PKG_DEPENDENCIES': '\n'.join(child_process_output)} | | 684 | env = {'URL2PKG_DEPENDENCIES': '\n'.join(child_process_output)} |
685 | cmd = "printf '%s\n' \"$URL2PKG_DEPENDENCIES\"" | | 685 | cmd = "printf '%s\n' \"$URL2PKG_DEPENDENCIES\"" |
686 | | | 686 | |
687 | adjuster = Adjuster(up, '', Lines()) | | 687 | adjuster = Adjuster(g, '', Lines()) |
688 | adjuster.read_dependencies(cmd, env, '.', 'py-') | | 688 | adjuster.read_dependencies(cmd, env, '.', 'py-') |
689 | | | 689 | |
690 | assert adjuster.depends == [ | | 690 | assert adjuster.depends == [ |
691 | 'py-pyobjc-framework-Quartz>=0:../../devel/py-pyobjc-framework-Quartz', | | 691 | 'py-pyobjc-framework-Quartz>=0:../../devel/py-pyobjc-framework-Quartz', |
692 | ] | | 692 | ] |
693 | | | 693 | |
694 | | | 694 | |
695 | def test_Adjuster_wrksrc_grep(tmp_path: Path): | | 695 | def test_Adjuster_wrksrc_grep(tmp_path: Path): |
696 | adjuster = Adjuster(up, '', Lines()) | | 696 | adjuster = Adjuster(g, '', Lines()) |
697 | adjuster.abs_wrksrc = tmp_path | | 697 | adjuster.abs_wrksrc = tmp_path |
698 | (tmp_path / 'file').write_text('\n'.join( | | 698 | (tmp_path / 'file').write_text('\n'.join( |
699 | ('a', 'b', 'c', 'd', 'e', 'abc', 'def', 'ghi') | | 699 | ('a', 'b', 'c', 'd', 'e', 'abc', 'def', 'ghi') |
700 | )) | | 700 | )) |
701 | | | 701 | |
702 | assert adjuster.wrksrc_grep('file', r'e') == ['e', 'def'] | | 702 | assert adjuster.wrksrc_grep('file', r'e') == ['e', 'def'] |
703 | assert adjuster.wrksrc_grep('file', r'(.)(.)(.)') == [ | | 703 | assert adjuster.wrksrc_grep('file', r'(.)(.)(.)') == [ |
704 | ['a', 'b', 'c'], | | 704 | ['a', 'b', 'c'], |
705 | ['d', 'e', 'f'], | | 705 | ['d', 'e', 'f'], |
706 | ['g', 'h', 'i'], | | 706 | ['g', 'h', 'i'], |
707 | ] | | 707 | ] |
708 | | | 708 | |
709 | | | 709 | |
710 | def test_Adjuster_generate_adjusted_Makefile_lines(): | | 710 | def test_Adjuster_generate_adjusted_Makefile_lines(): |
711 | adjuster = Adjuster(up, 'https://example.org/pkgname-1.0.tar.gz', Lines()) | | 711 | adjuster = Adjuster(g, 'https://example.org/pkgname-1.0.tar.gz', Lines()) |
712 | adjuster.makefile_lines = Lines( | | 712 | adjuster.makefile_lines = Lines( |
713 | '# before 1', | | 713 | '# before 1', |
714 | '# before 2', | | 714 | '# before 2', |
715 | '# url2pkg-marker', | | 715 | '# url2pkg-marker', |
716 | '# after 1', | | 716 | '# after 1', |
717 | '# after 2' | | 717 | '# after 2' |
718 | ) | | 718 | ) |
719 | | | 719 | |
720 | lines = adjuster.generate_lines() | | 720 | lines = adjuster.generate_lines() |
721 | | | 721 | |
722 | assert lines.lines == [ | | 722 | assert lines.lines == [ |
723 | '# before 1', | | 723 | '# before 1', |
724 | '# before 2', | | 724 | '# before 2', |
725 | '# after 1', | | 725 | '# after 1', |
726 | '# after 2', | | 726 | '# after 2', |
727 | ] | | 727 | ] |
728 | | | 728 | |
729 | | | 729 | |
730 | def test_Adjuster_generate_adjusted_Makefile_lines__dependencies(): | | 730 | def test_Adjuster_generate_adjusted_Makefile_lines__dependencies(): |
731 | adjuster = Adjuster(up, 'https://example.org/pkgname-1.0.tar.gz', Lines()) | | 731 | adjuster = Adjuster(g, 'https://example.org/pkgname-1.0.tar.gz', Lines()) |
732 | adjuster.makefile_lines.add( | | 732 | adjuster.makefile_lines.add( |
733 | mkcvsid, | | 733 | mkcvsid, |
734 | '', | | 734 | '', |
735 | '# url2pkg-marker', | | 735 | '# url2pkg-marker', |
736 | ".include \"../../mk/bsd.pkg.mk\"" | | 736 | ".include \"../../mk/bsd.pkg.mk\"" |
737 | ) | | 737 | ) |
738 | # some dependencies whose directory will not be found | | 738 | # some dependencies whose directory will not be found |
739 | adjuster.add_dependency('DEPENDS', 'depends', '>=5.0', '../../devel/depends') | | 739 | adjuster.add_dependency('DEPENDS', 'depends', '>=5.0', '../../devel/depends') |
740 | adjuster.add_dependency('TOOL_DEPENDS', 'tool-depends', '>=6.0', '../../devel/tool-depends') | | 740 | adjuster.add_dependency('TOOL_DEPENDS', 'tool-depends', '>=6.0', '../../devel/tool-depends') |
741 | adjuster.add_dependency('BUILD_DEPENDS', 'build-depends', '>=7.0', '../../devel/build-depends') | | 741 | adjuster.add_dependency('BUILD_DEPENDS', 'build-depends', '>=7.0', '../../devel/build-depends') |
742 | adjuster.add_dependency('TEST_DEPENDS', 'test-depends', '>=8.0', '../../devel/test-depends') | | 742 | adjuster.add_dependency('TEST_DEPENDS', 'test-depends', '>=8.0', '../../devel/test-depends') |
743 | # some dependencies whose directory is explicitly given | | 743 | # some dependencies whose directory is explicitly given |
744 | adjuster.depends.append('depends>=11.0:../../devel/depends') | | 744 | adjuster.depends.append('depends>=11.0:../../devel/depends') |
| @@ -754,273 +754,273 @@ def test_Adjuster_generate_adjusted_Make | | | @@ -754,273 +754,273 @@ def test_Adjuster_generate_adjusted_Make |
754 | '', | | 754 | '', |
755 | 'BUILD_DEPENDS+= # TODO: build-depends>=7.0', | | 755 | 'BUILD_DEPENDS+= # TODO: build-depends>=7.0', |
756 | 'BUILD_DEPENDS+= build-depends>=12.0:../../devel/build-depends', | | 756 | 'BUILD_DEPENDS+= build-depends>=12.0:../../devel/build-depends', |
757 | 'DEPENDS+= # TODO: depends>=5.0', | | 757 | 'DEPENDS+= # TODO: depends>=5.0', |
758 | 'DEPENDS+= depends>=11.0:../../devel/depends', | | 758 | 'DEPENDS+= depends>=11.0:../../devel/depends', |
759 | 'TEST_DEPENDS+= # TODO: test-depends>=8.0', | | 759 | 'TEST_DEPENDS+= # TODO: test-depends>=8.0', |
760 | 'TEST_DEPENDS+= test-depends>=13.0:../../devel/test-depends', | | 760 | 'TEST_DEPENDS+= test-depends>=13.0:../../devel/test-depends', |
761 | '', | | 761 | '', |
762 | ".include \"../../mk/bsd.pkg.mk\"" | | 762 | ".include \"../../mk/bsd.pkg.mk\"" |
763 | ] | | 763 | ] |
764 | | | 764 | |
765 | | | 765 | |
766 | def test_Adjuster_generate_adjusted_Makefile_lines__dont_overwrite_PKGNAME(): | | 766 | def test_Adjuster_generate_adjusted_Makefile_lines__dont_overwrite_PKGNAME(): |
767 | adjuster = Adjuster(up, 'https://example.org/pkgname-1.0.tar.gz', Lines()) | | 767 | adjuster = Adjuster(g, 'https://example.org/pkgname-1.0.tar.gz', Lines()) |
768 | adjuster.makefile_lines.add( | | 768 | adjuster.makefile_lines.add( |
769 | mkcvsid, | | 769 | mkcvsid, |
770 | 'DISTNAME=\tdistname-1.0', | | 770 | 'DISTNAME=\tdistname-1.0', |
771 | 'PKGNAME=\tmanually-edited-pkgname-1.0' | | 771 | 'PKGNAME=\tmanually-edited-pkgname-1.0' |
772 | '', | | 772 | '', |
773 | '# url2pkg-marker', | | 773 | '# url2pkg-marker', |
774 | ".include \"../../mk/bsd.pkg.mk\"" | | 774 | ".include \"../../mk/bsd.pkg.mk\"" |
775 | ) | | 775 | ) |
776 | | | 776 | |
777 | lines = adjuster.generate_lines() | | 777 | lines = adjuster.generate_lines() |
778 | | | 778 | |
779 | assert detab(lines) == [ | | 779 | assert detab(lines) == [ |
780 | mkcvsid, | | 780 | mkcvsid, |
781 | 'DISTNAME= distname-1.0', | | 781 | 'DISTNAME= distname-1.0', |
782 | 'PKGNAME= manually-edited-pkgname-1.0', | | 782 | 'PKGNAME= manually-edited-pkgname-1.0', |
783 | ".include \"../../mk/bsd.pkg.mk\"" | | 783 | ".include \"../../mk/bsd.pkg.mk\"" |
784 | ] | | 784 | ] |
785 | | | 785 | |
786 | | | 786 | |
787 | def test_Adjuster_generate_adjusted_Makefile_lines__add_PKGNAME(): | | 787 | def test_Adjuster_generate_adjusted_Makefile_lines__add_PKGNAME(): |
788 | adjuster = Adjuster(up, 'https://example.org/pkgname-1.0.tar.gz', Lines()) | | 788 | adjuster = Adjuster(g, 'https://example.org/pkgname-1.0.tar.gz', Lines()) |
789 | adjuster.makefile_lines.add( | | 789 | adjuster.makefile_lines.add( |
790 | mkcvsid, | | 790 | mkcvsid, |
791 | 'DISTNAME=\tdistname-1.0', | | 791 | 'DISTNAME=\tdistname-1.0', |
792 | '', | | 792 | '', |
793 | '# url2pkg-marker', | | 793 | '# url2pkg-marker', |
794 | ".include \"../../mk/bsd.pkg.mk\"" | | 794 | ".include \"../../mk/bsd.pkg.mk\"" |
795 | ) | | 795 | ) |
796 | | | 796 | |
797 | lines = adjuster.generate_lines() | | 797 | lines = adjuster.generate_lines() |
798 | | | 798 | |
799 | assert lines.lines == [ | | 799 | assert lines.lines == [ |
800 | mkcvsid, | | 800 | mkcvsid, |
801 | 'DISTNAME=\tdistname-1.0', | | 801 | 'DISTNAME=\tdistname-1.0', |
802 | '', | | 802 | '', |
803 | ".include \"../../mk/bsd.pkg.mk\"" | | 803 | ".include \"../../mk/bsd.pkg.mk\"" |
804 | ] | | 804 | ] |
805 | | | 805 | |
806 | | | 806 | |
807 | def test_Adjuster_generate_adjusted_Makefile_lines__add_PKGNAME_with_prefix(): | | 807 | def test_Adjuster_generate_adjusted_Makefile_lines__add_PKGNAME_with_prefix(): |
808 | adjuster = Adjuster(up, 'https://example.org/pkgname-1.0.tar.gz', Lines()) | | 808 | adjuster = Adjuster(g, 'https://example.org/pkgname-1.0.tar.gz', Lines()) |
809 | adjuster.makefile_lines.add( | | 809 | adjuster.makefile_lines.add( |
810 | mkcvsid, | | 810 | mkcvsid, |
811 | 'DISTNAME=\tdistname-1.0', | | 811 | 'DISTNAME=\tdistname-1.0', |
812 | '', | | 812 | '', |
813 | '# url2pkg-marker', | | 813 | '# url2pkg-marker', |
814 | ".include \"../../mk/bsd.pkg.mk\"" | | 814 | ".include \"../../mk/bsd.pkg.mk\"" |
815 | ) | | 815 | ) |
816 | adjuster.pkgname_prefix = '${PYPKGPREFIX}-' | | 816 | adjuster.pkgname_prefix = '${PYPKGPREFIX}-' |
817 | | | 817 | |
818 | lines = adjuster.generate_lines() | | 818 | lines = adjuster.generate_lines() |
819 | | | 819 | |
820 | assert lines.lines == [ | | 820 | assert lines.lines == [ |
821 | mkcvsid, | | 821 | mkcvsid, |
822 | 'DISTNAME=\tdistname-1.0', | | 822 | 'DISTNAME=\tdistname-1.0', |
823 | 'PKGNAME=\t${PYPKGPREFIX}-${DISTNAME}', | | 823 | 'PKGNAME=\t${PYPKGPREFIX}-${DISTNAME}', |
824 | '', | | 824 | '', |
825 | ".include \"../../mk/bsd.pkg.mk\"" | | 825 | ".include \"../../mk/bsd.pkg.mk\"" |
826 | ] | | 826 | ] |
827 | | | 827 | |
828 | | | 828 | |
829 | def test_Adjuster_add_dependency__buildlink(): | | 829 | def test_Adjuster_add_dependency__buildlink(): |
830 | # Note: this test only works because it runs in pkgtools/url2pkg, | | 830 | # Note: this test only works because it runs in pkgtools/url2pkg, |
831 | # and from there the file ../../devel/libusb/buildlink3.mk is visible. | | 831 | # and from there the file ../../devel/libusb/buildlink3.mk is visible. |
832 | | | 832 | |
833 | adjuster = Adjuster(up, 'https://example.org/distfile-1.0.zip', Lines()) | | 833 | adjuster = Adjuster(g, 'https://example.org/distfile-1.0.zip', Lines()) |
834 | adjuster.makefile_lines.add('# url2pkg-marker') | | 834 | adjuster.makefile_lines.add('# url2pkg-marker') |
835 | | | 835 | |
836 | adjuster.add_dependency('BUILD_DEPENDS', 'libusb', '>=2019', '../../devel/libusb') | | 836 | adjuster.add_dependency('BUILD_DEPENDS', 'libusb', '>=2019', '../../devel/libusb') |
837 | | | 837 | |
838 | lines = adjuster.generate_lines() | | 838 | lines = adjuster.generate_lines() |
839 | | | 839 | |
840 | assert lines.lines == [ | | 840 | assert lines.lines == [ |
841 | 'BUILDLINK_DEPENDS.libusb+=\tbuild', | | 841 | 'BUILDLINK_DEPENDS.libusb+=\tbuild', |
842 | 'BUILDLINK_API_DEPENDS.libusb+=\tlibusb>=2019', | | 842 | 'BUILDLINK_API_DEPENDS.libusb+=\tlibusb>=2019', |
843 | '.include "../../devel/libusb/buildlink3.mk"', | | 843 | '.include "../../devel/libusb/buildlink3.mk"', |
844 | ] | | 844 | ] |
845 | | | 845 | |
846 | | | 846 | |
847 | def test_Adjuster_adjust_cmake(tmp_path: Path): | | 847 | def test_Adjuster_adjust_cmake(tmp_path: Path): |
848 | adjuster = Adjuster(up, '', Lines()) | | 848 | adjuster = Adjuster(g, '', Lines()) |
849 | adjuster.abs_wrksrc = tmp_path | | 849 | adjuster.abs_wrksrc = tmp_path |
850 | (tmp_path / 'CMakeLists.txt').touch() | | 850 | (tmp_path / 'CMakeLists.txt').touch() |
851 | | | 851 | |
852 | adjuster.adjust_cmake() | | 852 | adjuster.adjust_cmake() |
853 | | | 853 | |
854 | assert str_vars(adjuster.build_vars) == ['USE_CMAKE=yes'] | | 854 | assert str_vars(adjuster.build_vars) == ['USE_CMAKE=yes'] |
855 | | | 855 | |
856 | | | 856 | |
857 | def test_Adjuster_adjust_configure__none(tmp_path: Path): | | 857 | def test_Adjuster_adjust_configure__none(tmp_path: Path): |
858 | adjuster = Adjuster(up, '', Lines()) | | 858 | adjuster = Adjuster(g, '', Lines()) |
859 | adjuster.abs_wrksrc = tmp_path | | 859 | adjuster.abs_wrksrc = tmp_path |
860 | | | 860 | |
861 | adjuster.adjust_configure() | | 861 | adjuster.adjust_configure() |
862 | | | 862 | |
863 | assert adjuster.build_vars == [] | | 863 | assert adjuster.build_vars == [] |
864 | | | 864 | |
865 | | | 865 | |
866 | def test_Adjuster_adjust_configure__GNU(tmp_path: Path): | | 866 | def test_Adjuster_adjust_configure__GNU(tmp_path: Path): |
867 | adjuster = Adjuster(up, '', Lines()) | | 867 | adjuster = Adjuster(g, '', Lines()) |
868 | adjuster.abs_wrksrc = tmp_path | | 868 | adjuster.abs_wrksrc = tmp_path |
869 | adjuster.wrksrc_files.append('configure') | | 869 | adjuster.wrksrc_files.append('configure') |
870 | (tmp_path / 'configure').write_text('# Free Software Foundation\n') | | 870 | (tmp_path / 'configure').write_text('# Free Software Foundation\n') |
871 | | | 871 | |
872 | adjuster.adjust_configure() | | 872 | adjuster.adjust_configure() |
873 | | | 873 | |
874 | assert str_vars(adjuster.build_vars) == [ | | 874 | assert str_vars(adjuster.build_vars) == [ |
875 | 'GNU_CONFIGURE=yes', | | 875 | 'GNU_CONFIGURE=yes', |
876 | ] | | 876 | ] |
877 | | | 877 | |
878 | | | 878 | |
879 | def test_Adjuster_adjust_configure__other(tmp_path: Path): | | 879 | def test_Adjuster_adjust_configure__other(tmp_path: Path): |
880 | adjuster = Adjuster(up, '', Lines()) | | 880 | adjuster = Adjuster(g, '', Lines()) |
881 | adjuster.abs_wrksrc = tmp_path | | 881 | adjuster.abs_wrksrc = tmp_path |
882 | adjuster.wrksrc_files.append('configure') | | 882 | adjuster.wrksrc_files.append('configure') |
883 | (tmp_path / 'configure').write_text('# A generic configure script\n') | | 883 | (tmp_path / 'configure').write_text('# A generic configure script\n') |
884 | | | 884 | |
885 | adjuster.adjust_configure() | | 885 | adjuster.adjust_configure() |
886 | | | 886 | |
887 | assert str_vars(adjuster.build_vars) == [ | | 887 | assert str_vars(adjuster.build_vars) == [ |
888 | 'HAS_CONFIGURE=yes', | | 888 | 'HAS_CONFIGURE=yes', |
889 | ] | | 889 | ] |
890 | | | 890 | |
891 | | | 891 | |
892 | def test_Adjuster_adjust_cargo__not_found(tmp_path: Path): | | 892 | def test_Adjuster_adjust_cargo__not_found(tmp_path: Path): |
893 | adjuster = Adjuster(up, '', Lines()) | | 893 | adjuster = Adjuster(g, '', Lines()) |
894 | adjuster.abs_wrksrc = tmp_path | | 894 | adjuster.abs_wrksrc = tmp_path |
895 | | | 895 | |
896 | adjuster.adjust_cargo() | | 896 | adjuster.adjust_cargo() |
897 | | | 897 | |
898 | assert str_vars(adjuster.build_vars) == [] | | 898 | assert str_vars(adjuster.build_vars) == [] |
899 | | | 899 | |
900 | | | 900 | |
901 | def test_Adjuster_adjust_cargo__found(tmp_path: Path): | | 901 | def test_Adjuster_adjust_cargo__found(tmp_path: Path): |
902 | adjuster = Adjuster(up, '', Lines()) | | 902 | adjuster = Adjuster(g, '', Lines()) |
903 | adjuster.abs_wrksrc = tmp_path | | 903 | adjuster.abs_wrksrc = tmp_path |
904 | (tmp_path / 'Cargo.lock').write_text('"checksum cargo-pkg 1.2.3 1234"') | | 904 | (tmp_path / 'Cargo.lock').write_text('"checksum cargo-pkg 1.2.3 1234"') |
905 | | | 905 | |
906 | adjuster.adjust_cargo() | | 906 | adjuster.adjust_cargo() |
907 | | | 907 | |
908 | assert str_vars(adjuster.build_vars) == [ | | 908 | assert str_vars(adjuster.build_vars) == [ |
909 | 'CARGO_CRATE_DEPENDS+=cargo-pkg-1.2.3', | | 909 | 'CARGO_CRATE_DEPENDS+=cargo-pkg-1.2.3', |
910 | ] | | 910 | ] |
911 | | | 911 | |
912 | | | 912 | |
913 | def test_Adjuster_adjust_gconf2(): | | 913 | def test_Adjuster_adjust_gconf2(): |
914 | adjuster = Adjuster(up, '', Lines()) | | 914 | adjuster = Adjuster(g, '', Lines()) |
915 | adjuster.wrksrc_files = [ | | 915 | adjuster.wrksrc_files = [ |
916 | 'file1.schemas', | | 916 | 'file1.schemas', |
917 | 'file2.schemas.in', | | 917 | 'file2.schemas.in', |
918 | 'file6.schemas.in.in.in.in.in.in', # realistic maximum is 2 times | | 918 | 'file6.schemas.in.in.in.in.in.in', # realistic maximum is 2 times |
919 | ] | | 919 | ] |
920 | | | 920 | |
921 | adjuster.adjust_gconf2_schemas() | | 921 | adjuster.adjust_gconf2_schemas() |
922 | | | 922 | |
923 | assert adjuster.includes == [ | | 923 | assert adjuster.includes == [ |
924 | '../../devel/GConf/schemas.mk', | | 924 | '../../devel/GConf/schemas.mk', |
925 | ] | | 925 | ] |
926 | assert str_vars(adjuster.extra_vars) == [ | | 926 | assert str_vars(adjuster.extra_vars) == [ |
927 | 'GCONF_SCHEMAS+=file1.schemas', | | 927 | 'GCONF_SCHEMAS+=file1.schemas', |
928 | 'GCONF_SCHEMAS+=file2.schemas', | | 928 | 'GCONF_SCHEMAS+=file2.schemas', |
929 | 'GCONF_SCHEMAS+=file6.schemas', | | 929 | 'GCONF_SCHEMAS+=file6.schemas', |
930 | ] | | 930 | ] |
931 | | | 931 | |
932 | | | 932 | |
933 | def test_Adjuster_adjust_libtool__ltconfig(tmp_path: Path): | | 933 | def test_Adjuster_adjust_libtool__ltconfig(tmp_path: Path): |
934 | adjuster = Adjuster(up, '', Lines()) | | 934 | adjuster = Adjuster(g, '', Lines()) |
935 | adjuster.abs_wrksrc = tmp_path | | 935 | adjuster.abs_wrksrc = tmp_path |
936 | (tmp_path / 'ltconfig').write_text('') | | 936 | (tmp_path / 'ltconfig').write_text('') |
937 | | | 937 | |
938 | adjuster.adjust_libtool() | | 938 | adjuster.adjust_libtool() |
939 | | | 939 | |
940 | assert str_vars(adjuster.build_vars) == ['USE_LIBTOOL=yes'] | | 940 | assert str_vars(adjuster.build_vars) == ['USE_LIBTOOL=yes'] |
941 | | | 941 | |
942 | | | 942 | |
943 | def test_Adjuster_adjust_libtool__libltdl(tmp_path: Path): | | 943 | def test_Adjuster_adjust_libtool__libltdl(tmp_path: Path): |
944 | adjuster = Adjuster(up, '', Lines()) | | 944 | adjuster = Adjuster(g, '', Lines()) |
945 | adjuster.abs_wrksrc = tmp_path | | 945 | adjuster.abs_wrksrc = tmp_path |
946 | (tmp_path / 'libltdl').mkdir() | | 946 | (tmp_path / 'libltdl').mkdir() |
947 | | | 947 | |
948 | adjuster.adjust_libtool() | | 948 | adjuster.adjust_libtool() |
949 | | | 949 | |
950 | assert adjuster.includes == [ | | 950 | assert adjuster.includes == [ |
951 | '../../devel/libltdl/convenience.mk', | | 951 | '../../devel/libltdl/convenience.mk', |
952 | ] | | 952 | ] |
953 | | | 953 | |
954 | | | 954 | |
955 | def test_Adjuster_adjust_meson(tmp_path: Path): | | 955 | def test_Adjuster_adjust_meson(tmp_path: Path): |
956 | adjuster = Adjuster(up, '', Lines()) | | 956 | adjuster = Adjuster(g, '', Lines()) |
957 | adjuster.abs_wrksrc = tmp_path | | 957 | adjuster.abs_wrksrc = tmp_path |
958 | (tmp_path / 'meson.build').touch() | | 958 | (tmp_path / 'meson.build').touch() |
959 | | | 959 | |
960 | adjuster.adjust_meson() | | 960 | adjuster.adjust_meson() |
961 | | | 961 | |
962 | assert adjuster.includes == ['../../devel/meson/build.mk'] | | 962 | assert adjuster.includes == ['../../devel/meson/build.mk'] |
963 | | | 963 | |
964 | | | 964 | |
965 | def test_Adjuster_adjust_perl_module_Build_PL(tmp_path: Path): | | 965 | def test_Adjuster_adjust_perl_module_Build_PL(tmp_path: Path): |
966 | up.perl5 = 'echo perl5' | | 966 | g.perl5 = 'echo perl5' |
967 | up.libdir = '/libdir' | | 967 | g.libdir = '/libdir' |
968 | up.verbose = True | | 968 | g.verbose = True |
969 | adjuster = Adjuster(up, '', Lines()) | | 969 | adjuster = Adjuster(g, '', Lines()) |
970 | adjuster.abs_wrksrc = tmp_path | | 970 | adjuster.abs_wrksrc = tmp_path |
971 | | | 971 | |
972 | adjuster.adjust_perl_module_Build_PL() | | 972 | adjuster.adjust_perl_module_Build_PL() |
973 | | | 973 | |
974 | assert str_vars(adjuster.build_vars) == ['PERL5_MODULE_TYPE=Module::Build'] | | 974 | assert str_vars(adjuster.build_vars) == ['PERL5_MODULE_TYPE=Module::Build'] |
975 | assert up.err.written() == [ | | 975 | assert g.err.written() == [ |
976 | f'url2pkg: reading dependencies: cd \'{tmp_path}\' && env {{}} \'echo perl5 -I/libdir -I. Build.PL\'', | | 976 | f'url2pkg: reading dependencies: cd \'{tmp_path}\' && env {{}} \'echo perl5 -I/libdir -I. Build.PL\'', |
977 | 'url2pkg: unknown dependency line: \'perl5 -I/libdir -I. Build.PL\'' | | 977 | 'url2pkg: unknown dependency line: \'perl5 -I/libdir -I. Build.PL\'' |
978 | ] | | 978 | ] |
979 | | | 979 | |
980 | | | 980 | |
981 | def test_Adjuster_adjust_perl_module_Makefile_PL(tmp_path: Path): | | 981 | def test_Adjuster_adjust_perl_module_Makefile_PL(tmp_path: Path): |
982 | up.perl5 = 'echo perl5' | | 982 | g.perl5 = 'echo perl5' |
983 | up.libdir = '/libdir' | | 983 | g.libdir = '/libdir' |
984 | up.verbose = True | | 984 | g.verbose = True |
985 | adjuster = Adjuster(up, '', Lines()) | | 985 | adjuster = Adjuster(g, '', Lines()) |
986 | adjuster.abs_wrksrc = tmp_path | | 986 | adjuster.abs_wrksrc = tmp_path |
987 | | | 987 | |
988 | adjuster.adjust_perl_module_Makefile_PL() | | 988 | adjuster.adjust_perl_module_Makefile_PL() |
989 | | | 989 | |
990 | assert str_vars(adjuster.build_vars) == [] | | 990 | assert str_vars(adjuster.build_vars) == [] |
991 | assert up.err.written() == [ | | 991 | assert g.err.written() == [ |
992 | f'url2pkg: reading dependencies: cd \'{tmp_path}\' && env {{}} \'echo perl5 -I/libdir -I. Makefile.PL\'', | | 992 | f'url2pkg: reading dependencies: cd \'{tmp_path}\' && env {{}} \'echo perl5 -I/libdir -I. Makefile.PL\'', |
993 | 'url2pkg: unknown dependency line: \'perl5 -I/libdir -I. Makefile.PL\'' | | 993 | 'url2pkg: unknown dependency line: \'perl5 -I/libdir -I. Makefile.PL\'' |
994 | ] | | 994 | ] |
995 | | | 995 | |
996 | | | 996 | |
997 | def test_Adjuster_adjust_perl_module_homepage(): | | 997 | def test_Adjuster_adjust_perl_module_homepage(): |
998 | adjuster = Adjuster(up, 'https://example.org/Perl-Module-1.0.tar.gz', Lines()) | | 998 | adjuster = Adjuster(g, 'https://example.org/Perl-Module-1.0.tar.gz', Lines()) |
999 | adjuster.makefile_lines.add_vars( | | 999 | adjuster.makefile_lines.add_vars( |
1000 | Var('DISTNAME', '=', 'Perl-Module-1.0.tar.gz'), | | 1000 | Var('DISTNAME', '=', 'Perl-Module-1.0.tar.gz'), |
1001 | Var('MASTER_SITES', '=', '${MASTER_SITE_PERL_CPAN:=subdir/}'), | | 1001 | Var('MASTER_SITES', '=', '${MASTER_SITE_PERL_CPAN:=subdir/}'), |
1002 | Var('HOMEPAGE', '=', 'https://example.org/'), | | 1002 | Var('HOMEPAGE', '=', 'https://example.org/'), |
1003 | ) | | 1003 | ) |
1004 | | | 1004 | |
1005 | adjuster.adjust_perl_module_homepage() | | 1005 | adjuster.adjust_perl_module_homepage() |
1006 | | | 1006 | |
1007 | assert adjuster.makefile_lines.get('HOMEPAGE') == 'https://metacpan.org/pod/Perl::Module' | | 1007 | assert adjuster.makefile_lines.get('HOMEPAGE') == 'https://metacpan.org/pod/Perl::Module' |
1008 | | | 1008 | |
1009 | | | 1009 | |
1010 | def test_Adjuster_adjust_perl_module__Build_PL(tmp_path: Path): | | 1010 | def test_Adjuster_adjust_perl_module__Build_PL(tmp_path: Path): |
1011 | up.perl5 = 'echo perl5' | | 1011 | g.perl5 = 'echo perl5' |
1012 | up.pkgdir = tmp_path # for removing the PLIST | | 1012 | g.pkgdir = tmp_path # for removing the PLIST |
1013 | adjuster = Adjuster(up, 'https://example.org/Perl-Module-1.0.tar.gz', Lines()) | | 1013 | adjuster = Adjuster(g, 'https://example.org/Perl-Module-1.0.tar.gz', Lines()) |
1014 | adjuster.abs_wrksrc = tmp_path | | 1014 | adjuster.abs_wrksrc = tmp_path |
1015 | adjuster.makefile_lines.add_vars( | | 1015 | adjuster.makefile_lines.add_vars( |
1016 | Var('DISTNAME', '=', 'Perl-Module-1.0.tar.gz'), | | 1016 | Var('DISTNAME', '=', 'Perl-Module-1.0.tar.gz'), |
1017 | Var('MASTER_SITES', '=', '${MASTER_SITE_PERL_CPAN:=subdir/}'), | | 1017 | Var('MASTER_SITES', '=', '${MASTER_SITE_PERL_CPAN:=subdir/}'), |
1018 | Var('HOMEPAGE', '=', 'https://example.org/'), | | 1018 | Var('HOMEPAGE', '=', 'https://example.org/'), |
1019 | ) | | 1019 | ) |
1020 | adjuster.makefile_lines.add('# url2pkg-marker') | | 1020 | adjuster.makefile_lines.add('# url2pkg-marker') |
1021 | (tmp_path / 'Build.PL').touch() | | 1021 | (tmp_path / 'Build.PL').touch() |
1022 | (tmp_path / 'PLIST').touch() | | 1022 | (tmp_path / 'PLIST').touch() |
1023 | | | 1023 | |
1024 | adjuster.adjust_perl_module() | | 1024 | adjuster.adjust_perl_module() |
1025 | | | 1025 | |
1026 | assert detab(adjuster.generate_lines()) == [ | | 1026 | assert detab(adjuster.generate_lines()) == [ |
| @@ -1030,187 +1030,187 @@ def test_Adjuster_adjust_perl_module__Bu | | | @@ -1030,187 +1030,187 @@ def test_Adjuster_adjust_perl_module__Bu |
1030 | 'HOMEPAGE= https://metacpan.org/pod/Perl::Module', | | 1030 | 'HOMEPAGE= https://metacpan.org/pod/Perl::Module', |
1031 | '', | | 1031 | '', |
1032 | 'PERL5_MODULE_TYPE= Module::Build', | | 1032 | 'PERL5_MODULE_TYPE= Module::Build', |
1033 | 'PERL5_PACKLIST= auto/Perl/Module/.packlist', | | 1033 | 'PERL5_PACKLIST= auto/Perl/Module/.packlist', |
1034 | '', | | 1034 | '', |
1035 | '.include "../../lang/perl5/module.mk"', | | 1035 | '.include "../../lang/perl5/module.mk"', |
1036 | ] | | 1036 | ] |
1037 | assert not (tmp_path / 'PLIST').exists() | | 1037 | assert not (tmp_path / 'PLIST').exists() |
1038 | | | 1038 | |
1039 | | | 1039 | |
1040 | def test_Adjuster_adjust_perl_module__Makefile_PL_without_PLIST(tmp_path: Path): | | 1040 | def test_Adjuster_adjust_perl_module__Makefile_PL_without_PLIST(tmp_path: Path): |
1041 | # For code coverage, when PLIST cannot be unlinked. | | 1041 | # For code coverage, when PLIST cannot be unlinked. |
1042 | | | 1042 | |
1043 | up.perl5 = 'echo perl5' | | 1043 | g.perl5 = 'echo perl5' |
1044 | up.pkgdir = tmp_path | | 1044 | g.pkgdir = tmp_path |
1045 | adjuster = Adjuster(up, 'https://example.org/Mod-1.0.tar.gz', Lines()) | | 1045 | adjuster = Adjuster(g, 'https://example.org/Mod-1.0.tar.gz', Lines()) |
1046 | adjuster.abs_wrksrc = tmp_path | | 1046 | adjuster.abs_wrksrc = tmp_path |
1047 | adjuster.makefile_lines.add_vars( | | 1047 | adjuster.makefile_lines.add_vars( |
1048 | Var('DISTNAME', '=', 'Mod-1.0.tar.gz'), | | 1048 | Var('DISTNAME', '=', 'Mod-1.0.tar.gz'), |
1049 | Var('MASTER_SITES', '=', '${MASTER_SITE_PERL_CPAN:=subdir/}'), | | 1049 | Var('MASTER_SITES', '=', '${MASTER_SITE_PERL_CPAN:=subdir/}'), |
1050 | Var('HOMEPAGE', '=', 'https://example.org/'), | | 1050 | Var('HOMEPAGE', '=', 'https://example.org/'), |
1051 | ) | | 1051 | ) |
1052 | adjuster.makefile_lines.add('# url2pkg-marker') | | 1052 | adjuster.makefile_lines.add('# url2pkg-marker') |
1053 | (tmp_path / 'Makefile.PL').touch() | | 1053 | (tmp_path / 'Makefile.PL').touch() |
1054 | | | 1054 | |
1055 | adjuster.adjust_perl_module() | | 1055 | adjuster.adjust_perl_module() |
1056 | | | 1056 | |
1057 | assert not (tmp_path / 'PLIST').exists() | | 1057 | assert not (tmp_path / 'PLIST').exists() |
1058 | | | 1058 | |
1059 | | | 1059 | |
1060 | def test_Adjuster_adjust_python_module(tmp_path: Path): | | 1060 | def test_Adjuster_adjust_python_module(tmp_path: Path): |
1061 | url = 'https://example.org/Mod-1.0.tar.gz' | | 1061 | url = 'https://example.org/Mod-1.0.tar.gz' |
1062 | up.pythonbin = 'echo python' | | 1062 | g.pythonbin = 'echo python' |
1063 | up.pkgdir = tmp_path | | 1063 | g.pkgdir = tmp_path |
1064 | adjuster = Adjuster(up, url, Lines()) | | 1064 | adjuster = Adjuster(g, url, Lines()) |
1065 | adjuster.abs_wrksrc = tmp_path | | 1065 | adjuster.abs_wrksrc = tmp_path |
1066 | adjuster.makefile_lines = Generator(url).generate_Makefile() | | 1066 | adjuster.makefile_lines = Generator(url).generate_Makefile() |
1067 | (tmp_path / 'setup.py').touch() | | 1067 | (tmp_path / 'setup.py').touch() |
1068 | | | 1068 | |
1069 | adjuster.adjust_python_module() | | 1069 | adjuster.adjust_python_module() |
1070 | | | 1070 | |
1071 | assert detab(adjuster.generate_lines()) == [ | | 1071 | assert detab(adjuster.generate_lines()) == [ |
1072 | mkcvsid, | | 1072 | mkcvsid, |
1073 | '', | | 1073 | '', |
1074 | 'DISTNAME= Mod-1.0', | | 1074 | 'DISTNAME= Mod-1.0', |
1075 | 'PKGNAME= ${PYPKGPREFIX}-${DISTNAME}', | | 1075 | 'PKGNAME= ${PYPKGPREFIX}-${DISTNAME}', |
1076 | 'CATEGORIES= pkgtools python', | | 1076 | 'CATEGORIES= pkgtools python', |
1077 | 'MASTER_SITES= https://example.org/', | | 1077 | 'MASTER_SITES= https://example.org/', |
1078 | '', | | 1078 | '', |
1079 | 'MAINTAINER= INSERT_YOUR_MAIL_ADDRESS_HERE # or use pkgsrc-users@NetBSD.org', | | 1079 | 'MAINTAINER= INSERT_YOUR_MAIL_ADDRESS_HERE # or use pkgsrc-users@NetBSD.org', |
1080 | 'HOMEPAGE= https://example.org/', | | 1080 | 'HOMEPAGE= https://example.org/', |
1081 | 'COMMENT= TODO: Short description of the package', | | 1081 | 'COMMENT= TODO: Short description of the package', |
1082 | '#LICENSE= # TODO: (see mk/license.mk)', | | 1082 | '#LICENSE= # TODO: (see mk/license.mk)', |
1083 | '', | | 1083 | '', |
1084 | '.include "../../lang/python/egg.mk"', | | 1084 | '.include "../../lang/python/egg.mk"', |
1085 | '.include "../../mk/bsd.pkg.mk"', | | 1085 | '.include "../../mk/bsd.pkg.mk"', |
1086 | ] | | 1086 | ] |
1087 | | | 1087 | |
1088 | | | 1088 | |
1089 | def test_Adjuster_adjust_po__not_found(): | | 1089 | def test_Adjuster_adjust_po__not_found(): |
1090 | adjuster = Adjuster(up, '', Lines()) | | 1090 | adjuster = Adjuster(g, '', Lines()) |
1091 | | | 1091 | |
1092 | adjuster.adjust_po() | | 1092 | adjuster.adjust_po() |
1093 | | | 1093 | |
1094 | assert adjuster.build_vars == [] | | 1094 | assert adjuster.build_vars == [] |
1095 | | | 1095 | |
1096 | | | 1096 | |
1097 | def test_Adjuster_adjust_po__mo_found(): | | 1097 | def test_Adjuster_adjust_po__mo_found(): |
1098 | adjuster = Adjuster(up, '', Lines()) | | 1098 | adjuster = Adjuster(g, '', Lines()) |
1099 | adjuster.wrksrc_files = ['share/locale/de.mo'] | | 1099 | adjuster.wrksrc_files = ['share/locale/de.mo'] |
1100 | | | 1100 | |
1101 | adjuster.adjust_po() | | 1101 | adjuster.adjust_po() |
1102 | | | 1102 | |
1103 | assert str_vars(adjuster.build_vars) == ['USE_PKGLOCALEDIR=yes'] | | 1103 | assert str_vars(adjuster.build_vars) == ['USE_PKGLOCALEDIR=yes'] |
1104 | | | 1104 | |
1105 | | | 1105 | |
1106 | def test_Adjuster_adjust_po__po_found(): | | 1106 | def test_Adjuster_adjust_po__po_found(): |
1107 | adjuster = Adjuster(up, '', Lines()) | | 1107 | adjuster = Adjuster(g, '', Lines()) |
1108 | adjuster.wrksrc_files = ['po/de.po'] | | 1108 | adjuster.wrksrc_files = ['po/de.po'] |
1109 | | | 1109 | |
1110 | adjuster.adjust_po() | | 1110 | adjuster.adjust_po() |
1111 | | | 1111 | |
1112 | assert str_vars(adjuster.build_vars) == ['USE_PKGLOCALEDIR=yes'] | | 1112 | assert str_vars(adjuster.build_vars) == ['USE_PKGLOCALEDIR=yes'] |
1113 | | | 1113 | |
1114 | | | 1114 | |
1115 | def test_Adjuster_adjust_use_languages__none(): | | 1115 | def test_Adjuster_adjust_use_languages__none(): |
1116 | adjuster = Adjuster(up, '', Lines()) | | 1116 | adjuster = Adjuster(g, '', Lines()) |
1117 | | | 1117 | |
1118 | adjuster.adjust_use_languages() | | 1118 | adjuster.adjust_use_languages() |
1119 | | | 1119 | |
1120 | assert str_vars(adjuster.build_vars) == ['USE_LANGUAGES=# none'] | | 1120 | assert str_vars(adjuster.build_vars) == ['USE_LANGUAGES=# none'] |
1121 | | | 1121 | |
1122 | | | 1122 | |
1123 | def test_Adjuster_adjust_use_languages__c(): | | 1123 | def test_Adjuster_adjust_use_languages__c(): |
1124 | adjuster = Adjuster(up, '', Lines()) | | 1124 | adjuster = Adjuster(g, '', Lines()) |
1125 | adjuster.wrksrc_files = ['main.c'] | | 1125 | adjuster.wrksrc_files = ['main.c'] |
1126 | | | 1126 | |
1127 | adjuster.adjust_use_languages() | | 1127 | adjuster.adjust_use_languages() |
1128 | | | 1128 | |
1129 | assert str_vars(adjuster.build_vars) == [] | | 1129 | assert str_vars(adjuster.build_vars) == [] |
1130 | | | 1130 | |
1131 | | | 1131 | |
1132 | def test_Adjuster_adjust_use_languages__c_in_subdir(): | | 1132 | def test_Adjuster_adjust_use_languages__c_in_subdir(): |
1133 | adjuster = Adjuster(up, '', Lines()) | | 1133 | adjuster = Adjuster(g, '', Lines()) |
1134 | adjuster.wrksrc_files = ['subdir/main.c'] | | 1134 | adjuster.wrksrc_files = ['subdir/main.c'] |
1135 | | | 1135 | |
1136 | adjuster.adjust_use_languages() | | 1136 | adjuster.adjust_use_languages() |
1137 | | | 1137 | |
1138 | assert str_vars(adjuster.build_vars) == [] | | 1138 | assert str_vars(adjuster.build_vars) == [] |
1139 | | | 1139 | |
1140 | | | 1140 | |
1141 | def test_Adjuster_adjust_use_languages__cplusplus_in_subdir(): | | 1141 | def test_Adjuster_adjust_use_languages__cplusplus_in_subdir(): |
1142 | adjuster = Adjuster(up, '', Lines()) | | 1142 | adjuster = Adjuster(g, '', Lines()) |
1143 | adjuster.wrksrc_files = ['subdir/main.cpp'] | | 1143 | adjuster.wrksrc_files = ['subdir/main.cpp'] |
1144 | | | 1144 | |
1145 | adjuster.adjust_use_languages() | | 1145 | adjuster.adjust_use_languages() |
1146 | | | 1146 | |
1147 | assert str_vars(adjuster.build_vars) == ['USE_LANGUAGES=c++'] | | 1147 | assert str_vars(adjuster.build_vars) == ['USE_LANGUAGES=c++'] |
1148 | | | 1148 | |
1149 | | | 1149 | |
1150 | def test_Adjuster_adjust_use_languages__cplusplus_and_fortran(): | | 1150 | def test_Adjuster_adjust_use_languages__cplusplus_and_fortran(): |
1151 | adjuster = Adjuster(up, '', Lines()) | | 1151 | adjuster = Adjuster(g, '', Lines()) |
1152 | adjuster.wrksrc_files = ['subdir/main.cpp', 'main.f'] | | 1152 | adjuster.wrksrc_files = ['subdir/main.cpp', 'main.f'] |
1153 | | | 1153 | |
1154 | adjuster.adjust_use_languages() | | 1154 | adjuster.adjust_use_languages() |
1155 | | | 1155 | |
1156 | assert str_vars(adjuster.build_vars) == ['USE_LANGUAGES=c++ fortran'] | | 1156 | assert str_vars(adjuster.build_vars) == ['USE_LANGUAGES=c++ fortran'] |
1157 | | | 1157 | |
1158 | | | 1158 | |
1159 | def test_Adjuster_adjust_pkg_config__none(): | | 1159 | def test_Adjuster_adjust_pkg_config__none(): |
1160 | adjuster = Adjuster(up, '', Lines()) | | 1160 | adjuster = Adjuster(g, '', Lines()) |
1161 | | | 1161 | |
1162 | adjuster.adjust_pkg_config() | | 1162 | adjuster.adjust_pkg_config() |
1163 | | | 1163 | |
1164 | assert str_vars(adjuster.build_vars) == [] | | 1164 | assert str_vars(adjuster.build_vars) == [] |
1165 | assert str_vars(adjuster.extra_vars) == [] | | 1165 | assert str_vars(adjuster.extra_vars) == [] |
1166 | | | 1166 | |
1167 | | | 1167 | |
1168 | def test_Adjuster_adjust_pkg_config__pc_in(): | | 1168 | def test_Adjuster_adjust_pkg_config__pc_in(): |
1169 | adjuster = Adjuster(up, '', Lines()) | | 1169 | adjuster = Adjuster(g, '', Lines()) |
1170 | adjuster.wrksrc_files = ['library.pc.in'] | | 1170 | adjuster.wrksrc_files = ['library.pc.in'] |
1171 | | | 1171 | |
1172 | adjuster.adjust_pkg_config() | | 1172 | adjuster.adjust_pkg_config() |
1173 | | | 1173 | |
1174 | assert str_vars(adjuster.build_vars) == ['USE_TOOLS+=pkg-config'] | | 1174 | assert str_vars(adjuster.build_vars) == ['USE_TOOLS+=pkg-config'] |
1175 | assert str_vars(adjuster.extra_vars) == ['PKGCONFIG_OVERRIDE+=library.pc.in'] | | 1175 | assert str_vars(adjuster.extra_vars) == ['PKGCONFIG_OVERRIDE+=library.pc.in'] |
1176 | | | 1176 | |
1177 | | | 1177 | |
1178 | def test_Adjuster_adjust_pkg_config__uninstalled_pc_in(): | | 1178 | def test_Adjuster_adjust_pkg_config__uninstalled_pc_in(): |
1179 | adjuster = Adjuster(up, '', Lines()) | | 1179 | adjuster = Adjuster(g, '', Lines()) |
1180 | adjuster.wrksrc_files = ['library-uninstalled.pc.in'] | | 1180 | adjuster.wrksrc_files = ['library-uninstalled.pc.in'] |
1181 | | | 1181 | |
1182 | adjuster.adjust_pkg_config() | | 1182 | adjuster.adjust_pkg_config() |
1183 | | | 1183 | |
1184 | assert str_vars(adjuster.build_vars) == [] | | 1184 | assert str_vars(adjuster.build_vars) == [] |
1185 | assert str_vars(adjuster.extra_vars) == [] | | 1185 | assert str_vars(adjuster.extra_vars) == [] |
1186 | | | 1186 | |
1187 | | | 1187 | |
1188 | def test_Adjuster_adjust_pkg_config__both(): | | 1188 | def test_Adjuster_adjust_pkg_config__both(): |
1189 | adjuster = Adjuster(up, '', Lines()) | | 1189 | adjuster = Adjuster(g, '', Lines()) |
1190 | adjuster.wrksrc_files = [ | | 1190 | adjuster.wrksrc_files = [ |
1191 | 'library.pc.in', | | 1191 | 'library.pc.in', |
1192 | 'library-uninstalled.pc.in', | | 1192 | 'library-uninstalled.pc.in', |
1193 | ] | | 1193 | ] |
1194 | | | 1194 | |
1195 | adjuster.adjust_pkg_config() | | 1195 | adjuster.adjust_pkg_config() |
1196 | | | 1196 | |
1197 | assert str_vars(adjuster.build_vars) == ['USE_TOOLS+=pkg-config'] | | 1197 | assert str_vars(adjuster.build_vars) == ['USE_TOOLS+=pkg-config'] |
1198 | assert str_vars(adjuster.extra_vars) == ['PKGCONFIG_OVERRIDE+=library.pc.in'] | | 1198 | assert str_vars(adjuster.extra_vars) == ['PKGCONFIG_OVERRIDE+=library.pc.in'] |
1199 | | | 1199 | |
1200 | | | 1200 | |
1201 | def test_Adjuster_generate_lines(): | | 1201 | def test_Adjuster_generate_lines(): |
1202 | url = 'https://dummy.example.org/package-1.0.tar.gz' | | 1202 | url = 'https://dummy.example.org/package-1.0.tar.gz' |
1203 | adjuster = Adjuster(up, url, Lines()) | | 1203 | adjuster = Adjuster(g, url, Lines()) |
1204 | adjuster.makefile_lines = Generator(url).generate_Makefile() | | 1204 | adjuster.makefile_lines = Generator(url).generate_Makefile() |
1205 | adjuster.update_vars['HOMEPAGE'] = 'https://example.org/' | | 1205 | adjuster.update_vars['HOMEPAGE'] = 'https://example.org/' |
1206 | adjuster.update_vars['#LICENSE'] = 'BSD # TODO: too unspecific' | | 1206 | adjuster.update_vars['#LICENSE'] = 'BSD # TODO: too unspecific' |
1207 | adjuster.depends.append('dependency>=0:../../category/dependency') | | 1207 | adjuster.depends.append('dependency>=0:../../category/dependency') |
1208 | adjuster.todos.append('Run pkglint') | | 1208 | adjuster.todos.append('Run pkglint') |
1209 | | | 1209 | |
1210 | lines = adjuster.generate_lines() | | 1210 | lines = adjuster.generate_lines() |
1211 | | | 1211 | |
1212 | assert detab(lines) == [ | | 1212 | assert detab(lines) == [ |
1213 | mkcvsid, | | 1213 | mkcvsid, |
1214 | '', | | 1214 | '', |
1215 | 'DISTNAME= package-1.0', | | 1215 | 'DISTNAME= package-1.0', |
1216 | 'CATEGORIES= pkgtools', | | 1216 | 'CATEGORIES= pkgtools', |
| @@ -1220,126 +1220,126 @@ def test_Adjuster_generate_lines(): | | | @@ -1220,126 +1220,126 @@ def test_Adjuster_generate_lines(): |
1220 | 'HOMEPAGE= https://example.org/', | | 1220 | 'HOMEPAGE= https://example.org/', |
1221 | 'COMMENT= TODO: Short description of the package', | | 1221 | 'COMMENT= TODO: Short description of the package', |
1222 | '#LICENSE= BSD # TODO: too unspecific', | | 1222 | '#LICENSE= BSD # TODO: too unspecific', |
1223 | '', | | 1223 | '', |
1224 | '# TODO: Run pkglint', | | 1224 | '# TODO: Run pkglint', |
1225 | '', | | 1225 | '', |
1226 | 'DEPENDS+= dependency>=0:../../category/dependency', | | 1226 | 'DEPENDS+= dependency>=0:../../category/dependency', |
1227 | '', | | 1227 | '', |
1228 | '.include "../../mk/bsd.pkg.mk"', | | 1228 | '.include "../../mk/bsd.pkg.mk"', |
1229 | ] | | 1229 | ] |
1230 | | | 1230 | |
1231 | | | 1231 | |
1232 | def test_Adjuster_determine_wrksrc__no_files(tmp_path: Path): | | 1232 | def test_Adjuster_determine_wrksrc__no_files(tmp_path: Path): |
1233 | adjuster = Adjuster(up, '', Lines()) | | 1233 | adjuster = Adjuster(g, '', Lines()) |
1234 | adjuster.abs_wrkdir = tmp_path | | 1234 | adjuster.abs_wrkdir = tmp_path |
1235 | | | 1235 | |
1236 | adjuster.determine_wrksrc() | | 1236 | adjuster.determine_wrksrc() |
1237 | | | 1237 | |
1238 | assert adjuster.abs_wrksrc == adjuster.abs_wrkdir | | 1238 | assert adjuster.abs_wrksrc == adjuster.abs_wrkdir |
1239 | | | 1239 | |
1240 | | | 1240 | |
1241 | def test_Adjuster_determine_wrksrc__single_dir(tmp_path: Path): | | 1241 | def test_Adjuster_determine_wrksrc__single_dir(tmp_path: Path): |
1242 | adjuster = Adjuster(up, '', Lines()) | | 1242 | adjuster = Adjuster(g, '', Lines()) |
1243 | adjuster.abs_wrkdir = tmp_path | | 1243 | adjuster.abs_wrkdir = tmp_path |
1244 | (tmp_path / 'subdir').mkdir() | | 1244 | (tmp_path / 'subdir').mkdir() |
1245 | | | 1245 | |
1246 | adjuster.determine_wrksrc() | | 1246 | adjuster.determine_wrksrc() |
1247 | | | 1247 | |
1248 | assert adjuster.abs_wrksrc == adjuster.abs_wrkdir / 'subdir' | | 1248 | assert adjuster.abs_wrksrc == adjuster.abs_wrkdir / 'subdir' |
1249 | | | 1249 | |
1250 | | | 1250 | |
1251 | def test_Adjuster_determine_wrksrc__distname_dir(tmp_path: Path): | | 1251 | def test_Adjuster_determine_wrksrc__distname_dir(tmp_path: Path): |
1252 | adjuster = Adjuster(up, '', Lines()) | | 1252 | adjuster = Adjuster(g, '', Lines()) |
1253 | adjuster.abs_wrkdir = tmp_path | | 1253 | adjuster.abs_wrkdir = tmp_path |
1254 | adjuster.makefile_lines.add_vars(Var('DISTNAME', '=', 'distname-1.0')) | | 1254 | adjuster.makefile_lines.add_vars(Var('DISTNAME', '=', 'distname-1.0')) |
1255 | (tmp_path / 'distname-1.0').mkdir() | | 1255 | (tmp_path / 'distname-1.0').mkdir() |
1256 | | | 1256 | |
1257 | adjuster.determine_wrksrc() | | 1257 | adjuster.determine_wrksrc() |
1258 | | | 1258 | |
1259 | assert adjuster.abs_wrksrc == adjuster.abs_wrkdir / 'distname-1.0' | | 1259 | assert adjuster.abs_wrksrc == adjuster.abs_wrkdir / 'distname-1.0' |
1260 | assert str_vars(adjuster.build_vars) == [] | | 1260 | assert str_vars(adjuster.build_vars) == [] |
1261 | | | 1261 | |
1262 | | | 1262 | |
1263 | def test_Adjuster_determine_wrksrc__several_dirs(tmp_path: Path): | | 1263 | def test_Adjuster_determine_wrksrc__several_dirs(tmp_path: Path): |
1264 | adjuster = Adjuster(up, '', Lines()) | | 1264 | adjuster = Adjuster(g, '', Lines()) |
1265 | adjuster.abs_wrkdir = tmp_path | | 1265 | adjuster.abs_wrkdir = tmp_path |
1266 | (tmp_path / 'subdir1').mkdir() | | 1266 | (tmp_path / 'subdir1').mkdir() |
1267 | (tmp_path / 'subdir2').mkdir() | | 1267 | (tmp_path / 'subdir2').mkdir() |
1268 | | | 1268 | |
1269 | adjuster.determine_wrksrc() | | 1269 | adjuster.determine_wrksrc() |
1270 | | | 1270 | |
1271 | assert adjuster.abs_wrksrc == adjuster.abs_wrkdir | | 1271 | assert adjuster.abs_wrksrc == adjuster.abs_wrkdir |
1272 | assert str_vars(adjuster.build_vars) == [ | | 1272 | assert str_vars(adjuster.build_vars) == [ |
1273 | 'WRKSRC=${WRKDIR} # TODO: one of subdir1 subdir2, or leave it as-is', | | 1273 | 'WRKSRC=${WRKDIR} # TODO: one of subdir1 subdir2, or leave it as-is', |
1274 | ] | | 1274 | ] |
1275 | | | 1275 | |
1276 | | | 1276 | |
1277 | def test_Adjuster_adjust__empty_wrkdir(tmp_path: Path): | | 1277 | def test_Adjuster_adjust__empty_wrkdir(tmp_path: Path): |
1278 | up.pkgdir = tmp_path | | 1278 | g.pkgdir = tmp_path |
1279 | up.show_var = lambda varname: {'WRKDIR': str(tmp_path)}[varname] | | 1279 | g.show_var = lambda varname: {'WRKDIR': str(tmp_path)}[varname] |
1280 | adjuster = Adjuster(up, 'https://example.org/distfile-1.0.zip', Lines()) | | 1280 | adjuster = Adjuster(g, 'https://example.org/distfile-1.0.zip', Lines()) |
1281 | (tmp_path / 'Makefile').write_text('# url2pkg-marker\n') | | 1281 | (tmp_path / 'Makefile').write_text('# url2pkg-marker\n') |
1282 | | | 1282 | |
1283 | adjuster.adjust() | | 1283 | adjuster.adjust() |
1284 | | | 1284 | |
1285 | assert detab(adjuster.generate_lines()) == [ | | 1285 | assert detab(adjuster.generate_lines()) == [ |
1286 | 'WRKSRC= ${WRKDIR}', | | 1286 | 'WRKSRC= ${WRKDIR}', |
1287 | 'USE_LANGUAGES= # none', | | 1287 | 'USE_LANGUAGES= # none', |
1288 | '', | | 1288 | '', |
1289 | ] | | 1289 | ] |
1290 | | | 1290 | |
1291 | | | 1291 | |
1292 | def test_Adjuster_adjust__files_in_wrksrc(tmp_path: Path): | | 1292 | def test_Adjuster_adjust__files_in_wrksrc(tmp_path: Path): |
1293 | wrkdir = tmp_path / 'work' | | 1293 | wrkdir = tmp_path / 'work' |
1294 | wrkdir.mkdir() | | 1294 | wrkdir.mkdir() |
1295 | (wrkdir / '.hidden').touch() | | 1295 | (wrkdir / '.hidden').touch() |
1296 | (wrkdir / 'file').touch() | | 1296 | (wrkdir / 'file').touch() |
1297 | (wrkdir / 'dir').mkdir() | | 1297 | (wrkdir / 'dir').mkdir() |
1298 | (wrkdir / 'dir' / '.hidden-dir').mkdir() | | 1298 | (wrkdir / 'dir' / '.hidden-dir').mkdir() |
1299 | (wrkdir / 'dir' / 'subdir').mkdir() | | 1299 | (wrkdir / 'dir' / 'subdir').mkdir() |
1300 | (wrkdir / 'dir' / 'subdir' / '.hidden').touch() | | 1300 | (wrkdir / 'dir' / 'subdir' / '.hidden').touch() |
1301 | (wrkdir / 'dir' / 'subdir' / 'file').touch() | | 1301 | (wrkdir / 'dir' / 'subdir' / 'file').touch() |
1302 | (wrkdir / 'dir2').mkdir() # to make WRKSRC = WRKDIR | | 1302 | (wrkdir / 'dir2').mkdir() # to make WRKSRC = WRKDIR |
1303 | up.show_var = lambda varname: {'WRKDIR': str(wrkdir)}[varname] | | 1303 | g.show_var = lambda varname: {'WRKDIR': str(wrkdir)}[varname] |
1304 | up.pkgdir = tmp_path | | 1304 | g.pkgdir = tmp_path |
1305 | (tmp_path / 'Makefile').write_text('# url2pkg-marker\n') | | 1305 | (tmp_path / 'Makefile').write_text('# url2pkg-marker\n') |
1306 | adjuster = Adjuster(up, 'https://example.org/distfile-1.0.zip', Lines()) | | 1306 | adjuster = Adjuster(g, 'https://example.org/distfile-1.0.zip', Lines()) |
1307 | | | 1307 | |
1308 | adjuster.adjust() | | 1308 | adjuster.adjust() |
1309 | | | 1309 | |
1310 | assert adjuster.wrksrc_dirs == [ | | 1310 | assert adjuster.wrksrc_dirs == [ |
1311 | 'dir', | | 1311 | 'dir', |
1312 | 'dir/.hidden-dir', | | 1312 | 'dir/.hidden-dir', |
1313 | 'dir/subdir', | | 1313 | 'dir/subdir', |
1314 | 'dir2', | | 1314 | 'dir2', |
1315 | ] | | 1315 | ] |
1316 | assert adjuster.wrksrc_files == [ | | 1316 | assert adjuster.wrksrc_files == [ |
1317 | 'dir/subdir/.hidden', | | 1317 | 'dir/subdir/.hidden', |
1318 | 'dir/subdir/file', | | 1318 | 'dir/subdir/file', |
1319 | 'file', | | 1319 | 'file', |
1320 | ] | | 1320 | ] |
1321 | | | 1321 | |
1322 | | | 1322 | |
1323 | def test_Adjuster_adjust_lines_python_module(tmp_path: Path): | | 1323 | def test_Adjuster_adjust_lines_python_module(tmp_path: Path): |
1324 | url = 'https://github.com/espressif/esptool/archive/v2.7.tar.gz' | | 1324 | url = 'https://github.com/espressif/esptool/archive/v2.7.tar.gz' |
1325 | up.pkgdir = tmp_path | | 1325 | g.pkgdir = tmp_path |
1326 | up.make = 'true' # the shell command | | 1326 | g.make = 'true' # the shell command |
1327 | up.verbose = True | | 1327 | g.verbose = True |
1328 | initial_lines = Generator(url).generate_Makefile() | | 1328 | initial_lines = Generator(url).generate_Makefile() |
1329 | initial_lines.append('CATEGORIES', 'python') | | 1329 | initial_lines.append('CATEGORIES', 'python') |
1330 | adjuster = Adjuster(up, url, initial_lines) | | 1330 | adjuster = Adjuster(g, url, initial_lines) |
1331 | adjuster.makefile_lines = Lines(*initial_lines.lines) | | 1331 | adjuster.makefile_lines = Lines(*initial_lines.lines) |
1332 | (up.pkgdir / 'Makefile').touch() | | 1332 | (g.pkgdir / 'Makefile').touch() |
1333 | | | 1333 | |
1334 | assert detab(adjuster.makefile_lines) == [ | | 1334 | assert detab(adjuster.makefile_lines) == [ |
1335 | mkcvsid, | | 1335 | mkcvsid, |
1336 | '', | | 1336 | '', |
1337 | 'GITHUB_PROJECT= esptool', | | 1337 | 'GITHUB_PROJECT= esptool', |
1338 | 'GITHUB_TAG= v2.7', | | 1338 | 'GITHUB_TAG= v2.7', |
1339 | 'DISTNAME= v2.7', | | 1339 | 'DISTNAME= v2.7', |
1340 | 'PKGNAME= ${GITHUB_PROJECT}-${DISTNAME:S,^v,,}', | | 1340 | 'PKGNAME= ${GITHUB_PROJECT}-${DISTNAME:S,^v,,}', |
1341 | 'CATEGORIES= pkgtools python', | | 1341 | 'CATEGORIES= pkgtools python', |
1342 | 'MASTER_SITES= ${MASTER_SITE_GITHUB:=espressif/}', | | 1342 | 'MASTER_SITES= ${MASTER_SITE_GITHUB:=espressif/}', |
1343 | 'DIST_SUBDIR= ${GITHUB_PROJECT}', | | 1343 | 'DIST_SUBDIR= ${GITHUB_PROJECT}', |
1344 | '', | | 1344 | '', |
1345 | 'MAINTAINER= INSERT_YOUR_MAIL_ADDRESS_HERE # or use pkgsrc-users@NetBSD.org', | | 1345 | 'MAINTAINER= INSERT_YOUR_MAIL_ADDRESS_HERE # or use pkgsrc-users@NetBSD.org', |
| @@ -1361,91 +1361,91 @@ def test_Adjuster_adjust_lines_python_mo | | | @@ -1361,91 +1361,91 @@ def test_Adjuster_adjust_lines_python_mo |
1361 | 'CATEGORIES= pkgtools python', | | 1361 | 'CATEGORIES= pkgtools python', |
1362 | 'MASTER_SITES= ${MASTER_SITE_PYPI:=e/esptool/}', | | 1362 | 'MASTER_SITES= ${MASTER_SITE_PYPI:=e/esptool/}', |
1363 | '', | | 1363 | '', |
1364 | 'MAINTAINER= INSERT_YOUR_MAIL_ADDRESS_HERE # or use pkgsrc-users@NetBSD.org', | | 1364 | 'MAINTAINER= INSERT_YOUR_MAIL_ADDRESS_HERE # or use pkgsrc-users@NetBSD.org', |
1365 | 'HOMEPAGE= https://github.com/espressif/esptool/', | | 1365 | 'HOMEPAGE= https://github.com/espressif/esptool/', |
1366 | 'COMMENT= TODO: Short description of the package', | | 1366 | 'COMMENT= TODO: Short description of the package', |
1367 | '#LICENSE= # TODO: (see mk/license.mk)', | | 1367 | '#LICENSE= # TODO: (see mk/license.mk)', |
1368 | '', | | 1368 | '', |
1369 | '# url2pkg-marker (please do not remove this line.)', | | 1369 | '# url2pkg-marker (please do not remove this line.)', |
1370 | '.include "../../mk/bsd.pkg.mk"', | | 1370 | '.include "../../mk/bsd.pkg.mk"', |
1371 | ] | | 1371 | ] |
1372 | | | 1372 | |
1373 | try_mk = tmp_path / 'try-pypi.mk' | | 1373 | try_mk = tmp_path / 'try-pypi.mk' |
1374 | assert up.err.written() == [ | | 1374 | assert g.err.written() == [ |
1375 | f"url2pkg: running ['true', '-f', '{try_mk}', 'distinfo'] to try PyPI", | | 1375 | f"url2pkg: running ['true', '-f', '{try_mk}', 'distinfo'] to try PyPI", |
1376 | ] | | 1376 | ] |
1377 | | | 1377 | |
1378 | | | 1378 | |
1379 | def test_Adjuster_adjust_lines_python_module__edited(): | | 1379 | def test_Adjuster_adjust_lines_python_module__edited(): |
1380 | # When the package developer has edited the Makefile, it's unclear | | 1380 | # When the package developer has edited the Makefile, it's unclear |
1381 | # what has changed. To not damage anything, let the package | | 1381 | # what has changed. To not damage anything, let the package |
1382 | # developer migrate manually. | | 1382 | # developer migrate manually. |
1383 | | | 1383 | |
1384 | url = 'https://github.com/espressif/esptool/archive/v2.7.tar.gz' | | 1384 | url = 'https://github.com/espressif/esptool/archive/v2.7.tar.gz' |
1385 | initial_lines = Generator(url).generate_Makefile() | | 1385 | initial_lines = Generator(url).generate_Makefile() |
1386 | initial_lines.append('CATEGORIES', 'python') | | 1386 | initial_lines.append('CATEGORIES', 'python') |
1387 | adjuster = Adjuster(up, url, initial_lines) | | 1387 | adjuster = Adjuster(g, url, initial_lines) |
1388 | adjuster.makefile_lines = Lines(*initial_lines.lines) | | 1388 | adjuster.makefile_lines = Lines(*initial_lines.lines) |
1389 | initial_lines.add('') # to make the lines different | | 1389 | initial_lines.add('') # to make the lines different |
1390 | | | 1390 | |
1391 | lines = adjuster.generate_lines() | | 1391 | lines = adjuster.generate_lines() |
1392 | | | 1392 | |
1393 | assert lines.get('GITHUB_PROJECT') == 'esptool' | | 1393 | assert lines.get('GITHUB_PROJECT') == 'esptool' |
1394 | | | 1394 | |
1395 | adjuster.adjust_lines_python_module(lines) | | 1395 | adjuster.adjust_lines_python_module(lines) |
1396 | | | 1396 | |
1397 | assert lines.get('GITHUB_PROJECT') == 'esptool' | | 1397 | assert lines.get('GITHUB_PROJECT') == 'esptool' |
1398 | assert lines.index('TODO: Migrate MASTER_SITES to MASTER_SITE_PYPI') == 14 | | 1398 | assert lines.index('TODO: Migrate MASTER_SITES to MASTER_SITE_PYPI') == 14 |
1399 | | | 1399 | |
1400 | | | 1400 | |
1401 | def test_main__wrong_dir(tmp_path): | | 1401 | def test_main__wrong_dir(tmp_path): |
1402 | os.chdir(tmp_path) | | 1402 | os.chdir(tmp_path) |
1403 | error = r'url2pkg: must be run from a package directory' | | 1403 | error = r'url2pkg: must be run from a package directory' |
1404 | | | 1404 | |
1405 | with pytest.raises(SystemExit, match=error): | | 1405 | with pytest.raises(SystemExit, match=error): |
1406 | main(['url2pkg'], up) | | 1406 | main(['url2pkg'], g) |
1407 | | | 1407 | |
1408 | | | 1408 | |
1409 | def test_main__unknown_option(): | | 1409 | def test_main__unknown_option(): |
1410 | with pytest.raises(SystemExit, match=r'usage:'): | | 1410 | with pytest.raises(SystemExit, match=r'usage:'): |
1411 | main(['url2pkg', '--unknown'], up) | | 1411 | main(['url2pkg', '--unknown'], g) |
1412 | | | 1412 | |
1413 | | | 1413 | |
1414 | def test_main__verbose(): | | 1414 | def test_main__verbose(): |
1415 | with pytest.raises(SystemExit, match=r'url2pkg: invalid URL: broken URL'): | | 1415 | with pytest.raises(SystemExit, match=r'url2pkg: invalid URL: broken URL'): |
1416 | main(['url2pkg', '--verbose', 'broken URL'], up) | | 1416 | main(['url2pkg', '--verbose', 'broken URL'], g) |
1417 | | | 1417 | |
1418 | | | 1418 | |
1419 | def test_main__valid_URL(): | | 1419 | def test_main__valid_URL(): |
1420 | import shutil | | 1420 | import shutil |
1421 | | | 1421 | |
1422 | up.editor = 'true' | | 1422 | g.editor = 'true' |
1423 | up.make = os.getenv('MAKE') or sys.exit('MAKE must be set') | | 1423 | g.make = os.getenv('MAKE') or sys.exit('MAKE must be set') |
1424 | up.pkgdir = up.pkgsrcdir / 'pkgtools' / 'url2pkg-test-main' | | 1424 | g.pkgdir = g.pkgsrcdir / 'pkgtools' / 'url2pkg-test-main' |
1425 | up.pkgdir.is_dir() and shutil.rmtree(up.pkgdir) | | 1425 | g.pkgdir.is_dir() and shutil.rmtree(g.pkgdir) |
1426 | try: | | 1426 | try: |
1427 | up.pkgdir.mkdir() | | 1427 | g.pkgdir.mkdir() |
1428 | except OSError: | | 1428 | except OSError: |
1429 | return # skip if the directory is not writable | | 1429 | return # skip if the directory is not writable |
1430 | os.chdir(up.pkgdir) | | 1430 | os.chdir(g.pkgdir) |
1431 | | | 1431 | |
1432 | main(['url2pkg', '-v', 'https://github.com/rillig/checkperms/archive/v1.12.tar.gz'], up) | | 1432 | main(['url2pkg', '-v', 'https://github.com/rillig/checkperms/archive/v1.12.tar.gz'], g) |
1433 | | | 1433 | |
1434 | assert up.out.written() == [ | | 1434 | assert g.out.written() == [ |
1435 | '', | | 1435 | '', |
1436 | 'Remember to run pkglint when you\'re done.', | | 1436 | 'Remember to run pkglint when you\'re done.', |
1437 | 'See ../../doc/pkgsrc.txt to get some help.', | | 1437 | 'See ../../doc/pkgsrc.txt to get some help.', |
1438 | '', | | 1438 | '', |
1439 | ] | | 1439 | ] |
1440 | assert up.err.written() == [ | | 1440 | assert g.err.written() == [ |
1441 | f'url2pkg: running bmake (\'clean\', \'distinfo\', \'extract\') in \'{up.pkgdir}\'', | | 1441 | f'url2pkg: running bmake (\'clean\', \'distinfo\', \'extract\') in \'{g.pkgdir}\'', |
1442 | 'url2pkg: Adjusting the Makefile', | | 1442 | 'url2pkg: Adjusting the Makefile', |
1443 | ] | | 1443 | ] |
1444 | | | 1444 | |
1445 | up.verbose = False | | 1445 | g.verbose = False |
1446 | up.bmake('clean') # remove the work directory | | 1446 | g.bmake('clean') # remove the work directory |
1447 | | | 1447 | |
1448 | expected_files = ['DESCR', 'Makefile', 'PLIST', 'distinfo'] | | 1448 | expected_files = ['DESCR', 'Makefile', 'PLIST', 'distinfo'] |
1449 | assert sorted([f.name for f in up.pkgdir.glob("*")]) == expected_files | | 1449 | assert sorted([f.name for f in g.pkgdir.glob("*")]) == expected_files |
1450 | | | 1450 | |
1451 | shutil.rmtree(up.pkgdir) | | 1451 | shutil.rmtree(g.pkgdir) |