Skip to content

Commit 48bea76

Browse files
committed
Deprecate framework builtin
1 parent 00e92cf commit 48bea76

11 files changed

Lines changed: 47 additions & 113 deletions

File tree

‎CHANGES.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
- The `install_name` for libraries on macOS now (again) uses `@rpath`-based
1313
paths prior to installation
1414

15+
### Breaking changes
16+
- `framework` is now deprecated; use `mopack.yml` instead
17+
1518
### Bug fixes
1619
- Automatically update dependencies via `mopack` if the toolchain file has
1720
changed

‎bfg9000/builtins/packages.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import warnings
2+
13
from . import builtin
2-
from .. import options as opts
34
from ..exceptions import PackageResolutionError
45
from ..file_types import Executable
56
from ..iterutils import default_sentinel, listify
67
from ..objutils import objectify
7-
from ..packages import CommonPackage, Framework, Package, PackageKind
8+
from ..packages import Framework, FrameworkPackage, Package, PackageKind
89
from ..path import Path, Root
910
from ..shell import which
1011
from ..versioning import InvalidSpecifier, SpecifierSet
@@ -47,12 +48,13 @@ def system_executable(context, name, format=None):
4748

4849
@builtin.function()
4950
def framework(context, name, suffix=None):
51+
# TODO: Remove this after 0.8 is released.
52+
warnings.warn("'framework' is deprecated; use mopack.yml instead")
53+
5054
env = context.env
5155
if not env.target_platform.has_frameworks:
5256
raise PackageResolutionError("{} platform doesn't support frameworks"
5357
.format(env.target_platform.name))
5458

55-
framework = Framework(name, suffix)
56-
return CommonPackage(framework.full_name,
57-
format=env.target_platform.object_format,
58-
link_options=opts.option_list(opts.lib(framework)))
59+
return FrameworkPackage(Framework(name, suffix),
60+
format=env.target_platform.object_format)

‎bfg9000/options.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ def __init__(self, *args, **kwargs):
178178
value = self.__check_type(typ, value)
179179
setattr(self, name, value)
180180

181+
@classmethod
182+
def alias(cls, fn):
183+
cls.registry[fn.__name__] = fn
184+
return fn
185+
181186
def matches(self, rhs):
182187
return self == rhs
183188

@@ -239,6 +244,11 @@ class define(Option):
239244
rpath_link_dir = option('rpath_link_dir', path=path.BasePath)
240245

241246

247+
@Option.alias
248+
def framework(name, suffix=None):
249+
return lib(Framework(name, suffix))
250+
251+
242252
class gui(Option):
243253
main: bool = False
244254

‎bfg9000/packages.py‎

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,6 @@ def __repr__(self):
4848
)
4949

5050

51-
class CommonPackage(Package):
52-
def __init__(self, name, submodules=None, version=None, *, format,
53-
compile_options=None, link_options=None):
54-
super().__init__(name, submodules, format=format)
55-
self.version = version
56-
57-
# Import this here to avoid circular import.
58-
from .options import option_list
59-
self._compile_options = compile_options or option_list()
60-
self._link_options = link_options or option_list()
61-
62-
def compile_options(self, compiler, *, raw=False):
63-
return self._compile_options
64-
65-
def link_options(self, linker, *, raw=False):
66-
return self._link_options
67-
68-
6951
class Framework:
7052
# A reference to a macOS framework. Can be used in place of Library objects
7153
# within a Package.
@@ -84,3 +66,20 @@ def __eq__(self, rhs):
8466

8567
def __ne__(self, rhs):
8668
return not (self == rhs)
69+
70+
71+
# TODO: Remove this after 0.8 is released.
72+
class FrameworkPackage(Package):
73+
def __init__(self, framework, *, format):
74+
super().__init__(framework.full_name, None, format=format)
75+
76+
# Import this here to avoid circular import.
77+
from . import options as opts
78+
self._compile_options = opts.option_list()
79+
self._link_options = opts.option_list(opts.framework(framework))
80+
81+
def compile_options(self, compiler, *, raw=False):
82+
return self._compile_options
83+
84+
def link_options(self, linker, *, raw=False):
85+
return self._link_options

‎bfg9000/tools/mopack.py‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from .. import shell
99
from ..exceptions import PackageResolutionError
1010
from ..iterutils import iterate
11-
from ..packages import Framework
1211
from ..path import Path, Root
1312
from ..safe_str import safe_format
1413

