diff --git a/conversions/index.js b/conversions/index.js index 619f79a..b32d7f6 100644 --- a/conversions/index.js +++ b/conversions/index.js @@ -116,5 +116,48 @@ describe('loose conversions', function() { }); }); + + describe('pass_object()', function () { + /* pass_object accepts any object and extracts numeric x/y properties. It + then constructs a new object with the sum and product of x/y. It + demonstrates how properties can be handled with objects in V8. + */ + + it('should fully compute properties given object with required properties', function () { + assert.equal(13, loose.pass_object({x:3, y:10}).sum); + assert.equal(30, loose.pass_object({x:3, y:10}).product); + }); + it('should set sum and product to NaN given object without x or y', function () { + assert(13, isNaN(loose.pass_object({y:10}).sum)); + assert(30, isNaN(loose.pass_object({x:3}).product)); + assert(isNaN(loose.pass_object({x:3, y:"hello"}).product)); + }); + it('should fully compute properties given object with required properties - even when not pure numerics', function () { + assert.equal(4, loose.pass_object({x:3, y:true}).sum); + assert.equal(30, loose.pass_object({x:3, y:"10"}).product); + assert.equal(0, loose.pass_object({x:3, y:null}).product); + }); + }); + + + + describe('pass_array()', function () { + /* pass_array accepts an array (input) and assumes it has 3 numeric elements at index 0-2. + It also looks for an additional property called "not_index". + It contstructs a new array consisting of [input[0]+1, input.not_index, input[2]+1]. + No one said these functions should be sensible ;) + */ + + it('should fully compute given expected array', function () { + var a = [4, 7, 9]; + a.not_index = "hello"; + assert.deepEqual([5, "hello", 10], loose.pass_array(a)); + }); + it('should return array with undefined values given incomplete input', function() { + assert.deepEqual([2, undefined, 4], loose.pass_array([1, 2, 3])); + assert.deepEqual([2, undefined, undefined], loose.pass_array([1, 2])); + assert.deepEqual([undefined, undefined, undefined], loose.pass_array([])); + }); + }); }); diff --git a/conversions/loose/build/Makefile b/conversions/loose/build/Makefile index d605800..f7258ea 100644 --- a/conversions/loose/build/Makefile +++ b/conversions/loose/build/Makefile @@ -41,9 +41,9 @@ all_deps := CC.target ?= $(CC) -CFLAGS.target ?= $(CFLAGS) +CFLAGS.target ?= $(CPPFLAGS) $(CFLAGS) CXX.target ?= $(CXX) -CXXFLAGS.target ?= $(CXXFLAGS) +CXXFLAGS.target ?= $(CPPFLAGS) $(CXXFLAGS) LINK.target ?= $(LINK) LDFLAGS.target ?= $(LDFLAGS) AR.target ?= $(AR) @@ -54,9 +54,9 @@ LINK ?= $(CXX.target) # TODO(evan): move all cross-compilation logic to gyp-time so we don't need # to replicate this environment fallback in make as well. CC.host ?= gcc -CFLAGS.host ?= +CFLAGS.host ?= $(CPPFLAGS_host) $(CFLAGS_host) CXX.host ?= g++ -CXXFLAGS.host ?= +CXXFLAGS.host ?= $(CPPFLAGS_host) $(CXXFLAGS_host) LINK.host ?= $(CXX.host) LDFLAGS.host ?= AR.host ?= ar @@ -126,6 +126,34 @@ cmd_cc = $(CC.$(TOOLSET)) $(GYP_CFLAGS) $(DEPFLAGS) $(CFLAGS.$(TOOLSET)) -c -o $ quiet_cmd_cxx = CXX($(TOOLSET)) $@ cmd_cxx = $(CXX.$(TOOLSET)) $(GYP_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $< +quiet_cmd_objc = CXX($(TOOLSET)) $@ +cmd_objc = $(CC.$(TOOLSET)) $(GYP_OBJCFLAGS) $(DEPFLAGS) -c -o $@ $< + +quiet_cmd_objcxx = CXX($(TOOLSET)) $@ +cmd_objcxx = $(CXX.$(TOOLSET)) $(GYP_OBJCXXFLAGS) $(DEPFLAGS) -c -o $@ $< + +# Commands for precompiled header files. +quiet_cmd_pch_c = CXX($(TOOLSET)) $@ +cmd_pch_c = $(CC.$(TOOLSET)) $(GYP_PCH_CFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $< +quiet_cmd_pch_cc = CXX($(TOOLSET)) $@ +cmd_pch_cc = $(CC.$(TOOLSET)) $(GYP_PCH_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $< +quiet_cmd_pch_m = CXX($(TOOLSET)) $@ +cmd_pch_m = $(CC.$(TOOLSET)) $(GYP_PCH_OBJCFLAGS) $(DEPFLAGS) -c -o $@ $< +quiet_cmd_pch_mm = CXX($(TOOLSET)) $@ +cmd_pch_mm = $(CC.$(TOOLSET)) $(GYP_PCH_OBJCXXFLAGS) $(DEPFLAGS) -c -o $@ $< + +# gyp-mac-tool is written next to the root Makefile by gyp. +# Use $(4) for the command, since $(2) and $(3) are used as flag by do_cmd +# already. +quiet_cmd_mac_tool = MACTOOL $(4) $< +cmd_mac_tool = ./gyp-mac-tool $(4) $< "$@" + +quiet_cmd_mac_package_framework = PACKAGE FRAMEWORK $@ +cmd_mac_package_framework = ./gyp-mac-tool package-framework "$@" $(4) + +quiet_cmd_infoplist = INFOPLIST $@ +cmd_infoplist = $(CC.$(TOOLSET)) -E -P -Wno-trigraphs -x c $(INFOPLIST_DEFINES) "$<" -o "$@" + quiet_cmd_touch = TOUCH $@ cmd_touch = touch $@ @@ -133,39 +161,17 @@ quiet_cmd_copy = COPY $@ # send stderr to /dev/null to ignore messages when linking directories. cmd_copy = rm -rf "$@" && cp -af "$<" "$@" -quiet_cmd_alink = AR($(TOOLSET)) $@ -cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^) +quiet_cmd_alink = LIBTOOL-STATIC $@ +cmd_alink = rm -f $@ && ./gyp-mac-tool filter-libtool libtool $(GYP_LIBTOOLFLAGS) -static -o $@ $(filter %.o,$^) -quiet_cmd_alink_thin = AR($(TOOLSET)) $@ -cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^) - -# Due to circular dependencies between libraries :(, we wrap the -# special "figure out circular dependencies" flags around the entire -# input list during linking. quiet_cmd_link = LINK($(TOOLSET)) $@ -cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS) - -# We support two kinds of shared objects (.so): -# 1) shared_library, which is just bundling together many dependent libraries -# into a link line. -# 2) loadable_module, which is generating a module intended for dlopen(). -# -# They differ only slightly: -# In the former case, we want to package all dependent code into the .so. -# In the latter case, we want to package just the API exposed by the -# outermost module. -# This means shared_library uses --whole-archive, while loadable_module doesn't. -# (Note that --whole-archive is incompatible with the --start-group used in -# normal linking.) - -# Other shared-object link notes: -# - Set SONAME to the library filename so our binaries don't reference -# the local, absolute paths used on the link command-line. +cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o "$@" $(LD_INPUTS) $(LIBS) + quiet_cmd_solink = SOLINK($(TOOLSET)) $@ -cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--whole-archive $(LD_INPUTS) -Wl,--no-whole-archive $(LIBS) +cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o "$@" $(LD_INPUTS) $(LIBS) quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@ -cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--start-group $(filter-out FORCE_DO_CMD, $^) -Wl,--end-group $(LIBS) +cmd_solink_module = $(LINK.$(TOOLSET)) -bundle $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS) # Define an escape_quotes function to escape single quotes. @@ -230,7 +236,7 @@ define do_cmd $(if $(or $(command_changed),$(prereq_changed)), @$(call exact_echo, $($(quiet)cmd_$(1))) @mkdir -p "$(call dirx,$@)" "$(dir $(depfile))" - $(if $(findstring flock,$(word 1,$(cmd_$1))), + $(if $(findstring flock,$(word 2,$(cmd_$1))), @$(cmd_$(1)) @echo " $(quiet_cmd_$(1)): Finished", @$(cmd_$(1)) @@ -268,6 +274,10 @@ $(obj).$(TOOLSET)/%.o: $(srcdir)/%.cpp FORCE_DO_CMD @$(call do_cmd,cxx,1) $(obj).$(TOOLSET)/%.o: $(srcdir)/%.cxx FORCE_DO_CMD @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.m FORCE_DO_CMD + @$(call do_cmd,objc,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.mm FORCE_DO_CMD + @$(call do_cmd,objcxx,1) $(obj).$(TOOLSET)/%.o: $(srcdir)/%.S FORCE_DO_CMD @$(call do_cmd,cc,1) $(obj).$(TOOLSET)/%.o: $(srcdir)/%.s FORCE_DO_CMD @@ -282,6 +292,10 @@ $(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cpp FORCE_DO_CMD @$(call do_cmd,cxx,1) $(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cxx FORCE_DO_CMD @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.m FORCE_DO_CMD + @$(call do_cmd,objc,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.mm FORCE_DO_CMD + @$(call do_cmd,objcxx,1) $(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.S FORCE_DO_CMD @$(call do_cmd,cc,1) $(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.s FORCE_DO_CMD @@ -295,6 +309,10 @@ $(obj).$(TOOLSET)/%.o: $(obj)/%.cpp FORCE_DO_CMD @$(call do_cmd,cxx,1) $(obj).$(TOOLSET)/%.o: $(obj)/%.cxx FORCE_DO_CMD @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.m FORCE_DO_CMD + @$(call do_cmd,objc,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.mm FORCE_DO_CMD + @$(call do_cmd,objcxx,1) $(obj).$(TOOLSET)/%.o: $(obj)/%.S FORCE_DO_CMD @$(call do_cmd,cc,1) $(obj).$(TOOLSET)/%.o: $(obj)/%.s FORCE_DO_CMD @@ -308,8 +326,8 @@ ifeq ($(strip $(foreach prefix,$(NO_LOAD),\ endif quiet_cmd_regen_makefile = ACTION Regenerating $@ -cmd_regen_makefile = cd $(srcdir); /home/sfrees/.node/lib/node_modules/node-gyp/gyp/gyp_main.py -fmake --ignore-environment "--toplevel-dir=." -I/home/sfrees/projects/nodecpp-demo/conversions/loose/build/config.gypi -I/home/sfrees/.node/lib/node_modules/node-gyp/addon.gypi -I/home/sfrees/.node-gyp/4.0.0/common.gypi "--depth=." "-Goutput_dir=." "--generator-output=build" "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/home/sfrees/.node-gyp/4.0.0" "-Dnode_gyp_dir=/home/sfrees/.node/lib/node_modules/node-gyp" "-Dmodule_root_dir=/home/sfrees/projects/nodecpp-demo/conversions/loose" binding.gyp -Makefile: $(srcdir)/../../../../.node-gyp/4.0.0/common.gypi $(srcdir)/../../../../.node/lib/node_modules/node-gyp/addon.gypi $(srcdir)/build/config.gypi $(srcdir)/binding.gyp +cmd_regen_makefile = cd $(srcdir); /usr/local/lib/node_modules/node-gyp/gyp/gyp_main.py -fmake --ignore-environment "--toplevel-dir=." -I/Users/sfrees/projects/nodecpp-demo/conversions/loose/build/config.gypi -I/usr/local/lib/node_modules/node-gyp/addon.gypi -I/Users/sfrees/.node-gyp/0.12.5/common.gypi "--depth=." "-Goutput_dir=." "--generator-output=build" "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/Users/sfrees/.node-gyp/0.12.5" "-Dnode_gyp_dir=/usr/local/lib/node_modules/node-gyp" "-Dnode_lib_file=node.lib" "-Dmodule_root_dir=/Users/sfrees/projects/nodecpp-demo/conversions/loose" binding.gyp +Makefile: $(srcdir)/../../../../../../usr/local/lib/node_modules/node-gyp/addon.gypi $(srcdir)/../../../../.node-gyp/0.12.5/common.gypi $(srcdir)/build/config.gypi $(srcdir)/binding.gyp $(call do_cmd,regen_makefile) # "all" is a concatenation of the "all" targets from all the included diff --git a/conversions/loose/build/Release/.deps/Release/loose_type_demo.node.d b/conversions/loose/build/Release/.deps/Release/loose_type_demo.node.d index 125579c..0f7c0e9 100644 --- a/conversions/loose/build/Release/.deps/Release/loose_type_demo.node.d +++ b/conversions/loose/build/Release/.deps/Release/loose_type_demo.node.d @@ -1 +1 @@ -cmd_Release/loose_type_demo.node := rm -rf "Release/loose_type_demo.node" && cp -af "Release/obj.target/loose_type_demo.node" "Release/loose_type_demo.node" +cmd_Release/loose_type_demo.node := c++ -bundle -undefined dynamic_lookup -Wl,-search_paths_first -mmacosx-version-min=10.5 -arch x86_64 -L./Release -o Release/loose_type_demo.node Release/obj.target/loose_type_demo/loose_type_demo.o diff --git a/conversions/loose/build/Release/.deps/Release/obj.target/loose_type_demo/loose_type_demo.o.d b/conversions/loose/build/Release/.deps/Release/obj.target/loose_type_demo/loose_type_demo.o.d index 938dbaa..93d7f03 100644 --- a/conversions/loose/build/Release/.deps/Release/obj.target/loose_type_demo/loose_type_demo.o.d +++ b/conversions/loose/build/Release/.deps/Release/obj.target/loose_type_demo/loose_type_demo.o.d @@ -1,13 +1,13 @@ -cmd_Release/obj.target/loose_type_demo/loose_type_demo.o := g++ '-DNODE_GYP_MODULE_NAME=loose_type_demo' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DBUILDING_NODE_EXTENSION' -I/home/sfrees/.node-gyp/4.0.0/src -I/home/sfrees/.node-gyp/4.0.0/deps/uv/include -I/home/sfrees/.node-gyp/4.0.0/deps/v8/include -fPIC -pthread -Wall -Wextra -Wno-unused-parameter -m64 -O3 -ffunction-sections -fdata-sections -fno-omit-frame-pointer -fno-rtti -fno-exceptions -std=gnu++0x -MMD -MF ./Release/.deps/Release/obj.target/loose_type_demo/loose_type_demo.o.d.raw -c -o Release/obj.target/loose_type_demo/loose_type_demo.o ../loose_type_demo.cpp +cmd_Release/obj.target/loose_type_demo/loose_type_demo.o := c++ '-DNODE_GYP_MODULE_NAME=loose_type_demo' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DBUILDING_NODE_EXTENSION' -I/Users/sfrees/.node-gyp/0.12.5/include/node -I/Users/sfrees/.node-gyp/0.12.5/src -I/Users/sfrees/.node-gyp/0.12.5/deps/uv/include -I/Users/sfrees/.node-gyp/0.12.5/deps/v8/include -Os -gdwarf-2 -mmacosx-version-min=10.5 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-rtti -fno-exceptions -fno-threadsafe-statics -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/loose_type_demo/loose_type_demo.o.d.raw -c -o Release/obj.target/loose_type_demo/loose_type_demo.o ../loose_type_demo.cpp Release/obj.target/loose_type_demo/loose_type_demo.o: \ - ../loose_type_demo.cpp /home/sfrees/.node-gyp/4.0.0/src/node.h \ - /home/sfrees/.node-gyp/4.0.0/deps/v8/include/v8.h \ - /home/sfrees/.node-gyp/4.0.0/deps/v8/include/v8-version.h \ - /home/sfrees/.node-gyp/4.0.0/deps/v8/include/v8config.h \ - /home/sfrees/.node-gyp/4.0.0/src/node_version.h + ../loose_type_demo.cpp /Users/sfrees/.node-gyp/0.12.5/src/node.h \ + /Users/sfrees/.node-gyp/0.12.5/deps/v8/include/v8.h \ + /Users/sfrees/.node-gyp/0.12.5/deps/v8/include/v8stdint.h \ + /Users/sfrees/.node-gyp/0.12.5/deps/v8/include/v8config.h \ + /Users/sfrees/.node-gyp/0.12.5/src/node_version.h ../loose_type_demo.cpp: -/home/sfrees/.node-gyp/4.0.0/src/node.h: -/home/sfrees/.node-gyp/4.0.0/deps/v8/include/v8.h: -/home/sfrees/.node-gyp/4.0.0/deps/v8/include/v8-version.h: -/home/sfrees/.node-gyp/4.0.0/deps/v8/include/v8config.h: -/home/sfrees/.node-gyp/4.0.0/src/node_version.h: +/Users/sfrees/.node-gyp/0.12.5/src/node.h: +/Users/sfrees/.node-gyp/0.12.5/deps/v8/include/v8.h: +/Users/sfrees/.node-gyp/0.12.5/deps/v8/include/v8stdint.h: +/Users/sfrees/.node-gyp/0.12.5/deps/v8/include/v8config.h: +/Users/sfrees/.node-gyp/0.12.5/src/node_version.h: diff --git a/conversions/loose/build/Release/linker.lock b/conversions/loose/build/Release/linker.lock new file mode 100644 index 0000000..e69de29 diff --git a/conversions/loose/build/Release/loose_type_demo.node b/conversions/loose/build/Release/loose_type_demo.node index 75e439d..5bbc982 100755 Binary files a/conversions/loose/build/Release/loose_type_demo.node and b/conversions/loose/build/Release/loose_type_demo.node differ diff --git a/conversions/loose/build/Release/obj.target/loose_type_demo/loose_type_demo.o b/conversions/loose/build/Release/obj.target/loose_type_demo/loose_type_demo.o index bcf88d5..2767a45 100644 Binary files a/conversions/loose/build/Release/obj.target/loose_type_demo/loose_type_demo.o and b/conversions/loose/build/Release/obj.target/loose_type_demo/loose_type_demo.o differ diff --git a/conversions/loose/build/config.gypi b/conversions/loose/build/config.gypi index 21f2e07..1ba2db9 100644 --- a/conversions/loose/build/config.gypi +++ b/conversions/loose/build/config.gypi @@ -8,45 +8,44 @@ "libraries": [] }, "variables": { - "asan": 0, - "gas_version": "2.23", + "clang": 1, "host_arch": "x64", - "icu_data_file": "icudt55l.dat", - "icu_data_in": "../../deps/icu/source/data/in/icudt55l.dat", + "icu_data_file": "icudt54l.dat", + "icu_data_in": "../../deps/icu/source/data/in/icudt54l.dat", "icu_endianness": "l", "icu_gyp_path": "tools/icu/icu-generic.gyp", "icu_locales": "en,root", "icu_path": "./deps/icu", "icu_small": "true", - "icu_ver_major": "55", - "node_byteorder": "little", + "icu_ver_major": "54", "node_install_npm": "true", - "node_prefix": "/", - "node_release_urlbase": "https://nodejs.org/download/release/", + "node_prefix": "", + "node_shared_cares": "false", "node_shared_http_parser": "false", "node_shared_libuv": "false", "node_shared_openssl": "false", + "node_shared_v8": "false", "node_shared_zlib": "false", "node_tag": "", - "node_use_dtrace": "false", + "node_use_dtrace": "true", "node_use_etw": "false", - "node_use_lttng": "false", + "node_use_mdb": "false", "node_use_openssl": "true", "node_use_perfctr": "false", - "openssl_fips": "", "openssl_no_asm": 0, - "python": "/home/iojs/bin/python", + "python": "/usr/bin/python", "target_arch": "x64", + "uv_library": "static_library", "uv_parent_path": "/deps/uv/", - "uv_use_dtrace": "false", + "uv_use_dtrace": "true", "v8_enable_gdbjit": 0, "v8_enable_i18n_support": 1, "v8_no_strict_aliasing": 1, "v8_optimized_debug": 0, "v8_random_seed": 0, - "v8_use_snapshot": 1, + "v8_use_snapshot": "false", "want_separate_host_toolset": 0, - "nodedir": "/home/sfrees/.node-gyp/4.0.0", + "nodedir": "/Users/sfrees/.node-gyp/0.12.5", "copy_dev_lib": "true", "standalone_static_library": 1 } diff --git a/conversions/loose/build/gyp-mac-tool b/conversions/loose/build/gyp-mac-tool new file mode 100755 index 0000000..8ef02b0 --- /dev/null +++ b/conversions/loose/build/gyp-mac-tool @@ -0,0 +1,611 @@ +#!/usr/bin/env python +# Generated by gyp. Do not edit. +# Copyright (c) 2012 Google Inc. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Utility functions to perform Xcode-style build steps. + +These functions are executed via gyp-mac-tool when using the Makefile generator. +""" + +import fcntl +import fnmatch +import glob +import json +import os +import plistlib +import re +import shutil +import string +import subprocess +import sys +import tempfile + + +def main(args): + executor = MacTool() + exit_code = executor.Dispatch(args) + if exit_code is not None: + sys.exit(exit_code) + + +class MacTool(object): + """This class performs all the Mac tooling steps. The methods can either be + executed directly, or dispatched from an argument list.""" + + def Dispatch(self, args): + """Dispatches a string command to a method.""" + if len(args) < 1: + raise Exception("Not enough arguments") + + method = "Exec%s" % self._CommandifyName(args[0]) + return getattr(self, method)(*args[1:]) + + def _CommandifyName(self, name_string): + """Transforms a tool name like copy-info-plist to CopyInfoPlist""" + return name_string.title().replace('-', '') + + def ExecCopyBundleResource(self, source, dest, convert_to_binary): + """Copies a resource file to the bundle/Resources directory, performing any + necessary compilation on each resource.""" + extension = os.path.splitext(source)[1].lower() + if os.path.isdir(source): + # Copy tree. + # TODO(thakis): This copies file attributes like mtime, while the + # single-file branch below doesn't. This should probably be changed to + # be consistent with the single-file branch. + if os.path.exists(dest): + shutil.rmtree(dest) + shutil.copytree(source, dest) + elif extension == '.xib': + return self._CopyXIBFile(source, dest) + elif extension == '.storyboard': + return self._CopyXIBFile(source, dest) + elif extension == '.strings': + self._CopyStringsFile(source, dest, convert_to_binary) + else: + shutil.copy(source, dest) + + def _CopyXIBFile(self, source, dest): + """Compiles a XIB file with ibtool into a binary plist in the bundle.""" + + # ibtool sometimes crashes with relative paths. See crbug.com/314728. + base = os.path.dirname(os.path.realpath(__file__)) + if os.path.relpath(source): + source = os.path.join(base, source) + if os.path.relpath(dest): + dest = os.path.join(base, dest) + + args = ['xcrun', 'ibtool', '--errors', '--warnings', '--notices', + '--output-format', 'human-readable-text', '--compile', dest, source] + ibtool_section_re = re.compile(r'/\*.*\*/') + ibtool_re = re.compile(r'.*note:.*is clipping its content') + ibtoolout = subprocess.Popen(args, stdout=subprocess.PIPE) + current_section_header = None + for line in ibtoolout.stdout: + if ibtool_section_re.match(line): + current_section_header = line + elif not ibtool_re.match(line): + if current_section_header: + sys.stdout.write(current_section_header) + current_section_header = None + sys.stdout.write(line) + return ibtoolout.returncode + + def _ConvertToBinary(self, dest): + subprocess.check_call([ + 'xcrun', 'plutil', '-convert', 'binary1', '-o', dest, dest]) + + def _CopyStringsFile(self, source, dest, convert_to_binary): + """Copies a .strings file using iconv to reconvert the input into UTF-16.""" + input_code = self._DetectInputEncoding(source) or "UTF-8" + + # Xcode's CpyCopyStringsFile / builtin-copyStrings seems to call + # CFPropertyListCreateFromXMLData() behind the scenes; at least it prints + # CFPropertyListCreateFromXMLData(): Old-style plist parser: missing + # semicolon in dictionary. + # on invalid files. Do the same kind of validation. + import CoreFoundation + s = open(source, 'rb').read() + d = CoreFoundation.CFDataCreate(None, s, len(s)) + _, error = CoreFoundation.CFPropertyListCreateFromXMLData(None, d, 0, None) + if error: + return + + fp = open(dest, 'wb') + fp.write(s.decode(input_code).encode('UTF-16')) + fp.close() + + if convert_to_binary == 'True': + self._ConvertToBinary(dest) + + def _DetectInputEncoding(self, file_name): + """Reads the first few bytes from file_name and tries to guess the text + encoding. Returns None as a guess if it can't detect it.""" + fp = open(file_name, 'rb') + try: + header = fp.read(3) + except e: + fp.close() + return None + fp.close() + if header.startswith("\xFE\xFF"): + return "UTF-16" + elif header.startswith("\xFF\xFE"): + return "UTF-16" + elif header.startswith("\xEF\xBB\xBF"): + return "UTF-8" + else: + return None + + def ExecCopyInfoPlist(self, source, dest, convert_to_binary, *keys): + """Copies the |source| Info.plist to the destination directory |dest|.""" + # Read the source Info.plist into memory. + fd = open(source, 'r') + lines = fd.read() + fd.close() + + # Insert synthesized key/value pairs (e.g. BuildMachineOSBuild). + plist = plistlib.readPlistFromString(lines) + if keys: + plist = dict(plist.items() + json.loads(keys[0]).items()) + lines = plistlib.writePlistToString(plist) + + # Go through all the environment variables and replace them as variables in + # the file. + IDENT_RE = re.compile(r'[/\s]') + for key in os.environ: + if key.startswith('_'): + continue + evar = '${%s}' % key + evalue = os.environ[key] + lines = string.replace(lines, evar, evalue) + + # Xcode supports various suffices on environment variables, which are + # all undocumented. :rfc1034identifier is used in the standard project + # template these days, and :identifier was used earlier. They are used to + # convert non-url characters into things that look like valid urls -- + # except that the replacement character for :identifier, '_' isn't valid + # in a URL either -- oops, hence :rfc1034identifier was born. + evar = '${%s:identifier}' % key + evalue = IDENT_RE.sub('_', os.environ[key]) + lines = string.replace(lines, evar, evalue) + + evar = '${%s:rfc1034identifier}' % key + evalue = IDENT_RE.sub('-', os.environ[key]) + lines = string.replace(lines, evar, evalue) + + # Remove any keys with values that haven't been replaced. + lines = lines.split('\n') + for i in range(len(lines)): + if lines[i].strip().startswith("${"): + lines[i] = None + lines[i - 1] = None + lines = '\n'.join(filter(lambda x: x is not None, lines)) + + # Write out the file with variables replaced. + fd = open(dest, 'w') + fd.write(lines) + fd.close() + + # Now write out PkgInfo file now that the Info.plist file has been + # "compiled". + self._WritePkgInfo(dest) + + if convert_to_binary == 'True': + self._ConvertToBinary(dest) + + def _WritePkgInfo(self, info_plist): + """This writes the PkgInfo file from the data stored in Info.plist.""" + plist = plistlib.readPlist(info_plist) + if not plist: + return + + # Only create PkgInfo for executable types. + package_type = plist['CFBundlePackageType'] + if package_type != 'APPL': + return + + # The format of PkgInfo is eight characters, representing the bundle type + # and bundle signature, each four characters. If that is missing, four + # '?' characters are used instead. + signature_code = plist.get('CFBundleSignature', '????') + if len(signature_code) != 4: # Wrong length resets everything, too. + signature_code = '?' * 4 + + dest = os.path.join(os.path.dirname(info_plist), 'PkgInfo') + fp = open(dest, 'w') + fp.write('%s%s' % (package_type, signature_code)) + fp.close() + + def ExecFlock(self, lockfile, *cmd_list): + """Emulates the most basic behavior of Linux's flock(1).""" + # Rely on exception handling to report errors. + fd = os.open(lockfile, os.O_RDONLY|os.O_NOCTTY|os.O_CREAT, 0o666) + fcntl.flock(fd, fcntl.LOCK_EX) + return subprocess.call(cmd_list) + + def ExecFilterLibtool(self, *cmd_list): + """Calls libtool and filters out '/path/to/libtool: file: foo.o has no + symbols'.""" + libtool_re = re.compile(r'^.*libtool: file: .* has no symbols$') + libtool_re5 = re.compile( + r'^.*libtool: warning for library: ' + + r'.* the table of contents is empty ' + + r'\(no object file members in the library define global symbols\)$') + env = os.environ.copy() + # Ref: + # http://www.opensource.apple.com/source/cctools/cctools-809/misc/libtool.c + # The problem with this flag is that it resets the file mtime on the file to + # epoch=0, e.g. 1970-1-1 or 1969-12-31 depending on timezone. + env['ZERO_AR_DATE'] = '1' + libtoolout = subprocess.Popen(cmd_list, stderr=subprocess.PIPE, env=env) + _, err = libtoolout.communicate() + for line in err.splitlines(): + if not libtool_re.match(line) and not libtool_re5.match(line): + print >>sys.stderr, line + # Unconditionally touch the output .a file on the command line if present + # and the command succeeded. A bit hacky. + if not libtoolout.returncode: + for i in range(len(cmd_list) - 1): + if cmd_list[i] == "-o" and cmd_list[i+1].endswith('.a'): + os.utime(cmd_list[i+1], None) + break + return libtoolout.returncode + + def ExecPackageFramework(self, framework, version): + """Takes a path to Something.framework and the Current version of that and + sets up all the symlinks.""" + # Find the name of the binary based on the part before the ".framework". + binary = os.path.basename(framework).split('.')[0] + + CURRENT = 'Current' + RESOURCES = 'Resources' + VERSIONS = 'Versions' + + if not os.path.exists(os.path.join(framework, VERSIONS, version, binary)): + # Binary-less frameworks don't seem to contain symlinks (see e.g. + # chromium's out/Debug/org.chromium.Chromium.manifest/ bundle). + return + + # Move into the framework directory to set the symlinks correctly. + pwd = os.getcwd() + os.chdir(framework) + + # Set up the Current version. + self._Relink(version, os.path.join(VERSIONS, CURRENT)) + + # Set up the root symlinks. + self._Relink(os.path.join(VERSIONS, CURRENT, binary), binary) + self._Relink(os.path.join(VERSIONS, CURRENT, RESOURCES), RESOURCES) + + # Back to where we were before! + os.chdir(pwd) + + def _Relink(self, dest, link): + """Creates a symlink to |dest| named |link|. If |link| already exists, + it is overwritten.""" + if os.path.lexists(link): + os.remove(link) + os.symlink(dest, link) + + def ExecCompileXcassets(self, keys, *inputs): + """Compiles multiple .xcassets files into a single .car file. + + This invokes 'actool' to compile all the inputs .xcassets files. The + |keys| arguments is a json-encoded dictionary of extra arguments to + pass to 'actool' when the asset catalogs contains an application icon + or a launch image. + + Note that 'actool' does not create the Assets.car file if the asset + catalogs does not contains imageset. + """ + command_line = [ + 'xcrun', 'actool', '--output-format', 'human-readable-text', + '--compress-pngs', '--notices', '--warnings', '--errors', + ] + is_iphone_target = 'IPHONEOS_DEPLOYMENT_TARGET' in os.environ + if is_iphone_target: + platform = os.environ['CONFIGURATION'].split('-')[-1] + if platform not in ('iphoneos', 'iphonesimulator'): + platform = 'iphonesimulator' + command_line.extend([ + '--platform', platform, '--target-device', 'iphone', + '--target-device', 'ipad', '--minimum-deployment-target', + os.environ['IPHONEOS_DEPLOYMENT_TARGET'], '--compile', + os.path.abspath(os.environ['CONTENTS_FOLDER_PATH']), + ]) + else: + command_line.extend([ + '--platform', 'macosx', '--target-device', 'mac', + '--minimum-deployment-target', os.environ['MACOSX_DEPLOYMENT_TARGET'], + '--compile', + os.path.abspath(os.environ['UNLOCALIZED_RESOURCES_FOLDER_PATH']), + ]) + if keys: + keys = json.loads(keys) + for key, value in keys.iteritems(): + arg_name = '--' + key + if isinstance(value, bool): + if value: + command_line.append(arg_name) + elif isinstance(value, list): + for v in value: + command_line.append(arg_name) + command_line.append(str(v)) + else: + command_line.append(arg_name) + command_line.append(str(value)) + # Note: actool crashes if inputs path are relative, so use os.path.abspath + # to get absolute path name for inputs. + command_line.extend(map(os.path.abspath, inputs)) + subprocess.check_call(command_line) + + def ExecMergeInfoPlist(self, output, *inputs): + """Merge multiple .plist files into a single .plist file.""" + merged_plist = {} + for path in inputs: + plist = self._LoadPlistMaybeBinary(path) + self._MergePlist(merged_plist, plist) + plistlib.writePlist(merged_plist, output) + + def ExecCodeSignBundle(self, key, resource_rules, entitlements, provisioning): + """Code sign a bundle. + + This function tries to code sign an iOS bundle, following the same + algorithm as Xcode: + 1. copy ResourceRules.plist from the user or the SDK into the bundle, + 2. pick the provisioning profile that best match the bundle identifier, + and copy it into the bundle as embedded.mobileprovision, + 3. copy Entitlements.plist from user or SDK next to the bundle, + 4. code sign the bundle. + """ + resource_rules_path = self._InstallResourceRules(resource_rules) + substitutions, overrides = self._InstallProvisioningProfile( + provisioning, self._GetCFBundleIdentifier()) + entitlements_path = self._InstallEntitlements( + entitlements, substitutions, overrides) + subprocess.check_call([ + 'codesign', '--force', '--sign', key, '--resource-rules', + resource_rules_path, '--entitlements', entitlements_path, + os.path.join( + os.environ['TARGET_BUILD_DIR'], + os.environ['FULL_PRODUCT_NAME'])]) + + def _InstallResourceRules(self, resource_rules): + """Installs ResourceRules.plist from user or SDK into the bundle. + + Args: + resource_rules: string, optional, path to the ResourceRules.plist file + to use, default to "${SDKROOT}/ResourceRules.plist" + + Returns: + Path to the copy of ResourceRules.plist into the bundle. + """ + source_path = resource_rules + target_path = os.path.join( + os.environ['BUILT_PRODUCTS_DIR'], + os.environ['CONTENTS_FOLDER_PATH'], + 'ResourceRules.plist') + if not source_path: + source_path = os.path.join( + os.environ['SDKROOT'], 'ResourceRules.plist') + shutil.copy2(source_path, target_path) + return target_path + + def _InstallProvisioningProfile(self, profile, bundle_identifier): + """Installs embedded.mobileprovision into the bundle. + + Args: + profile: string, optional, short name of the .mobileprovision file + to use, if empty or the file is missing, the best file installed + will be used + bundle_identifier: string, value of CFBundleIdentifier from Info.plist + + Returns: + A tuple containing two dictionary: variables substitutions and values + to overrides when generating the entitlements file. + """ + source_path, provisioning_data, team_id = self._FindProvisioningProfile( + profile, bundle_identifier) + target_path = os.path.join( + os.environ['BUILT_PRODUCTS_DIR'], + os.environ['CONTENTS_FOLDER_PATH'], + 'embedded.mobileprovision') + shutil.copy2(source_path, target_path) + substitutions = self._GetSubstitutions(bundle_identifier, team_id + '.') + return substitutions, provisioning_data['Entitlements'] + + def _FindProvisioningProfile(self, profile, bundle_identifier): + """Finds the .mobileprovision file to use for signing the bundle. + + Checks all the installed provisioning profiles (or if the user specified + the PROVISIONING_PROFILE variable, only consult it) and select the most + specific that correspond to the bundle identifier. + + Args: + profile: string, optional, short name of the .mobileprovision file + to use, if empty or the file is missing, the best file installed + will be used + bundle_identifier: string, value of CFBundleIdentifier from Info.plist + + Returns: + A tuple of the path to the selected provisioning profile, the data of + the embedded plist in the provisioning profile and the team identifier + to use for code signing. + + Raises: + SystemExit: if no .mobileprovision can be used to sign the bundle. + """ + profiles_dir = os.path.join( + os.environ['HOME'], 'Library', 'MobileDevice', 'Provisioning Profiles') + if not os.path.isdir(profiles_dir): + print >>sys.stderr, ( + 'cannot find mobile provisioning for %s' % bundle_identifier) + sys.exit(1) + provisioning_profiles = None + if profile: + profile_path = os.path.join(profiles_dir, profile + '.mobileprovision') + if os.path.exists(profile_path): + provisioning_profiles = [profile_path] + if not provisioning_profiles: + provisioning_profiles = glob.glob( + os.path.join(profiles_dir, '*.mobileprovision')) + valid_provisioning_profiles = {} + for profile_path in provisioning_profiles: + profile_data = self._LoadProvisioningProfile(profile_path) + app_id_pattern = profile_data.get( + 'Entitlements', {}).get('application-identifier', '') + for team_identifier in profile_data.get('TeamIdentifier', []): + app_id = '%s.%s' % (team_identifier, bundle_identifier) + if fnmatch.fnmatch(app_id, app_id_pattern): + valid_provisioning_profiles[app_id_pattern] = ( + profile_path, profile_data, team_identifier) + if not valid_provisioning_profiles: + print >>sys.stderr, ( + 'cannot find mobile provisioning for %s' % bundle_identifier) + sys.exit(1) + # If the user has multiple provisioning profiles installed that can be + # used for ${bundle_identifier}, pick the most specific one (ie. the + # provisioning profile whose pattern is the longest). + selected_key = max(valid_provisioning_profiles, key=lambda v: len(v)) + return valid_provisioning_profiles[selected_key] + + def _LoadProvisioningProfile(self, profile_path): + """Extracts the plist embedded in a provisioning profile. + + Args: + profile_path: string, path to the .mobileprovision file + + Returns: + Content of the plist embedded in the provisioning profile as a dictionary. + """ + with tempfile.NamedTemporaryFile() as temp: + subprocess.check_call([ + 'security', 'cms', '-D', '-i', profile_path, '-o', temp.name]) + return self._LoadPlistMaybeBinary(temp.name) + + def _MergePlist(self, merged_plist, plist): + """Merge |plist| into |merged_plist|.""" + for key, value in plist.iteritems(): + if isinstance(value, dict): + merged_value = merged_plist.get(key, {}) + if isinstance(merged_value, dict): + self._MergePlist(merged_value, value) + merged_plist[key] = merged_value + else: + merged_plist[key] = value + else: + merged_plist[key] = value + + def _LoadPlistMaybeBinary(self, plist_path): + """Loads into a memory a plist possibly encoded in binary format. + + This is a wrapper around plistlib.readPlist that tries to convert the + plist to the XML format if it can't be parsed (assuming that it is in + the binary format). + + Args: + plist_path: string, path to a plist file, in XML or binary format + + Returns: + Content of the plist as a dictionary. + """ + try: + # First, try to read the file using plistlib that only supports XML, + # and if an exception is raised, convert a temporary copy to XML and + # load that copy. + return plistlib.readPlist(plist_path) + except: + pass + with tempfile.NamedTemporaryFile() as temp: + shutil.copy2(plist_path, temp.name) + subprocess.check_call(['plutil', '-convert', 'xml1', temp.name]) + return plistlib.readPlist(temp.name) + + def _GetSubstitutions(self, bundle_identifier, app_identifier_prefix): + """Constructs a dictionary of variable substitutions for Entitlements.plist. + + Args: + bundle_identifier: string, value of CFBundleIdentifier from Info.plist + app_identifier_prefix: string, value for AppIdentifierPrefix + + Returns: + Dictionary of substitutions to apply when generating Entitlements.plist. + """ + return { + 'CFBundleIdentifier': bundle_identifier, + 'AppIdentifierPrefix': app_identifier_prefix, + } + + def _GetCFBundleIdentifier(self): + """Extracts CFBundleIdentifier value from Info.plist in the bundle. + + Returns: + Value of CFBundleIdentifier in the Info.plist located in the bundle. + """ + info_plist_path = os.path.join( + os.environ['TARGET_BUILD_DIR'], + os.environ['INFOPLIST_PATH']) + info_plist_data = self._LoadPlistMaybeBinary(info_plist_path) + return info_plist_data['CFBundleIdentifier'] + + def _InstallEntitlements(self, entitlements, substitutions, overrides): + """Generates and install the ${BundleName}.xcent entitlements file. + + Expands variables "$(variable)" pattern in the source entitlements file, + add extra entitlements defined in the .mobileprovision file and the copy + the generated plist to "${BundlePath}.xcent". + + Args: + entitlements: string, optional, path to the Entitlements.plist template + to use, defaults to "${SDKROOT}/Entitlements.plist" + substitutions: dictionary, variable substitutions + overrides: dictionary, values to add to the entitlements + + Returns: + Path to the generated entitlements file. + """ + source_path = entitlements + target_path = os.path.join( + os.environ['BUILT_PRODUCTS_DIR'], + os.environ['PRODUCT_NAME'] + '.xcent') + if not source_path: + source_path = os.path.join( + os.environ['SDKROOT'], + 'Entitlements.plist') + shutil.copy2(source_path, target_path) + data = self._LoadPlistMaybeBinary(target_path) + data = self._ExpandVariables(data, substitutions) + if overrides: + for key in overrides: + if key not in data: + data[key] = overrides[key] + plistlib.writePlist(data, target_path) + return target_path + + def _ExpandVariables(self, data, substitutions): + """Expands variables "$(variable)" in data. + + Args: + data: object, can be either string, list or dictionary + substitutions: dictionary, variable substitutions to perform + + Returns: + Copy of data where each references to "$(variable)" has been replaced + by the corresponding value found in substitutions, or left intact if + the key was not found. + """ + if isinstance(data, str): + for key, value in substitutions.iteritems(): + data = data.replace('$(%s)' % key, value) + return data + if isinstance(data, list): + return [self._ExpandVariables(v, substitutions) for v in data] + if isinstance(data, dict): + return {k: self._ExpandVariables(data[k], substitutions) for k in data} + return data + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) diff --git a/conversions/loose/build/loose_type_demo.target.mk b/conversions/loose/build/loose_type_demo.target.mk index 4a83ef3..f8fc32b 100644 --- a/conversions/loose/build/loose_type_demo.target.mk +++ b/conversions/loose/build/loose_type_demo.target.mk @@ -4,6 +4,7 @@ TOOLSET := target TARGET := loose_type_demo DEFS_Debug := \ '-DNODE_GYP_MODULE_NAME=loose_type_demo' \ + '-D_DARWIN_USE_64_BIT_INODE=1' \ '-D_LARGEFILE_SOURCE' \ '-D_FILE_OFFSET_BITS=64' \ '-DBUILDING_NODE_EXTENSION' \ @@ -12,61 +13,78 @@ DEFS_Debug := \ # Flags passed to all source files. CFLAGS_Debug := \ - -fPIC \ - -pthread \ + -O0 \ + -gdwarf-2 \ + -mmacosx-version-min=10.5 \ + -arch x86_64 \ -Wall \ - -Wextra \ - -Wno-unused-parameter \ - -m64 \ - -g \ - -O0 + -Wendif-labels \ + -W \ + -Wno-unused-parameter # Flags passed to only C files. -CFLAGS_C_Debug := +CFLAGS_C_Debug := \ + -fno-strict-aliasing # Flags passed to only C++ files. CFLAGS_CC_Debug := \ -fno-rtti \ -fno-exceptions \ - -std=gnu++0x + -fno-threadsafe-statics \ + -fno-strict-aliasing + +# Flags passed to only ObjC files. +CFLAGS_OBJC_Debug := + +# Flags passed to only ObjC++ files. +CFLAGS_OBJCC_Debug := INCS_Debug := \ - -I/home/sfrees/.node-gyp/4.0.0/src \ - -I/home/sfrees/.node-gyp/4.0.0/deps/uv/include \ - -I/home/sfrees/.node-gyp/4.0.0/deps/v8/include + -I/Users/sfrees/.node-gyp/0.12.5/include/node \ + -I/Users/sfrees/.node-gyp/0.12.5/src \ + -I/Users/sfrees/.node-gyp/0.12.5/deps/uv/include \ + -I/Users/sfrees/.node-gyp/0.12.5/deps/v8/include DEFS_Release := \ '-DNODE_GYP_MODULE_NAME=loose_type_demo' \ + '-D_DARWIN_USE_64_BIT_INODE=1' \ '-D_LARGEFILE_SOURCE' \ '-D_FILE_OFFSET_BITS=64' \ '-DBUILDING_NODE_EXTENSION' # Flags passed to all source files. CFLAGS_Release := \ - -fPIC \ - -pthread \ + -Os \ + -gdwarf-2 \ + -mmacosx-version-min=10.5 \ + -arch x86_64 \ -Wall \ - -Wextra \ - -Wno-unused-parameter \ - -m64 \ - -O3 \ - -ffunction-sections \ - -fdata-sections \ - -fno-omit-frame-pointer + -Wendif-labels \ + -W \ + -Wno-unused-parameter # Flags passed to only C files. -CFLAGS_C_Release := +CFLAGS_C_Release := \ + -fno-strict-aliasing # Flags passed to only C++ files. CFLAGS_CC_Release := \ -fno-rtti \ -fno-exceptions \ - -std=gnu++0x + -fno-threadsafe-statics \ + -fno-strict-aliasing + +# Flags passed to only ObjC files. +CFLAGS_OBJC_Release := + +# Flags passed to only ObjC++ files. +CFLAGS_OBJCC_Release := INCS_Release := \ - -I/home/sfrees/.node-gyp/4.0.0/src \ - -I/home/sfrees/.node-gyp/4.0.0/deps/uv/include \ - -I/home/sfrees/.node-gyp/4.0.0/deps/v8/include + -I/Users/sfrees/.node-gyp/0.12.5/include/node \ + -I/Users/sfrees/.node-gyp/0.12.5/src \ + -I/Users/sfrees/.node-gyp/0.12.5/deps/uv/include \ + -I/Users/sfrees/.node-gyp/0.12.5/deps/v8/include OBJS := \ $(obj).target/$(TARGET)/loose_type_demo.o @@ -79,6 +97,8 @@ all_deps += $(OBJS) $(OBJS): TOOLSET := $(TOOLSET) $(OBJS): GYP_CFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_C_$(BUILDTYPE)) $(OBJS): GYP_CXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_CC_$(BUILDTYPE)) +$(OBJS): GYP_OBJCFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_C_$(BUILDTYPE)) $(CFLAGS_OBJC_$(BUILDTYPE)) +$(OBJS): GYP_OBJCXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_CC_$(BUILDTYPE)) $(CFLAGS_OBJCC_$(BUILDTYPE)) # Suffix rules, putting all outputs into $(obj). @@ -96,37 +116,44 @@ $(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.cpp FORCE_DO_CMD # End of this set of suffix rules ### Rules for final target. LDFLAGS_Debug := \ - -pthread \ - -rdynamic \ - -m64 + -undefined dynamic_lookup \ + -Wl,-search_paths_first \ + -mmacosx-version-min=10.5 \ + -arch x86_64 \ + -L$(builddir) + +LIBTOOLFLAGS_Debug := \ + -undefined dynamic_lookup \ + -Wl,-search_paths_first LDFLAGS_Release := \ - -pthread \ - -rdynamic \ - -m64 + -undefined dynamic_lookup \ + -Wl,-search_paths_first \ + -mmacosx-version-min=10.5 \ + -arch x86_64 \ + -L$(builddir) + +LIBTOOLFLAGS_Release := \ + -undefined dynamic_lookup \ + -Wl,-search_paths_first LIBS := -$(obj).target/loose_type_demo.node: GYP_LDFLAGS := $(LDFLAGS_$(BUILDTYPE)) -$(obj).target/loose_type_demo.node: LIBS := $(LIBS) -$(obj).target/loose_type_demo.node: TOOLSET := $(TOOLSET) -$(obj).target/loose_type_demo.node: $(OBJS) FORCE_DO_CMD +$(builddir)/loose_type_demo.node: GYP_LDFLAGS := $(LDFLAGS_$(BUILDTYPE)) +$(builddir)/loose_type_demo.node: LIBS := $(LIBS) +$(builddir)/loose_type_demo.node: GYP_LIBTOOLFLAGS := $(LIBTOOLFLAGS_$(BUILDTYPE)) +$(builddir)/loose_type_demo.node: TOOLSET := $(TOOLSET) +$(builddir)/loose_type_demo.node: $(OBJS) FORCE_DO_CMD $(call do_cmd,solink_module) -all_deps += $(obj).target/loose_type_demo.node +all_deps += $(builddir)/loose_type_demo.node # Add target alias .PHONY: loose_type_demo loose_type_demo: $(builddir)/loose_type_demo.node -# Copy this to the executable output path. -$(builddir)/loose_type_demo.node: TOOLSET := $(TOOLSET) -$(builddir)/loose_type_demo.node: $(obj).target/loose_type_demo.node FORCE_DO_CMD - $(call do_cmd,copy) - -all_deps += $(builddir)/loose_type_demo.node # Short alias for building this executable. .PHONY: loose_type_demo.node -loose_type_demo.node: $(obj).target/loose_type_demo.node $(builddir)/loose_type_demo.node +loose_type_demo.node: $(builddir)/loose_type_demo.node # Add executable to "all" target. .PHONY: all diff --git a/conversions/loose/loose_type_demo.cpp b/conversions/loose/loose_type_demo.cpp index ab23789..6694645 100644 --- a/conversions/loose/loose_type_demo.cpp +++ b/conversions/loose/loose_type_demo.cpp @@ -72,9 +72,9 @@ void PassArray(const FunctionCallbackInfo& args) { Local prop = String::NewFromUtf8(isolate, "not_index"); Local a = Array::New(isolate); - a->Set(0, Number::New(isolate, 10)); + a->Set(0, array->Get(0)); a->Set(1, array->Get(prop)); - a->Set(2, Number::New(isolate, 20)); + a->Set(2, array->Get(2)); args.GetReturnValue().Set(a); } diff --git a/conversions/package.json b/conversions/package.json new file mode 100644 index 0000000..8c5159c --- /dev/null +++ b/conversions/package.json @@ -0,0 +1,19 @@ +{ + "name": "conversions", + "version": "1.0.0", + "description": "Cheat sheet for JavaScript to C++ type conversions in V8", + "main": "index.js", + "scripts": { + "test": "mocha index.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/freezer333/nodecpp-demo.git" + }, + "author": "Scott Frees (http://scottfrees.com/)", + "license": "MIT", + "bugs": { + "url": "https://github.com/freezer333/nodecpp-demo/issues" + }, + "homepage": "https://github.com/freezer333/nodecpp-demo#readme" +}