Newer
Older
sources = module.setdefault('sources', [])
for source in sources:
if 'path' in source:
if source.get('type') == 'git':
clone = stack.enter_context(
TemporaryDirectory(
prefix='flatdeb-git.',
dir=scratch,
),
)
uploader = subprocess.Popen([
'tar',
'-cf-',
'-C', source['path'],
'.',
], stdout=subprocess.PIPE)
subprocess.check_call([
'tar',
'-xf-',
'-C', clone,
], stdin=uploader.stdout)
uploader.wait()
source['path'] = clone
else:
d = stack.enter_context(
TemporaryDirectory(
prefix='flatdeb-path.',
dir=scratch,
),
)
clone = os.path.join(
shutil.copyfile(
source['path'],
clone,
)
if GLib.file_test(
source['path'],
GLib.FileTest.IS_EXECUTABLE,
):
os.chmod(clone, 0o755)
else:
os.chmod(clone, 0o644)
source['path'] = clone
if 'x-flatdeb-apt-packages' in module:
packages = stack.enter_context(
TemporaryDirectory(
prefix='flatdeb-debs.',
dir=scratch,
),
)
subprocess.check_call([
'XDG_DATA_HOME={}/home'.format(scratch),
'flatpak', 'run',
'--filesystem={}'.format(packages),
'--share=network',
'--command=/usr/bin/env',
'{}/{}/{}'.format(
manifest['sdk'],
self.flatpak_arch,
'http_proxy=http://192.168.122.1:3142',
'export={}'.format(packages),
'sh',
'-euc',
'install -d /var/cache/apt/archives/partial\n'
'fakeroot apt-get update\n'
'fakeroot apt-get -y --download-only \\\n'
' --no-install-recommends install "$@"\n'
'for x in /var/cache/apt/archives/*.deb; do\n'
' package="$(dpkg-deb -f "$x" Package)"\n'
' source="$(dpkg-deb -f "$x" Source)"\n'
' bu="$(dpkg-deb -f "$x" Built-Using)"\n'
' version="$(dpkg-deb -f "$x" Version)"\n'
' if [ -z "$source" ]; then\n'
' source="$package"\n'
' fi\n'
' if [ "${source% (*}" != "$source" ]; then\n'
' version="${source#* (}"\n'
' version="${version%)}"\n'
' source="${source% (*}"\n'
' fi\n'
' ( cd "$export" && \\\n'
' apt-get -y --download-only \\\n'
' -oAPT::Get::Only-Source=true source \\\n'
' "$source=$version"\n'
' )\n'
' if [ -n "$bu" ]; then\n'
' oldIFS="$IFS"\n'
' IFS=","\n'
' for dep in $bu; do\n'
' bu="$(echo "$bu" | tr -d " ")"\n'
' version="${bu#*(=}"\n'
' version="${version%)}"\n'
' source="${bu%(*}"\n'
' ( cd "$export" && \\\n'
' apt-get -y --download-only \\\n'
' -oAPT::Get::Only-Source=true \\\n'
' source "$source=$version"\n'
' )\n'
' done\n'
' IFS="$oldIFS"\n'
' fi\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 = subprocess.check_output([
'sh', '-euc',
'cd "$1"\n'
'find * -type f -print0 | xargs -0 sha256sum -b\n'
'',
'sh', # argv[0]
packages,
for line in obtained:
sha256, f = line.split(' *', 1)
sources.append({
'dest': (os.path.dirname(f) or '.'),
'type': 'file',
'sha256': sha256,
'url': urllib.parse.urlunsplit((
'file',
'',
urllib.parse.quote(path),
'',
'',
))
})
json_manifest = os.path.join(scratch, manifest['id'] + '.json')
os.makedirs(
os.path.join(self.build_area, '.flatpak-builder'),
exist_ok=True,
)
if self.build_area != scratch:
subprocess.check_call([
'ln', '-nsf',
os.path.join(self.build_area, '.flatpak-builder'),
'{}/'.format(scratch),
with open(json_manifest, 'w', encoding='utf-8') as writer:
json.dump(manifest, writer, indent=2, sort_keys=True)
subprocess.check_call([
'XDG_DATA_HOME={}/home'.format(scratch),
'http_proxy=http://192.168.122.1:3142',
'sh', '-euc',
'cd "$1"; shift; exec "$@"',
'sh', # argv[0]
scratch, # directory to cd into
'--arch={}'.format(self.flatpak_arch),
'--bundle-sources',
os.path.join(scratch, 'workdir'),
json_manifest,
bundle = '{}-{}-{}.bundle'.format(
manifest['id'],
self.flatpak_arch,
manifest['branch'],
)
output = os.path.join(self.build_area, bundle)
subprocess.check_call([
'XDG_DATA_HOME={}/home'.format(scratch),
output + '.new',
manifest['id'],
manifest['branch'],
])
os.rename(output + '.new', output)
if sys.stderr.isatty():
try:
import colorlog
except ImportError:
pass
else:
formatter = colorlog.ColoredFormatter(
'%(log_color)s%(levelname)s:%(name)s:%(reset)s %(message)s')
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logging.getLogger().addHandler(handler)
else:
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
try:
Builder().run_command_line()
except KeyboardInterrupt:
raise SystemExit(130)
except subprocess.CalledProcessError as e:
logger.error('%s', e)
raise SystemExit(1)