JiriTrecak / Laurine

Laurine - Localization code generator written in Swift. Sweet!
MIT License
1.25k stars 77 forks source link

Xcode 10.2 error #67

Open emilpedersen opened 5 years ago

emilpedersen commented 5 years ago

I get this error when running in Xcode 10.2 - Swift 4.2

0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret /Users/emil/Virksomheder/Projekter/sense-ios/Sense/Sense/Libraries/LaurineGenerator.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -module-name LaurineGenerator -- -i /Users/emil/Virksomheder/Projekter/sense-ios/Sense/Sense/Assets/en.lproj/Localizable.strings -o /Users/emil/Virksomheder/Projekter/sense-ios/Sense/Sense/Helpers/Localizations.swift -c true 0 swift 0x00000001080cfee3 PrintStackTraceSignalHandler(void*) + 51 1 swift 0x00000001080cf6bc SignalHandler(int) + 348 2 libsystem_platform.dylib 0x00007fff71114b5d _sigtramp + 29 3 libsystem_platform.dylib 000000000000000000 _sigtramp + 2398008512 4 libswiftCore.dylib 0x00007fff70959c09 _swift_updateClassMetadataImpl(swift::TargetClassMetadata<swift::InProcess>*, swift::ClassLayoutFlags, unsigned long, swift::TypeLayout const* const*, unsigned long*, bool) + 265 5 libswiftCore.dylib 0x00007fff70959c4b swift_updateClassMetadata2 + 27 6 libswiftCore.dylib 0x000000010b1d14ce swift_updateClassMetadata2 + 2592569502 7 libswiftCore.dylib 0x00007fff70961b77 swift::MetadataCacheEntryBase<(anonymous namespace)::SingletonMetadataCacheEntry, int>::doInitialization(swift::ConcurrencyControl&, swift::MetadataCompletionQueueEntry*, swift::MetadataRequest) + 215 8 libswiftCore.dylib 0x00007fff709573f3 swift_getSingletonMetadata + 579 9 libswiftCore.dylib 0x000000010b1b01af swift_getSingletonMetadata + 2592444415 10 libswiftCore.dylib 0x000000010b1b013c swift_getSingletonMetadata + 2592444300 11 swift 0x000000010496719d llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 365 12 swift 0x000000010496d572 llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, char const* const*) + 1090 13 swift 0x0000000103f365d1 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 58913 14 swift 0x0000000103f246de swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6862 15 swift 0x0000000103ec27be main + 1246 16 libdyld.dylib 0x00007fff70f2f3d5 start + 1 /Users/emil/Library/Developer/Xcode/DerivedData/Sense-amrxbuahpzprwaepprxlnxrnivph/Build/Intermediates.noindex/Sense.build/Debug-iphoneos/Sense.build/Script-FD357AEE20B807A500F1DB2E.sh: line 27: 6297 Segmentation fault: 11 "$LAURINE_PATH" -i "$SOURCE_PATH" -o "$OUTPUT_PATH" -c true Command PhaseScriptExecution failed with a nonzero exit code

lch88 commented 5 years ago

Same here.

I've been running the laurine script in swift 5.

daaa57150 commented 5 years ago

Same here after updating the OS.

It's weird because we tried to debug the script by integrating it in a macos command line project and feeding it the parameters directly, and this worked no problem. We tried swift version 4, 4.2 and 5, they all worked.

It fails only as a script in the build phases or from the command line swift LaurineGenerator.swift -i Localizable.strings -c -o Localizations.swift (our paths are more complicated than that in reality)

emilpedersen commented 5 years ago

I downloaded Xcode 10.1. In Xcode changed Command Line Tools to Xcode 10.1. With that setting I can run swift LaurineGenerator.swift -i Localizable.strings -c -o Localizations.swift in Terminal and it creates the Localizations.swift file fine. I use that as a workaround right now.

ppth0608 commented 5 years ago

Same here :)

mflint commented 5 years ago

Hello, this seems to be because Laurine is being run as a script; if you compile it to an executable in a separate step, then it's fine:

Here's my updated Run Script build phase:

set -x

# Get base path to project
BASE_PATH="$PROJECT_DIR/$PROJECT_NAME"

#--------- START OF YOUR CONFIGURATION (change Path_To_.. to fit)

# Get path to Laurine Generator script its the binary
LAURINE_PATH="$BASE_PATH/../scripts/LaurineGenerator.swift"
LAURINE_BIN_PATH="$BASE_PATH/../bin/laurine"

# Get path to main localization file (usually english).
SOURCE_PATH="$BASE_PATH/Base.lproj/Localizable.strings"

# Get path to output. If you use ObjC version of output, set implementation file (.m), as header will be generated automatically
OUTPUT_PATH="$BASE_PATH/Localizations.swift"

#--------- END OF YOUR CONFIGURATION

