Opened 5 years ago

Closed 4 years ago

#5796 closed defect (fixed)

Models with long path names cause a code generation failure under Windows

Reported by: Francesco Casella Owned by: Lennart Ochel
Priority: blocker Milestone: 1.18.0
Component: Code Generation Version:
Keywords: Cc:

Description

When compiling model A.B.C.D, the current code generation module generates lots of intermediate files, such as A.B.C.D.c or A.B.C.D_12jac.c, etc., which OMEdit places in a directory named again as the full Modelica pathname. So you get filenames such as

C:\Users\John Doe\AppData\Local\Temp\OpenModelica\OMEdit\A.B.C.D\A.B.C.D_12jac.c

In case of libraries with long class names (which are encouraged in Modelica) and many nested packages, the full pathname can become very long and exceed the Windows limit of 256 characters on path names. This causes some models (e.g. in the ScalableTestSuite or PowerGrids library to fail without any apparent reason during code generation, which is very annoying.

Although it may makes sense to use the full pathname for the temp directory, to avoid aliasing, I understand there is really no need to use the full Modelica pathname as a prefix for all the intermediate filenames, since it is the same for all of them; I guess just using the last identifier (D in this case) would do, and would help mitigating the problem.

Using only D as prefix for the filenames looks like a very quick fix, that we should implent ASAP.

Change History (18)

comment:1 by Francesco Casella, 5 years ago

Milestone: 1.15.01.16.0

Release 1.15.0 was scrapped, because replaceable support eventually turned out to be more easily implemented in 1.16.0. Hence, all 1.15.0 tickets are rescheduled to 1.16.0

comment:2 by Francesco Casella, 4 years ago

Milestone: 1.16.01.17.0

Retargeted to 1.17.0 after 1.16.0 release

comment:3 by Francesco Casella, 4 years ago

This is very much apparent when trying to simulate
Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.ThermalResponseFactors.Validation.CylindricalHeatSource in OMEdit.

comment:4 by Francesco Casella, 4 years ago

Milestone: 1.17.01.18.0

comment:5 by Christoph Buchner <buchner@…>, 4 years ago

As a fix, you can maybe implement using extended-length paths, see the discussion at https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation. This mainly means adding a \\?\ prefix to paths.
I don't know if this plays nicely with OM internals, but I have successfully done this in Python code in the past - see an equivalent change that also includes UNC path handling here.

Btw, I think the limit is 260 chars, not 256.

comment:6 by Martin Sjölund, 4 years ago

You can manually set whatever prefix you want. Even in OMEdit (Simulation Setup -> Output -> File Name Prefix (Optional))

comment:7 by Adrian Pop, 4 years ago

The problem with using UNC paths is that gcc and make in msys2 didn't understand these.
So we could generate the code but not compile it.
I think that after the update to OMDev, the new gcc or maybe clang could work with UNC paths.
I'm not sure about make.

Another problem with UNC paths is that all the path handling needs to be done in the program, i.e. realpath, handling relative paths, etc.

I will do some checks with the new OMDev/msys2 and see if the UNC handling has been improved.

comment:8 by Christoph Buchner <buchner@…>, 4 years ago

Note: the extended-length path thing and UNC are somewhat orthogonal, but *if* you are using UNC paths, you need to tweak the fix beyond just slapping on a prefix. If you don't just the prefix "should" be fine (I haven't checked, though).

in reply to:  6 comment:9 by Francesco Casella, 4 years ago

Replying to sjoelund.se:

You can manually set whatever prefix you want. Even in OMEdit (Simulation Setup -> Output -> File Name Prefix (Optional))

This is not at all clear. By default that combo box is empty. What happens if I put in something? Is more stuff added to the already very long pathname?

comment:10 by Martin Sjölund, 4 years ago

This is not at all clear. By default that combo box is empty. What happens if I put in something? Is more stuff added to the already very long pathname?

It becomes whatever you put in there.

comment:11 by Francesco Casella, 4 years ago

Yeah, it could be a nice workaround, but you need to figure out first that the problem is that the default prefix is too long for Windows to handle. Not easy based on the OMEdit output.

I remain strongly in favour of not using the whole path name, but just the model name. It's simple and it solves most problems to most users automatically.

Can't we just do that, for starters?

comment:12 by Adeel Asghar, 4 years ago

See PR#7152.

in reply to:  12 comment:13 by Francesco Casella, 4 years ago

Replying to adeas31:

See PR#7152.

This fixes the issue in most cases: assuming 20-40 characters for the working directory base path (BTW, one could also use something short as c:\temp\omc), and 10-20 characters for the model name, there are over 200 characters left for the fully qualified name of the model being simulated. I think this is enough even for very complex and structured libraries. The longest fully qualified names in Buildings are around 120 characters.

comment:14 by Francesco Casella, 4 years ago

I'll check tomorrow with the nightly build and then close the ticket.

comment:15 by Francesco Casella, 4 years ago

Looks good, except that the .log file still uses the fully qualified name.

@adeas31, can you also take care of that?

Thanks!

comment:16 by Adeel Asghar, 4 years ago

Nice catch! Thanks for testing this @casella. The .log file name is fixed in 699fb91/OpenModelica.

comment:17 by Francesco Casella, 4 years ago

Just started a new nightly build. Will cross-check asap.

comment:18 by Francesco Casella, 4 years ago

Resolution: fixed
Status: newclosed

Worked like a charm. Going, going, gone!

Note: See TracTickets for help on using tickets.