Skip to content

PlatformIO: generate core_version.h when using feature/stage #5917

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

Merged
merged 4 commits into from
Apr 23, 2019
Merged
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
78 changes: 50 additions & 28 deletions tools/makecorever.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
38 changes: 38 additions & 0 deletions tools/platformio-build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -220,6 +223,41 @@ 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")
}

env.Prepend(CPPPATH=[
join("$BUILD_DIR", "core")
])
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
Expand Down