def ld_flags(): r"""Get the linker flags necessary for calling functions/classes from the interface library in a C or C++ program. Returns: list: The necessary library linking flags. """ from yggdrasil import platform parser = argparse.ArgumentParser( description='Get the linker flags necessary for a C/C++ program.') parser.add_argument('--cpp', action='store_true', help='Get linker flags for a C++ program.') parser.add_argument('--toolname', default=None, help=('Name of the tool that associated flags should ' 'be returned for.')) args = parser.parse_args() if args.cpp: from yggdrasil.drivers.CPPModelDriver import CPPModelDriver as driver else: from yggdrasil.drivers.CModelDriver import CModelDriver as driver out = ' '.join( driver.get_linker_flags(for_model=True, toolname=args.toolname, dry_run=True)) if platform._is_win: # pragma: windows: out = out.replace('/', '-') out = out.replace('\\', '/') # out = out.encode('unicode_escape').decode('utf-8') print(out)
def compile_osr(cls, target='OpenSimRootYgg'): r"""Compile the OpenSimRoot executable with the yggdrasil flag set. Args: target (str): Make target that should be build. Defaults to 'OpenSimRootYgg' (the yggdrasil-instrumented version of the OSR executable). """ if (cls.repository is not None) and CPPModelDriver.is_installed(): toolname = None # toolname = CPPModelDriver.get_tool('compiler', # return_prop='name', # default=None) cwd = os.path.join(cls.repository, 'OpenSimRoot') flags = ['-j4'] env = copy.deepcopy(os.environ) if platform._is_win: # pragma: windows toolname = 'cl' env['YGG_OSR_TOOL'] = toolname if toolname == 'cl': cl_path = shutil.which(toolname + '.exe') print('cl.exe', shutil.which(toolname), cl_path) subprocess.check_call( ['yggccflags', '--cpp', '--toolname=%s' % toolname]) subprocess.check_call( ['yggldflags', '--cpp', '--toolname=%s' % toolname]) if cl_path: msvc_bin = os.path.dirname(cl_path) env['YGG_OSR_CXX'] = cl_path env['YGG_OSR_LINK'] = os.path.join( msvc_bin, 'link.exe') for k in ['CL', '_CL_']: v = os.environ.get(k, None) if v is not None: env[k] = v.replace('/', '-').replace('\\', '/') else: # pragma: debug env.pop('YGG_OSR_TOOL') warnings.warn( "The MSVC compiler is not installed. Be aware " "that the GNU compiler takes a *very* long time " "to compile OpenSimRoot against yggdrasil on " "Windows (> 1 hr).") cwd = os.path.join(cwd, 'StaticBuild_win64') else: cwd = os.path.join(cwd, 'StaticBuild') if target != 'cleanygg': for x in cls.base_languages: base_cls = import_component('model', x) base_cls.compile_dependencies(toolname=toolname) elif not os.path.isfile(cls.executable_path): return cmd = ['make', target] + flags subprocess.check_call(cmd, cwd=cwd, env=env)
def test_call_compiler(self, python_class, instance): r"""Test call_compiler without full path.""" # instance.cleanup() CPPModelDriver.compile_dependencies() python_class.call_compiler(instance.source_files, builddir='build', working_dir=instance.working_dir, dont_build=True) out = instance.model_file if platform._is_win: out = os.path.join(os.path.dirname(out), 'Debug', os.path.basename(out)) compiler = CPPModelDriver.get_tool('compiler') python_class.call_compiler(instance.source_files, out=out, builddir='build', working_dir=instance.working_dir, overwrite=True, target_compiler=compiler.toolname, target_linker=compiler.linker().toolname)
def set_env_class(cls, **kwargs): r"""Set environment variables that are instance independent. Args: **kwargs: Additional keyword arguments are passed to the parent class's method. Returns: dict: Environment variables for the model process. """ out = super(OSRModelDriver, cls).set_env_class(**kwargs) if cls.repository is not None: out['OSR_REPOSITORY'] = cls.repository kwargs['existing'] = out out = CPPModelDriver.set_env_class(**kwargs) return out