Example #1
0
def run(flux_dir, proj_dir, args):
    """clean intermediate project dirs"""
    if len(args) > 0:
        print(args)

        # clean opts
        opts = BuildOpts() #TODO: CleanOpts or global Opts?
        args = opts.parse_opts(proj_dir, args)

        # target
        #target = Target(flux_dir, opts)

        for arg in args:
            arg = util.fix_path(arg)
            path = os.path.join(proj_dir, arg)

            proj = Project(flux_dir, path, opts)

            # change to project dir
            #os.chdir(os.path.abspath(path))

            # clean output dir
            if opts.verbose >= 1:
                log.info("cleaning `%s`: `%s`" % (proj.profile, proj.out_dir))
            proj.clean()
    else:
        # show usage
        usage()
Example #2
0
def run(flux_dir, proj_dir, args):
    if len(args) > 0:
        cmd = args[0]
        if cmd == 'install':
            sdk_version = None
            if len(args) > 1:
                sdk_version = args[1]
            emsdk.install(flux_dir, sdk_version)
        elif cmd == 'activate':
            sdk_version = None
            if len(args) > 1:
                sdk_version = args[1]
                emsdk.activate(flux_dir, sdk_version)
            else:
                log.error('emscripten SDK version expected (run "./flux emsdk list")')
        elif cmd == 'list':
            emsdk.list(flux_dir)
        elif cmd == 'uninstall':
            emsdk.uninstall(flux_dir)
        elif cmd == 'show-config':
            log.info('emscripten root directory: ' + emsdk.get_emscripten_dir(flux_dir))
            log.info('emscripten config file: ' + emsdk.get_sdk_config_file(flux_dir))
            emsdk.show_config(flux_dir)
        else:
            log.error('unknown subcommand "%s" (run "./flux help emsdk")' % cmd)
    else:
        log.error('expected a subcommand. run "./flux help emsdk" for help')
Example #3
0
def usage():
    log.info('flux %s' % VERSION)
    log.optional('\nusage', 'flux [verb] [opts] [projects]')
    log.text('\nverbs:')
    for verb_name in sorted(verb.verbs):
        log.item('  ' + verb_name, verb.verbs[verb_name].help())
    log.info('run `flux help` for more informations ')  #TODO: Add all usage
Example #4
0
def clean(flux_dir):
    '''this checks for any "old" SDKs and removes them'''
    old_sdk_dir = os.path.join(util.get_sdks_dir(flux_dir),
                               util.get_host_platform())
    if os.path.isdir(old_sdk_dir):
        log.info('deleting "%s"' % old_sdk_dir)
        shutil.rmtree(old_sdk_dir, onerror=util.remove_readonly)
    else:
        log.info('nothing deleted')
Example #5
0
def uninstall(flux_dir):
    sdk_dir = get_sdk_dir(flux_dir)
    log.colored(log.YELLOW,
                '=== uninstalling "emscripten" SDK at "%s"' % sdk_dir)
    clean(flux_dir)
    if sdk_dir_exists(flux_dir):
        log.info('deleting "%s"' % sdk_dir)
        shutil.rmtree(sdk_dir, onerror=util.remove_readonly)
    else:
        log.warn('emscripten SDK is not installed, nothing to do')
Example #6
0
def show_config(flux_dir):
    config = parse_config(flux_dir)
    for k, v in config.items():
        if k not in ['__builtins__', 'emsdk_path', 'os']:
            log.info('%s: %s' % (k, v))
