Esempio n. 1
0
        public BuildContext DoWorkImpl(ExportCommand command)
        {
            string buildFile = command.BuildFilePath;
            string target    = command.BuildTarget;

            if (buildFile == null || target == null)
            {
                throw new InvalidOperationException("Build file and target must be specified together.");
            }

            buildFile = BuildContext.GetValidatedCanonicalBuildFilePath(buildFile);

            string projectDirectory = FileUtil.GetParentDirectory(buildFile);

            BuildContext buildContext = null;

            buildContext = BuildContext.Parse(projectDirectory, FileUtil.ReadFileText(buildFile), target, command.ResourceErrorsShowRelativeDir);

            buildContext = buildContext ?? new BuildContext();

            // command line arguments override build file values if present.

            if (buildContext.Platform == null)
            {
                throw new InvalidOperationException("No platform specified in build file.");
            }

            if (buildContext.TopLevelAssembly.SourceFolders.Length == 0)
            {
                throw new InvalidOperationException("No source folder specified in build file.");
            }

            if (buildContext.OutputFolder == null)
            {
                throw new InvalidOperationException("No output folder specified in build file.");
            }

            buildContext.OutputFolder = FileUtil.JoinAndCanonicalizePath(projectDirectory, buildContext.OutputFolder);

            if (buildContext.LaunchScreenPath != null)
            {
                buildContext.LaunchScreenPath = FileUtil.JoinAndCanonicalizePath(projectDirectory, buildContext.LaunchScreenPath);
            }

            foreach (FilePath sourceFolder in buildContext.TopLevelAssembly.SourceFolders)
            {
                if (!FileUtil.DirectoryExists(sourceFolder.AbsolutePath))
                {
                    throw new InvalidOperationException("Source folder does not exist.");
                }
            }

            buildContext.ProjectID = buildContext.ProjectID ?? "Untitled";

            return(buildContext);
        }
Esempio n. 2
0
 private static BuildContext GetBuildContextCbx(string rawBuildFilePath)
 {
     using (new PerformanceSection("GetBuildContextCbx"))
     {
         string buildFile        = Program.GetValidatedCanonicalBuildFilePath(rawBuildFilePath);
         string projectDirectory = System.IO.Path.GetDirectoryName(buildFile);
         string buildFileContent = System.IO.File.ReadAllText(buildFile);
         return(BuildContext.Parse(projectDirectory, buildFileContent, null));
     }
 }
Esempio n. 3
0
        public BuildContext DoWorkImpl(ExportCommand command)
        {
            string buildFilePath = command.BuildFilePath;

            if (buildFilePath == null)
            {
                throw new InvalidOperationException("No build path was provided.");
            }

            string       buildFile        = BuildContext.GetValidatedCanonicalBuildFilePath(buildFilePath);
            string       projectDirectory = FileUtil.GetParentDirectory(buildFile);
            string       buildFileContent = FileUtil.ReadFileText(buildFile);
            BuildContext buildContext     = BuildContext.Parse(projectDirectory, buildFileContent, null, command.ResourceErrorsShowRelativeDir);

            return(buildContext);
        }
        public override CrayonWorkerResult DoWorkImpl(CrayonWorkerResult[] args)
        {
            ExportCommand command       = (ExportCommand)args[0].Value;
            string        buildFilePath = command.BuildFilePath;

            if (buildFilePath == null)
            {
                throw new InvalidOperationException("No build path was provided.");
            }

            string       buildFile        = BuildContext.GetValidatedCanonicalBuildFilePath(buildFilePath);
            string       projectDirectory = FileUtil.GetParentDirectory(buildFile);
            string       buildFileContent = FileUtil.ReadFileText(buildFile);
            BuildContext buildContext     = BuildContext.Parse(projectDirectory, buildFileContent, null);

            return(new CrayonWorkerResult()
            {
                Value = buildContext
            });
        }
