Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only remove the last extension from a source file name. #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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