Beispiel #1
0
    def call(self,
             context,
             args,
             outputHandler,
             options,
             cwd=None,
             environs=None):
        try:
            args = flatten([
                context.expandPropertyValues(x, expandList=True) for x in args
            ])

            try:
                outputHandlerInstance = outputHandler(os.path.basename(
                    args[0]),
                                                      options=options)
            except Exception, e:
                # backwards compatibility for output handlers that don't pass kwargs down
                outputHandlerInstance = outputHandler(os.path.basename(
                    args[0]))

            call(args,
                 outputHandler=outputHandlerInstance,
                 cwd=cwd,
                 env=self.getExpandedEnvirons(context, environs),
                 timeout=options['process.timeout'])
Beispiel #2
0
	def clean(self, context):
		BaseTarget.clean(self, context)
		options = context.mergeOptions(self)
		args = [ options['docker.path'] ]
		environs = { 'DOCKER_HOST' : options['docker.host'] } if options['docker.host'] else {}
		args.extend(['rmi', context.expandPropertyValues(self.imagename)])
		call(args, outputHandler=options['docker.processoutputhandler']('docker-rmi', False, options=options), timeout=options['process.timeout'], env=environs)
Beispiel #3
0
def signjar(path, keystore, options, alias=None, storepass=None, outputHandler=None):
	""" Signs an existing jar.

	@param path: Jar file to sign

	@param keystore: The keystore with which to sign it

	@param options: The current set of options to be used

	@param alias: An alias for the key (optional)

	@param storepass: The password for the keystore (optional)

	@param outputHandler: the output handler (optional)
	"""
	if options['java.home']:
		binary = os.path.join(options['java.home'], "bin/jarsigner")
	else:
		binary = "jarsigner"

	args = [binary]
	args.extend(options['jarsigner.options'])
	args.extend(['-keystore', keystore])
	if storepass: args.extend(['-storepass', storepass])
	args.append(path)
	if alias: args.append(alias)

	call(args, outputHandler=outputHandler, timeout=options['process.timeout'])
Beispiel #4
0
    def run(self, context):
        libs = self.libs.resolve(context)
        libnames = map(lambda x: os.path.basename(x), libs)
        libpaths = map(lambda x: os.path.dirname(x), libs)
        flags = [context.expandPropertyValues(x) for x in self.flags]

        args = [self.getOption('csharp.compiler'), "-out:" + self.path]
        if libnames:
            args.extend([
                "-reference:" + ",".join(libnames),
                "-lib:" + ",".join(libpaths)
            ])
        if self.main:
            args.extend(["-target:exe", "-main:" + self.main])
        else:
            args.append("-target:library")
        for (file, id) in self.resources:
            args.append('-resource:%s,%s' %
                        (context.expandPropertyValues(file),
                         context.expandPropertyValues(id)))
        args.extend(self.options['csharp.options'])
        args.extend(flags)
        args.extend(self.compile.resolve(context))

        mkdir(os.path.dirname(self.path))
        call(args,
             outputHandler=self.getOption('csharp.outputHandlerFactory')(
                 'csc', False, options=self.options),
             timeout=self.options['process.timeout'])
Beispiel #5
0
def jar(path,
        manifest,
        sourcedir,
        options,
        preserveManifestFormatting=False,
        update=False,
        outputHandler=None):
    """ Create a jar file containing a manifest and some other files

	@param path: jar file to create. Typically this file does not already exist, but if it does 
	then the specified files or manifest will be merged into it. 
	
	@param manifest: path to the manifest.mf file (or None to disable manifest entirely)

	@param sourcedir: the directory to pack everything from (this method may add extra files to this dir)

	@param options: options map. jar.options is a list of additional arguments

	@param preserveManifestFormatting: an advanced option that prevents that jar executable from 
	reformatting the specified manifest file to comply with Java conventions 
	(also prevents manifest merging if jar already exists)
	"""
    # work out if we need to create a parent directory
    dir = os.path.dirname(path)
    if dir and not os.path.exists(dir): mkdir(dir)
    # location of jar
    if options['java.home']:
        binary = os.path.join(options['java.home'], "bin/jar")
    else:
        binary = "jar"
    # build up arguments
    args = [binary]
    args.extend(options['jar.options'])

    if update:
        mode = '-u'
    else:
        mode = '-c'

    if not manifest:
        args.extend([mode + "fM", path])
    elif preserveManifestFormatting:
        mkdir(sourcedir + '/META-INF')
        srcf = normLongPath(sourcedir + '/META-INF/manifest.mf')

        with open(manifest, 'rb') as s:
            with openForWrite(srcf, 'wb') as d:
                d.write(s.read())
        args.extend([mode + "f", path])
    else:
        args.extend([mode + "fm", path, manifest])

    if sourcedir:
        args.extend(["-C", sourcedir, "."])

    # actually call jar
    call(args, outputHandler=outputHandler, timeout=options['process.timeout'])
