Ejemplo n.º 1
0
    def trace_command_test(self):
        from conans.build_info.command import run
        trace_file = os.path.join(temp_folder(), "conan_trace.log")
        # Generate some traces
        with tools.environment_append({"CONAN_TRACE_FILE": trace_file}):
            files = cpp_hello_conan_files("Hello0", "1.0", deps=[], build=False)
            self.client.save(files)
            self.client.run("export . lasote/stable")
            self.client.run("install Hello0/1.0@lasote/stable --build")
            self.client.run("upload '*' --all -c")

        # Get json from file
        output = os.path.join(temp_folder(), "build_info.json")
        sys.argv = ['conan_build_info', trace_file, '--output', output]
        run()

        the_json = json.loads(load(output))
        self.assertTrue(the_json["modules"][0]["id"], "Hello0/1.0@lasote/stable")

        # Now get from stdout
        sys.argv = ['conan_build_info', trace_file]
        run()

        try:  # in IDEs or with --nocapture it will fail
            stdout_value = sys.stdout.getvalue()
        except AttributeError:
            pass
        else:
            the_json = json.loads(stdout_value)
            self.assertTrue(the_json["modules"][0]["id"], "Hello0/1.0@lasote/stable")
Ejemplo n.º 2
0
    def test_trace_command(self):
        from conans.build_info.command import run
        trace_file = os.path.join(temp_folder(), "conan_trace.log")
        # Generate some traces
        with tools.environment_append({"CONAN_TRACE_FILE": trace_file}):
            self.client.save({"conanfile.py": GenConanfile("Hello0", "1.0")})
            self.client.run("export . lasote/stable")
            self.client.run("install Hello0/1.0@lasote/stable --build")
            self.client.run("upload '*' --all -c")

        # Get json from file
        output = os.path.join(temp_folder(), "build_info.json")
        sys.argv = ['conan_build_info', trace_file, '--output', output]
        run()

        the_json = json.loads(load(output))
        self.assertTrue(the_json["modules"][0]["id"],
                        "Hello0/1.0@lasote/stable")

        # Now get from stdout
        sys.argv = ['conan_build_info', trace_file]
        run()

        try:  # in IDEs or with --nocapture it will fail
            stdout_value = sys.stdout.getvalue()
        except AttributeError:
            pass
        else:
            the_json = json.loads(stdout_value)
            self.assertTrue(the_json["modules"][0]["id"],
                            "Hello0/1.0@lasote/stable")
Ejemplo n.º 3
0
    def test_build_info_old_lockfile_version(self, mock_cache, user_home_mock):
        base_folder = temp_folder(True)
        cache_folder = os.path.join(base_folder, ".conan")
        client = TestClient(cache_folder=cache_folder)
        client.save({"conan.lock": '{"version": "0.2"}'})
        mock_cache.return_value = client.cache
        user_home_mock.return_value = cache_folder

        sys.argv = ["conan_build_info", "--v2", "start", "MyBuildName", "42"]
        run()
        sys.argv = [
            "conan_build_info", "--v2", "create",
            os.path.join(client.current_folder, "buildinfo.json"),
            "--lockfile",
            os.path.join(client.current_folder, "conan.lock")
        ]

        old_stderr = sys.stderr
        try:
            result = StringIO()
            sys.stderr = result
            run()
            result = result.getvalue()
            self.assertIn(
                "This lockfile was created with an incompatible version of Conan",
                result)
        finally:
            sys.stderr = old_stderr
