Sublime Forum

Where should I add a path in Linux so Sublime Build system can call it?

#1

I am developing on linux, and I have added the path to the flutter sdk to my ~/.profile file.

I can open a terminal, and run ./flutter, and it will run the flutter tool.

When I add a sublime build cmd to call ./flutter, it says it can no find the file. What configuration file on linux can I added the flutter path to, such that sublime build systems will be able to call it?

Thanks!

0 Likes

#2

Can you share what your sublime-build looks like and what the output of which flutter is when you run it in terminal?

If you use ./ in front of a command when you execute it in a shell, you’re telling bash (or whatever your shell is) that it should execute the flutter in the current directory, which stops it from ever looking at the PATH at all.

If that’s how you’re running it, then possibly the problem is that the current working directory (working_dir in the sublime-build file) needs to be set to the location where flutter is so that it will be found.

If which flutter shows a path that’s not relative to the current directory then I would think you could fix your problem by using just flutter in the build, so that the shell will scan the path and find it.

0 Likes

#3

{
“cmd”: [“flutter”],
“working_dir”: “${project_path}”,
“file_regex”: “^ (/…?):([0-9]):?([0-9])”,
}

Regardless of whether I use ./ or not before the flutter cmd, the output is the same…

[Errno 2] No such file or directory: ‘flutter’
[cmd: [‘flutter’]]
[dir: /home/scott/src/Chess/client]
[path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/scott/android_sdk/platform-tools:/home/scott/android_sdk/emulator:/home/scott/android_sdk/tools/bin]
[Finished]

0 Likes

#4

Does flutter appear in one of the folders that are listed in the [path: part of the error diagnostic?

0 Likes

#5

No it doesn’t.

the flutter sdk path is added to my .profile. Maybe I should also added it to bashrc…

0 Likes

#6

Does it work if you quit Sublime and then launch Sublime from a terminal rather than starting Sublime from your window manager (e.g. the dock, etc)? If so, then you may be able to get it working by logging out and in again (or in extreme cases, rebooting).

Basically the idea here is that programs inherit the environment of the task that launches them. If you modify your .profile while you’re logged in, then your window manager doesn’t see the change to the environment until it restarts, so it launches programs with the old environment and they don’t see the path. Lauching a terminal executes bash which sets up a new environment based on its own profile files.

It may also help to use shell_cmd in place of cmd, which makes Sublime tell bash to execute the command instead of trying to find and launch it directly. Or alternatively add "shell": true if you’re using cmd so that the underlying Python library knows that it should ask bash to do the same thing.

If all else fails you can add a line to the build to get the build system to modify the path directly.

If you’re using cmd, then you can add this:

"path": "/flutterpath:$PATH"

That tells Sublime to modify the $PATH before it launches the program, and adjust it back once the build is done. That would make sure that the environment that Sublime has definitely includes the correct item.

If instead you’re using shell_cmd, then you can do something like this instead:

    "env": {
        "PATH": "/flutterpath:$PATH"
    },

This tells Sublime to adjust the $PATH of the program while it’s running. So you can’t use it to find the item in cmd because until it’s actually running, the path isn’t modified, and it can’t be found because the path hasn’t been modified yet.

All else being equal I personally think it’s a better idea to use the env route (and shell_cmd) because currently the exec command will not fix the path if the build fails in various ways, which can potentially lead to clobbering the $PATH and requiring you to restart Sublime.

Possibly adding the item to your .bashrc may help as well; bash only loads the .profile file (or the other named variants) for a login shell. I’m not sure what Python is doing internally when you use cmd to launch a task though.

0 Likes

#7

You were correct about launching with an old environment.

Once I launched from a new session, the path sublime was correctly contained flutter path.

Unfortunately the error STILL persists. Observe the latest output…

[Errno 2] No such file or directory: ‘flutter’
[cmd: [‘flutter’]]
[dir: /home/myuser/src/Chess/client]
[path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/myuser/android_sdk/platform-tools:/home/myuser/android_sdk/emulator:/home/myuser/android_sdk/tools/bin:~/.flutter_sdk/bin]
[Finished]

When I change from using the “cmd” parameter, to using “shell_cmd”, the output is just blank. Nothing happens.

0 Likes

#8

That ~ there doesn’t work as you think it does. Tildes are usually expanded by the shell (or by some applications) only when they are the first character. What you need inside a string is $HOME.

1 Like

#9

I am trying to expand the environment build path to use a project local path like so:

{
   "shell_cmd": "action",
   "env": {
      "PATH": "$project_path/bin"
   }
}

But $project_path isn’t expanded. I can’t figure out a workaround :frowning:

As usual, just after posting. I figure out that I can prepend the environment to the shell command line, where the variables get expanded…

0 Likes