예제 #1
0
    def default_profile(self):
        if self._default_profile is None:
            if not os.path.exists(self.default_profile_path):
                self._output.writeln(
                    "Auto detecting your dev setup to initialize the "
                    "default profile (%s)" % self.default_profile_path,
                    Color.BRIGHT_YELLOW)

                default_settings = detect_defaults_settings(self._output)
                self._output.writeln("Default settings", Color.BRIGHT_YELLOW)
                self._output.writeln(
                    "\n".join(
                        ["\t%s=%s" % (k, v) for (k, v) in default_settings]),
                    Color.BRIGHT_YELLOW)
                self._output.writeln(
                    "*** You can change them in %s ***" %
                    self.default_profile_path, Color.BRIGHT_MAGENTA)
                self._output.writeln(
                    "*** Or override with -s compiler='other' -s ...s***\n\n",
                    Color.BRIGHT_MAGENTA)

                self._default_profile = Profile()
                tmp = OrderedDict(default_settings)
                self._default_profile.update_settings(tmp)
                save(self.default_profile_path, self._default_profile.dumps())
            else:
                self._default_profile, _ = read_profile(
                    self.default_profile_path, get_cwd(), self.profiles_path)

            # Mix profile settings with environment
            mixed_settings = _mix_settings_with_env(
                self._default_profile.settings)
            self._default_profile.settings = mixed_settings

        return self._default_profile
예제 #2
0
def _load_profile(text, profile_path, default_folder):
    """ Parse and return a Profile object from a text config like representation.
        cwd is needed to be able to load the includes
    """
    try:
        inherited_profile = Profile()
        cwd = os.path.dirname(os.path.abspath(profile_path)) if profile_path else None
        profile_parser = ProfileParser(text)
        # Iterate the includes and call recursive to get the profile and variables
        # from parent profiles
        for include in profile_parser.get_includes():
            # Recursion !!
            profile, included_vars = read_profile(include, cwd, default_folder)
            inherited_profile.update(profile)
            profile_parser.update_vars(included_vars)

        # Apply the automatic PROFILE_DIR variable
        if cwd:
            profile_parser.vars["PROFILE_DIR"] = os.path.abspath(cwd).replace('\\', '/')

        # Replace the variables from parents in the current profile
        profile_parser.apply_vars()

        # Current profile before update with parents (but parent variables already applied)
        doc = ConfigParser(profile_parser.profile_text,
                           allowed_fields=["build_requires", "settings", "env", "options", "conf"])

        # Merge the inherited profile with the readed from current profile
        _apply_inner_profile(doc, inherited_profile)

        return inherited_profile, profile_parser.vars
    except ConanException:
        raise
    except Exception as exc:
        raise ConanException("Error parsing the profile text file: %s" % str(exc))
예제 #3
0
 def _create_profile(self, name, settings, scopes=None, env=None):
     profile = Profile()
     profile.settings = settings or {}
     if scopes:
         profile.scopes = Scopes.from_list(["%s=%s" % (key, value) for key, value in scopes.items()])
     profile.env = env or {}
     save(self.client.client_cache.profile_path(name), profile.dumps())
예제 #4
0
 def _create_profile(self, name, settings, env=None):
     env = env or {}
     profile = Profile()
     profile._settings = settings or {}
     for varname, value in env.items():
         profile.env_values.add(varname, value)
     save(os.path.join(self.client.client_cache.profiles_path, name), "include(default)\n" + profile.dumps())
예제 #5
0
    def build_graph(self,
                    content,
                    profile_build_requires=None,
                    ref=None,
                    create_ref=None,
                    install=True):
        path = temp_folder()
        path = os.path.join(path, "conanfile.py")
        save(path, str(content))
        self.loader.cached_conanfiles = {}

        profile = Profile()
        if profile_build_requires:
            profile.build_requires = profile_build_requires
        profile.process_settings(self.cache)
        update = check_updates = False
        recorder = ActionRecorder()
        remotes = Remotes()
        build_mode = []  # Means build all
        ref = ref or ConanFileReference(None, None, None, None, validate=False)
        options = OptionsValues()
        graph_info = GraphInfo(profile, options, root_ref=ref)
        deps_graph, _ = self.manager.load_graph(path, create_ref, graph_info,
                                                build_mode, check_updates,
                                                update, remotes, recorder)
        if install:
            self.binary_installer.install(deps_graph, None, False, graph_info)
        return deps_graph
예제 #6
0
 def _create_profile(self, name, settings, env=None):
     env = env or {}
     profile = Profile()
     profile._settings = settings or {}
     for varname, value in env.items():
         profile.env_values.add(varname, value)
     save(os.path.join(self.client.cache.profiles_path, name), "include(default)\n" + profile.dumps())
예제 #7
0
    def _loader(self, conan_info_path=None, profile=None):
        # The disk settings definition, already including the default disk values
        settings = self._client_cache.settings
        mixed_profile = Profile()
        if profile is None:
            if conan_info_path and os.path.exists(conan_info_path):
                existing_info = ConanInfo.load_file(conan_info_path)
                settings.values = existing_info.full_settings
                mixed_profile.options = existing_info.full_options
                mixed_profile.scopes = existing_info.scope
                mixed_profile.env_values = existing_info.env_values
        else:
            mixed_profile.env_values.update(profile.env_values)
            settings.values = profile.settings_values
            if profile.scopes:
                mixed_profile.scopes.update_scope(profile.scopes)
            mixed_profile.options.update(profile.options)
            for pkg, pkg_settings in profile.package_settings.items():
                mixed_profile.package_settings[pkg].update(pkg_settings)

        self._current_scopes = mixed_profile.scopes
        return ConanFileLoader(
            self._runner,
            settings=settings,
            package_settings=mixed_profile.package_settings_values,
            options=mixed_profile.options,
            scopes=mixed_profile.scopes,
            env_values=mixed_profile.env_values)
