11#!/usr/bin/env python3
22import fileinput
33import os
4+ import re
45import shutil
56import subprocess
67from optparse import OptionParser
@@ -34,9 +35,10 @@ def copy_bundle(binary_name, src_path):
3435def copy_binary (binary_name ):
3536 shutil .copy (binary_name , target_binary (binary_name ))
3637
37- def apply_plist_template (plist_file , version ):
38+ def apply_plist_template (plist_file , version , category ):
39+ print (">> setting bundle category to " + category )
3840 for line in fileinput .input (plist_file , inplace = True ):
39- print (line .rstrip ().replace ("${VERSION}" , version ))
41+ print (line .rstrip ().replace ("${VERSION}" , version ). replace ( "${CATEGORY}" , category ) )
4042
4143def sign_bundle (binary_name ):
4244 sign_directories = ["Contents/Frameworks" , "Contents/MacOS" ]
@@ -48,12 +50,12 @@ def sign_bundle(binary_name):
4850 subprocess .run (["codesign" , "--force" , "-s" , "-" , path ])
4951 subprocess .run (["codesign" , "--force" , "-s" , "-" , bundle_path (binary_name )])
5052
51- def bundle_version (src_path ):
53+ def bundle_version (build_path ):
5254 version = "UNKNOWN"
53- version_path = os .path .join (src_path , "MPV_VERSION " )
54- if os .path .exists (version_path ):
55- x = open (version_path )
56- version = x .read ()
55+ version_h_path = os .path .join (build_path , "common" , "version.h " )
56+ if os .path .exists (version_h_path ):
57+ x = open (version_h_path )
58+ version = re . findall ( r"#define\s+VERSION\s+\"v(.+)\"" , x .read ())[ 0 ]
5759 x .close ()
5860 return version
5961
@@ -63,24 +65,28 @@ def main():
6365 parser .add_option ("-s" , "--skip-deps" , action = "store_false" , dest = "deps" ,
6466 default = True ,
6567 help = "don't bundle the dependencies" )
68+ parser .add_option ("-c" , "--category" , action = "store" , dest = "category" ,
69+ type = "choice" , choices = ["video" , "games" ], default = "video" ,
70+ help = "sets bundle category" )
6671
6772 (options , args ) = parser .parse_args ()
6873
6974 if len (args ) < 1 or len (args ) > 2 :
7075 parser .error ("incorrect number of arguments" )
7176 else :
7277 binary_name = args [0 ]
78+ build_path = os .path .dirname (binary_name )
7379 src_path = args [1 ] if len (args ) > 1 else "."
7480
75- version = bundle_version (src_path ).rstrip ()
81+ version = bundle_version (build_path ).rstrip ()
7682
7783 print (f"Creating macOS application bundle (version: { version } )..." )
7884 print ("> copying bundle skeleton" )
7985 copy_bundle (binary_name , src_path )
8086 print ("> copying binary" )
8187 copy_binary (binary_name )
8288 print ("> generating Info.plist" )
83- apply_plist_template (target_plist (binary_name ), version )
89+ apply_plist_template (target_plist (binary_name ), version , options . category )
8490
8591 if options .deps :
8692 print ("> bundling dependencies" )
0 commit comments