When you add a project library to a project or a JAR file to a
solution, MPS asks you to choose the
path. The path you choose or enter is shown as absolute (say, /Users/sergej/Projects/myproject/mylibrary
) so how do
you make it work on other developers’ machines or in your CI environment?
It turns out that MPS will attempt to turn the absolute path into a relative path automatically, behind the scenes. In MPS terminology this is called path shrinking.
Relative to what? MPS will try a few possible starting points: a path variable, the directory of the current module
(${module}
) or project ($PROJECT_DIR$
), the lib
directory of MPS (${platform_lib}
) or the home directory of MPS
(${mps_home}
).
Unfortunately, the chosen starting point cannot be influenced and is not visible in the UI. You can, however, find the
shrunk path by manually inspecting the XML files that MPS writes (.mps/libraries.xml
for project libraries,
.mps/modules.xml
for project modules, or foo.msd
for the stubs associated with solution foo
).
Especially with regards to modules in a MPS project (stored in .mps/modules.xml
) it may happen that the path of the
module will not be stored relative to the project directory but relative to a path variable. If myproject.home
path
variable was defined to point to the project directory (as is customary to make MPS tests work), then occasionally
instead of storing the path as $PROJECT_DIR$/.../mysolution.msd
MPS would store it as
${myproject.home}/.../mysolution.msd
.
Although this seems harmless, it’s best to avoid path variables in module paths for two reasons.
First, a user that checks out the project for the first time may not have the variable defined and won’t be able to see any modules in the project.
Second, a path variable in MPS can only have one value. If the user wants to open a second copy of the project, the use of the path variable will cause all modules to be opened from the original copy.
This has been a source of much confusion historically. Fortunately, the bug that caused MPS to prefer a path variable over the project directory seems to have been fixed in the latest patch versions of MPS. Still, I wish the “shrunk” paths were visible in the UI and the whole shrinking functionality worked similar to Eclipse where you choose the starting point of a relative path explicitly.