noseglid / atom-build

:hammer: Build your project directly from the Atom editor
https://atom.io/packages/build
MIT License
248 stars 97 forks source link

cwd keeps defaulting to %UserProfile% #422

Closed seamusgalla closed 8 years ago

seamusgalla commented 8 years ago

My .atom-build.json file:

{
  "cmd": "gb",
  "args": ["build", "all"],
  "sh": false,
  "cwd": "C:\\Code\\crs_apps",
  "errorMatch": "\n(?<file>[^:\n]+):(?<line>\\d+)"
}

My Error: FATAL: unable to construct context: could not locate project root: could not find project root in "C:\Users\myname" or its parents

I am using atom on windows 7 64bit.

Up until recently this build file was working but since I upgraded all my packages in atom it has stopped working. Build keeps trying to run the command from %UserProfile% rather than the cwd that is defined in the build file. It does catch errors if I change cwd to something invalid. It also does not work if I change cwd to "{FILE_ACTIVE_PATH}". Is there something wrong with my settings?

noseglid commented 8 years ago

How do you start Atom?

seamusgalla commented 8 years ago

I call atom . from the location C:\Code\crs_apps in the command prompt.

noseglid commented 8 years ago

That's weird then. The error is unknown to me. It is likely thrown from Atom itself when build is trying to get project roots. Could you re-install atom and all the plugins?

seamusgalla commented 8 years ago

Unfortunately a fresh install of atom and your package did not resolve the issue.

noseglid commented 8 years ago

Where do you get the error message, could you please provide a screenshot of your editor when it happens?

seamusgalla commented 8 years ago

http://imgur.com/qb8aiI3

noseglid commented 8 years ago

Are you sure that error is not from gb, whatever that is?

seamusgalla commented 8 years ago

gb is a program that handles packages for the Go language, gb. I can run the command gb build all from the command prompt without any issues.

seamusgalla commented 8 years ago

From the correct directory of course.

noseglid commented 8 years ago

Most likely the environment is not the same in the two cases. Or something else differs. I don't know anything about gb so I can't help you there. It looks like the command is correctly run though.

seamusgalla commented 8 years ago

Thanks for all your help so far and for building build in the first place!! Back to the issue: If I change the command to pwd, the output that it gives me is still not what is entered in the cwd specifier. I think that this problem is with the build package rather than an environment variable while calling gb.

noseglid commented 8 years ago

What if you put /c/Users/sgalla06 in cwd ?

seamusgalla commented 8 years ago

If I put the string exactly as you have it there I get the error: Unable to execute: gb Make sure cmd:'gb' and cwd:'/c/Users/sgalla06' exists and have correct access permissions. Binaries are found in these folders: undefined since it's an invalid directory.

if i use C:/Users/sgalla06 i get the usual error: FATAL: unable to construct context: could not locate project root: could not find project root in "C:\Users\sgalla06" or its parents which I would get normally if the gb command is executed from C:/Users/sgalla06 as it is not a project directory with the appropriate folder structure.

if the cmd is "pwd", cwd is "C:\Users\sgalla06" with no args field specified, then I get the following output

/c/Users/sgalla06

noseglid commented 8 years ago

That's really weird. Also, if you're on windows, where does the forward slashes come from?

seamusgalla commented 8 years ago

Probably coming from minGW installations which allow me to use linux commands on window command prompt. However It was working with previous versions of build, it was only when I upgraded your package that this problem started occurring.

New build file:

{
  "cmd": "cd",
  "sh": false,
  "cwd": "C:\\Code\\crs_apps",
  "errorMatch": "\n(?<file>[^:\n]+):(?<line>\\d+)"
}

output: C:\Users\sgalla06 (correct slashes)

If I use cd (native to windows) instead of pwd the error persists, in that cwd does not make any effect on the location of where cmd is carried out.

noseglid commented 8 years ago

So, cwd is passed to cross-spawn-async here: https://github.com/noseglid/atom-build/blob/master/lib/build.js#L155

Could you create a small node script which essentially looks like (you need to install node_modules):

var spawn = require('cross-spawn-async');

var child = spawn('pwd', { cwd: "C:\\Code\\crs_apps" });

I haven't tested above so some modifications might be necessary.

You could also test with child_process directly from nodejs and see if this might shed some light over it.

seamusgalla commented 8 years ago

Hi Again, Sorry for the delay in response, only back at work today. Executing the following using node

var exec = require('child_process').exec;
exec('cd',{cwd: "C:\\Code\\crs_apps"},function(error,stdout,stderr) {
    console.log(stdout);
});

gives me the incorrect directory: C:\Users\sgalla06. I reinstalled nodejs and the problem persists. I am not sure why 'cwd' worked for as long as it did within your build package...weird.

I also haven't seen cwd as an issue on stack overflow. Maybe it's the work installation of Windows, I've spent too much time trying to figure this out already.

Since I cant use:

{
  "cmd": "cd",
  "args": ["C:/Code/crs_apps", "&&", "gb", "build", "all"],
  "sh": false,
  "errorMatch": "\n(?<file>[^:\n]+):(?<line>\\d+)"
}

or

{
  "cmd": "cd C:\\Code\\crs_apps && gb",
  "args": ["build", "all"],
  "sh": false,
  "errorMatch": "\n(?<file>[^:\n]+):(?<line>\\d+)"
}

as my build files, I don't really know what else to do.

noseglid commented 8 years ago

Since you get the same issue with vanilla nodejs I'm going to close this issue.

I will try and see if I can reproduce this on my windows machine. Otherwise I'd suggest you create an issue with node with the sample script you have there.

seamusgalla commented 8 years ago

Sure thing, thanks very much for your help

trianglesis commented 7 years ago

Hi, Is there any updates? I have the similar issue.

cmd: 'C:\Python34\python.exe C:\Users\USER\.atom\packages\language-tplpre\check.py'

cwd: {FILE_ACTIVE_PATH}

check.py will create log file in working dir, and this is WD which logger can see: logger: C:\Users\USER\AppData\Local\atom\app-1.19.4

So all logs go to atom folder, not to currenly active file's folder (

Lol: Fixed:

cwd: '{FILE_ACTIVE_PATH}'

Thanks.