コード例 #1
0
ファイル: csharp.py プロジェクト: ramanawithu/xpybuild
    def __init__(self,
                 output,
                 compile,
                 main=None,
                 libs=None,
                 flags=None,
                 dependencies=None,
                 resources=None):
        """ 
		@param output: the resulting .exe or .dll
		
		@param compile: the input PathSet, path or list of .cs file(s)
		
		@param main: The main class to execute if an exe is to be built.
		If this is set then an executable will be created.
		Otherwise this target will build a library.

		@param libs: a list of input libraries (or a PathSet)
		"""
        self.compile = FilteredPathSet(_isDotNetFile, PathSet(compile))
        self.main = main
        self.flags = flags or []
        self.libs = PathSet(libs or [])
        self.resources = resources or []
        BaseTarget.__init__(self, output, [
            self.compile, self.libs, [x for (x, y) in self.resources],
            dependencies or []
        ])
        self.tags('c#')
コード例 #2
0
    def __init__(self,
                 jar,
                 compile,
                 classpath,
                 manifest,
                 options=None,
                 package=None,
                 preserveManifestFormatting=False):
        """ 
		To add additional entries to the manifest's classpath which are needed at runtime 
		but not during compilation, use .option('jar.manifest.classpathAppend', [...])
		
		@param jar: path to jar to create

		@param compile: PathSet (or list)  of things to compile

		@param classpath: PathSet (or list) of things to be on the classpath; 
		destination mapping indicates how they will appear in the manifest

		@param manifest: map of manifest entries, OR a string with the filename to use 
		OR None to disable manifest generation and just produce a normal zip

		@param options: [DEPRECATED - use .option() instead]

		@param package: PathSet (or list) of other files to include in the jar; 
			destination mapping indicates where they will appear in the jar
		
		@param preserveManifestFormatting: an advanced option that prevents the jar tool from 
			reformatting the specified manifest file to comply with Java conventions 
			(also prevents manifest merging if jar already exists)

		
		"""
        self.compile = FilteredPathSet(_isJavaFile,
                                       PathSet(compile)) if compile else None

        self.classpath = PathSet(classpath)

        self.package = PathSet(package)
        self.manifest = manifest
        BaseTarget.__init__(self, jar, [
            self.compile, self.classpath, self.package,
            manifest if isinstance(manifest, basestring) else None
        ])

        for k, v in (options or {}).items():
            self.option(k, v)
        self.preserveManifestFormatting = preserveManifestFormatting
コード例 #3
0
ファイル: java.py プロジェクト: CaribouJohn/xpybuild
	def __init__(self, jar, compile, classpath, manifest, options=None, package=None, preserveManifestFormatting=False):
		""" 
		@param jar: path to jar to create

		@param compile: PathSet (or list)  of things to compile

		@param classpath: PathSet (or list) of things to be on the classpath; 
		destination mapping indicates how they will appear in the manifest

		@param manifest: map of manifest entries, OR a string with the filename to use 
		OR None to disable manifest generation and just produce a normal zip

		@param options: generic target options map

		@param package: PathSet (or list) of other files to include in the jar; 
			destination mapping indicates where they will appear in the jar
		
		@param preserveManifestFormatting: an advanced option that prevents the jar tool from 
			reformatting the specified manifest file to comply with Java conventions 
			(also prevents manifest merging if jar already exists)

		
		"""
		self.compile = FilteredPathSet(_isJavaFile, PathSet(compile)) if compile else None
			
		self.classpath = PathSet(classpath)
		
		self.package = PathSet(package)
		self.manifest = manifest
		BaseTarget.__init__(self, jar, [self.compile,self.classpath,self.package, 
			manifest if isinstance(manifest, basestring) else None])
			
		self.options = options
		self.preserveManifestFormatting = preserveManifestFormatting
コード例 #4
0
    def __init__(self, output, compile, classpath, options=None):
        """ 
		@param output: output dir for class files

		@param compile: PathSet (or list)  of things to compile

		@param classpath: PathSet (or list) of things to be on the classpath; 

		@param options: [DEPRECATED - use .option() instead]
		"""
        self.compile = FilteredPathSet(_isJavaFile, PathSet(compile))

        self.classpath = PathSet(classpath)

        BaseTarget.__init__(self, output, [self.compile, self.classpath])
        for k, v in (options or {}).items():
            self.option(k, v)
