|
1 | 1 | import textwrap
|
2 | 2 |
|
| 3 | +from conan.test.utils.mocks import ConanFileMock |
3 | 4 | from conan.test.utils.tools import TestClient
|
| 5 | +from conan.tools.env.environment import environment_wrap_command |
| 6 | +from conan.test.assets.genconanfile import GenConanfile |
4 | 7 |
|
5 | 8 |
|
6 | 9 | def assert_vars_file(client, configuration):
|
@@ -62,3 +65,114 @@ def package_info(self):
|
62 | 65 | # Assert package per configuration files
|
63 | 66 | assert_vars_file(client, 'debug')
|
64 | 67 | assert_vars_file(client, 'release')
|
| 68 | + |
| 69 | + |
| 70 | +def test_todo(): |
| 71 | + # Create package |
| 72 | + client = TestClient() |
| 73 | + # client.run("remote add conancenter https://center2.conan.io") |
| 74 | + |
| 75 | + def run_pkg(msg): |
| 76 | + host_arch = client.get_default_host_profile().settings['arch'] |
| 77 | + cmd_release = environment_wrap_command(ConanFileMock(), f"conanrunenv-release-{host_arch}", |
| 78 | + client.current_folder, "dep") |
| 79 | + client.run_command(cmd_release) |
| 80 | + assert "{}: Hello World Release!".format(msg) in client.out |
| 81 | + |
| 82 | + client.run("new cmake_lib -d name=dep -d version=1.0 -o dep") |
| 83 | + |
| 84 | + consumer_source = textwrap.dedent(""" |
| 85 | + #include <iostream> |
| 86 | + #include "dep.h" |
| 87 | +
|
| 88 | + int main(void) { |
| 89 | + dep(); |
| 90 | + std::cout << "Hello World" << std::endl; |
| 91 | + return 0; |
| 92 | + } |
| 93 | + """) |
| 94 | + |
| 95 | + premake5 = textwrap.dedent(""" |
| 96 | + include("conandeps.premake5.lua") |
| 97 | +
|
| 98 | + workspace "HelloWorld" |
| 99 | + configurations { "Debug", "Release" } |
| 100 | +
|
| 101 | + project "HelloWorld" |
| 102 | + kind "ConsoleApp" |
| 103 | + language "C++" |
| 104 | + targetdir "bin/%{cfg.buildcfg}" |
| 105 | +
|
| 106 | + files { "**.h", "**.cpp" } |
| 107 | + conan_setup() |
| 108 | +
|
| 109 | + filter "configurations:Debug" |
| 110 | + defines { "DEBUG" } |
| 111 | + symbols "On" |
| 112 | +
|
| 113 | + filter "configurations:Release" |
| 114 | + defines { "NDEBUG" } |
| 115 | + optimize "On" |
| 116 | + """) |
| 117 | + |
| 118 | + |
| 119 | + conanfile = textwrap.dedent(""" |
| 120 | + from conan import ConanFile |
| 121 | + from conan import ConanFile |
| 122 | + from conan.tools.files import copy, get, collect_libs, chdir, save, replace_in_file |
| 123 | + from conan.tools.layout import basic_layout |
| 124 | + from conan.tools.microsoft import MSBuild |
| 125 | + from conan.tools.premake import Premake, PremakeDeps |
| 126 | + import os |
| 127 | +
|
| 128 | + class Pkg(ConanFile): |
| 129 | + settings = "os", "compiler", "build_type", "arch" |
| 130 | + name = "pkg" |
| 131 | + version = "1.0" |
| 132 | + exports_sources = '*' |
| 133 | +
|
| 134 | + def layout(self): |
| 135 | + basic_layout(self, src_folder="src") |
| 136 | +
|
| 137 | + def requirements(self): |
| 138 | + self.requires("dep/1.0") |
| 139 | +
|
| 140 | + def generate(self): |
| 141 | + deps = PremakeDeps(self) |
| 142 | + deps.generate() |
| 143 | +
|
| 144 | + def build(self): |
| 145 | + with chdir(self, self.source_folder): |
| 146 | + premake = Premake(self) |
| 147 | + premake.arguments = {"scripts": "../build-release/conan"} |
| 148 | + premake.configure() |
| 149 | + if self.settings.os == "Windows": |
| 150 | + pass |
| 151 | + # msbuild = MSBuild(self) |
| 152 | + # msbuild.build("Yojimbo.sln") |
| 153 | + else: |
| 154 | + build_type = str(self.settings.build_type) |
| 155 | + self.run(f"make config={build_type.lower()} -j") |
| 156 | +
|
| 157 | + def package(self): |
| 158 | + copy(self, "*.h", os.path.join(self.source_folder, "include"), os.path.join(self.package_folder, "include", "pkg")) |
| 159 | + for lib in ("*.lib", "*.a"): |
| 160 | + copy(self, lib, self.source_folder, os.path.join(self.package_folder, "lib"), keep_path=False) |
| 161 | + """) |
| 162 | + |
| 163 | + client.save({"consumer/conanfile.py": conanfile, |
| 164 | + "consumer/src/hello.cpp": consumer_source, |
| 165 | + "consumer/src/premake5.lua": premake5, |
| 166 | + }) |
| 167 | + |
| 168 | + client.run("create dep") |
| 169 | + client.run("create consumer --build=missing") |
| 170 | + build_folder = client.created_layout().build() |
| 171 | + print(build_folder) |
| 172 | + |
| 173 | + print(client.out) |
| 174 | + client.run("install consumer") |
| 175 | + run_pkg("Hello World") |
| 176 | + |
| 177 | + print(client.out) |
| 178 | + |
0 commit comments