Ejemplo n.º 1
0
def test_zip_download_with_subfolder_new_tools(no_copy_source):
    """If we have a zip with the sources in a subfolder, specifying it in the self.folders.source
    will unzip in the base and will work both locally (conan build) or in the cache
    (exporting the sources)"""

    tmp = TestClient()  # Used only to save some files, sorry for the lazyness
    cmake = gen_cmakelists(appname="my_app", appsources=["main.cpp"])
    app = gen_function_cpp(name="main")
    tmp.save({
        "subfolder/main.cpp": app,
        "subfolder/CMakeLists.txt": cmake,
        "ignored_subfolder/ignored.txt": ""
    })
    zippath = os.path.join(tmp.current_folder, "my_sources.zip")
    zipdir(tmp.current_folder, zippath)

    conan_file = GenConanfile() \
        .with_import("import os") \
        .with_import("from conan.tools.files import get") \
        .with_import("from conan.tools.cmake import CMake") \
        .with_name("app").with_version("1.0") \
        .with_settings("os", "arch", "build_type", "compiler") \
        .with_generator("CMakeToolchain") \
        .with_class_attribute("no_copy_source={}".format(no_copy_source))

    conan_file = str(conan_file)
    conan_file += """
    def source(self):
        get(self, "http://fake_url/my_sources.zip")

    def layout(self):
        self.folders.source = "subfolder"

    def build(self):
        assert os.path.exists(os.path.join(self.source_folder, "CMakeLists.txt"))
        assert "subfolder" in self.source_folder
        assert os.path.exists(os.path.join(self.source_folder, "..",
                                           "ignored_subfolder", "ignored.txt"))
        cmake = CMake(self)
        cmake.configure()
        cmake.build()
    """
    client = TestClient()
    client.save({"conanfile.py": conan_file})

    with mock.patch("conan.tools.files.files.download") as mock_download:

        def download_zip(*args, **kwargs):
            copy(zippath, os.getcwd())

        mock_download.side_effect = download_zip
        client.run("create . ")
Ejemplo n.º 2
0
 def mock_download(*args, **kwargs):
     tmp_folder = temp_folder()
     with chdir(tmp_folder):
         ori_files_dir = os.path.join(tmp_folder, "subfolder-1.2.3")
         file1 = os.path.join(ori_files_dir, "file1")
         file2 = os.path.join(ori_files_dir, "folder", "file2")
         # !!! This file is not under the root "subfolder-1.2.3"
         file3 = os.path.join("file3")
         save(file1, "")
         save(file2, "")
         save(file3, "")
         zip_file = os.path.join(zip_folder, "file.zip")
         zipdir(tmp_folder, zip_file)
Ejemplo n.º 3
0
 def _create_zip(self, zippath=None):
     folder = self._create_profile_folder()
     zippath = zippath or os.path.join(folder, "myconfig.zip")
     zipdir(folder, zippath)
     return zippath