Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect project path #4

Closed
starFelix opened this issue Dec 1, 2017 · 10 comments
Closed

Detect project path #4

starFelix opened this issue Dec 1, 2017 · 10 comments

Comments

@starFelix
Copy link

If I was changing a file in subProject, the path returned is subproject's path, not the main porject's path.

And If the subproject's Header Search Path was relative, it would not find the headers. I try to resolve this problem by chainge the code like below:

                    my $realPath = "";
                    while (defined (my $line = <GUNZIP>)) {
                        if (index($line, "cd ") != -1) {
                            $realPath = $line;
                            $realPath =~ s/^\\s+|\\s+$//g;
                        }
                        if ($line =~ m@\(regexp.escaping("\"$"))@o and $line =~ " \(arch())") {
                            # 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 = "/tmp/filelist.txt";
                                        my $swift_sources = join "\n", keys %$json_map;
                                        IO::File->new( "> $filelist" )->print( $swift_sources );
                                        $line =~ s/( -filelist )(\\S+)( )/$1$filelist$3/;
                                        last;
                                    }
                                }
                            }
                            print $realPath." && ";
                            # stop search
                            print $line;
                            exit 0;
                        }
                    }
@johnno1962
Copy link
Owner

Thanks for this, I’ve pushed as version of which works with Swift as well along with other changes and updated the binary d1edb9e

@starFelix
Copy link
Author

I am not sure if you understand my question. The first Qusetion is the function findDerivedData and findProject will return the subProject's path for derived data. But I think return the main poject's is right.

@johnno1962
Copy link
Owner

johnno1962 commented Dec 1, 2017

findDerivedData should return the main project otherwise there will be no derived data. Do you need the path to be the main project or the subproject for things to compile? I’m using the following:

                    # grep the log until there is a match
                    my $realPath;
                    while (defined (my $line = <GUNZIP>)) {
                        if ($line =~ /^\\s*cd /) {
                            $realPath = $line;
                        }
                        elsif ($line =~ m@\(regexp.escaping("\"$"))@o and $line =~ " \(arch)") {
                            # 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 = "/tmp/filelist.txt";
                                        my $swift_sources = join "\n", keys %$json_map;
                                        IO::File->new( "> $filelist" )->print( $swift_sources );
                                        $line =~ s/( -filelist )(\\S+)( )/$1$filelist$3/;
                                        last;
                                    }
                                }
                            }
                            if ($realPath and (undef, $realPath) = $realPath =~ /cd (\\"?)(.*?)\\1\\r/) {
                                print "cd \\"$realPath\\" && ";
                            }
                            # stop search
                            print $line;
                            exit 0;

@starFelix
Copy link
Author

There are two questions.What you said is the second question.
For example,my path is "..../mainProject/some/subProject/subProject.xcodeproj"
For usual situation, the findDerivedData will return right path. But if I had once opend the subproject and had build it. There will have a folder named "subProject" in derived path. Then as the function findDerivedData worked, it will found this folder and return it. But I think "../DerivedData/mainProject/..." is the right path.

@johnno1962
Copy link
Owner

johnno1962 commented Dec 1, 2017

What you say is true. Once you’ve built the subproject and it has derived data the logs will be taken from that directory. If it built that shouldn’t be a problem though particularly now the “cd” directory for the compile comes from the logs? It should use the most recently modified log directory perhaps.

@starFelix
Copy link
Author

Because the subProject's activitylog may be out of date. So it will failed when rebuild the file.

@johnno1962
Copy link
Owner

johnno1962 commented Dec 1, 2017

Something like the following?

    func findProject(for source: URL, derivedData: URL) -> (projectFile: URL, logsDir: URL)? {
        let dir = source.deletingLastPathComponent()
        if dir.path == "/" {
            return nil
        }

        var candidate = findProject(for: dir, derivedData: derivedData)

        if let files = try? FileManager.default.contentsOfDirectory(atPath: dir.path),
            let project = file(withExt: "xcworkspace", in: files) ?? file(withExt: "xcodeproj", in: files),
            let logsDir = logsDir(project: dir.appendingPathComponent(project), derivedData: derivedData),
            mtime(logsDir.path) > candidate.flatMap({ mtime($0.logsDir.path) }) ?? 0 {
                candidate = (dir.appendingPathComponent(project), logsDir)
        }

        return candidate
    }

@starFelix
Copy link
Author

When we start the app, the injection server will get the project root. Maybe transfer it to the client is better?

@johnno1962
Copy link
Owner

johnno1962 commented Dec 6, 2017

Pushed a version that determines the full log directory at the server and passes it through.

@johnno1962
Copy link
Owner

johnno1962 commented Dec 6, 2017

This release includes “Xprobe”, you’ll need to do a git clone https://github.com/johnno1962/InjectionIII --recurse-submodules now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants