Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed workspace imports #9281

Merged
merged 2 commits into from Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions conans/client/installer.py
Expand Up @@ -467,6 +467,7 @@ def _handle_node_editable(self, node, profile_host, profile_build, graph_lock):
conanfile.folders.set_base_source(base_path)
conanfile.folders.set_base_build(base_path)
conanfile.folders.set_base_install(base_path)
conanfile.folders.set_base_imports(base_path)

output = conanfile.output
output.info("Rewriting files of editable package "
Expand Down Expand Up @@ -516,6 +517,7 @@ def _handle_node_editable(self, node, profile_host, profile_build, graph_lock):
output.info("Generated %s" % BUILD_INFO)
# Build step might need DLLs, binaries as protoc to generate source files
# So execute imports() before build, storing the list of copied_files
conanfile.folders.set_base_imports(build_folder)
copied_files = run_imports(conanfile)
report_copied_files(copied_files, output)

Expand Down
78 changes: 71 additions & 7 deletions conans/test/functional/workspace/workspace_test.py
@@ -1,5 +1,6 @@
import os
import platform
import textwrap
import unittest
from textwrap import dedent

Expand All @@ -14,7 +15,7 @@
from conans.model.workspace import Workspace
from conans.test.utils.test_files import temp_folder
from conans.test.utils.tools import TestClient, GenConanfile
from conans.util.files import load, save
from conans.util.files import save

conanfile_build = """from conans import ConanFile, CMake
class Pkg(ConanFile):
Expand Down Expand Up @@ -192,7 +193,7 @@ def files(name, depend=None):
for f in ("conanbuildinfo.cmake", "conaninfo.txt", "conanbuildinfo.txt"):
self.assertTrue(os.path.exists(os.path.join(client.current_folder, sub, f)))

@parameterized.expand([("csv",), ("list",), (("abbreviated_list"))])
@parameterized.expand([("csv",), ("list",), ("abbreviated_list",)])
@pytest.mark.tool_cmake
def test_multiple_roots(self, root_attribute_format):
# https://github.com/conan-io/conan/issues/4720
Expand Down Expand Up @@ -850,9 +851,9 @@ def files(name, depend=None):
self.assertIn("HelloB/0.1@lasote/stable from user folder - Editable", client.out)
self.assertIn("HelloC/0.1@lasote/stable from user folder - Editable", client.out)

cmake = client.load(os.path.join("A", "build", "conanbuildinfo.cmake"))
self.assertIn("myincludeC", cmake)
self.assertIn("myincludeB", cmake)
conanbuildcmake = client.load(os.path.join("A", "build", "conanbuildinfo.cmake"))
self.assertIn("myincludeC", conanbuildcmake)
self.assertIn("myincludeB", conanbuildcmake)

@pytest.mark.tool_compiler
def test_generators(self):
Expand Down Expand Up @@ -1063,12 +1064,75 @@ def package_info(self):
""")
client.save({"conanws.yml": project,
"layout": layout})
client.run(
"workspace install conanws.yml --install-folder=ws_install --build Tool/0.1@user/testing")
client.run("workspace install conanws.yml --install-folder=ws_install "
"--build Tool/0.1@user/testing")
self.assertTrue(os.path.exists(os.path.join(client.current_folder, "ws_install",
"conanworkspace.cmake")))

def test_missing_subarguments(self):
client = TestClient()
client.run("workspace", assert_error=True)
self.assertIn("ERROR: Exiting with code: 2", client.out)


def test_error_imports():
# https://github.com/conan-io/conan/issues/9263
c = TestClient()
conanws = dedent("""
editables:
liba/0.1:
path: liba
libb/0.1:
path: libb
layout: layout
root: libb/0.1
""")
libb = textwrap.dedent("""
from conans import ConanFile
class LibB(ConanFile):
requires = "liba/0.1"
generator = "cmake"

def imports(self):
self.copy("*.txt")
""")
layout = dedent("""
[build_folder]
build
""")
c.save({"liba/conanfile.py": GenConanfile(),
"liba/filea.txt": "HelloA!",
"libb/conanfile.py": libb,
"conanws.yml": conanws,
"layout": layout})
c.run("workspace install conanws.yml")
assert c.load("libb/build/filea.txt") == "HelloA!"


def test_error_imports_modern():
# https://github.com/conan-io/conan/issues/9263
c = TestClient()
conanws = dedent("""
editables:
liba/0.1:
path: liba
libb/0.1:
path: libb
root: libb/0.1
""")
libb = textwrap.dedent("""
from conans import ConanFile
class LibB(ConanFile):
requires = "liba/0.1"
generator = "cmake"
def layout(self):
pass
def imports(self):
self.copy("*.txt")
""")
c.save({"liba/conanfile.py": GenConanfile(),
"liba/filea.txt": "HelloA!",
"libb/conanfile.py": libb,
"conanws.yml": conanws})
c.run("workspace install conanws.yml")
assert c.load("libb/filea.txt") == "HelloA!"