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 May 1, 2018
1 parent 458c13e commit 68c7c08
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 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
20 changes: 20 additions & 0 deletions src/bkl/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,26 @@ def change_extension(self, newext):
comps = self.components[:-1] + [LiteralExpr(tail)]
return PathExpr(comps, self.anchor, self.anchor_file, pos=self.pos)

def add_extension(self, newext):
"""
Adds extension *newext* to the filename and returns
:class:`bkl.expr.PathExpr` with the new path.
"""
if not self.components:
raise Error("cannot change extension of empty path", self.pos)

last = self.components[-1]
if isinstance(last, ConcatExpr):
last = last.items[-1]
if not isinstance(last, LiteralExpr):
raise Error("cannot add extension .%s to \"%s\"" % (newext, self),
self.pos)

tail = "%s.%s" % (last.value, newext)

comps = self.components[:-1] + [LiteralExpr(tail)]
return PathExpr(comps, self.anchor, self.anchor_file, pos=self.pos)

def is_external_absolute(self):
"""
Returns true if the path is to be treated as an absolute path provided
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 @@ -301,7 +301,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 68c7c08

Please sign in to comment.