Newer
Older
# TODO: SDK extension
self.root_worker.check_call([
'install', '-d', '{}/ostree/main'.format(chroot),
])
self.root_worker.check_call([
'mv', '{}/usr'.format(chroot),
'{}/ostree/main/files'.format(chroot),
])
ref = 'runtime/{}/{}/{}'.format(
runtime, self.flatpak_arch, self.runtime_branch,
with TemporaryDirectory(prefix='flatdeb-ostreeify.') as t:
metadata = os.path.join(t, 'metadata')
keyfile = GLib.KeyFile()
keyfile.set_string('Runtime', 'name', runtime)
keyfile.set_string(
'Runtime', 'runtime',
'{}.Platform/{}/{}\n'.format(
prefix,
self.flatpak_arch,
)
)
keyfile.set_string(
'Runtime', 'sdk',
'{}.Sdk/{}/{}\n'.format(
prefix,
self.flatpak_arch,
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
)
)
keyfile.set_string(
'Environment', 'XDG_DATA_DIRS',
':'.join([
'/app/share', '/usr/share', '/usr/share/runtime/share',
]),
)
if 'libgstreamer1.0-0' in installed:
keyfile.set_string(
'Environment', 'GST_PLUGIN_SYSTEM_PATH',
':'.join([
'/app/lib/gstreamer-1.0',
'/usr/lib/extensions/gstreamer-1.0',
'/usr/lib/gstreamer-1.0',
]),
)
if 'libgirepository-1.0-1' in installed:
keyfile.set_string(
'Environment', 'GI_TYPELIB_PATH',
':'.join([
'/app/lib/girepository-1.0',
]),
)
keyfile.save_to_file(metadata)
self.root_worker.install_file(
metadata,
'{}/ostree/main/metadata'.format(chroot),
)
tarball = '{}-ostree-{}-{}.tar.gz'.format(
runtime,
self.flatpak_arch,
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
)
self.root_worker.check_call([
'tar', '-zcf',
'{}/{}'.format(
self.remote_build_area,
tarball,
),
'-C', '{}/ostree/main'.format(chroot),
'.',
])
self.worker.check_call([
'time',
'ostree',
'--repo=' + self.remote_repo,
'commit',
'--branch=' + ref,
'--subject=Update',
'--tree=tar={}/{}'.format(self.remote_build_area, tarball),
'--fsync=false',
])
# Don't keep the history in this working repository:
# if history is desired, mirror the commits into a public
# repository and maintain history there.
self.worker.check_call([
'time',
'ostree',
'--repo=' + self.remote_repo,
'prune',
'--refs-only',
'--depth=1',
])
if not isinstance(self.worker, HostWorker):
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
self.worker.check_call([
'time',
'flatpak',
'build-update-repo',
self.remote_repo,
])
with self.worker.remote_dir_context(self.remote_repo) as mount:
subprocess.call([
'ostree',
'--repo={}'.format(self.repo),
'remote',
'delete',
'flatdeb-worker',
])
print('^ It is OK if that failed with "remote not found"')
subprocess.check_call([
'ostree',
'--repo={}'.format(self.repo),
'remote',
'add',
'--no-gpg-verify',
'flatdeb-worker',
'file://' + urllib.parse.quote(mount),
])
subprocess.check_call([
'ostree',
'--repo={}'.format(self.repo),
'pull',
'--depth=1',
'--disable-fsync',
'--mirror',
'--untrusted',
'flatdeb-worker',
'runtime/{}/{}/{}'.format(
runtime,
self.flatpak_arch,
self.runtime_branch,
),
])
subprocess.check_call([
'ostree',
'--repo={}'.format(self.repo),
'remote',
'delete',
'flatdeb-worker',
])
output = os.path.join(self.build_area, tarball)
with open(output + '.new', 'wb') as writer:
self.worker.check_call([
'cat',
'{}/{}'.format(self.remote_build_area, tarball),
], stdout=writer)
os.rename(output + '.new', output)
def command_app(self, *, app_branch, prefix, **kwargs):
self.ensure_local_repo()
self.ensure_remote_repo()
# Be nice to people using tab-completion
if prefix.endswith('.yaml'):
prefix = prefix[:-5]
with open(prefix + '.yaml') as reader:
manifest = yaml.safe_load(reader)
if self.runtime_branch is None:
self.runtime_branch = manifest.get('runtime-version')
if self.runtime_branch is None:
self.runtime_branch = self.apt_suite
self.app_branch = app_branch
if self.app_branch is None:
self.app_branch = manifest.get('branch')
if self.app_branch is None:
self.app_branch = 'master'
manifest['branch'] = self.app_branch
manifest['runtime-version'] = self.runtime_branch
with ExitStack() as stack:
stack.enter_context(self.worker)
t = stack.enter_context(
TemporaryDirectory(prefix='flatpak-app.')
)
self.worker.check_call([
'mkdir', '-p', '{}/home'.format(self.worker.scratch),
])
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
if not isinstance(self.worker, HostWorker):
with self.worker.remote_dir_context(self.remote_repo) as mount:
subprocess.call([
'ostree',
'--repo={}'.format(mount),
'remote',
'delete',
'flatdeb-host',
])
print('^ It is OK if that failed with "remote not found"')
subprocess.check_call([
'ostree',
'--repo={}'.format(mount),
'remote',
'add',
'--no-gpg-verify',
'flatdeb-host',
'file://' + urllib.parse.quote(self.repo),
])
subprocess.check_call([
'ostree',
'--repo={}'.format(mount),
'pull',
'--depth=1',
'--disable-fsync',
'--mirror',
'flatdeb-host',
'runtime/{}/{}/{}'.format(
manifest['sdk'],
self.flatpak_arch,
manifest['runtime-version'],
),
])
subprocess.check_call([
'ostree',
'--repo={}'.format(mount),
'pull',
'--depth=1',
'--disable-fsync',
'--mirror',
'flatdeb-host',
'runtime/{}/{}/{}'.format(
manifest['runtime'],
self.flatpak_arch,
manifest['runtime-version'],
),
])
subprocess.check_call([
'ostree',
'--repo={}'.format(mount),
'remote',
'delete',
'flatdeb-host',
])
self.worker.check_call([
'env',
'XDG_DATA_HOME={}/home'.format(self.worker.scratch),
'flatpak', '--user',
'remote-add', '--no-gpg-verify',
'flatdeb', '{}'.format(self.remote_repo),
])
self.worker.check_call([
'env',
'XDG_DATA_HOME={}/home'.format(self.worker.scratch),
'flatpak', '--user',
'install', 'flatdeb',
'{}/{}/{}'.format(
manifest['sdk'],
self.flatpak_arch,
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
),
])
self.worker.check_call([
'env',
'XDG_DATA_HOME={}/home'.format(self.worker.scratch),
'flatpak', '--user',
'install', 'flatdeb',
'{}/{}/{}'.format(
manifest['runtime'],
self.flatpak_arch,
manifest['runtime-version'],
),
])
for module in manifest.get('modules', []):
if isinstance(module, dict):
sources = module.setdefault('sources', [])
for source in sources:
if 'path' in source:
if source.get('type') == 'git':
clone = self.worker.check_output([
'mktemp', '-d',
'-p', self.worker.scratch,
'flatdeb-git.XXXXXX',
]).decode('utf-8').rstrip('\n')
uploader = subprocess.Popen([
'tar',
'-cf-',
'-C', source['path'],
'.',
], stdout=subprocess.PIPE)
self.worker.check_call([
'tar',
'-xf-',
'-C', clone,
], stdin=uploader.stdout)
uploader.wait()
source['path'] = clone
else:
d = self.worker.check_output([
'mktemp', '-d',
'-p', self.worker.scratch,
'flatdeb-path.XXXXXX',
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
]).decode('utf-8').rstrip('\n')
clone = '{}/{}'.format(
d, os.path.basename(source['path']),
)
permissions = 0o644
if GLib.file_test(
source['path'],
GLib.FileTest.IS_EXECUTABLE,
):
permissions = 0o755
self.worker.install_file(
source['path'],
clone,
permissions,
)
source['path'] = clone
if 'x-flatdeb-apt-packages' in module:
packages = self.worker.check_output([
'mktemp', '-d',
'-p', self.worker.scratch,
'flatdeb-debs.XXXXXX',
]).decode('utf-8').rstrip('\n')
self.worker.check_call([
'env',
'XDG_DATA_HOME={}/home'.format(self.worker.scratch),
'flatpak', 'run',
'--filesystem={}'.format(packages),
'--share=network',
'--command=/usr/bin/env',
'{}/{}/{}'.format(
manifest['sdk'],
self.flatpak_arch,
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
),
'http_proxy=http://192.168.122.1:3142',
'export={}'.format(packages),
'sh',
'-euc',
'cp -a /usr/var /\n'
'install -d /var/cache/apt/archives/partial\n'
'fakeroot apt-get update\n'
'fakeroot apt-get -y --download-only install "$@"\n'
'mv /var/cache/apt/archives/*.deb "$export"\n'
'mv /var/lib/apt/lists "$export"\n'
'',
'sh', # argv[0]
] + module['x-flatdeb-apt-packages'])
obtained = self.worker.check_output([
'ls', packages,
]).decode('utf-8').splitlines()
for f in obtained:
path = '{}/{}'.format(packages, f)
if f.endswith('.deb'):
sources.append({
'dest': '.',
'type': 'file',
'path': path,
})
remote_manifest = '{}/{}.json'.format(self.worker.scratch, prefix)
with TemporaryDirectory(prefix='flatdeb-manifest.') as t:
json_manifest = os.path.join(t, prefix + '.json')
with open(
json_manifest, 'w', encoding='utf-8',
) as writer:
json.dump(manifest, writer, indent=2, sort_keys=True)
self.worker.install_file(json_manifest, remote_manifest)
self.worker.check_call([
'env',
'XDG_DATA_HOME={}/home'.format(self.worker.scratch),
'flatpak-builder',
'--repo={}'.format(self.remote_repo),
'{}/workdir'.format(self.worker.scratch),
remote_manifest,
])
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
if not isinstance(self.worker, HostWorker):
self.worker.check_call([
'time',
'flatpak',
'build-update-repo',
self.remote_repo,
])
with self.worker.remote_dir_context(self.remote_repo) as mount:
subprocess.call([
'ostree',
'--repo={}'.format(self.repo),
'remote',
'delete',
'flatdeb-worker',
])
subprocess.check_call([
'ostree',
'--repo={}'.format(self.repo),
'remote',
'add',
'--no-gpg-verify',
'flatdeb-worker',
'file://' + urllib.parse.quote(mount),
])
subprocess.check_call([
'ostree',
'--repo={}'.format(self.repo),
'pull',
'--depth=1',
'--disable-fsync',
'--mirror',
'--untrusted',
'app/{}/{}/{}'.format(
manifest['id'],
self.flatpak_arch,
manifest['branch'],
),
])
subprocess.check_call([
'ostree',
'--repo={}'.format(self.repo),
'remote',
'delete',
'flatdeb-worker',
])
'time',
'env',
'XDG_DATA_HOME={}/home'.format(self.worker.scratch),
'flatpak',
'build-bundle',
self.remote_repo,
manifest['id'],
manifest['branch'],
])
bundle = '{}-{}-{}.bundle'.format(
manifest['id'],
self.flatpak_arch,
manifest['branch'],
)
output = os.path.join(self.build_area, bundle)
with open(output + '.new', 'wb') as writer:
self.worker.check_call([
'cat',
'{}/bundle'.format(self.worker.scratch),
], stdout=writer)
os.rename(output + '.new', output)
if __name__ == '__main__':
Builder().run_command_line()