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

Allow increment after successful upload + tidyup #4

Merged
merged 11 commits into from
Jun 4, 2020
Prev Previous commit
Next Next commit
sys import not used, pre no longer needs upload check
  • Loading branch information
pfeerick committed May 29, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 2454360fd5c11be6ddb649ac6d2d76fd89f9b934
4 changes: 2 additions & 2 deletions version_increment_post.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
""" Similar to the pre script, but increments build number """
## DO NOT EDIT THIS FILE, edit version file if you want to start from a different version
#
# version_increment.py - Simple versioning script for Platformio
#
@@ -17,13 +19,11 @@
# If not, see <https://opensource.org/licenses/MIT/>.
#

import sys
import datetime
import os

Import("env")

## DO NOT EDIT THIS FILE, edit version file if you want to start from a different version
BUILD_NUMBER = 'version'
VERSION_FILE = 'Version.h'
version = '0.1.'
78 changes: 31 additions & 47 deletions version_increment_pre.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
""" Create version header and tracker file if missing """
## DO NOT EDIT THIS FILE, edit version file if you want to start from a different version
#
# version_increment.py - Simple versioning script for Platformio
#
@@ -17,59 +19,41 @@
# If not, see <https://opensource.org/licenses/MIT/>.
#

import sys
import datetime
import os

## DO NOT EDIT THIS FILE, edit version file if you want to start from a different version
BUILD_NUMBER = 'version'
VERSION_FILE = 'Version.h'
version = '0.1.'

## Increment version during the upload stage only
upload = False
n = len(sys.argv)

for i in range(1, n):
if sys.argv[i] == "upload":
upload = True;

if upload:

print("Version Increment Scritp ARGS=")
print (sys.argv[1:])
build_no = 0

try:
with open(BUILD_NUMBER) as f:
build_no = f.readline()
version = build_no[0:build_no.rindex('.')+1]
build_no = int(build_no[build_no.rindex('.')+1:])
except:
print('No version file found or incorrect data in it. Starting from 0.1.0')
build_no = 0

try:
with open(BUILD_NUMBER) as f:
build_no = f.readline()
version = build_no[0:build_no.rindex('.')+1]
build_no = int(build_no[build_no.rindex('.')+1:])
except:
print('No version file found or incorrect data in it. Starting from 0.1.0')
build_no = 0
with open(BUILD_NUMBER, 'w+') as f:
f.write(version + str(build_no))
print('Build number: {}'.format(version + str(build_no)))

hf = """
// AUTO GENERATED FILE FROM version_increment.py, DO NOT EDIT THIS FILE
#ifndef VERSION
#define VERSION "{}"
#endif
#ifndef BUILD_TIMESTAMP
#define BUILD_TIMESTAMP "{}"
#endif
""".format(version + str(build_no), datetime.datetime.now(), version+str(build_no))

if (os.environ.get('PLATFORMIO_INCLUDE_DIR') != None):
VERSION_FILE = os.environ.get('PLATFORMIO_INCLUDE_DIR') + "/" + VERSION_FILE
elif os.path.exists("include"):
VERSION_FILE = "include/" + VERSION_FILE

with open(VERSION_FILE, 'w+') as f:
f.write(hf)
else:
print("Version Increment Script. Nothing to do. ARGS=")
print (sys.argv[1:])
with open(BUILD_NUMBER, 'w+') as f:
f.write(version + str(build_no))
print('Build number: {}'.format(version + str(build_no)))

hf = """
// AUTO GENERATED FILE FROM version_increment.py, DO NOT EDIT THIS FILE
#ifndef VERSION
#define VERSION "{}"
#endif
#ifndef BUILD_TIMESTAMP
#define BUILD_TIMESTAMP "{}"
#endif
""".format(version + str(build_no), datetime.datetime.now(), version+str(build_no))

if (os.environ.get('PLATFORMIO_INCLUDE_DIR') != None):
VERSION_FILE = os.environ.get('PLATFORMIO_INCLUDE_DIR') + "/" + VERSION_FILE
elif os.path.exists("include"):
VERSION_FILE = "include/" + VERSION_FILE

with open(VERSION_FILE, 'w+') as f:
f.write(hf)