How can I change directories in a homebrew formula? - ruby

I am trying to create my own homebrew formula using brew create and brew edit .
As part of the install for this project I need to change into a sub directory and build things there, for example
cd sub/dir/place
make -f makefile otherMakeTarget
I tried adding to my formula.rb
system "cd", "sub/dir/place/"
system "make", "etc"
But it doesn't seem to do the cd correctly. The logfile 01.cd shows the cd and the argument on two separate lines, I'm not sure if that's the problem.

Calling system creates a subshell and any modifications to the working directory go away when that call completes.
You could try using chdir:
Dir.chdir('sub/dir/place')

Another way to do it is to use a chdir block.
chdir "vendor" do
system "make", "install"
end

Related

use make install to expose a script to user

inside my makefile I have the following...
install:
$(INSTALL) $(PWD)/run.sh $(bindir)/run
so when the user clones my repo and CDs into it, I want them to type make install
my hope is that they will then be able to call the run.sh script as run
does anyone have any idea how this could be achieved?
If you want to install it globally then what you need is to copy it to a system-wide binary directory (like /usr/local/bin f.e.), and if you don't want them to need to use the .sh then you need to rename it to just run during the copy and add a shebang to the file (#!/bin/sh at the top).
One thing to keep in mind is that you might need to chmod +x $(bindir)/run if the file hasn't been marked as executable before.

path in makefile not working

Im running the following makefile
which needs to change dir to specific target and run there npm install
The problem is that I was able to see in the output that it print the directory (project/app) to the right directory but the installation (npm install) run on level up (project), why ?
For example
When I run it I see from cd $(DIR)/app
/Users/i03432/go/src/project/app
Now the second command is
npm install
And I got error that id doesn’t find the package json in the project path which is right... it’s only in the app path. Why the cd is not working ?
it try to find it here
/Users/i03432/go/src/project/package.json
and here is the package.json
/Users/i03432/go/src/project/app/package.json
The makefile is
module:
DIR=$(PWD)
#echo $(DIR)
cd $(DIR)/app
npm install
Every command in a rule is run in a single process (sub-shell). Every change you perform on the environment is hence tied to that particular line. You want to change your snippet to
cd $(PWD)/app && npm install
This command runs in a single subprocess and should yield the desired result. Note that this problem occurs for the definition of DIR, too, so you might want to move this a few lines up:
DIR = $(PWD)
module:
cd $(DIR) && npm install
This way, you are referring to a variable that make provides, and you don't rely upon subprocesses here.

Can I get the locate to work on Windows through Git Bash?

Git Bash seems to have nice support of various Linux commands. It even supports locate, though it never finds anything:
mypc#mypc MINGW64 ~
$ locate --regex .*?\/[^\/]+\.docx
I tried to update the locate database, but the support is not finished there:
mypc#mypc MINGW64 ~
$ updatedb
/usr/bin/updatedb: line 323: /usr/var/locatedb.n: No such file or directory
Failed to generate /usr/var/locatedb.n
Can I fix that by editing some script? What causes this problem?
from git bash run:
mkdir /c/Program\ Files/Git/usr/var; updatedb --localpaths='/c/'
Also you can add the following alias in your ~/.bash_profile:
alias updatedb="updatedb --localpaths='/c/'"
I havent tried the alias out yet bit I don't see why it would work.
Just make sure to either
source ~/.bash_profile
or open a new shell after you have added the alias so it gets loaded.
Thanks for the tip!
Just wanted to add to #danielpflood's answer, that I needed to run "Git Bash" as administrator, to be able to create the needed /var/ directory.
This is on Windows 10.
[wanted to add as a comment, but I do not have enough reputation for that.]
I found I needed to create a directory C:\Program Files\Git\usr\var and give my user full access to it.
This fixed the permissions issue, but in order to get it to index the correct files I also had to invoke updatedb as updatedb --localpaths='/c/' (I imagine this can be put in a config file somewhere)

Shell build script with ember

I am attempting to write a build script to be used with Facebook watchman and my ember-cli application.
My build script is:
#!/bin/sh
cd ..
ember build
cd ..
cp ./ember-app/dist/index.html ./slim-app/app/templates/app.php
cp -r ./ember-app/dist/assets/ ./slim-app/public/assets/
And my watchman command is:
watchman -- trigger $PWD/ember-app/app 'ember-build' '**' -- sh $PWD/build.sh
Watchman triggers and finds my script fine but when I look at the log I get an error saying ember cannot be found. I'm not really sure why because when i run sh build.sh everything works fine.
Is there any way I could do something like which ember to determine the path to ember and use it directly? I know I can just do which ember and copy and paste that path into the script but I really don't want to do that because I want the build script to work no matter which version of node/nvm I am using.
I'm also open to suggestions to a better way of doing this.
Sounds like a PATH problem. When watchman is first started it captures your PATH environment variable, except on OS X at the moment, due to a bug in our launchd integration.
https://github.com/facebook/watchman/issues/68 has some suggestions for an awkward workaround.
Another possibility is to simply put a line in your build script to set the PATH:
# Add the path to ember in here somewhere
PATH=/usr/local/bin:$PATH

Windows - start git in given directory

I'm using git portable on windows. It's rather user friendly, but there is one thing that bothers me. Every time I run it I have to type the entire path to the project directory, which is quite long sometimes. Maybe it's not a serious problem, but it would be very nice to shorten it. I tried the following:
bash script.sh // cd in this file // nothing happens
create symbolic link it - it just copies the directory
create windows shortcut - can't open it within git console
Anybody managed to solve this?
You can right click on the Windows shortcut that launches Git Bash, edit its properties and modify the "Start in" path to your project path. Every time you launch this shortcut, it will cd into that project path.
Or you can add an alias to your ~/.bashrc like below:
alias proj="cd /path/to/project/"
This will allow you to cd into the project dir on demand by typing the alias name at the prompt.
If you run git-bash.bat from Portable git, it should work mostly as normal git installation. So, to work with a specific repository, just cd into it:
cd /c/code/MyRepo/
git whatever
I've added
cd /c/dev
to
~/.bashrc
with
echo cd /c/dev >> ~/.bashrc
But I'm running MSysGit the non-portable version. Hope this helps in some way anyway.

Resources