Skip to content

Commit 3878b8d

Browse files
author
Martin Valgur
committed
cc65: migrate to Conan v2
1 parent d7da970 commit 3878b8d

File tree

4 files changed

+164
-125
lines changed

4 files changed

+164
-125
lines changed

recipes/cc65/all/conandata.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ sources:
88
patches:
99
"2.18":
1010
- patch_file: "patches/2.18-0001-no-embedded-paths-makefile.patch"
11-
base_path: "source_subfolder"
1211
- patch_file: "patches/2.18-0002-libsrc-use-extension.patch"
13-
base_path: "source_subfolder"
1412
"2.19":
1513
- patch_file: "patches/2.19-0001-no-embedded-paths-makefile.patch"
16-
base_path: "source_subfolder"
1714
- patch_file: "patches/2.19-0002-libsrc-use-extension.patch"
18-
base_path: "source_subfolder"

recipes/cc65/all/conanfile.py

Lines changed: 107 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,163 +1,167 @@
1-
from conans import AutoToolsBuildEnvironment, ConanFile, MSBuild, tools
2-
from conans.errors import ConanInvalidConfiguration
31
import os
42

3+
from conan import ConanFile
4+
from conan.errors import ConanInvalidConfiguration
5+
from conan.tools.files import apply_conandata_patches, chdir, copy, export_conandata_patches, get, replace_in_file, rmdir
6+
from conan.tools.gnu import Autotools, AutotoolsToolchain
7+
from conan.tools.layout import basic_layout
8+
from conan.tools.microsoft import MSBuild, is_msvc, msvs_toolset
9+
10+
required_conan_version = ">=1.47.0"
11+
512

613
class Cc65Conan(ConanFile):
714
name = "cc65"
8-
url = "https://github.com/conan-io/conan-center-index"
9-
homepage = "https://cc65.github.io/"
1015
description = "A freeware C compiler for 6502 based systems"
1116
license = "Zlib"
12-
topics = ("conan", "cc65", "compiler", "cmos", "6502", "8bit")
13-
exports_sources = "patches/**"
17+
url = "https://github.com/conan-io/conan-center-index"
18+
homepage = "https://cc65.github.io/"
19+
topics = ("compiler", "cmos", "6502", "8bit")
1420

21+
package_type = "application"
1522
settings = "os", "arch", "compiler", "build_type"
1623

17-
_autotools = None
18-
_source_subfolder = "source_subfolder"
24+
def export_sources(self):
25+
export_conandata_patches(self)
1926

2027
def configure(self):
21-
del self.settings.compiler.libcxx
22-
del self.settings.compiler.cppstd
23-
if self.settings.compiler == "Visual Studio":
28+
self.settings.rm_safe("compiler.libcxx")
29+
self.settings.rm_safe("compiler.cppstd")
30+
if is_msvc(self):
2431
if self.settings.arch not in ("x86", "x86_64"):
2532
raise ConanInvalidConfiguration("Invalid arch")
2633
if self.settings.arch == "x86_64":
2734
self.output.info("This recipe will build x86 instead of x86_64 (the binaries are compatible)")
2835

29-
def build_requirements(self):
30-
if self.settings.compiler == "Visual Studio" and not tools.which("make"):
31-
self.build_requires("make/4.2.1")
36+
def layout(self):
37+
basic_layout(self, src_folder="src")
3238

33-
def source(self):
34-
tools.get(**self.conan_data["sources"][self.version])
35-
extracted_dir = self.name + "-" + self.version
36-
os.rename(extracted_dir, self._source_subfolder)
39+
def package_id(self):
40+
if str(self.info.settings.compiler) in ["msvc", "Visual Studio"]:
41+
if self.settings.arch == "x86_64":
42+
self.info.settings.arch = "x86"
43+
del self.info.settings.compiler
3744

38-
@property
39-
def _datadir(self):
40-
return os.path.join(self.package_folder, "bin", "share", "cc65")
45+
def build_requirements(self):
46+
if is_msvc(self):
47+
self.tool_requires("make/4.3")
4148

42-
@property
43-
def _samplesdir(self):
44-
return os.path.join(self.package_folder, "samples")
49+
def source(self):
50+
get(self, **self.conan_data["sources"][self.version], strip_root=True)
51+
52+
def generate(self):
53+
tc = AutotoolsToolchain(self)
54+
tc.make_args += [
55+
f"PREFIX=/",
56+
f"datadir=/bin/share/cc65",
57+
f"samplesdir=/samples",
58+
]
59+
if self.settings.os == "Windows":
60+
tc.make_args.append("EXE_SUFFIX=.exe")
61+
tc.generate()
4562

