how to configure files paths in VSCode task errors - delphi

I configured a task in VSCode to compile a Delphi 2005 dpk. It is working and returning the errors on the "problems view", but it is not showing that errors in the file.
I think it is happening because when I click on an error, I get the error message:
Unable to open 'sr075pro.pas': File not found
(...projectfolder\sr075pro.pas)
But the file is in ...projectfolder\webservices\sr075pro.pas.
I can't find a way to tell to the task that the file is in a subfolder. I tried to use the "relative" option on the "fileLocation" tag without sucess.
The error returned:
Compiling sa_webservices...
Borland Delphi Version 13.0 Copyright (c) 1983,99 Inprise Corporation
sr075pro.pas(99) Error: Undeclared identifier: 'ni'
sa_webservices.dpk(802) Fatal: Could not compile used unit 'sr075pro.pas'
My task configuration:
{
"version": "0.1.0",
"name": "Compilar",
"command": "C:\\Compilers\\compile.bat",
"suppressTaskName": true,
"isShellCommand": true,
"isBuildCommand": true,
"tasks": [
{
"taskName": "Compile sa_webservices",
"isBuildCommand": false,
"isTestCommand": false,
"showOutput": "always",
"args": [
"sa_webservices"
],
"problemMatcher": {
"owner": "external",
"fileLocation": "relative",
"pattern": {
"regexp": "^([\\w]+\\.(pas|dpr|dpk))\\((\\d+)\\)\\s(Fatal|Error|Warning|Hint):(.*)",
"file": 1,
"line": 3,
"message": 5
}
}
}
My compile.bat:
#echo off
#P:
#set arg1=%1
shift
...
if "%arg1%" == "sa_webservices" set arg2="webservices"
...
echo Compiling %arg1%...
cd\%arg2%
dcc32.exe -H -W -Q %arg1%.dpk

Your task configuration is wrong. First of all you don't close all brackets but I guess it's a mistake made by copying and pasting it here on StackOverflow. Otherwise the task configuration wouldn't have worked at all.
Now to the real problem:
DCC32 produces hints and warnings containing relative file paths. These paths are relative to the project file. In your task configuration you define the compiler's output to contain relative paths by setting
"fileLocation": "relative"
Visual Studio Code doesn't know how to build the correct absolute path from the relative paths given by the compiler message. So it guesses your current ${workspaceRoot} (in your case it's projectfolder) would be the absolute path.
This explains why you see errors and warnings which contain wrong file paths. In order to get the correct paths you'll need to tell VSCode the correct path to combine the relative paths with.
You do this by simply adding the correct path to the fileLocation entry in you tasks.json:
"fileLocation": ["relative", "${workspaceRoot}\\webservices"]
The entire tasks.json looks like that:
{
"version": "0.1.0",
"name": "Compilar",
"command": "C:\\Compilers\\compile.bat",
"suppressTaskName": true,
"isShellCommand": true,
"isBuildCommand": true,
"tasks": [
{
"taskName": "Compile sa_webservices",
"isBuildCommand": false,
"isTestCommand": false,
"showOutput": "always",
"args": [
"sa_webservices"
],
"problemMatcher": {
"owner": "external",
"fileLocation": ["relative", "${workspaceRoot}\\webservices"],
"pattern": {
"regexp": "^([\\w]+\\.(pas|dpr|dpk))\\((\\d+)\\)\\s(Fatal|Error|Warning|Hint):(.*)",
"file": 1,
"line": 3,
"message": 5
}
}
}
]
}

It might be easier to find files in the problemMatcher in vscode 1.74, see file location search: v1.74 release notes. There is a new option search for the fileLocation property:
New file location method; search
Previously, problem matchers needed to know exactly where to look for
the problematic files, via the fileLocation property. The supported
methods were absolute, relative, or autoDetect (i.e., check for
relative paths first and opt to absolute paths in case of failure).
However, in workspaces that need to invoke various scripts residing in
nested sub-directories, the developers could have a hard time setting
up their tasks; since such scripts seldom report file paths in a
unified manner (e.g., relative to the workspace's base directory).
To help alleviate the problem, a new file location method, named
search, is introduced in this version. With this method, a deep file
system search will be initiated to locate any captured path. See the
example below on how to setup the search file location method
(although, all parameters are optional):
// ...
"fileLocation": [
"search",
{
"include": [ // Optional; defaults to ["${workspaceFolder}"]
"${workspaceFolder}/src",
"${workspaceFolder}/extensions"
],
"exclude": [ // Optional
"${workspaceFolder}/extensions/node_modules"
]
}
],
// ... } ```
⚠️ Of course, users should be wary of the possibly **heavy file system
searches** (e.g., looking inside `node_modules` directories) and set
the `exclude` property with discretion.

Related

How to build electron application with assets folder by Electron-builder

I have built an application with electron-builder. There was a video in media folder in the development area. But when I built the application I figure out the video folder replaced with asar file in a resource folder in C://Programs.
I want videos to have in media folder in production. How can I do that
You may want to try with asar: false in your package.json file. But, this is not the recommended way to do it.
The best you can do is to add the resources you want to keep outside the asar file with the extraResources directive:
"build": {
"extraResources": [
{
"from": "../media",
"to": "media",
"filter": [
"**/*",
"!*.mp3",
]
}
],
"asar": false,
}
The accepted answer did not work for me... What did work was to specify the directory whose contents I wanted to access post-build in the same format as specified for the files configuration.
electron-builder.json:
{
...
"extraResources": [
"src/assets/my-assets/*"
],
...
}
After the build, you will find your folder at the same location as the asar file (.../app/resources/src/assets/my-assets), under resources. There's no need to specify asar: false.
On the main process, if you use __dirname, it will end with app.asar. The assets can be accessed using:
// Removing 8 characters to remove "app.asar"
let strippedPath = __dirname.substring(0, __dirname.length - 8);
let execPath = '\"' + strippedPath + 'src\\assets\\my-assets' + '\"';
Now execPath can be appended to with whatever needs to be executed from the assets folder.

How Do I Bundle Artifacts in JFrog Artifactory Using Filespecs?

Trying to figure out how to get the "X.Y.Z" substituted below when not every file will have that in the name. Simple filespec:
{
"files": [
{
"pattern": "artifacts/",
"target": "repository/project/X.Y.Z/"
}
]
}
Not all of the files have the full version number in them so I can't use a simple placeholder (per this solution). I was wondering if there was some other way to dynamically figure out the part to replace the "X.Y.Z" using some maybe-more-complex syntax?
Thinking about the problem a bit more it occurred to me that I could put the artifacts in a specially-named directory that I could then use to publish from.
{
"files": [
{
"pattern": "artifacts-(*)/",
"target": "repository/project/{1}/"
}
]
}
Tested, and that seemed to do the trick. It just required a little scripting at the end of the build to name that directory with the version number in it.

Why TFS Build Step Extension Icon Is Missing?

I created a new extension for TFS following MS tutorial. For some reason when I'm adding Icon to my extension I can see this icon when I'm installing the extension and in the "Extension Manager" page,
But when I choose my extension from the build step menu the image is missing.
In the "vss-extension.json" file I added:
"icons": {
"default": "images/icon.png"
},
"files": [
{
"path": "images",
"addressable": true
},
{
"path": "dist",
"addressable": true,
"packagePath": "scripts"
},
{
"path": "infoTab.html",
"addressable": true
},
{
"path": "node_modules/vss-web-extension-sdk/lib",
"addressable": true,
"packagePath": "lib"
},
{
"path": "buildtask"
}
],
The image file is 32x32
Should this image be reference in the "task.json" file as well?
The accepted answer is not correct for Microsoft Visual Studio Team Foundation Server version 15.105.25910.0. Perhaps it was correct for previous versions.
The image file must be named icon.png.
The image file must be in the same folder as task.json.
The image file should be 32 x 32; no image scaling is applied.
The task.json file does not contain any reference to this file. It is located by using these conventions.
The task itself has its own icon and it must be stored in the same directory as the task.json and must be called icon.png and be 32x32 pixels and optionally an additional icon.svg can be put alongside it. This has to do with the fact that one extension can contain multiple build tasks, each build task then has its own icon. It's not referenced from the task.json, the correct file name will cause it to be picked up.
For an example, check my Azure Pipelines Snyk task. Also, if this is your complete extension manifest, then it's missing the Build task contribution point:
"contributions": [
{
"id": "buildtask",
"type": "ms.vss-distributed-task.task",
"targets": [
"ms.vss-distributed-task.tasks"
],
"properties": {
"name": "buildtask"
}
}

How to avoid the eslint-plugin-import "unresolved path to module 'electron'" error

Ok, so this is documented plain as day, yet I'm probably doing something stupid and can't get it to work...
I'm using the eslint-plugin-import on an Electron app and I'm getting a lint error of Unable to resolve path to module 'electron'.
In the docs, it says I need to either A.) use the shared Electron config B.) pass in an array with electron in to the "import/core-modules" setting.
for A, I tried this:
{
"extends": [
"airbnb",
"plugin:import/electron"
]
}
and when I lint, I get this:
for B, I tried:
{
"extends": [
"airbnb"
],
"plugins": [
"import"
],
"rules": {
"import/core-modules": [
"electron"
]
}
}
and get this:
I've also tried:
{
"extends": [
"airbnb"
],
"plugins": [
"import"
],
"settings": {
"import/core-modules": [
"electron"
]
}
}
and I just get the "unresolved path to module' error.
It's probably something really silly, but what am I doing wrong? Ideally I'd just like to use the shared config.
Ok, after posting this issue on the Github repo, turns out that the Electron related changes have not been released to npm yet. They will be in the next release, but as of now, they are only in master.
https://github.com/benmosher/eslint-plugin-import/issues/393#issuecomment-227821876

Zend Framework 2 Autoload Third Party library using composer

I am trying to use composer to autoload a third party library into my ZF2 application - specifically Google api.
I followed the answer in this post on SO, edited my composer.json
"autoload": {
"psr-0": {"Googleanalytics\\": "vendor/google-api-php-client/src/"}
}
and ran update.
I can see the entry in composer/autoload_namespaces.php
'Googleanalytics\\' => array($vendorDir . '/google-api-php-client/src'),
but i still get a fatal error class not found when trying to instantiate a class in that directory (Google_Client.php).
Any ideas what i am missing?
I am including the file in the class i am trying to use it:
use Googleanalytics\Google_Client;
I have tried renaming the directory in case the - was the problem and also creating a simple test.php file in that dir in case the underscore in the class name (Google_Client.php) was the problem, but still the same error.
Is there anything else i need to add to my ZF2 application to autoload this library?
Also note i decided not to use ZendGdata as this component does not seem to be maintained anymore.
Thanks in advance
The autoload definition of your software should not include the autoload definition of any vendor module. Move that to the package definition you use to include the software.
And in other news: If it does not work with PSR-0, the classmap autoloader should take care of it.
Update
How to create the package for a repository not offering a composer.json
Essentially you'd need only a couple of pieces of information:
The version number and where it's located in that repository.
A name of the software you are trying to use - you'd probably only want to add a vendor name and not be too creative with the module.
Know how to autoload the package, i.e. know which path is used for the software and apply the classmap autoloader to it.
At least one of the following, preferredly both:
The URL of the repository that hosts the code
The URL of a download of a published version
In case of the "google-api-php-client", the a) URL of the repository is http://google-api-php-client.googlecode.com/svn/, the b) most current version number is 0.6.7, the A) download URL of that package is http://google-api-php-client.googlecode.com/files/google-api-php-client-0.6.7.tar.gz.
And now you fill it into this "template":
"repositories": [
{
"type": "package",
"package": {
"name": "name from (2)",
"version": "version from (1)",
"dist": {
"url": "URL from (4/2)",
"type": "tar or zip according to download"
},
"source": {
"url": "URL from (4/1)",
"type": "svn",
"reference": "tags/version from (1)"
},
"autoload": {
"classmap": ["path from (3)"]
}
}
}
]
And then you can require that exact package in your requirements: "require": { "name from (2)": "version from (1)" }
For the google package you are using this would essentially get you to use this:
"require": {
"google/google-api-php-client":"*"
},
"repositories": [
{
"type": "package",
"package": {
"name": "google/google-api-php-client",
"version": "0.6.7",
"dist": {
"url": "http://google-api-php-client.googlecode.com/files/google-api-php-client-0.6.7.tar.gz",
"type": "tar"
},
"source": {
"url": "http://google-api-php-client.googlecode.com/svn/",
"type": "svn",
"reference": "tags/0.6.7"
},
"autoload": {
"classmap": ["src/"]
}
}
}
]
The benefit of adding this mostly boilerplate stuff is that you get the downloading of the software for free now. You don't have to care about how to manually download, unpack and install the package. You did add the autoloading information for this software to your own composer.json, but it is contained in the package definition of the software you want to use, it is not contained in the autoloading area of your own software.
You also do not have to worry about Composer removing your manually downloaded package accidentally.
For anyone else looking to add a third party library to ZF2 using composer, here are the steps that worked for me.
Copy third party library to vendor folder
Add following line to composer.json
"autoload": {
"classmap": ["vendor/PATH TO LIBRARY"]
}
Run php composer.phar update
Then you should see all the classes that were in the 3rd party library in the file in the composer folder: composer/autoload_classmap.php
When instantiating any class from the library in your zf2 application, dont forget to prefix the class name with a \.
For example:
$client = new \Google_Client();

Resources