Xcode Locations Don't Work Properly - xcode

Whenever I add a new file to the project, it is added with the default location of "Relative to Group" and a problematic path of (for example):
../../../../../MyUsername/Folder/Foo/Foo/Foo/Bar.swift
It's not as if I put the file in another user's directory. In this case, ../myUsername resolves to .. Same with every other double dot. You could simplify it as follows:
../../../../../MyUsername/Folder/Foo/Foo/Foo/Bar.swift
../../../../Folder/Foo/Foo/Foo/Bar.swift
../../../Foo/Foo/Foo/Bar.swift
../../Foo/Foo/Bar.swift
../Foo/Bar.swift
Bar.swift
Because it literally is going down the path then going back up the same way. It is equivalent to running cd ../; cd ~- in a shell.
I expected the path to be simply Bar.swift. This causes many problems when using shared code because other people have the project in different places with different usernames.
The only solution I have found so far is manually editing the project.pbxproj file. What is causing this problem and what should I do to fix it?
Note: I suspect that this might have to do something with the case of the username due to the fact that the username is as far back as the path goes.
EDIT: Here is a screenshot (red is my username, and green is the app name):
Also, cding to the directory and running realpath ../../../../../MyUsername/Folder/Foo/Foo/Foo/Bar.swift returns Bar.swift.
EDIT 2: My suspicions were right about the username being case-sensitive! Look what happens when I set the Location to Absolute Path:
Previously, the username was only Title case (../MyUsername, /Users/MyUsername, etc.). However, now Xcode seems to go:
Down the directory tree from the lowercase username (to the group folder)...
Past the directory containing the project...
Into the directory containing the file...
Back up to the Users directory...
Down the same path with the Title case username.
I think that this is a bug in Xcode. If I had to guess, what happens internally is:
Xcode gets the absolute path to the file
From a file picker while adding
From a file picker while relocating by pressing the folder icon in the Location section
Somehow from creating a new file(?)
This path uses the Title case username.
Xcode gets the absolute group path
From its records (project.pbxproj?)
For some reason, this path uses the lowercase username
Xcode tries to figure out the path from #1 relative to the path from #2.
For example, if the path to the file was /foo/bar/baz.swift, and the group was /foo, the intended result is bar/baz.swift.
Xcode starts at the absolute path to the group (because the end path should be relative to the group).
Xcode looks at both paths and compares them. /Users/myusername/Folder/Foo/Foo/Foo vs /Users/MyUsername/Folder/Foo/Foo/Foo/Bar.swift.
Xcode sees that the only differences are:
At the end of the path (one has the filename and the other does not)
In the username (myusername vs MyUsername)
Xcode moves up to the farthest problem up the file tree using the double dot (../). /Users/myusername/Folder/Foo/Foo/Foo/../../../../.., or simply /Users.
Xcode starts down again, but this time uses the remaining portion of the absolute path for the file (Xcode never goes back down to /Users because it is the same for both paths).
Xcode continues all the way to the filename, using the Title case username. /Users/myusername/Folder/Foo/Foo/Foo/../../../../../MyUsername/Folder/Foo/Foo/Foo/Bar.swift.
When location is set to Relative to Group, the path to the group is implied, so the previous path simply becomes:
../../../../../MyUsername/Folder/Foo/Foo/Foo/Bar.swift.
Familiar?
Anyways, how do I fix that?????

It turns out that the problem was that I had my home directory path set to a different capitalization than the actual folder.

Related

Get FinalPath for any given UNC folder path (including NAS) and any per-user redirects

I need to figure out if a given (UNC) path actually points/ends/is the given path (directory).
Example: "\?\UNC\machine1\shared1". GetFinalPathNameByHandle will result in "\?\UNC\machine1\shared1".
However, if there's a symlink "sym" inside shared1 and the given path is "\?\UNC\machine1\shared1\sym", having "sym" be created with mklink and pointing to "\machine2\shared2", the result given by GetFinalPathNameByHandle is "\?\UNC\machine2\shared2".
Now, we have a QNAP NAS, with "home" folders enabled - meaning that each domain user, when navigating to "\nas\home", will end up in its own directory.
GetFinalPathNameByHandle for "\?\UNC\nas\home" results in "\?\UNC\nas\home", while I would need to get my hands on the actual directory name, like "\?\UNC\nas\homes\user_name". I do not need to read/write - I just need to know that "\?\UNC\nas\home" is really not "\?\UNC\nas\home".
This idea then propagates to any similar scenarios when "\machine\folder" ends up somewhere else (per user). Say I do not even need to know where does it really end, just that there's some kind of reparsing happening...
Any ideas?

perforce shorter client directory structure

