Skip to content

Commit

Permalink
podio_class_generator: only write files if their content changed
Browse files Browse the repository at this point in the history
Avoids spurious re-compilation
  • Loading branch information
andresailer authored and gaede committed Feb 17, 2020
1 parent 2f78a3f commit a646f68
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions python/podio_class_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def configure_clang_format(self, apply):
print " Please make sure it is in the PATH."
self.clang_format = []
return
self.clang_format = [cformat_exe, "-i", "-style=file", "-fallback-style=llvm"]

self.clang_format = [cformat_exe, "-style=file", "-fallback-style=llvm"]

def process(self):
self.reader.read()
Expand Down Expand Up @@ -1034,17 +1033,22 @@ def prepare_vectorized_access(self, classname,members ):
declaration += "\ttemplate<size_t arraysize>\n\tconst std::array<%s,arraysize> %s() const;\n" %(klass, name)
return declaration, implementation

def write_file(self, name,content):
def write_file(self, name, content):
#dispatch headers to header dir, the rest to /src
# fullname = os.path.join(self.install_dir,self.package_name,name)
if name.endswith("h"):
fullname = os.path.join(self.install_dir,self.package_name,name)
else:
fullname = os.path.join(self.install_dir,"src",name)
if not self.dryrun:
open(fullname, "w").write(content)
if self.clang_format:
subprocess.call(self.clang_format + [fullname])
cfproc = subprocess.Popen(self.clang_format, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
content = cfproc.communicate(input=content)[0]
existing_content = ''
if os.path.exists(fullname):
existing_content = open(fullname, 'r').read()
if existing_content != content:
open(fullname, 'w').write(content)

def evaluate_template(self, filename, substitutions):
""" reads in a given template, evaluates it
Expand Down

0 comments on commit a646f68

Please sign in to comment.