@@ -107,17 +106,6 @@ def get_linkage(env, name, submodules=None, include_path=None, lib_path=None,
107106
raise PackageResolutionError(msg)
108107

109108

110-
def to_frameworks(libs):
111-
def convert(lib):
112-
if isinstance(lib, dict):
113-
if lib['type'] == 'framework':
114-
return Framework(lib['name'])
115-
raise ValueError('unknown type {!r}'.format(lib['type']))
116-
return lib
117-
118-
return [convert(i) for i in libs]
119-
120-
121109
def _dump_yaml(data):
122110
# `sort_keys` only works on newer versions of PyYAML, so don't worry too
123111
# much if we can't use it.

‎doc/about/changes.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ in progress
1414
- The `install_name` for libraries on macOS now (again) uses `@rpath`-based
1515
paths prior to installation
1616

17+
### Breaking changes
18+
- `framework` is now deprecated; use `mopack.yml` instead
19+
1720
### Bug fixes
1821
- Automatically update dependencies via `mopack` if the toolchain file has
1922
changed

‎doc/reference/builtins.md‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -797,12 +797,6 @@ to modify [static libraries](#static_library).
797797

798798
## Package resolvers
799799

800-
### framework(*name*, [*suffix*]) { #framework }
801-
802-
Reference a macOS [framework][framework] named *name* with the optional suffix
803-
*suffix*. Though not a "package" in name, this can be used wherever packages are
804-
accepted.
805-
806800
### package(*name*, [*submodules*], [*version*], \*, [*lang*], [*kind*], [*system*]) { #package }
807801
Availability: `build.bfg`
808802
{: .subtitle}

‎test/unit/builtins/test_packages.py‎

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66
from .common import BuiltinTestCase
77
from .. import *
88

9-
from bfg9000 import file_types, options as opts
10-
from bfg9000.build_inputs import BuildInputs
9+
from bfg9000 import file_types
1110
from bfg9000.builtins import builtin, packages, project # noqa: F401
12-
from bfg9000.exceptions import PackageResolutionError
1311
from bfg9000.iterutils import first
14-
from bfg9000.packages import CommonPackage, Framework
15-
from bfg9000.path import abspath, Path, Root
12+
from bfg9000.path import abspath
1613
from bfg9000.versioning import SpecifierSet, Version
1714

1815

@@ -66,47 +63,6 @@ def mock_execute_msvc(args, **kwargs):
6663
return mock_execute_common(args, **kwargs)
6764

6865

69-
class TestFramework(TestCase):
70-
def _make_context(self, env):
71-
build = BuildInputs(env, Path('build.bfg', Root.srcdir))
72-
return builtin.BuildContext(env, build, None)
73-
74-
def test_framework(self):
75-
env = make_env('macos')
76-
context = self._make_context(env)
77-
78-
self.assertEqual(
79-
context['framework']('name'),
80-
CommonPackage('name', format=env.target_platform.object_format,
81-
link_options=opts.option_list(opts.lib(
82-
Framework('name')
83-
)))
84-
)
85-
86-
def test_framework_suffix(self):
87-
env = make_env('macos')
88-
context = self._make_context(env)
89-
90-
self.assertEqual(
91-
context['framework']('name', 'suffix'),
92-
CommonPackage('name,suffix',
93-
format=env.target_platform.object_format,
94-
link_options=opts.option_list(opts.lib(
95-
Framework('name', 'suffix')
96-
)))
97-
)
98-
99-
def test_frameworks_unsupported(self):
100-
env = make_env('linux')
101-
context = self._make_context(env)
102-
103-
with self.assertRaises(PackageResolutionError):
104-
context['framework']('name')
105-
106-
with self.assertRaises(PackageResolutionError):
107-
context['framework']('name', 'suffix')
108-
109-
11066
class TestPackageCc(BuiltinTestCase):
11167
mock_execute = staticmethod(mock_execute_cc)
11268
mock_platform = 'linux'

‎test/unit/tools/cc/test_linker.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from bfg9000.builtins.install import installify
1010
from bfg9000.file_types import *
1111
from bfg9000.tools.cc import CcBuilder
12-
from bfg9000.packages import Framework
1312
from bfg9000.path import abspath, InstallRoot, Path, Root
1413
from bfg9000.versioning import Version
1514

@@ -202,7 +201,7 @@ def test_flags_lib_dir(self):
202201

203202
# Framework
204203
self.assertEqual(self.linker.flags(opts.option_list(
205-
opts.lib(Framework('cocoa'))
204+
opts.framework('cocoa')
206205
)), [])
207206

208207
# Mixed
@@ -391,7 +390,7 @@ def test_lib_flags_lib(self):
391390
), mode='pkg-config')
392391

393392
# Framework
394-
fw = opts.lib(Framework('cocoa'))
393+
fw = opts.framework('cocoa')
395394
if self.env.target_platform.genus == 'darwin':
396395
self.assertEqual(self.linker.lib_flags(opts.option_list(fw)),
397396
['-framework', 'cocoa'])

‎test/unit/tools/msvc/test_linker.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from bfg9000 import options as opts
77
from bfg9000.file_types import *
88
from bfg9000.iterutils import merge_dicts
9-
from bfg9000.packages import Framework
109
from bfg9000.path import Path
1110
from bfg9000.tools.msvc import MsvcBuilder
1211

@@ -186,7 +185,7 @@ def test_lib_flags_lib(self):
186185

187186
with self.assertRaises(TypeError):
188187
self.linker.lib_flags(opts.option_list(
189-
opts.lib(Framework('cocoa'))
188+
opts.framework('cocoa')
190189
))
191190

192191
def test_lib_flags_lib_literal(self):

0 commit comments

Comments
 (0)