This is a very basic query, but I am using perforce to create a workspace for a particular project that is deep in the depot directory.
Hence, on windows I am facing a warning as to "File name ... exceeds the limit of 260 characters"
I am trying to search a way to limit the folder structure to something just like : "C:\p4\dept.. " without the long list of folders.
Is there an easy way to do this?
I have come across following similar solution on :
[http://answers.perforce.com/articles/KB/3051?startURL=%2Farticles%2FKB_Article%2FSubmitting-or-Syncing-Files-with-Long-Path-Names][1]
But, cannot find out the command execution.
Is there a better, easier way to do this ?
The local paths (which exceed 260 chars in your case) are composed by concatenating
the workspace root
the paths (relative to the workspace root) as defined by your mapping.
To shorten the two, open Connection > Edit Current Workspace in P4V. Then
Shorten your Workspace root (e.g. to C:\p4)
Shorten your mappings:
In the same dialog as above, expand Workspace Mappings. This may be displayed as a graphical tree view. If that's the case, click one of the icons near its top-right corner to switch to a text-area view.
In the text-area view, each line has two parts: the depot path and the local path. The local path is something like //foo/some/relative/path/to/bar, where foo is your Workspace name. Shorten it to something like //foo/bar.
This should produce much shorter local paths.

What does it mean when you check on "Recursive" in Header Search Paths

I've been referencing a lot of Projects, and i do it through adding their paths in Header Search Paths.
I've been following the referencing stuffs through the "Referenced Project's" getting Started (like for example including the ZXingWidget).
And I've been doing it a lot now, but I don't understand the checking of recursive.
What does this mean?
When do I check a path for "recursive?"
Thanks
If you give Xcode a path to use for headers, it will check that path when you use an #include or #import statement. If the file isn't there, it quits.
If you have the path set as "recursive", Xcode will search folders it finds there if it doesn't find the file.
Looks like this:
1) Enter your desired path for Header Search Paths, click enter.
2) Double click the path text that you entered.
3) On the right of the dialog box select recursive.
For those wondering, as I was, what the effect of choosing recursive for a Header Search Path is on the compiler command line, it's to generate a -I argument for every directory in the tree rooted at the given path. This can lead to very long compiler command lines which will make looking for anything else in there well nigh impossible. So it's worth considering how many directories are below the path you are specifying if you want to use recursive.
I tried specifying -I../path/to/subproject/** as a Compiler Flag for an individual file but that doesn't work (which is obviously why Xcode does the expansion itself).
(this is true for Xcode 9.4.1)
Xcode Recursive path
When you set a path(e.g. Header Search Paths, Library Search Paths, Framework Search Paths...) you can define a path to one of parent folder and set recursive(/** will be added to the end of the path). For example you can defile a path to a include directory(or more over to a Build directory) with recursive parameter instead of include/<target_name>.
Please note: If the patch contains spaces - , you should escape them using \ or enclose the path in double quotes ""

Relative paths for portable notebooks in mathematica

I Cannot find how to use relative paths in mathematica. My directory structure is simple.
Import["G:\\Research\\Acc and Vel Runs\\5-24\\Mathematica\\Data\\250 \
Acc.xls"][[1]] // TableForm
That Demonstrates the Absolute path by using the insert path from the menus. I want this notebook to be portable. I want to give someone the "Mathematica" directory and I want them to be able to run the code. I don't want the paths to break because It will be run on a different machine. Basically I just want to use a relative path starting at the Mathematica level shown above.
In Mathematica you can get the current directory using Directory[] and you can set it to something else using SetDirectory[]. You can go back to the last location using ReserDirectory[] or check all previous locations using DirectoryStack[].
This is described in the documentation here.
You can set the current directory to the directory where the notebook is using
SetDirectory[NotebookDirectory[]]
For NotebookDirectory to work, you must be using the Front End and the notebook must be saved.
You can always use path relative to the current directory (Directory[]), for example Import["data/somedata.txt"].
Regarding directory separators: / will always works, on all of Windows/Linux/Mac. When you are typing a relative path name, it's much more convenient to just use / for portability than FileNameJoin.
I usually do this.
SetDirectory[
FileNameJoin[{$InitialDirectory, "dir1", "dir2"}]];
Quiet[Close["Log.txt"]];
logStream = Quiet[OpenWrite["xmlAreaTagsLog.txt"]];
xmlDoc = Import["XmlData.xml"];
Using $InitialDirectory gets you the .nb directory and using FileNameJoin allows you to have relative access.

Directory navigation in command prompts

I'm trying to run a batch file that exists in one folder, from a batch file in another folder:
Parent folder Big containes 2 folders BatchFolder and Medium.
BatchFolder contains a batch file called Batch1.
Medium contains another folder called Small.
Small contains a batch file called Batch2 that needs to run Batch1.
The command prompt is run from the location of Batch2
Therefor, how do I navigate up the folders To Big, and then navigate into the BatchFolder?
I've been trying alsorts to achieve this with no success, such as Bacth2 containing the following "call ../BatchFolder/Batch1.bat"
I'm not sure whether you really need to navigate to the required folder (i.e. set it as the current one) or you simply need a way to call the batch script in that folder using a relative path notation. Navigating, from how I understand the term, means the former, but your last sentence seem to show that you need the latter.
First, the answer:
call %~dp0%..\..\BatchFolder\Batch1.bat
Next, what it means. %~dp0% is a variation of %0: the latter is the full path to this batch file (i.e. Batch2.bat) including the file name, and the former is the full path to this batch's folder (including the trailing \).
.. points to the immediate parent folder. It is repeated twice because we need to access the 'grand-parent' of the Batch2.bat's folder, and the grand-parent is Big. Once we are pointing to Big, we can address the files/folders in it, in this case it's BatchFolder that we need, and eventually we can put the name of Batch1.bat.
This works regardless of what the current folder is. That is, in case I wasn't clear on that head, by simply calling a batch file you are not yet changing the current folder. You would have to use the CD command for that. That would be navigating (but I'm still open to being corrected as to my understanding of this term).

Resources