From 9962a9e5c7b47acc0403ba3db6d7c1dfcf73b9e2 Mon Sep 17 00:00:00 2001 From: Ryan Phillips Date: Tue, 21 Jun 2016 15:17:08 -0700 Subject: [PATCH] Only remove the last extension from a source file name. 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. --- src/bkl/compilers.py | 2 +- src/bkl/expr.py | 12 ++++-------- src/bkl/plugins/vs200x.py | 2 +- src/bkl/plugins/vs201x.py | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/bkl/compilers.py b/src/bkl/compilers.py index 64bb6a5d..ace9985f 100644 --- a/src/bkl/compilers.py +++ b/src/bkl/compilers.py @@ -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) diff --git a/src/bkl/expr.py b/src/bkl/expr.py index 165fad70..15950f12 100644 --- a/src/bkl/expr.py +++ b/src/bkl/expr.py @@ -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: @@ -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) diff --git a/src/bkl/plugins/vs200x.py b/src/bkl/plugins/vs200x.py index 41a5f50e..b01eb5d6 100644 --- a/src/bkl/plugins/vs200x.py +++ b/src/bkl/plugins/vs200x.py @@ -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) diff --git a/src/bkl/plugins/vs201x.py b/src/bkl/plugins/vs201x.py index a42bf43b..c15a4f9b 100644 --- a/src/bkl/plugins/vs201x.py +++ b/src/bkl/plugins/vs201x.py @@ -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)