+ def mount(self, m):
+ pass
+
+ @property
+ def ccache(self):
+ return self._ccache
+
+ @ccache.setter
+ def ccache(self, v):
+ self._ccache = v
+
+
+class DockerTarget(Target):
+ def __init__(self, platform, directory):
+ super(DockerTarget, self).__init__(platform, directory)
+ self.mounts = []
+ self.privileged = False
+
+ def _user_tag(self):
+ if config.get('docker_no_user'):
+ return ''
+ return '-u %s' % getpass.getuser()
+
+ def _mount_option(self, d):
+ return '-v %s:%s ' % (os.path.realpath(d), os.path.realpath(d))
+
+ def setup(self):
+ opts = self._mount_option(self.directory)
+ for m in self.mounts:
+ opts += self._mount_option(m)
+ if config.has('git_reference'):
+ opts += self._mount_option(config.get('git_reference'))
+ if self.privileged:
+ opts += '--privileged=true '
+ if self.ccache:
+ opts += "-e CCACHE_DIR=/ccache/%s-%d --mount source=ccache,target=/ccache" % (self.image, os.getuid())
+
+ tag = self.image
+ if config.has('docker_hub_repository'):
+ tag = '%s:%s' % (config.get('docker_hub_repository'), tag)
+
+ self.container = command_and_read('%s run %s %s -itd %s /bin/bash' % (config.docker(), self._user_tag(), opts, tag))[0].strip()
+
+ def command(self, cmd):
+ dir = os.path.join(self.directory, os.path.relpath(os.getcwd(), self.directory))
+ interactive_flag = '-i ' if sys.stdin.isatty() else ''
+ command('%s exec %s %s -t %s /bin/bash -c \'export %s; cd %s; %s\'' % (config.docker(), self._user_tag(), interactive_flag, self.container, self.variables_string(), dir, cmd))
+
+ def cleanup(self):
+ super(DockerTarget, self).cleanup()
+ command('%s kill %s' % (config.docker(), self.container))
+
+ def mount(self, m):
+ self.mounts.append(m)