Beispiel #6
0
 def blame(self, ref, path, lineno=None):
     if lineno:
         result = call(self.repository,
                       'blame -L %s,%s --porcelain %s -- %s' % (
                           lineno, lineno, ref, path))
     else:
         result = call(self.repository,
                       'blame -p -CM %s -- %s' % (ref, path))
     result = format_blame(result['stdout'], self.repository)
     return self.show(ref), result
Beispiel #7
0
	def clean(self, context):
		BaseTarget.clean(self, context)
		args = [ self.getOption('docker.path') ]
		environs = { 'DOCKER_HOST' : self.getOption('docker.host') } if self.getOption('docker.host') else {}
		args.extend(['rmi', context.expandPropertyValues(self.imagename)])
		try:
			call(args, outputHandler=self.getOption('docker.processoutputhandler')('docker-rmi', False, options=self.options), timeout=self.getOption('process.timeout'), env=environs)
		except Exception as e:
			logger = logging.getLogger('DockerBase')
			logger.info('Exception cleaning Docker target: %s' % e)
Beispiel #8
0
	def call(self, context, args, outputHandler, options, cwd=None, environs=None):
		try:
			args = flatten([context.expandPropertyValues(x, expandList=True) for x in args])
			
			try:
				outputHandlerInstance=outputHandler(os.path.basename(args[0]), options=options)
			except Exception, e:
				# backwards compatibility for output handlers that don't pass kwargs down
				outputHandlerInstance = outputHandler(os.path.basename(args[0]))
			
			call(args, outputHandler=outputHandlerInstance, cwd=cwd, env=self.getExpandedEnvirons(context, environs), timeout=options['process.timeout'])
Beispiel #9
0
def jar(path, manifest, sourcedir, options, preserveManifestFormatting=False, update=False, outputHandler=None):
	""" Create a jar file containing a manifest and some other files

	@param path: jar file to create. Typically this file does not already exist, but if it does 
	then the specified files or manifest will be merged into it. 
	
	@param manifest: path to the manifest.mf file (or None to disable manifest entirely)

	@param sourcedir: the directory to pack everything from (this method may add extra files to this dir)

	@param options: options map. jar.options is a list of additional arguments

	@param preserveManifestFormatting: an advanced option that prevents that jar executable from 
	reformatting the specified manifest file to comply with Java conventions 
	(also prevents manifest merging if jar already exists)
	"""
	# work out if we need to create a parent directory
	dir = os.path.dirname(path)
	if dir and not os.path.exists(dir): mkdir(dir)
	# location of jar
	if options['java.home']:
		binary = os.path.join(options['java.home'], "bin/jar")
	else:
		binary = "jar"
	# build up arguments
	args = [binary]
	args.extend(options['jar.options'])

	if update:
		mode='-u'
	else:
		mode='-c'
	
	if not manifest: 
		args.extend([mode+"fM", path])
	elif preserveManifestFormatting:
		mkdir(sourcedir+'/META-INF')
		srcf = normLongPath(sourcedir+'/META-INF/manifest.mf')

		with open(manifest, 'rb') as s:
			with openForWrite(srcf, 'wb') as d:
				d.write(s.read())
		args.extend([mode+"f", path])
	else:
		args.extend([mode+"fm", path, manifest])

	if sourcedir: 
		args.extend(["-C", sourcedir, "."])


	# actually call jar
	call(args, outputHandler=outputHandler, timeout=options['process.timeout'])