コード例 #5
0
class Javac(BaseTarget):
    """ Compile java source to a directory (without jarring it)
	"""
    compile = None
    classpath = None

    def __init__(self, output, compile, classpath, options=None):
        """ 
		@param output: output dir for class files

		@param compile: PathSet (or list)  of things to compile

		@param classpath: PathSet (or list) of things to be on the classpath; 

		@param options: [DEPRECATED - use .option() instead]
		"""
        self.compile = FilteredPathSet(_isJavaFile, PathSet(compile))

        self.classpath = PathSet(classpath)

        BaseTarget.__init__(self, output, [self.compile, self.classpath])
        for k, v in (options or {}).items():
            self.option(k, v)

    def run(self, context):
        # make sure outputdir exists
        mkdir(self.path)

        # create the classpath, sorting within PathSet (for determinism), but retaining original order of
        # PathSet elements in the list
        classpath = os.pathsep.join(self.classpath.resolve(context))

        # compile everything
        mkdir(self.getOption('javac.logs'))
        javac(self.path,
              self.compile.resolve(context),
              classpath,
              options=self.options,
              logbasename=self.options['javac.logs'] + '/' +
              targetNameToUniqueId(self.name),
              targetname=self.name)

    def getHashableImplicitInputs(self, context):
        # changes in the manifest text should cause a rebuild
        # for now, don't bother factoring global jar.manifest.defaults option
        # in here (it'll almost never change anyway)
        return super(Javac, self).getHashableImplicitInputs(context) + sorted([
            'option: %s = "%s"' % (k, v) for (k, v) in self.options.items()
            if v and (k.startswith('javac.') or k == 'java.home')
        ])
コード例 #6
0
ファイル: csharp.py プロジェクト: CaribouJohn/xpybuild
class CSharp(BaseTarget):
	""" Compile C# files to an executable or dll
	"""
	compile = None
	main = None
	libs = None
	def __init__(self, output, compile, main=None, libs=None, flags=None, dependencies=None, resources=None):
		""" 
		@param output: the resulting .exe or .dll
		
		@param compile: the input PathSet, path or list of .cs file(s)
		
		@param main: The main class to execute if an exe is to be built.
		If this is set then an executable will be created.
		Otherwise this target will build a library.

		@param libs: a list of input libraries (or a PathSet)
		"""
		self.compile = FilteredPathSet(_isDotNetFile, PathSet(compile))
		self.main = main
		self.flags = flags or []
		self.libs = PathSet(libs or [])
		self.resources = resources or []
		BaseTarget.__init__(self, output, [self.compile, self.libs, [x for (x, y) in self.resources], dependencies or []])
		self.tags('c#')

	def getHashableImplicitInputs(self, context):
		return super(CSharp, self).getHashableImplicitInputs(context) + (['main = %s'%context.expandPropertyValues(('%s'%self.main))] if self.main else [])

	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'])
コード例 #7
0
ファイル: csharp.py プロジェクト: ddfourni/xpybuild
class CSharp(BaseTarget):
	""" Compile C# files to an executable or dll
	"""
	compile = None
	main = None
	libs = None
	def __init__(self, output, compile, main=None, libs=None, flags=None, dependencies=None, resources=None):
		""" 
		@param output: the resulting .exe or .dll
		
		@param compile: the input PathSet, path or list of .cs file(s)
		
		@param main: The main class to execute if an exe is to be built.
		If this is set then an executable will be created.
		Otherwise this target will build a library.

		@param libs: a list of input libraries (or a PathSet)
		"""
		self.compile = FilteredPathSet(_isDotNetFile, PathSet(compile))
		self.main = main
		self.flags = flags or []
		self.libs = PathSet(libs or [])
		self.resources = resources or []
		BaseTarget.__init__(self, output, [self.compile, self.libs, [x for (x, y) in self.resources], dependencies or []])
		self.tags('c#')

	def getHashableImplicitInputs(self, context):
		return super(CSharp, self).getHashableImplicitInputs(context) + (['main = %s'%context.expandPropertyValues(('%s'%self.main))] if self.main else [])

	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.processoutputhandler')('csc', False, options=self.options), timeout=self.options['process.timeout'])
コード例 #8
0
ファイル: java.py プロジェクト: CaribouJohn/xpybuild
	def __init__(self, output, compile, classpath, options=None):
		""" 
		@param output: output dir for class files

		@param compile: PathSet (or list)  of things to compile

		@param classpath: PathSet (or list) of things to be on the classpath; 

		@param options: generic target options map for passing options to the 
		underlying operation (optional)
		"""
		self.compile = FilteredPathSet(_isJavaFile, PathSet(compile))
			
		self.classpath = PathSet(classpath)
		
		BaseTarget.__init__(self, output, [self.compile,self.classpath])
		self.options = options
