From bcdb84fcbe31b9dff686794b1cabaff0e95a5e91 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Tue, 5 Nov 2013 00:16:17 +0200 Subject: [PATCH] Can use object files directly in targets. --- backends.py | 6 +++++ build.py | 25 +++++++++++++----- interpreter.py | 21 ++++++++------- .../prebuilt object/1 basic/linux-amd64.o | Bin 0 -> 2592 bytes test cases/prebuilt object/1 basic/main.c | 5 ++++ .../prebuilt object/1 basic/meson.build | 19 +++++++++++++ test cases/prebuilt object/1 basic/source.c | 8 ++++++ 7 files changed, 69 insertions(+), 15 deletions(-) create mode 100644 test cases/prebuilt object/1 basic/linux-amd64.o create mode 100644 test cases/prebuilt object/1 basic/main.c create mode 100644 test cases/prebuilt object/1 basic/meson.build create mode 100644 test cases/prebuilt object/1 basic/source.c diff --git a/backends.py b/backends.py index 01e782cd6..989b65883 100644 --- a/backends.py +++ b/backends.py @@ -171,6 +171,12 @@ class Backend(): for src in target.get_sources(): if not self.environment.is_header(src): obj_list.append(self.generate_single_compile(target, outfile, src, False, header_deps)) + for obj in target.get_objects(): + if isinstance(obj, str): + o = os.path.join(self.build_to_src, target.get_subdir(), obj) + else: + raise MesonException('Unknown data type in object list.') + obj_list.append(o) elem = self.generate_link(target, outfile, outname, obj_list) self.generate_shlib_aliases(target, self.get_target_dir(target), outfile, elem) self.processed_targets[name] = True diff --git a/build.py b/build.py index e95020d86..7b5e513b5 100644 --- a/build.py +++ b/build.py @@ -91,11 +91,12 @@ class IncludeDirs(): return self.incdirs class BuildTarget(): - def __init__(self, name, subdir, is_cross, sources, environment, kwargs): + def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs): self.name = name self.subdir = subdir self.is_cross = is_cross self.sources = [] + self.objects = [] self.external_deps = [] self.include_dirs = [] self.link_targets = [] @@ -105,10 +106,19 @@ class BuildTarget(): self.extra_args = {} self.generated = [] self.process_sourcelist(sources) + self.process_objectlist(objects) self.process_kwargs(kwargs) if len(self.sources) == 0 and len(self.generated) == 0: raise InvalidArguments('Build target %s has no sources.' % name) + def process_objectlist(self, objects): + assert(isinstance(objects, list)) + for s in objects: + if isinstance(s, str): + self.objects.append(s) + else: + raise InvalidArguments('Bad object in target %s.' % self.name) + def process_sourcelist(self, sources): if not isinstance(sources, list): sources = [sources] @@ -215,6 +225,9 @@ class BuildTarget(): def get_sources(self): return self.sources + def get_objects(self): + return self.objects + def get_generated_sources(self): return self.generated @@ -386,8 +399,8 @@ class GeneratedList(): return self.generator class Executable(BuildTarget): - def __init__(self, name, subdir, is_cross, sources, environment, kwargs): - super().__init__(name, subdir, is_cross, sources, environment, kwargs) + def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs): + super().__init__(name, subdir, is_cross, sources, objects, environment, kwargs) suffix = environment.get_exe_suffix() if suffix != '': self.filename = self.name + '.' + suffix @@ -396,14 +409,14 @@ class Executable(BuildTarget): class StaticLibrary(BuildTarget): - def __init__(self, name, subdir, is_cross, sources, environment, kwargs): - super().__init__(name, subdir, is_cross, sources, environment, kwargs) + def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs): + super().__init__(name, subdir, is_cross, sources, objects, environment, kwargs) prefix = environment.get_static_lib_prefix() suffix = environment.get_static_lib_suffix() self.filename = prefix + self.name + '.' + suffix class SharedLibrary(BuildTarget): - def __init__(self, name, subdir, is_cross, sources, environment, kwargs): + def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs): self.version = None self.soversion = None super().__init__(name, subdir, is_cross, sources, environment, kwargs); diff --git a/interpreter.py b/interpreter.py index 4ab5c5f86..a754cdb6d 100644 --- a/interpreter.py +++ b/interpreter.py @@ -312,23 +312,23 @@ class Man(InterpreterObject): return self.sources class BuildTargetHolder(InterpreterObject): - def __init__(self, targetttype, name, subdir, is_cross, sources, environment, kwargs): - self.target = targetttype(name, subdir, is_cross, sources, environment, kwargs) + def __init__(self, targetttype, name, subdir, is_cross, sources, objects, environment, kwargs): + self.target = targetttype(name, subdir, is_cross, sources, objects, environment, kwargs) def is_cross(self): return self.target.is_cross() class ExecutableHolder(BuildTargetHolder): - def __init__(self, name, subdir, is_cross, sources, environment, kwargs): - super().__init__(build.Executable, name, subdir, is_cross, sources, environment, kwargs) + def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs): + super().__init__(build.Executable, name, subdir, is_cross, sources, objects, environment, kwargs) class StaticLibraryHolder(BuildTargetHolder): - def __init__(self, name, subdir, is_cross, sources, environment, kwargs): - super().__init__(build.StaticLibrary, name, subdir, is_cross, sources, environment, kwargs) + def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs): + super().__init__(build.StaticLibrary, name, subdir, is_cross, sources, objects, environment, kwargs) class SharedLibraryHolder(BuildTargetHolder): - def __init__(self, name, subdir, is_cross, sources, environment, kwargs): - super().__init__(build.SharedLibrary, name, subdir, is_cross, sources, environment, kwargs) + def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs): + super().__init__(build.SharedLibrary, name, subdir, is_cross, sources, objects, environment, kwargs) class Test(InterpreterObject): def __init__(self, name, exe, is_parallel, cmd_args, env): @@ -985,10 +985,13 @@ class Interpreter(): except KeyError: kw_src = [] sources += kw_src + objs = self.flatten(kwargs.get('objects', [])) + if not isinstance(objs, list): + objs = [objs] if name in self.build.targets: raise InvalidCode('Tried to create target "%s", but a target of that name already exists.' % name) self.check_sources_exist(os.path.join(self.environment.source_dir, self.subdir), sources) - l = targetclass(name, self.subdir, is_cross, sources, self.environment, kwargs) + l = targetclass(name, self.subdir, is_cross, sources, objs, self.environment, kwargs) self.build.targets[name] = l.target if self.environment.is_cross_build() and l.is_cross: txt = ' cross build ' diff --git a/test cases/prebuilt object/1 basic/linux-amd64.o b/test cases/prebuilt object/1 basic/linux-amd64.o new file mode 100644 index 0000000000000000000000000000000000000000..5c2488542b1276721deed3ca80ed711537d15fd8 GIT binary patch literal 2592 zcmbtW&1(}u6rateZED(>wu&tkTtU%_*)&jUsJ2FftskY7LJuCKY_^k+rr8a<8?AcK zg9={6gCK%};6LH9;N6pdfEVxest0{`5Q&zW09bbKcBs^5n+qazfJ>k;ax- zPa~AE?}?sV3dIteU|F_#^W~4v7XY~TWewiR(3A=@^rcCM#^@EM)3nQP(dxEiq$*xZ6nT7P_^sNa5OOtP}Pcf#SVd?ZzT2Dd3i||D4 zqShlS&_g1r2rR))!CTXQXGY;24g~twnD2Hxo11pzIozFscIR#)0iG*sn?~7~GmB=y z$hCrw!xwAZ;axj+m_AqE$+KcKHz>}*p|=zeB0xdPGdJP+{zBb<_ku}@*6g*b{t!3a;02eFwSpQ zI!@5ZuQnXZbED>Rh1pJs7H1+LS`a%Xxb|p+X?t01dSoc|8diQ1aD0%$xn0X-UnI(- zgUjH6py@ws1y%)k;6=PnQo#2DW^P-7#mtKDGt=X{mbncJsBJZzstdMIwkj2m-#=uw zJjA)OK*nwO)SCNR(=?>OgFL9DDhXXZ zQ|h5V4StB}!k^e35)`h+p94G2`(NV=5Ub|Il2m^K6^T?|yi3ugmYh%=j`aPAu`%H2 zM>lR#;ETZ3oM`$W?3V;5ruwdfLB-Jbn+TW{oS5p1>x}DvU-VD$*#8hbYX94SsW|~+ zNdaC#MIzOA3v6-q4@7;M6V^vat=|R=b5frmhEx)TUJ)QT)hGTK@VNM|!U6YJCW<5e z42&epe!t?t7~gjS>wY*Xi2(51D-*4sus0yY%`bH%@{s430f^#dT)jIOSrqj@MQOTk zby=wQ^$yraJS;%#B48ZkQFzq)xTkUT4}{}Uu*;;@mu<3)eo6N8kBpJ5$L<*R5w{Y= z<2pneNQ6I+RCZi&!k2^&e@#MC&(Vy)(Vxx?LZ*ac-KRpQ ed!pu{o-xmW@I{stvg%LwUBwOIk0(SvC4T|8D5~iI literal 0 HcmV?d00001 diff --git a/test cases/prebuilt object/1 basic/main.c b/test cases/prebuilt object/1 basic/main.c new file mode 100644 index 000000000..480bda5f4 --- /dev/null +++ b/test cases/prebuilt object/1 basic/main.c @@ -0,0 +1,5 @@ +int func(); + +int main(int argc, char **argv) { + return func() == 42 ? 0 : 99; +} diff --git a/test cases/prebuilt object/1 basic/meson.build b/test cases/prebuilt object/1 basic/meson.build new file mode 100644 index 000000000..5e4fb7e49 --- /dev/null +++ b/test cases/prebuilt object/1 basic/meson.build @@ -0,0 +1,19 @@ +# This test is on its own because it is special. +# To run the test you need the prebuilt object +# file for the given platform. +# +# Combined with cross compilation this would make +# the state space explode so let's just keep this +# in its own subdir so it's not run during cross +# compilation tests. + +project('prebuilt object', 'c') + +object = 'linux-amd64.o' + +# Remember: do not put source.c in this +# declaration. Only the prebuilt object. +e = executable('prog', 'main.c', +objects : object) + +test('objtest', e) diff --git a/test cases/prebuilt object/1 basic/source.c b/test cases/prebuilt object/1 basic/source.c new file mode 100644 index 000000000..f39b4f366 --- /dev/null +++ b/test cases/prebuilt object/1 basic/source.c @@ -0,0 +1,8 @@ +/* + * Compile this manually on new platforms and add the + * object file to revision control and Meson configuration. + */ + +int func() { + return 42; +}