Ejemplo n.º 4
0
    def test_build_info_create_scm(self, mock_cache, user_home_mock):
        base_folder = temp_folder(True)
        cache_folder = os.path.join(base_folder, ".conan")
        servers = {
            "default":
            TestServer([("*/*@*/*", "*")], [("*/*@*/*", "*")],
                       users={"lasote": "mypass"})
        }
        client = TestClient(servers=servers,
                            users={"default": [("lasote", "mypass")]},
                            cache_folder=cache_folder)

        mock_cache.return_value = client.cache
        user_home_mock.return_value = base_folder
        conanfile = textwrap.dedent("""
            from conans import ConanFile, load
            import os
            class Pkg(ConanFile):
                name = "PkgA"
                version = "0.1"
                scm = {"type": "git",
                        "url": "auto",
                        "revision": "auto"}

                def imports(self):
                    self.copy("myfile.txt", folder=True)
                def package(self):
                    self.copy("*myfile.txt")
                """)

        client.save({"conanfile.py": conanfile, "myfile.txt": "HelloA"})
        client.run_command("git init")
        client.run_command('git config user.email "*****@*****.**"')
        client.run_command('git config user.name "Your Name"')
        client.run_command(
            "git remote add origin https://github.com/fake/fake.git")
        client.run_command("git add .")
        client.run_command("git commit -m \"initial commit\"")

        client.run("export .")

        client.run("lock create conanfile.py --lockfile-out=conan.lock")

        client.run("create . --lockfile=conan.lock")
        client.run("upload * --confirm -r default --force")

        sys.argv = ["conan_build_info", "--v2", "start", "MyBuildName", "42"]
        run()
        sys.argv = [
            "conan_build_info", "--v2", "create",
            os.path.join(client.current_folder, "buildinfo.json"),
            "--lockfile",
            os.path.join(client.current_folder, LOCKFILE)
        ]
        run()
        if not os.path.exists(
                os.path.join(client.current_folder, "buildinfo.json")):
            self.fail("build info create failed")
Ejemplo n.º 5
0
 def test_build_info_stop(self, mock_cache):
     conan_user_home = temp_folder(True)
     mock_cache.return_value = ClientCache(
         os.path.join(conan_user_home, ".conan"), TestBufferConanOutput())
     sys.argv = ["conan_build_info", "--v2", "stop"]
     run()
     with open(mock_cache.return_value.artifacts_properties_path) as f:
         content = f.read()
         self.assertEqual("", content)
Ejemplo n.º 6
0
 def test_build_info_start(self, mock_cache):
     conan_user_home = temp_folder(True)
     mock_cache.return_value = ClientCache(
         os.path.join(conan_user_home, ".conan"), TestBufferConanOutput())
     sys.argv = ["conan_build_info", "--v2", "start", "MyBuildName", "42"]
     run()
     with open(mock_cache.return_value.put_headers_path) as f:
         content = f.read()
         self.assertIn("MyBuildName", content)
         self.assertIn("42", content)
