1. 程式人生 > >yocto-sumo源碼解析(五): bitbake/lib/bb/main.py

yocto-sumo源碼解析(五): bitbake/lib/bb/main.py

存在 ces tail stat writable 初始 orm evel clas

續前面分析,就該對bitbake_main()這個函數進行分析了,這個函數位於bitbake/lib/bb/main.py。

1. 檢測主機操作系統是否為linux並且/dev/shm是否存在,python的multiprocessing需要/dev/shm支持:

    # Python multiprocessing requires /dev/shm on Linux
    if sys.platform.startswith(‘linux‘) and not os.access(‘/dev/shm‘, os.W_OK | os.X_OK):
        raise BBMainException("FATAL: /dev/shm does not exist or is not writable")

2. 重新設置stdout,禁用緩沖以避免長log被截斷:

    # Unbuffer stdout to avoid log truncation in the event
    # of an unorderly exit as well as to provide timely
    # updates to log files for use with tail
    try:
        if sys.stdout.name == ‘<stdout>‘:
            # Reopen with O_SYNC (unbuffered)
            fl = fcntl.fcntl(sys.stdout.fileno(), fcntl.F_GETFL)
            fl |= os.O_SYNC
            fcntl.fcntl(sys.stdout.fileno(), fcntl.F_SETFL, fl)
    except:
        pass

3. 設置配置參數:

    configuration.setConfigParameters(configParams)

4. 檢查配置參數:server_only和remote_server在配置參數中不能同時存在:

    if configParams.server_only and configParams.remote_server:
            raise BBMainException("FATAL: The ‘--server-only‘ option conflicts with %s.\n" %
                                  ("the BBSERVER environment variable" if "BBSERVER" in os.environ                                    else "the ‘--remote-server‘ option"))

5. 檢查配置參數:如果是observe_only,那麽remote_server和bind不能同時配置:

    if configParams.observe_only and not (configParams.remote_server or configParams.bind):
        raise BBMainException("FATAL: ‘--observe-only‘ can only be used by UI clients "
                              "connecting to a server.\n")

6. 配置BBDEBUG級別,如果環境變量BBDEBUG配置級別大於配置參數中的debug級別,采用BBDEBUG:

    if "BBDEBUG" in os.environ:
        level = int(os.environ["BBDEBUG"])
        if level > configuration.debug:
            configuration.debug = level

7. 初始化消息配置:

    bb.msg.init_msgconfig(configParams.verbose, configuration.debug,
                          configuration.debug_domains)

8. 建立bitbake:並且進入ui_module的main函數

    server_connection, ui_module = setup_bitbake(configParams, configuration)
    # No server connection
    if server_connection is None:
        if configParams.status_only:
            return 1
        if configParams.kill_server:
            return 0

    if not configParams.server_only:
        if configParams.status_only:
            server_connection.terminate()
            return 0

        try:
            for event in bb.event.ui_queue:
                server_connection.events.queue_event(event)
            bb.event.ui_queue = []

            return ui_module.main(server_connection.connection, server_connection.events,
                                  configParams)
        finally:
            server_connection.terminate()
    else:
        return 0

    return 1

yocto-sumo源碼解析(五): bitbake/lib/bb/main.py