Skip to content

Commit 57940b7

Browse files
author
Nathan Hawes
authored
Merge pull request #16929 from nathawes/add-api-diff-data-dir-option-for-migrator-testing-4.2
[4.2][migrator] Add -api-diff-data-dir option to override the default location for the migrator's platform + version specific api diff json files
2 parents 129a0f1 + 2a05e6f commit 57940b7

File tree

14 files changed

+167
-4
lines changed

14 files changed

+167
-4
lines changed

include/swift/Option/Options.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,13 @@ def api_diff_data_file: Separate<["-"], "api-diff-data-file">,
545545
HelpText<"API migration data is from <path>">,
546546
MetaVarName<"<path>">;
547547

548+
def api_diff_data_dir: Separate<["-"], "api-diff-data-dir">,
549+
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild,
550+
ArgumentIsPath]>,
551+
HelpText<"Load platform and version specific API migration data files from <path>. "
552+
"Ignored if -api-diff-data-file is specified.">,
553+
MetaVarName<"<path>">;
554+
548555
def dump_usr: Flag<["-"], "dump-usr">,
549556
Flags<[FrontendOption, NoInteractiveOption]>,
550557
HelpText<"Dump USR for each declaration reference">;

lib/Driver/ToolChains.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ ToolChain::constructInvocation(const CompileJobAction &job,
267267
Arguments.push_back("-api-diff-data-file");
268268
Arguments.push_back(DataPath->getValue());
269269
}
270+
if (auto DataDir = context.Args.getLastArg(options::OPT_api_diff_data_dir)) {
271+
Arguments.push_back("-api-diff-data-dir");
272+
Arguments.push_back(DataDir->getValue());
273+
}
270274
if (context.Args.hasArg(options::OPT_dump_usr)) {
271275
Arguments.push_back("-dump-usr");
272276
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -951,9 +951,16 @@ static bool ParseMigratorArgs(MigratorOptions &Opts,
951951
auto &Triple = LangOpts.Target;
952952
bool isSwiftVersion3 = LangOpts.isSwiftVersion3();
953953

954+
llvm::SmallString<128> basePath;
955+
if (auto DataDir = Args.getLastArg(OPT_api_diff_data_dir)) {
956+
basePath = DataDir->getValue();
957+
} else {
958+
basePath = ResourcePath;
959+
llvm::sys::path::append(basePath, "migrator");
960+
}
961+
954962
bool Supported = true;
955-
llvm::SmallString<128> dataPath(ResourcePath);
956-
llvm::sys::path::append(dataPath, "migrator");
963+
llvm::SmallString<128> dataPath(basePath);
957964

958965
if (Triple.isMacOSX())
959966
llvm::sys::path::append(dataPath,
@@ -970,8 +977,7 @@ static bool ParseMigratorArgs(MigratorOptions &Opts,
970977
else
971978
Supported = false;
972979
if (Supported) {
973-
llvm::SmallString<128> authoredDataPath(ResourcePath);
974-
llvm::sys::path::append(authoredDataPath, "migrator");
980+
llvm::SmallString<128> authoredDataPath(basePath);
975981
llvm::sys::path::append(authoredDataPath,
976982
getScriptFileName("overlay", isSwiftVersion3));
977983
// Add authored list first to take higher priority.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"DiffItemKind": "CommonDiffItem",
4+
"NodeKind": "Function",
5+
"NodeAnnotation": "Rename",
6+
"ChildIndex": "0",
7+
"LeftUsr": "c:objc(cs)BarForwardDeclaredClass(im)barInstanceFunc1:anotherValue:anotherValue1:anotherValue2:",
8+
"LeftComment": "",
9+
"RightUsr": "",
10+
"RightComment": "barNewSwift3InstanceFunc1(newlabel1:newlabel2:newlabel3:newlabel4:)",
11+
"ModuleName": "bar"
12+
}
13+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"DiffItemKind": "CommonDiffItem",
4+
"NodeKind": "Function",
5+
"NodeAnnotation": "Rename",
6+
"ChildIndex": "0",
7+
"LeftUsr": "c:objc(cs)BarForwardDeclaredClass(im)barInstanceFunc1:anotherValue:anotherValue1:anotherValue2:",
8+
"LeftComment": "",
9+
"RightUsr": "",
10+
"RightComment": "barNewSwift4InstanceFunc1(newlabel1:newlabel2:newlabel3:newlabel4:)",
11+
"ModuleName": "bar"
12+
}
13+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"DiffItemKind": "CommonDiffItem",
4+
"NodeKind": "Function",
5+
"NodeAnnotation": "Rename",
6+
"ChildIndex": "0",
7+
"LeftUsr": "c:objc(cs)BarForwardDeclaredClass(im)barInstanceFunc1:anotherValue:anotherValue1:anotherValue2:",
8+
"LeftComment": "",
9+
"RightUsr": "",
10+
"RightComment": "barNewSwift3InstanceFunc1(newlabel1:newlabel2:newlabel3:newlabel4:)",
11+
"ModuleName": "bar"
12+
}
13+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"DiffItemKind": "CommonDiffItem",
4+
"NodeKind": "Function",
5+
"NodeAnnotation": "Rename",
6+
"ChildIndex": "0",
7+
"LeftUsr": "c:objc(cs)BarForwardDeclaredClass(im)barInstanceFunc1:anotherValue:anotherValue1:anotherValue2:",
8+
"LeftComment": "",
9+
"RightUsr": "",
10+
"RightComment": "barNewSwift4InstanceFunc1(newlabel1:newlabel2:newlabel3:newlabel4:)",
11+
"ModuleName": "bar"
12+
}
13+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"DiffItemKind": "CommonDiffItem",
4+
"NodeKind": "Function",
5+
"NodeAnnotation": "Rename",
6+
"ChildIndex": "0",
7+
"LeftUsr": "c:@F@barGlobalFuncOldName",
8+
"LeftComment": "",
9+
"RightUsr": "",
10+
"RightComment": "barGlobalFuncNewSwift3OverlayName(newlabel:)",
11+
"ModuleName": "bar"
12+
}
13+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"DiffItemKind": "CommonDiffItem",
4+
"NodeKind": "Function",
5+
"NodeAnnotation": "Rename",
6+
"ChildIndex": "0",
7+
"LeftUsr": "c:@F@barGlobalFuncOldName",
8+
"LeftComment": "",
9+
"RightUsr": "",
10+
"RightComment": "barGlobalFuncNewSwift4OverlayName(newlabel:)",
11+
"ModuleName": "bar"
12+
}
13+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"DiffItemKind": "CommonDiffItem",
4+
"NodeKind": "Function",
5+
"NodeAnnotation": "Rename",
6+
"ChildIndex": "0",
7+
"LeftUsr": "c:objc(cs)BarForwardDeclaredClass(im)barInstanceFunc1:anotherValue:anotherValue1:anotherValue2:",
8+
"LeftComment": "",
9+
"RightUsr": "",
10+
"RightComment": "barNewSwift3InstanceFunc1(newlabel1:newlabel2:newlabel3:newlabel4:)",
11+
"ModuleName": "bar"
12+
}
13+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"DiffItemKind": "CommonDiffItem",
4+
"NodeKind": "Function",
5+
"NodeAnnotation": "Rename",
6+
"ChildIndex": "0",
7+
"LeftUsr": "c:objc(cs)BarForwardDeclaredClass(im)barInstanceFunc1:anotherValue:anotherValue1:anotherValue2:",
8+
"LeftComment": "",
9+
"RightUsr": "",
10+
"RightComment": "barNewSwift4InstanceFunc1(newlabel1:newlabel2:newlabel3:newlabel4:)",
11+
"ModuleName": "bar"
12+
}
13+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"DiffItemKind": "CommonDiffItem",
4+
"NodeKind": "Function",
5+
"NodeAnnotation": "Rename",
6+
"ChildIndex": "0",
7+
"LeftUsr": "c:objc(cs)BarForwardDeclaredClass(im)barInstanceFunc1:anotherValue:anotherValue1:anotherValue2:",
8+
"LeftComment": "",
9+
"RightUsr": "",
10+
"RightComment": "barNewSwift3InstanceFunc1(newlabel1:newlabel2:newlabel3:newlabel4:)",
11+
"ModuleName": "bar"
12+
}
13+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"DiffItemKind": "CommonDiffItem",
4+
"NodeKind": "Function",
5+
"NodeAnnotation": "Rename",
6+
"ChildIndex": "0",
7+
"LeftUsr": "c:objc(cs)BarForwardDeclaredClass(im)barInstanceFunc1:anotherValue:anotherValue1:anotherValue2:",
8+
"LeftComment": "",
9+
"RightUsr": "",
10+
"RightComment": "barNewSwift4InstanceFunc1(newlabel1:newlabel2:newlabel3:newlabel4:)",
11+
"ModuleName": "bar"
12+
}
13+
]