# Build laurine binary if necessary
if [ ! -f $LAURINE_BIN_PATH ]; then
env -i swiftc -emit-executable -o$LAURINE_BIN_PATH $LAURINE_PATH
fi

# Actually generate output. -- CUSTOMIZE -- parameters to your needs (see documentation).
# Will only re-generate script if something changed
if [ "$OUTPUT_PATH" -ot "$SOURCE_PATH" ]; then
"$LAURINE_BIN_PATH" -i "$SOURCE_PATH" -c -o "$OUTPUT_PATH"
fi

(env -i forces swiftc to run without Xcode environment variables - otherwise it tries to build an ARM binary)

cc @emilpedersen @lch88 @daaa57150 @ppth0608

alecmontgomery commented 5 years ago

Thanks mflint! It worked. I added mkdir -p $PROJECT_DIR/../Tools/Laurine/bin/ before # Build laurine binary if necessary to suppress an error about the bin directory not existing...

hypnotic commented 5 years ago

@emilpedersen @alecmontgomery Can any of you post you full script here please? I can't get it to work. Thanks. Meanwhile I have 10.1 version to run Laurine script only and work with 10.2 because my device is already in that version.

hypnotic commented 5 years ago

Just to be clear, and based on @mflint and @alecmontgomery comments, here is the complete code:

set -x

# Get base path to project
BASE_PATH="$PROJECT_DIR/$PROJECT_NAME"

#--------- START OF YOUR CONFIGURATION (change Path_To_.. to fit)

# Get path to Laurine Generator script its the binary
LAURINE_PATH="$BASE_PATH/LaurineGenerator.swift"
LAURINE_BIN_PATH="$BASE_PATH/../bin/laurine"

# Get path to main localization file (usually english).
SOURCE_PATH="$BASE_PATH/App/Base.lproj/Localizable.strings"

# Get path to output. If you use ObjC version of output, set implementation file (.m), as header will be generated automatically
OUTPUT_PATH="$BASE_PATH/App/Localizations.swift"

#--------- END OF YOUR CONFIGURATION

mkdir -p $LAURINE_BIN_PATH

# Build laurine binary if necessary
if [ ! -f $LAURINE_BIN_PATH ]; then
env -i swiftc -emit-executable -o$LAURINE_BIN_PATH $LAURINE_PATH
fi

# Actually generate output. -- CUSTOMIZE -- parameters to your needs (see documentation).
# Will only re-generate script if something changed
if [ "$OUTPUT_PATH" -ot "$SOURCE_PATH" ]; then
"$LAURINE_BIN_PATH" -i "$SOURCE_PATH" -c -o "$OUTPUT_PATH"
fi

Just make sure the paths are ok. In my case, I have the app inside the "App" folder and so the paths have that. The mkdir command uses the variable $LAURINE_BIN_PATH created above.

I hope its clear for everyone.

pacu commented 5 years ago

In my case I got the script running but, the camel casing is broken. the key SomeTestViewController. is generated as Sometestviewcontroller

edit: just remove -c flag and it will be fine

PiotrWitczak commented 5 years ago

I try to build Laurine in build phrase as above and I have these errors. ` Showing Recent Messages :-1: + env -i swiftc -emit-executable -o /Users/wikiwiktor/Documents/WorkSpace/iOS/ig-ios/InfoGym/../bin/laurine /Users/wikiwiktor/Documents/WorkSpace/iOS/ig-ios/Libraries/Laurine/LaurineGenerator.swift

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:16: while building module 'Darwin' imported from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:16:

:-1: #include <sys/types.h>

:-1: ^

/:29: in file included from :29:

:-1: #import "string.h"

:-1: ^

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/string.h:180: in file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/string.h:180:

:-1: #include "strings.h"

:-1: ^

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/strings.h:92: in file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/strings.h:92:

:-1: #include

:-1: ^

/usr/local/include/string.h:25: in file included from /usr/local/include/string.h:25:

:-1: #include <plist/Node.h>

:-1: ^

/usr/local/include/plist/Node.h:26: 'cstddef' file not found

:-1: #include

:-1: ^

/:1: in file included from :1:

:-1: #import "Headers/CoreFoundation.h"

:-1: ^

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:16: could not build module 'Darwin'

:-1: #include <sys/types.h>

:-1: ^

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFStream.h:20: while building module 'Dispatch' imported from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFStream.h:20:

:-1: #include <dispatch/dispatch.h>

:-1: ^

/:1: in file included from :1:

:-1: #import "dispatch.h"

:-1: ^

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/dispatch/dispatch.h:25: could not build module 'Darwin'

:-1: #include

:-1: ^

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFStream.h:20: while building module 'Dispatch' imported from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFStream.h:20:

:-1: #include <dispatch/dispatch.h>

:-1: ^

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/dispatch/dispatch.h:48: while building module 'os_object' imported from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/dispatch/dispatch.h:48:

:-1: #include <os/object.h>

:-1: ^

/:1: in file included from :1:

:-1: #import "os/object.h"

:-1: ^

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/os/object.h:25: could not build module 'Darwin'

:-1: #include

:-1: ^

/: could not build Objective-C module 'CoreFoundation'

`

