20
20
#include " llvm/ADT/STLExtras.h"
21
21
#include " llvm/CAS/HierarchicalTreeBuilder.h"
22
22
#include " llvm/CAS/ObjectStore.h"
23
+ #include " llvm/Support/Error.h"
24
+ #include " llvm/Support/MemoryBuffer.h"
23
25
24
26
using namespace swift ;
25
27
@@ -30,29 +32,45 @@ llvm::Expected<llvm::cas::ObjectRef> swift::createCompileJobBaseCacheKey(
30
32
31
33
// TODO: Improve this list.
32
34
static const std::vector<std::string> removeArgAndNext = {
33
- " -o" , " -supplementary-output-file-map" , " -serialize-diagnostics-path" ,
34
- " -num-threads" , " -cas-path" };
35
+ " -o" ,
36
+ " -output-filelist" ,
37
+ " -supplementary-output-file-map" ,
38
+ " -index-unit-output-path" ,
39
+ " -index-unit-output-path-filelist" ,
40
+ " -serialize-diagnostics-path" ,
41
+ " -num-threads" ,
42
+ " -cas-path" };
35
43
36
44
// Don't count the `-frontend` in the first location since only frontend
37
45
// invocation can have a cache key.
38
46
if (Args.size () > 1 && StringRef (Args.front ()) == " -frontend" )
39
47
Args = Args.drop_front ();
40
48
41
- bool SkipNext = false ;
42
- for (StringRef Arg : Args) {
43
- if (SkipNext) {
44
- SkipNext = false ;
45
- continue ;
46
- }
49
+ for (unsigned I = 0 , IE =Args.size (); I < IE; ++I) {
50
+ StringRef Arg = Args[I];
47
51
if (llvm::is_contained (removeArgAndNext, Arg)) {
48
- SkipNext = true ;
52
+ ++I ;
49
53
continue ;
50
54
}
51
55
// FIXME: Use a heuristic to remove all the flags that affect output paths.
52
56
// Those should not affect compile cache key.
53
57
if (Arg.startswith (" -emit-" )) {
54
58
if (Arg.endswith (" -path" ))
55
- SkipNext = true ;
59
+ ++I;
60
+ continue ;
61
+ }
62
+ // Handle -file-list option. Need to drop the option but adds the file
63
+ // content instead.
64
+ // FIXME: will be nice if the same list of files gets the same key no matter
65
+ // going through command-line or filelist.
66
+ if (Arg == " -filelist" || Arg == " -primary-filelist" ) {
67
+ auto FileList = llvm::MemoryBuffer::getFile (Args[++I]);
68
+ if (!FileList)
69
+ return llvm::errorCodeToError (FileList.getError ());
70
+ CommandLine.append (Arg);
71
+ CommandLine.push_back (0 );
72
+ CommandLine.append ((*FileList)->getBuffer ());
73
+ CommandLine.push_back (0 );
56
74
continue ;
57
75
}
58
76
CommandLine.append (Arg);
0 commit comments