OPCFoundation / UA-ModelCompiler

ModelCompiler converts XML files into C# and ANSI C
MIT License
151 stars 92 forks source link

File path is formatted incorrectly #93

Closed Anokhi1994 closed 2 years ago

Anokhi1994 commented 3 years ago

We have a small issue when the ua-model-compiler tries to find the required .csv file. I work with @Pro on ua-model-compiler.

Problem: In the file https://github.com/OPCFoundation/UA-ModelCompiler/blob/0b660e9a8ff2e68098f1e846154e880b69f0b0fe/ModelCompiler/ModelDesignerValidator.cs In the method LoadIncludedDesignFile:

If the 

designFileName is ../deps/DI/OpcUaDiModel

Then

(refer) designFilePath = ../deps/DI/OpcUaDiModel.xml

(refer) identifiersFileName = ../deps/DI/OpcUaDiModel.csv

(refer) identifiersFilePath = Path.Combine(Path.GetDirectoryName("../deps/DI/OpcUaDiModel.xml"), "../deps/DI/OpcUaDiModel.csv");

(refer) identifiersFilePath = Path.Combine("../deps/DI", "../deps/DI/OpcUaDiModel.csv");

Now the identifierFilePath looks like this: identifiersFilePath = "../deps/DI/../deps/DI/OpcUaDiModel.csv" -> "../deps/deps/DI/OpcUaDiModel.csv"

The .csv is searched in this path. identifiersFilePath = "../deps/DI/../deps/DI/OpcUaDiModel.csv/../deps/DI/OpcUaDiModel.csv"

What is the error? We set the FilePath here : https://github.com/opcua-skills/plug-and-produce/blob/master/robot/universal-robots/opcua/universalRobotsModel.xml#L24 And as you see that FilePath is relative: FilePath="../deps/common/deps/robotics_cs/deps/vdma_robotics/OpcUaRoboticsModel"

Why it happens? The source code was changed that formats the identifierFilePath in an undesired way. Please see the diff: https://github.com/OPCFoundation/UA-ModelCompiler/commit/97617ed1ac1db5136b6094102fbf607d7731d4dd#diff-38638fa1be6837b60bf9468dbb641a52cfc3a28d20e025724577c5d7d4725d0fR433

It worked with the old version before the change since string identifiersFilePath = identifiersFileName; We just used the relative FilePath directly (changing .xml to .csv)

Now the path is always combined in a wrong way via: var identifiersFilePath = Path.Combine(Path.GetDirectoryName(designFilePath), identifiersFileName); (reference)

A quick fix: We just created a symlink of deps in deps. This is a workaround for now, but of course not very clean and quite messy.

We hope you can fix this for us, it will be really helpful.

opcfoundation-org commented 3 years ago

Change was needed to maintain multiple versions of the same specification/design file. A common CSV ensures updates always use the same NodeId if new Nodes are added.

Fixed the logic to fall back to the old behavior if no file is found at the new location. Should be merged to public repo in the next couple days.

opcfoundation-org commented 3 years ago

Fix merged.

Anokhi1994 commented 3 years ago

Thank you so much for fixing it. I could not find any pull requests where the logic is modified to fall back to the old behavior. Is it already on master now?

I think some of the files changed and I cannot find the changes for the issue. Could you point to the commit or the diff, it would be helpful.

Thank you so much.

opcfoundation-org commented 3 years ago

Changes got obscured by a directory name change. https://github.com/OPCFoundation/UA-ModelCompiler/commit/a74113df544a82cc291f4e424de9c13cbd9275f4#r57806501

opcfoundation-org commented 2 years ago

No response from poster.