Skip to content

Commit

Permalink
Fea, Compile时传入完整路径,方便报错时查看代码路径
Browse files Browse the repository at this point in the history
  • Loading branch information
mingkuang-Chuyu committed Apr 29, 2023
1 parent 1faf69d commit b17ad7c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Microsoft.Build.CPPTasks/ToolSwitch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public class ToolSwitch

private ITaskItem[] taskItemArray;

#if __REMOVE
#else
// GCC工具链没有完整路径选择,为了方便出错时查看代码路径,所以添加了完整路径输出能力。
public bool TaskItemFullPath = false;
#endif
private string value = string.Empty;

private string switchValue = string.Empty;
Expand Down
36 changes: 32 additions & 4 deletions Microsoft.Build.CPPTasks/VCToolTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -915,18 +915,37 @@ private static void EmitTaskItemArraySwitch(CommandLineBuilder builder, ToolSwit
ITaskItem[] taskItemArray = toolSwitch.TaskItemArray;
foreach (ITaskItem taskItem in taskItemArray)
{
#if __REMOVE
builder.AppendSwitchIfNotNull(toolSwitch.SwitchValue, Environment.ExpandEnvironmentVariables(taskItem.ItemSpec));
#else
var ExpandItemSpec =Environment.ExpandEnvironmentVariables(toolSwitch.TaskItem.ItemSpec);
if(toolSwitch.TaskItemFullPath)
{
ExpandItemSpec = FileUtilities.NormalizePath(ExpandItemSpec);
}

builder.AppendSwitchIfNotNull(toolSwitch.SwitchValue, ExpandItemSpec);
#endif
}
return;
}
ITaskItem[] array = new ITaskItem[toolSwitch.TaskItemArray.Length];
for (int j = 0; j < toolSwitch.TaskItemArray.Length; j++)
{
#if __REMOVE
array[j] = new TaskItem(Environment.ExpandEnvironmentVariables(toolSwitch.TaskItemArray[j].ItemSpec));
//if (format == CommandLineFormat.ForTracking)
//{
// array[j].ItemSpec = array[j].ItemSpec.ToUpperInvariant();
//}
if (format == CommandLineFormat.ForTracking)
{
array[j].ItemSpec = array[j].ItemSpec.ToUpperInvariant();
}
#else
var ExpandItemSpec = Environment.ExpandEnvironmentVariables(toolSwitch.TaskItemArray[j].ItemSpec);
if (toolSwitch.TaskItemFullPath)
{
ExpandItemSpec = FileUtilities.NormalizePath(ExpandItemSpec);
}
array[j] = new TaskItem(ExpandItemSpec);
#endif
}
builder.AppendSwitchIfNotNull(toolSwitch.SwitchValue, array, toolSwitch.Separator);
}
Expand All @@ -935,7 +954,16 @@ private static void EmitTaskItemSwitch(CommandLineBuilder builder, ToolSwitch to
{
if (!string.IsNullOrEmpty(toolSwitch.TaskItem.ItemSpec))
{
#if __REMOVE
builder.AppendFileNameIfNotNull(Environment.ExpandEnvironmentVariables(toolSwitch.TaskItem.ItemSpec + toolSwitch.Separator));
#else
var ExpandItemSpec = Environment.ExpandEnvironmentVariables(toolSwitch.TaskItem.ItemSpec);
if(toolSwitch.TaskItemFullPath)
{
ExpandItemSpec = FileUtilities.NormalizePath(ExpandItemSpec);
}
builder.AppendFileNameIfNotNull(ExpandItemSpec + toolSwitch.Separator);
#endif
}
}

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

> 举个例子:代码完全优化(Full选项),微软编译器时中映射为 `-Ox`,而使用GCC时则映射为`-O3`
未来开发计划
* [ ] 解决增量编译不生效问题
目前开发计划
* [x] [Fea 5](https://github.com/Chuyu-Team/MSBuildCppCrossToolset/issues/5), 添加最小化生成支持
* [ ] 优化并行生成效率。
* [ ] 单元测试。

Expand Down
1 change: 1 addition & 0 deletions YY.Build.Linux.Tasks/GCC/Compile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public ITaskItem[] Sources
toolSwitch.Required = true;
toolSwitch.ArgumentRelationList = new ArrayList();
toolSwitch.TaskItemArray = value;
toolSwitch.TaskItemFullPath = true;
base.ActiveToolSwitches.Add("Sources", toolSwitch);
AddActiveSwitchToolValue(toolSwitch);
}
Expand Down

0 comments on commit b17ad7c

Please sign in to comment.