Exemplo n.º 1
0
    def profile_subsettings_update_test(self):
        prof = '''[settings]
os=Windows
compiler=Visual Studio
compiler.runtime=MT
'''
        new_profile, _ = _load_profile(prof, None, None)
        new_profile.update_settings(OrderedDict([("compiler", "gcc")]))
        self.assertEquals(dict(new_profile.settings), {
            "compiler": "gcc",
            "os": "Windows"
        })

        new_profile, _ = _load_profile(prof, None, None)
        new_profile.update_settings(
            OrderedDict([("compiler", "Visual Studio"),
                         ("compiler.subsetting", "3"), ("other", "value")]))

        self.assertEquals(
            dict(new_profile.settings), {
                "compiler": "Visual Studio",
                "os": "Windows",
                "compiler.runtime": "MT",
                "compiler.subsetting": "3",
                "other": "value"
            })
Exemplo n.º 2
0
 def env_vars_test_inheritance(self):
     tmp_dir = temp_folder()
     p1 = '''[env]\nVAR=1'''
     p2 = '''include(p1)\n[env]\nVAR=2'''
     save(os.path.join(tmp_dir, "p1"), p1)
     new_profile, _ = _load_profile(p2, tmp_dir, tmp_dir)
     self.assertEquals(new_profile.env_values.data[None]["VAR"], "2")
Exemplo n.º 3
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]
Exemplo n.º 4
0
 def env_vars_test_inheritance(self):
     tmp_dir = temp_folder()
     p1 = '''[env]\nVAR=1'''
     p2 = '''include(p1)\n[env]\nVAR=2'''
     save(os.path.join(tmp_dir, "p1"), p1)
     new_profile, _ = _load_profile(p2, tmp_dir, tmp_dir)
     self.assertEquals(new_profile.env_values.data[None]["VAR"], "2")
Exemplo n.º 5
0
 def loads(text):
     graph_json = json.loads(text)
     profile = graph_json["profile"]
     # FIXME: Reading private very ugly
     profile, _ = _load_profile(profile, None, None)
     graph_lock = GraphLock.from_dict(graph_json["graph_lock"])
     graph_lock_file = GraphLockFile(profile, graph_lock)
     return graph_lock_file
Exemplo n.º 6
0
 def _loads(text, revisions_enabled):
     graph_json = json.loads(text)
     version = graph_json.get("version")
     if version:
         if version != LOCKFILE_VERSION:
             raise ConanException("This lockfile was created with an incompatible "
                                  "version. Please regenerate the lockfile")
         # Do something with it, migrate, raise...
     profile_host = graph_json.get("profile_host", None)
     profile_build = graph_json.get("profile_build", None)
     # FIXME: Reading private very ugly
     if profile_host:
         profile_host, _ = _load_profile(profile_host, None, None)
     if profile_build:
         profile_build, _ = _load_profile(profile_build, None, None)
     graph_lock = GraphLock.deserialize(graph_json["graph_lock"], revisions_enabled)
     graph_lock_file = GraphLockFile(profile_host, profile_build, graph_lock)
     return graph_lock_file
Exemplo n.º 7
0
 def loads(text, revisions_enabled):
     graph_json = json.loads(text)
     version = graph_json.get("version")
     if version:
         version = Version(version)
         if version < "0.2":
             raise ConanException("This lockfile was created with a previous incompatible "
                                  "version. Please regenerate the lockfile")
         # Do something with it, migrate, raise...
     profile_host = graph_json.get("profile_host") or graph_json["profile"]
     profile_build = graph_json.get("profile_build", None)
     # FIXME: Reading private very ugly
     profile_host, _ = _load_profile(profile_host, None, None)
     if profile_build:
         profile_build, _ = _load_profile(profile_build, None, None)
     graph_lock = GraphLock.from_dict(graph_json["graph_lock"])
     graph_lock.revisions_enabled = revisions_enabled
     graph_lock_file = GraphLockFile(profile_host, profile_build, graph_lock)
     return graph_lock_file
Exemplo n.º 8
0
    def profile_subsettings_update_test(self):
        prof = '''[settings]
os=Windows
compiler=Visual Studio
compiler.runtime=MT
'''
        new_profile, _ = _load_profile(prof, None, None)
        new_profile.update_settings(OrderedDict([("compiler", "gcc")]))
        self.assertEquals(dict(new_profile.settings), {"compiler": "gcc", "os": "Windows"})

        new_profile, _ = _load_profile(prof, None, None)
        new_profile.update_settings(OrderedDict([("compiler", "Visual Studio"),
                                                 ("compiler.subsetting", "3"),
                                                 ("other", "value")]))

        self.assertEquals(dict(new_profile.settings), {"compiler": "Visual Studio",
                                                       "os": "Windows",
                                                       "compiler.runtime": "MT",
                                                       "compiler.subsetting": "3",
                                                       "other": "value"})
Exemplo n.º 9
0
 def loads(text):
     graph_json = json.loads(text)
     version = graph_json.get("version")
     if version:
         version = Version(version)
         # Do something with it, migrate, raise...
     profile = graph_json["profile"]
     # FIXME: Reading private very ugly
     profile, _ = _load_profile(profile, None, None)
     graph_lock = GraphLock.from_dict(graph_json["graph_lock"])
     graph_lock_file = GraphLockFile(profile, graph_lock)
     return graph_lock_file
Exemplo n.º 10
0
 def loads(text):
     graph_json = json.loads(text)
     profile = graph_json["profile"]
     # FIXME: Reading private very ugly
     profile, _ = _load_profile(profile, None, None)
     try:
         options = graph_json["options"]
     except KeyError:
         options = None
     else:
         options = OptionsValues(options)
     return GraphInfo(profile=profile, options=options)
