diff options
Diffstat (limited to 'scripts/lib/devtool/deploy.py')
-rw-r--r-- | scripts/lib/devtool/deploy.py | 240 |
1 files changed, 126 insertions, 114 deletions
diff --git a/scripts/lib/devtool/deploy.py b/scripts/lib/devtool/deploy.py index e5af2c95ae..b5ca8f2c2f 100644 --- a/scripts/lib/devtool/deploy.py +++ b/scripts/lib/devtool/deploy.py | |||
@@ -16,7 +16,7 @@ import bb.utils | |||
16 | import argparse_oe | 16 | import argparse_oe |
17 | import oe.types | 17 | import oe.types |
18 | 18 | ||
19 | from devtool import exec_fakeroot, setup_tinfoil, check_workspace_recipe, DevtoolError | 19 | from devtool import exec_fakeroot_no_d, setup_tinfoil, check_workspace_recipe, DevtoolError |
20 | 20 | ||
21 | logger = logging.getLogger('devtool') | 21 | logger = logging.getLogger('devtool') |
22 | 22 | ||
@@ -133,16 +133,38 @@ def _prepare_remote_script(deploy, verbose=False, dryrun=False, undeployall=Fals | |||
133 | 133 | ||
134 | return '\n'.join(lines) | 134 | return '\n'.join(lines) |
135 | 135 | ||
136 | |||
137 | |||
138 | def deploy(args, config, basepath, workspace): | 136 | def deploy(args, config, basepath, workspace): |
139 | """Entry point for the devtool 'deploy' subcommand""" | 137 | """Entry point for the devtool 'deploy' subcommand""" |
140 | import math | 138 | import oe.utils |
141 | import oe.recipeutils | ||
142 | import oe.package | ||
143 | 139 | ||
144 | check_workspace_recipe(workspace, args.recipename, checksrc=False) | 140 | check_workspace_recipe(workspace, args.recipename, checksrc=False) |
145 | 141 | ||
142 | tinfoil = setup_tinfoil(basepath=basepath) | ||
143 | try: | ||
144 | try: | ||
145 | rd = tinfoil.parse_recipe(args.recipename) | ||
146 | except Exception as e: | ||
147 | raise DevtoolError('Exception parsing recipe %s: %s' % | ||
148 | (args.recipename, e)) | ||
149 | |||
150 | srcdir = rd.getVar('D') | ||
151 | workdir = rd.getVar('WORKDIR') | ||
152 | path = rd.getVar('PATH') | ||
153 | strip_cmd = rd.getVar('STRIP') | ||
154 | libdir = rd.getVar('libdir') | ||
155 | base_libdir = rd.getVar('base_libdir') | ||
156 | max_process = oe.utils.get_bb_number_threads(rd) | ||
157 | fakerootcmd = rd.getVar('FAKEROOTCMD') | ||
158 | fakerootenv = rd.getVar('FAKEROOTENV') | ||
159 | finally: | ||
160 | tinfoil.shutdown() | ||
161 | |||
162 | return deploy_no_d(srcdir, workdir, path, strip_cmd, libdir, base_libdir, max_process, fakerootcmd, fakerootenv, args) | ||
163 | |||
164 | def deploy_no_d(srcdir, workdir, path, strip_cmd, libdir, base_libdir, max_process, fakerootcmd, fakerootenv, args): | ||
165 | import math | ||
166 | import oe.package | ||
167 | |||
146 | try: | 168 | try: |
147 | host, destdir = args.target.split(':') | 169 | host, destdir = args.target.split(':') |
148 | except ValueError: | 170 | except ValueError: |
@@ -152,118 +174,108 @@ def deploy(args, config, basepath, workspace): | |||
152 | if not destdir.endswith('/'): | 174 | if not destdir.endswith('/'): |
153 | destdir += '/' | 175 | destdir += '/' |
154 | 176 | ||
155 | tinfoil = setup_tinfoil(basepath=basepath) | 177 | recipe_outdir = srcdir |
156 | try: | 178 | if not os.path.exists(recipe_outdir) or not os.listdir(recipe_outdir): |
157 | try: | 179 | raise DevtoolError('No files to deploy - have you built the %s ' |
158 | rd = tinfoil.parse_recipe(args.recipename) | 180 | 'recipe? If so, the install step has not installed ' |
159 | except Exception as e: | 181 | 'any files.' % args.recipename) |
160 | raise DevtoolError('Exception parsing recipe %s: %s' % | 182 | |
161 | (args.recipename, e)) | 183 | if args.strip and not args.dry_run: |
162 | recipe_outdir = rd.getVar('D') | 184 | # Fakeroot copy to new destination |
163 | if not os.path.exists(recipe_outdir) or not os.listdir(recipe_outdir): | 185 | srcdir = recipe_outdir |
164 | raise DevtoolError('No files to deploy - have you built the %s ' | 186 | recipe_outdir = os.path.join(workdir, 'devtool-deploy-target-stripped') |
165 | 'recipe? If so, the install step has not installed ' | 187 | if os.path.isdir(recipe_outdir): |
166 | 'any files.' % args.recipename) | 188 | exec_fakeroot_no_d(fakerootcmd, fakerootenv, "rm -rf %s" % recipe_outdir, shell=True) |
167 | 189 | exec_fakeroot_no_d(fakerootcmd, fakerootenv, "cp -af %s %s" % (os.path.join(srcdir, '.'), recipe_outdir), shell=True) | |
168 | if args.strip and not args.dry_run: | 190 | os.environ['PATH'] = ':'.join([os.environ['PATH'], path or '']) |
169 | # Fakeroot copy to new destination | 191 | oe.package.strip_execs(args.recipename, recipe_outdir, strip_cmd, libdir, base_libdir, max_process) |
170 | srcdir = recipe_outdir | 192 | |
171 | recipe_outdir = os.path.join(rd.getVar('WORKDIR'), 'deploy-target-stripped') | 193 | filelist = [] |
172 | if os.path.isdir(recipe_outdir): | 194 | inodes = set({}) |
173 | bb.utils.remove(recipe_outdir, True) | 195 | ftotalsize = 0 |
174 | exec_fakeroot(rd, "cp -af %s %s" % (os.path.join(srcdir, '.'), recipe_outdir), shell=True) | 196 | for root, _, files in os.walk(recipe_outdir): |
175 | os.environ['PATH'] = ':'.join([os.environ['PATH'], rd.getVar('PATH') or '']) | 197 | for fn in files: |
176 | oe.package.strip_execs(args.recipename, recipe_outdir, rd.getVar('STRIP'), rd.getVar('libdir'), | 198 | fstat = os.lstat(os.path.join(root, fn)) |
177 | rd.getVar('base_libdir'), rd) | 199 | # Get the size in kiB (since we'll be comparing it to the output of du -k) |
178 | 200 | # MUST use lstat() here not stat() or getfilesize() since we don't want to | |
179 | filelist = [] | 201 | # dereference symlinks |
180 | inodes = set({}) | 202 | if fstat.st_ino in inodes: |
181 | ftotalsize = 0 | 203 | fsize = 0 |
182 | for root, _, files in os.walk(recipe_outdir): | 204 | else: |
183 | for fn in files: | 205 | fsize = int(math.ceil(float(fstat.st_size)/1024)) |
184 | fstat = os.lstat(os.path.join(root, fn)) | 206 | inodes.add(fstat.st_ino) |
185 | # Get the size in kiB (since we'll be comparing it to the output of du -k) | 207 | ftotalsize += fsize |
186 | # MUST use lstat() here not stat() or getfilesize() since we don't want to | 208 | # The path as it would appear on the target |
187 | # dereference symlinks | 209 | fpath = os.path.join(destdir, os.path.relpath(root, recipe_outdir), fn) |
188 | if fstat.st_ino in inodes: | 210 | filelist.append((fpath, fsize)) |
189 | fsize = 0 | 211 | |
190 | else: | 212 | if args.dry_run: |
191 | fsize = int(math.ceil(float(fstat.st_size)/1024)) | 213 | print('Files to be deployed for %s on target %s:' % (args.recipename, args.target)) |
192 | inodes.add(fstat.st_ino) | 214 | for item, _ in filelist: |
193 | ftotalsize += fsize | 215 | print(' %s' % item) |
194 | # The path as it would appear on the target | 216 | return 0 |
195 | fpath = os.path.join(destdir, os.path.relpath(root, recipe_outdir), fn) | ||
196 | filelist.append((fpath, fsize)) | ||
197 | |||
198 | if args.dry_run: | ||
199 | print('Files to be deployed for %s on target %s:' % (args.recipename, args.target)) | ||
200 | for item, _ in filelist: | ||
201 | print(' %s' % item) | ||
202 | return 0 | ||
203 | |||
204 | extraoptions = '' | ||
205 | if args.no_host_check: | ||
206 | extraoptions += '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' | ||
207 | if not args.show_status: | ||
208 | extraoptions += ' -q' | ||
209 | |||
210 | scp_sshexec = '' | ||
211 | ssh_sshexec = 'ssh' | ||
212 | if args.ssh_exec: | ||
213 | scp_sshexec = "-S %s" % args.ssh_exec | ||
214 | ssh_sshexec = args.ssh_exec | ||
215 | scp_port = '' | ||
216 | ssh_port = '' | ||
217 | if args.port: | ||
218 | scp_port = "-P %s" % args.port | ||
219 | ssh_port = "-p %s" % args.port | ||
220 | |||
221 | if args.key: | ||
222 | extraoptions += ' -i %s' % args.key | ||
223 | |||
224 | # In order to delete previously deployed files and have the manifest file on | ||
225 | # the target, we write out a shell script and then copy it to the target | ||
226 | # so we can then run it (piping tar output to it). | ||
227 | # (We cannot use scp here, because it doesn't preserve symlinks.) | ||
228 | tmpdir = tempfile.mkdtemp(prefix='devtool') | ||
229 | try: | ||
230 | tmpscript = '/tmp/devtool_deploy.sh' | ||
231 | tmpfilelist = os.path.join(os.path.dirname(tmpscript), 'devtool_deploy.list') | ||
232 | shellscript = _prepare_remote_script(deploy=True, | ||
233 | verbose=args.show_status, | ||
234 | nopreserve=args.no_preserve, | ||
235 | nocheckspace=args.no_check_space) | ||
236 | # Write out the script to a file | ||
237 | with open(os.path.join(tmpdir, os.path.basename(tmpscript)), 'w') as f: | ||
238 | f.write(shellscript) | ||
239 | # Write out the file list | ||
240 | with open(os.path.join(tmpdir, os.path.basename(tmpfilelist)), 'w') as f: | ||
241 | f.write('%d\n' % ftotalsize) | ||
242 | for fpath, fsize in filelist: | ||
243 | f.write('%s %d\n' % (fpath, fsize)) | ||
244 | # Copy them to the target | ||
245 | ret = subprocess.call("scp %s %s %s %s/* %s:%s" % (scp_sshexec, scp_port, extraoptions, tmpdir, args.target, os.path.dirname(tmpscript)), shell=True) | ||
246 | if ret != 0: | ||
247 | raise DevtoolError('Failed to copy script to %s - rerun with -s to ' | ||
248 | 'get a complete error message' % args.target) | ||
249 | finally: | ||
250 | shutil.rmtree(tmpdir) | ||
251 | 217 | ||
252 | # Now run the script | 218 | extraoptions = '' |
253 | ret = exec_fakeroot(rd, 'tar cf - . | %s %s %s %s \'sh %s %s %s %s\'' % (ssh_sshexec, ssh_port, extraoptions, args.target, tmpscript, args.recipename, destdir, tmpfilelist), cwd=recipe_outdir, shell=True) | 219 | if args.no_host_check: |
254 | if ret != 0: | 220 | extraoptions += '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' |
255 | raise DevtoolError('Deploy failed - rerun with -s to get a complete ' | 221 | if not args.show_status: |
256 | 'error message') | 222 | extraoptions += ' -q' |
257 | 223 | ||
258 | logger.info('Successfully deployed %s' % recipe_outdir) | 224 | scp_sshexec = '' |
225 | ssh_sshexec = 'ssh' | ||
226 | if args.ssh_exec: | ||
227 | scp_sshexec = "-S %s" % args.ssh_exec | ||
228 | ssh_sshexec = args.ssh_exec | ||
229 | scp_port = '' | ||
230 | ssh_port = '' | ||
231 | if args.port: | ||
232 | scp_port = "-P %s" % args.port | ||
233 | ssh_port = "-p %s" % args.port | ||
234 | |||
235 | if args.key: | ||
236 | extraoptions += ' -i %s' % args.key | ||
259 | 237 | ||
260 | files_list = [] | 238 | # In order to delete previously deployed files and have the manifest file on |
261 | for root, _, files in os.walk(recipe_outdir): | 239 | # the target, we write out a shell script and then copy it to the target |
262 | for filename in files: | 240 | # so we can then run it (piping tar output to it). |
263 | filename = os.path.relpath(os.path.join(root, filename), recipe_outdir) | 241 | # (We cannot use scp here, because it doesn't preserve symlinks.) |
264 | files_list.append(os.path.join(destdir, filename)) | 242 | tmpdir = tempfile.mkdtemp(prefix='devtool') |
243 | try: | ||
244 | tmpscript = '/tmp/devtool_deploy.sh' | ||
245 | tmpfilelist = os.path.join(os.path.dirname(tmpscript), 'devtool_deploy.list') | ||
246 | shellscript = _prepare_remote_script(deploy=True, | ||
247 | verbose=args.show_status, | ||
248 | nopreserve=args.no_preserve, | ||
249 | nocheckspace=args.no_check_space) | ||
250 | # Write out the script to a file | ||
251 | with open(os.path.join(tmpdir, os.path.basename(tmpscript)), 'w') as f: | ||
252 | f.write(shellscript) | ||
253 | # Write out the file list | ||
254 | with open(os.path.join(tmpdir, os.path.basename(tmpfilelist)), 'w') as f: | ||
255 | f.write('%d\n' % ftotalsize) | ||
256 | for fpath, fsize in filelist: | ||
257 | f.write('%s %d\n' % (fpath, fsize)) | ||
258 | # Copy them to the target | ||
259 | ret = subprocess.call("scp %s %s %s %s/* %s:%s" % (scp_sshexec, scp_port, extraoptions, tmpdir, args.target, os.path.dirname(tmpscript)), shell=True) | ||
260 | if ret != 0: | ||
261 | raise DevtoolError('Failed to copy script to %s - rerun with -s to ' | ||
262 | 'get a complete error message' % args.target) | ||
265 | finally: | 263 | finally: |
266 | tinfoil.shutdown() | 264 | shutil.rmtree(tmpdir) |
265 | |||
266 | # Now run the script | ||
267 | ret = exec_fakeroot_no_d(fakerootcmd, fakerootenv, 'tar cf - . | %s %s %s %s \'sh %s %s %s %s\'' % (ssh_sshexec, ssh_port, extraoptions, args.target, tmpscript, args.recipename, destdir, tmpfilelist), cwd=recipe_outdir, shell=True) | ||
268 | if ret != 0: | ||
269 | raise DevtoolError('Deploy failed - rerun with -s to get a complete ' | ||
270 | 'error message') | ||
271 | |||
272 | logger.info('Successfully deployed %s' % recipe_outdir) | ||
273 | |||
274 | files_list = [] | ||
275 | for root, _, files in os.walk(recipe_outdir): | ||
276 | for filename in files: | ||
277 | filename = os.path.relpath(os.path.join(root, filename), recipe_outdir) | ||
278 | files_list.append(os.path.join(destdir, filename)) | ||
267 | 279 | ||
268 | return 0 | 280 | return 0 |
269 | 281 | ||