/// <summary> /// Sets up a 'project reference' to the project passed in. /// (See heading comment notes, and comments in setupReferences() above.) /// </summary> private void setupProjectReference(ReferenceInfo referenceInfo, ProjectInfo_CSharp referencedProject) { // For each configuration in this project, we find the equivalent // configuration in the referenced-project, and set up references // to its output folder... foreach (ProjectConfigurationInfo_CSharp configurationInfo in m_configurationInfos) { // We find the equivalent configuration from the referenced project... ProjectConfigurationInfo_CSharp referencedConfiguration = findEquivalentConfiguration(configurationInfo.Name, referencedProject); if (referencedConfiguration == null) { // The project has no equivalent configuration. (It probably // doesn't have any configurations at all.) continue; } // We find the absolute and relative path to the output of this // configuration... string absolutePath = referencedProject.RootFolderAbsolute + "/" + referencedConfiguration.OutputFolder + "/" + referencedProject.OutputFileName; absolutePath = Path.GetFullPath(absolutePath); string relativePath = Utils.makeRelativePath(m_rootFolderAbsolute, absolutePath); // We store the reference-info for each configuration... ReferenceInfo info = new ReferenceInfo(); info.CopyLocal = referenceInfo.CopyLocal; info.AbsolutePath = absolutePath; info.RelativePath = relativePath; info.ReferenceType = ReferenceInfo.ReferenceTypeEnum.PROJECT_REFERENCE; info.ConfigurationInfo = referencedConfiguration; configurationInfo.addReference(info); } }
/// <summary> /// Sets up references for C# projects. /// </summary> public void setupReferences() { foreach (ProjectInfo project in m_projectInfos.Values) { // We only need to set up implicit linking for C# projects... ProjectInfo_CSharp csProject = project as ProjectInfo_CSharp; if (csProject != null) { csProject.setupReferences(); } } }
/// <summary> /// We set up the reference in all configurations of this project. /// (See notes in setupReferences above.) /// </summary> private void setupReference(ReferenceInfo referenceInfo) { // We check if the reference is pointing to another project in // the solution... ProjectInfo_CSharp referencedProject = findProjectReference(referenceInfo); if (referencedProject != null) { // The reference is to another project in the solution... setupProjectReference(referenceInfo, referencedProject); } else { // The reference is not to a project is the solution, // ie it is an 'external reference'... setupExternalReference(referenceInfo); } }
/// <summary> /// Constructor /// </summary> private MakefileBuilder_Project_CSharp(ProjectInfo_CSharp project) { m_projectInfo = project; try { // We create the file '[project-name].makefile', and set it to // use unix-style line endings... string path = String.Format("{0}/{1}.makefile", m_projectInfo.RootFolderAbsolute, m_projectInfo.Name); m_file = new StreamWriter(path, false); m_file.NewLine = "\n"; // We create variables... createCompilerVariable(); createFilesVariable(); createReferencesVariables(); createFlagsVariables(); createOutputVariables(); createTargetVariable(); // We create an 'all configurations' root target... m_file.WriteLine(""); createAllConfigurationsTarget(); // We create one target for each configuration... createConfigurationTargets(); // We create a target to create the intermediate and output folders... createCreateFoldersTarget(); // Creates the target that cleans intermediate files... createCleanTarget(); } finally { if (m_file != null) { m_file.Close(); m_file.Dispose(); } } }
/// <summary> /// Checks if the reference-info passed in comes from another project /// in the solution. /// Returns the referenced project if there is one, or null if the /// reference is not to another project in the solution. /// </summary> private ProjectInfo_CSharp findProjectReference(ReferenceInfo referenceInfo) { ProjectInfo_CSharp result = null; // We look through each project... foreach (ProjectInfo projectInfo in ParentSolution.getProjectInfos()) { // We are only interested in C# projects... ProjectInfo_CSharp csProjectInfo = projectInfo as ProjectInfo_CSharp; if (csProjectInfo == null) { continue; } // We check each configuration for the project... foreach (ProjectConfigurationInfo_CSharp configurationInfo in csProjectInfo.getConfigurationInfos()) { // We find the absolute path to the output for this configuration... string fullOutputPath = csProjectInfo.RootFolderAbsolute + "/" + configurationInfo.OutputFolder + "/" + csProjectInfo.OutputFileName; string fullIntermediatePath = csProjectInfo.RootFolderAbsolute + "/" + configurationInfo.IntermediateFolder + "/" + csProjectInfo.OutputFileName; // And we check if the reference passed points to the same assembly... if (Utils.isSamePath(fullOutputPath, referenceInfo.AbsolutePath) == true || Utils.isSamePath(fullIntermediatePath, referenceInfo.AbsolutePath) == true) { // We've found a match, so we return the project that this // configuration is a part of, as the reference appears to // be a 'project reference' to this project... return(csProjectInfo); } } } return(result); }
/// <summary> /// Returns the configuration from the referenced-project with the name that best /// matches the name passed in. /// Returns null if no configurations are found . /// </summary> private ProjectConfigurationInfo_CSharp findEquivalentConfiguration(string configurationName, ProjectInfo_CSharp referencedProject) { ProjectConfigurationInfo_CSharp result = null; int nearestDistance = -1; // To find the best match, we look at the 'levenshtein distance' between the // configuration names from the project and the name we are looking for. The // one with the smallest distance is the best match. // // The idea here is that we may not be matching exactly, but we still want // to find a good match. For example, our configuration may be called 'Debug' // and the best match may be called 'Debug Any CPU'. // // This is a bit 'fuzzy' but it should be reasonably good. If there is an // exac match, it will choose it. foreach (ProjectConfigurationInfo_CSharp configurationInfo in referencedProject.getConfigurationInfos()) { int distance = Utils.levenshteinDistance(configurationName, configurationInfo.Name); if (distance < nearestDistance || nearestDistance == -1) { // This configuration is the best match so far... result = configurationInfo; nearestDistance = distance; } } return(result); }
/// <summary> /// Returns the configuration from the referenced-project with the name that best /// matches the name passed in. /// Returns null if no configurations are found . /// </summary> private ProjectConfigurationInfo_CSharp findEquivalentConfiguration(string configurationName, ProjectInfo_CSharp referencedProject) { ProjectConfigurationInfo_CSharp result = null; int nearestDistance = -1; // To find the best match, we look at the 'levenshtein distance' between the // configuration names from the project and the name we are looking for. The // one with the smallest distance is the best match. // // The idea here is that we may not be matching exactly, but we still want // to find a good match. For example, our configuration may be called 'Debug' // and the best match may be called 'Debug Any CPU'. // // This is a bit 'fuzzy' but it should be reasonably good. If there is an // exac match, it will choose it. foreach (ProjectConfigurationInfo_CSharp configurationInfo in referencedProject.getConfigurationInfos()) { int distance = Utils.levenshteinDistance(configurationName, configurationInfo.Name); if (distance < nearestDistance || nearestDistance == -1) { // This configuration is the best match so far... result = configurationInfo; nearestDistance = distance; } } return result; }
/// <summary> /// We create a makefile for the project passed in. /// </summary> public static void createMakefile(ProjectInfo_CSharp project) { new MakefileBuilder_Project_CSharp(project); }