コード例 #1
0
def conf_definition():
    text = textwrap.dedent("""\
        tools.microsoft.msbuild:verbosity=minimal
        user.company.toolchain:flags=someflags""")
    c = ConfDefinition()
    c.loads(text)
    return c, text
コード例 #2
0
def test_conf_error_per_package():
    text = "*:core:verbosity=minimal"
    c = ConfDefinition()
    with pytest.raises(
            ConanException,
            match=r"Conf '\*:core:verbosity' cannot have a package pattern"):
        c.loads(text)
コード例 #3
0
ファイル: test_conf.py プロジェクト: ericLemanissier/conan
def test_conf_get_different_type_input_objects(text, expected):
    """
    Testing any possible Python-evaluable-input-format introduced
    by the user
    """
    c = ConfDefinition()
    c.loads(text)
    assert c.get(text.split("=")[0]) == expected
コード例 #4
0
def _apply_inner_profile(doc, base_profile):
    """

    :param doc: ConfigParser object from the current profile (excluding includes and vars,
    and with values already replaced)
    :param base_profile: Profile inherited, it's used as a base profile to modify it.
    :return: None
    """
    def get_package_name_value(item):
        """Parse items like package:name=value or name=value"""
        packagename = None
        if ":" in item:
            tmp = item.split(":", 1)
            packagename, item = tmp

        result_name, result_value = item.split("=", 1)
        result_name = result_name.strip()
        result_value = unquote(result_value)
        return packagename, result_name, result_value

    for setting in doc.settings.splitlines():
        setting = setting.strip()
        if setting and not setting.startswith("#"):
            if "=" not in setting:
                raise ConanException("Invalid setting line '%s'" % setting)
            package_name, name, value = get_package_name_value(setting)
            if package_name:
                base_profile.package_settings[package_name][name] = value
            else:
                base_profile.settings[name] = value

    if doc.build_requires:
        # FIXME CHECKS OF DUPLICATED?
        for req in doc.build_requires.splitlines():
            _load_single_build_require(base_profile, req)

    if doc.tool_requires:
        for req in doc.tool_requires.splitlines():
            _load_single_build_require(base_profile, req)

    if doc.options:
        base_profile.options.update(OptionsValues.loads(doc.options))

    # The env vars from the current profile (read in doc)
    # are updated with the included profiles (base_profile)
    # the current env values has priority
    current_env_values = EnvValues.loads(doc.env)
    current_env_values.update(base_profile.env_values)
    base_profile.env_values = current_env_values

    if doc.conf:
        new_prof = ConfDefinition()
        new_prof.loads(doc.conf, profile=True)
        base_profile.conf.update_conf_definition(new_prof)

    if doc.buildenv:
        buildenv = ProfileEnvironment.loads(doc.buildenv)
        base_profile.buildenv.update_profile_env(buildenv)
コード例 #5
0
ファイル: meson_test.py プロジェクト: ericLemanissier/conan
 def test_conf_skip_test(self):
     conf = ConfDefinition()
     conf.loads("tools.build:skip_test=1")
     conanfile = ConanFileMock()
     conanfile.settings = Settings()
     conanfile.conf = conf.get_conanfile_conf(None)
     meson = Meson(conanfile)
     meson.test()
     self.assertIsNone(conanfile.command)
コード例 #6
0
def conanfile():
    c = ConfDefinition()
    c.loads(textwrap.dedent("""\
        tools.build:jobs=10
    """))

    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)
    return conanfile
コード例 #7
0
def test_none():
    c = ConfDefinition()
    c.loads(textwrap.dedent("""\
    """))

    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)
    njobs = ninja_jobs_cmd_line_arg(conanfile)
    assert njobs is None
コード例 #8
0
def test_sdk_path():
    conanfile = ConanFileMock()
    conf = ConfDefinition()
    conf.loads("tools.apple:sdk_path=mypath")
    conanfile.conf = conf
    conanfile.settings = MockSettings({})
    xcodebuild = XcodeBuild(conanfile)
    xcodebuild.build("app.xcodeproj")
    assert "SDKROOT=mypath " in conanfile.command
コード例 #9
0
def test_none():
    c = ConfDefinition()
    c.loads(textwrap.dedent("""\
    """))

    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)
    max_cpu_count = msbuild_max_cpu_count_cmd_line_arg(conanfile)
    assert max_cpu_count is None
コード例 #10
0
ファイル: cache.py プロジェクト: angeek/conan
 def new_config(self):
     """ this is the new conan.cfgto replace the old conan.conf that contains
     configuration defined with the new syntax as in profiles, this config will be composed
     to the profile ones and passed to the conanfiles.conf, which can be passed to collaborators
     """
     if self._new_config is None:
         self._new_config = ConfDefinition()
         if os.path.exists(self.new_config_path):
             self._new_config.loads(load(self.new_config_path))
     return self._new_config
コード例 #11
0
def test_tools_ning():
    c = ConfDefinition()
    c.loads(textwrap.dedent("""\
        tools.ninja:jobs=23
    """))

    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)
    njobs = ninja_jobs_cmd_line_arg(conanfile)
    assert njobs == "-j23"
コード例 #12
0
def test_tools_build():
    c = ConfDefinition()
    c.loads(textwrap.dedent("""\
        tools.build:processes=10
    """))

    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)
    max_cpu_count = msbuild_max_cpu_count_cmd_line_arg(conanfile)
    assert max_cpu_count == "/m:10"
コード例 #13
0
def test_tools_build():
    c = ConfDefinition()
    c.loads(textwrap.dedent("""\
        tools.build:processes=10
    """))

    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)
    njobs = ninja_jobs_cmd_line_arg(conanfile)
    assert njobs == "-j10"
コード例 #14
0
def test_tools_ning():
    c = ConfDefinition()
    c.loads(textwrap.dedent("""\
        tools.microsoft.msbuild:max_cpu_count=23
    """))

    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)
    max_cpu_count = msbuild_max_cpu_count_cmd_line_arg(conanfile)
    assert max_cpu_count == "/m:23"
コード例 #15
0
def test_conf_rebase(conf_definition):
    c, _ = conf_definition
    text = textwrap.dedent("""\
       user.company.toolchain:flags=newvalue
       another.something:key=value""")
    c2 = ConfDefinition()
    c2.loads(text)
    c.rebase_conf_definition(c2)
    # The c profile will have precedence, and "
    result = textwrap.dedent("""\
        tools.microsoft.msbuild:verbosity=minimal
        user.company.toolchain:flags=someflags""")
    assert c.dumps() == result
コード例 #16
0
def conanfile():
    c = ConfDefinition()
    c.loads(
        textwrap.dedent("""\
        tools.gnu.make:jobs=40
        tools.ninja:jobs=30
        tools.microsoft.msbuild:max_cpu_count=20
        tools.build:processes=10
    """))

    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)
    return conanfile
コード例 #17
0
def test_conf_update(conf_definition):
    c, _ = conf_definition
    text = textwrap.dedent("""\
       user.company.toolchain:flags=newvalue
       another.something:key=value""")
    c2 = ConfDefinition()
    c2.loads(text)
    c.update_conf_definition(c2)
    result = textwrap.dedent("""\
        another.something:key=value
        tools.microsoft.msbuild:verbosity=minimal
        user.company.toolchain:flags=newvalue""")
    assert c.dumps() == result
コード例 #18
0
def test_bazel_command_with_empty_config():
    c = ConfDefinition()
    c.loads(textwrap.dedent("""\
        tools.google.bazel:config=
        tools.google.bazel:bazelrc_path=
    """))

    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)

    bazel = Bazel(conanfile)
    bazel.build(label='//test:label')

    assert 'bazel  build  //test:label' == str(conanfile.command)
コード例 #19
0
    def __init__(self):
        # Input sections, as defined by user profile files and command line
        self.settings = OrderedDict()
        self.package_settings = defaultdict(OrderedDict)
        self.env_values = EnvValues()
        self.options = OptionsValues()
        self.build_requires = OrderedDict()  # ref pattern: list of ref
        self.conf = ConfDefinition()

        # Cached processed values
        self.processed_settings = None  # Settings with values, and smart completion
        self._user_options = None
        self._package_settings_values = None
        self.dev_reference = None  # Reference of the package being develop
