Class: CompileCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/xcactivitylog/compile_command.rb

Instance Method Summary collapse

Instance Method Details

#getCompileCommand(xcactivitylog, compile_file, output_file) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/xcactivitylog/compile_command.rb', line 9

def getCompileCommand(xcactivitylog, compile_file, output_file)
    ret = false
    if File.directory?(xcactivitylog)
        path = "#{xcactivitylog}/*.xcactivitylog"
        files_sorted_by_time = Dir[path].sort!{ |x,y| File.mtime(y) <=> File.mtime(x) }
        files_sorted_by_time.each do |file|
            ret = getCompileCommandFromLog(file, compile_file, output_file)
            if ret
                break
            end
        end
    else
        ret = getCompileCommandFromLog(xcactivitylog, compile_file, output_file)
    end
end

#getCompileCommandFromLog(xcactivitylog, compile_file, output_file) ⇒ Object



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
# File 'lib/xcactivitylog/compile_command.rb', line 25

def getCompileCommandFromLog(xcactivitylog, compile_file, output_file)
    ext = File.extname(compile_file)
    file = File.basename(compile_file, ext)
    file = "#{file}.o"

    output_file = "#{output_file}.sh"

    # filter compile command
    reg = ".*clang+.*Applications(.*o)"

    # prase slf0 and filter the command
    flag = false
    text = XcodeResultBundleProcessor::Logdeserializer.deserialize_action_logs(xcactivitylog)
    text.each do |item|
        # puts item
        # if item =~ reg && item =~ /#{file}/
        if item =~ /#{file}/
            content = item.match(reg)
            if content
                puts content

                writeFile(output_file, content)
                flag = true
                break
            end
        end
    end

    flag
end

#writeFile(file, content) ⇒ Object



56
57
58
59
60
61
# File 'lib/xcactivitylog/compile_command.rb', line 56

def writeFile(file, content)
    aFile = File.new(file, "w+")
    if aFile
        aFile.syswrite(content)
    end
end