コード例 #1
0
        public override void Run()
        {
            Log.LogMessage("Generating module build package imports");

            ProjectRootElement propsProject   = ProjectRootElement.Create(PropsFile);
            ProjectRootElement targetsProject = ProjectRootElement.Create(TargetsFile);

            ProjectPropertyGroupElement propertyGroup = propsProject.AddPropertyGroup();

            foreach (BuildPackageInfo buildPackageInfo in ModulePaths.Select(BuildPackageInfo.FromModulePath).Where(i => i != null))
            {
                if (buildPackageInfo.PropsPath == null && buildPackageInfo.TargetsPath == null)
                {
                    Log.LogMessage(MessageImportance.Low, $"  Skipping '{buildPackageInfo.Id}' because it is not a standard NuGet build package.");
                    continue;
                }

                // If this is a cbt module do not auto import props or targets.
                if (File.Exists(Path.Combine(Path.GetDirectoryName(buildPackageInfo.PropsPath ?? buildPackageInfo.TargetsPath), "module.config")))
                {
                    Log.LogMessage(MessageImportance.Low, $"  Skipping '{buildPackageInfo.Id}' because it is a CBT Module.");
                    continue;
                }

                ProjectPropertyElement enableProperty = propertyGroup.AddProperty(buildPackageInfo.EnablePropertyName, "false");
                enableProperty.Condition = $" '$({buildPackageInfo.EnablePropertyName})' == '' ";

                ProjectPropertyElement runProperty = propertyGroup.AddProperty(buildPackageInfo.RunPropertyName, "true");
                runProperty.Condition = $" '$({buildPackageInfo.RunPropertyName})' == '' ";

                if (File.Exists(buildPackageInfo.PropsPath))
                {
                    ProjectImportElement import = propsProject.AddImport(buildPackageInfo.PropsPath);

                    import.Condition = $" '$({buildPackageInfo.EnablePropertyName})' == 'true' And '$({buildPackageInfo.RunPropertyName})' == 'true' ";
                }

                if (File.Exists(buildPackageInfo.TargetsPath))
                {
                    ProjectImportElement import = targetsProject.AddImport(buildPackageInfo.TargetsPath);

                    import.Condition = $" '$({buildPackageInfo.EnablePropertyName})' == 'true' And '$({buildPackageInfo.RunPropertyName})' == 'true' ";
                }

                Log.LogMessage($"  Generated imports for '{buildPackageInfo.Id}'.");
            }

            propsProject.Save();
            targetsProject.Save();
        }
コード例 #2
0
        public void CheckForOptionErrors(ErrorHandling errors)
        {
            CheckPath(SwiftBinPath, "path to swift binaries", errors);
            CheckPath(SwiftLibPath, "path to swift libraries", errors);
            TypeDatabasePaths.ForEach(path => CheckPath(path, "path to type database files", errors));

            EnsureFileExists("swiftc", new string [] { SwiftBinPath }, errors);
            EnsureFileExists("swift", new string [] { SwiftBinPath }, errors);
            ModulePaths.ForEach(path => CheckPath(path, "module path", errors));
            DylibPaths.ForEach(path => CheckPath(path, "library path", errors));
            if (ModuleName != null)
            {
                string wholeModule = "lib" + ModuleName + ".dylib";
                string libDir      = DylibPaths.FirstOrDefault(path => File.Exists(Path.Combine(path, wholeModule)));
                if (libDir == null)
                {
                    wholeModule = ModuleName;
                    libDir      = DylibPaths.FirstOrDefault(path => File.Exists(Path.Combine(path, wholeModule)));
                }
                if (libDir == null)
                {
                    errors.Add(new ReflectorError(new FileNotFoundException($"Couldn't find module {ModuleName}")));
                    return;
                }
                string libFile = Path.Combine(libDir, wholeModule);
                using (FileStream stm = new FileStream(libFile, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    try {
                        List <string> targets = MachOHelpers.TargetsFromDylib(stm);

                        Targets = FilterTargetsIfNeeded(targets, libFile);

                        if (Targets.Count > 0)
                        {
                            var targetOS = targets [0].ClangTargetOS();
                            if (SwiftGluePath != null)
                            {
                                string path = null;
                                if (targetOS.StartsWith("macos", StringComparison.Ordinal))
                                {
                                    path = Path.Combine(SwiftGluePath, "mac/XamGlue.framework");
                                }
                                else if (targetOS.StartsWith("ios", StringComparison.Ordinal))
                                {
                                    path = Path.Combine(SwiftGluePath, "iphone/XamGlue.framework");
                                }
                                else if (targetOS.StartsWith("tvos", StringComparison.Ordinal))
                                {
                                    path = Path.Combine(SwiftGluePath, "appletv/XamGlue.framework");
                                }
                                else if (targetOS.StartsWith("watchos", StringComparison.Ordinal))
                                {
                                    path = Path.Combine(SwiftGluePath, "watch/XamGlue.framework");
                                }
                                if (path != null)
                                {
                                    ModulePaths.Add(path);
                                    DylibPaths.Add(path);
                                }
                            }
                            if (targetOS.StartsWith("macos", StringComparison.Ordinal))
                            {
                                SwiftLibPath = Path.Combine(SwiftLibPath, "macosx");
                            }
                            else if (targetOS.StartsWith("ios", StringComparison.Ordinal))
                            {
                                SwiftLibPath = Path.Combine(SwiftLibPath, "iphoneos");
                            }
                            else if (targetOS.StartsWith("tvos", StringComparison.Ordinal))
                            {
                                SwiftLibPath = Path.Combine(SwiftLibPath, "appletvos");
                            }
                            else if (targetOS.StartsWith("watchos", StringComparison.Ordinal))
                            {
                                SwiftLibPath = Path.Combine(SwiftLibPath, "watchos");
                            }
                        }


                        // filter the targets here
                        foreach (string target in Targets)
                        {
                            StringBuilder sb = new StringBuilder();
                            foreach (string s in ModulePaths.Interleave(", "))
                            {
                                sb.Append(s);
                            }
                            using (ISwiftModuleLocation loc = SwiftModuleFinder.Find(ModulePaths, ModuleName, target)) {
                                if (loc == null)
                                {
                                    errors.Add(new ReflectorError(new FileNotFoundException($"Unable to find swift module file for {ModuleName} in target {target}. Searched in {sb.ToString ()}.")));
                                }
                            }

                            using (ISwiftModuleLocation loc = SwiftModuleFinder.Find(ModulePaths, "XamGlue", target)) {
                                if (loc == null)
                                {
                                    errors.Add(new ReflectorError(new FileNotFoundException($"Unable to find swift module file for XamGlue in target {target}. Did you forget to refer to it with -M or -C? Searched in {sb.ToString ()}.")));
                                }
                            }
                        }
                    } catch (Exception err) {
                        errors.Add(new RuntimeException(ReflectorError.kCantHappenBase + 63, true, err, $"{libFile}: {err.Message}"));
                    }
                }
            }
            if (String.IsNullOrEmpty(OutputDirectory))
            {
                ArgumentException ex = new ArgumentException("need to specify an output directory with -o");
                errors.Add(ex);
            }
            else
            {
                if (File.Exists(OutputDirectory) && !File.GetAttributes(OutputDirectory).HasFlag(FileAttributes.Directory))
                {
                    errors.Add(new ReflectorError(new ArgumentException($"output directory {OutputDirectory} is a file. It needs to be a directory.")));
                    return;
                }
                if (!Directory.Exists(OutputDirectory))
                {
                    Directory.CreateDirectory(OutputDirectory);
                }
            }
        }