johnno1962 / injectionforxcode

Runtime Code Injection for Objective-C & Swift
MIT License
6.55k stars 565 forks source link

Could not locate compile command for #301

Closed loohalh closed 2 years ago

loohalh commented 2 years ago

Hello, I have an error here, he can't work, can you help to check, thank you

Could not locate compile command for /Users/looha/Desktop/complete/mba/Sources/Modulars/QuesBank/ViewController/QuesSubjectViewController.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 paths are case sensitive. Try a build clean then rebuild to make logs available or consult: "/var/folders/bb/fyzc35s15bqdkss8pqb4fbcr0000gn/T/com.johnholdsworth.InjectionIII/command.sh".

com.johnholdsworth.InjectionIII/command.sh

// search through build logs, most recent first cd "/Users/looha/Library/Developer/Xcode/DerivedData/WEApp-hewpwktgjofkyngdormxeiqznpfe/Logs/Build" && for log in ls -t *.xcactivitylog; do

echo "Scanning $log"

/usr/bin/env perl "/var/folders/bb/fyzc35s15bqdkss8pqb4fbcr0000gn/T/com.johnholdsworth.InjectionIII/eval101.pl" "$log" >"/var/folders/bb/fyzc35s15bqdkss8pqb4fbcr0000gn/T/com.johnholdsworth.InjectionIII/eval101.sh" && exit 0

done exit 1;

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 =~ /^\scd /) { $realPath = $line; } elsif ($line =~ m@ -(?:primary-file|c(?<! -frontend -c)) (?:\?\"(\Q/Users/looha/Desktop/complete/mba/Sources/Modulars/QuesBank/ViewController/QuesSubjectViewController.swift\E)\?\"|(\Q/Users/looha/Desktop/complete/mba/Sources/Modulars/QuesBank/ViewController/QuesSubjectViewController.swift\E)) @oi and $line =~ " x86_64") { // found compile command // may need to extract file list if ($line =~ / -filelist /) { while (defined (my $line2 = )) { 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 = "/var/folders/bb/fyzc35s15bqdkss8pqb4fbcr0000gn/T/com.johnholdsworth.InjectionIII//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 )(\S+)( )/$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;

The eval101.sh file is empty

johnno1962 commented 2 years ago

Hi, this is usually due to strange characters in a file name or the path to your project root such as: ().

loohalh commented 2 years ago

Hi, this is usually due to strange characters in a file name or the path to your project root such as: ().

Thank you for your reply. But my project name is mba, project directory path is/Users/looha/Desktop/complete /, and no special characters

johnno1962 commented 2 years ago

Strange. Do you have a custom derived data directory or could you try moving your project out of the Desktop folder?

loohalh commented 2 years ago

Can I put the project directly under the user file? For example, / Users/looha

johnno1962 commented 2 years ago

home directory is fine, Desktop and Downloads have special permissions but that probably isn't the cause of this problem. Which version of InjectionIII is this App Store or is it one of the binary GitHub releases -- which Xcode, OS etc?

loohalh commented 2 years ago

home directory is fine, Desktop and Downloads have special permissions but that probably isn't the cause of this problem. Which version of InjectionIII is this App Store or is it one of the binary GitHub releases? InjectionIII was downloaded from the App Store,version 2.8.0, I'm trying to use it in the user directory to see what happens

loohalh commented 2 years ago

home directory is fine, Desktop and Downloads have special permissions but that probably isn't the cause of this problem. Which version of InjectionIII is this App Store or is it one of the binary GitHub releases -- which Xcode, OS etc?

Use it in the user directory and the same error is reported,Xcode Version is 12.5 (12E262),Mac OS is Version 11.0,

johnno1962 commented 2 years ago

This is an unusual problem. Can you rename your App Store version out of the way and try the 2.8.6 release please? Or have you tried the https://johnholdsworth.com/GettingStarted.zip example project?

loohalh commented 2 years ago

This is an unusual problem. Can you rename your App Store version out of the way and try the 2.8.6 release please?

Ok, I'll try it right away

loohalh commented 2 years ago

This is an unusual problem. Can you rename your App Store version out of the way and try the 2.8.6 release please? Or have you tried the https://johnholdsworth.com/GettingStarted.zip example project?

The same error was reported when version 2.8.6 was used. I tried to work normally on a new project. I tried to give you a case of our project

johnno1962 commented 2 years ago

No surprise. Not that much has changed but at least I know you're using the most up to date version. Did you try the getting started project to see injection working before you try something more ambitious. I can TeamView if that is possible.

johnno1962 commented 2 years ago

OK got your details, trying to connect but you don't seem to be on line.

loohalh commented 2 years ago

OK got your details, trying to connect but you don't seem to be on line.

I'm in China, I don't know if there are any restrictions

loohalh commented 2 years ago

OK got your details, trying to connect but you don't seem to be on line.

I refreshed the network, you try it

johnno1962 commented 2 years ago

Depends on your network. I've connected to China before.

johnno1962 commented 2 years ago

No luck. Did you try the GettingStarted project?

loohalh commented 2 years ago

It works

johnno1962 commented 2 years ago

Does any other file in your project inject or is it just this one file?

johnno1962 commented 2 years ago

OK, got you now (I left off the "1", Do'h

johnno1962 commented 2 years ago

Looks like there is a limit of perhaps 500 files per target with recent Xcodes for InjectionIII to work due to how it logs compilations. There was a fix for this but it no linger works.

loohalh commented 2 years ago

Looks like there is a limit of perhaps 500 files per target with recent Xcodes for InjectionIII to work due to how it logs compilations. There was a fix for this but it no linger works.

I have removed all the project files except the library of Cocopods and a test file, but it still does not work properly. I will send the project to you and wait for your good news. Thank you again

loohalh commented 2 years ago

My project also worked fine when I changed the value of SWIFT_WHOLE_MODULE_OPTIMIZATION in debug mode to NO, so I guess the root of the problem is SWIFT_WHOLE_MODULE_OPTIMIZATION. Thank you very much for your work. Thank you again