Beispiel #10
0
	def run(self, context):
		args = [ self.getOption('docker.path') ]
		environs = { 'DOCKER_HOST' : self.getOption('docker.host') } if self.getOption('docker.host') else {}

		dargs = list(args)
		dargs.extend([
				'build', '--rm=true', '-t', context.expandPropertyValues(self.imagename),
			])
		if self.buildArgs: dargs.extend(["--build-arg=%s" % context.expandPropertyValues(x) for x in self.buildArgs])
		if self.dockerfile: dargs.extend(["-f", context.expandPropertyValues(self.dockerfile)])
		inputs = self.inputs.resolve(context)
		if len(inputs) != 1: raise BuildException("Must specify a single input for Docker.BUILD", location = self.location)
		dargs.append(inputs[0])
		cwd = os.path.dirname(inputs[0])
		call(dargs, outputHandler=self.getOption('docker.processoutputhandler')('docker-build', False, options=self.options), timeout=self.getOption('process.timeout'), env=environs, cwd=cwd)
	
		# update the stamp file
		self.updateStampFile()
Beispiel #11
0
	def run(self, context):
		args = [ self.getOption('docker.path') ]
		environs = { 'DOCKER_HOST' : self.getOption('docker.host') } if self.getOption('docker.host') else {}

		inputs = self.inputs.resolve(context)
		if len(inputs) != 0: raise BuildException("Must not specify inputs for Docker.PUSHTAG", location = self.location)
		dargs = list(args)
		dargs.extend([
				'tag', context.expandPropertyValues(self.depimage), context.expandPropertyValues(self.imagename),
			])
		call(dargs, outputHandler=self.getOption('docker.processoutputhandler')('docker-tag', False, options=self.options), timeout=self.getOption('process.timeout'), env=environs)
		dargs = list(args)
		dargs.extend([
				'push', context.expandPropertyValues(self.imagename),
			])
		call(dargs, outputHandler=self.getOption('docker.processoutputhandler')('docker-push', False, options=self.options), timeout=self.getOption('process.timeout'), env=environs)
		
		# update the stamp file
		self.updateStampFile()
Beispiel #12
0
def javadoc(path, sources, classpath, options, outputHandler):
    """ Create javadoc from sources and a set of options

	@param path: The directory under which to create the javadoc

	@param sources: a list of source files

	@param classpath: a list of jars for the classpath

	@param options: the current set of options to use

	@param outputHandler: the output handler (optional)
	"""
    deleteDir(path)
    mkdir(path)
    # location of javadoc
    if options['java.home']:
        binary = os.path.join(options['java.home'], "bin/javadoc")
    else:
        binary = "javadoc"

    # store the list of files in a temporary file, then build from that.
    mkdir(options['tmpdir'])
    inputlistfile = os.path.join(options['tmpdir'], "javadoc.inputs")
    with openForWrite(inputlistfile, 'wb') as f:
        f.writelines(
            map(lambda x: '"' + x.replace('\\', '\\\\') + '"' + os.linesep,
                sources))

    # build up arguments
    args = [binary]
    args.extend(options['javadoc.options'])
    if options['javadoc.ignoreSourceFilesFromClasspath']:
        args.extend(['-sourcepath', path + '/xpybuild_fake_sourcepath'])
    args.extend([
        "-d", path, "-classpath", classpath, "-windowtitle",
        options['javadoc.title'], "-doctitle", options['javadoc.title'],
        "-%s" % options['javadoc.access'],
        "@%s" % inputlistfile
    ])
    # actually call javadoc
    call(args, outputHandler=outputHandler, timeout=options['process.timeout'])