예제 #8
0
    def test_package_settings(self):
        # CREATE A CONANFILE TO LOAD
        tmp_dir = temp_folder()
        conanfile_path = os.path.join(tmp_dir, "conanfile.py")
        conanfile = """from conans import ConanFile
class MyTest(ConanFile):
    requires = {}
    name = "MyPackage"
    version = "1.0"
    settings = "os"
"""
        save(conanfile_path, conanfile)

        # Apply windows for MyPackage
        profile = Profile()
        profile.package_settings = {"MyPackage": OrderedDict([("os", "Windows")])}
        loader = ConanFileLoader(None, Settings({"os": ["Windows", "Linux"]}), profile)

        recipe = loader.load_conan(conanfile_path, None)
        self.assertEquals(recipe.settings.os, "Windows")

        # Apply Linux for MyPackage
        profile.package_settings = {"MyPackage": OrderedDict([("os", "Linux")])}
        loader = ConanFileLoader(None, Settings({"os": ["Windows", "Linux"]}), profile)

        recipe = loader.load_conan(conanfile_path, None)
        self.assertEquals(recipe.settings.os, "Linux")

        # If the package name is different from the conanfile one, it wont apply
        profile.package_settings = {"OtherPACKAGE": OrderedDict([("os", "Linux")])}
        loader = ConanFileLoader(None, Settings({"os": ["Windows", "Linux"]}), profile)

        recipe = loader.load_conan(conanfile_path, None)
        self.assertIsNone(recipe.settings.os.value)
예제 #9
0
 def build_consumer(self,
                    path,
                    profile_build_requires=None,
                    ref=None,
                    create_ref=None,
                    install=True):
     profile = Profile()
     if profile_build_requires:
         profile.build_requires = profile_build_requires
     profile.process_settings(self.cache)
     update = check_updates = False
     recorder = ActionRecorder()
     remotes = Remotes()
     build_mode = []  # Means build all
     ref = ref or ConanFileReference(None, None, None, None, validate=False)
     options = OptionsValues()
     graph_info = GraphInfo(profile, options, root_ref=ref)
     app = self._get_app()
     deps_graph = app.graph_manager.load_graph(path, create_ref, graph_info,
                                               build_mode, check_updates,
                                               update, remotes, recorder)
     if install:
         binary_installer = BinaryInstaller(app, recorder)
         build_mode = BuildMode(build_mode, app.out)
         binary_installer.install(deps_graph, None, build_mode, update,
                                  False, graph_info)
     return deps_graph
예제 #10
0
    def profile_loads_test(self):
        prof = '''[env]
CXX_FLAGS="-DAAA=0"
[settings]
'''
        new_profile = Profile.loads(prof)
        self.assertEquals(new_profile.env["CXX_FLAGS"], "-DAAA=0")

        prof = '''[env]
CXX_FLAGS='-DAAA=0'
[settings]
'''
        new_profile = Profile.loads(prof)
        self.assertEquals(new_profile.env["CXX_FLAGS"], "-DAAA=0")

        prof = '''[env]
CXX_FLAGS=-DAAA=0
[settings]
'''
        new_profile = Profile.loads(prof)
        self.assertEquals(new_profile.env["CXX_FLAGS"], "-DAAA=0")

        prof = '''[env]
CXX_FLAGS="-DAAA=0
[settings]
'''
        new_profile = Profile.loads(prof)
        self.assertEquals(new_profile.env["CXX_FLAGS"], "\"-DAAA=0")
예제 #11
0
파일: profile.py 프로젝트: xaqq/conan
def cmd_profile_create(profile_name,
                       cache_profiles_path,
                       output,
                       detect=False):
    profile_path = get_profile_path(profile_name,
                                    cache_profiles_path,
                                    get_cwd(),
                                    exists=False)
    if os.path.exists(profile_path):
        raise ConanException("Profile already exists")

    profile = Profile()
    if detect:
        settings = detect_defaults_settings(output)
        for name, value in settings:
            profile.settings[name] = value

    contents = profile.dumps()
    save(profile_path, contents)

    if detect:
        output.info("Profile created with detected settings: %s" %
                    profile_path)
    else:
        output.info("Empty profile created: %s" % profile_path)
    return profile_path
예제 #12
0
 def _create_profile(self, name, settings, scopes=None, env=None):
     env = env or {}
     profile = Profile()
     profile._settings = settings or {}
     if scopes:
         profile.scopes = Scopes.from_list(["%s=%s" % (key, value) for key, value in scopes.items()])
     for varname, value in env.items():
         profile.env_values.add(varname, value)
     save(os.path.join(self.client.client_cache.profiles_path, name), profile.dumps())
예제 #13
0
    def profile_dump_order_test(self):
        # Settings
        profile = Profile()
        profile.settings["compiler.version"] = "12"
        profile.settings["arch"] = "x86_64"
        profile.settings["compiler"] = "Visual Studio"

        self.assertEqual('[settings]\narch=x86_64\ncompiler=Visual Studio\ncompiler.version=12\n[scopes]\n[env]',
                         profile.dumps())
예제 #14
0
 def _create_profile(self, name, settings, scopes=None, env=None):
     env = env or {}
     profile = Profile()
     profile._settings = settings or {}
     if scopes:
         profile.scopes = Scopes.from_list(["%s=%s" % (key, value) for key, value in scopes.items()])
     for varname, value in env.items():
         profile.env_values.add(varname, value)
     save(os.path.join(self.client.client_cache.profiles_path, name), profile.dumps())
