Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wasm] Having space in path fails builds #92399

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class BuildEnvironment
public static readonly string RelativeTestAssetsPath = @"..\testassets\";
public static readonly string TestAssetsPath = Path.Combine(AppContext.BaseDirectory, "testassets");
public static readonly string TestDataPath = Path.Combine(AppContext.BaseDirectory, "data");
public static readonly string TmpPath = Path.Combine(AppContext.BaseDirectory, "wbt");
public static readonly string TmpPath = Path.Combine(AppContext.BaseDirectory, "wbt artifacts");

public static readonly string DefaultRuntimeIdentifier =
#if TARGET_WASI
Expand Down
6 changes: 3 additions & 3 deletions src/mono/wasm/build/WasmApp.Native.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<UsingTask TaskName="Microsoft.WebAssembly.Build.Tasks.ManagedToNativeGenerator" AssemblyFile="$(WasmAppBuilderTasksAssemblyPath)" />
<UsingTask TaskName="Microsoft.WebAssembly.Build.Tasks.EmccCompile" AssemblyFile="$(WasmAppBuilderTasksAssemblyPath)" />
<UsingTask TaskName="MonoTargetsTasks.MarshalingPInvokeScanner" AssemblyFile="$(MonoTargetsTasksAssemblyPath)" />
<UsingTask TaskName="MonoTargetsTasks.MarshalingPInvokeScanner" AssemblyFile="$(MonoTargetsTasksAssemblyPath)" />

<PropertyGroup>
<_WasmBuildNativeCoreDependsOn>
Expand Down Expand Up @@ -211,7 +211,7 @@

<_EmccCompileBitcodeRsp>$(_WasmIntermediateOutputPath)emcc-compile-bc.rsp</_EmccCompileBitcodeRsp>
<_EmccLinkRsp>$(_WasmIntermediateOutputPath)emcc-link.rsp</_EmccLinkRsp>

<EmccInitialHeapSize Condition="'$(EmccInitialHeapSize)' == ''">$(EmccTotalMemory)</EmccInitialHeapSize>
<EmccStackSize Condition="'$(EmccStackSize)' == ''">5MB</EmccStackSize>
<WasmAllowUndefinedSymbols Condition="'$(WasmAllowUndefinedSymbols)' == ''">false</WasmAllowUndefinedSymbols>
Expand Down Expand Up @@ -250,7 +250,7 @@
<_EmccCFlags Include="-DGEN_PINVOKE=1" />
<_EmccCFlags Include="-emit-llvm" />

<_EmccCFlags Include="&quot;-I%(_EmccIncludePaths.Identity)&quot;" />
<_EmccCFlags Include="-I&quot;%(_EmccIncludePaths.Identity)&quot;" />

<!-- Adding optimization flag at the top, so it gets precedence -->
<_EmccLDFlags Include="$(EmccLinkOptimizationFlag)" />
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/build/WasmApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@
<FileWrites Include="$(WasmRunV8ScriptPath)" />
</ItemGroup>

<Exec Condition="'$(OS)' != 'Windows_NT'" Command="chmod a+x $(WasmRunV8ScriptPath)" />
<Exec Condition="'$(OS)' != 'Windows_NT'" Command="chmod a+x '$(WasmRunV8ScriptPath)'" />
</Target>

<Target Name="_WasmResolveReferences" Condition="'$(WasmResolveAssembliesBeforeBuild)' == 'true'">
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/AotCompilerTask/MonoAOTCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ private PrecompileArguments GetPrecompileArgumentsFor(ITaskItem assemblyItem, st
if (isDedup)
{
foreach (var aItem in _assembliesToCompile!)
processArgs.Add(aItem.ItemSpec);
processArgs.Add('"' + aItem.ItemSpec + '"');
}
else
{
Expand Down
99 changes: 99 additions & 0 deletions src/tasks/WasmAppBuilder/CreateResponseFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace Microsoft.WebAssembly.Build.Tasks
{
/// <summary>
/// This cannot be done with WriteLinesToFile task because we need to parse EmccCFlags before saving to file
/// by escaping spaces with backslashes. MsBuild converts all backslashes to forward slashes automatically,
/// so it cannot be done directly in the .targets (https://github.com/dotnet/msbuild/issues/3468).
/// </summary>
public class CreateResponseFile : Microsoft.Build.Utilities.Task
{
[NotNull]
[Required]
public ITaskItem[]? EmccCFlags { get; set; }
[Required]
public string? FilePath { get; set; }
public bool Overwrite { get; set; } = true;
public bool WriteOnlyWhenDifferent{ get; set; } = true;
public override bool Execute()
{
try
{
return ExecuteActual();
}
catch (LogAsErrorException laee)
{
Log.LogError(laee.Message);
return false;
}
}

private bool ExecuteActual()
{
if (EmccCFlags.Length == 0)
{
Log.LogError($"No Emcc flags to write");
return false;
}

if (string.IsNullOrEmpty(FilePath))
{
Log.LogError($"FilePath is empty");
return false;
}

if (File.Exists(FilePath))
{
if (!Overwrite)
return true;
var lines = File.ReadLines(FilePath);
bool isDifferent = lines.Count() != EmccCFlags.Length;
if (!isDifferent)
{
foreach (var element in lines.Zip(EmccCFlags, (line, flag) => new { Line = line, Flag = flag }) )
{
if (element.Line != element.Flag.ItemSpec)
{
Log.LogMessage($"Has a different line, element.Line={element.Line}, element.Flag.ItemSpec={element.Flag.ItemSpec}");
isDifferent = true;
break;
}
}
}
if (WriteOnlyWhenDifferent && isDifferent)
return true;
Write(FilePath, EmccCFlags);
}
else
{
Write(FilePath, EmccCFlags);
}
return !Log.HasLoggedErrors;
}

private static void Write(string path, ITaskItem[] flags)
{
using (StreamWriter outputFile = new StreamWriter(path))
{
foreach (ITaskItem flag in flags)
{
outputFile.WriteLine(flag.ItemSpec.Replace(" ", "\\ "));
}
}
}
}
}
Loading