generate a cpp exe using json in vscode - c++

I use this json file to generate a cpp exe in vs code, but it is unpleasant...After compiling a source file named 001.cpp, it generated a cpp exe named 001.cpp.exe. What should I do to generate a cpp exe named 001.exe?
Here is the JSON:
{
"version": "0.1.0",
"command": "g++",
"args": ["-g","${file}","-o","${file}.exe"],
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}

Related

AWS CodePipeline "The deployment failed because the AppSpec file that specifies the deployment configuration is missing ...."

I'm trying to set up a deployment pipeline using CodeCommit, ECR and ECS. My pipeline passes the source and builds the image right, except for deployment phase, where it fails:
The deployment failed because the AppSpec file that specifies the deployment configuration is missing or has an invalid configuration. The input AppSpec file is a not well-formed yaml. The template cannot be parsed.
appspec.yaml is in the output of my build phase (stored inside a zip file in S3)
The following is my code pipeline:
{
"pipeline": {
"name": "dashboardpipeline",
"roleArn": "arn:aws:iam::410208438878:role/service-role/AWSCodePipelineServiceRole-us-east-2-DashBoardPipeline",
"artifactStore": {
"type": "S3",
"location": "codepipeline-us-east-2-276644567431"
},
"stages": [
{
"name": "Source",
"actions": [
{
"name": "Source",
"actionTypeId": {
"category": "Source",
"owner": "AWS",
"provider": "CodeCommit",
"version": "1"
},
"runOrder": 2,
"configuration": {
"BranchName": "master",
"OutputArtifactFormat": "CODE_ZIP",
"PollForSourceChanges": "false",
"RepositoryName": "provisions_dashboard"
},
"outputArtifacts": [
{
"name": "SourceArtifact"
}
],
"inputArtifacts": [],
"region": "us-east-2",
"namespace": "SourceVariables"
},
{
"name": "Image",
"actionTypeId": {
"category": "Source",
"owner": "AWS",
"provider": "ECR",
"version": "1"
},
"runOrder": 2,
"configuration": {
"ImageTag": "latest",
"RepositoryName": "dashboard-web-app"
},
"outputArtifacts": [
{
"name": "MyImage"
}
],
"inputArtifacts": [],
"region": "us-east-2"
}
]
},
{
"name": "Build",
"actions": [
{
"name": "Build",
"actionTypeId": {
"category": "Build",
"owner": "AWS",
"provider": "CodeBuild",
"version": "1"
},
"runOrder": 1,
"configuration": {
"ProjectName": "DashboardApplicationBuild"
},
"outputArtifacts": [
{
"name": "BuildArtifact"
}
],
"inputArtifacts": [
{
"name": "SourceArtifact"
}
],
"region": "us-east-2",
"namespace": "BuildVariables"
}
]
},
{
"name": "Deploy",
"actions": [
{
"name": "Deploy",
"actionTypeId": {
"category": "Deploy",
"owner": "AWS",
"provider": "CodeDeployToECS",
"version": "1"
},
"runOrder": 1,
"configuration": {
"AppSpecTemplateArtifact": "BuildArtifact",
"AppSpecTemplatePath": "appspec.yaml",
"ApplicationName": "dashboarddeploymentapp",
"DeploymentGroupName": "dashboardappdeploygr",
"Image1ArtifactName": "MyImage",
"Image1ContainerName": "IMAGE_URI",
"TaskDefinitionTemplateArtifact": "BuildArtifact",
"TaskDefinitionTemplatePath": "taskdef.json"
},
"outputArtifacts": [],
"inputArtifacts": [
{
"name": "BuildArtifact"
},
{
"name": "MyImage"
}
],
"region": "us-east-2"
}
]
}
],
"version": 18
},
"metadata": {
"pipelineArn": "arn:aws:codepipeline:us-east-2:410208438878:dashboardpipeline",
"created": "2022-03-14T11:52:19.525000-03:00",
"updated": "2022-03-18T11:34:14.217000-03:00"
}
}

VSCode Extension: problem matching on compiler output with blank line

Im currently writing a vscode extension for a language used with Campbell Scientific dataloggers. Part of the extension I have made specifies a custom problem matcher for the compiler results.
The issue I am having is when I send the crbasic program (test.cr300) to the compiler using a task in tasks.json, I am unable to match the file name from the top of the compiler results.
Edit: This is due to the blank line in between the filename and the error messages. I currently am unable to find a way around this. Adding \n to the pattern doesn't work as expected even though it works on https://regex101.com/.
Example of returned text from the compiler:
test.cr300 -- Compile Failed!
line 12: Undeclared variable U1.
line 18: gmx600 not yet declared so cannot be aliased.
line 19: gmx600 not yet declared so cannot be aliased.
line 20: gmx600 not yet declared so cannot be aliased.
line 21: gmx600 not yet declared so cannot be aliased.
Pattern as specified in my package.json:
"pattern": [
{
"regexp": "^(.*\\.cr300).*\\n$",
"file": 1
},
{
"regexp": "^line\\s(\\d+):\\s(.+)$",
"line": 1,
"message": 2,
"loop": true
}
]
and here is my task from tasks.json when running the extension in debug.
{
"label": "CRBasic: Compiler",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"options": {
"shell": {
"executable": "powershell.exe"
}
},
"command": "${config:CRBasic.Path.Compiler path}\\cr300comp.exe",
"args": [
"${file}"
],
"problemMatcher": [
"$crbasicCompiler"
]
}
You need to change the order of the regexes and add a loop attribute and change the group number for line and message
"pattern": [
{
"regexp": "^(.*\\.cr300) -- Compile Failed.*$",
"file": 1
},
{ "regexp": "^\\s*$" },
{
"regexp": "^line\\s(\\d+):\\s(.+)$",
"line": 1,
"message": 2,
"loop": true
}
]
After narrowing down the issue to a blank line, the below pattern now problem matches the compile output. In hindsight it seems obvious. Thanks to #rioV8 for the help.
"pattern": [
{
"regexp": "^(.*\\.cr300) -- Compile Failed.*$",
"file": 1
},
{
"regexp": "^.*$"
},
{
"regexp": "^line\\s(\\d+):\\s(.+)$",
"line": 1,
"message": 2,
"loop": true
}
]

