~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.Autotools/MakefileData.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
using System.Text.RegularExpressions;
36
36
 
37
37
using MonoDevelop.Core;
 
38
using MonoDevelop.Core.Gui;
38
39
using MonoDevelop.Core.Execution;
39
40
using MonoDevelop.Core.ProgressMonitoring;
40
41
using MonoDevelop.Ide.Gui;
41
 
using MonoDevelop.Projects.Serialization;
 
42
using MonoDevelop.Core.Serialization;
42
43
using MonoDevelop.Projects;
43
44
 
44
45
namespace MonoDevelop.Autotools
55
56
                CustomMakefile makefile;
56
57
                
57
58
                [ItemProperty ("ExcludedFiles")]
58
 
                [ProjectPathItemProperty("File", Scope=1)]
 
59
                [ProjectPathItemProperty("File", Scope="*")]
59
60
                List<string> excludedFiles = new List<string> ();
60
61
 
61
62
                public MakefileData ()
82
83
                                        ProjectFileEventHandler filehandler = delegate (object sender, ProjectFileEventArgs e) {
83
84
                                                MakefileVar var = null;
84
85
                                                switch (e.ProjectFile.BuildAction) {
85
 
                                                case BuildAction.Compile:
 
86
                                                case "Compile":
86
87
                                                        var = BuildFilesVar;
87
88
                                                        break;
88
 
                                                case BuildAction.FileCopy:
 
89
                                                case "Content":
89
90
                                                        var = DeployFilesVar;
90
91
                                                        break;
91
 
                                                case BuildAction.EmbedAsResource:
 
92
                                                case "EmbeddedResource":
92
93
                                                        var = ResourcesVar;
93
94
                                                        break;
94
 
                                                case BuildAction.Nothing:
 
95
                                                case "None":
95
96
                                                        var = OthersVar;
96
97
                                                        break;
97
98
                                                }
415
416
                        }
416
417
                }
417
418
                
418
 
                public bool IsFileIntegrationEnabled (BuildAction fileType)
 
419
                public bool IsFileIntegrationEnabled (string buildAction)
419
420
                {
420
421
                        if (IntegrationEnabled) {
421
 
                                if (fileType == BuildAction.Compile)
 
422
                                if (buildAction == BuildAction.Compile)
422
423
                                        return BuildFilesVar.Sync;
423
 
                                else if (fileType == BuildAction.EmbedAsResource)
 
424
                                else if (buildAction == BuildAction.EmbeddedResource)
424
425
                                        return ResourcesVar.Sync;
425
 
                                else if (fileType == BuildAction.FileCopy)
 
426
                                else if (buildAction == BuildAction.Content)
426
427
                                        return DeployFilesVar.Sync;
427
428
                                else
428
429
                                        return OthersVar.Sync;
491
492
                                @"^\s*(?<file>[^:]*):(?<line>\d*){1}(:(?<column>\d*))?\s*:\s*error\s*:\s(?<message>.*)",
492
493
                                @"^\s*(?<file>[^:]*):(?<line>\d*){1}(:(?<column>\d*))?\s*:\s*warning\s*:\s(?<message>.*)"
493
494
                        };
 
495
                        
 
496
                        compilerMessageRegex ["Boo"] = new string [] {
 
497
                                @"(^\s*(?<file>.*)\((?<line>\d*){1}(,(?<column>\d*[\+]*))?\)(:|)\s+)*(?=BCE)(?<number>.*?):\s(?<message>.*)",
 
498
                                @"(^\s*(?<file>.*)\((?<line>\d*){1}(,(?<column>\d*[\+]*))?\)(:|)\s+)*(?=BCW)(?<number>.*?):\sWARNING:\s(?<message>.*)"
 
499
                        };
 
500
 
 
501
                        compilerMessageRegex ["Vala"] = new string [] {
 
502
                                @"((^\s*(?<file>.*):(?<line>\d*)\.(?<column>\d*)-\d*\.\d*: error: (?<message>.*))|(^\s*(?<file>[^:]*):(?<line>\d*){1}(:(?<column>\d*))?\s*:\s*error\s*:\s(?<message>.*)))",
 
503
                                @"((^\s*(?<file>.*):(?<line>\d*)\.(?<column>\d*)-\d*\.\d*: warning: (?<message>.*))|(^\s*(?<file>[^:]*):(?<line>\d*){1}(:(?<column>\d*))?\s*:\s*warning\s*:\s(?<message>.*)))"
 
504
                        };
494
505
                }
