-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconanfile.py
205 lines (179 loc) · 8.3 KB
/
conanfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
from conans import ConanFile, tools, util
from conan.errors import ConanException
import os
import tempfile
import subprocess
import json
import re
import shutil
from conans import __version__ as conan_version
from conans.tools import Version
def _get_file_attrs(glob, recursive=False):
try:
cmd = ["attrib"]
if recursive:
cmd.extend(["/D", "/S"])
cmd.append(glob)
output = subprocess.check_output(cmd)
lines = util.files.decode_text(output).split("\r\n")
except (ValueError, IOError, subprocess.CalledProcessError, UnicodeDecodeError) as e:
raise ConanException("attrib run error: %s" % str(e))
attrib_re = re.compile(r'^([RASHOIXVPU ]+ )(([A-Z]:|\\)\\.*)')
files = []
for line in lines:
match_obj = attrib_re.match(line)
if match_obj:
attrs = match_obj.group(1).replace(' ', '')
path = match_obj.group(2)
files.append((path, attrs))
return files
class CygwinInstallerConan(ConanFile):
name = "cygwin_installer"
description = "Cygwin is a distribution of popular GNU and other Open Source tools running on Windows"
topics = ("conan", "cygwin", "tools")
version = "2.9.0"
license = "https://cygwin.com/COPYING"
url = "https://github.com/bincrafters/conan-cygwin_installer"
homepage = "https://www.cygwin.com"
settings = {"os_build": ["Windows"], "arch_build": ["x86", "x86_64"]}
install_dir = 'cygwin-install'
short_paths = True
options = {"packages": "ANY", # Comma separated, https://cygwin.com/packages/package_list.html
"additional_packages": "ANY", # Comma separated, https://cygwin.com/packages/package_list.html
"exclude_files": "ANY", # Comma separated list of file patterns to exclude from the package
"no_acl": [True, False],
"cygwin": "ANY", # https://cygwin.com/cygwin-ug-net/using-cygwinenv.html
"db_enum": "ANY", # https://cygwin.com/cygwin-ug-net/ntsec.html#ntsec-mapping-nsswitch
"db_home": "ANY",
"db_shell": "ANY",
"db_gecos": "ANY",
"with_sage": [True, False]} # sage package manager https://github.com/svnpenn/sage
default_options = {
'packages': 'pkg-config,make,libtool,binutils,gcc-core,gcc-g++,autoconf,automake,gettext,curl',
'additional_packages': 'None',
'exclude_files': 'None',
'no_acl': False,
'cygwin': 'None',
'db_enum': 'None',
'db_home': 'None',
'db_shell': 'None',
'db_gecos': 'None',
'with_sage': True
}
@property
def os(self):
return self.settings.get_safe("os_build") or self.settings.get_safe("os")
@property
def arch(self):
return self.settings.get_safe("arch_build") or self.settings.get_safe("arch")
def build(self):
filename = "setup-%s.exe" % self.arch
url = "https://cygwin.com/%s" % filename
tools.download(url, filename)
if not os.path.isdir(self.install_dir):
os.makedirs(self.install_dir)
# https://cygwin.com/faq/faq.html#faq.setup.cli
command = filename
command += ' --arch %s' % self.arch
# Disable creation of desktop and start menu shortcuts
command += ' --no-shortcuts'
# Do not check for and enforce running as Administrator
command += ' --no-admin'
# Unattended setup mode
command += ' --quiet-mode'
command += ' --root %s' % os.path.abspath(self.install_dir)
# TODO : download and parse mirror list, probably also select the best one
command += ' -s http://cygwin.mirror.constant.com'
command += ' --local-package-dir %s' % tempfile.mkdtemp()
packages = []
if self.options.packages:
packages.extend(str(self.options.packages).split(","))
if self.options.additional_packages:
packages.extend(str(self.options.additional_packages).split(","))
if packages:
command += ' --packages %s' % ','.join(packages)
self.run(command)
os.unlink(filename)
# create /tmp dir in order to avoid
# bash.exe: warning: could not find /tmp, please create!
tmp_dir = os.path.join(self.install_dir, 'tmp')
if not os.path.isdir(tmp_dir):
os.makedirs(tmp_dir)
tmp_name = os.path.join(tmp_dir, 'dummy')
with open(tmp_name, 'a'):
os.utime(tmp_name, None)
def add_line(line):
nsswitch_conf = os.path.join(self.install_dir, 'etc', 'nsswitch.conf')
with open(nsswitch_conf, 'a') as f:
f.write('%s\n' % line)
if self.options.db_enum:
add_line('db_enum: %s' % self.options.db_enum)
if self.options.db_home:
add_line('db_home: %s' % self.options.db_home)
if self.options.db_shell:
add_line('db_shell: %s' % self.options.db_shell)
if self.options.db_gecos:
add_line('db_gecos: %s' % self.options.db_gecos)
if self.options.no_acl:
fstab = os.path.join(self.install_dir, 'etc', 'fstab')
fstab_in = fstab + ".in"
shutil.copyfile(fstab, fstab_in)
tools.replace_in_file(fstab_in,
"""# This is default anyway:
none /cygdrive cygdrive binary,posix=0,user 0 0""",
"""none /cygdrive cygdrive noacl,binary,posix=0,user 0 0
@CYGWIN_ROOT@/bin /usr/bin ntfs binary,auto,noacl 0 0
@CYGWIN_ROOT@/lib /usr/lib ntfs binary,auto,noacl 0 0
@CYGWIN_ROOT@ / ntfs override,binary,auto,noacl 0 0""")
if self.options.with_sage:
usr_local = os.path.join(self.install_dir, 'usr', 'local')
bash = os.path.abspath(os.path.join(self.install_dir, 'bin', 'bash.exe'))
with tools.chdir(usr_local):
for package in ['velour', 'sage']:
tools.get('https://codeload.github.com/svnpenn/%s/zip/master' % package)
self.run('%s -l -c "cd /usr/local/%s-master && ./install.sh"' % (bash, package))
def record_symlinks(self):
root = os.path.join(self.build_folder, self.install_dir)
symlinks = [os.path.relpath(path, root)
for (path, attrs) in _get_file_attrs(os.path.join(root, '*'), recursive=True)
if "S" in attrs]
symlinks_json = os.path.join(self.package_folder, "symlinks.json")
tools.save(symlinks_json, json.dumps(symlinks))
def package(self):
self.record_symlinks()
excludes = None
if self.options.exclude_files:
excludes = tuple(str(self.options.exclude_files).split(","))
self.copy(pattern="*", dst=".", src=self.install_dir, excludes=excludes)
def fix_symlinks(self):
symlinks_json = os.path.join(self.package_folder, "symlinks.json")
symlinks = json.loads(tools.load(symlinks_json))
for path in symlinks:
full_path = os.path.join(self.package_folder, path)
attrs = _get_file_attrs(full_path)[0][1]
if 'S' in attrs:
break
self.run('attrib -R +S "%s"' % full_path)
def package_id(self):
del self.info.options.cygwin
def package_info(self):
# workaround for error "cannot execute binary file: Exec format error"
# symbolic links must have system attribute in order to work properly
self.fix_symlinks()
cygwin_root = self.package_folder
cygwin_root_fs = cygwin_root.replace('\\', '/')
cygwin_bin = os.path.join(cygwin_root, "bin")
if self.options.no_acl:
fstab = os.path.join(cygwin_root, 'etc', 'fstab')
self.output.info("Updating /etc/fstab")
shutil.copyfile(fstab + ".in", fstab)
tools.replace_in_file(fstab, "@CYGWIN_ROOT@", cygwin_root_fs)
self.output.info("Creating CYGWIN_ROOT env var : %s" % cygwin_root)
self.env_info.CYGWIN_ROOT = cygwin_root
self.output.info("Creating CYGWIN_BIN env var : %s" % cygwin_bin)
self.env_info.CYGWIN_BIN = cygwin_bin
self.output.info("Appending PATH env var with : " + cygwin_bin)
self.env_info.path.append(cygwin_bin)
if self.options.cygwin:
self.output.info("Creating CYGWIN env var : %s" % self.options.cygwin)
self.env_info.CYGWIN = str(self.options.cygwin)