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

ftjam: migrate to Conan v2 #19238

Merged
merged 5 commits into from
Nov 14, 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
3 changes: 0 additions & 3 deletions recipes/ftjam/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
url: "http://downloads.sourceforge.net/freetype/ftjam-2.5.2.tar.gz"
sha256: "a5d456f65477d77936e1726f5f803a2e6def18a6c6fccf5ea8528926c136abc8"
patches:
"2.5.2":
- patch_file: "patches/0001-jam-2.5-overflow.patch"

Check warning on line 7 in recipes/ftjam/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/0001-jam ... ^ (line: 7)
base_path: "source_subfolder"
- patch_file: "patches/0002-msvc-mingw-fix-makefile.patch"

Check warning on line 8 in recipes/ftjam/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/0002-msv ... ^ (line: 8)
base_path: "source_subfolder"
- patch_file: "patches/0003-missing-includes.patch"

Check warning on line 9 in recipes/ftjam/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/0003-mis ... ^ (line: 9)
base_path: "source_subfolder"
173 changes: 94 additions & 79 deletions recipes/ftjam/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,127 +1,142 @@
from conans import AutoToolsBuildEnvironment, ConanFile, tools
from conans.errors import ConanInvalidConfiguration
import os

required_conan_version = ">=1.33.0"
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import cross_building
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import apply_conandata_patches, chdir, copy, export_conandata_patches, get, load, replace_in_file, save
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
from conan.tools.microsoft import is_msvc, NMakeToolchain

required_conan_version = ">=1.47.0"


class FtjamConan(ConanFile):
name = "ftjam"
description = "Jam (ftjam) is a small open-source build tool that can be used as a replacement for Make."
topics = ("conan", "ftjam", "build", "make")
license = "BSD-3-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.freetype.org/jam/"
license = "BSD-3-Clause"
exports_sources = "patches/*"
settings = "os", "arch", "compiler", "build_type"
topics = ("build", "make")

_autotools = None
package_type = "application"
settings = "os", "arch", "compiler", "build_type"

@property
def _source_subfolder(self):
return "source_subfolder"
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

def export_sources(self):
export_conandata_patches(self)

def configure(self):
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")

def validate(self):
if self.settings.compiler == "Visual Studio":
raise ConanInvalidConfiguration("ftjam doesn't build with Visual Studio yet")
if hasattr(self, "settings_build") and tools.cross_building(self):
raise ConanInvalidConfiguration("ftjam can't be cross-built")
def layout(self):
basic_layout(self, src_folder="src")

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

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)
def validate(self):
if is_msvc(self):
# Build fails with
# NMAKE : fatal error U1077: 'jam0 JamFile' : return code '0xc0000005'
raise ConanInvalidConfiguration("ftjam doesn't build with Visual Studio yet")

def validate_build(self):
if hasattr(self, "settings_build") and cross_building(self):
raise ConanInvalidConfiguration("ftjam can't be cross-built")

def build_requirements(self):
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
self.build_requires("msys2/cci.latest")
if self.settings.compiler == "Visual Studio":
self.build_requires("automake/1.16.2")
if self.settings.os != "Windows":
self.build_requires("bison/3.7.1")
if self._settings_build.os == "Windows":
self.tool_requires("winflexbison/2.5.24")
else:
self.tool_requires("bison/3.8.2")

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
env = VirtualBuildEnv(self)
env.generate()
if is_msvc(self):
tc = NMakeToolchain(self)
tc.generate()
else:
tc = AutotoolsToolchain(self)
tc.generate()

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
tools.replace_in_file(os.path.join(self._source_subfolder, "jamgram.c"),
"\n#line", "\n//#line")

def _configure_autotools(self):
if self._autotools:
return self._autotools
self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
self._autotools.libs = []
# The configure MUST be run inside this directory
with tools.chdir(os.path.join(self.build_folder, self._source_subfolder, "builds", "unix")):
self._autotools.configure()
return self._autotools
apply_conandata_patches(self)
replace_in_file(self, os.path.join(self.source_folder, "jamgram.c"), "\n#line", "\n//#line")

def _jam_toolset(self, os, compiler):

Check warning on line 76 in recipes/ftjam/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Redefining name 'os' from outer scope (line 1)
if is_msvc(self):
return "VISUALC"
if compiler == "intel-cc":
return "INTELC"
if os == "Windows":
return "MINGW"
return None

def build(self):
self._patch_sources()
with tools.chdir(self._source_subfolder):
with chdir(self, self.source_folder):
if self.settings.os == "Windows":
# toolset name of the system building ftjam
jam_toolset = self._jam_toolset(self.settings.os, self.settings.compiler)
autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
autotools.libs = []
env = autotools.vars
with tools.environment_append(env):
if self.settings.compiler == "Visual Studio":
with tools.vcvars(self.settings):
self.run("nmake -f builds/win32-visualc.mk JAM_TOOLSET={}".format(jam_toolset))
else:
with tools.environment_append({"PATH": [os.getcwd()]}):
autotools.make(args=["JAM_TOOLSET={}".format(jam_toolset), "-f", "builds/win32-gcc.mk"])
if is_msvc(self):
self.run(f"nmake -f builds/win32-visualc.mk JAM_TOOLSET={jam_toolset}")
else:
os.environ["PATH"] += os.pathsep + os.getcwd()
autotools = Autotools(self)
autotools.make(args=[f"JAM_TOOLSET={jam_toolset}", "-f", "builds/win32-gcc.mk"])
else:
autotools = self._configure_autotools()
autotools = Autotools(self)
autotools.configure(build_script_folder=os.path.join(self.source_folder, "builds", "unix"))
autotools.make()

def _extract_license(self):
txt = load(self, os.path.join(self.source_folder, "jam.c"))
license_txt = txt[: txt.find("*/") + 3]
save(self, os.path.join(self.package_folder, "licenses", "LICENSE"), license_txt)

def package(self):
txt = tools.load(os.path.join(self._source_subfolder, "jam.c"))
license_txt = txt[:txt.find("*/")+3]
tools.save(os.path.join(self.package_folder, "licenses", "LICENSE"), license_txt)
self._extract_license()
if self.settings.os == "Windows":
if self.settings.compiler == "Visual Studio":
pass
else:
self.copy("*.exe", src=os.path.join(self._source_subfolder, "bin.nt"), dst=os.path.join(self.package_folder, "bin"))
if not is_msvc(self):
copy(self, "*.exe",
src=os.path.join(self.source_folder, "bin.nt"),
dst=os.path.join(self.package_folder, "bin"))
else:
with tools.chdir(self._source_subfolder):
autotools = self._configure_autotools()
autotools.install()

def _jam_toolset(self, os, compiler):
if compiler == "Visual Studio":
return "VISUALC"
if compiler == "intel":
return "INTELC"
if os == "Windows":
return "MINGW"
return None
copy(self, "jam",
src=os.path.join(self.source_folder, "bin.unix"),
dst=os.path.join(self.package_folder, "bin"))

def package_info(self):
jam_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(jam_path))
self.env_info.PATH.append(jam_path)
self.cpp_info.frameworkdirs = []
self.cpp_info.libdirs = []
self.cpp_info.resdirs = []
self.cpp_info.includedirs = []

jam_path = os.path.join(self.package_folder, "bin")
jam_bin = os.path.join(jam_path, "jam")
if self.settings.os == "Windows":
jam_bin += ".exe"
self.output.info("Setting JAM environment variable: {}".format(jam_bin))
self.env_info.JAM = jam_bin
self.buildenv.define_path("JAM", jam_bin)
self.runenv.define_path("JAM", jam_bin)

# toolset of the system using ftjam
jam_toolset = self._jam_toolset(self.settings.os, self.settings.compiler)
if jam_toolset:
self.output.info("Setting JAM_TOOLSET environment variable: {}".format(jam_toolset))
self.buildenv.define("JAM_TOOLSET", jam_toolset)
self.runenv.define("JAM_TOOLSET", jam_toolset)

# TODO: Legacy, to be removed on Conan 2.0
self.env_info.PATH.append(jam_path)
self.env_info.JAM = jam_bin
valgur marked this conversation as resolved.
Show resolved Hide resolved
if jam_toolset:
self.env_info.JAM_TOOLSET = jam_toolset
36 changes: 17 additions & 19 deletions recipes/ftjam/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
from conans import AutoToolsBuildEnvironment, ConanFile, tools
import os
import shutil

from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.layout import basic_layout

class TestPackage(ConanFile):

class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "VirtualBuildEnv"
test_type = "explicit"

def build_requirements(self):
if hasattr(self, "settings_build"):
self.build_requires(str(self.requires["ftjam"]))
self.tool_requires(self.tested_reference_str)

def layout(self):
basic_layout(self)

def build(self):
for f in ("header.h", "main.c", "source.c", "Jamfile"):
shutil.copy(os.path.join(self.source_folder, f),
os.path.join(self.build_folder, f))
if not tools.cross_building(self):
assert os.path.isfile(tools.get_env("JAM"))

vars = AutoToolsBuildEnvironment(self).vars
vars["CCFLAGS"] = vars["CFLAGS"]
vars["C++FLAGS"] = vars["CXXFLAGS"]
vars["LINKFLAGS"] = vars["LDFLAGS"]
vars["LINKLIBS"] = vars["LIBS"]
with tools.environment_append(vars):
self.run("{} -d7".format(tools.get_env("JAM")), run_environment=True)
shutil.copy(os.path.join(self.source_folder, f), os.path.join(self.build_folder, f))
if can_run(self):
self.run("jam -d7")

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join(".", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
32 changes: 32 additions & 0 deletions recipes/ftjam/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from conans import AutoToolsBuildEnvironment, ConanFile, tools
import os
import shutil


class TestPackage(ConanFile):
settings = "os", "arch", "compiler", "build_type"

def build_requirements(self):
if hasattr(self, "settings_build"):
self.build_requires(str(self.requires["ftjam"]))

def build(self):
source_folder = os.path.join(self.source_folder, "..", "test_package")
for f in ("header.h", "main.c", "source.c", "Jamfile"):
shutil.copy(os.path.join(source_folder, f),
os.path.join(self.build_folder, f))
if not tools.cross_building(self):
assert os.path.isfile(tools.get_env("JAM"))

vars = AutoToolsBuildEnvironment(self).vars
vars["CCFLAGS"] = vars["CFLAGS"]
vars["C++FLAGS"] = vars["CXXFLAGS"]
vars["LINKFLAGS"] = vars["LDFLAGS"]
vars["LINKLIBS"] = vars["LIBS"]
with tools.environment_append(vars):
self.run("{} -d7".format(tools.get_env("JAM")), run_environment=True)

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join(".", "test_package")
self.run(bin_path, run_environment=True)