SwiftDate icon indicating copy to clipboard operation
SwiftDate copied to clipboard

RelativeFormatters don't work with Swift Package Manager

Open drewdeponte opened this issue 6 years ago • 15 comments

This is a side effect of Swift Package Manager not working with bundled resources. So, the Formatters/RelativeFormatter/langs/ various json files aren't included and therefore aren't accessible when using Swift Package Manager.

drewdeponte avatar Oct 08 '19 22:10 drewdeponte

Maybe it would be possible to bring these language mappings into the swift code so that it would work properly with Swift Package Manager?

drewdeponte avatar Oct 08 '19 23:10 drewdeponte

at least it should not crash :) ATM it crashing in suitableFlavour localeData.flavours[Flavour.long.rawValue].

RolandasRazma avatar Oct 10 '19 09:10 RolandasRazma

Gonna bump this. Is there a reason SwiftDate isn't working with bundled resources in SPM?

Sam-Spencer avatar Oct 16 '19 15:10 Sam-Spencer

Yeah, it is my understanding that SPM doesn't currently support having bundled resources.

drewdeponte avatar Oct 16 '19 22:10 drewdeponte

could some kindof "Run script" phase would help as a temp fix?

RolandasRazma avatar Oct 18 '19 08:10 RolandasRazma

I don’t believe so. My understanding is that the resource files need to be codified.

drewdeponte avatar Oct 18 '19 14:10 drewdeponte

Maybe if there was some script that you could tell the locales you wanted to support and it would copy the right codified files into place before the build. I am not sure how you would tie a script like this into the SPM build process. But might be worth looking into.

drewdeponte avatar Oct 18 '19 14:10 drewdeponte

I was more thinking about app "Build Phase" "Run Script" that you have to add manually as a workaround

RolandasRazma avatar Oct 18 '19 14:10 RolandasRazma

As stated by @drewdeponte why not take into consideration the move from json files into swift files? I don't know if it is possible to do that, but while we wait the implementation of bundled resources into SPM it may be one possible solution. Furthermore I agree on the fact that the library should not crash if can't find a particular locale. I would like the user to be able to choose which locales to include and have a default language in case some are missing.

rcasula avatar Oct 19 '19 06:10 rcasula

Update on SPM bundled resources: there is (as of this week) an official proposal now available for community comment.

Regardless, I agree with @robcas3 and @drewdeponte, the library shouldn't crash when a resource is missing. That seems like a doable fix.

Moving from those JSON files to Swift is quite the undertaking... Could that also hinder localization updates or additions?

Sam-Spencer avatar Oct 25 '19 17:10 Sam-Spencer

for now you can add new build phase at the end

# Go to the build root and search up the chain to find the Derived Data Path where the source packages are checked out.
DERIVED_DATA_CANDIDATE="${BUILD_ROOT}"

while ! [ -d "${DERIVED_DATA_CANDIDATE}/SourcePackages" ]; do
  if [ "${DERIVED_DATA_CANDIDATE}" = / ]; then
    echo >&2 "error: Unable to locate SourcePackages directory from BUILD_ROOT: '${BUILD_ROOT}'"
    exit 1
  fi

  DERIVED_DATA_CANDIDATE="$(dirname "${DERIVED_DATA_CANDIDATE}")"
done

# Grab a reference to the directory where langs are checked out
LANGS_PATH="${DERIVED_DATA_CANDIDATE}/SourcePackages/checkouts/SwiftDate/Sources/SwiftDate/Formatters/RelativeFormatter/langs"

if [ -z "${LANGS_PATH}" ]; then
    echo >&2 "error: Couldn't find the langs in your checked out SPM packages; make sure to add the framework to your project."
    exit 1
fi

cp -f -R "${LANGS_PATH}" "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app"

RolandasRazma avatar Nov 17 '19 23:11 RolandasRazma

I'm getting this error when running unit tests on Xcode 12, it seems to be related to the same issue:

Details:  Error: Mismatch between existing container extension: <DVTExtension 0x7fc7aa5a49d0: Swift Package Folder (Xcode.IDEFoundation.Container.SwiftPackageFolder) from com.apple.dt.IDE.IDESwiftPackageSupport> and requested container extension: <DVTExtension 0x7fc7ad1b6800: Folder (Xcode.IDEFoundation.Container.Folder) from com.apple.dt.IDEFoundation> for file path: <DVTFilePath:0x7fc7b1d824f0:'/Users/mkalatrash/Library/Developer/Xcode/DerivedData/Travel-bavpgrmwbxqafacvgowqxhoryoeq/SourcePackages/checkouts/SwiftDate/Sources/SwiftDate/Formatters/RelativeFormatter/langs'>
Object:   <IDEContainer>
Method:   +_retainedContainerAtFilePath:fileDataType:workspace:options:error:
Thread:   <NSThread: 0x7fc7ad207c60>{number = 1, name = main}
Hints:

If I run unit tests through Xcode it will crash, the above is from the command line. @RolandasRazma I did add the run script but it didn't work.

mohammad19991 avatar Sep 21 '20 10:09 mohammad19991

Should we just not attempt to use SPM with SwiftDate ? Or is it only an issue under certain scenarios ?

@mohammad19991 Xcode only crashed for me when I had code coverage on.

fatlazycat avatar Oct 19 '20 07:10 fatlazycat

@mohammad19991 script is for 6.1.0 version. 6.2.0 shouldn't need script but Xcode having problems...

RolandasRazma avatar Oct 19 '20 09:10 RolandasRazma

I closed #758 but is it a new issue ? I can compile and run using SPM and execute unit tests. When I attempt to get code coverage then Xcode just crashes.

Currently can work around getting code coverage by AppCode, if anyone has similar issue

fatlazycat avatar Oct 19 '20 09:10 fatlazycat