Ejemplo n.º 7
0
    def _test_buildinfo(self, client, user_channel):
        conanfile = textwrap.dedent("""
            from conans import ConanFile, load
            import os
            class Pkg(ConanFile):
                settings = "os"
                {requires}
                exports_sources = "myfile.txt"
                keep_imports = True
                def imports(self):
                    self.copy("myfile.txt", folder=True)
                def package(self):
                    self.copy("*myfile.txt")
                """)
        client.save({
            "PkgA/conanfile.py":
            conanfile.format(requires=""),
            "PkgA/myfile.txt":
            "HelloA",
            "PkgB/conanfile.py":
            conanfile.format(
                requires='requires = "PkgA/0.1@{}"'.format(user_channel)),
            "PkgB/myfile.txt":
            "HelloB",
            "PkgC/conanfile.py":
            conanfile.format(
                requires='requires = "PkgA/0.1@{}"'.format(user_channel)),
            "PkgC/myfile.txt":
            "HelloC",
            "PkgD/conanfile.py":
            conanfile.format(
                requires='requires = "PkgC/0.1@{0}", "PkgB/0.1@{0}"'.format(
                    user_channel)),
            "PkgD/myfile.txt":
            "HelloD"
        })
        for profile in ("Windows", "Linux"):
            client.run("create PkgA PkgA/0.1@{} -s os={}".format(
                user_channel, profile))
            client.run("create PkgB PkgB/0.1@{} -s os={}".format(
                user_channel, profile))
            client.run("create PkgC PkgC/0.1@{} -s os={}".format(
                user_channel, profile))
            client.run("create PkgD PkgD/0.1@{} -s os={}".format(
                user_channel, profile))
            client.run(
                "lock create --reference PkgD/0.1@{} --build=PkgC --build=PkgD -s os={}"
                " --lockfile-out={}.lock".format(user_channel, profile,
                                                 profile))

            client.run("create PkgC PkgC/0.1@{0} --lockfile={1}.lock "
                       "--lockfile-out={1}.lock".format(user_channel, profile))
            client.run("create PkgD PkgD/0.1@{0} --lockfile={1}.lock "
                       "--lockfile-out={1}.lock".format(user_channel, profile))
            client.run("upload * --all --confirm -r default")

        sys.argv = ["conan_build_info", "--v2", "start", "MyBuildName", "42"]
        run()
        sys.argv = [
            "conan_build_info", "--v2", "create",
            os.path.join(client.current_folder, "buildinfowin.json"),
            "--lockfile",
            os.path.join(client.current_folder, "Windows.lock")
        ]
        run()

        sys.argv = [
            "conan_build_info", "--v2", "create",
            os.path.join(client.current_folder, "buildinfolinux.json"),
            "--lockfile",
            os.path.join(client.current_folder, "Linux.lock")
        ]
        run()

        user_channel = "@" + user_channel if len(
            user_channel) > 2 else user_channel
        buildinfo = json.loads(client.load("buildinfowin.json"))
        self.assertEqual(buildinfo["name"], "MyBuildName")
        self.assertEqual(buildinfo["number"], "42")
        ids_list = [item["id"] for item in buildinfo["modules"]]
        expected = [
            "PkgC/0.1{}".format(user_channel),
            "PkgD/0.1{}".format(user_channel),
            "PkgC/0.1{}:3374c4fa6b7e865cfc3a1903ae014cf77a6938ec".format(
                user_channel),
            "PkgD/0.1{}:6cd742f1b907e693abf6da9f767aab3ee7fde606".format(
                user_channel)
        ]
        self.assertEqual(set(expected), set(ids_list))

        buildinfo = json.loads(client.load("buildinfolinux.json"))
        self.assertEqual(buildinfo["name"], "MyBuildName")
        self.assertEqual(buildinfo["number"], "42")
        ids_list = [item["id"] for item in buildinfo["modules"]]
        expected = [
            "PkgC/0.1{}".format(user_channel),
            "PkgD/0.1{}".format(user_channel),
            "PkgC/0.1{}:a1e39343af463cef4284c5550fde03912afd9852".format(
                user_channel),
            "PkgD/0.1{}:39af3f48fdee2bbc5f84e7da3a67ebab2a297acb".format(
                user_channel)
        ]
        self.assertEqual(set(expected), set(ids_list))

        sys.argv = [
            "conan_build_info", "--v2", "update",
            os.path.join(client.current_folder, "buildinfowin.json"),
            os.path.join(client.current_folder, "buildinfolinux.json"),
            "--output-file",
            os.path.join(client.current_folder, "mergedbuildinfo.json")
        ]
        run()

        f = client.load("mergedbuildinfo.json")
        buildinfo = json.loads(f)
        self.assertEqual(buildinfo["name"], "MyBuildName")
        self.assertEqual(buildinfo["number"], "42")
        ids_list = [item["id"] for item in buildinfo["modules"]]
        expected = [
            "PkgC/0.1{}".format(user_channel),
            "PkgD/0.1{}".format(user_channel),
            "PkgC/0.1{}:3374c4fa6b7e865cfc3a1903ae014cf77a6938ec".format(
                user_channel),
            "PkgC/0.1{}:a1e39343af463cef4284c5550fde03912afd9852".format(
                user_channel),
            "PkgD/0.1{}:6cd742f1b907e693abf6da9f767aab3ee7fde606".format(
                user_channel),
            "PkgD/0.1{}:39af3f48fdee2bbc5f84e7da3a67ebab2a297acb".format(
                user_channel),
        ]
        self.assertEqual(set(expected), set(ids_list))

        sys.argv = [
            "conan_build_info", "--v2", "publish",
            os.path.join(client.current_folder, "mergedbuildinfo.json"),
            "--url", "http://fakeurl:8081/artifactory", "--user", "user",
            "--password", "password"
        ]
        run()
        sys.argv = [
            "conan_build_info", "--v2", "publish",
            os.path.join(client.current_folder, "mergedbuildinfo.json"),
            "--url", "http://fakeurl:8081/artifactory", "--apikey", "apikey"
        ]
        run()

        sys.argv = ["conan_build_info", "--v2", "stop"]
        run()
Ejemplo n.º 8
0
    def _test_buildinfo(self, client, user_channel):
        conanfile = textwrap.dedent("""
            from conans import ConanFile, load
            import os
            class Pkg(ConanFile):
                {requires}
                exports_sources = "myfile.txt"
                keep_imports = True
                def imports(self):
                    self.copy("myfile.txt", folder=True)
                def package(self):
                    self.copy("*myfile.txt")
                """)
        client.save({
            "PkgA/conanfile.py": conanfile.format(requires=""),
            "PkgA/myfile.txt": "HelloA"
        })
        client.run("create PkgA PkgA/0.1@{}".format(user_channel))

        client.save({
            "PkgB/conanfile.py":
            conanfile.format(
                requires='requires = "PkgA/0.1@{}"'.format(user_channel)),
            "PkgB/myfile.txt":
            "HelloB"
        })
        client.run("create PkgB PkgB/0.1@{}".format(user_channel))

        client.save({
            "PkgC/conanfile.py":
            conanfile.format(
                requires='requires = "PkgA/0.1@{}"'.format(user_channel)),
            "PkgC/myfile.txt":
            "HelloC"
        })
        client.run("create PkgC PkgC/0.1@{}".format(user_channel))

        client.save({
            "PkgD/conanfile.py":
            conanfile.format(
                requires='requires = "PkgC/0.1@{0}", "PkgB/0.1@{0}"'.format(
                    user_channel)),
            "PkgD/myfile.txt":
            "HelloD"
        })

        client.run("create PkgD PkgD/0.1@{}".format(user_channel))
        client.run("graph lock PkgD/0.1@{}".format(user_channel))

        client.run("create PkgA PkgA/0.2@{} --lockfile".format(user_channel))

        shutil.copy(os.path.join(client.current_folder, "conan.lock"),
                    os.path.join(client.current_folder, "temp.lock"))

        client.run("create PkgB PkgB/0.1@{} --lockfile --build missing".format(
            user_channel))
        client.run("upload * --all --confirm -r default")

        sys.argv = ["conan_build_info", "--v2", "start", "MyBuildName", "42"]
        run()
        sys.argv = [
            "conan_build_info", "--v2", "create",
            os.path.join(client.current_folder, "buildinfo1.json"),
            "--lockfile",
            os.path.join(client.current_folder, LOCKFILE)
        ]
        run()

        shutil.copy(os.path.join(client.current_folder, "temp.lock"),
                    os.path.join(client.current_folder, "conan.lock"))

        client.run("create PkgC PkgC/0.1@{} --lockfile --build missing".format(
            user_channel))
        client.run("upload * --all --confirm -r default")

        sys.argv = [
            "conan_build_info", "--v2", "create",
            os.path.join(client.current_folder, "buildinfo2.json"),
            "--lockfile",
            os.path.join(client.current_folder, LOCKFILE)
        ]
        run()

        user_channel = "@" + user_channel if len(
            user_channel) > 2 else user_channel
        f = client.load("buildinfo1.json")
        buildinfo = json.loads(f)
        self.assertEqual(buildinfo["name"], "MyBuildName")
        self.assertEqual(buildinfo["number"], "42")
        ids_list = [item["id"] for item in buildinfo["modules"]]
        self.assertTrue("PkgB/0.1{}".format(user_channel) in ids_list)
        self.assertTrue("PkgB/0.1{}:09f152eb7b3e0a6e15a2a3f464245864ae8f8644".
                        format(user_channel) in ids_list)

        sys.argv = [
            "conan_build_info", "--v2", "update",
            os.path.join(client.current_folder, "buildinfo1.json"),
            os.path.join(client.current_folder, "buildinfo2.json"),
            "--output-file",
            os.path.join(client.current_folder, "mergedbuildinfo.json")
        ]
        run()

        f = client.load("mergedbuildinfo.json")
        buildinfo = json.loads(f)
        self.assertEqual(buildinfo["name"], "MyBuildName")
        self.assertEqual(buildinfo["number"], "42")
        ids_list = [item["id"] for item in buildinfo["modules"]]
        self.assertTrue("PkgC/0.1{}".format(user_channel) in ids_list)
        self.assertTrue("PkgB/0.1{}".format(user_channel) in ids_list)
        self.assertTrue("PkgC/0.1{}:09f152eb7b3e0a6e15a2a3f464245864ae8f8644".
                        format(user_channel) in ids_list)
        self.assertTrue("PkgB/0.1{}:09f152eb7b3e0a6e15a2a3f464245864ae8f8644".
                        format(user_channel) in ids_list)

        sys.argv = [
            "conan_build_info", "--v2", "publish",
            os.path.join(client.current_folder, "mergedbuildinfo.json"),
            "--url", "http://fakeurl:8081/artifactory", "--user", "user",
            "--password", "password"
        ]
        run()
        sys.argv = [
            "conan_build_info", "--v2", "publish",
            os.path.join(client.current_folder, "mergedbuildinfo.json"),
            "--url", "http://fakeurl:8081/artifactory", "--apikey", "apikey"
        ]
        run()

        sys.argv = ["conan_build_info", "--v2", "stop"]
        run()
