X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FMicrosoft.Build.Engine%2FMicrosoft.Build.BuildEngine%2FImport.cs;h=9088babcfecf8444dc178ef46234374432af271f;hb=e5fb257d8bf0b3dae7e404a5839b550bee78d685;hp=34c9615c056b79ca0e0d557846d2e50d40ad8411;hpb=43fb246720e0fa8d6e49f0cd99c3609456c31059;p=mono.git diff --git a/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Import.cs b/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Import.cs index 34c9615c056..9088babcfec 100644 --- a/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Import.cs +++ b/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Import.cs @@ -31,12 +31,19 @@ using System; using System.IO; using System.Xml; +using Microsoft.Build.Framework; +using Mono.XBuild.Utilities; + namespace Microsoft.Build.BuildEngine { public class Import { XmlElement importElement; Project project; ImportedProject originalProject; string evaluatedProjectPath; + + static string DotConfigExtensionsPath = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData), + Path.Combine ("xbuild", "tasks")); + const string MacOSXExternalXBuildDir = "/Library/Frameworks/Mono.framework/External/xbuild"; internal Import (XmlElement importElement, Project project, ImportedProject originalProject) { @@ -51,18 +58,30 @@ namespace Microsoft.Build.BuildEngine { if (ProjectPath == String.Empty) throw new InvalidProjectFileException ("The required attribute \"Project\" is missing from element ."); + + if (ConditionParser.ParseAndEvaluate (Condition, project)) { + evaluatedProjectPath = EvaluateProjectPath (ProjectPath); + evaluatedProjectPath = GetFullPath (); + if (EvaluatedProjectPath == String.Empty) + throw new InvalidProjectFileException ("The required attribute \"Project\" is missing from element ."); + } } - internal void Evaluate () + // FIXME: condition + internal void Evaluate (bool ignoreMissingImports) { - evaluatedProjectPath = EvaluateProjectPath (ProjectPath); - string filename = GetFullPath (); - - if (EvaluatedProjectPath == String.Empty) - throw new InvalidProjectFileException ("The required attribute \"Project\" is missing from element ."); + string filename = evaluatedProjectPath; + // NOTE: it's a hack to transform Microsoft.CSharp.Targets to Microsoft.CSharp.targets + if (Path.HasExtension (filename)) + filename = Path.ChangeExtension (filename, Path.GetExtension (filename)); if (!File.Exists (filename)) { - throw new InvalidProjectFileException (String.Format ("Imported project: \"{0}\" does not exist.", filename)); + if (ignoreMissingImports) { + project.LogWarning (project.FullFileName, "Could not find project file {0}, to import. Ignoring.", filename); + return; + } else { + throw new InvalidProjectFileException (String.Format ("Imported project: \"{0}\" does not exist.", filename)); + } } ImportedProject importedProject = new ImportedProject (); @@ -73,10 +92,68 @@ namespace Microsoft.Build.BuildEngine { string EvaluateProjectPath (string file) { - Expression exp; + string ret; + if (EvaluateAsMSBuildExtensionsPath (file, "MSBuildExtensionsPath", out ret) || + EvaluateAsMSBuildExtensionsPath (file, "MSBuildExtensionsPath32", out ret) || + EvaluateAsMSBuildExtensionsPath (file, "MSBuildExtensionsPath64", out ret)) + return ret; + + return EvaluatePath (file); + } + + bool EvaluateAsMSBuildExtensionsPath (string file, string property_name, out string epath) + { + epath = null; + string property_ref = String.Format ("$({0})", property_name); + if (file.IndexOf (property_ref) < 0) + return false; - exp = new Expression (); - exp.Parse (file); + // This is a *HACK* to support multiple paths for + // MSBuildExtensionsPath property. Normally it would + // get resolved to a single value, but here we special + // case it and try ~/.config/xbuild/tasks and any + // paths specified in the env var $MSBuildExtensionsPath . + // + // The property itself will resolve to the default + // location though, so you get in any other part of the + // project. + + string envvar = Environment.GetEnvironmentVariable (property_name); + envvar = String.Join (":", new string [] { + (envvar ?? String.Empty), + // For mac osx, look in the 'External' dir on macosx, + // see bug #663180 + MSBuildUtils.RunningOnMac ? MacOSXExternalXBuildDir : String.Empty, + DotConfigExtensionsPath}); + + string [] paths = envvar.Split (new char [] {':'}, StringSplitOptions.RemoveEmptyEntries); + foreach (string path in paths) { + if (!Directory.Exists (path)) { + project.ParentEngine.LogMessage (MessageImportance.Low, "Extension path '{0}' not found, ignoring.", path); + continue; + } + + string pfile = Path.GetFullPath (file.Replace ("\\", "/").Replace ( + property_ref, path + Path.DirectorySeparatorChar)); + + var evaluated_path = EvaluatePath (pfile); + if (File.Exists (evaluated_path)) { + project.ParentEngine.LogMessage (MessageImportance.Low, + "{0}: Importing project {1} from extension path {2}", project.FullFileName, evaluated_path, path); + epath = pfile; + return true; + } + project.ParentEngine.LogMessage (MessageImportance.Low, + "{0}: Couldn't find project {1} for extension path {2}", project.FullFileName, evaluated_path, path); + } + + return false; + } + + string EvaluatePath (string path) + { + var exp = new Expression (); + exp.Parse (path, ParseOptions.Split); return (string) exp.ConvertTo (project, typeof (string)); } @@ -97,7 +174,7 @@ namespace Microsoft.Build.BuildEngine { file = Path.Combine (dir, EvaluatedProjectPath); } - return file; + return MSBuildUtils.FromMSBuildPath (file); } public string Condition {