diff --git a/platformio/builder/tools/platformio.py b/platformio/builder/tools/platformio.py index c4e5dc8c..5c967d19 100644 --- a/platformio/builder/tools/platformio.py +++ b/platformio/builder/tools/platformio.py @@ -16,7 +16,6 @@ from __future__ import absolute_import import os import sys -from os.path import basename, dirname, isdir, join, realpath from SCons import Builder, Util # pylint: disable=import-error from SCons.Script import COMMAND_LINE_TARGETS # pylint: disable=import-error @@ -130,7 +129,14 @@ def BuildProgram(env): # append into the beginning a main LD script if env.get("LDSCRIPT_PATH") and not any("-Wl,-T" in f for f in env["LINKFLAGS"]): - env.Prepend(LINKFLAGS=["-T", env["LDSCRIPT_PATH"]]) + env.Prepend( + LINKFLAGS=[ + "-T", + env["LDSCRIPT_PATH"] + if os.path.isfile(env["LDSCRIPT_PATH"]) + else "$LDSCRIPT_PATH", + ] + ) # enable "cyclic reference" for linker if env.get("LIBS") and env.GetCompilerType() == "gcc": @@ -138,7 +144,7 @@ def BuildProgram(env): env.Append(_LIBFLAGS=" -Wl,--end-group") program = env.Program( - join("$BUILD_DIR", env.subst("$PROGNAME")), env["PIOBUILDFILES"] + os.path.join("$BUILD_DIR", env.subst("$PROGNAME")), env["PIOBUILDFILES"] ) env.Replace(PIOMAINPROG=program) @@ -181,13 +187,13 @@ def ParseFlagsExtended(env, flags): # pylint: disable=too-many-branches # fix relative CPPPATH & LIBPATH for k in ("CPPPATH", "LIBPATH"): for i, p in enumerate(result.get(k, [])): - if isdir(p): - result[k][i] = realpath(p) + if os.path.isdir(p): + result[k][i] = os.path.realpath(p) # fix relative path for "-include" for i, f in enumerate(result.get("CCFLAGS", [])): if isinstance(f, tuple) and f[0] == "-include": - result["CCFLAGS"][i] = (f[0], env.File(realpath(f[1].get_path()))) + result["CCFLAGS"][i] = (f[0], env.File(os.path.realpath(f[1].get_path()))) return result @@ -254,16 +260,16 @@ def CollectBuildFiles(env, variant_dir, src_dir, src_filter=None, duplicate=Fals src_dir = src_dir[:-1] for item in env.MatchSourceFiles(src_dir, src_filter): - _reldir = dirname(item) - _src_dir = join(src_dir, _reldir) if _reldir else src_dir - _var_dir = join(variant_dir, _reldir) if _reldir else variant_dir + _reldir = os.path.dirname(item) + _src_dir = os.path.join(src_dir, _reldir) if _reldir else src_dir + _var_dir = os.path.join(variant_dir, _reldir) if _reldir else variant_dir if _var_dir not in variants: variants.append(_var_dir) env.VariantDir(_var_dir, _src_dir, duplicate) if fs.path_endswith_ext(item, SRC_BUILD_EXT): - sources.append(env.File(join(_var_dir, basename(item)))) + sources.append(env.File(os.path.join(_var_dir, os.path.basename(item)))) return sources diff --git a/tests/test_pkgmanifest.py b/tests/test_pkgmanifest.py index cbd632ed..64b67047 100644 --- a/tests/test_pkgmanifest.py +++ b/tests/test_pkgmanifest.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os + import jsondiff import pytest @@ -551,22 +553,26 @@ def test_examples_from_dir(tmpdir_factory): [ { "name": "PlatformIO/hello", - "base": "examples/PlatformIO/hello", - "files": ["platformio.ini", "include/main.h", "src/main.cpp"], + "base": os.path.join("examples", "PlatformIO", "hello"), + "files": [ + "platformio.ini", + os.path.join("include", "main.h"), + os.path.join("src", "main.cpp"), + ], }, { "name": "1_General/SomeSketchIno", - "base": "examples/1. General/SomeSketchIno", + "base": os.path.join("examples", "1. General", "SomeSketchIno"), "files": ["SomeSketchIno.ino"], }, { "name": "1_General/SomeSketchPde", - "base": "examples/1. General/SomeSketchPde", + "base": os.path.join("examples", "1. General", "SomeSketchPde"), "files": ["SomeSketchPde.pde"], }, { "name": "demo", - "base": "examples/demo", + "base": os.path.join("examples", "demo"), "files": ["demo.h", "util.h", "demo.cpp"], }, { @@ -574,8 +580,8 @@ def test_examples_from_dir(tmpdir_factory): "base": "examples/world", "files": [ "platformio.ini", - "include/world.h", - "src/world.c", + os.path.join("include", "world.h"), + os.path.join("src", "world.c"), "README", "extra.py", ],