예제 #1
0
    // Assumption: filename already exists and is already verified to be a file
    public static void LoadFile(MetabuildProject metabuild, String filename)
    {
        Console.WriteLine("[DEBUG] Metabuild.LoadFile \"{0}\"", filename);
        String relativeDir = null;

        using (LfdTextReader reader = new LfdTextReader(new StreamReader(new FileStream(
                                                                             filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))))
        {
            LfdParser parser = new LfdParser(reader, filename);
            LfdLine   line   = parser.reader.ReadLineIgnoreComments();
            for (; ;)
            {
                if (line == null)
                {
                    return;
                }

                if (line.id == "Import")
                {
                    parser.errors.EnforceFieldCount(line, 1);
                    MetabuildUnit.LoadDirOrFile(metabuild, line.fields[0]);
                    line = parser.reader.ReadLineIgnoreComments();
                }
                else if (line.id == "CSharpProject")
                {
                    if (relativeDir == null)
                    {
                        relativeDir = Path.GetDirectoryName(filename);
                    }
                    line = CSharpProject.Parse(metabuild, parser, line, false, relativeDir);
                }
                else if (line.id == "CSharpTestProject")
                {
                    if (relativeDir == null)
                    {
                        relativeDir = Path.GetDirectoryName(filename);
                    }
                    line = CSharpProject.Parse(metabuild, parser, line, true, relativeDir);
                }
                else if (line.id == "GeneratePathPrefix")
                {
                    parser.errors.EnforceFieldCount(line, 1);
                    if (metabuild.generatePathPrefix != null)
                    {
                        throw parser.errors.Error(line, "GeneratePathPrefix was set more than once");
                    }
                    metabuild.generatePathPrefix = line.fields[0];
                    line = parser.reader.ReadLineIgnoreComments();
                }
                else
                {
                    throw parser.errors.Error(line, "unknown directive '{0}'", line.id);
                }
            }
        }
    }
예제 #2
0
    public static LfdLine Parse(MetabuildProject metabuild, LfdParser parser, LfdLine projectLine, Boolean isTestProject, String relativePath)
    {
        parser.errors.EnforceFieldCount(projectLine, 1);
        CSharpProject project       = new CSharpProject(relativePath, projectLine.fields[0], isTestProject);
        bool          setOutputType = false;

        LfdLine line;

        for (; ;)
        {
            line = parser.reader.ReadLineIgnoreComments();
            if (line == null)
            {
                break;
            }
            if (line.id == "ProjectGuid")
            {
                parser.errors.EnforceFieldCount(line, 1);
                if (project.projectGuid != default(Guid))
                {
                    throw parser.errors.Error(line, "ProjectGuid was set more than once");
                }
                project.projectGuid = new Guid(line.fields[0]);
            }
            else if (line.id == "OutputType")
            {
                parser.errors.EnforceFieldCount(line, 1);
                if (setOutputType)
                {
                    throw parser.errors.Error(line, "OutputType was set more than once");
                }
                setOutputType      = true;
                project.outputType = (OutputType)Enum.Parse(typeof(OutputType), line.fields[0], false);
            }
            else if (line.id == "AssemblyName")
            {
                parser.errors.EnforceFieldCount(line, 1);
                if (project.assemblyName != null)
                {
                    throw parser.errors.Error(line, "AssemblyName was set more than once");
                }
                project.assemblyName = line.fields[0];
            }
            else if (line.id == "AllowUnsafeBlocks")
            {
                parser.errors.EnforceFieldCount(line, 0);
                if (project.allowUnsafeBlocks)
                {
                    throw parser.errors.Error(line, "AllowUnsafeBlocks was set more than once");
                }
                project.allowUnsafeBlocks = true;
            }
            else if (line.id == "Reference")
            {
                parser.errors.EnforceFieldCount(line, 1);
                project.referenceList.Add(line.fields[0]);
            }
            else if (line.id == "ProjectReference")
            {
                metabuild.AddUnresolvedReference(new UnresolvedCSharpProjectReference(project, parser.errors, line));
            }
            else if (line.id == "Source")
            {
                parser.errors.EnforceFieldCount(line, 1);
                project.sourceList.Add(line.fields[0]);
            }
            else
            {
                break;
            }
        }

        //
        // Verify the project is valid
        //
        if (!setOutputType)
        {
            throw parser.errors.ErrorNoLine("Missing the 'OutputType' property");
        }
        if (project.assemblyName == null)
        {
            project.assemblyName = project.name;
        }
        if (project.projectGuid == default(Guid))
        {
            project.projectGuid = Guid.NewGuid();
        }
        metabuild.units.Add(project);
        return(line);
    }