@@ -27,8 +27,8 @@ type Invocation struct {
27
27
sessionID uint32 // incremental while a daemon is alive
28
28
29
29
// cmdLine is parsed to the following fields:
30
- cppInFile string // absolute path to the input file (.cpp for compilation, .h for pch generation)
31
- objOutFile string // absolute path to the output file (.o for compilation, .gch/.pch for pch generation)
30
+ cppInFile string // input file as specified in cmd line (.cpp for compilation, .h for pch generation)
31
+ objOutFile string // output file as specified in cmd line (.o for compilation, .gch/.pch for pch generation)
32
32
cxxName string // g++ / clang / etc.
33
33
cxxArgs []string // args like -Wall, -fpch-preprocess and many more, except:
34
34
cxxIDirs IncludeDirs // -I / -iquote / -isystem go here
@@ -89,13 +89,13 @@ func ParseCmdLineInvocation(daemon *Daemon, cwd string, cmdLine []string) (invoc
89
89
if cmdLine [* argIndex ] == "-Xclang" { // -Xclang -include -Xclang {file}
90
90
* argIndex ++
91
91
}
92
- return pathAbs ( cwd , cmdLine [* argIndex ]) , true
92
+ return cmdLine [* argIndex ], true
93
93
} else {
94
94
invocation .err = fmt .Errorf ("unsupported command-line: no argument after %s" , arg )
95
95
return "" , false
96
96
}
97
97
} else if strings .HasPrefix (arg , key ) { // -I/path
98
- return pathAbs ( cwd , arg [len (key ):]) , true
98
+ return arg [len (key ):], true
99
99
}
100
100
return "" , false
101
101
}
@@ -121,19 +121,18 @@ func ParseCmdLineInvocation(daemon *Daemon, cwd string, cmdLine []string) (invoc
121
121
if arg [0 ] == '-' {
122
122
if oFile , ok := parseArgFile ("-o" , arg , & i ); ok {
123
123
invocation .objOutFile = oFile
124
- invocation .depsFlags .SetCmdOutputFile (strings .TrimPrefix (arg , "-o" ))
125
124
continue
126
125
} else if dir , ok := parseArgFile ("-I" , arg , & i ); ok {
127
- invocation .cxxIDirs .dirsI = append (invocation .cxxIDirs .dirsI , dir )
126
+ invocation .cxxIDirs .dirsI = append (invocation .cxxIDirs .dirsI , pathAbs ( cwd , dir ) )
128
127
continue
129
128
} else if dir , ok := parseArgFile ("-iquote" , arg , & i ); ok {
130
- invocation .cxxIDirs .dirsIquote = append (invocation .cxxIDirs .dirsIquote , dir )
129
+ invocation .cxxIDirs .dirsIquote = append (invocation .cxxIDirs .dirsIquote , pathAbs ( cwd , dir ) )
131
130
continue
132
131
} else if dir , ok := parseArgFile ("-isystem" , arg , & i ); ok {
133
- invocation .cxxIDirs .dirsIsystem = append (invocation .cxxIDirs .dirsIsystem , dir )
132
+ invocation .cxxIDirs .dirsIsystem = append (invocation .cxxIDirs .dirsIsystem , pathAbs ( cwd , dir ) )
134
133
continue
135
134
} else if iFile , ok := parseArgFile ("-include" , arg , & i ); ok {
136
- invocation .cxxIDirs .filesI = append (invocation .cxxIDirs .filesI , iFile )
135
+ invocation .cxxIDirs .filesI = append (invocation .cxxIDirs .filesI , pathAbs ( cwd , iFile ) )
137
136
continue
138
137
} else if arg == "-march=native" {
139
138
invocation .err = fmt .Errorf ("-march=native can't be launched remotely" )
@@ -190,8 +189,7 @@ func ParseCmdLineInvocation(daemon *Daemon, cwd string, cmdLine []string) (invoc
190
189
invocation .err = fmt .Errorf ("unsupported command-line: multiple input source files" )
191
190
return
192
191
}
193
- invocation .cppInFile = pathAbs (cwd , arg )
194
- invocation .depsFlags .SetCmdInputFile (arg )
192
+ invocation .cppInFile = arg
195
193
continue
196
194
} else if strings .HasSuffix (arg , ".o" ) || strings .HasPrefix (arg , ".so" ) || strings .HasSuffix (arg , ".a" ) {
197
195
invocation .invokeType = invokedForLinking
@@ -221,15 +219,26 @@ func ParseCmdLineInvocation(daemon *Daemon, cwd string, cmdLine []string) (invoc
221
219
// There are two modes of finding dependencies:
222
220
// 1. Natively: invoke "cxx -M" (it invokes preprocessor only).
223
221
// 2. Own includes parser, which works much faster and theoretically should return the same (or a bit more) results.
224
- func (invocation * Invocation ) CollectDependentIncludes (disableOwnIncludes bool ) (hFiles []* IncludedFile , cppFile IncludedFile , err error ) {
222
+ func (invocation * Invocation ) CollectDependentIncludes (cwd string , disableOwnIncludes bool ) (hFiles []* IncludedFile , cppFile IncludedFile , err error ) {
223
+ cppInFileAbs := invocation .GetCppInFileAbs (cwd )
224
+
225
225
if disableOwnIncludes {
226
- return CollectDependentIncludesByCxxM (invocation .includesCache , invocation .cxxName , invocation . cppInFile , invocation .cxxArgs , invocation .cxxIDirs )
226
+ return CollectDependentIncludesByCxxM (invocation .includesCache , cwd , invocation .cxxName , cppInFileAbs , invocation .cxxArgs , invocation .cxxIDirs )
227
227
}
228
228
229
229
includeDirs := invocation .cxxIDirs
230
230
includeDirs .MergeWith (invocation .includesCache .cxxDefIDirs )
231
231
232
- return CollectDependentIncludesByOwnParser (invocation .includesCache , invocation .cppInFile , includeDirs )
232
+ return CollectDependentIncludesByOwnParser (invocation .includesCache , cppInFileAbs , includeDirs )
233
+ }
234
+
235
+ // GetCppInFileAbs returns an absolute path to invocation.cppInFile.
236
+ // (remember, that it's stored as-is from cmd line)
237
+ func (invocation * Invocation ) GetCppInFileAbs (cwd string ) string {
238
+ if invocation .cppInFile [0 ] == '/' {
239
+ return invocation .cppInFile
240
+ }
241
+ return cwd + "/" + invocation .cppInFile
233
242
}
234
243
235
244
func (invocation * Invocation ) DoneRecvObj (err error ) {
0 commit comments