4663
def _build_msvc(self):
4764
msbuild = MSBuild(self)
48-
msvc_platforms = {
49-
"x86": "Win32",
50-
}
51-
arch = str(self.settings.arch)
52-
if arch != "x86":
53-
self.output.warn("{} detected: building x86 instead".format(self.settings.arch))
54-
arch = "x86"
55-
56-
msbuild.build(os.path.join(self._source_subfolder, "src", "cc65.sln"),
57-
build_type="Debug" if self.settings.build_type == "Debug" else "Release",
58-
arch=arch, platforms=msvc_platforms)
59-
autotools = self._configure_autotools()
60-
with tools.chdir(os.path.join(self._source_subfolder, "libsrc")):
65+
msbuild.build(sln=os.path.join(self.source_folder, "src", "cc65.sln"))
66+
with chdir(self, os.path.join(self.source_folder, "libsrc")):
67+
autotools = Autotools(self)
68+
autotools.configure()
6169
autotools.make()
6270

63-
def _configure_autotools(self):
64-
if self._autotools:
65-
return self._autotools
66-
self._autotools = AutoToolsBuildEnvironment(self)
67-
return self._autotools
68-
69-
@property
70-
def _make_args(self):
71-
datadir = self._datadir
72-
prefix = self.package_folder
73-
samplesdir = self._samplesdir
74-
if tools.os_info.is_windows:
75-
datadir = tools.unix_path(datadir)
76-
prefix = tools.unix_path(prefix)
77-
samplesdir = tools.unix_path(samplesdir)
78-
args = [
79-
"PREFIX={}".format(prefix),
80-
"datadir={}".format(datadir),
81-
"samplesdir={}".format(samplesdir),
82-
]
83-
if self.settings.os == "Windows":
84-
args.append("EXE_SUFFIX=.exe")
85-
return args
86-
8771
def _build_autotools(self):
88-
autotools = self._configure_autotools()
89-
with tools.chdir(os.path.join(self._source_subfolder)):
90-
autotools.make(args=self._make_args)
72+
with chdir(self, self.source_folder):
73+
autotools = Autotools(self)
74+
autotools.make()
9175

9276
def _patch_sources(self):
93-
for patch in self.conan_data["patches"][self.version]:
94-
tools.patch(**patch)
95-
if self.settings.compiler == "Visual Studio":
96-
with tools.chdir(os.path.join(self._source_subfolder, "src")):
77+
apply_conandata_patches(self)
78+
if is_msvc(self):
79+
with chdir(self, os.path.join(self.source_folder, "src")):
9780
for fn in os.listdir("."):
9881
if not fn.endswith(".vcxproj"):
9982
continue
100-
tools.replace_in_file(fn, "v141", tools.msvs_toolset(self))
101-
tools.replace_in_file(fn, "<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>", "")
83+
replace_in_file(self, fn, "v141", msvs_toolset(self))
84+
replace_in_file(self, fn,
85+
("<WindowsTargetPlatformVersion>"
86+
"10.0.16299.0"
87+
"</WindowsTargetPlatformVersion>"),
88+
"")
10289
if self.settings.os == "Windows":
10390
# Add ".exe" suffix to calls from cl65 to other utilities
104-
for fn, var in (("cc65", "CC65"), ("ca65", "CA65"), ("co65", "CO65"), ("ld65", "LD65"), ("grc65", "GRC")):
105-
v = "{},".format(var).ljust(5)
106-
tools.replace_in_file(os.path.join(self._source_subfolder, "src", "cl65", "main.c"),
107-
"CmdInit (&{v} CmdPath, \"{n}\");".format(v=v, n=fn),
108-
"CmdInit (&{v} CmdPath, \"{n}.exe\");".format(v=v, n=fn))
91+
for fn, var in [
92+
("cc65", "CC65"),
93+
("ca65", "CA65"),
94+
("co65", "CO65"),
95+
("ld65", "LD65"),
96+
("grc65", "GRC"),
97+
]:
98+
v = f"{var},".ljust(5)
99+
replace_in_file(self, os.path.join(self.source_folder, "src", "cl65", "main.c"),
100+
f'CmdInit (&{v} CmdPath, "{fn}");',
101+
f'CmdInit (&{v} CmdPath, "{fn}.exe");')
109102

