public bool GetHeaderAsBoolean(string name) { string value = this.GetHeader(name); return(BoolUtil.Parse(value)); }
public static BuildContext Parse(string projectDir, string buildFile, string nullableTargetName, bool useRelativePathsInErrors) { BuildRoot buildInput = GetBuildRoot(buildFile); string platform = null; Dictionary <string, BuildVarCanonicalized> varLookup; string targetName = nullableTargetName; Target desiredTarget = null; if (nullableTargetName != null) { desiredTarget = FindTarget(targetName, buildInput.Targets); if (desiredTarget == null) { throw new InvalidOperationException("Build target does not exist in build file: '" + targetName + "'."); } platform = desiredTarget.Platform; } else { targetName = "cbx"; desiredTarget = FindTarget(targetName, buildInput.Targets) ?? new Target(); } Dictionary <string, string> replacements = new Dictionary <string, string>() { { "TARGET_NAME", targetName } }; varLookup = BuildVarParser.GenerateBuildVars(buildInput, desiredTarget, replacements); if (desiredTarget.HasLegacyIcon || buildInput.HasLegacyIcon) { // TODO: remove this in 2.2.0 or something throw new InvalidOperationException( "This build file has a string property for an icon path. " + "This has been changed to a JSON array of strings for icon paths with a key called \"icons\" instead of \"icon\". " + "Please update your build file accordingly."); } if (desiredTarget.HasLegacyTitle || buildInput.HasLegacyTitle) { throw new InvalidOperationException("This build file has a \"default-title\" property, which was changed to just \"title\" in 2.1.0. Please update your build file accordingly."); } SourceItem[] sources = desiredTarget.SourcesNonNull.Union(buildInput.SourcesNonNull).ToArray(); string output = desiredTarget.Output ?? buildInput.Output; string projectId = desiredTarget.ProjectId ?? buildInput.ProjectId; string version = desiredTarget.Version ?? buildInput.Version ?? "1.0"; string jsFilePrefix = desiredTarget.JsFilePrefix ?? buildInput.JsFilePrefix; bool jsFullPage = NullableBoolean.ToBoolean(desiredTarget.JsFullPageRaw ?? buildInput.JsFullPageRaw, false); ImageSheet[] imageSheets = MergeImageSheets(desiredTarget.ImageSheets, buildInput.ImageSheets); // TODO: maybe set this default value to true, although this does nothing as of now. bool minified = NullableBoolean.ToBoolean(desiredTarget.MinifiedRaw ?? buildInput.MinifiedRaw, false); bool exportDebugByteCode = BoolUtil.Parse(desiredTarget.ExportDebugByteCodeRaw ?? buildInput.ExportDebugByteCodeRaw); string guidSeed = desiredTarget.GuidSeed ?? buildInput.GuidSeed ?? ""; // TODO: make this a string array. string[] iconFilePaths = CombineAndFlattenStringArrays(desiredTarget.IconFilePaths, buildInput.IconFilePaths); string launchScreen = desiredTarget.LaunchScreen ?? buildInput.LaunchScreen; string projectTitle = desiredTarget.ProjectTitle ?? buildInput.ProjectTitle; string orientation = desiredTarget.Orientation ?? buildInput.Orientation; string iosBundlePrefix = desiredTarget.IosBundlePrefix ?? buildInput.IosBundlePrefix; string javaPackage = desiredTarget.JavaPackage ?? buildInput.JavaPackage; string[] localDeps = CombineAndFlattenStringArrays(desiredTarget.LocalDeps, buildInput.LocalDeps); string[] remoteDeps = CombineAndFlattenStringArrays(desiredTarget.RemoteDeps, buildInput.RemoteDeps); string description = desiredTarget.Description ?? buildInput.Description ?? ""; Size windowSize = Size.Merge(desiredTarget.WindowSize, buildInput.WindowSize) ?? new Size(); string compilerLocale = desiredTarget.CompilerLocale ?? buildInput.CompilerLocale ?? "en"; bool isCSharpCompatMode = desiredTarget.IsCSharpCompatMode || buildInput.IsCSharpCompatMode; // TODO(acrylic-convert): should have unset state with ?? string programmingLanguage = buildInput.ProgrammingLanguage ?? "Crayon"; string delegateMainTo = desiredTarget.DelegateMainTo ?? buildInput.DelegateMainTo; if (output == null) { throw new InvalidOperationException("No output directory defined."); } PercentReplacer pr = new PercentReplacer() .AddReplacement("COMPILER_VERSION", VersionInfo.VersionString) .AddReplacement("COMPILER_LANGUAGE", programmingLanguage) .AddReplacement("TARGET_NAME", targetName); version = pr.Replace(version); pr.AddReplacement("VERSION", version); compilerLocale = pr.Replace(compilerLocale); pr.AddReplacement("COMPILER_LOCALE", compilerLocale); output = FileUtil.GetCanonicalizeUniversalPath(pr.Replace(output)); projectId = pr.Replace(projectId); jsFilePrefix = pr.Replace(jsFilePrefix); guidSeed = pr.Replace(guidSeed); iconFilePaths = iconFilePaths .Select(t => pr.Replace(t)) .Select(t => FileUtil.GetAbsolutePathFromRelativeOrAbsolutePath(projectDir, t)) .Select(t => FileUtil.GetCanonicalizeUniversalPath(t)) .ToArray(); launchScreen = pr.Replace(launchScreen); projectTitle = pr.Replace(projectTitle); orientation = pr.Replace(orientation); iosBundlePrefix = pr.Replace(iosBundlePrefix); javaPackage = pr.Replace(javaPackage); programmingLanguage = pr.Replace(programmingLanguage); localDeps = localDeps .Select(t => CommonUtil.Environment.EnvironmentVariables.DoReplacementsInString(t)) .Select(t => pr.Replace(t)) .Select(t => FileUtil.GetCanonicalizeUniversalPath(t)) .ToArray(); remoteDeps = remoteDeps .Select(t => pr.Replace(t)) .ToArray(); description = pr.Replace(description); BuildContext buildContext = new BuildContext() { ProjectDirectory = projectDir, JsFilePrefix = jsFilePrefix, OutputFolder = output, Platform = platform, ProjectID = projectId, Minified = minified, ReadableByteCode = exportDebugByteCode, GuidSeed = guidSeed, IconFilePaths = iconFilePaths, LaunchScreenPath = launchScreen, ProjectTitle = projectTitle, Orientation = orientation, LocalDeps = localDeps, RemoteDeps = remoteDeps, IosBundlePrefix = iosBundlePrefix, JavaPackage = javaPackage, JsFullPage = jsFullPage, WindowWidth = windowSize.Width, WindowHeight = windowSize.Height, CompilerLocale = Locale.Get(compilerLocale), IsCSharpCompatibilityMode = isCSharpCompatMode, DelegateMainTo = delegateMainTo, }; ProgrammingLanguage?nullableLanguage = ProgrammingLanguageParser.Parse(programmingLanguage); if (nullableLanguage == null) { throw new InvalidOperationException("Invalid programming language specified: '" + programmingLanguage + "'"); } buildContext.TopLevelAssembly = new AssemblyContext(buildContext) { Description = description, Version = version, SourceFolders = ToFilePaths(projectDir, sources), ImageSheetPrefixesById = imageSheets.ToDictionary <ImageSheet, string, string[]>(s => s.Id, s => s.Prefixes), ImageSheetIds = imageSheets.Select <ImageSheet, string>(s => s.Id).ToArray(), BuildVariableLookup = varLookup, ProgrammingLanguage = nullableLanguage.Value, }; return(buildContext.ValidateValues(useRelativePathsInErrors)); }