1 # Copyright (C) 2007, Thomas Leonard
2 # See http://0install.net/0compile.html
7 from zeroinstall
import SafeException
8 from zeroinstall
.zerostore
import manifest
10 from support
import BuildEnv
, ensure_dir
, lookup
12 def do_include_deps(args
):
16 depdir
= os
.path
.realpath('dependencies')
21 sels
= buildenv
.get_selections()
22 for needed_iface
in sels
.selections
:
23 impl
= buildenv
.chosen_impl(needed_iface
)
25 if impl
.id.startswith('/'):
26 raise SafeException("Can't export '%s' as it's a local implementation (not supported yet; sorry)" % impl
)
27 if not impl
.id.startswith('package:'):
28 dirs_to_copy
.append(lookup(impl
))
31 for cached
in dirs_to_copy
:
32 required_digest
= os
.path
.basename(cached
)
33 target_impl_dir
= os
.path
.join(depdir
, required_digest
)
34 if not os
.path
.isdir(target_impl_dir
):
35 if required_digest
.startswith('sha1='):
36 shutil
.copytree(cached
, target_impl_dir
)
38 manifest_data
= file(os
.path
.join(cached
, '.manifest')).read()
39 manifest
.copy_tree_with_verify(cached
, depdir
, manifest_data
, required_digest
)
42 print "Copied %d dependencies to %s (%d already there)" % (copied
, depdir
, len(dirs_to_copy
) - copied
)
44 __main__
.commands
.append(do_include_deps
)