495
506
 
496
507
                void InitBuildVars ()
630
641
 
631
642
                        //FIXME: Improve the message
632
643
                        if (promptForRemoval) {
633
 
                                int choice = IdeApp.Services.MessageService.ShowCustomDialog (
634
 
                                                GettextCatalog.GetString ("Enable Makefile integration"),
635
 
                                                GettextCatalog.GetString ("Enabling Makefile integration. You can choose to have either the Project or the Makefile be used as the master copy. This is done only when enabling this feature. After this, the Makefile will be taken as the master copy."),
636
 
                                                "Project", "Makefile");
637
 
 
638
 
                                if (choice == 0) {
 
644
                                AlertButton projectButton = new AlertButton ("_Project");
 
645
                                AlertButton makefileButton = new AlertButton ("_Makefile");
 
646
                                AlertButton choice = MessageService.AskQuestion (GettextCatalog.GetString ("Enabling Makefile integration. You can choose to have either the Project or the Makefile be used as the master copy. This is done only when enabling this feature. After this, the Makefile will be taken as the master copy."),
 
647
                                                                                 projectButton, makefileButton);
 
648
                                if (choice == projectButton) {
639
649
                                        //Sync Project --> Makefile
640
650
                                        dirty = true;
641
651
                                        return;
676
686
                                        AbsoluteConfigureInPath, OwnerProject.Name, e.ToString ());
677
687
 
678
688
                                monitor.ReportWarning (GettextCatalog.GetString (
679
 
                                        "Error trying to read configure.in ('{0'}) for project '{1}':\n{2}",
 
689
                                        "Error trying to read configure.in ('{0}') for project '{1}':\n{2}",
680
690
                                        AbsoluteConfigureInPath, OwnerProject.Name, e.Message));
681
691
                        }
682
692
 
683
693
                        ReadFiles (BuildFilesVar, BuildAction.Compile, "Build", promptForRemoval);
684
 
                        ReadFiles (DeployFilesVar, BuildAction.FileCopy, "Deploy", promptForRemoval);
685
 
                        ReadFiles (OthersVar, BuildAction.Nothing, "Others", promptForRemoval);
686
 
                        ReadFiles (ResourcesVar, BuildAction.EmbedAsResource, "Resources", promptForRemoval);
 
694
                        ReadFiles (DeployFilesVar, BuildAction.Content, "Deploy", promptForRemoval);
 
695
                        ReadFiles (OthersVar, BuildAction.None, "Others", promptForRemoval);
 
696
                        ReadFiles (ResourcesVar, BuildAction.EmbeddedResource, "Resources", promptForRemoval);
687
697
 
688
698
                        if (!SyncReferences)
689
699
                                return;
699
709
                                        ProjectRefVar.Extra.Clear ();
700
710
 
701
711
                                        existingGacRefs = new Dictionary<string, ProjectReference> ();
 
712
                                        requiredPackageVersions = new Dictionary<string,string> ();
702
713
                                        newGacRefs = new Dictionary<string, ProjectReference> ();
703
714
 
704
715
                                        List<ProjectReference> toRemove = new List<ProjectReference> ();
705
 
                                        foreach (ProjectReference pref in OwnerProject.ProjectReferences) {
 
716
                                        foreach (ProjectReference pref in dotnetProject.References) {
706
717
                                                if (pref.ReferenceType == ReferenceType.Gac) {
707
 
                                                        string [] files = pref.GetReferencedFileNames ();
 
718
                                                        string [] files = pref.GetReferencedFileNames (ProjectService.DefaultConfiguration);
708
719
                                                        if (files == null)
709
720
                                                                continue;
710
721
 
 
722
                                                        if (pref.ReferenceType == ReferenceType.Gac) {
 
723
                                                                // Store the package version required by this reference. We'll use
 
724
                                                                // the same version when trying to match references coming from the makefile
 
725
                                                                SystemPackage pkg = Runtime.SystemAssemblyService.GetPackageFromFullName (pref.StoredReference);
 
726
                                                                if (pkg != null)
 
727
                                                                        requiredPackageVersions [pkg.Name] = pkg.Version;
 
728
                                                        }
711
729
                                                        // this should help normalize paths like /foo//bar/../
712
730
                                                        string fullpath = Path.GetFullPath (files [0]);
713
731
                                                        if (existingGacRefs.ContainsKey (fullpath))
719
737
 
720
738
                                        // Remove the repeats
721
739
                                        foreach (ProjectReference pref in toRemove)
722
 
                                                OwnerProject.ProjectReferences.Remove (pref);
 
740
                                                dotnetProject.References.Remove (pref);
723
741
 
724
742
                                        ReadReferences (GacRefVar, ReferenceType.Gac, "Gac References", dotnetProject);
725
743
 
732
750
                                        
733
751
                                        //Resolve References
734
752
                                        //Required when UpdateProject gets called by ui
735
 
                                        if (ownerProject.RootCombine != null)
736
 
                                                ResolveProjectReferences (ownerProject.RootCombine, monitor);
 
753
                                        if (ownerProject.ParentSolution != null)
 
754
                                                ResolveProjectReferences (ownerProject.ParentSolution.RootFolder, monitor);
737
755
 
738
756
                                        foreach (ProjectReference pr in existingGacRefs.Values)
739
 
                                                ownerProject.ProjectReferences.Remove (pr);
 
757
                                                dotnetProject.References.Remove (pr);
740
758
 
741
759
                                        existingGacRefs.Clear ();
742
760
                                        newGacRefs.Clear ();
753
771
                        this.monitor = null;
754
772
                }
755
773
 
756
 
                void ReadFiles (MakefileVar fileVar, BuildAction buildAction, string id, bool promptForRemoval)
 
774
                void ReadFiles (MakefileVar fileVar, string buildAction, string id, bool promptForRemoval)
757
775
                {
758
776
                        try { 
759
777
                                fileVar.SaveEnabled = true;
766
784
                        }
767
785
                }
768
786
 
769
 
                void ReadFilesActual (MakefileVar fileVar, BuildAction buildAction, string id, bool promptForRemoval)
 
787
                void ReadFilesActual (MakefileVar fileVar, string buildAction, string id, bool promptForRemoval)
770
788
                {
771
789
                        fileVar.Extra.Clear ();
772
790
                        if (!fileVar.Sync || String.IsNullOrEmpty (fileVar.Name))
793
811
                                len = fileVar.Prefix.Length;
794
812
 
795
813
                        Dictionary<string, ProjectFile> existingFiles = new Dictionary<string, ProjectFile> ();
796
 
                        foreach (ProjectFile pf in ownerProject.ProjectFiles) {
 
814
                        foreach (ProjectFile pf in ownerProject.Files) {
797
815
                                if (pf.BuildAction == buildAction)
798
816
                                        existingFiles [ownerProject.GetAbsoluteChildPath (pf.FilePath)] = pf;
799
817
                        }
814
832
                                        fname = UnescapeString (fname);
815
833
 
816
834
                                        string resourceId = null;
817
 
                                        if (buildAction == BuildAction.EmbedAsResource && fname.IndexOf (',') >= 0) {
 
835
                                        if (buildAction == BuildAction.EmbeddedResource && fname.IndexOf (',') >= 0) {
818
836
                                                string [] tmp = fname.Split (new char [] {','}, 2);
819
837
                                                fname = tmp [0];
820
838
                                                if (tmp.Length > 1)
859
877
                                        }
860
878
 
861
879
                                        ProjectFile pf = ownerProject.AddFile (absPath, buildAction);
862
 
                                        if (buildAction == BuildAction.EmbedAsResource && resourceId != null)
 
880
                                        if (buildAction == BuildAction.EmbeddedResource && resourceId != null)
863
881
                                                pf.ResourceId = resourceId;
864
882
                                } catch (Exception e) {
865
883
                                        LoggingService.LogError (e.ToString ());
870
888
                        if (existingFiles.Count > 0) {
871
889
                                foreach (ProjectFile file in existingFiles.Values) {
872
890
                                        if (!IsFileExcluded (file.FilePath))
873
 
                                                ownerProject.ProjectFiles.Remove (file);
 
891
                                                ownerProject.Files.Remove (file);
874
892
                                }
875
893
                        }
876
894
                }
877
895
 
878
896
                Dictionary<string, ProjectReference> existingGacRefs = null;
879
897
                Dictionary<string, ProjectReference> newGacRefs = null;
 
898
                Dictionary<string, string> requiredPackageVersions = null;
880
899
 
881
900
                void ReadReferences (MakefileVar refVar, ReferenceType refType, string id, DotNetProject project)
882
901
                {
1040
1059
 
1041
1060
                bool LoadPackageReference (string pkgName, DotNetProject project, string prefix)
1042
1061
                {
1043
 
                        SystemPackage pkg = Runtime.SystemAssemblyService.GetPackage (pkgName);
 
1062
                        SystemPackage pkg = null;
 
1063
                        string packageVersion;
 
1064
                        if (requiredPackageVersions.TryGetValue (pkgName, out packageVersion))
 
1065
                                pkg = Runtime.SystemAssemblyService.GetPackage (pkgName, packageVersion);
 
1066
                        if (pkg == null)
 
1067
                                pkg = Runtime.SystemAssemblyService.GetPackage (pkgName);
 
1068
                        
1044
1069
                        if (pkg == null) {
1045
1070
                                LoggingService.LogWarning ("No package named '{0}' found. Ignoring.", pkgName);
1046
1071
                                return false;
1103
1128
                        if (fullname == null)
1104
1129
                                return null;
1105
1130
 
1106
 
                        fullname = Runtime.SystemAssemblyService.GetAssemblyNameForVersion (fullname, project.ClrVersion);
 
1131
                        fullname = Runtime.SystemAssemblyService.GetAssemblyNameForVersion (fullname, project.TargetFramework);
1107
1132
                        if (fullname == null)
1108
1133
                                return null;
1109
1134
 
1131
1156
                        return null;
1132
1157
                }
1133
1158
 
1134
 
                ProjectReference AddNewGacReference (Project project, string fullname, string fullpath)
 
1159
                ProjectReference AddNewGacReference (DotNetProject project, string fullname, string fullpath)
1135
1160
                {
1136
1161
                        ProjectReference pref = new ProjectReference (ReferenceType.Gac, fullname);
1137
 
                        project.ProjectReferences.Add (pref);
 
1162
                        project.References.Add (pref);
1138
1163
                        newGacRefs [fullpath] = pref;
1139
1164
 
1140
1165
                        return pref;
1141
1166
                }
1142
1167
 
1143
 
                public static void ResolveProjectReferences (Combine c, IProgressMonitor monitor)
 
1168
                public static void ResolveProjectReferences (SolutionFolder folder, IProgressMonitor monitor)
1144
1169
                {
1145
 
                        Dictionary<string, Project> projects = new Dictionary<string, Project> ();
1146
 
                        foreach (Project p in c.GetAllProjects ()) {
1147
 
                                string filename = p.GetOutputFileName ();
 
1170
                        Dictionary<string, DotNetProject> projects = new Dictionary<string, DotNetProject> ();
 
1171
                        string defConfig = ProjectService.DefaultConfiguration;
 
1172
                        foreach (DotNetProject p in folder.GetAllItems<DotNetProject> ()) {
 
1173
                                string filename = p.GetOutputFileName (defConfig);
1148
1174
                                // Can be null for Generic projects
1149
1175
                                if (!String.IsNullOrEmpty (filename))
1150
1176
                                        projects [filename] = p;
1151
1177
                        }
1152
1178
 
1153
 
                        foreach (Project sproj in projects.Values) {
 
1179
                        foreach (DotNetProject sproj in projects.Values) {
1154
1180
                                MakefileData mdata = sproj.ExtendedProperties ["MonoDevelop.Autotools.MakefileInfo"] as MakefileData;
1155
1181
                                if (mdata == null)
1156
1182
                                        continue;
1160
1186
                                        Dictionary<string, ProjectReference> asmProjectRefs =
1161
1187
                                                new Dictionary<string, ProjectReference> ();
1162
1188
 
1163
 
                                        foreach (ProjectReference pr in sproj.ProjectReferences) {
 
1189
                                        foreach (ProjectReference pr in sproj.References) {
1164
1190
                                                if (pr.ReferenceType != ReferenceType.Assembly &&
1165
1191
                                                        pr.ReferenceType != ReferenceType.Project)
1166
1192
                                                        continue;
1167
1193
                                                
1168
 
                                                string [] files = pr.GetReferencedFileNames ();
 
1194
                                                string [] files = pr.GetReferencedFileNames (defConfig);
1169
1195
                                                if (files.Length > 0)
1170
1196
                                                        asmProjectRefs [files [0]] = pr;
1171
1197
                                        }
1179
1205
                                                } else {
1180
1206
                                                        // Try as a project ref
1181
1207
                                                        if (projects.ContainsKey (refstr)) {
1182
 
                                                                sproj.ProjectReferences.Add (new ProjectReference (projects [refstr]));
 
1208
                                                                sproj.References.Add (new ProjectReference (projects [refstr]));
1183
1209
                                                                toRemove.Add (refstr);
1184
1210
                                                        }
1185
1211
                                                }
1190
1216
 
1191
1217
                                        // Add all remaining unresolved refs as Assembly refs
1192
1218
                                        foreach (string s in mdata.UnresolvedReferences.Keys)
1193
 
                                                sproj.ProjectReferences.Add (new ProjectReference (ReferenceType.Assembly, s));
 
1219
                                                sproj.References.Add (new ProjectReference (ReferenceType.Assembly, s));
1194
1220
                                                
1195
1221
                                        // Remove asm/project refs not found in UnresolvedReferences
1196
1222
                                        foreach (ProjectReference pr in asmProjectRefs.Values)
1197
 
                                                sproj.ProjectReferences.Remove (pr);
 
1223
                                                sproj.References.Remove (pr);
1198
1224
 
1199
1225
                                        mdata.UnresolvedReferences.Clear ();
1200
1226
                                }
1301
1327
                        //FIXME: If anything fails while writing, skip completely
1302
1328
                        //FIXME: All the file vars must be distinct
1303
1329
                        WriteFiles (BuildFilesVar, BuildAction.Compile, makeRelative, "Build");
1304
 
                        WriteFiles (DeployFilesVar, BuildAction.FileCopy, makeRelative, "Deploy");
1305
 
                        WriteFiles (OthersVar, BuildAction.Nothing, makeRelative, "Others");
1306
 
                        WriteFiles (ResourcesVar, BuildAction.EmbedAsResource, makeRelative, "Resources");
 
1330
                        WriteFiles (DeployFilesVar, BuildAction.Content, makeRelative, "Deploy");
 
1331
                        WriteFiles (OthersVar, BuildAction.None, makeRelative, "Others");
 
1332
                        WriteFiles (ResourcesVar, BuildAction.EmbeddedResource, makeRelative, "Resources");
1307
1333
 
1308
1334
                        if (SyncReferences && SaveReferences) {
1309
1335
                                Makefile.ClearVariableValue (GacRefVar.Name);
1342
1368
                        this.monitor = null;
1343
1369
                }
1344
1370
 
1345
 
                bool WriteFiles (MakefileVar fileVar, BuildAction action, bool makeRelative, string id)
 
1371
                bool WriteFiles (MakefileVar fileVar, string buildAction, bool makeRelative, string id)
1346
1372
                {
1347
1373
                        if (!fileVar.Sync || !fileVar.SaveEnabled)
1348
1374
                                return false;
1357
1383
                        }
1358
1384
 
1359
1385
                        List<string> files = new List<string> ();
1360
 
                        foreach (ProjectFile pf in OwnerProject.ProjectFiles) {
 
1386
                        foreach (ProjectFile pf in OwnerProject.Files) {
1361
1387
                                if (pf.Subtype != Subtype.Code)
1362
1388
                                        continue;
1363
1389
                                if (IsFileExcluded (pf.FilePath))
1364
1390
                                        continue;
1365
 
                                if (pf.BuildAction == action) {
 
1391
                                if (pf.BuildAction == buildAction) {
1366
1392
                                        string str = null;
1367
1393
                                        if (makeRelative)
1368
1394
                                                //Files are relative to the Makefile
1381
1407
                                        }
1382
1408
 
1383
1409
                                        // Emit the resource ID only when it is different from the file name
1384
 
                                        if (pf.BuildAction == BuildAction.EmbedAsResource && pf.ResourceId != null && pf.ResourceId.Length > 0 && pf.ResourceId != unescapedFileName)
 
1410
                                        if (pf.BuildAction == BuildAction.EmbeddedResource && pf.ResourceId != null && pf.ResourceId.Length > 0 && pf.ResourceId != unescapedFileName)
1385
1411
                                                str = String.Format ("{0}{1},{2}", fileVar.Prefix, str, EscapeString (pf.ResourceId));
1386
1412
                                        else
1387
1413
                                                str = String.Format ("{0}{1}", fileVar.Prefix, str);
1421
1447
                        //      key -> pkgname, emit as -pkg:$key
1422
1448
                        Dictionary<string, bool> hasAcSubstPackages = new Dictionary<string, bool> ();
1423
1449
 
1424
 
                        foreach (ProjectReference pr in OwnerProject.ProjectReferences) {
 
1450
                        foreach (ProjectReference pr in ((DotNetProject)OwnerProject).References) {
1425
1451
                                if (pr.ReferenceType != refType)
1426
1452
                                        continue;
1427
1453
 
1488
1514
                        }
1489
1515
 
1490
1516
                        if (pkg == null)
1491
 
                                return AsmRefToString (pr.GetReferencedFileNames () [0], refVar, false);
 
1517
                                return AsmRefToString (pr.GetReferencedFileNames (ProjectService.DefaultConfiguration) [0], refVar, false);
1492
1518
 
1493
1519
                        // Reference is from a package
1494
1520
 
1550
1576
 
1551
1577
                string ProjectRefToString (ProjectReference pr, MakefileVar refVar)
1552
1578
                {
1553
 
                        string [] tmp = pr.GetReferencedFileNames ();
 
1579
                        string [] tmp = pr.GetReferencedFileNames (ProjectService.DefaultConfiguration);
1554
1580
                        if (tmp == null || tmp.Length == 0)
1555
1581
                                //Reference not found, ignoring
1556
1582
                                return null;