diff options
| -rwxr-xr-x | bitbake/bin/bitbake-setup | 161 | ||||
| -rw-r--r-- | bitbake/lib/bb/tests/setup.py | 13 |
2 files changed, 69 insertions, 105 deletions
diff --git a/bitbake/bin/bitbake-setup b/bitbake/bin/bitbake-setup index e9e73a9270..71b5b8de9f 100755 --- a/bitbake/bin/bitbake-setup +++ b/bitbake/bin/bitbake-setup | |||
| @@ -436,6 +436,7 @@ def init_config(top_dir, settings, args, d): | |||
| 436 | progress = event.progress if event.progress > 0 else 0 | 436 | progress = event.progress if event.progress > 0 else 0 |
| 437 | print("{}% {} ".format(progress, rate), file=stdout, end='\r') | 437 | print("{}% {} ".format(progress, rate), file=stdout, end='\r') |
| 438 | 438 | ||
| 439 | create_siteconf(top_dir, args.non_interactive) | ||
| 439 | source_overrides = json.load(open(args.source_overrides)) if args.source_overrides else {'sources':{}} | 440 | source_overrides = json.load(open(args.source_overrides)) if args.source_overrides else {'sources':{}} |
| 440 | upstream_config = obtain_config(top_dir, settings, args, source_overrides, d) | 441 | upstream_config = obtain_config(top_dir, settings, args, source_overrides, d) |
| 441 | print("\nRun 'bitbake-setup init --non-interactive {}' to select this configuration non-interactively.\n".format(" ".join(upstream_config['non-interactive-cmdline-options']))) | 442 | print("\nRun 'bitbake-setup init --non-interactive {}' to select this configuration non-interactively.\n".format(" ".join(upstream_config['non-interactive-cmdline-options']))) |
| @@ -636,30 +637,15 @@ def install_buildtools(top_dir, settings, args, d): | |||
| 636 | def default_settings_path(top_dir): | 637 | def default_settings_path(top_dir): |
| 637 | return os.path.join(top_dir, 'settings.conf') | 638 | return os.path.join(top_dir, 'settings.conf') |
| 638 | 639 | ||
| 639 | def create_settings(top_dir, non_interactive=True): | 640 | def create_siteconf(top_dir, non_interactive=True): |
| 640 | settings_path = default_settings_path(top_dir) | ||
| 641 | settings = configparser.ConfigParser() | ||
| 642 | settings['default'] = { | ||
| 643 | } | ||
| 644 | os.makedirs(os.path.dirname(settings_path), exist_ok=True) | ||
| 645 | |||
| 646 | siteconfpath = os.path.join(top_dir, 'site.conf') | 641 | siteconfpath = os.path.join(top_dir, 'site.conf') |
| 647 | print('A new empty settings file will be created in (you can add settings to it to override defaults from the global settings file)\n {}\n'.format(settings_path)) | ||
| 648 | print('A common site.conf file will be created, please edit or replace before running builds\n {}\n'.format(siteconfpath)) | 642 | print('A common site.conf file will be created, please edit or replace before running builds\n {}\n'.format(siteconfpath)) |
| 649 | if not non_interactive: | 643 | if not non_interactive: |
| 650 | y_or_n = input('Bitbake-setup will be configured with the above settings in {}, (y/N): '.format(top_dir)) | 644 | y_or_n = input('Proceed? (y/N): ') |
| 651 | if y_or_n != 'y': | 645 | if y_or_n != 'y': |
| 652 | print("\nYou can run 'bitbake-setup install-settings' to edit them before setting up builds") | ||
| 653 | exit() | 646 | exit() |
| 654 | print() | ||
| 655 | |||
| 656 | if os.path.exists(settings_path): | ||
| 657 | backup_conf = settings_path + "-backup.{}".format(time.strftime("%Y%m%d%H%M%S")) | ||
| 658 | os.rename(settings_path, backup_conf) | ||
| 659 | print("Previous settings are in {}".format(backup_conf)) | ||
| 660 | with open(settings_path, 'w') as settingsfile: | ||
| 661 | settings.write(settingsfile) | ||
| 662 | 647 | ||
| 648 | os.makedirs(os.path.dirname(top_dir), exist_ok=True) | ||
| 663 | if os.path.exists(siteconfpath): | 649 | if os.path.exists(siteconfpath): |
| 664 | backup_siteconf = siteconfpath + "-backup.{}".format(time.strftime("%Y%m%d%H%M%S")) | 650 | backup_siteconf = siteconfpath + "-backup.{}".format(time.strftime("%Y%m%d%H%M%S")) |
| 665 | os.rename(siteconfpath, backup_siteconf) | 651 | os.rename(siteconfpath, backup_siteconf) |
| @@ -667,58 +653,26 @@ def create_settings(top_dir, non_interactive=True): | |||
| 667 | with open(siteconfpath, 'w') as siteconffile: | 653 | with open(siteconfpath, 'w') as siteconffile: |
| 668 | siteconffile.write('# This file is intended for build host-specific bitbake settings\n') | 654 | siteconffile.write('# This file is intended for build host-specific bitbake settings\n') |
| 669 | 655 | ||
| 670 | def load_settings(top_dir, non_interactive): | ||
| 671 | settings_path = default_settings_path(top_dir) | ||
| 672 | if not os.path.exists(settings_path): | ||
| 673 | create_settings(top_dir, non_interactive=non_interactive) | ||
| 674 | |||
| 675 | settings = configparser.ConfigParser() | ||
| 676 | print('Loading settings from\n {}\n'.format(settings_path)) | ||
| 677 | settings.read_file(open(settings_path)) | ||
| 678 | return settings | ||
| 679 | |||
| 680 | def global_settings_path(args): | 656 | def global_settings_path(args): |
| 681 | return os.path.abspath(args.global_settings) if args.global_settings else os.path.join(os.path.expanduser('~'), '.config', 'bitbake-setup', 'settings.conf') | 657 | return os.path.abspath(args.global_settings) if args.global_settings else os.path.join(os.path.expanduser('~'), '.config', 'bitbake-setup', 'settings.conf') |
| 682 | 658 | ||
| 683 | def create_global_settings(settings_path, non_interactive=True): | 659 | def load_settings(settings_path): |
| 684 | settings = configparser.ConfigParser() | 660 | settings = configparser.ConfigParser() |
| 685 | settings['default'] = { | ||
| 686 | 'top-dir-prefix':os.path.expanduser('~'), | ||
| 687 | 'top-dir-name':'bitbake-builds', | ||
| 688 | 'registry':default_registry, | ||
| 689 | 'dl-dir':os.path.join(os.path.expanduser('~'), '.cache', 'bitbake-setup', 'downloads'), | ||
| 690 | } | ||
| 691 | os.makedirs(os.path.dirname(settings_path), exist_ok=True) | ||
| 692 | print('Configuring global settings in\n {}\n'.format(settings_path)) | ||
| 693 | print('Top directory prefix (where all top level directories are created) set to\n {}\n'.format(settings['default']['top-dir-prefix'])) | ||
| 694 | print('Top directory name (this is added to the top directory prefix to form a top directory where builds are set up) set to\n {}\n'.format(settings['default']['top-dir-name'])) | ||
| 695 | print('Configuration registry set to\n {}\n'.format(settings['default']['registry'])) | ||
| 696 | print('Bitbake-setup download cache (DL_DIR) set to\n {}\n'.format(settings['default']['dl-dir'])) | ||
| 697 | if not non_interactive: | ||
| 698 | y_or_n = input('Write out the global settings as specified above (y/N)? ') | ||
| 699 | if y_or_n != 'y': | ||
| 700 | print("\nYou can run 'bitbake-setup install-global-settings' to edit them before setting up builds") | ||
| 701 | exit() | ||
| 702 | print() | ||
| 703 | |||
| 704 | if os.path.exists(settings_path): | 661 | if os.path.exists(settings_path): |
| 705 | backup_conf = settings_path + "-backup.{}".format(time.strftime("%Y%m%d%H%M%S")) | 662 | print('Loading settings from\n {}\n'.format(settings_path)) |
| 706 | os.rename(settings_path, backup_conf) | 663 | settings.read_file(open(settings_path)) |
| 707 | print("Previous global settings are in {}".format(backup_conf)) | ||
| 708 | with open(settings_path, 'w') as settingsfile: | ||
| 709 | settings.write(settingsfile) | ||
| 710 | |||
| 711 | def load_global_settings(settings_path, non_interactive): | ||
| 712 | if not os.path.exists(settings_path): | ||
| 713 | create_global_settings(settings_path, non_interactive=non_interactive) | ||
| 714 | |||
| 715 | settings = configparser.ConfigParser() | ||
| 716 | print('Loading global settings from\n {}\n'.format(settings_path)) | ||
| 717 | settings.read_file(open(settings_path)) | ||
| 718 | return settings | 664 | return settings |
| 719 | 665 | ||
| 720 | def change_setting(settings_path, settings, args): | 666 | def change_setting(top_dir, args): |
| 667 | if vars(args)['global']: | ||
| 668 | settings_path = global_settings_path(args) | ||
| 669 | else: | ||
| 670 | settings_path = default_settings_path(top_dir) | ||
| 671 | settings = load_settings(settings_path) | ||
| 672 | |||
| 721 | if args.section and args.key and args.value: | 673 | if args.section and args.key and args.value: |
| 674 | if args.section not in settings.keys(): | ||
| 675 | settings[args.section] = {} | ||
| 722 | settings[args.section][args.key] = args.value | 676 | settings[args.section][args.key] = args.value |
| 723 | print("Setting '{}' in section '{}' is changed to '{}'".format(args.key, args.section, args.value)) | 677 | print("Setting '{}' in section '{}' is changed to '{}'".format(args.key, args.section, args.value)) |
| 724 | if args.unset: | 678 | if args.unset: |
| @@ -728,19 +682,21 @@ def change_setting(settings_path, settings, args): | |||
| 728 | del settings[section][setting] | 682 | del settings[section][setting] |
| 729 | print("Setting '{} in section '{}' is removed".format(setting, section)) | 683 | print("Setting '{} in section '{}' is removed".format(setting, section)) |
| 730 | 684 | ||
| 685 | os.makedirs(os.path.dirname(settings_path), exist_ok=True) | ||
| 731 | with open(settings_path, 'w') as settingsfile: | 686 | with open(settings_path, 'w') as settingsfile: |
| 732 | settings.write(settingsfile) | 687 | settings.write(settingsfile) |
| 733 | print("New settings written to {}".format(settings_path)) | 688 | print("New settings written to {}".format(settings_path)) |
| 734 | 689 | ||
| 735 | def setting_global(args): | 690 | def list_settings(all_settings): |
| 736 | settings = load_global_settings(global_settings_path(args), args.non_interactive) | 691 | for section, section_settings in all_settings.items(): |
| 737 | settings_path = global_settings_path(args) | 692 | for key, value in section_settings.items(): |
| 738 | change_setting(settings_path, settings, args) | 693 | print("{} {} {}".format(section, key, value)) |
| 739 | 694 | ||
| 740 | def setting(top_dir, args): | 695 | def settings_func(top_dir, all_settings, args): |
| 741 | settings = load_settings(top_dir, args.non_interactive) | 696 | if args.list: |
| 742 | settings_path = default_settings_path(top_dir) | 697 | list_settings(all_settings) |
| 743 | change_setting(settings_path, settings, args) | 698 | else: |
| 699 | change_setting(top_dir, args) | ||
| 744 | 700 | ||
| 745 | def get_build_dir_via_bbpath(): | 701 | def get_build_dir_via_bbpath(): |
| 746 | bbpath = os.environ.get('BBPATH') | 702 | bbpath = os.environ.get('BBPATH') |
| @@ -766,11 +722,13 @@ def get_top_dir(args, settings): | |||
| 766 | top_dir_name = settings['default']['top-dir-name'] | 722 | top_dir_name = settings['default']['top-dir-name'] |
| 767 | return os.path.join(top_dir_prefix, top_dir_name) | 723 | return os.path.join(top_dir_prefix, top_dir_name) |
| 768 | 724 | ||
| 769 | def merge_settings(global_settings, local_settings, cmdline_settings): | 725 | def merge_settings(builtin_settings, global_settings, local_settings, cmdline_settings): |
| 770 | all_settings = global_settings | 726 | all_settings = builtin_settings |
| 771 | for section, section_settings in local_settings.items(): | 727 | |
| 772 | for setting, value in section_settings.items(): | 728 | for s in (global_settings, local_settings): |
| 773 | all_settings[section][setting] = value | 729 | for section, section_settings in s.items(): |
| 730 | for setting, value in section_settings.items(): | ||
| 731 | all_settings[section][setting] = value | ||
| 774 | 732 | ||
| 775 | for (section, setting, value) in cmdline_settings: | 733 | for (section, setting, value) in cmdline_settings: |
| 776 | all_settings[section][setting] = value | 734 | all_settings[section][setting] = value |
| @@ -824,16 +782,14 @@ def main(): | |||
| 824 | parser_install_buildtools.add_argument('--force', action='store_true', help='Force a reinstall of buildtools over the previous installation.') | 782 | parser_install_buildtools.add_argument('--force', action='store_true', help='Force a reinstall of buildtools over the previous installation.') |
| 825 | parser_install_buildtools.set_defaults(func=install_buildtools) | 783 | parser_install_buildtools.set_defaults(func=install_buildtools) |
| 826 | 784 | ||
| 827 | parser_install_global_settings = subparsers.add_parser('install-global-settings', help='Write a global settings file with default values') | 785 | parser_settings = subparsers.add_parser('settings', help='List current settings, or set or unset a setting in a settings file (e.g. the default prefix and name of the top directory, the location of build configuration registry, downloads directory and other settings specific to a top directory)') |
| 828 | parser_install_global_settings.set_defaults(func=create_global_settings) | 786 | parser_settings.add_argument('section', nargs='?', help="Section in a settings file, typically 'default'") |
| 829 | 787 | parser_settings.add_argument('key', nargs='?', help="Name of the setting") | |
| 830 | parser_setting = subparsers.add_parser('setting', help='Set or unset a setting in a setting file (e.g. the default prefix and name of the top directory, the location of build configuration registry, downloads directory and other settings specific to a top directory)') | 788 | parser_settings.add_argument('value', nargs='?', help="Value of the setting") |
| 831 | parser_setting.add_argument('section', nargs='?', help="Section in a settings file, typically 'default'") | 789 | parser_settings.add_argument('--global', action='store_true', help="Modify the setting in a global settings file, rather than one specific to a top directory") |
| 832 | parser_setting.add_argument('key', nargs='?', help="Name of the setting") | 790 | parser_settings.add_argument('--unset', nargs=2, help="Unset a setting, e.g. 'bitbake-setup setting --unset default registry' would revert to the registry setting in a global settings file") |
| 833 | parser_setting.add_argument('value', nargs='?', help="Value of the setting") | 791 | parser_settings.add_argument('-l' ,'--list', action='store_true', help="List all settings with their values") |
| 834 | parser_setting.add_argument('--global', action='store_true', help="Modify the setting in a global settings file, rather than one specific to a top directory") | 792 | parser_settings.set_defaults(func=settings_func) |
| 835 | parser_setting.add_argument('--unset', nargs=2, help="Unset a setting, e.g. 'bitbake-setup setting --unset default registry' would revert to the registry setting in a global settings file") | ||
| 836 | parser_setting.set_defaults(func=setting) | ||
| 837 | 793 | ||
| 838 | args = parser.parse_args() | 794 | args = parser.parse_args() |
| 839 | 795 | ||
| @@ -850,10 +806,6 @@ def main(): | |||
| 850 | level=logger.getEffectiveLevel()) | 806 | level=logger.getEffectiveLevel()) |
| 851 | 807 | ||
| 852 | if 'func' in args: | 808 | if 'func' in args: |
| 853 | if args.func == create_global_settings: | ||
| 854 | create_global_settings(global_settings_path(args)) | ||
| 855 | return | ||
| 856 | |||
| 857 | if hasattr(args, 'build_dir'): | 809 | if hasattr(args, 'build_dir'): |
| 858 | if not os.path.exists(os.path.join(args.build_dir,'build', 'init-build-env')): | 810 | if not os.path.exists(os.path.join(args.build_dir,'build', 'init-build-env')): |
| 859 | print("Not a valid build directory: build/init-build-env does not exist in {}".format(args.build_dir)) | 811 | print("Not a valid build directory: build/init-build-env does not exist in {}".format(args.build_dir)) |
| @@ -862,23 +814,30 @@ def main(): | |||
| 862 | if not hasattr(args, 'non_interactive'): | 814 | if not hasattr(args, 'non_interactive'): |
| 863 | args.non_interactive = True | 815 | args.non_interactive = True |
| 864 | 816 | ||
| 865 | if args.func == setting and vars(args)['global']: | 817 | builtin_settings = {} |
| 866 | setting_global(args) | 818 | builtin_settings['default'] = { |
| 867 | return | 819 | 'top-dir-prefix':os.path.expanduser('~'), |
| 820 | 'top-dir-name':'bitbake-builds', | ||
| 821 | 'registry':default_registry, | ||
| 822 | } | ||
| 823 | |||
| 824 | global_settings = load_settings(global_settings_path(args)) | ||
| 825 | top_dir = get_top_dir(args, merge_settings(builtin_settings, global_settings, {}, args.setting)) | ||
| 826 | |||
| 827 | # This cannot be set with the rest of the builtin settings as top_dir needs to be determined first | ||
| 828 | builtin_settings['default']['dl-dir'] = os.path.join(top_dir, '.bitbake-setup-downloads') | ||
| 868 | 829 | ||
| 869 | global_settings = load_global_settings(global_settings_path(args), args.non_interactive) | 830 | topdir_settings = load_settings(default_settings_path(top_dir)) |
| 870 | top_dir = get_top_dir(args, merge_settings(global_settings, {}, args.setting)) | 831 | all_settings = merge_settings(builtin_settings, global_settings, topdir_settings, args.setting) |
| 871 | 832 | ||
| 872 | if args.func == setting: | 833 | if args.func == settings_func: |
| 873 | setting(top_dir, args) | 834 | settings_func(top_dir, all_settings, args) |
| 874 | return | 835 | return |
| 875 | 836 | ||
| 876 | print('Bitbake-setup is using {} as top directory (can be changed by setting top dir prefix and name in {}).\n'.format(top_dir, global_settings_path(args))) | 837 | print('Bitbake-setup is using {} as top directory ("bitbake-setup setting --help" shows how to change it).\n'.format(top_dir, global_settings_path(args))) |
| 877 | 838 | ||
| 878 | settings = load_settings(top_dir, args.non_interactive) | 839 | d = init_bb_cache(top_dir, all_settings, args) |
| 879 | settings = merge_settings(global_settings, settings, args.setting) | 840 | args.func(top_dir, all_settings, args, d) |
| 880 | d = init_bb_cache(top_dir, settings, args) | ||
| 881 | args.func(top_dir, settings, args, d) | ||
| 882 | save_bb_cache() | 841 | save_bb_cache() |
| 883 | else: | 842 | else: |
| 884 | from argparse import Namespace | 843 | from argparse import Namespace |
diff --git a/bitbake/lib/bb/tests/setup.py b/bitbake/lib/bb/tests/setup.py index 22edda40e4..b238926b29 100644 --- a/bitbake/lib/bb/tests/setup.py +++ b/bitbake/lib/bb/tests/setup.py | |||
| @@ -232,24 +232,29 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"])) | |||
| 232 | self.runbbsetup("--help") | 232 | self.runbbsetup("--help") |
| 233 | 233 | ||
| 234 | # set up global location for top-dir-prefix | 234 | # set up global location for top-dir-prefix |
| 235 | out = self.runbbsetup("install-global-settings") | 235 | out = self.runbbsetup("settings --global default top-dir-prefix {}".format(self.tempdir)) |
| 236 | settings_path = "{}/global-config".format(self.tempdir) | 236 | settings_path = "{}/global-config".format(self.tempdir) |
| 237 | self.assertIn(settings_path, out[0]) | 237 | self.assertIn(settings_path, out[0]) |
| 238 | out = self.runbbsetup("setting --global default top-dir-prefix {}".format(self.tempdir)) | ||
| 239 | self.assertIn("Setting 'top-dir-prefix' in section 'default' is changed to", out[0]) | 238 | self.assertIn("Setting 'top-dir-prefix' in section 'default' is changed to", out[0]) |
| 240 | self.assertIn("New settings written to".format(settings_path), out[0]) | 239 | self.assertIn("New settings written to".format(settings_path), out[0]) |
| 241 | out = self.runbbsetup("setting --global default dl-dir {}".format(os.path.join(self.tempdir, 'downloads'))) | 240 | out = self.runbbsetup("settings --global default dl-dir {}".format(os.path.join(self.tempdir, 'downloads'))) |
| 242 | self.assertIn("Setting 'dl-dir' in section 'default' is changed to", out[0]) | 241 | self.assertIn("Setting 'dl-dir' in section 'default' is changed to", out[0]) |
| 243 | self.assertIn("New settings written to".format(settings_path), out[0]) | 242 | self.assertIn("New settings written to".format(settings_path), out[0]) |
| 244 | 243 | ||
| 245 | # check that writing settings works and then adjust them to point to | 244 | # check that writing settings works and then adjust them to point to |
| 246 | # test registry repo | 245 | # test registry repo |
| 247 | out = self.runbbsetup("setting default registry 'git://{};protocol=file;branch=master;rev=master'".format(self.registrypath)) | 246 | out = self.runbbsetup("settings default registry 'git://{};protocol=file;branch=master;rev=master'".format(self.registrypath)) |
| 248 | settings_path = "{}/bitbake-builds/settings.conf".format(self.tempdir) | 247 | settings_path = "{}/bitbake-builds/settings.conf".format(self.tempdir) |
| 249 | self.assertIn(settings_path, out[0]) | 248 | self.assertIn(settings_path, out[0]) |
| 250 | self.assertIn("Setting 'registry' in section 'default' is changed to", out[0]) | 249 | self.assertIn("Setting 'registry' in section 'default' is changed to", out[0]) |
| 251 | self.assertIn("New settings written to".format(settings_path), out[0]) | 250 | self.assertIn("New settings written to".format(settings_path), out[0]) |
| 252 | 251 | ||
| 252 | # check that listing settings works | ||
| 253 | out = self.runbbsetup("settings --list") | ||
| 254 | self.assertIn("default top-dir-prefix {}".format(self.tempdir), out[0]) | ||
| 255 | self.assertIn("default dl-dir {}".format(os.path.join(self.tempdir, 'downloads')), out[0]) | ||
| 256 | self.assertIn("default registry {}".format('git://{};protocol=file;branch=master;rev=master'.format(self.registrypath)), out[0]) | ||
| 257 | |||
| 253 | # check that 'list' produces correct output with no configs, one config and two configs | 258 | # check that 'list' produces correct output with no configs, one config and two configs |
| 254 | out = self.runbbsetup("list") | 259 | out = self.runbbsetup("list") |
| 255 | self.assertNotIn("test-config-1", out[0]) | 260 | self.assertNotIn("test-config-1", out[0]) |