I use xcode Version 10.2.1

SandeepAggarwal commented 5 years ago

@PiotrWitczak Did you able to make it work?

felipenandz commented 5 years ago

Hi Guys,

I'm still having such a problem with the script. Using the script you published here the code runs but doesn't modify or add the string. It's not working properly and I don't know why.. I'm still getting the

Segmentation fault 11 Command PhaseScriptExecution failed with a nonzero exit code I would appreciate if someone could help me.

I've got Xcode 10.1.3 Thank you very much!

mflint commented 5 years ago

@felipenandz Can you post your script please?

felipenandz commented 5 years ago

@mflint Sure ,

I dowloaded the project Laurine from the Repo and as expected their code is not working in Xcode 10.1.3 giving the same Problem. So I put your script there.

It's giving this error

set -x

Get base path to project

BASE_PATH="$PROJECT_DIR/$PROJECT_NAME"

--------- START OF YOUR CONFIGURATION (change PathTo.. to fit)

Get path to Laurine Generator script its the binary LAURINE_PATH="$BASE_PATH/../../LaurineGenerator.swift" LAURINE_BIN_PATH="$BASE_PATH/../bin/laurine"

Get path to main localization file (usually english). SOURCE_PATH="$BASE_PATH/Resources/Localizations/en.lproj/Localizable.strings"

Get path to output. If you use ObjC version of output, set implementation file (.m), as header will be generated automatically OUTPUT_PATH="$BASE_PATH/Classes/Generated/Localizations.swift"

mkdir -p $LAURINE_BIN_PATH

--------- END OF YOUR CONFIGURATION

Build laurine binary if necessary if [ ! -f $LAURINE_BIN_PATH ]; then env -i swiftc -emit-executable -o$LAURINE_BIN_PATH $LAURINE_PATH fi

Actually generate output. -- CUSTOMIZE -- parameters to your needs (see documentation). Will only re-generate script if something changed if [ "$OUTPUT_PATH" -ot "$SOURCE_PATH" ]; then "$LAURINE_BIN_PATH" -i "$SOURCE_PATH" -c -o "$OUTPUT_PATH" fi

Right Now is giving this error

:-1: ld: can't open output file for writing: /Users/fnandz/Downloads/Laurine-master/Example/Laurine/../bin/laurine, errno=21 for architecture x86_64

:-1: /Users/fnandz/Library/Developer/Xcode/DerivedData/Laurine-cqayukqhekxkitbikrlrwttefoxo/Build/Intermediates.noindex/Laurine.build/Debug-iphonesimulator/Laurine.build/Script-0BF9E6791BF2375E0055C0D8.sh: line 32: /Users/fnandz/Downloads/Laurine-master/Example/Laurine/../bin/laurine: is a directory

mflint commented 5 years ago

@felipenandz

Your problem is that mkdir -p $LAURINE_BIN_PATH is making a directory with the name bin/laurine/, when it should just be making the directory bin/.

I'd change the script like this:

LAURINE_PATH="$BASE_PATH/../../LaurineGenerator.swift"
BIN_PATH="$BASE_PATH/../bin"
LAURINE_BIN_PATH="$BIN_PATH/laurine"

... and further down:

mkdir -p $BIN_PATH

Then the script will make bin/ directory, then compile the laurine binary into bin/laurine.

(You'll also need to manually delete the directory bin/laurine/, before building for the first time)

felipenandz commented 5 years ago

@mflint

All the best to you , your family and your generations!

It works.. Thank you very much!

JiriTrecak commented 5 years ago

Hey guys - Very long time no see. I have been helming my startup, https://supernova.io/ and it has been absolutely crazy - though it is something you might be interested in. That being said, I have definitely didn't stop to observe this project and I have recently started fixing the issues and improving laurine in general. I expect that I could have the fixed version done and released within few days, so don't lose hope - I'll do my best to catch up.

Hope it helps some of you! :)

felipenandz commented 5 years ago

@mflint

Do you have any idea why it is executed like this and not the old way as it was working in xcode 10.1.1

Just to know , because I need to explain it. But if you don't it Ok anyway , it's all working good.

mflint commented 5 years ago

Do you have any idea why it is executed like this and not the old way as it was working in xcode 10.1.1

I don't know. I guess something has changed with the Swift interpreter, which means it cannot successfully parse/execute the Laurine script. But luckily it is able to compile the script into a binary, which we can then execute. ¯_(ツ)_/¯

MatyasKriz commented 4 years ago

If you're looking for generating assets and others among localizables, consider moving to SwiftGen which is still maintained and under active development.