bool CheckAssetDirty(BuildDataInputFile file)
        {
            NPath path = file.path;

            if (!path.Exists())
            {
                Console.WriteLine($"Rebuilding Data files because {path} is dirty (deleted)");
                return(true);
            }

            string contentHash = "";

            if (path.Extension == "cs")
            {
                var monoScript = AssetDatabase.LoadAssetAtPath <MonoScript>(path.ToString());
                if (monoScript != null)
                {
                    contentHash = monoScript.GetPropertiesHashString(buildOptions.HasFlag(BuildOptions.Development));
                }
            }
            else
            {
                contentHash = AssetDatabase.GetAssetDependencyHash(file.path).ToString();
            }

            if (contentHash != file.contentHash)
            {
                Console.WriteLine($"Rebuilding Data files because {path} is dirty (hash)");
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// The Start implementation.
        /// </summary>
        protected override RunningProgram StartImpl(string workingDirectory, string[] arguments, Dictionary <string, string> envVars)
        {
            var executable = new NPath(Executable).MakeAbsolute();

            if (!executable.Exists())
            {
                executable = Executable; // fallback to system path
            }
            var psi = new ProcessStartInfo()
            {
                UseShellExecute        = false,
                FileName               = executable.ToString(SlashMode.Native),
                Arguments              = AlwaysArguments.Concat(arguments).SeparateWithSpace(),
                CreateNoWindow         = true,
                RedirectStandardError  = !StdOutMode.HasFlag(StdOutMode.Stream),
                RedirectStandardOutput = !StdOutMode.HasFlag(StdOutMode.Stream),
                RedirectStandardInput  = true,
                WorkingDirectory       = workingDirectory,
            };

            foreach (var kvp in AlwaysEnvironmentVariables)
            {
                psi.EnvironmentVariables[kvp.Key] = kvp.Value;
            }
            if (envVars != null)
            {
                foreach (var kvp in envVars)
                {
                    psi.EnvironmentVariables[kvp.Key] = kvp.Value;
                }
            }

            return(new SystemProcessRunningProgram(StdOutMode, psi));
        }
 private static List <FileInfo> CollectGeneratedFileInfo(NPath outputDirectory)
 {
     if (!outputDirectory.Exists(""))
     {
         return(new List <FileInfo>());
     }
     if (< > f__mg$cache0 == null)
     {
예제 #4
0
        public static TempFile CreateRandom()
        {
            string[] append = new string[] { System.IO.Path.GetRandomFileName() };
            NPath    path   = TempDir.Il2CppTemporaryDirectoryRoot.Combine(append);

            while (path.Exists(""))
            {
                string[] textArray2 = new string[] { System.IO.Path.GetRandomFileName() };
                path = TempDir.Il2CppTemporaryDirectoryRoot.Combine(textArray2);
            }
            return(new TempFile(path));
        }
예제 #5
0
        private static void RecreateDagDirectoryIfNeeded(NPath dagDirectory)
        {
            var beeBackendInfoPath = dagDirectory.Combine("bee_backend.info");
            var currentInfo        = new BeeBackendInfo()
            {
                BeeBackendHash = BeeBackendHash,
                UnityVersion   = Application.unityVersion
            };

            var diskInfo = new BeeBackendInfo();

            // Clear dag directory if it was produced with a different bee_backend, to avoid problem where bee_backend sometimes looses track of files.
            if (dagDirectory.Exists())
            {
                if (beeBackendInfoPath.Exists())
                {
                    var contents = beeBackendInfoPath.ReadAllText();
                    EditorJsonUtility.FromJsonOverwrite(contents, diskInfo);

                    // Note: We're clearing dag directory only when bee backend hash has changed, it's fine for Unity version to be different.
                    //       Unity version is used here for informational purposes, so we can clearly see from which Unity version the user was upgrading
                    if (string.IsNullOrEmpty(diskInfo.BeeBackendHash) ||
                        !diskInfo.BeeBackendHash.Equals(currentInfo.BeeBackendHash))
                    {
                        Console.WriteLine($"Clearing Bee directory '{dagDirectory}', since bee backend hash ('{beeBackendInfoPath}') is different, previous hash was {diskInfo.BeeBackendHash} (Unity version: {diskInfo.UnityVersion}), current hash is {currentInfo.BeeBackendHash} (Unity version: {currentInfo.UnityVersion}).");
                        dagDirectory.Delete();
                    }
                }
                else
                {
                    Console.WriteLine($"Clearing Bee directory '{dagDirectory}', since bee backend information ('{beeBackendInfoPath}') is missing.");
                    dagDirectory.Delete();
                }
            }

            dagDirectory.CreateDirectory();

            // Update info, if at least of one the fields is different
            if (string.IsNullOrEmpty(diskInfo.BeeBackendHash) ||
                string.IsNullOrEmpty(diskInfo.UnityVersion) ||
                !diskInfo.BeeBackendHash.Equals(currentInfo.BeeBackendHash) ||
                !diskInfo.UnityVersion.Equals(currentInfo.UnityVersion))
            {
                beeBackendInfoPath.WriteAllText(EditorJsonUtility.ToJson(currentInfo, true));
            }
        }
예제 #6
0
 public static bool ForgivingCleanDirectory(NPath directory)
 {
     try
     {
         if (directory.Exists(""))
         {
             directory.Delete(DeleteMode.Normal);
         }
         return(true);
     }
     catch (Exception)
     {
         if (!directory.Files(true).Any <NPath>())
         {
             return(true);
         }
     }
     return(false);
 }
예제 #7
0
        public override Shell.ExecuteResult RunAndMakeExecuteResult(string executable)
        {
            bool flag;

            Shell.ExecuteResult result;
            string[]            append = new string[] { "AppxManifest.xml" };
            NPath path = new NPath(Path.GetDirectoryName(executable)).Combine(append);

            if (!File.Exists(executable))
            {
                throw new ArgumentException($"Specified executable (" { executable } ") does not exist!");
            }
            if (!path.Exists(""))
            {
                throw new ArgumentException($"AppX manifest was not found next to the executable at " { path } "!");
            }
            WinRTManifest.AddActivatableClasses(path);
            using (Mutex mutex = new Mutex(true, @"Global\WinRTRunnerBuild", out flag))
            {
                if (!flag)
                {
                    mutex.WaitOne();
                }
                try
                {
                    MakeSureRunnerIsBuilt();
                    Shell.ExecuteArgs executeArgs = new Shell.ExecuteArgs {
                        Executable       = WinRTRunnerExecutablePath.ToString(),
                        Arguments        = path.InQuotes(),
                        WorkingDirectory = WinRTRunnerExecutablePath.Parent.ToString()
                    };
                    using (TinyProfiler.Section("Run WinRT Application", ""))
                    {
                        result = Shell.Execute(executeArgs, null);
                    }
                }
                finally
                {
                    mutex.ReleaseMutex();
                }
            }
            return(result);
        }
예제 #8
0
 public AndroidNDKUtilities(NPath ndkRootPath, Unity.IL2CPP.Building.Architecture architecture)
 {
     if (!ndkRootPath.Exists(""))
     {
         throw new ArgumentException("Android NDK path does not exist: " + ndkRootPath);
     }
     this.AndroidNdkRootDir = ndkRootPath;
     if (architecture is ARMv7Architecture)
     {
         this._architectureSettings = new ARMv7Settings();
     }
     else
     {
         if (!(architecture is x86Architecture))
         {
             throw new NotSupportedException("Unknown architecture: " + architecture);
         }
         this._architectureSettings = new X86Settings();
     }
 }
        internal static void InstallStreamingAssets(string stagingAreaDataPath, string streamingAssetsFolderName, BuildReport report)
        {
            if (Directory.Exists(StreamingAssets))
            {
                var outputPath = Path.Combine(stagingAreaDataPath, streamingAssetsFolderName);
                FileUtil.CopyDirectoryRecursiveForPostprocess(StreamingAssets, outputPath, true);
                report?.RecordFilesAddedRecursive(outputPath, CommonRoles.streamingAsset);
            }

            foreach (var(dst, src) in BuildPlayerContext.ActiveInstance.StreamingAssets)
            {
                NPath targetPlayerPath = $"{stagingAreaDataPath}/{streamingAssetsFolderName}/{dst}";
                if (targetPlayerPath.Exists())
                {
                    var errorMessage =
                        "error: Callback provided streaming assets file conflicts with file already present in project." +
                        $" Project file 'StreamingAssets/{dst}'. Callback provided file '{src}'.";
                    Debug.LogError(errorMessage);
                    throw new BuildFailedException(errorMessage);
                }
                FileUtil.UnityFileCopy(src.ToString(), targetPlayerPath.EnsureParentDirectoryExists().ToString());
                report?.RecordFileAdded(targetPlayerPath.ToString(SlashMode.Native), CommonRoles.streamingAsset);
            }
        }
예제 #10
0
    private static JObject ParseBuildSettingsFile()
    {
        var buildSettingsFile = new NPath("buildsettings.json");

        return(buildSettingsFile.Exists() ? JObject.Parse(buildSettingsFile.MakeAbsolute().ReadAllText()) : null);
    }
    public static Dictionary <string, List <DotsRuntimeCSharpProgramConfiguration> > MakeConfigs()
    {
        var platformList = DotsBuildSystemTargets;

        var settingsDir = new NPath("settings");

        if (settingsDir.Exists())
        {
            foreach (var settingsRelative in settingsDir.Files("*.json"))
            {
                var settingsFile = settingsRelative.MakeAbsolute();
                if (settingsFile.Exists())
                {
                    Backend.Current.RegisterFileInfluencingGraph(settingsFile);
                    var settingsObject = new FriendlyJObject {
                        Content = JObject.Parse(settingsFile.ReadAllText())
                    };

                    if (settingsObject.GetInt("Version", 0) != AsmDefConfigFile.BuildSettingsFileVersion ||
                        AsmDefConfigFile.AsmDefDescriptionFor(settingsObject.GetString("RootAssembly")) == null)
                    {
                        Console.WriteLine($"Found old settings file '{settingsFile}', removing...");
                        settingsFile.Delete();
                        continue;
                    }

                    var id = settingsObject.GetString("PlatformTargetIdentifier");

                    var target = platformList.Single(t => t.Identifier == id);

                    if (!target.ToolChain.CanBuild)
                    {
                        continue;
                    }

                    // Need to know this prior to determining need for burst
                    var mdb = ShouldEnableDevelopmentOptionForSetting("EnableManagedDebugging", new[] { DotsConfiguration.Debug, DotsConfiguration.Develop }, settingsObject);
                    if (!target.ValidateManagedDebugging(ref mdb))
                    {
                        continue;
                    }
                    if (mdb && DotsConfigForSettings(settingsObject, out var codeGen) == DotsConfiguration.Debug && target.ScriptingBackend == ScriptingBackend.TinyIl2cpp)
                    {
                        Errors.PrintWarning("Debug builds with managed debugging are very slow. It's recommended to use the Develop configuration instead.");
                    }

                    var multithreading  = settingsObject.GetBool("EnableMultithreading");
                    var targetUsesBurst = settingsObject.GetBool("EnableBurst");
                    if (!targetUsesBurst && multithreading)
                    {
                        // We currently do not support multithreaded debugging anywhere except .NET Framework and CoreCLR (so, Windows only)
                        // or il2cpp full profile
                        bool isFullIl2cpp = target.ScriptingBackend == ScriptingBackend.TinyIl2cpp && mdb;
                        bool isWindows    = target.ToolChain.Platform is WindowsPlatform;
                        if (!(isFullIl2cpp || isWindows))
                        {
                            Errors.PrintWarning($"BuildConfiguration '{settingsFile.FileNameWithoutExtension}' " +
                                                $"specified 'EnableBurst=False', but 'Multithreading=True'. Multithreading requires Burst, therefore enabling Burst.");
                            targetUsesBurst = true;
                        }
                    }

                    var dotsCfg        = DotsConfigForSettings(settingsObject, out var codegen);
                    var enableProfiler = ShouldEnableDevelopmentOptionForSetting("EnableProfiler", new [] { DotsConfiguration.Develop }, settingsObject);
                    var enableUnityCollectionsChecks = ShouldEnableDevelopmentOptionForSetting("EnableSafetyChecks", new[] { DotsConfiguration.Debug, DotsConfiguration.Develop }, settingsObject);

                    if (!target.CanUseBurst && targetUsesBurst)
                    {
                        Console.WriteLine($"Warning: BuildConfiguration '{settingsFile.FileNameWithoutExtension}' " +
                                          $"specified 'EnableBurst', but target ({target.Identifier}) does not support burst yet. Not using burst.");
                        targetUsesBurst = false;
                    }

                    // Workaround to disable burst in web debug builds since it will fail to compile
                    // https://unity3d.atlassian.net/browse/DOTSR-1886
                    if (targetUsesBurst && target is DotsWebTarget && codegen == CSharpCodeGen.Debug)
                    {
                        Console.WriteLine($"Warning: Web currently does not support building in debug configuration with Burst. Disabling burst....");
                        targetUsesBurst = false;
                    }

                    var waitForManagedDebugger = settingsObject.GetBool("WaitForManagedDebugger");

                    var    rootAssembly   = settingsObject.GetString("RootAssembly");
                    string finalOutputDir = null;
                    if (settingsObject.Content.TryGetValue("FinalOutputDirectory", out var finalOutputToken))
                    {
                        finalOutputDir = finalOutputToken.Value <string>();
                    }

                    var defines = new List <string>();
                    if (settingsObject.Content.TryGetValue("ScriptingDefines", out var definesJToken))
                    {
                        defines = ((JArray)definesJToken).Select(token => token.Value <string>()).ToList();
                    }

                    if (!PerConfigBuildSettings.ContainsKey(rootAssembly))
                    {
                        PerConfigBuildSettings[rootAssembly] = new List <DotsRuntimeCSharpProgramConfiguration>();
                    }

                    var identifier = settingsFile.FileNameWithoutExtension;
                    do
                    {
                        PerConfigBuildSettings[rootAssembly]
                        .Add(
                            target.CustomizeConfigForSettings(new DotsRuntimeCSharpProgramConfiguration(
                                                                  csharpCodegen: codegen,
                                                                  cppCodegen: codegen == CSharpCodeGen.Debug ? CodeGen.Debug : CodeGen.Release,
                                                                  nativeToolchain: target.ToolChain,
                                                                  scriptingBackend: target.ScriptingBackend,
                                                                  targetFramework: target.TargetFramework,
                                                                  identifier: identifier,
                                                                  enableUnityCollectionsChecks: enableUnityCollectionsChecks,
                                                                  enableManagedDebugging: mdb,
                                                                  waitForManagedDebugger: waitForManagedDebugger,
                                                                  multiThreadedJobs: multithreading,
                                                                  dotsConfiguration: dotsCfg,
                                                                  enableProfiler: enableProfiler,
                                                                  useBurst: targetUsesBurst,
                                                                  defines: defines,
                                                                  finalOutputDirectory: finalOutputDir),
                                                              settingsObject));

                        //We have to introduce the concept of "complementary targets" to accommodate building "fat" binaries on Android,
                        //for both armv7 and arm64 architectures. This means we have to build two copies of the final binaries, and then do one
                        //packaging step to package both steps into a single apk. But also, since C# code is allowed to do #if UNITY_DOTSRUNTIME64
                        //(and indeed we need that ability for the static type registry to generate correct sizes of things), we need to compile
                        //two sets of c# assemblies, one per architecture, and run il2cpp and burst on each one separately, in order to produce
                        //these two sets of final binaries.
                        //For that purpose, we associate a second DotsRuntimeCSharpProgramConfiguration (known as the complementary target) to
                        //specify the build for the other architecture we wish to compile against, and we do all the building steps up to the final
                        //packaging step for that config as well as the main one. We skip the final packaging step for the complementary config,
                        //and make the packaging step for the main config consume both sets of binaries.
                        //This is a crazy scheme, and we theorize and hope that when we adopt the incremental buildpipeline, we will be able
                        //to use their concept of per-platform custom graph build steps to make this be more reasonable.
                        target = target.ComplementaryTarget;

                        //We use "identifier" as a directory name for all intermediate files.
                        //For complementary target these files will be generated in "target.Identifier" subdirectory.
                        //So for example in case of arm64 complemenary target a path would be
                        //"{target.Identifiler}/android_complementary_arm64".
                        if (target != null)
                        {
                            identifier += "/" + target.Identifier;
                        }
                    } while (target != null);
                }
            }
        }

        return(PerConfigBuildSettings);
    }
예제 #12
0
    public static Dictionary <string, List <DotsRuntimeCSharpProgramConfiguration> > MakeConfigs()
    {
        var platformList = DotsBuildSystemTargets;

        var settingsDir = new NPath("settings");

        if (settingsDir.Exists())
        {
            foreach (var settingsRelative in settingsDir.Files("*.json"))
            {
                var settingsFile = settingsRelative.MakeAbsolute();
                if (settingsFile.Exists())
                {
                    Backend.Current.RegisterFileInfluencingGraph(settingsFile);
                    var settingsObject = new FriendlyJObject {
                        Content = JObject.Parse(settingsFile.ReadAllText())
                    };

                    var id = settingsObject.GetString("PlatformTargetIdentifier");

                    var target = platformList.Single(t => t.Identifier == id);

                    if (!target.ToolChain.CanBuild)
                    {
                        continue;
                    }

                    var targetShouldUseBurst = settingsObject.GetBool("UseBurst");

                    var dotsCfg = DotsConfigForSettings(settingsObject, out var codegen);
                    var enableUnityCollectionsChecks = dotsCfg != DotsConfiguration.Release;
                    if (!target.CanUseBurst && targetShouldUseBurst)
                    {
                        Console.WriteLine($"Warning: BuildConfiguration '{settingsFile.FileNameWithoutExtension}' " +
                                          $"specified 'UseBurst', but target ({target.Identifier}) does not support burst yet. Not using burst.");
                        targetShouldUseBurst = false;
                    }

                    var mdb = ManagedDebuggingForSettings(settingsObject);
                    if (target.Identifier == "asmjs" || target.Identifier == "wasm")
                    {
                        mdb = false;
                    }
                    var waitForManagedDebugger = settingsObject.GetBool("WaitForManagedDebugger");

                    var    rootAssembly   = settingsObject.GetString("RootAssembly");
                    string finalOutputDir = null;
                    if (settingsObject.Content.TryGetValue("FinalOutputDirectory", out var finalOutputToken))
                    {
                        finalOutputDir = finalOutputToken.Value <string>();
                    }

                    var multithreading = settingsObject.GetBool("EnableMultiThreading");
                    var defines        = new List <string>();

                    if (settingsObject.Content.TryGetValue("ScriptingDefines", out var definesJToken))
                    {
                        defines = ((JArray)definesJToken).Select(token => token.Value <string>()).ToList();
                    }

                    if (!PerConfigBuildSettings.ContainsKey(rootAssembly))
                    {
                        PerConfigBuildSettings[rootAssembly] = new List <DotsRuntimeCSharpProgramConfiguration>();
                    }

                    PerConfigBuildSettings[rootAssembly]
                    .Add(
                        new DotsRuntimeCSharpProgramConfiguration(
                            csharpCodegen: codegen,
                            cppCodegen: codegen == CSharpCodeGen.Debug ? CodeGen.Debug : CodeGen.Release,
                            nativeToolchain: target.ToolChain,
                            scriptingBackend: target.ScriptingBackend,
                            targetFramework: target.TargetFramework,
                            identifier: settingsFile.FileNameWithoutExtension,
                            enableUnityCollectionsChecks: enableUnityCollectionsChecks,
                            enableManagedDebugging: mdb,
                            waitForManagedDebugger: waitForManagedDebugger,
                            multiThreadedJobs: multithreading,
                            dotsConfiguration: dotsCfg,
                            useBurst: targetShouldUseBurst,
                            executableFormat: target.CustomizeExecutableForSettings(settingsObject),
                            defines: defines,
                            finalOutputDirectory: finalOutputDir));
                }
            }
        }

        return(PerConfigBuildSettings);
    }
예제 #13
0
    public static Dictionary <string, List <DotsRuntimeCSharpProgramConfiguration> > MakeConfigs()
    {
        var platformList = DotsBuildSystemTargets;

        var settingsDir = new NPath("settings");

        if (settingsDir.Exists())
        {
            foreach (var settingsRelative in settingsDir.Files("*.json"))
            {
                var settingsFile = settingsRelative.MakeAbsolute();
                if (settingsFile.Exists())
                {
                    Backend.Current.RegisterFileInfluencingGraph(settingsFile);
                    var settingsObject = new FriendlyJObject {
                        Content = JObject.Parse(settingsFile.ReadAllText())
                    };

                    var id = settingsObject.GetString("PlatformTargetIdentifier");

                    var target = platformList.Single(t => t.Identifier == id);

                    if (!target.ToolChain.CanBuild)
                    {
                        continue;
                    }

                    var targetShouldUseBurst = settingsObject.GetBool("UseBurst");

                    var dotsCfg = DotsConfigForSettings(settingsObject, out var codegen);
                    var enableUnityCollectionsChecks = dotsCfg != DotsConfiguration.Release;

                    /* dotnet reorders struct layout when there are managed components in the job struct,
                     * most notably DisposeSentinel. Mono does not. So disable burst on windows dotnet when
                     * collections checks are enabled.
                     */
                    var canUseBurst = target.CanUseBurst &&
                                      !(target is DotsWindowsDotNetTarget &&
                                        target.ScriptingBackend == ScriptingBackend.Dotnet &&
                                        enableUnityCollectionsChecks);
                    if (!canUseBurst && targetShouldUseBurst)
                    {
                        Console.WriteLine(
                            "Warning: UseBurst specified, but target does not support burst yet. Not using burst.");
                        targetShouldUseBurst = false;
                    }

                    var mdb = settingsObject.GetBool("EnableManagedDebugging");

                    var    rootAssembly   = settingsObject.GetString("RootAssembly");
                    string finalOutputDir = null;
                    if (settingsObject.Content.TryGetValue("FinalOutputDirectory", out var finalOutputToken))
                    {
                        finalOutputDir = finalOutputToken.Value <string>();
                    }

                    var multithreading = settingsObject.GetBool("EnableMultiThreading");
                    var defines        = new List <string>();

                    if (settingsObject.Content.TryGetValue("ScriptingDefines", out var definesJToken))
                    {
                        defines = ((JArray)definesJToken).Select(token => token.Value <string>()).ToList();
                    }

                    if (!PerConfigBuildSettings.ContainsKey(rootAssembly))
                    {
                        PerConfigBuildSettings[rootAssembly] = new List <DotsRuntimeCSharpProgramConfiguration>();
                    }

                    PerConfigBuildSettings[rootAssembly]
                    .Add(
                        new DotsRuntimeCSharpProgramConfiguration(codegen,
                                                                  codegen == CSharpCodeGen.Debug ? CodeGen.Debug : CodeGen.Release,
                                                                  target.ToolChain,
                                                                  target.ScriptingBackend,
                                                                  settingsFile.FileNameWithoutExtension,
                                                                  enableUnityCollectionsChecks,
                                                                  mdb,
                                                                  multithreading,
                                                                  dotsCfg,
                                                                  targetShouldUseBurst,
                                                                  target.CustomizeExecutableForSettings(settingsObject),
                                                                  defines,
                                                                  finalOutputDir));
                }
            }
        }

        return(PerConfigBuildSettings);
    }