예제 #15
0
    def profile_dump_order_test(self):
        # Settings
        profile = Profile()
        profile.settings["compiler.version"] = "12"
        profile.settings["arch"] = "x86_64"
        profile.settings["compiler"] = "Visual Studio"

        self.assertEqual(
            '[settings]\narch=x86_64\ncompiler=Visual Studio\ncompiler.version=12\n[scopes]\n[env]',
            profile.dumps())
예제 #16
0
def read_conaninfo_profile(current_path):
    conan_info_path = os.path.join(current_path, CONANINFO)
    if not os.path.exists(conan_info_path):
        return None
    existing_info = ConanInfo.load_file(conan_info_path)
    profile = Profile()
    profile.settings = OrderedDict(existing_info.full_settings.as_list())
    profile.options = existing_info.full_options
    profile.env_values = existing_info.env_values
    return profile
예제 #17
0
def _profile_parse_args(settings, options, envs):
    """ return a Profile object result of parsing raw data
    """
    def _get_tuples_list_from_extender_arg(items):
        if not items:
            return []
        # Validate the pairs
        for item in items:
            chunks = item.split("=", 1)
            if len(chunks) != 2:
                raise ConanException("Invalid input '%s', use 'name=value'" % item)
        return [(item[0], item[1]) for item in [item.split("=", 1) for item in items]]

    def _get_simple_and_package_tuples(items):
        """Parse items like "thing:item=value or item2=value2 and returns a tuple list for
        the simple items (name, value) and a dict for the package items
        {package: [(item, value)...)], ...}
        """
        simple_items = []
        package_items = defaultdict(list)
        tuples = _get_tuples_list_from_extender_arg(items)
        for name, value in tuples:
            if ":" in name:  # Scoped items
                tmp = name.split(":", 1)
                ref_name = tmp[0]
                name = tmp[1]
                package_items[ref_name].append((name, value))
            else:
                simple_items.append((name, value))
        return simple_items, package_items

    def _get_env_values(env, package_env):
        env_values = EnvValues()
        for name, value in env:
            env_values.add(name, EnvValues.load_value(value))
        for package, data in package_env.items():
            for name, value in data:
                env_values.add(name, EnvValues.load_value(value), package)
        return env_values

    result = Profile()
    options = _get_tuples_list_from_extender_arg(options)
    result.options = OptionsValues(options)
    env, package_env = _get_simple_and_package_tuples(envs)
    env_values = _get_env_values(env, package_env)
    result.env_values = env_values
    settings, package_settings = _get_simple_and_package_tuples(settings)
    result.settings = OrderedDict(settings)
    for pkg, values in package_settings.items():
        result.package_settings[pkg] = OrderedDict(values)
    return result
예제 #18
0
def create_profile(folder,
                   name,
                   settings=None,
                   scopes=None,
                   package_settings=None,
                   env=None,
                   package_env=None):

    package_env = package_env or {}

    profile = Profile()
    profile._settings = settings or {}
    if scopes:
        profile.scopes = Scopes.from_list(
            ["%s=%s" % (key, value) for key, value in scopes.items()])

    if package_settings:
        profile._package_settings = package_settings

    for package_name, envs in package_env.items():
        for var_name, value in envs:
            profile._package_env[package_name][var_name] = value

    for var_name, value in env or {}:
        profile._env[var_name] = value

    save(os.path.join(folder, name), profile.dumps())
예제 #19
0
파일: conan_api.py 프로젝트: zomeck/conan
    def create_profile(self, profile_name, detect=False):
        profile_path = get_profile_path(profile_name, self._client_cache.profiles_path, os.getcwd())
        if os.path.exists(profile_path):
            raise ConanException("Profile already exists")

        profile = Profile()
        if detect:
            settings = detect_defaults_settings(self._user_io.out)
            for name, value in settings:
                profile.settings[name] = value

        contents = profile.dumps()
        save(profile_path, contents)
        self._user_io.out.info("Empty profile created: %s" % profile_path)
        return profile_path
예제 #20
0
def _get_profile(build_conf):
    tmp = """
[settings]
%s
[options]
%s
[env]
%s
[build_requires]
%s
"""
    settings = "\n".join(["%s=%s" % (k, v) for k, v in sorted(build_conf.settings.items())])
    options = "\n".join(["%s=%s" % (k, v) for k, v in build_conf.options.items()])
    env_vars = "\n".join(["%s=%s" % (k, v) for k, v in build_conf.env_vars.items()])
    br_lines = ""
    for pattern, build_requires in build_conf.build_requires.items():
        br_lines += "\n".join(["%s:%s" % (pattern, br) for br in build_requires])

    profile_text = tmp % (settings, options, env_vars, br_lines)
    # FIXME: Remove when conan==0.24.0
    if hasattr(Profile, "loads"):
        return Profile.loads(profile_text)
    else:
        # Fixme, make public in conan?
        from conans.client.profile_loader import _load_profile
        return _load_profile(profile_text, None, None)[0]
예제 #21
0
파일: manager.py 프로젝트: conan-io/conan
    def read_profile(self, profile_name, cwd):
        if not profile_name:
            return None

        if os.path.isabs(profile_name):
            profile_path = profile_name
            folder = os.path.dirname(profile_name)
        elif profile_name.startswith("."):  # relative path name
            profile_path = os.path.abspath(os.path.join(cwd, profile_name))
            folder = os.path.dirname(profile_path)
        else:
            folder = self._client_cache.profiles_path
            profile_path = self._client_cache.profile_path(profile_name)

        try:
            text = load(profile_path)
        except Exception:
            if os.path.exists(folder):
                profiles = [name for name in os.listdir(folder) if not os.path.isdir(name)]
            else:
                profiles = []
            current_profiles = ", ".join(profiles) or "[]"
            raise ConanException("Specified profile '%s' doesn't exist.\nExisting profiles: "
                                 "%s" % (profile_name, current_profiles))

        try:
            return Profile.loads(text)
        except ConanException as exc:
            raise ConanException("Error reading '%s' profile: %s" % (profile_name, exc))
