Skip to content

Commit 42b22fb

Browse files
author
Nathan Hawes
committed
[migrator] Add -api-diff-data-dir option to override the default location for the migrator's platform + version specific api diff json files
This is useful for testing the migrator with different versions of the api diff data.
1 parent 4b037e2 commit 42b22fb

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
@@ -266,6 +266,10 @@ ToolChain::constructInvocation(const CompileJobAction &job,
266266
Arguments.push_back("-api-diff-data-file");
267267
Arguments.push_back(DataPath->getValue());
268268
}
269+
if (auto DataDir = context.Args.getLastArg(options::OPT_api_diff_data_dir)) {
270+
Arguments.push_back("-api-diff-data-dir");
271+
Arguments.push_back(DataDir->getValue());
272+
}
269273
if (context.Args.hasArg(options::OPT_dump_usr)) {
270274
Arguments.push_back("-dump-usr");
271275
}

lib/Frontend/CompilerInvocation.cpp

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

959+
llvm::SmallString<128> basePath;
960+
if (auto DataDir = Args.getLastArg(OPT_api_diff_data_dir)) {
961+
basePath = DataDir->getValue();
962+
} else {
963+
basePath = ResourcePath;
964+
llvm::sys::path::append(basePath, "migrator");
965+
}
966+
959967
bool Supported = true;
960-
llvm::SmallString<128> dataPath(ResourcePath);
961-
llvm::sys::path::append(dataPath, "migrator");
968+
llvm::SmallString<128> dataPath(basePath);
962969

963970
if (Triple.isMacOSX())
964971
llvm::sys::path::append(dataPath,
@@ -975,8 +982,7 @@ static bool ParseMigratorArgs(MigratorOptions &Opts,
975982
else
976983
Supported = false;
977984
if (Supported) {
978-
llvm::SmallString<128> authoredDataPath(ResourcePath);
979-
llvm::sys::path::append(authoredDataPath, "migrator");
985+
llvm::SmallString<128> authoredDataPath(basePath);
980986
llvm::sys::path::append(authoredDataPath,
981987
getScriptFileName("overlay", isSwiftVersion3));
982988
// 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)