aboutsummaryrefslogtreecommitdiff
path: root/packaging
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2020-11-24 15:40:57 -0500
committerJussi Pakkanen <jpakkane@gmail.com>2020-11-27 18:12:08 +0200
commitdf50123c058bd1e76c1b3230b4f27531f0adfe07 (patch)
treea9b62981c4e3f4023c9729301d1ddfd3fb2256ec /packaging
parentcef13b04c253150a449eaea806d97207281916eb (diff)
downloadmeson-df50123c058bd1e76c1b3230b4f27531f0adfe07.zip
meson-df50123c058bd1e76c1b3230b4f27531f0adfe07.tar.gz
meson-df50123c058bd1e76c1b3230b4f27531f0adfe07.tar.bz2
createmsi: move to generic packaging directory
We might want to create other dedicated packaging scripts, and put them all in one directory.
Diffstat (limited to 'packaging')
-rw-r--r--packaging/License.rtf73
-rw-r--r--packaging/createmsi.py352
2 files changed, 425 insertions, 0 deletions
diff --git a/packaging/License.rtf b/packaging/License.rtf
new file mode 100644
index 0000000..b3945ba
--- /dev/null
+++ b/packaging/License.rtf
@@ -0,0 +1,73 @@
+{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fswiss\fprq2\fcharset0 Arial;}}
+{\colortbl ;\red0\green0\blue255;}
+{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\qc\lang1033\b\f0\fs18 Apache License\par
+Version 2.0, January 2004\par
+{\field{\*\fldinst{HYPERLINK "http://www.apache.org/licenses/"}}{\fldrslt{\ul\cf1 http://www.apache.org/licenses/}}}\f0\fs18\par
+\b0\par
+\pard TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\par
+\par
+\pard\fi-180\li180 1. Definitions.\par
+\par
+\pard\li180 "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.\par
+\par
+"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.\par
+\par
+"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.\par
+\par
+"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.\par
+\par
+"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.\par
+\par
+"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.\par
+\par
+"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).\par
+\par
+"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.\par
+\par
+"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."\par
+\par
+"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.\par
+\pard\par
+\pard\fi-180\li180 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.\par
+\par
+3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.\par
+\par
+4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:\par
+\pard\par
+\pard\fi-270\li450 (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and\par
+\par
+(b) You must cause any modified files to carry prominent notices stating that You changed the files; and\par
+\par
+(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and\par
+\par
+(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.\par
+\pard\par
+\pard\li180 You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.\par
+\pard\par
+\pard\fi-180\li180 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.\par
+\par
+6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.\par
+\par
+7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.\par
+\par
+8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.\par
+\par
+9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.\par
+\pard\par
+END OF TERMS AND CONDITIONS\par
+\par
+APPENDIX: How to apply the Apache License to your work.\par
+\par
+To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.\par
+\par
+\pard\li180 Copyright [yyyy] [name of copyright owner]\par
+\par
+Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\par
+\par
+\pard\li360{\field{\*\fldinst{HYPERLINK "http://www.apache.org/licenses/LICENSE-2.0"}}{\fldrslt{\ul\cf1 http://www.apache.org/licenses/LICENSE-2.0}}}\f0\fs18\par
+\pard\li180\par
+Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\par
+\pard\par
+\par
+}
+
diff --git a/packaging/createmsi.py b/packaging/createmsi.py
new file mode 100644
index 0000000..e6c47f4
--- /dev/null
+++ b/packaging/createmsi.py
@@ -0,0 +1,352 @@
+#!/usr/bin/env python3
+
+# Copyright 2017 The Meson development team
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+'''
+This script is for generating MSI packages
+for Windows users.
+'''
+
+import subprocess
+import shutil
+import uuid
+import sys
+import os
+from glob import glob
+import platform
+import xml.etree.ElementTree as ET
+
+sys.path.append(os.getcwd())
+from mesonbuild import coredata
+
+def gen_guid():
+ '''
+ Generate guid
+ '''
+ return str(uuid.uuid4()).upper()
+
+class Node:
+ '''
+ Node to hold path and directory values
+ '''
+
+ def __init__(self, dirs, files):
+ self.check_dirs(dirs)
+ self.check_files(files)
+ self.dirs = dirs
+ self.files = files
+
+ @staticmethod
+ def check_dirs(dirs):
+ '''
+ Check to see if directory is instance of list
+ '''
+ assert isinstance(dirs, list)
+
+ @staticmethod
+ def check_files(files):
+ '''
+ Check to see if files is instance of list
+ '''
+ assert isinstance(files, list)
+
+
+class PackageGenerator:
+ '''
+ Package generator for MSI pacakges
+ '''
+
+ def __init__(self):
+ self.product_name = 'Meson Build System'
+ self.manufacturer = 'The Meson Development Team'
+ self.version = coredata.version.replace('dev', '')
+ self.root = None
+ self.guid = '*'
+ self.update_guid = '141527EE-E28A-4D14-97A4-92E6075D28B2'
+ self.main_xml = 'meson.wxs'
+ self.main_o = 'meson.wixobj'
+ self.bytesize = 32 if '32' in platform.architecture()[0] else 64
+ self.final_output = 'meson-{}-{}.msi'.format(self.version, self.bytesize)
+ self.staging_dirs = ['dist', 'dist2']
+ self.progfile_dir = 'ProgramFiles64Folder'
+ redist_glob = 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Redist\\MSVC\\v*\\MergeModules\\Microsoft_VC142_CRT_x64.msm'
+ trials = glob(redist_glob)
+ if len(trials) != 1:
+ sys.exit('Could not find unique MSM setup:' + '\n'.join(trials))
+ self.redist_path = trials[0]
+ self.component_num = 0
+ self.feature_properties = {
+ self.staging_dirs[0]: {
+ 'Id': 'MainProgram',
+ 'Title': 'Meson',
+ 'Description': 'Meson executables',
+ 'Level': '1',
+ 'Absent': 'disallow',
+ },
+ self.staging_dirs[1]: {
+ 'Id': 'NinjaProgram',
+ 'Title': 'Ninja',
+ 'Description': 'Ninja build tool',
+ 'Level': '1',
+ }
+ }
+ self.feature_components = {}
+ for s_d in self.staging_dirs:
+ self.feature_components[s_d] = []
+
+ @staticmethod
+ def get_all_modules_from_dir(dirname):
+ '''
+ Get all modules required for Meson build MSI package
+ from directories.
+ '''
+ modname = os.path.basename(dirname)
+ modules = [os.path.splitext(os.path.split(x)[1])[0] for x in glob(os.path.join(dirname, '*'))]
+ modules = ['mesonbuild.' + modname + '.' + x for x in modules if not x.startswith('_')]
+ return modules
+
+ @staticmethod
+ def get_more_modules():
+ '''
+ Getter for missing Modules.
+ Python packagers want to be minimal and only copy the things
+ that they can see that being used. They are blind to many things.
+ '''
+ return ['distutils.archive_util',
+ 'distutils.cmd',
+ 'distutils.config',
+ 'distutils.core',
+ 'distutils.debug',
+ 'distutils.dep_util',
+ 'distutils.dir_util',
+ 'distutils.dist',
+ 'distutils.errors',
+ 'distutils.extension',
+ 'distutils.fancy_getopt',
+ 'distutils.file_util',
+ 'distutils.spawn',
+ 'distutils.util',
+ 'distutils.version',
+ 'distutils.command.build_ext',
+ 'distutils.command.build',
+ ]
+
+ def build_dist(self):
+ '''
+ Build dist file from PyInstaller info
+ '''
+ for sdir in self.staging_dirs:
+ if os.path.exists(sdir):
+ shutil.rmtree(sdir)
+ main_stage, ninja_stage = self.staging_dirs
+ modules = self.get_all_modules_from_dir('mesonbuild/modules')
+ modules += self.get_all_modules_from_dir('mesonbuild/scripts')
+ modules += self.get_more_modules()
+
+ pyinstaller = shutil.which('pyinstaller')
+ if not pyinstaller:
+ print("ERROR: This script requires pyinstaller.")
+ sys.exit(1)
+
+ pyinstaller_tmpdir = 'pyinst-tmp'
+ if os.path.exists(pyinstaller_tmpdir):
+ shutil.rmtree(pyinstaller_tmpdir)
+ pyinst_cmd = [pyinstaller,
+ '--clean',
+ '--distpath',
+ pyinstaller_tmpdir]
+ for m in modules:
+ pyinst_cmd += ['--hidden-import', m]
+ pyinst_cmd += ['meson.py']
+ subprocess.check_call(pyinst_cmd)
+ shutil.move(pyinstaller_tmpdir + '/meson', main_stage)
+ if not os.path.exists(os.path.join(main_stage, 'meson.exe')):
+ sys.exit('Meson exe missing from staging dir.')
+ os.mkdir(ninja_stage)
+ shutil.copy(shutil.which('ninja'), ninja_stage)
+ if not os.path.exists(os.path.join(ninja_stage, 'ninja.exe')):
+ sys.exit('Ninja exe missing from staging dir.')
+
+ def generate_files(self):
+ '''
+ Generate package files for MSI installer package
+ '''
+ self.root = ET.Element('Wix', {'xmlns': 'http://schemas.microsoft.com/wix/2006/wi'})
+ product = ET.SubElement(self.root, 'Product', {
+ 'Name': self.product_name,
+ 'Manufacturer': 'The Meson Development Team',
+ 'Id': self.guid,
+ 'UpgradeCode': self.update_guid,
+ 'Language': '1033',
+ 'Codepage': '1252',
+ 'Version': self.version,
+ })
+
+ package = ET.SubElement(product, 'Package', {
+ 'Id': '*',
+ 'Keywords': 'Installer',
+ 'Description': 'Meson {} installer'.format(self.version),
+ 'Comments': 'Meson is a high performance build system',
+ 'Manufacturer': 'The Meson Development Team',
+ 'InstallerVersion': '500',
+ 'Languages': '1033',
+ 'Compressed': 'yes',
+ 'SummaryCodepage': '1252',
+ })
+
+ ET.SubElement(product, 'MajorUpgrade',
+ {'DowngradeErrorMessage': 'A newer version of Meson is already installed.'})
+
+ if self.bytesize == 64:
+ package.set('Platform', 'x64')
+ ET.SubElement(product, 'Media', {
+ 'Id': '1',
+ 'Cabinet': 'meson.cab',
+ 'EmbedCab': 'yes',
+ })
+ targetdir = ET.SubElement(product, 'Directory', {
+ 'Id': 'TARGETDIR',
+ 'Name': 'SourceDir',
+ })
+ progfiledir = ET.SubElement(targetdir, 'Directory', {
+ 'Id': self.progfile_dir,
+ })
+ installdir = ET.SubElement(progfiledir, 'Directory', {
+ 'Id': 'INSTALLDIR',
+ 'Name': 'Meson',
+ })
+ ET.SubElement(installdir, 'Merge', {
+ 'Id': 'VCRedist',
+ 'SourceFile': self.redist_path,
+ 'DiskId': '1',
+ 'Language': '0',
+ })
+
+ ET.SubElement(product, 'Property', {
+ 'Id': 'WIXUI_INSTALLDIR',
+ 'Value': 'INSTALLDIR',
+ })
+ ET.SubElement(product, 'UIRef', {
+ 'Id': 'WixUI_FeatureTree',
+ })
+ for s_d in self.staging_dirs:
+ assert os.path.isdir(s_d)
+ top_feature = ET.SubElement(product, 'Feature', {
+ 'Id': 'Complete',
+ 'Title': 'Meson ' + self.version,
+ 'Description': 'The complete package',
+ 'Display': 'expand',
+ 'Level': '1',
+ 'ConfigurableDirectory': 'INSTALLDIR',
+ })
+ for s_d in self.staging_dirs:
+ nodes = {}
+ for root, dirs, files in os.walk(s_d):
+ cur_node = Node(dirs, files)
+ nodes[root] = cur_node
+ self.create_xml(nodes, s_d, installdir, s_d)
+ self.build_features(top_feature, s_d)
+ vcredist_feature = ET.SubElement(top_feature, 'Feature', {
+ 'Id': 'VCRedist',
+ 'Title': 'Visual C++ runtime',
+ 'AllowAdvertise': 'no',
+ 'Display': 'hidden',
+ 'Level': '1',
+ })
+ ET.SubElement(vcredist_feature, 'MergeRef', {'Id': 'VCRedist'})
+ ET.ElementTree(self.root).write(self.main_xml, encoding='utf-8', xml_declaration=True)
+ # ElementTree can not do prettyprinting so do it manually
+ import xml.dom.minidom
+ doc = xml.dom.minidom.parse(self.main_xml)
+ with open(self.main_xml, 'w') as open_file:
+ open_file.write(doc.toprettyxml())
+
+ def build_features(self, top_feature, staging_dir):
+ '''
+ Generate build features
+ '''
+ feature = ET.SubElement(top_feature, 'Feature', self.feature_properties[staging_dir])
+ for component_id in self.feature_components[staging_dir]:
+ ET.SubElement(feature, 'ComponentRef', {
+ 'Id': component_id,
+ })
+
+ def create_xml(self, nodes, current_dir, parent_xml_node, staging_dir):
+ '''
+ Create XML file
+ '''
+ cur_node = nodes[current_dir]
+ if cur_node.files:
+ component_id = 'ApplicationFiles{}'.format(self.component_num)
+ comp_xml_node = ET.SubElement(parent_xml_node, 'Component', {
+ 'Id': component_id,
+ 'Guid': gen_guid(),
+ })
+ self.feature_components[staging_dir].append(component_id)
+ if self.bytesize == 64:
+ comp_xml_node.set('Win64', 'yes')
+ if self.component_num == 0:
+ ET.SubElement(comp_xml_node, 'Environment', {
+ 'Id': 'Environment',
+ 'Name': 'PATH',
+ 'Part': 'last',
+ 'System': 'yes',
+ 'Action': 'set',
+ 'Value': '[INSTALLDIR]',
+ })
+ self.component_num += 1
+ for f_node in cur_node.files:
+ file_id = os.path.join(current_dir, f_node).replace('\\', '_').replace('#', '_').replace('-', '_')
+ ET.SubElement(comp_xml_node, 'File', {
+ 'Id': file_id,
+ 'Name': f_node,
+ 'Source': os.path.join(current_dir, f_node),
+ })
+
+ for dirname in cur_node.dirs:
+ dir_id = os.path.join(current_dir, dirname).replace('\\', '_').replace('/', '_')
+ dir_node = ET.SubElement(parent_xml_node, 'Directory', {
+ 'Id': dir_id,
+ 'Name': dirname,
+ })
+ self.create_xml(nodes, os.path.join(current_dir, dirname), dir_node, staging_dir)
+
+ def build_package(self):
+ '''
+ Generate the Meson build MSI package.
+ '''
+ wixdir = 'c:\\Program Files\\Wix Toolset v3.11\\bin'
+ if not os.path.isdir(wixdir):
+ wixdir = 'c:\\Program Files (x86)\\Wix Toolset v3.11\\bin'
+ if not os.path.isdir(wixdir):
+ print("ERROR: This script requires WIX")
+ sys.exit(1)
+ subprocess.check_call([os.path.join(wixdir, 'candle'), self.main_xml])
+ subprocess.check_call([os.path.join(wixdir, 'light'),
+ '-ext', 'WixUIExtension',
+ '-cultures:en-us',
+ '-dWixUILicenseRtf=packaging\\License.rtf',
+ '-out', self.final_output,
+ self.main_o])
+
+if __name__ == '__main__':
+ if not os.path.exists('meson.py'):
+ sys.exit(print('Run me in the top level source dir.'))
+ subprocess.check_call(['pip', 'install', '--upgrade', 'pyinstaller'])
+
+ p = PackageGenerator()
+ p.build_dist()
+ p.generate_files()
+ p.build_package()