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

The plugin does not work on OSX #11

Closed
mcaceresb opened this issue Sep 9, 2017 · 65 comments
Closed

The plugin does not work on OSX #11

mcaceresb opened this issue Sep 9, 2017 · 65 comments

Comments

@mcaceresb
Copy link
Owner

Since I do not have a Mac and I have been unable to install OSX on a virtual machine, I have not been able to compile an OSX version of the plugin. This is currently on hold. Macs are expensive.

If you happen to have a Mac and are willing yo contribute to gtools, please comment here and I will give you instructions on how to compile.

@fbelotti
Copy link

Hi Mauricio, I'd be happy to help. Can you give me instructions to compile the plugin on OSX?

@mcaceresb
Copy link
Owner Author

Excellent! Let's do some checks first.

  1. Clone the repository,
  2. Install premake5; if you're not sure how then download it from https://premake.github.io/download.html and extract the contents.
  3. Make sure you have gcc and make installed. I think the easiest way to do this is to install the command line tools from Xcode (Preferences > Downloads > Command Line Tools).
  4. Open iTerm and run
cd /Path/To/stata-gtools
make spooky PREMAKE=/Path/To/premake5

Iet me know what happens. You only need to specify PREMAKE if it's not in your system's path.

@fbelotti
Copy link

Do I need to compile in the trunk?

@mcaceresb
Copy link
Owner Author

I think it would be best if you made a branch for it. Maybe run

git checkout -b osx

Before doing anything.

@fbelotti
Copy link

I just checked out the entire repository using -svn co-.

@mcaceresb
Copy link
Owner Author

You can use SVN with github? I didn't know that... I don't know enough SVN to help with branches. I think you will need git for make spooky to work. Can you install git as well? If you don't want to use it outside that then just do all this in the trunk, but git should be in your system path.

@fbelotti
Copy link

Ok. I realized that git comes with Xcode. I cloned the rep and started a new branch using

git checkout -b osx

but I have issues with premake5. See below:

Federicos-MacBook-Pro:stata-gtools federico$ make spooky PREMAKE=/Users/federico/Desktop/GiT/premake5/premake5.lua
cd lib/spookyhash/build && /Users/federico/Desktop/GiT/premake5/premake5.lua gmake
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 1: ---: command not found
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 2: --: command not found
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 3: --: command not found
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 4: ---: command not found
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 6: --: command not found
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 7: --: command not found
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 7: I: command not found
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 8: --: command not found
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 10: local: can only be used in a function
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 13: --: command not found
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 14: --: command not found
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 15: --: command not found
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 16: --: command not found
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 18: premake.api.deprecations: command not found
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 21: --: command not found
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 22: --: command not found
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 23: --: command not found
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 25: newaction: command not found
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 26: trigger: command not found
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 27: description: command not found
/Users/federico/Desktop/GiT/premake5/premake5.lua: line 28: syntax error near unexpected token (' /Users/federico/Desktop/GiT/premake5/premake5.lua: line 28: execute = function ()'
make: *** [spooky] Error 2

@mcaceresb
Copy link
Owner Author

Is premake5.lua an executable or a script? You should pass the path to the executable. One way to check is to look at the output of

ls -lah /Users/federico/Desktop/GiT/premake5/

@fbelotti
Copy link

It is a script. But I also followed the instructions at https://github.com/premake/premake-core/wiki/Building-Premake to create the premake5 executable. Then I tried to make spooky using the premake5 executable and I got

Federicos-MacBook-Pro:stata-gtools federico$ make spooky PREMAKE=/Users/federico/Desktop/GiT/premake5/bin/release/premake5
cd lib/spookyhash/build && /Users/federico/Desktop/GiT/premake5/bin/release/premake5 gmake
No Premake script (premake5.lua) found!
make: *** [spooky] Error 1

@mcaceresb
Copy link
Owner Author

That's odd. Can you run

cd lib/spookyhash/build
ls -lah
/Users/federico/Desktop/GiT/premake5/bin/release/premake5 gmake make

@fbelotti
Copy link

Federicos-MacBook-Pro:stata-gtools federico$ cd lib/spookyhash/build
Federicos-MacBook-Pro:build federico$ ls -lah
total 0
drwxr-xr-x 3 federico staff 102B Sep 28 16:21 .
drwxr-xr-x 3 federico staff 102B Sep 28 16:21 ..
drwxr-xr-x 3 federico staff 102B Sep 28 16:21 bin
Federicos-MacBook-Pro:build federico$ /Users/federico/Desktop/GiT/premake5/bin/release/premake5 gmake make
No Premake script (premake5.lua) found!

@mcaceresb
Copy link
Owner Author

Oh! I know what's up. Totally my bad; I should have read my own README. You need

git submodule update --init --recursive

before doing anything else. Try that and try the previous set of commands again.

@fbelotti
Copy link

Federicos-MacBook-Pro:GiT federico$ git clone https://github.com/mcaceresb/stata-gtools.git stata-gtools
Cloning into 'stata-gtools'...
remote: Counting objects: 1903, done.
remote: Compressing objects: 100% (173/173), done.
remote: Total 1903 (delta 252), reused 262 (delta 174), pack-reused 1556
Receiving objects: 100% (1903/1903), 4.44 MiB | 1.04 MiB/s, done.
Resolving deltas: 100% (1374/1374), done.

Federicos-MacBook-Pro:GiT federico$ cd stata-gtools/
Federicos-MacBook-Pro:stata-gtools federico$ git submodule update --init --recursive
Submodule 'lib/spookyhash' (https://github.com/centaurean/spookyhash) registered for path 'lib/spookyhash'
Cloning into '/Users/federico/Desktop/GiT/stata-gtools/lib/spookyhash'...
Submodule path 'lib/spookyhash': checked out '2c27b434d097198cab2272d4160b413a5f139049'
Submodule 'test/libs/cputime' (https://github.com/centaurean/cputime.git) registered for path 'lib/spookyhash/test/libs/cputime'
Cloning into '/Users/federico/Desktop/GiT/stata-gtools/lib/spookyhash/test/libs/cputime'...
Submodule path 'lib/spookyhash/test/libs/cputime': checked out 'd435d91b872a4824fb507a02d0d1814ed3e791b0'

Federicos-MacBook-Pro:stata-gtools federico$ git checkout -b osx
Switched to a new branch 'osx'

Federicos-MacBook-Pro:stata-gtools federico$ make spooky PREMAKE=/Users/federico/Desktop/GiT/premake5/bin/release/premake5
cd lib/spookyhash/build && /Users/federico/Desktop/GiT/premake5/bin/release/premake5 gmake
git version 2.13.5 (Apple Git-94)

Error: ...sktop/GiT/stata-gtools/lib/spookyhash/build/premake5.lua:37: attempt to compare number with boolean

make: *** [spooky] Error 1

@mcaceresb
Copy link
Owner Author

Please delete lines 37 through 40 of /Users/federico/Desktop/GiT/stata-gtools/lib/spookyhash/build/premake5.lua

@fbelotti
Copy link

line 37 in the ../stata-gtools/lib/spookyhash/build/premake5.lua script looks

if os.execute("git --version") > 0 then

@fbelotti
Copy link

Ok. A step ahead...but still an error

Federicos-MacBook-Pro:stata-gtools federico$ make spooky PREMAKE=/Users/federico/Desktop/GiT/premake5/bin/release/premake5
cd lib/spookyhash/build && /Users/federico/Desktop/GiT/premake5/bin/release/premake5 gmake

** Warning: the flags value OptimizeSpeed has been deprecated and will be removed.
Use optimize "Speed" instead.
@...sktop/GiT/stata-gtools/lib/spookyhash/build/premake5.lua(44)

Building configurations...
Running action 'gmake'...
Generated Makefile...
Generated spookyhash-static.make...
Generated spookyhash-shared.make...
Generated spookyhash-test.make...
Done (25ms).
cd lib/spookyhash/build && make clean
Cleaning spookyhash-static
Cleaning spookyhash-shared
Cleaning spookyhash-test
cd lib/spookyhash/build && make
==== Building spookyhash-static (release) ====
context.c
globals.c
spookyhash.c
Linking spookyhash-static
==== Building spookyhash-shared (release) ====
context.c
globals.c
spookyhash.c
Linking spookyhash-shared
==== Building spookyhash-test (release) ====
chronometer.c
test.c
Linking spookyhash-test
mkdir -p ./build
cp -f ./lib/spookyhash/build/libspookyhash.so ./build/libspookyhash.so
cp: ./lib/spookyhash/build/libspookyhash.so: No such file or directory
make: *** [spooky] Error 1

@mcaceresb
Copy link
Owner Author

Ok, but that's great progress, actually. Can you tell me the output of

ls -lahR /Users/federico/Desktop/GiT/stata-gtools/lib/spookyhash/build/

@mcaceresb
Copy link
Owner Author

You're looking for the library it made. I thought it would have the same name as in Linux but it seems not.

@fbelotti
Copy link

Federicos-MacBook-Pro:stata-gtools federico$ ls -lahR /Users/federico/Desktop/GiT/stata-gtools/lib/spookyhash/build/
total 64
drwxr-xr-x 10 federico staff 340B Sep 28 22:40 .
drwxr-xr-x 12 federico staff 408B Sep 28 18:19 ..
-rw-r--r-- 1 federico staff 12K Sep 28 22:17 .premake5.lua.swp
-rw-r--r-- 1 federico staff 1.6K Sep 28 18:34 Makefile
drwxr-xr-x 3 federico staff 102B Sep 28 18:34 bin
drwxr-xr-x 3 federico staff 102B Sep 28 18:34 obj
-rw-r--r-- 1 federico staff 2.3K Sep 28 18:34 premake5.lua
-rw-r--r-- 1 federico staff 3.0K Sep 28 18:34 spookyhash-shared.make
-rw-r--r-- 1 federico staff 2.9K Sep 28 18:34 spookyhash-static.make
-rw-r--r-- 1 federico staff 2.7K Sep 28 18:34 spookyhash-test.make

/Users/federico/Desktop/GiT/stata-gtools/lib/spookyhash/build//bin:
total 0
drwxr-xr-x 3 federico staff 102B Sep 28 18:34 .
drwxr-xr-x 10 federico staff 340B Sep 28 22:40 ..
drwxr-xr-x 5 federico staff 170B Sep 28 18:34 Release

/Users/federico/Desktop/GiT/stata-gtools/lib/spookyhash/build//bin/Release:
total 264
drwxr-xr-x 5 federico staff 170B Sep 28 18:34 .
drwxr-xr-x 3 federico staff 102B Sep 28 18:34 ..
-rw-r--r-- 1 federico staff 28K Sep 28 18:34 libspookyhash.a
-rwxr-xr-x 1 federico staff 21K Sep 28 18:34 libspookyhash.dylib
-rwxr-xr-x 1 federico staff 73K Sep 28 18:34 spookyhash-test

/Users/federico/Desktop/GiT/stata-gtools/lib/spookyhash/build//obj:
total 0
drwxr-xr-x 3 federico staff 102B Sep 28 18:34 .
drwxr-xr-x 10 federico staff 340B Sep 28 22:40 ..
drwxr-xr-x 5 federico staff 170B Sep 28 18:34 Release

/Users/federico/Desktop/GiT/stata-gtools/lib/spookyhash/build//obj/Release:
total 0
drwxr-xr-x 5 federico staff 170B Sep 28 18:34 .
drwxr-xr-x 3 federico staff 102B Sep 28 18:34 ..
drwxr-xr-x 8 federico staff 272B Sep 28 18:34 spookyhash-shared
drwxr-xr-x 8 federico staff 272B Sep 28 18:34 spookyhash-static
drwxr-xr-x 6 federico staff 204B Sep 28 18:34 spookyhash-test

/Users/federico/Desktop/GiT/stata-gtools/lib/spookyhash/build//obj/Release/spookyhash-shared:
total 88
drwxr-xr-x 8 federico staff 272B Sep 28 18:34 .
drwxr-xr-x 5 federico staff 170B Sep 28 18:34 ..
-rw-r--r-- 1 federico staff 184B Sep 28 18:34 context.d
-rw-r--r-- 1 federico staff 1.9K Sep 28 18:34 context.o
-rw-r--r-- 1 federico staff 148B Sep 28 18:34 globals.d
-rw-r--r-- 1 federico staff 1.8K Sep 28 18:34 globals.o
-rw-r--r-- 1 federico staff 236B Sep 28 18:34 spookyhash.d
-rw-r--r-- 1 federico staff 24K Sep 28 18:34 spookyhash.o

/Users/federico/Desktop/GiT/stata-gtools/lib/spookyhash/build//obj/Release/spookyhash-static:
total 88
drwxr-xr-x 8 federico staff 272B Sep 28 18:34 .
drwxr-xr-x 5 federico staff 170B Sep 28 18:34 ..
-rw-r--r-- 1 federico staff 184B Sep 28 18:34 context.d
-rw-r--r-- 1 federico staff 1.9K Sep 28 18:34 context.o
-rw-r--r-- 1 federico staff 148B Sep 28 18:34 globals.d
-rw-r--r-- 1 federico staff 1.8K Sep 28 18:34 globals.o
-rw-r--r-- 1 federico staff 236B Sep 28 18:34 spookyhash.d
-rw-r--r-- 1 federico staff 24K Sep 28 18:34 spookyhash.o

/Users/federico/Desktop/GiT/stata-gtools/lib/spookyhash/build//obj/Release/spookyhash-test:
total 72
drwxr-xr-x 6 federico staff 204B Sep 28 18:34 .
drwxr-xr-x 5 federico staff 170B Sep 28 18:34 ..
-rw-r--r-- 1 federico staff 254B Sep 28 18:34 chronometer.d
-rw-r--r-- 1 federico staff 4.4K Sep 28 18:34 chronometer.o
-rw-r--r-- 1 federico staff 445B Sep 28 18:34 test.d
-rw-r--r-- 1 federico staff 19K Sep 28 18:34 test.o

@mcaceresb
Copy link
Owner Author

That looks excellent! Thanks. Ok, let's try this:

make SPOOKYLIB=-l:libspookyhash.a

if that fails, try this

gcc -Wall -bundle -DSYSTEM=APPLEMAC -c -o build/stplugin.o src/plugin/spi/stplugin.c
gcc -Wall -bundle -DSYSTEM=APPLEMAC -c -o build/gtools.o src/plugin/gtools.c
gcc -Wall -bundle -DSYSTEM=APPLEMAC    -o build/gtools_macosx.plugin build/gtools.o build/stplugin.o -L./lib/spookyhash/build/bin/Release -l:libspookyhash.a
gcc -Wall -bundle -DSYSTEM=APPLEMAC -o build/env_set_macosx.plugin src/plugin/spi/stplugin.c src/plugin/env_set.c

If both fail, please post the output.

@fbelotti
Copy link

The make command failed

Federicos-MacBook-Pro:stata-gtools federico$ make SPOOKYLIB=-l:libspookyhash.a
rm -f build/gtools_macosx.plugin build/gtools_macosx_multi.plugin build/gtools_multi.o build/env_set_macosx.plugin build/stplugin.o
rm -f  src/plugin/lib
rm -f  src/plugin/spt
rm -f  src/plugin/spi
rm -f  src/plugin/spookyhash
ln -sf ../../lib 	  src/plugin/lib
ln -sf lib/spt-0.2 src/plugin/spt
ln -sf lib/spi-2.0 src/plugin/spi
ln -sf lib/spookyhash src/plugin/spookyhash
mkdir -p ./build
mkdir -p ./lib/spookyhash/build/bin/Release
gcc -Wall -O2 -bundle -DSYSTEM=APPLEMAC -o build/gtools_macosx.plugin  src/plugin/spi/stplugin.c src/plugin/gtools.c -L./lib/spookyhash/build/bin/Release -L./lib/spookyhash/build -l:libspookyhash.a
ld: library not found for -l:libspookyhash.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [gtools_other] Error 1

The same is true for the gcc for the creation of the library

Federicos-MacBook-Pro:stata-gtools federico$ gcc -Wall -bundle -DSYSTEM=APPLEMAC -c -o build/stplugin.o src/plugin/spi/stplugin.c
clang: warning: argument unused during compilation: '-bundle' [-Wunused-command-line-argument]
Federicos-MacBook-Pro:stata-gtools federico$ gcc -Wall -bundle -DSYSTEM=APPLEMAC -c -o build/gtools.o src/plugin/gtools.c
clang: warning: argument unused during compilation: '-bundle' [-Wunused-command-line-argument]
Federicos-MacBook-Pro:stata-gtools federico$ gcc -Wall -bundle -DSYSTEM=APPLEMAC    -o build/gtools_macosx.plugin build/gtools.o build/stplugin.o -L./lib/spookyhash/build/bin/Release -l:libspookyhash.a
ld: library not found for -l:libspookyhash.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Federicos-MacBook-Pro:stata-gtools federico$ gcc -Wall -bundle -DSYSTEM=APPLEMAC -o build/env_set_macosx.plugin src/plugin/spi/stplugin.c src/plugin/env_set.c

@mcaceresb
Copy link
Owner Author

mcaceresb commented Sep 29, 2017

I think it might be the double slash. Hopefully this works:

gcc -Wall -bundle -DSYSTEM=APPLEMAC -o build/gtools_macosx.plugin  src/plugin/spi/stplugin.c src/plugin/gtools.c -L./lib/spookyhash/build//bin/Release -l:libspookyhash.a

If not, can you go into -L./lib/spookyhash/build//bin/Release and copy libspookyhash.a two directories up? (to -L./lib/spookyhash/build/)? Then try again with

gcc -Wall -bundle -DSYSTEM=APPLEMAC -o build/gtools_macosx.plugin  src/plugin/spi/stplugin.c src/plugin/gtools.c -L./lib/spookyhash/build -l:libspookyhash.a

@fbelotti
Copy link

I finally found the right syntax to link the library using gcc in OSX, that is

gcc -Wall -bundle -DSYSTEM=APPLEMAC src/plugin/spi/stplugin.c src/plugin/gtools.c lib/spookyhash/build/bin/Release/libspookyhash.a -o build/gtools_macosx.plugin

After adding the missing line

f env_set_macosx.plugin

in the gtools.pkg file I tried to reinstall the gtools package using

net install gtools, from(/Users/federico/Desktop/GiT/stata-gtools/build) replace

and it seems that now the only missing file is the gtools_macosx_legacy.plugin. What do I have to compile to get this file?

@mcaceresb
Copy link
Owner Author

mcaceresb commented Sep 29, 2017

Ah, excellent! I've created an osx-plugin repo. Please fork the repo and compile the plugin on that branch.

  1. Fork the repo. Go to https://github.com/mcaceresb/stata-gtools, click on "fork"
  2. Run
cd /Users/federico/Desktop/GiT/
git clone https://github.com/fbelotti/stata-gtools stata-gtools-fork
cd stata-gtools-fork
git submodule update --init --recursive
git checkout osx-plugin
  1. Check out the osx-plugin branch and compile
make spooky PREMAKE=/Users/federico/Desktop/GiT/premake5/bin/release/premake5
make
  1. Run all the tests from Stata. That is, open up a Stata session and run
cd /Users/federico/Desktop/GiT/stata-gtools-fork/build
which gtools

Make sure the version is 0.7.3. Now run

log using gtools_tests_macosx.log, text
do gtools_tests.do 
log  close _all
  1. If all the tests pass, add the log and the plugin and commit the changes
cd /Users/federico/Desktop/GiT/stata-gtools-fork/
mv build/gtools_tests_macosx.log src/test/
git add src/test/gtools_tests_macosx.log
git add lib/plugin/gtools_macosx.plugin 
git add lib/plugin/env_set_macosx.plugin 
git add build/gtools_macosx.plugin -f
git add build/env_set_macosx.plugin -f
git commit -m "Compiled OSX plugin; tests passing."
git push -u origin osx-plugin
  1. Create a pull request. Go to https://github.com/mcaceresb/stata-gtools/pulls and click on "New pull request", review the info, and click "Create pull request."

Let me know if anything goes array.

Mauricio

@fbelotti
Copy link

fbelotti commented Oct 2, 2017

Hi Mauricio

Unfortunately there still are some issues.
First you need to modify the `lib/spookyhash/build/premake5.lua' script by removing the following

if os.execute("git --version") > 0 then
        io.write("Please install Git, it is required to update submodules.")
        os.exit(0)
end

I did it, and the process goes well up to

log using gtools_tests_macosx.log, text

When I run gtools_tests.do Stata crashes. I tried by compiling the plugin using the libspookyhash.dylib dynamic lib instead of `libspookyhash.a'. In that case the do file runs but Stata answers by saying

-------------------------------------
Basic unit-tests 11:16:27  2 Oct 2017
-------------------------------------
Could not load plugin: ./gtools_macosx.plugin
    test(failed): checks_corners, oncollision(error) debug_force_single

Any hint?

Federico

@mcaceresb
Copy link
Owner Author

Try copying libspookyhash.dylib to build and then running the tests again.

If that works I'll modify the code to use the dynamic library for OSX as well.

@fbelotti
Copy link

fbelotti commented Oct 2, 2017

No good news. The tests fail with the same error.

@fbelotti
Copy link

fbelotti commented Oct 3, 2017

The git checkout -- "build/*unix*" command does not put all the unix plugin back. The env_* is still missing.

@mcaceresb
Copy link
Owner Author

There should be a copy in lib/plugin; can you run cp lib/plugin/*unix* build/?

@fbelotti
Copy link

fbelotti commented Oct 3, 2017

Ok, I copied from lib/plugin. The output of do gcollapse.ado is now

. 
. ***********************************************************************
. *                         Define the plugins                          *
. ***********************************************************************
. 
. cap program drop env_set

. program env_set, plugin using("env_set_`:di lower("`c(os)'")'.plugin")
dlopen(./env_set_unix.plugin, 1): no suitable image found.  Did find:
                ./env_set_unix.plugin: unknown file type, first eight bytes: 0x
> 7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00
                /Users/federico/Desktop/GiT/stata-gtools-fork/build/env_set_uni
> x.plugin: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01
>  0x01 0x00
Could not load plugin: ./env_set_unix.plugin
r(9999);

end of do-file
r(9999);

end of do-file
r(9999);

@mcaceresb
Copy link
Owner Author

Ok, that's what I expected. Great. Now can you try running step 2? So, via stata-mp,

dii "`c(machine_type)'"
program gtools_plugin, plugin using(`"gtools_macosx.plugin"')
plugin call gtools_plugin, check

If that all works, please replace line 1409 in gcollapse.ado with program env_set, plugin using("env_set_macosx.plugin") and lines 1464 through 1492 with program gtools_plugin, plugin using("gtools_macosx.plugin"')` and try running

sysuse auto
gcollapse price, by(make)  v b

from stata-mp to, hopefully, finally be able to debug the crash.

@fbelotti
Copy link

fbelotti commented Oct 4, 2017

The first part runs without errors. After replacing the code in gcollapse.ado as you indicated, I ran again the tmp_file.do with

sysuse auto
gcollapse price, by(make)  v b

The result printed to the shell is

Federicos-MacBook-Pro:build federico$ /usr/local/bin/stata-mp -b do tmp_file.do
Abort trap: 6

Attached you can see the full log.
tmp_file.log

I also tried running the same commands in the Stata gui and it still crashes.

@mcaceresb
Copy link
Owner Author

Ok, it seems that's a memory error, so it may be that I'm not being careful about allocating all the internal arrays and I just haven't noticed because GCC in other systems is trying to fix it for me. If this is the case it's very fixable. Let's check:

  1. Create a sub-directory called test

  2. Download spooky_test.txt and rename it spooky_test.c. Put it in test

  3. Compile with

gcc -Wall -bundle -DSYSTEM=APPLEMAC lib/spi-2.0/stplugin.c test/spooky_test.c lib/spookyhash/build/bin/Release/libspookyhash.a -o test/spooky_test.plugin
  1. In test, create a do file with
program spooky_test, plugin using(spooky_test.plugin)
sysuse auto
plugin call spooky_test make price, check
plugin call spooky_test make price, read
plugin call spooky_test make price, spooky

and run it via stata-mp. Attach the log.

@fbelotti
Copy link

fbelotti commented Oct 4, 2017

tmp_file.log

@mcaceresb
Copy link
Owner Author

Ok, that's good news. There isn't a bug with spookyhash or calling it from Stata. The problem is the memory allocation. This means somewhere I define some string or array to be shorter than Stata expects it to be...

I will go through my code and double check everything. By the way, do the following run? (From the build directory using stata-mp)

sysuse auto
gcollapse price, by(foreign) v b
gcollapse foreign, by(price) v b

The internal code handles integers, floats and strings differently so this will give me a clue as to where my mistake is. Thanks a lot for helping narrow down the issue.

@fbelotti
Copy link

fbelotti commented Oct 5, 2017

You are welcome! This helps me a lot in understanding how Stata plugin works. Attached the log file.
tmp_file.log

@mcaceresb
Copy link
Owner Author

I'll be pushing the new version tomorrow. I've made it so every array is allocated, so hopefully there won't be any memory leaks. Before I do that, I want to try and fix the mishap where Stata in batch mode thinks it is in Unix. Can you tell me what happens when you run this from the command line (i.e. using stata-mp on a do file)?

di "`c(machine_type)'"

@fbelotti
Copy link

fbelotti commented Oct 9, 2017

Great. This is what the machine_type macro looks like running stata-mp from terminal

. di "`c(machine_type)'"
Macintosh (Intel 64-bit)

@mcaceresb
Copy link
Owner Author

Ok. I have taken this into account. Please run

git fetch upstream
git checkout osx-plugin
git merge upstream/osx-plugin

And then re-compile the plugin and try to run the tests again (make should do to compile). Make sure you are on version 0.7.5; if it fails let me know.

@mcaceresb
Copy link
Owner Author

@fbelotti Just wanted to follow-up and see if you'd had time to re-try compiling the plugin and running the tests.

@fbelotti
Copy link

Hi Mauricio, sorry I didn't see your email.
I ran git fetch upstream from the stata-gtools-fork dir but I got

Federicos-MacBook-Pro:stata-gtools-fork federico$ git fetch upstream
fatal: 'upstream' does not appear to be a git repository
fatal: Could not read from remote repository.

@mcaceresb
Copy link
Owner Author

mcaceresb commented Oct 13, 2017

I always forget you have to add remotes. Here:

git remote add upstream https://github.com/mcaceresb/stata-gtools.git

Then re-run the commands. If there are merge conflicts on .ado, .c, .do, or .sthlp files, just accept the ones from upstream. If there are merge conflicts in other files let me know.

@fbelotti
Copy link

It seems that the git merge upstream/osx-plugin still fails. This is the output.:

Federicos-MacBook-Pro:stata-gtools-fork federico$ git remote add upstream https://github.com/mcaceresb/stata-gtools.git
Federicos-MacBook-Pro:stata-gtools-fork federico$ git checkout osx-plugin
M	build/changelog.md
M	build/env_set_windows.plugin
M	build/gcollapse.ado
M	build/gcollapse.sthlp
M	build/gegen.ado
M	build/gegen.sthlp
M	build/gisid.ado
M	build/gisid.sthlp
M	build/glevelsof.ado
M	build/glevelsof.sthlp
M	build/gtools.ado
M	build/gtools.pkg
M	build/gtools.sthlp
M	build/gtools_tests.do
M	build/gtools_windows.plugin
M	build/spookyhash.dll
M	build/stata.toc
M	lib/spookyhash
M	lib/spt-0.2/st_gentools.c
Already on 'osx-plugin'
Your branch is up-to-date with 'origin/osx-plugin'.
Federicos-MacBook-Pro:stata-gtools-fork federico$ git merge upstream/osx-plugin
merge: upstream/osx-plugin - not something we can merge

@mcaceresb
Copy link
Owner Author

Perhaps it is due to the changes. Let's see:

git commit -a -m "Working draft of OSX plugin (0.7.3)"
git fetch upstream
git merge upstream/osx-plugin

?

@fbelotti
Copy link

Hi Mauricio. I think I need to refresh my working copy. There is something wrong. Do I need to fork again from the rep?

@mcaceresb mcaceresb reopened this Oct 26, 2017
@mcaceresb
Copy link
Owner Author

mcaceresb commented Oct 26, 2017

Hi; apologies I have been AWAL. I decided to refactor the code base, which took some a while since I could only work on this on my spare time.

Anyway, could you start fresh? Several new commands and options have been added since we first started this thread.

git clone https://github.com/mcaceresb/stata-gtools
cd stata-gtools
git checkout osx-plugin
git submodule update --init --recursive
sed -i.bak -e '37,40d' ./lib/spookyhash/build/premake5.lua
make spooky PREMAKE=/Users/federico/Desktop/GiT/premake5/bin/release/premake5
make clean
make

If that works, go into build, start Stata, and run do gtools_tests.do. It might fail if it can't find libspookyhash.a; if it's not in lib/spookyhash/build/bin/Release/libspookyhash.a then it's almost surely in lib/spookyhash/build/libspookyhash.a; run

make SPOOKY=lib/spookyhash/build/libspookyhash.a

if the first make attempt failed.

@sergiocorreia
Copy link

By the way, a convenient alternative would be to use Travis-CI to build the files on multiple platforms on every commit. They support OS-X, Linux, and Windows. It can get a bit tricky to get the .travis.yml file set up, but once that's done, builds become incredibly easy.

@mcaceresb
Copy link
Owner Author

Travis does not have Stata, which is why I don't use it in this way. You will note that my .travis.yml file only runs make. The reason is that I only commit after running the set of tests I've written (and usually after pushing I install from the repo and re-run the tests just to double-check).

While I might forgo the second test, I don't think it's sensible to commit w/o testing the plugin at all because even a very minor mistake could cause a crash.

(As an aside, when did Travis add Windows support? I use appveyor to test windows bc I thought Travis only supported OSX and Linux.)

@sergiocorreia
Copy link

Sorry, it is indeed appveyor for Windows.

I agree that committing without testing is useful. One option then is to use git hooks to run the master do file with the tests?

One problem I envision is that it would be good that the three OSes have the same version, which means waiting for OSX users to run the update. This can be solved if you use Travis for the OSX build, with the caveat that errors that occur on OSX only will not be detected.

@mcaceresb
Copy link
Owner Author

If I manage to get OSX working and gtools to 1.0 then I would not commit to master with the OS versions out of sync, but I wouldn't mind committing to develop out of sync.

The OSX version already compiles and loads w/o error, btw, but the latest was that it crashed Stata; pretty sure I fixed that but it's wait and see for now. So I'm really uneasy about committing at all w/o running tests. I'd be happy to use travis if I knew I could get the tests running elsewhere, but I don't see how git hooks solves this. I still need OSX w Stata for that.

mcaceresb added a commit that referenced this issue Nov 1, 2017
gtools-0.9.0 (2017-11-01)

Features

- The plugin now works on OSX
- Online documentation is now available: [gtools.readthedocs.io](http://gtools.readthedocs.io/en/latest/index.html)
- `gcontract` is a fast alternative to `contrast`
- `gtoplevelsof` is a new command that allows the user to glean the most
  common levels of a set of variables.  Similar to `gcontract` with a `gsort`
  of frequency by descending order thereafter, but `gtoplevelsof` does not
  modify the source data and saves a matrix with the results after its run.
- `gdistinct` now saves its results to a matrix when there are multiple
  variables.
- Improved and normalized documentation

Bug fixes

- OSX version; fixes #11
- `gisid` now sient w/o benchmark or verbose; fixes #20
- Added quotes to `cd cwd` in `gtools`; fixes #22
- `gcontract` available; fixes #23
@mcaceresb
Copy link
Owner Author

@fbelotti : Thanks for all your help debugging this. I was able to compile on a MacbookAir I was lent with all tests passing, so I closed the issue. 0.9.0 in master should include a full-featured OSX version.

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

No branches or pull requests

3 participants