Skip to content

[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 #16929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,13 @@ def api_diff_data_file: Separate<["-"], "api-diff-data-file">,
HelpText<"API migration data is from <path>">,
MetaVarName<"<path>">;

def api_diff_data_dir: Separate<["-"], "api-diff-data-dir">,
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild,
ArgumentIsPath]>,
HelpText<"Load platform and version specific API migration data files from <path>. "
"Ignored if -api-diff-data-file is specified.">,
MetaVarName<"<path>">;

def dump_usr: Flag<["-"], "dump-usr">,
Flags<[FrontendOption, NoInteractiveOption]>,
HelpText<"Dump USR for each declaration reference">;
Expand Down
4 changes: 4 additions & 0 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ ToolChain::constructInvocation(const CompileJobAction &job,
Arguments.push_back("-api-diff-data-file");
Arguments.push_back(DataPath->getValue());
}
if (auto DataDir = context.Args.getLastArg(options::OPT_api_diff_data_dir)) {
Arguments.push_back("-api-diff-data-dir");
Arguments.push_back(DataDir->getValue());
}
if (context.Args.hasArg(options::OPT_dump_usr)) {
Arguments.push_back("-dump-usr");
}
Expand Down
14 changes: 10 additions & 4 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,9 +951,16 @@ static bool ParseMigratorArgs(MigratorOptions &Opts,
auto &Triple = LangOpts.Target;
bool isSwiftVersion3 = LangOpts.isSwiftVersion3();

llvm::SmallString<128> basePath;
if (auto DataDir = Args.getLastArg(OPT_api_diff_data_dir)) {
basePath = DataDir->getValue();
} else {
basePath = ResourcePath;
llvm::sys::path::append(basePath, "migrator");
}

bool Supported = true;
llvm::SmallString<128> dataPath(ResourcePath);
llvm::sys::path::append(dataPath, "migrator");
llvm::SmallString<128> dataPath(basePath);

if (Triple.isMacOSX())
llvm::sys::path::append(dataPath,
Expand All @@ -970,8 +977,7 @@ static bool ParseMigratorArgs(MigratorOptions &Opts,
else
Supported = false;
if (Supported) {
llvm::SmallString<128> authoredDataPath(ResourcePath);
llvm::sys::path::append(authoredDataPath, "migrator");
llvm::SmallString<128> authoredDataPath(basePath);
llvm::sys::path::append(authoredDataPath,
getScriptFileName("overlay", isSwiftVersion3));
// Add authored list first to take higher priority.
Expand Down
13 changes: 13 additions & 0 deletions test/Migrator/Inputs/api-diff-data-dir/ios3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "Rename",
"ChildIndex": "0",
"LeftUsr": "c:objc(cs)BarForwardDeclaredClass(im)barInstanceFunc1:anotherValue:anotherValue1:anotherValue2:",
"LeftComment": "",
"RightUsr": "",
"RightComment": "barNewSwift3InstanceFunc1(newlabel1:newlabel2:newlabel3:newlabel4:)",
"ModuleName": "bar"
}
]
13 changes: 13 additions & 0 deletions test/Migrator/Inputs/api-diff-data-dir/ios4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "Rename",
"ChildIndex": "0",
"LeftUsr": "c:objc(cs)BarForwardDeclaredClass(im)barInstanceFunc1:anotherValue:anotherValue1:anotherValue2:",
"LeftComment": "",
"RightUsr": "",
"RightComment": "barNewSwift4InstanceFunc1(newlabel1:newlabel2:newlabel3:newlabel4:)",
"ModuleName": "bar"
}
]
13 changes: 13 additions & 0 deletions test/Migrator/Inputs/api-diff-data-dir/macos3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "Rename",
"ChildIndex": "0",
"LeftUsr": "c:objc(cs)BarForwardDeclaredClass(im)barInstanceFunc1:anotherValue:anotherValue1:anotherValue2:",
"LeftComment": "",
"RightUsr": "",
"RightComment": "barNewSwift3InstanceFunc1(newlabel1:newlabel2:newlabel3:newlabel4:)",
"ModuleName": "bar"
}
]
13 changes: 13 additions & 0 deletions test/Migrator/Inputs/api-diff-data-dir/macos4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "Rename",
"ChildIndex": "0",
"LeftUsr": "c:objc(cs)BarForwardDeclaredClass(im)barInstanceFunc1:anotherValue:anotherValue1:anotherValue2:",
"LeftComment": "",
"RightUsr": "",
"RightComment": "barNewSwift4InstanceFunc1(newlabel1:newlabel2:newlabel3:newlabel4:)",
"ModuleName": "bar"
}
]
13 changes: 13 additions & 0 deletions test/Migrator/Inputs/api-diff-data-dir/overlay3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "Rename",
"ChildIndex": "0",
"LeftUsr": "c:@F@barGlobalFuncOldName",
"LeftComment": "",
"RightUsr": "",
"RightComment": "barGlobalFuncNewSwift3OverlayName(newlabel:)",
"ModuleName": "bar"
}
]
13 changes: 13 additions & 0 deletions test/Migrator/Inputs/api-diff-data-dir/overlay4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "Rename",
"ChildIndex": "0",
"LeftUsr": "c:@F@barGlobalFuncOldName",
"LeftComment": "",
"RightUsr": "",
"RightComment": "barGlobalFuncNewSwift4OverlayName(newlabel:)",
"ModuleName": "bar"
}
]
13 changes: 13 additions & 0 deletions test/Migrator/Inputs/api-diff-data-dir/tvos3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "Rename",
"ChildIndex": "0",
"LeftUsr": "c:objc(cs)BarForwardDeclaredClass(im)barInstanceFunc1:anotherValue:anotherValue1:anotherValue2:",
"LeftComment": "",
"RightUsr": "",
"RightComment": "barNewSwift3InstanceFunc1(newlabel1:newlabel2:newlabel3:newlabel4:)",
"ModuleName": "bar"
}
]
13 changes: 13 additions & 0 deletions test/Migrator/Inputs/api-diff-data-dir/tvos4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "Rename",
"ChildIndex": "0",
"LeftUsr": "c:objc(cs)BarForwardDeclaredClass(im)barInstanceFunc1:anotherValue:anotherValue1:anotherValue2:",
"LeftComment": "",
"RightUsr": "",
"RightComment": "barNewSwift4InstanceFunc1(newlabel1:newlabel2:newlabel3:newlabel4:)",
"ModuleName": "bar"
}
]
13 changes: 13 additions & 0 deletions test/Migrator/Inputs/api-diff-data-dir/watchos3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "Rename",
"ChildIndex": "0",
"LeftUsr": "c:objc(cs)BarForwardDeclaredClass(im)barInstanceFunc1:anotherValue:anotherValue1:anotherValue2:",
"LeftComment": "",
"RightUsr": "",
"RightComment": "barNewSwift3InstanceFunc1(newlabel1:newlabel2:newlabel3:newlabel4:)",
"ModuleName": "bar"
}
]
13 changes: 13 additions & 0 deletions test/Migrator/Inputs/api-diff-data-dir/watchos4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "Rename",
"ChildIndex": "0",
"LeftUsr": "c:objc(cs)BarForwardDeclaredClass(im)barInstanceFunc1:anotherValue:anotherValue1:anotherValue2:",
"LeftComment": "",
"RightUsr": "",
"RightComment": "barNewSwift4InstanceFunc1(newlabel1:newlabel2:newlabel3:newlabel4:)",
"ModuleName": "bar"
}
]
16 changes: 16 additions & 0 deletions test/Migrator/api-diff-data-dir.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// REQUIRES: objc_interop
// 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
// RUN: %FileCheck %s -input-file %t/api-diff-data-dir.swift.result -match-full-lines -check-prefix=SWIFT3
// 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
// RUN: %FileCheck %s -input-file %t/api-diff-data-dir.swift.result -match-full-lines -check-prefix=SWIFT4

import Bar

func foo(_ b: BarForwardDeclaredClass) {
b.barInstanceFunc1(0, anotherValue: 1, anotherValue1: 2, anotherValue2: 3)
// SWIFT3: b.barNewSwift3InstanceFunc1(newlabel1: 0, newlabel2: 1, newlabel3: 2, newlabel4: 3)
// SWIFT4: b.barNewSwift4InstanceFunc1(newlabel1: 0, newlabel2: 1, newlabel3: 2, newlabel4: 3)
barGlobalFuncOldName(2)
// SWIFT3: barGlobalFuncNewSwift3OverlayName(newlabel: 2)
// SWIFT4: barGlobalFuncNewSwift4OverlayName(newlabel: 2)
}