This repository has been archived by the owner on Nov 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
build_ffmpeg.py
89 lines (71 loc) · 2.75 KB
/
build_ffmpeg.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
#!/usr/bin/env python3
import os, sys, yaml, json, subprocess, datetime
import manifest
cwd = os.getcwd()
def run_os_command(command, environment=None, shell=False):
if shell:
cmd = command
else:
cmd = command.split()
try:
command_output = subprocess.run(
cmd,
env=environment,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=shell
)
except Exception as e:
print(e)
print(command_output)
return command_output.stdout.decode('utf8'), command_output.stderr.decode('utf8'), command_output.returncode
def build_ffmpeg(project, package):
# Extract our name and type
project_name = project['name']
project_type = project['type']
# Set out the directories
type_dir = "{}/projects/{}".format(cwd, project_type)
project_dir = "{}/projects/{}/{}".format(cwd, project_type, project_name)
# Check if a build configuration exists and load it
manifest_file = '{}/build.yaml'.format(project_dir)
if not os.path.exists(manifest_file):
print("ERROR: Project {} does not contain a valid 'build.yaml' file.".format(project['name']))
return False
build_cfg = manifest.load_manifest(manifest_file)
project_version = build_cfg['version']
project_packages = build_cfg['packages']
packages_list = list()
if package == 'all':
packages_list = project_packages
else:
if package in project_packages:
packages_list.append(package)
else:
print('ERROR: Package type {} is not valid. Valid packages are:'.format(package))
print('\n > '.join(project_packages))
return False
# move into the project directory
revdir = os.getcwd()
# Build each package type
for package in packages_list:
os.chdir(project_dir)
# Get release and architecture
release, architecture = package.split('-')
# We wrap `build` so we expect it to be sane and like what we send it
subprocess.call('./build {} {}'.format(release, architecture), shell=True)
# Move back to the previous directory
os.chdir(revdir)
# Collect artifacts
src_dir = "{}/bin".format(type_dir)
target_dir = "./bin/{}".format(project_name)
# Make the type dir if it doesn't exist
if not os.path.isdir(target_dir):
os.makedirs(target_dir)
# Move the artifacts
stdout, stderr, retcode = run_os_command("mv {}/* {}/".format(src_dir, target_dir), shell=True)
if retcode:
print('Could not move archive: {}'.format(stderr))
return False
# Remove build junk
run_os_command("rm -rf {}".format(src_dir))
return True