Example #7
0
    def find_msvc(self):

        def find_max_ver_dir(ver_dir):
            max_ver = 0
            max_ver_dir = ''

            for f in os.listdir(ver_dir):
                ver_dir = os.path.join(ver_dir, f)
                if not os.path.isdir(ver_dir):
                    continue
                ver = int(f.replace('.', ''))
                if ver > max_ver:
                    max_ver = ver
                    max_ver_dir = ver_dir
            return max_ver_dir

        if self.toolchain == 'msvc':
            # MSVC
            msvcs = ''
            for ver in self.msvc_version:
                msvcs = os.path.join(os.environ['ProgramFiles(x86)'], 'Microsoft Visual Studio', str(ver).strip())
                if os.path.isdir(msvcs):
                    break
            if not os.path.isdir(msvcs):
                return False

            # Windows Kits
            wkits = os.path.join(os.environ['ProgramFiles(x86)'], 'Windows Kits\\10')
            if not os.path.isdir(wkits):
                return False

            # VC Tools
            tools_dir = ''
            max_ver = 0
            for f in os.listdir(msvcs):
                d = os.path.join(msvcs, f, 'VC\\Tools\\MSVC')
                if not os.path.isdir(d):
                    continue
                
                for ff in os.listdir(d):
                    ver_dir = os.path.join(d, ff)
                    if not os.path.isdir(ver_dir):
                        continue
                    ver = int(ff.replace('.', ''))
                    if ver > max_ver:
                        tools_dir = ver_dir
                        max_ver = ver

            # VC Includes
            incs_dir = find_max_ver_dir(os.path.join(wkits, 'Include'))
            if not incs_dir:
                return False

            # VC Libs
            libs_dir = find_max_ver_dir(os.path.join(wkits, 'Lib'))
            if not libs_dir:
                return False

            # show msvc dirs
            if self.buildopts.verbose >= 3:
                log.info('MSVC installation auto-detected: %s"%s"%s' % (log.YELLOW, msvcs, log.DEFAULT))
                log.info('- VC Tools   = %s"%s"%s' % (log.YELLOW, tools_dir, log.DEFAULT))
                log.info('- VC Include = %s"%s"%s' % (log.YELLOW, incs_dir, log.DEFAULT))
                log.info('- VC Lib     = %s"%s"%s' % (log.YELLOW, libs_dir, log.DEFAULT))

            # set msvc env vars
            if self.buildopts.arch == 'x86':
                os.environ['FLUX_MSVC_PATH'] = tools_dir+'\\bin\\Hostx86\\x86'
                os.environ['FLUX_MSVC_INCLUDE'] = tools_dir+'\\include;'+incs_dir+'\\ucrt;'+incs_dir+'\\shared;'+incs_dir+'\\um;'+incs_dir+'\\winrt'
                os.environ['FLUX_MSVC_LIB'] = tools_dir+'\\lib\\x86;'+libs_dir+'\\ucrt\\x86;'+libs_dir+'\\um\\x86'
            elif self.buildopts.arch == 'x64':
                os.environ['FLUX_MSVC_PATH'] = tools_dir+'\\bin\\Hostx64\\x64'
                os.environ['FLUX_MSVC_INCLUDE'] = tools_dir+'\\include;'+incs_dir+'\\ucrt;'+incs_dir+'\\shared;'+incs_dir+'\\um;'+incs_dir+'\\winrt'
                os.environ['FLUX_MSVC_LIB'] = tools_dir+'\\lib\\x64;'+libs_dir+'\\ucrt\\x64;'+libs_dir+'\\um\\x64'
            else:
                log.fatal('unrecognized architecture build option `%s`' % self.opts.arch)

            return True
        else:
            return False



            
