Skip to content

Commit

Permalink
Only remove the last extension from a source file name.
Browse files Browse the repository at this point in the history
Since get_basename() already removes the extension from a path expression, changing the extension removes a second extension, causing *hello.x.c* and *hello.y.c* to both generate *hello.o*. Adding an extension instead generates *hello.x.o* and *hello.y.o* as expected.
  • Loading branch information
ryan-phillips committed Jun 21, 2016
1 parent 149f36b commit 9962a9e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/bkl/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def _make_build_nodes_for_file(toolset, target, srcfile, ft_to, files_map):
objbase = src.get_basename()
objname = expr.PathExpr([expr.LiteralExpr("%s_%s" % (target.name, objbase))],
expr.ANCHOR_BUILDDIR,
pos=src.pos).change_extension(ft_to.extensions[0])
pos=src.pos).add_extension(ft_to.extensions[0])

ft_from = get_file_type(ext)
compiler = get_compiler(toolset, ft_from, ft_to)
Expand Down
12 changes: 4 additions & 8 deletions src/bkl/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,9 @@ def get_extension(self):

raise CannotDetermineError("cannot determine extension of \"%s\"" % self, self.pos)

def change_extension(self, newext):
def add_extension(self, newext):
"""
Changes extension of the filename to *newext* and returns
Adds extension *newext* to the filename and returns
:class:`bkl.expr.PathExpr` with the new path.
"""
if not self.components:
Expand All @@ -592,14 +592,10 @@ def change_extension(self, newext):
if isinstance(last, ConcatExpr):
last = last.items[-1]
if not isinstance(last, LiteralExpr):
raise Error("cannot change extension of \"%s\" to .%s" % (self, newext),
raise Error("cannot add extension .%s to \"%s\"" % (newext, self),
self.pos)

dot = last.value.rfind(".")
if dot != -1:
tail = "%s.%s" % (last.value[:dot], newext)
else:
tail = "%s.%s" % (last.value, newext)
tail = "%s.%s" % (last.value, newext)

comps = self.components[:-1] + [LiteralExpr(tail)]
return PathExpr(comps, self.anchor, self.anchor_file, pos=self.pos)
Expand Down
2 changes: 1 addition & 1 deletion src/bkl/plugins/vs200x.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def build_files_list(self, target):
genfiletype = bkl.compilers.CxxFileType.get()
genname = bkl.expr.PathExpr([bkl.expr.LiteralExpr(sfile.filename.get_basename())],
bkl.expr.ANCHOR_BUILDDIR,
pos=sfile.filename.pos).change_extension("cpp")
pos=sfile.filename.pos).add_extension("cpp")

ft_from = bkl.compilers.get_file_type(ext)
compiler = bkl.compilers.get_compiler(self, ft_from, genfiletype)
Expand Down
2 changes: 1 addition & 1 deletion src/bkl/plugins/vs201x.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def gen_for_target(self, target, project):
genfiletype = bkl.compilers.CxxFileType.get()
genname = bkl.expr.PathExpr([bkl.expr.LiteralExpr(sfile.filename.get_basename())],
bkl.expr.ANCHOR_BUILDDIR,
pos=sfile.filename.pos).change_extension("cpp")
pos=sfile.filename.pos).add_extension("cpp")

ft_from = bkl.compilers.get_file_type(ext)
compiler = bkl.compilers.get_compiler(self, ft_from, genfiletype)
Expand Down

0 comments on commit 9962a9e

Please sign in to comment.