Skip to content

Commit 82eef75

Browse files
committed
Guard with env var SWIFT_ENABLE_PACKAGE_INTERFACE_LOAD
Update tests and formatting
1 parent 0f3625b commit 82eef75

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,9 +633,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
633633
Opts.EnableExperimentalStringProcessing = true;
634634
}
635635

636-
if (Args.hasArg(OPT_experimental_package_interface_load)) {
637-
Opts.EnablePackageInterfaceLoad = true;
638-
}
636+
// Either the env var and the flag has to be set to enable package interface load
637+
Opts.EnablePackageInterfaceLoad = Args.hasArg(OPT_experimental_package_interface_load) ||
638+
::getenv("SWIFT_ENABLE_PACKAGE_INTERFACE_LOAD");
639639

640640
// Experimental string processing.
641641
if (auto A = Args.getLastArg(OPT_enable_experimental_string_processing,

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,9 @@ std::string SerializedModuleBaseName::getName(file_types::ID fileTy) const {
596596
return std::string(result.str());
597597
}
598598

599-
llvm::Optional<std::string> SerializedModuleBaseName::getPackageInterfacePathIfInSamePackage(llvm::vfs::FileSystem &fs, ASTContext &ctx) const {
600-
599+
llvm::Optional<std::string>
600+
SerializedModuleBaseName::getPackageInterfacePathIfInSamePackage(llvm::vfs::FileSystem &fs,
601+
ASTContext &ctx) const {
601602
if (!ctx.LangOpts.EnablePackageInterfaceLoad)
602603
return {};
603604

test/ModuleInterface/package_interface.swift

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,33 @@
2121
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
2222
// RUN: -package-name barpkg \
2323
// RUN: -experimental-package-interface-load \
24-
// RUN: -Rmodule-loading 2> %t/load-pkg-enabled.output
25-
// RUN: %FileCheck -check-prefix=CHECK-LOAD-PKG-ENABLED %s < %t/load-pkg-enabled.output
26-
// CHECK-LOAD-PKG-ENABLED: loaded module 'Bar'; source: '{{.*}}/Bar.package.swiftinterface', loaded: '{{.*}}/Bar-{{.*}}.swiftmodule'
24+
// RUN: -Rmodule-loading 2> %t/load-pkg-flag.output
25+
// RUN: %FileCheck -check-prefix=CHECK-LOAD-PKG-ENABLED %s < %t/load-pkg-flag.output
2726

28-
/// Client should not load a package interface module without -experimental-package-interface-load
27+
/// Client should load a package interface module if enabled with env var `SWIFT_ENABLE_PACKAGE_INTERFACE_LOAD`
28+
// RUN: env SWIFT_ENABLE_PACKAGE_INTERFACE_LOAD=true \
29+
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
30+
// RUN: -package-name barpkg \
31+
// RUN: -Rmodule-loading 2> %t/load-pkg-env-var.output
32+
// RUN: %FileCheck -check-prefix=CHECK-LOAD-PKG-ENABLED %s < %t/load-pkg-env-var.output
33+
34+
// CHECK-LOAD-PKG-ENABLED: loaded module 'Bar'; source: '{{.*}}Bar.package.swiftinterface', loaded: '{{.*}}Bar-{{.*}}.swiftmodule'
35+
36+
/// Client should not load a package interface module without the flag or the env var
2937
// RUN: not %target-swift-frontend -typecheck %t/Client.swift -I %t \
3038
// RUN: -package-name barpkg \
3139
// RUN: -Rmodule-loading 2> %t/load-pkg-off.output
3240
// RUN: %FileCheck -check-prefix=CHECK-LOAD-PKG-OFF %s < %t/load-pkg-off.output
33-
// CHECK-LOAD-PKG-OFF: loaded module 'Bar'; source: '{{.*}}/Bar.private.swiftinterface', loaded: '{{.*}}/Bar-{{.*}}.swiftmodule'
34-
// CHECK-LOAD-PKG-OFF: error: module 'Bar' is in package 'barpkg' but was built from a non-package interface; modules of the same package can only be loaded if built from source or package interface: {{.*}}/Bar.private.swiftinterface
41+
// CHECK-LOAD-PKG-OFF: loaded module 'Bar'; source: '{{.*}}Bar.private.swiftinterface', loaded: '{{.*}}Bar-{{.*}}.swiftmodule'
42+
// CHECK-LOAD-PKG-OFF: error: module 'Bar' is in package 'barpkg' but was built from a non-package interface; modules of the same package can only be loaded if built from source or package interface: {{.*}}Bar.private.swiftinterface
3543

3644
/// Client loads a private interface since the package-name is different from the loaded module's.
3745
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
3846
// RUN: -package-name foopkg \
3947
// RUN: -experimental-package-interface-load \
4048
// RUN: -Rmodule-loading 2> %t/load-diff-pkg.output
4149
// RUN: %FileCheck -check-prefix=CHECK-LOAD-DIFF-PKG %s < %t/load-diff-pkg.output
42-
// CHECK-LOAD-DIFF-PKG: loaded module 'Bar'; source: '{{.*}}/Bar.private.swiftinterface', loaded: '{{.*}}/Bar-{{.*}}.swiftmodule'
50+
// CHECK-LOAD-DIFF-PKG: loaded module 'Bar'; source: '{{.*}}Bar.private.swiftinterface', loaded: '{{.*}}Bar-{{.*}}.swiftmodule'
4351

4452
// RUN: rm -rf %t/*.swiftmodule
4553
// RUN: rm -rf %t/Bar.package.swiftinterface
@@ -50,8 +58,8 @@
5058
// RUN: -experimental-package-interface-load \
5159
// RUN: -Rmodule-loading 2> %t/load-priv.output
5260
// RUN: %FileCheck -check-prefix=CHECK-LOAD-PRIV %s < %t/load-priv.output
53-
// CHECK-LOAD-PRIV: loaded module 'Bar'; source: '{{.*}}/Bar.private.swiftinterface', loaded: '{{.*}}/Bar-{{.*}}.swiftmodule'
54-
// CHECK-LOAD-PRIV: error: module 'Bar' is in package 'barpkg' but was built from a non-package interface; modules of the same package can only be loaded if built from source or package interface: {{.*}}/Bar.private.swiftinterface
61+
// CHECK-LOAD-PRIV: loaded module 'Bar'; source: '{{.*}}Bar.private.swiftinterface', loaded: '{{.*}}Bar-{{.*}}.swiftmodule'
62+
// CHECK-LOAD-PRIV: error: module 'Bar' is in package 'barpkg' but was built from a non-package interface; modules of the same package can only be loaded if built from source or package interface: {{.*}}Bar.private.swiftinterface
5563

5664
// RUN: rm -rf %t/*.swiftmodule
5765
// RUN: rm -rf %t/Bar.private.swiftinterface
@@ -64,8 +72,8 @@
6472
// RUN: -Rmodule-loading 2> %t/load-pub.output
6573

6674
// RUN: %FileCheck -check-prefix=CHECK-LOAD-PUB %s < %t/load-pub.output
67-
// CHECK-LOAD-PUB: loaded module 'Bar'; source: '{{.*}}/Bar.swiftinterface', loaded: '{{.*}}/Bar-{{.*}}.swiftmodule'
68-
// CHECK-LOAD-PUB: error: module 'Bar' is in package 'barpkg' but was built from a non-package interface; modules of the same package can only be loaded if built from source or package interface: {{.*}}/Bar.swiftinterface
75+
// CHECK-LOAD-PUB: loaded module 'Bar'; source: '{{.*}}Bar.swiftinterface', loaded: '{{.*}}Bar-{{.*}}.swiftmodule'
76+
// CHECK-LOAD-PUB: error: module 'Bar' is in package 'barpkg' but was built from a non-package interface; modules of the same package can only be loaded if built from source or package interface: {{.*}}Bar.swiftinterface
6977

7078

7179
//--- Bar.swift

0 commit comments

Comments
 (0)