Exemplo n.º 11
0
    def profile_settings_update_test(self):
        prof = '''[settings]
os=Windows
'''
        new_profile, _ = _load_profile(prof, None, None)

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

        new_profile.update_settings(OrderedDict([("compiler", "2"), ("compiler.version", "3")]))
        self.assertEquals(new_profile.settings,
                          OrderedDict([("os", "Windows"), ("OTHER", "2"),
                                       ("compiler", "2"), ("compiler.version", "3")]))
Exemplo n.º 12
0
    def test_profile_settings_update(self):
        prof = '''[settings]
os=Windows
'''
        new_profile, _ = _load_profile(prof, None, None)

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

        new_profile.update_settings(OrderedDict([("compiler", "2"), ("compiler.version", "3")]))
        self.assertEqual(new_profile.settings,
                          OrderedDict([("os", "Windows"), ("OTHER", "2"),
                                       ("compiler", "2"), ("compiler.version", "3")]))
Exemplo n.º 13
0
    def package_settings_update_test(self):
        prof = '''[settings]
MyPackage:os=Windows
'''
        np , _ = _load_profile(prof, None, None)

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

        np.update_package_settings({"MyPackage": [("compiler", "2"), ("compiler.version", "3")]})
        self.assertEquals(np.package_settings_values,
                          {"MyPackage": [("os", "Windows"), ("OTHER", "2"),
                                         ("compiler", "2"), ("compiler.version", "3")]})
Exemplo n.º 14
0
    def __init__(self,
                 profile_text,
                 username,
                 channel,
                 reference,
                 mingw_installer_reference=None,
                 runner=None,
                 args=None,
                 conan_pip_package=None,
                 exclude_vcvars_precommand=False,
                 conan_vars=None,
                 build_policy=None):

        self._conan_vars = conan_vars or {}
        self._profile_text = profile_text
        self._mingw_installer_reference = mingw_installer_reference
        self._args = args
        self._args += " --build=%s" % build_policy if build_policy else ""
        self._username = username
        self._channel = channel
        self._reference = reference
        self._conan_pip_package = conan_pip_package
        self._runner = runner or os.system
        self.runner = runner
        self.conan_api, self.client_cache, self.user_io = Conan.factory()
        self.conan_home = os.path.realpath(self.client_cache.conan_folder)
        self.data_home = os.path.realpath(self.client_cache.store)
        self._exclude_vcvars_precommand = exclude_vcvars_precommand

        if "default" in self._profile_text:  # User didn't specified a custom profile
            default_profile_name = os.path.basename(
                self.client_cache.default_profile_path)
            if not os.path.exists(self.client_cache.default_profile_path):
                self.conan_api.create_profile(default_profile_name,
                                              detect=True)

            if default_profile_name != "default":  # User have a different default profile name
                # https://github.com/conan-io/conan-package-tools/issues/121
                self._profile_text = self._profile_text.replace(
                    "include(default)", "include(%s)" % default_profile_name)

        # Save the profile in a tmp file
        tmp = os.path.join(
            tempfile.mkdtemp(suffix='conan_package_tools_profiles'), "profile")
        self.abs_profile_path = os.path.abspath(tmp)
        save(self.abs_profile_path, self._profile_text)

        self.profile, _ = _load_profile(self._profile_text,
                                        os.path.dirname(self.abs_profile_path),
                                        self.client_cache.profiles_path)
Exemplo n.º 15
0
 def deserialize(data):
     the_json = json.loads(data)
     if hasattr(Profile, "loads"):
         profile = Profile.loads(the_json["profile"])
     else:
         # Fixme, make public in conan?
         from conans.client.profile_loader import _load_profile
         profile = _load_profile(the_json["profile"], None, None)[0]
     ret = TestPackageRunner(
         profile,
         username=the_json["username"],
         channel=the_json["channel"],
         args=the_json["args"],
         conan_pip_package=the_json["conan_pip_package"])
     return ret
Exemplo n.º 16
0
    def package_settings_update_test(self):
        prof = '''[settings]
MyPackage:os=Windows
'''
        np, _ = _load_profile(prof, None, None)

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

        np.update_package_settings(
            {"MyPackage": [("compiler", "2"), ("compiler.version", "3")]})
        self.assertEquals(
            np.package_settings_values, {
                "MyPackage": [("os", "Windows"), ("OTHER", "2"),
                              ("compiler", "2"), ("compiler.version", "3")]
            })
Exemplo n.º 17
0
    def test_package_settings_update(self):
        prof = '''[settings]
MyPackage:os=Windows

    # In the previous line there are some spaces
'''
        np, _ = _load_profile(prof, None, None)

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

        np._package_settings_values = None  # invalidate caching
        np.update_package_settings({"MyPackage": [("compiler", "2"), ("compiler.version", "3")]})
        self.assertEqual(np.package_settings_values,
                         {"MyPackage": [("os", "Windows"), ("OTHER", "2"),
                                        ("compiler", "2"), ("compiler.version", "3")]})
Exemplo n.º 18
0
 def loads(text):
     graph_json = json.loads(text)
     profile = graph_json["profile"]
     # FIXME: Reading private very ugly
     profile, _ = _load_profile(profile, None, None)
     try:
         options = graph_json["options"]
     except KeyError:
         options = None
     else:
         options = OptionsValues(options)
     root = graph_json["root"]
     root_ref = ConanFileReference(root["name"],
                                   root["version"],
                                   root["user"],
                                   root["channel"],
                                   validate=False)
     return GraphInfo(profile=profile, options=options, root_ref=root_ref)
Exemplo n.º 19
0
def load_profile(profile_abs_path, client_cache):
    text = tools.load(profile_abs_path)
    profile, _ = _load_profile(text, os.path.dirname(profile_abs_path),
                               client_cache.profiles_path)
    return profile