Beispiel #13
0
	def run(self, context):
		options = context.mergeOptions(self) # get the merged options
		libs = self.libs.resolve(context)
		libnames = map(lambda x:os.path.basename(x), libs)
		libpaths = map(lambda x:os.path.dirname(x), libs)
		flags = [context.expandPropertyValues(x) for x in self.flags]

		args = [options['csharp.compiler'], "-out:"+self.path]
		if libnames: args.extend(["-reference:"+",".join(libnames), "-lib:"+",".join(libpaths)])
		if self.main:
			args.extend(["-target:exe", "-main:"+self.main])
		else:
			args.append("-target:library")
		for (file, id) in self.resources:
			args.append('-resource:%s,%s' % (context.expandPropertyValues(file), context.expandPropertyValues(id)))
		args.extend(options['csharp.options'])
		args.extend(flags)
		args.extend(self.compile.resolve(context))

		mkdir(os.path.dirname(self.path))
		call(args, outputHandler=options['csharp.processoutputhandler']('csc', False, options=options), timeout=options['process.timeout'])
Beispiel #14
0
 def merge(self, ref, msg='automerge', commit_msg='', no_ff=False, _raise=True, _env=None):
     cmd = ['merge', ref]
     if msg:
         cmd.append('-m')
         cmd.append(msg)
     if commit_msg:
         cmd.append('-m')
         cmd.append(commit_msg)
     if no_ff:
         cmd.append('--no-ff')
     errcode = call(self.repository, cmd, env=_env)
     return errcode
Beispiel #15
0
def javadoc(path, sources, classpath, options, outputHandler):
	""" Create javadoc from sources and a set of options

	@param path: The directory under which to create the javadoc

	@param sources: a list of source files

	@param classpath: a list of jars for the classpath

	@param options: the current set of options to use

	@param outputHandler: the output handler (optional)
	"""
	deleteDir(path)
	mkdir(path)
	# location of javadoc
	if options['java.home']:
		binary = os.path.join(options['java.home'], "bin/javadoc")
	else:
		binary = "javadoc"

	# store the list of files in a temporary file, then build from that.
	mkdir(options['tmpdir'])
	inputlistfile = os.path.join(options['tmpdir'], "javadoc.inputs")
	with openForWrite(inputlistfile, 'wb') as f:
		f.writelines(map(lambda x: '"'+x.replace('\\','\\\\')+'"'+os.linesep, sources))

	# build up arguments
	args = [binary]
	args.extend(options['javadoc.options'])
	args.extend([
		"-d", path,
		"-classpath", classpath,
		"-windowtitle", options['javadoc.title'],
		"-doctitle", options['javadoc.title'],
		"-%s" % options['javadoc.access'],
		"@%s" % inputlistfile
	])
	# actually call javadoc
	call(args, outputHandler=outputHandler, timeout=options['process.timeout'])
Beispiel #16
0
	def run(self, context):
		options = context.mergeOptions(self)
		args = [ options['docker.path'] ]
		environs = { 'DOCKER_HOST' : options['docker.host'] } if options['docker.host'] else {}
		if self.mode == Docker.BUILD:
			dargs = list(args)
			dargs.extend([
					'build', '--rm=true', '-t', context.expandPropertyValues(self.imagename),
				])
			if self.buildArgs: dargs.extend(["--build-arg=%s" % [context.expandPropertyValues(x) for x in self.buildArgs]])
			if self.dockerfile: dargs.extend(["-f", context.expandPropertyValues(self.dockerfile)])
			inputs = self.inputs.resolve(context)
			if len(inputs) != 1: raise BuildException("Must specify a single input for Docker.BUILD", location = self.location)
			dargs.append(inputs[0])
			cwd = os.path.dirname(inputs[0])
			call(dargs, outputHandler=options['docker.processoutputhandler']('docker-build', False, options=options), timeout=options['process.timeout'], env=environs, cwd=cwd)
		elif self.mode == Docker.PUSHTAG:
			inputs = self.inputs.resolve(context)
			if len(inputs) != 0: raise BuildException("Must not specify inputs for Docker.PUSHTAG", location = self.location)
			dargs = list(args)
			dargs.extend([
					'tag', context.expandPropertyValues(self.depimage), context.expandPropertyValues(self.imagename),
				])
			call(dargs, outputHandler=options['docker.processoutputhandler']('docker-tag', False, options=options), timeout=options['process.timeout'], env=environs)
			dargs = list(args)
			dargs.extend([
					'push', context.expandPropertyValues(self.imagename),
				])
			call(dargs, outputHandler=options['docker.processoutputhandler']('docker-push', False, options=options), timeout=options['process.timeout'], env=environs)
		else:
			raise BuildException('Unknown Docker mode. Must be Docker.BUILD or Docker.PUSHTAG', location = self.location)
		
		# update the stamp file
		path = normLongPath(self.path)
		mkdir(os.path.dirname(path))
		with openForWrite(path, 'wb') as f:
			pass