コード例 #20
0
def test_verbosity(mode):
    conanfile = ConanFileMock()
    conf = ConfDefinition()
    conf.loads("tools.apple.xcodebuild:verbosity={}".format(mode))
    conanfile.conf = conf
    conanfile.settings = MockSettings({})
    xcodebuild = XcodeBuild(conanfile)
    if mode != "invalid":
        xcodebuild.build("app.xcodeproj")
        assert "-{}".format(mode) in conanfile.command
    else:
        with pytest.raises(ConanException) as excinfo:
            xcodebuild.build("app.xcodeproj")
        assert "Value {} for 'tools.apple.xcodebuild:verbosity' is not valid".format(
            mode) == str(excinfo.value)
コード例 #21
0
ファイル: cache.py プロジェクト: ericLemanissier/conan
 def new_config(self):
     """ this is the new global.conf to replace the old conan.conf that contains
     configuration defined with the new syntax as in profiles, this config will be composed
     to the profile ones and passed to the conanfiles.conf, which can be passed to collaborators
     """
     if self._new_config is None:
         self._new_config = ConfDefinition()
         if os.path.exists(self.new_config_path):
             text = load(self.new_config_path)
             content = Template(text).render({
                 "platform": platform,
                 "os": os
             })
             self._new_config.loads(content)
     return self._new_config
コード例 #22
0
def test_msbuild_standard():
    settings = Settings({
        "build_type": ["Release"],
        "compiler": {
            "msvc": {
                "version": ["19.3"],
                "cppstd": ["20"]
            }
        },
        "os": ["Windows"],
        "arch": ["x86_64"]
    })
    conanfile = ConanFile(Mock(), None)
    conanfile.folders.set_base_generators(".")
    conanfile.install_folder = os.getcwd()
    conanfile.conf = ConfDefinition()
    conanfile.settings = "os", "compiler", "build_type", "arch"
    conanfile.initialize(settings, EnvValues())
    conanfile.settings.build_type = "Release"
    conanfile.settings.compiler = "msvc"
    conanfile.settings.compiler.version = "19.3"
    conanfile.settings.compiler.cppstd = "20"
    conanfile.settings.os = "Windows"
    conanfile.settings.arch = "x86_64"

    msbuild = MSBuildToolchain(conanfile)
    with mock.patch("conan.tools.microsoft.visual.vcvars_path",
                    mock.MagicMock(return_value=".")):
        msbuild.generate()
    assert '<LanguageStandard>stdcpp20</LanguageStandard>' in load(
        'conantoolchain_release_x64.props')
コード例 #23
0
def test_unix_path(subsystem, expected_path):
    c = ConfDefinition()
    c.loads(
        textwrap.dedent("""\
        tools.microsoft.bash:subsystem={}
    """.format(subsystem)))

    settings = MockSettings({"os": "Windows"})
    conanfile = ConanFileMock()
    conanfile.conf = c.get_conanfile_conf(None)
    conanfile.settings = settings
    conanfile.settings_build = settings
    conanfile.win_bash = True

    path = unix_path(conanfile, "c:/path/to/stuff")
    assert expected_path == path
コード例 #24
0
 def __init__(self, shared=None, options=None, options_values=None):
     options = options or ""
     self.command = None
     self.path = None
     self.settings = None
     self.options = Options(PackageOptions.loads(options))
     if options_values:
         for var, value in options_values.items():
             self.options._data[var] = value
     self.deps_cpp_info = MockDepsCppInfo()  # ("deps_cpp_info", "sysroot")("/path/to/sysroot")
     self.deps_cpp_info.sysroot = "/path/to/sysroot"
     self.output = TestBufferConanOutput()
     self.in_local_cache = False
     if shared is not None:
         self.options = namedtuple("options", "shared")(shared)
     self.should_configure = True
     self.should_build = True
     self.should_install = True
     self.should_test = True
     self.generators = []
     self.captured_env = {}
     self.deps_env_info = DepsEnvInfo()
     self.env_info = EnvInfo()
     self.deps_user_info = DepsUserInfo()
     self._conan_env_values = EnvValues()
     self.folders = Folders()
     self.folders.set_base_source(".")
     self.folders.set_base_build(".")
     self.folders.set_base_install("myinstallfolder")
     self.folders.set_base_generators(".")
     self._conan_user = None
     self._conan_channel = None
     self.env_scripts = {}
     self.win_bash = None
     self.conf = ConfDefinition().get_conanfile_conf(None)