예제 #22
0
    def read_profile(self, profile_name, cwd):
        if not profile_name:
            return None

        if os.path.isabs(profile_name):
            profile_path = profile_name
            folder = os.path.dirname(profile_name)
        elif profile_name.startswith("."):  # relative path name
            profile_path = os.path.abspath(os.path.join(cwd, profile_name))
            folder = os.path.dirname(profile_path)
        else:
            folder = self._client_cache.profiles_path
            profile_path = self._client_cache.profile_path(profile_name)

        try:
            text = load(profile_path)
        except Exception:
            if os.path.exists(folder):
                profiles = [name for name in os.listdir(folder) if not os.path.isdir(name)]
            else:
                profiles = []
            current_profiles = ", ".join(profiles) or "[]"
            raise ConanException("Specified profile '%s' doesn't exist.\nExisting profiles: "
                                 "%s" % (profile_name, current_profiles))

        try:
            return Profile.loads(text)
        except ConanException as exc:
            raise ConanException("Error reading '%s' profile: %s" % (profile_name, exc))
예제 #23
0
파일: loader_test.py 프로젝트: stkw0/conan
    def setUp(self):
        settings = Settings()
        self.profile = Profile()
        self.profile.processed_settings = settings

        output = TestBufferConanOutput()
        self.loader = ConanFileLoader(None, output,
                                      ConanPythonRequire(None, None))
예제 #24
0
    def test_not_crossbuilding(self):
        """ Build_requires uses 'force_host_context=False', but no profile for build_machine """
        profile_host = Profile()
        profile_host.settings["os"] = "Host"
        profile_host.process_settings(self.cache)

        try:
            deps_graph = self._build_graph(profile_host=profile_host,
                                           profile_build=None,
                                           install=True)
        except Exception as e:
            self.fail(
                "ERROR! Although the recipe specifies 'force_host_context=False', as we"
                " are not providing a profile for the build_machine, the context will be"
                " host for this build_require.\n Exception has been: {}".
                format(e))
        else:
            # Check packages (all are HOST packages)
            application = deps_graph.root.dependencies[0].dst
            self.assertEqual(len(application.dependencies), 3)
            self.assertEqual(application.conanfile.name, "app")
            self.assertEqual(application.context, CONTEXT_HOST)
            self.assertEqual(application.conanfile.settings.os,
                             profile_host.settings['os'])

            protobuf_host = application.dependencies[0].dst
            self.assertEqual(protobuf_host.conanfile.name, "protobuf")
            self.assertEqual(protobuf_host.context, CONTEXT_HOST)
            self.assertEqual(protobuf_host.conanfile.settings.os,
                             profile_host.settings['os'])

            protoc_host = application.dependencies[1].dst
            self.assertEqual(protoc_host.conanfile.name, "protoc")
            self.assertEqual(protoc_host.context, CONTEXT_HOST)
            self.assertEqual(protoc_host.conanfile.settings.os,
                             profile_host.settings['os'])

            protoc_protobuf_host = protoc_host.dependencies[0].dst
            self.assertEqual(protoc_protobuf_host, protobuf_host)

            gtest_host = application.dependencies[2].dst
            self.assertEqual(gtest_host.conanfile.name, "gtest")
            self.assertEqual(gtest_host.context, CONTEXT_HOST)
            self.assertEqual(gtest_host.conanfile.settings.os,
                             profile_host.settings['os'])
예제 #25
0
def create_profile(folder,
                   name,
                   settings=None,
                   scopes=None,
                   package_settings=None,
                   env=None,
                   package_env=None,
                   options=None):

    package_env = package_env or {}

    profile = Profile()
    profile.settings = settings or {}
    if scopes:
        profile.scopes = Scopes.from_list(
            ["%s=%s" % (key, value) for key, value in scopes.items()])

    if package_settings:
        profile.package_settings = package_settings

    if options:
        profile.options = OptionsValues(options)

    for package_name, envs in package_env.items():
        for var_name, value in envs:
            profile.env_values.add(var_name, value, package_name)

    for var_name, value in env or {}:
        profile.env_values.add(var_name, value)

    save(os.path.join(folder, name), profile.dumps())
    def test_crossbuilding(self):
        profile_host = Profile()
        profile_host.settings["os"] = "Host"
        profile_host.process_settings(self.cache)

        profile_build = Profile()
        profile_build.settings["os"] = "Build"
        profile_build.process_settings(self.cache)

        deps_graph = self._build_graph(profile_host=profile_host,
                                       profile_build=profile_build)

        # Check HOST packages
        application = deps_graph.root.dependencies[0].dst
        self.assertEqual(len(application.dependencies), 2)
        self.assertEqual(application.conanfile.name, "app")
        self.assertEqual(application.context, CONTEXT_HOST)
        self.assertEqual(application.conanfile.settings.os,
                         profile_host.settings['os'])

        lib_host = application.dependencies[0].dst
        self.assertEqual(lib_host.conanfile.name, "lib")
        self.assertEqual(lib_host.context, CONTEXT_HOST)
        self.assertEqual(lib_host.conanfile.settings.os,
                         profile_host.settings['os'])

        # Check BUILD packages
        breq_application_build = application.dependencies[1].dst
        self.assertEqual(breq_application_build.conanfile.name, "breq")
        self.assertEqual(breq_application_build.context, CONTEXT_BUILD)
        self.assertEqual(str(breq_application_build.conanfile.settings.os),
                         profile_build.settings['os'])

        breq_lib_build = lib_host.dependencies[0].dst
        self.assertNotEqual(breq_application_build, breq_lib_build)
        self.assertEqual(breq_lib_build.conanfile.name, "breq")
        self.assertEqual(breq_lib_build.context, CONTEXT_BUILD)
        self.assertEqual(str(breq_lib_build.conanfile.settings.os),
                         profile_build.settings['os'])

        breq_lib_build = breq_application_build.dependencies[0].dst
        self.assertEqual(breq_lib_build.conanfile.name, "breq_lib")
        self.assertEqual(breq_lib_build.context, CONTEXT_BUILD)
        self.assertEqual(str(breq_lib_build.conanfile.settings.os),
                         profile_build.settings['os'])
