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

waf: migrate to Conan v2 #18745

Merged
merged 7 commits into from
Dec 5, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions recipes/waf/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
sources:
"2.0.26":
url: "https://waf.io/waf-2.0.26.tar.bz2"
sha256: "c33d19c1bdfae1b078edaef2fab19b1bc734294edd4cc005d4881e9d53ed219c"
"2.0.25":
url: "https://waf.io/waf-2.0.25.tar.bz2"
sha256: "66cff7beed0e77db874e9232cc08874abb3e866c7f0f1f34ba2f959fde44fdd4"
"2.0.19":
url: "https://waf.io/waf-2.0.19.tar.bz2"
sha256: "d8402689b72fe75f759a83b5f6bdf9b4f34ca7fd6007d80680ecfcbef5c2bba5"
57 changes: 32 additions & 25 deletions recipes/waf/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
from conans import ConanFile, tools
import os

from conan import ConanFile
from conan.tools.files import copy, get, save
from conan.tools.layout import basic_layout

required_conan_version = ">=1.47.0"


class WafConan(ConanFile):
name = "waf"
description = "The Waf build system"
topics = ("conan", "waf", "builsystem")
license = "BSD-3-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://waf.io"
license = "BSD-3-Clause"
settings = "os", "arch"
topics = ("buildsystem", "pre-built")

@property
def _source_subfolder(self):
return "source_subfolder"
package_type = "application"
settings = "os", "arch", "compiler", "build_type"

def layout(self):
basic_layout(self, src_folder="src")

def package_id(self):
del self.info.settings.compiler
del self.info.settings.build_type

def source(self):
tools.get(**self.conan_data["sources"][self.version])
os.rename("waf-{}".format(self.version), self._source_subfolder)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

@property
def _license_text(self):
[_, license, _] = open(os.path.join(self.source_folder, self._source_subfolder, "waf"), "rb").read().split(b"\"\"\"", 3)
return license.decode().lstrip()
license_text = self.source_path.joinpath("waf").read_bytes().split(b'"""', 3)[1]
return license_text.decode().lstrip()

def build(self):
pass
Expand All @@ -31,30 +40,28 @@ def package(self):
binpath = os.path.join(self.package_folder, "bin")
libpath = os.path.join(self.package_folder, "lib")

os.mkdir(binpath)
os.mkdir(libpath)
save(self, os.path.join(self.package_folder, "licenses", "LICENSE"), self._license_text)

tools.save(os.path.join(self.package_folder, "licenses", "LICENSE"), self._license_text)

self.copy("waf", src=self._source_subfolder, dst=binpath)
self.copy("waf-light", src=self._source_subfolder, dst=binpath)
self.copy("waflib/*", src=self._source_subfolder, dst=libpath)
copy(self, "waf", src=self.source_folder, dst=binpath)
copy(self, "waf-light", src=self.source_folder, dst=binpath)
copy(self, "waflib/*", src=self.source_folder, dst=libpath)

if self.settings.os == "Windows":
self.copy("waf.bat", src=os.path.join(self._source_subfolder, "utils"), dst=binpath)
copy(self, "waf.bat", src=os.path.join(self.source_folder, "utils"), dst=binpath)

os.chmod(os.path.join(binpath, "waf"), 0o755)
os.chmod(os.path.join(binpath, "waf-light"), 0o755)

def package_info(self):
self.cpp_info.frameworkdirs = []
self.cpp_info.resdirs = []
self.cpp_info.includedirs = []
self.cpp_info.libdirs = []

wafdir = os.path.join(self.package_folder, "lib")
self.buildenv_info.define_path("WAFDIR", wafdir)

# TODO: Legacy, remove in 2.0
binpath = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH env var: {}".format(binpath))
self.env_info.PATH.append(binpath)

wafdir = os.path.join(self.package_folder, "lib")
self.output.info("Setting WAFDIR env var: {}".format(wafdir))
self.env_info.WAFDIR = wafdir