Beispiel #17
0
 def push(self, remote, ref):
     cmd = ['push', remote, ref]
     errcode = call(self.repository, cmd)
     return errcode
Beispiel #18
0
 def format_patch(self, ref, from_ref=None):
     if from_ref:
         result = call(self.repository, 'format-patch --stdout %s...%s' % (from_ref, ref))
     else:
         result = call(self.repository, 'format-patch -1 --stdout %s' % ref)
     return result['stdout']
Beispiel #19
0
def update_server_info(repository):
    return call(repository, 'update-server-info')
Beispiel #20
0
def javac(output, inputs, classpath, options, logbasename, targetname):
	""" Compile some java files to class files.

	Will raise BuildException if compilation fails.

	@param output: path to a directory in which to put the class files (will be created)

	@param inputs: list of paths (.java files) to be compiled

	@param classpath: classpath to compile with, as a string

	@param options: options map. javac.options is a list of additional arguments, javac.source is the source version, 
	javac.target is the target version

	@param logbasename: absolute, expanded, path to a directory and filename prefix 
		to use for files such as .err, .out, etc files

	@param targetname: to log appropriate error messages

	"""

	assert logbasename and '$' not in logbasename
	logbasename = os.path.normpath(logbasename)
	# make the output directory
	if not os.path.exists(output): mkdir(output)
	# location of javac
	if options['java.home']:
		javacpath = os.path.join(options['java.home'], "bin/javac")
	else:
		javacpath = "javac" # just get it from the path
	# store the list of files in a temporary file, then build from that.
	mkdir(options['tmpdir'])
	
	argsfile = os.path.join(options['tmpdir'], "javac_args.txt")
	
	# build up the arguments
	args = ["-d", output]
	if options["javac.source"]: args.extend(["-source", options["javac.source"]])
	if options["javac.target"]: args.extend(["-source", options["javac.target"]])
	if options["javac.encoding"]: args.extend(["-encoding", options["javac.encoding"]])
	if options["javac.debug"]:
		args.append('-g')
	if options['javac.warningsAsErrors']:
		args.append('-Werror')
	# TODO: should add -Xlint options here I think
		
	args.extend(getStringList(options['javac.options']))
	if classpath: args.extend(['-cp', classpath])
	args.extend([x for x in inputs if x.endswith('.java')]) # automatically filter out non-java files

	with openForWrite(argsfile, 'wb') as f:
		for a in args:
			a = '"%s"'%a.replace('\\','\\\\')
			print >>f, a

	success=False
	try:

		log.info('Executing javac for %s, writing output to %s: %s', targetname, logbasename+'.out', ''.join(['\n\t"%s"'%x for x in [javacpath]+args]))
		
		# make sure we have no old ones hanging around still
		try:
			deleteFile(logbasename+'-errors.txt', allowRetry=True)
			deleteFile(logbasename+'-warnings.txt', allowRetry=True)
			deleteFile(logbasename+'.out', allowRetry=True)
		except Exception as e:
			log.info('Cleaning up file failed: %s' % e)
		
		outputHandler = JavacProcessOutputHandler(targetname, options=options)
		outputHandler.setJavacLogBasename(logbasename)
		
		call([javacpath, "@%s" % argsfile], outputHandler=outputHandler, outputEncoding='UTF-8', cwd=output, timeout=options['process.timeout'])
		
		if (not os.listdir(output)): # unlikely, but useful failsafe
			raise EnvironmentError('javac command failed to create any target files (but returned no error code); see output at "%s"'%(logbasename+'.out'))
		success = True
	finally:
		if not success and classpath:
			log.info('Classpath for failed javac was: \n   %s', '\n   '.join(classpath.split(os.pathsep)))