stella.stamenova created this revision.
stella.stamenova added reviewers: zturner, asmith.
Herald added subscribers: lldb-commits, abidh.
This adds an implementation for compile as well as compile-and-link, but not
link. For compile-and-link we rely on clang to orchestrate both similarly to
how the tests use it today.
Repository:
rLLDB LLDB
https://reviews.llvm.org/D55569
Files:
lit/BuildScript/modes-nonwin.test
lit/BuildScript/modes-win.test
lit/BuildScript/modes.test
lit/BuildScript/script-args.test
lit/helper/build.py
Index: lit/helper/build.py
===================================================================
--- lit/helper/build.py
+++ lit/helper/build.py
@@ -151,11 +151,14 @@
return result
def print_environment(env):
- for e in env:
- value = env[e]
- lines = value.split(os.pathsep)
- formatted_value = format_text(lines, 0, 7 + len(e))
- print(' {0} = {1}'.format(e, formatted_value))
+ if env:
+ for e in env:
+ value = env[e]
+ lines = value.split(os.pathsep)
+ formatted_value = format_text(lines, 0, 7 + len(e))
+ print(' {0} = {1}'.format(e, formatted_value))
+ else:
+ print(' No environment specified')
def find_executable(binary_name, search_paths):
if sys.platform == 'win32':
@@ -604,11 +607,108 @@
def __init__(self, toolchain_type, args):
Builder.__init__(self, toolchain_type, args)
+ def _output_name(self, input, extension, with_executable=False):
+ basename = os.path.splitext(os.path.basename(input))[0] + extension
+ if with_executable:
+ exe_basename = os.path.basename(self._exe_file_name())
+ basename = exe_basename + '-' + basename
+
+ output = os.path.join(self.outdir, basename)
+ return os.path.normpath(output)
+
+ def _obj_file_names(self):
+ if self.mode == 'link':
+ return self.inputs
+
+ if self.mode == 'compile-and-link':
+ # Object file names should factor in both the input file (source)
+ # name and output file (executable) name, to ensure that two tests
+ # which share a common source file don't race to write the same
+ # object file.
+ return [self._output_name(x, '.o', True) for x in self.inputs]
+
+ if self.mode == 'compile' and self.output:
+ return [self.output]
+
+ return [self._output_name(x, '.o') for x in self.inputs]
+
+ def _exe_file_name(self):
+ if self.mode == 'compile':
+ return None
+ return self.output
+
+ def _get_compilation_command(self, source, obj):
+ args = []
+
+ args.append(self.compiler)
+
+ if self.opt == 'none':
+ args.append('-O0')
+ elif self.opt == 'basic':
+ args.append('-O2')
+ elif self.opt == 'lto':
+ args.append('-flto=thin')
+
+ args.append('-c')
+ args.append('-g')
+ args.append('-o' + obj)
+ args.append(source)
+
+ return ('compiling', [source], obj,
+ None,
+ args)
+
+ def _get_compile_and_link_command(self):
+ args = []
+
+ args.append(self.compiler)
+
+ if self.opt == 'none':
+ args.append('-O0')
+ elif self.opt == 'basic':
+ args.append('-O2')
+ elif self.opt == 'lto':
+ args.append('-flto=thin')
+
+ args.append('-g')
+ args.append('-o' + self._exe_file_name())
+ args.extend(self.inputs)
+
+ return ('compiling and linking', self.inputs, self._exe_file_name(),
+ None,
+ args)
+
+ def _get_link_command(self):
+ args = []
+ args.append('echo linking only not supported')
+
+ return ('linking', self._obj_file_names(), self._exe_file_name(),
+ None,
+ args)
+
def build_commands(self):
- pass
+ commands = []
+ if self.mode == 'compile':
+ for input, output in zip(self.inputs, self._obj_file_names()):
+ commands.append(self._get_compilation_command(input, output))
+ if self.mode == 'compile-and-link':
+ commands.append(self._get_compile_and_link_command())
+ if self.mode == 'link':
+ commands.append(self._get_link_command())
+ return commands
def output_files(self):
- pass
+ outdir = os.path.dirname(self.output)
+ file = os.path.basename(self.output)
+ name, ext = os.path.splitext(file)
+
+ outputs = []
+ if self.mode == 'compile' or self.mode == 'compile-and-link':
+ outputs.extend(self._obj_file_names())
+ if self.mode == 'link' or self.mode == 'compile-and-link':
+ outputs.append(self._exe_file_name())
+
+ return [x for x in outputs if x is not None]
def indent(text, spaces):
def prefixed_lines():
Index: lit/BuildScript/script-args.test
===================================================================
--- lit/BuildScript/script-args.test
+++ lit/BuildScript/script-args.test
@@ -1,5 +1,3 @@
-REQUIRES: system-windows
-
RUN: %build -n --verbose --arch=32 --mode=compile --compiler=any -o %t/foo.out foobar.c \
RUN: | FileCheck %s
RUN: %build -n --verbose --arch=32 --mode=compile --compiler=any --outdir %t foo.c bar.c \
Index: lit/BuildScript/modes-nonwin.test
===================================================================
--- /dev/null
+++ lit/BuildScript/modes-nonwin.test
@@ -0,0 +1,34 @@
+UNSUPPORTED: system-windows
+
+RUN: %build -n --verbose --arch=32 --mode=compile --compiler=any -o %t/foo.out foobar.c \
+RUN: | FileCheck --check-prefix=COMPILE %s
+
+RUN: %build -n --verbose --arch=32 --mode=compile --compiler=any --outdir %t foo.c bar.c \
+RUN: | FileCheck --check-prefix=COMPILE-MULTI %s
+
+RUN: %build -n --verbose --arch=32 --mode=link --compiler=any -o %t/foo.out foobar.o \
+RUN: | FileCheck --check-prefix=LINK %s
+
+RUN: %build -n --verbose --arch=32 --mode=link --compiler=any -o %t/foobar.out foo.o bar.o \
+RUN: | FileCheck --check-prefix=LINK-MULTI %s
+
+RUN: %build -n --verbose --arch=32 --mode=compile-and-link --compiler=any -o %t/foobar.out foobar.c \
+RUN: | FileCheck --check-prefix=BOTH %s
+
+RUN: %build -n --verbose --arch=32 --mode=compile-and-link --compiler=any -o %t/foobar.out foo.c bar.c \
+RUN: | FileCheck --check-prefix=BOTH-MULTI %s
+
+
+COMPILE: compiling foobar.c -> foo.out
+
+COMPILE-MULTI: compiling foo.c -> foo.o
+COMPILE-MULTI: compiling bar.c -> bar.o
+
+
+LINK: linking only not supported
+
+LINK-MULTI: linking only not supported
+
+BOTH: compiling and linking foobar.c -> foobar.out
+
+BOTH-MULTI: compiling and linking foo.c+bar.c -> foobar.out
_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits