Giter VIP home page Giter VIP logo

Comments (5)

vinivendra avatar vinivendra commented on June 15, 2024 1

it worked 🎉

Good to know 😄

what about adding a Copy Files phase to the Gryphon target?

I thought about this when I was creating this feature. If I remember correctly, the problem was that the list of files wasn't forwarded to the script that called Gryphon, so I couldn't access it. Maybe I'll revisit this idea now that I have more experience with the Xcode integration, though.

Since this solved your problem, I'm merging the changes. Plus, I made it so that using --target on gryphon init also adds the target name to the Xcode run script phase, so you shouldn't have to do it manually anymore. Any other problems, just let me know.

from gryphon.

vinivendra avatar vinivendra commented on June 15, 2024

Hi @massimobio, I pushed an experimental implementation of this to a new custom-targets branch. Could you try to see if it fixes your problem?

You would have to clone/checkout the branch, then run the installation script. Then, try initializing Gryphon again, this time passing your target:

gryphon init MyProject.xcproject --target=MyTarget

If it works, try translating your target with the console:

gryphon MyProject.xcproject gryphonInputFiles.xcfilelist --target=MyTarget

If that works, then you should be able to add the --target argument to the Run Script Phase of the Gryphon target in your Xcode project and translate everything from Xcode.

from gryphon.

massimobio avatar massimobio commented on June 15, 2024

Thank you @vinivendra for looking into this so fast.
I installed the custom-tagerts brach successfully.
I re-ran the gryphon init with the --target argument but it didn't make any meaningful changes to the project.pbxproj file.

I attempted to translate my target from the command line and this time the dump shows all the files associated with the target so that seems to work:
updateASTDumps.txt

..but then it crashed:

/Users/massimo/Developer/iReal-Pro-iOS-macOS/.gryphon/GryphonTemplatesLibrary.swift
---
3.	While evaluating request InterfaceTypeRequest(iRealPro.(file).CountInView.init(frame:).frame@/Users/massimo/Developer/iReal-Pro-iOS-macOS/Shared/Classes/CountInView.swift:14:23)
4.	While resolving type CGRect at [/Users/massimo/Developer/iReal-Pro-iOS-macOS/Shared/Classes/CountInView.swift:14:30 - line:14:30] RangeText=""
5.	While evaluating request UnqualifiedLookupRequest(looking up 'CGRect' from 0x7faa17120eb0 AbstractFunctionDecl name=init(frame:) : (no type set) with options { TypeLookup })
0  swift                    0x00000001066634ea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x0000000106662cc0 SignalHandler(int) + 352
2  libsystem_platform.dylib 0x00007fff718f85fd _sigtramp + 29
3  libsystem_platform.dylib 000000000000000000 _sigtramp + 2389735968
4  libsystem_c.dylib        0x00007fff717ce808 abort + 120
5  swift                    0x00000001023b76b1 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*)::$_1::__invoke(void*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) + 1137
6  swift                    0x00000001065de5c6 llvm::report_fatal_error(llvm::Twine const&, bool) + 278
7  swift                    0x00000001065de4ab llvm::report_fatal_error(char const*, bool) + 43
8  swift                    0x000000010337760c swift::ASTScope::unqualifiedLookup(swift::SourceFile*, swift::DeclName, swift::SourceLoc, swift::DeclContext const*, swift::namelookup::AbstractASTScopeDeclConsumer&) + 2812
9  swift                    0x00000001034d64c4 (anonymous namespace)::UnqualifiedLookupFactory::lookInASTScopes() + 116
10 swift                    0x00000001034a2530 swift::SimpleRequest<swift::UnqualifiedLookupRequest, swift::LookupResult (swift::UnqualifiedLookupDescriptor), (swift::CacheKind)0>::evaluateRequest(swift::UnqualifiedLookupRequest const&, swift::Evaluator&) + 1136
11 swift                    0x00000001023e09b9 llvm::Expected<swift::UnqualifiedLookupRequest::OutputType> swift::Evaluator::getResultUncached<swift::UnqualifiedLookupRequest>(swift::UnqualifiedLookupRequest const&) + 521
12 swift                    0x00000001023dff76 swift::UnqualifiedLookupRequest::OutputType swift::evaluateOrDefault<swift::UnqualifiedLookupRequest>(swift::Evaluator&, swift::UnqualifiedLookupRequest, swift::UnqualifiedLookupRequest::OutputType) + 38
13 swift                    0x0000000102fec6e1 swift::TypeChecker::lookupUnqualifiedType(swift::DeclContext*, swift::DeclName, swift::SourceLoc, swift::OptionSet<swift::NameLookupFlags, unsigned int>) + 225
14 swift                    0x000000010307e731 resolveIdentTypeComponent(swift::TypeResolution, llvm::ArrayRef<swift::ComponentIdentTypeRepr*>, swift::TypeResolutionOptions) + 1201
15 swift                    0x000000010307deef swift::TypeChecker::resolveIdentifierType(swift::TypeResolution, swift::IdentTypeRepr*, swift::TypeResolutionOptions) + 191
16 swift                    0x0000000103083c59 (anonymous namespace)::TypeResolver::resolveType(swift::TypeRepr*, swift::TypeResolutionOptions) + 281
17 swift                    0x0000000103083952 swift::TypeResolution::resolveType(swift::TypeRepr*, swift::TypeResolutionOptions) + 354
18 swift                    0x00000001030481e2 swift::SimpleRequest<swift::InterfaceTypeRequest, swift::Type (swift::ValueDecl*), (swift::CacheKind)2>::evaluateRequest(swift::InterfaceTypeRequest const&, swift::Evaluator&) + 5010
19 swift                    0x00000001033b965e swift::InterfaceTypeRequest::OutputType swift::evaluateOrDefault<swift::InterfaceTypeRequest>(swift::Evaluator&, swift::InterfaceTypeRequest, swift::InterfaceTypeRequest::OutputType) + 910
20 swift                    0x0000000103348b76 swift::ParamDecl::isNonEphemeral() const + 150
21 swift                    0x0000000103348346 (anonymous namespace)::PrintDecl::printParameter(swift::ParamDecl const*) + 2886
22 swift                    0x0000000103343f56 (anonymous namespace)::PrintDecl::printParameterList(swift::ParameterList const*, swift::ASTContext const*) + 406
23 swift                    0x000000010334c722 (anonymous namespace)::PrintDecl::printAbstractFunctionDecl(swift::AbstractFunctionDecl*) + 210
24 swift                    0x00000001033426be swift::ASTVisitor<(anonymous namespace)::PrintDecl, void, void, void, void, void, void>::visit(swift::Decl*) + 10958
25 swift                    0x0000000103340cf9 swift::ASTVisitor<(anonymous namespace)::PrintDecl, void, void, void, void, void, void>::visit(swift::Decl*) + 4361
26 swift                    0x00000001033431cd swift::ASTVisitor<(anonymous namespace)::PrintDecl, void, void, void, void, void, void>::visit(swift::Decl*) + 13789
27 swift                    0x000000010334de71 swift::SourceFile::dump(llvm::raw_ostream&) const + 609
28 swift                    0x00000001023b0c79 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 31465
29 swift                    0x000000010232cb73 main + 1283
30 libdyld.dylib            0x00007fff716ffcc9 start + 1
<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)

