11244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao#!/usr/bin/python
21244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
31244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao# Use of this source code is governed by a BSD-style license that can be
41244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao# found in the LICENSE file.
51244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao
61244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao# This is the setup script for pyxinput autotest dependency, which
71244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao# will be called at emerge stage.
81244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao
91244cd836567f942762b186fe1b170c32ea837dcHsinyu Chaoimport logging
101244cd836567f942762b186fe1b170c32ea837dcHsinyu Chaoimport os
111244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao
121244cd836567f942762b186fe1b170c32ea837dcHsinyu Chaoimport ctypesgencore
131244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao
141244cd836567f942762b186fe1b170c32ea837dcHsinyu Chaofrom autotest_lib.client.bin import utils
151244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao
161244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao
171244cd836567f942762b186fe1b170c32ea837dcHsinyu Chaoversion = 1
181244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao
191244cd836567f942762b186fe1b170c32ea837dcHsinyu Chaodef setup(topdir):
201244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao    class Opt(object):
211244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao        """Object to hold ctypesgen parseing options"""
221244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao        def __init__(self, attrs):
231244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao            for attr in attrs:
241244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao                setattr(self, attr, attrs[attr])
251244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao
261244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao        def gen(self):
271244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao            """Generate outputs"""
281244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao            desc = ctypesgencore.parser.parse(self.headers, self)
291244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao            ctypesgencore.processor.process(desc, self)
301244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao            ctypesgencore.printer.WrapperPrinter(self.output, self, desc)
311244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao
321244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao    os.chdir(os.path.join(topdir, 'src'))
331244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao
341244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao    # Generate xlib.py
351244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao    opt = Opt(ctypesgencore.options.default_values)
361244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao    opt.libraries = ['X11']
371244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao    opt.headers = ['/usr/include/X11/Xlib.h',
381244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao                   '/usr/include/X11/X.h',
391244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao                   '/usr/include/X11/Xutil.h']
401244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao    opt.output = 'xlib.py'
411244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao    opt.other_known_names = ['None']
421244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao    opt.gen()
431244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao
441244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao    # Generate xi2.py
451244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao    opt = Opt(ctypesgencore.options.default_values)
461244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao    opt.libraries = ['Xi']
471244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao    opt.headers = ['/usr/include/X11/extensions/XI2.h',
481244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao                   '/usr/include/X11/extensions/XInput2.h']
491244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao    opt.output = 'xi2.py'
501244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao    opt.other_known_names = ['None']
511244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao    opt.gen()
521244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao
531244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao    os.chdir(topdir)
541244cd836567f942762b186fe1b170c32ea837dcHsinyu Chao
551244cd836567f942762b186fe1b170c32ea837dcHsinyu Chaopwd = os.getcwd()
561244cd836567f942762b186fe1b170c32ea837dcHsinyu Chaoutils.update_version(pwd + '/src', True, version, setup, pwd)
57