<s> import os <EOL> import sys <EOL> import subprocess <EOL> from subprocess import CalledProcessError <EOL> import hashlib <EOL> import CoreFoundation <EOL> import tempfile <EOL> import struct <EOL> from . logging_helper import logging_helper <EOL> class xcrun_helper ( object ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def hashStringForPath ( cls , path ) : <EOL> """<STR_LIT>""" <EOL> hash_context = hashlib . md5 ( ) ; <EOL> hash_context . update ( path ) ; <EOL> md5_digest_hex = hash_context . digest ( ) ; <EOL> hash_path = [ None ] * <NUM_LIT> ; <EOL> first_value = struct . unpack ( '<STR_LIT>' , md5_digest_hex [ : <NUM_LIT:8> ] ) [ <NUM_LIT:0> ] ; <EOL> counter = <NUM_LIT> ; <EOL> while counter >= <NUM_LIT:0> : <EOL> hash_path [ counter ] = chr ( ( first_value % <NUM_LIT> ) + ord ( '<STR_LIT:a>' ) ) ; <EOL> first_value = first_value / <NUM_LIT> ; <EOL> counter -= <NUM_LIT:1> ; <EOL> second_value = struct . unpack ( '<STR_LIT>' , md5_digest_hex [ <NUM_LIT:8> : ] ) [ <NUM_LIT:0> ] ; <EOL> counter = <NUM_LIT> ; <EOL> while counter > <NUM_LIT> : <EOL> hash_path [ counter ] = chr ( ( second_value % <NUM_LIT> ) + ord ( '<STR_LIT:a>' ) ) ; <EOL> second_value = second_value / <NUM_LIT> ; <EOL> counter -= <NUM_LIT:1> ; <EOL> hash_path = '<STR_LIT>' . join ( hash_path ) ; <EOL> return hash_path ; <EOL> @ classmethod <EOL> def ResolveDerivedDataPath ( cls ) : <EOL> default_dd_path = os . path . expanduser ( "<STR_LIT>" ) ; <EOL> relative_dd_path = False ; <EOL> derived_data = CoreFoundation . CFPreferencesCopyAppValue ( '<STR_LIT>' , '<STR_LIT>' ) ; <EOL> if derived_data == None : <EOL> derived_data = default_dd_path ; <EOL> else : <EOL> if derived_data [ <NUM_LIT:0> ] != '<STR_LIT:/>' : <EOL> derived_data = os . path . join ( project . path , derived_data ) ; <EOL> return derived_data ; <EOL> @ classmethod <EOL> def ResolveBuildLocation ( cls , project , sym_root ) : <EOL> build_dir_path = '<STR_LIT>' ; <EOL> derived_data = cls . ResolveDerivedDataPath ( ) ; <EOL> location_style = CoreFoundation . CFPreferencesCopyAppValue ( '<STR_LIT>' , '<STR_LIT>' ) ; <EOL> if location_style == '<STR_LIT>' : <EOL> xcodeproj_path = os . path . join ( project . projectRoot . obj_path , project . name ) ; <EOL> unique_path = xcrun_helper . hashStringForPath ( xcodeproj_path ) ; <EOL> project_dir_name = os . path . splitext ( project . name ) [ <NUM_LIT:0> ] + '<STR_LIT:->' + unique_path + '<STR_LIT>' ; <EOL> build_dir_path = os . path . join ( derived_data , project_dir_name ) ; <EOL> elif location_style == '<STR_LIT>' : <EOL> shared_path = CoreFoundation . CFPreferencesCopyAppValue ( '<STR_LIT>' , '<STR_LIT>' ) ; <EOL> build_dir_path = os . path . join ( derived_data , shared_path ) ; <EOL> elif location_style == '<STR_LIT>' : <EOL> location_type = CoreFoundation . CFPreferencesCopyAppValue ( '<STR_LIT>' , '<STR_LIT>' ) ; <EOL> custom_path = CoreFoundation . CFPreferencesCopyAppValue ( '<STR_LIT>' , '<STR_LIT>' ) ; <EOL> if location_type == '<STR_LIT>' : <EOL> build_dir_path = os . path . join ( derived_data , custom_path ) ; <EOL> elif location_type == '<STR_LIT>' : <EOL> build_dir_path = os . path . join ( project . path . base_path , custom_path ) ; <EOL> elif location_type == '<STR_LIT>' : <EOL> build_dir_path = custom_path ; <EOL> elif location_style == '<STR_LIT>' : <EOL> build_dir_path = os . path . join ( project . projectRoot . obj_path , sym_root ) ; <EOL> return build_dir_path ; <EOL> @ classmethod <EOL> def IntermediatesBuildLocation ( cls , project , target_name , config_name , sym_root ) : <EOL> build_dir_path = cls . ResolveBuildLocation ( project , sym_root ) ; <EOL> project_name = project . name . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] ; <EOL> project_dir_path = os . path . join ( build_dir_path , project_name + '<STR_LIT>' ) ; <EOL> config_dir_path = os . path . join ( project_dir_path , config_name ) ; <EOL> target_dir_path = os . path . join ( config_dir_path , target_name + '<STR_LIT>' ) ; <EOL> return target_dir_path ; <EOL> @ classmethod <EOL> def ProductsBuildLocation ( cls , project , sym_root ) : <EOL> """<STR_LIT>""" <EOL> build_dir_path = cls . ResolveBuildLocation ( project , sym_root ) ; <EOL> return build_dir_path ; <EOL> @ classmethod <EOL> def resolvePathFromLocation ( cls , location_string , path , base_path ) : <EOL> path_type , item_path = location_string . split ( '<STR_LIT::>' ) ; <EOL> if path_type == '<STR_LIT>' : <EOL> path = os . path . join ( base_path , path ) ; <EOL> return os . path . join ( path , item_path ) ; <EOL> elif path_type == '<STR_LIT>' : <EOL> return item_path ; <EOL> elif path_type == '<STR_LIT>' : <EOL> return os . path . join ( resolve_developer_path ( ) , item_path ) ; <EOL> elif path_type == '<STR_LIT>' : <EOL> return os . path . join ( base_path , item_path ) ; <EOL> else : <EOL> logging_helper . getLogger ( ) . error ( '<STR_LIT>' ) ; <EOL> return item_path ; <EOL> @ classmethod <EOL> def make_subprocess_session ( cls , action_list ) : <EOL> script = '<STR_LIT>' ; <EOL> for action in action_list : <EOL> script += action + '<STR_LIT>' ; <EOL> script_file = tempfile . NamedTemporaryFile ( '<STR_LIT>' ) <EOL> script_file . write ( script ) <EOL> script_file . flush ( ) <EOL> proc = subprocess . Popen ( [ '<STR_LIT>' , script_file . name ] , stdin = subprocess . PIPE , stdout = subprocess . PIPE ) <EOL> stdout = proc . communicate ( action ) [ <NUM_LIT:0> ] ; <EOL> return stdout ; <EOL> @ classmethod <EOL> def make_subprocess_call ( cls , call_args , shell_state = False ) : <EOL> error = <NUM_LIT:0> ; <EOL> output = '<STR_LIT>' ; <EOL> try : <EOL> output = subprocess . check_output ( call_args , shell = shell_state ) ; <EOL> error = <NUM_LIT:0> ; <EOL> except CalledProcessError as e : <EOL> output = e . output ; <EOL> error = e . returncode ; <EOL> return ( output , error ) ; <EOL> @ classmethod <EOL> def make_xcrun_with_args ( cls , args_tuple ) : <EOL> xcrun_result = xcrun_helper . make_subprocess_call ( ( ( '<STR_LIT>' , ) + args_tuple ) ) ; <EOL> if xcrun_result [ <NUM_LIT:1> ] != <NUM_LIT:0> : <EOL> logging_helper . getLogger ( ) . info ( '<STR_LIT>' ) ; <EOL> sys . exit ( ) ; <EOL> xcrun_output = xcrun_result [ <NUM_LIT:0> ] . rstrip ( '<STR_LIT:\n>' ) ; <EOL> return xcrun_output ; <EOL> @ classmethod <EOL> def resolve_sdk_path ( cls , sdk_name ) : <EOL> return xcrun_helper . make_xcrun_with_args ( ( '<STR_LIT>' , '<STR_LIT>' , sdk_name ) ) ; <EOL> @ classmethod <EOL> def resolve_developer_path ( cls ) : <EOL> platform_path = '<STR_LIT>' ; <EOL> xcrun_result = xcrun_helper . make_subprocess_call ( ( '<STR_LIT>' , '<STR_LIT>' ) ) ; <EOL> if xcrun_result [ <NUM_LIT:1> ] != <NUM_LIT:0> : <EOL> logging_helper . getLogger ( ) . info ( '<STR_LIT>' ) ; <EOL> sys . exit ( ) ; <EOL> developer_path = xcrun_result [ <NUM_LIT:0> ] . rstrip ( '<STR_LIT:\n>' ) ; <EOL> return developer_path ; <EOL> @ classmethod <EOL> def perform_xcodebuild ( cls , project , scheme_name , type , scheme_config_settings ) : <EOL> build_command = '<STR_LIT>' + project . path . obj_path + '<STR_LIT>' + scheme_name + '<STR_LIT>' ; <EOL> for item in scheme_config_settings : <EOL> build_command += str ( item ) + '<STR_LIT:U+0020>' ; <EOL> build_command += '<STR_LIT:U+0020>' + type ; <EOL> result = xcrun_helper . make_subprocess_call ( build_command , True ) ; <EOL> print result [ <NUM_LIT:0> ] ; </s>
