GithubHelp home page GithubHelp logo

Wrong source file filtering when source directory contains a subdirectory with name ends with `Target.validSourceExtensions` about tuist HOT 5 OPEN

kyounh12 avatar kyounh12 commented on June 1, 2024
Wrong source file filtering when source directory contains a subdirectory with name ends with `Target.validSourceExtensions`

from tuist.

Comments (5)

fortmarek avatar fortmarek commented on June 1, 2024 1

I would probably do it directly in Target+Core.swift instead of providing a new option in the glob behavior.

from tuist.

fortmarek avatar fortmarek commented on June 1, 2024

Hey 👋

Yeah, that looks like a valid issue (I'm still being surprised every day by some of the decisions of package authors). Would you want to take a look?

I wouldn't fix this at the ProjectFileElements level but instead wherever we expand the source file glob, we should do a case-sensitive comparison. Before we do that, I'd double check how vanilla SPM works if a package has an actual Swift file called "MyFile.Swift`. Does it pick up? If so, then instead of doing a case sensitive comparison, we would need to check if a given path is a file or a directory.

from tuist.

danieleformichelli avatar danieleformichelli commented on June 1, 2024

Hey 👋

Yeah, that looks like a valid issue (I'm still being surprised every day by some of the decisions of package authors). Would you want to take a look?

I wouldn't fix this at the ProjectFileElements level but instead wherever we expand the source file glob, we should do a case-sensitive comparison. Before we do that, I'd double check how vanilla SPM works if a package has an actual Swift file called "MyFile.Swift`. Does it pick up? If so, then instead of doing a case sensitive comparison, we would need to check if a given path is a file or a directory.

Can't we check whether it's a file or a directory rather than relying on case?
not 100% sure, but I think Xcode/SPM also accepts upper case, at least for some extensions

from tuist.

fortmarek avatar fortmarek commented on June 1, 2024

Can't we check whether it's a file or a directory rather than relying on case? not 100% sure, but I think Xcode/SPM also accepts upper case, at least for some extensions

Yeah, we can, that's what I said we could also do 😄 I'm not sure how fast the isDirectory operation is because we would technically need to run it for every file, so even if it's fast, it could compound. But maybe it's fast enough that it wouldn't add to the generation time.

If SPM/Xcode pick up files with .Swift extension, then we can't rely on case-sensitive compare of the extension, yeah.

from tuist.

kyounh12 avatar kyounh12 commented on June 1, 2024
스크린샷 2024-04-15 오후 5 43 27

Looks like vanilla SPM accepts uppercased .Swift extension. So now we should check if the path is directory or a file.

I'm not sure which place would be the best to run the check.

  1. Add an extra guard statement below Target+Core.swift L:85 to filter out paths that are directories.
.filter { path in
    guard let `extension` = path.extension else { return false }
    guard !FileHandler.shared.isFolder(path) else { return false } // Adding this line solves the problem
    return Target.validSourceExtensions
        .contains(where: { $0.caseInsensitiveCompare(`extension`) == .orderedSame })
}
  1. Add behavior: Glob.Behavior parameter to throwingGlob function and pass a behavior with includesDirectoriesInResults set to false when getting paths from glob execution. ( Target+Core.swift L:75 )

I tested both implementations and all of them worked as expected

from tuist.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.