コード例 #9
0
ファイル: java.py プロジェクト: CaribouJohn/xpybuild
class Javac(BaseTarget):
	""" Compile java source to a directory (without jarring it)
	"""
	compile = None
	classpath = None
	def __init__(self, output, compile, classpath, options=None):
		""" 
		@param output: output dir for class files

		@param compile: PathSet (or list)  of things to compile

		@param classpath: PathSet (or list) of things to be on the classpath; 

		@param options: generic target options map for passing options to the 
		underlying operation (optional)
		"""
		self.compile = FilteredPathSet(_isJavaFile, PathSet(compile))
			
		self.classpath = PathSet(classpath)
		
		BaseTarget.__init__(self, output, [self.compile,self.classpath])
		self.options = options

	def run(self, context):
		options = context.mergeOptions(self) # get the merged options

		# make sure outputdir exists
		mkdir(self.path)

		# create the classpath, sorting within PathSet (for determinism), but retaining original order of 
		# PathSet elements in the list
		classpath = os.pathsep.join(self.classpath.resolve(context)) 

		# compile everything
		mkdir(options.get('javac.logs'))
		javac(self.path, self.compile.resolve(context), classpath, options=options, logbasename=options.get('javac.logs')+'/'+targetNameToUniqueId(self.name), targetname=self.name)

	def getHashableImplicitInputs(self, context):
		# changes in the manifest text should cause a rebuild
		# for now, don't bother factoring global jar.manifest.defaults option 
		# in here (it'll almost never change anyway)
		return super(Javac, self).getHashableImplicitInputs(context) + sorted([
			'option: %s = "%s"'%(k,v) for (k,v) in context.mergeOptions(self).items() 
				if v and (k.startswith('javac.') or k == 'java.home')])
コード例 #10
0
ファイル: csharp.py プロジェクト: CaribouJohn/xpybuild
	def __init__(self, output, compile, main=None, libs=None, flags=None, dependencies=None, resources=None):
		""" 
		@param output: the resulting .exe or .dll
		
		@param compile: the input PathSet, path or list of .cs file(s)
		
		@param main: The main class to execute if an exe is to be built.
		If this is set then an executable will be created.
		Otherwise this target will build a library.

		@param libs: a list of input libraries (or a PathSet)
		"""
		self.compile = FilteredPathSet(_isDotNetFile, PathSet(compile))
		self.main = main
		self.flags = flags or []
		self.libs = PathSet(libs or [])
		self.resources = resources or []
		BaseTarget.__init__(self, output, [self.compile, self.libs, [x for (x, y) in self.resources], dependencies or []])
		self.tags('c#')
コード例 #11
0
class Jar(BaseTarget):
    """ Create a Jar, first compiling some java, then packing it all up
	"""
    compile = None
    classpath = None
    package = None
    manifest = None

    def __init__(self,
                 jar,
                 compile,
                 classpath,
                 manifest,
                 options=None,
                 package=None,
                 preserveManifestFormatting=False):
        """ 
		To add additional entries to the manifest's classpath which are needed at runtime 
		but not during compilation, use .option('jar.manifest.classpathAppend', [...])
		
		@param jar: path to jar to create

		@param compile: PathSet (or list)  of things to compile

		@param classpath: PathSet (or list) of things to be on the classpath; 
		destination mapping indicates how they will appear in the manifest

		@param manifest: map of manifest entries, OR a string with the filename to use 
		OR None to disable manifest generation and just produce a normal zip

		@param options: [DEPRECATED - use .option() instead]

		@param package: PathSet (or list) of other files to include in the jar; 
			destination mapping indicates where they will appear in the jar
		
		@param preserveManifestFormatting: an advanced option that prevents the jar tool from 
			reformatting the specified manifest file to comply with Java conventions 
			(also prevents manifest merging if jar already exists)

		
		"""
        self.compile = FilteredPathSet(_isJavaFile,
                                       PathSet(compile)) if compile else None

        self.classpath = PathSet(classpath)

        self.package = PathSet(package)
        self.manifest = manifest
        BaseTarget.__init__(self, jar, [
            self.compile, self.classpath, self.package,
            manifest if isinstance(manifest, basestring) else None
        ])

        for k, v in (options or {}).items():
            self.option(k, v)
        self.preserveManifestFormatting = preserveManifestFormatting

    def run(self, context):
        options = self.options

        # make sure temp dir exists
        mkdir(self.workDir)

        classes = os.path.join(self.workDir,
                               "classes")  # output dir for classes

        # create the classpath, sorting within PathSet (for determinism), but retaining original order of
        # PathSet elements in the list
        classpath = os.pathsep.join(self.classpath.resolve(context))

        # compile everything
        mkdir(
            classes
        )  # (need this for assembling other files to package later on, even if we don't do any javac)
        if self.compile:
            mkdir(self.getOption('javac.logs'))
            javac(classes,
                  self.compile.resolve(context),
                  classpath,
                  options=options,
                  logbasename=options.get('javac.logs') + '/' +
                  targetNameToUniqueId(self.name),
                  targetname=self.name)

        manifest = os.path.join(self.workDir, "MANIFEST.MF")  # manifest file

        if isinstance(self.manifest, basestring):
            manifest = context.getFullPath(self.manifest, self.baseDir)
        elif self.manifest == None:
            manifest = None
        else:  # generate one
            # rewrite property values in the manifest
            manifest_entries = {}
            for i in self.manifest:
                manifest_entries[i] = context.expandPropertyValues(
                    self.manifest[i])

            # determine classpath for manifest
            classpath_entries = []

            if "Class-path" not in manifest_entries:  # assuming it wasn't hardcoded, set it here
                for src, dest in self.classpath.resolveWithDestinations(
                        context):
                    # we definitely do want to support use of ".." in destinations here, it can be very useful
                    classpath_entries.append(dest)
                assert isinstance(
                    options['jar.manifest.classpathAppend'], list), options[
                        'jar.manifest.classpathAppend']  # must not be a string
                classpath_entries.extend(
                    options['jar.manifest.classpathAppend'] or [])

                # need to always use / not \ for these to be valid
                classpath_entries = [
                    p.replace(os.path.sep, '/').replace('\\', '/')
                    for p in classpath_entries if p
                ]

                if classpath_entries:
                    manifest_entries["Class-path"] = " ".join(
                        classpath_entries)  # include the classpath from here
            if not manifest_entries.get(
                    'Class-path'
            ):  # suppress this element entirely if not needed, otherwise there would be no way to have an empty classpath
                manifest_entries.pop('Class-path', '')

            # create the manifest file
            create_manifest(manifest, manifest_entries, options=options)

        # copy in the additional things to include
        for (src, dest) in self.package.resolveWithDestinations(context):
            if '..' in dest:
                raise Exception(
                    'This target does not permit packaged destination paths to contain ".." relative path expressions'
                )
            mkdir(os.path.dirname(os.path.join(classes, dest)))
            destpath = normLongPath(classes + '/' + dest)
            srcpath = normLongPath(src)

            if os.path.isdir(srcpath):
                mkdir(destpath)
            else:
                with open(srcpath, 'rb') as s:
                    with openForWrite(destpath, 'wb') as d:
                        d.write(s.read())

        # create the jar
        jar(self.path,
            manifest,
            classes,
            options=options,
            preserveManifestFormatting=self.preserveManifestFormatting,
            outputHandler=ProcessOutputHandler('jar',
                                               treatStdErrAsErrors=False,
                                               options=options))

    def getHashableImplicitInputs(self, context):
        # changes in the manifest text should cause a rebuild
        # for now, don't bother factoring global jar.manifest.defaults option
        # in here (it'll almost never change anyway)
        return super(Jar, self).getHashableImplicitInputs(context) + [
         'manifest = '+context.expandPropertyValues(str(self.manifest)),
         'classpath = '+context.expandPropertyValues(str(self.classpath)), # because classpath destinations affect manifest
         ]+(['preserveManifestFormatting = true'] if self.preserveManifestFormatting else [])\
         +sorted(['option: %s = "%s"'%(k,v) for (k,v) in self.options.items()
          if v and (k.startswith('javac.') or k.startswith('jar.') or k == 'java.home')])
コード例 #12
0
ファイル: java.py プロジェクト: CaribouJohn/xpybuild
class Jar(BaseTarget):
	""" Create a Jar, first compiling some java, then packing it all up
	"""
	compile = None
	classpath = None
	package = None
	manifest = None
	def __init__(self, jar, compile, classpath, manifest, options=None, package=None, preserveManifestFormatting=False):
		""" 
		@param jar: path to jar to create

		@param compile: PathSet (or list)  of things to compile

		@param classpath: PathSet (or list) of things to be on the classpath; 
		destination mapping indicates how they will appear in the manifest

		@param manifest: map of manifest entries, OR a string with the filename to use 
		OR None to disable manifest generation and just produce a normal zip

		@param options: generic target options map

		@param package: PathSet (or list) of other files to include in the jar; 
			destination mapping indicates where they will appear in the jar
		
		@param preserveManifestFormatting: an advanced option that prevents the jar tool from 
			reformatting the specified manifest file to comply with Java conventions 
			(also prevents manifest merging if jar already exists)

		
		"""
		self.compile = FilteredPathSet(_isJavaFile, PathSet(compile)) if compile else None
			
		self.classpath = PathSet(classpath)
		
		self.package = PathSet(package)
		self.manifest = manifest
		BaseTarget.__init__(self, jar, [self.compile,self.classpath,self.package, 
			manifest if isinstance(manifest, basestring) else None])
			
		self.options = options
		self.preserveManifestFormatting = preserveManifestFormatting

	def run(self, context):
		options = context.mergeOptions(self) # get the merged options

		# make sure temp dir exists
		mkdir(self.workDir)

		classes = os.path.join(self.workDir, "classes") # output dir for classes
		
		# create the classpath, sorting within PathSet (for determinism), but retaining original order of 
		# PathSet elements in the list
		classpath = os.pathsep.join(self.classpath.resolve(context)) 

		# compile everything
		mkdir(classes) # (need this for assembling other files to package later on, even if we don't do any javac)
		if self.compile:
			mkdir(options.get('javac.logs'))
			javac(classes, self.compile.resolve(context), classpath, options=options, logbasename=options.get('javac.logs')+'/'+targetNameToUniqueId(self.name), targetname=self.name)

		manifest = os.path.join(self.workDir, "MANIFEST.MF") # manifest file
	
		if isinstance(self.manifest, basestring):
			manifest = context.getFullPath(self.manifest, self.baseDir)
		elif self.manifest == None:
			manifest = None
		else: # generate one
			# rewrite property values in the manifest
			manifest_entries = {}
			for i in self.manifest:
				manifest_entries[i] = context.expandPropertyValues(self.manifest[i])
	
			# determine classpath for manifest
			classpath_entries = []
			
			if "Class-path" not in manifest_entries: # assuming it wasn't hardcoded, set it here
				for src, dest in self.classpath.resolveWithDestinations(context):
					classpath_entries.append(dest)
				assert isinstance(options['jar.manifest.classpathAppend'], list), options['jar.manifest.classpathAppend'] # must not be a string
				classpath_entries.extend(options['jar.manifest.classpathAppend'] or [])
				
				# need to always use / not \ for these to be valid
				classpath_entries = [p.replace(os.path.sep, '/').replace('\\', '/') for p in classpath_entries if p]
				
				if classpath_entries:
					manifest_entries["Class-path"] = " ".join(classpath_entries) # include the classpath from here
			if not manifest_entries.get('Class-path'): # suppress this element entirely if not needed, otherwise there would be no way to have an empty classpath
				manifest_entries.pop('Class-path','')
			
			# create the manifest file
			create_manifest(manifest, manifest_entries, options=options)

		# copy in the additional things to include
		for (src, dest) in self.package.resolveWithDestinations(context):
			mkdir(os.path.dirname(os.path.join(classes, dest)))
			destpath = normLongPath(classes+'/'+dest)
			srcpath = normLongPath(src)

			if os.path.isdir(srcpath):
				mkdir(destpath)
			else:
				with open(srcpath, 'rb') as s:
					with openForWrite(destpath, 'wb') as d:
						d.write(s.read())

		# create the jar
		jar(self.path, manifest, classes, options=options, preserveManifestFormatting=self.preserveManifestFormatting, 
			outputHandler=ProcessOutputHandler('jar', treatStdErrAsErrors=False,options=options))

	def getHashableImplicitInputs(self, context):
		# changes in the manifest text should cause a rebuild
		# for now, don't bother factoring global jar.manifest.defaults option 
		# in here (it'll almost never change anyway)
		return super(Jar, self).getHashableImplicitInputs(context) + [
			'manifest = '+context.expandPropertyValues(str(self.manifest)),
			'classpath = '+context.expandPropertyValues(str(self.classpath)), # because classpath destinations affect manifest
			]+(['preserveManifestFormatting = true'] if self.preserveManifestFormatting else [])\
			+sorted(['option: %s = "%s"'%(k,v) for (k,v) in context.mergeOptions(self).items() 
				if v and (k.startswith('javac.') or k.startswith('jar.') or k == 'java.home')])