コード例 #25
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
コード例 #26
0
ファイル: test_conf.py プロジェクト: yipdw/conan
def test_conf_error_uppercase():
    text = "tools.something:Verbosity=minimal"
    c = ConfDefinition()
    with pytest.raises(ConanException,
                       match=r"Conf key 'Verbosity' must be lowercase"):
        c.loads(text)
    text = "tools.Something:verbosity=minimal"
    c = ConfDefinition()
    with pytest.raises(
            ConanException,
            match=r"Conf module 'tools.Something' must be lowercase"):
        c.loads(text)
コード例 #27
0
ファイル: test_meson.py プロジェクト: Imerso3D/conan
def test_meson_build():
    c = ConfDefinition()
    c.loads(textwrap.dedent("""\
        tools.ninja:jobs=23
        tools.build:processes=10
    """))

    settings = MockSettings({"build_type": "Release",
                             "compiler": "gcc",
                             "compiler.version": "7",
                             "os": "Linux",
                             "arch": "x86_64"})
    conanfile = ConanFileMock()
    conanfile.settings = settings
    conanfile.display_name = 'test'
    conanfile.conf = c.get_conanfile_conf(None)

    meson = Meson(conanfile)
    meson.build()
    
    assert '-j23' in str(conanfile.command)
コード例 #28
0
def test_conf_definition(conf_definition):
    c, text = conf_definition
    # Round trip
    assert c.dumps() == text
    # access
    assert c["tools.microsoft.msbuild:verbosity"] == "minimal"
    assert c["user.company.toolchain:flags"] == "someflags"
    assert c["tools.microsoft.msbuild:nonexist"] is None
    assert c["nonexist:nonexist"] is None
    # bool
    assert bool(c)
    assert not bool(ConfDefinition())
コード例 #29
0
def test_sdk():
    conanfile = ConanFileMock()
    conf = ConfDefinition()
    conf.loads("tools.apple:sdk_path=mypath")
    conanfile.conf = conf
    conanfile.settings = MockSettings({"os": "Macos", "os.sdk": "macosx"})
    xcodebuild = XcodeBuild(conanfile)
    xcodebuild.build("app.xcodeproj")
    # sdk_path takes preference
    assert "SDKROOT=mypath " in conanfile.command
    conf = ConfDefinition()
    conanfile.conf = conf
    xcodebuild = XcodeBuild(conanfile)
    xcodebuild.build("app.xcodeproj")
    assert "SDKROOT=macosx " in conanfile.command
    conanfile.settings = MockSettings({
        "os": "Macos",
        "os.sdk": "macosx",
        "os.sdk_version": "12.1"
    })
    xcodebuild = XcodeBuild(conanfile)
    xcodebuild.build("app.xcodeproj")
    assert "SDKROOT=macosx12.1 " in conanfile.command
    conanfile.settings = MockSettings({})
    xcodebuild = XcodeBuild(conanfile)
    xcodebuild.build("app.xcodeproj")
    assert "SDKROOT" not in conanfile.command
コード例 #30
0
ファイル: test_msbuild.py プロジェクト: Enhex/conan
def test_msbuild_cpu_count():
    c = ConfDefinition()
    c.loads(
        textwrap.dedent("""\
        tools.microsoft.msbuild:max_cpu_count=23
    """))

    settings = MockSettings({
        "build_type": "Release",
        "compiler": "gcc",
        "compiler.version": "7",
        "os": "Linux",
        "arch": "x86_64"
    })
    conanfile = ConanFileMock()
    conanfile.settings = settings
    conanfile.conf = c.get_conanfile_conf(None)

    msbuild = MSBuild(conanfile)
    cmd = msbuild.command('project.sln')

    assert '/m:23' in cmd