예제 #27
0
 def setUp(self):
     settings = Settings()
     self.profile = Profile()
     self.profile._settings = settings
     self.profile._user_options = None
     self.profile._env_values = None
     self.conanfile_txt_path = os.path.join(temp_folder(), "conanfile.txt")
     output = TestBufferConanOutput()
     self.loader = ConanFileLoader(None, output, None)
예제 #28
0
    def setUp(self):
        super(GrapherTestCase, self).setUp()
        self._cache_recipe(self.protobuf_ref, self.protobuf)
        self._cache_recipe(self.protoc_ref, self.protoc)
        self._cache_recipe(self.gtest_ref, self.gtest)
        self._cache_recipe(self.app_ref, self.application)

        profile_host = Profile()
        profile_host.settings["os"] = "Host"
        profile_host.process_settings(self.cache)

        profile_build = Profile()
        profile_build.settings["os"] = "Build"
        profile_build.process_settings(self.cache)

        deps_graph = self._build_graph(profile_host=profile_host, profile_build=profile_build)

        self.grapher = Grapher(deps_graph)
예제 #29
0
 def load_profile(self, name):
     try:
         text = load(self.profile_path(name))
     except Exception:
         current_profiles = ", ".join(self.current_profiles()) or "[]"
         raise ConanException(
             "Specified profile '%s' doesn't exist.\nExisting profiles: "
             "%s" % (name, current_profiles))
     return Profile.loads(text)
예제 #30
0
    def profile_load_dump_test(self):
        # Empty profile
        tmp = temp_folder()
        profile = Profile()
        dumps = profile.dumps()
        new_profile, _ = self._get_profile(tmp, dumps)
        self.assertEqual(new_profile.settings, profile.settings)

        # Settings
        profile = Profile()
        profile.settings["arch"] = "x86_64"
        profile.settings["compiler"] = "Visual Studio"
        profile.settings["compiler.version"] = "12"

        profile.env_values.add("CXX", "path/to/my/compiler/g++")
        profile.env_values.add("CC", "path/to/my/compiler/gcc")

        profile.build_requires["*"] = [
            "android_toolchain/1.2.8@lasote/testing"
        ]
        profile.build_requires["zlib/*"] = [
            "cmake/1.0.2@lasote/stable", "autotools/1.0.3@lasote/stable"
        ]

        dump = profile.dumps()
        new_profile, _ = self._get_profile(tmp, dump)
        self.assertEqual(new_profile.settings, profile.settings)
        self.assertEqual(new_profile.settings["arch"], "x86_64")
        self.assertEqual(new_profile.settings["compiler.version"], "12")
        self.assertEqual(new_profile.settings["compiler"], "Visual Studio")

        self.assertEqual(new_profile.env_values.env_dicts(""),
                         ({
                             'CXX': 'path/to/my/compiler/g++',
                             'CC': 'path/to/my/compiler/gcc'
                         }, {}))

        self.assertEqual(new_profile.build_requires["zlib/*"], [
            ConanFileReference.loads("cmake/1.0.2@lasote/stable"),
            ConanFileReference.loads("autotools/1.0.3@lasote/stable")
        ])
        self.assertEqual(new_profile.build_requires["*"], [
            ConanFileReference.loads("android_toolchain/1.2.8@lasote/testing")
        ])
예제 #31
0
def _profile_parse_args(settings, options, envs, conf):
    """ return a Profile object result of parsing raw data
    """
    def _get_tuples_list_from_extender_arg(items):
        if not items:
            return []
        # Validate the pairs
        for item in items:
            chunks = item.split("=", 1)
            if len(chunks) != 2:
                raise ConanException("Invalid input '%s', use 'name=value'" %
                                     item)
        return [(item[0], item[1])
                for item in [item.split("=", 1) for item in items]]

    def _get_simple_and_package_tuples(items):
        """Parse items like "thing:item=value or item2=value2 and returns a tuple list for
        the simple items (name, value) and a dict for the package items
        {package: [(item, value)...)], ...}
        """
        simple_items = []
        package_items = defaultdict(list)
        tuples = _get_tuples_list_from_extender_arg(items)
        for name, value in tuples:
            if ":" in name:  # Scoped items
                tmp = name.split(":", 1)
                ref_name = tmp[0]
                name = tmp[1]
                package_items[ref_name].append((name, value))
            else:
                simple_items.append((name, value))
        return simple_items, package_items

    def _get_env_values(_env, _package_env):
        _env_values = EnvValues()
        for name, value in _env:
            _env_values.add(name, EnvValues.load_value(value))
        for package, data in _package_env.items():
            for name, value in data:
                _env_values.add(name, EnvValues.load_value(value), package)
        return _env_values

    options = _get_tuples_list_from_extender_arg(options)
    env, package_env = _get_simple_and_package_tuples(envs)
    env_values = _get_env_values(env, package_env)
    settings, package_settings = _get_simple_and_package_tuples(settings)

    result = Profile()
    result.options = OptionsValues(options)
    result.env_values = env_values
    result.settings = OrderedDict(settings)
    if conf:
        result.conf = ConfDefinition()
        result.conf.loads("\n".join(conf))

    for pkg, values in package_settings.items():
        result.package_settings[pkg] = OrderedDict(values)

    return result
