def build_autotiler(build_dir, generator, model_path): if isdir(build_dir): fs.rmtree(build_dir) # parse custom library path from `platformio.ini` tmpenv = env.Clone() tmpenv.ProcessFlags(env.get("BUILD_FLAGS")) genv = env.Environment( tools=["ar", "gas", "gcc", "g++", "gnulink"], CC="gcc", CPPPATH=[ join(AUTOTILER_DIR, "include"), join(AUTOTILER_DIR, "generators", generator, "generator", "include") ], LIBPATH=[ join(AUTOTILER_DIR, "lib"), env.GetProjectConfig().get("platformio", "lib_dir") ] + tmpenv.get("LIBPATH", []), LIBS=["tile"]) # CHECK "libtile.a" found_libtile = False for d in genv['LIBPATH']: if isfile(genv.subst(join(d, "libtile.a"))): found_libtile = True break if not found_libtile: sys.stderr.write( "Error: AutoTiler library has not been found. Please read => " "https://docs.platformio.org/page/platforms/riscv_gap.html" "#autotiler\n") env.Exit(1) variant_dirs = [(join(build_dir, "model"), dirname(model_path)), (join(build_dir, "generator"), join(AUTOTILER_DIR, "generators", generator, "generator", "src"))] for (var_dir, src_dir) in variant_dirs: if not isdir(genv.subst(var_dir)): makedirs(genv.subst(var_dir)) genv.VariantDir(var_dir, src_dir, duplicate=0) src_files = [join(build_dir, "model", basename(model_path))] src_files.extend(genv.Glob(join(build_dir, "generator", "*Generator?.c"))) for o in genv.Object(src_files): if not int(ARGUMENTS.get("PIOVERBOSE", 0)): genv.Replace(CCCOMSTR="Compiling %s" % relpath(str(o))) o.build() if not int(ARGUMENTS.get("PIOVERBOSE", 0)): genv.Replace(LINKCOMSTR="Linking AutoTiler") return genv.Program(join(build_dir, "program"), src_files)[0].build()
def setup_environment(tools): env = None if sys.platform.find('win') == 0: system_root = os.environ['SystemRoot'] comspec = os.environ['ComSpec'] env = { 'PATH': [ os.path.dirname(comspec) ], 'SystemRoot': os.environ['SystemRoot'], 'ComSpec': comspec, 'TEMP': os.environ['TEMP'], 'TMP': os.environ['TMP'] } else: raise DGSConsException("Platform {} is not supported". format(os.platform)) compiler = GetOption('compiler') if compiler == 'mingw': mingwbin = ARGUMENTS.get('mingwbin') if not mingwbin or not os.path.isdir(mingwbin): raise DGSConsException("Unable to determine " "Mingw compiler location. " "Provided 'mingwbin' value: {}". format(mingwbin)) env['PATH'].append(mingwbin) tools.append('mingw') else: raise DGSConsException("Compiler type {} is not supported". format(compiler)) compile_mode = '' variant = GetOption('variant') if variant == 'Debug': compile_mode = '-g' elif variant == 'Release': compile_mode = '-O2' else: raise DGSConsException("Variant {} is not supported".format(variant)) default_environment = DefaultEnvironment( ENV = env, tools = tools, VARIANT = variant, CCFLAGS = compile_mode, CXXFLAGS = compile_mode, LINKFLAGS = compile_mode, QTDIR = ARGUMENTS.get('qtroot', None), DGDINC = ARGUMENTS.get('dgdinc', None) ) if GetOption('dumpenv'): print default_environment.Dump() default_environment.Exit(0) return default_environment
def __init__(self): LanguageBuilder.__init__(self) cpplint._cpplint_state.ResetErrorCounts() self._build_mode = ARGUMENTS.get('c', 'dbg') self._distcc_log = ARGUMENTS.get('distcc_log', '%s/distcc_log' % Flags.SNAKE_OUT) self._use_distcc = ARGUMENTS.get('use_distcc', 'on') self._lib_name_map = {} self._source_files = set() self._checked_dir = set()
def checkForLockPrefix(conf): """Check for user-supplied lock prefix.""" conf.Message("Checking for user supplied lockprefix... ") lp = ARGUMENTS.get('lockprefix', 0) or ARGUMENTS.get("with-lockprefix",0) if lp: conf.Result(1) conf.env.Append(CPPFLAGS = '-DFSP_KEY_PREFIX=\\"'+lp+'\\"') else: conf.Result(0)
def getPreConfig(): pre_config = "typical" if ARGUMENTS.get("CUSTOM_PRE_CONFIG", ""): pre_config = b64decode(ARGUMENTS.get("CUSTOM_PRE_CONFIG")) if pre_config and not isdir(join(FRAMEWORK_DIR, "libsdk", pre_config)): sys.stderr.write( "Error: Wrong `custom_pre_config`, please check it in " "platformio.ini. Use 'typical' as default.\n") env.Exit(1) return pre_config
def get_command_line_variant(env): ''' return the list of variants ''' cv = [] if ARGUMENTS.get('deploy_variant', None): cv.append(ARGUMENTS.get('deploy_variant').upper()) else: cv = DeployVariant.get_supported_variants() return cv
def checkForLockPrefix(conf): """Check for user-supplied lock prefix.""" conf.Message("Checking for user supplied lockprefix... ") lp = ARGUMENTS.get('lockprefix', 0) or ARGUMENTS.get("with-lockprefix", 0) if lp: conf.Result(1) conf.env.Append(CPPFLAGS='-DFSP_KEY_PREFIX=\\"' + lp + '\\"') else: conf.Result(0)
def setup_environment(tools): env = None if sys.platform.find('win') == 0: system_root = os.environ['SystemRoot'] comspec = os.environ['ComSpec'] env = { 'PATH': [os.path.dirname(comspec)], 'SystemRoot': os.environ['SystemRoot'], 'ComSpec': comspec, 'TEMP': os.environ['TEMP'], 'TMP': os.environ['TMP'] } else: raise DGSConsException("Platform {} is not supported".format( os.platform)) compiler = GetOption('compiler') if compiler == 'mingw': mingwbin = ARGUMENTS.get('mingwbin') if not mingwbin or not os.path.isdir(mingwbin): raise DGSConsException( "Unable to determine " "Mingw compiler location. " "Provided 'mingwbin' value: {}".format(mingwbin)) env['PATH'].append(mingwbin) tools.append('mingw') else: raise DGSConsException( "Compiler type {} is not supported".format(compiler)) compile_mode = '' variant = GetOption('variant') if variant == 'Debug': compile_mode = '-g' elif variant == 'Release': compile_mode = '-O2' else: raise DGSConsException("Variant {} is not supported".format(variant)) default_environment = DefaultEnvironment( ENV=env, tools=tools, VARIANT=variant, CCFLAGS=compile_mode, CXXFLAGS=compile_mode, LINKFLAGS=compile_mode, QTDIR=ARGUMENTS.get('qtroot', None), DGDINC=ARGUMENTS.get('dgdinc', None)) if GetOption('dumpenv'): print default_environment.Dump() default_environment.Exit(0) return default_environment
def __init__(self): LanguageBuilder.__init__(self) cpplint._cpplint_state.ResetErrorCounts() self._build_mode = ARGUMENTS.get('c', 'dbg') self._distcc_log = ARGUMENTS.get('distcc_log', '%s/distcc_log' % Flags.SNAKE_OUT) self._use_distcc = ARGUMENTS.get('use_distcc', 'on') self._use_ccache = ARGUMENTS.get('use_ccache', 'off') self._lib_name_map = {} self._source_files = set() self._checked_dir = set()
def get_deploy_root(env): ''' this function constructs the deploy root from the environment variables if it is not passed as a command line parameter ''' if not ARGUMENTS.get('deploy_root', None): #construct the path return os.path.join( os.path.dirname(ammend_file_path(env.subst('${BUILD_ROOT}'))), 'deploy_' + env.subst('${BUILD_ID}')) return ARGUMENTS.get('deploy_root')
def build(self, target, source, env): import hotshot env['runtype'] = 'dryrun' env['verbose'] = ARGUMENTS.get('verbose', 0) env['logfile'] = ARGUMENTS.get('log', None) env['callbacks'] = [] prof = hotshot.Profile(str(target[0])) prof.runcall(self.act, self.target, source, env) prof.close()
def disassemble(source, target, env): verbose = int(ARGUMENTS.get("PIOVERBOSE", 0)) source = path.abspath(env.subst('$PIOMAINPROG')) target = env.subst( env.GetProjectOption('custom_disassemble_target', '$BUILD_DIR/${PROGNAME}.lst')) target = path.abspath(target) command = env.subst( env.GetProjectOption('custom_disassemble_bin', env['CC'].replace('gcc', 'objdump'))) options = re.split( r'[\s]', env.subst(env.GetProjectOption('custom_disassemble_options', '-S -C'))) args = [command] + options + [source, '>', target] if verbose: click.echo(' '.join(args)) return_code = subprocess.run(args, shell=True).returncode if return_code != 0: click.secho('failed to run: %s' % ' '.join(args)) env.Exit(1) click.echo('-' * click.get_terminal_size()[0]) click.secho('Created: ', fg='yellow', nl=False) click.secho(target)
def findDocbookStylesheets(check): """Return path to Docbook stylesheets or None.""" directories = [ "/usr/local/share/sgml/docbook/dsssl/modular", "/usr/share/sgml/stylesheets/dsssl/docbook" ] customdsssl = ARGUMENTS.get('dsssl', None) if customdsssl: directories.insert(0, customdsssl) files = ["html/docbook.dsl", "catalog", "common/dbcommon.dsl"] check.Message("Locating Docbook DSSSL Stylesheets... ") for d in directories: try: st = os.stat(d) if not stat.S_ISDIR(st.st_mode): continue for f in files: st = os.stat(d + os.sep + f) if not stat.S_ISREG(st.st_mode): raise OSError check.Result(d) return d except OSError: continue check.Result(False) return None
def get_cmdline_bool(option, default): """We use `ARGUMENTS.get()` to check if options were manually overridden on the command line, and SCons' _text2bool helper to convert them to booleans, otherwise they're handled as strings. """ cmdline_val = ARGUMENTS.get(option) if cmdline_val is not None: return _text2bool(cmdline_val) else: return default
def _get_plaform_data(): data = ["PLATFORM: %s %s" % (platform.title, platform.version)] if platform.src_version: data.append("#" + platform.src_version) if int(ARGUMENTS.get("PIOVERBOSE", 0)) and platform.src_url: data.append("(%s)" % platform.src_url) if board_config: data.extend([">", board_config.get("name")]) return data
def checkForBuildingSharedLibrary(conf): """check if building shared library was requested""" conf.Message("checking whether to build shared library... ") makeshared = ARGUMENTS.get('enable-shared', 0) if makeshared == 0 or makeshared == 'no': conf.Result(0) return False else: conf.Result(1) return True
def checkForBuildingSharedLibrary(conf): """check if building shared library was requested""" conf.Message("checking whether to build shared library... ") makeshared=ARGUMENTS.get('enable-shared', 0) if makeshared == 0 or makeshared == 'no': conf.Result(0) return False else: conf.Result(1) return True
def checkForUserPrefix(conf, oldprefix=None): """Returns prefix specified on command line or oldprefix if none is found.""" conf.Message("Checking for user supplied prefix... ") lp = ARGUMENTS.get('prefix', 0) if lp: conf.Result(1) return lp else: conf.Result(0) return oldprefix
def generate(env): # initialize environment globals that other tools rely on env['OFT_SCONS_TOOLS'] = os.path.dirname(os.path.abspath(__file__)) env['OFT_ROOT'] = os.path.abspath(os.path.join(env['OFT_SCONS_TOOLS'], '..')) env['OFT_VM_INCLUDE'] = os.path.abspath(os.path.join(env['OFT_ROOT'], 'vm', 'src')) # import terminal type to enable gcc/clang to print colored output # http://stackoverflow.com/questions/9922521/why-doesnt-clang-show-color-output-under-scons env['ENV']['TERM'] = os.environ['TERM'] # copy path from os environment env['ENV']['PATH'] = os.environ['PATH'] # initialize logger env.Tool('logger') log_level = ARGUMENTS.get('log-level', None) if log_level == None: log_level = ARGUMENTS.get('ll', None) if log_level == None: log_level = 'warn' env.SetLogLevel(log_level) # load other tools env.Tool('find_files') env.Tool('oft_java') env.Tool('infuser') env.Tool('c_array') env.Tool('target') env.Tool('oft_runtime') # helper functions env.AddMethod(run_program, 'Run') env['OFT_SHOW_SIZE_COMSTR'] = "Size:" env.AddMethod(show_size, 'ShowSize') # determine build directory # this is inspired by the code in `scons/site_tools/xpcc.py` # from the `xpcc` microcontroller library project if not 'OFT_BUILDPATH' in env: env['OFT_BUILDPATH'] = os.path.join(Dir('.').abspath, 'build') # start list of ostfiresentee libraries env['OFT_LIBS'] = []
def checkForUserMandir(conf, oldmandir=None): """Returns mandir specified on command line or oldmandir if none is supplied.""" conf.Message("Checking for user supplied mandir... ") lp = ARGUMENTS.get('mandir', 0) if lp: conf.Result(1) return lp else: conf.Result(0) return oldmandir
def checkForUserPrefix(conf,oldprefix=None): """Returns prefix specified on command line or oldprefix if none is found.""" conf.Message("Checking for user supplied prefix... ") lp = ARGUMENTS.get('prefix', 0) if lp: conf.Result(1) return lp else: conf.Result(0) return oldprefix
def checkForLockingType(check, conf): """check for available locking methods""" fun_lockf = conf.CheckFunc("lockf") fun_semop = conf.CheckFunc("semop") fun_shmget = conf.CheckFunc("shmget") fun_flock = conf.CheckFunc("flock") # select locking type check.Message("Checking for FSP locking type... ") lt = ARGUMENTS.get('locking', 0) or ARGUMENTS.get( "with-locking", 0) or ARGUMENTS.get("lock", 0) or ARGUMENTS.get( "with-lock", 0) if lt == "none": conf.env.Append(CPPFLAGS='-DFSP_NOLOCKING') check.Result("none") elif lt == "lockf" and fun_lockf: conf.env.Append(CPPFLAGS='-DFSP_USE_LOCKF') check.Result("lockf") elif lt == "semop" and fun_semop and fun_shmget: conf.env.Append(CPPFLAGS='-DFSP_USE_SHAREMEM_AND_SEMOP') check.Result("semop and shmget") elif lt == "shmget" and fun_shmget and fun_lockf: conf.env.Append(CPPFLAGS='-DFSP_USE_SHAREMEM_AND_LOCKF') check.Result("lockf and shmget") elif lt == "flock" and fun_flock: conf.env.Append(CPPFLAGS='-DFSP_USE_FLOCK') check.Result("flock") # AUTODETECT best available locking type elif fun_semop and fun_shmget: conf.env.Append(CPPFLAGS='-DFSP_USE_SHAREMEM_AND_SEMOP') check.Result("semop and shmget") elif fun_shmget and fun_lockf: conf.env.Append(CPPFLAGS='-DFSP_USE_SHAREMEM_AND_LOCKF') check.Result("lockf and shmget") elif fun_lockf: conf.env.Append(CPPFLAGS='-DFSP_USE_LOCKF') check.Result("lockf") elif fun_flock: conf.env.Append(CPPFLAGS='-DFSP_USE_FLOCK') check.Result("flock") else: conf.env.Append(CPPFLAGS='-DFSP_NOLOCKING') check.Result("none")
def get_update_po_targets(): target = ARGUMENTS.get('update-po', '') if not target: return [] targets = target.split(',') result = [] for t in targets: t.strip() if t: result.append(t) return result
def print_deps_tree(root, level=0): margin = "| " * (level) for lb in root.depbuilders: title = "<%s>" % lb.name if lb.version: title += " v%s" % lb.version if int(ARGUMENTS.get("PIOVERBOSE", 0)): title += " (%s)" % lb.path print "%s|-- %s" % (margin, title) if lb.depbuilders: print_deps_tree(lb, level + 1)
def build(self, target, source, env): # env['runtype'] = 'dryrun' env['verbose'] = ARGUMENTS.get('verbose', 0) debug = ARGUMENTS.get('debug', None) if debug: debug = debug.split(',') else: debug = [] env['debug'] = debug env['logfile'] = None runner = dottestRunner() from slimpy_base.Environment.InstanceManager import InstanceManager __env__ = InstanceManager() __env__['graphmgr'].setRunner(runner) self.act(target, source, env)
def checkForMaintainerMode(conf,force=False): """Check if user wants to enable maintainer compilation mode. If force is true than maintainer mode is forced""" conf.Message("Checking whether to enable maintainer mode... ") maint=ARGUMENTS.get('maintainer-mode', 0) or \ ARGUMENTS.get('enable-maintainer-mode', 0) try: maint2=int(maint) except ValueError: maint2=None if force: maint2 = 1 if maint2 > 0 or str(maint).lower() == 'yes': conf.Result(1) conf.env.Append(CCFLAGS = '-O0') conf.env.Append(CPPFLAGS = '-DMAINTAINER_MODE') return True else: conf.Result(0) return False
def checkForMaintainerMode(conf, force=False): """Check if user wants to enable maintainer compilation mode. If force is true than maintainer mode is forced""" conf.Message("Checking whether to enable maintainer mode... ") maint=ARGUMENTS.get('maintainer-mode', 0) or \ ARGUMENTS.get('enable-maintainer-mode', 0) try: maint2 = int(maint) except ValueError: maint2 = None if force: maint2 = 1 if maint2 > 0 or str(maint).lower() == 'yes': conf.Result(1) conf.env.Append(CCFLAGS='-O0') conf.env.Append(CPPFLAGS='-DMAINTAINER_MODE') return True else: conf.Result(0) return False
def _get_plaform_data(): data = ["PLATFORM: %s %s" % (platform.title, platform.version)] src_manifest_path = platform.pm.get_src_manifest_path(platform.get_dir()) if src_manifest_path: src_manifest = fs.load_json(src_manifest_path) if "version" in src_manifest: data.append("#" + src_manifest["version"]) if int(ARGUMENTS.get("PIOVERBOSE", 0)): data.append("(%s)" % src_manifest["url"]) if board_config: data.extend([">", board_config.get("name")]) return data
def checkForLockingType(check,conf): """check for available locking methods""" fun_lockf=conf.CheckFunc("lockf") fun_semop=conf.CheckFunc("semop") fun_shmget=conf.CheckFunc("shmget") fun_flock=conf.CheckFunc("flock") # select locking type check.Message("Checking for FSP locking type... ") lt=ARGUMENTS.get('locking', 0) or ARGUMENTS.get("with-locking",0) or ARGUMENTS.get("lock",0) or ARGUMENTS.get("with-lock",0) if lt == "none": conf.env.Append(CPPFLAGS = '-DFSP_NOLOCKING') check.Result("none") elif lt == "lockf" and fun_lockf: conf.env.Append(CPPFLAGS = '-DFSP_USE_LOCKF') check.Result("lockf") elif lt == "semop" and fun_semop and fun_shmget: conf.env.Append(CPPFLAGS = '-DFSP_USE_SHAREMEM_AND_SEMOP') check.Result("semop and shmget") elif lt == "shmget" and fun_shmget and fun_lockf: conf.env.Append(CPPFLAGS = '-DFSP_USE_SHAREMEM_AND_LOCKF') check.Result("lockf and shmget") elif lt == "flock" and fun_flock: conf.env.Append(CPPFLAGS = '-DFSP_USE_FLOCK') check.Result("flock") # AUTODETECT best available locking type elif fun_semop and fun_shmget: conf.env.Append(CPPFLAGS = '-DFSP_USE_SHAREMEM_AND_SEMOP') check.Result("semop and shmget") elif fun_shmget and fun_lockf: conf.env.Append(CPPFLAGS = '-DFSP_USE_SHAREMEM_AND_LOCKF') check.Result("lockf and shmget") elif fun_lockf: conf.env.Append(CPPFLAGS = '-DFSP_USE_LOCKF') check.Result("lockf") elif fun_flock: conf.env.Append(CPPFLAGS = '-DFSP_USE_FLOCK') check.Result("flock") else: conf.env.Append(CPPFLAGS = '-DFSP_NOLOCKING') check.Result("none")
def checkForLamerpack(conf): """Check command line arguments if user requested lamerpack build.""" conf.Message("Checking if we are building lamer pack... ") buildlamer=ARGUMENTS.get('enable-lamerpack', 0) try: buildlamer2=int(buildlamer) except ValueError: buildlamer2=None if buildlamer2 == 0 or str(buildlamer).lower() == 'no': conf.Result(0) else: conf.env.Append(CPPFLAGS = '-DLAMERPACK') conf.Result(1)
def _get_plaform_data(): data = [ "PLATFORM: %s (%s)" % ( platform.title, pkg_metadata.version if pkg_metadata else platform.version, ) ] if (int(ARGUMENTS.get("PIOVERBOSE", 0)) and pkg_metadata and pkg_metadata.spec.external): data.append("(%s)" % pkg_metadata.spec.url) if board_config: data.extend([">", board_config.get("name")]) return data
def checkForClientTimeout(conf): """Check command line arguments if user requested disabling timeouts.""" conf.Message("Checking if client commands can time out... ") timeout = ARGUMENTS.get('disable-timeout', 0) try: timeout2 = int(timeout) except ValueError: timeout2 = None if timeout2 == 0 or str(timeout).lower() == 'no': conf.env.Append(CPPFLAGS='-DCLIENT_TIMEOUT') conf.Result(1) else: conf.Result(0)
def GetArg( name, helpmsg, default, allowed_values = None, caseless = True ): """Utility for adding help information and retrieving argument""" if allowed_values is not None: VARS.Add( EnumVariable( name, helpmsg, default, allowed_values = allowed_values, ignorecase = 2 ) ) else: VARS.Add( name, helpmsg, default ) value = ARGUMENTS.get( name, default ) if value is not None and caseless: value = value.lower() return value
def checkForUserSysconfdir(conf, prefix): """Returns sysconfdir specified on command line or prefix/etc if none is supplied.""" conf.Message("Checking for user supplied sysconfdir... ") lp = ARGUMENTS.get('sysconfdir', 0) if lp: conf.Result(1) else: conf.Result(0) lp = prefix + '/etc' conf.env.Append(CPPFLAGS='-DSYSCONFDIR=\\"' + lp + '\\"') return lp
def PrepareEnv(env): log = ARGUMENTS.get('log', 'vs') if log == 'q': env['CMD_LOGFILE'] = os.path.join(Flags.SNAKE_OUT, 'build.log') env['PRINT_CMD_LINE_FUNC'] = QuietBuild print('%s %s' % (Highlight('Build log:', 1, False), env['CMD_LOGFILE'])) if os.path.exists(env['CMD_LOGFILE']): os.remove(env['CMD_LOGFILE']) elif log == 's': ColorfulBuild(env, False) elif log == 'vs': ColorfulBuild(env, True)
def run_tool(cmd): idf_env = os.environ.copy() populate_idf_env_vars(idf_env) result = exec_command(cmd, env=idf_env) if result["returncode"] != 0: sys.stderr.write(result["out"] + "\n") sys.stderr.write(result["err"] + "\n") env.Exit(1) if int(ARGUMENTS.get("PIOVERBOSE", 0)): print(result["out"]) print(result["err"])
def check_env(): import racy.renv.configs.commandline racy.renv.configs.commandline.check_opts(ARGUMENTS) for opt, val in ARGUMENTS.items(): racy.renv.configs.allowedvalues.check_value_with_msg( opt, val, 'commandline argument' ) for target in TARGETS.values(): racy.renv.configs.commandline.check_prj_opts(target.opts) racy.renv.configs.allowedvalues.check_dict_with_msg( target.opts, "commandline project's argument" )
def checkForBuildingClients(conf): """Check command line arguments if user requested to not build client commands.""" conf.Message("Checking if we are building client commands... ") buildlamer = ARGUMENTS.get('without-clients', 0) try: buildlamer2 = int(buildlamer) except ValueError: buildlamer2 = None if buildlamer2 == 1 or str(buildlamer).lower() == 'yes': conf.Result(0) return False else: conf.Result(1) return True
def GenerateEnv(self, env): env['ENV']['PATH'] += ':%s' % Flags.CUDA_BIN_DIR env['NVCC'] = Flags.CUDA_NVCC_BIN env['CUDA_INC'] = Flags.CUDA_INC env['CUDA_SDK_COMMON_INC'] = Flags.CUDA_SDK_COMMON_INC env['CUDA_SDK_SHARED_INC'] = Flags.CUDA_SDK_SHARED_INC env['CUDACOM'] = ('$NVCC $NVCC_FLAGS -I. -I $CUDA_INC -I $CUDA_SDK_COMMON_INC ' '-I $CUDA_SDK_SHARED_INC -c -o $CUDAOUTOBJ ${SOURCES}') env['CUDAOUTOBJ'] = "" build_strategy = ARGUMENTS.get('c', 'dbg') if build_strategy == 'dbg': env['NVCC_FLAGS'] = ' '; elif build_strategy == 'opt': env['NVCC_FLAGS'] = '-O2 -DNDEBUG';
def new(env, path, verbose=int(ARGUMENTS.get("PIOVERBOSE", 0))): clsname = "UnknownLibBuilder" if isfile(join(path, "library.json")): clsname = "PlatformIOLibBuilder" else: used_frameworks = LibBuilderFactory.get_used_frameworks(env, path) common_frameworks = set(env.get("PIOFRAMEWORK", [])) & set(used_frameworks) if common_frameworks: clsname = "%sLibBuilder" % list(common_frameworks)[0].title() elif used_frameworks: clsname = "%sLibBuilder" % used_frameworks[0].title() obj = getattr(sys.modules[__name__], clsname)(env, path, verbose=verbose) assert isinstance(obj, LibBuilderBase) return obj
def __init__(self): LanguageBuilder.__init__(self) self._is_svn_client = Path.IsSVNClient() self._is_git_client = Path.IsGITClient() cpplint._cpplint_state.ResetErrorCounts() self._opend_files = set() self._checked_dir = set() self._always_test = ARGUMENTS.get('always_test', 'on') self._build_mode = ARGUMENTS.get('c', 'dbg') # self._check_lib_dep = ARGUMENTS.get('check_dep', 'on') self._check_style = ARGUMENTS.get('check_cpp_style', 'on') self._test_suffix = 'passed' self._access_checker = AccessChecker() self._lib_name_map = {} self._binaries = set() p = 'libs/gtest/lib%s.a' lib_base = self._GetStaticLib('//base:base', abort = False) if not lib_base: lib_base = self._GetLibName('//base:base') self._gtest_lib_source = [Path.GetAbsPath(x, abort = False) for x in (p % 'gtest_main', p % 'gmock', p % 'gtest')] + [lib_base] self._benchmark_lib_source = [Path.GetAbsPath(x, abort = False) for x in (p % 'benchmark_main', p % 'gtest')] + [lib_base] self._main_lib = [Path.GetAbsPath(Flags.MAIN_LIB, abort = False)]
def print_deps_tree(root, level=0): margin = "| " * (level) for lb in root.depbuilders: title = "<%s>" % lb.name vcs_info = lb.vcs_info if lb.version: title += " %s" % lb.version if vcs_info and vcs_info.get("version"): title += " #%s" % vcs_info.get("version") sys.stdout.write("%s|-- %s" % (margin, title)) if int(ARGUMENTS.get("PIOVERBOSE", 0)): if vcs_info: sys.stdout.write(" [%s]" % vcs_info.get("url")) sys.stdout.write(" (") sys.stdout.write(lb.path) sys.stdout.write(")") sys.stdout.write("\n") if lb.depbuilders: print_deps_tree(lb, level + 1)
def GetCustomizedOutputPath(obj = None): outDir = '' target = ARGUMENTS.get('t') if (target == 'mobile/mob_frontend' or target == 'mobile/mob_prod'): outDir = 'mobile' elif (target == 'mobilesearch/mobsearch_frontend' or target == 'mobilesearch/mobsearch_prod'): outDir = 'mobilesearch' elif (target == 'frontend/mobilesearchwap/wwwroot' or target == 'frontend/mobilesearchwap/prod'): outDir = 'frontend/mobilesearchwap' elif (target == 'frontend/weiboreaderm/wwwroot' or target == 'frontend/weiboreaderm/prod'): outDir = 'frontend/weiboreaderm' elif (target == 'searchmblog/smblog_frontend' or target == 'searchmblog/smblog_prod'): outDir = 'searchmblog' elif (target == 'frontend/wwwroot' or target == 'frontend/prod'): outDir = 'frontend' elif (target == 'app/app_frontend' or target == 'app/app_prod'): outDir = 'app' elif (target == 'frontend/yyreader/wwwroot' or target == 'frontend/yyreader/prod'): outDir = 'frontend/yyreader' elif (target == 'frontend/yysso/wwwroot' or target == 'frontend/yysso/prod'): outDir = 'frontend/yysso' elif (target == 'sinasearch/sinasearch_frontend' or target == 'sinasearch/sinasearch_prod'): outDir = 'sinasearch' elif (target == 'frontend/yyoauth/wwwroot' or target == 'frontend/yyoauth/prod'): outDir = 'frontend/yyoauth' return os.path.join(GetOutputDir(), outDir)
"--reset" ], UPLOADCMD="$UPLOADER $UPLOADERFLAGS $SOURCES" ) if board.get("build.core") == "adafruit": env.Append( UPLOADERFLAGS=["-U", "--offset", board.get("upload.offset_address")]) else: env.Append(UPLOADERFLAGS=[ "-U", "true" if env.BoardConfig().get("upload.native_usb", False) else "false" ]) if "sam3x8e" in build_mcu: env.Append(UPLOADERFLAGS=["--boot"]) if int(ARGUMENTS.get("PIOVERBOSE", 0)): env.Prepend(UPLOADERFLAGS=["--info", "--debug"]) upload_actions = [ env.VerboseAction(BeforeUpload, "Looking for upload port..."), env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE") ] elif upload_protocol == "stk500v2": env.Replace( UPLOADER="avrdude", UPLOADERFLAGS=[ "-p", "atmega2560", # Arduino M0/Tian upload hook "-C", join( platform.get_package_dir("tool-avrdude") or "", "avrdude.conf"),
def find(): python_include = ARGUMENTS.get('pythoninc') python_lib = ARGUMENTS.get('pythonlib') return (python_include, python_lib)
def __init__(self): LanguageBuilder.__init__(self) self._build_mode = ARGUMENTS.get('c', 'dbg')
def find(): boost_include = ARGUMENTS.get('boostinc') boost_lib = ARGUMENTS.get('boostlib') boost_lib_suffix = ARGUMENTS.get('boostlibsuf', '') return (boost_include, boost_lib, boost_lib_suffix)
# File : Proto.py # Brief : from LanguageBuilder import LanguageBuilder from LanguageBuilder import RegisterObj from SCons.Script import Action from SCons.Script import Builder from SCons.Script import ARGUMENTS import os import Cpp import Flags import Path import SCons.Util import Util _proto_bin = ARGUMENTS.get('proto_bin', '') def proto_library(name = None, srcs= [], deps = [], gen_cpp = '', gen_py = ''): if not name.endswith('_proto'): Util.Abort('proto lib\'s name should ends with "_proto"') if len(srcs) != 1 or not srcs[0].endswith('.proto'): Util.Abort('proto src should be only one .proto file') opt = {'gen_cpp':False, 'gen_py':False} if str(gen_cpp) == '1': opt['gen_cpp'] = True if str(gen_py) == '1': opt['gen_py'] = True RegisterObj(name, srcs, deps, opt, 'proto_library') def _proto_cpp_emitter(target, source, env):
from LanguageBuilder import LanguageBuilder from LanguageBuilder import RegisterObj from SCons.Script import Action from SCons.Script import Builder from SCons.Script import ARGUMENTS import os import Cpp import Flags import Path import SCons.Util import Util _thrift_bin = ARGUMENTS.get('thrift_bin', '') def thrift_library(name = None, srcs = [], deps = [], gen_cpp = '', gen_php = '', gen_py = ''): if not name.endswith('_thrift'): Util.Abort('thrift lib\'s name should ends with "_thirft": %s' % name) if len(srcs) != 1 or not srcs[0].endswith('.thrift'): Util.Abort('thrift src should be only one .thrift file: %s' % str(srcs)) opt = {'gen_cpp':False, 'gen_php':False, 'gen_py':False} if str(gen_cpp) == '1': opt['gen_cpp'] = True if str(gen_php) == '1': opt['gen_php'] = True if str(gen_py) == '1': opt['gen_py'] = True RegisterObj(name, srcs, deps, opt, 'thrift_library') def _GetServiceNames(file_path):
def generate(env): """Common environment generation code""" from SCons.Script import ARGUMENTS # Machine try: env['machine'] = ARGUMENTS['machine'] except KeyError: env['machine'] = _machine_map.get(os.environ.get('PROCESSOR_ARCHITECTURE', _platform.machine()), 'generic') # Toolchain try: env['toolchain'] = ARGUMENTS['toolchain'] except KeyError: if sys.platform != 'win32': env['toolchain'] = 'crossmingw' else: env['toolchain'] = 'default' if env['toolchain'] == 'crossmingw' and env['machine'] not in ('generic', 'x86'): env['machine'] = 'x86' # Build type env['debug'] = _bool_map[ARGUMENTS.get('debug', 'no')] env['profile'] = _bool_map[ARGUMENTS.get('profile', 'no')] # Put build output in a separate dir, which depends on the current # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample try: env['variant_dir'] = ARGUMENTS['variant_dir'] except KeyError: build_topdir = 'build' build_subdir = env['toolchain'] if env['machine'] != 'generic': build_subdir += '-' + env['machine'] if env['debug']: build_subdir += "-debug" if env['profile']: build_subdir += "-profile" env['variant_dir'] = os.path.join(build_topdir, build_subdir) # Place the .sconsign file in the build dir too, to avoid issues with # different scons versions building the same source file #env.VariantDir(env['variant_dir'] #env.SConsignFile(os.path.join(env['variant_dir'], '.sconsign')) # Parallel build if env.GetOption('num_jobs') <= 1: env.SetOption('num_jobs', num_jobs()) # Summary print print ' toolchain=%s' % env['toolchain'] print ' machine=%s' % env['machine'] print ' debug=%s' % ['no', 'yes'][env['debug']] print ' profile=%s' % ['no', 'yes'][env['profile']] #print ' variant_dir=%s' % env['variant_dir'] print # Load tool chain env.Tool(env['toolchain']) # shortcuts debug = env['debug'] machine = env['machine'] x86 = env['machine'] == 'x86' ppc = env['machine'] == 'ppc' gcc = 'gcc' in env['CC'].split('-') msvc = 'cl' in env['CC'] # C preprocessor options cppdefines = [] if debug: cppdefines += ['DEBUG'] else: cppdefines += ['NDEBUG'] if env['profile']: cppdefines += ['PROFILE'] cppdefines += [ 'WIN32', '_WINDOWS', #'_UNICODE', #'UNICODE', ('_WIN32_WINNT', '0x0501'), # minimum required OS version ('WINVER', '0x0501'), ] if msvc: cppdefines += [ # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx, 'VC_EXTRALEAN', '_CRT_SECURE_NO_DEPRECATE', ] if debug: cppdefines += ['_DEBUG'] env.Append(CPPDEFINES = cppdefines) # C compiler options cflags = [] # C cxxflags = [] # C++ ccflags = [] # C & C++ if gcc: if debug: ccflags += ['-O0', '-g3'] else: ccflags += ['-O3', '-g0'] if env['profile']: ccflags += ['-pg'] if env['machine'] == 'x86': ccflags += [ '-m32', ] if env['machine'] == 'x86_64': ccflags += ['-m64'] ccflags += [ '-Wall', '-Wno-long-long', '-fmessage-length=0', # be nice to Eclipse ] cflags += [ '-Wmissing-prototypes', ] if msvc: # See also: # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx # - cl /? if debug: ccflags += [ '/Od', # disable optimizations '/Oi', # enable intrinsic functions '/Oy-', # disable frame pointer omission ] else: ccflags += [ '/Ox', # maximum optimizations '/Oi', # enable intrinsic functions '/Ot', # favor code speed #'/fp:fast', # fast floating point ] if env['profile']: ccflags += [ '/Gh', # enable _penter hook function '/GH', # enable _pexit hook function ] ccflags += [ '/W3', # warning level #'/Wp64', # enable 64 bit porting warnings ] if env['machine'] == 'x86': ccflags += [ #'/QIfist', # Suppress _ftol #'/arch:SSE2', # use the SSE2 instructions ] # Automatic pdb generation # See http://scons.tigris.org/issues/show_bug.cgi?id=1656 env.EnsureSConsVersion(0, 98, 0) env['PDB'] = '${TARGET.base}.pdb' env.Append(CCFLAGS = ccflags) env.Append(CFLAGS = cflags) env.Append(CXXFLAGS = cxxflags) if msvc: # Choose the appropriate MSVC CRT # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx if env['debug']: env.Append(CCFLAGS = ['/MTd']) env.Append(SHCCFLAGS = ['/LDd']) else: env.Append(CCFLAGS = ['/MT']) env.Append(SHCCFLAGS = ['/LD']) # Assembler options if gcc: if env['machine'] == 'x86': env.Append(ASFLAGS = ['-m32']) if env['machine'] == 'x86_64': env.Append(ASFLAGS = ['-m64']) # Linker options linkflags = [] if gcc: if env['machine'] == 'x86': linkflags += ['-m32'] if env['machine'] == 'x86_64': linkflags += ['-m64'] if msvc: # See also: # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx if env['profile']: linkflags += [ '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx ] env.Append(LINKFLAGS = linkflags) # Default libs env.Append(LIBS = [])
def CheckUploadSize(_, target, source, env): check_conditions = [ env.get("BOARD"), env.get("SIZETOOL") or env.get("SIZECHECKCMD") ] if not all(check_conditions): return program_max_size = int(env.BoardConfig().get("upload.maximum_size", 0)) data_max_size = int(env.BoardConfig().get("upload.maximum_ram_size", 0)) if program_max_size == 0: return def _configure_defaults(): env.Replace( SIZECHECKCMD="$SIZETOOL -B -d $SOURCES", SIZEPROGREGEXP=r"^(\d+)\s+(\d+)\s+\d+\s", SIZEDATAREGEXP=r"^\d+\s+(\d+)\s+(\d+)\s+\d+") def _get_size_output(): cmd = env.get("SIZECHECKCMD") if not cmd: return None if not isinstance(cmd, list): cmd = cmd.split() cmd = [arg.replace("$SOURCES", str(source[0])) for arg in cmd if arg] sysenv = environ.copy() sysenv['PATH'] = str(env['ENV']['PATH']) result = util.exec_command(env.subst(cmd), env=sysenv) if result['returncode'] != 0: return None return result['out'].strip() def _calculate_size(output, pattern): if not output or not pattern: return -1 size = 0 regexp = re.compile(pattern) for line in output.split("\n"): line = line.strip() if not line: continue match = regexp.search(line) if not match: continue size += sum(int(value) for value in match.groups()) return size def _format_availale_bytes(value, total): percent_raw = float(value) / float(total) blocks_per_progress = 10 used_blocks = int(round(blocks_per_progress * percent_raw)) if used_blocks > blocks_per_progress: used_blocks = blocks_per_progress return "[{:{}}] {: 6.1%} (used {:d} bytes from {:d} bytes)".format( "=" * used_blocks, blocks_per_progress, percent_raw, value, total) if not env.get("SIZECHECKCMD") and not env.get("SIZEPROGREGEXP"): _configure_defaults() output = _get_size_output() program_size = _calculate_size(output, env.get("SIZEPROGREGEXP")) data_size = _calculate_size(output, env.get("SIZEDATAREGEXP")) print("Memory Usage -> http://bit.ly/pio-memory-usage") if data_max_size and data_size > -1: print("DATA: %s" % _format_availale_bytes(data_size, data_max_size)) if program_size > -1: print("PROGRAM: %s" % _format_availale_bytes(program_size, program_max_size)) if int(ARGUMENTS.get("PIOVERBOSE", 0)): print(output) # raise error # if data_max_size and data_size > data_max_size: # sys.stderr.write( # "Error: The data size (%d bytes) is greater " # "than maximum allowed (%s bytes)\n" % (data_size, data_max_size)) # env.Exit(1) if program_size > program_max_size: sys.stderr.write("Error: The program size (%d bytes) is greater " "than maximum allowed (%s bytes)\n" % (program_size, program_max_size)) env.Exit(1)
PROJECTTEST_DIR=util.get_projecttest_dir(), PROJECTDATA_DIR=util.get_projectdata_dir(), PROJECTBUILD_DIR=util.get_projectbuild_dir(), BUILD_DIR=join("$PROJECTBUILD_DIR", "$PIOENV"), BUILDSRC_DIR=join("$BUILD_DIR", "src"), BUILDTEST_DIR=join("$BUILD_DIR", "test"), LIBSOURCE_DIRS=[ util.get_projectlib_dir(), util.get_projectlibdeps_dir(), join("$PIOHOME_DIR", "lib") ], PROGNAME="program", PROG_PATH=join("$BUILD_DIR", "$PROGNAME$PROGSUFFIX"), PYTHONEXE=util.get_pythonexe_path()) if not int(ARGUMENTS.get("PIOVERBOSE", 0)): DEFAULT_ENV_OPTIONS['ARCOMSTR'] = "Archiving $TARGET" DEFAULT_ENV_OPTIONS['LINKCOMSTR'] = "Linking $TARGET" DEFAULT_ENV_OPTIONS['RANLIBCOMSTR'] = "Indexing $TARGET" for k in ("ASCOMSTR", "ASPPCOMSTR", "CCCOMSTR", "CXXCOMSTR"): DEFAULT_ENV_OPTIONS[k] = "Compiling $TARGET" env = DefaultEnvironment(**DEFAULT_ENV_OPTIONS) # decode common variables for k in commonvars.keys(): if k in env: env[k] = base64.b64decode(env[k]) if k in MULTILINE_VARS: env[k] = util.parse_conf_multi_values(env[k])
def GetLibBuilders(env): # pylint: disable=too-many-branches if "__PIO_LIB_BUILDERS" in DefaultEnvironment(): return DefaultEnvironment()['__PIO_LIB_BUILDERS'] items = [] compat_mode = int(env.get("LIB_COMPAT_MODE", 1)) verbose = (int(ARGUMENTS.get("PIOVERBOSE", 0)) and not env.GetOption('clean')) def _check_lib_builder(lb): if lb.name in env.get("LIB_IGNORE", []): if verbose: sys.stderr.write("Ignored library %s\n" % lb.path) return if compat_mode > 1 and not lb.is_platforms_compatible( env['PIOPLATFORM']): if verbose: sys.stderr.write( "Platform incompatible library %s\n" % lb.path) return False if compat_mode > 0 and "PIOFRAMEWORK" in env and \ not lb.is_frameworks_compatible(env.get("PIOFRAMEWORK", [])): if verbose: sys.stderr.write( "Framework incompatible library %s\n" % lb.path) return False return True found_incompat = False for libs_dir in env['LIBSOURCE_DIRS']: libs_dir = env.subst(libs_dir) if not isdir(libs_dir): continue for item in sorted(os.listdir(libs_dir)): if item == "__cores__" or not isdir(join(libs_dir, item)): continue try: lb = LibBuilderFactory.new( env, join(libs_dir, item), verbose=verbose) except ValueError: if verbose: sys.stderr.write("Skip library with broken manifest: %s\n" % join(libs_dir, item)) continue if _check_lib_builder(lb): items.append(lb) else: found_incompat = True for lb in env.get("EXTRA_LIB_BUILDERS", []): if _check_lib_builder(lb): items.append(lb) else: found_incompat = True if verbose and found_incompat: sys.stderr.write( "More details about \"Library Compatibility Mode\": " "http://docs.platformio.org/page/librarymanager/ldf.html#" "ldf-compat-mode\n") DefaultEnvironment()['__PIO_LIB_BUILDERS'] = items return items
def VerboseAction(_, act, actstr): if int(ARGUMENTS.get("PIOVERBOSE", 0)): return act else: return Action(act, actstr)
from SCons.Script import ARGUMENTS import os import re import Flags import Util _base_dir = os.path.normpath(ARGUMENTS.get('base_dir')) def GetBaseDir(): """root dir of the code base.""" return _base_dir def GetOutputDir(): """'.snake-out/opt' or '.snake-out/dbg'""" strategy = ARGUMENTS.get('c', 'dbg') return os.path.join(GetBaseDir(), Flags.SNAKE_OUT, strategy) def GetSnakeFilePath(logical_path): """'//base/internal:base' --> '~/$ROOT/base/internal/SNAKE'""" assert logical_path.startswith('//') and logical_path.find(':') != -1 , "INPUT : %s" % logical_path snake_path = os.path.join(logical_path.split(':')[0], Flags.SNAKE_NAME) return GetAbsPath(snake_path, abort = True) def IsInDir(file_path, dir_path): """Is file_path in dir_path?""" dir_path = os.path.normpath(dir_path) + '/' return file_path.startswith(dir_path)
import glob import hashlib import inspect import os import re import subprocess import sys import time import Flags import SCons import socket import fcntl import struct import stat _verbose = int(ARGUMENTS.get('verbose', '1')) def GetIp(ifname): """get the ip of host""" s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, # SIOCGIFADDR struct.pack('256s', ifname[:15]) )[20:24] ) def Log(msg, v = 0): """print log info""" if v < _verbose: return s = inspect.stack() prefix = ''
def GetOutputDir(): """'.snake-out/opt' or '.snake-out/dbg'""" strategy = ARGUMENTS.get('c', 'dbg') return os.path.join(GetBaseDir(), Flags.SNAKE_OUT, strategy)