Skip to content

Commit

Permalink
[wasm][build] Don't use GetTempFileName; emit webcil to subdir of obj (
Browse files Browse the repository at this point in the history
…#86972)

See #73793

Instead of using GetTempFileName (which can run out of temp file names
on Windows after 64K files), emit the temporary webcil files to a
directory in IntermediateOutputPath before copying them to the final
location, if they changed (which is elsewhere in
IntermediateOutputPath).
  • Loading branch information
lambdageek committed Jun 1, 2023
1 parent 19b1c9a commit a4dd36d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<_WasmBuildWebCilPath>$(IntermediateOutputPath)webcil</_WasmBuildWebCilPath>
</PropertyGroup>

<ConvertDllsToWebCil Candidates="@(_BuildAssetsCandidates)" OutputPath="$(_WasmBuildWebCilPath)" IsEnabled="$(_WasmEnableWebcil)">
<ConvertDllsToWebCil Candidates="@(_BuildAssetsCandidates)" IntermediateOutputPath="$(IntermediateOutputPath)tmp-webcil" OutputPath="$(_WasmBuildWebCilPath)" IsEnabled="$(_WasmEnableWebcil)">
<Output TaskParameter="WebCilCandidates" ItemName="_WebCilAssetsCandidates" />
<Output TaskParameter="FileWrites" ItemName="FileWrites" />
</ConvertDllsToWebCil>
Expand Down Expand Up @@ -391,7 +391,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<_WasmPublishWebCilPath>$(IntermediateOutputPath)webcil\publish</_WasmPublishWebCilPath>
</PropertyGroup>

<ConvertDllsToWebCil Candidates="@(_NewWasmPublishStaticWebAssets)" OutputPath="$(_WasmPublishWebCilPath)" IsEnabled="$(_WasmEnableWebcil)">
<ConvertDllsToWebCil Candidates="@(_NewWasmPublishStaticWebAssets)" IntermediateOutputPath="$(ConvertDllsToWebCil)tmp-webcil\publish" OutputPath="$(_WasmPublishWebCilPath)" IsEnabled="$(_WasmEnableWebcil)">
<Output TaskParameter="WebCilCandidates" ItemName="_NewWebCilPublishStaticWebAssets" />
<Output TaskParameter="FileWrites" ItemName="FileWrites" />
</ConvertDllsToWebCil>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class ConvertDllsToWebCil : Task
[Required]
public string OutputPath { get; set; }

[Required]
public string IntermediateOutputPath { get; set; }

[Required]
public bool IsEnabled { get; set; }

Expand All @@ -36,6 +39,7 @@ public class ConvertDllsToWebCil : Task
[Output]
public string[]? FileWrites => _fileWrites.ToArray();


public override bool Execute()
{
var webCilCandidates = new List<ITaskItem>();
Expand All @@ -52,21 +56,25 @@ public override bool Execute()

var extension = candidate.GetMetadata("Extension");
var filePath = candidate.ItemSpec;
var webcilFileName = Path.GetFileNameWithoutExtension(filePath) + Utils.WebcilInWasmExtension;

if (!Directory.Exists(OutputPath))
Directory.CreateDirectory(OutputPath);

if (extension == ".dll")
{
var tmpWebcil = Path.GetTempFileName();
var tmpDir = IntermediateOutputPath;
if (!Directory.Exists(tmpDir))
Directory.CreateDirectory(tmpDir);
var tmpWebcil = string.Concat (tmpDir, webcilFileName);
var webcilWriter = Microsoft.WebAssembly.Build.Tasks.WebcilConverter.FromPortableExecutable(inputPath: filePath, outputPath: tmpWebcil, logger: Log);
webcilWriter.ConvertToWebcil();

string candicatePath = Path.Combine(OutputPath, candidate.GetMetadata("Culture"));
if (!Directory.Exists(candicatePath))
Directory.CreateDirectory(candicatePath);

var finalWebcil = Path.Combine(candicatePath, Path.GetFileNameWithoutExtension(filePath) + Utils.WebcilInWasmExtension);
var finalWebcil = Path.Combine(candicatePath, webcilFileName);
if (Utils.CopyIfDifferent(tmpWebcil, finalWebcil, useHash: true))
Log.LogMessage(MessageImportance.Low, $"Generated {finalWebcil} .");
else
Expand Down

0 comments on commit a4dd36d

Please sign in to comment.