Example #8
0
def run(flux_dir, proj_dir, args):
    flux_dir = util.fix_path(flux_dir)
    proj_dir = util.fix_path(proj_dir)
    curr_dir = proj_dir

    # check space in project path
    if ' ' in proj_dir:
        log.warn(
            'whitespace in project path detected, `flux` will not work correctly'
        )

    # import verbs from flux dir
    verb.import_verbs(flux_dir)

    # parse args
    if len(args) <= 1:
        usage()
    else:
        name = args[1]
        args = args[2:]

        # run available verb
        if name in verb.verbs:
            verb.verbs[name].run(flux_dir, proj_dir, args)

        # for development stuff only
        elif name == 'dev':
            pass
        elif name == 'build':
            #log.text('===== test console output begin =====')
            #log.trace('trace message')
            #log.debug('debug message')
            #log.info('info message')
            #log.warn('warn message')
            #log.error('error message')
            #log.text('===== test console output end =====')

            # set build opts
            opts = BuildOpts()
            args = opts.parse_opts(proj_dir, args)

            # get target datas
            #TODO: add user custom targets

            # set target opts
            target = Target(flux_dir, opts)
            if target.toolchain == 'msvc':
                # check msvc install
                if target.find_msvc():
                    # update env vars
                    os.environ['PATH'] = os.environ[
                        'FLUX_MSVC_PATH'] + ';' + os.environ['PATH']
                    os.environ['INCLUDE'] = os.environ['FLUX_MSVC_INCLUDE']
                    os.environ['LIB'] = os.environ['FLUX_MSVC_LIB']
                else:
                    log.fatal('MSVC installation not found!')
            elif target.target == 'emscripten':
                from mods.sdks import emsdk
                if emsdk.sdk_dir_exists(flux_dir):
                    os.environ[
                        'PATH'] += os.pathsep + emsdk.get_emscripten_dir(
                            flux_dir)

            if opts.verbose >= 3:
                log.info('python %s.%s.%s' % (sys.version_info[:3]))
                log.info('os.environ:')
                for ev in sorted(
                        filter(lambda x: x.startswith('FLUX_'), os.environ)):
                    log.info('- %s: %s' %
                             (ev, log.YELLOW + os.environ[ev] + log.DEFAULT))

            # if not arg, set project in current dir
            if not len(args):
                args += [proj_dir]

            # for each projets
            for arg in args:
                print(log.YELLOW + ("===== `%s`" % arg) + log.DEFAULT)
                arg = util.fix_path(arg)
                path = os.path.join(proj_dir, arg)

                #print(path)

                proj = Project(flux_dir, path, opts)

                # change to project dir
                os.chdir(os.path.abspath(path))

                # clean output dir
                if opts.clean:
                    if opts.verbose >= 1:
                        log.info("cleaning `%s`" % proj.out_dir)
                    proj.clean()

                # create project intermediate dirs
                proj.make_dirs()

                # make Info.plist file
                if proj.target == 'macos' and proj.apptype == 'window':
                    proj.make_info_plist()

                # parse project file
                proj.parse_inputs()

                #print(proj)

                # depends
                if proj.build in ['app']:  # app only?
                    if len(proj.flux_libs):
                        sys_libs = []
                        for lib in proj.flux_libs:
                            # load dep project file
                            dep_dir = os.path.join(
                                util.get_workspace_dir(flux_dir), lib)
                            dep = Project(flux_dir, dep_dir, opts, True)

                            # module or library dep only
                            if dep.build in ['mod', 'lib']:
                                # change dir to dep dir
                                cd = os.getcwd()
                                os.chdir(os.path.abspath(dep_dir))

                                # parse dep project file
                                dep.parse_inputs()

                                # files stamp
                                out_file_stamp = None
                                gen_file_stamp = None

                                # check if module archive exists
                                if not os.path.exists(dep.out_file):
                                    if not os.path.exists(dep.gen_file):
                                        #create dep intermediate dirs
                                        dep.make_dirs()

                                        # generate ninja file for dep
                                        if opts.verbose >= 1:
                                            log.info('generate `%s`' %
                                                     dep.gen_file)
                                        with open(dep.gen_file, 'w') as out:
                                            dep.gen_ninja(out, opts, target)
                                else:
                                    #TODO: regenerate ninja if 'dep.flux_file' is most recent than 'dep.out_file'
                                    pass

                                # add 'dep.gen_file' to project
                                proj.ninja_files.append(dep.gen_file)

                                # build dep module
                                if os.path.exists(dep.gen_file):
                                    if opts.verbose >= 1:
                                        log.info(
                                            'building `%s` %s' %
                                            (dep.base_dir, log.BLUE +
                                             '(dependency)' + log.DEFAULT))
                                    dep.build_ninja(verbose=opts.verbose >= 3)

                                # add dep include dirs (abspath)
                                for inc in dep.include_dirs:
                                    proj.cc_opts.append('-I"%s"' % inc)
                                    proj.cxx_opts.append('-I"%s"' % inc)

                                # add dep module archive
                                proj.lib_files.append('"%s"' % dep.out_file)

                                # append system libs
                                for lib in dep.lib_files:
                                    if lib not in sys_libs:
                                        sys_libs.append(lib)

                                # return to main project
                                os.chdir(cd)

                        # add dep system libs at end
                        for lib in sys_libs:
                            if lib not in proj.lib_files:
                                proj.lib_files.append(lib)

                # set rules vars
                #rule_vars = target.get_rule_vars(proj)

                # generate ninja in proj.out_dir
                if opts.verbose >= 1:
                    log.info('generate `%s`' % proj.gen_file)
                with open(proj.gen_file, 'w') as out:  #StringIO()
                    proj.gen_ninja(out, opts, target)

                # build project from ninja
                if os.path.exists(proj.gen_file):
                    if opts.verbose >= 1:
                        log.info('building `%s`' % proj.base_dir)
                    proj.build_ninja(verbose=opts.verbose >= 3)
                    # copy assets files
                    proj.copy_assets(proj.asset_dir)
                    proj.copy_binaries(proj.out_dir)

            # return to start dir
            os.chdir(curr_dir)
        else:
            log.error('unknown verb `%s`' % name)