From 6360633df14cdff424b17007234c733705a80efb Mon Sep 17 00:00:00 2001 From: Bryan Date: Thu, 15 Oct 2015 16:16:58 -0700 Subject: [PATCH 01/11] package_tool initial commit --- .gitignore | 9 + package_tool/README.md | 64 ++++ package_tool/example_config.json | 39 +++ package_tool/package_files/debian/compat | 1 + package_tool/package_files/debian/rules | 3 + .../package_files/debian/source/format | 1 + package_tool/packagify | 198 ++++++++++++ .../scripts/config_template_generator.py | 224 +++++++++++++ package_tool/scripts/debian_build_lib.sh | 157 +++++++++ package_tool/scripts/extract_json_value.py | 59 ++++ package_tool/scripts/manpage_generator.py | 299 ++++++++++++++++++ package_tool/setup/build_setup.sh | 10 + package_tool/setup/test_setup.sh | 17 + package_tool/templates/debian/changelog | 5 + package_tool/templates/debian/control | 13 + package_tool/templates/debian/copyright | 8 + package_tool/test.sh | 36 +++ .../test/integration_tests/test_package.bats | 46 +++ package_tool/test/test_assets/lkgtestman.1 | 99 ++++++ .../test_package_layout/debian_config.json | 40 +++ .../test_assets/test_package_layout/docs.json | 108 +++++++ .../test_package_layout/docs/testdocs.1 | 99 ++++++ .../path_relative_to_package_root/test_exe.sh | 13 + .../package_root/test_called.sh | 3 + .../test_package_layout/samples/testsample.cs | 9 + package_tool/test/test_assets/testdocs.json | 108 +++++++ .../unit_tests/test_debian_build_lib.bats | 275 ++++++++++++++++ .../test/unit_tests/test_scripts.bats | 24 ++ 28 files changed, 1967 insertions(+) create mode 100644 package_tool/README.md create mode 100644 package_tool/example_config.json create mode 100644 package_tool/package_files/debian/compat create mode 100644 package_tool/package_files/debian/rules create mode 100644 package_tool/package_files/debian/source/format create mode 100644 package_tool/packagify create mode 100644 package_tool/scripts/config_template_generator.py create mode 100644 package_tool/scripts/debian_build_lib.sh create mode 100644 package_tool/scripts/extract_json_value.py create mode 100644 package_tool/scripts/manpage_generator.py create mode 100644 package_tool/setup/build_setup.sh create mode 100644 package_tool/setup/test_setup.sh create mode 100644 package_tool/templates/debian/changelog create mode 100644 package_tool/templates/debian/control create mode 100644 package_tool/templates/debian/copyright create mode 100644 package_tool/test.sh create mode 100644 package_tool/test/integration_tests/test_package.bats create mode 100644 package_tool/test/test_assets/lkgtestman.1 create mode 100644 package_tool/test/test_assets/test_package_layout/debian_config.json create mode 100644 package_tool/test/test_assets/test_package_layout/docs.json create mode 100644 package_tool/test/test_assets/test_package_layout/docs/testdocs.1 create mode 100644 package_tool/test/test_assets/test_package_layout/package_root/path_relative_to_package_root/test_exe.sh create mode 100644 package_tool/test/test_assets/test_package_layout/package_root/test_called.sh create mode 100644 package_tool/test/test_assets/test_package_layout/samples/testsample.cs create mode 100644 package_tool/test/test_assets/testdocs.json create mode 100644 package_tool/test/unit_tests/test_debian_build_lib.bats create mode 100644 package_tool/test/unit_tests/test_scripts.bats diff --git a/.gitignore b/.gitignore index 4099ccc78..f08574c3d 100644 --- a/.gitignore +++ b/.gitignore @@ -24,5 +24,14 @@ debugSettings.json project.lock.json TestResults/ +# Debian and python stuff +*.dsc +*.tar.gz +*.build +*.changes +*.deb +*.pyc +*.pyo + # Profiler result files, just in case they are left lying around :) .vs/ diff --git a/package_tool/README.md b/package_tool/README.md new file mode 100644 index 000000000..d42668652 --- /dev/null +++ b/package_tool/README.md @@ -0,0 +1,64 @@ +# Debian Packagify + +A tool which consumes a directory structure to produce a debian package. + +## Usage + + package_tool [path to input directory] [path to output directory] + +## Input Directory Spec + + package/ + $/ (Contents in this directory will be placed absolutely according to their relative path) + usr/lib/somelib.so (ex. This file gets placed at /usr/lib/somelib.so at install) + package_root/ (Contents placed in install root) + samples/ (Contents here will be installed as samples) + docs/ (Contents will be installed as manpages) + debian_config.json (See example below) + docs.json (For manpage generation) + (ex. dotnet-commands-test.sh) + + + +## full example debian_config.json +Note: remove all comments before using this + + { + "maintainer_name":"Microsoft", // [required] + "maintainer_email": "optimus@service.microsoft.com", // [required] + + "package_name": "Packagify_Test", // [required] + + "short_description": "This is a test package", // [required] Max. 60 chars + "long_description": "This is a longer description of the test package", // [required] + "homepage": "http://testpackage.com", // (optional no default) + + "release":{ + "package_version":"0.1", // [required] + "package_revision":"1", // [required] + "urgency" : "low", // (optional default="low") https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Urgency + "changelog_message" : "some stuff here" // [required] + }, + + "control": { // (optional) + "priority":"standard", // (optional default="standard") https://www.debian.org/doc/debian-policy/ch-archive.html#s-priorities + "section":"devel", // (optional default="misc") https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections + "architecture":"all" // (optional default="all" ) + }, + + "copyright": "2015 Microsoft", // [required] + "license": { // [required] + "type": "some_license", // [required] + "full_text": "full license text here" // [required] + }, + + "debian_dependencies" : { // (optional no default) + "package_name": { + "package_version" : "1.0.0" // (optional within package_name no default) + } + }, + + "symlinks": { // (optional no defaults) + "path_relative_to_package_root/test_exe.sh" : "/usr/bin/test_exe.sh" + } + } \ No newline at end of file diff --git a/package_tool/example_config.json b/package_tool/example_config.json new file mode 100644 index 000000000..acffec7ac --- /dev/null +++ b/package_tool/example_config.json @@ -0,0 +1,39 @@ +{ + "maintainer_name":"Microsoft", // [required] + "maintainer_email": "optimus@service.microsoft.com", // [required] + + "package_name": "Packagify_Test", // [required] + + "short_description": "This is a test package", // [required] Max. 60 chars + "long_description": "This is a longer description of the test package", // [required] + "homepage": "http://testpackage.com", // (optional no default) + + "release":{ + "package_version":"0.1", // [required] + "package_revision":"1", // [required] + "urgency" : "low", // (optional default="low") https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Urgency + "changelog_message" : "some stuff here" // [required] + }, + + "control": { // (optional) + "priority":"standard", // (optional default="standard") https://www.debian.org/doc/debian-policy/ch-archive.html#s-priorities + "section":"devel", // (optional default="misc") https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections + "architecture":"all" // (optional default="all" ) + }, + + "copyright": "2015 Microsoft", // [required] + "license": { // [required] + "type": "some_license", // [required] + "full_text": "full license text here" // [required] + }, + + "debian_dependencies" : { // (optional no default) + "package_name": { + "package_version" : "1.0.0" // (optional within package_name no default) + } + }, + + "symlinks": { // (optional no defaults) + "path_relative_to_package_root/test_exe.sh" : "/usr/bin/test_exe.sh" + } +} \ No newline at end of file diff --git a/package_tool/package_files/debian/compat b/package_tool/package_files/debian/compat new file mode 100644 index 000000000..ec635144f --- /dev/null +++ b/package_tool/package_files/debian/compat @@ -0,0 +1 @@ +9 diff --git a/package_tool/package_files/debian/rules b/package_tool/package_files/debian/rules new file mode 100644 index 000000000..cbe925d75 --- /dev/null +++ b/package_tool/package_files/debian/rules @@ -0,0 +1,3 @@ +#!/usr/bin/make -f +%: + dh $@ diff --git a/package_tool/package_files/debian/source/format b/package_tool/package_files/debian/source/format new file mode 100644 index 000000000..163aaf8d8 --- /dev/null +++ b/package_tool/package_files/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/package_tool/packagify b/package_tool/packagify new file mode 100644 index 000000000..b43975d23 --- /dev/null +++ b/package_tool/packagify @@ -0,0 +1,198 @@ +#!/bin/bash +# +# Takes Parameters: +# $0 = Input Directory +# $1 = Output Directory + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +## Load Functions ## +source $SCRIPT_DIR/scripts/debian_build_lib.sh + +INPUT_DIR=$1 +OUTPUT_DIR=$2 + +# Special Input Directories + Paths +ABSOLUTE_PLACEMENT_DIR="${INPUT_DIR}/\$" +PACKAGE_ROOT_PLACEMENT_DIR="${INPUT_DIR}/package_root" + +# Output Directories + +# Inputs +INPUT_SAMPLES_DIR="$INPUT_DIR/samples" +INPUT_DOCS_DIR="$INPUT_DIR/docs" +DOCS_JSON_PATH="$INPUT_DIR/docs.json" +CONFIG="$INPUT_DIR/debian_config.json" + +## Debian Package Creation Functions ## +execute(){ + # Exit if required validation fails + if ! validate_inputs; then + exit 1 + fi + + parse_config_and_set_env_vars + clean_or_create_build_dirs + package_all + generate_all + create_source_tarball + + # Actually Build Package Files + (cd ${PACKAGE_SOURCE_DIR}; debuild -us -uc) + + copy_files_to_output +} + +validate_inputs(){ + local ret=0 + if [[ ! -d $ABSOLUTE_PLACEMENT_DIR ]]; then + echo "ERROR: $ directory does not exist" + echo $ABSOLUTE_PLACEMENT_DIR + ret=1 + fi + + if [[ ! -d $PACKAGE_ROOT_PLACEMENT_DIR ]]; then + echo "ERROR: package_root directory does not exist" + echo $PACKAGE_ROOT_PLACEMENT_DIR + ret=1 + fi + + if [[ ! -f $CONFIG ]]; then + echo "ERROR: debian_config.json file does not exist" + echo $CONFIG + ret=1 + fi + + return $ret +} + +parse_config_and_set_env_vars(){ + extract_base_cmd="python $SCRIPT_DIR/scripts/extract_json_value.py" + + PACKAGE_NAME=$($extract_base_cmd $CONFIG "package_name") + PACKAGE_VERSION=$($extract_base_cmd $CONFIG "release.package_version") + + PACKAGE_SOURCE_DIR="${OUTPUT_DIR}/${PACKAGE_NAME}-${PACKAGE_VERSION}" + + DEBIAN_DIR="${PACKAGE_SOURCE_DIR}/debian" + DOCS_DIR="${PACKAGE_SOURCE_DIR}/docs" +} + +clean_or_create_build_dirs(){ + rm -rf ${PACKAGE_SOURCE_DIR} + mkdir -p $DEBIAN_DIR +} + +package_all(){ + package_static_files + package_package_root_placement + package_absolute_placement + package_samples +} + +generate_all(){ + generate_config_templates + generate_manpages + generate_manpage_manifest + generate_sample_manifest + write_debian_install_file +} + +create_source_tarball(){ + rm -f ${OUTPUT_DIR}/${PACKAGE_NAME}_${PACKAGE_VERSION}.orig.tar.gz + tar -cvzf ${OUTPUT_DIR}/${PACKAGE_NAME}_${PACKAGE_VERSION}.orig.tar.gz -C $PACKAGE_SOURCE_DIR . +} + +copy_files_to_output(){ + # .deb, .dsc, etc.. Already in output dir + # Copy Test files + + cp $SCRIPT_DIR/test/integration_tests/test_package.bats $OUTPUT_DIR +} + +## Packaging Functions ## +package_static_files(){ + cp -a $SCRIPT_DIR/package_files/debian/* ${PACKAGE_SOURCE_DIR}/debian +} + +package_package_root_placement(){ + add_dir_to_install ${PACKAGE_ROOT_PLACEMENT_DIR} "" +} + +package_absolute_placement(){ + abs_in_package_dir="\$" + + add_dir_to_install ${ABSOLUTE_PLACEMENT_DIR} $abs_in_package_dir + + # Get List of all files in directory tree, relative to ABSOLUTE_PLACEMENT_DIR + abs_files=( $(_get_files_in_dir_tree $ABSOLUTE_PLACEMENT_DIR) ) + + # For each file add a a system placement + for abs_file in $abs_files + do + parent_dir=$(dirname $abs_file) + filename=$(basename $abs_file) + + add_system_file_placement "$abs_in_package_dir/$abs_file" "/$parent_dir" + done +} + +package_samples(){ + if [[ -d "$INPUT_SAMPLES_DIR" ]]; then + cp -a $INPUT_SAMPLES_DIR/. $PACKAGE_SOURCE_DIR + fi +} + +package_docs(){ + if [[ -d "$INPUT_DOCS_DIR" ]]; then + mkdir -p $DOCS_DIR + cp -a $INPUT_DOCS_DIR/. $DOCS_DIR + fi +} + +## Generation Functions ## +generate_config_templates(){ + python ${SCRIPT_DIR}/scripts/config_template_generator.py $CONFIG $SCRIPT_DIR/templates/debian $DEBIAN_DIR +} + +generate_manpages(){ + if [[ -f "$DOCS_JSON_PATH" ]]; then + mkdir -p $DOCS_DIR + + # Generate the manpages from json spec + python ${SCRIPT_DIR}/scripts/manpage_generator.py ${DOCS_JSON_PATH} ${DOCS_DIR} + fi +} + +generate_manpage_manifest(){ + # Get a list of files generated relative to $DOCS_DIR + generated_manpages=( $(_get_files_in_dir_tree $DOCS_DIR) ) + + # Get path relative to $PACKAGE_SOURCE_DIR to prepend to each filename + # This syntax is bash substring removal + docs_rel_path=${DOCS_DIR#${PACKAGE_SOURCE_DIR}} + + # Remove any existing manifest + rm -f ${DEBIAN_DIR}/${PACKAGE_NAME}.manpages + + for manpage in $generated_manpages + do + echo "${docs_rel_path}/${manpage}" >> "${DEBIAN_DIR}/${PACKAGE_NAME}.manpages" + done +} + +generate_sample_manifest(){ + if [[ -d "$INPUT_SAMPLES_DIR" ]]; then + generated_manpages=( $(_get_files_in_dir_tree $INPUT_SAMPLES_DIR) ) + + rm sample_manifest + for sample in $samples + do + echo "$sample" >> "${DEBIAN_DIR}/${PACKAGE_NAME}.examples" + done + else + echo "Provide a 'samples' directory in INPUT_DIR to package samples" + fi +} + +execute diff --git a/package_tool/scripts/config_template_generator.py b/package_tool/scripts/config_template_generator.py new file mode 100644 index 000000000..fb7a8fead --- /dev/null +++ b/package_tool/scripts/config_template_generator.py @@ -0,0 +1,224 @@ +#!/usr/bin/python +# +# Parses debian_config.json and generates appropriate templates +# Where optional defaults exist, they are defined in the template_dict +# of the appropriate generation function + +import os +import sys +import json +import datetime + +FILE_CHANGELOG = 'changelog' +FILE_CONTROL = 'control' +FILE_COPYRIGHT = 'copyright' +FILE_SYMLINK_FORMAT = '{package_name}.links' + +PACKAGE_ROOT_FORMAT = "/usr/share/{package_name}" +CHANGELOG_DATE_FORMAT = "%a, %d %b %Y %H:%M:%S %z" + +# UTC Timezone for Changelog date +class UTC(datetime.tzinfo): + def utcoffset(self, dt): + return datetime.timedelta(0) + + def tzname(self, dt): + return "UTC" + + def dst(self, dt): + return datetime.timedelta(0) + +# Generation Functions +def generate_and_write_all(config_data, template_dir, output_dir): + # try: + changelog_contents = generate_changelog(config_data, template_dir) + control_contents = generate_control(config_data, template_dir) + copyright_contents = generate_copyright(config_data, template_dir) + symlink_contents = generate_symlinks(config_data) + # except Exception as exc: + # print exc + # help_and_exit("Error: Generation Failed, check your config file.") + + write_file(changelog_contents, output_dir, FILE_CHANGELOG) + write_file(control_contents, output_dir, FILE_CONTROL) + write_file(copyright_contents, output_dir, FILE_COPYRIGHT) + + # Symlink File is optional + if symlink_contents: + symlink_filename = get_symlink_filename(config_data) + write_file(symlink_contents, output_dir, symlink_filename) + + return + +def generate_changelog(config_data, template_dir): + template = get_template(template_dir, FILE_CHANGELOG) + + release_data = config_data["release"] + + template_dict = dict(\ + PACKAGE_VERSION=release_data["package_version"], + PACKAGE_REVISION=release_data["package_revision"], + CHANGELOG_MESSAGE=release_data["changelog_message"], + URGENCY=release_data.get("urgency", "low"), + + PACKAGE_NAME=config_data["package_name"], + MAINTAINER_NAME=config_data["maintainer_name"], + MAINTAINER_EMAIL=config_data["maintainer_email"], + DATE=datetime.datetime.now(UTC()).strftime(CHANGELOG_DATE_FORMAT) + ) + + contents = template.format(**template_dict) + + return contents + +def generate_control(config_data, template_dir): + template = get_template(template_dir, FILE_CONTROL) + + dependency_data = config_data.get("debian_dependencies", None) + dependency_str = get_dependendent_packages_string(dependency_data) + + # Default to empty dict, so we don't explode on nested optional values + control_data = config_data.get("control", dict()) + + template_dict = dict(\ + SHORT_DESCRIPTION=config_data["short_description"], + LONG_DESCRIPTION=config_data["long_description"], + HOMEPAGE=config_data.get("homepage", ""), + + SECTION=control_data.get("section", "misc"), + PRIORITY=control_data.get("priority", "low"), + ARCH=control_data.get("architecture", "all"), + + DEPENDENT_PACKAGES=dependency_str, + + PACKAGE_NAME=config_data["package_name"], + MAINTAINER_NAME=config_data["maintainer_name"], + MAINTAINER_EMAIL=config_data["maintainer_email"] + ) + + contents = template.format(**template_dict) + + return contents + +def generate_copyright(config_data, template_dir): + template = get_template(template_dir, FILE_COPYRIGHT) + + license_data = config_data["license"] + + template_dict = dict(\ + COPYRIGHT_TEXT=config_data["copyright"], + LICENSE_NAME=license_data["type"], + LICENSE_TEXT=license_data["full_text"] + ) + + contents = template.format(**template_dict) + + return contents + +def generate_symlinks(config_data): + symlink_entries = [] + package_root_path = get_package_root(config_data) + + symlink_data = config_data.get("symlinks", dict()) + + for package_rel_path, symlink_path in symlink_data.iteritems(): + + package_abs_path = os.path.join(package_root_path, package_rel_path) + + symlink_entries.append( '%s %s' % (package_abs_path, symlink_path) ) + + return '\n'.join(symlink_entries) + +# Helper Functions +def get_package_root(config_data): + package_name = config_data["package_name"] + return PACKAGE_ROOT_FORMAT.format(package_name=package_name) + +def get_symlink_filename(config_data): + package_name = config_data["package_name"] + return FILE_SYMLINK_FORMAT.format(package_name=package_name) + +def get_dependendent_packages_string(debian_dependency_data): + if debian_dependency_data is None: + return "" + + dependencies = [] + + for debian_package_name in debian_dependency_data: + dep_str = debian_package_name + + if debian_dependency_data[debian_package_name].get("package_version", None): + debian_package_version = debian_dependency_data[debian_package_name].get("package_version") + + dep_str += " (>= %s)" % debian_package_version + + dependencies.append(dep_str) + + # Leading Comma is important here + return ', ' + ', '.join(dependencies) + + +def load_json(json_path): + json_data = None + with open(json_path, 'r') as json_file: + json_data = json.load(json_file) + + return json_data + +def get_template(template_dir, name): + path = os.path.join(template_dir, name) + template_contents = None + + with open(path, 'r') as template_file: + template_contents = template_file.read() + + return template_contents + +def write_file(contents, output_dir, name): + path = os.path.join(output_dir, name) + + with open(path, 'w') as out_file: + out_file.write(contents) + + return + +# Tool Functions +def help_and_exit(msg): + print msg + sys.exit(1) + +def print_usage(): + print "Usage: config_template_generator.py [config file path] [template directory path] [output directory]" + +def parse_and_validate_args(): + if len(sys.argv) < 4: + print_usage() + help_and_exit("Error: Invalid Arguments") + + config_path = sys.argv[1] + template_dir = sys.argv[2] + output_dir = sys.argv[3] + + if not os.path.isfile(config_path): + help_and_exit("Error: Invalid config file path") + + if not os.path.isdir(template_dir): + help_and_exit("Error: Invalid template directory path") + + if not os.path.isdir(output_dir): + print output_dir #TODO debug + help_and_exit("Error: Invalid output directory path") + + return (config_path, template_dir, output_dir) + + + +def execute(): + config_path, template_dir, output_dir = parse_and_validate_args() + + config_data = load_json(config_path) + + generate_and_write_all(config_data, template_dir, output_dir) + +if __name__ == "__main__": + execute() \ No newline at end of file diff --git a/package_tool/scripts/debian_build_lib.sh b/package_tool/scripts/debian_build_lib.sh new file mode 100644 index 000000000..eb51f0b93 --- /dev/null +++ b/package_tool/scripts/debian_build_lib.sh @@ -0,0 +1,157 @@ +# This file is not intended to be executed directly +# Import these functions using source +# +# Relies on these environment variables: +# PACKAGE_SOURCE_DIR :: Package Source Staging Directory +# PACKAGE_DIR :: Package Build Directory +# INSTALL_ROOT :: Absolute path of package installation root + +# write_debian_install_file +# Summary: Writes the contents of the "install_placement" array to the debian/install +# This array is populated by calls to the "add_system_file_placement" function +# Usage: write_debian_install_file + +write_debian_install_file(){ + # Remove any existing install file, we need to overwrite it + rm -f ${PACKAGE_SOURCE_DIR}/debian/install + + for i in "${install_placement[@]}" + do + echo "${i}" >> "${PACKAGE_SOURCE_DIR}/debian/install" + done +} + +# add_system_file_placement +# Summary: Registers a file placement on the filesystem from the package by populating the "install_placement" array +# Usage: add_system_file_placement {local path of file in package} {absolute path of directory to place file in} +add_system_file_placement(){ + #Initialize placement_index variable + if [[ -z "$placement_index" ]]; then + placement_index=0 + fi + + install_placement[${placement_index}]="${1} ${2}" + placement_index=$((${placement_index}+1)) +} + +# add_system_dir_placement +# Summary: Registers a directory placement on the post-installation package from an in-package path +add_system_dir_placement(){ + + in_package_dir=$1 + abs_installation_dir=$2 + + dir_files=( $(_get_files_in_dir_tree $PACKAGE_SOURCE_DIR/$in_package_dir) ) + + for rel_filepath in ${dir_files[@]} + do + local parent_path=$(dirname $rel_filepath) + + # If there is no parent, parent_path = "." + if [[ "$parent_path" == "." ]]; then + add_system_file_placement "${in_package_dir}/${rel_filepath}" "${abs_installation_dir}" + else + add_system_file_placement "${in_package_dir}/${rel_filepath}" "${abs_installation_dir}/${parent_path}" + fi + + done +} + +# add_file_to_install +# Summary: Adds a file from the local filesystem to the package and installs it rooted at INSTALL_ROOT +# Usage: add_install_file {relative path to local file} {relative path to INSTALL_ROOT to place file} +add_file_to_install(){ + copy_from_file=$1 + rel_install_path=$2 + + local filename=$(basename $copy_from_file) + local parent_dir=$(dirname $copy_from_file) + + # Create Relative Copy From Path + rel_copy_from_file=${copy_from_file#$parent_dir/} + + # Delete any existing file and ensure path exists + rm -f ./${PACKAGE_SOURCE_DIR}/${rel_install_path}/${filename} + mkdir -p ./${PACKAGE_SOURCE_DIR}/${rel_install_path} + + dir_files=( "$rel_copy_from_file" ) + + _copy_files_to_package $parent_dir $rel_install_path "${dir_files[@]}" + + add_system_file_placement "${rel_install_path}/${filename}" "${INSTALL_ROOT}/$rel_install_path" +} + +# add_dir_to_install +# Summary: Adds contents of a directory on the local filesystem to the package and installs them rooted at INSTALL_ROOT +# Note: Does not install the directory passed, only its contents +# Usage: add_dir_to_install {relative path of directory to copy} {relative path to INSTALL_ROOT to place directory tree} +add_dir_to_install(){ + + copy_from_dir=$1 + rel_install_path=$2 + + # Delete and Create any existing directory + mkdir -p ${PACKAGE_SOURCE_DIR}/${rel_install_path} + + dir_files=( $(_get_files_in_dir_tree $copy_from_dir) ) + + _copy_files_to_package "$copy_from_dir" "$rel_install_path" "${dir_files[@]}" + + add_system_dir_placement "$rel_install_path" "${INSTALL_ROOT}/$rel_install_path" +} + +# Usage: _copy_files_to_package {local files root directory} {relative directory in package to copy to} "${filepath_array[@]}" +# Note: The specific syntax on the parameter shows how to pass an array +_copy_files_to_package(){ + local_root_dir=$1 + package_dest_dir=$2 + + # Consume the remaining input as an array + shift; shift; + rel_filepath_list=( $@ ) + + for rel_filepath in ${rel_filepath_list[@]} + do + local parent_dir=$(dirname $rel_filepath) + local filename=$(basename $rel_filepath) + + mkdir -p ${PACKAGE_SOURCE_DIR}/${package_dest_dir}/${parent_dir} + + # Ignore $parent_dir if it there isn't one + if [[ "$parent_dir" == "." ]]; then + cp "${local_root_dir}/${rel_filepath}" "${PACKAGE_SOURCE_DIR}/${package_dest_dir}" + else + cp "${local_root_dir}/${rel_filepath}" "${PACKAGE_SOURCE_DIR}/${package_dest_dir}/${parent_dir}" + fi + + done +} + +# Usage: _get_files_in_dir_tree {path of directory} +_get_files_in_dir_tree(){ + + root_dir=$1 + + # Use Globstar expansion to enumerate all directories and files in the tree + shopt -s globstar + dir_tree_list=( "${root_dir}/"** ) + + # Build a new array with only the Files contained in $dir_tree_list + local index=0 + for file_path in "${dir_tree_list[@]}" + do + if [ -f $file_path ]; then + dir_tree_file_list[${index}]=$file_path + index=$(($index+1)) + fi + done + + # Remove $root_dir prefix from each path in dir_tree_file_list + # This is confusing syntax, so here's a reference link (Substring Removal) + # http://wiki.bash-hackers.org/syntax/pe + dir_tree_file_list=( "${dir_tree_file_list[@]#${root_dir}/}" ) + + # Echo is the return mechanism + echo "${dir_tree_file_list[@]}" +} + diff --git a/package_tool/scripts/extract_json_value.py b/package_tool/scripts/extract_json_value.py new file mode 100644 index 000000000..ccd76c36c --- /dev/null +++ b/package_tool/scripts/extract_json_value.py @@ -0,0 +1,59 @@ +#!/usr/bin/python +# Extract Json Value +# +# Very simple tool to ease extracting json values from the cmd line. +import os +import sys +import json + +def print_usage(): + print """ + Usage: extract_json_value.py [json file path] [key of value to extract] + For nested keys, use . separator + """ + +def help_and_exit(msg=None): + print msg + print_usage() + sys.exit(1) + +def parse_and_validate_args(): + + if len(sys.argv) < 3: + help_and_exit(msg="Error: Invalid Args") + + json_path = sys.argv[1] + json_key = sys.argv[2] + + if not os.path.isfile(json_path): + help_and_exit("Error: Invalid json file path") + + return json_path, json_key + +def extract_key(json_path, json_key): + json_data = None + + with open(json_path, 'r') as json_file: + json_data = json.load(json_file) + + nested_keys = json_key.split('.') + json_context = json_data + + for key in nested_keys: + json_context = json_context.get(key, None) + + if json_context is None: + help_and_exit("Error: Invalid json key") + + return str(json_context) + +def execute(): + json_path, json_key = parse_and_validate_args() + + value = extract_key(json_path, json_key) + + return value + +if __name__ == "__main__": + print execute() + diff --git a/package_tool/scripts/manpage_generator.py b/package_tool/scripts/manpage_generator.py new file mode 100644 index 000000000..b2ead05f4 --- /dev/null +++ b/package_tool/scripts/manpage_generator.py @@ -0,0 +1,299 @@ +#!/usr/bin/python +# manpage_generator +# Converts top level docs.json format command info to +# nroff manpage format. Done in python for easy json parsing. +# +# Usage: argv[1] = path to docs.json; argv[2] = output path + +import sys +import os +import json +import datetime + +SECTION_SEPARATOR = "\n.P \n" +MANPAGE_EXTENSION = ".1" + +# For now this is a magic number +# See https://www.debian.org/doc/manuals/maint-guide/dother.en.html#manpage +SECTION_NUMBER = 1 + +def generate_man_pages(doc_path, output_dir): + + with open(doc_path) as doc_file: + doc_json = None + try: + doc_json = json.load(doc_file) + except: + raise Exception("Failed to load json file. Check formatting.") + + tools = doc_json.get("tools", None) + + if tools is None: + raise Exception("No tool sections in doc.json") + + for tool_name in tools: + tool_data = tools[tool_name] + + man_page_content = generate_man_page(tool_name, tool_data) + man_page_path = get_output_path(tool_name, output_dir) + + write_man_page(man_page_path, man_page_content) + +def get_output_path(toolname, output_dir): + out_filename = toolname + MANPAGE_EXTENSION + + return os.path.join(output_dir, out_filename) + +def write_man_page(path, content): + with open(path, 'w') as man_file: + man_file.write(content) + + #Build Fails without a final newline + man_file.write('\n') + +def generate_man_page(tool_name, tool_data): + + sections = [ + generate_header_section(tool_name, tool_data), + generate_name_section(tool_name, tool_data), + generate_synopsis_section(tool_name, tool_data), + generate_description_section(tool_name, tool_data), + generate_options_section(tool_name, tool_data), + generate_author_section(tool_name, tool_data), + generate_copyright_section(tool_name, tool_data) + ] + + return SECTION_SEPARATOR.join(sections) + +def generate_header_section(tool_name, tool_data):# + roff_text_builder = [] + + header_format = ".TH {program_name} {section_number} {center_footer} {left_footer} {center_header}" + + today = datetime.date.today() + today_string = today.strftime("%B %d, %Y") + + format_args = { + "program_name" : tool_name, + "section_number" : SECTION_NUMBER, + "center_footer" : "", # Omitted + "left_footer" : "", # Omitted + "center_header" : "" # Omitted + } + + roff_text_builder.append(header_format.format(**format_args)) + + return SECTION_SEPARATOR.join(roff_text_builder) + +def generate_name_section(tool_name, tool_data):# + roff_text_builder = [] + roff_text_builder.append(".SH NAME") + + tool_short_description = tool_data.get("short_description", "") + name_format = ".B {program_name} - {short_description}" + + name_format_args = { + "program_name": tool_name, + "short_description" : tool_short_description + } + + roff_text_builder.append(name_format.format(**name_format_args)) + + return SECTION_SEPARATOR.join(roff_text_builder) + +def generate_synopsis_section(tool_name, tool_data):# + roff_text_builder = [] + roff_text_builder.append(".SH SYNOPSIS") + + #TODO: append ellipsis conditionally if argument_list_name is added + synopsis_format = '.B {program_name} {command_name} \n.RI {options} " "\n.I "{argument_list_name}"' + + tool_commands = tool_data.get("commands", []) + for command_name in tool_commands: + command_data = tool_commands[command_name] + + # Default options to empty list so the loop doesn't blow up + options = command_data.get("options", []) + argument_list = command_data.get("argumentlist", None) + + # Construct Option Strings + option_string_list = [] + argument_list_name = "" + + for option_name in options: + option_data = options[option_name] + + specifier_short = option_data.get("short", None) + specifier_long = option_data.get("long", None) + parameter = option_data.get("parameter", None) + + option_string = _option_string_helper(specifier_short, specifier_long, parameter) + + option_string_list.append(option_string) + + # Populate Argument List Name + if argument_list: + argument_list_name = argument_list.get("name", "") + + cmd_format_args = { + 'program_name' : tool_name, + 'command_name' : command_name, + 'options' : '" "'.join(option_string_list), + 'argument_list_name' : argument_list_name + } + + cmd_string = synopsis_format.format(**cmd_format_args) + + roff_text_builder.append(cmd_string) + + return SECTION_SEPARATOR.join(roff_text_builder) + +def generate_description_section(tool_name, tool_data):# + roff_text_builder = [] + roff_text_builder.append(".SH DESCRIPTION") + + # Tool Description + long_description = tool_data.get("long_description", "") + roff_text_builder.append(".PP {0}".format(long_description)) + + # Command Descriptions + cmd_description_format = ".B {program_name} {command_name}\n{command_description}" + + tool_commands = tool_data.get("commands", []) + for command_name in tool_commands: + command_data = tool_commands[command_name] + + command_description = command_data.get("description", "") + + format_args = { + "program_name" : tool_name, + "command_name" : command_name, + "command_description" : command_description + } + + cmd_string = cmd_description_format.format(**format_args) + + roff_text_builder.append(cmd_string) + + return SECTION_SEPARATOR.join(roff_text_builder) + +def generate_options_section(tool_name, tool_data):# + roff_text_builder = [] + roff_text_builder.append(".SH OPTIONS") + + options_format = '.TP\n.B {option_specifiers}\n{option_description}' + + tool_commands = tool_data.get("commands", []) + for command_name in tool_commands: + command_data = tool_commands[command_name] + + # Default to empty list so the loop doesn't blow up + options = command_data.get("options", []) + + for option_name in options: + option_data = options[option_name] + + specifier_short = option_data.get("short", None) + specifier_long = option_data.get("long", None) + parameter = option_data.get("parameter", None) + description = option_data.get("description", "") + + option_specifiers_string = _option_string_helper(specifier_short, + specifier_long, + parameter, + include_brackets = False, + delimiter=' ", " ') + + format_args = { + "option_specifiers": option_specifiers_string, + "option_description" : description + } + + roff_text_builder.append(options_format.format(**format_args)) + + return SECTION_SEPARATOR.join(roff_text_builder) + +def generate_author_section(tool_name, tool_data):# + roff_text_builder = [] + roff_text_builder.append(".SH AUTHOR") + + author_format = '.B "{author_name}" " " \n.RI ( "{author_email}" )' + + author_name = tool_data.get("author", "") + author_email = tool_data.get("author_email", "") + + format_args = { + "author_name" : author_name, + "author_email" : author_email + } + + roff_text_builder.append(author_format.format(**format_args)) + + return SECTION_SEPARATOR.join(roff_text_builder) + +def generate_copyright_section(tool_name, tool_data):# + roff_text_builder = [] + roff_text_builder.append(".SH COPYRIGHT") + + copyright_data = tool_data.get("copyright") + + roff_text_builder.append('.B "{0}"'.format(copyright_data)) + + return SECTION_SEPARATOR.join(roff_text_builder) + +def _option_string_helper(specifier_short, specifier_long, parameter, include_brackets = True, delimiter = " | "): + option_string = "" + + if include_brackets: + option_string = " [ " + + if specifier_short: + option_string += ' "{0}" '.format(specifier_short) + + if specifier_short and specifier_long: + option_string += delimiter + + if specifier_long: + option_string += ' "{0}" '.format(specifier_long) + + if parameter: + option_string += ' " " ' + option_string += ' "{0}" '.format(parameter) + + if include_brackets: + option_string += " ] " + + return option_string + + +def print_usage(): + print "Usage: argv[1] = path to docs.json; argv[2] = output path" + print "Example: manpage_generator.py ../docs.json ./dotnet-1.0/debian" + +def parse_args(): + doc_path = sys.argv[1] + output_dir = sys.argv[2] + + return (doc_path, output_dir) + +def validate_args(doc_path, output_dir): + if not os.path.isfile(doc_path): + raise Exception("Docs.json path is not valid.") + + if not os.path.isdir(output_dir): + raise Exception("Output Directory Path is not valid.") + +def execute_command_line(): + try: + doc_path, output_dir = parse_args() + + validate_args(doc_path, output_dir) + + generate_man_pages(doc_path, output_dir) + + except Exception as exc: + print "Error: ", exc + print_usage() + +if __name__ == "__main__": + execute_command_line() diff --git a/package_tool/setup/build_setup.sh b/package_tool/setup/build_setup.sh new file mode 100644 index 000000000..6d70859f6 --- /dev/null +++ b/package_tool/setup/build_setup.sh @@ -0,0 +1,10 @@ +install_dependencies(){ + apt-get update + apt-get install -y debhelper build-essential devscripts git +} + +setup(){ + install_dependencies +} + +setup \ No newline at end of file diff --git a/package_tool/setup/test_setup.sh b/package_tool/setup/test_setup.sh new file mode 100644 index 000000000..cdc3b0f7b --- /dev/null +++ b/package_tool/setup/test_setup.sh @@ -0,0 +1,17 @@ +install_dependencies(){ + apt-get update + apt-get install -y debhelper build-essential devscripts git +} + +install_bats(){ + git clone https://github.com/sstephenson/bats.git + cd bats + ./install.sh /usr/local +} + +setup(){ + install_dependencies + install_bats +} + +setup \ No newline at end of file diff --git a/package_tool/templates/debian/changelog b/package_tool/templates/debian/changelog new file mode 100644 index 000000000..8eccaab39 --- /dev/null +++ b/package_tool/templates/debian/changelog @@ -0,0 +1,5 @@ +{PACKAGE_NAME} ({PACKAGE_VERSION}-{PACKAGE_REVISION}) unstable; urgency={URGENCY} + + * {CHANGELOG_MESSAGE} + + -- {MAINTAINER_NAME} <{MAINTAINER_EMAIL}> {DATE} diff --git a/package_tool/templates/debian/control b/package_tool/templates/debian/control new file mode 100644 index 000000000..c5a212e6d --- /dev/null +++ b/package_tool/templates/debian/control @@ -0,0 +1,13 @@ +Source: {PACKAGE_NAME} +Maintainer: {MAINTAINER_NAME} <{MAINTAINER_EMAIL}> +Section: {SECTION} +Priority: {PRIORITY} +Standards-Version: 3.9.2 +Build-Depends: debhelper (>=9) +Homepage: {HOMEPAGE} + +Package: {PACKAGE_NAME} +Architecture: {ARCH} +Depends: ${{shlibs:Depends}}, ${{misc:Depends}}{DEPENDENT_PACKAGES} +Description: {SHORT_DESCRIPTION} + {LONG_DESCRIPTION} diff --git a/package_tool/templates/debian/copyright b/package_tool/templates/debian/copyright new file mode 100644 index 000000000..89b776ab8 --- /dev/null +++ b/package_tool/templates/debian/copyright @@ -0,0 +1,8 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ + +Files: * +Copyright: {COPYRIGHT_TEXT} +License: {LICENSE_NAME} + +License: {LICENSE_NAME} + {LICENSE_TEXT} \ No newline at end of file diff --git a/package_tool/test.sh b/package_tool/test.sh new file mode 100644 index 000000000..5af650644 --- /dev/null +++ b/package_tool/test.sh @@ -0,0 +1,36 @@ + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +run_setup(){ + bash $DIR/setup/test_setup.sh +} + +run_unit_tests(){ + bats $DIR/test/unit_tests/test_debian_build_lib.bats + bats $DIR/test/unit_tests/test_scripts.bats +} + +run_integration_tests(){ + input_dir=$DIR/test/test_assets/test_package_layout + output_dir=$DIR/p_out + + # Create output dir + mkdir -p $output_dir + + # Build the actual package + sudo $DIR/package_tool $input_dir $output_dir + + # Integration Test Entrypoint placed by package_tool + bats $output_dir/test_package.bats + + # Cleanup output dir + rm -rf $DIR/test/test_assets/test_package_output +} + +run_all(){ + #run_setup + run_unit_tests + run_integration_tests +} + +run_all diff --git a/package_tool/test/integration_tests/test_package.bats b/package_tool/test/integration_tests/test_package.bats new file mode 100644 index 000000000..0d3bdb49d --- /dev/null +++ b/package_tool/test/integration_tests/test_package.bats @@ -0,0 +1,46 @@ +#!/bin/bash + +#Ensure running with superuser privileges +current_user=$(whoami) +if [ $current_user != "root" ]; then + echo "test_package.sh requires superuser privileges to run" + exit 1 +fi + +setup(){ + DIR="$BATS_TEST_DIRNAME" + + PACKAGE_FILENAME="$(ls $DIR | grep .deb -m 1)" + PACKAGE_PATH="$DIR/*.deb" + + # Get Package name from package path, + PACKAGE_NAME=${PACKAGE_FILENAME%%_*} +} + +install_package(){ + dpkg -i $PACKAGE_PATH +} + +remove_package(){ + dpkg -r $PACKAGE_NAME +} + +purge_package(){ + dpkg -P $PACKAGE_NAME +} + +@test "package install + removal test" { + install_package + remove_package +} + +@test "package install + purge test" { + install_package + purge_package +} + +# Ultimate Package Test +# https://www.debian.org/doc/manuals/maint-guide/checkit.en.html#pmaintscripts +@test "package install + upgrade + purge + install + remove + install + purge test" { + # TODO: need to figure out how to mock upgrades +} diff --git a/package_tool/test/test_assets/lkgtestman.1 b/package_tool/test/test_assets/lkgtestman.1 new file mode 100644 index 000000000..57915b0a6 --- /dev/null +++ b/package_tool/test/test_assets/lkgtestman.1 @@ -0,0 +1,99 @@ +.TH tool1 1 +.P +.SH NAME +.P +.B tool1 - A tool to Vestibulum lacinia arcu eget nulla. +.P +.SH SYNOPSIS +.P +.B tool1 noOptionsCommand +.RI " " +.I "argument list stuff" +.P +.B tool1 noArgumentListFullOptions +.RI [ "-t" | "--target" " " "TARGET" ] " " [ "--noshortparam" ] " " [ "-l" ] " " [ "-p" | "--noparam" ] " " [ "-n" " " "NOLONG" ] " " [ "--noshort" " " "NOSHORT" ] " " [ "-a" | "--another" " " "ANOTHER" ] " " +.I "" +.P +.B tool1 fullcommand1 +.RI [ "-t" | "--target" " " "TARGET" ] " " [ "--noshortparam" ] " " [ "-l" ] " " [ "-p" | "--noparam" ] " " [ "-n" " " "NOLONG" ] " " [ "--noshort" " " "NOSHORT" ] " " [ "-a" | "--another" " " "ANOTHER" ] " " +.I "argument list stuff" +.P +.SH DESCRIPTION +.P +.PP Tool1 is a really great Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. +.P +.B tool1 noOptionsCommand +builds a native executable from specified source files +.P +.B tool1 noArgumentListFullOptions +builds a native executable from specified source files +.P +.B tool1 fullcommand1 +builds a native executable from specified source files +.P +.SH OPTIONS +.P +.TP +.B "-t" ", " "--target" " " "TARGET" +Specifies target binary output type. EXE or DLL +.P +.TP +.B "--noshortparam" +Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra +.P +.TP +.B "-l" +Specifies noparam nolong congue elementum. Morbi in ipsum sit amet pede facilisis laoreet +.P +.TP +.B "-p" ", " "--noparam" +Specifies noparam metus vitae pharetra auctor, sem +.P +.TP +.B "-n" " " "NOLONG" +Specifies nolong Nunc feugiat mi a tellus consequat +.P +.TP +.B "--noshort" " " "NOSHORT" +Specifies noshortNam nec ante. Sed lacinia, urna non tincidunt +.P +.TP +.B "-a" ", " "--another" " " "ANOTHER" +Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra +.P +.TP +.B "-t" ", " "--target" " " "TARGET" +Specifies target binary output type. EXE or DLL +.P +.TP +.B "--noshortparam" +Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra +.P +.TP +.B "-l" +Specifies noparam nolong congue elementum. Morbi in ipsum sit amet pede facilisis laoreet +.P +.TP +.B "-p" ", " "--noparam" +Specifies noparam metus vitae pharetra auctor, sem +.P +.TP +.B "-n" " " "NOLONG" +Specifies nolong Nunc feugiat mi a tellus consequat +.P +.TP +.B "--noshort" " " "NOSHORT" +Specifies noshortNam nec ante. Sed lacinia, urna non tincidunt +.P +.TP +.B "-a" ", " "--another" " " "ANOTHER" +Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra +.P +.SH AUTHOR +.P +.B "Test Author" " " +.RI ( "testing@testing.com" ) +.P +.SH COPYRIGHT +.P +.B "This is the copyright of tool1." diff --git a/package_tool/test/test_assets/test_package_layout/debian_config.json b/package_tool/test/test_assets/test_package_layout/debian_config.json new file mode 100644 index 000000000..23a6eb139 --- /dev/null +++ b/package_tool/test/test_assets/test_package_layout/debian_config.json @@ -0,0 +1,40 @@ +{ + "maintainer_name":"Microsoft", + "maintainer_email": "optimus@service.microsoft.com", + + "package_name": "packagetooltest", + + "short_description": "This is a test package", + "long_description": "This is a longer description of the test package", + "homepage": "http://testpackage.com", + + "release":{ + "package_version":"0.1", + "package_revision":"1", + "urgency" : "low", + "changelog_message" : "some stuff here" + }, + + "control": { + "priority":"standard", + "section":"devel", + "architecture":"any" + }, + + "copyright": "2015 Microsoft", + "license": { + "type": "some_license", + "full_text": "full license text here" + }, + + "debian_dependencies" : { + "curl": { + "package_version" : "0.5.3" + }, + "python":{} + }, + + "symlinks": { + "path_relative_to_package_root/test_exe.sh" : "/usr/bin/test_exe.sh" + } +} \ No newline at end of file diff --git a/package_tool/test/test_assets/test_package_layout/docs.json b/package_tool/test/test_assets/test_package_layout/docs.json new file mode 100644 index 000000000..2f999d342 --- /dev/null +++ b/package_tool/test/test_assets/test_package_layout/docs.json @@ -0,0 +1,108 @@ +{ + "tools": { + "tool1": { + "copyright": "This is the copyright of tool1.", + "license" : "This is the license of tool1", + "author":"Test Author", + "author_email":"testing@testing.com", + "short_description":"A tool to Vestibulum lacinia arcu eget nulla.", + "long_description":"Tool1 is a really great Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. ", + "commands": { + "fullcommand1":{ + "description":"builds a native executable from specified source files", + "options" : { + "target": { + "short": "-t", + "long":"--target", + "description":"Specifies target binary output type. EXE or DLL", + "parameter":"TARGET" + }, + "target2": { + "short": "-a", + "long":"--another", + "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra", + "parameter":"ANOTHER" + }, + "noshort": { + "long":"--noshort", + "description":"Specifies noshortNam nec ante. Sed lacinia, urna non tincidunt", + "parameter":"NOSHORT" + }, + "nolong": { + "short": "-n", + "description":"Specifies nolong Nunc feugiat mi a tellus consequat ", + "parameter":"NOLONG" + }, + "noparam": { + "short": "-p", + "long":"--noparam", + "description":"Specifies noparam metus vitae pharetra auctor, sem" + }, + "noParamNoShort": { + "long":"--noshortparam", + "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra" + }, + "noParamNoLong": { + "short": "-l", + "description":"Specifies noparam nolong congue elementum. Morbi in ipsum sit amet pede facilisis laoreet" + } + }, + "argumentlist" : { + "name":"argument list stuff", + "description":"ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;" + } + + }, + "noOptionsCommand":{ + "description":"builds a native executable from specified source files", + "argumentlist" : { + "name":"argument list stuff", + "description":"ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;" + } + + }, + "noArgumentListFullOptions":{ + "description":"builds a native executable from specified source files", + "options" : { + "target": { + "short": "-t", + "long":"--target", + "description":"Specifies target binary output type. EXE or DLL", + "parameter":"TARGET" + }, + "target2": { + "short": "-a", + "long":"--another", + "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra", + "parameter":"ANOTHER" + }, + "noshort": { + "long":"--noshort", + "description":"Specifies noshortNam nec ante. Sed lacinia, urna non tincidunt", + "parameter":"NOSHORT" + }, + "nolong": { + "short": "-n", + "description":"Specifies nolong Nunc feugiat mi a tellus consequat ", + "parameter":"NOLONG" + }, + "noparam": { + "short": "-p", + "long":"--noparam", + "description":"Specifies noparam metus vitae pharetra auctor, sem" + }, + "noParamNoShort": { + "long":"--noshortparam", + "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra" + }, + "noParamNoLong": { + "short": "-l", + "description":"Specifies noparam nolong congue elementum. Morbi in ipsum sit amet pede facilisis laoreet" + } + } + } + } + + } + } +} diff --git a/package_tool/test/test_assets/test_package_layout/docs/testdocs.1 b/package_tool/test/test_assets/test_package_layout/docs/testdocs.1 new file mode 100644 index 000000000..57915b0a6 --- /dev/null +++ b/package_tool/test/test_assets/test_package_layout/docs/testdocs.1 @@ -0,0 +1,99 @@ +.TH tool1 1 +.P +.SH NAME +.P +.B tool1 - A tool to Vestibulum lacinia arcu eget nulla. +.P +.SH SYNOPSIS +.P +.B tool1 noOptionsCommand +.RI " " +.I "argument list stuff" +.P +.B tool1 noArgumentListFullOptions +.RI [ "-t" | "--target" " " "TARGET" ] " " [ "--noshortparam" ] " " [ "-l" ] " " [ "-p" | "--noparam" ] " " [ "-n" " " "NOLONG" ] " " [ "--noshort" " " "NOSHORT" ] " " [ "-a" | "--another" " " "ANOTHER" ] " " +.I "" +.P +.B tool1 fullcommand1 +.RI [ "-t" | "--target" " " "TARGET" ] " " [ "--noshortparam" ] " " [ "-l" ] " " [ "-p" | "--noparam" ] " " [ "-n" " " "NOLONG" ] " " [ "--noshort" " " "NOSHORT" ] " " [ "-a" | "--another" " " "ANOTHER" ] " " +.I "argument list stuff" +.P +.SH DESCRIPTION +.P +.PP Tool1 is a really great Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. +.P +.B tool1 noOptionsCommand +builds a native executable from specified source files +.P +.B tool1 noArgumentListFullOptions +builds a native executable from specified source files +.P +.B tool1 fullcommand1 +builds a native executable from specified source files +.P +.SH OPTIONS +.P +.TP +.B "-t" ", " "--target" " " "TARGET" +Specifies target binary output type. EXE or DLL +.P +.TP +.B "--noshortparam" +Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra +.P +.TP +.B "-l" +Specifies noparam nolong congue elementum. Morbi in ipsum sit amet pede facilisis laoreet +.P +.TP +.B "-p" ", " "--noparam" +Specifies noparam metus vitae pharetra auctor, sem +.P +.TP +.B "-n" " " "NOLONG" +Specifies nolong Nunc feugiat mi a tellus consequat +.P +.TP +.B "--noshort" " " "NOSHORT" +Specifies noshortNam nec ante. Sed lacinia, urna non tincidunt +.P +.TP +.B "-a" ", " "--another" " " "ANOTHER" +Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra +.P +.TP +.B "-t" ", " "--target" " " "TARGET" +Specifies target binary output type. EXE or DLL +.P +.TP +.B "--noshortparam" +Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra +.P +.TP +.B "-l" +Specifies noparam nolong congue elementum. Morbi in ipsum sit amet pede facilisis laoreet +.P +.TP +.B "-p" ", " "--noparam" +Specifies noparam metus vitae pharetra auctor, sem +.P +.TP +.B "-n" " " "NOLONG" +Specifies nolong Nunc feugiat mi a tellus consequat +.P +.TP +.B "--noshort" " " "NOSHORT" +Specifies noshortNam nec ante. Sed lacinia, urna non tincidunt +.P +.TP +.B "-a" ", " "--another" " " "ANOTHER" +Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra +.P +.SH AUTHOR +.P +.B "Test Author" " " +.RI ( "testing@testing.com" ) +.P +.SH COPYRIGHT +.P +.B "This is the copyright of tool1." diff --git a/package_tool/test/test_assets/test_package_layout/package_root/path_relative_to_package_root/test_exe.sh b/package_tool/test/test_assets/test_package_layout/package_root/path_relative_to_package_root/test_exe.sh new file mode 100644 index 000000000..3c448d928 --- /dev/null +++ b/package_tool/test/test_assets/test_package_layout/package_root/path_relative_to_package_root/test_exe.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Resolve symlinks until we have the parent dir of the actual file +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + +# This is how tools should be called +exec bash $DIR/test_called.sh diff --git a/package_tool/test/test_assets/test_package_layout/package_root/test_called.sh b/package_tool/test/test_assets/test_package_layout/package_root/test_called.sh new file mode 100644 index 000000000..999e63c7c --- /dev/null +++ b/package_tool/test/test_assets/test_package_layout/package_root/test_called.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "script called" diff --git a/package_tool/test/test_assets/test_package_layout/samples/testsample.cs b/package_tool/test/test_assets/test_package_layout/samples/testsample.cs new file mode 100644 index 000000000..5d5981bb6 --- /dev/null +++ b/package_tool/test/test_assets/test_package_layout/samples/testsample.cs @@ -0,0 +1,9 @@ +using System; + +public class Program { + + public static void Main(){ + System.Console.WriteLine("Hello World"); + } + +} \ No newline at end of file diff --git a/package_tool/test/test_assets/testdocs.json b/package_tool/test/test_assets/testdocs.json new file mode 100644 index 000000000..2f999d342 --- /dev/null +++ b/package_tool/test/test_assets/testdocs.json @@ -0,0 +1,108 @@ +{ + "tools": { + "tool1": { + "copyright": "This is the copyright of tool1.", + "license" : "This is the license of tool1", + "author":"Test Author", + "author_email":"testing@testing.com", + "short_description":"A tool to Vestibulum lacinia arcu eget nulla.", + "long_description":"Tool1 is a really great Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. ", + "commands": { + "fullcommand1":{ + "description":"builds a native executable from specified source files", + "options" : { + "target": { + "short": "-t", + "long":"--target", + "description":"Specifies target binary output type. EXE or DLL", + "parameter":"TARGET" + }, + "target2": { + "short": "-a", + "long":"--another", + "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra", + "parameter":"ANOTHER" + }, + "noshort": { + "long":"--noshort", + "description":"Specifies noshortNam nec ante. Sed lacinia, urna non tincidunt", + "parameter":"NOSHORT" + }, + "nolong": { + "short": "-n", + "description":"Specifies nolong Nunc feugiat mi a tellus consequat ", + "parameter":"NOLONG" + }, + "noparam": { + "short": "-p", + "long":"--noparam", + "description":"Specifies noparam metus vitae pharetra auctor, sem" + }, + "noParamNoShort": { + "long":"--noshortparam", + "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra" + }, + "noParamNoLong": { + "short": "-l", + "description":"Specifies noparam nolong congue elementum. Morbi in ipsum sit amet pede facilisis laoreet" + } + }, + "argumentlist" : { + "name":"argument list stuff", + "description":"ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;" + } + + }, + "noOptionsCommand":{ + "description":"builds a native executable from specified source files", + "argumentlist" : { + "name":"argument list stuff", + "description":"ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;" + } + + }, + "noArgumentListFullOptions":{ + "description":"builds a native executable from specified source files", + "options" : { + "target": { + "short": "-t", + "long":"--target", + "description":"Specifies target binary output type. EXE or DLL", + "parameter":"TARGET" + }, + "target2": { + "short": "-a", + "long":"--another", + "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra", + "parameter":"ANOTHER" + }, + "noshort": { + "long":"--noshort", + "description":"Specifies noshortNam nec ante. Sed lacinia, urna non tincidunt", + "parameter":"NOSHORT" + }, + "nolong": { + "short": "-n", + "description":"Specifies nolong Nunc feugiat mi a tellus consequat ", + "parameter":"NOLONG" + }, + "noparam": { + "short": "-p", + "long":"--noparam", + "description":"Specifies noparam metus vitae pharetra auctor, sem" + }, + "noParamNoShort": { + "long":"--noshortparam", + "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra" + }, + "noParamNoLong": { + "short": "-l", + "description":"Specifies noparam nolong congue elementum. Morbi in ipsum sit amet pede facilisis laoreet" + } + } + } + } + + } + } +} diff --git a/package_tool/test/unit_tests/test_debian_build_lib.bats b/package_tool/test/unit_tests/test_debian_build_lib.bats new file mode 100644 index 000000000..97029575a --- /dev/null +++ b/package_tool/test/unit_tests/test_debian_build_lib.bats @@ -0,0 +1,275 @@ +#!/usr/bin/env bats +# +# Tests for debian_build_lib.sh + +setup(){ + DIR="$BATS_TEST_DIRNAME" + PACKAGIFY_DIR="$(readlink -f $DIR/../../)" + + PACKAGE_DIR="$BATS_TMPDIR/test-package" + PACKAGE_SOURCE_DIR="$BATS_TMPDIR/test-source-package" + INSTALL_ROOT="test-install-root" + + # # Create Mock Package Directory + mkdir -p $PACKAGE_SOURCE_DIR/debian + mkdir $PACKAGE_DIR + + source $PACKAGIFY_DIR/scripts/debian_build_lib.sh + +} + +teardown(){ + # Remove Mock Package Directory + rm -r $PACKAGE_DIR + rm -r $PACKAGE_SOURCE_DIR +} + +@test "add_system_file_placement populates placement array" { + + add_system_file_placement "testfile0" "testdir0" + add_system_file_placement "testfile1" "testdir1" + + [ $placement_index -eq "2" ] + [ "${install_placement[0]}" = "testfile0 testdir0" ] + [ "${install_placement[1]}" = "testfile1 testdir1" ] +} + +@test "add_system_dir_placement adds files in dir to placement array" { + test_package_rel_dir="test-dir" + abs_test_path="/abs/test/path" + + mkdir $PACKAGE_SOURCE_DIR/$test_package_rel_dir + echo "file0 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/file0 + echo "file1 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/file1 + echo "file2 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/file2 + + add_system_dir_placement $test_package_rel_dir $abs_test_path + + rm -r $PACKAGE_SOURCE_DIR/$test_package_rel_dir + + [ "$placement_index" -eq 3 ] + [ "${install_placement[0]}" = "$test_package_rel_dir/file0 $abs_test_path" ] + [ "${install_placement[1]}" = "$test_package_rel_dir/file1 $abs_test_path" ] + [ "${install_placement[2]}" = "$test_package_rel_dir/file2 $abs_test_path" ] +} + +@test "add_system_dir_placement adds all files in subdir to placement array" { + test_package_rel_dir="test-dir" + test_package_rel_subdir="test-subdir" + abs_test_path="/abs/test/path" + + mkdir -p $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir + echo "file0 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir/file0 + echo "file1 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir/file1 + echo "file2 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir/file2 + + add_system_dir_placement $test_package_rel_dir $abs_test_path + + rm -r $PACKAGE_SOURCE_DIR/$test_package_rel_dir + + [ "$placement_index" -eq "3" ] + [ "${install_placement[0]}" = "$test_package_rel_dir/$test_package_rel_subdir/file0 $abs_test_path/$test_package_rel_subdir" ] + [ "${install_placement[1]}" = "$test_package_rel_dir/$test_package_rel_subdir/file1 $abs_test_path/$test_package_rel_subdir" ] + [ "${install_placement[2]}" = "$test_package_rel_dir/$test_package_rel_subdir/file2 $abs_test_path/$test_package_rel_subdir" ] +} + +@test "add_system_dir_placement adds all files in subdir and dir to placement array" { + test_package_rel_dir="test-dir" + test_package_rel_subdir="test-subdir" + abs_test_path="/abs/test/path" + + mkdir -p $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir + echo "file0 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/file0 + echo "file1 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/file1 + echo "file2 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/file2 + echo "file3 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir/file3 + echo "file4 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir/file4 + echo "file5 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir/file5 + + add_system_dir_placement $test_package_rel_dir $abs_test_path + + rm -r $PACKAGE_SOURCE_DIR/$test_package_rel_dir + + [ "$placement_index" -eq "6" ] + [ "${install_placement[0]}" = "$test_package_rel_dir/file0 $abs_test_path" ] + [ "${install_placement[1]}" = "$test_package_rel_dir/file1 $abs_test_path" ] + [ "${install_placement[2]}" = "$test_package_rel_dir/file2 $abs_test_path" ] + [ "${install_placement[3]}" = "$test_package_rel_dir/$test_package_rel_subdir/file3 $abs_test_path/$test_package_rel_subdir" ] + [ "${install_placement[4]}" = "$test_package_rel_dir/$test_package_rel_subdir/file4 $abs_test_path/$test_package_rel_subdir" ] + [ "${install_placement[5]}" = "$test_package_rel_dir/$test_package_rel_subdir/file5 $abs_test_path/$test_package_rel_subdir" ] +} + +@test "write_debian_install_file writes to debian/install" { + add_system_file_placement "somefile" "/some/abs/path" + write_debian_install_file + + [ -f "$PACKAGE_SOURCE_DIR/debian/install" ] + [ "$(cat $PACKAGE_SOURCE_DIR/debian/install)" = "somefile /some/abs/path" ] +} + +@test "add_file_to_install adds file to package_dest_dir" { + local_test_dir="$BATS_TMPDIR/local-dir" + local_subdir="the/path/should/not/matter" + package_test_dir="package-dir" + + mkdir $PACKAGE_SOURCE_DIR/$package_test_dir + mkdir -p $local_test_dir/$local_subdir + echo "file0 contents" > $local_test_dir/$local_subdir/file0 + echo "file1 contents" > $local_test_dir/$local_subdir/file1 + echo "file2 contents" > $local_test_dir/$local_subdir/file2 + + add_file_to_install "$local_test_dir/$local_subdir/file0" "$package_test_dir" + add_file_to_install "$local_test_dir/$local_subdir/file1" "$package_test_dir" + add_file_to_install "$local_test_dir/$local_subdir/file2" "$package_test_dir" + + rm -r $local_test_dir + + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file0" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file1" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file2" ] +} + +@test "add_file_to_install added files written to install file after write_debian_install_file" { + local_test_dir="$BATS_TMPDIR/local-dir" + local_subdir="the/path/should/not/matter" + package_test_dir="package-dir" + + mkdir $PACKAGE_SOURCE_DIR/$package_test_dir + mkdir -p $local_test_dir/$local_subdir + echo "file0 contents" > $local_test_dir/$local_subdir/file0 + + add_file_to_install "$local_test_dir/$local_subdir/file0" "$package_test_dir" + + rm -r $local_test_dir + + [ ! -e $PACKAGE_SOURCE_DIR/debian/install ] + write_debian_install_file + [ -f $PACKAGE_SOURCE_DIR/debian/install ] + [ "$(cat $PACKAGE_SOURCE_DIR/debian/install)" = "$package_test_dir/file0 $INSTALL_ROOT/$package_test_dir" ] +} + +@test "add_dir_to_install adds files in dir to package_dest_dir" { + local_test_dir="$BATS_TMPDIR/local-dir" + package_test_dir="package-dir" + + mkdir $PACKAGE_SOURCE_DIR/$package_test_dir + mkdir $local_test_dir + echo "file0 contents" > $local_test_dir/file0 + echo "file1 contents" > $local_test_dir/file1 + echo "file2 contents" > $local_test_dir/file2 + + add_dir_to_install "$local_test_dir" "$package_test_dir" + + rm -r $local_test_dir + + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file0" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file1" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file2" ] +} + +@test "add_dir_to_install adds files in subdirectory tree to package_dest_dir" { + local_test_dir="$BATS_TMPDIR/local-dir" + local_test_subdir="local-subdir" + + package_test_dir="package-dir" + + mkdir $PACKAGE_SOURCE_DIR/$package_test_dir + mkdir -p $local_test_dir/$local_test_subdir + echo "file0 contents" > $local_test_dir/$local_test_subdir/file0 + echo "file1 contents" > $local_test_dir/$local_test_subdir/file1 + echo "file2 contents" > $local_test_dir/$local_test_subdir/file2 + + add_dir_to_install "$local_test_dir" "$package_test_dir" + + rm -r $local_test_dir + + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/$local_test_subdir/file0" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/$local_test_subdir/file1" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/$local_test_subdir/file2" ] +} + +@test "add_dir_to_install adds files in directory and subdirectory tree to package_dest_dir" { + local_test_dir="$BATS_TMPDIR/local-dir" + local_test_subdir="local-subdir" + + package_test_dir="package-dir" + + mkdir $PACKAGE_SOURCE_DIR/$package_test_dir + mkdir -p $local_test_dir/$local_test_subdir + + echo "file0 contents" > $local_test_dir/file0 + echo "file1 contents" > $local_test_dir/file1 + echo "file2 contents" > $local_test_dir/file2 + echo "file3 contents" > $local_test_dir/$local_test_subdir/file3 + echo "file4 contents" > $local_test_dir/$local_test_subdir/file4 + echo "file5 contents" > $local_test_dir/$local_test_subdir/file5 + + add_dir_to_install "$local_test_dir" "$package_test_dir" + + rm -r $local_test_dir + + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file0" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file1" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file2" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/$local_test_subdir/file3" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/$local_test_subdir/file4" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/$local_test_subdir/file5" ] +} + +@test "add_dir_to_install added files written to install file after write_debian_install_file" { + local_test_dir="$BATS_TMPDIR/local-dir" + package_test_dir="package-dir" + + mkdir $PACKAGE_SOURCE_DIR/$package_test_dir + mkdir -p $local_test_dir + + echo "file0 contents" > $local_test_dir/file0 + + add_dir_to_install "$local_test_dir" "$package_test_dir" + + rm -r $local_test_dir + + [ ! -e $PACKAGE_SOURCE_DIR/debian/install ] + write_debian_install_file + [ -f $PACKAGE_SOURCE_DIR/debian/install ] + [ "$(cat $PACKAGE_SOURCE_DIR/debian/install)" = "$package_test_dir/file0 $INSTALL_ROOT/$package_test_dir" ] +} + +@test "add_dir_to_install with empty dest dir outputs to PACKAGE_SOURCE_DIR" { + local_test_dir="$BATS_TMPDIR/local-dir" + mkdir -p $local_test_dir + + echo "file0 contents" > $local_test_dir/file0 + + add_dir_to_install "$local_test_dir" "" + + rm -r $local_test_dir + + [ -f "$PACKAGE_SOURCE_DIR/file0" ] +} + + +@test "add_dir_to_install with empty dest dir adds files in directory and subdirectory tree to $PACKAGE_SOURCE_DIR" { + local_test_dir="$BATS_TMPDIR/local-dir" + local_test_subdir="local-subdir" + + mkdir -p $local_test_dir/$local_test_subdir + + echo "file0 contents" > $local_test_dir/file0 + echo "file1 contents" > $local_test_dir/file1 + echo "file2 contents" > $local_test_dir/file2 + echo "file3 contents" > $local_test_dir/$local_test_subdir/file3 + echo "file4 contents" > $local_test_dir/$local_test_subdir/file4 + echo "file5 contents" > $local_test_dir/$local_test_subdir/file5 + + add_dir_to_install "$local_test_dir" "" + + rm -r $local_test_dir + + [ -f "$PACKAGE_SOURCE_DIR/file0" ] + [ -f "$PACKAGE_SOURCE_DIR/file1" ] + [ -f "$PACKAGE_SOURCE_DIR/file2" ] + [ -f "$PACKAGE_SOURCE_DIR/$local_test_subdir/file3" ] + [ -f "$PACKAGE_SOURCE_DIR/$local_test_subdir/file4" ] + [ -f "$PACKAGE_SOURCE_DIR/$local_test_subdir/file5" ] +} diff --git a/package_tool/test/unit_tests/test_scripts.bats b/package_tool/test/unit_tests/test_scripts.bats new file mode 100644 index 000000000..fc492a013 --- /dev/null +++ b/package_tool/test/unit_tests/test_scripts.bats @@ -0,0 +1,24 @@ +#!/usr/bin/env bats +# +# Tests for debian_build_lib.sh + +setup(){ + DIR="$BATS_TEST_DIRNAME" + PACKAGIFY_DIR="$(readlink -f $DIR/../../)" +} + +@test "manpage generation is identical to lkg file" { + # Output is file "tool1.1" + # LKG file is "lkgtestman.1" + python $PACKAGIFY_DIR/scripts/manpage_generator.py $PACKAGIFY_DIR/test/test_assets/testdocs.json $PACKAGIFY_DIR/test/test_assets + + # Test Output existence + [ -f $PACKAGIFY_DIR/test/test_assets/tool1.1 ] + + # Test Output matches LKG + # If this is failing double check line ending style + [ -z "$(diff "$PACKAGIFY_DIR/test/test_assets/tool1.1" "$PACKAGIFY_DIR/test/test_assets/lkgtestman.1")" ] + + # Cleanup + rm $PACKAGIFY_DIR/test/test_assets/tool1.1 +} \ No newline at end of file From 1bcfb6c287578802482523b830c8eb5e40f1ff65 Mon Sep 17 00:00:00 2001 From: Bryan Date: Thu, 15 Oct 2015 16:23:44 -0700 Subject: [PATCH 02/11] rename tool --- package_tool/{packagify => package_tool} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename package_tool/{packagify => package_tool} (100%) diff --git a/package_tool/packagify b/package_tool/package_tool similarity index 100% rename from package_tool/packagify rename to package_tool/package_tool From 4fa2348a3829dedca084069c6df1e1e8aa999beb Mon Sep 17 00:00:00 2001 From: Bryan Date: Thu, 15 Oct 2015 16:38:34 -0700 Subject: [PATCH 03/11] fix gitignore of test package layout --- .gitignore | 3 ++- .../test_assets/test_package_layout/$/usr/bin/test_exe2.sh | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 package_tool/test/test_assets/test_package_layout/$/usr/bin/test_exe2.sh diff --git a/.gitignore b/.gitignore index f08574c3d..1c1d88213 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ [Oo]bj/ -[Bb]in/ +# Top level bin ignore only, so package_tool test_assets are added correctly +/[Bb]in/ .nuget/ _ReSharper.*/ packages/ diff --git a/package_tool/test/test_assets/test_package_layout/$/usr/bin/test_exe2.sh b/package_tool/test/test_assets/test_package_layout/$/usr/bin/test_exe2.sh new file mode 100644 index 000000000..fcc1f2ff4 --- /dev/null +++ b/package_tool/test/test_assets/test_package_layout/$/usr/bin/test_exe2.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# Example of something you shouldn't do, but is good for a testing scenario +exec bash /usr/share/Packagify_Test/test_called.sh \ No newline at end of file From 2cf04d37ce9b7cc397f0c4a8239ef1fd15780d88 Mon Sep 17 00:00:00 2001 From: Bryan Thornbury Date: Thu, 15 Oct 2015 16:57:43 -0700 Subject: [PATCH 04/11] adjust file permissions --- package_tool/package_tool | 3 ++- package_tool/setup/test_setup.sh | 0 package_tool/test.sh | 0 3 files changed, 2 insertions(+), 1 deletion(-) mode change 100644 => 100755 package_tool/package_tool mode change 100644 => 100755 package_tool/setup/test_setup.sh mode change 100644 => 100755 package_tool/test.sh diff --git a/package_tool/package_tool b/package_tool/package_tool old mode 100644 new mode 100755 index b43975d23..ddfe2ab4c --- a/package_tool/package_tool +++ b/package_tool/package_tool @@ -88,6 +88,7 @@ package_all(){ package_package_root_placement package_absolute_placement package_samples + package_docs } generate_all(){ @@ -170,7 +171,7 @@ generate_manpage_manifest(){ # Get path relative to $PACKAGE_SOURCE_DIR to prepend to each filename # This syntax is bash substring removal - docs_rel_path=${DOCS_DIR#${PACKAGE_SOURCE_DIR}} + docs_rel_path=${DOCS_DIR#${PACKAGE_SOURCE_DIR}/} # Remove any existing manifest rm -f ${DEBIAN_DIR}/${PACKAGE_NAME}.manpages diff --git a/package_tool/setup/test_setup.sh b/package_tool/setup/test_setup.sh old mode 100644 new mode 100755 diff --git a/package_tool/test.sh b/package_tool/test.sh old mode 100644 new mode 100755 From 9b4cc953123f26cecf65f138aeff72e20a2f79e9 Mon Sep 17 00:00:00 2001 From: Bryan Date: Thu, 15 Oct 2015 17:03:55 -0700 Subject: [PATCH 05/11] tweak symlink generation so leading slashes are omitted --- package_tool/README.md | 2 +- package_tool/example_config.json | 2 +- package_tool/scripts/config_template_generator.py | 3 +-- package_tool/scripts/manpage_generator.py | 1 - .../test/test_assets/test_package_layout/debian_config.json | 2 +- 5 files changed, 4 insertions(+), 6 deletions(-) diff --git a/package_tool/README.md b/package_tool/README.md index d42668652..c94686bb9 100644 --- a/package_tool/README.md +++ b/package_tool/README.md @@ -59,6 +59,6 @@ Note: remove all comments before using this }, "symlinks": { // (optional no defaults) - "path_relative_to_package_root/test_exe.sh" : "/usr/bin/test_exe.sh" + "path_relative_to_package_root/test_exe.sh" : "usr/bin/test_exe.sh" } } \ No newline at end of file diff --git a/package_tool/example_config.json b/package_tool/example_config.json index acffec7ac..2c048ba9d 100644 --- a/package_tool/example_config.json +++ b/package_tool/example_config.json @@ -34,6 +34,6 @@ }, "symlinks": { // (optional no defaults) - "path_relative_to_package_root/test_exe.sh" : "/usr/bin/test_exe.sh" + "path_relative_to_package_root/test_exe.sh" : "usr/bin/test_exe.sh" } } \ No newline at end of file diff --git a/package_tool/scripts/config_template_generator.py b/package_tool/scripts/config_template_generator.py index fb7a8fead..85c329742 100644 --- a/package_tool/scripts/config_template_generator.py +++ b/package_tool/scripts/config_template_generator.py @@ -14,7 +14,7 @@ FILE_CONTROL = 'control' FILE_COPYRIGHT = 'copyright' FILE_SYMLINK_FORMAT = '{package_name}.links' -PACKAGE_ROOT_FORMAT = "/usr/share/{package_name}" +PACKAGE_ROOT_FORMAT = "usr/share/{package_name}" CHANGELOG_DATE_FORMAT = "%a, %d %b %Y %H:%M:%S %z" # UTC Timezone for Changelog date @@ -206,7 +206,6 @@ def parse_and_validate_args(): help_and_exit("Error: Invalid template directory path") if not os.path.isdir(output_dir): - print output_dir #TODO debug help_and_exit("Error: Invalid output directory path") return (config_path, template_dir, output_dir) diff --git a/package_tool/scripts/manpage_generator.py b/package_tool/scripts/manpage_generator.py index b2ead05f4..5ad77de6a 100644 --- a/package_tool/scripts/manpage_generator.py +++ b/package_tool/scripts/manpage_generator.py @@ -105,7 +105,6 @@ def generate_synopsis_section(tool_name, tool_data):# roff_text_builder = [] roff_text_builder.append(".SH SYNOPSIS") - #TODO: append ellipsis conditionally if argument_list_name is added synopsis_format = '.B {program_name} {command_name} \n.RI {options} " "\n.I "{argument_list_name}"' tool_commands = tool_data.get("commands", []) diff --git a/package_tool/test/test_assets/test_package_layout/debian_config.json b/package_tool/test/test_assets/test_package_layout/debian_config.json index 23a6eb139..db873c716 100644 --- a/package_tool/test/test_assets/test_package_layout/debian_config.json +++ b/package_tool/test/test_assets/test_package_layout/debian_config.json @@ -35,6 +35,6 @@ }, "symlinks": { - "path_relative_to_package_root/test_exe.sh" : "/usr/bin/test_exe.sh" + "path_relative_to_package_root/test_exe.sh" : "usr/bin/test_exe.sh" } } \ No newline at end of file From c1f036c2e8c30c816678de83e6bcaf4fe2acbe23 Mon Sep 17 00:00:00 2001 From: Bryan Date: Thu, 15 Oct 2015 17:27:58 -0700 Subject: [PATCH 06/11] fix install root not set --- package_tool/package_tool | 1 + 1 file changed, 1 insertion(+) diff --git a/package_tool/package_tool b/package_tool/package_tool index ddfe2ab4c..7689adfea 100755 --- a/package_tool/package_tool +++ b/package_tool/package_tool @@ -73,6 +73,7 @@ parse_config_and_set_env_vars(){ PACKAGE_VERSION=$($extract_base_cmd $CONFIG "release.package_version") PACKAGE_SOURCE_DIR="${OUTPUT_DIR}/${PACKAGE_NAME}-${PACKAGE_VERSION}" + INSTALL_ROOT="/usr/share/${PACKAGE_NAME}" DEBIAN_DIR="${PACKAGE_SOURCE_DIR}/debian" DOCS_DIR="${PACKAGE_SOURCE_DIR}/docs" From efd3abb51edca81d4acdced28cdff2d9f907a1c4 Mon Sep 17 00:00:00 2001 From: Bryan Date: Thu, 15 Oct 2015 17:34:15 -0700 Subject: [PATCH 07/11] fix test executables --- .../test/test_assets/test_package_layout/$/usr/bin/test_exe2.sh | 2 +- .../package_root/path_relative_to_package_root/test_exe.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package_tool/test/test_assets/test_package_layout/$/usr/bin/test_exe2.sh b/package_tool/test/test_assets/test_package_layout/$/usr/bin/test_exe2.sh index fcc1f2ff4..647c8f389 100644 --- a/package_tool/test/test_assets/test_package_layout/$/usr/bin/test_exe2.sh +++ b/package_tool/test/test_assets/test_package_layout/$/usr/bin/test_exe2.sh @@ -1,4 +1,4 @@ #!/bin/bash # Example of something you shouldn't do, but is good for a testing scenario -exec bash /usr/share/Packagify_Test/test_called.sh \ No newline at end of file +exec bash /usr/share/packagetooltest/test_called.sh \ No newline at end of file diff --git a/package_tool/test/test_assets/test_package_layout/package_root/path_relative_to_package_root/test_exe.sh b/package_tool/test/test_assets/test_package_layout/package_root/path_relative_to_package_root/test_exe.sh index 3c448d928..e5444633b 100644 --- a/package_tool/test/test_assets/test_package_layout/package_root/path_relative_to_package_root/test_exe.sh +++ b/package_tool/test/test_assets/test_package_layout/package_root/path_relative_to_package_root/test_exe.sh @@ -10,4 +10,4 @@ done DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" # This is how tools should be called -exec bash $DIR/test_called.sh +exec bash $DIR/../test_called.sh From b8111ba345eff7a5361dc46f3c63900387b19972 Mon Sep 17 00:00:00 2001 From: Bryan Thornbury Date: Thu, 15 Oct 2015 17:41:50 -0700 Subject: [PATCH 08/11] test.sh needs sudo --- package_tool/test.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/package_tool/test.sh b/package_tool/test.sh index 5af650644..48a3d768c 100755 --- a/package_tool/test.sh +++ b/package_tool/test.sh @@ -1,9 +1,11 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -run_setup(){ - bash $DIR/setup/test_setup.sh -} +current_user=$(whoami) +if [ $current_user != "root" ]; then + echo "test.sh requires superuser privileges to run" + exit 1 +fi run_unit_tests(){ bats $DIR/test/unit_tests/test_debian_build_lib.bats @@ -18,7 +20,7 @@ run_integration_tests(){ mkdir -p $output_dir # Build the actual package - sudo $DIR/package_tool $input_dir $output_dir + $DIR/package_tool $input_dir $output_dir # Integration Test Entrypoint placed by package_tool bats $output_dir/test_package.bats @@ -28,7 +30,6 @@ run_integration_tests(){ } run_all(){ - #run_setup run_unit_tests run_integration_tests } From c38ccd805485601edda7fe8bb54035fe20907f2d Mon Sep 17 00:00:00 2001 From: Bryan Date: Thu, 15 Oct 2015 17:52:51 -0700 Subject: [PATCH 09/11] fix commented out try catch in config_template_generator --- .../scripts/config_template_generator.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/package_tool/scripts/config_template_generator.py b/package_tool/scripts/config_template_generator.py index 85c329742..1ce61d734 100644 --- a/package_tool/scripts/config_template_generator.py +++ b/package_tool/scripts/config_template_generator.py @@ -30,14 +30,14 @@ class UTC(datetime.tzinfo): # Generation Functions def generate_and_write_all(config_data, template_dir, output_dir): - # try: - changelog_contents = generate_changelog(config_data, template_dir) - control_contents = generate_control(config_data, template_dir) - copyright_contents = generate_copyright(config_data, template_dir) - symlink_contents = generate_symlinks(config_data) - # except Exception as exc: - # print exc - # help_and_exit("Error: Generation Failed, check your config file.") + try: + changelog_contents = generate_changelog(config_data, template_dir) + control_contents = generate_control(config_data, template_dir) + copyright_contents = generate_copyright(config_data, template_dir) + symlink_contents = generate_symlinks(config_data) + except Exception as exc: + print exc + help_and_exit("Error: Generation Failed, check your config file.") write_file(changelog_contents, output_dir, FILE_CHANGELOG) write_file(control_contents, output_dir, FILE_CONTROL) From 7b8b4b10e0825d072801ab5a204147b6345311f2 Mon Sep 17 00:00:00 2001 From: Bryan Date: Fri, 16 Oct 2015 12:13:52 -0700 Subject: [PATCH 10/11] Code review feedback, normalize whitespace to spaces --- .gitignore | 1 - package_tool/example_config.json | 46 +-- package_tool/test.sh | 32 +- .../test_assets/test_package_layout/docs.json | 212 +++++------ .../test_package_layout/samples/testsample.cs | 6 +- package_tool/test/test_assets/testdocs.json | 212 +++++------ .../unit_tests/test_debian_build_lib.bats | 342 +++++++++--------- .../test/unit_tests/test_scripts.bats | 26 +- 8 files changed, 438 insertions(+), 439 deletions(-) diff --git a/.gitignore b/.gitignore index 1c1d88213..8830360c7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ [Oo]bj/ # Top level bin ignore only, so package_tool test_assets are added correctly -/[Bb]in/ .nuget/ _ReSharper.*/ packages/ diff --git a/package_tool/example_config.json b/package_tool/example_config.json index 2c048ba9d..74e8012dc 100644 --- a/package_tool/example_config.json +++ b/package_tool/example_config.json @@ -1,39 +1,39 @@ { - "maintainer_name":"Microsoft", // [required] - "maintainer_email": "optimus@service.microsoft.com", // [required] + "maintainer_name":"Microsoft", + "maintainer_email": "optimus@service.microsoft.com", - "package_name": "Packagify_Test", // [required] + "package_name": "Packagify_Test", - "short_description": "This is a test package", // [required] Max. 60 chars - "long_description": "This is a longer description of the test package", // [required] - "homepage": "http://testpackage.com", // (optional no default) + "short_description": "This is a test package", + "long_description": "This is a longer description of the test package", + "homepage": "http://testpackage.com", "release":{ - "package_version":"0.1", // [required] - "package_revision":"1", // [required] - "urgency" : "low", // (optional default="low") https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Urgency - "changelog_message" : "some stuff here" // [required] + "package_version":"0.1", + "package_revision":"1", + "urgency" : "low", + "changelog_message" : "some stuff here" }, - "control": { // (optional) - "priority":"standard", // (optional default="standard") https://www.debian.org/doc/debian-policy/ch-archive.html#s-priorities - "section":"devel", // (optional default="misc") https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections - "architecture":"all" // (optional default="all" ) + "control": { + "priority":"standard", + "section":"devel", + "architecture":"all" }, - "copyright": "2015 Microsoft", // [required] - "license": { // [required] - "type": "some_license", // [required] - "full_text": "full license text here" // [required] + "copyright": "2015 Microsoft", + "license": { + "type": "some_license", + "full_text": "full license text here" }, - "debian_dependencies" : { // (optional no default) + "debian_dependencies" : { "package_name": { - "package_version" : "1.0.0" // (optional within package_name no default) + "package_version" : "1.0.0" } - }, + }, - "symlinks": { // (optional no defaults) - "path_relative_to_package_root/test_exe.sh" : "usr/bin/test_exe.sh" + "symlinks": { + "path_relative_to_package_root/test_exe.sh" : "usr/bin/test_exe.sh" } } \ No newline at end of file diff --git a/package_tool/test.sh b/package_tool/test.sh index 48a3d768c..ea76a6e62 100755 --- a/package_tool/test.sh +++ b/package_tool/test.sh @@ -3,35 +3,35 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" current_user=$(whoami) if [ $current_user != "root" ]; then - echo "test.sh requires superuser privileges to run" - exit 1 + echo "test.sh requires superuser privileges to run" + exit 1 fi run_unit_tests(){ - bats $DIR/test/unit_tests/test_debian_build_lib.bats - bats $DIR/test/unit_tests/test_scripts.bats + bats $DIR/test/unit_tests/test_debian_build_lib.bats + bats $DIR/test/unit_tests/test_scripts.bats } run_integration_tests(){ - input_dir=$DIR/test/test_assets/test_package_layout - output_dir=$DIR/p_out + input_dir=$DIR/test/test_assets/test_package_layout + output_dir=$DIR/p_out - # Create output dir - mkdir -p $output_dir + # Create output dir + mkdir -p $output_dir - # Build the actual package - $DIR/package_tool $input_dir $output_dir + # Build the actual package + $DIR/package_tool $input_dir $output_dir - # Integration Test Entrypoint placed by package_tool - bats $output_dir/test_package.bats + # Integration Test Entrypoint placed by package_tool + bats $output_dir/test_package.bats - # Cleanup output dir - rm -rf $DIR/test/test_assets/test_package_output + # Cleanup output dir + rm -rf $DIR/test/test_assets/test_package_output } run_all(){ - run_unit_tests - run_integration_tests + run_unit_tests + run_integration_tests } run_all diff --git a/package_tool/test/test_assets/test_package_layout/docs.json b/package_tool/test/test_assets/test_package_layout/docs.json index 2f999d342..e35fdb3bf 100644 --- a/package_tool/test/test_assets/test_package_layout/docs.json +++ b/package_tool/test/test_assets/test_package_layout/docs.json @@ -1,108 +1,108 @@ { - "tools": { - "tool1": { - "copyright": "This is the copyright of tool1.", - "license" : "This is the license of tool1", - "author":"Test Author", - "author_email":"testing@testing.com", - "short_description":"A tool to Vestibulum lacinia arcu eget nulla.", - "long_description":"Tool1 is a really great Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. ", - "commands": { - "fullcommand1":{ - "description":"builds a native executable from specified source files", - "options" : { - "target": { - "short": "-t", - "long":"--target", - "description":"Specifies target binary output type. EXE or DLL", - "parameter":"TARGET" - }, - "target2": { - "short": "-a", - "long":"--another", - "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra", - "parameter":"ANOTHER" - }, - "noshort": { - "long":"--noshort", - "description":"Specifies noshortNam nec ante. Sed lacinia, urna non tincidunt", - "parameter":"NOSHORT" - }, - "nolong": { - "short": "-n", - "description":"Specifies nolong Nunc feugiat mi a tellus consequat ", - "parameter":"NOLONG" - }, - "noparam": { - "short": "-p", - "long":"--noparam", - "description":"Specifies noparam metus vitae pharetra auctor, sem" - }, - "noParamNoShort": { - "long":"--noshortparam", - "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra" - }, - "noParamNoLong": { - "short": "-l", - "description":"Specifies noparam nolong congue elementum. Morbi in ipsum sit amet pede facilisis laoreet" - } - }, - "argumentlist" : { - "name":"argument list stuff", - "description":"ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;" - } - - }, - "noOptionsCommand":{ - "description":"builds a native executable from specified source files", - "argumentlist" : { - "name":"argument list stuff", - "description":"ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;" - } - - }, - "noArgumentListFullOptions":{ - "description":"builds a native executable from specified source files", - "options" : { - "target": { - "short": "-t", - "long":"--target", - "description":"Specifies target binary output type. EXE or DLL", - "parameter":"TARGET" - }, - "target2": { - "short": "-a", - "long":"--another", - "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra", - "parameter":"ANOTHER" - }, - "noshort": { - "long":"--noshort", - "description":"Specifies noshortNam nec ante. Sed lacinia, urna non tincidunt", - "parameter":"NOSHORT" - }, - "nolong": { - "short": "-n", - "description":"Specifies nolong Nunc feugiat mi a tellus consequat ", - "parameter":"NOLONG" - }, - "noparam": { - "short": "-p", - "long":"--noparam", - "description":"Specifies noparam metus vitae pharetra auctor, sem" - }, - "noParamNoShort": { - "long":"--noshortparam", - "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra" - }, - "noParamNoLong": { - "short": "-l", - "description":"Specifies noparam nolong congue elementum. Morbi in ipsum sit amet pede facilisis laoreet" - } - } - } - } - - } - } + "tools": { + "tool1": { + "copyright": "This is the copyright of tool1.", + "license" : "This is the license of tool1", + "author":"Test Author", + "author_email":"testing@testing.com", + "short_description":"A tool to Vestibulum lacinia arcu eget nulla.", + "long_description":"Tool1 is a really great Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. ", + "commands": { + "fullcommand1":{ + "description":"builds a native executable from specified source files", + "options" : { + "target": { + "short": "-t", + "long":"--target", + "description":"Specifies target binary output type. EXE or DLL", + "parameter":"TARGET" + }, + "target2": { + "short": "-a", + "long":"--another", + "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra", + "parameter":"ANOTHER" + }, + "noshort": { + "long":"--noshort", + "description":"Specifies noshortNam nec ante. Sed lacinia, urna non tincidunt", + "parameter":"NOSHORT" + }, + "nolong": { + "short": "-n", + "description":"Specifies nolong Nunc feugiat mi a tellus consequat ", + "parameter":"NOLONG" + }, + "noparam": { + "short": "-p", + "long":"--noparam", + "description":"Specifies noparam metus vitae pharetra auctor, sem" + }, + "noParamNoShort": { + "long":"--noshortparam", + "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra" + }, + "noParamNoLong": { + "short": "-l", + "description":"Specifies noparam nolong congue elementum. Morbi in ipsum sit amet pede facilisis laoreet" + } + }, + "argumentlist" : { + "name":"argument list stuff", + "description":"ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;" + } + + }, + "noOptionsCommand":{ + "description":"builds a native executable from specified source files", + "argumentlist" : { + "name":"argument list stuff", + "description":"ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;" + } + + }, + "noArgumentListFullOptions":{ + "description":"builds a native executable from specified source files", + "options" : { + "target": { + "short": "-t", + "long":"--target", + "description":"Specifies target binary output type. EXE or DLL", + "parameter":"TARGET" + }, + "target2": { + "short": "-a", + "long":"--another", + "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra", + "parameter":"ANOTHER" + }, + "noshort": { + "long":"--noshort", + "description":"Specifies noshortNam nec ante. Sed lacinia, urna non tincidunt", + "parameter":"NOSHORT" + }, + "nolong": { + "short": "-n", + "description":"Specifies nolong Nunc feugiat mi a tellus consequat ", + "parameter":"NOLONG" + }, + "noparam": { + "short": "-p", + "long":"--noparam", + "description":"Specifies noparam metus vitae pharetra auctor, sem" + }, + "noParamNoShort": { + "long":"--noshortparam", + "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra" + }, + "noParamNoLong": { + "short": "-l", + "description":"Specifies noparam nolong congue elementum. Morbi in ipsum sit amet pede facilisis laoreet" + } + } + } + } + + } + } } diff --git a/package_tool/test/test_assets/test_package_layout/samples/testsample.cs b/package_tool/test/test_assets/test_package_layout/samples/testsample.cs index 5d5981bb6..5d5ccc3ab 100644 --- a/package_tool/test/test_assets/test_package_layout/samples/testsample.cs +++ b/package_tool/test/test_assets/test_package_layout/samples/testsample.cs @@ -2,8 +2,8 @@ using System; public class Program { - public static void Main(){ - System.Console.WriteLine("Hello World"); - } + public static void Main(){ + System.Console.WriteLine("Hello World"); + } } \ No newline at end of file diff --git a/package_tool/test/test_assets/testdocs.json b/package_tool/test/test_assets/testdocs.json index 2f999d342..e35fdb3bf 100644 --- a/package_tool/test/test_assets/testdocs.json +++ b/package_tool/test/test_assets/testdocs.json @@ -1,108 +1,108 @@ { - "tools": { - "tool1": { - "copyright": "This is the copyright of tool1.", - "license" : "This is the license of tool1", - "author":"Test Author", - "author_email":"testing@testing.com", - "short_description":"A tool to Vestibulum lacinia arcu eget nulla.", - "long_description":"Tool1 is a really great Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. ", - "commands": { - "fullcommand1":{ - "description":"builds a native executable from specified source files", - "options" : { - "target": { - "short": "-t", - "long":"--target", - "description":"Specifies target binary output type. EXE or DLL", - "parameter":"TARGET" - }, - "target2": { - "short": "-a", - "long":"--another", - "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra", - "parameter":"ANOTHER" - }, - "noshort": { - "long":"--noshort", - "description":"Specifies noshortNam nec ante. Sed lacinia, urna non tincidunt", - "parameter":"NOSHORT" - }, - "nolong": { - "short": "-n", - "description":"Specifies nolong Nunc feugiat mi a tellus consequat ", - "parameter":"NOLONG" - }, - "noparam": { - "short": "-p", - "long":"--noparam", - "description":"Specifies noparam metus vitae pharetra auctor, sem" - }, - "noParamNoShort": { - "long":"--noshortparam", - "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra" - }, - "noParamNoLong": { - "short": "-l", - "description":"Specifies noparam nolong congue elementum. Morbi in ipsum sit amet pede facilisis laoreet" - } - }, - "argumentlist" : { - "name":"argument list stuff", - "description":"ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;" - } - - }, - "noOptionsCommand":{ - "description":"builds a native executable from specified source files", - "argumentlist" : { - "name":"argument list stuff", - "description":"ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;" - } - - }, - "noArgumentListFullOptions":{ - "description":"builds a native executable from specified source files", - "options" : { - "target": { - "short": "-t", - "long":"--target", - "description":"Specifies target binary output type. EXE or DLL", - "parameter":"TARGET" - }, - "target2": { - "short": "-a", - "long":"--another", - "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra", - "parameter":"ANOTHER" - }, - "noshort": { - "long":"--noshort", - "description":"Specifies noshortNam nec ante. Sed lacinia, urna non tincidunt", - "parameter":"NOSHORT" - }, - "nolong": { - "short": "-n", - "description":"Specifies nolong Nunc feugiat mi a tellus consequat ", - "parameter":"NOLONG" - }, - "noparam": { - "short": "-p", - "long":"--noparam", - "description":"Specifies noparam metus vitae pharetra auctor, sem" - }, - "noParamNoShort": { - "long":"--noshortparam", - "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra" - }, - "noParamNoLong": { - "short": "-l", - "description":"Specifies noparam nolong congue elementum. Morbi in ipsum sit amet pede facilisis laoreet" - } - } - } - } - - } - } + "tools": { + "tool1": { + "copyright": "This is the copyright of tool1.", + "license" : "This is the license of tool1", + "author":"Test Author", + "author_email":"testing@testing.com", + "short_description":"A tool to Vestibulum lacinia arcu eget nulla.", + "long_description":"Tool1 is a really great Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. ", + "commands": { + "fullcommand1":{ + "description":"builds a native executable from specified source files", + "options" : { + "target": { + "short": "-t", + "long":"--target", + "description":"Specifies target binary output type. EXE or DLL", + "parameter":"TARGET" + }, + "target2": { + "short": "-a", + "long":"--another", + "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra", + "parameter":"ANOTHER" + }, + "noshort": { + "long":"--noshort", + "description":"Specifies noshortNam nec ante. Sed lacinia, urna non tincidunt", + "parameter":"NOSHORT" + }, + "nolong": { + "short": "-n", + "description":"Specifies nolong Nunc feugiat mi a tellus consequat ", + "parameter":"NOLONG" + }, + "noparam": { + "short": "-p", + "long":"--noparam", + "description":"Specifies noparam metus vitae pharetra auctor, sem" + }, + "noParamNoShort": { + "long":"--noshortparam", + "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra" + }, + "noParamNoLong": { + "short": "-l", + "description":"Specifies noparam nolong congue elementum. Morbi in ipsum sit amet pede facilisis laoreet" + } + }, + "argumentlist" : { + "name":"argument list stuff", + "description":"ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;" + } + + }, + "noOptionsCommand":{ + "description":"builds a native executable from specified source files", + "argumentlist" : { + "name":"argument list stuff", + "description":"ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;" + } + + }, + "noArgumentListFullOptions":{ + "description":"builds a native executable from specified source files", + "options" : { + "target": { + "short": "-t", + "long":"--target", + "description":"Specifies target binary output type. EXE or DLL", + "parameter":"TARGET" + }, + "target2": { + "short": "-a", + "long":"--another", + "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra", + "parameter":"ANOTHER" + }, + "noshort": { + "long":"--noshort", + "description":"Specifies noshortNam nec ante. Sed lacinia, urna non tincidunt", + "parameter":"NOSHORT" + }, + "nolong": { + "short": "-n", + "description":"Specifies nolong Nunc feugiat mi a tellus consequat ", + "parameter":"NOLONG" + }, + "noparam": { + "short": "-p", + "long":"--noparam", + "description":"Specifies noparam metus vitae pharetra auctor, sem" + }, + "noParamNoShort": { + "long":"--noshortparam", + "description":"Specifies another aptent taciti sociosqu ad litora torquent per conubia nostra" + }, + "noParamNoLong": { + "short": "-l", + "description":"Specifies noparam nolong congue elementum. Morbi in ipsum sit amet pede facilisis laoreet" + } + } + } + } + + } + } } diff --git a/package_tool/test/unit_tests/test_debian_build_lib.bats b/package_tool/test/unit_tests/test_debian_build_lib.bats index 97029575a..a93445f87 100644 --- a/package_tool/test/unit_tests/test_debian_build_lib.bats +++ b/package_tool/test/unit_tests/test_debian_build_lib.bats @@ -3,273 +3,273 @@ # Tests for debian_build_lib.sh setup(){ - DIR="$BATS_TEST_DIRNAME" - PACKAGIFY_DIR="$(readlink -f $DIR/../../)" + DIR="$BATS_TEST_DIRNAME" + PACKAGIFY_DIR="$(readlink -f $DIR/../../)" - PACKAGE_DIR="$BATS_TMPDIR/test-package" - PACKAGE_SOURCE_DIR="$BATS_TMPDIR/test-source-package" - INSTALL_ROOT="test-install-root" + PACKAGE_DIR="$BATS_TMPDIR/test-package" + PACKAGE_SOURCE_DIR="$BATS_TMPDIR/test-source-package" + INSTALL_ROOT="test-install-root" - # # Create Mock Package Directory - mkdir -p $PACKAGE_SOURCE_DIR/debian - mkdir $PACKAGE_DIR + # # Create Mock Package Directory + mkdir -p $PACKAGE_SOURCE_DIR/debian + mkdir $PACKAGE_DIR - source $PACKAGIFY_DIR/scripts/debian_build_lib.sh + source $PACKAGIFY_DIR/scripts/debian_build_lib.sh } teardown(){ - # Remove Mock Package Directory - rm -r $PACKAGE_DIR - rm -r $PACKAGE_SOURCE_DIR + # Remove Mock Package Directory + rm -r $PACKAGE_DIR + rm -r $PACKAGE_SOURCE_DIR } @test "add_system_file_placement populates placement array" { - - add_system_file_placement "testfile0" "testdir0" - add_system_file_placement "testfile1" "testdir1" + + add_system_file_placement "testfile0" "testdir0" + add_system_file_placement "testfile1" "testdir1" - [ $placement_index -eq "2" ] - [ "${install_placement[0]}" = "testfile0 testdir0" ] - [ "${install_placement[1]}" = "testfile1 testdir1" ] + [ $placement_index -eq "2" ] + [ "${install_placement[0]}" = "testfile0 testdir0" ] + [ "${install_placement[1]}" = "testfile1 testdir1" ] } @test "add_system_dir_placement adds files in dir to placement array" { - test_package_rel_dir="test-dir" - abs_test_path="/abs/test/path" + test_package_rel_dir="test-dir" + abs_test_path="/abs/test/path" - mkdir $PACKAGE_SOURCE_DIR/$test_package_rel_dir - echo "file0 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/file0 - echo "file1 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/file1 - echo "file2 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/file2 + mkdir $PACKAGE_SOURCE_DIR/$test_package_rel_dir + echo "file0 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/file0 + echo "file1 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/file1 + echo "file2 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/file2 - add_system_dir_placement $test_package_rel_dir $abs_test_path + add_system_dir_placement $test_package_rel_dir $abs_test_path - rm -r $PACKAGE_SOURCE_DIR/$test_package_rel_dir + rm -r $PACKAGE_SOURCE_DIR/$test_package_rel_dir - [ "$placement_index" -eq 3 ] - [ "${install_placement[0]}" = "$test_package_rel_dir/file0 $abs_test_path" ] - [ "${install_placement[1]}" = "$test_package_rel_dir/file1 $abs_test_path" ] - [ "${install_placement[2]}" = "$test_package_rel_dir/file2 $abs_test_path" ] + [ "$placement_index" -eq 3 ] + [ "${install_placement[0]}" = "$test_package_rel_dir/file0 $abs_test_path" ] + [ "${install_placement[1]}" = "$test_package_rel_dir/file1 $abs_test_path" ] + [ "${install_placement[2]}" = "$test_package_rel_dir/file2 $abs_test_path" ] } @test "add_system_dir_placement adds all files in subdir to placement array" { - test_package_rel_dir="test-dir" - test_package_rel_subdir="test-subdir" - abs_test_path="/abs/test/path" + test_package_rel_dir="test-dir" + test_package_rel_subdir="test-subdir" + abs_test_path="/abs/test/path" - mkdir -p $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir - echo "file0 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir/file0 - echo "file1 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir/file1 - echo "file2 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir/file2 + mkdir -p $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir + echo "file0 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir/file0 + echo "file1 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir/file1 + echo "file2 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir/file2 - add_system_dir_placement $test_package_rel_dir $abs_test_path + add_system_dir_placement $test_package_rel_dir $abs_test_path - rm -r $PACKAGE_SOURCE_DIR/$test_package_rel_dir + rm -r $PACKAGE_SOURCE_DIR/$test_package_rel_dir - [ "$placement_index" -eq "3" ] - [ "${install_placement[0]}" = "$test_package_rel_dir/$test_package_rel_subdir/file0 $abs_test_path/$test_package_rel_subdir" ] - [ "${install_placement[1]}" = "$test_package_rel_dir/$test_package_rel_subdir/file1 $abs_test_path/$test_package_rel_subdir" ] - [ "${install_placement[2]}" = "$test_package_rel_dir/$test_package_rel_subdir/file2 $abs_test_path/$test_package_rel_subdir" ] + [ "$placement_index" -eq "3" ] + [ "${install_placement[0]}" = "$test_package_rel_dir/$test_package_rel_subdir/file0 $abs_test_path/$test_package_rel_subdir" ] + [ "${install_placement[1]}" = "$test_package_rel_dir/$test_package_rel_subdir/file1 $abs_test_path/$test_package_rel_subdir" ] + [ "${install_placement[2]}" = "$test_package_rel_dir/$test_package_rel_subdir/file2 $abs_test_path/$test_package_rel_subdir" ] } @test "add_system_dir_placement adds all files in subdir and dir to placement array" { - test_package_rel_dir="test-dir" - test_package_rel_subdir="test-subdir" - abs_test_path="/abs/test/path" + test_package_rel_dir="test-dir" + test_package_rel_subdir="test-subdir" + abs_test_path="/abs/test/path" - mkdir -p $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir - echo "file0 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/file0 - echo "file1 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/file1 - echo "file2 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/file2 - echo "file3 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir/file3 - echo "file4 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir/file4 - echo "file5 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir/file5 + mkdir -p $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir + echo "file0 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/file0 + echo "file1 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/file1 + echo "file2 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/file2 + echo "file3 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir/file3 + echo "file4 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir/file4 + echo "file5 contents" > $PACKAGE_SOURCE_DIR/$test_package_rel_dir/$test_package_rel_subdir/file5 - add_system_dir_placement $test_package_rel_dir $abs_test_path + add_system_dir_placement $test_package_rel_dir $abs_test_path - rm -r $PACKAGE_SOURCE_DIR/$test_package_rel_dir + rm -r $PACKAGE_SOURCE_DIR/$test_package_rel_dir - [ "$placement_index" -eq "6" ] - [ "${install_placement[0]}" = "$test_package_rel_dir/file0 $abs_test_path" ] - [ "${install_placement[1]}" = "$test_package_rel_dir/file1 $abs_test_path" ] - [ "${install_placement[2]}" = "$test_package_rel_dir/file2 $abs_test_path" ] - [ "${install_placement[3]}" = "$test_package_rel_dir/$test_package_rel_subdir/file3 $abs_test_path/$test_package_rel_subdir" ] - [ "${install_placement[4]}" = "$test_package_rel_dir/$test_package_rel_subdir/file4 $abs_test_path/$test_package_rel_subdir" ] - [ "${install_placement[5]}" = "$test_package_rel_dir/$test_package_rel_subdir/file5 $abs_test_path/$test_package_rel_subdir" ] + [ "$placement_index" -eq "6" ] + [ "${install_placement[0]}" = "$test_package_rel_dir/file0 $abs_test_path" ] + [ "${install_placement[1]}" = "$test_package_rel_dir/file1 $abs_test_path" ] + [ "${install_placement[2]}" = "$test_package_rel_dir/file2 $abs_test_path" ] + [ "${install_placement[3]}" = "$test_package_rel_dir/$test_package_rel_subdir/file3 $abs_test_path/$test_package_rel_subdir" ] + [ "${install_placement[4]}" = "$test_package_rel_dir/$test_package_rel_subdir/file4 $abs_test_path/$test_package_rel_subdir" ] + [ "${install_placement[5]}" = "$test_package_rel_dir/$test_package_rel_subdir/file5 $abs_test_path/$test_package_rel_subdir" ] } @test "write_debian_install_file writes to debian/install" { - add_system_file_placement "somefile" "/some/abs/path" - write_debian_install_file + add_system_file_placement "somefile" "/some/abs/path" + write_debian_install_file - [ -f "$PACKAGE_SOURCE_DIR/debian/install" ] - [ "$(cat $PACKAGE_SOURCE_DIR/debian/install)" = "somefile /some/abs/path" ] + [ -f "$PACKAGE_SOURCE_DIR/debian/install" ] + [ "$(cat $PACKAGE_SOURCE_DIR/debian/install)" = "somefile /some/abs/path" ] } @test "add_file_to_install adds file to package_dest_dir" { - local_test_dir="$BATS_TMPDIR/local-dir" - local_subdir="the/path/should/not/matter" - package_test_dir="package-dir" + local_test_dir="$BATS_TMPDIR/local-dir" + local_subdir="the/path/should/not/matter" + package_test_dir="package-dir" - mkdir $PACKAGE_SOURCE_DIR/$package_test_dir - mkdir -p $local_test_dir/$local_subdir - echo "file0 contents" > $local_test_dir/$local_subdir/file0 - echo "file1 contents" > $local_test_dir/$local_subdir/file1 - echo "file2 contents" > $local_test_dir/$local_subdir/file2 + mkdir $PACKAGE_SOURCE_DIR/$package_test_dir + mkdir -p $local_test_dir/$local_subdir + echo "file0 contents" > $local_test_dir/$local_subdir/file0 + echo "file1 contents" > $local_test_dir/$local_subdir/file1 + echo "file2 contents" > $local_test_dir/$local_subdir/file2 - add_file_to_install "$local_test_dir/$local_subdir/file0" "$package_test_dir" - add_file_to_install "$local_test_dir/$local_subdir/file1" "$package_test_dir" - add_file_to_install "$local_test_dir/$local_subdir/file2" "$package_test_dir" + add_file_to_install "$local_test_dir/$local_subdir/file0" "$package_test_dir" + add_file_to_install "$local_test_dir/$local_subdir/file1" "$package_test_dir" + add_file_to_install "$local_test_dir/$local_subdir/file2" "$package_test_dir" - rm -r $local_test_dir + rm -r $local_test_dir - [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file0" ] - [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file1" ] - [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file2" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file0" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file1" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file2" ] } @test "add_file_to_install added files written to install file after write_debian_install_file" { - local_test_dir="$BATS_TMPDIR/local-dir" - local_subdir="the/path/should/not/matter" - package_test_dir="package-dir" + local_test_dir="$BATS_TMPDIR/local-dir" + local_subdir="the/path/should/not/matter" + package_test_dir="package-dir" - mkdir $PACKAGE_SOURCE_DIR/$package_test_dir - mkdir -p $local_test_dir/$local_subdir - echo "file0 contents" > $local_test_dir/$local_subdir/file0 + mkdir $PACKAGE_SOURCE_DIR/$package_test_dir + mkdir -p $local_test_dir/$local_subdir + echo "file0 contents" > $local_test_dir/$local_subdir/file0 - add_file_to_install "$local_test_dir/$local_subdir/file0" "$package_test_dir" + add_file_to_install "$local_test_dir/$local_subdir/file0" "$package_test_dir" - rm -r $local_test_dir + rm -r $local_test_dir - [ ! -e $PACKAGE_SOURCE_DIR/debian/install ] - write_debian_install_file - [ -f $PACKAGE_SOURCE_DIR/debian/install ] - [ "$(cat $PACKAGE_SOURCE_DIR/debian/install)" = "$package_test_dir/file0 $INSTALL_ROOT/$package_test_dir" ] + [ ! -e $PACKAGE_SOURCE_DIR/debian/install ] + write_debian_install_file + [ -f $PACKAGE_SOURCE_DIR/debian/install ] + [ "$(cat $PACKAGE_SOURCE_DIR/debian/install)" = "$package_test_dir/file0 $INSTALL_ROOT/$package_test_dir" ] } @test "add_dir_to_install adds files in dir to package_dest_dir" { - local_test_dir="$BATS_TMPDIR/local-dir" - package_test_dir="package-dir" + local_test_dir="$BATS_TMPDIR/local-dir" + package_test_dir="package-dir" - mkdir $PACKAGE_SOURCE_DIR/$package_test_dir - mkdir $local_test_dir - echo "file0 contents" > $local_test_dir/file0 - echo "file1 contents" > $local_test_dir/file1 - echo "file2 contents" > $local_test_dir/file2 + mkdir $PACKAGE_SOURCE_DIR/$package_test_dir + mkdir $local_test_dir + echo "file0 contents" > $local_test_dir/file0 + echo "file1 contents" > $local_test_dir/file1 + echo "file2 contents" > $local_test_dir/file2 - add_dir_to_install "$local_test_dir" "$package_test_dir" + add_dir_to_install "$local_test_dir" "$package_test_dir" - rm -r $local_test_dir + rm -r $local_test_dir - [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file0" ] - [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file1" ] - [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file2" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file0" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file1" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file2" ] } @test "add_dir_to_install adds files in subdirectory tree to package_dest_dir" { - local_test_dir="$BATS_TMPDIR/local-dir" - local_test_subdir="local-subdir" + local_test_dir="$BATS_TMPDIR/local-dir" + local_test_subdir="local-subdir" - package_test_dir="package-dir" + package_test_dir="package-dir" - mkdir $PACKAGE_SOURCE_DIR/$package_test_dir - mkdir -p $local_test_dir/$local_test_subdir - echo "file0 contents" > $local_test_dir/$local_test_subdir/file0 - echo "file1 contents" > $local_test_dir/$local_test_subdir/file1 - echo "file2 contents" > $local_test_dir/$local_test_subdir/file2 + mkdir $PACKAGE_SOURCE_DIR/$package_test_dir + mkdir -p $local_test_dir/$local_test_subdir + echo "file0 contents" > $local_test_dir/$local_test_subdir/file0 + echo "file1 contents" > $local_test_dir/$local_test_subdir/file1 + echo "file2 contents" > $local_test_dir/$local_test_subdir/file2 - add_dir_to_install "$local_test_dir" "$package_test_dir" + add_dir_to_install "$local_test_dir" "$package_test_dir" - rm -r $local_test_dir + rm -r $local_test_dir - [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/$local_test_subdir/file0" ] - [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/$local_test_subdir/file1" ] - [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/$local_test_subdir/file2" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/$local_test_subdir/file0" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/$local_test_subdir/file1" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/$local_test_subdir/file2" ] } @test "add_dir_to_install adds files in directory and subdirectory tree to package_dest_dir" { - local_test_dir="$BATS_TMPDIR/local-dir" - local_test_subdir="local-subdir" + local_test_dir="$BATS_TMPDIR/local-dir" + local_test_subdir="local-subdir" - package_test_dir="package-dir" + package_test_dir="package-dir" - mkdir $PACKAGE_SOURCE_DIR/$package_test_dir - mkdir -p $local_test_dir/$local_test_subdir + mkdir $PACKAGE_SOURCE_DIR/$package_test_dir + mkdir -p $local_test_dir/$local_test_subdir - echo "file0 contents" > $local_test_dir/file0 - echo "file1 contents" > $local_test_dir/file1 - echo "file2 contents" > $local_test_dir/file2 - echo "file3 contents" > $local_test_dir/$local_test_subdir/file3 - echo "file4 contents" > $local_test_dir/$local_test_subdir/file4 - echo "file5 contents" > $local_test_dir/$local_test_subdir/file5 + echo "file0 contents" > $local_test_dir/file0 + echo "file1 contents" > $local_test_dir/file1 + echo "file2 contents" > $local_test_dir/file2 + echo "file3 contents" > $local_test_dir/$local_test_subdir/file3 + echo "file4 contents" > $local_test_dir/$local_test_subdir/file4 + echo "file5 contents" > $local_test_dir/$local_test_subdir/file5 - add_dir_to_install "$local_test_dir" "$package_test_dir" + add_dir_to_install "$local_test_dir" "$package_test_dir" - rm -r $local_test_dir + rm -r $local_test_dir - [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file0" ] - [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file1" ] - [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file2" ] - [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/$local_test_subdir/file3" ] - [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/$local_test_subdir/file4" ] - [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/$local_test_subdir/file5" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file0" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file1" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/file2" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/$local_test_subdir/file3" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/$local_test_subdir/file4" ] + [ -f "$PACKAGE_SOURCE_DIR/$package_test_dir/$local_test_subdir/file5" ] } @test "add_dir_to_install added files written to install file after write_debian_install_file" { - local_test_dir="$BATS_TMPDIR/local-dir" - package_test_dir="package-dir" + local_test_dir="$BATS_TMPDIR/local-dir" + package_test_dir="package-dir" - mkdir $PACKAGE_SOURCE_DIR/$package_test_dir - mkdir -p $local_test_dir + mkdir $PACKAGE_SOURCE_DIR/$package_test_dir + mkdir -p $local_test_dir - echo "file0 contents" > $local_test_dir/file0 + echo "file0 contents" > $local_test_dir/file0 - add_dir_to_install "$local_test_dir" "$package_test_dir" + add_dir_to_install "$local_test_dir" "$package_test_dir" - rm -r $local_test_dir + rm -r $local_test_dir - [ ! -e $PACKAGE_SOURCE_DIR/debian/install ] - write_debian_install_file - [ -f $PACKAGE_SOURCE_DIR/debian/install ] - [ "$(cat $PACKAGE_SOURCE_DIR/debian/install)" = "$package_test_dir/file0 $INSTALL_ROOT/$package_test_dir" ] + [ ! -e $PACKAGE_SOURCE_DIR/debian/install ] + write_debian_install_file + [ -f $PACKAGE_SOURCE_DIR/debian/install ] + [ "$(cat $PACKAGE_SOURCE_DIR/debian/install)" = "$package_test_dir/file0 $INSTALL_ROOT/$package_test_dir" ] } @test "add_dir_to_install with empty dest dir outputs to PACKAGE_SOURCE_DIR" { - local_test_dir="$BATS_TMPDIR/local-dir" - mkdir -p $local_test_dir + local_test_dir="$BATS_TMPDIR/local-dir" + mkdir -p $local_test_dir - echo "file0 contents" > $local_test_dir/file0 + echo "file0 contents" > $local_test_dir/file0 - add_dir_to_install "$local_test_dir" "" + add_dir_to_install "$local_test_dir" "" - rm -r $local_test_dir + rm -r $local_test_dir - [ -f "$PACKAGE_SOURCE_DIR/file0" ] + [ -f "$PACKAGE_SOURCE_DIR/file0" ] } @test "add_dir_to_install with empty dest dir adds files in directory and subdirectory tree to $PACKAGE_SOURCE_DIR" { - local_test_dir="$BATS_TMPDIR/local-dir" - local_test_subdir="local-subdir" + local_test_dir="$BATS_TMPDIR/local-dir" + local_test_subdir="local-subdir" - mkdir -p $local_test_dir/$local_test_subdir + mkdir -p $local_test_dir/$local_test_subdir - echo "file0 contents" > $local_test_dir/file0 - echo "file1 contents" > $local_test_dir/file1 - echo "file2 contents" > $local_test_dir/file2 - echo "file3 contents" > $local_test_dir/$local_test_subdir/file3 - echo "file4 contents" > $local_test_dir/$local_test_subdir/file4 - echo "file5 contents" > $local_test_dir/$local_test_subdir/file5 + echo "file0 contents" > $local_test_dir/file0 + echo "file1 contents" > $local_test_dir/file1 + echo "file2 contents" > $local_test_dir/file2 + echo "file3 contents" > $local_test_dir/$local_test_subdir/file3 + echo "file4 contents" > $local_test_dir/$local_test_subdir/file4 + echo "file5 contents" > $local_test_dir/$local_test_subdir/file5 - add_dir_to_install "$local_test_dir" "" + add_dir_to_install "$local_test_dir" "" - rm -r $local_test_dir + rm -r $local_test_dir - [ -f "$PACKAGE_SOURCE_DIR/file0" ] - [ -f "$PACKAGE_SOURCE_DIR/file1" ] - [ -f "$PACKAGE_SOURCE_DIR/file2" ] - [ -f "$PACKAGE_SOURCE_DIR/$local_test_subdir/file3" ] - [ -f "$PACKAGE_SOURCE_DIR/$local_test_subdir/file4" ] - [ -f "$PACKAGE_SOURCE_DIR/$local_test_subdir/file5" ] + [ -f "$PACKAGE_SOURCE_DIR/file0" ] + [ -f "$PACKAGE_SOURCE_DIR/file1" ] + [ -f "$PACKAGE_SOURCE_DIR/file2" ] + [ -f "$PACKAGE_SOURCE_DIR/$local_test_subdir/file3" ] + [ -f "$PACKAGE_SOURCE_DIR/$local_test_subdir/file4" ] + [ -f "$PACKAGE_SOURCE_DIR/$local_test_subdir/file5" ] } diff --git a/package_tool/test/unit_tests/test_scripts.bats b/package_tool/test/unit_tests/test_scripts.bats index fc492a013..08e208c1c 100644 --- a/package_tool/test/unit_tests/test_scripts.bats +++ b/package_tool/test/unit_tests/test_scripts.bats @@ -3,22 +3,22 @@ # Tests for debian_build_lib.sh setup(){ - DIR="$BATS_TEST_DIRNAME" - PACKAGIFY_DIR="$(readlink -f $DIR/../../)" + DIR="$BATS_TEST_DIRNAME" + PACKAGIFY_DIR="$(readlink -f $DIR/../../)" } @test "manpage generation is identical to lkg file" { - # Output is file "tool1.1" - # LKG file is "lkgtestman.1" - python $PACKAGIFY_DIR/scripts/manpage_generator.py $PACKAGIFY_DIR/test/test_assets/testdocs.json $PACKAGIFY_DIR/test/test_assets + # Output is file "tool1.1" + # LKG file is "lkgtestman.1" + python $PACKAGIFY_DIR/scripts/manpage_generator.py $PACKAGIFY_DIR/test/test_assets/testdocs.json $PACKAGIFY_DIR/test/test_assets - # Test Output existence - [ -f $PACKAGIFY_DIR/test/test_assets/tool1.1 ] - - # Test Output matches LKG - # If this is failing double check line ending style - [ -z "$(diff "$PACKAGIFY_DIR/test/test_assets/tool1.1" "$PACKAGIFY_DIR/test/test_assets/lkgtestman.1")" ] + # Test Output existence + [ -f $PACKAGIFY_DIR/test/test_assets/tool1.1 ] + + # Test Output matches LKG + # If this is failing double check line ending style + [ -z "$(diff "$PACKAGIFY_DIR/test/test_assets/tool1.1" "$PACKAGIFY_DIR/test/test_assets/lkgtestman.1")" ] - # Cleanup - rm $PACKAGIFY_DIR/test/test_assets/tool1.1 + # Cleanup + rm $PACKAGIFY_DIR/test/test_assets/tool1.1 } \ No newline at end of file From 2e6223c22425d4aff76de9052d8cfac6ab9d9ecb Mon Sep 17 00:00:00 2001 From: Bryan Date: Fri, 16 Oct 2015 12:15:25 -0700 Subject: [PATCH 11/11] undo gitignore changes --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8830360c7..f08574c3d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ [Oo]bj/ -# Top level bin ignore only, so package_tool test_assets are added correctly +[Bb]in/ .nuget/ _ReSharper.*/ packages/