<s> import ConfigParser <EOL> import optparse <EOL> import os <EOL> import re <EOL> import sys <EOL> import time <EOL> import engine <EOL> import data <EOL> import genautodep <EOL> APPDIR_RE = re . compile ( r"<STR_LIT>" ) <EOL> def RegisterJavaLibrary ( module , f ) : <EOL> name = "<STR_LIT>" % f . name <EOL> lib = data . JavaLibrary ( <EOL> module . name , f . path , name , <EOL> list ( data . FixPath ( module . name , f . path , [ "<STR_LIT>" % f . name ] ) ) , <EOL> [ ] , <EOL> list ( c . DepName ( ) for c in f . classes ) , <EOL> [ ] ) <EOL> data . DataHolder . Register ( module . name , f . path , name , lib ) <EOL> binary = data . JavaBinary ( <EOL> module . name , f . path , f . name , <EOL> "<STR_LIT>" % ( f . path , f . name ) , <EOL> [ "<STR_LIT>" % ( f . path , name ) ] ) <EOL> data . DataHolder . Register ( module . name , f . path , f . name , binary ) <EOL> jar = data . JavaJar ( <EOL> module . name , f . path , f . name + "<STR_LIT>" , binary . FullName ( ) ) <EOL> data . DataHolder . Register ( module . name , f . path , f . name + "<STR_LIT>" , jar ) <EOL> def main ( ) : <EOL> start_time = time . time ( ) <EOL> parser = optparse . OptionParser ( ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" ) <EOL> ( options , args ) = parser . parse_args ( ) <EOL> data . VERBOSE = options . verbose <EOL> config = ConfigParser . SafeConfigParser ( allow_no_value = True ) <EOL> config . optionxform = str <EOL> config . read ( "<STR_LIT>" ) <EOL> if config . has_section ( "<STR_LIT>" ) : <EOL> module_paths = [ path for path , _ in config . items ( "<STR_LIT>" ) ] <EOL> else : <EOL> module_paths = [ "<STR_LIT>" , "<STR_LIT:src>" ] <EOL> if config . has_option ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> data . JAVA_BINARY_FLAGS_DEFAULT = config . getboolean ( <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> if config . has_option ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> protobuf_java = config . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> else : <EOL> protobuf_java = "<STR_LIT>" <EOL> try : <EOL> os . mkdir ( engine . BUILD_DIR ) <EOL> except : <EOL> pass <EOL> modules = genautodep . ComputeDependencies ( module_paths ) <EOL> for module in modules . itervalues ( ) : <EOL> mname = module . name <EOL> app_dirs = { } <EOL> for package , farr in module . files . iteritems ( ) : <EOL> filemap = { } <EOL> java_files = [ ] <EOL> proto_files = [ ] <EOL> for f in farr : <EOL> if mname == "<STR_LIT:src>" : <EOL> m = APPDIR_RE . search ( f . path ) <EOL> if m : <EOL> appdir = f . path [ : m . end ( <NUM_LIT:1> ) ] <EOL> app_dirs . setdefault ( appdir , [ ] ) . append ( f ) <EOL> filemap . setdefault ( f . path , [ ] ) . append ( f ) <EOL> if isinstance ( f , genautodep . ProtoFile ) : <EOL> proto_files . append ( f ) <EOL> else : <EOL> java_files . append ( f ) <EOL> for f in java_files : <EOL> RegisterJavaLibrary ( module , f ) <EOL> for f in proto_files : <EOL> if data . DataHolder . Get ( mname , f . DepName ( ) ) : <EOL> continue <EOL> RegisterJavaLibrary ( module , f ) <EOL> data . DataHolder . Get ( mname , f . DepName ( ) ) . deps . append ( <EOL> protobuf_java ) <EOL> gen = data . Generate ( <EOL> mname , f . path , f . name + "<STR_LIT>" , <EOL> "<STR_LIT>" % engine . ICBM_PATH , None , <EOL> list ( data . FixPath ( mname , f . path , [ "<STR_LIT>" % f . protoname ] ) ) + f . extras , <EOL> [ os . path . join ( f . path , "<STR_LIT>" % f . name ) ] ) <EOL> data . DataHolder . Register ( mname , f . path , f . name + "<STR_LIT>" , gen ) <EOL> for path , file_arr in filemap . iteritems ( ) : <EOL> lib = data . JavaLibrary ( <EOL> mname , path , "<STR_LIT>" , <EOL> [ ] , <EOL> [ ] , <EOL> list ( f . DepName ( ) for f in file_arr ) , <EOL> [ ] ) <EOL> data . DataHolder . Register ( mname , path , "<STR_LIT>" , lib ) <EOL> for path , file_arr in app_dirs . iteritems ( ) : <EOL> deps = set ( ) <EOL> for f in file_arr : <EOL> for c in f . classes : <EOL> if not APPDIR_RE . search ( c . path ) : <EOL> deps . add ( c . DepName ( ) ) <EOL> lib = data . JavaLibrary ( <EOL> mname , path , "<STR_LIT>" , <EOL> [ ] , <EOL> [ ] , <EOL> list ( deps ) , <EOL> [ ] ) <EOL> data . DataHolder . Register ( mname , path , "<STR_LIT>" , lib ) <EOL> for jar in module . jars : <EOL> lib = data . JavaLibrary ( <EOL> mname , "<STR_LIT>" , jar . name , [ ] , <EOL> list ( data . FixPath ( mname , jar . path , [ "<STR_LIT>" % jar . name ] ) ) , <EOL> [ ] , [ ] ) <EOL> data . DataHolder . Register ( mname , jar . path , jar . name , lib ) <EOL> lib = data . JavaLibrary ( <EOL> mname , "<STR_LIT>" , "<STR_LIT>" , <EOL> [ ] , <EOL> [ ] , <EOL> list ( f . DepName ( ) for f in module . jars ) , <EOL> [ ] ) <EOL> data . DataHolder . Register ( mname , "<STR_LIT>" , "<STR_LIT>" , lib ) <EOL> if module . jsps : <EOL> lib = data . JavaLibrary ( <EOL> mname , "<STR_LIT>" , "<STR_LIT>" , <EOL> [ ] , <EOL> [ ] , <EOL> list ( c . DepName ( ) for jsp in module . jsps for c in jsp . classes ) , <EOL> [ ] ) <EOL> data . DataHolder . Register ( mname , "<STR_LIT>" , "<STR_LIT>" , lib ) <EOL> for target in args : <EOL> data . LoadTargetSpec ( data . TOPLEVEL , target ) <EOL> for target in args : <EOL> d = data . DataHolder . Get ( data . TOPLEVEL , target ) <EOL> if not d : <EOL> print "<STR_LIT>" , target <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> d . LoadSpecs ( ) <EOL> success = data . DataHolder . Go ( args ) <EOL> elapsed_time = time . time ( ) - start_time <EOL> print <EOL> print "<STR_LIT>" % elapsed_time <EOL> if not success : <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