예제 #32
0
 def get_profile_from_trace(self, number):
     call = self.calls[number]
     profile_start = call.find("--profile") + 10
     end_profile = call[profile_start:].find(" ") + profile_start
     profile_path = call[profile_start:end_profile]
     if hasattr(Profile, "loads"):  # retrocompatibility
         return Profile.loads(load(profile_path))
     else:
         from conans.client.profile_loader import read_profile
         return read_profile(profile_path, None, None)[0]
예제 #33
0
    def profile_load_dump_test(self):

        # Empty profile
        tmp = temp_folder()
        profile = Profile()
        dump = profile.dumps()
        new_profile, _ = self._get_profile(tmp, "")
        self.assertEquals(new_profile.settings, profile.settings)

        # Settings
        profile = Profile()
        profile.settings["arch"] = "x86_64"
        profile.settings["compiler"] = "Visual Studio"
        profile.settings["compiler.version"] = "12"

        profile.env_values.add("CXX", "path/to/my/compiler/g++")
        profile.env_values.add("CC", "path/to/my/compiler/gcc")

        profile.scopes["p1"]["conaning"] = "1"
        profile.scopes["p2"]["testing"] = "2"

        profile.build_requires["*"] = ["android_toolchain/1.2.8@lasote/testing"]
        profile.build_requires["zlib/*"] = ["cmake/1.0.2@lasote/stable",
                                            "autotools/1.0.3@lasote/stable"]

        dump = profile.dumps()
        new_profile, _ = self._get_profile(tmp, dump)
        self.assertEquals(new_profile.settings, profile.settings)
        self.assertEquals(new_profile.settings["arch"], "x86_64")
        self.assertEquals(new_profile.settings["compiler.version"], "12")
        self.assertEquals(new_profile.settings["compiler"], "Visual Studio")

        self.assertEquals(new_profile.env_values.env_dicts(""), ({'CXX': 'path/to/my/compiler/g++',
                                                                  'CC': 'path/to/my/compiler/gcc'}, {}))

        self.assertEquals(dict(new_profile.scopes)["p1"]["conaning"], '1')
        self.assertEquals(dict(new_profile.scopes)["p2"]["testing"], '2')

        self.assertEquals(new_profile.build_requires["zlib/*"],
                          [ConanFileReference.loads("cmake/1.0.2@lasote/stable"),
                           ConanFileReference.loads("autotools/1.0.3@lasote/stable")])
        self.assertEquals(new_profile.build_requires["*"],
                          [ConanFileReference.loads("android_toolchain/1.2.8@lasote/testing")])
예제 #34
0
def _load_profile(text, profile_path, default_folder):
    """ Parse and return a Profile object from a text config like representation.
        cwd is needed to be able to load the includes
    """

    try:
        inherited_profile = Profile()
        cwd = os.path.dirname(os.path.abspath(profile_path)) if profile_path else None
        profile_parser = ProfileParser(text)
        inherited_vars = profile_parser.vars
        # Iterate the includes and call recursive to get the profile and variables
        # from parent profiles
        for include in profile_parser.includes:
            # Recursion !!
            profile, declared_vars = read_profile(include, cwd, default_folder)
            inherited_profile.update(profile)
            inherited_vars.update(declared_vars)

        # Apply the automatic PROFILE_DIR variable
        if cwd:
            inherited_vars["PROFILE_DIR"] = os.path.abspath(cwd)
            # Allows PYTHONPATH=$PROFILE_DIR/pythontools

        # Replace the variables from parents in the current profile
        profile_parser.apply_vars(inherited_vars)

        # Current profile before update with parents (but parent variables already applied)
        doc = ConfigParser(profile_parser.profile_text,
                           allowed_fields=["build_requires", "settings", "env",
                                           "scopes", "options"])

        # Merge the inherited profile with the readed from current profile
        _apply_inner_profile(doc, inherited_profile)

        # Return the intherited vars to apply them in the parent profile if exists
        inherited_vars.update(profile_parser.vars)
        return inherited_profile, inherited_vars

    except ConanException:
        raise
    except Exception as exc:
        raise ConanException("Error parsing the profile text file: %s" % str(exc))
예제 #35
0
    def initialize_default_profile(self):
        if not os.path.exists(self.default_profile_path):
            self._output.writeln("Auto detecting your dev setup to initialize the "
                                 "default profile (%s)" % self.default_profile_path,
                                 Color.BRIGHT_YELLOW)

            default_settings = detect_defaults_settings(self._output,
                                                        profile_path=self.default_profile_path)
            self._output.writeln("Default settings", Color.BRIGHT_YELLOW)
            self._output.writeln("\n".join(["\t%s=%s" % (k, v) for (k, v) in default_settings]),
                                 Color.BRIGHT_YELLOW)
            self._output.writeln("*** You can change them in %s ***" % self.default_profile_path,
                                 Color.BRIGHT_MAGENTA)
            self._output.writeln("*** Or override with -s compiler='other' -s ...s***\n\n",
                                 Color.BRIGHT_MAGENTA)

            default_profile = Profile()
            tmp = OrderedDict(default_settings)
            default_profile.update_settings(tmp)
            save(self.default_profile_path, default_profile.dumps())
예제 #36
0
파일: profile.py 프로젝트: 19317362/conan
def cmd_profile_create(profile_name, cache_profiles_path, output, detect=False):
    profile_path = get_profile_path(profile_name, cache_profiles_path, get_cwd(),
                                    exists=False)
    if os.path.exists(profile_path):
        raise ConanException("Profile already exists")

    profile = Profile()
    if detect:
        settings = detect_defaults_settings(output)
        for name, value in settings:
            profile.settings[name] = value

    contents = profile.dumps()
    save(profile_path, contents)

    if detect:
        output.info("Profile created with detected settings: %s" % profile_path)
    else:
        output.info("Empty profile created: %s" % profile_path)
    return profile_path
