1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-03-15 07:29:15 +01:00

Merge remote-tracking branch 'origin/parched/OP-1639_make_non-git_source' into next

This commit is contained in:
Fredrik Larsson 2014-12-01 14:03:53 +11:00
commit e8d182978f
2 changed files with 64 additions and 0 deletions

View File

@ -47,6 +47,7 @@ export DL_DIR := $(if $(OPENPILOT_DL_DIR),$(call slashfix,$(OPENPILOT_DL_DI
export TOOLS_DIR := $(if $(OPENPILOT_TOOLS_DIR),$(call slashfix,$(OPENPILOT_TOOLS_DIR)),$(ROOT_DIR)/tools)
export BUILD_DIR := $(ROOT_DIR)/build
export PACKAGE_DIR := $(ROOT_DIR)/build/package
export SOURCE_DIR := $(ROOT_DIR)/build/source
# Set up default build configurations (debug | release)
GCS_BUILD_CONF := release
@ -900,6 +901,27 @@ build-info:
--template="make/templates/$@.txt" \
--outfile="$(BUILD_DIR)/$@.txt"
##############################
#
# Source for distribution
#
##############################
.PHONY: source
source:
@$(ECHO) " SOURCE FOR DISTRIBUTION $(call toprel, $(SOURCE_DIR))"
$(V1) $(MKDIR) -p "$(SOURCE_DIR)"
$(V1) $(VERSION_INFO) \
--jsonpath="$(SOURCE_DIR)"
$(eval SOURCE_NAME := $(call toprel, "$(SOURCE_DIR)/OpenPilot-$(shell git describe).tar"))
$(V1) git archive --prefix="OpenPilot/" -o "$(SOURCE_NAME)" HEAD
$(V1) tar --append --file="$(SOURCE_NAME)" \
--transform='s,.*version-info.json,OpenPilot/version-info.json,' \
$(call toprel, "$(SOURCE_DIR)/version-info.json")
$(V1) gzip -f "$(SOURCE_NAME)"
##############################
#
# Help message, the default Makefile goal
@ -1035,6 +1057,7 @@ help:
@$(ECHO) " clean_package - Clean, build and package the OpenPilot platform-dependent package"
@$(ECHO) " package - Build and package the OpenPilot platform-dependent package (no clean)"
@$(ECHO) " opfw_resource - Generate resources to embed firmware binaries into the GCS"
@$(ECHO) " source - Generate source archive for distribution"
@$(ECHO)
@$(ECHO) " [Code Formatting]"
@$(ECHO) " uncrustify_<source> - Reformat <source> code according to the project's standards"

View File

@ -14,6 +14,8 @@ from string import Template
import optparse
import hashlib
import sys
import os.path
import json
class Repo:
"""A simple git repository HEAD commit info class
@ -90,6 +92,23 @@ class Repo:
if self._rc:
self._dirty = True
def _load_json(self):
"""Loads the repo data from version-info.json"""
json_path = os.path.join(self._path, 'version-info.json')
if os.path.isfile(json_path):
with open(json_path) as json_file:
json_data = json.load(json_file)
self._hash = json_data['hash']
self._origin = json_data['origin']
self._time = json_data['time']
self._tag = json_data['tag']
self._branch = json_data['branch']
self._dirty = json_data['dirty']
return True
return False
def __init__(self, path = "."):
"""Initialize object instance and read repo info"""
self._path = path
@ -101,6 +120,8 @@ class Repo:
self._get_tag()
self._get_branch()
self._get_dirty()
elif self._load_json():
pass
else:
self._hash = None
self._origin = None
@ -192,6 +213,21 @@ class Repo:
print "label: ", self.label()
print "revision: ", self.revision()
def save_to_json(self, path):
"""Saves the repo data to version-info.json"""
json_data = dict()
json_data['hash'] = self._hash
json_data['origin'] = self._origin
json_data['time'] = self._time
json_data['tag'] = self._tag
json_data['branch'] = self._branch
json_data['dirty'] = self._dirty
json_path = os.path.join(path, 'version-info.json')
with open(json_path, 'w') as json_file:
json.dump(json_data, json_file)
def file_from_template(tpl_name, out_name, dict):
"""Create or update file from template using dictionary
@ -387,6 +423,8 @@ string given.
help='board revision, for example, 0x01');
parser.add_option('--uavodir', default = "",
help='uav object definition directory');
parser.add_option('--jsonpath',
help='path to save version info');
(args, positional_args) = parser.parse_args()
# Process arguments. No advanced error handling is here.
@ -438,6 +476,9 @@ string given.
if args.outfile != None:
file_from_template(args.template, args.outfile, dictionary)
if args.jsonpath != None:
r.save_to_json(args.jsonpath)
return 0
if __name__ == "__main__":