Ejemplo n.º 9
0
    def _test_buildinfo(self, client, user_channel):
        conanfile = textwrap.dedent("""
            from conans import ConanFile, load
            import os
            class Pkg(ConanFile):
                settings = "os"
                {requires}
                exports_sources = "myfile.txt"
                keep_imports = True
                def imports(self):
                    self.copy("myfile.txt", folder=True)
                def package(self):
                    self.copy("*myfile.txt")
                """)
        client.save({"PkgA/conanfile.py": conanfile.format(requires=""),
                     "PkgA/myfile.txt": "HelloA",
                     "PkgB/conanfile.py": conanfile.format(
                         requires='requires = "PkgA/0.1@{}"'.format(user_channel)),
                     "PkgB/myfile.txt": "HelloB",
                     "PkgC/conanfile.py": conanfile.format(
                         requires='requires = "PkgA/0.1@{}"'.format(user_channel)),
                     "PkgC/myfile.txt": "HelloC",
                     "PkgD/conanfile.py": conanfile.format(
                         requires='requires = "PkgC/0.1@{0}", "PkgB/0.1@{0}"'.format(user_channel)),
                     "PkgD/myfile.txt": "HelloD"
                     })
        for profile in ("Windows", "Linux"):
            client.run("create PkgA PkgA/0.1@{} -s os={}".format(user_channel, profile))
            client.run("create PkgB PkgB/0.1@{} -s os={}".format(user_channel, profile))
            client.run("create PkgC PkgC/0.1@{} -s os={}".format(user_channel, profile))
            client.run("create PkgD PkgD/0.1@{} -s os={}".format(user_channel, profile))
            client.run("lock create --reference PkgD/0.1@{} --build=PkgC --build=PkgD -s os={}"
                       " --lockfile-out={}.lock".format(user_channel, profile, profile))

            client.run("create PkgC PkgC/0.1@{0} --lockfile={1}.lock "
                       "--lockfile-out={1}.lock".format(user_channel, profile))
            client.run("create PkgD PkgD/0.1@{0} --lockfile={1}.lock "
                       "--lockfile-out={1}.lock".format(user_channel, profile))
            client.run("upload * --all --confirm -r default")

        sys.argv = ["conan_build_info", "--v2", "start", "MyBuildName", "42"]
        run()
        sys.argv = ["conan_build_info", "--v2", "create",
                    os.path.join(client.current_folder, "buildinfowin.json"), "--lockfile",
                    os.path.join(client.current_folder, "Windows.lock")]
        run()

        sys.argv = ["conan_build_info", "--v2", "create",
                    os.path.join(client.current_folder, "buildinfolinux.json"), "--lockfile",
                    os.path.join(client.current_folder, "Linux.lock")]
        run()

        user_channel = "@" + user_channel if user_channel else user_channel
        buildinfo = json.loads(client.load("buildinfowin.json"))
        self.assertEqual(buildinfo["name"], "MyBuildName")
        self.assertEqual(buildinfo["number"], "42")
        ids_list = [item["id"] for item in buildinfo["modules"]]
        rrev_pkgd, rrev_pkgc, prev_pkgd_win, prev_pkgc_win, prev_pkgd_linux, prev_pkgc_linux = "", "", "", "", "", ""
        if client.cache.config.revisions_enabled:
            rrev_pkgd = "#4923df588db8c6e5867f8df8b8d4e79d" if user_channel else "#a4041e14960e937df21d431579e32e9c"
            rrev_pkgc = "#4fb6c2b0610701ceb5d3b5ccb7a93ecf" if user_channel else "#9d4a7842c95b2ab65b99e2a8834c58da"
            prev_pkgd_win = "#fae36f88c6cc61dafd2afe78687ab248" if user_channel else "#5f50bfa7642cd8924c80b3d6be87b4c5"
            prev_pkgc_win = "#d0f5b7f73cb879dcc78b72ed3af8c85c" if user_channel else "#861f0854c9135d1e753ca9ffe8587d4a"
            prev_pkgd_linux = "#ca5538e3a9abdfcc024ebd96837b7161" if user_channel else "#e6adeb06f3b4296c63a751b5d68ed858"
            prev_pkgc_linux = "#472d19aea10fe10ddf081d13ca716404" if user_channel else "#919776eb660a26575c327cceb2f046f8"

        expected = ["PkgC/0.1{}{}".format(user_channel, rrev_pkgc),
                    "PkgD/0.1{}{}".format(user_channel, rrev_pkgd),
                    "PkgC/0.1{}{}:3374c4fa6b7e865cfc3a1903ae014cf77a6938ec{}".format(user_channel, rrev_pkgc, prev_pkgc_win),
                    "PkgD/0.1{}{}:6cd742f1b907e693abf6da9f767aab3ee7fde606{}".format(user_channel, rrev_pkgd, prev_pkgd_win)]
        self.assertEqual(set(expected), set(ids_list))

        buildinfo = json.loads(client.load("buildinfolinux.json"))
        self.assertEqual(buildinfo["name"], "MyBuildName")
        self.assertEqual(buildinfo["number"], "42")
        ids_list = [item["id"] for item in buildinfo["modules"]]
        expected = ["PkgC/0.1{}{}".format(user_channel, rrev_pkgc),
                    "PkgD/0.1{}{}".format(user_channel, rrev_pkgd),
                    "PkgC/0.1{}{}:a1e39343af463cef4284c5550fde03912afd9852{}".format(user_channel, rrev_pkgc, prev_pkgc_linux),
                    "PkgD/0.1{}{}:39af3f48fdee2bbc5f84e7da3a67ebab2a297acb{}".format(user_channel, rrev_pkgd, prev_pkgd_linux)]
        self.assertEqual(set(expected), set(ids_list))

        sys.argv = ["conan_build_info", "--v2", "update",
                    os.path.join(client.current_folder, "buildinfowin.json"),
                    os.path.join(client.current_folder, "buildinfolinux.json"),
                    "--output-file", os.path.join(client.current_folder, "mergedbuildinfo.json")]
        run()

        f = client.load("mergedbuildinfo.json")
        buildinfo = json.loads(f)
        self.assertEqual(buildinfo["name"], "MyBuildName")
        self.assertEqual(buildinfo["number"], "42")
        ids_list = [item["id"] for item in buildinfo["modules"]]
        expected = ["PkgC/0.1{}{}".format(user_channel, rrev_pkgc),
                    "PkgD/0.1{}{}".format(user_channel, rrev_pkgd),
                    "PkgC/0.1{}{}:3374c4fa6b7e865cfc3a1903ae014cf77a6938ec{}".format(user_channel, rrev_pkgc, prev_pkgc_win),
                    "PkgC/0.1{}{}:a1e39343af463cef4284c5550fde03912afd9852{}".format(user_channel, rrev_pkgc, prev_pkgc_linux),
                    "PkgD/0.1{}{}:6cd742f1b907e693abf6da9f767aab3ee7fde606{}".format(user_channel, rrev_pkgd, prev_pkgd_win),
                    "PkgD/0.1{}{}:39af3f48fdee2bbc5f84e7da3a67ebab2a297acb{}".format(user_channel, rrev_pkgd, prev_pkgd_linux)
                    ]
        self.assertEqual(set(expected), set(ids_list))

        sys.argv = ["conan_build_info", "--v2", "publish",
                    os.path.join(client.current_folder, "mergedbuildinfo.json"), "--url",
                    "http://fakeurl:8081/artifactory", "--user", "user", "--password", "password"]
        run()
        sys.argv = ["conan_build_info", "--v2", "publish",
                    os.path.join(client.current_folder, "mergedbuildinfo.json"), "--url",
                    "http://fakeurl:8081/artifactory", "--apikey", "apikey"]
        run()

        sys.argv = ["conan_build_info", "--v2", "stop"]
        run()