Skip to content

Commit

Permalink
Restore editor defines, buildconstants after build.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaser324 committed Apr 13, 2017
1 parent 9fa9b35 commit 428eefa
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
18 changes: 18 additions & 0 deletions Editor/Build/BuildProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ private static void PerformBuild(string[] buildConfigs, BuildOptions options = B
int successCount = 0;
int failCount = 0;

// Save current script defines, build constants, etc. so we can restore them after build.
string currentDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone);
string buildConstantsPath = BuildConstantsGenerator.FindFile();
string currentBuildConstantsFile = null;
if (!string.IsNullOrEmpty(buildConstantsPath))
{
currentBuildConstantsFile = FileUtil.GetUniqueTempPathInProject();
File.Copy(buildConstantsPath, currentBuildConstantsFile);
}

DateTime buildTime;
PerformPreBuild(out buildTime);

Expand All @@ -213,6 +223,14 @@ private static void PerformBuild(string[] buildConfigs, BuildOptions options = B

PerformPostBuild();

// Restore editor status.
PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, currentDefines);
if (!string.IsNullOrEmpty(buildConstantsPath))
{
File.Copy(currentBuildConstantsFile, buildConstantsPath, true);
File.Delete(currentBuildConstantsFile);
}

// Report success/failure.
StringBuilder sb = new StringBuilder();
if (failCount == 0)
Expand Down
23 changes: 15 additions & 8 deletions Editor/BuildConstantsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@ public static class BuildConstantsGenerator
{
public const string NONE = "None";

public static void Generate(
DateTime buildTime,
string currentVersion = "",
BuildReleaseType currentReleaseType = null,
BuildPlatform currentBuildPlatform = null,
BuildArchitecture currentBuildArchitecture = null,
BuildDistribution currentBuildDistribution = null)
public static string FindFile()
{
// Find the BuildConstants file.
string[] fileSearchResults = Directory.GetFiles(Application.dataPath, "BuildConstants.cs", SearchOption.AllDirectories);
string filePath = null;
string desiredFilePath = string.Format("UnityBuild{0}BuildConstants.cs", Path.DirectorySeparatorChar);
Expand All @@ -33,6 +26,20 @@ public static void Generate(
}
}

return filePath;
}

public static void Generate(
DateTime buildTime,
string currentVersion = "",
BuildReleaseType currentReleaseType = null,
BuildPlatform currentBuildPlatform = null,
BuildArchitecture currentBuildArchitecture = null,
BuildDistribution currentBuildDistribution = null)
{
// Find the BuildConstants file.
string filePath = FindFile();

if (string.IsNullOrEmpty(filePath))
{
return;
Expand Down

0 comments on commit 428eefa

Please sign in to comment.