[m-rev.] for review: format C# file names according to which C# compiler we are using

Peter Ross pro at missioncriticalit.com
Wed Jan 11 11:47:21 AEDT 2012


On 11 January 2012 02:57, Julien Fischer <juliensf at csse.unimelb.edu.au> wrote:
>
> Hi Pete,
>
>
> On Tue, 10 Jan 2012, Peter Ross wrote:
>
>> Estimated hours taken: 4
>> Branches: main, 11.07
>>
>> The Microsoft C# compiler only accepts paths in the Windows format, so
>> add code to format file names depending on which host environment we are
>> compiling and which C# compiler we are using.
>>
>> compiler/compile_target_code.m:
>>        Convert to file names to use windows paths when required.
>>
>> compiler/globals.m:
>> compiler/handle_options.m:
>> compiler/mercury_compile.m:
>> compiler/options.m:
>> m4/mercury.m4:
>> scripts/Mercury.config.in:
>>        Add code to determine the C# compiler type and pass it to the
>> compiler.
>>
>> doc/user_guide.texi:
>>        Document the --output-csharp-compiler-type option.
>>
>> Index: compiler/compile_target_code.m
>> ===================================================================
>> RCS file:
>> /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
>> retrieving revision 1.181
>> diff -u -r1.181 compile_target_code.m
>> --- compiler/compile_target_code.m      16 Dec 2011 03:38:20 -0000
>>  1.181
>> +++ compiler/compile_target_code.m      10 Jan 2012 02:43:25 -0000
>> @@ -2735,7 +2735,14 @@
>>    bool::out, io::di, io::uo) is det.
>>
>> create_csharp_exe_or_lib(Globals, ErrorStream, LinkTargetType,
>> MainModuleName,
>> -        OutputFileName, SourceList, Succeeded, !IO) :-
>> +        OutputFileName0, SourceList0, Succeeded, !IO) :-
>> +
>> +    get_host_env_type(Globals, EnvType),
>> +    get_csharp_compiler_type(Globals, CSharpCompilerType),
>> +
>> +    OutputFileName = csharp_file_name(EnvType, CSharpCompilerType,
>> OutputFileName0),
>> +    SourceList = list.map(csharp_file_name(EnvType, CSharpCompilerType),
>> SourceList0),
>> +
>>    globals.lookup_string_option(Globals, csharp_compiler, CSharpCompiler),
>>    globals.lookup_bool_option(Globals, highlevel_data, HighLevelData),
>>    (
>> @@ -2820,6 +2827,32 @@
>>        Succeeded = Succeeded0
>>    ).
>>
>> +    % Converts the given filename into a format acceptable to the C#
>> compiler.
>
>
> You should explain why this is necessary, e.g. because the MS C#
> compiler only accepts paths that use "\" as a the directory separator.
>
>
>> +    % Note we expect the given file name to be using "/" for the
>> directory separator.
>
>
> What do you mean by that?  It's entirely possible to be given something
> like:
>
>    C:\foo\bar\baz/Mercury/css/somefile.cs
>
The point I was trying to make was that we only handle one direction /
to \, for example
if another C# compiler doesn't handle \ we don't fix those up.

I've changed the comment to be as follows

    % Converts the given filename into a format acceptable to the C# compiler.
    %
    % This is because the MS C# compiler only allows \ as the path separator,
    % so we convert all / into \ when using the MC C# compiler.
    %

>
>> +:- func csharp_file_name(env_type, csharp_compiler_type, file_name) =
>> file_name.
>> +
>> +csharp_file_name(env_type_posix, csharp_microsoft, Filename) =
>> convert_to_windows_path_format(Filename).
>
>
> This combination should never occur.  You should just check for
> --host-env-type=posix --csharp-compiler-type=microsoft in
> compiler/handle_options.m and emit an error message there.
> You can just call unexpected/2 here.
>
>
Done, we output the following error

    ( HostEnvType = env_type_posix, CSharp_CompilerType = csharp_microsoft ->
        add_error(
            "`--host-env-type posix` is incompatible with\n" ++
            "`--csharp-compiler-type microsoft'.",
            !Errors)
    ;
        true
    ).


>> +csharp_file_name(env_type_posix, csharp_mono, Filename) = Filename.
>> +csharp_file_name(env_type_posix, csharp_unknown, Filename) = Filename.
>> +
>> +csharp_file_name(env_type_cygwin, csharp_microsoft, Filename) =
>> convert_to_windows_path_format(Filename).
>> +csharp_file_name(env_type_cygwin, csharp_mono, Filename) = Filename.
>> +csharp_file_name(env_type_cygwin, csharp_unknown, Filename) = Filename.
>> +
>> +    % MSYS converts the path for us to the windows format.
>> +csharp_file_name(env_type_msys, csharp_microsoft, Filename) = Filename.
>> +csharp_file_name(env_type_msys, csharp_mono, Filename) = Filename.
>> +csharp_file_name(env_type_msys, csharp_unknown, Filename) = Filename.
>> +
>> +csharp_file_name(env_type_win_cmd, csharp_microsoft, Filename) =
>> convert_to_windows_path_format(Filename).
>> +csharp_file_name(env_type_win_cmd, csharp_mono, Filename) = Filename.
>> +csharp_file_name(env_type_win_cmd, csharp_unknown, Filename) =
>> convert_to_windows_path_format(Filename).
>
>
> The rest looks okay.  Please wait until the end of the week before
> committing the remainder of this.
>
OK, will do.  Should I commit to the 11.07 branch as well, or will you
look after that.

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list