1 # Copyright (C) 2009, Thomas Leonard
2 # See the README file for details, or visit http://0install.net.
7 from logging
import info
9 from zeroinstall
.injector
import reader
, iface_cache
, model
10 from zeroinstall
.injector
.policy
import Policy
12 XMLNS_0COMPILE
= 'http://zero-install.sourceforge.net/2006/namespaces/0compile'
19 def run(self
, command
, success
):
20 assert self
.child
is None
21 self
.success
= success
22 self
.child
= subprocess
.Popen(command
,
23 stdout
= subprocess
.PIPE
,
24 stderr
= subprocess
.STDOUT
)
25 gobject
.io_add_watch(self
.child
.stdout
, gobject
.IO_IN | gobject
.IO_HUP
, self
.got_data
)
27 def got_data(self
, src
, cond
):
28 data
= os
.read(src
.fileno(), 100)
33 status
= self
.child
.wait()
36 if os
.WIFEXITED(status
) and os
.WEXITSTATUS(status
) == 0:
39 if os
.WIFEXITED(status
):
40 status
= os
.WEXITSTATUS(status
)
41 if status
== 1 and not self
.error
:
42 return False # Cancelled
43 dialog
.alert(None, "Command failed with exit code %d:\n%s\n" %
46 dialog
.alert(None, "Command failed:\n%s\n" % self
.error
)
49 def compile(policy
, interface
):
51 # A new local feed may have been registered, so update the interface from the cache
52 info("0compile command completed successfully. Reloading interface details.")
53 reader
.update_from_cache(interface
)
57 # Get the chosen versions
58 src_policy
= Policy(interface
.uri
, src
= True)
59 src_policy
.freshness
= 0
61 src_policy
.recalculate()
62 if not src_policy
.ready
:
63 raise Exception('Internal error: required source components not found!')
65 root_iface
= iface_cache
.iface_cache
.get_interface(src_policy
.root
)
66 impl
= src_policy
.implementation
[root_iface
]
67 min_version
= impl
.metadata
.get(XMLNS_0COMPILE
+ ' min-version', None)
68 if not min_version
: min_version
= '0.4'
69 # Check the syntax is valid and the version is high enough
70 if model
.parse_version(min_version
) < model
.parse_version('0.4'):
73 # Do the whole build-and-register-feed
76 '--message', 'Download the 0compile tool, to compile the source code',
77 '--not-before=' + min_version
,
78 "http://0install.net/2006/interfaces/0compile.xml",
81 interface
.uri
), add_feed
)
83 # Prompt user to choose source version
86 '--message', 'Download the source code to be compiled',
87 '--gui', '--source', '--download-only', interface
.uri
], build
)