Skip to content

Commit

Permalink
Merge pull request #513 from insertinterestingnamehere/cpp_timestamps
Browse files Browse the repository at this point in the history
Fix timestamps option to work when generating a C++ output file.
  • Loading branch information
robertwb committed May 1, 2016
2 parents d591d50 + ed0f978 commit c4c202b
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions Cython/Compiler/Main.py
Expand Up @@ -285,11 +285,10 @@ def find_root_package_dir(self, file_path):
def check_package_dir(self, dir, package_names):
return Utils.check_package_dir(dir, tuple(package_names))

def c_file_out_of_date(self, source_path):
c_path = Utils.replace_suffix(source_path, ".c")
if not os.path.exists(c_path):
def c_file_out_of_date(self, source_path, output_path):
if not os.path.exists(output_path):
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):
return 1
pos = [source_path]
Expand Down Expand Up @@ -427,24 +426,28 @@ def teardown_errors(self, err, options, result):
pass
result.c_file = None

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
def get_output_filename(source_filename, cwd, options):
if options.cplus:
c_suffix = ".cpp"
else:
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:
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):
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:
result.c_file = out_path
return out_path
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
return result

Expand Down Expand Up @@ -651,11 +654,14 @@ def compile_multiple(sources, options):
timestamps = options.timestamps
verbose = options.verbose
context = None
cwd = os.getcwd()
for source in sources:
if source not in processed:
if context is None:
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:
sys.stderr.write("Compiling %s\n" % source)

Expand Down

0 comments on commit c4c202b

Please sign in to comment.