perpetualKid / GetText.NET

A .NET Standard cross-platform implementation of GNU Gettext
Other
34 stars 11 forks source link

PathExtension requires Windows dll import #34

Closed devployment closed 2 years ago

devployment commented 2 years ago

Trying to run the extractor I get the following error on macOS, as the code imports a Windows native dll.

https://github.com/perpetualKid/GetText.NET/blob/95917ba4bbe38e4e9cd6928aaa5888c163260504/src/GetText.Extractor/Template/PathExtension.cs#L55

Not sure about the details, but might Path.GetRelativePath(String, String) do the job as well?

https://docs.microsoft.com/en-us/dotnet/api/system.io.path.getrelativepath?view=net-6.0

At least a quick smoke test seems to proof the example of the shlwapi documentation. But maybe I'm missing the point of public static string GetRelativePath's real usage.

Running on macOS

image

Running on Windows

image

❯ GetText.Extractor                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         ─╯
Unhandled exception: System.DllNotFoundException: Unable to load shared library 'shlwapi.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libshlwapi.dll, 0x0001): tried: 'libshlwapi.dll' (no such file), '/usr/local/lib/libshlwapi.dll' (no such file), '/usr/lib/libshlwapi.dll' (no such file), '/Users/dw/dev/com.pm-international/pmi.services.identity/Identity.API/libshlwapi.dll' (no such file), '/usr/local/lib/libshlwapi.dll' (no such file), '/usr/lib/libshlwapi.dll' (no such file)
   at GetText.Extractor.Template.NativeMethods.PathRelativePathTo(StringBuilder pszPath, String pszFrom, Int32 dwAttrFrom, String pszTo, Int32 dwAttrTo)
   at GetText.Extractor.Template.PathExtension.GetRelativePath(String relativeTo, String path, Boolean unixStyle) in /_/src/GetText.Extractor/Template/PathExtension.cs:line 27
   at GetText.Extractor.Engine.ParserBase`1.GetStrings(SyntaxTree tree)
   at GetText.Extractor.Engine.SyntaxTreeParser.<Parse>b__1_1(SyntaxTree tree) in /_/src/GetText.Extractor/Engine/SyntaxTreeParser.cs:line 37
   at System.Threading.Tasks.Dataflow.ActionBlock`1.ProcessMessage(Action`1 action, KeyValuePair`2 messageWithId)
   at System.Threading.Tasks.Dataflow.ActionBlock`1.<>c__DisplayClass6_0.<.ctor>b__0(KeyValuePair`2 messageWithId)
   at System.Threading.Tasks.Dataflow.Internal.TargetCore`1.ProcessMessagesLoopCore()
--- End of stack trace from previous location where exception was thrown ---
   at GetText.Extractor.Engine.SyntaxTreeParser.Parse() in /_/src/GetText.Extractor/Engine/SyntaxTreeParser.cs:line 44
   at GetText.Extractor.Program.Execute(FileInfo source, FileInfo target, Boolean unixStyle, Boolean sortOutput, Boolean verbose) in /_/src/GetText.Extractor/Program.cs:line 50
   at GetText.Extractor.Program.<>c.<<Main>b__1_0>d.MoveNext() in /_/src/GetText.Extractor/Program.cs:line 36
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Invocation.AnonymousCommandHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass18_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass13_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass20_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__19_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__6_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass9_0.<<UseExceptionHandler>b__0>d.MoveNext()
dotnet --info                                                                                                                                                                                                                                    ─╯
.NET SDK (reflecting any global.json):
 Version:   6.0.100
 Commit:    9e8b04bbff

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  12.2
 OS Platform: Darwin
 RID:         osx.12-x64
 Base Path:   /usr/local/share/dotnet/x64/sdk/6.0.100/

Host (useful for support):
  Version: 6.0.2
  Commit:  839cdfb0ec

.NET SDKs installed:
  3.1.415 [/usr/local/share/dotnet/x64/sdk]
  5.0.403 [/usr/local/share/dotnet/x64/sdk]
  6.0.100 [/usr/local/share/dotnet/x64/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.21 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.12 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.2 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.21 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.12 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.2 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
perpetualKid commented 2 years ago

seems safe to update using Path.GetRelativePath now.

I remember have been looked into that before, but originally when the extractor was build for .NET Standard 2.0 and NetFX there was no GetRelativePath available. However to publish as dotnet tool, the extractor had to be lifted to Standard 2.1 (whereas the GetText library still supports Standard 2.0), and obviously than, didn't rework the GetRelativePath.

If I'd update the code, would you be able to build locally and run (package if needed) before I publish a new nuget package? So we can test if there are other issues ie. on MacOS/Non-Windows?

devployment commented 2 years ago

If I'd update the code, would you be able to build locally and run (package if needed) before I publish a new nuget package?

Happy to do so. But there seems to be more to it being on macOS. The extractor project does not build ootb.

image

Building in Rider gives some more hints, but not sure about all of that at the moment. Need to dig a bit more in general here.

image

perpetualKid commented 2 years ago

I'll publish an RC version which we can use iterate if there are other issues, before having a new release. Takes a while to run the pipeline, I'll post an update when available

perpetualKid commented 2 years ago

there you go https://www.nuget.org/packages/GetText.NET.Extractor/1.2.4-rc since it's pre-release, you'll need to give the exact version for dotnet update dotnet tool update -g gettext.net.extractor --version 1.2.4-rc

devployment commented 2 years ago

Seems to work. Just executed it inside your project examples folder and it created the messages.pot file with content.

image

Does not extract anything in my project, but that's probably a different story. Will explore it a bit in general. As well try to figure out on how to build it locally on my machine.

perpetualKid commented 2 years ago

thanks for input/feedback. I'll keep the RC version for a few days so we can fix if further subsequent issues