예제 #37
0
    def profile_settings_update_test(self):
        prof = '''[settings]
os=Windows
'''
        new_profile = Profile.loads(prof)

        new_profile.update_settings([("OTHER", "2")])
        self.assertEquals(new_profile.settings, [("os", "Windows"), ("OTHER", "2")])

        new_profile.update_settings([("compiler.version", "3"), ("compiler", "2")])
        self.assertEquals(new_profile.settings, [("os", "Windows"), ("OTHER", "2"),
                                                 ("compiler", "2"), ("compiler.version", "3")])
예제 #38
0
    def _build_and_check(self, tmp_dir, file_path, text_file, msg):
        loader = ConanFileLoader(None, Settings(), Profile())
        ret = loader.load_conan(file_path, None)
        curdir = os.path.abspath(os.curdir)
        os.chdir(tmp_dir)
        try:
            ret.build()
        finally:
            os.chdir(curdir)

        content = load(text_file)
        self.assertEquals(content, msg)
예제 #39
0
파일: profiles.py 프로젝트: 19317362/conan
def create_profile(folder, name, settings=None, package_settings=None, env=None,
                   package_env=None, options=None):

    package_env = package_env or {}

    profile = Profile()
    profile.settings = settings or {}

    if package_settings:
        profile.package_settings = package_settings

    if options:
        profile.options = OptionsValues(options)

    for package_name, envs in package_env.items():
        for var_name, value in envs:
            profile.env_values.add(var_name, value, package_name)

    for var_name, value in env or {}:
        profile.env_values.add(var_name, value)

    save(os.path.join(folder, name), profile.dumps())
예제 #40
0
    def package_settings_update_test(self):
        prof = '''[settings]
MyPackage:os=Windows
'''
        np = Profile.loads(prof)

        np.update_package_settings({"MyPackage": [("OTHER", "2")]})
        self.assertEquals(np.package_settings, {"MyPackage": [("os", "Windows"), ("OTHER", "2")]})

        np.update_package_settings({"MyPackage": [("compiler.version", "3"), ("compiler", "2")]})
        self.assertEquals(np.package_settings, {"MyPackage":
                                                [("os", "Windows"), ("OTHER", "2"),
                                                 ("compiler", "2"), ("compiler.version", "3")]})
예제 #41
0
    def profile_env_update_test(self):
        prof = '''[env]
CXX_FLAGS="-DAAA=0"
[settings]
'''
        new_profile = Profile.loads(prof)

        new_profile.update_env([("OTHER", "2")])
        self.assertEquals(new_profile.env, [("OTHER", "2"), ("CXX_FLAGS", "-DAAA=0")])

        new_profile.update_env([("OTHER", "3"), ("NEW", "4")])
        self.assertEquals(new_profile.env, [("OTHER", "3"), ("NEW", "4"), ("CXX_FLAGS", "-DAAA=0")])

        new_profile.update_env([("NEW", "4"), ("CXX_FLAGS", "A")])
        self.assertEquals(new_profile.env, [("NEW", "4"), ("CXX_FLAGS", "A"), ("OTHER", "3")])
예제 #42
0
    def profile_package_env_update_test(self):
        prof = '''[env]
MyPackage:VARIABLE=2
[settings]
'''
        new_profile = Profile.loads(prof)

        new_profile.update_packages_env({"MyPackage": [("VARIABLE", "3")]})
        self.assertEquals(new_profile.package_env["MyPackage"], [("VARIABLE", "3")])

        new_profile.update_packages_env({"MyPackage": [("OTHER", "2")]})
        self.assertEquals(new_profile.package_env["MyPackage"], [("OTHER", "2"), ("VARIABLE", "3")])

        new_profile.update_packages_env({"MyPackage": [("SOME", "VAR"), ("OTHER", "22")]})
        self.assertEquals(new_profile.package_env["MyPackage"], [("SOME", "VAR"), ("OTHER", "22"), ("VARIABLE", "3")])

        new_profile.update_packages_env({"OtherPackage": [("ONE", "2")]})
        self.assertEquals(new_profile.package_env["MyPackage"], [("SOME", "VAR"), ("OTHER", "22"), ("VARIABLE", "3")])
        self.assertEquals(new_profile.package_env["OtherPackage"], [("ONE", "2")])
예제 #43
0
    def profile_loads_test(self):
        prof = '''[env]
CXX_FLAGS="-DAAA=0"
[settings]
'''
        new_profile = Profile.loads(prof)
        self.assertEquals(new_profile.env, [("CXX_FLAGS", "-DAAA=0")])

        prof = '''[env]
CXX_FLAGS="-DAAA=0"
MyPackage:VAR=1
MyPackage:OTHER=2
OtherPackage:ONE=ONE
[settings]
'''
        new_profile = Profile.loads(prof)
        self.assertEquals(new_profile.env, [("CXX_FLAGS", "-DAAA=0")])
        self.assertEquals(new_profile.package_env, {"MyPackage": [("VAR", "1"), ("OTHER", "2")],
                                                    "OtherPackage": [("ONE", "ONE")]})

        prof = '''[env]
CXX_FLAGS='-DAAA=0'
[settings]
'''
        new_profile = Profile.loads(prof)
        self.assertEquals(new_profile.env, [("CXX_FLAGS", "-DAAA=0")])

        prof = '''[env]
CXX_FLAGS=-DAAA=0
[settings]
'''
        new_profile = Profile.loads(prof)
        self.assertEquals(new_profile.env, [("CXX_FLAGS", "-DAAA=0")])

        prof = '''[env]
CXX_FLAGS="-DAAA=0
[settings]
'''
        new_profile = Profile.loads(prof)
        self.assertEquals(new_profile.env, [("CXX_FLAGS", "\"-DAAA=0")])

        prof = '''
[settings]
zlib:compiler=gcc
compiler=Visual Studio
'''
        new_profile = Profile.loads(prof)
        self.assertEquals(new_profile._package_settings["zlib"], {"compiler": "gcc"})
        self.assertEquals(new_profile._settings["compiler"], "Visual Studio")
