johnno1962 / InjectionIII

Re-write of Injection for Xcode in (mostly) Swift
MIT License
3.96k stars 312 forks source link

It does't work, I tried all issues functions #396

Closed DSPerson closed 2 years ago

DSPerson commented 2 years ago
💉 ⚠️ Could not locate compile command for /Users/zuiyou/Gits/maga3/MAGA/MAGA/Bussniess/Publish/View/PublishKeyboardVoteView.swift.
This could be due to one of the following:
1. Injection does not work with Whole Module Optimization.
2. There are restrictions on characters allowed in paths.
3. File paths in the simulator are case sensitive.
4. The modified source file is not in the current project.
5. The source file is an XCTest that has not been run yet.
Try a build clean then rebuild to make logs available or
consult: "/Users/zuiyou/Library/Developer/CoreSimulator/Devices/1AB498A6-489F-4328-B6FB-69A6ADD74227/data/Containers/Data/Application/A29BC540-3EA2-48DC-AEEB-6979853443D4/tmp/command.sh".

xcode 13.3 injection: 4.26 compilation mode: singlefile

DSPerson commented 2 years ago

can you help me?

DSPerson commented 2 years ago

this is sh content

# search through build logs, most recent first
cd "/Users/zuiyou/Library/Developer/Xcode/DerivedData/MAGA-dpsgcoadfiawyggstyjrwvpulung/Logs/Build" &&
for log in `ls -t *.xcactivitylog`; do
    #echo "Scanning $log"
    /usr/bin/env perl "/Users/zuiyou/Library/Developer/CoreSimulator/Devices/1AB498A6-489F-4328-B6FB-69A6ADD74227/data/Containers/Data/Application/D09A8D95-515C-4B24-98C8-9C8EFC6408FE/tmp/eval101.pl" "$log"     >"/Users/zuiyou/Library/Developer/CoreSimulator/Devices/1AB498A6-489F-4328-B6FB-69A6ADD74227/data/Containers/Data/Application/D09A8D95-515C-4B24-98C8-9C8EFC6408FE/tmp/eval101.sh" 2>"/Users/zuiyou/Library/Developer/CoreSimulator/Devices/1AB498A6-489F-4328-B6FB-69A6ADD74227/data/Containers/Data/Application/D09A8D95-515C-4B24-98C8-9C8EFC6408FE/tmp/eval101.err" && exit 0
done
exit 1;
johnno1962 commented 2 years ago

Hi, can I get back to you on this later. I can't think of anything obvious. Have you tried a simpler project first to get started? Try looking at the script it mentions and the Perl script it calls to see if there is anything more you can tell me? You can run it from the command line and try to work out what the problem is by seeing if it returns status 0 or 1 (echo $?)

DSPerson commented 2 years ago

first question: simple project it works; but in my project it not work, I tried all README functions....... image like this? output: image

johnno1962 commented 2 years ago

Can you send me the Perl script it calls or post it here to see if I can spot something. It's may be a character set issue though I don't see from the fileppath what the problem would be. Also, if you could export the project build logs using export on the build tab and send them though to GitHub at johnholdsworth.com I could take a look.

DSPerson commented 2 years ago

Can you send me the Perl script it calls or post it here to see if I can spot something. It's may be a character set issue though I don't see from the fileppath what the problem would be. Also, if you could export the project build logs using export on the build tab and send them though to GitHub at johnholdsworth.com I could take a look.

image

Thank you very much for your reply. but i'm sorry, i don't understand how to call perl script. I never use it, even listen it. Maybe you can teach me how to perform it. Thanks.

johnno1962 commented 2 years ago

In the command.sh it mentions, it calls a Perl script (.pl). Can you send me the Perl script thanks or post it here.

DSPerson commented 2 years ago
  1. comment.sh
    # search through build logs, most recent first
    cd "/Users/zuiyou/Library/Developer/Xcode/DerivedData/MAGA-dpsgcoadfiawyggstyjrwvpulung/Logs/Build" &&
    for log in `ls -t *.xcactivitylog`; do
    #echo "Scanning $log"
    /usr/bin/env perl "/Users/zuiyou/Library/Developer/CoreSimulator/Devices/1AB498A6-489F-4328-B6FB-69A6ADD74227/data/Containers/Data/Application/5ABB292F-CCE0-4BAE-BA8F-673BB7E1C148/tmp/eval101.pl" "$log"     >"/Users/zuiyou/Library/Developer/CoreSimulator/Devices/1AB498A6-489F-4328-B6FB-69A6ADD74227/data/Containers/Data/Application/5ABB292F-CCE0-4BAE-BA8F-673BB7E1C148/tmp/eval101.sh" 2>"/Users/zuiyou/Library/Developer/CoreSimulator/Devices/1AB498A6-489F-4328-B6FB-69A6ADD74227/data/Containers/Data/Application/5ABB292F-CCE0-4BAE-BA8F-673BB7E1C148/tmp/eval101.err" && exit 0
    done
    exit 1;
  2. eval101.pl
    
    use JSON::PP;
    use English;
    use strict;

line separator in Xcode logs

$INPUT_RECORD_SEPARATOR = "\r";

format is gzip

open GUNZIP, "/usr/bin/gunzip <\"$ARGV[0]\" 2>/dev/null |" or die;

grep the log until there is a match

my ($realPath, $command); while (defined (my $line = )) { if ($line =~ /^\s*cd /) { $realPath = $line; } elsif ($line =~ m@ -(?:primary-file|c(?<! -frontend -c)) (?:\?\"(\Q/Users/zuiyou/Gits/maga3/MAGA/MAGA/Bussniess/Login/ViewController/BindPhoneViewController.swift\E)\?\"|(\Q/Users/zuiyou/Gits/maga3/MAGA/MAGA/Bussniess/Login/ViewController/BindPhoneViewController.swift\E)) @oi and $line =~ " arm64") {

found compile command

    # may need to extract file list
    if ($line =~ / -filelist /) {
        while (defined (my $line2 = <GUNZIP>)) {
            if (my($filemap) = $line2 =~ / -output-file-map ([^ \\]+(?:\\.[^ \\]+)*) / ) {
                $filemap =~ s/\\//g;
                my $file_handle = IO::File->new( "< $filemap" )
                    or die "Could not open filemap '$filemap'";
                my $json_text = join'', $file_handle->getlines();
                my $json_map = decode_json( $json_text, { utf8  => 1 } );
                my $filelist = '/Users/zuiyou/Library/Developer/CoreSimulator/Devices/1AB498A6-489F-4328-B6FB-69A6ADD74227/data/Containers/Data/Application/5ABB292F-CCE0-4BAE-BA8F-673BB7E1C148/tmp//filelist.txt';
                my $swift_sources = join "\n", keys %$json_map;
                my $listfile = IO::File->new( "> $filelist" )
                    or die "Could not open list file '$filelist'";
                binmode $listfile, ':utf8';
                $listfile->print( $swift_sources );
                $listfile->close();
                $line =~ s/( -filelist )([^ \\]*(?:\\.[^ \\]*)*)( )/$1$filelist$3/;
                last;
            }
        }
    }
    if ($realPath and (undef, $realPath) = $realPath =~ /cd (\"?)(.*?)\1\r/) {

print "cd \"$realPath\" && ";

    }
    # find last
    $command = $line
    #exit 0;
}

}

if ($command) { print $command; exit 0; }

class/file not found

exit 1;

3. eval101.sh and eval101.err

they are all empty



> last i found `$filelist` has two `/`, is it error reason?
johnno1962 commented 2 years ago

Thanks for sending that through. Can you go to the Xcode build tab of your project, click the export button and send the resulting file through to me please - github at johnholdsworth.com

DSPerson commented 2 years ago

Thanks for yore reply. I sent you mail image

johnno1962 commented 2 years ago

Thanks for sending that through. InjectionIII relies on being able to see how files are compiled from these build logs. For some reason the log you sent through doesn't contain any compilations that I would expect. Are you using Bazel or some other build system? Until your build log contains the compilation commands,InjectionIII can not work.

DSPerson commented 2 years ago

image I just click Xcode run

johnno1962 commented 2 years ago

Yes, but how is the project configured. If you are using the Xcode build system there should be a lot of compile commands in the log. Without them you will get this error.

DSPerson commented 2 years ago

I clean my Xcode, and i rebuild, i will send you soon

johnno1962 commented 2 years ago

OK, got it. There is still something about your Xcode configuration I've not encountered before. It is not logging. the actual compile command but instead something which is no use to InjectionIII like this:

    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend @/var/folders/nm/wz3rck2521dbkrdpy12t6w440000gp/T/TemporaryDirectory.n6ijyQ/arguments-6374883059988158360.resp

Please check your build settings and check if you have anything unusual set. Is this a very, very large project?

johnno1962 commented 2 years ago

Does the file /var/folders/nm/wz3rck2521dbkrdpy12t6w440000gp/T/TemporaryDirectory.n6ijyQ/arguments-6374883059988158360.resp still exist?

DSPerson commented 2 years ago

No... it is temp file.

johnno1962 commented 2 years ago

You won't be able to use use injection on this project as it stands. Can you email its .xcodeproj file?

johnno1962 commented 2 years ago

Have tried adding build parameter SWIFT_ENABLE_BATCH_MODE = NO?

DSPerson commented 2 years ago

Have tried adding build parameter SWIFT_ENABLE_BATCH_MODE = NO? Wait, I try once;

DSPerson commented 2 years ago

Have tried adding build parameter SWIFT_ENABLE_BATCH_MODE = NO?

it not work. image

DSPerson commented 2 years ago

You won't be able to use use injection on this project as it stands. Can you email its .xcodeproj file?

I had sent xxx.xcodeproj.zip to you.

johnno1962 commented 2 years ago

Thanks for sending the project through. I can't see anything particular part from the sheer size of the project. Until you find a way to avoid these ".resp" temporary files in the logs instead of the full compiler command, I'm sorry but, there isn't much I can do.

xiaohanyu commented 2 years ago

@DSPerson are you running this on devices or simulators?

One more thing to check, did you turn off bitcode for your targets? At the same time have you added the necessary linker flags as well?

Recently we found that InjectionIII won't work with whole-module optimization and bitcode, so you have to turn off both whole-module optimization and bitcode.

DSPerson commented 2 years ago

@DSPerson are you running this on devices or simulators?

One more thing to check, did you turn off bitcode for your targets? At the same time have you added the necessary linker flags as well?

Recently we found that InjectionIII won't work with whole-module optimization and bitcode, so you have to turn off both whole-module optimization and bitcode.

Thanks, but I turn off bitcode and had add SWIFT-WHOLE-MODULE-OPTIMIZATION in Xcode User-Defined

DSPerson commented 2 years ago

Until you find a way to avoid these ".resp" temporary files in the logs instead of the full compiler command

alright, Maybe i should give up. ┭┮﹏┭┮

johnno1962 commented 2 years ago

Sorry, let me know if you ever work out what the problem was here. I've never seen this before except perhaps something related to Bazel??