test/Migrator/api-diff-data-dir.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// REQUIRES: objc_interop
2+
// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -swift-version 3 -primary-file %s -F %S/mock-sdk -api-diff-data-dir %S/Inputs/api-diff-data-dir -emit-migrated-file-path %t/api-diff-data-dir.swift.result -emit-remap-file-path %t/api-diff-data-dir.swift.remap -o /dev/null
3+
// RUN: %FileCheck %s -input-file %t/api-diff-data-dir.swift.result -match-full-lines -check-prefix=SWIFT3
4+
// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -swift-version 4 -primary-file %s -F %S/mock-sdk -api-diff-data-dir %S/Inputs/api-diff-data-dir -emit-migrated-file-path %t/api-diff-data-dir.swift.result -emit-remap-file-path %t/api-diff-data-dir.swift.remap -o /dev/null
5+
// RUN: %FileCheck %s -input-file %t/api-diff-data-dir.swift.result -match-full-lines -check-prefix=SWIFT4
6+
7+
import Bar
8+
9+
func foo(_ b: BarForwardDeclaredClass) {
10+
b.barInstanceFunc1(0, anotherValue: 1, anotherValue1: 2, anotherValue2: 3)
11+
// SWIFT3: b.barNewSwift3InstanceFunc1(newlabel1: 0, newlabel2: 1, newlabel3: 2, newlabel4: 3)
12+
// SWIFT4: b.barNewSwift4InstanceFunc1(newlabel1: 0, newlabel2: 1, newlabel3: 2, newlabel4: 3)
13+
barGlobalFuncOldName(2)
14+
// SWIFT3: barGlobalFuncNewSwift3OverlayName(newlabel: 2)
15+
// SWIFT4: barGlobalFuncNewSwift4OverlayName(newlabel: 2)
16+
}

0 commit comments

Comments
 (0)