Commit ed0f9787 authored by Ian Henriksen's avatar Ian Henriksen

Fix timestamps option to work when generating a C++ output file and when

writing output file to a specified location.
parent ef57fb78
...@@ -285,11 +285,10 @@ class Context(object): ...@@ -285,11 +285,10 @@ class Context(object):
def check_package_dir(self, dir, package_names): def check_package_dir(self, dir, package_names):
return Utils.check_package_dir(dir, tuple(package_names)) return Utils.check_package_dir(dir, tuple(package_names))
def c_file_out_of_date(self, source_path): def c_file_out_of_date(self, source_path, output_path):
c_path = Utils.replace_suffix(source_path, ".c") if not os.path.exists(output_path):
if not os.path.exists(c_path):
return 1 return 1
c_time = Utils.modification_time(c_path) c_time = Utils.modification_time(output_path)
if Utils.file_newer_than(source_path, c_time): if Utils.file_newer_than(source_path, c_time):
return 1 return 1
pos = [source_path] pos = [source_path]
...@@ -427,24 +426,28 @@ class Context(object): ...@@ -427,24 +426,28 @@ class Context(object):
pass pass
result.c_file = None result.c_file = None
def create_default_resultobj(compilation_source, options): def get_output_filename(source_filename, cwd, options):
result = CompilationResult()
result.main_source_file = compilation_source.source_desc.filename
result.compilation_source = compilation_source
source_desc = compilation_source.source_desc
if options.cplus: if options.cplus:
c_suffix = ".cpp" c_suffix = ".cpp"
else: else:
c_suffix = ".c" c_suffix = ".c"
suggested_file_name = Utils.replace_suffix(source_desc.filename, c_suffix) suggested_file_name = Utils.replace_suffix(source_filename, c_suffix)
if options.output_file: if options.output_file:
out_path = os.path.join(compilation_source.cwd, options.output_file) out_path = os.path.join(cwd, options.output_file)
if os.path.isdir(out_path): if os.path.isdir(out_path):
result.c_file = os.path.join(out_path, os.path.basename(suggested_file_name)) return os.path.join(out_path, os.path.basename(suggested_file_name))
else: else:
result.c_file = out_path return out_path
else: else:
result.c_file = suggested_file_name return suggested_file_name
def create_default_resultobj(compilation_source, options):
result = CompilationResult()
result.main_source_file = compilation_source.source_desc.filename
result.compilation_source = compilation_source
source_desc = compilation_source.source_desc
result.c_file = get_output_filename(source_desc.filename,
compilation_source.cwd, options)
result.embedded_metadata = options.embedded_metadata result.embedded_metadata = options.embedded_metadata
return result return result
...@@ -651,11 +654,14 @@ def compile_multiple(sources, options): ...@@ -651,11 +654,14 @@ def compile_multiple(sources, options):
timestamps = options.timestamps timestamps = options.timestamps
verbose = options.verbose verbose = options.verbose
context = None context = None
cwd = os.getcwd()
for source in sources: for source in sources:
if source not in processed: if source not in processed:
if context is None: if context is None:
context = options.create_context() context = options.create_context()
if not timestamps or context.c_file_out_of_date(source): output_filename = get_output_filename(source, cwd, options)
out_of_date = context.c_file_out_of_date(source, output_filename)
if (not timestamps) or out_of_date:
if verbose: if verbose:
sys.stderr.write("Compiling %s\n" % source) sys.stderr.write("Compiling %s\n" % source)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment