Skip to content

Update Driver to generate package interface only if package-name is p… #70282

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
merged 1 commit into from
Dec 8, 2023
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
6 changes: 4 additions & 2 deletions lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2348,7 +2348,8 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
C.createAction<VerifyModuleInterfaceJobAction>(MergeModuleAction,
file_types::TY_PrivateSwiftModuleInterfaceFile));
}
if (Args.hasArgNoClaim(options::OPT_emit_package_module_interface_path)) {
if (Args.hasArg(options::OPT_package_name) &&
Args.hasArgNoClaim(options::OPT_emit_package_module_interface_path)) {
TopLevelActions.push_back(
C.createAction<VerifyModuleInterfaceJobAction>(MergeModuleAction,
file_types::TY_PackageSwiftModuleInterfaceFile));
Expand Down Expand Up @@ -2995,7 +2996,8 @@ Job *Driver::buildJobsForAction(Compilation &C, const JobAction *JA,
chooseModuleInterfacePath(C, JA, workingDirectory, Buf,
file_types::TY_PrivateSwiftModuleInterfaceFile, Output.get());

if (C.getArgs().hasArg(options::OPT_emit_package_module_interface_path))
if (C.getArgs().hasArg(options::OPT_package_name) &&
C.getArgs().hasArg(options::OPT_emit_package_module_interface_path))
chooseModuleInterfacePath(C, JA, workingDirectory, Buf,
file_types::TY_PackageSwiftModuleInterfaceFile, Output.get());

Expand Down
38 changes: 38 additions & 0 deletions test/ModuleInterface/package_interface_conditional_gen.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// RUN: %empty-directory(%t)
// RUN: split-file %s %t

/// A package swiftinterface should be generated only if -package-name is passed.
// RUN: %target-build-swift -emit-module %t/Bar.swift -I %t \
// RUN: -module-name Bar -package-name foopkg \
// RUN: -enable-library-evolution -swift-version 5 \
// RUN: -emit-module-interface-path %t/Bar.swiftinterface \
// RUN: -emit-package-module-interface-path %t/Bar.package.swiftinterface

// RUN: %FileCheck %s < %t/Bar.package.swiftinterface
// CHECK: -package-name foopkg
// CHECK: public struct PubStruct
// CHECK: package struct PkgStruct

/// If -package-name is not passed, a package interface should not be generated even if
/// `-emit-package-module-interface-path` is passed.
// RUN: %target-build-swift -emit-module %t/Baz.swift -I %t \
// RUN: -module-name Baz \
// RUN: -enable-library-evolution -swift-version 5 \
// RUN: -emit-module-interface-path %t/Baz.swiftinterface \
// RUN: -emit-package-module-interface-path %t/Baz.package.swiftinterface

// RUN: ls %t | not grep "Baz.package.swiftinterface"

//--- Bar.swift
public struct PubStruct {

}

package struct PkgStruct {

}

//--- Baz.swift
public struct PubStruct {

}