Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into feature/base_path
Browse files Browse the repository at this point in the history
  • Loading branch information
lasote committed Sep 13, 2021
2 parents f8e731b + acfaf91 commit 8f3fbb5
Show file tree
Hide file tree
Showing 15 changed files with 214 additions and 19 deletions.
6 changes: 3 additions & 3 deletions conan/tools/env/environment.py
Expand Up @@ -194,7 +194,7 @@ def prepend_path(self, name, value):
def remove(self, name, value):
self._values[name].remove(value)

def save_bat(self, filename, generate_deactivate=False, pathsep=os.pathsep):
def save_bat(self, filename, generate_deactivate=True, pathsep=os.pathsep):
deactivate = textwrap.dedent("""\
echo Capturing current environment in deactivate_{filename}
setlocal
Expand Down Expand Up @@ -228,7 +228,7 @@ def save_bat(self, filename, generate_deactivate=False, pathsep=os.pathsep):
content = "\n".join(result)
save(filename, content)

def save_ps1(self, filename, generate_deactivate=False, pathsep=os.pathsep):
def save_ps1(self, filename, generate_deactivate=True, pathsep=os.pathsep):
# FIXME: This is broken and doesnt work
deactivate = ""
capture = textwrap.dedent("""\
Expand All @@ -242,7 +242,7 @@ def save_ps1(self, filename, generate_deactivate=False, pathsep=os.pathsep):
content = "\n".join(result)
save(filename, content)

def save_sh(self, filename, generate_deactivate=False, pathsep=os.pathsep):
def save_sh(self, filename, generate_deactivate=True, pathsep=os.pathsep):
deactivate = textwrap.dedent("""\
echo Capturing current environment in deactivate_{filename}
echo echo Restoring variables >> deactivate_{filename}
Expand Down
2 changes: 1 addition & 1 deletion conans/__init__.py
Expand Up @@ -20,4 +20,4 @@
SERVER_CAPABILITIES = [COMPLEX_SEARCH_CAPABILITY, REVISIONS] # Server is always with revisions
DEFAULT_REVISION_V1 = "0"

__version__ = '1.40.0'
__version__ = '1.41.0-dev'
2 changes: 1 addition & 1 deletion conans/client/conf/config_installer.py
Expand Up @@ -137,7 +137,7 @@ def _process_folder(config, folder, cache, output):
def _process_download(config, cache, output, requester):
with tmp_config_install_folder(cache) as tmp_folder:
output.info("Trying to download %s" % _hide_password(config.uri))
zippath = os.path.join(tmp_folder, "config.zip")
zippath = os.path.join(tmp_folder, os.path.basename(config.uri))
try:
tools.download(config.uri, zippath, out=output, verify=config.verify_ssl,
requester=requester)
Expand Down
2 changes: 2 additions & 0 deletions conans/client/migrations_settings.py
Expand Up @@ -2430,3 +2430,5 @@
cppstd: [None, 98, gnu98, 11, gnu11, 14, gnu14, 17, gnu17, 20, gnu20, 23, gnu23] # Deprecated, use compiler.cppstd
"""

settings_1_41_0 = settings_1_40_0
5 changes: 3 additions & 2 deletions conans/client/source.py
Expand Up @@ -105,7 +105,7 @@ def get_sources_from_exports():
# First of all get the exported scm sources (if auto) or clone (if fixed)
_run_cache_scm(conanfile, scm_sources_folder, output)
# so self exported files have precedence over python_requires ones
merge_directories(export_folder, conanfile.source_folder)
merge_directories(export_folder, conanfile.folders.base_source)
# Now move the export-sources to the right location
merge_directories(export_source_folder, conanfile.folders.base_source)

Expand Down Expand Up @@ -139,7 +139,8 @@ def _run_source(conanfile, conanfile_path, hook_manager, reference, cache,
get_sources_from_exports()

if cache:
_clean_source_folder(src_folder) # TODO: Why is it needed in cache?
# Clear the conanfile.py to avoid errors cloning git repositories.
_clean_source_folder(src_folder)
with conanfile_exception_formatter(conanfile.display_name, "source"):

with conan_v2_property(conanfile, 'settings',
Expand Down
1 change: 0 additions & 1 deletion conans/requirements.txt
Expand Up @@ -8,7 +8,6 @@ fasteners>=0.14.1
six>=1.10.0,<=1.16.0
node-semver==0.6.1
distro>=1.0.2, <=1.6.0
future>=0.16.0, <0.19.0
pygments>=2.0, <3.0
tqdm>=4.28.1, <5
Jinja2>=2.9, <3
Expand Down
29 changes: 28 additions & 1 deletion conans/test/functional/command/config_install_test.py
@@ -1,6 +1,7 @@
import json
import os
import shutil
import tarfile
import textwrap
import time
import unittest
Expand All @@ -16,7 +17,7 @@
from conans.client.downloaders.file_downloader import FileDownloader
from conans.errors import ConanException
from conans.test.assets.genconanfile import GenConanfile
from conans.test.utils.test_files import temp_folder
from conans.test.utils.test_files import scan_folder, temp_folder, tgz_with_contents
from conans.test.utils.tools import TestClient, StoppableThreadBottle, zipdir
from conans.util.files import load, mkdir, save, save_files, make_file_read_only

Expand Down Expand Up @@ -144,6 +145,21 @@ def _create_zip(self, zippath=None):
zipdir(folder, zippath)
return zippath

@staticmethod
def _get_files(folder):
relpaths = scan_folder(folder)
files = {}
for path in relpaths:
with open(os.path.join(folder, path), "r") as file_handle:
files[path] = file_handle.read()
return files

def _create_tgz(self, tgz_path=None):
folder = self._create_profile_folder()
tgz_path = tgz_path or os.path.join(folder, "myconfig.tar.gz")
files = self._get_files(folder)
return tgz_with_contents(files, tgz_path)

def _check(self, params):
typ, uri, verify, args = [p.strip() for p in params.split(",")]
configs = json.loads(load(self.client.cache.config_install_file))
Expand Down Expand Up @@ -362,6 +378,17 @@ def my_download(obj, url, file_path, **kwargs): # @UnusedVariable
self.client.run("config install http://myfakeurl.com/myconf.zip --verify-ssl=False")
self._check("url, http://myfakeurl.com/myconf.zip, False, None")

def test_install_url_tgz(self):
""" should install from a URL to tar.gz
"""

def my_download(obj, url, file_path, **kwargs): # @UnusedVariable
self._create_tgz(file_path)

with patch.object(FileDownloader, 'download', new=my_download):
self.client.run("config install http://myfakeurl.com/myconf.tar.gz")
self._check("url, http://myfakeurl.com/myconf.tar.gz, True, None")

def test_failed_install_repo(self):
""" should install from a git repo
"""
Expand Down
34 changes: 34 additions & 0 deletions conans/test/functional/layout/test_in_cache.py
Expand Up @@ -7,6 +7,7 @@
from conans import load
from conans.model.ref import ConanFileReference, PackageReference
from conans.test.assets.genconanfile import GenConanfile
from conans.test.utils.test_files import temp_folder
from conans.test.utils.tools import TestClient


Expand Down Expand Up @@ -270,3 +271,36 @@ def generate(self):
assert 'set(hello_INCLUDE_DIRS_RELEASE "${hello_PACKAGE_FOLDER_RELEASE}/foo/include")' in cmake
assert 'set(hello_LIB_DIRS_RELEASE "${hello_PACKAGE_FOLDER_RELEASE}/foo/libs")' in cmake
assert 'set(hello_LIBS_RELEASE foo)' in cmake


def test_git_clone_with_source_layout():
client = TestClient()
repo = temp_folder()
conanfile = textwrap.dedent("""
import os
from conans import ConanFile
class Pkg(ConanFile):
exports = "*.txt"
def layout(self):
self.folders.source = "src"
def source(self):
self.run('git clone "{}" src')
""").format(repo.replace("\\", "/"))

client.save({"conanfile.py": conanfile,
"myfile.txt": "My file is copied"})
with client.chdir(repo):
client.save({"cloned.txt": "foo"}, repo)
client.init_git_repo()

client.run("create . hello/1.0@")
sf = client.cache.package_layout(ConanFileReference.loads("hello/1.0@")).source()
assert os.path.exists(os.path.join(sf, "myfile.txt"))
# The conanfile is cleared from the root before cloning
assert not os.path.exists(os.path.join(sf, "conanfile.py"))
assert not os.path.exists(os.path.join(sf, "cloned.txt"))

assert os.path.exists(os.path.join(sf, "src", "cloned.txt"))
assert not os.path.exists(os.path.join(sf, "src", "myfile.txt"))
Expand Up @@ -48,11 +48,14 @@ def package_info(self):
self.cpp_info.set_property("cmake_module_file_name", "mi_dependencia")
self.cpp_info.set_property("cmake_module_target_name", "mi_dependencia_target")
self.cpp_info.set_property("cmake_module_target_namespace", "mi_dependencia_namespace")
self.cpp_info.set_property("cmake_module_target_namespace",
"mi_dependencia_namespace")
self.cpp_info.components["crispin"].libs = ["mydep"]
self.cpp_info.components["crispin"].set_property("cmake_target_name", "MyCrispinTarget")
self.cpp_info.components["crispin"].set_property("cmake_module_target_name", "mi_crispin_target")
self.cpp_info.components["crispin"].set_property("cmake_target_name",
"MyCrispinTarget")
self.cpp_info.components["crispin"].set_property("cmake_module_target_name",
"mi_crispin_target")
""")

t.save({"conanfile.py": conanfile,
Expand Down
131 changes: 131 additions & 0 deletions conans/test/functional/toolchains/cmake/test_cmaketoolchain_paths.py
@@ -0,0 +1,131 @@
import textwrap

import pytest

from conans.test.utils.tools import TestClient


@pytest.mark.tool_cmake
@pytest.mark.parametrize("package", ["hello", "ZLIB"])
@pytest.mark.parametrize("find_package", ["module", "config"])
def test_cmaketoolchain_path_find(package, find_package):
"""Test with user "Hello" and also ZLIB one, to check that package ZLIB
has priority over the CMake system one
Also, that user cmake files in the root are accessible via CMake include()
"""
client = TestClient()
conanfile = textwrap.dedent("""
from conans import ConanFile
class TestConan(ConanFile):
exports = "*"
def layout(self):
pass
def package(self):
self.copy(pattern="*", keep_path=False)
""")
find = textwrap.dedent("""
SET({package}_FOUND 1)
MESSAGE("HELLO FROM THE {package} FIND PACKAGE!")
""").format(package=package)
myowncmake = textwrap.dedent("""
MESSAGE("MYOWNCMAKE FROM {package}!")
""").format(package=package)

filename = "{}Config.cmake" if find_package == "config" else "Find{}.cmake"
filename = filename.format(package)
client.save({"conanfile.py": conanfile,
"{}".format(filename): find,
"myowncmake.cmake": myowncmake})
client.run("create . {}/0.1@".format(package))

consumer = textwrap.dedent("""
set(CMAKE_CXX_COMPILER_WORKS 1)
set(CMAKE_CXX_ABI_COMPILED 1)
project(MyHello CXX)
cmake_minimum_required(VERSION 3.15)
find_package({package} REQUIRED)
include(myowncmake)
""").format(package=package)

client.save({"CMakeLists.txt": consumer}, clean_first=True)
client.run("install {}/0.1@ -g CMakeToolchain".format(package))
with client.chdir("build"):
client.run_command("cmake .. -DCMAKE_TOOLCHAIN_FILE=../conan_toolchain.cmake")
assert "Conan: Target declared" not in client.out
assert "HELLO FROM THE {package} FIND PACKAGE!".format(package=package) in client.out
assert "MYOWNCMAKE FROM {package}!".format(package=package) in client.out

# If using the CMakeDeps generator, the in-package .cmake will be ignored
# But it is still possible to include(owncmake)
client.run("install {}/0.1@ -g CMakeToolchain -g CMakeDeps".format(package))
with client.chdir("build2"): # A clean folder, not the previous one, CMake cache doesnt affect
client.run_command("cmake .. -DCMAKE_TOOLCHAIN_FILE=../conan_toolchain.cmake")
assert "Conan: Target declared '{package}::{package}'".format(package=package) in client.out
assert "HELLO FROM THE {package} FIND PACKAGE!".format(package=package) not in client.out
assert "MYOWNCMAKE FROM {package}!".format(package=package) in client.out


@pytest.mark.tool_cmake
def test_cmaketoolchain_path_find_real_config():
client = TestClient()
conanfile = textwrap.dedent("""
from conans import ConanFile
from conan.tools.cmake import CMake
class TestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
exports = "*"
generators = "CMakeToolchain"
def layout(self):
pass
def build(self):
cmake = CMake(self)
cmake.configure()
def package(self):
cmake = CMake(self)
cmake.install()
""")
cmake = textwrap.dedent("""
cmake_minimum_required(VERSION 3.15)
project(MyHello NONE)
add_library(hello INTERFACE)
install(TARGETS hello EXPORT helloConfig)
export(TARGETS hello
NAMESPACE hello::
FILE "${CMAKE_CURRENT_BINARY_DIR}/helloConfig.cmake"
)
install(EXPORT helloConfig
DESTINATION "${CMAKE_INSTALL_PREFIX}/hello/cmake"
NAMESPACE hello::
)
""")
client.save({"conanfile.py": conanfile,
"CMakeLists.txt": cmake})
client.run("create . hello/0.1@")

consumer = textwrap.dedent("""
project(MyHello NONE)
cmake_minimum_required(VERSION 3.15)
find_package(hello REQUIRED)
""")

client.save({"CMakeLists.txt": consumer}, clean_first=True)
client.run("install hello/0.1@ -g CMakeToolchain")
with client.chdir("build"):
client.run_command("cmake .. -DCMAKE_TOOLCHAIN_FILE=../conan_toolchain.cmake")
# If it didn't fail, it found the helloConfig.cmake
assert "Conan: Target declared" not in client.out

# If using the CMakeDeps generator, the in-package .cmake will be ignored
# But it is still possible to include(owncmake)
client.run("install hello/0.1@ -g CMakeToolchain -g CMakeDeps")
with client.chdir("build2"): # A clean folder, not the previous one, CMake cache doesnt affect
client.run_command("cmake .. -DCMAKE_TOOLCHAIN_FILE=../conan_toolchain.cmake")
assert "Conan: Target declared 'hello::hello'" in client.out

6 changes: 3 additions & 3 deletions conans/test/unittests/tools/env/test_env.py
Expand Up @@ -257,7 +257,7 @@ def check(cmd_):

with chdir(folder):
if platform.system() == "Windows":
env.save_bat("test.bat", pathsep=":", generate_deactivate=True)
env.save_bat("test.bat", pathsep=":")

save("display.bat", display_bat)
cmd = "test.bat && display.bat && deactivate_test.bat && display.bat"
Expand All @@ -270,7 +270,7 @@ def check(cmd_):
# stdout, stderr = decode_text(stdout), decode_text(stderr)
# check(cmd)
else:
env.save_sh("test.sh", pathsep=":", generate_deactivate=True)
env.save_sh("test.sh", pathsep=":")
save("display.sh", display_sh)
os.chmod("display.sh", 0o777)
cmd = '. ./test.sh && ./display.sh && . ./deactivate_test.sh && ./display.sh'
Expand All @@ -294,7 +294,7 @@ def test_windows_case_insensitive():
""")

with chdir(folder):
env.save_bat("test.bat", generate_deactivate=True)
env.save_bat("test.bat")
save("display.bat", display_bat)
cmd = "test.bat && display.bat && deactivate_test.bat && display.bat"
out, _ = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
Expand Down
4 changes: 2 additions & 2 deletions conans/test/utils/test_files.py
Expand Up @@ -73,9 +73,9 @@ def scan_folder(folder):
return sorted(scanned_files)


def tgz_with_contents(files):
def tgz_with_contents(files, output_path=None):
folder = temp_folder()
file_path = os.path.join(folder, "myfile.tar.gz")
file_path = output_path or os.path.join(folder, "myfile.tar.gz")

with open(file_path, "wb") as tgz_handle:
tgz = gzopen_without_timestamps("myfile.tar.gz", mode="w", fileobj=tgz_handle)
Expand Down
2 changes: 0 additions & 2 deletions pyinstaller.py
@@ -1,5 +1,3 @@
from __future__ import print_function

import os
import platform
import shutil
Expand Down

0 comments on commit 8f3fbb5

Please sign in to comment.