Ejemplo n.º 1
0
        private void DoBuilding()
        {
            var ops = Unary.OperationsManager;

            if (BuildingOperation == null)
            {
                BuildingOperation = new BuildOperation(ops);
            }

            var foundations = ops.FreeUnits.Concat(BuildingOperation.Units)
                              .Where(u => u.GetData(ObjectData.STATUS) == 0 && u.GetData(ObjectData.CATEGORY) == 80)
                              .ToList();

            if (foundations.Count == 0)
            {
                BuildingOperation.ClearUnits();

                return;
            }

            Unary.Log.Info($"StrategyManager: Have {foundations.Count} foundations");

            foreach (var foundation in foundations)
            {
                BuildingOperation.AddUnit(foundation);

                Unary.Log.Info($"Foundation type {foundation[ObjectData.TYPE]} pos {foundation.Position}");
            }

            if (BuildingOperation.Units.Count(u => u[ObjectData.CMDID] == (int)CmdId.VILLAGER) == 0)
            {
                var vill = ops.FreeUnits.FirstOrDefault(u => u.GetData(ObjectData.CMDID) == (int)CmdId.VILLAGER);

                if (vill != null)
                {
                    BuildingOperation.AddUnit(vill);
                }
            }

            if (BuildingOperation.Units.Count(u => u[ObjectData.CMDID] == (int)CmdId.VILLAGER) == 0)
            {
                foreach (var unit in ops.Operations.Where(o => !(o is BuildOperation)).SelectMany(o => o.Units).Where(u => u[ObjectData.CMDID] == (int)CmdId.VILLAGER))
                {
                    if (unit[ObjectData.CARRY] == 0)
                    {
                        BuildingOperation.AddUnit(unit);

                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Compile
        /// </summary>
        public IList <BuildOperation> CreateCompileOperations(
            CompileArguments arguments)
        {
            var operations = new List <BuildOperation>();

            // Write the shared arguments to the response file
            var responseFile                  = arguments.ObjectDirectory + new Path("CompileArguments.rsp");
            var sharedCommandArguments        = ArgumentBuilder.BuildSharedCompilerArguments(arguments);
            var writeSharedArgumentsOperation = SharedOperations.CreateWriteFileOperation(
                arguments.TargetRootDirectory,
                responseFile,
                string.Join(" ", sharedCommandArguments));

            operations.Add(writeSharedArgumentsOperation);

            var symbolFile = new Path(arguments.Target.ToString());

            symbolFile.SetFileExtension("pdb");

            var targetResponseFile = arguments.TargetRootDirectory + responseFile;

            // Build up the input/output sets
            var inputFiles = new List <Path>();

            inputFiles.Add(targetResponseFile);
            inputFiles.AddRange(arguments.SourceFiles);
            inputFiles.AddRange(arguments.ReferenceLibraries);
            var outputFiles = new List <Path>()
            {
                arguments.TargetRootDirectory + arguments.Target,
                arguments.TargetRootDirectory + arguments.ReferenceTarget,
                arguments.TargetRootDirectory + symbolFile,
            };

            // Generate the compile build operation
            var uniqueCommandArguments = ArgumentBuilder.BuildUniqueCompilerArguments();
            var commandArguments       = $"@{targetResponseFile} {string.Join(" ", uniqueCommandArguments)}";
            var buildOperation         = new BuildOperation(
                $"Compile - {arguments.Target}",
                arguments.SourceRootDirectory,
                _compilerExecutable,
                commandArguments,
                inputFiles,
                outputFiles);

            operations.Add(buildOperation);

            return(operations);
        }
Ejemplo n.º 3
0
        public void TriggerOperation(BuildOperation operation)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            Operation = operation;
            SetGeneratorProperties();

            switch (operation)
            {
            case BuildOperation.Build:         TriggerBuildSolution(); break;

            case BuildOperation.Rebuild:       TriggerBuildSolution(); break;

            case BuildOperation.GenerateClang: _ = TriggerClangGeneratorAsync(); break;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Link
        /// </summary>
        public BuildOperation CreateLinkOperation(
            LinkArguments arguments)
        {
            // Select the correct executable for linking libraries or executables
            Path executablePath;

            switch (arguments.TargetType)
            {
            case LinkTarget.StaticLibrary:
                executablePath = _libraryExecutable;
                break;

            case LinkTarget.DynamicLibrary:
            case LinkTarget.Executable:
            case LinkTarget.WindowsApplication:
                executablePath = _linkerExecutable;
                break;

            default:
                throw new InvalidOperationException("Unknown LinkTarget.");
            }

            // Build the set of input/output files along with the arguments
            var inputFiles = new List <Path>();

            inputFiles.AddRange(arguments.LibraryFiles);
            inputFiles.AddRange(arguments.ObjectFiles);
            var outputFiles = new List <Path>()
            {
                arguments.TargetRootDirectory + arguments.TargetFile,
            };
            var commandarguments = ArgumentBuilder.BuildLinkerArguments(arguments);

            var buildOperation = new BuildOperation(
                arguments.TargetFile.ToString(),
                arguments.TargetRootDirectory,
                executablePath,
                CombineArguments(commandarguments),
                inputFiles,
                outputFiles);

            return(buildOperation);
        }
Ejemplo n.º 5
0
        public void LinkWindowsApplication_Simple()
        {
            var uut = new Compiler(
                new Path("C:/bin/mock.cl.exe"),
                new Path("C:/bin/mock.link.exe"),
                new Path("C:/bin/mock.lib.exe"),
                new Path("C:/bin/mock.rc.exe"));

            var arguments = new LinkArguments();

            arguments.TargetType          = LinkTarget.WindowsApplication;
            arguments.TargetArchitecture  = "x64";
            arguments.TargetFile          = new Path("Something.exe");
            arguments.TargetRootDirectory = new Path("C:/target/");
            arguments.ObjectFiles         = new List <Path>()
            {
                new Path("File.mock.obj"),
            };
            arguments.LibraryFiles = new List <Path>()
            {
                new Path("Library.mock.a"),
            };

            var result = uut.CreateLinkOperation(arguments);

            // Verify result
            var expected = new BuildOperation(
                "./Something.exe",
                new Path("C:/target/"),
                new Path("C:/bin/mock.link.exe"),
                "/nologo /subsystem:windows /machine:X64 /out:\"./Something.exe\" ./Library.mock.a ./File.mock.obj",
                new List <Path>()
            {
                new Path("Library.mock.a"),
                new Path("File.mock.obj"),
            },
                new List <Path>()
            {
                new Path("C:/target/Something.exe"),
            });

            Assert.Equal(expected, result);
        }
        private static object ResolveArgument(BuildOperation operation, IBuilderContext context)
        {
            try
            {
                context.CurrentOperation = operation;
                var policy = context.GetOverriddenResolver(typeof(ParameterOverride));

                return(null != policy?policy.Resolve(context)
                           : context.Container.Resolve(operation.TypeBeingConstructed));
            }
            catch (Exception e)
            {
                throw new ResolutionFailedException(operation.TypeBeingConstructed,
                                                    (operation as ParameterResolveOperation)?.ParameterName,
                                                    e, context, Constants.FactoryResolutionFailed);
            }
            finally
            {
                context.CurrentOperation = null;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Starts the specified build operation on the project for the currently selected project configuration.
        /// </summary>
        /// <param name="operation">The operation to perform.</param>
        public void StartBuild(BuildOperation operation)
        {
            Tracer.VerifyEnumArgument((int)operation, "operation", typeof(BuildOperation));

            // We have to verify that the environment is not busy right now
            if (Package.Instance.Context.IsSolutionBuilding)
            {
                Tracer.WriteLineVerbose(classType, "StartBuild", "The build manager is busy right now.");
                return;
            }

            // Get the build manager from VS
            IVsSolutionBuildManager solutionBuildMgr = this.ServiceProvider.GetServiceOrThrow(typeof(SVsSolutionBuildManager), typeof(IVsSolutionBuildManager), classType, "StartBuild") as IVsSolutionBuildManager;

            // Convert the enum to one of the VS flags
            VSSOLNBUILDUPDATEFLAGS flags = VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_NONE;

            switch (operation)
            {
            case BuildOperation.Clean:
                flags |= VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_CLEAN;
                break;

            case BuildOperation.Build:
                flags |= VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_BUILD;
                break;

            case BuildOperation.Rebuild:
                flags |= VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_CLEAN | VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_BUILD;
                break;

            default:
                Tracer.Fail("Unknown BuildOperation '{0}'", operation.ToString());
                return;
            }


            NativeMethods.ThrowOnFailure(solutionBuildMgr.StartSimpleUpdateProjectConfiguration((IVsHierarchy)this, null, null, (uint)flags, 0, 0));
        }
Ejemplo n.º 8
0
        private static object ResolveArgument(BuildOperation operation, IBuilderContext context, IUnityContainer container)
        {
            try
            {
                context.CurrentOperation = operation;
                var policy = context.GetOverriddenResolver(typeof(ParameterOverride));

                return(null != policy
                    ? policy.Resolve(context)
                    : container.Resolve(operation.TypeBeingConstructed));
            }
            catch
            {
                // ignored
            }
            finally
            {
                context.CurrentOperation = null;
            }

            return(GetDefaultValue(operation.TypeBeingConstructed));
        }
Ejemplo n.º 9
0
        public void Execute()
        {
            var activeState = this.buildState.ActiveState;
            var sharedState = this.buildState.SharedState;

            var recipeTable      = activeState["Recipe"].AsTable();
            var activeBuildTable = activeState["Build"].AsTable();
            var parametersTable  = activeState["Parameters"].AsTable();

            if (!recipeTable.ContainsKey("Tests"))
            {
                throw new InvalidOperationException("No Tests Specified");
            }

            var arguments = new BuildArguments();

            arguments.TargetArchitecture = parametersTable["Architecture"].AsString();

            // Load up the common build properties from the original Build table in the active state
            LoadBuildProperties(activeBuildTable, arguments);

            // Load the test properties
            var testTable = recipeTable["Tests"].AsTable();

            LoadTestBuildProperties(buildState, testTable, arguments);

            // Load up the input build parameters from the shared build state as if
            // this is a dependency build
            var sharedBuildTable = sharedState["Build"].AsTable();

            LoadDependencyBuildInput(sharedBuildTable, arguments);

            // Load up the test dependencies build input to add extra test runtime libraries
            LoadTestDependencyBuildInput(buildState, activeState, arguments);

            // Update to place the output in a sub folder
            arguments.ObjectDirectory = arguments.ObjectDirectory + new Path("Test/");
            arguments.BinaryDirectory = arguments.BinaryDirectory + new Path("Test/");

            // Initialize the compiler to use
            var compilerName = parametersTable["Compiler"].AsString();

            if (!this.compilerFactory.TryGetValue(compilerName, out var compileFactory))
            {
                this.buildState.LogTrace(TraceLevel.Error, "Unknown compiler: " + compilerName);
                throw new InvalidOperationException();
            }

            var compiler = compileFactory(activeState);

            var buildEngine = new BuildEngine(compiler);
            var buildResult = buildEngine.Execute(buildState, arguments);

            // Create the operation to run tests during build
            var title             = "Run Tests";
            var program           = new Path("C:/Program Files/dotnet/dotnet.exe");
            var runtimeConfigFile = arguments.BinaryDirectory + new Path($"{arguments.TargetName}.runtimeconfig.json");
            var workingDirectory  = arguments.TargetRootDirectory;
            var runArguments      = buildResult.TargetFile.ToString();

            // Ensure that the executable and all runtime dependencies are in place before running tests
            var inputFiles = new List <Path>(buildResult.RuntimeDependencies);

            inputFiles.Add(program);
            inputFiles.Add(runtimeConfigFile);

            // The test should have no output
            var outputFiles = new List <Path>();

            var runTestsOperation =
                new BuildOperation(
                    title,
                    workingDirectory,
                    program,
                    runArguments,
                    inputFiles,
                    outputFiles);

            // Run the test harness
            buildResult.BuildOperations.Add(runTestsOperation);

            // Register the build operations
            foreach (var operation in buildResult.BuildOperations)
            {
                buildState.CreateOperation(operation);
            }
        }
Ejemplo n.º 10
0
    private void ShowBuildUI(string platform)
    {
        versionPart = EditorGUILayout.Foldout(versionPart, "已打版本");
        if (versionPart)
        {
            var versionList = GetVersions(m_ExportAssetBundleDir + platform + "/Version");
            if (versionList != null && versionList.Count > 0)
            {
                GUILayoutOption[] options =
                {
                    GUILayout.Width(150),
                    GUILayout.Height(20),
                };

                EditorGUILayout.BeginVertical();
                EditorGUILayout.Space();

                foreach (var v in versionList)
                {
                    if (!m_VersionMap.ContainsKey(v.ToString()))
                    {
                        m_VersionMap.Add(v.ToString(), -1);
                    }

                    var selectIndex = m_VersionMap[v.ToString()];
                    selectIndex = GUILayout.SelectionGrid(selectIndex, new string[] { v.ToString() }, 1);
                    m_VersionMap[v.ToString()] = selectIndex;

                    if (selectIndex == 0)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.Space();

                        if (GUILayout.Button("浏览", options))
                        {
                            WindowsOSUtility.ExploreFile(m_ExportAssetBundleDir + platform + "/Version/" + v.ToString());
                        }

                        if (GUILayout.Button("检查ab包大小", options))
                        {
                            AssetBundleBuilder.CheckAssetBundleSize(m_ExportAssetBundleDir + platform + "/Version/" + v, ".pkg");
                        }

                        if (GUILayout.Button("取消查看", options))
                        {
                            m_VersionMap[v.ToString()] = -1;
                            Repaint();
                        }

                        if (GUILayout.Button("拷贝到StreamingAssets", options))
                        {
                            var targetPath = Application.dataPath + "/StreamingAssets/" + UGCoreConfig.MiddleFilePathName;
                            EditorFileUtility.ClearDirectory(targetPath);
                            EditorFileUtility.CopyDirectory(m_ExportAssetBundleDir + platform + "/Version/" + v.ToString(), targetPath);
                            AssetDatabase.Refresh();
                            WindowsOSUtility.ExploreFile(targetPath);
                        }

                        if (GUILayout.Button("拷贝到persistentDataPath", options))
                        {
                            var targetPath = Application.persistentDataPath + "/" + UGCoreConfig.MiddleFilePathName + "/" + UGCoreConfig.ResourcesFolderName;
                            EditorFileUtility.ClearDirectory(targetPath);
                            EditorFileUtility.CopyDirectory(m_ExportAssetBundleDir + platform + "/Version/" + v.ToString(), targetPath);
                            AssetDatabase.Refresh();
                            WindowsOSUtility.ExploreFile(targetPath);
                        }

                        if (GUILayout.Button("删除版本", options))
                        {
                            Directory.Delete(m_ExportAssetBundleDir + platform + "/Version/" + v.ToString(), true);
                            Repaint();
                        }
                        EditorGUILayout.Space();
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.Space();
                    }
                }

                EditorGUILayout.Space();
                EditorGUILayout.EndVertical();
            }
        }

        patchPart = EditorGUILayout.Foldout(patchPart, "已打补丁");
        if (patchPart)
        {
            var patchList = GetPatches(m_ExportAssetBundleDir + platform + "/Patches");
            if (patchList != null && patchList.Count > 0)
            {
                GUILayoutOption[] options =
                {
                    GUILayout.Width(150),
                    GUILayout.Height(20),
                };

                EditorGUILayout.BeginVertical();
                EditorGUILayout.Space();

                foreach (var p in patchList)
                {
                    if (!m_VersionMap.ContainsKey(p.ToString()))
                    {
                        m_VersionMap.Add(p.ToString(), -1);
                    }

                    var selectIndex = m_VersionMap[p.ToString()];
                    selectIndex = GUILayout.SelectionGrid(selectIndex, new string[] { p.ToString() }, 1);
                    m_VersionMap[p.ToString()] = selectIndex;

                    if (selectIndex == 0)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.Space();

                        if (GUILayout.Button("浏览", options))
                        {
                            WindowsOSUtility.ExploreFile(m_ExportAssetBundleDir + platform + "/Patches/" + p);
                        }

                        if (GUILayout.Button("取消查看", options))
                        {
                            m_VersionMap[p.ToString()] = -1;
                            Repaint();
                        }

                        if (GUILayout.Button("删除补丁", options))
                        {
                            Directory.Delete(m_ExportAssetBundleDir + platform + "/Patches/" + p, true);
                            Repaint();
                        }

                        EditorGUILayout.Space();
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.Space();
                    }
                }

                EditorGUILayout.Space();
                EditorGUILayout.EndVertical();
            }
        }

        GUIContent[] guiBuildObjs =
        {
            new GUIContent("打版本"),
            new GUIContent("打补丁"),
        };

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        m_BuildOperation = (BuildOperation)GUILayout.Toolbar((int)m_BuildOperation, guiBuildObjs);
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        if (m_BuildOperation == BuildOperation.Version)
        {
            m_CreateVersion = EditorGUILayout.TextField("打包版本号:", m_CreateVersion);

            GUILayoutOption[] options =
            {
                GUILayout.Width(150),
                GUILayout.Height(26),
            };
            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("重新打包版本(慎用)", options))
            {
                var versionNumber = ValidVersion(m_CreateVersion);
                if (versionNumber == null)
                {
                    GetWindow <AssetBundleBuildEditor>().ShowNotification(new GUIContent("版本名称不符合规范,请重新输入"));
                    return;
                }

                if (!Directory.Exists(m_ExportAssetBundleDir + platform + "/Version/" + versionNumber))
                {
                    GetWindow <AssetBundleBuildEditor>().ShowNotification(new GUIContent("版本号未经过打包,请使用打包版本选项来打包"));
                    return;
                }

                CreateVersion(m_ExportAssetBundleDir + platform + "/Version/" + versionNumber, true);
                WindowsOSUtility.ExploreFile(m_ExportAssetBundleDir + platform + "/Version/" + versionNumber);
            }
            if (GUILayout.Button("打包版本", options))
            {
                var versionNumber = ValidVersion(m_CreateVersion);
                if (versionNumber == null)
                {
                    GetWindow <AssetBundleBuildEditor>().ShowNotification(new GUIContent("版本名称不符合规范,请重新输入"));
                    return;
                }

                if (Directory.Exists(m_ExportAssetBundleDir + platform + "/Version/" + versionNumber))
                {
                    GetWindow <AssetBundleBuildEditor>().ShowNotification(new GUIContent("版本目录已经存在,请选择新的版本号或者清除现有的版本号目录"));
                    return;
                }

                var versionList = GetVersions(m_ExportAssetBundleDir + platform + "/Version");
                if (versionList != null && versionList.Count > 0)
                {
                    if (VersionNumber.CompareTo(versionList[versionList.Count - 1], versionNumber) > 0)
                    {
                        GetWindow <AssetBundleBuildEditor>().ShowNotification(new GUIContent("当前版本号低于最新的版本号,无法打包,请重新选择版本号"));
                        return;
                    }
                }

                CreateVersion(m_ExportAssetBundleDir + platform + "/Version/" + versionNumber);
                WindowsOSUtility.ExploreFile(m_ExportAssetBundleDir + platform + "/Version/" + versionNumber);
            }
            GUILayout.EndHorizontal();
        }
        else if (m_BuildOperation == BuildOperation.Patch)
        {
            var versionList = GetVersions(m_ExportAssetBundleDir + platform + "/Version");
            if (versionList != null && versionList.Count > 0)
            {
                List <string> versionStringList = new List <string>();
                foreach (var v in versionList)
                {
                    versionStringList.Add(v.ToString());
                }
                GUILayout.BeginHorizontal();
                EditorGUILayout.Space();

                GUILayout.BeginVertical();
                EditorGUILayout.LabelField("低版本");
                m_lowVersion = EditorGUILayout.Popup(m_lowVersion, versionStringList.ToArray());
                GUILayout.EndVertical();

                GUILayout.FlexibleSpace();

                GUILayout.BeginVertical();
                EditorGUILayout.LabelField("高版本");
                m_highVersion = EditorGUILayout.Popup(m_highVersion, versionStringList.ToArray());
                GUILayout.EndVertical();

                EditorGUILayout.Space();
                GUILayout.EndHorizontal();

                GUILayoutOption[] options =
                {
                    GUILayout.Width(150),
                    GUILayout.Height(26),
                };
                GUILayout.FlexibleSpace();
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();

                if (GUILayout.Button("打补丁", options))
                {
                    if (VersionNumber.CompareTo(versionList[m_lowVersion], versionList[m_highVersion]) >= 0)
                    {
                        GetWindow <AssetBundleBuildEditor>().ShowNotification(new GUIContent("低版本号不能大于等于高版本号"));
                        return;
                    }

                    var patchName = versionList[m_lowVersion] + "-" + versionList[m_highVersion];

                    var fileMd5LowVersion =
                        AssetBundleBuilder.GetFilesMD5(
                            m_ExportAssetBundleDir + platform + "/Version/" + versionList[m_lowVersion], ".pkg");

                    var fileMd5HighVersion =
                        AssetBundleBuilder.GetFilesMD5(
                            m_ExportAssetBundleDir + platform + "/Version/" + versionList[m_highVersion], ".pkg");

                    Dictionary <string, string> lowVersionAssets = new Dictionary <string, string>();
                    foreach (var v in fileMd5LowVersion)
                    {
                        var str = v.Key.Replace(Path.GetFullPath(m_ExportAssetBundleDir + platform + "/Version/" + versionList[m_lowVersion] + "/"), "");
                        lowVersionAssets.Add(str, v.Value);
                    }

                    Dictionary <string, string> highVersionAssets = new Dictionary <string, string>();
                    foreach (var v in fileMd5HighVersion)
                    {
                        var str = v.Key.Replace(Path.GetFullPath(m_ExportAssetBundleDir + platform + "/Version/" + versionList[m_highVersion] + "/"), "");
                        highVersionAssets.Add(str, v.Value);
                    }

                    Dictionary <string, string> resultAssets = new Dictionary <string, string>();
                    foreach (var v in highVersionAssets)
                    {
                        if (!lowVersionAssets.ContainsKey(v.Key))
                        {
                            resultAssets.Add(v.Key, v.Value);
                        }
                        else
                        {
                            if (lowVersionAssets[v.Key] != v.Value)
                            {
                                resultAssets.Add(v.Key, v.Value);
                            }
                        }
                    }

                    if (resultAssets.Count == 0)
                    {
                        GetWindow <AssetBundleBuildEditor>().ShowNotification(new GUIContent("两个版本之间没有差异,无需生成补丁"));
                        return;
                    }

                    EditorFileUtility.ClearDirectory(m_ExportAssetBundleDir + platform + "/Patches/" + patchName);

                    foreach (var v in resultAssets)
                    {
                        var sourceFileName = m_ExportAssetBundleDir + platform + "/Version/" +
                                             versionList[m_highVersion] + "/" + v.Key;
                        var targetFileName = m_ExportAssetBundleDir + platform + "/Patches/" + patchName + "/" + v.Key;
                        if (!Directory.Exists(Path.GetDirectoryName(targetFileName)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(targetFileName));
                        }

                        File.Copy(sourceFileName, targetFileName);
                    }

                    var targetPath = m_ExportAssetBundleDir + platform + "/Patches/" + patchName + "/";
                    AssetBundleBuilder.PackPatches(targetPath, patchName, targetPath, ".pkg");
                    WindowsOSUtility.ExploreFile(targetPath);
                }
                GUILayout.EndHorizontal();
            }
        }

        if (m_OldBuildOperation != m_BuildOperation)
        {
            m_lowVersion  = 0;
            m_highVersion = 0;
        }

        m_OldBuildOperation = m_BuildOperation;
    }
Ejemplo n.º 11
0
        /// <summary>
        /// Compile
        /// </summary>
        public IList <BuildOperation> CreateCompileOperations(
            SharedCompileArguments arguments)
        {
            var operations = new List <BuildOperation>();

            // Write the shared arguments to the response file
            var responseFile                  = arguments.ObjectDirectory + new Path("SharedCompileArguments.rsp");
            var sharedCommandArguments        = ArgumentBuilder.BuildSharedCompilerArguments(arguments);
            var writeSharedArgumentsOperation = SharedOperations.CreateWriteFileOperation(
                arguments.TargetRootDirectory,
                responseFile,
                CombineArguments(sharedCommandArguments));

            operations.Add(writeSharedArgumentsOperation);

            // Initialize a shared input set
            var sharedInputFiles = new List <Path>();

            sharedInputFiles.AddRange(arguments.IncludeModules);

            var absoluteResponseFile = arguments.TargetRootDirectory + responseFile;

            // Generate the resource build operation if present
            if (arguments.ResourceFile is not null)
            {
                var resourceFileArguments = arguments.ResourceFile;

                // Build up the input/output sets
                var inputFiles = sharedInputFiles.ToList();
                inputFiles.Add(resourceFileArguments.SourceFile);
                // TODO: The temp files require read access, need a way to tell build operation
                inputFiles.Add(arguments.TargetRootDirectory + new Path("fake_file"));
                var outputFiles = new List <Path>()
                {
                    arguments.TargetRootDirectory + resourceFileArguments.TargetFile,
                };

                // Build the unique arguments for this resource file
                var commandArguments = ArgumentBuilder.BuildResourceCompilerArguments(
                    arguments.TargetRootDirectory,
                    arguments);

                // Generate the operation
                var buildOperation = new BuildOperation(
                    resourceFileArguments.SourceFile.ToString(),
                    arguments.SourceRootDirectory,
                    _rcExecutable,
                    CombineArguments(commandArguments),
                    inputFiles,
                    outputFiles);
                operations.Add(buildOperation);
            }

            var internalModules = new List <Path>();

            foreach (var partitionUnitArguments in arguments.InterfacePartitionUnits)
            {
                // Build up the input/output sets
                var inputFiles = sharedInputFiles.ToList();
                inputFiles.Add(partitionUnitArguments.SourceFile);
                inputFiles.Add(absoluteResponseFile);
                inputFiles.AddRange(partitionUnitArguments.IncludeModules);

                var outputFiles = new List <Path>()
                {
                    arguments.TargetRootDirectory + partitionUnitArguments.TargetFile,
                    arguments.TargetRootDirectory + partitionUnitArguments.ModuleInterfaceTarget,
                };

                // Build the unique arguments for this translation unit
                var commandArguments = ArgumentBuilder.BuildPartitionUnitCompilerArguments(
                    arguments.TargetRootDirectory,
                    partitionUnitArguments,
                    absoluteResponseFile);

                // Generate the operation
                var buildOperation = new BuildOperation(
                    partitionUnitArguments.SourceFile.ToString(),
                    arguments.SourceRootDirectory,
                    _compilerExecutable,
                    CombineArguments(commandArguments),
                    inputFiles.ToArray(),
                    outputFiles);
                operations.Add(buildOperation);

                // Add our module interface back in for the downstream compilers
                internalModules.Add(arguments.TargetRootDirectory + partitionUnitArguments.ModuleInterfaceTarget);
            }

            // Generate the interface build operation if present
            if (arguments.InterfaceUnit is not null)
            {
                var interfaceUnitArguments = arguments.InterfaceUnit;

                // Build up the input/output sets
                var inputFiles = sharedInputFiles.ToList();
                inputFiles.Add(interfaceUnitArguments.SourceFile);
                inputFiles.Add(absoluteResponseFile);
                inputFiles.AddRange(interfaceUnitArguments.IncludeModules);

                var outputFiles = new List <Path>()
                {
                    arguments.TargetRootDirectory + interfaceUnitArguments.TargetFile,
                    arguments.TargetRootDirectory + interfaceUnitArguments.ModuleInterfaceTarget,
                };

                // Build the unique arguments for this translation unit
                var commandArguments = ArgumentBuilder.BuildInterfaceUnitCompilerArguments(
                    arguments.TargetRootDirectory,
                    interfaceUnitArguments,
                    absoluteResponseFile);

                // Generate the operation
                var buildOperation = new BuildOperation(
                    interfaceUnitArguments.SourceFile.ToString(),
                    arguments.SourceRootDirectory,
                    _compilerExecutable,
                    CombineArguments(commandArguments),
                    inputFiles,
                    outputFiles);
                operations.Add(buildOperation);

                // Add our module interface back in for the downstream compilers
                internalModules.Add(arguments.TargetRootDirectory + interfaceUnitArguments.ModuleInterfaceTarget);
            }

            foreach (var implementationUnitArguments in arguments.ImplementationUnits)
            {
                // Build up the input/output sets
                var inputFiles = sharedInputFiles.ToList();
                inputFiles.Add(implementationUnitArguments.SourceFile);
                inputFiles.Add(absoluteResponseFile);
                inputFiles.AddRange(implementationUnitArguments.IncludeModules);
                inputFiles.AddRange(internalModules);

                var outputFiles = new List <Path>()
                {
                    arguments.TargetRootDirectory + implementationUnitArguments.TargetFile,
                };

                // Build the unique arguments for this translation unit
                var commandArguments = ArgumentBuilder.BuildTranslationUnitCompilerArguments(
                    arguments.TargetRootDirectory,
                    implementationUnitArguments,
                    absoluteResponseFile,
                    internalModules);

                // Generate the operation
                var buildOperation = new BuildOperation(
                    implementationUnitArguments.SourceFile.ToString(),
                    arguments.SourceRootDirectory,
                    _compilerExecutable,
                    CombineArguments(commandArguments),
                    inputFiles.ToArray(),
                    outputFiles);
                operations.Add(buildOperation);
            }

            return(operations);
        }
Ejemplo n.º 12
0
		/// <summary>
		/// Starts the specified build operation on the project for the currently selected project configuration.
		/// </summary>
		/// <param name="operation">The operation to perform.</param>
		public void StartBuild(BuildOperation operation)
		{
			Tracer.VerifyEnumArgument((int)operation, "operation", typeof(BuildOperation));

			// We have to verify that the environment is not busy right now
			if (Package.Instance.Context.IsSolutionBuilding)
			{
				Tracer.WriteLineVerbose(classType, "StartBuild", "The build manager is busy right now.");
				return;
			}

			// Get the build manager from VS
			IVsSolutionBuildManager solutionBuildMgr = this.ServiceProvider.GetServiceOrThrow(typeof(SVsSolutionBuildManager), typeof(IVsSolutionBuildManager), classType, "StartBuild") as IVsSolutionBuildManager;

			// Convert the enum to one of the VS flags
			VSSOLNBUILDUPDATEFLAGS flags = VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_NONE;

			switch (operation)
			{
				case BuildOperation.Clean:
					flags |= VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_CLEAN;
					break;

				case BuildOperation.Build:
					flags |= VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_BUILD;
					break;

				case BuildOperation.Rebuild:
					flags |= VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_CLEAN | VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_BUILD;
					break;

				default:
					Tracer.Fail("Unknown BuildOperation '{0}'", operation.ToString());
					return;
			}


			NativeMethods.ThrowOnFailure(solutionBuildMgr.StartSimpleUpdateProjectConfiguration((IVsHierarchy)this, null, null, (uint)flags, 0, 0));
		}