Skip to content
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

exclude files are included during a build #8156

Open
1 task done
luispadron opened this issue Dec 4, 2024 · 0 comments
Open
1 task done

exclude files are included during a build #8156

luispadron opened this issue Dec 4, 2024 · 0 comments
Labels

Comments

@luispadron
Copy link

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

  • Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands, swift build, swift test, swift package etc.

Description

It seems that files in exclude may not actually be ignored if they are part of a build. For example, a header file is marked in excludes but a source file that imports it is not excluded. Currently SPM successfully builds in this case even though the header file should be excluded from the build (at least what seems to be expected given exclude documentation).

Reproducing the issue

There are real examples of packages that have this issue: https://github.com/microsoft/plcrashreporter, this package excludes several .hpp files but the .cpp are not excluded, the build passes.

For a simple reproducible example the following works:

.
├── Package.swift
├── Source
│   ├── Example.h
│   ├── Example.mm
│   ├── Foo.cpp
│   └── Foo.hpp
└── include
    └── Example.h -> ../Source/Example.h
# Package.swift

// swift-tools-version: 5.10

import PackageDescription

let package = Package(
    name: "IgnoredExcludesExample",
    products: [
        .library(name: "Example", targets: ["Example"])
    ],
    targets: [
        .target(
            name: "Example",
            path: "",
            exclude: [
                "Source/Foo.hpp"
            ],
            sources: [
                "Source"
            ]
        )
    ]
)
// Example.h

#import <Foundation/Foundation.h>

@interface Example : NSObject

@end
// Example.mm

#import "Example.h"
#import "Foo.hpp"

@implementation Example

- (void)bar {
    Foo *foo = new Foo();
    foo->bar();
}

@end
// Foo.cpp

#include "Foo.hpp"

void Foo::bar() {

}
// Foo.hpp

#ifndef FOO_HPP
#define FOO_HPP

class Foo {
public:
    void bar();
};

#endif

Expected behavior

I'm not entirely sure how this is intended to work from the SPM side of things, it feels like this should be a failed build since the header is excluded. Or the documentation should be made clearer as to what exclude actually does.

Our use-case is over in https://github.com/cgrindel/rules_swift_package_manager where we generate BUILD files based on the Package.swift representation and we are currently excluding files from exclude which causes our Bazel builds to fail while SPM builds do not. We are more trying to understand what the expected behavior is here.

Actual behavior

exclude files are still able to be included as part of a swift build

Steps to reproduce

  1. Make example project like the one in this issue
  2. swift build passes
  3. Delete Source/Foo.hpp, swift build fails.

Swift Package Manager version/commit hash

Swift Package Manager - Swift 6.0.2-dev

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
Target: arm64-apple-macosx14.0
Darwin local 23.6.0 Darwin Kernel Version 23.6.0: Thu Sep 12 23:36:23 PDT 2024; root:xnu-10063.141.1.701.1~1/RELEASE_ARM64_T6031 arm64
@luispadron luispadron added the bug label Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant