Skip to content

Conversation

@dimitre
Copy link
Member

@dimitre dimitre commented Apr 4, 2023

@dimitre dimitre marked this pull request as ready for review April 4, 2023 18:36
@ofTheo
Copy link
Member

ofTheo commented Apr 6, 2023

Ahh - thanks @dimitre!
One thing I noticed when testing #332 is projectDir was always absolute for me ( at least at this point https://github.com/openframeworks/projectGenerator/blob/master/ofxProjectGenerator/src/projects/baseProject.cpp#L22 )

So if I passed in a relative path for the project or an absolute path or an absolute path outside of the OF path projectDir was always absolute at that point. Things get made relative later but just good to know especially if you are relying on projectDir being both relative and absolute ( which it doesn't seem to be ).

Not sure if that affects this PR. But just wanted to mention it.

Also wondering how many filesystem bugs we might fix ( for spaces and non English characters ) if we handled paths relatively from an early stage. In the PG app. ( ie: if OF is a relative path and project is relative, we don't even need an abs path ). But that might be another large PR / project 🙂


projectDir = projectDir.lexically_normal();
if (projectDir.is_absolute()) {
relRoot = getOFRoot();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my experience is getOFRoot() is always absolute - but might be worth checking.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is, yes. in this case I'm setting relRoot to absolute root path, so we don't have some absurd relative paths going all the way down to root, like
../../../../../../../Users/z/Desktop/project

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might need a bit more handling here. First you would want to make relRoot relative to projectDir but only make relative if the projectDir exists inside the OF folder.

I think very similar to what I did here:
https://github.com/openframeworks/projectGenerator/blob/master/ofxProjectGenerator/src/projects/baseProject.cpp#L221-L224

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obviously in this case relRoot is misnamed. in fact updating PG always have the feeling it has to be completely rewritten :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise I think it will end up replacing ../../../ with absolute OF paths :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this is the best option.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to update this PR if you have the time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool - will do!
I just checked and it is currently making projectDir absolute - so then then relRoot gets made abs.

 relRoot is ../..
 projectDir is "/Users/theo/Documents/CODE/__OPENFRAMEWORKS/openFrameworks/apps/test123"
 relRoot is /Users/theo/Documents/CODE/__OPENFRAMEWORKS/openFrameworks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah with your path inside path detection it will do it right
yesterday before your PR I was searching for the same thing. I was wondering if std::filesystem had a function to check if a path contains another, so nothing in this case.
I was going to test this snipped but I've seen you already solved in your PR
Maybe we could have a function in Utils.cpp (or the core) so your solution can be reused if needed in other places.

bool is_subpath(const std::filesystem::path &path,
                const std::filesystem::path &base)
{
    auto rel = std::filesystem::relative(path, base);
    return !rel.empty() && rel.native()[0] != '.';
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dimitre yes! great idea. having a is_subpath or even more specific isPathInOFRoot or something would be helpful - the rfind approach is kind of hard to follow ( though it seems to work well )

@ofTheo
Copy link
Member

ofTheo commented Apr 6, 2023

Okay this should be good now.

a few tests:

[notice ] setting up new project /Users/theo/Documents/CODE/__OPENFRAMEWORKS/openFrameworks/apps/projectGenerator/commandLine/bin/../../../../apps/test345
 relRoot is ../..
 projectDir is "/Users/theo/Documents/CODE/__OPENFRAMEWORKS/openFrameworks/apps/test345"
 relRoot is ../..
[notice ] setting up new project /Users/theo/Documents/CODE/__OPENFRAMEWORKS/openFrameworks/apps/projectGenerator/commandLine/bin/../../../../apps/myApps/123App
 relRoot is ../../..
 projectDir is "/Users/theo/Documents/CODE/__OPENFRAMEWORKS/openFrameworks/apps/myApps/123App"
 relRoot is ../../..
[notice ] setting up new project /Users/theo/Desktop/_Test345
 relRoot is ../../Documents/CODE/__OPENFRAMEWORKS/openFrameworks
 projectDir is "/Users/theo/Desktop/_Test345"
 relRoot is /Users/theo/Documents/CODE/__OPENFRAMEWORKS/openFrameworks

And all the OF files show up in the side bar as expected.

@ofTheo ofTheo merged commit 8a3a744 into openframeworks:master Apr 6, 2023
@dimitre dimitre deleted the abs branch March 5, 2025 02:39
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

Successfully merging this pull request may close these issues.

Xcode sidebar OF reference/group is relative to ../../.. wherever the project is PG-created/updated

2 participants