Skip to content

Support line continuation characters on Unix #585

Open
@jonpryor

Description

In some recent work I've had need to execute an external program, so the <Exec/> task comes in handy:

<Exec Command="configure" />

The problem, though, is that the command I really need to execute is long -- resulting in a line which is nearly 596 characters long:

<Exec
       Command="configure LD=&quote;...&quote; ... # plus hundreds more characters..."
/>

I want shorter lines, both to make it easier to read, and to simplify version control review and validation (long lines make for terrible diffs).

There are (at least?) two ways to make for shorter lines:

  1. Use more variables

    <PropertyGroup>
      <Ld>LD=&quot;@(Runtimes->'%(Ld)')&quot;</Ld>
      <!-- ... -->
    </PropertyGroup>
    <Exec
        Command="configure $(Ld) ..."
    />
    
  2. Use line continuations:

    <Exec
        Command="configure ^
          LD=&quot;...&quot; ^
          ..."
    />
    

Truth be told, I tried (1) first, but that doesn't work with xbuild on OS X (doh!).

So I try the Unix variant on (2):

<Exec
    Command="configure \
      LD=&quot;...&quot; \
      ..."
/>

...which promptly fails because \ is replaced with / at all instances in both xbuild and msbuild (which is why I'm bringing it up here... ;-).

What would be useful is some way of using line-continuation characters in a portable fashion. I can think of two ways to support this:

  1. On Unix, replace ^<newline> with \<newline>. This would allow us to use the Windows line-continuation character of ^ in a portable fashion.

    The problem with this is if there are any shells or commands for which a trailing ^ is appropriate, though I can't think of any programs which use ^ in this manner offhand.

  2. Fix the s#\#/#g replacement that MSBuild performs so that \<newline> can be used within the //Exec/@Command attribute. Then, we could use Conditional to have one command for Windows and a different command for Unix:

    <Exec
        Condition="' $(OS' == 'Windows_NT' "
        Command="this is a ^
          very long command"
    />
    <Exec
        Condition="' $(OS' != 'Windows_NT' "
        Command="this is a \
          very long command"
    />
    

Metadata

Assignees

No one assigned

    Labels

    Area: EngineIssues impacting the core execution of targets and tasks.help wantedIssues that the core team doesn't plan to work on, but would accept a PR for. Comment to claim.needs-designRequires discussion with the dev team before attempting a fix.triagedxplat

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions