Skip to content

[wasm][build] Don't use GetTempFileName; emit webcil to subdir of obj #86972

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

Merged
merged 1 commit into from
Jun 1, 2023
Merged
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 @@ -214,7 +214,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 @@ -387,7 +387,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