How can I make a target 'makefile' in visual studio code?

I'm trying to figure out how to compile my c++ code within the vs code environment.
I'm able to compile using g++ but I haven't been able to figure it out in vs code yet.
I used the answer from BeeOnRope from this question to set up my build command and the associated hotkey.
How do I set up Visual Studio Code to compile C++ code?
The error that comes out is this
make: *** No rule to make target `Makefile'. Stop.
The terminal process terminated with exit code: 2
Edit: After working on my tasks.json it looks like this, however I'm still getting the same error shown above.
{
"version": "2.0.0",
"command": "make",
"tasks":[
{
"label": "Makefile",
"group": "build",
// Show the output window only if unrecognized errors occur.
"presentation": {"reveal": "always"},
// Pass 'all' as the build target
"args": ["all"],
// Use the standard less compilation problem matcher.
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
In your tasks.json, add/edit the "command" and "args" fields to have the build command line you would run manually. That could be g++, make, or whatever. See here:
https://code.visualstudio.com/docs/editor/tasks
Update:
Looking at the tasks.json file that you posted, your command needs to go inside a task. Something like this:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "My Build",
"group": "build",
"type": "shell",
"command": "g++",
"args": [
"-o", "LexParse", "Lexxy.cpp", "Parzival.cpp"
]
}
]
}
PS, One way to format your code here is to indent it all:
int main
{
[]( auto world ) { return "Hello"s + world; } ( ", World!" );
}
Another way is to wrap it in three backticks (no need to indent, though I do here so I can have backticks within backticks):
```
int main
{
[]( auto world ) { return "Hello"s + world; } ( ", World!" );
}
```

Visual Studio Code task regex not capturing build error output

I am having some problems with my Regex for parsing build output from rustc.
The output looks like
Compiling svd2rust v0.2.1 (file:///C:/trust/svd2rust)
error: expected one of `=>`, `#`, `if`, or `|`, found `Some`
--> src\main.rs:56:9
|
56 | Some("all") =>
| ^^^^
error: aborting due to previous error
error: Could not compile `svd2rust`.
To learn more, run the command again with --verbose.
My task at the moment looks like:
{
"version": "0.1.0",
"command": "cargo",
"isShellCommand": true,
"args": ["build"],
"problemMatcher": {
"owner": "build",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "(error):(.*)\\s+-->\\s+(.*):(\\d+):(\\d+)",
"file": 3,
"line": 4,
"column": 5,
"severity": 1,
"message": 2
}
}
}
According to regex101, it looks like the regex should match the appropriate sections.
According to the VS Code documentation, you need a multiline problem matcher. This might work; I did not test it:
{
"version": "0.1.0",
"command": "cargo",
"isShellCommand": true,
"args": ["build"],
"problemMatcher": {
"owner": "build",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": [{
"regexp": "(error):(.*)",
"severity": 1,
"message": 2
},{
"regexp": "-->\\s+([^:]*):(\\d+):(\\d+)",
"file": 1,
"line": 2,
"column": 3
}]
}
}
Correct regexp for Rust v1.20.0:
"pattern": [{
"regexp": "(error(?:\\[E\\d{4}\\])?|warning):\\s(.*)",
"severity": 1,
"message": 2
},{
"regexp": "-->\\s+([^:]*):(\\d+):(\\d+)",
"file": 1,
"line": 2,
"column": 3
}]

Why doesn't this problemMatcher in VS code work?

Why doesnt my problemMatcher work? I'm pretty sure about the regex, but it doesn't report any problems, even there are some on stdout...
// the matcher
"problemMatcher": {
"owner": "typescript",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^TypeScript (warning|error): (.*)\\((\\d+),(\\d+)\\): (.*)$",
"severity": 1,
"file": 2,
"line": 3,
"column": 4,
"message": 5
}
}
//the browserify/tsify pipeline
browserify().add('main.ts')
.plugin(tsify, { noImplicitAny: false, removeComments:true })
.transform("babelify",{ extensions: ['.ts'], presets: ["es2015"]})
.bundle()
.on('error', function (error) { console.log(error.toString()); })
.pipe(source('bundle.js'))
.pipe(gulp.dest('www/js/dist/'));
//gulp sample output
[00:39:00] Starting 'ts-compile'...
TypeScript error: main.ts(118,30): Error TS2339: Property 'object' does not exist on type 'boolean'.
TypeScript error: main.ts(137,24): Error TS2339: Property 'object' does not exist on type 'boolean'.
TypeScript error: main.ts(507,44): Error TS2304: Cannot find name 'loading'.
[00:39:03] Finished 'ts-compile' after 2.98 s
I resolved the problem by putting tasks.json into .vscode folder. I initially thought tasks.json would be found like tsconfig.json (project-root), but it turned out to be wrong.