johnno1962 / InjectionApp

Issue Tracking Repo for Injection as an App
MIT License
111 stars 7 forks source link

M1 mac: Could not locate compile command for PATH #42

Closed chandrapol closed 1 year ago

chandrapol commented 1 year ago

I am getting this error on M1 Mac (mentioned at the end of the post).

  1. No optimization enabled on Xcode image
  2. No spaces in Xcode project path or file paths.
  3. No customized Derived Data path.
  4. Installed app from AppStore (latest)
💉 ⚠️ Could not locate compile command for /Users/kbc/Projects/TicketBook/Universe/UserInformation/UserInfoEditMultiSelectionCell.swift.
This could be due to one of the following:
1. Injection does not work with Whole Module Optimization.
5. There are restrictions on characters allowed in paths.
6. File paths in the simulator are case sensitive.
7. The modified source file is not in the current project.
8. The source file is an XCTest that has not been run yet.
9. Xcode has removed the build logs. Edit a file and re-run.
Try a build clean then rebuild to make logs available or
consult: "/var/folders/_1/97p229zj2r94py8s8tp21h280000gn/T/com.johnholdsworth.InjectionIII/command.sh".
johnno1962 commented 1 year ago

Hi, what is the version number of the InjectionII app you're using? Have you tried downloading one of the binary releases on this repo? Have you looked at running the script it mentions to investigate what the problem is?

chandrapol commented 1 year ago
  1. Version 4.5.2
  2. Same issue on Intel mac too
  3. Tried the latest binary from Github. InjectionIII
  4. I ran the script. Nothing happend.
johnno1962 commented 1 year ago

If you look at the script it redirects all output into files so you wouldn't see anything happening. Is there anything in the .err file that captures stderr. Can you post the .pl file here so I can have a look?

chandrapol commented 1 year ago

Hello @johnno1962 : Here are the details that you asked for.

command.sh

# search through build logs, most recent first
cd "/Users/USER/Library/Developer/Xcode/DerivedData/TicketApp-aaapbleqojdykabvnkbnyvyskwoy/Logs/Build" &&
for log in `ls -t *.xcactivitylog`; do
    #echo "Scanning $log"
    /usr/bin/env perl "/var/folders/_1/97p229zj2r94py8s8tp21h280000gn/T/com.johnholdsworth.InjectionIII/eval101.pl" "$log"     >"/var/folders/_1/97p229zj2r94py8s8tp21h280000gn/T/com.johnholdsworth.InjectionIII/eval101.sh" 2>"/var/folders/_1/97p229zj2r94py8s8tp21h280000gn/T/com.johnholdsworth.InjectionIII/eval101.err" && exit 0
done
exit 1;

Contents of .err file

No contents. The file is empty.

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 "gnozip";

# grep the log until there is a match
my ($realPath, $command);
while (defined (my $line = <GUNZIP>)) {
    if ($line =~ /^\s*cd /) {
        $realPath = $line;
    }
    elsif ($line =~ m@ -(?:primary-file|c(?<!-frontend -c)) (?:\\?\"(\Q/Users/USER/Projects/test-TicketApp/Universe/UserInformation/Categories/Controller/CategoriesVC.swift\E)\\?\"|(\Q/Users/USER/Projects/test-TicketApp/Universe/UserInformation/Categories/Controller/CategoriesVC.swift\E)) @oi and $line =~ " x86_64") {
        # 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 = '/var/folders/_1/97p229zj2r94py8s8tp21h280000gn/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\\]*(?:\\.[^\s\\]*)*)( )/$1$filelist$3/;
                    last;
                }
            }
        }
        if ($realPath and (undef, $realPath) = $realPath =~ /cd (\"?)(.*?)\1\r/) {
#           print "cd \"$realPath\" && ";
        }
        # find last
        $command = $line
        #exit 0;
    }
    elsif (my ($bazel, $dir) = $line =~ /^Running "([^"]+)".* (?:patching output for workspace root|with project path) at ("[^"]+")/) {
        $command = "cd $dir && $bazel";
        last;
    }
}

if ($command) {
    print $command;
    exit 0;
}
# class/file not found
exit 1;
johnno1962 commented 1 year ago

Are you able to send through to GitHub at johnholdsworh.com, one of the compressed .xcactivity build logs in /Users/USER/Library/Developer/Xcode/DerivedData/TicketApp-aaapbleqojdykabvnkbnyvyskwoy/Logs/Build?

chandrapol commented 1 year ago

Are you able to send through to GitHub at johnholdsworh.com, one of the compressed .xcactivity build logs in /Users/USER/Library/Developer/Xcode/DerivedData/TicketApp-aaapbleqojdykabvnkbnyvyskwoy/Logs/Build?

Sent. Thank you.

johnno1962 commented 1 year ago

Very sorry, I gave you the wrong email address there.. GitHub at johnholdsworth.com. If should have bounced, can you send it again please?

chandrapol commented 1 year ago

Very sorry, I gave you the wrong email address there.. GitHub at johnholdsworth.com. If should have bounced, can you send it again please?

Sent again. Thank you for your prompt response.

johnno1962 commented 1 year ago

Great, thanks for sending it through. I don't know why but the file you're injecting isn't mentioned in the logs you sent through and if how to compile a file is logged it won't be possible to inject it. Is this to do with CocoaPods?

chandrapol commented 1 year ago

... but the file you're injecting isn't mentioned in the logs you sent through

This is happening for all the files including AppDelegate.swift or any other file. If you see any .swift file or .m file on the log, I see the same output on the Xcode terminal.

💉 ⚠️ Could not locate compile command for /Users/kbc/Projects/TicketBook/Universe/UserInformation/UserInfoEditMultiSelectionCell.swift.
This could be due to one of the following:
...
...
johnno1962 commented 1 year ago

As I said UserInfoEditMultiSelectionCell.swift is not mentioned in your log at all. With AppDelegate.swift it's in a directory that contains a space and there are some paths with & which is very difficult to support which is probably the problem there. There is much that is unusual about the log you sent which I can't quite work out. I can't spend too much time on this but I suggest you start with a simpler example and work your way up to what seems to be a very complex and unusual project, built in an unusual way. Are you sure you're not using whole module optimisation? image By spending more time looking at what the scripts do, it should be possible to work out why you're not getting a match. Injection delegates to scripts so people can support themselves a little more.

chandrapol commented 1 year ago

As I said UserInfoEditMultiSelectionCell.swift is not mentioned in your log at all. With AppDelegate.swift it's in a directory that contains a space and there are some paths with & which is very difficult to support which is probably the problem there. There is much that is unusual about the log you sent which I can't quite work out. I can't spend too much time on this but I suggest you start with a simpler example and work your way up to what seems to be a very complex and unusual project, built in an unusual way. Are you sure you're not using whole module optimisation?

I totally understand. Very much appreciated your time to make this tool and spent time supporting it. I will look a little more into the setup and other things you mentioned.

Godspeed.