예제 #1
0
파일: csharp.py 프로젝트: xpybuild/xpybuild
    def run(self, context):
        libs = self.libs.resolve(context)
        libnames = [os.path.basename(x) for x in libs]
        libpaths = [os.path.dirname(x) for x in 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'])
예제 #2
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 as 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'])
        except BuildException as e:
            # causedBy is not useful here
            raise BuildException("%s process failed" %
                                 (os.path.basename(args[0])),
                                 causedBy=True)
예제 #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'])
예제 #4
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'])
예제 #5
0
def javadoc(path, sources, classpath, options, workDir, 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 workDir: where temporary files are stored
	
	@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(workDir)
	inputlistfile = os.path.join(workDir, "javadoc.inputs")
	with openForWrite(inputlistfile, 'w', encoding=locale.getpreferredencoding()) as f:
		f.writelines('"'+x.replace('\\','\\\\')+'"'+'\n' for x in 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'])
예제 #6
0
파일: docker.py 프로젝트: xpybuild/xpybuild
    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)])

        # Allow warning/info logs but do not let failure of RMI cleanup break the build
        rmiOptions = dict(self.options)
        rmiOptions[ProcessOutputHandler.Options.ignoreReturnCode] = True
        rmiOptions[
            ProcessOutputHandler.Options.downgradeErrorsToWarnings] = True

        call(args,
             outputHandler=self.getOption('docker.outputHandlerFactory')(
                 'docker-rmi', treatStdErrAsErrors=False, options=rmiOptions),
             timeout=self.getOption('process.timeout'),
             env=environs)
예제 #7
0
파일: docker.py 프로젝트: xpybuild/xpybuild
    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),
        ])
        dargs.extend(self.getOption('docker.buildoptions'))
        if self.dockerArgs: dargs.extend(self.dockerArgs)
        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.outputHandlerFactory')(
                 'docker-build',
                 treatStdErrAsErrors=False,
                 options=self.options),
             timeout=self.getOption('process.timeout'),
             env=environs,
             cwd=cwd)

        # update the stamp file
        self.updateStampFile()
예제 #8
0
파일: docker.py 프로젝트: xpybuild/xpybuild
    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.outputHandlerFactory')(
                 'docker-tag', treatStdErrAsErrors=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.outputHandlerFactory')(
                 'docker-push',
                 treatStdErrAsErrors=False,
                 options=self.options),
             timeout=self.getOption('process.timeout'),
             env=environs)

        # update the stamp file
        self.updateStampFile()
예제 #9
0
def javac(output, inputs, classpath, options, logbasename, targetname, workDir):
	""" 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
	
	@param workDir: where temporary files are stored.  

	"""

	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(workDir)
	
	argsfile = os.path.join(workDir, "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(["-target", 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, 'w', encoding=locale.getpreferredencoding()) as f:
		for a in args:
			f.write('"%s"'%a.replace('\\','\\\\')+'\n')

	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 = options.get('javac.outputHandlerFactory', JavacProcessOutputHandler)(targetname, options=options)
		if hasattr(outputHandler, 'setJavacLogBasename'):
			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)))