bflattened / bflat

C# as you know it but with Go-inspired tooling (small, selfcontained, and native executables)
GNU Affero General Public License v3.0
3.63k stars 104 forks source link

`bflat build --target Shared --os linux ...` throws exception, looks like an arg parsing bug. #90

Open xiaoyuvax opened 1 year ago

xiaoyuvax commented 1 year ago

bflat build --target Shared --os linux <filelist> throws below exception, while bflat build --target Shared <filelist> works well.

Error: IO_FileNotFound_FileName, /--os
System.IO.FileNotFoundException: IO_FileNotFound_FileName, /--os
IO_FileName_Name, /--os
   at Interop.ThrowExceptionForIoErrno(Interop.ErrorInfo, String, Boolean) + 0x19
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String, Interop.Sys.OpenFlags, Int32, Func`4) + 0x105
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String, FileMode, FileAccess, FileShare, FileOptions, Int64, UnixFileMode, Int64&, UnixFileMode&, Func`4) + 0xdf
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String, FileMode, FileAccess, FileShare, FileOptions, Int64, Nullable`1) + 0x7f
   at ILBuildCommand.CreateCompilation(String, String[], String[], String[], OptimizationLevel, BuildTargetType, Boolean, String) + 0x2da
   at ILBuildCommand.Handle(ParseResult) + 0x166
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext() + 0x10b
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xc2
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x44
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<<UseParseErrorReporting>b__0>d.MoveNext() + 0xfd
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xc2
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x44
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass12_0.<<UseHelp>b__0>d.MoveNext() + 0xbd
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xc2
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x44
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseVersionOption>b__0>d.MoveNext() + 0x1c0
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xc2
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x44
   at System.CommandLine.Invocation.InvocationPipeline.<Invoke>g__FullInvocationChain|3_0(InvocationContext) + 0x9a
   at Program.Main(String[]) + 0x20b

Occured during compiling this demo project: https://github.com/xiaoyuvax/ObjectPoolReuseCaseDemo

MichalStrehovsky commented 1 year ago

I can't repro this - I ran bflat build --target Shared --os linux library.cs in the samples/DynamicLibrary directory of this repo.

Are you maybe using RSP files or something? The command line parser bflat uses is a big regret of mine: https://github.com/bflattened/bflat/pull/32#issue-1353505600

xiaoyuvax commented 1 year ago

i guess that command line parser is buggy somehow. yeah, it's in the RSP file, if i did not remember wrong, since recently i've been working on RSP, after u told me it's available. and this issue cannot be reproed manually.

xiaoyuvax commented 1 year ago

this issue is reproduced again today when using "build-il" , while change it to "build" is ok.

bflat build-il @build.rsp
Error: IO_FileNotFound_FileName, D:\Repos\bflata\bin\Debug\net7.0\--feature:System.Resources.ResourceManager.AllowCustomResourceTypes=true
IO_FileName_Name, D:\Repos\bflata\bin\Debug\net7.0\--feature:System.Resources.ResourceManager.AllowCustomResourceTypes=true
...

RSP file content:

-o Program.exe 
--target WinExe 
--feature:System.Resources.ResourceManager.AllowCustomResourceTypes=true
--feature:System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization=true
-O0
--ldflags /INCREMENTAL:no
Program.cs

The command line parser bflat uses is a big regret of mine: #32 (comment)

I guess it's true! :```-)

xiaoyuvax commented 1 year ago

possibly because build-il doesn't support any --feature opt?
i found --ldflags r not allowed too.

MichalStrehovsky commented 1 year ago

Yeah, those arguments don't make sense when building IL. The command line parser sends all unmatched parameters as file names. It's a ridiculous command line parser.

xiaoyuvax commented 1 year ago

should just be removed or ignored, so that user doesn't have to create different versions of args set for either 'build' or 'build-il'