xpybuild.targets.writefile

Contains targets for writing a single file containing dynamically generated contents.

WriteFile

class xpybuild.targets.writefile.WriteFile(name, getContents, dependencies=None, mode=None, executable=False, encoding=None, args=None, kwargs=None)[source]

Bases: xpybuild.basetarget.BaseTarget

Target for writing out a text or binary file with the specifiwed dynamically generated (or hardcoded) contents.

The file will only be updated if its contents have changed.

Example usage:

WriteFile('${OUTPUT_DIR}/foo.txt', lambda context: '\n'.join(['Foo:', context.expandPropertyValues('${FOO}')]))
Parameters
  • name – the output filename

  • getContents

    a unicode character string (which will be subject to expansion), or binary bytes, or a function that accepts a context as input followed optionally by any specified ‘args’) and returns the string/bytes that should be written to the file, using \n for newlines (not os.linesep - any occurrences of the newline character \n in the provided string will be replaced automatically with the OS-specific line separator unless bytes are provided).

    The function will be evaluated during the dependency resolution phase (before the build phase commences).

  • mode – unix permissions to set with chmod on the destination files. If not specified, default mode is used. Ignored on Windows platforms.

  • executable – set to True to add Unix executable permissions (simpler alternative to setting using mode)

  • encoding – The encoding to use for converting the str to bytes; if not specified the common.fileEncodingDecider option is used.

  • args – optional tuple containing arguments that should be passed to the getContents function, after the context argument (first arg).

  • kwargs – optional dictionary containing kwargs that should be passed to the getContents function.

  • dependencies – any targets which need to be built in order to run this target.

Touch

class xpybuild.targets.writefile.Touch(path)[source]

Bases: xpybuild.basetarget.BaseTarget

Target that creates an empty file.

Parameters

path – the output filename.