Welcome to mirror list, hosted at ThFree Co, Russian Federation.

RunWithEmSdkEnv.cs « WasmAppBuilder « tasks « src - github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: eb1fe1f712f880ed4579f5dc8ff9c37348bf0f82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Build.Framework;
using Microsoft.Build.Tasks;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.InteropServices;

namespace Microsoft.WebAssembly.Build.Tasks
{
    public class RunWithEmSdkEnv : Exec
    {
        [NotNull]
        [Required]
        public string? EmSdkPath { get; set; }

        public override bool Execute()
        {
            IgnoreStandardErrorWarningFormat = true;
            StandardOutputImportance = "Low";

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                string envScriptPath = Path.Combine(EmSdkPath, "emsdk_env.bat");
                if (!CheckEnvScript(envScriptPath))
                    return false;

                Command = $"@cmd /c \"call \"{envScriptPath}\" > nul 2>&1 && {Command}\"";
            }
            else
            {
                string envScriptPath = Path.Combine(EmSdkPath, "emsdk_env.sh");
                if (!CheckEnvScript(envScriptPath))
                    return false;

                Command = $"bash -c 'source {envScriptPath} > /dev/null 2>&1 && {Command}'";
            }

            var workingDir = string.IsNullOrEmpty(WorkingDirectory) ? Directory.GetCurrentDirectory() : WorkingDirectory;
            Log.LogMessage(MessageImportance.Low, $"Working directory: {workingDir}");
            Log.LogMessage(MessageImportance.Low, $"Using Command: {Command}");

            return base.Execute() && !Log.HasLoggedErrors;

            bool CheckEnvScript(string envScriptPath)
            {
                if (!File.Exists(envScriptPath))
                    Log.LogError($"Could not find '{envScriptPath}' required to run command: {Command}");

                return !Log.HasLoggedErrors;
            }
        }
    }
}