110103
def build(self):
111104
self._patch_sources()
112-
if self.settings.compiler == "Visual Studio":
105+
if is_msvc(self):
113106
self._build_msvc()
114107
else:
115108
self._build_autotools()
116109

117110
def _package_msvc(self):
118-
self.copy("*.exe", src=os.path.join(self._source_subfolder, "bin"), dst=os.path.join(self.package_folder, "bin"), keep_path=False)
111+
copy(self, "*.exe",
112+
dst=os.path.join(self.package_folder, "bin"),
113+
src=os.path.join(self.source_folder, "bin"),
114+
keep_path=False)
119115
for dir in ("asminc", "cfg", "include", "lib", "target"):
120-
self.copy("*", src=os.path.join(self._source_subfolder, dir), dst=os.path.join(self._datadir, dir))
116+
copy(self, "*",
117+
dst=os.path.join(self.package_folder, "bin", "share", "cc65", dir),
118+
src=os.path.join(self.source_folder, dir))
121119

122120
def _package_autotools(self):
123-
autotools = self._configure_autotools()
124-
with tools.chdir(os.path.join(self.build_folder, self._source_subfolder)):
125-
autotools.install(args=self._make_args)
126-
127-
tools.rmdir(self._samplesdir)
128-
tools.rmdir(os.path.join(self.package_folder, "share"))
121+
with chdir(self, os.path.join(self.source_folder)):
122+
autotools = Autotools(self)
123+
autotools.install()
124+
rmdir(self, os.path.join(self.package_path, "samples"))
125+
rmdir(self, os.path.join(self.package_folder, "share"))
129126

130127
def package(self):
131-
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
132-
if self.settings.compiler == "Visual Studio":
128+
copy(self, "LICENSE",
129+
dst=os.path.join(self.package_folder, "licenses"),
130+
src=self.source_folder)
131+
if is_msvc(self):
133132
self._package_msvc()
134133
else:
135134
self._package_autotools()
136135

137-
def package_id(self):
138-
del self.info.settings.compiler
139-
if self.settings.compiler == "Visual Studio":
140-
if self.settings.arch == "x86_64":
141-
self.info.settings.arch = "x86"
142-
143136
def package_info(self):
144-
bindir = os.path.join(self.package_folder, "bin")
145-
self.output.info("Appending PATH environment variable: %s" % bindir)
146-
self.env_info.PATH.append(bindir)
147-
148-
self.output.info("Seting CC65_HOME environment variable: %s" % self._datadir)
149-
self.env_info.CC65_HOME = self._datadir
137+
self.cpp_info.frameworkdirs = []
138+
self.cpp_info.libdirs = []
139+
self.cpp_info.resdirs = []
140+
self.cpp_info.includedirs = []
150141

151142
bin_ext = ".exe" if self.settings.os == "Windows" else ""
143+
bindir = os.path.join(self.package_folder, "bin")
144+
datadir = os.path.join(self.package_folder, "bin", "share", "cc65")
145+
146+
self.output.info(f"Setting CC65_HOME environment variable: {datadir}")
147+
self.buildenv_info.define_path("CC65_HOME", datadir)
152148

153149
cc65_cc = os.path.join(bindir, "cc65" + bin_ext)
154-
self.output.info("Seting CC65 environment variable: {}".format(cc65_cc))
155-
self.env_info.CC65 = cc65_cc
150+
self.output.info(f"Setting CC65 environment variable: {cc65_cc}")
151+
self.buildenv_info.define_path("CC65", cc65_cc)
156152

157153
cc65_as = os.path.join(bindir, "ca65" + bin_ext)
158-
self.output.info("Seting AS65 environment variable: {}".format(cc65_as))
159-
self.env_info.AS65 = cc65_as
154+
self.output.info(f"Setting AS65 environment variable: {cc65_as}")
155+
self.buildenv_info.define_path("AS65", cc65_as)
160156

161157
cc65_ld = os.path.join(bindir, "cl65" + bin_ext)
162-
self.output.info("Seting LD65 environment variable: {}".format(cc65_ld))
158+
self.output.info(f"Setting LD65 environment variable: {cc65_ld}")
159+
self.buildenv_info.define_path("LD65", cc65_ld)
160+
161+
# TODO: Legacy, to be removed on Conan 2.0
162+
self.output.info(f"Appending PATH environment variable: {bindir}")
163+
self.env_info.PATH.append(bindir)
164+
self.env_info.CC65_HOME = datadir
165+
self.env_info.CC65 = cc65_cc
166+
self.env_info.AS65 = cc65_as
163167
self.env_info.LD65 = cc65_ld
Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
1-
from conans import ConanFile, tools
21
import os
32
import shutil
43

