summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-07-27 15:18:35 +0100
committerBaserock Gerrit <gerrit@baserock.org>2015-08-25 15:02:17 +0000
commitbd34dceed26ec212dbe265d80a32d9c4c68bcbc7 (patch)
treee4a62ecdad4625d85f84d250ad9bab1861c67628
parent6c2672269dac107fd7f299fe7439dd967b4653d7 (diff)
downloaddefinitions-bd34dceed26ec212dbe265d80a32d9c4c68bcbc7.tar.gz
Add migration and schema for definitions version 7
Version 7 of the schema adds a new file called DEFAULTS. I thought the best way to describe the layout of this file was to add a JSON-Schema description of it, and I propose keeping the canonical version of it in this Git repository in the schemas/ subdirectory. Change-Id: I18b6b997ba4e9f34028b98ccf682bdf56e507cec
-rwxr-xr-xmigrations/007-defaults-in-definitions.py243
-rw-r--r--schemas/defaults.json-schema66
2 files changed, 309 insertions, 0 deletions
diff --git a/migrations/007-defaults-in-definitions.py b/migrations/007-defaults-in-definitions.py
new file mode 100755
index 00000000..fbc08dbd
--- /dev/null
+++ b/migrations/007-defaults-in-definitions.py
@@ -0,0 +1,243 @@
+#!/usr/bin/env python
+# Copyright (C) 2015 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+'''Migration to Baserock Definitions format version 7.
+
+Definitions version 7 adds a file named DEFAULTS which sets the default
+build commands and default split rules for the set of definitions in that
+repo.
+
+'''
+
+
+import os
+import sys
+import warnings
+
+import migrations
+
+
+TO_VERSION = 7
+
+
+REFERENCE_DEFAULTS = '''# Baserock definitions defaults
+# =============================
+#
+# The DEFAULTS file is treated specially by Baserock build tools.
+#
+# For more information, see: <http://wiki.baserock.org/definitions/current>.
+
+
+# Predefined build commands
+# -------------------------
+#
+# Common patterns in build instructions can be defined here, which can save
+# users from having to write lots of similar-looking chunk .morph files.
+#
+# There are pre- and post- variants for each set of commands. These exist so
+# you can add more commands without having to copy the defaults. For example,
+# to create an extra symlink after running `make install`, you can use
+# post-install-commands. Since these exist as a way of extending the defaults,
+# you cannot set default values for the pre- and post- commands.
+#
+# The set of environment variables available when these commands are executed
+# is not formally specified right now, but you can assume PREFIX, DESTDIR and
+# MORPH_ARCH are all set.
+#
+build-systems:
+ manual:
+ # The special, default 'no-op' build system.
+ configure-commands: []
+ build-commands: []
+ install-commands: []
+ strip-commands: []
+
+ autotools:
+ # GNU Autoconf and GNU Automake, or anything which follow the same pattern.
+ #
+ # See also: https://github.com/cgwalters/build-api/blob/master/build-api.md
+ configure-commands:
+ - |
+ export NOCONFIGURE=1;
+ if [ -e autogen ]; then ./autogen;
+ elif [ -e autogen.sh ]; then ./autogen.sh;
+ elif [ ! -e ./configure ]; then autoreconf -ivf;
+ fi
+ ./configure --prefix="$PREFIX"
+ build-commands:
+ - make
+ install-commands:
+ - make DESTDIR="$DESTDIR" install
+ strip-commands:
+ # TODO: Make idempotent when files are hardlinks
+ # Strip all ELF binary files that are executable or named like a library.
+ # .so files for C, .cmxs for OCaml and .node for Node.
+ #
+ # The file name and permissions checks are done with the `find` command before
+ # the ELF header is checked with the shell command, because it is a lot cheaper
+ # to check the mode and file name first, because it is a metadata check, rather
+ # than a subprocess and a file read.
+ #
+ # `file` is not used, to keep the dependency requirements down.
+ - &generic-strip-command |
+ find "$DESTDIR" -type f
+ '(' -perm -111 -o -name '*.so*' -o -name '*.cmxs' -o -name '*.node' ')'
+ -exec sh -ec
+ read -n4 hdr <"$1" # check for elf header
+ if [ "$hdr" != "$(printf \x7ELF)" ]; then
+ exit 0
+ fi
+ debugfile="$DESTDIR$PREFIX/lib/debug/$(basename "$1")"
+ mkdir -p "$(dirname "$debugfile")"
+ objcopy --only-keep-debug "$1" "$debugfile"
+ chmod 644 "$debugfile"
+ strip --remove-section=.comment --remove-section=.note --strip-unneeded "$1"
+ objcopy --add-gnu-debuglink "$debugfile" "$1"' - {} ';'
+
+ python-distutils:
+ # The Python distutils build systems.
+ configure-commands: []
+ build-commands:
+ - python setup.py build
+ install-commands:
+ - python setup.py install --prefix "$PREFIX" --root "$DESTDIR"
+ strip-commands:
+ - *generic-strip-command
+
+ cpan:
+ # The Perl ExtUtil::MakeMaker build system.
+ configure-commands:
+ # This is subject to change, see: https://gerrit.baserock.org/#/c/986/
+ - |
+ perl Makefile.PL INSTALLDIRS=perl
+ INSTALLARCHLIB="$PREFIX/lib/perl"
+ INSTALLPRIVLIB="$PREFIX/lib/perl"
+ INSTALLBIN="$PREFIX/bin"
+ INSTALLSCRIPT="$PREFIX/bin"
+ INSTALLMAN1DIR="$PREFIX/share/man/man1"
+ INSTALLMAN3DIR="$PREFIX/share/man/man3"
+ build-commands:
+ - make
+ install-commands:
+ - make DESTDIR="$DESTDIR" install
+ strip-commands:
+ - *generic-strip-command
+
+ cmake:
+ # The CMake build system.
+ configure-commands:
+ - cmake -DCMAKE_INSTALL_PREFIX="$PREFIX"'
+ build-commands:
+ - make
+ install-commands:
+ - make DESTDIR="$DESTDIR" install
+ strip-commands:
+ - *generic-strip-command
+
+ qmake:
+ # The Qt build system.
+ configure-commands:
+ - qmake -makefile
+ build-commands:
+ - make
+ install-commands:
+ - make INSTALL_ROOT="$DESTDIR" install
+ strip-commands:
+ - *generic-strip-command
+
+
+# Predefined artifact splitting rules
+# -----------------------------------
+#
+# Once a build has completed, you have some files that have been installed into
+# $DESTDIR. The splitting rules control how many 'artifact' tarballs are
+# generated as a result of the build, and which files from $DESTDIR end up in
+# which 'artifact'.
+#
+# The default split rules are defined here. These can be overriden in
+# individual chunk .morph files and stratum .morph files using the 'products'
+# field.
+#
+split-rules:
+ chunk:
+ - artifact: -bins
+ include:
+ - (usr/)?s?bin/.*
+ - artifact: -libs
+ include:
+ - (usr/)?lib(32|64)?/lib[^/]*\.so(\.\d+)*
+ - (usr/)libexec/.*
+ - artifact: -devel
+ include:
+ - (usr/)?include/.*
+ - (usr/)?lib(32|64)?/lib.*\.a
+ - (usr/)?lib(32|64)?/lib.*\.la
+ - (usr/)?(lib(32|64)?|share)/pkgconfig/.*\.pc
+ - artifact: -doc
+ include:
+ - (usr/)?share/doc/.*
+ - (usr/)?share/man/.*
+ - (usr/)?share/info/.*
+ - artifact: -locale
+ include:
+ - (usr/)?share/locale/.*
+ - (usr/)?share/i18n/.*
+ - (usr/)?share/zoneinfo/.*
+ - artifact: -misc
+ include:
+ - .*
+
+ stratum:
+ - artifact: -devel
+ include:
+ - .*-devel
+ - .*-debug
+ - .*-doc
+ - artifact: -runtime
+ include:
+ - .*-bins
+ - .*-libs
+ - .*-locale
+ - .*-misc
+ - .*
+'''
+
+
+try:
+ if migrations.check_definitions_version(TO_VERSION - 1):
+ if os.path.exists('DEFAULTS'):
+ warnings.warn(
+ "DEFAULTS file already exists in these definitions.")
+ valid = False
+ else:
+ with open('DEFAULTS', 'w') as f:
+ f.write(REFERENCE_DEFAULTS)
+ valid = True
+
+ if valid:
+ migrations.set_definitions_version(TO_VERSION)
+ sys.stdout.write("Migration completed successfully.\n")
+ sys.exit(0)
+ else:
+ sys.stderr.write(
+ "Migration failed due to one or more warnings.\n")
+ sys.exit(1)
+ else:
+ sys.stdout.write("Nothing to do.\n")
+ sys.exit(0)
+except RuntimeError as e:
+ sys.stderr.write("Error: %s\n" % e.message)
+ sys.exit(1)
diff --git a/schemas/defaults.json-schema b/schemas/defaults.json-schema
new file mode 100644
index 00000000..2f713425
--- /dev/null
+++ b/schemas/defaults.json-schema
@@ -0,0 +1,66 @@
+$schema: http://json-schema.org/draft-04/schema#
+id: http://git.baserock.org/cgi-bin/cgit.cgi/baserock/baserock/definitions.git/tree/schemas/defaults.json-schema
+
+description: |
+ This is a JSON-Schema description of the DEFAULTS file specified in the
+ Baserock definitions format. DEFAULTS is a YAML file that contains global
+ defaults for a set of Baserock definitions.
+
+ This JSON-Schema file is valid for VERSION 7 of the Baserock definitions
+ YAML serialisation format.
+
+ The Baserock definitions YAML serialisation format is the recommended way of
+ representing Baserock definitions on disk. The actual data model is described
+ separately. See <https://wiki.baserock.org/definitions> for more information.
+
+ This schema is represented as YAML, so that it can be edited more easily.
+ You may need to convert to JSON if using a JSON-Schema tool that expects
+ its input to be an actual string containing data serialised as JSON.
+
+definitions:
+ command-sequence:
+ type: array
+ items: {type: string}
+
+ build-system:
+ type: object
+ additionalProperties: false
+ properties:
+ build-commands: {$ref: '#/definitions/command-sequence'}
+ configure-commands: {$ref: '#/definitions/command-sequence'}
+ install-commands: {$ref: '#/definitions/command-sequence'}
+ strip-commands: {$ref: '#/definitions/command-sequence'}
+
+ split-rules:
+ type: array
+ items:
+ type: object
+
+ required: [artifact, include]
+ additionalProperties: false
+
+ properties:
+ artifact: {type: string}
+ include:
+ type: array
+ items:
+ type: string
+ format: regex
+
+type: object
+additionalProperties: false
+
+properties:
+ # Predefined build systems.
+ build-systems:
+ type: object
+ patternProperties:
+ ^.*$: {$ref: '#/definitions/build-system'}
+
+ # Predefined artifact splitting rules.
+ split-rules:
+ type: object
+ additionalProperties: false
+ properties:
+ chunk: {$ref: '#/definitions/split-rules'}
+ stratum: {$ref: '#/definitions/split-rules'}