Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.mod files for linting out of src directory #159

Closed
newmrdenis opened this issue Feb 20, 2020 · 13 comments
Closed

.mod files for linting out of src directory #159

newmrdenis opened this issue Feb 20, 2020 · 13 comments
Labels

Comments

@newmrdenis
Copy link

Hello there. First of all thank you a lot for creating and maintaining this great extension!

My question is pretty simple: is there any way to create .mod files needed for linting in user-specific directory? Because my project has the corresponding structure:
project
-src
-obj
makefile
And I really want to have the setting specifying the obj dir as storing .mods files. Something like adding -J obj seems not to work.

Thank you for reply in advance.

@pedro-ricardo
Copy link
Collaborator

pedro-ricardo commented Feb 27, 2020

Hello there,
Isn't this done with the setting fortran.includePaths ?
Or you want something like #132 ?

Also other flags to the compile command can be set in fortran.linterExtraArgs

@pedro-ricardo
Copy link
Collaborator

I've tested the include and -J and it works as expected, but the path needs to be absolute

@pedro-ricardo
Copy link
Collaborator

@newmrdenis Need any help with this? It worked?

@pedro-ricardo
Copy link
Collaborator

This will be closed due to be a duplicate of the improvements proposed in #86

@newmrdenis
Copy link
Author

Oh, thanks for your reply. I was busy so couldn't answer instantly, sorry.
"Or you want something like #132 ?" No, I don't. As you can see, my work dir structure is pretty simple)

The include works as expected for me, but is it really? You have to paste only absolute path? This really bad. Because I use it for my external libraries and there I specified only an absolute path I've never noticed it .

As for -J option it seems no longer to create .mods file in dir I specified. Or maybe I've done something wrong?

Here I'll try to clarify my request: is there any way to create temporary .mods files, used for checking interfaces of funcs and others, create in the out of dir where the sources of these modules are storing?

@pedro-ricardo
Copy link
Collaborator

My bad,
I'll make a step-by-step tutorial below to help narrow down the problem your're getting.

@pedro-ricardo
Copy link
Collaborator

Intro

Firstly our extension has two major drawbacks (that we are aware of) when it comes to the linter usage:

  • All folders must be specified as absolute paths
  • Sub-folders aren't supported, you need to specify separately every folder

I'm gathering these To-Do developments in #86.

Tutorial

Folder structure

This tutorial runs in the following code structure:

.
├── bin
│   └── Makefile
├── LICENSE
├── README.md
└── src
    ├── linked_list.f08
    └── test_link.f08

Where linked_list.f08 is the module file and test_link.f08 the program

Let's compile the code now. Our linter helps you see errors end warnings but doesn't know compilation order, linking and stuff like that. After running make in the bin folder the structure looks like this:

.
├── bin
│   ├── a.out
│   ├── linked_list.mod
│   ├── linked_list.o
│   ├── Makefile
│   └── test_link.o
├── LICENSE
├── README.md
└── src
    ├── linked_list.f08
    └── test_link.f08

Include folders

Now we open the VSCode in this workspace, with the following settings in this extension:

{
    "fortran.gfortranExecutable": "gfortran",
    "fortran.linterEnabled": true
}

By opening the program file (test_link.f08) the following error will appear:
Screenshot_2020-02-29_11-43-54
The linked_list.mod file is in the bin directory so the linter can't find it. To solve this we need to add the path to the bin folder (where the linked_list.mod is). Therefore the settings now become:

{
    "fortran.gfortranExecutable": "gfortran",
    "fortran.linterEnabled": true,
    "fortran.includePaths": [
        "/home/pedro/Documents/Codes/LinkedList/bin"
    ]
}

By saving/reopening the test_link.f08 again and the error will disappear

Managing temporary .mod files

By opening the linked_list.f08 (the module file) you'll see that a .mod file will be created along side linked_list.f08 file
Screenshot_2020-02-29_11-54-02
This means that the linter worked and compiled your file, but having the .modfiles in src folder can become a mess. To solve this, let's use the -J flag that redirect the .mod to binfolder where it belongs. This is done in settings like:

{
    "fortran.gfortranExecutable": "gfortran",
    "fortran.linterEnabled": true,
    "fortran.includePaths": [
        "/home/pedro/Documents/Codes/LinkedList/bin"
    ],
    "fortran.linterExtraArgs": [
        "-Wall",
        "-J/home/pedro/Documents/Codes/LinkedList/bin"
    ]
}

As you can see, other flags like -Wall can be passed the same way.

By excluding that .mod created in the src folder you can see that by saving/reopening the module file the linter will return you errors and warnings but now creating the .mod in bin dir.

@pedro-ricardo
Copy link
Collaborator

@newmrdenis I'll wait longer now I promise 👍

Let me know if this helps, or if something is still wrong.

@newmrdenis
Copy link
Author

Yes, now all is clarified.I am really grateful for your spent time.

P.S. There is one more trouble with -J option such as you have to paste your dir right after -J key. No space is available. This is confusing.

@pedro-ricardo
Copy link
Collaborator

It doesn't bother me so much since I'm used with similar flags -I and -L that usually don't have spaces for the folder argument.

But I understand, if it bothers that much you can separate it like this:

"fortran.linterExtraArgs": [
    "-Wall",
    "-J","/home/pedro/Documents/Codes/LinkedList/bin"
]

It also works.

I'll leave the closure of this issue to you. If there's something else just ask.

@newmrdenis
Copy link
Author

Thank you again)

@Koushikphy
Copy link

Intro

Firstly our extension has two major drawbacks (that we are aware of) when it comes to the linter usage:

  • All folders must be specified as absolute paths
  • Sub-folders aren't supported, you need to specify separately every folder

I'm gathering these To-Do developments in #86.

Tutorial

Folder structure

This tutorial runs in the following code structure:

.
├── bin
│   └── Makefile
├── LICENSE
├── README.md
└── src
    ├── linked_list.f08
    └── test_link.f08

Where linked_list.f08 is the module file and test_link.f08 the program

Let's compile the code now. Our linter helps you see errors end warnings but doesn't know compilation order, linking and stuff like that. After running make in the bin folder the structure looks like this:

.
├── bin
│   ├── a.out
│   ├── linked_list.mod
│   ├── linked_list.o
│   ├── Makefile
│   └── test_link.o
├── LICENSE
├── README.md
└── src
    ├── linked_list.f08
    └── test_link.f08

Include folders

Now we open the VSCode in this workspace, with the following settings in this extension:

{
    "fortran.gfortranExecutable": "gfortran",
    "fortran.linterEnabled": true
}

By opening the program file (test_link.f08) the following error will appear:
Screenshot_2020-02-29_11-43-54
The linked_list.mod file is in the bin directory so the linter can't find it. To solve this we need to add the path to the bin folder (where the linked_list.mod is). Therefore the settings now become:

{
    "fortran.gfortranExecutable": "gfortran",
    "fortran.linterEnabled": true,
    "fortran.includePaths": [
        "/home/pedro/Documents/Codes/LinkedList/bin"
    ]
}

By saving/reopening the test_link.f08 again and the error will disappear

Managing temporary .mod files

By opening the linked_list.f08 (the module file) you'll see that a .mod file will be created along side linked_list.f08 file
Screenshot_2020-02-29_11-54-02
This means that the linter worked and compiled your file, but having the .modfiles in src folder can become a mess. To solve this, let's use the -J flag that redirect the .mod to binfolder where it belongs. This is done in settings like:

{
    "fortran.gfortranExecutable": "gfortran",
    "fortran.linterEnabled": true,
    "fortran.includePaths": [
        "/home/pedro/Documents/Codes/LinkedList/bin"
    ],
    "fortran.linterExtraArgs": [
        "-Wall",
        "-J/home/pedro/Documents/Codes/LinkedList/bin"
    ]
}

As you can see, other flags like -Wall can be passed the same way.

By excluding that .mod created in the src folder you can see that by saving/reopening the module file the linter will return you errors and warnings but now creating the .mod in bin dir.

Can this be done in a per project basis? If I do the following setting then all the mod files from all my project/folder will be dumped on the same folder. But the temporary mod/.o files should be local to that project.

@gnikit
Copy link
Member

gnikit commented Mar 17, 2021

Not as far as I know, you can use VSCode workspaces and set the -J in the workspace settings. You might also be able to use relative directories although I have not tested that myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants