From 8193dd746cecf3644b31e19a2de9abe496a944a0 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Wed, 30 Aug 2017 14:02:50 -0300 Subject: [PATCH] Add a target to generate nugets. --- ges/meson.build | 2 - meson.build | 69 +++++++++++++------------ nuget.py | 123 ++++++++++++++++++++++++++++++++++++++++++++ sources/meson.build | 4 +- 4 files changed, 159 insertions(+), 39 deletions(-) create mode 100644 nuget.py diff --git a/ges/meson.build b/ges/meson.build index b077d4492b..166f710776 100644 --- a/ges/meson.build +++ b/ges/meson.build @@ -12,7 +12,6 @@ sources = [ subdir('generated') -# Install with gacutil_install.py from gtk-sharp. ges_sharp = library(pkg + '-sharp', source_gen, sources, cs_args: ['-nowarn:169', '-nowarn:108', '-nowarn:114', '-unsafe', '-keyfile:' + snk], @@ -29,7 +28,6 @@ library('gessharpglue-1.0.0', gluegen, dependencies: gst_deps + [ges_dep]) ges_sharp_dep = declare_dependency(dependencies: [glib_sharp_dep, gio_sharp_dep, gst_sharp_dep, ges_dep], link_with: ges_sharp) -meson.add_install_script(gacutil_install, meson.project_name(), gst_sharp.full_path()) configure_file( input: pkg + '-sharp.dll.config', diff --git a/meson.build b/meson.build index a61fdf4e1f..f8ba34fad9 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,5 @@ project('gstreamer-sharp', ['cs', 'c'], version: '1.12.0', - meson_version: '>0.42') - + meson_version: '>0.42', license: 'LGPL') if host_machine.system() == 'osx' lib_prefix='' @@ -12,47 +11,36 @@ endif gtk_sharp_required_version = '>=3.22.6' -glib_sharp_dep = dependency('glib-sharp-3.0', - version: gtk_sharp_required_version, - fallback: ['gtk-sharp', 'glib_sharp_dep']) +subproject('gtk-sharp', default_options: ['install=false']) +gtk_sharp = subproject('gtk-sharp') -gio_sharp_dep = dependency('gio-sharp-3.0', - version: gtk_sharp_required_version, - fallback: ['gtk-sharp', 'gio_sharp_dep']) +glib_sharp_dep = gtk_sharp.get_variable('glib_sharp_dep') +glib_sharp = gtk_sharp.get_variable('glib_sharp') -if glib_sharp_dep.type_name() == 'internal' - gtk_sharp = subproject('gtk-sharp') - gapi_fixup = gtk_sharp.get_variable('gapi_fixup') - gapi_codegen = gtk_sharp.get_variable('gapi_codegen') - glib_api_includes = gtk_sharp.get_variable('glib_api_includes') - gio_api_includes = gtk_sharp.get_variable('gio_api_includes') - has_gtk = gtk_sharp.get_variable('has_gtk') - if has_gtk - gtk_sharp_dep = [gtk_sharp.get_variable('gtk_sharp_dep'), - gtk_sharp.get_variable('atk_sharp_dep')] - else - gtk_sharp_dep = dependency('gtk-sharp-3.0', version: gtk_sharp_required_version, - required: false) - endif - codegen_dependencies = [gapi_codegen, gapi_fixup] - gapi_fixup = gapi_fixup.full_path() - gapi_codegen = gapi_codegen.full_path() +gio_sharp_dep = gtk_sharp.get_variable('gio_sharp_dep') +gio_sharp = gtk_sharp.get_variable('gio_sharp') +gio_glue = gtk_sharp.get_variable('gio_glue') + +gapi_fixup = gtk_sharp.get_variable('gapi_fixup') +gapi_codegen = gtk_sharp.get_variable('gapi_codegen') + +glib_api_includes = gtk_sharp.get_variable('glib_api_includes') +gio_api_includes = gtk_sharp.get_variable('gio_api_includes') +has_gtk = gtk_sharp.get_variable('has_gtk') +if has_gtk + gtk_sharp_dep = [gtk_sharp.get_variable('gtk_sharp_dep'), + gtk_sharp.get_variable('atk_sharp_dep')] else gtk_sharp_dep = dependency('gtk-sharp-3.0', version: gtk_sharp_required_version, required: false) - has_gtk = gtk_sharp_dep.found() - - gapi_fixup = find_program('gapi3-fixup') - gapi_codegen = find_program('gapi3-codegen') - pkgconfig = find_program('pkg-config') - glib_api_includes = run_command(pkgconfig, '--cflags', 'glib-sharp-3.0').stdout() - gio_api_includes = run_command(pkgconfig, '--cflags', 'gio-sharp-3.0').stdout() - codegen_dependencies = [] endif +codegen_dependencies = [gapi_codegen, gapi_fixup] +gapi_fixup = gapi_fixup.full_path() +gapi_codegen = gapi_codegen.full_path() gacutil = find_program('gacutil') generate_api = find_program('generate_code.py') -gacutil_install = join_paths(meson.current_source_dir(), 'gacutil_install.py') +nuget = join_paths(meson.current_source_dir(), 'nuget.py') # TODO Handle monodoc @@ -88,6 +76,19 @@ if ges_dep.found() subdir('ges') endif +meson.add_install_script(nuget, '--package-name', 'GstSharp', + '--assembly', gst_sharp.full_path(), + '--native', gst_glue.full_path(), + '--assembly', gio_sharp.full_path(), + '--native', gio_glue.full_path(), + '--assembly', glib_sharp.full_path(), + '--project-url', 'https://gstreamer.freedesktop.org/modules/gstreamer-sharp.html', + '--icon-url', 'https://gstreamer.freedesktop.org/images/header-logo-top.png', + '--license-url', 'https://cgit.freedesktop.org/gstreamer/gstreamer-sharp/plain/COPYING', + '--version', meson.project_version(), + '--tags', 'GStreamer GstSharp bindings', + ) + subdir('samples') bindinate = find_program('bindinate', required: false) diff --git a/nuget.py b/nuget.py new file mode 100644 index 0000000000..38d6888e4c --- /dev/null +++ b/nuget.py @@ -0,0 +1,123 @@ +#!/usr/bin/python3 +import argparse +import getpass +import os +import shutil +import subprocess +from datetime import datetime + +NUSPEC_TEMPLATE =""" + + + {package_name} + {author} + {owner} + {license_url} + {project_url} + {icon_url} + false + {description}. + {copyright} + {tags} + {version} + +{dependencies} + + +{files} + +""" + +TARGETS_TEMPLATE = """ + + + + + + + + +""" + + +class Nugetifier: + def cleanup_args(self): + self.builddir = os.path.abspath(os.path.curdir) + self.nugetdir = os.path.join(self.builddir, + self.package_name + 'nupkg') + self.frameworkdir = 'net45' + self.nuget_build_dir = os.path.join(self.nugetdir, 'build', self.frameworkdir) + self.nuget_lib_dir = os.path.join(self.nugetdir, 'lib', self.frameworkdir) + self.nuspecfile = os.path.join(self.nugetdir, '%s.nuspec' % self.package_name) + self.nugettargets = os.path.join(self.nuget_build_dir, "%s.targets" % self.package_name) + self.nuget = shutil.which('nuget') + if not self.nuget: + print("Could not find the `nuget` tool, install it and retry!") + return -1 + + for d in [self.nugetdir, self.nuget_lib_dir, self.nuget_build_dir]: + os.makedirs(d, exist_ok=True) + if not self.description: + self.description = "%s c# bindings" % self.package_name + if not self.copyright: + self.copyright = "Copyright %s" % datetime.now().year + if not self.tags: + self.tags = self.package_name + + return 0 + + def run(self): + res = self.cleanup_args() + if res: + return res + + self.files = '' + def add_file(path, target="lib"): + f = ' \n' % ( + path, os.path.join(target, self.frameworkdir, os.path.basename(path))) + self.files += f + + self.dependencies = '' + for dependency in self.dependency: + _id, version = dependency.split(":") + self.dependencies += ' \n' % ( + _id, version) + + for assembly in self.assembly: + add_file(assembly) + + for f in [assembly + '.config', assembly[:-3] + 'pdb']: + if os.path.exists(f): + add_file(f, 'build') + + with open(self.nugettargets, 'w') as _: + print(TARGETS_TEMPLATE.format(**self.__dict__), file=_) + add_file(self.nugettargets, 'build') + + with open(self.nuspecfile, 'w') as _: + print(NUSPEC_TEMPLATE.format(**self.__dict__), file=_) + + subprocess.check_call([self.nuget, 'pack', self.nuspecfile], + cwd=self.builddir) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('--package-name') + parser.add_argument('--author', default=getpass.getuser()) + parser.add_argument('--owner', default=getpass.getuser()) + parser.add_argument('--native', action='append', default=[]) + parser.add_argument('--assembly', action='append', default=[]) + parser.add_argument('--out') + parser.add_argument('--description') + parser.add_argument('--copyright') + parser.add_argument('--version') + parser.add_argument('--icon-url', default='') + parser.add_argument('--project-url', default='') + parser.add_argument('--license-url', default='') + parser.add_argument('--tags', default='') + + nugetifier = Nugetifier() + options = parser.parse_args(namespace=nugetifier) + + exit(nugetifier.run()) diff --git a/sources/meson.build b/sources/meson.build index ff226abba5..18b4f98059 100644 --- a/sources/meson.build +++ b/sources/meson.build @@ -36,7 +36,6 @@ sources = [ subdir('generated') -# Install with gacutil_install.py from gtk-sharp. gst_sharp = library('gstreamer-sharp', gst_source_gen, sources, cs_args: ['-nowarn:169', '-nowarn:108', '-nowarn:114', '-unsafe', '-keyfile:' + snk], @@ -48,11 +47,10 @@ gluegen = custom_target('gluegen', command: [generate_api, '--fakeglue'], depends: [gst_source_gen]) -library('gstreamersharpglue-1.0.0', gluegen, 'glue/gobject.c', dependencies: gst_deps) +gst_glue = library('gstreamersharpglue-1.0.0', gluegen, 'glue/gobject.c', dependencies: gst_deps) gst_sharp_dep = declare_dependency(dependencies: [glib_sharp_dep, gio_sharp_dep], link_with: gst_sharp) -meson.add_install_script(gacutil_install, meson.project_name(), gst_sharp.full_path()) configure_file( input: '../out/gstreamer-sharp.dll.config',