diff options
Diffstat (limited to 'scripts/lib/devtool/build_image.py')
| -rw-r--r-- | scripts/lib/devtool/build_image.py | 124 |
1 files changed, 65 insertions, 59 deletions
diff --git a/scripts/lib/devtool/build_image.py b/scripts/lib/devtool/build_image.py index 14c646a066..ae75511dc7 100644 --- a/scripts/lib/devtool/build_image.py +++ b/scripts/lib/devtool/build_image.py | |||
| @@ -86,70 +86,76 @@ def build_image_task(config, basepath, workspace, image, add_packages=None, task | |||
| 86 | raise | 86 | raise |
| 87 | 87 | ||
| 88 | tinfoil = setup_tinfoil(basepath=basepath) | 88 | tinfoil = setup_tinfoil(basepath=basepath) |
| 89 | rd = parse_recipe(config, tinfoil, image, True) | ||
| 90 | if not rd: | ||
| 91 | # Error already shown | ||
| 92 | return (1, None) | ||
| 93 | if not bb.data.inherits_class('image', rd): | ||
| 94 | raise TargetNotImageError() | ||
| 95 | |||
| 96 | # Get the actual filename used and strip the .bb and full path | ||
| 97 | target_basename = rd.getVar('FILE', True) | ||
| 98 | target_basename = os.path.splitext(os.path.basename(target_basename))[0] | ||
| 99 | config.set('SDK', 'target_basename', target_basename) | ||
| 100 | config.write() | ||
| 101 | |||
| 102 | appendfile = os.path.join(config.workspace_path, 'appends', | ||
| 103 | '%s.bbappend' % target_basename) | ||
| 104 | |||
| 105 | outputdir = None | ||
| 106 | try: | 89 | try: |
| 107 | if workspace or add_packages: | 90 | rd = parse_recipe(config, tinfoil, image, True) |
| 108 | if add_packages: | 91 | if not rd: |
| 109 | packages = add_packages | 92 | # Error already shown |
| 110 | else: | 93 | return (1, None) |
| 111 | packages = _get_packages(tinfoil, workspace, config) | 94 | if not bb.data.inherits_class('image', rd): |
| 112 | else: | 95 | raise TargetNotImageError() |
| 113 | packages = None | 96 | |
| 114 | if not task: | 97 | # Get the actual filename used and strip the .bb and full path |
| 115 | if not packages and not add_packages and workspace: | 98 | target_basename = rd.getVar('FILE', True) |
| 116 | logger.warning('No recipes in workspace, building image %s unmodified', image) | 99 | target_basename = os.path.splitext(os.path.basename(target_basename))[0] |
| 117 | elif not packages: | 100 | config.set('SDK', 'target_basename', target_basename) |
| 118 | logger.warning('No packages to add, building image %s unmodified', image) | 101 | config.write() |
| 119 | |||
| 120 | if packages or extra_append: | ||
| 121 | bb.utils.mkdirhier(os.path.dirname(appendfile)) | ||
| 122 | with open(appendfile, 'w') as afile: | ||
| 123 | if packages: | ||
| 124 | # include packages from workspace recipes into the image | ||
| 125 | afile.write('IMAGE_INSTALL_append = " %s"\n' % ' '.join(packages)) | ||
| 126 | if not task: | ||
| 127 | logger.info('Building image %s with the following ' | ||
| 128 | 'additional packages: %s', image, ' '.join(packages)) | ||
| 129 | if extra_append: | ||
| 130 | for line in extra_append: | ||
| 131 | afile.write('%s\n' % line) | ||
| 132 | |||
| 133 | if task in ['populate_sdk', 'populate_sdk_ext']: | ||
| 134 | outputdir = rd.getVar('SDK_DEPLOY', True) | ||
| 135 | else: | ||
| 136 | outputdir = rd.getVar('DEPLOY_DIR_IMAGE', True) | ||
| 137 | |||
| 138 | tinfoil.shutdown() | ||
| 139 | 102 | ||
| 140 | options = '' | 103 | appendfile = os.path.join(config.workspace_path, 'appends', |
| 141 | if task: | 104 | '%s.bbappend' % target_basename) |
| 142 | options += '-c %s' % task | ||
| 143 | 105 | ||
| 144 | # run bitbake to build image (or specified task) | 106 | outputdir = None |
| 145 | try: | 107 | try: |
| 146 | exec_build_env_command(config.init_path, basepath, | 108 | if workspace or add_packages: |
| 147 | 'bitbake %s %s' % (options, image), watch=True) | 109 | if add_packages: |
| 148 | except ExecutionError as err: | 110 | packages = add_packages |
| 149 | return (err.exitcode, None) | 111 | else: |
| 112 | packages = _get_packages(tinfoil, workspace, config) | ||
| 113 | else: | ||
| 114 | packages = None | ||
| 115 | if not task: | ||
| 116 | if not packages and not add_packages and workspace: | ||
| 117 | logger.warning('No recipes in workspace, building image %s unmodified', image) | ||
| 118 | elif not packages: | ||
| 119 | logger.warning('No packages to add, building image %s unmodified', image) | ||
| 120 | |||
| 121 | if packages or extra_append: | ||
| 122 | bb.utils.mkdirhier(os.path.dirname(appendfile)) | ||
| 123 | with open(appendfile, 'w') as afile: | ||
| 124 | if packages: | ||
| 125 | # include packages from workspace recipes into the image | ||
| 126 | afile.write('IMAGE_INSTALL_append = " %s"\n' % ' '.join(packages)) | ||
| 127 | if not task: | ||
| 128 | logger.info('Building image %s with the following ' | ||
| 129 | 'additional packages: %s', image, ' '.join(packages)) | ||
| 130 | if extra_append: | ||
| 131 | for line in extra_append: | ||
| 132 | afile.write('%s\n' % line) | ||
| 133 | |||
| 134 | if task in ['populate_sdk', 'populate_sdk_ext']: | ||
| 135 | outputdir = rd.getVar('SDK_DEPLOY', True) | ||
| 136 | else: | ||
| 137 | outputdir = rd.getVar('DEPLOY_DIR_IMAGE', True) | ||
| 138 | |||
| 139 | tmp_tinfoil = tinfoil | ||
| 140 | tinfoil = None | ||
| 141 | tmp_tinfoil.shutdown() | ||
| 142 | |||
| 143 | options = '' | ||
| 144 | if task: | ||
| 145 | options += '-c %s' % task | ||
| 146 | |||
| 147 | # run bitbake to build image (or specified task) | ||
| 148 | try: | ||
| 149 | exec_build_env_command(config.init_path, basepath, | ||
| 150 | 'bitbake %s %s' % (options, image), watch=True) | ||
| 151 | except ExecutionError as err: | ||
| 152 | return (err.exitcode, None) | ||
| 153 | finally: | ||
| 154 | if os.path.isfile(appendfile): | ||
| 155 | os.unlink(appendfile) | ||
| 150 | finally: | 156 | finally: |
| 151 | if os.path.isfile(appendfile): | 157 | if tinfoil: |
| 152 | os.unlink(appendfile) | 158 | tinfoil.shutdown() |
| 153 | return (0, outputdir) | 159 | return (0, outputdir) |
| 154 | 160 | ||
| 155 | 161 | ||
