From 84bf8c268d5ae92c2b7bdfe6428eeceab2c51614 Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Sun, 24 Mar 2019 00:43:59 +0300 Subject: [PATCH 1/3] platformio: generate core_version.h when using feature/stage --- tools/makecorever.py | 78 +++++++++++++++++++++++++-------------- tools/platformio-build.py | 36 ++++++++++++++++++ 2 files changed, 86 insertions(+), 28 deletions(-) diff --git a/tools/makecorever.py b/tools/makecorever.py index fd5556630e..95928bd1a0 100755 --- a/tools/makecorever.py +++ b/tools/makecorever.py @@ -21,31 +21,53 @@ import os import subprocess -parser = argparse.ArgumentParser(description='Generate core_version.h') -parser.add_argument('-b', '--build_path', action='store', required=True, help='build.path variable') -parser.add_argument('-p', '--platform_path', action='store', required=True, help='platform.path variable') -parser.add_argument('-v', '--version', action='store', required=True, help='version variable') - -args = parser.parse_args() - -core = args.build_path + '/core' -try: - os.makedirs(core) -except: - pass - -out = open(core + '/core_version.h', "w") - -try: - p = subprocess.Popen(['git', '--git-dir', args.platform_path + '/.git', 'rev-parse', '--short=8', 'HEAD'], stdout = subprocess.PIPE ) - git_ver = '0x' + p.stdout.readlines()[0].strip() - p = subprocess.Popen(['git', '--git-dir', args.platform_path + '/.git', 'describe', '--tags'], stdout = subprocess.PIPE ) - git_desc = p.stdout.readlines()[0].strip() -except: - git_ver = '0xffffffff' - git_desc = args.version - -out.write('#define ARDUINO_ESP8266_GIT_VER ' + git_ver + '\n') -out.write('#define ARDUINO_ESP8266_GIT_DESC ' + git_desc + '\n') - -out.close() + +def generate(path, platform_path, git_ver="0xffffffff", git_desc="unspecified"): + def git(*args): + cmd = ["git", "-C", platform_path] + cmd.extend(args) + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True) + return proc.stdout.readlines()[0].strip() + + try: + git_ver = git("rev-parse", "--short=8", "HEAD") + git_desc = git("describe", "--tags") + except: + pass + + with open(path, "w") as out: + out.write("#define ARDUINO_ESP8266_GIT_VER 0x{}\n".format(git_ver)) + out.write("#define ARDUINO_ESP8266_GIT_DESC {}\n".format(git_desc)) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Generate core_version.h") + + parser.add_argument( + "-b", "--build_path", action="store", required=True, help="build.path variable" + ) + parser.add_argument( + "-p", + "--platform_path", + action="store", + required=True, + help="platform.path variable", + ) + parser.add_argument( + "-v", "--version", action="store", required=True, help="version variable" + ) + parser.add_argument("-i", "--include_dir", default="core") + + args = parser.parse_args() + + include_dir = os.path.join(args.build_path, args.include_dir) + try: + os.makedirs(include_dir) + except: + pass + + generate( + os.path.join(include_dir, "core_version.h"), + args.platform_path, + git_desc=args.version, + ) diff --git a/tools/platformio-build.py b/tools/platformio-build.py index deee8aac7c..e879580f0a 100644 --- a/tools/platformio-build.py +++ b/tools/platformio-build.py @@ -24,6 +24,9 @@ # Extends: https://github.com/platformio/platform-espressif8266/blob/develop/builder/main.py +import os +import subprocess + from os.path import isdir, join from SCons import Builder, Util @@ -103,6 +106,7 @@ def scons_patched_match_splitext(path, suffixes=None): ], CPPPATH=[ + join("$BUILD_DIR", "core"), join(FRAMEWORK_DIR, "tools", "sdk", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "libc", "xtensa-lx106-elf", "include"), @@ -220,6 +224,38 @@ def scons_patched_match_splitext(path, suffixes=None): "Generating LD script $TARGET")) env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", app_ld) +# +# Dynamic core_version.h for staging builds +# + +def platform_txt_version(default): + with open(join(FRAMEWORK_DIR, "platform.txt"), "r") as platform_txt: + for line in platform_txt: + if not line: + continue + k, delim, v = line.partition("=") + if not delim: + continue + if k == "version": + return v.strip() + + return default + +if isdir(join(FRAMEWORK_DIR, ".git")): + cmd = "$PYTHONEXE {script} -b $BUILD_DIR -p {framework_dir} -v {version}" + fmt = { + "script": join(FRAMEWORK_DIR, "tools", "makecorever.py"), + "framework_dir": FRAMEWORK_DIR, + "version": platform_txt_version("unspecified") + } + + core_version = env.Command( + join("$BUILD_DIR", "core", "core_version.h"), + join(FRAMEWORK_DIR, ".git"), + env.VerboseAction(cmd.format(**fmt), "Generating $TARGET") + ) + env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", core_version) + # # Target: Build Core Library From 8950fb0448e2c00fb1cdc7e2a08ba257727a2727 Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Tue, 26 Mar 2019 12:25:32 +0300 Subject: [PATCH 2/3] quote command line --- tools/platformio-build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/platformio-build.py b/tools/platformio-build.py index e879580f0a..35494a31f0 100644 --- a/tools/platformio-build.py +++ b/tools/platformio-build.py @@ -242,7 +242,7 @@ def platform_txt_version(default): return default if isdir(join(FRAMEWORK_DIR, ".git")): - cmd = "$PYTHONEXE {script} -b $BUILD_DIR -p {framework_dir} -v {version}" + cmd = '"$PYTHONEXE" "{script}" -b "$BUILD_DIR" -p "{framework_dir}" -v {version}' fmt = { "script": join(FRAMEWORK_DIR, "tools", "makecorever.py"), "framework_dir": FRAMEWORK_DIR, From cb06ca83133239234a0de021e901d8b7e38d2992 Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Tue, 26 Mar 2019 12:27:41 +0300 Subject: [PATCH 3/3] Modify CPPFLAGS conditionally --- tools/platformio-build.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/platformio-build.py b/tools/platformio-build.py index 35494a31f0..a784753b76 100644 --- a/tools/platformio-build.py +++ b/tools/platformio-build.py @@ -106,7 +106,6 @@ def scons_patched_match_splitext(path, suffixes=None): ], CPPPATH=[ - join("$BUILD_DIR", "core"), join(FRAMEWORK_DIR, "tools", "sdk", "include"), join(FRAMEWORK_DIR, "tools", "sdk", "libc", "xtensa-lx106-elf", "include"), @@ -249,6 +248,9 @@ def platform_txt_version(default): "version": platform_txt_version("unspecified") } + env.Prepend(CPPPATH=[ + join("$BUILD_DIR", "core") + ]) core_version = env.Command( join("$BUILD_DIR", "core", "core_version.h"), join(FRAMEWORK_DIR, ".git"),