It looks like it's crashing on evaluating the override init(frame: CGRect) line in CountInView.swift

    #if os(iOS)
        override init(frame: CGRect) {
            super.init(frame: frame)
            backgroundColor = .clear
        }

        required init?(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)
            backgroundColor = .clear
        }
    #else
        override var isFlipped: Bool {
            return true
        }
    #endif

Maybe gryphon gets confused by the #if that I use to help with sharing code between my iOS and macOS targets?

I have just one file set to be translated in gryphonInputFiles.xcfilelist and that is GryphonTest.swift so shouldn't it limit the translation to that file?

GryphonTest.swift looks like this:

// gryphon output: ../iReal-Pro-Android/iRealPro/src/main/java/com/massimobiolcati/irealb/MixerInstrumentType.kt

import Foundation

class Test {
    var testVar = "test"
}

from gryphon.

vinivendra avatar vinivendra commented on June 15, 2024

..but then it crashed:

Damn.

I have just one file set to be translated in gryphonInputFiles.xcfilelist and that is GryphonTest.swift so shouldn't it limit the translation to that file?

I know this bug. It's actually a bug in the Swift compiler. Gryphon really would limit the translation to that file, but since Swift crashes before it can print the AST dumps, Gryphon never even starts looking at the code.

I reported this bug a while ago, and it's already fixed in the development snapshots, but I don't know if it made it to any releases. I'm using Swift 5.2.2 right now, and the bug's still there.

One temporary workaround would be to separate this code into two files, one for iOS and one for macOS... but that depends a lot on your project.

Another idea would be to use another Swift version just for Gryphon. If the new ones don't work, try an older one like Swift 5.1, which didn't have this bug. If you have the 5.1 toolchain installed, you can use it with

gryphon MyProject.xcproject gryphonInputFiles.xcfilelist --target=MyTarget --toolchain="swift 5.1"

If not, you can download it here.

from gryphon.

massimobio avatar massimobio commented on June 15, 2024

Xcode 12 is around the corner so we'll probably get a newer version of Swift with the bug fix then.

I though of a simpler solution: since I don't want to translate any of the classes containing #if for now: I created a separate Target (of type Framework) and added the one file to translate to it and it worked 🎉
From the console
$ gryphon iReal\ Pro.xcodeproj gryphonInputFiles.xcfilelist --target=Cross\ Platform
And it also works by adding the --target argument in the in the build phase in Xcode.

This made me think...
...what about adding a Copy Files phase to the Gryphon target? This would allow you to add swift files to the target and that way you wouldn't need gryphonInputFiles.xcfilelist, you could just add the files you'd like to translate to the Gryphon target. I couldn't make it work. I guess you'd need to have the Swift files compiled before the gryphon command runs, but maybe you cannot add a Compile Sources phase to an Aggregate target...

from gryphon.

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.