Skip to content

Commit c5278f5

Browse files
Merge pull request #79779 from cachemeifyoucan/eng/PR-146155049
[Caching] Mark `-emit-module-source-info-path` as CacheInvariant
2 parents a870e25 + ae69713 commit c5278f5

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

include/swift/Option/Options.td

+2-2
Original file line numberDiff line numberDiff line change
@@ -730,12 +730,12 @@ def avoid_emit_module_source_info :
730730
def emit_module_source_info_path :
731731
Separate<["-"], "emit-module-source-info-path">,
732732
Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath,
733-
SupplementaryOutput]>,
733+
SupplementaryOutput, CacheInvariant]>,
734734
MetaVarName<"<path>">, HelpText<"Output module source info file to <path>">;
735735
def emit_variant_module_source_info_path :
736736
Separate<["-"], "emit-variant-module-source-info-path">,
737737
Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath,
738-
SupplementaryOutput, NewDriverOnlyOption]>,
738+
SupplementaryOutput, NewDriverOnlyOption, CacheInvariant]>,
739739
MetaVarName<"<path>">, HelpText<"Output module source info file for the target variant to <path>">;
740740

741741
def emit_parseable_module_interface :

unittests/Basic/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ add_swift_unittest(SwiftBasicTests
2424
ImmutablePointerSetTest.cpp
2525
JSONSerialization.cpp
2626
OptionSetTest.cpp
27+
Options.cpp
2728
OwnedStringTest.cpp
2829
MultiMapCacheTest.cpp
2930
PointerIntEnumTest.cpp
@@ -48,8 +49,10 @@ add_dependencies(SwiftBasicTests "${gyb_dependency_targets}")
4849
target_link_libraries(SwiftBasicTests
4950
PRIVATE
5051
swiftBasic
52+
swiftOption
5153
swiftThreading
5254
clangBasic
55+
LLVMOption
5356
LLVMTestingSupport
5457
)
5558

unittests/Basic/Options.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===--- Options.cpp ------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "swift/Option/Options.h"
14+
#include "llvm/Option/Option.h"
15+
#include "gtest/gtest.h"
16+
17+
using namespace swift;
18+
using namespace swift::options;
19+
20+
TEST(Options, outputPathCacheInvariant) {
21+
auto optTable = createSwiftOptTable();
22+
// 0 is OP_INVALD
23+
for (auto id = 1; id < LastOption; ++id) {
24+
auto opt = optTable->getOption(id);
25+
// Only check the flag accepted by swift-frontend.
26+
if (!opt.hasFlag(SwiftFlags::FrontendOption))
27+
continue;
28+
29+
// The following two options are only accepted by migrator.
30+
if (id == OPT_emit_migrated_file_path || id == OPT_emit_remap_file_path)
31+
continue;
32+
33+
auto name = opt.getName();
34+
// Check that if a flag matches the convention `-emit-*-path{=}`, it should
35+
// be a path to an output file and should be marked as cache invariant.
36+
if (name.starts_with("emit") &&
37+
(name.ends_with("-path") || name.ends_with("-path=")))
38+
ASSERT_TRUE(opt.hasFlag(SwiftFlags::CacheInvariant));
39+
}
40+
}

0 commit comments

Comments
 (0)