67 changes: 35 additions & 32 deletions recipes/waf/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
from conans import ConanFile, tools
from contextlib import contextmanager
import os
import shutil

from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.env import Environment, VirtualBuildEnv
from conan.tools.files import chdir
from conan.tools.layout import basic_layout


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
settings = "os", "arch", "compiler", "build_type"
test_type = "explicit"
exports_sources = "a.cpp", "b.cpp", "main.c", "main.cpp", "wscript"

def build_requirements(self):
self.tool_requires(self.tested_reference_str)

def layout(self):
basic_layout(self)

def generate(self):
buildenv = VirtualBuildEnv(self)
buildenv.generate()

env = Environment()
for var in ["DYLD_LIBRARY_PATH", "LD_LIBRARY_PATH"]:
env.append_path(var, self.build_folder)
env.vars(self, scope="run").save_script("conanrun_macos_dyld_path")

def build(self):
if tools.cross_building(self.settings):
return

for src in self.exports_sources:
shutil.copy(os.path.join(self.source_folder, src), self.build_folder)

waf_path = tools.which("waf")
if waf_path:
waf_path = waf_path.replace("\\", "/")
assert waf_path.startswith(str(self.deps_cpp_info["waf"].rootpath))

with tools.vcvars(self.settings) if self.settings.compiler == "Visual Studio" else tools.no_op():
self.run("waf -h")
self.run("waf configure")
self.run("waf")

@contextmanager
def _add_ld_search_path(self):
env = {}
if self.settings.os == "Linux":
env["LD_LIBRARY_PATH"] = [os.path.join(os.getcwd(), "build")]
elif self.settings.os == "Macos":
env["DYLD_LIBRARY_PATH"] = [os.path.join(os.getcwd(), "build")]
with tools.environment_append(env):
yield
if can_run(self):
for src in self.exports_sources:
shutil.copy(os.path.join(self.source_folder, src), self.build_folder)

with chdir(self, self.build_folder):
self.run(f"waf configure -o {self.cpp.build.bindir}")
self.run("waf")

def test(self):
if not tools.cross_building(self.settings):
with self._add_ld_search_path():
self.run(os.path.join("build", "app"), run_environment=True)
self.run(os.path.join("build", "app2"), run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "app")
self.run(bin_path, env="conanrun")
bin_path = os.path.join(self.cpp.build.bindir, "app2")
self.run(bin_path, env="conanrun")
43 changes: 43 additions & 0 deletions recipes/waf/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from conan.tools.apple import is_apple_os
from conans import ConanFile, tools
from contextlib import contextmanager
import os
import shutil


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
exports_sources = "a.cpp", "b.cpp", "main.c", "main.cpp", "wscript"

def build(self):
if tools.cross_building(self.settings):
return

for src in self.exports_sources:
shutil.copy(os.path.join(self.source_folder, os.pardir, "test_package", src), self.build_folder)

waf_path = tools.which("waf")
if waf_path:
waf_path = waf_path.replace("\\", "/")
assert waf_path.startswith(str(self.deps_cpp_info["waf"].rootpath))

with tools.vcvars(self.settings) if self.settings.compiler == "Visual Studio" else tools.no_op():
self.run("waf -h")
self.run("waf configure")
self.run("waf")

@contextmanager
def _add_ld_search_path(self):
env = {}
if self.settings.os in ["Linux", "FreeBSD"]:
env["LD_LIBRARY_PATH"] = [os.path.join(os.getcwd(), "build")]
elif is_apple_os(self):
env["DYLD_LIBRARY_PATH"] = [os.path.join(os.getcwd(), "build")]
with tools.environment_append(env):
yield

def test(self):
if not tools.cross_building(self.settings):
with self._add_ld_search_path():
self.run(os.path.join("build", "app"), run_environment=True)
self.run(os.path.join("build", "app2"), run_environment=True)
4 changes: 4 additions & 0 deletions recipes/waf/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
versions:
"2.0.26":
folder: all
"2.0.25":
folder: all
"2.0.19":
folder: all