4+
from conan import ConanFile
5+
from conan.tools.build import can_run
6+
from conan.tools.files import copy, mkdir, rm
7+
from conan.tools.layout import basic_layout
8+
59

610
class TestPackageConan(ConanFile):
711
settings = "os", "arch", "compiler", "build_type"
8-
9-
exports_sources = "hello.c", "text.s"
12+
generators = "VirtualRunEnv"
13+
test_type = "explicit"
1014

1115
_targets = ("c64", "apple2")
1216

17+
def build_requirements(self):
18+
self.tool_requires(self.tested_reference_str)
19+
20+
def layout(self):
21+
basic_layout(self)
22+
1323
def build(self):
14-
if not tools.cross_building(self.settings):
15-
for src in self.exports_sources:
24+
if can_run(self):
25+
for src in ["hello.c", "text.s"]:
1626
shutil.copy(os.path.join(self.source_folder, src), os.path.join(self.build_folder, src))
1727
for target in self._targets:
18-
output = "hello_{}".format(target)
19-
tools.mkdir(target)
20-
try:
21-
# Try removing the output file to give confidence it is created by cc65
22-
os.unlink(output)
23-
except FileNotFoundError:
24-
pass
25-
self.run("{p} -O -t {t} hello.c -o {t}/hello.s".format(p=os.environ["CC65"], t=target))
26-
self.run("{p} -t {t} {t}/hello.s -o {t}/hello.o".format(p=os.environ["AS65"], t=target))
27-
self.run("{p} -t {t} text.s -o {t}/text.o".format(p=os.environ["AS65"], t=target))
28-
self.run("{p} -o {o} -t {t} {t}/hello.o {t}/text.o {t}.lib".format(o=output, p=os.environ["LD65"], t=target))
28+
output = f"hello_{target}"
29+
mkdir(self, target)
30+
rm(self, output, self.build_folder)
31+
self.run(f"cc65 -O -t {target} hello.c -o {target}/hello.s")
32+
self.run(f"ca65 -t {target} {target}/hello.s -o {target}/hello.o")
33+
self.run(f"ca65 -t {target} text.s -o {target}/text.o")
34+
self.run(f"ld65 -o {output} -t {target} {target}/hello.o {target}/text.o {target}.lib")
2935

3036
def test(self):
31-
if not tools.cross_building(self.settings):
37+
if can_run(self):
3238
for target in self._targets:
33-
assert os.path.isfile("hello_{}".format(target))
39+
assert os.path.isfile(f"hello_{target}")
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from conans import ConanFile, tools
2+
import os
3+
import shutil
4+
5+
6+
class TestPackageConan(ConanFile):
7+
settings = "os", "arch", "compiler", "build_type"
8+
9+
exports_sources = "hello.c", "text.s"
10+
11+
_targets = ("c64", "apple2")
12+
13+
def build(self):
14+
if not tools.cross_building(self.settings):
15+
for src in self.exports_sources:
16+
shutil.copy(os.path.join(self.source_folder, src), os.path.join(self.build_folder, src))
17+
for target in self._targets:
18+
output = "hello_{}".format(target)
19+
tools.mkdir(target)
20+
try:
21+
# Try removing the output file to give confidence it is created by cc65
22+
os.unlink(output)
23+
except FileNotFoundError:
24+
pass
25+
self.run("{p} -O -t {t} hello.c -o {t}/hello.s".format(p=os.environ["CC65"], t=target))
26+
self.run("{p} -t {t} {t}/hello.s -o {t}/hello.o".format(p=os.environ["AS65"], t=target))
27+
self.run("{p} -t {t} text.s -o {t}/text.o".format(p=os.environ["AS65"], t=target))
28+
self.run("{p} -o {o} -t {t} {t}/hello.o {t}/text.o {t}.lib".format(o=output, p=os.environ["LD65"], t=target))
29+
30+
def test(self):
31+
if not tools.cross_building(self.settings):
32+
for target in self._targets:
33+
assert os.path.isfile("hello_{}".format(target))

0 commit comments

Comments
 (0)