Skip to content

Commit

Permalink
0.14.3-preview - 2019/03/12
Browse files Browse the repository at this point in the history
@2018.3
  • Loading branch information
ErikMoczi committed Mar 16, 2019
1 parent a681244 commit 0148f5f
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 279 deletions.
3 changes: 3 additions & 0 deletions package/CHANGELOG.md
Expand Up @@ -4,6 +4,9 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.14.3] - 2019-03-11
* Fixed a release issue affecting new installs

## [0.14.2] - 2019-03-05
* Fixed the freezing of the editor when quitting Unity with a Tiny project opened
* Must use Unity 2018.3.0f2 and above
Expand Down
50 changes: 10 additions & 40 deletions package/Editor/Export/TinyBuildPipeline.cs
Expand Up @@ -146,11 +146,6 @@ public sealed class TinyBuildOptions
/// Context for the build.
/// </summary>
internal TinyContext Context { get; set; }

/// <summary>
/// Editor Context for the build.
/// </summary>
internal EditorContextType EditorContext { get; set; }

/// <summary>
/// Project to build, part of the given <see cref="Context"/>.
Expand Down Expand Up @@ -393,7 +388,6 @@ public static TinyBuildOptions LoadProject(string projectPath)
return new TinyBuildOptions()
{
Context = context,
EditorContext = EditorContextType.Project,
Project = project
};
}
Expand All @@ -404,6 +398,11 @@ public static TinyBuildOptions LoadProject(string projectPath)
/// <returns>The build results.</returns>
public static TinyBuildResult BuildAndLaunch()
{
if (EditorApplication.isCompiling)
{
throw new Exception($"{TinyConstants.ApplicationName}: Exporting a project is not allowed while Unity is compiling.");
}

using (var progress = new TinyEditorUtility.ProgressBarScope())
{
var workspace = TinyEditorApplication.EditorContext.Workspace;
Expand Down Expand Up @@ -439,7 +438,6 @@ public static TinyBuildOptions WorkspaceBuildOptions
{
Context = context.Context,
Project = context.Project,
EditorContext = TinyEditorApplication.ContextType,
Configuration = context.Workspace.BuildConfiguration,
Platform = context.Workspace.Platform,
AutoConnectProfiler = context.Workspace.AutoConnectProfiler
Expand All @@ -455,24 +453,13 @@ public static TinyBuildOptions WorkspaceBuildOptions
/// <exception cref="ArgumentException">If the input <see cref="options"/> are invalid.</exception>
public static TinyBuildResult Build(TinyBuildOptions options)
{
try
if (options?.Project == null)
{
if (options.EditorContext != EditorContextType.Project)
{
EditorGUIUtilityBridge.DisplayDialog("Invalid Context", "Export only available in project context.", "Okay");
throw new InvalidOperationException($"{TinyConstants.ApplicationName}: Export only available in project context.");
}

if (EditorApplication.isCompiling)
{
throw new InvalidOperationException($"{TinyConstants.ApplicationName}: Exporting a project is not allowed while Unity is compiling.");
}

if (options == null || !ValidateProject(options.Project))
{
throw new ArgumentException($"{TinyConstants.ApplicationName}: invalid build options provided", nameof(options));
}
throw new ArgumentException($"{TinyConstants.ApplicationName}: invalid build options provided", nameof(options));
}

try
{
// Platform builder
ITinyBuilder builder = null;
switch (options.Platform)
Expand Down Expand Up @@ -541,7 +528,6 @@ public static TinyBuildResult Build(TinyBuildOptions options)
catch (Exception ex)
{
TinyEditorAnalytics.SendException("BuildPipeline.Build", ex);
EditorApplication.isPlaying = false;
throw;
}
finally
Expand All @@ -550,22 +536,6 @@ public static TinyBuildResult Build(TinyBuildOptions options)
}
}

private static bool ValidateProject(TinyProject project)
{
if (project == null)
{
return false;
}

var configuration = project.Configuration.Dereference(project.Registry);
if (configuration == null)
{
return false;
}

return true;
}

private static TinyBuildResult RunBuildSteps(TinyEditorUtility.ProgressBarScope progress, TinyBuildContext context)
{
var startTime = DateTime.Now;
Expand Down
163 changes: 69 additions & 94 deletions package/Editor/Export/TinyRuntimeInstaller.cs
Expand Up @@ -5,23 +5,16 @@
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.Assertions;

namespace Unity.Tiny
{
internal static class TinyRuntimeInstaller
{
private const string RuntimeVariantFull = "RuntimeFull";
private const string RuntimeVariantStripped = "RuntimeStripped";
private const string PublicDistFolder = "Tiny/Dist/artifacts/Stevedore/tiny-dist";
private const string PublicSamplesPackage = "Tiny/Dist/artifacts/Stevedore/tiny-samples/tiny-samples.unitypackage";
internal const string RuntimeVariantFull = "RuntimeFull";
internal const string RuntimeVariantStripped = "RuntimeStripped";

static TinyRuntimeInstaller()
{
LazyInstall();
}

private static void LazyInstall()
[InitializeOnLoadMethod]
internal static void InstallOnLoad()
{
if (!EditorApplication.isPlayingOrWillChangePlaymode)
{
Expand All @@ -42,15 +35,6 @@ private static void LazyInstall()
}
}

private static string PrependMono(string program)
{
#if UNITY_EDITOR_WIN
return program.Replace('/', '\\');
#else
return "mono " + program;
#endif
}

/// <summary>
/// Utility class to use whenever tools binaries need to be overwritten.
/// Upon new scope, running tools instances will be killed.
Expand Down Expand Up @@ -232,7 +216,12 @@ private static void BuildRuntime(BuildRuntimeFlags buildFlags)
};
using (var progress = new TinyEditorUtility.ProgressBarScope("Building Runtime...", "..."))
{
var beeProgram = PrependMono("bee.exe");
#if UNITY_EDITOR_WIN
var beeProgram = "bee.exe";
#else
var beeProgram = "mono bee.exe";
#endif

for (var i = 0; i < beeTargets.Count; ++i)
{
var target = beeTargets[i];
Expand All @@ -253,7 +242,7 @@ private static void BuildRuntime(BuildRuntimeFlags buildFlags)
}

var buildFolder = runtimeFolder + "build/";
var distFolder = GetRuntimeDistDirectory() + "/";
var distFolder = "./Tiny/Dist/";

if (isClean)
{
Expand Down Expand Up @@ -312,11 +301,8 @@ private static void BuildRuntime(BuildRuntimeFlags buildFlags)

var runtimeRev = distFolder + "runtime-rev.txt";
var projectRoot = new DirectoryInfo(".");
#if UNITY_EDITOR_WIN

TinyShell.RunInShell($"git show --format=\"%%H\" --no-patch > {runtimeRev}", new ShellProcessArgs()
#else
TinyShell.RunInShell($"git show --format=\"%H\" --no-patch > {runtimeRev}", new ShellProcessArgs()
#endif
{
WorkingDirectory = projectRoot,
ThrowOnError = true
Expand Down Expand Up @@ -363,10 +349,14 @@ private static void BuildTools(bool clean)
{
TinyPreferences.MonoDirectory
};
using (new TinyEditorUtility.ProgressBarScope("Building Tools...", "Packaging node tools into native executables, please wait!"))
using (var progress = new TinyEditorUtility.ProgressBarScope("Building Tools...", "Packaging node tools into native executables, please wait!"))
{
var program = PrependMono("Packages/com.unity.tiny/Dist~/bee.exe");
var output = TinyShell.RunInShell(program, new ShellProcessArgs()
#if UNITY_EDITOR_WIN
var program = "bee.exe";
#else
var program = "mono bee.exe";
#endif
var output = TinyShell.RunInShell($"{program}", new ShellProcessArgs()
{
WorkingDirectory = rootDir,
ExtraPaths = extraPaths,
Expand All @@ -383,61 +373,43 @@ private static void BuildTools(bool clean)

#endif // UNITY_TINY_INTERNAL

private static void UpdateToolchain(bool force)
{
var depDir = new DirectoryInfo("Tiny/Dist");
var dstBeeScript = new FileInfo("Tiny/Dist/Bees/BuildProgram.bee.cs");

// we can't run bee from the Packages folder, as it may be read-only
var srcBeeScript = new FileInfo(Path.GetFullPath("Packages/com.unity.tiny/Dist~/Bees/BuildProgram.bee.cs"));
Assert.IsTrue(srcBeeScript.Exists, "Could not find Tiny toolchain update script");

if (false == dstBeeScript.Exists)
{
// main bee script not found (package install)? synchronize the whole tree
TinyBuildUtilities.CopyDirectory(
from: new DirectoryInfo(Path.GetFullPath("Packages/com.unity.tiny/Dist~")),
to: depDir,
purge: true);
}
else if (force || dstBeeScript.LastWriteTimeUtc < srcBeeScript.LastWriteTimeUtc)
{
// new bee script (package update)? synchronize only the Bees folder
TinyBuildUtilities.CopyDirectory(
from: new DirectoryInfo(Path.GetFullPath("Packages/com.unity.tiny/Dist~/Bees")),
to: new DirectoryInfo(Path.Combine(depDir.FullName, "Bees")),
purge: true);
}
else
{
// let bee handle the rest: incremental builds are cheap
}

var extraPaths = new string[]
{
TinyPreferences.MonoDirectory
};
var program = PrependMono("bee.exe");
var output = TinyShell.RunInShell(program, new ShellProcessArgs()
{
WorkingDirectory = depDir,
ExtraPaths = extraPaths,
ThrowOnError = false,
MaxIdleTimeInMilliseconds = 10 * 1000 // 10min
});
if (!output.Succeeded || !Directory.Exists(PublicDistFolder))
{
throw new Exception($"Failed to update dependencies:\n{output.FullOutput}");
}
}

private static void Install(bool force, bool silent)
{
using (new OverwriteToolsScope())
using (new TinyEditorUtility.ProgressBarScope("Tiny Mode", "Updating toolchain..."))
using (var progress = new TinyEditorUtility.ProgressBarScope())
{
UpdateToolchain(force);

var installLocation = new DirectoryInfo("Tiny");
var versionFile = new FileInfo(Path.Combine(installLocation.FullName, "lastUpdate.txt"));
var sourcePackage = new FileInfo(TinyConstants.PackagePath + "/tiny-runtime-dist.zip");
var shouldUpdate = sourcePackage.Exists && (!versionFile.Exists || versionFile.LastWriteTimeUtc < sourcePackage.LastWriteTimeUtc);

if (!force && !shouldUpdate)
{
if (!silent)
{
UnityEngine.Debug.Log("Tiny: Runtime is already up to date");
}
return;
}

if (!sourcePackage.Exists)
{
if (!silent)
{
UnityEngine.Debug.LogError($"Tiny: could not find {sourcePackage.FullName}");
}
return;
}

if (installLocation.Exists)
{
progress.Update($"{TinyConstants.ApplicationName} Runtime", "Removing old runtime...");
TinyBuildUtilities.PurgeDirectory(installLocation);
}
progress.Update("Installing new runtime...", 0.5f);
TinyBuildUtilities.UnzipFile(sourcePackage.FullName, installLocation.Parent);
File.WriteAllText(versionFile.FullName, $"{sourcePackage.FullName} install time: {DateTime.UtcNow.ToString()}");

#if UNITY_EDITOR_OSX
// TODO: figure out why UnzipFile does not preserve executable bits in some cases
// chmod +x any native executables here
Expand All @@ -457,10 +429,7 @@ private static void Install(bool force, bool silent)
});
#endif

if (!silent)
{
UnityEngine.Debug.Log($"Installed {TinyConstants.ApplicationName} toolchain successfully");
}
UnityEngine.Debug.Log($"Installed {TinyConstants.ApplicationName} runtime at: {installLocation.FullName}");
}
}

Expand All @@ -486,7 +455,8 @@ private static void OpenUserForums()

internal static void InstallSamples(bool interactive)
{
AssetDatabase.ImportPackage(PublicSamplesPackage, interactive);
var packagePath = Path.GetFullPath(TinyConstants.PackagePath + "/tiny-samples.unitypackage");
AssetDatabase.ImportPackage(packagePath, interactive);
CreateSampleLayers();
}

Expand All @@ -511,11 +481,7 @@ private static void CreateSampleLayers()

internal static string GetRuntimeDistDirectory()
{
#if UNITY_TINY_INTERNAL
return Path.Combine("Tiny", "Runtime");
#else
return Path.Combine(PublicDistFolder, "Tiny", "Runtime");
#endif
return Path.Combine("Tiny", "Dist");
}

internal static readonly DirectoryInfo RuntimeDataDefinitionDirectory =
Expand Down Expand Up @@ -558,11 +524,7 @@ internal static string GetToolDirectory(string toolName)
{
throw new ArgumentException("tool");
}
#if UNITY_TINY_INTERNAL
return Path.Combine("Tiny", "Tools", toolName);
#else
return Path.Combine(PublicDistFolder, "Tiny", "Tools", toolName);
#endif
}

private static bool IncludesModule(TinyProject project, string moduleName)
Expand All @@ -577,4 +539,17 @@ internal static string GetJsRuntimeVariant(TinyBuildOptions options)
return options.Configuration == TinyBuildConfiguration.Release || IncludesModule(options.Project, k_BuiltInPhysicsModule) ? RuntimeVariantFull : RuntimeVariantStripped;
}
}

#if !UNITY_TINY_INTERNAL
internal class TinyAssetPostProcessor : AssetPostprocessor
{
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
if (!UnityEditorInternal.InternalEditorUtility.inBatchMode)
{
TinyRuntimeInstaller.InstallOnLoad();
}
}
}
#endif
}
5 changes: 3 additions & 2 deletions package/Editor/TinyAssetsMenuItems/FileMenuItems.cs
Expand Up @@ -55,7 +55,7 @@ private static bool ValidateContextIsOpened()
[MenuItem(k_FileMenuPrefix + k_NewProject, priority = k_BasePriority)]
public static void CreateNewProject()
{
CreateNew(() => TinyEditorApplication.NewProject());
CreateNew(TinyEditorApplication.NewProject);
}

[MenuItem(k_TinyMenuPrefix + k_OpenProject, priority = k_BasePriority + 1)]
Expand All @@ -69,7 +69,7 @@ public static void OpenProject()
[MenuItem(k_FileMenuPrefix + k_NewModule, priority = k_BasePriority + 50)]
public static void CreateNewModule()
{
CreateNew(() => TinyEditorApplication.NewModule());
CreateNew(TinyEditorApplication.NewModule);
}

[MenuItem(k_TinyMenuPrefix + k_OpenModule, priority = k_BasePriority + 51)]
Expand Down Expand Up @@ -126,6 +126,7 @@ private static void CreateNew<TPersistentObject>(Func<TPersistentObject> creator
{
return;
}

SelectTinyObject(creator.Invoke());
}

Expand Down

0 comments on commit 0148f5f

Please sign in to comment.