Esempio n. 5
0
        private static BuildContext GetBuildContext(string[] args)
        {
#if DEBUG
            if (args.Length == 0)
            {
                string crayonHome = System.Environment.GetEnvironmentVariable("CRAYON_HOME");
                if (crayonHome != null)
                {
                    string debugArgsFile = System.IO.Path.Combine(crayonHome, "DEBUG_ARGS.txt");
                    if (System.IO.File.Exists(debugArgsFile))
                    {
                        string[] debugArgs  = System.IO.File.ReadAllText(debugArgsFile).Trim().Split('\n');
                        string   lastArgSet = debugArgs[debugArgs.Length - 1].Trim();
                        if (lastArgSet.Length > 0)
                        {
                            args = lastArgSet.Split(' ');
                        }
                    }
                }
            }
#endif

            Dictionary <string, string> argLookup = Program.ParseArgs(args);

            string buildFile        = argLookup.ContainsKey("buildfile") ? argLookup["buildfile"] : null;
            string target           = argLookup.ContainsKey("target") ? argLookup["target"] : null;
            string workingDirectory = ".";

            BuildContext buildContext = null;
            if (buildFile != null || target != null)
            {
                if (buildFile == null || target == null)
                {
                    throw new InvalidOperationException("Build file and target must be specified together.");
                }

                argLookup.Remove("buildfile");
                argLookup.Remove("target");
                workingDirectory = System.IO.Path.GetDirectoryName(buildFile);

                if (!System.IO.File.Exists(buildFile))
                {
                    throw new InvalidOperationException("Build file does not exist: " + buildFile);
                }

                buildContext = BuildContext.Parse(System.IO.File.ReadAllText(buildFile), target);
            }

            buildContext = buildContext ?? new BuildContext();

            // command line arguments override build file values if present.

            if (argLookup.ContainsKey("min"))
            {
                buildContext.Minified = true;
                argLookup.Remove("min");
            }

            if (argLookup.ContainsKey("readablebytecode"))
            {
                buildContext.ReadableByteCode = true;
                argLookup.Remove("readablebytecode");
            }

            if (argLookup.ContainsKey("source"))
            {
                buildContext.SourceFolder = argLookup["source"];
                argLookup.Remove("source");
            }

            if (argLookup.ContainsKey("output"))
            {
                buildContext.OutputFolder = argLookup["output"];
                argLookup.Remove("output");
            }

            if (argLookup.ContainsKey("jsfileprefix"))
            {
                buildContext.JsFilePrefix = argLookup["jsfileprefix"];
                argLookup.Remove("jsfileprefix");
            }

            if (argLookup.ContainsKey("platform"))
            {
                buildContext.Platform = argLookup["platform"];
                argLookup.Remove("platform");
            }

            if (argLookup.ContainsKey("name"))
            {
                buildContext.ProjectID = argLookup["name"];
                argLookup.Remove("name");
            }

            if (argLookup.Count > 0)
            {
                throw new InvalidOperationException("Unrecognized command line flags: " +
                                                    string.Join(", ", argLookup.Keys.OrderBy <string, string>(s => s.ToLowerInvariant())) +
                                                    ". See usage.");
            }

            if (buildContext.Platform == null)
            {
                throw new InvalidOperationException("No platform specified. See usage.");
            }

            if (buildContext.SourceFolder == null)
            {
                throw new InvalidOperationException("No source folder specified. See usage.");
            }

            if (buildContext.OutputFolder == null)
            {
                throw new InvalidOperationException("No output folder specified. See usage.");
            }

            buildContext.SourceFolder = System.IO.Path.Combine(workingDirectory, buildContext.SourceFolder).Replace('/', '\\');
            buildContext.OutputFolder = System.IO.Path.Combine(workingDirectory, buildContext.OutputFolder).Replace('/', '\\');
            if (buildContext.IconFilePath != null)
            {
                buildContext.IconFilePath = System.IO.Path.Combine(workingDirectory, buildContext.IconFilePath).Replace('/', '\\');
            }

            if (!FileUtil.DirectoryExists(buildContext.SourceFolder))
            {
                throw new InvalidOperationException("Source folder does not exist.");
            }

            buildContext.ProjectID = buildContext.ProjectID ?? "Untitled";

            return(buildContext);
        }
Esempio n. 6
0
        private static BuildContext GetBuildContext(Dictionary <string, string> argLookup)
        {
            using (new PerformanceSection("GetBuildContext"))
            {
                string buildFile = argLookup.ContainsKey("buildfile") ? argLookup["buildfile"] : null;
                string target    = argLookup.ContainsKey("target") ? argLookup["target"] : null;

                if (buildFile == null || target == null)
                {
                    throw new InvalidOperationException("Build file and target must be specified together.");
                }

                buildFile = GetValidatedCanonicalBuildFilePath(buildFile);

                string projectDirectory = System.IO.Path.GetDirectoryName(buildFile);

                BuildContext buildContext = null;

                argLookup.Remove("buildfile");
                argLookup.Remove("target");
                projectDirectory = System.IO.Path.GetDirectoryName(buildFile);

                buildContext = BuildContext.Parse(projectDirectory, System.IO.File.ReadAllText(buildFile), target);

                buildContext = buildContext ?? new BuildContext();

                // command line arguments override build file values if present.

                if (buildContext.Platform == null)
                {
                    throw new InvalidOperationException("No platform specified in build file.");
                }

                if (buildContext.SourceFolders.Length == 0)
                {
                    throw new InvalidOperationException("No source folder specified in build file.");
                }

                if (buildContext.OutputFolder == null)
                {
                    throw new InvalidOperationException("No output folder specified in build file.");
                }

                buildContext.OutputFolder = FileUtil.JoinAndCanonicalizePath(projectDirectory, buildContext.OutputFolder);
                if (buildContext.IconFilePath != null)
                {
                    buildContext.IconFilePath = FileUtil.JoinAndCanonicalizePath(projectDirectory, buildContext.IconFilePath);
                }

                foreach (FilePath sourceFolder in buildContext.SourceFolders)
                {
                    if (!FileUtil.DirectoryExists(sourceFolder.AbsolutePath))
                    {
                        throw new InvalidOperationException("Source folder does not exist.");
                    }
                }

                buildContext.ProjectID = buildContext.ProjectID ?? "Untitled";

                return(buildContext);
            }
        }