예제 #44
0
    def profile_dump_order_test(self):
        # Settings
        profile = Profile()
        profile.package_settings["zlib"] = {"compiler": "gcc"}
        profile.settings["arch"] = "x86_64"
        profile.settings["compiler"] = "Visual Studio"
        profile.settings["compiler.version"] = "12"
        profile.build_requires["*"] = ["zlib/1.2.8@lasote/testing"]
        profile.build_requires["zlib/*"] = ["aaaa/1.2.3@lasote/testing", "bb/1.2@lasote/testing"]
        self.assertEqual("""[settings]
arch=x86_64
compiler=Visual Studio
compiler.version=12
zlib:compiler=gcc
[options]
[build_requires]
*: zlib/1.2.8@lasote/testing
zlib/*: aaaa/1.2.3@lasote/testing, bb/1.2@lasote/testing
[env]""".splitlines(), profile.dumps().splitlines())
예제 #45
0
파일: profiles.py 프로젝트: conan-io/conan
def create_profile(folder, name, settings=None, scopes=None, package_settings=None, env=None,
                   package_env=None):

    package_env = package_env or {}

    profile = Profile()
    profile._settings = settings or {}
    if scopes:
        profile.scopes = Scopes.from_list(["%s=%s" % (key, value) for key, value in scopes.items()])

    if package_settings:
        profile._package_settings = package_settings

    for package_name, envs in package_env.items():
        for var_name, value in envs:
            profile._package_env[package_name][var_name] = value

    for var_name, value in env or {}:
        profile._env[var_name] = value

    save(os.path.join(folder, name), profile.dumps())
예제 #46
0
    def apply_test(self):
        # Settings
        profile = Profile()
        profile.settings["arch"] = "x86_64"
        profile.settings["compiler"] = "Visual Studio"
        profile.settings["compiler.version"] = "12"

        profile.env_values.add("CXX", "path/to/my/compiler/g++")
        profile.env_values.add("CC", "path/to/my/compiler/gcc")

        profile.update_settings(OrderedDict([("compiler.version", "14")]))

        self.assertEqual('[settings]\narch=x86_64\ncompiler=Visual Studio'
                         '\ncompiler.version=14\n'
                         '[options]\n'
                         '[build_requires]\n'
                         '[env]\nCC=path/to/my/compiler/gcc\nCXX=path/to/my/compiler/g++',
                         profile.dumps())
예제 #47
0
    def apply_test(self):
        # Settings
        profile = Profile()
        profile.settings["compiler.version"] = "12"
        profile.settings["arch"] = "x86_64"
        profile.settings["compiler"] = "Visual Studio"

        profile.env["CXX"] = "path/to/my/compiler/g++"
        profile.env["CC"] = "path/to/my/compiler/gcc"

        profile.scopes["p1"]["conaning"] = "True"
        profile.scopes["p2"]["testing"] = "True"

        profile.update_settings({"compiler.version": "14"})

        self.assertEqual('[settings]\narch=x86_64\ncompiler=Visual Studio\ncompiler.version=14\n'
                         '[scopes]\np1:conaning=True\np2:testing=True\n'
                         '[env]\nCC=path/to/my/compiler/gcc\nCXX=path/to/my/compiler/g++',
                         profile.dumps())

        profile.update_scopes({"p1": {"new_one": 2}})
        self.assertEqual('[settings]\narch=x86_64\ncompiler=Visual Studio\ncompiler.version=14\n'
                         '[scopes]\np1:new_one=2\np2:testing=True\n'
                         '[env]\nCC=path/to/my/compiler/gcc\nCXX=path/to/my/compiler/g++',
                         profile.dumps())
예제 #48
0
 def load_profile(self, name):
     text = load(self.profile_path(name))
     return Profile.loads(text)
예제 #49
0
    def profile_test(self):

        # Empty profile
        profile = Profile()
        dump = profile.dumps()
        new_profile = Profile.loads(dump)
        self.assertEquals(new_profile.settings, profile.settings)

        # Settings
        profile = Profile()
        profile.settings["arch"] = "x86_64"
        profile.settings["compiler.version"] = "12"
        profile.settings["compiler"] = "Visual Studio"

        profile.env["CXX"] = "path/to/my/compiler/g++"
        profile.env["CC"] = "path/to/my/compiler/gcc"

        profile.scopes["p1"]["conaning"] = "1"
        profile.scopes["p2"]["testing"] = "2"

        dump = profile.dumps()
        new_profile = Profile.loads(dump)
        self.assertEquals(new_profile.settings, profile.settings)
        self.assertEquals(new_profile.settings["arch"], "x86_64")
        self.assertEquals(new_profile.settings["compiler.version"], "12")
        self.assertEquals(new_profile.settings["compiler"], "Visual Studio")

        self.assertEquals(new_profile.env["CXX"], "path/to/my/compiler/g++")
        self.assertEquals(new_profile.env["CC"], "path/to/my/compiler/gcc")

        self.assertEquals(dict(new_profile.scopes)["p1"]["conaning"], '1')
        self.assertEquals(dict(new_profile.scopes)["p2"]["testing"], '2')