summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2020-04-27 01:14:05 +0200
committerCarl Hetherington <cth@carlh.net>2020-04-27 01:14:05 +0200
commitf230a2fbbe9515c118f211bf663f20a22387eea3 (patch)
tree27f0bb01e2b15673ab1c9934e5642640dd710b52
parent284bae39e6ba8ff533ae89d3385f7e8f1962ebf5 (diff)
HacX.snap
-rwxr-xr-xcdist49
1 files changed, 49 insertions, 0 deletions
diff --git a/cdist b/cdist
index 9e6be5f..536742a 100755
--- a/cdist
+++ b/cdist
@@ -31,6 +31,7 @@ import inspect
import getpass
import shlex
import multiprocessing
+import textwrap
TEMPORARY_DIRECTORY = '/var/tmp'
@@ -781,6 +782,7 @@ class OSXUniversalTarget(OSXTarget):
for p in packages:
copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
+
class SourceTarget(Target):
"""Build a source .tar.bz2"""
def __init__(self):
@@ -801,6 +803,50 @@ class SourceTarget(Target):
p = os.path.abspath('%s-%s.tar.bz2' % (name, tree.version))
copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
+
+class SnapTarget(Target):
+ """Build a snap"""
+ def __init__(self):
+ super(SnapTarget, self).__init__('snap')
+
+ def command(self, c):
+ command('%s %s' % (self.variables_string(), c))
+
+ def cleanup(self):
+ rmtree(self.directory)
+
+ def package(self, project, checkout, output_dir, options):
+ makedirs(os.path.join(self.directory, 'plugins'))
+ f = open(os.path.join(self.directory, 'plugins', 'cdist.py'), 'w')
+ print("""
+import snapcraft
+
+class CdistPlugin(snapcraft.BasePlugin):
+ def build(self):
+ print('cdist plugin builds!')
+""", file=f)
+ f.close()
+
+ f = open(os.path.join(self.directory, 'snapcraft.yaml'), 'w')
+ print('name: %s' % project, file=f)
+ tree = globals.trees.get(project, checkout, self)
+ print('version: %s' % tree.version, file=f)
+ print('summary: %s' % tree.cscript['summary'], file=f)
+ print('description: |', file=f)
+ for l in textwrap.wrap(' '.join(tree.cscript['description'].split())):
+ print("\t%s" % l, file=f)
+ print('confinement: devmode', file=f)
+ print('base: core18', file=f)
+ print('parts:', file=f)
+ for t in tree.dependencies({}):
+ print("\t%s:" % t[0].name, file=f)
+ print("\t\tplugin: cdist", file=f)
+ print("\t\tsource-type: git", file=f)
+ print("\t\tsource: git://%s/%s" % (config.get('git_prefix'), t[0].name), file=f)
+ print("\t\tsource-commit: %s" % t[0].git_commit, file=f)
+
+
+
# @param s Target string:
# windows-{32,64}
# or ubuntu-version-{32,64}
@@ -812,6 +858,7 @@ class SourceTarget(Target):
# or source
# or flatpak
# or appimage
+# or snap
# @param debug True to build with debugging symbols (where possible)
def target_factory(args):
s = args.target
@@ -849,6 +896,8 @@ def target_factory(args):
target = FlatpakTarget(args.project, args.checkout)
elif s == 'appimage':
target = AppImageTarget(args.work)
+ elif s == 'snap':
+ target = SnapTarget()
if target is None:
raise Error("Bad target `%s'" % s)