Skip to content

Commit

Permalink
gyp working
Browse files Browse the repository at this point in the history
- generates valid xcode project
- generates valid Makefile
- doesn't generate ninja at all
  • Loading branch information
thlorenz committed Oct 5, 2014
1 parent 64da643 commit 888e151
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -13,3 +13,7 @@ results

npm-debug.log
node_modules
deps
build
out
*.xcodeproj
112 changes: 112 additions & 0 deletions gyp_learnuv.py
@@ -0,0 +1,112 @@
#!/usr/bin/env python

import glob
import platform
import os
import subprocess
import sys

try:
import multiprocessing.synchronize
gyp_parallel_support = True
except ImportError:
gyp_parallel_support = False


CC = os.environ.get('CC', 'cc')
script_dir = os.path.dirname(__file__)
learnuv_root = os.path.normpath(script_dir)
uv_root = os.path.join(os.path.abspath(learnuv_root), 'deps', 'libuv')
output_dir = os.path.join(os.path.abspath(learnuv_root), 'out')

sys.path.insert(0, os.path.join(learnuv_root, 'build', 'gyp', 'pylib'))
try:
import gyp
except ImportError:
print('You need to install gyp in build/gyp first. See the README.')
sys.exit(42)


def host_arch():
machine = platform.machine()
if machine == 'i386': return 'ia32'
if machine == 'x86_64': return 'x64'
if machine.startswith('arm'): return 'arm'
if machine.startswith('mips'): return 'mips'
return machine # Return as-is and hope for the best.


def compiler_version():
proc = subprocess.Popen(CC.split() + ['--version'], stdout=subprocess.PIPE)
is_clang = 'clang' in proc.communicate()[0].split('\n')[0]
proc = subprocess.Popen(CC.split() + ['-dumpversion'], stdout=subprocess.PIPE)
version = proc.communicate()[0].split('.')
version = map(int, version[:2])
version = tuple(version)
return (version, is_clang)


def run_gyp(args):
rc = gyp.main(args)
if rc != 0:
print 'Error running GYP'
sys.exit(rc)


if __name__ == '__main__':
args = sys.argv[1:]

# GYP bug.
# On msvs it will crash if it gets an absolute path.
# On Mac/make it will crash if it doesn't get an absolute path.
if sys.platform == 'win32':
args.append(os.path.join(learnuv_root, 'learnuv.gyp'))
common_fn = os.path.join(uv_root, 'common.gypi')
options_fn = os.path.join(uv_root, 'options.gypi')
# we force vs 2010 over 2008 which would otherwise be the default for gyp
if not os.environ.get('GYP_MSVS_VERSION'):
os.environ['GYP_MSVS_VERSION'] = '2010'
else:
args.append(os.path.join(os.path.abspath(learnuv_root), 'learnuv.gyp'))
common_fn = os.path.join(os.path.abspath(uv_root), 'common.gypi')
options_fn = os.path.join(os.path.abspath(uv_root), 'options.gypi')

if os.path.exists(common_fn):
args.extend(['-I', common_fn])

if os.path.exists(options_fn):
args.extend(['-I', options_fn])

args.append('--depth=' + learnuv_root)

# There's a bug with windows which doesn't allow this feature.
if sys.platform != 'win32':
if '-f' not in args:
args.extend('-f make'.split())
if 'eclipse' not in args and 'ninja' not in args:
args.extend(['-Goutput_dir=' + output_dir])
args.extend(['--generator-output', output_dir])
(major, minor), is_clang = compiler_version()
args.append('-Dgcc_version=%d' % (10 * major + minor))
args.append('-Dclang=%d' % int(is_clang))

if not any(a.startswith('-Dhost_arch=') for a in args):
args.append('-Dhost_arch=%s' % host_arch())

if not any(a.startswith('-Dtarget_arch=') for a in args):
args.append('-Dtarget_arch=%s' % host_arch())

if not any(a.startswith('-Duv_library=') for a in args):
args.append('-Duv_library=static_library')

if not any(a.startswith('-Dcomponent=') for a in args):
args.append('-Dcomponent=static_library')

# Some platforms (OpenBSD for example) don't have multiprocessing.synchronize
# so gyp must be run with --no-parallel
if not gyp_parallel_support:
args.append('--no-parallel')

gyp_args = list(args)
print gyp_args
run_gyp(gyp_args)
11 changes: 11 additions & 0 deletions learnuv.gyp
@@ -0,0 +1,11 @@
{
'targets': [
{
'target_name': 'learnuv_ex01',
'type': 'executable',
'dependencies': [ './deps/libuv/uv.gyp:libuv' ],
'include_dirs': [ './src/ex01' ],
'sources' : [ './src/ex01/ex01_main.c' ]
}
]
}
7 changes: 2 additions & 5 deletions package.json
Expand Up @@ -4,11 +4,8 @@
"description" : " Learn uv for fun and profit, a self guided workshop to the library that powers Node.js.",
"main" : "index.js",
"scripts" : {
"test-main" : "tap test/*.js",
"test-0.8" : "nave use 0.8 npm run test-main",
"test-0.10" : "nave use 0.10 npm run test-main",
"test-all": "npm run test-main && npm run test-0.8 && npm run test-0.10",
"test" : "if [ -e $TRAVIS ]; then npm run test-all; else npm run test-main; fi"
"clean": "rm -rf build && rm -rf deps",
"preinstall": "python scripts/install-dependencies.py"
},
"repository" : {
"type" : "git",
Expand Down
30 changes: 30 additions & 0 deletions scripts/install-dependencies.py
@@ -0,0 +1,30 @@
#!/usr/bin/env python

from subprocess import call
import os

script_dir = os.path.dirname(__file__)
root_dir = os.path.join(os.path.abspath(script_dir), '..')
deps_dir = os.path.join(root_dir, 'deps')
libuv_dir = os.path.join(deps_dir, 'libuv')
build_dir = os.path.join(root_dir, 'build')
gyp_dir = os.path.join(build_dir, 'gyp')

def mkdirp(dir):
try:
os.mkdir(dir)
except OSError:
pass

def run(cmd):
print '\033[0;32mlearnuv\033[0m executing: ' + cmd
os.system(cmd)

# libuv
mkdirp(deps_dir)
## todo: This may not work with older git versions (http://stackoverflow.com/questions/20280726/how-to-git-clone-a-specific-tag)
run('git clone --depth 1 --branch v1.0.0-rc1 https://github.com/joyent/libuv.git ' + libuv_dir)

# gyp
mkdirp(build_dir)
run('git clone https://git.chromium.org/external/gyp.git ' + gyp_dir)
23 changes: 23 additions & 0 deletions src/ex01/ex01_main.c
@@ -0,0 +1,23 @@
#include <stdio.h>
#include "uv.h"

void idle_cb(uv_idle_t* handle) {
static int64_t count = -1;
count++;
if ((count % 10000) == 0) fprintf(stderr, ".");
if (count >= 10e6) uv_idle_stop(handle);
}

int main() {
uv_idle_t idle_handle;

uv_loop_t *loop = uv_default_loop();
uv_idle_init(loop, &idle_handle);
uv_idle_start(&idle_handle, idle_cb);

fprintf(stderr, "\nidling ...\n");
uv_run(loop, UV_RUN_DEFAULT);

return 0;
}

0 comments on commit 888e151

Please sign in to comment.