Ejemplo n.º 1
0
def get_compiler_info_env (project_path):
    lib_path = hxsettings.haxe_library_path();
    env = os.environ.copy()
    if lib_path != None :
        abs_lib_path = path_tools.join_norm(project_path, lib_path)
        env["HAXE_LIBRARY_PATH"] = abs_lib_path
        log("export HAXE_LIBRARY_PATH=" + abs_lib_path)
    return env
Ejemplo n.º 2
0
def collect_compiler_info (project_path):
    log("collect compiler info")
    haxe_exec = hxsettings.haxe_exec()
    
    env = get_compiler_info_env(project_path)

    if haxe_exec != "haxe":
        if project_path != None:
            haxe_exec = path_tools.join_norm(project_path, haxe_exec)
    
    
    log("cmd" + " ".join([haxe_exec, "-main", "Nothing", "-v", "--no-output"]))
    out, err = run_cmd( [haxe_exec, "-main", "Nothing", "-v", "--no-output"], env=env )
    log( out )
    log( err )
    m = classpath_line.match(out)
    
    classes = []
    packs = []
    std_paths = []

    if m is not None :
        std_paths = set(m.group(1).split(";")) - set([".","./"])
    


    for p in std_paths : 
        
        p = os.path.normpath(p)
        
        # last_pos - 2 on windows (why -2) ????? 
        # TODO check this, seems to work, but dirty
        last_pos = len(p)-2
        
        if (len(p) > 0 and (p[last_pos] == "/" or  p[last_pos] == "\\" or p[last_pos] == os.path.sep)):
            p = p[0:last_pos]
        log("path: " + p)
        log(os.path.exists(p))
        log(os.path.isdir(p))

        if len(p) > 1 and os.path.exists(p) and os.path.isdir(p):
            log("do extract")
            classes, packs = hxtypes.extract_types( p, [], [], 0, [], False )
            

    ver = re.search( haxe_version , out )
    log("collected classes: " + str(len(classes)))
    return (classes, packs, ver, std_paths)
Ejemplo n.º 3
0
    def handle_json_response(self, json_res, add, using_line, word_end, build, temp_path, temp_file, use_display, inline_workaround):
        view = self.view
        if "file" in json_res:
            file = json_res["file"]
            min = json_res["min"]
            max = json_res["max"]

            #abs_path = abs_path.replace(build.get_relative_path(temp_file), build.get_relative_path(view.file_name())
            
            abs_path = path_tools.join_norm(build.get_build_folder(), file)
            abs_path_temp = path_tools.join_norm(build.get_build_folder(), build.get_relative_path(os.path.join(temp_path, temp_file)))


            if (abs_path == temp_file):
                if min > word_end:
                    min -= len(add)
                min -= len(using_line)
                # we have manually stored a temp file with only \n line endings
                # so we don't have to adjust the real file position and the sublime
                # text position
            else:
                f = codecs.open(abs_path, "r", "utf-8")
                real_source = f.read()
                f.close()
                # line endings could be \r\n, but sublime text has only \n after
                # opening a file, so we have to calculate the offset betweet the
                # returned position and the real position by counting all \r before min
                # should be moved to a utility function
                offset = 0
                for i in range(0,min):
                    
                    if real_source[i] == u"\r":
                        offset += 1
                log("offset: " + str(offset))

                min -= offset

            if (abs_path == temp_file):
                # file is active view
                abs_path = view.file_name()
                target_view = view
   

                log("line ending: " + str(view.settings().get("line_ending")))

                target_view.sel().clear()
                target_view.sel().add(sublime.Region(min))

                target_view.show(sublime.Region(min))
            else:
                global find_decl_pos, find_decl_file
                find_decl_file = abs_path
                find_decl_pos = min
                # open file and listen => HaxeFindDeclarationListener
                target_view = view.window().open_file(abs_path)

        elif "error" in json_res:
            error = json_res["error"]
            if (error =="inlined" and not inline_workaround):
                # try workaround when the current method was inlined (extern inlines are forced) by the compiler
                self.run1(use_display, True)
            else:
                log("nothing found (1), cannot find declaration")
        else:
            # can we really get here??????
            if use_display:
                log("nothing found yet (1), try again without display (takes longer, workaround for a compiler bug)")
                self.run1(False)
            else:
                log("nothing found (2), cannot find declaration")
Ejemplo n.º 4
0
def hxml_to_builds (build, folder):
	builds = []

	current_build = HaxeBuild()
	current_build.hxml = build
	build_path = os.path.dirname(build);

	# print("build file exists")
	f = codecs.open( build , "r+" , "utf-8" , "ignore" )
	while 1:
		l = f.readline() 
		if not l : 
			break;
		if l.startswith("--next") :
			builds.append( current_build )
			current_build = HaxeBuild()
			current_build.hxml = build
			
		l = l.strip()
		
		if l.startswith("-main") :
			spl = l.split(" ")
			if len( spl ) == 2 :
				current_build.main = spl[1]
			else :
				sublime.status_message( "Invalid build.hxml : no Main class" )
		
		if l.startswith("-lib") :
			spl = l.split(" ")
			if len( spl ) == 2 :
				lib = hxlib.HaxeLib.get( spl[1] )
				current_build.libs.append( lib )
			else :
				sublime.status_message( "Invalid build.hxml : lib not found" )

		if l.startswith("-cmd") :
			spl = l.split(" ")
			current_build.args.append( ( "-cmd" , " ".join(spl[1:]) ) )
		
		for flag in [ "lib" , "D" , "swf-version" , "swf-header", 
					"debug" , "-no-traces" , "-flash-use-stage" , "-gen-hx-classes" , 
					"-remap" , "-no-inline" , "-no-opt" , "-php-prefix" , 
					"-js-namespace" , "-interp" , "-macro" , "-dead-code-elimination" , 
					"-remap" , "-php-front" , "-php-lib", "dce" , "-js-modern", "-times" ] :
			if l.startswith( "-"+flag ) :
				current_build.args.append( tuple(l.split(" ") ) )
				
				break
		
		for flag in [ "resource" , "xml" , "x" , "swf-lib" ] :
			if l.startswith( "-"+flag ) :
				spl = l.split(" ")
				outp = os.path.join( folder , " ".join(spl[1:]) )
				current_build.args.append( ("-"+flag, outp) )
				if (flag == "x"):
					current_build.target = "neko"
				break

		for flag in hxconfig.targets:
			if l.startswith( "-" + flag + " " ) :
				spl = l.split(" ")
				#outp = os.path.join( folder , " ".join(spl[1:]) ) 
				outp = " ".join(spl[1:]) 
				current_build.args.append( ("-"+flag, outp) )
				
				current_build.target = flag
				current_build.output = outp
				break

		if l.startswith("-cp "):
			cp = l.split(" ")
			
			cp.pop(0)
			classpath = " ".join( cp )
			
			abs_classpath = path_tools.join_norm( build_path , classpath )
			current_build.classpaths.append( abs_classpath )
			current_build.args.append( ("-cp" , abs_classpath ) )
	
	if len(current_build.classpaths) == 0:
		log("no classpaths")
		current_build.classpaths.append( build_path )
		current_build.args.append( ("-cp" , build_path ) )
	
	if current_build.main is not None :
		builds.append( current_build )

	return builds