def test_expandlibsdeps(self):
        '''Test library expansion for dependencies'''
        # Dependency list for a library with a descriptor is equivalent to
        # the arguments expansion, to which we add each descriptor
        args = self.arg_files + [self.tmpfile('liby', Lib('y'))]
        self.assertRelEqual(
            ExpandLibsDeps(args),
            ExpandArgs(args) + [
                self.tmpfile('libx',
                             Lib('x') + config.LIBS_DESC_SUFFIX),
                self.tmpfile('liby',
                             Lib('y') + config.LIBS_DESC_SUFFIX)
            ])

        # When a library exists at the same time as a descriptor, the
        # descriptor is not a dependency
        self.touch([self.tmpfile('libx', Lib('x'))])
        args = self.arg_files + [self.tmpfile('liby', Lib('y'))]
        self.assertRelEqual(
            ExpandLibsDeps(args),
            ExpandArgs(args) +
            [self.tmpfile('liby',
                          Lib('y') + config.LIBS_DESC_SUFFIX)])

        self.touch([self.tmpfile('liby', Lib('y'))])
        args = self.arg_files + [self.tmpfile('liby', Lib('y'))]
        self.assertRelEqual(ExpandLibsDeps(args), ExpandArgs(args))
def main():
    parser = OptionParser()
    parser.add_option("--depend", dest="depend", metavar="FILE",
        help="generate dependencies for the given execution and store it in the given file")
    parser.add_option("--target", dest="target", metavar="FILE",
        help="designate the target for dependencies")
    parser.add_option("--extract", action="store_true", dest="extract",
        help="when a library has no descriptor file, extract it first, when possible")
    parser.add_option("--uselist", action="store_true", dest="uselist",
        help="use a list file for objects when executing a command")
    parser.add_option("--verbose", action="store_true", dest="verbose",
        help="display executed command and temporary files content")
    parser.add_option("--symbol-order", dest="symbol_order", metavar="FILE",
        help="use the given list of symbols to order symbols in the resulting binary when using with a linker")

    (options, args) = parser.parse_args()

    if not options.target:
        options.depend = False
    if options.depend:
        deps = ExpandLibsDeps(args)
        # Filter out common command wrappers
        while os.path.basename(deps[0]) in ['ccache', 'distcc']:
            deps.pop(0)
        # Remove command
        deps.pop(0)
    with ExpandArgsMore(args) as args:
        if options.extract:
            args.extract()
        if options.symbol_order:
            args.orderSymbols(options.symbol_order)
        if options.uselist:
            args.makelist()

        if True: #options.verbose:
            print_command(sys.stderr, args)
        proc = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
        (stdout, stderr) = proc.communicate()
        if proc.returncode and not options.verbose:
            print_command(sys.stderr, args)
        sys.stderr.write(stdout)
        sys.stderr.flush()
        if proc.returncode:
            exit(proc.returncode)
    if not options.depend:
        return
    ensureParentDir(options.depend)
    with open(options.depend, 'w') as depfile:
        depfile.write("%s : %s\n" % (options.target, ' '.join(dep for dep in deps if os.path.isfile(dep) and dep != options.target)))

        for dep in deps:
            if os.path.isfile(dep) and dep != options.target:
                depfile.write("%s :\n" % dep)
def main():
    parser = OptionParser()
    parser.add_option(
        "--depend",
        dest="depend",
        metavar="FILE",
        help=
        "generate dependencies for the given execution and store it in the given file"
    )
    parser.add_option("--target",
                      dest="target",
                      metavar="FILE",
                      help="designate the target for dependencies")
    parser.add_option(
        "--extract",
        action="store_true",
        dest="extract",
        help=
        "when a library has no descriptor file, extract it first, when possible"
    )
    parser.add_option(
        "--uselist",
        action="store_true",
        dest="uselist",
        help="use a list file for objects when executing a command")
    parser.add_option(
        "--verbose",
        action="store_true",
        dest="verbose",
        help="display executed command and temporary files content")
    parser.add_option(
        "--symbol-order",
        dest="symbol_order",
        metavar="FILE",
        help=
        "use the given list of symbols to order symbols in the resulting binary when using with a linker"
    )

    (options, args) = parser.parse_args()

    if not options.target:
        options.depend = False
    if options.depend:
        deps = ExpandLibsDeps(args)
        # Filter out common command wrappers
        while os.path.basename(deps[0]) in ['ccache', 'distcc']:
            deps.pop(0)
        # Remove command
        deps.pop(0)
    with ExpandArgsMore(args) as args:
        if options.extract:
            args.extract()
        if options.symbol_order:
            args.orderSymbols(options.symbol_order)
        if options.uselist:
            args.makelist()

        if options.verbose:
            print_command(sys.stderr, args)
        try:
            proc = subprocess.Popen(args,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.STDOUT)
        except Exception, e:
            print >> sys.stderr, 'error: Launching', args, ':', e
            raise e
        (stdout, stderr) = proc.communicate()
        if proc.returncode and not options.verbose:
            print_command(sys.stderr, args)
        sys.stderr.write(stdout)
        sys.stderr.flush()
        if proc.returncode:
            exit(proc.returncode)
Esempio n. 4
0
                raise Exception("File not found: %s" % arg)
    return desc


if __name__ == '__main__':
    parser = OptionParser()
    parser.add_option(
        "--depend",
        dest="depend",
        metavar="FILE",
        help=
        "generate dependencies for the given execution and store it in the given file"
    )
    parser.add_option("-o",
                      dest="output",
                      metavar="FILE",
                      help="send output to the given file")

    (options, args) = parser.parse_args()
    if not options.output:
        raise Exception("Missing option: -o")

    ensureParentDir(options.output)
    with open(options.output, 'w') as outfile:
        print >> outfile, generate(args)
    if options.depend:
        ensureParentDir(options.depend)
        with open(options.depend, 'w') as depfile:
            depfile.write("%s : %s\n" %
                          (options.output, ' '.join(ExpandLibsDeps(args))))
Esempio n. 5
0

if __name__ == '__main__':
    parser = OptionParser()
    parser.add_option(
        "--depend",
        dest="depend",
        metavar="FILE",
        help=
        "generate dependencies for the given execution and store it in the given file"
    )
    parser.add_option("-o",
                      dest="output",
                      metavar="FILE",
                      help="send output to the given file")

    (options, args) = parser.parse_args()
    if not options.output:
        raise Exception("Missing option: -o")

    ensureParentDir(options.output)
    with open(options.output, 'w') as outfile:
        print >> outfile, generate(args)
    if options.depend:
        ensureParentDir(options.depend)
        with open(options.depend, 'w') as depfile:
            deps = ExpandLibsDeps(args)
            depfile.write("%s : %s\n" % (options.output, ' '.join(deps)))
            for dep in deps:
                depfile.write("%s :\n" % dep)