summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore119
-rw-r--r--LICENSE574
-rw-r--r--Makefile70
-rw-r--r--Makefile.am149
-rw-r--r--README.Solaris6
-rw-r--r--README.md159
-rw-r--r--acinclude.m4.in30
-rw-r--r--apps/couch/AUTHORS (renamed from AUTHORS)0
-rw-r--r--apps/couch/BUGS (renamed from BUGS)0
-rw-r--r--apps/couch/CHANGES (renamed from CHANGES)64
-rw-r--r--apps/couch/DEVELOPERS (renamed from DEVELOPERS)0
-rw-r--r--apps/couch/INSTALL.Unix (renamed from INSTALL.Unix)2
-rw-r--r--apps/couch/INSTALL.Windows (renamed from INSTALL.Windows)0
-rw-r--r--apps/couch/LICENSE371
-rw-r--r--apps/couch/NEWS (renamed from NEWS)27
-rw-r--r--apps/couch/NOTICE (renamed from NOTICE)0
-rw-r--r--apps/couch/README (renamed from README)0
-rw-r--r--apps/couch/THANKS (renamed from THANKS)0
-rw-r--r--apps/couch/c_src/couch_icu_driver.c (renamed from src/couchdb/priv/icu_driver/couch_icu_driver.c)0
-rw-r--r--apps/couch/c_src/spawnkillable/couchspawnkillable_win.c (renamed from src/couchdb/priv/spawnkillable/couchspawnkillable_win.c)0
-rw-r--r--apps/couch/include/couch_db.hrl (renamed from src/couchdb/couch_db.hrl)43
-rw-r--r--apps/couch/license.skip (renamed from license.skip)0
-rwxr-xr-x[-rw-r--r--]apps/couch/priv/couchspawnkillable.sh (renamed from src/couchdb/priv/spawnkillable/couchspawnkillable.sh)0
-rw-r--r--apps/couch/priv/stat_descriptions.cfg (renamed from src/couchdb/priv/stat_descriptions.cfg.in)0
-rw-r--r--apps/couch/rebar.config10
-rw-r--r--apps/couch/src/couch.app.src (renamed from src/couchdb/couch.app.tpl.in)16
-rw-r--r--apps/couch/src/couch.erl (renamed from src/couchdb/couch.erl)4
-rw-r--r--apps/couch/src/couch_app.erl (renamed from src/couchdb/couch_app.erl)31
-rw-r--r--apps/couch/src/couch_auth_cache.erl (renamed from src/couchdb/couch_auth_cache.erl)2
-rw-r--r--apps/couch/src/couch_btree.erl (renamed from src/couchdb/couch_btree.erl)46
-rw-r--r--apps/couch/src/couch_changes.erl (renamed from src/couchdb/couch_changes.erl)54
-rw-r--r--apps/couch/src/couch_config.erl (renamed from src/couchdb/couch_config.erl)44
-rw-r--r--apps/couch/src/couch_config_event.erl46
-rw-r--r--apps/couch/src/couch_config_writer.erl (renamed from src/couchdb/couch_config_writer.erl)0
-rw-r--r--apps/couch/src/couch_db.erl (renamed from src/couchdb/couch_db.erl)232
-rw-r--r--apps/couch/src/couch_db_update_notifier.erl (renamed from src/couchdb/couch_db_update_notifier.erl)0
-rw-r--r--apps/couch/src/couch_db_update_notifier_sup.erl (renamed from src/couchdb/couch_db_update_notifier_sup.erl)8
-rw-r--r--apps/couch/src/couch_db_updater.erl (renamed from src/couchdb/couch_db_updater.erl)400
-rw-r--r--apps/couch/src/couch_doc.erl (renamed from src/couchdb/couch_doc.erl)108
-rw-r--r--apps/couch/src/couch_drv.erl38
-rw-r--r--apps/couch/src/couch_event_sup.erl (renamed from src/couchdb/couch_event_sup.erl)0
-rw-r--r--apps/couch/src/couch_external_manager.erl (renamed from src/couchdb/couch_external_manager.erl)2
-rw-r--r--apps/couch/src/couch_external_server.erl (renamed from src/couchdb/couch_external_server.erl)0
-rw-r--r--apps/couch/src/couch_file.erl (renamed from src/couchdb/couch_file.erl)35
-rw-r--r--apps/couch/src/couch_httpd.erl (renamed from src/couchdb/couch_httpd.erl)2
-rw-r--r--apps/couch/src/couch_httpd_auth.erl (renamed from src/couchdb/couch_httpd_auth.erl)11
-rw-r--r--apps/couch/src/couch_httpd_db.erl (renamed from src/couchdb/couch_httpd_db.erl)0
-rw-r--r--apps/couch/src/couch_httpd_external.erl (renamed from src/couchdb/couch_httpd_external.erl)0
-rw-r--r--apps/couch/src/couch_httpd_misc_handlers.erl (renamed from src/couchdb/couch_httpd_misc_handlers.erl)4
-rw-r--r--apps/couch/src/couch_httpd_oauth.erl (renamed from src/couchdb/couch_httpd_oauth.erl)0
-rw-r--r--apps/couch/src/couch_httpd_proxy.erl (renamed from src/couchdb/couch_httpd_proxy.erl)2
-rw-r--r--apps/couch/src/couch_httpd_rewrite.erl (renamed from src/couchdb/couch_httpd_rewrite.erl)5
-rw-r--r--apps/couch/src/couch_httpd_show.erl (renamed from src/couchdb/couch_httpd_show.erl)0
-rw-r--r--apps/couch/src/couch_httpd_stats_handlers.erl (renamed from src/couchdb/couch_httpd_stats_handlers.erl)0
-rw-r--r--apps/couch/src/couch_httpd_vhost.erl (renamed from src/couchdb/couch_httpd_vhost.erl)0
-rw-r--r--apps/couch/src/couch_httpd_view.erl (renamed from src/couchdb/couch_httpd_view.erl)0
-rw-r--r--apps/couch/src/couch_js_functions.hrl (renamed from src/couchdb/couch_js_functions.hrl)0
-rw-r--r--apps/couch/src/couch_key_tree.erl (renamed from src/couchdb/couch_key_tree.erl)50
-rw-r--r--apps/couch/src/couch_log.erl (renamed from src/couchdb/couch_log.erl)16
-rw-r--r--apps/couch/src/couch_native_process.erl (renamed from src/couchdb/couch_native_process.erl)0
-rw-r--r--apps/couch/src/couch_os_daemons.erl (renamed from src/couchdb/couch_os_daemons.erl)0
-rw-r--r--apps/couch/src/couch_os_process.erl (renamed from src/couchdb/couch_os_process.erl)20
-rw-r--r--apps/couch/src/couch_primary_sup.erl48
-rw-r--r--apps/couch/src/couch_proc_manager.erl184
-rw-r--r--apps/couch/src/couch_query_servers.erl284
-rw-r--r--apps/couch/src/couch_ref_counter.erl (renamed from src/couchdb/couch_ref_counter.erl)0
-rw-r--r--apps/couch/src/couch_rep.erl (renamed from src/couchdb/couch_rep.erl)56
-rw-r--r--apps/couch/src/couch_rep_att.erl (renamed from src/couchdb/couch_rep_att.erl)1
-rw-r--r--apps/couch/src/couch_rep_changes_feed.erl (renamed from src/couchdb/couch_rep_changes_feed.erl)2
-rw-r--r--apps/couch/src/couch_rep_httpc.erl (renamed from src/couchdb/couch_rep_httpc.erl)6
-rw-r--r--apps/couch/src/couch_rep_missing_revs.erl (renamed from src/couchdb/couch_rep_missing_revs.erl)0
-rw-r--r--apps/couch/src/couch_rep_reader.erl (renamed from src/couchdb/couch_rep_reader.erl)0
-rw-r--r--apps/couch/src/couch_rep_sup.erl (renamed from src/couchdb/couch_rep_sup.erl)0
-rw-r--r--apps/couch/src/couch_rep_writer.erl (renamed from src/couchdb/couch_rep_writer.erl)0
-rw-r--r--apps/couch/src/couch_replication_manager.erl (renamed from src/couchdb/couch_replication_manager.erl)0
-rw-r--r--apps/couch/src/couch_secondary_sup.erl35
-rw-r--r--apps/couch/src/couch_server.erl373
-rw-r--r--apps/couch/src/couch_server_sup.erl (renamed from src/couchdb/couch_server_sup.erl)107
-rw-r--r--apps/couch/src/couch_stats_aggregator.erl (renamed from src/couchdb/couch_stats_aggregator.erl)7
-rw-r--r--apps/couch/src/couch_stats_collector.erl (renamed from src/couchdb/couch_stats_collector.erl)25
-rw-r--r--apps/couch/src/couch_stream.erl (renamed from src/couchdb/couch_stream.erl)0
-rw-r--r--apps/couch/src/couch_task_status.erl (renamed from src/couchdb/couch_task_status.erl)1
-rw-r--r--apps/couch/src/couch_util.erl (renamed from src/couchdb/couch_util.erl)4
-rw-r--r--apps/couch/src/couch_uuids.erl (renamed from src/couchdb/couch_uuids.erl)0
-rw-r--r--apps/couch/src/couch_view.erl (renamed from src/couchdb/couch_view.erl)36
-rw-r--r--apps/couch/src/couch_view_compactor.erl (renamed from src/couchdb/couch_view_compactor.erl)15
-rw-r--r--apps/couch/src/couch_view_group.erl (renamed from src/couchdb/couch_view_group.erl)225
-rw-r--r--apps/couch/src/couch_view_updater.erl (renamed from src/couchdb/couch_view_updater.erl)113
-rw-r--r--apps/couch/src/couch_work_queue.erl (renamed from src/couchdb/couch_work_queue.erl)0
-rw-r--r--apps/couch/src/test_util.erl (renamed from test/etap/test_util.erl.in)19
-rw-r--r--apps/couch/test/bench/bench_marks.js (renamed from test/bench/bench_marks.js)0
-rwxr-xr-xapps/couch/test/bench/benchbulk.sh (renamed from test/bench/benchbulk.sh)0
-rwxr-xr-xapps/couch/test/bench/run.tpl (renamed from test/bench/run.tpl)0
-rwxr-xr-xapps/couch/test/etap/001-load.t (renamed from test/etap/001-load.t)2
-rw-r--r--apps/couch/test/etap/002-icu-driver.t (renamed from test/etap/002-icu-driver.t)2
-rwxr-xr-xapps/couch/test/etap/010-file-basics.t (renamed from test/etap/010-file-basics.t)0
-rwxr-xr-xapps/couch/test/etap/011-file-headers.t (renamed from test/etap/011-file-headers.t)0
-rwxr-xr-xapps/couch/test/etap/020-btree-basics.t (renamed from test/etap/020-btree-basics.t)1
-rwxr-xr-xapps/couch/test/etap/021-btree-reductions.t (renamed from test/etap/021-btree-reductions.t)3
-rwxr-xr-xapps/couch/test/etap/030-doc-from-json.t (renamed from test/etap/030-doc-from-json.t)1
-rwxr-xr-xapps/couch/test/etap/031-doc-to-json.t (renamed from test/etap/031-doc-to-json.t)10
-rwxr-xr-xapps/couch/test/etap/040-util.t (renamed from test/etap/040-util.t)0
-rw-r--r--apps/couch/test/etap/041-uuid-gen-seq.ini (renamed from test/etap/041-uuid-gen-seq.ini)0
-rw-r--r--apps/couch/test/etap/041-uuid-gen-utc.ini (renamed from test/etap/041-uuid-gen-utc.ini)0
-rwxr-xr-xapps/couch/test/etap/041-uuid-gen.t (renamed from test/etap/041-uuid-gen.t)24
-rwxr-xr-xapps/couch/test/etap/050-stream.t (renamed from test/etap/050-stream.t)3
-rwxr-xr-xapps/couch/test/etap/060-kt-merging.t (renamed from test/etap/060-kt-merging.t)0
-rwxr-xr-xapps/couch/test/etap/061-kt-missing-leaves.t (renamed from test/etap/061-kt-missing-leaves.t)0
-rwxr-xr-xapps/couch/test/etap/062-kt-remove-leaves.t (renamed from test/etap/062-kt-remove-leaves.t)0
-rwxr-xr-xapps/couch/test/etap/063-kt-get-leaves.t (renamed from test/etap/063-kt-get-leaves.t)0
-rwxr-xr-xapps/couch/test/etap/064-kt-counting.t (renamed from test/etap/064-kt-counting.t)0
-rwxr-xr-xapps/couch/test/etap/065-kt-stemming.t (renamed from test/etap/065-kt-stemming.t)0
-rw-r--r--apps/couch/test/etap/080-config-get-set.ini8
-rwxr-xr-xapps/couch/test/etap/080-config-get-set.t (renamed from test/etap/080-config-get-set.t)3
-rw-r--r--apps/couch/test/etap/081-config-default.ini6
-rw-r--r--apps/couch/test/etap/081-config-override.1.ini (renamed from test/etap/081-config-override.1.ini)0
-rw-r--r--apps/couch/test/etap/081-config-override.2.ini (renamed from test/etap/081-config-override.2.ini)0
-rwxr-xr-xapps/couch/test/etap/081-config-override.t (renamed from test/etap/081-config-override.t)7
-rw-r--r--apps/couch/test/etap/082-config-default.ini6
-rwxr-xr-xapps/couch/test/etap/082-config-register.t (renamed from test/etap/082-config-register.t)3
-rwxr-xr-xapps/couch/test/etap/083-config-no-files.t (renamed from test/etap/083-config-no-files.t)3
-rwxr-xr-xapps/couch/test/etap/090-task-status.t (renamed from test/etap/090-task-status.t)0
-rwxr-xr-xapps/couch/test/etap/100-ref-counter.t (renamed from test/etap/100-ref-counter.t)0
-rwxr-xr-xapps/couch/test/etap/120-stats-collect.inactive (renamed from test/etap/120-stats-collect.t)0
-rw-r--r--apps/couch/test/etap/121-stats-aggregates.cfg (renamed from test/etap/121-stats-aggregates.cfg)0
-rwxr-xr-xapps/couch/test/etap/121-stats-aggregates.inactive (renamed from test/etap/121-stats-aggregates.t)0
-rw-r--r--apps/couch/test/etap/121-stats-aggregates.ini (renamed from test/etap/121-stats-aggregates.ini)0
-rw-r--r--apps/couch/test/etap/etap.beambin0 -> 13880 bytes
-rw-r--r--apps/couch/test/etap/random_port.ini (renamed from test/etap/random_port.ini)0
-rw-r--r--apps/couch/test/etap/run.tpl (renamed from test/etap/run.tpl)0
-rw-r--r--apps/couch/test/etap/test_cfg_register.c (renamed from test/etap/test_cfg_register.c)0
-rw-r--r--apps/couch/test/etap/test_web.erl (renamed from test/etap/test_web.erl)0
-rw-r--r--apps/couch/test/javascript/cli_runner.js (renamed from test/javascript/cli_runner.js)0
-rw-r--r--apps/couch/test/javascript/couch_http.js (renamed from test/javascript/couch_http.js)0
-rw-r--r--apps/couch/test/javascript/run.tpl (renamed from test/javascript/run.tpl)0
-rw-r--r--apps/couch/test/view_server/query_server_spec.rb (renamed from test/view_server/query_server_spec.rb)0
-rwxr-xr-xapps/couch/test/view_server/run_native_process.es (renamed from test/view_server/run_native_process.es)0
-rw-r--r--bin/Makefile.am98
-rw-r--r--bin/couchdb.bat.tpl.in26
-rw-r--r--bin/couchdb.tpl.in330
-rw-r--r--bin/couchjs.tpl.in92
-rwxr-xr-xbootstrap68
-rwxr-xr-xconfigure89
-rw-r--r--configure.ac440
-rw-r--r--couchjs/SConstruct (renamed from test/etap/172-os-daemon-errors.1.sh)9
-rw-r--r--couchjs/c_src/SConscript75
-rw-r--r--couchjs/c_src/http.c (renamed from src/couchdb/priv/couch_js/http.c)69
-rw-r--r--couchjs/c_src/http.h (renamed from src/couchdb/priv/couch_js/http.h)0
-rw-r--r--couchjs/c_src/main.c (renamed from src/couchdb/priv/couch_js/main.c)25
-rw-r--r--couchjs/c_src/utf8.c (renamed from src/couchdb/priv/couch_js/utf8.c)31
-rw-r--r--couchjs/c_src/utf8.h (renamed from src/couchdb/priv/couch_js/utf8.h)0
-rw-r--r--[-rwxr-xr-x]couchjs/js/SConscript (renamed from test/etap/172-os-daemon-errors.2.sh)14
-rw-r--r--couchjs/js/filter.js (renamed from share/server/filter.js)0
-rw-r--r--couchjs/js/json2.js (renamed from share/server/json2.js)0
-rw-r--r--couchjs/js/loop.js (renamed from share/server/loop.js)0
-rw-r--r--couchjs/js/mimeparse.js (renamed from share/server/mimeparse.js)0
-rw-r--r--couchjs/js/render.js (renamed from share/server/render.js)0
-rw-r--r--couchjs/js/state.js (renamed from share/server/state.js)0
-rw-r--r--couchjs/js/util.js (renamed from share/server/util.js)0
-rw-r--r--couchjs/js/validate.js (renamed from share/server/validate.js)0
-rw-r--r--couchjs/js/views.js (renamed from share/server/views.js)0
-rw-r--r--couchjs/scons/scons-LICENSE25
-rw-r--r--couchjs/scons/scons-README204
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Action.py1241
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Builder.py877
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/CacheDir.py216
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Conftest.py793
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Debug.py220
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Defaults.py480
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Environment.py2318
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Errors.py205
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Executor.py633
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Job.py435
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Memoize.py244
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Node/Alias.py152
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Node/FS.py3142
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Node/Python.py128
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Node/__init__.py1328
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Options/BoolOption.py50
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Options/EnumOption.py50
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Options/ListOption.py50
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Options/PackageOption.py50
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Options/PathOption.py76
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Options/__init__.py67
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/PathList.py231
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Platform/__init__.py241
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Platform/aix.py69
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Platform/cygwin.py55
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Platform/darwin.py46
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Platform/hpux.py46
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Platform/irix.py44
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Platform/os2.py58
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Platform/posix.py263
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Platform/sunos.py50
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Platform/win32.py385
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/SConf.py1030
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/SConsign.py383
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Scanner/C.py132
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Scanner/D.py73
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Scanner/Dir.py109
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Scanner/Fortran.py316
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Scanner/IDL.py48
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Scanner/LaTeX.py384
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Scanner/Prog.py101
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Scanner/RC.py55
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Scanner/__init__.py413
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Script/Interactive.py384
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Script/Main.py1334
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Script/SConsOptions.py939
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Script/SConscript.py640
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Script/__init__.py412
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Sig.py63
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Subst.py904
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Taskmaster.py1017
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/386asm.py61
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/BitKeeper.py67
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/CVS.py73
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/FortranCommon.py246
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/JavaCommon.py323
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/__init__.py56
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/arch.py61
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/common.py240
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/netframework.py82
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/sdk.py391
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/vc.py456
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/vs.py499
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/Perforce.py103
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/PharLapCommon.py137
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/RCS.py64
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/SCCS.py64
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/Subversion.py71
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/__init__.py681
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/aixc++.py82
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/aixcc.py74
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/aixf77.py80
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/aixlink.py76
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/applelink.py71
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/ar.py63
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/as.py78
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/bcc32.py81
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/c++.py99
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/cc.py102
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/cvf.py58
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/default.py50
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/dmd.py223
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/dvi.py64
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/dvipdf.py124
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/dvips.py94
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/f77.py62
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/f90.py62
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/f95.py63
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/filesystem.py98
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/fortran.py62
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/g++.py90
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/g77.py73
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/gas.py53
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/gcc.py80
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/gfortran.py64
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/gnulink.py63
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/gs.py81
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/hpc++.py84
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/hpcc.py53
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/hplink.py77
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/icc.py59
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/icl.py52
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/ifl.py72
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/ifort.py88
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/ilink.py59
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/ilink32.py60
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/install.py229
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/intelc.py482
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/ipkg.py67
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/jar.py110
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/javac.py230
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/javah.py137
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/latex.py79
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/lex.py97
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/link.py121
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/linkloc.py112
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/m4.py63
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/masm.py77
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/midl.py88
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/mingw.py158
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/mslib.py64
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/mslink.py266
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/mssdk.py50
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/msvc.py268
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/msvs.py1388
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/mwcc.py207
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/mwld.py107
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/nasm.py72
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/__init__.py312
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/ipk.py185
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/msi.py527
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/rpm.py365
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/src_tarbz2.py43
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/src_targz.py43
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/src_zip.py43
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/tarbz2.py44
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/targz.py44
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/zip.py44
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/pdf.py78
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/pdflatex.py83
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/pdftex.py108
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/qt.py336
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/rmic.py120
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/rpcgen.py70
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/rpm.py132
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/sgiar.py68
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/sgic++.py58
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/sgicc.py53
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/sgilink.py63
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/sunar.py67
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/sunc++.py142
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/suncc.py58
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/sunf77.py63
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/sunf90.py64
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/sunf95.py64
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/sunlink.py77
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/swig.py182
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/tar.py73
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/tex.py813
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/textfile.py175
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/tlib.py53
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/wix.py99
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/yacc.py130
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Tool/zip.py99
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Util.py1492
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Variables/BoolVariable.py89
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Variables/EnumVariable.py103
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Variables/ListVariable.py135
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Variables/PackageVariable.py106
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Variables/PathVariable.py147
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Variables/__init__.py312
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/Warnings.py246
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/__init__.py49
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/compat/__init__.py237
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_builtins.py150
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_collections.py45
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_dbm.py45
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_hashlib.py76
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_io.py45
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_sets.py563
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_subprocess.py1281
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/cpp.py589
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/dblite.py251
-rw-r--r--couchjs/scons/scons-local-2.0.1/SCons/exitfuncs.py77
-rw-r--r--couchjs/scons/scons-local-2.0.1/scons-2.0.1.egg-info13
-rwxr-xr-xcouchjs/scons/scons-time.py1544
-rwxr-xr-xcouchjs/scons/scons.py196
-rwxr-xr-xcouchjs/scons/sconsign.py513
-rw-r--r--etc/Makefile.am117
-rw-r--r--etc/couchdb/Makefile.am86
-rw-r--r--etc/couchdb/local.ini74
-rw-r--r--etc/default/Makefile.am13
-rw-r--r--etc/default/couchdb7
-rw-r--r--etc/init/Makefile.am13
-rw-r--r--etc/init/couchdb.tpl.in168
-rw-r--r--etc/launchd/Makefile.am13
-rw-r--r--etc/launchd/org.apache.couchdb.plist.tpl.in30
-rw-r--r--etc/logrotate.d/Makefile.am13
-rw-r--r--etc/logrotate.d/couchdb.tpl.in9
-rw-r--r--etc/windows/Makefile.am13
-rw-r--r--etc/windows/README.txt.tpl29
-rw-r--r--etc/windows/couchdb.iss.tpl87
-rw-r--r--m4/ac_check_curl.m4.gzbin944 -> 0 bytes
-rw-r--r--m4/ac_check_icu.m4.gzbin956 -> 0 bytes
-rwxr-xr-xrebarbin0 -> 101309 bytes
-rw-r--r--rebar.config49
-rwxr-xr-xrel/overlay/bin/bigcouch28
-rw-r--r--rel/overlay/erts-vsn/bin/erl47
-rw-r--r--rel/overlay/etc/default.ini (renamed from etc/couchdb/default.ini.tpl.in)53
-rw-r--r--rel/overlay/etc/local.ini1
-rw-r--r--rel/overlay/etc/vm.args22
-rw-r--r--rel/overlay/share/www/_sidebar.html (renamed from share/www/_sidebar.html)0
-rw-r--r--rel/overlay/share/www/config.html (renamed from share/www/config.html)0
-rw-r--r--rel/overlay/share/www/couch_tests.html (renamed from share/www/couch_tests.html)0
-rw-r--r--rel/overlay/share/www/custom_test.html (renamed from share/www/custom_test.html)0
-rw-r--r--rel/overlay/share/www/database.html (renamed from share/www/database.html)0
-rw-r--r--rel/overlay/share/www/dialog/_admin_party.html (renamed from share/www/dialog/_admin_party.html)0
-rw-r--r--rel/overlay/share/www/dialog/_compact_cleanup.html (renamed from share/www/dialog/_compact_cleanup.html)0
-rw-r--r--rel/overlay/share/www/dialog/_create_admin.html (renamed from share/www/dialog/_create_admin.html)0
-rw-r--r--rel/overlay/share/www/dialog/_create_config.html (renamed from share/www/dialog/_create_config.html)0
-rw-r--r--rel/overlay/share/www/dialog/_create_database.html (renamed from share/www/dialog/_create_database.html)0
-rw-r--r--rel/overlay/share/www/dialog/_database_security.html (renamed from share/www/dialog/_database_security.html)0
-rw-r--r--rel/overlay/share/www/dialog/_delete_database.html (renamed from share/www/dialog/_delete_database.html)0
-rw-r--r--rel/overlay/share/www/dialog/_delete_document.html (renamed from share/www/dialog/_delete_document.html)0
-rw-r--r--rel/overlay/share/www/dialog/_login.html (renamed from share/www/dialog/_login.html)0
-rw-r--r--rel/overlay/share/www/dialog/_save_view_as.html (renamed from share/www/dialog/_save_view_as.html)0
-rw-r--r--rel/overlay/share/www/dialog/_share_test_reports.html (renamed from share/www/dialog/_share_test_reports.html)0
-rw-r--r--rel/overlay/share/www/dialog/_signup.html (renamed from share/www/dialog/_signup.html)0
-rw-r--r--rel/overlay/share/www/dialog/_upload_attachment.html (renamed from share/www/dialog/_upload_attachment.html)0
-rw-r--r--rel/overlay/share/www/document.html (renamed from share/www/document.html)0
-rw-r--r--rel/overlay/share/www/favicon.ico (renamed from share/www/favicon.ico)bin9326 -> 9326 bytes
-rw-r--r--rel/overlay/share/www/image/add.png (renamed from share/www/image/add.png)bin709 -> 709 bytes
-rw-r--r--rel/overlay/share/www/image/apply.gif (renamed from share/www/image/apply.gif)bin652 -> 652 bytes
-rw-r--r--rel/overlay/share/www/image/bg.png (renamed from share/www/image/bg.png)bin372 -> 372 bytes
-rw-r--r--rel/overlay/share/www/image/cancel.gif (renamed from share/www/image/cancel.gif)bin659 -> 659 bytes
-rw-r--r--rel/overlay/share/www/image/compact.png (renamed from share/www/image/compact.png)bin28735 -> 28735 bytes
-rw-r--r--rel/overlay/share/www/image/delete-mini.png (renamed from share/www/image/delete-mini.png)bin418 -> 418 bytes
-rw-r--r--rel/overlay/share/www/image/delete.png (renamed from share/www/image/delete.png)bin718 -> 718 bytes
-rw-r--r--rel/overlay/share/www/image/grippie.gif (renamed from share/www/image/grippie.gif)bin75 -> 75 bytes
-rw-r--r--rel/overlay/share/www/image/hgrad.gif (renamed from share/www/image/hgrad.gif)bin118 -> 118 bytes
-rw-r--r--rel/overlay/share/www/image/key.png (renamed from share/www/image/key.png)bin859 -> 859 bytes
-rw-r--r--rel/overlay/share/www/image/load.png (renamed from share/www/image/load.png)bin780 -> 780 bytes
-rw-r--r--rel/overlay/share/www/image/logo.png (renamed from share/www/image/logo.png)bin3010 -> 3010 bytes
-rw-r--r--rel/overlay/share/www/image/order-asc.gif (renamed from share/www/image/order-asc.gif)bin195 -> 195 bytes
-rw-r--r--rel/overlay/share/www/image/order-desc.gif (renamed from share/www/image/order-desc.gif)bin187 -> 187 bytes
-rw-r--r--rel/overlay/share/www/image/path.gif (renamed from share/www/image/path.gif)bin104 -> 104 bytes
-rw-r--r--rel/overlay/share/www/image/progress.gif (renamed from share/www/image/progress.gif)bin10819 -> 10819 bytes
-rw-r--r--rel/overlay/share/www/image/rarrow.png (renamed from share/www/image/rarrow.png)bin27721 -> 27721 bytes
-rw-r--r--rel/overlay/share/www/image/run-mini.png (renamed from share/www/image/run-mini.png)bin478 -> 478 bytes
-rw-r--r--rel/overlay/share/www/image/run.png (renamed from share/www/image/run.png)bin718 -> 718 bytes
-rw-r--r--rel/overlay/share/www/image/running.png (renamed from share/www/image/running.png)bin284 -> 284 bytes
-rw-r--r--rel/overlay/share/www/image/save.png (renamed from share/www/image/save.png)bin843 -> 843 bytes
-rw-r--r--rel/overlay/share/www/image/sidebar-toggle.png (renamed from share/www/image/sidebar-toggle.png)bin512 -> 512 bytes
-rw-r--r--rel/overlay/share/www/image/spinner.gif (renamed from share/www/image/spinner.gif)bin3008 -> 3008 bytes
-rw-r--r--rel/overlay/share/www/image/test_failure.gif (renamed from share/www/image/test_failure.gif)bin114 -> 114 bytes
-rw-r--r--rel/overlay/share/www/image/test_success.gif (renamed from share/www/image/test_success.gif)bin185 -> 185 bytes
-rw-r--r--rel/overlay/share/www/image/thead-key.gif (renamed from share/www/image/thead-key.gif)bin77 -> 77 bytes
-rw-r--r--rel/overlay/share/www/image/thead.gif (renamed from share/www/image/thead.gif)bin51 -> 51 bytes
-rw-r--r--rel/overlay/share/www/image/toggle-collapse.gif (renamed from share/www/image/toggle-collapse.gif)bin176 -> 176 bytes
-rw-r--r--rel/overlay/share/www/image/toggle-expand.gif (renamed from share/www/image/toggle-expand.gif)bin181 -> 181 bytes
-rw-r--r--rel/overlay/share/www/image/twisty.gif (renamed from share/www/image/twisty.gif)bin160 -> 160 bytes
-rw-r--r--rel/overlay/share/www/index.html (renamed from share/www/index.html)0
-rw-r--r--rel/overlay/share/www/replicator.html (renamed from share/www/replicator.html)20
-rw-r--r--rel/overlay/share/www/script/base64.js (renamed from share/www/script/base64.js)0
-rw-r--r--rel/overlay/share/www/script/couch.js (renamed from share/www/script/couch.js)4
-rw-r--r--rel/overlay/share/www/script/couch_test_runner.js (renamed from share/www/script/couch_test_runner.js)0
-rw-r--r--rel/overlay/share/www/script/couch_tests.js (renamed from share/www/script/couch_tests.js)0
-rw-r--r--rel/overlay/share/www/script/futon.browse.js (renamed from share/www/script/futon.browse.js)2
-rw-r--r--rel/overlay/share/www/script/futon.format.js (renamed from share/www/script/futon.format.js)0
-rw-r--r--rel/overlay/share/www/script/futon.js (renamed from share/www/script/futon.js)0
-rw-r--r--rel/overlay/share/www/script/jquery.couch.js (renamed from share/www/script/jquery.couch.js)2
-rw-r--r--rel/overlay/share/www/script/jquery.dialog.js (renamed from share/www/script/jquery.dialog.js)0
-rw-r--r--rel/overlay/share/www/script/jquery.editinline.js (renamed from share/www/script/jquery.editinline.js)0
-rw-r--r--rel/overlay/share/www/script/jquery.form.js (renamed from share/www/script/jquery.form.js)0
-rw-r--r--rel/overlay/share/www/script/jquery.js (renamed from share/www/script/jquery.js)0
-rw-r--r--rel/overlay/share/www/script/jquery.resizer.js (renamed from share/www/script/jquery.resizer.js)0
-rw-r--r--rel/overlay/share/www/script/jquery.suggest.js (renamed from share/www/script/jquery.suggest.js)0
-rw-r--r--rel/overlay/share/www/script/json2.js (renamed from share/www/script/json2.js)0
-rw-r--r--rel/overlay/share/www/script/jspec/jspec.css (renamed from share/www/script/jspec/jspec.css)0
-rw-r--r--rel/overlay/share/www/script/jspec/jspec.jquery.js (renamed from share/www/script/jspec/jspec.jquery.js)0
-rw-r--r--rel/overlay/share/www/script/jspec/jspec.js (renamed from share/www/script/jspec/jspec.js)0
-rw-r--r--rel/overlay/share/www/script/jspec/jspec.xhr.js (renamed from share/www/script/jspec/jspec.xhr.js)0
-rw-r--r--rel/overlay/share/www/script/oauth.js (renamed from share/www/script/oauth.js)0
-rw-r--r--rel/overlay/share/www/script/sha1.js (renamed from share/www/script/sha1.js)0
-rw-r--r--rel/overlay/share/www/script/test/all_docs.js (renamed from share/www/script/test/all_docs.js)0
-rw-r--r--rel/overlay/share/www/script/test/attachment_conflicts.js (renamed from share/www/script/test/attachment_conflicts.js)0
-rw-r--r--rel/overlay/share/www/script/test/attachment_names.js (renamed from share/www/script/test/attachment_names.js)0
-rw-r--r--rel/overlay/share/www/script/test/attachment_paths.js (renamed from share/www/script/test/attachment_paths.js)0
-rw-r--r--rel/overlay/share/www/script/test/attachment_views.js (renamed from share/www/script/test/attachment_views.js)0
-rw-r--r--rel/overlay/share/www/script/test/attachments.js (renamed from share/www/script/test/attachments.js)2
-rw-r--r--rel/overlay/share/www/script/test/attachments_multipart.js (renamed from share/www/script/test/attachments_multipart.js)10
-rw-r--r--rel/overlay/share/www/script/test/auth_cache.js (renamed from share/www/script/test/auth_cache.js)0
-rw-r--r--rel/overlay/share/www/script/test/basics.js (renamed from share/www/script/test/basics.js)0
-rw-r--r--rel/overlay/share/www/script/test/batch_save.js (renamed from share/www/script/test/batch_save.js)0
-rw-r--r--rel/overlay/share/www/script/test/bulk_docs.js (renamed from share/www/script/test/bulk_docs.js)0
-rw-r--r--rel/overlay/share/www/script/test/changes.js (renamed from share/www/script/test/changes.js)0
-rw-r--r--rel/overlay/share/www/script/test/compact.js (renamed from share/www/script/test/compact.js)0
-rw-r--r--rel/overlay/share/www/script/test/config.js (renamed from share/www/script/test/config.js)0
-rw-r--r--rel/overlay/share/www/script/test/conflicts.js (renamed from share/www/script/test/conflicts.js)0
-rw-r--r--rel/overlay/share/www/script/test/content_negotiation.js (renamed from share/www/script/test/content_negotiation.js)0
-rw-r--r--rel/overlay/share/www/script/test/cookie_auth.js (renamed from share/www/script/test/cookie_auth.js)2
-rw-r--r--rel/overlay/share/www/script/test/copy_doc.js (renamed from share/www/script/test/copy_doc.js)0
-rw-r--r--rel/overlay/share/www/script/test/delayed_commits.js (renamed from share/www/script/test/delayed_commits.js)0
-rw-r--r--rel/overlay/share/www/script/test/design_docs.js (renamed from share/www/script/test/design_docs.js)0
-rw-r--r--rel/overlay/share/www/script/test/design_options.js (renamed from share/www/script/test/design_options.js)0
-rw-r--r--rel/overlay/share/www/script/test/design_paths.js (renamed from share/www/script/test/design_paths.js)0
-rw-r--r--rel/overlay/share/www/script/test/erlang_views.js (renamed from share/www/script/test/erlang_views.js)0
-rw-r--r--rel/overlay/share/www/script/test/etags_head.js (renamed from share/www/script/test/etags_head.js)0
-rw-r--r--rel/overlay/share/www/script/test/etags_views.js (renamed from share/www/script/test/etags_views.js)4
-rw-r--r--rel/overlay/share/www/script/test/form_submit.js (renamed from share/www/script/test/form_submit.js)0
-rw-r--r--rel/overlay/share/www/script/test/http.js (renamed from share/www/script/test/http.js)0
-rw-r--r--rel/overlay/share/www/script/test/invalid_docids.js (renamed from share/www/script/test/invalid_docids.js)0
-rw-r--r--rel/overlay/share/www/script/test/jsonp.js (renamed from share/www/script/test/jsonp.js)0
-rw-r--r--rel/overlay/share/www/script/test/large_docs.js (renamed from share/www/script/test/large_docs.js)0
-rw-r--r--rel/overlay/share/www/script/test/list_views.js (renamed from share/www/script/test/list_views.js)0
-rw-r--r--rel/overlay/share/www/script/test/lorem.txt (renamed from share/www/script/test/lorem.txt)0
-rw-r--r--rel/overlay/share/www/script/test/lorem_b64.txt (renamed from share/www/script/test/lorem_b64.txt)0
-rw-r--r--rel/overlay/share/www/script/test/lots_of_docs.js (renamed from share/www/script/test/lots_of_docs.js)0
-rw-r--r--rel/overlay/share/www/script/test/method_override.js (renamed from share/www/script/test/method_override.js)0
-rw-r--r--rel/overlay/share/www/script/test/multiple_rows.js (renamed from share/www/script/test/multiple_rows.js)0
-rw-r--r--rel/overlay/share/www/script/test/oauth.js (renamed from share/www/script/test/oauth.js)0
-rw-r--r--rel/overlay/share/www/script/test/proxyauth.js (renamed from share/www/script/test/proxyauth.js)2
-rw-r--r--rel/overlay/share/www/script/test/purge.js (renamed from share/www/script/test/purge.js)0
-rw-r--r--rel/overlay/share/www/script/test/reader_acl.js (renamed from share/www/script/test/reader_acl.js)0
-rw-r--r--rel/overlay/share/www/script/test/recreate_doc.js (renamed from share/www/script/test/recreate_doc.js)0
-rw-r--r--rel/overlay/share/www/script/test/reduce.js (renamed from share/www/script/test/reduce.js)0
-rw-r--r--rel/overlay/share/www/script/test/reduce_builtin.js (renamed from share/www/script/test/reduce_builtin.js)0
-rw-r--r--rel/overlay/share/www/script/test/reduce_false.js (renamed from share/www/script/test/reduce_false.js)0
-rw-r--r--rel/overlay/share/www/script/test/reduce_false_temp.js (renamed from share/www/script/test/reduce_false_temp.js)0
-rw-r--r--rel/overlay/share/www/script/test/replication.js (renamed from share/www/script/test/replication.js)0
-rw-r--r--rel/overlay/share/www/script/test/rev_stemming.js (renamed from share/www/script/test/rev_stemming.js)0
-rw-r--r--rel/overlay/share/www/script/test/rewrite.js (renamed from share/www/script/test/rewrite.js)21
-rw-r--r--rel/overlay/share/www/script/test/security_validation.js (renamed from share/www/script/test/security_validation.js)0
-rw-r--r--rel/overlay/share/www/script/test/show_documents.js (renamed from share/www/script/test/show_documents.js)0
-rw-r--r--rel/overlay/share/www/script/test/stats.js (renamed from share/www/script/test/stats.js)0
-rw-r--r--rel/overlay/share/www/script/test/update_documents.js (renamed from share/www/script/test/update_documents.js)0
-rw-r--r--rel/overlay/share/www/script/test/users_db.js (renamed from share/www/script/test/users_db.js)0
-rw-r--r--rel/overlay/share/www/script/test/utf8.js (renamed from share/www/script/test/utf8.js)0
-rw-r--r--rel/overlay/share/www/script/test/uuids.js (renamed from share/www/script/test/uuids.js)0
-rw-r--r--rel/overlay/share/www/script/test/view_collation.js (renamed from share/www/script/test/view_collation.js)0
-rw-r--r--rel/overlay/share/www/script/test/view_collation_raw.js (renamed from share/www/script/test/view_collation_raw.js)0
-rw-r--r--rel/overlay/share/www/script/test/view_compaction.js (renamed from share/www/script/test/view_compaction.js)0
-rw-r--r--rel/overlay/share/www/script/test/view_conflicts.js (renamed from share/www/script/test/view_conflicts.js)0
-rw-r--r--rel/overlay/share/www/script/test/view_errors.js (renamed from share/www/script/test/view_errors.js)0
-rw-r--r--rel/overlay/share/www/script/test/view_include_docs.js (renamed from share/www/script/test/view_include_docs.js)0
-rw-r--r--rel/overlay/share/www/script/test/view_multi_key_all_docs.js (renamed from share/www/script/test/view_multi_key_all_docs.js)0
-rw-r--r--rel/overlay/share/www/script/test/view_multi_key_design.js (renamed from share/www/script/test/view_multi_key_design.js)0
-rw-r--r--rel/overlay/share/www/script/test/view_multi_key_temp.js (renamed from share/www/script/test/view_multi_key_temp.js)0
-rw-r--r--rel/overlay/share/www/script/test/view_offsets.js (renamed from share/www/script/test/view_offsets.js)0
-rw-r--r--rel/overlay/share/www/script/test/view_pagination.js (renamed from share/www/script/test/view_pagination.js)0
-rw-r--r--rel/overlay/share/www/script/test/view_sandboxing.js (renamed from share/www/script/test/view_sandboxing.js)0
-rw-r--r--rel/overlay/share/www/script/test/view_update_seq.js (renamed from share/www/script/test/view_update_seq.js)0
-rw-r--r--rel/overlay/share/www/script/test/view_xml.js (renamed from share/www/script/test/view_xml.js)0
-rw-r--r--rel/overlay/share/www/session.html (renamed from share/www/session.html)0
-rw-r--r--rel/overlay/share/www/spec/couch_js_class_methods_spec.js (renamed from share/www/spec/couch_js_class_methods_spec.js)0
-rw-r--r--rel/overlay/share/www/spec/couch_js_instance_methods_1_spec.js (renamed from share/www/spec/couch_js_instance_methods_1_spec.js)0
-rw-r--r--rel/overlay/share/www/spec/couch_js_instance_methods_2_spec.js (renamed from share/www/spec/couch_js_instance_methods_2_spec.js)0
-rw-r--r--rel/overlay/share/www/spec/couch_js_instance_methods_3_spec.js (renamed from share/www/spec/couch_js_instance_methods_3_spec.js)0
-rw-r--r--rel/overlay/share/www/spec/custom_helpers.js (renamed from share/www/spec/custom_helpers.js)0
-rw-r--r--rel/overlay/share/www/spec/jquery_couch_js_class_methods_spec.js (renamed from share/www/spec/jquery_couch_js_class_methods_spec.js)0
-rw-r--r--rel/overlay/share/www/spec/jquery_couch_js_instance_methods_1_spec.js (renamed from share/www/spec/jquery_couch_js_instance_methods_1_spec.js)0
-rw-r--r--rel/overlay/share/www/spec/jquery_couch_js_instance_methods_2_spec.js (renamed from share/www/spec/jquery_couch_js_instance_methods_2_spec.js)0
-rw-r--r--rel/overlay/share/www/spec/jquery_couch_js_instance_methods_3_spec.js (renamed from share/www/spec/jquery_couch_js_instance_methods_3_spec.js)0
-rw-r--r--rel/overlay/share/www/spec/run.html (renamed from share/www/spec/run.html)0
-rw-r--r--rel/overlay/share/www/status.html (renamed from share/www/status.html)0
-rw-r--r--rel/overlay/share/www/style/layout.css (renamed from share/www/style/layout.css)2
-rw-r--r--rel/reltool.config61
-rw-r--r--rel/sv/README1
-rw-r--r--rel/sv/bigcouch/log/main/current0
-rwxr-xr-xrel/sv/bigcouch/log/run2
-rwxr-xr-xrel/sv/bigcouch/run4
-rw-r--r--share/Makefile.am202
-rw-r--r--share/www/dialog/_change_password.html31
-rw-r--r--share/www/image/spinner_33.gifbin2987 -> 0 bytes
-rw-r--r--share/www/image/spinner_6b.gifbin2969 -> 0 bytes
-rw-r--r--share/www/script/jquery-ui-1.8.11.custom.min.js81
-rw-r--r--share/www/script/test/attachment_ranges.js134
-rw-r--r--share/www/script/test/replicator_db.js1380
-rw-r--r--share/www/style/jquery-ui-1.8.11.custom.css347
-rw-r--r--src/Makefile.am13
-rw-r--r--src/couchdb/Makefile.am209
-rw-r--r--src/couchdb/couch_query_servers.erl589
-rw-r--r--src/couchdb/couch_server.erl405
-rw-r--r--src/couchdb/priv/Makefile.am93
-rw-r--r--src/erlang-oauth/Makefile.am50
-rw-r--r--src/erlang-oauth/oauth.app.in20
-rw-r--r--src/erlang-oauth/oauth.erl107
-rw-r--r--src/erlang-oauth/oauth_hmac_sha1.erl11
-rw-r--r--src/erlang-oauth/oauth_http.erl22
-rw-r--r--src/erlang-oauth/oauth_plaintext.erl10
-rw-r--r--src/erlang-oauth/oauth_rsa_sha1.erl30
-rw-r--r--src/erlang-oauth/oauth_unix.erl16
-rw-r--r--src/erlang-oauth/oauth_uri.erl98
-rw-r--r--src/etap/Makefile.am44
-rw-r--r--src/etap/etap.erl416
-rw-r--r--src/etap/etap_application.erl72
-rw-r--r--src/etap/etap_can.erl79
-rw-r--r--src/etap/etap_exception.erl66
-rw-r--r--src/etap/etap_process.erl42
-rw-r--r--src/etap/etap_report.erl343
-rw-r--r--src/etap/etap_request.erl89
-rw-r--r--src/etap/etap_string.erl47
-rw-r--r--src/etap/etap_web.erl65
-rw-r--r--src/ibrowse/Makefile.am49
-rw-r--r--src/ibrowse/ibrowse.app.in13
-rw-r--r--src/ibrowse/ibrowse.erl863
-rw-r--r--src/ibrowse/ibrowse.hrl21
-rw-r--r--src/ibrowse/ibrowse_app.erl63
-rw-r--r--src/ibrowse/ibrowse_http_client.erl1855
-rw-r--r--src/ibrowse/ibrowse_lb.erl235
-rw-r--r--src/ibrowse/ibrowse_lib.erl391
-rw-r--r--src/ibrowse/ibrowse_sup.erl63
-rw-r--r--src/ibrowse/ibrowse_test.erl513
-rw-r--r--src/mochiweb/Makefile.am102
-rw-r--r--src/mochiweb/internal.hrl3
-rw-r--r--src/mochiweb/mochifmt.erl425
-rw-r--r--src/mochiweb/mochifmt_records.erl38
-rw-r--r--src/mochiweb/mochifmt_std.erl30
-rw-r--r--src/mochiweb/mochiglobal.erl107
-rw-r--r--src/mochiweb/mochihex.erl91
-rw-r--r--src/mochiweb/mochijson.erl531
-rw-r--r--src/mochiweb/mochijson2.erl802
-rw-r--r--src/mochiweb/mochilists.erl104
-rw-r--r--src/mochiweb/mochilogfile2.erl140
-rw-r--r--src/mochiweb/mochinum.erl331
-rw-r--r--src/mochiweb/mochitemp.erl310
-rw-r--r--src/mochiweb/mochiutf8.erl316
-rw-r--r--src/mochiweb/mochiweb.app.in32
-rw-r--r--src/mochiweb/mochiweb.app.src9
-rw-r--r--src/mochiweb/mochiweb.erl289
-rw-r--r--src/mochiweb/mochiweb_acceptor.erl48
-rw-r--r--src/mochiweb/mochiweb_app.erl27
-rw-r--r--src/mochiweb/mochiweb_charref.erl308
-rw-r--r--src/mochiweb/mochiweb_cookies.erl309
-rw-r--r--src/mochiweb/mochiweb_cover.erl75
-rw-r--r--src/mochiweb/mochiweb_echo.erl38
-rw-r--r--src/mochiweb/mochiweb_headers.erl299
-rw-r--r--src/mochiweb/mochiweb_html.erl1061
-rw-r--r--src/mochiweb/mochiweb_http.erl273
-rw-r--r--src/mochiweb/mochiweb_io.erl46
-rw-r--r--src/mochiweb/mochiweb_mime.erl94
-rw-r--r--src/mochiweb/mochiweb_multipart.erl824
-rw-r--r--src/mochiweb/mochiweb_request.erl768
-rw-r--r--src/mochiweb/mochiweb_response.erl64
-rw-r--r--src/mochiweb/mochiweb_skel.erl86
-rw-r--r--src/mochiweb/mochiweb_socket.erl84
-rw-r--r--src/mochiweb/mochiweb_socket_server.erl272
-rw-r--r--src/mochiweb/mochiweb_sup.erl41
-rw-r--r--src/mochiweb/mochiweb_util.erl973
-rw-r--r--src/mochiweb/reloader.erl161
-rw-r--r--test/Makefile.am14
-rw-r--r--test/bench/Makefile.am22
-rwxr-xr-xtest/etap/070-couch-db.t73
-rwxr-xr-xtest/etap/110-replication-httpc.t132
-rwxr-xr-xtest/etap/111-replication-changes-feed.t253
-rwxr-xr-xtest/etap/112-replication-missing-revs.t207
-rwxr-xr-xtest/etap/113-replication-attachment-comp.t314
-rwxr-xr-xtest/etap/130-attachments-md5.t248
-rwxr-xr-xtest/etap/140-attachment-comp.t762
-rwxr-xr-xtest/etap/150-invalid-view-seq.t190
-rwxr-xr-xtest/etap/160-vhosts.t291
-rwxr-xr-xtest/etap/170-os-daemons.es26
-rwxr-xr-xtest/etap/170-os-daemons.t114
-rwxr-xr-xtest/etap/171-os-daemons-config.es83
-rwxr-xr-xtest/etap/171-os-daemons-config.t74
-rwxr-xr-xtest/etap/172-os-daemon-errors.3.sh15
-rwxr-xr-xtest/etap/172-os-daemon-errors.4.sh15
-rwxr-xr-xtest/etap/172-os-daemon-errors.t126
-rwxr-xr-xtest/etap/173-os-daemon-cfg-register.t93
-rw-r--r--test/etap/180-http-proxy.ini20
-rwxr-xr-xtest/etap/180-http-proxy.t378
-rwxr-xr-xtest/etap/190-oauth.t31
-rwxr-xr-xtest/etap/200-view-group-no-db-leaks.t262
-rw-r--r--test/etap/Makefile.am89
-rw-r--r--test/javascript/Makefile.am25
-rw-r--r--test/view_server/Makefile.am15
-rw-r--r--utils/Makefile.am42
-rw-r--r--var/Makefile.am23
641 files changed, 50975 insertions, 25962 deletions
diff --git a/.gitignore b/.gitignore
index 33028e7e..beafc50b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,100 +1,31 @@
-*.beam
-*.gz
-*.tpl
*.o
-*.lo
-*.la
-*.m4
-*.in
+*.so
+*.Tpo
+*.beam
*~
*.orig
*.rej
erl_crash.dump
-configure
-autom4te.cache
-build-aux
-*.diff
-
-# ./configure
-
-Makefile
-bin/Makefile
-config.h
-config.log
-config.status
-etc/Makefile
-etc/couchdb/Makefile
-etc/default/Makefile
-etc/init/Makefile
-etc/launchd/Makefile
-etc/logrotate.d/Makefile
-libtool
-share/Makefile
-src/couchdb/.deps/*
-src/couchdb/Makefile
-src/couchdb/priv/Makefile
-src/mochiweb/Makefile
-stamp-h1
-test/.deps/
-test/Makefile
-test/javascript/run_js_tests.sh
-var/Makefile
-
-# for make
-
-bin/couchdb
-bin/couchdb.1
-bin/couchjs
-bin/couchjs.1
-etc/couchdb/default.ini
-etc/launchd/org.apache.couchdb.plist
-etc/logrotate.d/couchdb
-src/couchdb/.libs/*
-src/couchdb/couch.app
-src/couchdb/couchjs
-src/couchdb/edoc-info
-src/couchdb/erlang.png
-src/couchdb/stylesheet.css
-src/couchdb/priv/.deps/
-src/couchdb/priv/.libs/
-src/couchdb/priv/couch_icu_driver.la
-src/couchdb/priv/couchjs
-src/couchdb/priv/couchspawnkillable
-src/couchdb/priv/stat_descriptions.cfg
-src/erlang-oauth/oauth.app
-src/ibrowse/ibrowse.app
-src/mochiweb/mochiweb.app
-test/local.ini
-test/etap/.deps/
-test/etap/run
-test/etap/test_cfg_register
-test/etap/test_util.erl
-test/javascript/run
-share/server/main.js
-
-# for make dev
-
-bin/.deps/
-bin/couchjs_dev
-bin/couchpw
-etc/couchdb/default_dev.ini
-etc/couchdb/local_dev.ini
-utils/run
-tmp
-src/couchdb/priv/stat_descriptions.cfg
-src/erlang-oauth/oauth.app
-src/ibrowse/ibrowse.app
-src/mochiweb/mochiweb.app
-test/etap/run
-
-# for make check
-
-test/etap/temp.*
-test/bench/run
-couchdb.stderr
-couchdb.stdout
-
-# for make cover
-cover/*
-INSTALL
+# building
+apps/*/ebin/
+rel/dbcore
+rel/bigcouch.config
+rel/overlay.config
+install.mk
+
+# scons building
+couchjs/.sconf_temp/
+couchjs/.sconsign.dblite
+couchjs/build/
+couchjs/config.log
+*.pyc
+
+# testing
+.eunit
+@abs_top_builddir@/
+apps/couch/test/temp*
+
+# dev
+rel/dev*
+rel/tmpdata \ No newline at end of file
diff --git a/LICENSE b/LICENSE
index 063c9981..e454a525 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,400 +1,178 @@
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-
-Apache CouchDB Subcomponents
-
-The Apache CouchDB project includes a number of subcomponents with separate
-copyright notices and license terms. Your use of the code for the these
-subcomponents is subject to the terms and conditions of the following licenses.
-
-For the m4/ac_check_icu.m4 component:
-
- Copyright (c) 2005 Akos Maroy <darkeye@tyrell.hu>
-
- Copying and distribution of this file, with or without modification, are
- permitted in any medium without royalty provided the copyright notice
- and this notice are preserved.
-
-For the share/www/script/jquery.js component:
-
- Copyright (c) 2009 John Resig, http://jquery.com/
-
- Permission is hereby granted, free of charge, to any person obtaining
- a copy of this software and associated documentation files (the
- "Software"), to deal in the Software without restriction, including
- without limitation the rights to use, copy, modify, merge, publish,
- distribute, sublicense, and/or sell copies of the Software, and to
- permit persons to whom the Software is furnished to do so, subject to
- the following conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-For the share/www/script/jquery-ui-1.8.11.custom.min.js and
- share/www/style/jquery-ui-1.8.11.custom.css components:
-
- Copyright (c) 2011 Paul Bakaus, http://jqueryui.com/
-
- This software consists of voluntary contributions made by many
- individuals (AUTHORS.txt, http://jqueryui.com/about) For exact
- contribution history, see the revision history and logs, available
- at http://jquery-ui.googlecode.com/svn/
-
- Permission is hereby granted, free of charge, to any person obtaining
- a copy of this software and associated documentation files (the
- "Software"), to deal in the Software without restriction, including
- without limitation the rights to use, copy, modify, merge, publish,
- distribute, sublicense, and/or sell copies of the Software, and to
- permit persons to whom the Software is furnished to do so, subject to
- the following conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-For the share/www/script/jquery.form.js component:
-
- http://malsup.com/jquery/form/
-
- Permission is hereby granted, free of charge, to any person obtaining
- a copy of this software and associated documentation files (the
- "Software"), to deal in the Software without restriction, including
- without limitation the rights to use, copy, modify, merge, publish,
- distribute, sublicense, and/or sell copies of the Software, and to
- permit persons to whom the Software is furnished to do so, subject to
- the following conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-For the share/www/script/json2.js component:
-
- Public Domain
-
- No warranty expressed or implied. Use at your own risk.
-
-For the src/mochiweb component:
-
- Copyright (c) 2007 Mochi Media, Inc.
-
- Permission is hereby granted, free of charge, to any person obtaining
- a copy of this software and associated documentation files (the
- "Software"), to deal in the Software without restriction, including
- without limitation the rights to use, copy, modify, merge, publish,
- distribute, sublicense, and/or sell copies of the Software, and to
- permit persons to whom the Software is furnished to do so, subject to
- the following conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-For the src/ibrowse component:
-
- Copyright (c) 2006, Chandrashekhar Mullaparthi
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the T-Mobile nor the names of its contributors may be
- used to endorse or promote products derived from this software without
- specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-For the src/erlang-oauth component:
-
- Copyright (c) 2008-2009 Tim Fletcher <http://tfletcher.com/>
-
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation
- files (the "Software"), to deal in the Software without
- restriction, including without limitation the rights to use,
- copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following
- conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- OTHER DEALINGS IN THE SOFTWARE.
-
-For the src/etap component:
-
- Copyright (c) 2008-2009 Nick Gerakines <nick@gerakines.net>
-
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation
- files (the "Software"), to deal in the Software without
- restriction, including without limitation the rights to use,
- copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following
- conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- OTHER DEALINGS IN THE SOFTWARE.
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
diff --git a/Makefile b/Makefile
new file mode 100644
index 00000000..4bf74e8c
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,70 @@
+# Copyright 2010 Cloudant
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+all: compile
+
+appfile = apps/couch/ebin/couch.app
+compile:
+ @echo "==> couchjs (compile)"
+ @cd couchjs && python scons/scons.py
+ @./rebar compile
+ @cat $(appfile) | sed s/%VSN%/`git describe --match 1.*`/ > $(appfile)
+
+clean:
+ @echo "==> couchjs (clean)"
+ @cd couchjs && python scons/scons.py --clean
+ @./rebar clean
+
+# compile is required here because of cross-dependencies between apps
+check: compile
+ @./rebar eunit
+ @ERL_FLAGS="-pa `pwd`/apps/couch/ebin" prove apps/couch/test/etap/*.t
+
+dist: compile
+ @rm -rf rel/bigcouch
+ @./rebar generate
+
+distclean: clean
+ @rm -rf rel/bigcouch
+
+include install.mk
+install: dist
+ @mkdir -p $(prefix)
+ @cp -R rel/bigcouch/* $(prefix)
+ @mkdir -p $(data_dir)
+ @chown $(user) $(data_dir)
+ @mkdir -p $(view_dir)
+ @chown $(user) $(view_dir)
+ @touch $(prefix)/var/log/bigcouch.log
+ @chown $(user) $(prefix)/var/log/bigcouch.log
+
+dev: compile
+ @rm -rf rel/dev1 rel/dev2 rel/dev3
+ @echo "==> Building development node #1 (ports 15984/15986)"
+ @./rebar generate target_dir=dev1 overlay_vars=dev1.config
+ @echo "==> Building development node #2 (ports 25984/25986)"
+ @./rebar generate target_dir=dev2 overlay_vars=dev2.config
+ @echo "==> Building development node #3 (ports 35984/35986)"
+ @./rebar generate target_dir=dev3 overlay_vars=dev3.config
+ @echo "\n\
+Development nodes are built, and can be started using ./rel/dev[123]/bin/bigcouch.\n\
+Once the nodes are started, they must be joined together by editing the local\n\
+nodes DB. For example, executing\n\
+\n\
+ curl localhost:15986/nodes/dev2@127.0.0.1 -X PUT -d '{}'\n\
+ curl localhost:15986/nodes/dev3@127.0.0.1 -X PUT -d '{}'\n\
+\n\
+will cause node 1 to immediately connect to nodes 2 and 3 and form a cluster.\n\
+The content of the nodes database is continuously replicated throughout the\n\
+cluster, so this is a one-time operation.\n"
diff --git a/Makefile.am b/Makefile.am
deleted file mode 100644
index 2d0bbbe6..00000000
--- a/Makefile.am
+++ /dev/null
@@ -1,149 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-SUBDIRS = bin etc src share test var utils
-
-ACLOCAL_AMFLAGS = -I m4
-
-localdoc_DATA = \
- AUTHORS.gz \
- BUGS.gz \
- CHANGES.gz \
- DEVELOPERS.gz \
- INSTALL.gz \
- INSTALL.Unix.gz \
- INSTALL.Windows.gz \
- LICENSE.gz \
- NEWS.gz \
- NOTICE.gz \
- README.gz \
- THANKS.gz
-
-DISTCLEANFILES = $(localdoc_DATA)
-
-EXTRA_DIST = \
- AUTHORS \
- BUGS \
- CHANGES \
- DEVELOPERS \
- INSTALL \
- INSTALL.Unix \
- INSTALL.Windows \
- LICENSE \
- NEWS \
- NOTICE \
- README \
- THANKS \
- license.skip
-
-AUTHORS.gz: $(top_srcdir)/AUTHORS
- -gzip -9 < $< > $@
-
-BUGS.gz: $(top_srcdir)/BUGS
- -gzip -9 < $< > $@
-
-CHANGES.gz: $(top_srcdir)/CHANGES
- -gzip -9 < $< > $@
-
-DEVELOPERS.gz: $(top_srcdir)/DEVELOPERS
- -gzip -9 < $< > $@
-
-INSTALL.gz: $(top_srcdir)/INSTALL
- -gzip -9 < $< > $@
-
-INSTALL.Unix.gz: $(top_srcdir)/INSTALL.Unix
- -gzip -9 < $< > $@
-
-INSTALL.Windows.gz: $(top_srcdir)/INSTALL.Windows
- -gzip -9 < $< > $@
-
-LICENSE.gz: $(top_srcdir)/LICENSE
- -gzip -9 < $< > $@
-
-NEWS.gz: $(top_srcdir)/NEWS
- -gzip -9 < $< > $@
-
-NOTICE.gz: $(top_srcdir)/NOTICE
- -gzip -9 < $< > $@
-
-README.gz: $(top_srcdir)/README
- -gzip -9 < $< > $@
-
-THANKS.gz: $(top_srcdir)/THANKS
- -gzip -9 < $< > $@
-
-check: dev
- $(top_builddir)/test/etap/run
-
-cover: dev
- rm -f cover/*.coverdata
- COVER=1 COVER_BIN=./src/couchdb/ $(top_builddir)/test/etap/run
- SRC=./src/couchdb/ \
- $(ERL) -noshell \
- -pa src/etap \
- -eval 'etap_report:create()' \
- -s init stop > /dev/null 2>&1
-
-dev: all
- @echo "This command is intended for developers to use;"
- @echo "it creates development ini files as well as a"
- @echo "$(top_builddir)/tmp structure for development runtime files."
- @echo "Use ./utils/run to launch CouchDB from the source tree."
- mkdir -p $(top_builddir)/etc/couchdb/default.d
- mkdir -p $(top_builddir)/etc/couchdb/local.d
- mkdir -p $(top_builddir)/tmp/lib
- mkdir -p $(top_builddir)/tmp/log
- mkdir -p $(top_builddir)/tmp/run/couchdb
-
-install-data-hook:
- @echo
- @echo "You have installed Apache CouchDB, time to relax."
-
-distclean-local:
- rm -fr $(top_builddir)/etc/couchdb/default.d
- rm -fr $(top_builddir)/etc/couchdb/local.d
- rm -fr $(top_builddir)/tmp
-
-.PHONY: local-clean
-local-clean: maintainer-clean
- @echo "This command is intended for maintainers to use;"
- @echo "it deletes files that may need special tools to rebuild."
- rm -f $(top_srcdir)/INSTALL
- rm -f $(top_srcdir)/acinclude.m4
- rm -f $(top_srcdir)/aclocal.m4
- rm -f $(top_srcdir)/config.h.in
- rm -f $(top_srcdir)/configure
- rm -f $(top_srcdir)/test/etap/temp.*
- rm -f $(top_srcdir)/*.tar.gz
- rm -f $(top_srcdir)/*.tar.gz.*
- find $(top_srcdir) -name Makefile.in -exec rm -f {} \;
-
-dist-hook:
- find $(top_srcdir) -type f -name "._*" -exec rm -f {} \;
- find $(top_builddir) -type f -name "._*" -exec rm -f {} \;
-
-distcheck-hook:
- grep -rL 'http://www.apache.org/licenses/LICENSE-2.0' * \
- | grep -vEf license.skip; \
- test "$$?" -eq 1
-
-.PHONY: distsign
-distsign: distcheck check
- @# @@ unpack archive and run diff -r to double check missing files
- @# @@ does automake have anything that does this?
- gpg --armor --detach-sig --default-key DF3CEBA3 \
- < $(top_srcdir)/$(distdir).tar.gz \
- > $(top_srcdir)/$(distdir).tar.gz.asc
- md5sum $(top_srcdir)/$(distdir).tar.gz \
- > $(top_srcdir)/$(distdir).tar.gz.md5
- sha1sum $(top_srcdir)/$(distdir).tar.gz \
- > $(top_srcdir)/$(distdir).tar.gz.sha
diff --git a/README.Solaris b/README.Solaris
new file mode 100644
index 00000000..18b4b641
--- /dev/null
+++ b/README.Solaris
@@ -0,0 +1,6 @@
+
+To build on solaris, you will need some additional packages.
+
+sudo pkgin install erlang-14.1.1 spidermonkey-1.8.0 icu-4.2.1 scmgit-1.7.0.7
+
+BigCouch is tested on 5.11 snv_121 (http://genunix.org/dist/indiana/osol-1002-121-x86.iso)
diff --git a/README.md b/README.md
new file mode 100644
index 00000000..b6fb1a42
--- /dev/null
+++ b/README.md
@@ -0,0 +1,159 @@
+### Overview
+
+BigCouch is a highly available, fault-tolerant, clustered, mostly api-compliant version of [Apache CouchDB][1]. While it appears to the end-user as one CouchDB instance, it is in fact one or more BigCouch nodes in an elastic cluster, acting in concert to store and retrieve documents, index and serve views, and serve CouchApps. BigCouch has been developed and is continually maintained by [Cloudant][2] who offer hosted CouchDB as a service.
+
+Clusters behave according to concepts outlined in [Amazon's Dynamo paper][4], namely that each BigCouch node can accept requests, data is placed on partitions based on a consistent hashing algorithm, and quorum protocols are for read/write operations.
+
+### Contents
+
+ * README.md this file
+ * LICENSE open-source license governing BigCouch
+
+### Getting Started
+
+#### Prerequisites
+
+BigCouch has the same dependencies as CouchDB:
+
+ * Erlang (R13B03 or higher)
+ * ICU (4.2 is preferable)
+ * Spidermonkey (1.9.2 preferable, [https://launchpad.net/~commonjs/+archive/ppa/][6])
+ * LibCurl (7.18 or higher)
+ * OpenSSL
+ * make
+ * Python (2.4 or higher)
+
+#### Installing prerequisites on Ubuntu
+
+ sudo apt-get install erlang libicu42 libicu-dev libcurl4-openssl-dev
+
+To install Spidermonkey 1.9.2 from PPA:
+
+ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 74EE6429
+ sudo bash -c 'echo "deb http://ppa.launchpad.net/commonjs/ppa/ubuntu karmic main" >> /etc/apt/sources.list.d/commonjs.list'
+ sudo apt-get update
+ sudo apt-get install libmozjs-1.9.2 libmozjs-1.9.2-dev
+ sudo ln -s /usr/lib/libmozjs-1.9.2.so /usr/lib/libmozjs.so
+
+#### Installing prerequisites on Mac OS X with [Homebrew][7]
+
+ brew install erlang icu4c spidermonkey
+ brew ln icu4c
+
+#### Installing prerequisites on RedHat/Centos
+
+ yum install js-devel libicu libicu-devel openssl openssl-devel python python-devel
+
+ Erlang and LibCurl need to be installed from source to meet version requirements
+
+#### Building and installing BigCouch
+
+`$CLOUDANT_SRC` is the directory holding your downloaded source files, while `$PREFIX` is the prefix to which the software is installed (defaults to `/opt/bigcouch`):
+
+ cd $CLOUDANT_SRC
+ ./configure -p $PREFIX
+ make
+ sudo make install
+
+`sudo` is only necessary when installing to a prefix which is not user-writeable. In any case, the installer tries to chown the database directory and logfile to the user who configured BigCouchbigcouch.
+
+Run into any issues? Check out our wiki, [https://github.com/cloudant/bigcouch/wiki/Troubleshooting][8]
+
+#### Starting BigCouch
+
+ $PREFIX/bin/bigcouch
+
+Now, visit http://localhost:5984/_utils in a browser to verify the BigCouch node is operational.
+
+BigCouch listens on two ports. Defaults and explanations:
+
+ * 5984 - front door, cluster-aware port, appears as a standalone CouchDB.
+ * 5986 - back door, single-node port, used for admin functions
+
+Note: see the `rel/sv/README` file for information on using `runit` to stop/start BigCouch.
+
+#### Joining a new node to the cluster
+
+Each BigCouch node has a local `nodes` database, accessible through the backend interface on port 5986. Documents in the `nodes` DB name nodes in the cluster. To add a new node, create a document with that node's name as the ID. For example
+
+ curl -X PUT http://foo.example.com:5986/nodes/bigcouch@bar.example.com -d {}
+
+Everything else should be automatic, provided the machines can ping each other and the nodes set the same magic cookie. You are advised to change the magic cookie from the default in `rel/etc/vm.args` when on a public network.
+
+#### Local development cluster
+
+The `make dev` target will build a three-node cluster under the rel/ directory. Get the nodes running, like above, by doing the following (in separate terminals):
+
+ ./rel/dev1/bin/bigcouch
+ ./rel/dev2/bin/bigcouch
+ ./rel/dev3/bin/bigcouch
+
+These development nodes listen on ports 15984/15986 (dev1), 25984/25986 (dev2), and 35984/35986 (dev3). Now, once the nodes are started, join the dev2 node by sending this PUT to dev1's listening backend port:
+
+ curl -X PUT http://127.0.0.1:15986/nodes/dev2@127.0.0.1 -d {}
+
+To verify the two-node cluster has been linked properly, on either node (via proper frontend port), try:
+
+ curl http://127.0.0.1:15984/_membership
+
+You should see something similar to this:
+
+ {"all_nodes":["dev1@127.0.0.1","dev2@127.0.0.1"],"cluster_nodes":["dev1@127.0.0.1","dev2@127.0.0.1"]}
+
+Add node 3 to the cluster by sending a similar PUT to either of the first two nodes.
+
+#### Now What?
+
+If the above steps were successful, you should have a running BigCouch cluster that looks just like a standalone CouchDB. You may interact with it the same way you would a standalone CouchDB, via the HTTP REST interface.
+
+Because every node can handle requests equally, you may want to put a load balancer in front of the cluster and set up a round-robin strategy for distributing incoming requests across all of your cluster's nodes.
+
+##### Create a database:
+
+ curl -X PUT http://loadbalancer:5984/test_db
+
+Also note that 'q' and 'n' are query string arguments that may be specified. These are Cloudant-specific options, and their values and defaults are discussed in the Configuration section below. Ex: &q=12 or &n=4.
+
+##### Create a document:
+
+ curl -X PUT http://loadbalancer:5984/test_db/doc_1 -d '{"a":1,"b":2}'
+
+You may also provide 'r' and 'w' on the GET and PUT/POST document operations respectively. Their values and defaults are discussed in the Configuration section below. Ex: &r=3 for high consistency reads, or &w=1 for higher throughput writes.
+
+##### Check out Futon, CouchDB's web UI:
+
+ * [http://loadbalancer:5984/_utils][5]
+
+### Configuration
+
+#### Cluster constants
+
+_Q_ - number of partitions per database. Q is specified in the default.ini file, but may be provided as a URL parameter when creating a database. Default value is 8, query parameter is &q=12 or similar.
+
+_N_ - replication constant. N defaults to 3, but can vary by database just as Q can vary. N copies of each document will be written to the data store, on N different nodes.
+
+_R_ - read quorum constant. N writes have occurred for each document, as noted above. When reads are requested, N reads are sent to the N nodes that store the particular document. The system will return to the requesting client with the document when R successful reads have returned, and agree on versioning. R defaults to 2. Lower R values often result in faster reads at the expense of consistency. Higher R values usually result in slower reads, but more consistent, or agreed-upon data values returning.
+
+_W_ - write quorum constant. When writing the N copies, the data store will respond to the write client after W successful writes have completed. The remaining N-W writes are still being attempted in the background, but the client receives a 201 Created status and can resume execution. W defaults to 2. Lower W values mean more write throughput, and higher W values mean more data durability.
+
+### Troubleshooting
+
+Please see [http://github.com/cloudant/bigcouch/wiki/troubleshooting][8]
+
+### Contact
+
+Cloudant folks are usually hanging out in IRC. Freenode, channel #cloudant. We may also be reached:
+
+ * [http://cloudant.com][2]
+ * [info@cloudant.com][3]
+
+----
+
+[1]: http://couchdb.apache.org
+[2]: http://cloudant.com
+[3]: mailto:info@cloudant.com
+[4]: http://www.allthingsdistributed.com/2007/10/amazons_dynamo.html
+[5]: http://loadbalancer:5984/_utils
+[6]: https://launchpad.net/~commonjs/+archive/ppa/
+[7]: http://mxcl.github.com/homebrew/
+[8]: http://github.com/cloudant/bigcouch/wiki/troubleshooting
diff --git a/acinclude.m4.in b/acinclude.m4.in
deleted file mode 100644
index e1efe10c..00000000
--- a/acinclude.m4.in
+++ /dev/null
@@ -1,30 +0,0 @@
-dnl Licensed under the Apache License, Version 2.0 (the "License"); you may not
-dnl use this file except in compliance with the License. dnl You may obtain a
-dnl copy of the License at
-dnl
-dnl http://www.apache.org/licenses/LICENSE-2.0
-dnl
-dnl Unless required by applicable law or agreed to in writing, software
-dnl distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-dnl WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-dnl License for the specific language governing permissions and limitations
-dnl under the License.
-
-m4_define([LOCAL_PACKAGE_AUTHOR_NAME], [The Apache Software Foundation])
-m4_define([LOCAL_PACKAGE_AUTHOR_ADDRESS], [dev@couchdb.apache.org])
-m4_define([LOCAL_PACKAGE_IDENTIFIER], [couchdb])
-m4_define([LOCAL_PACKAGE_TARNAME], [apache-couchdb])
-m4_define([LOCAL_PACKAGE_NAME], [Apache CouchDB])
-m4_define([LOCAL_BUG_URI], [https://issues.apache.org/jira/browse/COUCHDB])
-m4_define([LOCAL_VERSION_MAJOR], [1])
-m4_define([LOCAL_VERSION_MINOR], [1])
-m4_define([LOCAL_VERSION_REVISION], [0])
-m4_define([LOCAL_VERSION_STAGE], [])
-m4_define([LOCAL_VERSION_RELEASE], [%release%])
-m4_define([LOCAL_VERSION_PRIMARY],
- [LOCAL_VERSION_MAJOR.LOCAL_VERSION_MINOR.LOCAL_VERSION_REVISION])
-m4_define([LOCAL_VERSION_SECONDARY],
- [LOCAL_VERSION_STAGE[]LOCAL_VERSION_RELEASE])
-m4_define([LOCAL_VERSION],
- [LOCAL_VERSION_PRIMARY[]LOCAL_VERSION_SECONDARY])
-
diff --git a/AUTHORS b/apps/couch/AUTHORS
index e0181c1d..e0181c1d 100644
--- a/AUTHORS
+++ b/apps/couch/AUTHORS
diff --git a/BUGS b/apps/couch/BUGS
index 8cd1d161..8cd1d161 100644
--- a/BUGS
+++ b/apps/couch/BUGS
diff --git a/CHANGES b/apps/couch/CHANGES
index 7c522b96..54a2e03c 100644
--- a/CHANGES
+++ b/apps/couch/CHANGES
@@ -1,6 +1,11 @@
Apache CouchDB CHANGES
======================
+Version 1.1.1
+-------------
+
+This version has not been released yet.
+
Version 1.1.0
-------------
@@ -56,6 +61,65 @@ URL Rewriter & Vhosts:
* Fix for variable substituion
+Version 1.0.2
+-------------
+
+Futon:
+
+ * Make test suite work with Safari and Chrome.
+ * Fixed animated progress spinner.
+ * Fix raw view document link due to overzealous URI encoding.
+ * Spell javascript correctly in loadScript(uri).
+
+Storage System:
+
+ * Fix leaking file handles after compacting databases and views.
+ * Fix databases forgetting their validation function after compaction.
+ * Fix occasional timeout errors after successfully compacting large databases.
+ * Fix ocassional error when writing to a database that has just been compacted.
+ * Fix occasional timeout errors on systems with slow or heavily loaded IO.
+ * Fix for OOME when compactions include documents with many conflicts.
+ * Fix for missing attachment compression when MIME types included parameters.
+ * Preserve purge metadata during compaction to avoid spurious view rebuilds.
+ * Fix spurious conflicts introduced when uploading an attachment after
+ a doc has been in a conflict. See COUCHDB-902 for details.
+ * Fix for frequently edited documents in multi-master deployments being
+ duplicated in _changes and _all_docs. See COUCHDDB-968 for details on how
+ to repair.
+ * Significantly higher read and write throughput against database and
+ view index files.
+
+Log System:
+
+ * Reduce lengthy stack traces.
+ * Allow logging of native <xml> types.
+
+HTTP Interface:
+
+ * Allow reduce=false parameter in map-only views.
+ * Fix parsing of Accept headers.
+ * Fix for multipart GET APIs when an attachment was created during a
+ local-local replication. See COUCHDB-1022 for details.
+
+Replicator:
+
+ * Updated ibrowse library to 2.1.2 fixing numerous replication issues.
+ * Make sure that the replicator respects HTTP settings defined in the config.
+ * Fix error when the ibrowse connection closes unexpectedly.
+ * Fix authenticated replication (with HTTP basic auth) of design documents
+ with attachments.
+ * Various fixes to make replication more resilient for edge-cases.
+
+View Server:
+
+ * Don't trigger view updates when requesting `_design/doc/_info`.
+ * Fix for circular references in CommonJS requires.
+ * Made isArray() function available to functions executed in the query server.
+ * Documents are now sealed before being passed to map functions.
+ * Force view compaction failure when duplicated document data exists. When
+ this error is seen in the logs users should rebuild their views from
+ scratch to fix the issue. See COUCHDB-999 for details.
+
Version 1.0.1
-------------
diff --git a/DEVELOPERS b/apps/couch/DEVELOPERS
index a7a6926e..a7a6926e 100644
--- a/DEVELOPERS
+++ b/apps/couch/DEVELOPERS
diff --git a/INSTALL.Unix b/apps/couch/INSTALL.Unix
index 768e3846..720134d4 100644
--- a/INSTALL.Unix
+++ b/apps/couch/INSTALL.Unix
@@ -8,7 +8,7 @@ Dependencies
You will need the following installed:
- * Erlang OTP (>=R12B5) (http://erlang.org/)
+ * Erlang OTP (>=R13B2) (http://erlang.org/)
* ICU (http://icu.sourceforge.net/)
* OpenSSL (http://www.openssl.org/)
* Mozilla SpiderMonkey (1.8) (http://www.mozilla.org/js/spidermonkey/)
diff --git a/INSTALL.Windows b/apps/couch/INSTALL.Windows
index d2082734..d2082734 100644
--- a/INSTALL.Windows
+++ b/apps/couch/INSTALL.Windows
diff --git a/apps/couch/LICENSE b/apps/couch/LICENSE
new file mode 100644
index 00000000..20a425b1
--- /dev/null
+++ b/apps/couch/LICENSE
@@ -0,0 +1,371 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+Apache CouchDB Subcomponents
+
+The Apache CouchDB project includes a number of subcomponents with separate
+copyright notices and license terms. Your use of the code for the these
+subcomponents is subject to the terms and conditions of the following licenses.
+
+For the m4/ac_check_icu.m4 component:
+
+ Copyright (c) 2005 Akos Maroy <darkeye@tyrell.hu>
+
+ Copying and distribution of this file, with or without modification, are
+ permitted in any medium without royalty provided the copyright notice
+ and this notice are preserved.
+
+For the share/www/script/jquery.js component:
+
+ Copyright (c) 2009 John Resig, http://jquery.com/
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+For the share/www/script/jquery.form.js component:
+
+ http://malsup.com/jquery/form/
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+For the share/www/script/json2.js component:
+
+ Public Domain
+
+ No warranty expressed or implied. Use at your own risk.
+
+For the src/mochiweb component:
+
+ Copyright (c) 2007 Mochi Media, Inc.
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+For the src/ibrowse component:
+
+ Copyright (c) 2006, Chandrashekhar Mullaparthi
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of the T-Mobile nor the names of its contributors may be
+ used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+For the src/erlang-oauth component:
+
+ Copyright (c) 2008-2009 Tim Fletcher <http://tfletcher.com/>
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+
+For the src/etap component:
+
+ Copyright (c) 2008-2009 Nick Gerakines <nick@gerakines.net>
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+
diff --git a/NEWS b/apps/couch/NEWS
index b709ef25..97eb58e7 100644
--- a/NEWS
+++ b/apps/couch/NEWS
@@ -7,6 +7,11 @@ For details about backwards incompatible changes, see:
Each release section notes when backwards incompatible changes have been made.
+Version 1.1.1
+-------------
+
+This version has not been released yet.
+
Version 1.1.0
-------------
@@ -32,6 +37,28 @@ This release contains backwards incompatible changes.
to lack of permissions.
* Added a "change password"-feature to Futon.
+Version 1.0.2
+-------------
+
+ * Make test suite work with Safari and Chrome.
+ * Fix leaking file handles after compacting databases and views.
+ * Fix databases forgetting their validation function after compaction.
+ * Fix occasional timeout errors.
+ * Reduce lengthy stack traces.
+ * Allow logging of native <xml> types.
+ * Updated ibrowse library to 2.1.2 fixing numerous replication issues.
+ * Fix authenticated replication of design documents with attachments.
+ * Fix multipart GET APIs by always sending attachments in compressed
+ form when the source attachment is compressed on disk. Fixes a possible
+ edge case when an attachment underwent local-local replication.
+ * Various fixes to make replicated more resilient for edge-cases.
+ * Don't trigger a view update when requesting `_design/doc/_info`.
+ * Fix for circular references in CommonJS requires.
+ * Fix for frequently edited documents in multi-master deployments being
+ duplicated in _changes and _all_docs.
+ * Fix spurious conflict generation during attachment uploads.
+ * Fix for various bugs in Futon.
+
Version 1.0.1
-------------
diff --git a/NOTICE b/apps/couch/NOTICE
index 4daa496f..4daa496f 100644
--- a/NOTICE
+++ b/apps/couch/NOTICE
diff --git a/README b/apps/couch/README
index 540226d3..540226d3 100644
--- a/README
+++ b/apps/couch/README
diff --git a/THANKS b/apps/couch/THANKS
index aae7991c..aae7991c 100644
--- a/THANKS
+++ b/apps/couch/THANKS
diff --git a/src/couchdb/priv/icu_driver/couch_icu_driver.c b/apps/couch/c_src/couch_icu_driver.c
index 1afe8eac..1afe8eac 100644
--- a/src/couchdb/priv/icu_driver/couch_icu_driver.c
+++ b/apps/couch/c_src/couch_icu_driver.c
diff --git a/src/couchdb/priv/spawnkillable/couchspawnkillable_win.c b/apps/couch/c_src/spawnkillable/couchspawnkillable_win.c
index 06782315..06782315 100644
--- a/src/couchdb/priv/spawnkillable/couchspawnkillable_win.c
+++ b/apps/couch/c_src/spawnkillable/couchspawnkillable_win.c
diff --git a/src/couchdb/couch_db.hrl b/apps/couch/include/couch_db.hrl
index 003cb688..a96d5d4f 100644
--- a/src/couchdb/couch_db.hrl
+++ b/apps/couch/include/couch_db.hrl
@@ -48,6 +48,7 @@
{id = <<"">>,
update_seq = 0,
deleted = false,
+ data_size = 0,
rev_tree = []
}).
@@ -126,9 +127,9 @@
{disk_version = ?LATEST_DISK_VERSION,
update_seq = 0,
unused = 0,
- fulldocinfo_by_id_btree_state = nil,
- docinfo_by_seq_btree_state = nil,
- local_docs_btree_state = nil,
+ id_tree_state = nil,
+ seq_tree_state = nil,
+ local_tree_state = nil,
purge_seq = 0,
purged_docs = nil,
security_ptr = nil,
@@ -141,16 +142,16 @@
compactor_pid = nil,
instance_start_time, % number of microsecs since jan 1 1970 as a binary string
fd,
- fd_ref_counter,
+ fd_monitor,
header = #db_header{},
committed_update_seq,
- fulldocinfo_by_id_btree,
- docinfo_by_seq_btree,
- local_docs_btree,
+ id_tree,
+ seq_tree,
+ local_tree,
update_seq,
name,
filepath,
- validate_doc_funs = [],
+ validate_doc_funs = undefined,
security = [],
security_ptr = nil,
user_ctx = #user_ctx{},
@@ -181,7 +182,10 @@
stale = false,
multi_get = false,
callback = nil,
- list = nil
+ list = nil,
+ keys = nil,
+ sorted = true,
+ extra = []
}).
-record(view_fold_helper_funs, {
@@ -206,7 +210,7 @@
-record(group, {
sig=nil,
- db=nil,
+ dbname,
fd=nil,
name,
def_lang,
@@ -243,7 +247,7 @@
auth = [],
resource = "",
headers = [
- {"User-Agent", "CouchDB/"++couch_server:get_version()},
+ {"User-Agent", "CouchDB/"++couch:version()},
{"Accept", "application/json"},
{"Accept-Encoding", "gzip"}
],
@@ -276,3 +280,20 @@
db_open_options = []
}).
+-record(proc, {
+ pid,
+ lang,
+ client = nil,
+ ddoc_keys = [],
+ prompt_fun,
+ set_timeout_fun,
+ stop_fun
+}).
+
+-record(leaf, {
+ deleted,
+ ptr,
+ seq,
+ size = 0,
+ atts = []
+}).
diff --git a/license.skip b/apps/couch/license.skip
index 151ccc08..151ccc08 100644
--- a/license.skip
+++ b/apps/couch/license.skip
diff --git a/src/couchdb/priv/spawnkillable/couchspawnkillable.sh b/apps/couch/priv/couchspawnkillable.sh
index f8d042e3..f8d042e3 100644..100755
--- a/src/couchdb/priv/spawnkillable/couchspawnkillable.sh
+++ b/apps/couch/priv/couchspawnkillable.sh
diff --git a/src/couchdb/priv/stat_descriptions.cfg.in b/apps/couch/priv/stat_descriptions.cfg
index b80d7684..b80d7684 100644
--- a/src/couchdb/priv/stat_descriptions.cfg.in
+++ b/apps/couch/priv/stat_descriptions.cfg
diff --git a/apps/couch/rebar.config b/apps/couch/rebar.config
new file mode 100644
index 00000000..25b7e569
--- /dev/null
+++ b/apps/couch/rebar.config
@@ -0,0 +1,10 @@
+{so_name, "couch_icu_driver.so"}.
+{port_envs, [
+ {"DRV_CFLAGS", "$DRV_CFLAGS -DPIC -O2 -fno-common"},
+ {"DRV_LDFLAGS", "$DRV_LDFLAGS -lm -licuuc -licudata -licui18n -lpthread"},
+ {"linux", "DRV_LDFLAGS", "$DRV_LDFLAGS -lcrypt"},
+ {"freebsd", "DRV_CFLAGS", "$DRV_CFLAGS -I/usr/local/include"},
+ {"freebsd", "DRV_LDFLAGS", "$DRV_LDFLAGS -L/usr/local/lib"},
+ {"solaris", "CC", "/usr/sfw/bin/gcc"},
+ {"solaris", "DRV_LDFLAGS", "$DRV_LDFLAGS -L/opt/local/lib"}
+]}.
diff --git a/src/couchdb/couch.app.tpl.in b/apps/couch/src/couch.app.src
index 36b0b34c..3b94feb7 100644
--- a/src/couchdb/couch.app.tpl.in
+++ b/apps/couch/src/couch.app.src
@@ -1,7 +1,6 @@
{application, couch, [
- {description, "@package_name@"},
- {vsn, "@version@"},
- {modules, [@modules@]},
+ {description, "Apache CouchDB"},
+ {vsn, "%VSN%"},
{registered, [
couch_config,
couch_db_update,
@@ -10,7 +9,7 @@
couch_httpd,
couch_log,
couch_primary_services,
- couch_query_servers,
+ couch_proc_manager,
couch_rep_sup,
couch_secondary_services,
couch_server,
@@ -20,10 +19,7 @@
couch_task_status,
couch_view
]},
- {mod, {couch_app, [
- "%localconfdir%/@defaultini@",
- "%localconfdir%/@localini@"
- ]}},
- {applications, [kernel, stdlib]},
- {included_applications, [crypto, sasl, inets, oauth, ibrowse, mochiweb]}
+ {mod, {couch_app, []}},
+ {applications, [kernel, stdlib, crypto, sasl, inets, oauth, ibrowse,
+ mochiweb, ssl]}
]}.
diff --git a/src/couchdb/couch.erl b/apps/couch/src/couch.erl
index 956e9489..f6b048a5 100644
--- a/src/couchdb/couch.erl
+++ b/apps/couch/src/couch.erl
@@ -37,3 +37,7 @@ reload() ->
{error, Reason} ->
{error, Reason}
end.
+
+version() ->
+ {ok, FullVersion} = application:get_key(couch, vsn),
+ hd(string:tokens(FullVersion, "-")).
diff --git a/src/couchdb/couch_app.erl b/apps/couch/src/couch_app.erl
index 232953d9..70e1b7e0 100644
--- a/src/couchdb/couch_app.erl
+++ b/apps/couch/src/couch_app.erl
@@ -18,19 +18,17 @@
-export([start/2, stop/1]).
-start(_Type, DefaultIniFiles) ->
- IniFiles = get_ini_files(DefaultIniFiles),
- case start_apps([crypto, public_key, sasl, inets, oauth, ssl, ibrowse, mochiweb]) of
- ok ->
- couch_server_sup:start_link(IniFiles);
- {error, Reason} ->
- {error, Reason}
- end.
+start(_Type, _Args) ->
+ catch erlang:system_flag(scheduler_bind_type, default_bind),
+ IniFiles = get_ini_files(),
+ couch_server_sup:start_link(IniFiles).
stop(_) ->
ok.
-get_ini_files(Default) ->
+get_ini_files() ->
+ Etc = filename:join(code:root_dir(), "etc"),
+ Default = [filename:join(Etc,"default.ini"), filename:join(Etc,"local.ini")],
case init:get_argument(couch_ini) of
error ->
Default;
@@ -39,18 +37,3 @@ get_ini_files(Default) ->
{ok, [Values]} ->
Values
end.
-
-start_apps([]) ->
- ok;
-start_apps([App|Rest]) ->
- case application:start(App) of
- ok ->
- start_apps(Rest);
- {error, {already_started, App}} ->
- start_apps(Rest);
- {error, _Reason} when App =:= public_key ->
- % ignore on R12B5
- start_apps(Rest);
- {error, _Reason} ->
- {error, {app_would_not_start, App}}
- end.
diff --git a/src/couchdb/couch_auth_cache.erl b/apps/couch/src/couch_auth_cache.erl
index e0715b88..8b911543 100644
--- a/src/couchdb/couch_auth_cache.erl
+++ b/apps/couch/src/couch_auth_cache.erl
@@ -291,6 +291,8 @@ refresh_entries(AuthDb) ->
end.
+refresh_entry(Db, #full_doc_info{} = FDI) ->
+ refresh_entry(Db, couch_doc:to_doc_info(FDI));
refresh_entry(Db, #doc_info{high_seq = DocSeq} = DocInfo) ->
case is_user_doc(DocInfo) of
{true, UserName} ->
diff --git a/src/couchdb/couch_btree.erl b/apps/couch/src/couch_btree.erl
index f8c126f3..3f2e86d8 100644
--- a/src/couchdb/couch_btree.erl
+++ b/apps/couch/src/couch_btree.erl
@@ -16,23 +16,27 @@
-export([fold/4, full_reduce/1, final_reduce/2, foldl/3, foldl/4]).
-export([fold_reduce/4, lookup/2, get_state/1, set_options/2]).
--define(CHUNK_THRESHOLD, 16#4ff).
-
-record(btree,
{fd,
root,
- extract_kv = fun({Key, Value}) -> {Key, Value} end,
- assemble_kv = fun(Key, Value) -> {Key, Value} end,
- less = fun(A, B) -> A < B end,
+ extract_kv,
+ assemble_kv,
+ less,
reduce = nil
}).
+extract(#btree{extract_kv = undefined}, Value) ->
+ Value;
extract(#btree{extract_kv=Extract}, Value) ->
Extract(Value).
+assemble(#btree{assemble_kv = undefined}, Key, Value) ->
+ {Key, Value};
assemble(#btree{assemble_kv=Assemble}, Key, Value) ->
Assemble(Key, Value).
+less(#btree{less = undefined}, A, B) ->
+ A < B;
less(#btree{less=Less}, A, B) ->
Less(A, B).
@@ -61,8 +65,8 @@ final_reduce(#btree{reduce=Reduce}, Val) ->
final_reduce(Reduce, Val);
final_reduce(Reduce, {[], []}) ->
Reduce(reduce, []);
-final_reduce(_Bt, {[], [Red]}) ->
- Red;
+final_reduce(Reduce, {[], [Red]}) ->
+ Reduce(rereduce, [Red]);
final_reduce(Reduce, {[], Reductions}) ->
Reduce(rereduce, Reductions);
final_reduce(Reduce, {KVs, Reductions}) ->
@@ -100,8 +104,8 @@ fold_reduce(#btree{root=Root}=Bt, Fun, Acc, Options) ->
full_reduce(#btree{root=nil,reduce=Reduce}) ->
{ok, Reduce(reduce, [])};
-full_reduce(#btree{root={_P, Red}}) ->
- {ok, Red}.
+full_reduce(#btree{root={_P, Red}, reduce=Reduce}) ->
+ {ok, Reduce(rereduce, [Red])}.
% wraps a 2 arity function with the proper 3 arity function
convert_fun_arity(Fun) when is_function(Fun, 2) ->
@@ -109,29 +113,29 @@ convert_fun_arity(Fun) when is_function(Fun, 2) ->
convert_fun_arity(Fun) when is_function(Fun, 3) ->
Fun. % Already arity 3
-make_key_in_end_range_function(#btree{less=Less}, fwd, Options) ->
+make_key_in_end_range_function(Bt, fwd, Options) ->
case couch_util:get_value(end_key_gt, Options) of
undefined ->
case couch_util:get_value(end_key, Options) of
undefined ->
fun(_Key) -> true end;
LastKey ->
- fun(Key) -> not Less(LastKey, Key) end
+ fun(Key) -> not less(Bt, LastKey, Key) end
end;
EndKey ->
- fun(Key) -> Less(Key, EndKey) end
+ fun(Key) -> less(Bt, Key, EndKey) end
end;
-make_key_in_end_range_function(#btree{less=Less}, rev, Options) ->
+make_key_in_end_range_function(Bt, rev, Options) ->
case couch_util:get_value(end_key_gt, Options) of
undefined ->
case couch_util:get_value(end_key, Options) of
undefined ->
fun(_Key) -> true end;
LastKey ->
- fun(Key) -> not Less(Key, LastKey) end
+ fun(Key) -> not less(Bt, Key, LastKey) end
end;
EndKey ->
- fun(Key) -> Less(EndKey, Key) end
+ fun(Key) -> less(Bt, EndKey, Key) end
end.
@@ -201,7 +205,11 @@ op_order(remove) -> 2;
op_order(insert) -> 3.
lookup(#btree{root=Root, less=Less}=Bt, Keys) ->
- SortedKeys = lists:sort(Less, Keys),
+ case Less of undefined ->
+ SortedKeys = lists:sort(Keys);
+ _ ->
+ SortedKeys = lists:sort(Less, Keys)
+ end,
{ok, SortedResults} = lookup(Bt, Root, SortedKeys),
% We want to return the results in the same order as the keys were input
% but we may have changed the order when we sorted. So we need to put the
@@ -274,9 +282,11 @@ complete_root(Bt, KPs) ->
% it's probably really inefficient.
chunkify(InList) ->
+ BaseChunkSize = list_to_integer(couch_config:get("couchdb",
+ "btree_chunk_size", "1279")),
case byte_size(term_to_binary(InList)) of
- Size when Size > ?CHUNK_THRESHOLD ->
- NumberOfChunksLikely = ((Size div ?CHUNK_THRESHOLD) + 1),
+ Size when Size > BaseChunkSize ->
+ NumberOfChunksLikely = ((Size div BaseChunkSize) + 1),
ChunkThreshold = Size div NumberOfChunksLikely,
chunkify(InList, ChunkThreshold, [], 0, []);
_Else ->
diff --git a/src/couchdb/couch_changes.erl b/apps/couch/src/couch_changes.erl
index 6eb6f7e1..8d5eae70 100644
--- a/src/couchdb/couch_changes.erl
+++ b/apps/couch/src/couch_changes.erl
@@ -13,9 +13,10 @@
-module(couch_changes).
-include("couch_db.hrl").
--export([handle_changes/3]).
+-export([handle_changes/3, get_changes_timeout/2, get_rest_db_updated/0,
+ configure_filter/4, filter/2]).
-%% @type Req -> #httpd{} | {json_req, JsonObj()}
+%% @spec handle_changes(#changes_args{}, #httpd{} | {json_req, {[any()]}}, #db{}) -> any()
handle_changes(#changes_args{style=Style}=Args1, Req, Db) ->
#changes_args{feed = Feed} = Args = Args1#changes_args{
filter = make_filter_fun(Args1#changes_args.filter, Style, Req, Db)
@@ -77,7 +78,8 @@ get_callback_acc({Callback, _UserAcc} = Pair) when is_function(Callback, 3) ->
get_callback_acc(Callback) when is_function(Callback, 2) ->
{fun(Ev, Data, _) -> Callback(Ev, Data) end, ok}.
-%% @type Req -> #httpd{} | {json_req, JsonObj()}
+%% @spec make_filter_fun(string(), main_only|all_docs, #httpd{} | {json_req,
+%% {[any()]}}, #db{}) -> fun()
make_filter_fun([$_ | _] = FilterName, Style, Req, Db) ->
builtin_filter_fun(FilterName, Style, Req, Db);
make_filter_fun(FilterName, Style, Req, Db) ->
@@ -113,7 +115,7 @@ os_filter_fun(FilterName, Style, Req, Db) ->
[{[{<<"rev">>, couch_doc:rev_to_str({RevPos,RevId})}]}
|| {Pass, #doc{revs={RevPos,[RevId|_]}}}
<- lists:zip(Passes, Docs), Pass == true]
- end;
+ end;
_Else ->
throw({bad_request,
"filter parameter must be of the form `designname/filtername`"})
@@ -162,6 +164,45 @@ builtin_results(Style, [#rev_info{rev=Rev}|_]=Revs) ->
|| #rev_info{rev=R} <- Revs]
end.
+configure_filter(Filter, Style, Req, Db) when is_list(Filter) ->
+ case [?l2b(couch_httpd:unquote(X)) || X <- string:tokens(Filter, "/")] of
+ [] ->
+ % fall back to standard filter
+ Style;
+ [DName, FName] ->
+ JsonReq = chttpd_external:json_req_obj(Req, Db),
+ DesignId = <<"_design/", DName/binary>>,
+ DDoc = chttpd_db:couch_doc_open(Db, DesignId, nil, []),
+ % validate that the ddoc has the filter fun
+ #doc{body={Props}} = DDoc,
+ couch_util:get_nested_json_value({Props}, [<<"filters">>, FName]),
+ {custom, Style, {Db, JsonReq, DDoc, FName}};
+ _Else ->
+ throw({bad_request,
+ "filter parameter must be of the form `designname/filtername`"})
+ end;
+configure_filter(_, Style, _, _) ->
+ Style.
+
+filter(#doc_info{revs=[#rev_info{rev=Rev}|_]}, main_only) ->
+ [{[{<<"rev">>, couch_doc:rev_to_str(Rev)}]}];
+filter(#doc_info{revs=Revs}, all_docs) ->
+ [{[{<<"rev">>, couch_doc:rev_to_str(Rev)}]} || #rev_info{rev=Rev} <- Revs];
+filter(#doc_info{id=Id, revs=RevInfos}, {custom, main_only, Acc}) ->
+ custom_filter(Id, [(hd(RevInfos))#rev_info.rev], Acc);
+filter(#doc_info{id=Id, revs=RevInfos}, {custom, all_docs, Acc}) ->
+ custom_filter(Id, [R || #rev_info{rev=R} <- RevInfos], Acc).
+
+custom_filter(Id, Revs, {Db, JsonReq, DDoc, Filter}) ->
+ {ok, Results} = fabric:open_revs(Db, Id, Revs, [deleted, conflicts]),
+ Docs = [Doc || {ok, Doc} <- Results],
+ {ok, Passes} = couch_query_servers:filter_docs({json_req,JsonReq}, Db,
+ DDoc, Filter, Docs),
+ % ?LOG_INFO("filtering ~p ~p", [Id, Passes]),
+ [{[{<<"rev">>, couch_doc:rev_to_str({RevPos,RevId})}]}
+ || {Pass, #doc{revs={RevPos,[RevId|_]}}}
+ <- lists:zip(Passes, Docs), Pass == true].
+
get_changes_timeout(Args, Callback) ->
#changes_args{
heartbeat = Heartbeat,
@@ -337,3 +378,8 @@ get_rest_db_updated(UserAcc) ->
after 0 ->
{updated, UserAcc}
end.
+
+get_rest_db_updated() ->
+ receive db_updated -> get_rest_db_updated()
+ after 0 -> updated
+ end.
diff --git a/src/couchdb/couch_config.erl b/apps/couch/src/couch_config.erl
index 792ff5a0..933bb5d5 100644
--- a/src/couchdb/couch_config.erl
+++ b/apps/couch/src/couch_config.erl
@@ -88,7 +88,7 @@ register(Fun) ->
?MODULE:register(Fun, self()).
register(Fun, Pid) ->
- gen_server:call(?MODULE, {register, Fun, Pid}).
+ couch_config_event:register(Fun, Pid).
init(IniFiles) ->
@@ -115,7 +115,7 @@ terminate(_Reason, _State) ->
handle_call(all, _From, Config) ->
Resp = lists:sort((ets:tab2list(?MODULE))),
{reply, Resp, Config};
-handle_call({set, Sec, Key, Val, Persist}, From, Config) ->
+handle_call({set, Sec, Key, Val, Persist}, _From, Config) ->
Result = case {Persist, Config#config.write_filename} of
{true, undefined} ->
ok;
@@ -127,15 +127,13 @@ handle_call({set, Sec, Key, Val, Persist}, From, Config) ->
case Result of
ok ->
true = ets:insert(?MODULE, {{Sec, Key}, Val}),
- spawn_link(fun() ->
- [catch F(Sec, Key, Val, Persist) || {_Pid, F} <- Config#config.notify_funs],
- gen_server:reply(From, ok)
- end),
- {noreply, Config};
+ Event = {config_change, Sec, Key, Val, Persist},
+ gen_event:sync_notify(couch_config_event, Event),
+ {reply, ok, Config};
_Error ->
{reply, Result, Config}
end;
-handle_call({delete, Sec, Key, Persist}, From, Config) ->
+handle_call({delete, Sec, Key, Persist}, _From, Config) ->
true = ets:delete(?MODULE, {Sec,Key}),
case {Persist, Config#config.write_filename} of
{true, undefined} ->
@@ -145,26 +143,9 @@ handle_call({delete, Sec, Key, Persist}, From, Config) ->
_ ->
ok
end,
- spawn_link(fun() ->
- [catch F(Sec, Key, deleted, Persist) || {_Pid, F} <- Config#config.notify_funs],
- gen_server:reply(From, ok)
- end),
- {noreply, Config};
-handle_call({register, Fun, Pid}, _From, #config{notify_funs=PidFuns}=Config) ->
- erlang:monitor(process, Pid),
- % convert 1 and 2 arity to 3 arity
- Fun2 =
- case Fun of
- _ when is_function(Fun, 1) ->
- fun(Section, _Key, _Value, _Persist) -> Fun(Section) end;
- _ when is_function(Fun, 2) ->
- fun(Section, Key, _Value, _Persist) -> Fun(Section, Key) end;
- _ when is_function(Fun, 3) ->
- fun(Section, Key, Value, _Persist) -> Fun(Section, Key, Value) end;
- _ when is_function(Fun, 4) ->
- Fun
- end,
- {reply, ok, Config#config{notify_funs=[{Pid, Fun2} | PidFuns]}}.
+ Event = {config_change, Sec, Key, deleted, Persist},
+ gen_event:sync_notify(couch_config_event, Event),
+ {reply, ok, Config}.
handle_cast(stop, State) ->
@@ -172,10 +153,9 @@ handle_cast(stop, State) ->
handle_cast(_Msg, State) ->
{noreply, State}.
-handle_info({'DOWN', _, _, DownPid, _}, #config{notify_funs=PidFuns}=Config) ->
- % remove any funs registered by the downed process
- FilteredPidFuns = [{Pid,Fun} || {Pid,Fun} <- PidFuns, Pid /= DownPid],
- {noreply, Config#config{notify_funs=FilteredPidFuns}}.
+handle_info(Info, State) ->
+ ?LOG_ERROR("couch_config:handle_info Info: ~p~n", [Info]),
+ {noreply, State}.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
diff --git a/apps/couch/src/couch_config_event.erl b/apps/couch/src/couch_config_event.erl
new file mode 100644
index 00000000..e353c7d8
--- /dev/null
+++ b/apps/couch/src/couch_config_event.erl
@@ -0,0 +1,46 @@
+-module(couch_config_event).
+-behaviour(gen_event).
+-export([init/1, handle_event/2, handle_call/2, handle_info/2, terminate/2,
+ code_change/3]).
+
+-export([start_link/0, register/2]).
+
+-include("couch_db.hrl").
+
+start_link() ->
+ gen_event:start_link({local, ?MODULE}).
+
+register(Fun, Pid) ->
+ gen_event:add_handler(?MODULE, {?MODULE, Fun}, [Fun, Pid]).
+
+init([Fun, Pid]) ->
+ Ref = erlang:monitor(process, Pid),
+ {ok, {Fun, Ref}}.
+
+handle_event({config_change,Sec,_,_,_}, {F,_}=St) when is_function(F,1) ->
+ catch F(Sec),
+ {ok, St};
+handle_event({config_change,Sec,K,_,_}, {F,_}=St) when is_function(F,2) ->
+ catch F(Sec,K),
+ {ok, St};
+handle_event({config_change,Sec,K,V,_}, {F,_}=St) when is_function(F,3) ->
+ catch F(Sec,K,V),
+ {ok, St};
+handle_event({config_change,Sec,K,V,Write}, {F,_}=St) when is_function(F,4) ->
+ catch F(Sec,K,V,Write),
+ {ok, St}.
+
+handle_call(_Request, St) ->
+ {ok, ok, St}.
+
+handle_info({'DOWN', Ref, _, _, _}, {_, Ref}) ->
+ remove_handler;
+handle_info(_Info, St) ->
+ {ok, St}.
+
+terminate(Reason, St) ->
+ ?LOG_INFO("config_event handler ~p terminating with ~p", [St, Reason]),
+ ok.
+
+code_change(_OldVsn, St, _Extra) ->
+ {ok, St}.
diff --git a/src/couchdb/couch_config_writer.erl b/apps/couch/src/couch_config_writer.erl
index decd269a..decd269a 100644
--- a/src/couchdb/couch_config_writer.erl
+++ b/apps/couch/src/couch_config_writer.erl
diff --git a/src/couchdb/couch_db.erl b/apps/couch/src/couch_db.erl
index 85f7e291..e8a0824c 100644
--- a/src/couchdb/couch_db.erl
+++ b/apps/couch/src/couch_db.erl
@@ -11,7 +11,6 @@
% the License.
-module(couch_db).
--behaviour(gen_server).
-export([open/2,open_int/2,close/1,create/2,start_compact/1,get_db_info/1,get_design_docs/1]).
-export([open_ref_counted/2,is_idle/1,monitor/1,count_changes_since/2]).
@@ -22,22 +21,21 @@
-export([enum_docs/4,enum_docs_since/5]).
-export([enum_docs_since_reduce_to_count/1,enum_docs_reduce_to_count/1]).
-export([increment_update_seq/1,get_purge_seq/1,purge_docs/2,get_last_purged/1]).
--export([start_link/3,open_doc_int/3,ensure_full_commit/1]).
+-export([start_link/3,open_doc_int/3,ensure_full_commit/1,ensure_full_commit/2]).
-export([set_security/2,get_security/1]).
--export([init/1,terminate/2,handle_call/3,handle_cast/2,code_change/3,handle_info/2]).
-export([changes_since/5,changes_since/6,read_doc/2,new_revid/1]).
--export([check_is_admin/1, check_is_reader/1]).
--export([reopen/1]).
+-export([check_is_admin/1, check_is_reader/1, get_doc_count/1]).
+-export([reopen/1, make_doc/5]).
-include("couch_db.hrl").
-
start_link(DbName, Filepath, Options) ->
case open_db_file(Filepath, Options) of
{ok, Fd} ->
- StartResult = gen_server:start_link(couch_db, {DbName, Filepath, Fd, Options}, []),
+ {ok, UpdaterPid} = gen_server:start_link(couch_db_updater, {DbName,
+ Filepath, Fd, Options}, []),
unlink(Fd),
- StartResult;
+ gen_server:call(UpdaterPid, get_db);
Else ->
Else
end.
@@ -53,7 +51,7 @@ open_db_file(Filepath, Options) ->
{ok, Fd} ->
?LOG_INFO("Found ~s~s compaction file, using as primary storage.", [Filepath, ".compact"]),
ok = file:rename(Filepath ++ ".compact", Filepath),
- ok = couch_file:sync(Fd),
+ ok = couch_file:sync(Filepath),
{ok, Fd};
{error, enoent} ->
{not_found, no_db_file}
@@ -87,36 +85,44 @@ open(DbName, Options) ->
Else -> Else
end.
-reopen(#db{main_pid = Pid, fd_ref_counter = OldRefCntr, user_ctx = UserCtx}) ->
- {ok, #db{fd_ref_counter = NewRefCntr} = NewDb} =
- gen_server:call(Pid, get_db, infinity),
- case NewRefCntr =:= OldRefCntr of
+reopen(#db{main_pid = Pid, fd = Fd, fd_monitor = OldRef, user_ctx = UserCtx}) ->
+ {ok, #db{fd = NewFd} = NewDb} = gen_server:call(Pid, get_db, infinity),
+ case NewFd =:= Fd of
true ->
- ok;
+ {ok, NewDb#db{user_ctx = UserCtx}};
false ->
- couch_ref_counter:add(NewRefCntr),
- catch couch_ref_counter:drop(OldRefCntr)
- end,
- {ok, NewDb#db{user_ctx = UserCtx}}.
+ erlang:demonitor(OldRef),
+ NewRef = erlang:monitor(process, NewFd),
+ {ok, NewDb#db{user_ctx = UserCtx, fd_monitor = NewRef}}
+ end.
+
+ensure_full_commit(#db{main_pid=Pid, instance_start_time=StartTime}) ->
+ ok = gen_server:call(Pid, full_commit, infinity),
+ {ok, StartTime}.
-ensure_full_commit(#db{update_pid=UpdatePid,instance_start_time=StartTime}) ->
- ok = gen_server:call(UpdatePid, full_commit, infinity),
+ensure_full_commit(Db, RequiredSeq) ->
+ #db{main_pid=Pid, instance_start_time=StartTime} = Db,
+ ok = gen_server:call(Pid, {full_commit, RequiredSeq}, infinity),
{ok, StartTime}.
-close(#db{fd_ref_counter=RefCntr}) ->
- couch_ref_counter:drop(RefCntr).
+close(#db{fd_monitor=RefCntr}) ->
+ erlang:demonitor(RefCntr).
open_ref_counted(MainPid, OpenedPid) ->
gen_server:call(MainPid, {open_ref_count, OpenedPid}).
-is_idle(MainPid) ->
- gen_server:call(MainPid, is_idle).
+is_idle(#db{compactor_pid=nil, waiting_delayed_commit=nil} = Db) ->
+ {monitored_by, Pids} = erlang:process_info(Db#db.fd, monitored_by),
+ (Pids -- [Db#db.main_pid, whereis(couch_stats_collector)]) =:= [];
+is_idle(_Db) ->
+ false.
monitor(#db{main_pid=MainPid}) ->
erlang:monitor(process, MainPid).
-start_compact(#db{update_pid=Pid}) ->
- gen_server:call(Pid, start_compact).
+start_compact(#db{main_pid=Pid}) ->
+ {ok, _} = gen_server:call(Pid, start_compact),
+ ok.
delete_doc(Db, Id, Revisions) ->
DeletedDocs = [#doc{id=Id, revs=[Rev], deleted=true} || Rev <- Revisions],
@@ -223,13 +229,13 @@ get_full_doc_info(Db, Id) ->
Result.
get_full_doc_infos(Db, Ids) ->
- couch_btree:lookup(Db#db.fulldocinfo_by_id_btree, Ids).
+ couch_btree:lookup(Db#db.id_tree, Ids).
-increment_update_seq(#db{update_pid=UpdatePid}) ->
- gen_server:call(UpdatePid, increment_update_seq).
+increment_update_seq(#db{main_pid=Pid}) ->
+ gen_server:call(Pid, increment_update_seq).
-purge_docs(#db{update_pid=UpdatePid}, IdsRevs) ->
- gen_server:call(UpdatePid, {purge_docs, IdsRevs}).
+purge_docs(#db{main_pid=Pid}, IdsRevs) ->
+ gen_server:call(Pid, {purge_docs, IdsRevs}).
get_committed_update_seq(#db{committed_update_seq=Seq}) ->
Seq.
@@ -245,17 +251,21 @@ get_last_purged(#db{header=#db_header{purged_docs=nil}}) ->
get_last_purged(#db{fd=Fd, header=#db_header{purged_docs=PurgedPointer}}) ->
couch_file:pread_term(Fd, PurgedPointer).
+get_doc_count(Db) ->
+ {ok, {Count, _, _}} = couch_btree:full_reduce(Db#db.id_tree),
+ {ok, Count}.
+
get_db_info(Db) ->
#db{fd=Fd,
header=#db_header{disk_version=DiskVersion},
compactor_pid=Compactor,
update_seq=SeqNum,
name=Name,
- fulldocinfo_by_id_btree=FullDocBtree,
+ id_tree=FullDocBtree,
instance_start_time=StartTime,
committed_update_seq=CommittedUpdateSeq} = Db,
{ok, Size} = couch_file:bytes(Fd),
- {ok, {Count, DelCount}} = couch_btree:full_reduce(FullDocBtree),
+ {ok, {Count, DelCount, DataSize}} = couch_btree:full_reduce(FullDocBtree),
InfoList = [
{db_name, Name},
{doc_count, Count},
@@ -264,13 +274,21 @@ get_db_info(Db) ->
{purge_seq, couch_db:get_purge_seq(Db)},
{compact_running, Compactor/=nil},
{disk_size, Size},
+ {other, {[{data_size, DataSize}]}},
{instance_start_time, StartTime},
{disk_format_version, DiskVersion},
{committed_update_seq, CommittedUpdateSeq}
],
{ok, InfoList}.
-get_design_docs(#db{fulldocinfo_by_id_btree=Btree}=Db) ->
+get_design_docs(#db{name = <<"shards/", _/binary>> = ShardName}) ->
+ {_, Ref} = spawn_monitor(fun() ->
+ exit(fabric:design_docs(mem3:dbname(ShardName)))
+ end),
+ receive {'DOWN', Ref, _, _, Response} ->
+ Response
+ end;
+get_design_docs(#db{id_tree=Btree}=Db) ->
{ok,_, Docs} = couch_btree:fold(Btree,
fun(#full_doc_info{id= <<"_design/",_/binary>>}=FullDocInfo, _Reds, AccDocs) ->
{ok, Doc} = couch_db:open_doc_int(Db, FullDocInfo, []),
@@ -332,7 +350,7 @@ get_readers(#db{security=SecProps}) ->
get_security(#db{security=SecProps}) ->
{SecProps}.
-set_security(#db{update_pid=Pid}=Db, {NewSecProps}) when is_list(NewSecProps) ->
+set_security(#db{main_pid=Pid}=Db, {NewSecProps}) when is_list(NewSecProps) ->
check_is_admin(Db),
ok = validate_security_object(NewSecProps),
ok = gen_server:call(Pid, {set_security, NewSecProps}, infinity),
@@ -367,7 +385,7 @@ validate_names_and_roles({Props}) when is_list(Props) ->
get_revs_limit(#db{revs_limit=Limit}) ->
Limit.
-set_revs_limit(#db{update_pid=Pid}=Db, Limit) when Limit > 0 ->
+set_revs_limit(#db{main_pid=Pid}=Db, Limit) when Limit > 0 ->
check_is_admin(Db),
gen_server:call(Pid, {set_revs_limit, Limit}, infinity);
set_revs_limit(_Db, _Limit) ->
@@ -419,6 +437,9 @@ group_alike_docs([Doc|Rest], [Bucket|RestBuckets]) ->
validate_doc_update(#db{}=Db, #doc{id= <<"_design/",_/binary>>}, _GetDiskDocFun) ->
catch check_is_admin(Db);
+validate_doc_update(#db{validate_doc_funs = undefined} = Db, Doc, Fun) ->
+ ValidationFuns = load_validation_funs(Db),
+ validate_doc_update(Db#db{validate_doc_funs = ValidationFuns}, Doc, Fun);
validate_doc_update(#db{validate_doc_funs=[]}, _Doc, _GetDiskDocFun) ->
ok;
validate_doc_update(_Db, #doc{id= <<"_local/",_/binary>>}, _GetDiskDocFun) ->
@@ -437,6 +458,27 @@ validate_doc_update(Db, Doc, GetDiskDocFun) ->
Error
end.
+% to be safe, spawn a middleman here
+load_validation_funs(#db{main_pid = Pid} = Db) ->
+ {_, Ref} = spawn_monitor(fun() ->
+ {ok, DesignDocs} = get_design_docs(Db),
+ exit({ok, lists:flatmap(fun(DesignDoc) ->
+ case couch_doc:get_validate_doc_fun(DesignDoc) of
+ nil ->
+ [];
+ Fun ->
+ [Fun]
+ end
+ end, DesignDocs)})
+ end),
+ receive
+ {'DOWN', Ref, _, _, {ok, Funs}} ->
+ gen_server:cast(Pid, {load_validation_funs, Funs}),
+ Funs;
+ {'DOWN', Ref, _, _, Reason} ->
+ ?LOG_ERROR("could not load validation funs ~p", [Reason]),
+ throw(internal_server_error)
+ end.
prep_and_validate_update(Db, #doc{id=Id,revs={RevStart, Revs}}=Doc,
OldFullDocInfo, LeafRevsDict, AllowConflict) ->
@@ -507,8 +549,8 @@ prep_and_validate_updates(Db, [DocBucket|RestBuckets],
[{ok, #full_doc_info{rev_tree=OldRevTree}=OldFullDocInfo}|RestLookups],
AllowConflict, AccPrepped, AccErrors) ->
Leafs = couch_key_tree:get_all_leafs(OldRevTree),
- LeafRevsDict = dict:from_list([{{Start, RevId}, {Deleted, Sp, Revs}} ||
- {{Deleted, Sp, _Seq}, {Start, [RevId|_]}=Revs} <- Leafs]),
+ LeafRevsDict = dict:from_list([{{Start, RevId}, {Del, Ptr, Revs}} ||
+ {#leaf{deleted=Del, ptr=Ptr}, {Start, [RevId|_]}=Revs} <- Leafs]),
{PreppedBucket, AccErrors3} = lists:foldl(
fun(Doc, {Docs2Acc, AccErrors2}) ->
case prep_and_validate_update(Db, Doc, OldFullDocInfo,
@@ -737,7 +779,7 @@ make_first_doc_on_disk(Db, Id, Pos, [{_Rev, #doc{}} | RestPath]) ->
make_first_doc_on_disk(Db, Id, Pos-1, RestPath);
make_first_doc_on_disk(Db, Id, Pos, [{_Rev, ?REV_MISSING}|RestPath]) ->
make_first_doc_on_disk(Db, Id, Pos - 1, RestPath);
-make_first_doc_on_disk(Db, Id, Pos, [{_Rev, {IsDel, Sp, _Seq}} |_]=DocPath) ->
+make_first_doc_on_disk(Db, Id, Pos, [{_, #leaf{deleted=IsDel, ptr=Sp}} |_]=DocPath) ->
Revs = [Rev || {Rev, _} <- DocPath],
make_doc(Db, Id, IsDel, Sp, {Pos, Revs}).
@@ -759,37 +801,37 @@ set_commit_option(Options) ->
[full_commit|Options]
end.
-collect_results(UpdatePid, MRef, ResultsAcc) ->
+collect_results(Pid, MRef, ResultsAcc) ->
receive
- {result, UpdatePid, Result} ->
- collect_results(UpdatePid, MRef, [Result | ResultsAcc]);
- {done, UpdatePid} ->
+ {result, Pid, Result} ->
+ collect_results(Pid, MRef, [Result | ResultsAcc]);
+ {done, Pid} ->
{ok, ResultsAcc};
- {retry, UpdatePid} ->
+ {retry, Pid} ->
retry;
{'DOWN', MRef, _, _, Reason} ->
exit(Reason)
end.
-write_and_commit(#db{update_pid=UpdatePid}=Db, DocBuckets,
+write_and_commit(#db{main_pid=Pid, user_ctx=Ctx}=Db, DocBuckets,
NonRepDocs, Options0) ->
Options = set_commit_option(Options0),
MergeConflicts = lists:member(merge_conflicts, Options),
FullCommit = lists:member(full_commit, Options),
- MRef = erlang:monitor(process, UpdatePid),
+ MRef = erlang:monitor(process, Pid),
try
- UpdatePid ! {update_docs, self(), DocBuckets, NonRepDocs, MergeConflicts, FullCommit},
- case collect_results(UpdatePid, MRef, []) of
+ Pid ! {update_docs, self(), DocBuckets, NonRepDocs, MergeConflicts, FullCommit},
+ case collect_results(Pid, MRef, []) of
{ok, Results} -> {ok, Results};
retry ->
% This can happen if the db file we wrote to was swapped out by
% compaction. Retry by reopening the db and writing to the current file
- {ok, Db2} = open_ref_counted(Db#db.main_pid, self()),
+ {ok, Db2} = open(Db#db.name, [{user_ctx, Ctx}]),
DocBuckets2 = [[doc_flush_atts(Doc, Db2#db.fd) || Doc <- Bucket] || Bucket <- DocBuckets],
% We only retry once
close(Db2),
- UpdatePid ! {update_docs, self(), DocBuckets2, NonRepDocs, MergeConflicts, FullCommit},
- case collect_results(UpdatePid, MRef, []) of
+ Pid ! {update_docs, self(), DocBuckets2, NonRepDocs, MergeConflicts, FullCommit},
+ case collect_results(Pid, MRef, []) of
{ok, Results} -> {ok, Results};
retry -> throw({update_error, compaction_retry})
end
@@ -937,15 +979,21 @@ enum_docs_since_reduce_to_count(Reds) ->
fun couch_db_updater:btree_by_seq_reduce/2, Reds).
enum_docs_reduce_to_count(Reds) ->
- {Count, _DelCount} = couch_btree:final_reduce(
+ {Count, _, _} = couch_btree:final_reduce(
fun couch_db_updater:btree_by_id_reduce/2, Reds),
Count.
changes_since(Db, Style, StartSeq, Fun, Acc) ->
changes_since(Db, Style, StartSeq, Fun, [], Acc).
-
+
changes_since(Db, Style, StartSeq, Fun, Options, Acc) ->
- Wrapper = fun(DocInfo, _Offset, Acc2) ->
+ Wrapper = fun(FullDocInfo, _Offset, Acc2) ->
+ case FullDocInfo of
+ #full_doc_info{} ->
+ DocInfo = couch_doc:to_doc_info(FullDocInfo);
+ #doc_info{} ->
+ DocInfo = FullDocInfo
+ end,
#doc_info{revs=Revs} = DocInfo,
DocInfo2 =
case Style of
@@ -958,83 +1006,27 @@ changes_since(Db, Style, StartSeq, Fun, Options, Acc) ->
end,
Fun(DocInfo2, Acc2)
end,
- {ok, _LastReduction, AccOut} = couch_btree:fold(Db#db.docinfo_by_seq_btree,
- Wrapper, Acc, [{start_key, StartSeq + 1}] ++ Options),
+ {ok, _LastReduction, AccOut} = couch_btree:fold(Db#db.seq_tree, Wrapper,
+ Acc, [{start_key, couch_util:to_integer(StartSeq) + 1} | Options]),
{ok, AccOut}.
count_changes_since(Db, SinceSeq) ->
{ok, Changes} =
- couch_btree:fold_reduce(Db#db.docinfo_by_seq_btree,
+ couch_btree:fold_reduce(Db#db.seq_tree,
fun(_SeqStart, PartialReds, 0) ->
- {ok, couch_btree:final_reduce(Db#db.docinfo_by_seq_btree, PartialReds)}
+ {ok, couch_btree:final_reduce(Db#db.seq_tree, PartialReds)}
end,
0, [{start_key, SinceSeq + 1}]),
Changes.
enum_docs_since(Db, SinceSeq, InFun, Acc, Options) ->
- {ok, LastReduction, AccOut} = couch_btree:fold(Db#db.docinfo_by_seq_btree, InFun, Acc, [{start_key, SinceSeq + 1} | Options]),
+ {ok, LastReduction, AccOut} = couch_btree:fold(Db#db.seq_tree, InFun, Acc, [{start_key, SinceSeq + 1} | Options]),
{ok, enum_docs_since_reduce_to_count(LastReduction), AccOut}.
enum_docs(Db, InFun, InAcc, Options) ->
- {ok, LastReduce, OutAcc} = couch_btree:fold(Db#db.fulldocinfo_by_id_btree, InFun, InAcc, Options),
+ {ok, LastReduce, OutAcc} = couch_btree:fold(Db#db.id_tree, InFun, InAcc, Options),
{ok, enum_docs_reduce_to_count(LastReduce), OutAcc}.
-% server functions
-
-init({DbName, Filepath, Fd, Options}) ->
- {ok, UpdaterPid} = gen_server:start_link(couch_db_updater, {self(), DbName, Filepath, Fd, Options}, []),
- {ok, #db{fd_ref_counter=RefCntr}=Db} = gen_server:call(UpdaterPid, get_db),
- couch_ref_counter:add(RefCntr),
- case lists:member(sys_db, Options) of
- true ->
- ok;
- false ->
- couch_stats_collector:track_process_count({couchdb, open_databases})
- end,
- process_flag(trap_exit, true),
- {ok, Db}.
-
-terminate(_Reason, Db) ->
- couch_util:shutdown_sync(Db#db.update_pid),
- ok.
-
-handle_call({open_ref_count, OpenerPid}, _, #db{fd_ref_counter=RefCntr}=Db) ->
- ok = couch_ref_counter:add(RefCntr, OpenerPid),
- {reply, {ok, Db}, Db};
-handle_call(is_idle, _From, #db{fd_ref_counter=RefCntr, compactor_pid=Compact,
- waiting_delayed_commit=Delay}=Db) ->
- % Idle means no referrers. Unless in the middle of a compaction file switch,
- % there are always at least 2 referrers, couch_db_updater and us.
- {reply, (Delay == nil) andalso (Compact == nil) andalso (couch_ref_counter:count(RefCntr) == 2), Db};
-handle_call({db_updated, NewDb}, _From, #db{fd_ref_counter=OldRefCntr}) ->
- #db{fd_ref_counter=NewRefCntr}=NewDb,
- case NewRefCntr =:= OldRefCntr of
- true -> ok;
- false ->
- couch_ref_counter:add(NewRefCntr),
- couch_ref_counter:drop(OldRefCntr)
- end,
- {reply, ok, NewDb};
-handle_call(get_db, _From, Db) ->
- {reply, {ok, Db}, Db}.
-
-
-handle_cast(Msg, Db) ->
- ?LOG_ERROR("Bad cast message received for db ~s: ~p", [Db#db.name, Msg]),
- exit({error, Msg}).
-
-code_change(_OldVsn, State, _Extra) ->
- {ok, State}.
-
-handle_info({'EXIT', _Pid, normal}, Db) ->
- {noreply, Db};
-handle_info({'EXIT', _Pid, Reason}, Server) ->
- {stop, Reason, Server};
-handle_info(Msg, Db) ->
- ?LOG_ERROR("Bad message received for db ~s: ~p", [Db#db.name, Msg]),
- exit({error, Msg}).
-
-
%%% Internal function %%%
open_doc_revs_int(Db, IdRevs, Options) ->
Ids = [Id || {Id, _Revs} <- IdRevs],
@@ -1061,7 +1053,7 @@ open_doc_revs_int(Db, IdRevs, Options) ->
?REV_MISSING ->
% we have the rev in our list but know nothing about it
{{not_found, missing}, {Pos, Rev}};
- {IsDeleted, SummaryPtr, _UpdateSeq} ->
+ #leaf{deleted=IsDeleted, ptr=SummaryPtr} ->
{ok, make_doc(Db, Id, IsDeleted, SummaryPtr, FoundRevPath)}
end
end, FoundRevs),
@@ -1076,7 +1068,7 @@ open_doc_revs_int(Db, IdRevs, Options) ->
IdRevs, LookupResults).
open_doc_int(Db, <<?LOCAL_DOC_PREFIX, _/binary>> = Id, _Options) ->
- case couch_btree:lookup(Db#db.local_docs_btree, [Id]) of
+ case couch_btree:lookup(Db#db.local_tree, [Id]) of
[{ok, {_, {Rev, BodyData}}}] ->
{ok, #doc{id=Id, revs={0, [list_to_binary(integer_to_list(Rev))]}, body=BodyData}};
[not_found] ->
@@ -1108,9 +1100,9 @@ doc_meta_info(#doc_info{high_seq=Seq,revs=[#rev_info{rev=Rev}|RestInfo]}, RevTre
couch_key_tree:get_full_key_paths(RevTree, [Rev]),
[{revs_info, Pos, lists:map(
- fun({Rev1, {true, _Sp, _UpdateSeq}}) ->
+ fun({Rev1, #leaf{deleted=true}}) ->
{Rev1, deleted};
- ({Rev1, {false, _Sp, _UpdateSeq}}) ->
+ ({Rev1, #leaf{deleted=false}}) ->
{Rev1, available};
({Rev1, ?REV_MISSING}) ->
{Rev1, missing}
diff --git a/src/couchdb/couch_db_update_notifier.erl b/apps/couch/src/couch_db_update_notifier.erl
index 150eb31b..150eb31b 100644
--- a/src/couchdb/couch_db_update_notifier.erl
+++ b/apps/couch/src/couch_db_update_notifier.erl
diff --git a/src/couchdb/couch_db_update_notifier_sup.erl b/apps/couch/src/couch_db_update_notifier_sup.erl
index 4d730fc7..e7cc16c1 100644
--- a/src/couchdb/couch_db_update_notifier_sup.erl
+++ b/apps/couch/src/couch_db_update_notifier_sup.erl
@@ -22,16 +22,14 @@
-behaviour(supervisor).
--export([start_link/0,init/1]).
+-export([start_link/0, init/1, config_change/3]).
start_link() ->
supervisor:start_link({local, couch_db_update_notifier_sup},
couch_db_update_notifier_sup, []).
init([]) ->
- ok = couch_config:register(
- fun("update_notification", Key, Value) -> reload_config(Key, Value) end
- ),
+ ok = couch_config:register(fun ?MODULE:config_change/3),
UpdateNotifierExes = couch_config:get("update_notification"),
@@ -48,7 +46,7 @@ init([]) ->
%% @doc when update_notification configuration changes, terminate the process
%% for that notifier and start a new one with the updated config
-reload_config(Id, Exe) ->
+config_change("update_notification", Id, Exe) ->
ChildSpec = {
Id,
{couch_db_update_notifier, start_link, [Exe]},
diff --git a/src/couchdb/couch_db_updater.erl b/apps/couch/src/couch_db_updater.erl
index 2b317d95..179e1f35 100644
--- a/src/couchdb/couch_db_updater.erl
+++ b/apps/couch/src/couch_db_updater.erl
@@ -13,14 +13,14 @@
-module(couch_db_updater).
-behaviour(gen_server).
--export([btree_by_id_reduce/2,btree_by_seq_reduce/2]).
+-export([btree_by_id_split/1,btree_by_id_join/2,btree_by_id_reduce/2]).
+-export([btree_by_seq_split/1,btree_by_seq_join/2,btree_by_seq_reduce/2]).
-export([init/1,terminate/2,handle_call/3,handle_cast/2,code_change/3,handle_info/2]).
-include("couch_db.hrl").
-init({MainPid, DbName, Filepath, Fd, Options}) ->
- process_flag(trap_exit, true),
+init({DbName, Filepath, Fd, Options}) ->
case lists:member(create, Options) of
true ->
% create a new header and writes it to the file
@@ -44,25 +44,40 @@ init({MainPid, DbName, Filepath, Fd, Options}) ->
end,
Db = init_db(DbName, Filepath, Fd, Header),
- Db2 = refresh_validate_doc_funs(Db),
- {ok, Db2#db{main_pid = MainPid, is_sys_db = lists:member(sys_db, Options)}}.
+ couch_stats_collector:track_process_count({couchdb, open_databases}),
+ % we don't load validation funs here because the fabric query is liable to
+ % race conditions. Instead see couch_db:validate_doc_update, which loads
+ % them lazily
+ {ok, Db#db{main_pid = self(), is_sys_db = lists:member(sys_db, Options)}}.
terminate(_Reason, Db) ->
couch_file:close(Db#db.fd),
couch_util:shutdown_sync(Db#db.compactor_pid),
- couch_util:shutdown_sync(Db#db.fd_ref_counter),
+ couch_util:shutdown_sync(Db#db.fd),
ok.
+handle_call(start_compact, _From, Db) ->
+ {noreply, NewDb} = handle_cast(start_compact, Db),
+ {reply, {ok, NewDb#db.compactor_pid}, NewDb};
+
handle_call(get_db, _From, Db) ->
{reply, {ok, Db}, Db};
handle_call(full_commit, _From, #db{waiting_delayed_commit=nil}=Db) ->
+ {reply, ok, Db};
+handle_call(full_commit, _From, Db) ->
+ {reply, ok, commit_data(Db)};
+
+handle_call({full_commit, _}, _From, #db{waiting_delayed_commit=nil}=Db) ->
{reply, ok, Db}; % no data waiting, return ok immediately
-handle_call(full_commit, _From, Db) ->
+handle_call({full_commit, RequiredSeq}, _From, Db) when RequiredSeq =<
+ Db#db.committed_update_seq ->
+ {reply, ok, Db};
+handle_call({full_commit, _}, _, Db) ->
{reply, ok, commit_data(Db)}; % commit the data and return ok
handle_call(increment_update_seq, _From, Db) ->
Db2 = commit_data(Db#db{update_seq=Db#db.update_seq+1}),
- ok = gen_server:call(Db2#db.main_pid, {db_updated, Db2}),
+ ok = gen_server:call(couch_server, {db_updated, Db2}, infinity),
couch_db_update_notifier:notify({updated, Db#db.name}),
{reply, {ok, Db2#db.update_seq}, Db2};
@@ -70,13 +85,13 @@ handle_call({set_security, NewSec}, _From, Db) ->
{ok, Ptr} = couch_file:append_term(Db#db.fd, NewSec),
Db2 = commit_data(Db#db{security=NewSec, security_ptr=Ptr,
update_seq=Db#db.update_seq+1}),
- ok = gen_server:call(Db2#db.main_pid, {db_updated, Db2}),
+ ok = gen_server:call(couch_server, {db_updated, Db2}, infinity),
{reply, ok, Db2};
handle_call({set_revs_limit, Limit}, _From, Db) ->
Db2 = commit_data(Db#db{revs_limit=Limit,
update_seq=Db#db.update_seq+1}),
- ok = gen_server:call(Db2#db.main_pid, {db_updated, Db2}),
+ ok = gen_server:call(couch_server, {db_updated, Db2}, infinity),
{reply, ok, Db2};
handle_call({purge_docs, _IdRevs}, _From,
@@ -85,8 +100,8 @@ handle_call({purge_docs, _IdRevs}, _From,
handle_call({purge_docs, IdRevs}, _From, Db) ->
#db{
fd=Fd,
- fulldocinfo_by_id_btree = DocInfoByIdBTree,
- docinfo_by_seq_btree = DocInfoBySeqBTree,
+ id_tree = DocInfoByIdBTree,
+ seq_tree = DocInfoBySeqBTree,
update_seq = LastSeq,
header = Header = #db_header{purge_seq=PurgeSeq}
} = Db,
@@ -137,29 +152,32 @@ handle_call({purge_docs, IdRevs}, _From, Db) ->
Db2 = commit_data(
Db#db{
- fulldocinfo_by_id_btree = DocInfoByIdBTree2,
- docinfo_by_seq_btree = DocInfoBySeqBTree2,
+ id_tree = DocInfoByIdBTree2,
+ seq_tree = DocInfoBySeqBTree2,
update_seq = NewSeq + 1,
header=Header#db_header{purge_seq=PurgeSeq+1, purged_docs=Pointer}}),
- ok = gen_server:call(Db2#db.main_pid, {db_updated, Db2}),
+ ok = gen_server:call(couch_server, {db_updated, Db2}, infinity),
couch_db_update_notifier:notify({updated, Db#db.name}),
- {reply, {ok, (Db2#db.header)#db_header.purge_seq, IdRevsPurged}, Db2};
-handle_call(start_compact, _From, Db) ->
+ {reply, {ok, (Db2#db.header)#db_header.purge_seq, IdRevsPurged}, Db2}.
+
+
+handle_cast({load_validation_funs, ValidationFuns}, Db) ->
+ Db2 = Db#db{validate_doc_funs = ValidationFuns},
+ ok = gen_server:call(couch_server, {db_updated, Db2}, infinity),
+ {noreply, Db2};
+handle_cast(start_compact, Db) ->
case Db#db.compactor_pid of
nil ->
?LOG_INFO("Starting compaction for db \"~s\"", [Db#db.name]),
Pid = spawn_link(fun() -> start_copy_compact(Db) end),
Db2 = Db#db{compactor_pid=Pid},
- ok = gen_server:call(Db#db.main_pid, {db_updated, Db2}),
- {reply, ok, Db2};
+ ok = gen_server:call(couch_server, {db_updated, Db2}, infinity),
+ {noreply, Db2};
_ ->
% compact currently running, this is a no-op
- {reply, ok, Db}
- end.
-
-
-
+ {noreply, Db}
+ end;
handle_cast({compact_done, CompactFilepath}, #db{filepath=Filepath}=Db) ->
{ok, NewFd} = couch_file:open(CompactFilepath),
{ok, NewHeader} = couch_file:read_header(NewFd),
@@ -169,13 +187,13 @@ handle_cast({compact_done, CompactFilepath}, #db{filepath=Filepath}=Db) ->
case Db#db.update_seq == NewSeq of
true ->
% suck up all the local docs into memory and write them to the new db
- {ok, _, LocalDocs} = couch_btree:foldl(Db#db.local_docs_btree,
+ {ok, _, LocalDocs} = couch_btree:foldl(Db#db.local_tree,
fun(Value, _Offset, Acc) -> {ok, [Value | Acc]} end, []),
- {ok, NewLocalBtree} = couch_btree:add(NewDb#db.local_docs_btree, LocalDocs),
+ {ok, NewLocalBtree} = couch_btree:add(NewDb#db.local_tree, LocalDocs),
NewDb2 = commit_data(NewDb#db{
- local_docs_btree = NewLocalBtree,
- main_pid = Db#db.main_pid,
+ local_tree = NewLocalBtree,
+ main_pid = self(),
filepath = Filepath,
instance_start_time = Db#db.instance_start_time,
revs_limit = Db#db.revs_limit
@@ -188,14 +206,14 @@ handle_cast({compact_done, CompactFilepath}, #db{filepath=Filepath}=Db) ->
ok = file:rename(CompactFilepath, Filepath),
close_db(Db),
NewDb3 = refresh_validate_doc_funs(NewDb2),
- ok = gen_server:call(Db#db.main_pid, {db_updated, NewDb3}, infinity),
+ ok = gen_server:call(couch_server, {db_updated, NewDb3}, infinity),
couch_db_update_notifier:notify({compacted, NewDb3#db.name}),
?LOG_INFO("Compaction for db \"~s\" completed.", [Db#db.name]),
{noreply, NewDb3#db{compactor_pid=nil}};
false ->
- ?LOG_INFO("Compaction file still behind main file "
+ ?LOG_INFO("Compaction for ~s still behind main file "
"(update seq=~p. compact update seq=~p). Retrying.",
- [Db#db.update_seq, NewSeq]),
+ [Db#db.name, Db#db.update_seq, NewSeq]),
close_db(NewDb),
Pid = spawn_link(fun() -> start_copy_compact(Db) end),
Db2 = Db#db{compactor_pid=Pid},
@@ -218,7 +236,7 @@ handle_info({update_docs, Client, GroupedDocs, NonRepDocs, MergeConflicts,
try update_docs_int(Db, GroupedDocs3, NonRepDocs2, MergeConflicts,
FullCommit2) of
{ok, Db2} ->
- ok = gen_server:call(Db#db.main_pid, {db_updated, Db2}),
+ ok = gen_server:call(couch_server, {db_updated, Db2}, infinity),
if Db2#db.update_seq /= Db#db.update_seq ->
couch_db_update_notifier:notify({updated, Db2#db.name});
true -> ok
@@ -238,13 +256,16 @@ handle_info(delayed_commit, Db) ->
Db ->
{noreply, Db};
Db2 ->
- ok = gen_server:call(Db2#db.main_pid, {db_updated, Db2}),
+ ok = gen_server:call(couch_server, {db_updated, Db2}, infinity),
{noreply, Db2}
end;
handle_info({'EXIT', _Pid, normal}, Db) ->
{noreply, Db};
handle_info({'EXIT', _Pid, Reason}, Db) ->
- {stop, Reason, Db}.
+ {stop, Reason, Db};
+handle_info({'DOWN', Ref, _, _, Reason}, #db{fd_monitor=Ref, name=Name} = Db) ->
+ ?LOG_ERROR("DB ~s shutting down - Fd ~p", [Name, Reason]),
+ {stop, normal, Db}.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
@@ -282,17 +303,29 @@ collect_updates(GroupedDocsAcc, ClientsAcc, MergeConflicts, FullCommit) ->
end.
-btree_by_seq_split(#doc_info{id=Id, high_seq=KeySeq, revs=Revs}) ->
- {RevInfos, DeletedRevInfos} = lists:foldl(
- fun(#rev_info{deleted = false, seq = Seq} = Ri, {Acc, AccDel}) ->
- {[{Ri#rev_info.rev, Seq, Ri#rev_info.body_sp} | Acc], AccDel};
- (#rev_info{deleted = true, seq = Seq} = Ri, {Acc, AccDel}) ->
- {Acc, [{Ri#rev_info.rev, Seq, Ri#rev_info.body_sp} | AccDel]}
- end,
- {[], []}, Revs),
- {KeySeq, {Id, lists:reverse(RevInfos), lists:reverse(DeletedRevInfos)}}.
+rev_tree(DiskTree) ->
+ couch_key_tree:map(fun(_RevId, {Del, Ptr, Seq}) ->
+ #leaf{deleted=(Del==1), ptr=Ptr, seq=Seq};
+ (_RevId, {Del, Ptr, Seq, Size, Atts}) ->
+ #leaf{deleted=(Del==1), ptr=Ptr, seq=Seq, size=Size, atts=Atts};
+ (_RevId, ?REV_MISSING) ->
+ ?REV_MISSING
+ end, DiskTree).
+
+disk_tree(RevTree) ->
+ couch_key_tree:map(fun(_RevId, ?REV_MISSING) ->
+ ?REV_MISSING;
+ (_RevId, #leaf{deleted=Del, ptr=Ptr, seq=Seq, size=Size, atts=Atts}) ->
+ {if Del -> 1; true -> 0 end, Ptr, Seq, Size, Atts}
+ end, RevTree).
+btree_by_seq_split(#full_doc_info{id=Id, update_seq=Seq, deleted=Del, rev_tree=T}) ->
+ {Seq, {Id, if Del -> 1; true -> 0 end, disk_tree(T)}}.
+
+btree_by_seq_join(Seq, {Id, Del, T}) when is_integer(Del) ->
+ #full_doc_info{id=Id, update_seq=Seq, deleted=Del==1, rev_tree=rev_tree(T)};
btree_by_seq_join(KeySeq, {Id, RevInfos, DeletedRevInfos}) ->
+ % 1.0 stored #doc_info records in the seq tree. compact to upgrade.
#doc_info{
id = Id,
high_seq=KeySeq,
@@ -315,48 +348,37 @@ btree_by_seq_join(KeySeq,{Id, Rev, Bp, Conflicts, DelConflicts, Deleted}) ->
[#rev_info{rev=Rev2,seq=KeySeq,deleted=true} || Rev2 <- DelConflicts]}.
btree_by_id_split(#full_doc_info{id=Id, update_seq=Seq,
- deleted=Deleted, rev_tree=Tree}) ->
- DiskTree =
- couch_key_tree:map(
- fun(_RevId, {IsDeleted, BodyPointer, UpdateSeq}) ->
- {if IsDeleted -> 1; true -> 0 end, BodyPointer, UpdateSeq};
- (_RevId, ?REV_MISSING) ->
- ?REV_MISSING
- end, Tree),
- {Id, {Seq, if Deleted -> 1; true -> 0 end, DiskTree}}.
+ data_size=Size, deleted=Deleted, rev_tree=Tree}) ->
+ {Id, {Seq, if Deleted -> 1; true -> 0 end, Size, disk_tree(Tree)}}.
+%% handle old formats before `data_size` added
btree_by_id_join(Id, {HighSeq, Deleted, DiskTree}) ->
- Tree =
- couch_key_tree:map(
- fun(_RevId, {IsDeleted, BodyPointer, UpdateSeq}) ->
- {IsDeleted == 1, BodyPointer, UpdateSeq};
- (_RevId, ?REV_MISSING) ->
- ?REV_MISSING;
- (_RevId, {IsDeleted, BodyPointer}) ->
- % 09 UPGRADE CODE
- % this is the 0.9.0 and earlier rev info record. It's missing the seq
- % nums, which means couchdb will sometimes reexamine unchanged
- % documents with the _changes API.
- % This is fixed by compacting the database.
- {IsDeleted == 1, BodyPointer, HighSeq}
- end, DiskTree),
+ btree_by_id_join(Id, {HighSeq, Deleted, 0, DiskTree});
- #full_doc_info{id=Id, update_seq=HighSeq, deleted=Deleted==1, rev_tree=Tree}.
+btree_by_id_join(Id, {HighSeq, Deleted, Size, DiskTree}) ->
+ #full_doc_info{id=Id, update_seq=HighSeq,
+ deleted=Deleted==1, data_size=Size,
+ rev_tree=rev_tree(DiskTree)}.
btree_by_id_reduce(reduce, FullDocInfos) ->
lists:foldl(
- fun(#full_doc_info{deleted = false}, {NotDeleted, Deleted}) ->
- {NotDeleted + 1, Deleted};
- (#full_doc_info{deleted = true}, {NotDeleted, Deleted}) ->
- {NotDeleted, Deleted + 1}
+ fun(#full_doc_info{deleted = false, data_size=Size},
+ {NotDeleted, Deleted, DocSize}) ->
+ {NotDeleted + 1, Deleted, DocSize + Size};
+ (#full_doc_info{deleted = true, data_size=Size},
+ {NotDeleted, Deleted, DocSize}) ->
+ {NotDeleted, Deleted + 1, DocSize + Size}
end,
- {0, 0}, FullDocInfos);
-btree_by_id_reduce(rereduce, [FirstRed | RestReds]) ->
+ {0, 0, 0}, FullDocInfos);
+
+btree_by_id_reduce(rereduce, Reductions) ->
lists:foldl(
- fun({NotDeleted, Deleted}, {AccNotDeleted, AccDeleted}) ->
- {AccNotDeleted + NotDeleted, AccDeleted + Deleted}
+ fun({NotDeleted, Deleted}, {AccNotDeleted, AccDeleted, AccDocSizes}) ->
+ {AccNotDeleted + NotDeleted, AccDeleted + Deleted, AccDocSizes};
+ ({NotDeleted, Deleted, DocSizes}, {AccNotDeleted, AccDeleted, AccDocSizes}) ->
+ {AccNotDeleted + NotDeleted, AccDeleted + Deleted, DocSizes + AccDocSizes}
end,
- FirstRed, RestReds).
+ {0, 0, 0}, Reductions).
btree_by_seq_reduce(reduce, DocInfos) ->
% count the number of documents
@@ -390,19 +412,19 @@ init_db(DbName, Filepath, Fd, Header0) ->
"[before_header, after_header, on_file_open]")),
case lists:member(on_file_open, FsyncOptions) of
- true -> ok = couch_file:sync(Fd);
+ true -> ok = couch_file:sync(Filepath);
_ -> ok
end,
- {ok, IdBtree} = couch_btree:open(Header#db_header.fulldocinfo_by_id_btree_state, Fd,
- [{split, fun(X) -> btree_by_id_split(X) end},
- {join, fun(X,Y) -> btree_by_id_join(X,Y) end},
- {reduce, fun(X,Y) -> btree_by_id_reduce(X,Y) end}]),
- {ok, SeqBtree} = couch_btree:open(Header#db_header.docinfo_by_seq_btree_state, Fd,
- [{split, fun(X) -> btree_by_seq_split(X) end},
- {join, fun(X,Y) -> btree_by_seq_join(X,Y) end},
- {reduce, fun(X,Y) -> btree_by_seq_reduce(X,Y) end}]),
- {ok, LocalDocsBtree} = couch_btree:open(Header#db_header.local_docs_btree_state, Fd),
+ {ok, IdBtree} = couch_btree:open(Header#db_header.id_tree_state, Fd,
+ [{split, fun ?MODULE:btree_by_id_split/1},
+ {join, fun ?MODULE:btree_by_id_join/2},
+ {reduce, fun ?MODULE:btree_by_id_reduce/2}]),
+ {ok, SeqBtree} = couch_btree:open(Header#db_header.seq_tree_state, Fd,
+ [{split, fun ?MODULE:btree_by_seq_split/1},
+ {join, fun ?MODULE:btree_by_seq_join/2},
+ {reduce, fun ?MODULE:btree_by_seq_reduce/2}]),
+ {ok, LocalDocsBtree} = couch_btree:open(Header#db_header.local_tree_state, Fd),
case Header#db_header.security_ptr of
nil ->
Security = [],
@@ -414,15 +436,13 @@ init_db(DbName, Filepath, Fd, Header0) ->
{MegaSecs, Secs, MicroSecs} = now(),
StartTime = ?l2b(io_lib:format("~p",
[(MegaSecs*1000000*1000000) + (Secs*1000000) + MicroSecs])),
- {ok, RefCntr} = couch_ref_counter:start([Fd]),
#db{
- update_pid=self(),
fd=Fd,
- fd_ref_counter = RefCntr,
+ fd_monitor = erlang:monitor(process,Fd),
header=Header,
- fulldocinfo_by_id_btree = IdBtree,
- docinfo_by_seq_btree = SeqBtree,
- local_docs_btree = LocalDocsBtree,
+ id_tree = IdBtree,
+ seq_tree = SeqBtree,
+ local_tree = LocalDocsBtree,
committed_update_seq = Header#db_header.update_seq,
update_seq = Header#db_header.update_seq,
name = DbName,
@@ -435,8 +455,8 @@ init_db(DbName, Filepath, Fd, Header0) ->
}.
-close_db(#db{fd_ref_counter = RefCntr}) ->
- couch_ref_counter:drop(RefCntr).
+close_db(#db{fd_monitor = Ref}) ->
+ erlang:demonitor(Ref).
refresh_validate_doc_funs(Db) ->
@@ -448,7 +468,13 @@ refresh_validate_doc_funs(Db) ->
Fun -> [Fun]
end
end, DesignDocs),
- Db#db{validate_doc_funs=ProcessDocFuns}.
+ case Db#db.name of
+ <<"shards/", _/binary>> = ShardName ->
+ fabric:reset_validation_funs(mem3:dbname(ShardName)),
+ Db#db{validate_doc_funs=undefined};
+ _ ->
+ Db#db{validate_doc_funs=ProcessDocFuns}
+ end.
% rev tree functions
@@ -466,14 +492,17 @@ flush_trees(#db{fd=Fd,header=Header}=Db,
% make sure the Fd in the written bins is the same Fd we are
% and convert bins, removing the FD.
% All bins should have been written to disk already.
- DiskAtts =
+ {DiskAtts, SizeInfo} =
case Atts of
- [] -> [];
+ [] -> {[],[]};
[#att{data={BinFd, _Sp}} | _ ] when BinFd == Fd ->
- [{N,T,P,AL,DL,R,M,E}
+ {[{N,T,P,AL,DL,R,M,E}
|| #att{name=N,type=T,data={_,P},md5=M,revpos=R,
att_len=AL,disk_len=DL,encoding=E}
- <- Atts];
+ <- Atts],
+ [{P1,AL1}
+ || #att{data={_,P1},att_len=AL1}
+ <- Atts]};
_ ->
% BinFd must not equal our Fd. This can happen when a database
% is being switched out during a compaction
@@ -488,7 +517,13 @@ flush_trees(#db{fd=Fd,header=Header}=Db,
false ->
couch_file:append_term_md5(Fd, {Doc#doc.body, DiskAtts})
end,
- {IsDeleted, NewSummaryPointer, UpdateSeq};
+ #leaf{
+ deleted = IsDeleted,
+ ptr = NewSummaryPointer,
+ seq = UpdateSeq,
+ size = size(term_to_binary(Doc#doc.body)),
+ atts = SizeInfo
+ };
_ ->
Value
end
@@ -577,14 +612,11 @@ merge_rev_trees(Limit, MergeConflicts, [NewDocs|RestDocsList],
-new_index_entries([], AccById, AccBySeq) ->
- {AccById, AccBySeq};
-new_index_entries([FullDocInfo|RestInfos], AccById, AccBySeq) ->
- #doc_info{revs=[#rev_info{deleted=Deleted}|_]} = DocInfo =
- couch_doc:to_doc_info(FullDocInfo),
- new_index_entries(RestInfos,
- [FullDocInfo#full_doc_info{deleted=Deleted}|AccById],
- [DocInfo|AccBySeq]).
+new_index_entries([], Acc) ->
+ Acc;
+new_index_entries([Info|Rest], Acc) ->
+ #doc_info{revs=[#rev_info{deleted=Del}|_]} = couch_doc:to_doc_info(Info),
+ new_index_entries(Rest, [Info#full_doc_info{deleted=Del}|Acc]).
stem_full_doc_infos(#db{revs_limit=Limit}, DocInfos) ->
@@ -593,8 +625,8 @@ stem_full_doc_infos(#db{revs_limit=Limit}, DocInfos) ->
update_docs_int(Db, DocsList, NonRepDocs, MergeConflicts, FullCommit) ->
#db{
- fulldocinfo_by_id_btree = DocInfoByIdBTree,
- docinfo_by_seq_btree = DocInfoBySeqBTree,
+ id_tree = DocInfoByIdBTree,
+ seq_tree = DocInfoBySeqBTree,
update_seq = LastSeq,
revs_limit = RevsLimit
} = Db,
@@ -619,17 +651,18 @@ update_docs_int(Db, DocsList, NonRepDocs, MergeConflicts, FullCommit) ->
% Write out the document summaries (the bodies are stored in the nodes of
% the trees, the attachments are already written to disk)
{ok, FlushedFullDocInfos} = flush_trees(Db2, NewFullDocInfos, []),
-
- {IndexFullDocInfos, IndexDocInfos} =
- new_index_entries(FlushedFullDocInfos, [], []),
-
+ IndexInfos =
+ new_index_entries(compute_data_sizes(FlushedFullDocInfos, []),
+ []),
% and the indexes
- {ok, DocInfoByIdBTree2} = couch_btree:add_remove(DocInfoByIdBTree, IndexFullDocInfos, []),
- {ok, DocInfoBySeqBTree2} = couch_btree:add_remove(DocInfoBySeqBTree, IndexDocInfos, RemoveSeqs),
+ {ok, DocInfoByIdBTree2} = couch_btree:add_remove(DocInfoByIdBTree,
+ IndexInfos, []),
+ {ok, DocInfoBySeqBTree2} = couch_btree:add_remove(DocInfoBySeqBTree,
+ IndexInfos, RemoveSeqs),
Db3 = Db2#db{
- fulldocinfo_by_id_btree = DocInfoByIdBTree2,
- docinfo_by_seq_btree = DocInfoBySeqBTree2,
+ id_tree = DocInfoByIdBTree2,
+ seq_tree = DocInfoBySeqBTree2,
update_seq = NewSeq},
% Check if we just updated any design documents, and update the validation
@@ -644,27 +677,40 @@ update_docs_int(Db, DocsList, NonRepDocs, MergeConflicts, FullCommit) ->
{ok, commit_data(Db4, not FullCommit)}.
+compute_data_sizes([], Acc) ->
+ lists:reverse(Acc);
+
+compute_data_sizes([FullDocInfo | RestDocInfos], Acc) ->
+ #full_doc_info{rev_tree=Tree} = FullDocInfo,
+ Size = couch_key_tree:compute_data_size(Tree),
+ compute_data_sizes(RestDocInfos,
+ [FullDocInfo#full_doc_info{data_size=Size}
+ | Acc]).
+
+
update_local_docs(Db, []) ->
{ok, Db};
-update_local_docs(#db{local_docs_btree=Btree}=Db, Docs) ->
+update_local_docs(#db{local_tree=Btree}=Db, Docs) ->
Ids = [Id || {_Client, #doc{id=Id}} <- Docs],
OldDocLookups = couch_btree:lookup(Btree, Ids),
BtreeEntries = lists:zipwith(
- fun({Client, #doc{id=Id,deleted=Delete,revs={0,PrevRevs},body=Body}}, OldDocLookup) ->
+ fun({Client, #doc{id=Id,deleted=Delete,revs={0,PrevRevs},body=Body}},
+ _OldDocLookup) ->
case PrevRevs of
[RevStr|_] ->
PrevRev = list_to_integer(?b2l(RevStr));
[] ->
PrevRev = 0
end,
- OldRev =
- case OldDocLookup of
- {ok, {_, {OldRev0, _}}} -> OldRev0;
- not_found -> 0
- end,
- case OldRev == PrevRev of
- true ->
+ %% disabled conflict checking for local docs -- APK 16 June 2010
+ % OldRev =
+ % case OldDocLookup of
+ % {ok, {_, {OldRev0, _}}} -> OldRev0;
+ % not_found -> 0
+ % end,
+ % case OldRev == PrevRev of
+ % true ->
case Delete of
false ->
send_result(Client, Id, {0, PrevRevs}, {ok,
@@ -674,11 +720,11 @@ update_local_docs(#db{local_docs_btree=Btree}=Db, Docs) ->
send_result(Client, Id, {0, PrevRevs},
{ok, {0, <<"0">>}}),
{remove, Id}
- end;
- false ->
- send_result(Client, Id, {0, PrevRevs}, conflict),
- ignore
- end
+ end%;
+ % false ->
+ % send_result(Client, Id, {0, PrevRevs}, conflict),
+ % ignore
+ % end
end, Docs, OldDocLookups),
BtreeIdsRemove = [Id || {remove, Id} <- BtreeEntries],
@@ -687,7 +733,7 @@ update_local_docs(#db{local_docs_btree=Btree}=Db, Docs) ->
{ok, Btree2} =
couch_btree:add_remove(Btree, BtreeIdsUpdate, BtreeIdsRemove),
- {ok, Db#db{local_docs_btree = Btree2}}.
+ {ok, Db#db{local_tree = Btree2}}.
commit_data(Db) ->
@@ -696,9 +742,9 @@ commit_data(Db) ->
db_to_header(Db, Header) ->
Header#db_header{
update_seq = Db#db.update_seq,
- docinfo_by_seq_btree_state = couch_btree:get_state(Db#db.docinfo_by_seq_btree),
- fulldocinfo_by_id_btree_state = couch_btree:get_state(Db#db.fulldocinfo_by_id_btree),
- local_docs_btree_state = couch_btree:get_state(Db#db.local_docs_btree),
+ seq_tree_state = couch_btree:get_state(Db#db.seq_tree),
+ id_tree_state = couch_btree:get_state(Db#db.id_tree),
+ local_tree_state = couch_btree:get_state(Db#db.local_tree),
security_ptr = Db#db.security_ptr,
revs_limit = Db#db.revs_limit}.
@@ -779,27 +825,40 @@ copy_doc_attachments(#db{fd=SrcFd}=SrcDb, {Pos,_RevId}, SrcSp, DestFd) ->
end, BinInfos),
{BodyData, NewBinInfos}.
-copy_docs(Db, #db{fd=DestFd}=NewDb, InfoBySeq0, Retry) ->
+merge_lookups(Infos, []) ->
+ Infos;
+merge_lookups([], _) ->
+ [];
+merge_lookups([#doc_info{}|RestInfos], [{ok, FullDocInfo}|RestLookups]) ->
+ [FullDocInfo|merge_lookups(RestInfos, RestLookups)];
+merge_lookups([FullDocInfo|RestInfos], Lookups) ->
+ [FullDocInfo|merge_lookups(RestInfos, Lookups)].
+
+copy_docs(Db, #db{fd=DestFd}=NewDb, MixedInfos, Retry) ->
+ % lookup any necessary full_doc_infos
+ DocInfoIds = [Id || #doc_info{id=Id} <- MixedInfos],
+ LookupResults = couch_btree:lookup(Db#db.id_tree, DocInfoIds),
% COUCHDB-968, make sure we prune duplicates during compaction
- InfoBySeq = lists:usort(fun(#doc_info{id=A}, #doc_info{id=B}) -> A =< B end,
- InfoBySeq0),
- Ids = [Id || #doc_info{id=Id} <- InfoBySeq],
- LookupResults = couch_btree:lookup(Db#db.fulldocinfo_by_id_btree, Ids),
-
- NewFullDocInfos1 = lists:map(
- fun({ok, #full_doc_info{rev_tree=RevTree}=Info}) ->
- Info#full_doc_info{rev_tree=couch_key_tree:map(
- fun(Rev, {IsDel, Sp, Seq}, leaf) ->
- DocBody = copy_doc_attachments(Db, Rev, Sp, DestFd),
- {ok, Pos} = couch_file:append_term_md5(DestFd, DocBody),
- {IsDel, Pos, Seq};
- (_, _, branch) ->
- ?REV_MISSING
- end, RevTree)}
- end, LookupResults),
-
- NewFullDocInfos = stem_full_doc_infos(Db, NewFullDocInfos1),
- NewDocInfos = [couch_doc:to_doc_info(Info) || Info <- NewFullDocInfos],
+ Infos = lists:usort(fun(#full_doc_info{id=A}, #full_doc_info{id=B}) ->
+ A =< B
+ end, merge_lookups(MixedInfos, LookupResults)),
+
+ NewInfos1 = [Info#full_doc_info{rev_tree=couch_key_tree:map(
+ fun(Rev, #leaf{ptr=Sp, size=Size0}=Leaf, leaf) ->
+ {Body, AttInfos} = copy_doc_attachments(Db, Rev, Sp, DestFd),
+ {ok, Pos} = couch_file:append_term_md5(DestFd, {Body, AttInfos}),
+ if Size0 > 0 ->
+ Leaf#leaf{ptr=Pos};
+ true ->
+ DocSize = byte_size(term_to_binary(Body)),
+ AttSizes = [{element(3,A), element(4,A)} || A <- AttInfos],
+ Leaf#leaf{ptr=Pos, size=DocSize, atts=AttSizes}
+ end;
+ (_, _, branch) ->
+ ?REV_MISSING
+ end, RevTree)} || #full_doc_info{rev_tree=RevTree}=Info <- Infos],
+
+ NewInfos = stem_full_doc_infos(Db, compute_data_sizes(NewInfos1, [])),
RemoveSeqs =
case Retry of
false ->
@@ -807,16 +866,16 @@ copy_docs(Db, #db{fd=DestFd}=NewDb, InfoBySeq0, Retry) ->
true ->
% We are retrying a compaction, meaning the documents we are copying may
% already exist in our file and must be removed from the by_seq index.
- Existing = couch_btree:lookup(NewDb#db.fulldocinfo_by_id_btree, Ids),
+ Ids = [Id || #full_doc_info{id=Id} <- Infos],
+ Existing = couch_btree:lookup(NewDb#db.id_tree, Ids),
[Seq || {ok, #full_doc_info{update_seq=Seq}} <- Existing]
end,
- {ok, DocInfoBTree} = couch_btree:add_remove(
- NewDb#db.docinfo_by_seq_btree, NewDocInfos, RemoveSeqs),
- {ok, FullDocInfoBTree} = couch_btree:add_remove(
- NewDb#db.fulldocinfo_by_id_btree, NewFullDocInfos, []),
- NewDb#db{ fulldocinfo_by_id_btree=FullDocInfoBTree,
- docinfo_by_seq_btree=DocInfoBTree}.
+ {ok, SeqTree} = couch_btree:add_remove(
+ NewDb#db.seq_tree, NewInfos, RemoveSeqs),
+ {ok, IdTree} = couch_btree:add_remove(
+ NewDb#db.id_tree, NewInfos, []),
+ NewDb#db{id_tree=IdTree, seq_tree=SeqTree}.
@@ -825,13 +884,20 @@ copy_compact(Db, NewDb0, Retry) ->
NewDb = NewDb0#db{fsync_options=FsyncOptions},
TotalChanges = couch_db:count_changes_since(Db, NewDb#db.update_seq),
EnumBySeqFun =
- fun(#doc_info{high_seq=Seq}=DocInfo, _Offset, {AccNewDb, AccUncopied, TotalCopied}) ->
+ fun(DocInfo, _Offset, {AccNewDb, AccUncopied, TotalCopied}) ->
+ case DocInfo of
+ #full_doc_info{update_seq=Seq} ->
+ ok;
+ #doc_info{high_seq=Seq} ->
+ ok
+ end,
couch_task_status:update("Copied ~p of ~p changes (~p%)",
[TotalCopied, TotalChanges, (TotalCopied*100) div TotalChanges]),
if TotalCopied rem 1000 =:= 0 ->
NewDb2 = copy_docs(Db, AccNewDb, lists:reverse([DocInfo | AccUncopied]), Retry),
if TotalCopied rem 10000 =:= 0 ->
- {ok, {commit_data(NewDb2#db{update_seq=Seq}), [], TotalCopied + 1}};
+ NewDb3 = commit_data(NewDb2#db{update_seq=Seq}),
+ {ok, {NewDb3, [], TotalCopied + 1}};
true ->
{ok, {NewDb2#db{update_seq=Seq}, [], TotalCopied + 1}}
end;
@@ -843,7 +909,7 @@ copy_compact(Db, NewDb0, Retry) ->
couch_task_status:set_update_frequency(500),
{ok, _, {NewDb2, Uncopied, TotalChanges}} =
- couch_btree:foldl(Db#db.docinfo_by_seq_btree, EnumBySeqFun,
+ couch_btree:foldl(Db#db.seq_tree, EnumBySeqFun,
{NewDb, [], 0},
[{start_key, NewDb#db.update_seq + 1}]),
@@ -892,5 +958,5 @@ start_copy_compact(#db{name=Name,filepath=Filepath,header=#db_header{purge_seq=P
NewDb3 = copy_compact(Db, NewDb2, Retry),
close_db(NewDb3),
- gen_server:cast(Db#db.update_pid, {compact_done, CompactFile}).
+ gen_server:cast(Db#db.main_pid, {compact_done, CompactFile}).
diff --git a/src/couchdb/couch_doc.erl b/apps/couch/src/couch_doc.erl
index 5cd6ac80..c7b9dbb9 100644
--- a/src/couchdb/couch_doc.erl
+++ b/apps/couch/src/couch_doc.erl
@@ -47,8 +47,8 @@ revid_to_str(RevId) ->
rev_to_str({Pos, RevId}) ->
?l2b([integer_to_list(Pos),"-",revid_to_str(RevId)]).
-
-
+
+
revs_to_strs([]) ->
[];
revs_to_strs([{Pos, RevId}| Rest]) ->
@@ -309,7 +309,7 @@ max_seq([#rev_info{seq=Seq}|Rest], Max) ->
to_doc_info_path(#full_doc_info{id=Id,rev_tree=Tree}) ->
RevInfosAndPath =
[{#rev_info{deleted=Del,body_sp=Bp,seq=Seq,rev={Pos,RevId}}, Path} ||
- {{Del, Bp, Seq},{Pos, [RevId|_]}=Path} <-
+ {#leaf{deleted=Del, ptr=Bp, seq=Seq},{Pos, [RevId|_]}=Path} <-
couch_key_tree:get_all_leafs(Tree)],
SortedRevInfosAndPath = lists:sort(
fun({#rev_info{deleted=DeletedA,rev=RevA}, _PathA},
@@ -364,6 +364,8 @@ att_to_bin(#att{data=DataFun, att_len=Len}) when is_function(DataFun)->
))
).
+get_validate_doc_fun({Props}) ->
+ get_validate_doc_fun(couch_doc:from_json_obj({Props}));
get_validate_doc_fun(#doc{body={Props}}=DDoc) ->
case couch_util:get_value(<<"validate_doc_update">>, Props) of
undefined ->
@@ -389,12 +391,12 @@ merge_stubs(#doc{id=Id,atts=MemBins}=StubsDoc, #doc{atts=DiskBins}) ->
MergedBins = lists:map(
fun(#att{name=Name, data=stub, revpos=StubRevPos}) ->
case dict:find(Name, BinDict) of
- {ok, #att{revpos=DiskRevPos}=DiskAtt}
+ {ok, #att{revpos=DiskRevPos}=DiskAtt}
when DiskRevPos == StubRevPos orelse StubRevPos == nil ->
DiskAtt;
_ ->
throw({missing_stub,
- <<"id:", Id/binary, ", name:", Name/binary>>})
+ <<"Invalid attachment stub in ", Id/binary, " for ", Name/binary>>})
end;
(Att) ->
Att
@@ -482,18 +484,14 @@ doc_from_multi_part_stream(ContentType, DataFun) ->
Parent ! {self(), finished}
end),
Parser ! {get_doc_bytes, self()},
- receive
+ receive
{doc_bytes, DocBytes} ->
Doc = from_json_obj(?JSON_DECODE(DocBytes)),
- % go through the attachments looking for 'follows' in the data,
- % replace with function that reads the data from MIME stream.
- ReadAttachmentDataFun = fun() ->
- Parser ! {get_bytes, self()},
- receive {bytes, Bytes} -> Bytes end
- end,
+ % we'll send the Parser process ID to the remote nodes so they can
+ % retrieve their own copies of the attachment data
Atts2 = lists:map(
fun(#att{data=follows}=A) ->
- A#att{data=ReadAttachmentDataFun};
+ A#att{data={follows, Parser}};
(A) ->
A
end, Doc#doc.atts),
@@ -520,25 +518,75 @@ mp_parse_doc(body_end, AccBytes) ->
From ! {doc_bytes, lists:reverse(AccBytes)}
end,
fun (Next) ->
- mp_parse_atts(Next)
+ mp_parse_atts(Next, {[], 0, orddict:new(), []})
end.
-mp_parse_atts(eof) ->
- ok;
-mp_parse_atts({headers, _H}) ->
- fun (Next) ->
- mp_parse_atts(Next)
- end;
-mp_parse_atts({body, Bytes}) ->
- receive {get_bytes, From} ->
- From ! {bytes, Bytes}
- end,
- fun (Next) ->
- mp_parse_atts(Next)
- end;
-mp_parse_atts(body_end) ->
- fun (Next) ->
- mp_parse_atts(Next)
+mp_parse_atts({headers, _}, Acc) ->
+ fun(Next) -> mp_parse_atts(Next, Acc) end;
+mp_parse_atts(body_end, Acc) ->
+ fun(Next) -> mp_parse_atts(Next, Acc) end;
+mp_parse_atts({body, Bytes}, {DataList, Offset, Counters, Waiting}) ->
+ NewAcc = maybe_send_data({DataList++[Bytes], Offset, Counters, Waiting}),
+ fun(Next) -> mp_parse_atts(Next, NewAcc) end;
+mp_parse_atts(eof, {DataList, Offset, Counters, Waiting}) ->
+ N = list_to_integer(couch_config:get("cluster", "n", "3")),
+ M = length(Counters),
+ case (M == N) andalso DataList == [] of
+ true ->
+ ok;
+ false ->
+ receive {get_bytes, From} ->
+ C2 = orddict:update_counter(From, 1, Counters),
+ NewAcc = maybe_send_data({DataList, Offset, C2, [From|Waiting]}),
+ mp_parse_atts(eof, NewAcc)
+ after 3600000 ->
+ ok
+ end
end.
+maybe_send_data({ChunkList, Offset, Counters, Waiting}) ->
+ receive {get_bytes, From} ->
+ NewCounters = orddict:update_counter(From, 1, Counters),
+ maybe_send_data({ChunkList, Offset, NewCounters, [From|Waiting]})
+ after 0 ->
+ % reply to as many writers as possible
+ NewWaiting = lists:filter(fun(Writer) ->
+ WhichChunk = orddict:fetch(Writer, Counters),
+ ListIndex = WhichChunk - Offset,
+ if ListIndex =< length(ChunkList) ->
+ Writer ! {bytes, lists:nth(ListIndex, ChunkList)},
+ false;
+ true ->
+ true
+ end
+ end, Waiting),
+
+ % check if we can drop a chunk from the head of the list
+ case Counters of
+ [] ->
+ SmallestIndex = 0;
+ _ ->
+ SmallestIndex = lists:min(element(2, lists:unzip(Counters)))
+ end,
+ Size = length(Counters),
+ N = list_to_integer(couch_config:get("cluster", "n", "3")),
+ if Size == N andalso SmallestIndex == (Offset+1) ->
+ NewChunkList = tl(ChunkList),
+ NewOffset = Offset+1;
+ true ->
+ NewChunkList = ChunkList,
+ NewOffset = Offset
+ end,
+ % we should wait for a writer if no one has written the last chunk
+ LargestIndex = lists:max([0|element(2, lists:unzip(Counters))]),
+ if LargestIndex >= (Offset + length(ChunkList)) ->
+ % someone has written all possible chunks, keep moving
+ {NewChunkList, NewOffset, Counters, NewWaiting};
+ true ->
+ receive {get_bytes, X} ->
+ C2 = orddict:update_counter(X, 1, Counters),
+ maybe_send_data({NewChunkList, NewOffset, C2, [X|NewWaiting]})
+ end
+ end
+ end.
diff --git a/apps/couch/src/couch_drv.erl b/apps/couch/src/couch_drv.erl
new file mode 100644
index 00000000..9f4cfac1
--- /dev/null
+++ b/apps/couch/src/couch_drv.erl
@@ -0,0 +1,38 @@
+-module(couch_drv).
+-behaviour(gen_server).
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
+ code_change/3]).
+
+-export([start_link/0]).
+
+-include("couch_db.hrl").
+
+start_link() ->
+ gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
+
+init([]) ->
+ case erl_ddll:load(code:priv_dir(couch), "couch_icu_driver") of
+ ok ->
+ {ok, nil};
+ {error, already_loaded} ->
+ ?LOG_INFO("~p reloading couch_erl_driver", [?MODULE]),
+ ok = erl_ddll:reload(code:priv_dir(couch), "couch_erl_driver"),
+ {ok, nil};
+ {error, Error} ->
+ {stop, erl_ddll:format_error(Error)}
+ end.
+
+handle_call(_Request, _From, State) ->
+ {reply, ok, State}.
+
+handle_cast(_Request, State) ->
+ {noreply, State}.
+
+handle_info(_Info, State) ->
+ {noreply, State}.
+
+terminate(_Reason, _State) ->
+ ok.
+
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
diff --git a/src/couchdb/couch_event_sup.erl b/apps/couch/src/couch_event_sup.erl
index 07c48790..07c48790 100644
--- a/src/couchdb/couch_event_sup.erl
+++ b/apps/couch/src/couch_event_sup.erl
diff --git a/src/couchdb/couch_external_manager.erl b/apps/couch/src/couch_external_manager.erl
index 7e401389..0c66ef8c 100644
--- a/src/couchdb/couch_external_manager.erl
+++ b/apps/couch/src/couch_external_manager.erl
@@ -39,7 +39,7 @@ config_change("external", UrlName) ->
init([]) ->
process_flag(trap_exit, true),
Handlers = ets:new(couch_external_manager_handlers, [set, private]),
- couch_config:register(fun config_change/2),
+ couch_config:register(fun ?MODULE:config_change/2),
{ok, Handlers}.
terminate(_Reason, Handlers) ->
diff --git a/src/couchdb/couch_external_server.erl b/apps/couch/src/couch_external_server.erl
index 045fcee9..045fcee9 100644
--- a/src/couchdb/couch_external_server.erl
+++ b/apps/couch/src/couch_external_server.erl
diff --git a/src/couchdb/couch_file.erl b/apps/couch/src/couch_file.erl
index 7b677034..0136e877 100644
--- a/src/couchdb/couch_file.erl
+++ b/apps/couch/src/couch_file.erl
@@ -72,10 +72,10 @@ open(Filepath, Options) ->
%%----------------------------------------------------------------------
append_term(Fd, Term) ->
- append_binary(Fd, term_to_binary(Term)).
+ append_binary(Fd, term_to_binary(Term, [compressed, {minor_version,1}])).
append_term_md5(Fd, Term) ->
- append_binary_md5(Fd, term_to_binary(Term)).
+ append_binary_md5(Fd, term_to_binary(Term, [compressed, {minor_version,1}])).
%%----------------------------------------------------------------------
@@ -173,8 +173,7 @@ sync(Fd) ->
%% Returns: ok
%%----------------------------------------------------------------------
close(Fd) ->
- couch_util:shutdown_sync(Fd).
-
+ gen_server:call(Fd, close, infinity).
delete(RootDir, Filepath) ->
delete(RootDir, Filepath, true).
@@ -242,6 +241,7 @@ init_status_error(ReturnPid, Ref, Error) ->
init({Filepath, Options, ReturnPid, Ref}) ->
process_flag(trap_exit, true),
+ erlang:send_after(60000, self(), maybe_close),
case lists:member(create, Options) of
true ->
filelib:ensure_dir(Filepath),
@@ -285,17 +285,16 @@ init({Filepath, Options, ReturnPid, Ref}) ->
end
end.
-maybe_track_open_os_files(FileOptions) ->
- case lists:member(sys_db, FileOptions) of
- true ->
- ok;
- false ->
- couch_stats_collector:track_process_count({couchdb, open_os_files})
- end.
+maybe_track_open_os_files(_FileOptions) ->
+ couch_stats_collector:track_process_count({couchdb, open_os_files}).
+terminate(_Reason, #file{fd = nil}) ->
+ ok;
terminate(_Reason, #file{fd = Fd}) ->
- ok = file:close(Fd).
+ file:close(Fd).
+handle_call(close, _From, #file{fd=Fd}=File) ->
+ {stop, normal, file:close(Fd), File#file{fd = nil}};
handle_call({pread_iolist, Pos}, _From, File) ->
{RawData, NextPos} = try
@@ -487,6 +486,18 @@ handle_cast(close, Fd) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
+handle_info(maybe_close, Fd) ->
+ case process_info(self(), monitored_by) of
+ {monitored_by, [_StatsCollector]} ->
+ {stop, normal, Fd};
+ {monitored_by, []} ->
+ ?LOG_ERROR("~p ~p is un-monitored, maybe stats collector died",
+ [?MODULE, self()]),
+ {stop, normal, Fd};
+ _Else ->
+ erlang:send_after(10000, self(), maybe_close),
+ {noreply, Fd}
+ end;
handle_info({'EXIT', _, normal}, Fd) ->
{noreply, Fd};
handle_info({'EXIT', _, Reason}, Fd) ->
diff --git a/src/couchdb/couch_httpd.erl b/apps/couch/src/couch_httpd.erl
index 7c7781f6..8fb2687c 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/apps/couch/src/couch_httpd.erl
@@ -851,7 +851,7 @@ negotiate_content_type(#httpd{mochi_req=MochiReq}) ->
end.
server_header() ->
- [{"Server", "CouchDB/" ++ couch_server:get_version() ++
+ [{"Server", "CouchDB/" ++ couch:version() ++
" (Erlang OTP/" ++ erlang:system_info(otp_release) ++ ")"}].
diff --git a/src/couchdb/couch_httpd_auth.erl b/apps/couch/src/couch_httpd_auth.erl
index 155865e5..9f6ed18a 100644
--- a/src/couchdb/couch_httpd_auth.erl
+++ b/apps/couch/src/couch_httpd_auth.erl
@@ -231,7 +231,7 @@ cookie_auth_cookie(Req, User, Secret, TimeStamp) ->
Hash = crypto:sha_mac(Secret, SessionData),
mochiweb_cookies:cookie("AuthSession",
couch_util:encodeBase64Url(SessionData ++ ":" ++ ?b2l(Hash)),
- [{path, "/"}, cookie_scheme(Req)]).
+ [{path, "/"}] ++ cookie_scheme(Req)).
hash_password(Password, Salt) ->
?l2b(couch_util:to_hex(crypto:sha(<<Password/binary, Salt/binary>>))).
@@ -292,7 +292,7 @@ handle_session_req(#httpd{method='POST', mochi_req=MochiReq}=Req) ->
]});
_Else ->
% clear the session
- Cookie = mochiweb_cookies:cookie("AuthSession", "", [{path, "/"}, cookie_scheme(Req)]),
+ Cookie = mochiweb_cookies:cookie("AuthSession", "", [{path, "/"}] ++ cookie_scheme(Req)),
send_json(Req, 401, [Cookie], {[{error, <<"unauthorized">>},{reason, <<"Name or password is incorrect.">>}]})
end;
% get user info
@@ -322,7 +322,7 @@ handle_session_req(#httpd{method='GET', user_ctx=UserCtx}=Req) ->
end;
% logout by deleting the session
handle_session_req(#httpd{method='DELETE'}=Req) ->
- Cookie = mochiweb_cookies:cookie("AuthSession", "", [{path, "/"}, cookie_scheme(Req)]),
+ Cookie = mochiweb_cookies:cookie("AuthSession", "", [{path, "/"}] ++ cookie_scheme(Req)),
{Code, Headers} = case couch_httpd:qs_value(Req, "next", nil) of
nil ->
{200, [Cookie]};
@@ -353,7 +353,8 @@ make_cookie_time() ->
NowMS * 1000000 + NowS.
cookie_scheme(#httpd{mochi_req=MochiReq}) ->
+ [{http_only, true}] ++
case MochiReq:get(scheme) of
- http -> {http_only, true};
- https -> {secure, true}
+ http -> [];
+ https -> [{secure, true}]
end.
diff --git a/src/couchdb/couch_httpd_db.erl b/apps/couch/src/couch_httpd_db.erl
index e3638b25..e3638b25 100644
--- a/src/couchdb/couch_httpd_db.erl
+++ b/apps/couch/src/couch_httpd_db.erl
diff --git a/src/couchdb/couch_httpd_external.erl b/apps/couch/src/couch_httpd_external.erl
index 2e91fb50..2e91fb50 100644
--- a/src/couchdb/couch_httpd_external.erl
+++ b/apps/couch/src/couch_httpd_external.erl
diff --git a/src/couchdb/couch_httpd_misc_handlers.erl b/apps/couch/src/couch_httpd_misc_handlers.erl
index 213cbfd4..15f0cad3 100644
--- a/src/couchdb/couch_httpd_misc_handlers.erl
+++ b/apps/couch/src/couch_httpd_misc_handlers.erl
@@ -32,7 +32,7 @@
handle_welcome_req(#httpd{method='GET'}=Req, WelcomeMessage) ->
send_json(Req, {[
{couchdb, WelcomeMessage},
- {version, list_to_binary(couch_server:get_version())}
+ {version, list_to_binary(couch:version())}
]});
handle_welcome_req(Req, _) ->
send_method_not_allowed(Req, "GET,HEAD").
@@ -238,7 +238,7 @@ handle_approved_config_req(#httpd{method='PUT', path_parts=[_, Section, Key]}=Re
OldValue = couch_config:get(Section, Key, ""),
case couch_config:set(Section, Key, ?b2l(Value), Persist) of
ok ->
- send_json(Req, 200, list_to_binary(OldValue));
+ send_json(Req, 200, list_to_binary(OldValue));
Error ->
throw(Error)
end;
diff --git a/src/couchdb/couch_httpd_oauth.erl b/apps/couch/src/couch_httpd_oauth.erl
index 05ee10e2..05ee10e2 100644
--- a/src/couchdb/couch_httpd_oauth.erl
+++ b/apps/couch/src/couch_httpd_oauth.erl
diff --git a/src/couchdb/couch_httpd_proxy.erl b/apps/couch/src/couch_httpd_proxy.erl
index 65e3e432..c196f72d 100644
--- a/src/couchdb/couch_httpd_proxy.erl
+++ b/apps/couch/src/couch_httpd_proxy.erl
@@ -14,7 +14,7 @@
-export([handle_proxy_req/2]).
-include("couch_db.hrl").
--include("../ibrowse/ibrowse.hrl").
+-include_lib("ibrowse/include/ibrowse.hrl").
-define(TIMEOUT, infinity).
-define(PKT_SIZE, 4096).
diff --git a/src/couchdb/couch_httpd_rewrite.erl b/apps/couch/src/couch_httpd_rewrite.erl
index e24cb5db..8480c1e9 100644
--- a/src/couchdb/couch_httpd_rewrite.erl
+++ b/apps/couch/src/couch_httpd_rewrite.erl
@@ -125,7 +125,10 @@ handle_rewrite_req(#httpd{
case couch_util:get_value(<<"rewrites">>, Props) of
undefined ->
couch_httpd:send_error(Req, 404, <<"rewrite_error">>,
- <<"Invalid path.">>);
+ <<"Invalid path.">>);
+ Bin when is_binary(Bin) ->
+ couch_httpd:send_error(Req, 400, <<"rewrite_error">>,
+ <<"Rewrite rules are a String. They must be a JSON Array.">>);
Rules ->
% create dispatch list from rules
DispatchList = [make_rule(Rule) || {Rule} <- Rules],
diff --git a/src/couchdb/couch_httpd_show.erl b/apps/couch/src/couch_httpd_show.erl
index 59f74e1c..59f74e1c 100644
--- a/src/couchdb/couch_httpd_show.erl
+++ b/apps/couch/src/couch_httpd_show.erl
diff --git a/src/couchdb/couch_httpd_stats_handlers.erl b/apps/couch/src/couch_httpd_stats_handlers.erl
index 41aeaed0..41aeaed0 100644
--- a/src/couchdb/couch_httpd_stats_handlers.erl
+++ b/apps/couch/src/couch_httpd_stats_handlers.erl
diff --git a/src/couchdb/couch_httpd_vhost.erl b/apps/couch/src/couch_httpd_vhost.erl
index 9bfb5951..9bfb5951 100644
--- a/src/couchdb/couch_httpd_vhost.erl
+++ b/apps/couch/src/couch_httpd_vhost.erl
diff --git a/src/couchdb/couch_httpd_view.erl b/apps/couch/src/couch_httpd_view.erl
index b71fc2c6..b71fc2c6 100644
--- a/src/couchdb/couch_httpd_view.erl
+++ b/apps/couch/src/couch_httpd_view.erl
diff --git a/src/couchdb/couch_js_functions.hrl b/apps/couch/src/couch_js_functions.hrl
index d07eead5..d07eead5 100644
--- a/src/couchdb/couch_js_functions.hrl
+++ b/apps/couch/src/couch_js_functions.hrl
diff --git a/src/couchdb/couch_key_tree.erl b/apps/couch/src/couch_key_tree.erl
index e5d3549f..c5fd1088 100644
--- a/src/couchdb/couch_key_tree.erl
+++ b/apps/couch/src/couch_key_tree.erl
@@ -12,7 +12,8 @@
-module(couch_key_tree).
--export([merge/3, find_missing/2, get_key_leafs/2, get_full_key_paths/2, get/2]).
+-export([merge/3, find_missing/2, get_key_leafs/2,
+ get_full_key_paths/2, get/2, compute_data_size/1]).
-export([map/2, get_all_leafs/1, count_leafs/1, remove_leafs/2,
get_all_leafs_full/1,stem/2,map_leafs/2]).
@@ -284,6 +285,53 @@ count_leafs_simple([{_Key, _Value, []} | RestTree]) ->
count_leafs_simple([{_Key, _Value, SubTree} | RestTree]) ->
count_leafs_simple(SubTree) + count_leafs_simple(RestTree).
+compute_data_size(Tree) ->
+ {TotBodySizes,TotAttSizes} =
+ tree_fold(fun({_Pos, _Key, _Value},branch,Acc) ->
+ {ok,Acc};
+ ({_Pos, _Key, Value},leaf,Acc) ->
+ {ok, sum_up_sizes(Value, Acc)}
+ end,{0,[]},Tree),
+ SumTotAttSizes = lists:foldl(fun({_K,V},Acc) ->
+ V + Acc
+ end,0,TotAttSizes),
+ TotBodySizes + SumTotAttSizes.
+
+sum_up_sizes(#leaf{deleted=true}, Acc) ->
+ Acc;
+sum_up_sizes(#leaf{deleted=false, size=DocBodySize, atts=AttSizes},Acc) ->
+ {TotBodySizes,TotalAttSizes} = Acc,
+ {TotBodySizes + DocBodySize, add_att_sizes(TotalAttSizes, AttSizes)}.
+
+add_att_sizes(TotalAttSizes,AttSizes) ->
+ lists:umerge(TotalAttSizes, lists:sort(AttSizes)).
+
+tree_fold(_Fun, Acc, []) ->
+ Acc;
+
+tree_fold(Fun, Acc, [{Pos, Branch} | Rest]) ->
+ Acc1 = tree_fold_simple(Fun, Pos, [Branch], Acc),
+ tree_fold(Fun, Acc1, Rest).
+
+tree_fold_simple(_Fun, _Pos, [], Acc) ->
+ Acc;
+
+tree_fold_simple(Fun, Pos, [{Key, Value, []} | RestTree], Acc) ->
+ case Fun({Pos, Key, Value}, leaf, Acc) of
+ {ok, Acc1} ->
+ tree_fold_simple(Fun, Pos, RestTree, Acc1);
+ {stop, Acc1} ->
+ Acc1
+ end;
+
+tree_fold_simple(Fun, Pos, [{Key, Value, SubTree} | RestTree], Acc) ->
+ Acc1 = tree_fold_simple(Fun, Pos + 1, SubTree, Acc),
+ case Fun({Pos, Key, Value}, branch, Acc1) of
+ {ok, Acc2} ->
+ tree_fold_simple(Fun, Pos, RestTree, Acc2);
+ {stop, Acc2} ->
+ Acc2
+ end.
map(_Fun, []) ->
[];
diff --git a/src/couchdb/couch_log.erl b/apps/couch/src/couch_log.erl
index b3d3297c..9bac7450 100644
--- a/src/couchdb/couch_log.erl
+++ b/apps/couch/src/couch_log.erl
@@ -144,7 +144,8 @@ when Sasl =/= false ->
handle_event({_, _, {Pid, _, _}}=Event, {Fd, LogLevel, _Sasl}=State)
when LogLevel =< ?LEVEL_TMI ->
% log every remaining event if tmi!
- log(Fd, Pid, tmi, "~p", [Event]),
+ {ConMsg, FileMsg} = get_log_messages(Pid, tmi, "~p", [Event]),
+ log(Fd, ConMsg, FileMsg),
{ok, State};
handle_event(_Event, State) ->
{ok, State}.
@@ -162,20 +163,17 @@ code_change(_OldVsn, State, _Extra) ->
terminate(_Arg, {Fd, _LoggingLevel, _Sasl}) ->
file:close(Fd).
-log(Fd, Pid, Level, Format, Args) ->
- Msg = io_lib:format(Format, Args),
- ok = io:format("[~s] [~p] ~s~n", [Level, Pid, Msg]), % dump to console too
- Msg2 = re:replace(lists:flatten(Msg),"\\r\\n|\\r|\\n", "\r\n",
- [global, {return, list}]),
- ok = io:format(Fd, "[~s] [~s] [~p] ~s\r~n", [httpd_util:rfc1123_date(), Level, Pid, Msg2]).
-
log(Fd, ConsoleMsg, FileMsg) ->
ok = io:put_chars(ConsoleMsg),
ok = io:put_chars(Fd, FileMsg).
get_log_messages(Pid, Level, Format, Args) ->
+ Nonce = case erlang:get(nonce) of
+ undefined -> "--------";
+ Else -> Else
+ end,
ConsoleMsg = unicode:characters_to_binary(io_lib:format(
- "[~s] [~p] " ++ Format ++ "~n", [Level, Pid | Args])),
+ "[~s] [~p] [~s] " ++ Format ++ "~n", [Level, Pid, Nonce | Args])),
FileMsg = ["[", httpd_util:rfc1123_date(), "] ", ConsoleMsg],
{ConsoleMsg, iolist_to_binary(FileMsg)}.
diff --git a/src/couchdb/couch_native_process.erl b/apps/couch/src/couch_native_process.erl
index b512f712..b512f712 100644
--- a/src/couchdb/couch_native_process.erl
+++ b/apps/couch/src/couch_native_process.erl
diff --git a/src/couchdb/couch_os_daemons.erl b/apps/couch/src/couch_os_daemons.erl
index d03f550c..d03f550c 100644
--- a/src/couchdb/couch_os_daemons.erl
+++ b/apps/couch/src/couch_os_daemons.erl
diff --git a/src/couchdb/couch_os_process.erl b/apps/couch/src/couch_os_process.erl
index 5776776b..7fe8aa89 100644
--- a/src/couchdb/couch_os_process.erl
+++ b/apps/couch/src/couch_os_process.erl
@@ -59,12 +59,12 @@ prompt(Pid, Data) ->
% Utility functions for reading and writing
% in custom functions
-writeline(OsProc, Data) when is_record(OsProc, os_proc) ->
- port_command(OsProc#os_proc.port, Data ++ "\n").
+writeline(#os_proc{port=Port}, Data) ->
+ port_command(Port, Data ++ "\n").
readline(#os_proc{} = OsProc) ->
readline(OsProc, []).
-readline(#os_proc{port = Port} = OsProc, Acc) ->
+readline(#os_proc{port=Port, timeout=Timeout} = OsProc, Acc) ->
receive
{Port, {data, {noeol, Data}}} ->
readline(OsProc, [Data|Acc]);
@@ -73,7 +73,7 @@ readline(#os_proc{port = Port} = OsProc, Acc) ->
{Port, Err} ->
catch port_close(Port),
throw({os_process_error, Err})
- after OsProc#os_proc.timeout ->
+ after Timeout ->
catch port_close(Port),
throw({os_process_error, "OS process timed out."})
end.
@@ -81,12 +81,12 @@ readline(#os_proc{port = Port} = OsProc, Acc) ->
% Standard JSON functions
writejson(OsProc, Data) when is_record(OsProc, os_proc) ->
JsonData = ?JSON_ENCODE(Data),
- ?LOG_DEBUG("OS Process ~p Input :: ~s", [OsProc#os_proc.port, JsonData]),
+ % ?LOG_DEBUG("OS Process ~p Input :: ~s", [OsProc#os_proc.port, JsonData]),
true = writeline(OsProc, JsonData).
-readjson(OsProc) when is_record(OsProc, os_proc) ->
+readjson(#os_proc{} = OsProc) ->
Line = readline(OsProc),
- ?LOG_DEBUG("OS Process ~p Output :: ~s", [OsProc#os_proc.port, Line]),
+ % ?LOG_DEBUG("OS Process ~p Output :: ~s", [OsProc#os_proc.port, Line]),
case ?JSON_DECODE(Line) of
[<<"log">>, Msg] when is_binary(Msg) ->
% we got a message to log. Log it and continue
@@ -104,9 +104,7 @@ readjson(OsProc) when is_record(OsProc, os_proc) ->
% gen_server API
init([Command, Options, PortOptions]) ->
- process_flag(trap_exit, true),
- PrivDir = couch_util:priv_dir(),
- Spawnkiller = filename:join(PrivDir, "couchspawnkillable"),
+ Spawnkiller = filename:join([code:priv_dir(couch), "couchspawnkillable.sh"]),
BaseProc = #os_proc{
command=Command,
port=open_port({spawn, Spawnkiller ++ " " ++ Command}, PortOptions),
@@ -115,7 +113,7 @@ init([Command, Options, PortOptions]) ->
},
KillCmd = readline(BaseProc),
Pid = self(),
- ?LOG_DEBUG("OS Process Start :: ~p", [BaseProc#os_proc.port]),
+ % ?LOG_DEBUG("OS Process Start :: ~p", [BaseProc#os_proc.port]),
spawn(fun() ->
% this ensure the real os process is killed when this process dies.
erlang:monitor(process, Pid),
diff --git a/apps/couch/src/couch_primary_sup.erl b/apps/couch/src/couch_primary_sup.erl
new file mode 100644
index 00000000..2aff86ef
--- /dev/null
+++ b/apps/couch/src/couch_primary_sup.erl
@@ -0,0 +1,48 @@
+-module(couch_primary_sup).
+-behaviour(supervisor).
+-export([init/1, start_link/0]).
+
+start_link() ->
+ supervisor:start_link({local,couch_primary_services}, ?MODULE, []).
+
+init([]) ->
+ Children = [
+ {collation_driver,
+ {couch_drv, start_link, []},
+ permanent,
+ brutal_kill,
+ worker,
+ [couch_drv]},
+ {couch_task_status,
+ {couch_task_status, start_link, []},
+ permanent,
+ brutal_kill,
+ worker,
+ [couch_task_status]},
+ {couch_server,
+ {couch_server, sup_start_link, []},
+ permanent,
+ brutal_kill,
+ worker,
+ [couch_server]},
+ {couch_db_update_event,
+ {gen_event, start_link, [{local, couch_db_update}]},
+ permanent,
+ brutal_kill,
+ worker,
+ dynamic},
+ {couch_replication_supervisor,
+ {couch_rep_sup, start_link, []},
+ permanent,
+ infinity,
+ supervisor,
+ [couch_rep_sup]},
+ {couch_log,
+ {couch_log, start_link, []},
+ permanent,
+ brutal_kill,
+ worker,
+ [couch_log]}
+ ],
+ {ok, {{one_for_one, 10, 3600}, Children}}.
+
diff --git a/apps/couch/src/couch_proc_manager.erl b/apps/couch/src/couch_proc_manager.erl
new file mode 100644
index 00000000..438f7973
--- /dev/null
+++ b/apps/couch/src/couch_proc_manager.erl
@@ -0,0 +1,184 @@
+-module(couch_proc_manager).
+-behaviour(gen_server).
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
+ code_change/3]).
+
+-export([start_link/0, get_proc_count/0]).
+
+-include("couch_db.hrl").
+
+-record(state, {tab}).
+
+start_link() ->
+ gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
+
+get_proc_count() ->
+ gen_server:call(?MODULE, get_proc_count).
+
+init([]) ->
+ process_flag(trap_exit, true),
+ {ok, #state{tab = ets:new(procs, [{keypos, #proc.pid}])}}.
+
+handle_call(get_table, _From, State) ->
+ {reply, State#state.tab, State};
+
+handle_call(get_proc_count, _From, State) ->
+ {reply, ets:info(State#state.tab, size), State};
+
+handle_call({get_proc, #doc{body={Props}}=DDoc, DDocKey}, {Client, _}, State) ->
+ Lang = couch_util:get_value(<<"language">>, Props, <<"javascript">>),
+ try get_procs(State#state.tab, Lang) of
+ Procs ->
+ case proc_with_ddoc(DDoc, DDocKey, Procs) of
+ {ok, Proc0} ->
+ Proc = Proc0#proc{client = erlang:monitor(process, Client)},
+ ets:insert(State#state.tab, Proc),
+ {reply, {ok, Proc, get_query_server_config()}, State};
+ {error, Reason} ->
+ {reply, {error, Reason}, State}
+ end
+ catch {unknown_query_language, _} ->
+ {reply, {unknown_query_language, Lang}, State};
+ error:Reason ->
+ ?LOG_ERROR("~p ~p ~p", [?MODULE, Reason, erlang:get_stacktrace()]),
+ {reply, {error, Reason}, State}
+ end;
+
+handle_call({get_proc, Lang}, {Client, _}, State) ->
+ try get_procs(State#state.tab, Lang) of
+ [Proc0|_] ->
+ Proc = Proc0#proc{client = erlang:monitor(process, Client)},
+ ets:insert(State#state.tab, Proc),
+ {reply, {ok, Proc, get_query_server_config()}, State}
+ catch {unknown_query_language, _} ->
+ {reply, {unknown_query_language, Lang}, State};
+ error:Reason ->
+ ?LOG_ERROR("~p ~p ~p", [?MODULE, Reason, erlang:get_stacktrace()]),
+ {reply, {error, Reason}, State}
+ end;
+
+handle_call({ret_proc, #proc{client=Ref, pid=Pid} = Proc}, _From, State) ->
+ erlang:demonitor(Ref, [flush]),
+ % We need to check if the process is alive here, as the client could be
+ % handing us a #proc{} with a dead one. We would have already removed the
+ % #proc{} from our own table, so the alternative is to do a lookup in the
+ % table before the insert. Don't know which approach is cheaper.
+ case is_process_alive(Pid) of true ->
+ maybe_reuse_proc(State#state.tab, Proc);
+ false -> ok end,
+ {reply, true, State};
+
+handle_call(_Call, _From, State) ->
+ {reply, ignored, State}.
+
+handle_cast(_Msg, State) ->
+ {noreply, State}.
+
+handle_info({'EXIT', Pid, Reason}, State) ->
+ ?LOG_INFO("~p ~p died ~p", [?MODULE, Pid, Reason]),
+ ets:delete(State#state.tab, Pid),
+ {noreply, State};
+
+handle_info({'DOWN', Ref, _, _, _Reason}, State) ->
+ case ets:match_object(State#state.tab, #proc{client=Ref, _='_'}) of
+ [] ->
+ ok;
+ [#proc{pid = Pid} = Proc] ->
+ case is_process_alive(Pid) of true ->
+ maybe_reuse_proc(State#state.tab, Proc);
+ false -> ok end
+ end,
+ {noreply, State};
+
+handle_info(_Msg, State) ->
+ {noreply, State}.
+
+terminate(_Reason, #state{tab=Tab}) ->
+ ets:foldl(fun(#proc{pid=P}, _) -> couch_util:shutdown_sync(P) end, 0, Tab),
+ ok.
+
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+
+maybe_reuse_proc(Tab, #proc{pid = Pid} = Proc) ->
+ Limit = couch_config:get("query_server_config", "os_process_soft_limit", "100"),
+ case ets:info(Tab, size) > list_to_integer(Limit) of
+ true ->
+ ets:delete(Tab, Pid),
+ unlink(Pid),
+ exit(Pid, kill);
+ false ->
+ garbage_collect(Pid),
+ ets:insert(Tab, Proc#proc{client=nil})
+ end.
+
+get_procs(Tab, Lang) when is_binary(Lang) ->
+ get_procs(Tab, binary_to_list(Lang));
+get_procs(Tab, Lang) when is_list(Lang) ->
+ case ets:match_object(Tab, #proc{lang=Lang, client=nil, _='_'}) of
+ [] ->
+ {ok, NewProc} = new_proc(Lang), % check OS process limit
+ [NewProc];
+ Procs ->
+ Procs
+ end.
+
+new_proc(Lang) when is_list(Lang) ->
+ case couch_config:get("query_servers", Lang) of
+ undefined ->
+ case couch_config:get("native_query_servers", Lang) of
+ undefined ->
+ throw({unknown_query_language, Lang});
+ SpecStr ->
+ {ok, {M,F,A}} = couch_util:parse_term(SpecStr),
+ {ok, Pid} = apply(M, F, A),
+ make_proc(Pid, Lang, M)
+ end;
+ Command ->
+ {ok, Pid} = couch_os_process:start_link(Command),
+ make_proc(Pid, Lang, couch_os_process)
+ end.
+
+make_proc(Pid, Lang, Mod) ->
+ Proc = #proc{
+ lang = Lang,
+ pid = Pid,
+ prompt_fun = {Mod, prompt},
+ set_timeout_fun = {Mod, set_timeout},
+ stop_fun = {Mod, stop}
+ },
+ {ok, Proc}.
+
+get_query_server_config() ->
+ Limit = couch_config:get("query_server_config", <<"reduce_limit">>, "true"),
+ {[{<<"reduce_limit">>, list_to_atom(Limit)}]}.
+
+proc_with_ddoc(DDoc, DDocKey, Procs) ->
+ Filter = fun(#proc{ddoc_keys=Keys}) -> not lists:member(DDocKey, Keys) end,
+ case lists:dropwhile(Filter, Procs) of
+ [DDocProc|_] ->
+ {ok, DDocProc};
+ [] ->
+ teach_any_proc(DDoc, DDocKey, Procs)
+ end.
+
+teach_any_proc(DDoc, DDocKey, [Proc|Rest]) ->
+ try
+ teach_ddoc(DDoc, DDocKey, Proc)
+ catch _:_ ->
+ teach_any_proc(DDoc, DDocKey, Rest)
+ end;
+teach_any_proc(_, _, []) ->
+ {error, noproc}.
+
+teach_ddoc(DDoc, {DDocId, _Rev}=DDocKey, #proc{ddoc_keys=Keys}=Proc) ->
+ % send ddoc over the wire
+ % we only share the rev with the client we know to update code
+ % but it only keeps the latest copy, per each ddoc, around.
+ true = couch_query_servers:proc_prompt(Proc, [<<"ddoc">>, <<"new">>,
+ DDocId, couch_doc:to_json_obj(DDoc, [])]),
+ % we should remove any other ddocs keys for this docid
+ % because the query server overwrites without the rev
+ Keys2 = [{D,R} || {D,R} <- Keys, D /= DDocId],
+ % add ddoc to the proc
+ {ok, Proc#proc{ddoc_keys=[DDocKey|Keys2]}}.
diff --git a/apps/couch/src/couch_query_servers.erl b/apps/couch/src/couch_query_servers.erl
new file mode 100644
index 00000000..be7c465b
--- /dev/null
+++ b/apps/couch/src/couch_query_servers.erl
@@ -0,0 +1,284 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_query_servers).
+
+-export([start_doc_map/3, map_docs/2, stop_doc_map/1]).
+-export([reduce/3, rereduce/3,validate_doc_update/5]).
+-export([filter_docs/5]).
+
+-export([with_ddoc_proc/2, proc_prompt/2, ddoc_prompt/3, ddoc_proc_prompt/3, json_doc/1]).
+-export([get_os_process/1, ret_os_process/1]).
+
+% -export([test/0]).
+
+-include("couch_db.hrl").
+
+start_doc_map(Lang, Functions, Lib) ->
+ Proc = get_os_process(Lang),
+ case Lib of
+ {[]} -> ok;
+ Lib ->
+ true = proc_prompt(Proc, [<<"add_lib">>, Lib])
+ end,
+ lists:foreach(fun(FunctionSource) ->
+ true = proc_prompt(Proc, [<<"add_fun">>, FunctionSource])
+ end, Functions),
+ {ok, Proc}.
+
+map_docs(Proc, Docs) ->
+ % send the documents
+ Results = lists:map(
+ fun(Doc) ->
+ Json = couch_doc:to_json_obj(Doc, []),
+
+ FunsResults = proc_prompt(Proc, [<<"map_doc">>, Json]),
+ % the results are a json array of function map yields like this:
+ % [FunResults1, FunResults2 ...]
+ % where funresults is are json arrays of key value pairs:
+ % [[Key1, Value1], [Key2, Value2]]
+ % Convert the key, value pairs to tuples like
+ % [{Key1, Value1}, {Key2, Value2}]
+ lists:map(
+ fun(FunRs) ->
+ [list_to_tuple(FunResult) || FunResult <- FunRs]
+ end,
+ FunsResults)
+ end,
+ Docs),
+ {ok, Results}.
+
+
+stop_doc_map(nil) ->
+ ok;
+stop_doc_map(Proc) ->
+ ok = ret_os_process(Proc).
+
+group_reductions_results([]) ->
+ [];
+group_reductions_results(List) ->
+ {Heads, Tails} = lists:foldl(
+ fun([H|T], {HAcc,TAcc}) ->
+ {[H|HAcc], [T|TAcc]}
+ end, {[], []}, List),
+ case Tails of
+ [[]|_] -> % no tails left
+ [Heads];
+ _ ->
+ [Heads | group_reductions_results(Tails)]
+ end.
+
+rereduce(_Lang, [], _ReducedValues) ->
+ {ok, []};
+rereduce(Lang, RedSrcs, ReducedValues) ->
+ Grouped = group_reductions_results(ReducedValues),
+ Results = lists:zipwith(
+ fun
+ (<<"_", _/binary>> = FunSrc, Values) ->
+ {ok, [Result]} = builtin_reduce(rereduce, [FunSrc], [[[], V] || V <- Values], []),
+ Result;
+ (FunSrc, Values) ->
+ os_rereduce(Lang, [FunSrc], Values)
+ end, RedSrcs, Grouped),
+ {ok, Results}.
+
+reduce(_Lang, [], _KVs) ->
+ {ok, []};
+reduce(Lang, RedSrcs, KVs) ->
+ {OsRedSrcs, BuiltinReds} = lists:partition(fun
+ (<<"_", _/binary>>) -> false;
+ (_OsFun) -> true
+ end, RedSrcs),
+ {ok, OsResults} = os_reduce(Lang, OsRedSrcs, KVs),
+ {ok, BuiltinResults} = builtin_reduce(reduce, BuiltinReds, KVs, []),
+ recombine_reduce_results(RedSrcs, OsResults, BuiltinResults, []).
+
+recombine_reduce_results([], [], [], Acc) ->
+ {ok, lists:reverse(Acc)};
+recombine_reduce_results([<<"_", _/binary>>|RedSrcs], OsResults, [BRes|BuiltinResults], Acc) ->
+ recombine_reduce_results(RedSrcs, OsResults, BuiltinResults, [BRes|Acc]);
+recombine_reduce_results([_OsFun|RedSrcs], [OsR|OsResults], BuiltinResults, Acc) ->
+ recombine_reduce_results(RedSrcs, OsResults, BuiltinResults, [OsR|Acc]).
+
+os_reduce(_Lang, [], _KVs) ->
+ {ok, []};
+os_reduce(#proc{} = Proc, OsRedSrcs, KVs) ->
+ [true, Reductions] = proc_prompt(Proc, [<<"reduce">>, OsRedSrcs, KVs]),
+ {ok, Reductions};
+os_reduce(Lang, OsRedSrcs, KVs) ->
+ Proc = get_os_process(Lang),
+ try os_reduce(Proc, OsRedSrcs, KVs) after ok = ret_os_process(Proc) end.
+
+os_rereduce(#proc{} = Proc, OsRedSrcs, KVs) ->
+ [true, [Reduction]] = proc_prompt(Proc, [<<"rereduce">>, OsRedSrcs, KVs]),
+ Reduction;
+os_rereduce(Lang, OsRedSrcs, KVs) ->
+ Proc = get_os_process(Lang),
+ try os_rereduce(Proc, OsRedSrcs, KVs) after ok = ret_os_process(Proc) end.
+
+builtin_reduce(_Re, [], _KVs, Acc) ->
+ {ok, lists:reverse(Acc)};
+builtin_reduce(Re, [<<"_sum",_/binary>>|BuiltinReds], KVs, Acc) ->
+ Sum = builtin_sum_rows(KVs),
+ builtin_reduce(Re, BuiltinReds, KVs, [Sum|Acc]);
+builtin_reduce(reduce, [<<"_count",_/binary>>|BuiltinReds], KVs, Acc) ->
+ Count = length(KVs),
+ builtin_reduce(reduce, BuiltinReds, KVs, [Count|Acc]);
+builtin_reduce(rereduce, [<<"_count",_/binary>>|BuiltinReds], KVs, Acc) ->
+ Count = builtin_sum_rows(KVs),
+ builtin_reduce(rereduce, BuiltinReds, KVs, [Count|Acc]);
+builtin_reduce(Re, [<<"_stats",_/binary>>|BuiltinReds], KVs, Acc) ->
+ Stats = builtin_stats(Re, KVs),
+ builtin_reduce(Re, BuiltinReds, KVs, [Stats|Acc]).
+
+builtin_sum_rows(KVs) ->
+ lists:foldl(fun
+ ([_Key, Value], Acc) when is_number(Value), is_number(Acc) ->
+ Acc + Value;
+ ([_Key, Value], Acc) when is_list(Value), is_list(Acc) ->
+ sum_terms(Acc, Value);
+ ([_Key, Value], Acc) when is_number(Value), is_list(Acc) ->
+ sum_terms(Acc, [Value]);
+ ([_Key, Value], Acc) when is_list(Value), is_number(Acc) ->
+ sum_terms([Acc], Value);
+ (_Else, _Acc) ->
+ throw({invalid_value, <<"builtin _sum function requires map values to be numbers or lists of numbers">>})
+ end, 0, KVs).
+
+sum_terms([], []) ->
+ [];
+sum_terms([_|_]=Xs, []) ->
+ Xs;
+sum_terms([], [_|_]=Ys) ->
+ Ys;
+sum_terms([X|Xs], [Y|Ys]) when is_number(X), is_number(Y) ->
+ [X+Y | sum_terms(Xs,Ys)];
+sum_terms(_, _) ->
+ throw({invalid_value, <<"builtin _sum function requires map values to be numbers or lists of numbers">>}).
+
+builtin_stats(_, []) ->
+ {[{sum,0}, {count,0}, {min,0}, {max,0}, {sumsqr,0}]};
+
+builtin_stats(reduce, [[_,First]|Rest]) when is_number(First) ->
+ Stats = lists:foldl(fun([_K,V], {S,C,Mi,Ma,Sq}) when is_number(V) ->
+ {S+V, C+1, lists:min([Mi, V]), lists:max([Ma, V]), Sq+(V*V)};
+ (_, _) ->
+ throw({invalid_value,
+ <<"builtin _stats function requires map values to be numbers">>})
+ end, {First,1,First,First,First*First}, Rest),
+ {Sum, Cnt, Min, Max, Sqr} = Stats,
+ {[{sum,Sum}, {count,Cnt}, {min,Min}, {max,Max}, {sumsqr,Sqr}]};
+
+builtin_stats(rereduce, [[_,First]|Rest]) ->
+ {[{sum,Sum0}, {count,Cnt0}, {min,Min0}, {max,Max0}, {sumsqr,Sqr0}]} = First,
+ Stats = lists:foldl(fun([_K,Red], {S,C,Mi,Ma,Sq}) ->
+ {[{sum,Sum}, {count,Cnt}, {min,Min}, {max,Max}, {sumsqr,Sqr}]} = Red,
+ {Sum+S, Cnt+C, lists:min([Min, Mi]), lists:max([Max, Ma]), Sqr+Sq}
+ end, {Sum0,Cnt0,Min0,Max0,Sqr0}, Rest),
+ {Sum, Cnt, Min, Max, Sqr} = Stats,
+ {[{sum,Sum}, {count,Cnt}, {min,Min}, {max,Max}, {sumsqr,Sqr}]}.
+
+% use the function stored in ddoc.validate_doc_update to test an update.
+validate_doc_update(DDoc, EditDoc, DiskDoc, Ctx, SecObj) ->
+ JsonEditDoc = couch_doc:to_json_obj(EditDoc, [revs]),
+ JsonDiskDoc = json_doc(DiskDoc),
+ case ddoc_prompt(DDoc, [<<"validate_doc_update">>], [JsonEditDoc, JsonDiskDoc, Ctx, SecObj]) of
+ 1 ->
+ ok;
+ {[{<<"forbidden">>, Message}]} ->
+ throw({forbidden, Message});
+ {[{<<"unauthorized">>, Message}]} ->
+ throw({unauthorized, Message})
+ end.
+
+json_doc(nil) -> null;
+json_doc(Doc) ->
+ couch_doc:to_json_obj(Doc, [revs]).
+
+filter_docs(Req, Db, DDoc, FName, Docs) ->
+ JsonReq = case Req of
+ {json_req, JsonObj} ->
+ JsonObj;
+ #httpd{} = HttpReq ->
+ couch_httpd_external:json_req_obj(HttpReq, Db)
+ end,
+ JsonDocs = [couch_doc:to_json_obj(Doc, [revs]) || Doc <- Docs],
+ [true, Passes] = ddoc_prompt(DDoc, [<<"filters">>, FName], [JsonDocs, JsonReq]),
+ {ok, Passes}.
+
+ddoc_proc_prompt({Proc, DDocId}, FunPath, Args) ->
+ proc_prompt(Proc, [<<"ddoc">>, DDocId, FunPath, Args]).
+
+ddoc_prompt(DDoc, FunPath, Args) ->
+ with_ddoc_proc(DDoc, fun({Proc, DDocId}) ->
+ proc_prompt(Proc, [<<"ddoc">>, DDocId, FunPath, Args])
+ end).
+
+with_ddoc_proc(#doc{id=DDocId,revs={Start, [DiskRev|_]}}=DDoc, Fun) ->
+ Rev = couch_doc:rev_to_str({Start, DiskRev}),
+ DDocKey = {DDocId, Rev},
+ Proc = get_ddoc_process(DDoc, DDocKey),
+ try Fun({Proc, DDocId})
+ after
+ ok = ret_os_process(Proc)
+ end.
+
+proc_prompt(Proc, Args) ->
+ {Mod, Func} = Proc#proc.prompt_fun,
+ apply(Mod, Func, [Proc#proc.pid, Args]).
+
+proc_stop(Proc) ->
+ {Mod, Func} = Proc#proc.stop_fun,
+ apply(Mod, Func, [Proc#proc.pid]).
+
+proc_set_timeout(Proc, Timeout) ->
+ {Mod, Func} = Proc#proc.set_timeout_fun,
+ apply(Mod, Func, [Proc#proc.pid, Timeout]).
+
+get_ddoc_process(#doc{} = DDoc, DDocKey) ->
+ % remove this case statement
+ case gen_server:call(couch_proc_manager, {get_proc, DDoc, DDocKey}) of
+ {ok, Proc, QueryConfig} ->
+ % process knows the ddoc
+ case (catch proc_prompt(Proc, [<<"reset">>, QueryConfig])) of
+ true ->
+ proc_set_timeout(Proc, list_to_integer(couch_config:get(
+ "couchdb", "os_process_timeout", "5000"))),
+ Proc;
+ _ ->
+ catch proc_stop(Proc),
+ get_ddoc_process(DDoc, DDocKey)
+ end;
+ Error ->
+ throw(Error)
+ end.
+
+get_os_process(Lang) ->
+ case gen_server:call(couch_proc_manager, {get_proc, Lang}) of
+ {ok, Proc, QueryConfig} ->
+ case (catch proc_prompt(Proc, [<<"reset">>, QueryConfig])) of
+ true ->
+ proc_set_timeout(Proc, list_to_integer(couch_config:get(
+ "couchdb", "os_process_timeout", "5000"))),
+ Proc;
+ _ ->
+ catch proc_stop(Proc),
+ get_os_process(Lang)
+ end;
+ Error ->
+ throw(Error)
+ end.
+
+ret_os_process(Proc) ->
+ true = gen_server:call(couch_proc_manager, {ret_proc, Proc}),
+ catch unlink(Proc#proc.pid),
+ ok.
diff --git a/src/couchdb/couch_ref_counter.erl b/apps/couch/src/couch_ref_counter.erl
index 5a111ab6..5a111ab6 100644
--- a/src/couchdb/couch_ref_counter.erl
+++ b/apps/couch/src/couch_ref_counter.erl
diff --git a/src/couchdb/couch_rep.erl b/apps/couch/src/couch_rep.erl
index 6e4295ea..482b84dc 100644
--- a/src/couchdb/couch_rep.erl
+++ b/apps/couch/src/couch_rep.erl
@@ -22,7 +22,7 @@
-include("couch_db.hrl").
-include("couch_js_functions.hrl").
--include("../ibrowse/ibrowse.hrl").
+-include_lib("ibrowse/include/ibrowse.hrl").
-define(REP_ID_VERSION, 2).
@@ -110,20 +110,20 @@ checkpoint(Server) ->
gen_server:cast(Server, do_checkpoint).
get_result(Server, {BaseId, _Extension}, {Props} = PostBody, UserCtx) ->
- case couch_util:get_value(<<"continuous">>, Props, false) of
- true ->
- {ok, {continuous, ?l2b(BaseId)}};
- false ->
- try gen_server:call(Server, get_result, infinity) of
- retry -> replicate(PostBody, UserCtx);
- Else -> Else
- catch
- exit:{noproc, {gen_server, call, [Server, get_result, infinity]}} ->
- %% oops, this replication just finished -- restart it.
- replicate(PostBody, UserCtx);
- exit:{normal, {gen_server, call, [Server, get_result, infinity]}} ->
- %% we made the call during terminate
- replicate(PostBody, UserCtx)
+ case couch_util:get_value(<<"continuous">>, Props, false) of
+ true ->
+ {ok, {continuous, ?l2b(BaseId)}};
+ false ->
+ try gen_server:call(Server, get_result, infinity) of
+ retry -> replicate(PostBody, UserCtx);
+ Else -> Else
+ catch
+ exit:{noproc, {gen_server, call, [Server, get_result , infinity]}} ->
+ %% oops, this replication just finished -- restart it.
+ replicate(PostBody, UserCtx);
+ exit:{normal, {gen_server, call, [Server, get_result , infinity]}} ->
+ %% we made the call during terminate
+ replicate(PostBody, UserCtx)
end
end.
@@ -156,13 +156,13 @@ do_init([RepId, {PostProps} = RepDoc, UserCtx] = InitArgs) ->
[SourceLog, TargetLog] = find_replication_logs(
[Source, Target], RepId, {PostProps}, UserCtx),
- {StartSeq, History} = compare_replication_logs(SourceLog, TargetLog),
+ {StartSeq, History} = compare_replication_logs(SourceLog, TargetLog),
- {ok, ChangesFeed} =
+ {ok, ChangesFeed} =
couch_rep_changes_feed:start_link(self(), Source, StartSeq, PostProps),
- {ok, MissingRevs} =
+ {ok, MissingRevs} =
couch_rep_missing_revs:start_link(self(), Target, ChangesFeed, PostProps),
- {ok, Reader} =
+ {ok, Reader} =
couch_rep_reader:start_link(self(), Source, MissingRevs, PostProps),
{ok, Writer} =
couch_rep_writer:start_link(self(), Target, Reader, PostProps),
@@ -622,18 +622,18 @@ open_db(<<"https://",_/binary>>=Url, _, ProxyParams, CreateTarget) ->
open_db({[{<<"url">>,Url}]}, [], ProxyParams, CreateTarget);
open_db(<<DbName/binary>>, UserCtx, _ProxyParams, CreateTarget) ->
try
- case CreateTarget of
- true ->
- ok = couch_httpd:verify_is_server_admin(UserCtx),
- couch_server:create(DbName, [{user_ctx, UserCtx}]);
+ case CreateTarget of
+ true ->
+ ok = couch_httpd:verify_is_server_admin(UserCtx),
+ couch_server:create(DbName, [{user_ctx, UserCtx}]);
false ->
ok
- end,
+ end,
- case couch_db:open(DbName, [{user_ctx, UserCtx}]) of
- {ok, Db} ->
- couch_db:monitor(Db),
- Db;
+ case couch_db:open(DbName, [{user_ctx, UserCtx}]) of
+ {ok, Db} ->
+ couch_db:monitor(Db),
+ Db;
{not_found, no_db_file} ->
throw({db_not_found, DbName})
end
diff --git a/src/couchdb/couch_rep_att.erl b/apps/couch/src/couch_rep_att.erl
index 6bb993a8..9988c5db 100644
--- a/src/couchdb/couch_rep_att.erl
+++ b/apps/couch/src/couch_rep_att.erl
@@ -78,7 +78,6 @@ receive_data(Ref, ReqId, ContentEncoding) ->
?LOG_ERROR("streaming attachment ~p failed with ~p", [ReqId, Err]),
throw({attachment_request_failed, Err});
{ibrowse_async_response, ReqId, Data} ->
- % ?LOG_DEBUG("got ~p bytes for ~p", [size(Data), ReqId]),
Data;
{ibrowse_async_response_end, ReqId} ->
?LOG_ERROR("streaming att. ended but more data requested ~p", [ReqId]),
diff --git a/src/couchdb/couch_rep_changes_feed.erl b/apps/couch/src/couch_rep_changes_feed.erl
index 1c298937..36fe82aa 100644
--- a/src/couchdb/couch_rep_changes_feed.erl
+++ b/apps/couch/src/couch_rep_changes_feed.erl
@@ -21,7 +21,7 @@
-define(DOC_IDS_FILTER_NAME, "_doc_ids").
-include("couch_db.hrl").
--include("../ibrowse/ibrowse.hrl").
+-include_lib("ibrowse/include/ibrowse.hrl").
-record (state, {
changes_from = nil,
diff --git a/src/couchdb/couch_rep_httpc.erl b/apps/couch/src/couch_rep_httpc.erl
index bbe390a9..e22c8f81 100644
--- a/src/couchdb/couch_rep_httpc.erl
+++ b/apps/couch/src/couch_rep_httpc.erl
@@ -12,7 +12,7 @@
-module(couch_rep_httpc).
-include("couch_db.hrl").
--include("../ibrowse/ibrowse.hrl").
+-include_lib("ibrowse/include/ibrowse.hrl").
-export([db_exists/1, db_exists/2]).
-export([full_url/1, request/1, redirected_request/3]).
@@ -207,8 +207,8 @@ process_response({error, Reason}, Req) ->
Else ->
Else
end,
- ?LOG_DEBUG("retrying couch_rep_httpc ~p request in ~p seconds due to " ++
- "{error, ~p}", [Method, Pause/1000, ShortReason]),
+ ?LOG_ERROR("~p retry ~p ~s in ~p seconds due to {error, ~p}",
+ [?MODULE, Method, full_url(Req), Pause/1000, ShortReason]),
timer:sleep(Pause),
if Reason == worker_is_dead ->
C = spawn_link_worker_process(Req),
diff --git a/src/couchdb/couch_rep_missing_revs.erl b/apps/couch/src/couch_rep_missing_revs.erl
index 9809ca5e..9809ca5e 100644
--- a/src/couchdb/couch_rep_missing_revs.erl
+++ b/apps/couch/src/couch_rep_missing_revs.erl
diff --git a/src/couchdb/couch_rep_reader.erl b/apps/couch/src/couch_rep_reader.erl
index 0d344e5c..0d344e5c 100644
--- a/src/couchdb/couch_rep_reader.erl
+++ b/apps/couch/src/couch_rep_reader.erl
diff --git a/src/couchdb/couch_rep_sup.erl b/apps/couch/src/couch_rep_sup.erl
index 1318c598..1318c598 100644
--- a/src/couchdb/couch_rep_sup.erl
+++ b/apps/couch/src/couch_rep_sup.erl
diff --git a/src/couchdb/couch_rep_writer.erl b/apps/couch/src/couch_rep_writer.erl
index 2b722e8e..2b722e8e 100644
--- a/src/couchdb/couch_rep_writer.erl
+++ b/apps/couch/src/couch_rep_writer.erl
diff --git a/src/couchdb/couch_replication_manager.erl b/apps/couch/src/couch_replication_manager.erl
index 6537c8b2..6537c8b2 100644
--- a/src/couchdb/couch_replication_manager.erl
+++ b/apps/couch/src/couch_replication_manager.erl
diff --git a/apps/couch/src/couch_secondary_sup.erl b/apps/couch/src/couch_secondary_sup.erl
new file mode 100644
index 00000000..8ccbd799
--- /dev/null
+++ b/apps/couch/src/couch_secondary_sup.erl
@@ -0,0 +1,35 @@
+-module(couch_secondary_sup).
+-behaviour(supervisor).
+-export([init/1, start_link/0]).
+
+start_link() ->
+ supervisor:start_link({local,couch_secondary_services}, ?MODULE, []).
+init([]) ->
+ SecondarySupervisors = [
+ {couch_db_update_notifier_sup,
+ {couch_db_update_notifier_sup, start_link, []},
+ permanent,
+ infinity,
+ supervisor,
+ [couch_db_update_notifier_sup]},
+ {couch_metrics_event_manager,
+ {gen_event, start_link, [{local, couch_metrics_event_manager}]},
+ permanent,
+ brutal_kill,
+ worker,
+ dynamic}
+ ],
+ Children = SecondarySupervisors ++ [
+ begin
+ {ok, {Module, Fun, Args}} = couch_util:parse_term(SpecStr),
+
+ {list_to_atom(Name),
+ {Module, Fun, Args},
+ permanent,
+ brutal_kill,
+ worker,
+ [Module]}
+ end
+ || {Name, SpecStr}
+ <- couch_config:get("daemons"), SpecStr /= ""],
+ {ok, {{one_for_one, 10, 3600}, Children}}.
diff --git a/apps/couch/src/couch_server.erl b/apps/couch/src/couch_server.erl
new file mode 100644
index 00000000..cfe0b5fc
--- /dev/null
+++ b/apps/couch/src/couch_server.erl
@@ -0,0 +1,373 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_server).
+-behaviour(gen_server).
+
+-export([open/2,create/2,delete/2,all_databases/0,all_databases/1]).
+-export([init/1, handle_call/3,sup_start_link/0]).
+-export([handle_cast/2,code_change/3,handle_info/2,terminate/2]).
+-export([dev_start/0,is_admin/2,has_admins/0,get_stats/0,config_change/4]).
+-export([close_lru/0]).
+
+-include("couch_db.hrl").
+
+-record(server,{
+ root_dir = [],
+ dbname_regexp,
+ max_dbs_open=100,
+ dbs_open=0,
+ start_time=""
+ }).
+
+dev_start() ->
+ couch:stop(),
+ up_to_date = make:all([load, debug_info]),
+ couch:start().
+
+get_stats() ->
+ {ok, #server{start_time=Time,dbs_open=Open}} =
+ gen_server:call(couch_server, get_server),
+ [{start_time, ?l2b(Time)}, {dbs_open, Open}].
+
+sup_start_link() ->
+ gen_server:start_link({local, couch_server}, couch_server, [], []).
+
+
+open(DbName, Options) ->
+ Ctx = couch_util:get_value(user_ctx, Options, #user_ctx{}),
+ case ets:lookup(couch_dbs, DbName) of
+ [#db{fd=Fd, fd_monitor=Lock} = Db] when Lock =/= locked ->
+ ets:insert(couch_lru, {DbName, now()}),
+ {ok, Db#db{user_ctx=Ctx, fd_monitor=erlang:monitor(process,Fd)}};
+ _ ->
+ Timeout = couch_util:get_value(timeout, Options, infinity),
+ case gen_server:call(couch_server, {open, DbName, Options}, Timeout) of
+ {ok, #db{fd=Fd} = Db} ->
+ ets:insert(couch_lru, {DbName, now()}),
+ {ok, Db#db{user_ctx=Ctx, fd_monitor=erlang:monitor(process,Fd)}};
+ Error ->
+ Error
+ end
+ end.
+
+close_lru() ->
+ gen_server:call(couch_server, close_lru).
+
+create(DbName, Options) ->
+ case gen_server:call(couch_server, {create, DbName, Options}, infinity) of
+ {ok, #db{fd=Fd} = Db} ->
+ Ctx = couch_util:get_value(user_ctx, Options, #user_ctx{}),
+ {ok, Db#db{user_ctx=Ctx, fd_monitor=erlang:monitor(process,Fd)}};
+ Error ->
+ Error
+ end.
+
+delete(DbName, Options) ->
+ gen_server:call(couch_server, {delete, DbName, Options}, infinity).
+
+check_dbname(#server{dbname_regexp=RegExp}, DbName) ->
+ case re:run(DbName, RegExp, [{capture, none}]) of
+ nomatch ->
+ case DbName of
+ "_users" -> ok;
+ "_replicator" -> ok;
+ _Else ->
+ {error, illegal_database_name}
+ end;
+ match ->
+ ok
+ end.
+
+is_admin(User, ClearPwd) ->
+ case couch_config:get("admins", User) of
+ "-hashed-" ++ HashedPwdAndSalt ->
+ [HashedPwd, Salt] = string:tokens(HashedPwdAndSalt, ","),
+ couch_util:to_hex(crypto:sha(ClearPwd ++ Salt)) == HashedPwd;
+ _Else ->
+ false
+ end.
+
+has_admins() ->
+ couch_config:get("admins") /= [].
+
+get_full_filename(Server, DbName) ->
+ filename:join([Server#server.root_dir, "./" ++ DbName ++ ".couch"]).
+
+hash_admin_passwords() ->
+ hash_admin_passwords(true).
+
+hash_admin_passwords(Persist) ->
+ lists:foreach(
+ fun({_User, "-hashed-" ++ _}) ->
+ ok; % already hashed
+ ({User, ClearPassword}) ->
+ Salt = ?b2l(couch_uuids:random()),
+ Hashed = couch_util:to_hex(crypto:sha(ClearPassword ++ Salt)),
+ couch_config:set("admins",
+ User, "-hashed-" ++ Hashed ++ "," ++ Salt, Persist)
+ end, couch_config:get("admins")).
+
+init([]) ->
+ % read config and register for configuration changes
+
+ % just stop if one of the config settings change. couch_server_sup
+ % will restart us and then we will pick up the new settings.
+
+ RootDir = couch_config:get("couchdb", "database_dir", "."),
+ MaxDbsOpen = list_to_integer(
+ couch_config:get("couchdb", "max_dbs_open")),
+ ok = couch_config:register(fun ?MODULE:config_change/4),
+ ok = couch_file:init_delete_dir(RootDir),
+ hash_admin_passwords(),
+ {ok, RegExp} = re:compile(
+ "^[a-z][a-z0-9\\_\\$()\\+\\-\\/]*" % use the stock CouchDB regex
+ "(\\.[0-9]{10,})?$" % but allow an optional shard timestamp at the end
+ ),
+ ets:new(couch_dbs, [set, protected, named_table, {keypos, #db.name}]),
+ ets:new(couch_lru, [set, public, named_table]),
+ process_flag(trap_exit, true),
+ {ok, #server{root_dir=RootDir,
+ dbname_regexp=RegExp,
+ max_dbs_open=MaxDbsOpen,
+ start_time=httpd_util:rfc1123_date()}}.
+
+terminate(_Reason, _Srv) ->
+ ets:foldl(fun(#db{main_pid=Pid}, _) -> couch_util:shutdown_sync(Pid) end,
+ nil, couch_dbs),
+ ok.
+
+config_change("couchdb", "database_dir", _, _) ->
+ exit(whereis(couch_server), config_change);
+config_change("couchdb", "max_dbs_open", Max, _) ->
+ gen_server:call(couch_server, {set_max_dbs_open, list_to_integer(Max)});
+config_change("admins", _, _, Persist) ->
+ % spawn here so couch_config doesn't try to call itself
+ spawn(fun() -> hash_admin_passwords(Persist) end).
+
+all_databases() ->
+ all_databases("").
+
+all_databases(Prefix) ->
+ {ok, #server{root_dir=Root}} = gen_server:call(couch_server, get_server),
+ NormRoot = couch_util:normpath(Root),
+ Filenames =
+ filelib:fold_files(Root++Prefix,
+ "^[a-z0-9\\_\\$()\\+\\-]*" % stock CouchDB name regex
+ "(\\.[0-9]{10,})?" % optional shard timestamp
+ "\\.couch$", % filename extenstion
+ true,
+ fun(Filename, AccIn) ->
+ NormFilename = couch_util:normpath(Filename),
+ case NormFilename -- NormRoot of
+ [$/ | RelativeFilename] -> ok;
+ RelativeFilename -> ok
+ end,
+ [list_to_binary(filename:rootname(RelativeFilename, ".couch")) | AccIn]
+ end, []),
+ {ok, lists:usort(Filenames)}.
+
+
+maybe_close_lru_db(#server{dbs_open=NumOpen, max_dbs_open=MaxOpen}=Server)
+ when NumOpen < MaxOpen ->
+ {ok, Server};
+maybe_close_lru_db(#server{dbs_open=NumOpen}=Server) ->
+ % must free up the lru db.
+ case try_close_lru(now()) of
+ ok ->
+ {ok, Server#server{dbs_open=NumOpen - 1}};
+ Error -> Error
+ end.
+
+find_oldest_db({DbName, Lru}, Acc) ->
+ erlang:min({Lru, DbName}, Acc).
+
+try_close_lru(StartTime) ->
+ case ets:foldl(fun find_oldest_db/2, {StartTime, nil}, couch_lru) of
+ {StartTime, nil} ->
+ {error, all_dbs_active};
+ {_, DbName} ->
+ % There may exist an extremely small possibility of a race
+ % condition here, if a process could lookup the DB before the lock,
+ % but fail to monitor the fd before the is_idle check.
+ true = ets:update_element(couch_dbs, DbName, {#db.fd_monitor, locked}),
+ [#db{main_pid = Pid} = Db] = ets:lookup(couch_dbs, DbName),
+ case couch_db:is_idle(Db) of true ->
+ true = ets:delete(couch_dbs, DbName),
+ true = ets:delete(couch_lru, DbName),
+ exit(Pid, kill),
+ ok;
+ false ->
+ true = ets:update_element(couch_dbs, DbName, {#db.fd_monitor, nil}),
+ true = ets:insert(couch_lru, {DbName, now()}),
+ try_close_lru(StartTime)
+ end
+ end.
+
+open_async(Server, From, DbName, Filepath, Options) ->
+ Parent = self(),
+ Opener = spawn_link(fun() ->
+ Res = couch_db:start_link(DbName, Filepath, Options),
+ gen_server:call(Parent, {open_result, DbName, Res}, infinity),
+ unlink(Parent)
+ end),
+ % icky hack of field values - compactor_pid used to store clients
+ true = ets:insert(couch_dbs, #db{
+ name = DbName,
+ main_pid = Opener,
+ compactor_pid = [From],
+ fd_monitor = locked
+ }),
+ Server#server{dbs_open=Server#server.dbs_open + 1}.
+
+handle_call(close_lru, _From, #server{dbs_open=N} = Server) ->
+ case try_close_lru(now()) of
+ ok ->
+ {reply, ok, Server#server{dbs_open = N-1}};
+ Error ->
+ {reply, Error, Server}
+ end;
+handle_call(open_dbs_count, _From, Server) ->
+ {reply, Server#server.dbs_open, Server};
+handle_call({set_dbname_regexp, RegExp}, _From, Server) ->
+ {reply, ok, Server#server{dbname_regexp=RegExp}};
+handle_call({set_max_dbs_open, Max}, _From, Server) ->
+ {reply, ok, Server#server{max_dbs_open=Max}};
+handle_call(get_server, _From, Server) ->
+ {reply, {ok, Server}, Server};
+handle_call({open_result, DbName, {ok, Db}}, _From, Server) ->
+ link(Db#db.main_pid),
+ % icky hack of field values - compactor_pid used to store clients
+ [#db{compactor_pid=Froms}] = ets:lookup(couch_dbs, DbName),
+ [gen_server:reply(From, {ok, Db}) || From <- Froms],
+ true = ets:insert(couch_dbs, Db),
+ true = ets:insert(couch_lru, {DbName, now()}),
+ {reply, ok, Server};
+handle_call({open_result, DbName, Error}, _From, Server) ->
+ % icky hack of field values - compactor_pid used to store clients
+ [#db{compactor_pid=Froms}] = ets:lookup(couch_dbs, DbName),
+ [gen_server:reply(From, Error) || From <- Froms],
+ true = ets:delete(couch_dbs, DbName),
+ {reply, ok, Server#server{dbs_open=Server#server.dbs_open - 1}};
+handle_call({open, DbName, Options}, From, Server) ->
+ case ets:lookup(couch_dbs, DbName) of
+ [] ->
+ DbNameList = binary_to_list(DbName),
+ case check_dbname(Server, DbNameList) of
+ ok ->
+ case maybe_close_lru_db(Server) of
+ {ok, Server2} ->
+ Filepath = get_full_filename(Server, DbNameList),
+ {noreply, open_async(Server2, From, DbName, Filepath, Options)};
+ CloseError ->
+ {reply, CloseError, Server}
+ end;
+ Error ->
+ {reply, Error, Server}
+ end;
+ [#db{compactor_pid = Froms} = Db] when is_list(Froms) ->
+ % icky hack of field values - compactor_pid used to store clients
+ true = ets:insert(couch_dbs, Db#db{compactor_pid = [From|Froms]}),
+ {noreply, Server};
+ [#db{} = Db] ->
+ {reply, {ok, Db}, Server}
+ end;
+handle_call({create, DbName, Options}, From, Server) ->
+ DbNameList = binary_to_list(DbName),
+ case check_dbname(Server, DbNameList) of
+ ok ->
+ case ets:lookup(couch_dbs, DbName) of
+ [] ->
+ case maybe_close_lru_db(Server) of
+ {ok, Server2} ->
+ Filepath = get_full_filename(Server, DbNameList),
+ {noreply, open_async(Server2, From, DbName, Filepath,
+ [create | Options])};
+ CloseError ->
+ {reply, CloseError, Server}
+ end;
+ [_AlreadyRunningDb] ->
+ {reply, file_exists, Server}
+ end;
+ Error ->
+ {reply, Error, Server}
+ end;
+handle_call({delete, DbName, _Options}, _From, Server) ->
+ DbNameList = binary_to_list(DbName),
+ case check_dbname(Server, DbNameList) of
+ ok ->
+ FullFilepath = get_full_filename(Server, DbNameList),
+ Server2 =
+ case ets:lookup(couch_dbs, DbName) of
+ [] -> Server;
+ [#db{main_pid=Pid, compactor_pid=Froms}] when is_list(Froms) ->
+ % icky hack of field values - compactor_pid used to store clients
+ true = ets:delete(couch_dbs, DbName),
+ true = ets:delete(couch_lru, DbName),
+ exit(Pid, kill),
+ [gen_server:reply(F, not_found) || F <- Froms],
+ Server#server{dbs_open=Server#server.dbs_open - 1};
+ [#db{main_pid=Pid}] ->
+ true = ets:delete(couch_dbs, DbName),
+ true = ets:delete(couch_lru, DbName),
+ exit(Pid, kill),
+ Server#server{dbs_open=Server#server.dbs_open - 1}
+ end,
+
+ %% Delete any leftover .compact files. If we don't do this a subsequent
+ %% request for this DB will try to open the .compact file and use it.
+ couch_file:delete(Server#server.root_dir, FullFilepath ++ ".compact"),
+
+ case couch_file:delete(Server#server.root_dir, FullFilepath) of
+ ok ->
+ couch_db_update_notifier:notify({deleted, DbName}),
+ {reply, ok, Server2};
+ {error, enoent} ->
+ {reply, not_found, Server2};
+ Else ->
+ {reply, Else, Server2}
+ end;
+ Error ->
+ {reply, Error, Server}
+ end;
+handle_call({db_updated, #db{name = DbName} = Db}, _From, Server) ->
+ true = ets:insert(couch_dbs, Db),
+ true = ets:insert(couch_lru, {DbName, now()}),
+ {reply, ok, Server}.
+
+
+handle_cast(Msg, Server) ->
+ {stop, {unknown_cast_message, Msg}, Server}.
+
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+
+handle_info({'EXIT', _Pid, config_change}, Server) ->
+ {stop, config_change, Server};
+handle_info({'EXIT', Pid, Reason}, #server{dbs_open=DbsOpen}=Server) ->
+ case ets:match_object(couch_dbs, #db{main_pid=Pid, _='_'}) of
+ [#db{name = DbName, compactor_pid=Froms}] ->
+ ?LOG_INFO("db ~s died with reason ~p", [DbName, Reason]),
+ % icky hack of field values - compactor_pid used to store clients
+ if is_list(Froms) ->
+ [gen_server:reply(From, Reason) || From <- Froms];
+ true ->
+ ok
+ end,
+ true = ets:delete(couch_dbs, DbName),
+ true = ets:delete(couch_lru, DbName),
+ {noreply, Server#server{dbs_open=DbsOpen - 1}};
+ [] ->
+ {noreply, Server}
+ end;
+handle_info(Info, Server) ->
+ {stop, {unknown_message, Info}, Server}.
diff --git a/src/couchdb/couch_server_sup.erl b/apps/couch/src/couch_server_sup.erl
index fafd83ed..bc1e6036 100644
--- a/src/couchdb/couch_server_sup.erl
+++ b/apps/couch/src/couch_server_sup.erl
@@ -14,9 +14,8 @@
-behaviour(supervisor).
--export([start_link/1,stop/0, couch_config_start_link_wrapper/2,
- start_primary_services/0,start_secondary_services/0,
- restart_core_server/0]).
+-export([start_link/1, couch_config_start_link_wrapper/2,
+ restart_core_server/0, config_change/2]).
-include("couch_db.hrl").
@@ -57,7 +56,7 @@ start_server(IniFiles) ->
LogLevel = couch_config:get("log", "level", "info"),
% announce startup
io:format("Apache CouchDB ~s (LogLevel=~s) is starting.~n", [
- couch_server:get_version(),
+ couch:version(),
LogLevel
]),
case LogLevel of
@@ -68,53 +67,39 @@ start_server(IniFiles) ->
_ -> ok
end,
- LibDir =
- case couch_config:get("couchdb", "util_driver_dir", null) of
- null ->
- filename:join(couch_util:priv_dir(), "lib");
- LibDir0 -> LibDir0
- end,
-
- ok = couch_util:start_driver(LibDir),
-
BaseChildSpecs =
- {{one_for_all, 10, 3600},
+ {{one_for_all, 10, 60},
[{couch_config,
{couch_server_sup, couch_config_start_link_wrapper, [IniFiles, ConfigPid]},
permanent,
brutal_kill,
worker,
[couch_config]},
+ {couch_config_event,
+ {couch_config_event, start_link, []},
+ permanent,
+ 1000,
+ worker,
+ dynamic},
{couch_primary_services,
- {couch_server_sup, start_primary_services, []},
+ {couch_primary_sup, start_link, []},
permanent,
infinity,
supervisor,
- [couch_server_sup]},
+ [couch_primary_sup]},
{couch_secondary_services,
- {couch_server_sup, start_secondary_services, []},
+ {couch_secondary_sup, start_link, []},
permanent,
infinity,
supervisor,
- [couch_server_sup]}
+ [couch_secondary_sup]}
]},
- % ensure these applications are running
- application:start(ibrowse),
- application:start(crypto),
-
{ok, Pid} = supervisor:start_link(
{local, couch_server_sup}, couch_server_sup, BaseChildSpecs),
- % launch the icu bridge
% just restart if one of the config settings change.
-
- couch_config:register(
- fun("couchdb", "util_driver_dir") ->
- ?MODULE:stop();
- ("daemons", _) ->
- ?MODULE:stop()
- end, Pid),
+ couch_config:register(fun ?MODULE:config_change/2, Pid),
unlink(ConfigPid),
@@ -140,62 +125,12 @@ start_server(IniFiles) ->
{ok, Pid}.
-start_primary_services() ->
- supervisor:start_link({local, couch_primary_services}, couch_server_sup,
- {{one_for_one, 10, 3600},
- [{couch_log,
- {couch_log, start_link, []},
- permanent,
- brutal_kill,
- worker,
- [couch_log]},
- {couch_replication_supervisor,
- {couch_rep_sup, start_link, []},
- permanent,
- infinity,
- supervisor,
- [couch_rep_sup]},
- {couch_task_status,
- {couch_task_status, start_link, []},
- permanent,
- brutal_kill,
- worker,
- [couch_task_status]},
- {couch_server,
- {couch_server, sup_start_link, []},
- permanent,
- 1000,
- worker,
- [couch_server]},
- {couch_db_update_event,
- {gen_event, start_link, [{local, couch_db_update}]},
- permanent,
- brutal_kill,
- worker,
- dynamic}
- ]
- }).
-
-start_secondary_services() ->
- DaemonChildSpecs = [
- begin
- {ok, {Module, Fun, Args}} = couch_util:parse_term(SpecStr),
-
- {list_to_atom(Name),
- {Module, Fun, Args},
- permanent,
- 1000,
- worker,
- [Module]}
- end
- || {Name, SpecStr}
- <- couch_config:get("daemons"), SpecStr /= ""],
-
- supervisor:start_link({local, couch_secondary_services}, couch_server_sup,
- {{one_for_one, 10, 3600}, DaemonChildSpecs}).
-
-stop() ->
- catch exit(whereis(couch_server_sup), normal).
+config_change("daemons", _) ->
+ exit(whereis(couch_server_sup), shutdown);
+config_change("couchdb", "util_driver_dir") ->
+ [Pid] = [P || {collation_driver,P,_,_}
+ <- supervisor:which_children(couch_primary_services)],
+ Pid ! reload_driver.
init(ChildSpecs) ->
{ok, ChildSpecs}.
diff --git a/src/couchdb/couch_stats_aggregator.erl b/apps/couch/src/couch_stats_aggregator.erl
index 6090355d..7dac1124 100644
--- a/src/couchdb/couch_stats_aggregator.erl
+++ b/apps/couch/src/couch_stats_aggregator.erl
@@ -94,7 +94,12 @@ init(StatDescsFileName) ->
ets:new(?MODULE, [named_table, set, protected]),
SampleStr = couch_config:get("stats", "samples", "[0]"),
{ok, Samples} = couch_util:parse_term(SampleStr),
- {ok, Descs} = file:consult(StatDescsFileName),
+ case file:consult(StatDescsFileName) of
+ {ok, Descs} ->
+ ok;
+ {error, _} ->
+ Descs = []
+ end,
lists:foreach(fun({Sect, Key, Value}) ->
lists:foreach(fun(Secs) ->
Agg = #aggregate{
diff --git a/src/couchdb/couch_stats_collector.erl b/apps/couch/src/couch_stats_collector.erl
index f7b9bb48..74238fc8 100644
--- a/src/couchdb/couch_stats_collector.erl
+++ b/apps/couch/src/couch_stats_collector.erl
@@ -85,21 +85,12 @@ track_process_count(Stat) ->
track_process_count(self(), Stat).
track_process_count(Pid, Stat) ->
- MonitorFun = fun() ->
- Ref = erlang:monitor(process, Pid),
- receive {'DOWN', Ref, _, _, _} -> ok end,
- couch_stats_collector:decrement(Stat)
- end,
- case (catch couch_stats_collector:increment(Stat)) of
- ok -> spawn(MonitorFun);
- _ -> ok
- end.
-
+ gen_server:cast(?MODULE, {track_process_count, Stat, Pid}).
init(_) ->
ets:new(?HIT_TABLE, [named_table, set, public]),
ets:new(?ABS_TABLE, [named_table, duplicate_bag, public]),
- {ok, nil}.
+ {ok, []}.
terminate(_Reason, _State) ->
ok.
@@ -107,11 +98,15 @@ terminate(_Reason, _State) ->
handle_call(stop, _, State) ->
{stop, normal, stopped, State}.
-handle_cast(foo, State) ->
- {noreply, State}.
+handle_cast({track_process_count, Stat, Pid}, State) ->
+ ok = couch_stats_collector:increment(Stat),
+ Ref = erlang:monitor(process, Pid),
+ {noreply, [{Ref,Stat} | State]}.
-handle_info(_Info, State) ->
- {noreply, State}.
+handle_info({'DOWN', Ref, _, _, _}, State) ->
+ {Ref, Stat} = lists:keyfind(Ref, 1, State),
+ ok = couch_stats_collector:decrement(Stat),
+ {noreply, lists:keydelete(Ref, 1, State)}.
code_change(_OldVersion, State, _Extra) ->
{ok, State}.
diff --git a/src/couchdb/couch_stream.erl b/apps/couch/src/couch_stream.erl
index 60af1c2b..60af1c2b 100644
--- a/src/couchdb/couch_stream.erl
+++ b/apps/couch/src/couch_stream.erl
diff --git a/src/couchdb/couch_task_status.erl b/apps/couch/src/couch_task_status.erl
index c4487dc4..639515c7 100644
--- a/src/couchdb/couch_task_status.erl
+++ b/apps/couch/src/couch_task_status.erl
@@ -107,7 +107,6 @@ handle_call(all, _, Server) ->
handle_cast({update_status, Pid, StatusText}, Server) ->
[{Pid, {Type, TaskName, _StatusText}}] = ets:lookup(?MODULE, Pid),
- ?LOG_DEBUG("New task status for ~s: ~s",[TaskName, StatusText]),
true = ets:insert(?MODULE, {Pid, {Type, TaskName, StatusText}}),
{noreply, Server};
handle_cast(stop, State) ->
diff --git a/src/couchdb/couch_util.erl b/apps/couch/src/couch_util.erl
index 53dfe5e3..839f5956 100644
--- a/src/couchdb/couch_util.erl
+++ b/apps/couch/src/couch_util.erl
@@ -189,8 +189,8 @@ json_apply_field({Key, NewValue}, [{OtherKey, OtherVal} | Headers], Acc) ->
json_apply_field({Key, NewValue}, [], Acc) ->
{[{Key, NewValue}|Acc]}.
-json_user_ctx(#db{name=DbName, user_ctx=Ctx}) ->
- {[{<<"db">>, DbName},
+json_user_ctx(#db{name=ShardName, user_ctx=Ctx}) ->
+ {[{<<"db">>, mem3:dbname(ShardName)},
{<<"name">>,Ctx#user_ctx.name},
{<<"roles">>,Ctx#user_ctx.roles}]}.
diff --git a/src/couchdb/couch_uuids.erl b/apps/couch/src/couch_uuids.erl
index e1851e1d..e1851e1d 100644
--- a/src/couchdb/couch_uuids.erl
+++ b/apps/couch/src/couch_uuids.erl
diff --git a/src/couchdb/couch_view.erl b/apps/couch/src/couch_view.erl
index 911f1aa6..2d84b0f9 100644
--- a/src/couchdb/couch_view.erl
+++ b/apps/couch/src/couch_view.erl
@@ -17,7 +17,8 @@
detuple_kvs/2,init/1,terminate/2,handle_call/3,handle_cast/2,handle_info/2,
code_change/3,get_reduce_view/4,get_temp_reduce_view/5,get_temp_map_view/4,
get_map_view/4,get_row_count/1,reduce_to_count/1,fold_reduce/4,
- extract_map_view/1,get_group_server/2,get_group_info/2,cleanup_index_files/1]).
+ extract_map_view/1,get_group_server/2,get_group_info/2,
+ cleanup_index_files/1,config_change/2, data_size/2]).
-include("couch_db.hrl").
@@ -92,13 +93,18 @@ cleanup_index_files(Db) ->
FileList = list_index_files(Db),
+ DeleteFiles =
+ if length(Sigs) =:= 0 ->
+ FileList;
+ true ->
% regex that matches all ddocs
RegExp = "("++ string:join(Sigs, "|") ++")",
% filter out the ones in use
- DeleteFiles = [FilePath
- || FilePath <- FileList,
- re:run(FilePath, RegExp, [{capture, none}]) =:= nomatch],
+ [FilePath || FilePath <- FileList,
+ re:run(FilePath, RegExp, [{capture, none}]) =:= nomatch]
+ end,
+
% delete unused files
?LOG_DEBUG("deleting unused view index files: ~p",[DeleteFiles]),
RootDir = couch_config:get("couchdb", "view_index_dir"),
@@ -112,7 +118,7 @@ list_index_files(Db) ->
get_row_count(#view{btree=Bt}) ->
- {ok, {Count, _Reds}} = couch_btree:full_reduce(Bt),
+ {ok, {Count, _, _}} = couch_btree:full_reduce(Bt),
{ok, Count}.
get_temp_reduce_view(Db, Language, DesignOptions, MapSrc, RedSrc) ->
@@ -160,6 +166,13 @@ expand_dups([{Key, {dups, Vals}} | Rest], Acc) ->
expand_dups([KV | Rest], Acc) ->
expand_dups(Rest, [KV | Acc]).
+data_size(KVList, Reduction) ->
+ lists:foldl(fun([[Key, _], Value], Acc) ->
+ size(term_to_binary(Key)) +
+ size(term_to_binary(Value)) +
+ Acc
+ end,size(term_to_binary(Reduction)),KVList).
+
fold_reduce({temp_reduce, #view{btree=Bt}}, Fun, Acc, Options) ->
WrapperFun = fun({GroupedKey, _}, PartialReds, Acc0) ->
{_, [Red]} = couch_btree:final_reduce(Bt, PartialReds),
@@ -176,7 +189,7 @@ fold_reduce({reduce, NthRed, Lang, #view{btree=Bt, reduce_funs=RedFuns}}, Fun, A
{ok, Reduced} = couch_query_servers:reduce(Lang, [FunSrc], detuple_kvs(expand_dups(KVs, []),[])),
{0, PreResultPadding ++ Reduced ++ PostResultPadding};
(rereduce, Reds) ->
- UserReds = [[lists:nth(NthRed, UserRedsList)] || {_, UserRedsList} <- Reds],
+ UserReds = [[lists:nth(NthRed, element(2, R))] || R <- Reds],
{ok, Reduced} = couch_query_servers:rereduce(Lang, [FunSrc], UserReds),
{0, PreResultPadding ++ Reduced ++ PostResultPadding}
end,
@@ -256,11 +269,7 @@ fold(#view{btree=Btree}, Fun, Acc, Options) ->
init([]) ->
% read configuration settings and register for configuration changes
RootDir = couch_config:get("couchdb", "view_index_dir"),
- Self = self(),
- ok = couch_config:register(
- fun("couchdb", "view_index_dir")->
- exit(Self, config_change)
- end),
+ ok = couch_config:register(fun ?MODULE:config_change/2),
couch_db_update_notifier:start_link(
fun({deleted, DbName}) ->
@@ -337,7 +346,7 @@ do_reset_indexes(DbName, Root) ->
handle_info({'EXIT', FromPid, Reason}, Server) ->
case ets:lookup(couch_groups_by_updater, FromPid) of
[] ->
- if Reason /= normal ->
+ if Reason =/= normal, Reason =/= no_db_file ->
% non-updater linked process died, we propagate the error
?LOG_ERROR("Exit on non-updater process: ~p", [Reason]),
exit(Reason);
@@ -357,6 +366,9 @@ handle_info({'DOWN', _, _, _, {DbName, Sig, Reply}}, Server) ->
_ -> ok end,
{noreply, Server}.
+config_change("couchdb", "view_index_dir") ->
+ exit(whereis(couch_view), config_change).
+
add_to_ets(Pid, DbName, Sig) ->
true = ets:insert(couch_groups_by_updater, {Pid, {DbName, Sig}}),
true = ets:insert(group_servers_by_sig, {{DbName, Sig}, Pid}),
diff --git a/src/couchdb/couch_view_compactor.erl b/apps/couch/src/couch_view_compactor.erl
index 9a47f5f8..38f63f66 100644
--- a/src/couchdb/couch_view_compactor.erl
+++ b/apps/couch/src/couch_view_compactor.erl
@@ -36,15 +36,20 @@ compact_group(Group, EmptyGroup) ->
} = Group,
#group{
- db = Db,
+ dbname = DbName,
+ fd = Fd,
id_btree = EmptyIdBtree,
+ sig = Sig,
views = EmptyViews
} = EmptyGroup,
- {ok, {Count, _}} = couch_btree:full_reduce(Db#db.fulldocinfo_by_id_btree),
+ erlang:monitor(process, Fd),
+
+ {ok, Db} = couch_db:open(DbName, []),
+
+ {ok, Count} = couch_db:get_doc_count(Db),
<<"_design", ShortName/binary>> = GroupId,
- DbName = couch_db:name(Db),
TaskName = <<DbName/binary, ShortName/binary>>,
couch_task_status:add_task(<<"View Group Compaction">>, TaskName, <<"">>),
@@ -76,10 +81,10 @@ compact_group(Group, EmptyGroup) ->
current_seq=Seq
},
- Pid = couch_view:get_group_server(DbName, GroupId),
+ Pid = ets:lookup_element(group_servers_by_sig, {DbName, Sig}, 2),
gen_server:cast(Pid, {compact_done, NewGroup}).
-%% @spec compact_view(View, EmptyView, Retry) -> CompactView
+%% @spec compact_view(View, EmptyView) -> CompactView
compact_view(View, EmptyView) ->
{ok, Count} = couch_view:get_row_count(View),
diff --git a/src/couchdb/couch_view_group.erl b/apps/couch/src/couch_view_group.erl
index 6ef1dcb4..e6fac237 100644
--- a/src/couchdb/couch_view_group.erl
+++ b/apps/couch/src/couch_view_group.erl
@@ -39,8 +39,7 @@
request_group(Pid, Seq) ->
?LOG_DEBUG("request_group {Pid, Seq} ~p", [{Pid, Seq}]),
case gen_server:call(Pid, {request_group, Seq}, infinity) of
- {ok, Group, RefCounter} ->
- couch_ref_counter:add(RefCounter),
+ {ok, Group, _RefCounter} ->
{ok, Group};
Error ->
?LOG_DEBUG("request_group Error ~p", [Error]),
@@ -77,28 +76,25 @@ start_link(InitArgs) ->
% init creates a closure which spawns the appropriate view_updater.
init({{_, DbName, _} = InitArgs, ReturnPid, Ref}) ->
process_flag(trap_exit, true),
- try prepare_group(InitArgs, false) of
- {ok, #group{db=Db, fd=Fd, current_seq=Seq}=Group} ->
+ case prepare_group(InitArgs, false) of
+ {ok, #group{fd=Fd, current_seq=Seq}=Group} ->
+ {ok, Db} = couch_db:open(DbName, []),
case Seq > couch_db:get_update_seq(Db) of
true ->
ReturnPid ! {Ref, self(), {error, invalid_view_seq}},
+ couch_db:close(Db),
ignore;
_ ->
- couch_db:monitor(Db),
- couch_db:close(Db),
- {ok, RefCounter} = couch_ref_counter:start([Fd]),
+ try couch_db:monitor(Db) after couch_db:close(Db) end,
{ok, #group_state{
db_name=DbName,
init_args=InitArgs,
- group=Group#group{db=nil},
- ref_counter=RefCounter}}
+ group=Group#group{dbname=DbName},
+ ref_counter=erlang:monitor(process,Fd)}}
end;
Error ->
ReturnPid ! {Ref, self(), Error},
ignore
- catch exit:no_db_file ->
- ReturnPid ! {Ref, self(), {error, no_db_file}},
- ignore
end.
@@ -119,19 +115,16 @@ init({{_, DbName, _} = InitArgs, ReturnPid, Ref}) ->
handle_call({request_group, RequestSeq}, From,
#group_state{
- db_name=DbName,
group=#group{current_seq=Seq}=Group,
updater_pid=nil,
waiting_list=WaitList
}=State) when RequestSeq > Seq ->
- {ok, Db} = couch_db:open_int(DbName, []),
- Group2 = Group#group{db=Db},
Owner = self(),
- Pid = spawn_link(fun()-> couch_view_updater:update(Owner, Group2) end),
+ Pid = spawn_link(fun()-> couch_view_updater:update(Owner, Group) end),
{noreply, State#group_state{
updater_pid=Pid,
- group=Group2,
+ group=Group,
waiting_list=[{From,RequestSeq}|WaitList]
}, infinity};
@@ -152,6 +145,10 @@ handle_call({request_group, RequestSeq}, From,
waiting_list=[{From, RequestSeq}|WaitList]
}, infinity};
+handle_call({start_compact, CompactFun}, _From, State) ->
+ {noreply, NewState} = handle_cast({start_compact, CompactFun}, State),
+ {reply, {ok, NewState#group_state.compactor_pid}, NewState};
+
handle_call(request_group_info, _From, State) ->
GroupInfo = get_group_info(State),
{reply, {ok, GroupInfo}, State}.
@@ -159,24 +156,23 @@ handle_call(request_group_info, _From, State) ->
handle_cast({start_compact, CompactFun}, #group_state{compactor_pid=nil}
= State) ->
#group_state{
- group = #group{name = GroupId, sig = GroupSig} = Group,
- init_args = {RootDir, DbName, _}
+ group = #group{dbname = DbName, name = GroupId, sig = GroupSig} = Group,
+ init_args = {RootDir, _, _}
} = State,
?LOG_INFO("View index compaction starting for ~s ~s", [DbName, GroupId]),
- {ok, Db} = couch_db:open_int(DbName, []),
{ok, Fd} = open_index_file(compact, RootDir, DbName, GroupSig),
- NewGroup = reset_file(Db, Fd, DbName, Group),
+ NewGroup = reset_file(Fd, DbName, Group),
Pid = spawn_link(fun() -> CompactFun(Group, NewGroup) end),
{noreply, State#group_state{compactor_pid = Pid}};
handle_cast({start_compact, _}, State) ->
%% compact already running, this is a no-op
{noreply, State};
-handle_cast({compact_done, #group{current_seq=NewSeq} = NewGroup},
+handle_cast({compact_done, #group{fd=NewFd, current_seq=NewSeq} = NewGroup},
#group_state{group = #group{current_seq=OldSeq}} = State)
when NewSeq >= OldSeq ->
#group_state{
- group = #group{name=GroupId, fd=OldFd, sig=GroupSig} = Group,
+ group = #group{name=GroupId, fd=OldFd, sig=GroupSig},
init_args = {RootDir, DbName, _},
updater_pid = UpdaterPid,
compactor_pid = CompactorPid,
@@ -204,22 +200,12 @@ handle_cast({compact_done, #group{current_seq=NewSeq} = NewGroup},
unlink(CompactorPid),
receive {'EXIT', CompactorPid, normal} -> ok after 0 -> ok end,
unlink(OldFd),
- couch_ref_counter:drop(RefCounter),
- {ok, NewRefCounter} = couch_ref_counter:start([NewGroup#group.fd]),
- case Group#group.db of
- nil -> ok;
- Else -> couch_db:close(Else)
- end,
-
- case NewGroup#group.db of
- nil -> ok;
- _ -> couch_db:close(NewGroup#group.db)
- end,
+ erlang:demonitor(RefCounter),
self() ! delayed_commit,
{noreply, State#group_state{
- group=NewGroup#group{db = nil},
- ref_counter=NewRefCounter,
+ group=NewGroup,
+ ref_counter=erlang:monitor(process,NewFd),
compactor_pid=nil,
updater_pid=NewUpdaterPid
}};
@@ -230,18 +216,14 @@ handle_cast({compact_done, NewGroup}, State) ->
} = State,
?LOG_INFO("View index compaction still behind for ~s ~s -- current: ~p " ++
"compact: ~p", [DbName, GroupId, CurrentSeq, NewGroup#group.current_seq]),
- couch_db:close(NewGroup#group.db),
+ GroupServer = self(),
Pid = spawn_link(fun() ->
- {ok, Db} = couch_db:open_int(DbName, []),
+ erlang:monitor(process, NewGroup#group.fd),
{_,Ref} = erlang:spawn_monitor(fun() ->
- couch_view_updater:update(nil, NewGroup#group{db = Db})
+ couch_view_updater:update(nil, NewGroup)
end),
- receive
- {'DOWN', Ref, _, _, {new_group, NewGroup2}} ->
- couch_db:close(Db),
- #group{name=GroupId} = NewGroup2,
- Pid2 = couch_view:get_group_server(DbName, GroupId),
- gen_server:cast(Pid2, {compact_done, NewGroup2#group{db = nil}})
+ receive {'DOWN', Ref, _, _, {new_group, NewGroup2}} ->
+ gen_server:cast(GroupServer, {compact_done, NewGroup2})
end
end),
{noreply, State#group_state{compactor_pid = Pid}};
@@ -253,7 +235,7 @@ handle_cast({partial_update, Pid, NewGroup}, #group_state{updater_pid=Pid}
waiting_commit = WaitingCommit
} = State,
NewSeq = NewGroup#group.current_seq,
- ?LOG_INFO("checkpointing view update at seq ~p for ~s ~s", [NewSeq,
+ ?LOG_DEBUG("checkpointing view update at seq ~p for ~s ~s", [NewSeq,
DbName, NewGroup#group.name]),
if not WaitingCommit ->
erlang:send_after(1000, self(), delayed_commit);
@@ -283,13 +265,12 @@ handle_info(delayed_commit, #group_state{db_name=DbName,group=Group}=State) ->
{noreply, State#group_state{waiting_commit=true}}
end;
-handle_info({'EXIT', FromPid, {new_group, #group{db=Db}=Group}},
- #group_state{db_name=DbName,
+handle_info({'EXIT', FromPid, {new_group, Group}},
+ #group_state{
updater_pid=UpPid,
ref_counter=RefCounter,
waiting_list=WaitList,
waiting_commit=WaitingCommit}=State) when UpPid == FromPid ->
- ok = couch_db:close(Db),
if not WaitingCommit ->
erlang:send_after(1000, self(), delayed_commit);
true -> ok
@@ -297,26 +278,20 @@ handle_info({'EXIT', FromPid, {new_group, #group{db=Db}=Group}},
case reply_with_group(Group, WaitList, [], RefCounter) of
[] ->
{noreply, State#group_state{waiting_commit=true, waiting_list=[],
- group=Group#group{db=nil}, updater_pid=nil}};
+ group=Group, updater_pid=nil}};
StillWaiting ->
- % we still have some waiters, reopen the database and reupdate the index
- {ok, Db2} = couch_db:open_int(DbName, []),
- Group2 = Group#group{db=Db2},
+ % we still have some waiters, reupdate the index
Owner = self(),
- Pid = spawn_link(fun() -> couch_view_updater:update(Owner, Group2) end),
+ Pid = spawn_link(fun() -> couch_view_updater:update(Owner, Group) end),
{noreply, State#group_state{waiting_commit=true,
- waiting_list=StillWaiting, group=Group2, updater_pid=Pid}}
+ waiting_list=StillWaiting, group=Group, updater_pid=Pid}}
end;
handle_info({'EXIT', _, {new_group, _}}, State) ->
%% message from an old (probably pre-compaction) updater; ignore
{noreply, State};
-handle_info({'EXIT', FromPid, reset},
- #group_state{
- init_args=InitArgs,
- updater_pid=UpPid,
- group=Group}=State) when UpPid == FromPid ->
- ok = couch_db:close(Group#group.db),
+handle_info({'EXIT', FromPid, reset}, #group_state{init_args=InitArgs,
+ updater_pid=FromPid}=State) ->
case prepare_group(InitArgs, true) of
{ok, ResetGroup} ->
Owner = self(),
@@ -342,8 +317,9 @@ handle_info({'EXIT', FromPid, Reason}, State) ->
?LOG_DEBUG("Exit from linked pid: ~p", [{FromPid, Reason}]),
{stop, Reason, State};
-handle_info({'DOWN',_,_,_,_}, State) ->
- ?LOG_INFO("Shutting down view group server, monitored db is closing.", []),
+handle_info({'DOWN',_,_,Pid,Reason}, #group_state{group=G}=State) ->
+ ?LOG_INFO("Shutting down group server ~p, db ~p closing w/ reason~n~p",
+ [G#group.name, Pid, Reason]),
{stop, normal, reply_all(State, shutdown)}.
@@ -379,32 +355,29 @@ reply_all(#group_state{waiting_list=WaitList}=State, Reply) ->
[catch gen_server:reply(Pid, Reply) || {Pid, _} <- WaitList],
State#group_state{waiting_list=[]}.
+prepare_group({Root, DbName, #group{dbname=X}=G}, Reset) when X =/= DbName ->
+ prepare_group({Root, DbName, G#group{dbname=DbName}}, Reset);
prepare_group({RootDir, DbName, #group{sig=Sig}=Group}, ForceReset)->
- case couch_db:open_int(DbName, []) of
- {ok, Db} ->
- case open_index_file(RootDir, DbName, Sig) of
- {ok, Fd} ->
- if ForceReset ->
- % this can happen if we missed a purge
- {ok, reset_file(Db, Fd, DbName, Group)};
- true ->
- % 09 UPGRADE CODE
- ok = couch_file:upgrade_old_header(Fd, <<$r, $c, $k, 0>>),
- case (catch couch_file:read_header(Fd)) of
- {ok, {Sig, HeaderInfo}} ->
- % sigs match!
- {ok, init_group(Db, Fd, Group, HeaderInfo)};
- _ ->
- % this happens on a new file
- {ok, reset_file(Db, Fd, DbName, Group)}
- end
- end;
- Error ->
- catch delete_index_file(RootDir, DbName, Sig),
- Error
+ case open_index_file(RootDir, DbName, Sig) of
+ {ok, Fd} ->
+ if ForceReset ->
+ % this can happen if we missed a purge
+ {ok, reset_file(Fd, DbName, Group)};
+ true ->
+ % 09 UPGRADE CODE
+ ok = couch_file:upgrade_old_header(Fd, <<$r, $c, $k, 0>>),
+ case (catch couch_file:read_header(Fd)) of
+ {ok, {Sig, HeaderInfo}} ->
+ % sigs match!
+ {ok, init_group(Fd, Group, HeaderInfo)};
+ _ ->
+ % this happens on a new file
+ {ok, reset_file(Fd, DbName, Group)}
+ end
end;
- Else ->
- Else
+ Error ->
+ catch delete_index_file(RootDir, DbName, Sig),
+ Error
end.
get_index_header_data(#group{current_seq=Seq, purge_seq=PurgeSeq,
@@ -502,18 +475,18 @@ sort_lib([{LName, LCode}|Rest], LAcc) ->
sort_lib(Rest, [{LName, LCode}|LAcc]).
open_db_group(DbName, GroupId) ->
- case couch_db:open_int(DbName, []) of
- {ok, Db} ->
- case couch_db:open_doc(Db, GroupId) of
- {ok, Doc} ->
- couch_db:close(Db),
- {ok, design_doc_to_view_group(Doc)};
- Else ->
- couch_db:close(Db),
- Else
- end;
- Else ->
- Else
+ {Pid, Ref} = spawn_monitor(fun() ->
+ exit(try
+ fabric:open_doc(mem3:dbname(DbName), GroupId, [])
+ catch error:database_does_not_exist ->
+ {ok, Db} = couch_db:open(DbName, []),
+ couch_db:open_doc(Db, GroupId)
+ end)
+ end),
+ receive {'DOWN', Ref, process, Pid, {ok, Doc}} ->
+ {ok, design_doc_to_view_group(Doc)};
+ {'DOWN', Ref, process, Pid, Error} ->
+ Error
end.
get_group_info(State) ->
@@ -528,6 +501,7 @@ get_group_info(State) ->
fd = Fd,
sig = GroupSig,
def_lang = Lang,
+ views = Views,
current_seq=CurrentSeq,
purge_seq=PurgeSeq
} = Group,
@@ -536,6 +510,7 @@ get_group_info(State) ->
{signature, ?l2b(hex_sig(GroupSig))},
{language, Lang},
{disk_size, Size},
+ {data_size, compute_data_size(Views)},
{updater_running, UpdaterPid /= nil},
{compact_running, CompactorPid /= nil},
{waiting_commit, WaitingCommit},
@@ -544,6 +519,13 @@ get_group_info(State) ->
{purge_seq, PurgeSeq}
].
+compute_data_size(ViewList) ->
+ lists:foldl(fun(#view{btree=Btree}, Acc) ->
+ {ok, {_, _, Size}} = couch_btree:full_reduce(Btree),
+ Size + Acc
+ end, 0, ViewList).
+
+
% maybe move to another module
design_doc_to_view_group(#doc{id=Id,body={Fields}}) ->
Language = couch_util:get_value(<<"language">>, Fields, <<"javascript">>),
@@ -580,26 +562,31 @@ design_doc_to_view_group(#doc{id=Id,body={Fields}}) ->
end, 0, lists:sort(dict:to_list(DictBySrc))),
set_view_sig(#group{name=Id, lib=Lib, views=Views, def_lang=Language, design_options=DesignOptions}).
-reset_group(#group{views=Views}=Group) ->
+reset_group(DbName, #group{views=Views}=Group) ->
Views2 = [View#view{btree=nil} || View <- Views],
- Group#group{db=nil,fd=nil,query_server=nil,current_seq=0,
+ Group#group{dbname=DbName,fd=nil,query_server=nil,current_seq=0,
id_btree=nil,views=Views2}.
-reset_file(Db, Fd, DbName, #group{sig=Sig,name=Name} = Group) ->
+reset_file(Fd, DbName, #group{sig=Sig,name=Name} = Group) ->
?LOG_DEBUG("Resetting group index \"~s\" in db ~s", [Name, DbName]),
ok = couch_file:truncate(Fd, 0),
ok = couch_file:write_header(Fd, {Sig, nil}),
- init_group(Db, Fd, reset_group(Group), nil).
+ init_group(Fd, reset_group(DbName, Group), nil).
delete_index_file(RootDir, DbName, GroupSig) ->
couch_file:delete(RootDir, index_file_name(RootDir, DbName, GroupSig)).
-init_group(Db, Fd, #group{views=Views}=Group, nil) ->
- init_group(Db, Fd, Group,
- #index_header{seq=0, purge_seq=couch_db:get_purge_seq(Db),
- id_btree_state=nil, view_states=[{nil, 0, 0} || _ <- Views]});
-init_group(Db, Fd, #group{def_lang=Lang,views=Views}=
- Group, IndexHeader) ->
+init_group(Fd, #group{dbname=DbName, views=Views}=Group, nil) ->
+ case couch_db:open(DbName, []) of
+ {ok, Db} ->
+ PurgeSeq = try couch_db:get_purge_seq(Db) after couch_db:close(Db) end,
+ Header = #index_header{purge_seq=PurgeSeq, view_states=[{nil, 0, 0} || _ <- Views]},
+ init_group(Fd, Group, Header);
+ {not_found, no_db_file} ->
+ ?LOG_ERROR("~p no_db_file ~p", [?MODULE, DbName]),
+ exit(no_db_file)
+ end;
+init_group(Fd, #group{def_lang=Lang,views=Views}=Group, IndexHeader) ->
#index_header{seq=Seq, purge_seq=PurgeSeq,
id_btree_state=IdBtreeState, view_states=ViewStates} = IndexHeader,
StateUpdate = fun
@@ -617,13 +604,14 @@ init_group(Db, Fd, #group{def_lang=Lang,views=Views}=
KVs3 = couch_view:detuple_kvs(KVs2,[]),
{ok, Reduced} = couch_query_servers:reduce(Lang, FunSrcs,
KVs3),
- {length(KVs3), Reduced};
+ {length(KVs3), Reduced, couch_view:data_size(KVs3, Reduced)};
(rereduce, Reds) ->
- Count = lists:sum([Count0 || {Count0, _} <- Reds]),
- UserReds = [UserRedsList || {_, UserRedsList} <- Reds],
+ Count = lists:sum(extract(Reds, counts)),
+ DataSize = lists:sum(extract(Reds, data_size)),
+ UserReds = extract(Reds, user_reds),
{ok, Reduced} = couch_query_servers:rereduce(Lang, FunSrcs,
UserReds),
- {Count, Reduced}
+ {Count, Reduced, DataSize}
end,
case couch_util:get_value(<<"collation">>, Options, <<"default">>) of
@@ -638,5 +626,12 @@ init_group(Db, Fd, #group{def_lang=Lang,views=Views}=
View#view{btree=Btree, update_seq=USeq, purge_seq=PSeq}
end,
ViewStates2, Views),
- Group#group{db=Db, fd=Fd, current_seq=Seq, purge_seq=PurgeSeq,
- id_btree=IdBtree, views=Views2}.
+ Group#group{fd=Fd, current_seq=Seq, purge_seq=PurgeSeq, id_btree=IdBtree,
+ views=Views2}.
+
+extract(Reds, counts) ->
+ [element(1, R) || R <- Reds];
+extract(Reds, user_reds) ->
+ [element(2, R) || R <- Reds];
+extract(Reds, data_size) ->
+ lists:map(fun({_, _}) -> 0; ({_, _, Size}) -> Size end, Reds).
diff --git a/src/couchdb/couch_view_updater.erl b/apps/couch/src/couch_view_updater.erl
index 8e089fa9..90cb20d4 100644
--- a/src/couchdb/couch_view_updater.erl
+++ b/apps/couch/src/couch_view_updater.erl
@@ -12,7 +12,7 @@
-module(couch_view_updater).
--export([update/2]).
+-export([update/2, do_maps/4, do_writes/5, load_docs/3]).
-include("couch_db.hrl").
@@ -20,20 +20,21 @@
update(Owner, Group) ->
#group{
- db = #db{name=DbName} = Db,
+ dbname = DbName,
name = GroupName,
current_seq = Seq,
purge_seq = PurgeSeq
} = Group,
couch_task_status:add_task(<<"View Group Indexer">>, <<DbName/binary," ",GroupName/binary>>, <<"Starting index update">>),
+ {ok, Db} = couch_db:open(DbName, []),
DbPurgeSeq = couch_db:get_purge_seq(Db),
Group2 =
if DbPurgeSeq == PurgeSeq ->
Group;
DbPurgeSeq == PurgeSeq + 1 ->
couch_task_status:update(<<"Removing purged entries from view index.">>),
- purge_index(Group);
+ purge_index(Db, Group);
true ->
couch_task_status:update(<<"Resetting view index due to lost purge entries.">>),
exit(reset)
@@ -44,8 +45,8 @@ update(Owner, Group) ->
[{max_size, 100000}, {max_items, 500}]),
Self = self(),
ViewEmptyKVs = [{View, []} || View <- Group2#group.views],
- spawn_link(fun() -> do_maps(Group, MapQueue, WriteQueue, ViewEmptyKVs) end),
- spawn_link(fun() -> do_writes(Self, Owner, Group2, WriteQueue, Seq == 0) end),
+ spawn_link(?MODULE, do_maps, [Group, MapQueue, WriteQueue, ViewEmptyKVs]),
+ spawn_link(?MODULE, do_writes, [Self, Owner, Group2, WriteQueue, Seq == 0]),
% compute on all docs modified since we last computed.
TotalChanges = couch_db:count_changes_since(Db, Seq),
% update status every half second
@@ -59,17 +60,9 @@ update(Owner, Group) ->
true -> [conflicts, deleted_conflicts, local_seq];
_ -> [conflicts, deleted_conflicts]
end,
- {ok, _, _}
- = couch_db:enum_docs_since(
- Db,
- Seq,
- fun(DocInfo, _, ChangesProcessed) ->
- couch_task_status:update("Processed ~p of ~p changes (~p%)",
- [ChangesProcessed, TotalChanges, (ChangesProcessed*100) div TotalChanges]),
- load_doc(Db, DocInfo, MapQueue, DocOpts, IncludeDesign),
- {ok, ChangesProcessed+1}
- end,
- 0, []),
+ EnumFun = fun ?MODULE:load_docs/3,
+ Acc0 = {0, Db, MapQueue, DocOpts, IncludeDesign, TotalChanges},
+ {ok, _, _} = couch_db:enum_docs_since(Db, Seq, EnumFun, Acc0, []),
couch_task_status:set_update_frequency(0),
couch_task_status:update("Finishing."),
couch_work_queue:close(MapQueue),
@@ -78,8 +71,13 @@ update(Owner, Group) ->
NewGroup#group{current_seq=couch_db:get_update_seq(Db)}})
end.
+load_docs(DocInfo, _, {I, Db, MapQueue, DocOpts, IncludeDesign, Total} = Acc) ->
+ couch_task_status:update("Processed ~p of ~p changes (~p%)", [I, Total,
+ (I*100) div Total]),
+ load_doc(Db, DocInfo, MapQueue, DocOpts, IncludeDesign),
+ {ok, setelement(1, Acc, I+1)}.
-purge_index(#group{db=Db, views=Views, id_btree=IdBtree}=Group) ->
+purge_index(Db, #group{views=Views, id_btree=IdBtree}=Group) ->
{ok, PurgedIdsRevs} = couch_db:get_last_purged(Db),
Ids = [Id || {Id, _Revs} <- PurgedIdsRevs],
{ok, Lookups, IdBtree2} = couch_btree:query_modify(IdBtree, Ids, [], Ids),
@@ -116,9 +114,14 @@ purge_index(#group{db=Db, views=Views, id_btree=IdBtree}=Group) ->
views=Views2,
purge_seq=PurgeSeq}.
-
-load_doc(Db, DocInfo, MapQueue, DocOpts, IncludeDesign) ->
- #doc_info{id=DocId, high_seq=Seq, revs=[#rev_info{deleted=Deleted}|_]} = DocInfo,
+-spec load_doc(#db{}, #doc_info{}, pid(), [atom()], boolean()) -> ok.
+load_doc(Db, DI, MapQueue, DocOpts, IncludeDesign) ->
+ DocInfo = case DI of
+ #full_doc_info{id=DocId, update_seq=Seq, deleted=Deleted} ->
+ couch_doc:to_doc_info(DI);
+ #doc_info{id=DocId, high_seq=Seq, revs=[#rev_info{deleted=Deleted}|_]} ->
+ DI
+ end,
case {IncludeDesign, DocId} of
{false, <<?DESIGN_DOC_PREFIX, _/binary>>} -> % we skip design docs
ok;
@@ -130,7 +133,8 @@ load_doc(Db, DocInfo, MapQueue, DocOpts, IncludeDesign) ->
couch_work_queue:queue(MapQueue, {Seq, Doc})
end
end.
-
+
+-spec do_maps(#group{}, pid(), pid(), any()) -> any().
do_maps(Group, MapQueue, WriteQueue, ViewEmptyKVs) ->
case couch_work_queue:dequeue(MapQueue) of
closed ->
@@ -144,35 +148,55 @@ do_maps(Group, MapQueue, WriteQueue, ViewEmptyKVs) ->
{ViewKVs, DocIdViewIdKeys} = view_insert_query_results(Docs,
Results, ViewEmptyKVs, DelKVs),
couch_work_queue:queue(WriteQueue, {LastSeq, ViewKVs, DocIdViewIdKeys}),
- do_maps(Group1, MapQueue, WriteQueue, ViewEmptyKVs)
+ ?MODULE:do_maps(Group1, MapQueue, WriteQueue, ViewEmptyKVs)
end.
+-spec do_writes(pid(), pid() | nil, #group{}, pid(), boolean()) -> any().
do_writes(Parent, Owner, Group, WriteQueue, InitialBuild) ->
- case couch_work_queue:dequeue(WriteQueue) of
- closed ->
+ case accumulate_writes(WriteQueue, couch_work_queue:dequeue(WriteQueue), nil) of
+ stop ->
Parent ! {new_group, Group};
- {ok, Queue} ->
- {NewSeq, ViewKeyValues, DocIdViewIdKeys} = lists:foldl(
- fun({Seq, ViewKVs, DocIdViewIdKeys}, nil) ->
- {Seq, ViewKVs, DocIdViewIdKeys};
- ({Seq, ViewKVs, DocIdViewIdKeys}, Acc) ->
- {Seq2, AccViewKVs, AccDocIdViewIdKeys} = Acc,
- AccViewKVs2 = lists:zipwith(
- fun({View, KVsIn}, {_View, KVsAcc}) ->
- {View, KVsIn ++ KVsAcc}
- end, ViewKVs, AccViewKVs),
- {lists:max([Seq, Seq2]),
- AccViewKVs2, DocIdViewIdKeys ++ AccDocIdViewIdKeys}
- end, nil, Queue),
+ {Go, {NewSeq, ViewKeyValues, DocIdViewIdKeys}} ->
Group2 = write_changes(Group, ViewKeyValues, DocIdViewIdKeys, NewSeq,
InitialBuild),
- case Owner of
- nil -> ok;
- _ -> ok = gen_server:cast(Owner, {partial_update, Parent, Group2})
- end,
- do_writes(Parent, Owner, Group2, WriteQueue, InitialBuild)
+ if Go =:= stop ->
+ Parent ! {new_group, Group2};
+ true ->
+ case Owner of
+ nil -> ok;
+ _ -> ok = gen_server:cast(Owner, {partial_update, Parent, Group2})
+ end,
+ ?MODULE:do_writes(Parent, Owner, Group2, WriteQueue, InitialBuild)
+ end
end.
+accumulate_writes(_, closed, nil) ->
+ stop;
+accumulate_writes(_, closed, Acc) ->
+ {stop, Acc};
+accumulate_writes(W, {ok, Queue}, Acc0) ->
+ {_, _, DocIdViewIdKeys} = NewAcc = lists:foldl(
+ fun(First, nil) -> First; ({Seq, ViewKVs, DocIdViewIdKeys}, Acc) ->
+ {Seq2, AccViewKVs, AccDocIdViewIdKeys} = Acc,
+ AccViewKVs2 = lists:zipwith(
+ fun({View, KVsIn}, {_View, KVsAcc}) ->
+ {View, KVsIn ++ KVsAcc}
+ end, ViewKVs, AccViewKVs),
+ {erlang:max(Seq, Seq2), AccViewKVs2,
+ DocIdViewIdKeys ++ AccDocIdViewIdKeys}
+ end, Acc0, Queue),
+ % check if we have enough items now
+ MinItems = couch_config:get("view_updater", "min_writer_items", "100"),
+ MinSize = couch_config:get("view_updater", "min_writer_size", "16777216"),
+ case length(DocIdViewIdKeys) >= list_to_integer(MinItems) orelse
+ process_info(self(), memory) >= list_to_integer(MinSize) of
+ true ->
+ {ok, NewAcc};
+ false ->
+ accumulate_writes(W, couch_work_queue:dequeue(W), NewAcc)
+ end.
+
+-spec view_insert_query_results([#doc{}], list(), any(), any()) -> any().
view_insert_query_results([], [], ViewKVs, DocIdViewIdKeysAcc) ->
{ViewKVs, DocIdViewIdKeysAcc};
view_insert_query_results([Doc|RestDocs], [QueryResults | RestResults], ViewKVs, DocIdViewIdKeysAcc) ->
@@ -180,7 +204,8 @@ view_insert_query_results([Doc|RestDocs], [QueryResults | RestResults], ViewKVs,
NewDocIdViewIdKeys = [{Doc#doc.id, NewViewIdKeys} | DocIdViewIdKeysAcc],
view_insert_query_results(RestDocs, RestResults, NewViewKVs, NewDocIdViewIdKeys).
-
+-spec view_insert_doc_query_results(#doc{}, list(), list(), any(), any()) ->
+ any().
view_insert_doc_query_results(_Doc, [], [], ViewKVsAcc, ViewIdKeysAcc) ->
{lists:reverse(ViewKVsAcc), lists:reverse(ViewIdKeysAcc)};
view_insert_doc_query_results(#doc{id=DocId}=Doc, [ResultKVs|RestResults], [{View, KVs}|RestViewKVs], ViewKVsAcc, ViewIdKeysAcc) ->
@@ -207,6 +232,7 @@ view_insert_doc_query_results(#doc{id=DocId}=Doc, [ResultKVs|RestResults], [{Vie
NewViewIdKeysAcc = NewViewIdKeys ++ ViewIdKeysAcc,
view_insert_doc_query_results(Doc, RestResults, RestViewKVs, NewViewKVsAcc, NewViewIdKeysAcc).
+-spec view_compute(#group{}, [#doc{}]) -> {#group{}, any()}.
view_compute(Group, []) ->
{Group, []};
view_compute(#group{def_lang=DefLang, lib=Lib, query_server=QueryServerIn}=Group, Docs) ->
@@ -222,7 +248,6 @@ view_compute(#group{def_lang=DefLang, lib=Lib, query_server=QueryServerIn}=Group
{Group#group{query_server=QueryServer}, Results}.
-
write_changes(Group, ViewKeyValuesToAdd, DocIdViewIdKeys, NewSeq, InitialBuild) ->
#group{id_btree=IdBtree} = Group,
diff --git a/src/couchdb/couch_work_queue.erl b/apps/couch/src/couch_work_queue.erl
index 13ec7335..13ec7335 100644
--- a/src/couchdb/couch_work_queue.erl
+++ b/apps/couch/src/couch_work_queue.erl
diff --git a/test/etap/test_util.erl.in b/apps/couch/src/test_util.erl
index 460b0293..55b95139 100644
--- a/test/etap/test_util.erl.in
+++ b/apps/couch/src/test_util.erl
@@ -15,28 +15,19 @@
-export([init_code_path/0]).
-export([source_file/1, build_file/1, config_files/0]).
-srcdir() ->
- "@abs_top_srcdir@".
-
-builddir() ->
- "@abs_top_builddir@".
-
init_code_path() ->
- Paths = ["etap", "couchdb", "erlang-oauth", "ibrowse", "mochiweb"],
- lists:foreach(fun(Name) ->
- code:add_patha(filename:join([builddir(), "src", Name]))
- end, Paths).
+ code:load_abs("apps/couch/test/etap/etap").
source_file(Name) ->
- filename:join([srcdir(), Name]).
+ filename:join(["apps/couch", Name]).
build_file(Name) ->
- filename:join([builddir(), Name]).
+ filename:join(["rel/overlay", Name]).
config_files() ->
[
- build_file("etc/couchdb/default_dev.ini"),
- build_file("etc/couchdb/local_dev.ini"),
+ build_file("etc/default.ini"),
+ build_file("etc/local.ini"),
source_file("test/etap/random_port.ini")
].
diff --git a/test/bench/bench_marks.js b/apps/couch/test/bench/bench_marks.js
index 4025adbb..4025adbb 100644
--- a/test/bench/bench_marks.js
+++ b/apps/couch/test/bench/bench_marks.js
diff --git a/test/bench/benchbulk.sh b/apps/couch/test/bench/benchbulk.sh
index 22804c64..22804c64 100755
--- a/test/bench/benchbulk.sh
+++ b/apps/couch/test/bench/benchbulk.sh
diff --git a/test/bench/run.tpl b/apps/couch/test/bench/run.tpl
index 9307863f..9307863f 100755
--- a/test/bench/run.tpl
+++ b/apps/couch/test/bench/run.tpl
diff --git a/test/etap/001-load.t b/apps/couch/test/etap/001-load.t
index 6f49e1ba..73bf66d3 100755
--- a/test/etap/001-load.t
+++ b/apps/couch/test/etap/001-load.t
@@ -60,7 +60,7 @@ main(_) ->
lists:foreach(
fun(Module) ->
- etap_can:loaded_ok(
+ etap:loaded_ok(
Module,
lists:concat(["Loaded: ", Module])
)
diff --git a/test/etap/002-icu-driver.t b/apps/couch/test/etap/002-icu-driver.t
index d70f3303..4167aeeb 100644
--- a/test/etap/002-icu-driver.t
+++ b/apps/couch/test/etap/002-icu-driver.t
@@ -16,7 +16,7 @@ main(_) ->
test_util:init_code_path(),
etap:plan(3),
etap:is(
- couch_util:start_driver("src/couchdb/priv/.libs"),
+ erl_ddll:load(code:priv_dir(couch), "couch_icu_driver"),
ok,
"Started couch_icu_driver."
),
diff --git a/test/etap/010-file-basics.t b/apps/couch/test/etap/010-file-basics.t
index ed71f5e8..ed71f5e8 100755
--- a/test/etap/010-file-basics.t
+++ b/apps/couch/test/etap/010-file-basics.t
diff --git a/test/etap/011-file-headers.t b/apps/couch/test/etap/011-file-headers.t
index 4705f629..4705f629 100755
--- a/test/etap/011-file-headers.t
+++ b/apps/couch/test/etap/011-file-headers.t
diff --git a/test/etap/020-btree-basics.t b/apps/couch/test/etap/020-btree-basics.t
index 18c4a836..996d240a 100755
--- a/test/etap/020-btree-basics.t
+++ b/apps/couch/test/etap/020-btree-basics.t
@@ -21,6 +21,7 @@ rows() -> 250.
main(_) ->
test_util:init_code_path(),
+ couch_config:start_link([]),
etap:plan(48),
case (catch test()) of
ok ->
diff --git a/test/etap/021-btree-reductions.t b/apps/couch/test/etap/021-btree-reductions.t
index 331e49af..6362594e 100755
--- a/test/etap/021-btree-reductions.t
+++ b/apps/couch/test/etap/021-btree-reductions.t
@@ -14,11 +14,12 @@
% License for the specific language governing permissions and limitations under
% the License.
-filename() -> "./test/etap/temp.021".
+filename() -> "./apps/couch/test/etap/temp.021".
rows() -> 1000.
main(_) ->
test_util:init_code_path(),
+ couch_config:start_link([]),
etap:plan(8),
case (catch test()) of
ok ->
diff --git a/test/etap/030-doc-from-json.t b/apps/couch/test/etap/030-doc-from-json.t
index b0c393ef..0a1e6ab3 100755
--- a/test/etap/030-doc-from-json.t
+++ b/apps/couch/test/etap/030-doc-from-json.t
@@ -34,6 +34,7 @@ main(_) ->
test() ->
couch_config:start_link(test_util:config_files()),
+ couch_config_event:start_link(),
couch_config:set("attachments", "compression_level", "0", false),
ok = test_from_json_success(),
ok = test_from_json_errors(),
diff --git a/test/etap/031-doc-to-json.t b/apps/couch/test/etap/031-doc-to-json.t
index ce950f95..6ceae344 100755
--- a/test/etap/031-doc-to-json.t
+++ b/apps/couch/test/etap/031-doc-to-json.t
@@ -34,6 +34,7 @@ main(_) ->
test() ->
couch_config:start_link(test_util:config_files()),
+ couch_config_event:start_link(),
couch_config:set("attachments", "compression_level", "0", false),
ok = test_to_json_success(),
ok.
@@ -115,16 +116,16 @@ test_to_json_success() ->
{
#doc{atts=[
#att{
- name = <<"big.xml">>,
- type = <<"xml/sucks">>,
+ name = <<"big.xml">>,
+ type = <<"xml/sucks">>,
data = fun() -> ok end,
revpos = 1,
att_len = 400,
disk_len = 400
},
#att{
- name = <<"fast.json">>,
- type = <<"json/ftw">>,
+ name = <<"fast.json">>,
+ type = <<"json/ftw">>,
data = <<"{\"so\": \"there!\"}">>,
revpos = 1,
att_len = 16,
@@ -194,4 +195,3 @@ test_to_json_success() ->
etap:is(couch_doc:to_json_obj(Doc, Options), EJson, Mesg)
end, Cases),
ok.
-
diff --git a/test/etap/040-util.t b/apps/couch/test/etap/040-util.t
index 8f80db87..8f80db87 100755
--- a/test/etap/040-util.t
+++ b/apps/couch/test/etap/040-util.t
diff --git a/test/etap/041-uuid-gen-seq.ini b/apps/couch/test/etap/041-uuid-gen-seq.ini
index 94cebc6f..94cebc6f 100644
--- a/test/etap/041-uuid-gen-seq.ini
+++ b/apps/couch/test/etap/041-uuid-gen-seq.ini
diff --git a/test/etap/041-uuid-gen-utc.ini b/apps/couch/test/etap/041-uuid-gen-utc.ini
index c2b83831..c2b83831 100644
--- a/test/etap/041-uuid-gen-utc.ini
+++ b/apps/couch/test/etap/041-uuid-gen-utc.ini
diff --git a/test/etap/041-uuid-gen.t b/apps/couch/test/etap/041-uuid-gen.t
index 1e6aa9ee..84c93a44 100755
--- a/test/etap/041-uuid-gen.t
+++ b/apps/couch/test/etap/041-uuid-gen.t
@@ -13,17 +13,15 @@
% License for the specific language governing permissions and limitations under
% the License.
-default_config() ->
- test_util:build_file("etc/couchdb/default_dev.ini").
-
seq_alg_config() ->
- test_util:source_file("test/etap/041-uuid-gen-seq.ini").
+ filename:join([code:lib_dir(couch, test), "etap/041-uuid-gen-seq.ini"]).
utc_alg_config() ->
- test_util:source_file("test/etap/041-uuid-gen-utc.ini").
+ filename:join([code:lib_dir(couch, test), "etap/041-uuid-gen-utc.ini"]).
% Run tests and wait for the gen_servers to shutdown
run_test(IniFiles, Test) ->
+ couch_config_event:start_link(),
{ok, Pid} = couch_config:start_link(IniFiles),
erlang:monitor(process, Pid),
couch_uuids:start(),
@@ -40,7 +38,7 @@ run_test(IniFiles, Test) ->
main(_) ->
test_util:init_code_path(),
application:start(crypto),
- etap:plan(6),
+ etap:plan(5),
case (catch test()) of
ok ->
@@ -60,9 +58,9 @@ test() ->
"Can generate 10K unique IDs"
)
end,
- run_test([default_config()], TestUnique),
- run_test([default_config(), seq_alg_config()], TestUnique),
- run_test([default_config(), utc_alg_config()], TestUnique),
+ %run_test([default_config()], TestUnique),
+ run_test([seq_alg_config()], TestUnique),
+ run_test([utc_alg_config()], TestUnique),
TestMonotonic = fun () ->
etap:is(
@@ -71,8 +69,8 @@ test() ->
"should produce monotonically increasing ids"
)
end,
- run_test([default_config(), seq_alg_config()], TestMonotonic),
- run_test([default_config(), utc_alg_config()], TestMonotonic),
+ run_test([seq_alg_config()], TestMonotonic),
+ run_test([utc_alg_config()], TestMonotonic),
% Pretty sure that the average of a uniform distribution is the
% midpoint of the range. Thus, to exceed a threshold, we need
@@ -87,14 +85,14 @@ test() ->
UUID = binary_to_list(couch_uuids:new()),
Prefix = element(1, lists:split(26, UUID)),
N = gen_until_pref_change(Prefix,0),
- etap:diag("N is: ~p~n",[N]),
+ etap:diag("N is: ~p~n",[N]),
etap:is(
N >= 5000 andalso N =< 11000,
true,
"should roll over every so often."
)
end,
- run_test([default_config(), seq_alg_config()], TestRollOver).
+ run_test([seq_alg_config()], TestRollOver).
test_unique(0, _) ->
true;
diff --git a/test/etap/050-stream.t b/apps/couch/test/etap/050-stream.t
index d30b524a..16f4f0c6 100755
--- a/test/etap/050-stream.t
+++ b/apps/couch/test/etap/050-stream.t
@@ -30,7 +30,8 @@ read_all(Fd, PosList) ->
iolist_to_binary(Data).
test() ->
- {ok, Fd} = couch_file:open("test/etap/temp.050", [create,overwrite]),
+ {ok, Fd} = couch_file:open("apps/couch/test/etap/temp.050",
+ [create,overwrite]),
{ok, Stream} = couch_stream:open(Fd),
etap:is(ok, couch_stream:write(Stream, <<"food">>),
diff --git a/test/etap/060-kt-merging.t b/apps/couch/test/etap/060-kt-merging.t
index 0e481a52..0e481a52 100755
--- a/test/etap/060-kt-merging.t
+++ b/apps/couch/test/etap/060-kt-merging.t
diff --git a/test/etap/061-kt-missing-leaves.t b/apps/couch/test/etap/061-kt-missing-leaves.t
index d60b4db8..d60b4db8 100755
--- a/test/etap/061-kt-missing-leaves.t
+++ b/apps/couch/test/etap/061-kt-missing-leaves.t
diff --git a/test/etap/062-kt-remove-leaves.t b/apps/couch/test/etap/062-kt-remove-leaves.t
index 745a00be..745a00be 100755
--- a/test/etap/062-kt-remove-leaves.t
+++ b/apps/couch/test/etap/062-kt-remove-leaves.t
diff --git a/test/etap/063-kt-get-leaves.t b/apps/couch/test/etap/063-kt-get-leaves.t
index 6d4e8007..6d4e8007 100755
--- a/test/etap/063-kt-get-leaves.t
+++ b/apps/couch/test/etap/063-kt-get-leaves.t
diff --git a/test/etap/064-kt-counting.t b/apps/couch/test/etap/064-kt-counting.t
index f182d287..f182d287 100755
--- a/test/etap/064-kt-counting.t
+++ b/apps/couch/test/etap/064-kt-counting.t
diff --git a/test/etap/065-kt-stemming.t b/apps/couch/test/etap/065-kt-stemming.t
index 6e781c1d..6e781c1d 100755
--- a/test/etap/065-kt-stemming.t
+++ b/apps/couch/test/etap/065-kt-stemming.t
diff --git a/apps/couch/test/etap/080-config-get-set.ini b/apps/couch/test/etap/080-config-get-set.ini
new file mode 100644
index 00000000..e72e08db
--- /dev/null
+++ b/apps/couch/test/etap/080-config-get-set.ini
@@ -0,0 +1,8 @@
+[daemons]
+something=somevalue
+
+[httpd_design_handlers]
+_view = {couch_httpd_view, handle_view_req}
+
+[httpd]
+port = 5984
diff --git a/test/etap/080-config-get-set.t b/apps/couch/test/etap/080-config-get-set.t
index a4a8577a..c457c7f0 100755
--- a/test/etap/080-config-get-set.t
+++ b/apps/couch/test/etap/080-config-get-set.t
@@ -14,7 +14,7 @@
% the License.
default_config() ->
- test_util:build_file("etc/couchdb/default_dev.ini").
+ filename:join([code:lib_dir(couch, test), "etap/080-config-get-set.ini"]).
main(_) ->
test_util:init_code_path(),
@@ -30,6 +30,7 @@ main(_) ->
test() ->
% start couch_config with default
+ couch_config_event:start_link(),
couch_config:start_link([default_config()]),
diff --git a/apps/couch/test/etap/081-config-default.ini b/apps/couch/test/etap/081-config-default.ini
new file mode 100644
index 00000000..abdf79bc
--- /dev/null
+++ b/apps/couch/test/etap/081-config-default.ini
@@ -0,0 +1,6 @@
+[couchdb]
+max_dbs_open=100
+
+[httpd]
+port=5984
+bind_address = 127.0.0.1
diff --git a/test/etap/081-config-override.1.ini b/apps/couch/test/etap/081-config-override.1.ini
index 55451dad..55451dad 100644
--- a/test/etap/081-config-override.1.ini
+++ b/apps/couch/test/etap/081-config-override.1.ini
diff --git a/test/etap/081-config-override.2.ini b/apps/couch/test/etap/081-config-override.2.ini
index 5f46357f..5f46357f 100644
--- a/test/etap/081-config-override.2.ini
+++ b/apps/couch/test/etap/081-config-override.2.ini
diff --git a/test/etap/081-config-override.t b/apps/couch/test/etap/081-config-override.t
index 01f8b4c2..16a6b6f6 100755
--- a/test/etap/081-config-override.t
+++ b/apps/couch/test/etap/081-config-override.t
@@ -14,19 +14,20 @@
% the License.
default_config() ->
- test_util:build_file("etc/couchdb/default_dev.ini").
+ filename:join([code:lib_dir(couch, test),"etap/081-config-default.ini"]).
local_config_1() ->
- test_util:source_file("test/etap/081-config-override.1.ini").
+ filename:join([code:lib_dir(couch, test),"etap/081-config-override.1.ini"]).
local_config_2() ->
- test_util:source_file("test/etap/081-config-override.2.ini").
+ filename:join([code:lib_dir(couch, test),"etap/081-config-override.2.ini"]).
local_config_write() ->
test_util:build_file("test/etap/temp.081").
% Run tests and wait for the config gen_server to shutdown.
run_tests(IniFiles, Tests) ->
+ couch_config_event:start_link(),
{ok, Pid} = couch_config:start_link(IniFiles),
erlang:monitor(process, Pid),
Tests(),
diff --git a/apps/couch/test/etap/082-config-default.ini b/apps/couch/test/etap/082-config-default.ini
new file mode 100644
index 00000000..e46f158f
--- /dev/null
+++ b/apps/couch/test/etap/082-config-default.ini
@@ -0,0 +1,6 @@
+[couchdb]
+max_dbs_open=500
+
+[httpd]
+port=5984
+bind_address = 127.0.0.1
diff --git a/test/etap/082-config-register.t b/apps/couch/test/etap/082-config-register.t
index 191ba8f8..36b48cf8 100755
--- a/test/etap/082-config-register.t
+++ b/apps/couch/test/etap/082-config-register.t
@@ -14,7 +14,7 @@
% the License.
default_config() ->
- test_util:build_file("etc/couchdb/default_dev.ini").
+ filename:join([code:lib_dir(couch, test), "etap/082-config-default.ini"]).
main(_) ->
test_util:init_code_path(),
@@ -29,6 +29,7 @@ main(_) ->
ok.
test() ->
+ couch_config_event:start_link(),
couch_config:start_link([default_config()]),
etap:is(
diff --git a/test/etap/083-config-no-files.t b/apps/couch/test/etap/083-config-no-files.t
index bc40ec9d..fe2b75c4 100755
--- a/test/etap/083-config-no-files.t
+++ b/apps/couch/test/etap/083-config-no-files.t
@@ -14,7 +14,7 @@
% the License.
default_config() ->
- test_util:build_file("etc/couchdb/default_dev.ini").
+ "rel/overlay/etc/default.ini".
main(_) ->
test_util:init_code_path(),
@@ -29,6 +29,7 @@ main(_) ->
ok.
test() ->
+ couch_config_event:start_link(),
couch_config:start_link([]),
etap:fun_is(
diff --git a/test/etap/090-task-status.t b/apps/couch/test/etap/090-task-status.t
index b278de7f..b278de7f 100755
--- a/test/etap/090-task-status.t
+++ b/apps/couch/test/etap/090-task-status.t
diff --git a/test/etap/100-ref-counter.t b/apps/couch/test/etap/100-ref-counter.t
index 8f996d04..8f996d04 100755
--- a/test/etap/100-ref-counter.t
+++ b/apps/couch/test/etap/100-ref-counter.t
diff --git a/test/etap/120-stats-collect.t b/apps/couch/test/etap/120-stats-collect.inactive
index dee88765..dee88765 100755
--- a/test/etap/120-stats-collect.t
+++ b/apps/couch/test/etap/120-stats-collect.inactive
diff --git a/test/etap/121-stats-aggregates.cfg b/apps/couch/test/etap/121-stats-aggregates.cfg
index 30e475da..30e475da 100644
--- a/test/etap/121-stats-aggregates.cfg
+++ b/apps/couch/test/etap/121-stats-aggregates.cfg
diff --git a/test/etap/121-stats-aggregates.t b/apps/couch/test/etap/121-stats-aggregates.inactive
index d678aa9d..d678aa9d 100755
--- a/test/etap/121-stats-aggregates.t
+++ b/apps/couch/test/etap/121-stats-aggregates.inactive
diff --git a/test/etap/121-stats-aggregates.ini b/apps/couch/test/etap/121-stats-aggregates.ini
index cc5cd218..cc5cd218 100644
--- a/test/etap/121-stats-aggregates.ini
+++ b/apps/couch/test/etap/121-stats-aggregates.ini
diff --git a/apps/couch/test/etap/etap.beam b/apps/couch/test/etap/etap.beam
new file mode 100644
index 00000000..da77f1d6
--- /dev/null
+++ b/apps/couch/test/etap/etap.beam
Binary files differ
diff --git a/test/etap/random_port.ini b/apps/couch/test/etap/random_port.ini
index ada3c13d..ada3c13d 100644
--- a/test/etap/random_port.ini
+++ b/apps/couch/test/etap/random_port.ini
diff --git a/test/etap/run.tpl b/apps/couch/test/etap/run.tpl
index faf0f456..faf0f456 100644
--- a/test/etap/run.tpl
+++ b/apps/couch/test/etap/run.tpl
diff --git a/test/etap/test_cfg_register.c b/apps/couch/test/etap/test_cfg_register.c
index 7161eb55..7161eb55 100644
--- a/test/etap/test_cfg_register.c
+++ b/apps/couch/test/etap/test_cfg_register.c
diff --git a/test/etap/test_web.erl b/apps/couch/test/etap/test_web.erl
index ed78651f..ed78651f 100644
--- a/test/etap/test_web.erl
+++ b/apps/couch/test/etap/test_web.erl
diff --git a/test/javascript/cli_runner.js b/apps/couch/test/javascript/cli_runner.js
index cdbe2e73..cdbe2e73 100644
--- a/test/javascript/cli_runner.js
+++ b/apps/couch/test/javascript/cli_runner.js
diff --git a/test/javascript/couch_http.js b/apps/couch/test/javascript/couch_http.js
index 5f4716d2..5f4716d2 100644
--- a/test/javascript/couch_http.js
+++ b/apps/couch/test/javascript/couch_http.js
diff --git a/test/javascript/run.tpl b/apps/couch/test/javascript/run.tpl
index c5abe6e7..c5abe6e7 100644
--- a/test/javascript/run.tpl
+++ b/apps/couch/test/javascript/run.tpl
diff --git a/test/view_server/query_server_spec.rb b/apps/couch/test/view_server/query_server_spec.rb
index de1df5c1..de1df5c1 100644
--- a/test/view_server/query_server_spec.rb
+++ b/apps/couch/test/view_server/query_server_spec.rb
diff --git a/test/view_server/run_native_process.es b/apps/couch/test/view_server/run_native_process.es
index fcf16d75..fcf16d75 100755
--- a/test/view_server/run_native_process.es
+++ b/apps/couch/test/view_server/run_native_process.es
diff --git a/bin/Makefile.am b/bin/Makefile.am
deleted file mode 100644
index b8b818cb..00000000
--- a/bin/Makefile.am
+++ /dev/null
@@ -1,98 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-if WINDOWS
-bin_SCRIPTS = couchdb.bat
-else
-bin_SCRIPTS = couchdb couchjs
-endif
-
-noinst_SCRIPTS = couchjs_dev
-
-if HELP2MAN
-dist_man1_MANS = couchdb.1 couchjs.1
-endif
-
-CLEANFILES = $(bin_SCRIPTS) $(dist_man1_MANS) $(noinst_SCRIPTS)
-
-transform = @program_transform_name@
-couchdb_command_name = `echo couchdb | sed '$(transform)'`
-couchjs_command_name = `echo couchjs | sed '$(transform)'`
-
-couchdb: couchdb.tpl
- sed -e "s|%ERL%|$(ERL)|g" \
- -e "s|%ICU_CONFIG%|$(ICU_CONFIG)|g" \
- -e "s|%bindir%|@bindir@|g" \
- -e "s|%localerlanglibdir%|@localerlanglibdir@|g" \
- -e "s|%defaultini%|default.ini|g" \
- -e "s|%localini%|local.ini|g" \
- -e "s|%localconfdir%|@localconfdir@|g" \
- -e "s|%localstatelogdir%|@localstatelogdir@|g" \
- -e "s|%localstatelibdir%|@localstatelibdir@|g" \
- -e "s|%localstatedir%|@localstatedir@|g" \
- -e "s|%bug_uri%|@bug_uri@|g" \
- -e "s|%package_author_address%|@package_author_address@|g" \
- -e "s|%package_author_name%|@package_author_name@|g" \
- -e "s|%package_name%|@package_name@|g" \
- -e "s|%version%|@version@|g" \
- -e "s|%couchdb_command_name%|$(couchdb_command_name)|g" > \
- $@ < $<
- chmod +x $@
-
-couchjs: couchjs.tpl
- sed -e "s|%locallibbindir%|@locallibbindir@|g" \
- -e "s|%bug_uri%|@bug_uri@|g" \
- -e "s|%package_author_address%|@package_author_address@|g" \
- -e "s|%package_author_name%|@package_author_name@|g" \
- -e "s|%package_name%|@package_name@|g" \
- -e "s|%version%|@version@|g" \
- -e "s|%couchjs_command_name%|$(couchjs_command_name)|g" > \
- $@ < $<
- chmod +x $@
-
-couchjs_dev: couchjs.tpl
- sed -e "s|%locallibbindir%|$(abs_top_builddir)/src/couchdb/priv|g" \
- -e "s|%bug_uri%|@bug_uri@|g" \
- -e "s|%package_author_address%|@package_author_address@|g" \
- -e "s|%package_author_name%|@package_author_name@|g" \
- -e "s|%package_name%|@package_name@|g" \
- -e "s|%version%|@version@|g" \
- -e "s|%couchjs_command_name%|$(couchjs_command_name)|g" > \
- $@ < $<
- chmod +x $@
-
-couchdb.bat: couchdb.bat.tpl
- sed -e "s|%ICU_CONFIG%|$(ICU_CONFIG)|g" \
- -e "s|%version%|@version@|g" \
- $< > $@
-
-HELP2MAN_OPTION=--no-info --help-option="-h" --version-option="-V"
-
-# XXX: Because the scripts are made at build time for the user we need to
-# XXX: depend on the original templates so as not to cause the rebuilding of
-# XXX: the man pages.
-
-couchdb.1: couchdb.tpl.in
- touch $@
- if test -x "$(HELP2MAN_EXECUTABLE)"; then \
- $(MAKE) -f Makefile couchdb; \
- $(HELP2MAN_EXECUTABLE) $(HELP2MAN_OPTION) \
- --name="Apache CouchDB database server" ./couchdb --output $@; \
- fi
-
-couchjs.1: couchjs.tpl.in
- touch $@
- if test -x "$(HELP2MAN_EXECUTABLE)"; then \
- $(MAKE) -f Makefile couchjs; \
- $(HELP2MAN_EXECUTABLE) $(HELP2MAN_OPTION) \
- --name="Apache CouchDB JavaScript interpreter" ./couchjs --output $@; \
- fi
diff --git a/bin/couchdb.bat.tpl.in b/bin/couchdb.bat.tpl.in
deleted file mode 100644
index 48d78513..00000000
--- a/bin/couchdb.bat.tpl.in
+++ /dev/null
@@ -1,26 +0,0 @@
-@echo off
-rem Licensed under the Apache License, Version 2.0 (the "License"); you may not
-rem use this file except in compliance with the License. You may obtain a copy
-rem of the License at
-rem
-rem http://www.apache.org/licenses/LICENSE-2.0
-rem
-rem Unless required by applicable law or agreed to in writing, software
-rem distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-rem WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-rem License for the specific language governing permissions and limitations
-rem under the License.
-
-setlocal
-rem First change to the drive with the erlang bin directory
-%~d0
-rem then change to the erlang bin directory
-cd %~dp0
-
-rem Allow a different erlang executable (eg, erl) to be used.
-rem When using erl instead of werl, server restarts during test runs can fail
-rem intermittently. But using erl should be fine for production use.
-if "%ERL%x" == "x" set ERL=werl.exe
-
-echo CouchDB %version% - prepare to relax...
-%ERL% -sasl errlog_type error -s couch
diff --git a/bin/couchdb.tpl.in b/bin/couchdb.tpl.in
deleted file mode 100644
index 94d47439..00000000
--- a/bin/couchdb.tpl.in
+++ /dev/null
@@ -1,330 +0,0 @@
-#! /bin/sh -e
-
-# Licensed under the Apache License, Version 2.0 (the "License"); you may not
-# use this file except in compliance with the License. You may obtain a copy of
-# the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations under
-# the License.
-
-BACKGROUND=false
-DEFAULT_CONFIG_DIR=%localconfdir%/default.d
-DEFAULT_CONFIG_FILE=%localconfdir%/%defaultini%
-ERL_START_OPTIONS="-sasl errlog_type error +K true +A 4"
-HEART_BEAT_TIMEOUT=11
-HEART_COMMAND="%bindir%/%couchdb_command_name% -k"
-INTERACTIVE=false
-KILL=false
-LOCAL_CONFIG_DIR=%localconfdir%/local.d
-LOCAL_CONFIG_FILE=%localconfdir%/%localini%
-PID_FILE=%localstatedir%/run/couchdb/couchdb.pid
-RECURSED=false
-RESET_CONFIG=true
-RESPAWN_TIMEOUT=0
-SCRIPT_ERROR=1
-SCRIPT_OK=0
-SHUTDOWN=false
-STDERR_FILE=couchdb.stderr
-STDOUT_FILE=couchdb.stdout
-
-print_arguments=""
-start_arguments=""
-background_start_arguments=""
-
-basename=`basename $0`
-
-display_version () {
- cat << EOF
-$basename - %package_name% %version%
-
-Licensed under the Apache License, Version 2.0 (the "License"); you may not use
-this file except in compliance with the License. You may obtain a copy of the
-License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software distributed
-under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-CONDITIONS OF ANY KIND, either express or implied. See the License for the
-specific language governing permissions and limitations under the License.
-
-EOF
-}
-
-display_help () {
- cat << EOF
-Usage: $basename [OPTION]
-
-The $basename command runs the %package_name% server.
-
-Erlang is called with:
-
- $ERL_START_OPTIONS
-
-Erlang inherits the environment of this command.
-
-You can override these options using the environment:
-
- ERL_AFLAGS, ERL_FLAGS, ERL_ZFLAGS
-
-See erl(1) for more information about the environment variables.
-
-The exit status is 0 for success or 1 for failure.
-
-Options:
-
- -h display a short help message and exit
- -V display version information and exit
- -a FILE add configuration FILE to chain
- -A DIR add configuration DIR to chain
- -n reset configuration file chain (including system default)
- -c print configuration file chain and exit
- -i use the interactive Erlang shell
- -b spawn as a background process
- -p FILE set the background PID FILE (overrides system default)
- -r SECONDS respawn background process after SECONDS (defaults to no respawn)
- -o FILE redirect background stdout to FILE (defaults to $STDOUT_FILE)
- -e FILE redirect background stderr to FILE (defaults to $STDERR_FILE)
- -s display the status of the background process
- -k kill the background process, will respawn if needed
- -d shutdown the background process
-
-Report bugs at <%bug_uri%>.
-EOF
-}
-
-display_error () {
- if test -n "$1"; then
- echo $1 >&2
- fi
- echo >&2
- echo "Try \`"$basename" -h' for more information." >&2
- false
-}
-
-_get_pid () {
- if test -f $PID_FILE; then
- PID=`cat $PID_FILE`
- fi
- echo $PID
-}
-
-_add_config_file () {
- if test -z "$print_arguments"; then
- print_arguments="$1"
- else
- print_arguments="`cat <<EOF
-$print_arguments
-$1
-EOF
-`"
- fi
- start_arguments="$start_arguments $1"
- background_start_arguments="$background_start_arguments -a $1"
-}
-
-_add_config_dir () {
- for file in "$1"/*.ini; do
- if [ -r "$file" ]; then
- _add_config_file "$file"
- fi
- done
-}
-
-_load_config () {
- _add_config_file "$DEFAULT_CONFIG_FILE"
- _add_config_dir "$DEFAULT_CONFIG_DIR"
- _add_config_file "$LOCAL_CONFIG_FILE"
- _add_config_dir "$LOCAL_CONFIG_DIR"
-}
-
-_reset_config () {
- print_arguments=""
- start_arguments=""
- background_start_arguments="-n"
-}
-
-_print_config () {
- cat <<EOF
-$print_arguments
-EOF
-}
-
-check_status () {
- PID=`_get_pid`
- if test -n "$PID"; then
- if kill -0 $PID 2> /dev/null; then
- echo "Apache CouchDB is running as process $PID, time to relax."
- return $SCRIPT_OK
- else
- echo >&2 << EOF
-Apache CouchDB is not running but a stale PID file exists: $PID_FILE"
-EOF
- fi
- else
- echo "Apache CouchDB is not running." >&2
- fi
- return $SCRIPT_ERROR
-}
-
-check_environment () {
- if test "$BACKGROUND" != "true"; then
- return
- fi
- touch $PID_FILE 2> /dev/null || true
- touch $STDOUT_FILE 2> /dev/null || true
- touch $STDERR_FILE 2> /dev/null || true
- message_prefix="Apache CouchDB needs write permission on the"
- if test ! -w $PID_FILE; then
- echo "$message_prefix PID file: $PID_FILE" >&2
- false
- fi
- if test ! -w $STDOUT_FILE; then
- echo "$message_prefix STDOUT file: $STDOUT_FILE" >&2
- false
- fi
- if test ! -w $STDERR_FILE; then
- echo "$message_prefix STDERR file: $STDERR_FILE" >&2
- false
- fi
- message_prefix="Apache CouchDB needs a regular"
- if test `echo 2> /dev/null >> $PID_FILE; echo $?` -gt 0; then
- echo "$message_prefix PID file: $PID_FILE" >&2
- false
- fi
- if test `echo 2> /dev/null >> $STDOUT_FILE; echo $?` -gt 0; then
- echo "$message_prefix STDOUT file: $STDOUT_FILE" >&2
- false
- fi
- if test `echo 2> /dev/null >> $STDERR_FILE; echo $?` -gt 0; then
- echo "$message_prefix STDERR file: $STDERR_FILE" >&2
- false
- fi
-}
-
-start_couchdb () {
- if test ! "$RECURSED" = "true"; then
- if check_status 2> /dev/null; then
- exit
- fi
- check_environment
- fi
- interactive_option="+Bd -noinput"
- if test "$INTERACTIVE" = "true"; then
- interactive_option=""
- fi
- if test "$BACKGROUND" = "true"; then
- touch $PID_FILE
- interactive_option="+Bd -noinput"
- fi
- command="%ERL% $interactive_option $ERL_START_OPTIONS \
- -env ERL_LIBS %localerlanglibdir% -couch_ini $start_arguments -s couch"
- if test "$BACKGROUND" = "true" -a "$RECURSED" = "false"; then
- $0 $background_start_arguments -b -r $RESPAWN_TIMEOUT -p $PID_FILE \
- -o $STDOUT_FILE -e $STDERR_FILE -R &
- echo "Apache CouchDB has started, time to relax."
- else
- if test "$RECURSED" = "true"; then
- while true; do
- export HEART_COMMAND
- export HEART_BEAT_TIMEOUT
- `eval $command -pidfile $PID_FILE -heart \
- >> $STDOUT_FILE 2>> $STDERR_FILE` || true
- PID=`_get_pid`
- if test -n "$PID"; then
- if kill -0 $PID 2> /dev/null; then
- return $SCRIPT_ERROR
- fi
- else
- return $SCRIPT_OK
- fi
- if test "$RESPAWN_TIMEOUT" = "0"; then
- return $SCRIPT_OK
- fi
- if test "$RESPAWN_TIMEOUT" != "1"; then
- plural_ending="s"
- fi
- cat << EOF
-Apache CouchDB crashed, restarting in $RESPAWN_TIMEOUT second$plural_ending.
-EOF
- sleep $RESPAWN_TIMEOUT
- done
- else
- eval exec $command
- fi
- fi
-}
-
-stop_couchdb () {
- PID=`_get_pid`
- if test -n "$PID"; then
- if test "$1" = "false"; then
- echo > $PID_FILE
- fi
- if kill -0 $PID 2> /dev/null; then
- if kill -1 $PID 2> /dev/null; then
- if test "$1" = "false"; then
- echo "Apache CouchDB has been shutdown."
- else
- echo "Apache CouchDB has been killed."
- fi
- return $SCRIPT_OK
- else
- echo "Apache CouchDB could not be killed." >&2
- return $SCRIPT_ERROR
- fi
- if test "$1" = "false"; then
- echo "Stale PID file exists but Apache CouchDB is not running."
- else
- echo "Stale PID file existed but Apache CouchDB is not running."
- fi
- fi
- else
- echo "Apache CouchDB is not running."
- fi
-}
-
-parse_script_option_list () {
- _load_config
- set +e
- options=`getopt hVa:A:ncibp:r:Ro:e:skd $@`
- if test ! $? -eq 0; then
- display_error
- fi
- set -e
- eval set -- $options
- while [ $# -gt 0 ]; do
- case "$1" in
- -h) shift; display_help; exit;;
- -V) shift; display_version; exit;;
- -a) shift; _add_config_file "$1"; shift;;
- -A) shift; _add_config_dir "$1"; shift;;
- -n) shift; _reset_config;;
- -c) shift; _print_config; exit;;
- -i) shift; INTERACTIVE=true;;
- -b) shift; BACKGROUND=true;;
- -r) shift; RESPAWN_TIMEOUT=$1; shift;;
- -R) shift; RECURSED=true;;
- -p) shift; PID_FILE=$1; shift;;
- -o) shift; STDOUT_FILE=$1; shift;;
- -e) shift; STDERR_FILE=$1; shift;;
- -s) shift; check_status; exit;;
- -k) shift; KILL=true;;
- -d) shift; SHUTDOWN=true;;
- --) shift; break;;
- *) display_error "Unknown option: $1" >&2;;
- esac
- done
- if test "$KILL" = "true" -o "$SHUTDOWN" = "true"; then
- stop_couchdb $KILL
- else
- start_couchdb
- fi
-}
-
-parse_script_option_list $@
diff --git a/bin/couchjs.tpl.in b/bin/couchjs.tpl.in
deleted file mode 100644
index 6927a0d4..00000000
--- a/bin/couchjs.tpl.in
+++ /dev/null
@@ -1,92 +0,0 @@
-#! /bin/sh -e
-
-# Licensed under the Apache License, Version 2.0 (the "License"); you may not
-# use this file except in compliance with the License. You may obtain a copy of
-# the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations under
-# the License.
-
-SCRIPT_OK=0
-SCRIPT_ERROR=1
-
-DEFAULT_VERSION=170
-
-basename=`basename $0`
-
-display_version () {
- cat << EOF
-$basename - %package_name% %version%
-
-Licensed under the Apache License, Version 2.0 (the "License"); you may not use
-this file except in compliance with the License. You may obtain a copy of the
-License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software distributed
-under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-CONDITIONS OF ANY KIND, either express or implied. See the License for the
-specific language governing permissions and limitations under the License.
-EOF
-}
-
-display_help () {
- cat << EOF
-Usage: $basename [FILE]
-
-The $basename command runs the %package_name% JavaScript interpreter.
-
-The exit status is 0 for success or 1 for failure.
-
-Options:
-
- -h display a short help message and exit
- -V display version information and exit
-
-Report bugs at <%bug_uri%>.
-EOF
-}
-
-display_error () {
- if test -n "$1"; then
- echo $1 >&2
- fi
- echo >&2
- echo "Try \`"$basename" -h' for more information." >&2
- exit $SCRIPT_ERROR
-}
-
-run_couchjs () {
- exec %locallibbindir%/%couchjs_command_name% $@
-}
-
-parse_script_option_list () {
- set +e
- options=`getopt hV $@`
- if test ! $? -eq 0; then
- display_error
- fi
- set -e
- eval set -- $options
- while [ $# -gt 0 ]; do
- case "$1" in
- -h) shift; display_help; exit $SCRIPT_OK;;
- -V) shift; display_version; exit $SCRIPT_OK;;
- --) shift; break;;
- *) break;;
- esac
- done
- option_list=`echo $@ | sed 's/--//'`
- if test -z "$option_list"; then
- display_error "You must specify a FILE."
- fi
- run_couchjs $option_list
-}
-
-parse_script_option_list $@
diff --git a/bootstrap b/bootstrap
deleted file mode 100755
index 0c576c40..00000000
--- a/bootstrap
+++ /dev/null
@@ -1,68 +0,0 @@
-#!/bin/sh -e
-
-# Licensed under the Apache License, Version 2.0 (the "License"); you may not
-# use this file except in compliance with the License. You may obtain a copy of
-# the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations under
-# the License.
-
-get () {
- variable_name=$1
- echo "changequote(\`[', \`]')" > acinclude.m4.tmp
- sed -e "s/m4_//" < acinclude.m4.in >> acinclude.m4.tmp
- echo $variable_name >> acinclude.m4.tmp
- if test -x "`which gm4 2> /dev/null || true`"; then
- gm4 acinclude.m4.tmp | grep -v "^$" || true
- else
- if test -x "`which m4 2> /dev/null || true`"; then
- m4 acinclude.m4.tmp | grep -v "^$" || true
- else
- echo unknown
- fi
- fi
- rm -f acinclude.m4.tmp
-}
-
-mkdir -p build-aux
-
-if test -z "$REVISION"; then
- if test -d .git; then
- REVISION=`git log --pretty="format:%h" | head -1`-git
- else
- # default to svn
- REVISION=`\`which svn\` info . 2> /dev/null | awk "/Revision:/{print \\$2}"`
- fi
-fi
-if test -z "`get LOCAL_VERSION_STAGE`" -o -z "$REVISION"; then
- sed "s/%release%//" < acinclude.m4.in > acinclude.m4
-else
- sed "s/%release%/$REVISION/" < acinclude.m4.in > acinclude.m4
-fi
-
-gunzip -c m4/ac_check_icu.m4.gz > m4/ac_check_icu.m4
-gunzip -c m4/ac_check_curl.m4.gz > m4/ac_check_curl.m4
-
-if test -x "`which glibtoolize 2> /dev/null || true`"; then
- glibtoolize -f -c --automake
-else
- libtoolize -f -c --automake
-fi
-
-aclocal -I m4
-autoheader -f
-automake -f -a 2>&1 | sed -e "/install/d"
-autoconf -f
-
-ln -f -s "`dirname \`readlink build-aux/missing\``/INSTALL"
-
-cat << EOF
-You have bootstrapped Apache CouchDB, time to relax.
-
-Run \`./configure' to configure the source before you install.
-EOF
diff --git a/configure b/configure
new file mode 100755
index 00000000..43231b62
--- /dev/null
+++ b/configure
@@ -0,0 +1,89 @@
+#!/bin/bash
+# Copyright 2010 Cloudant
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+
+
+PREFIX="/opt/bigcouch"
+BIGCOUCH_USER=`whoami`
+ABSPATH="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")"
+if test ! -n "$DIRPATH"; then DIRPATH=`dirname "$ABSPATH"`; fi
+
+while [ $# -gt 0 ]
+do
+ case $1
+ in
+ -p)
+ PREFIX=$2
+ shift 2
+ ;;
+ -t)
+ TEMPLATE=$2
+ shift 2
+ ;;
+ -d)
+ DATA=$2
+ shift 2
+ ;;
+ -v)
+ VIEW=$2
+ shift 2
+ ;;
+ -u)
+ BIGCOUCH_USER=$2
+ shift 2
+ ;;
+ *)
+ echo "usage: $0 [-p {prefix} -t {template} -d {data_dir} -v {view_dir} -u {user}]"
+ exit
+ ;;
+ esac
+done
+
+if test ! -n "$DATA"; then DATA="$PREFIX/var/lib"; fi
+if test ! -n "$VIEW"; then VIEW="$PREFIX/var/lib"; fi
+
+echo "==> configuring bigcouch in rel/bigcouch.config"
+cat > rel/bigcouch.config << EOF
+{prefix, "$PREFIX"}.
+{data_dir, "$DATA"}.
+{view_dir, "$VIEW"}.
+{user, "$BIGCOUCH_USER"}.
+{node_name, "-name bigcouch"}.
+{cluster_port, 5984}.
+{backend_port, 5986}.
+EOF
+
+cat > install.mk << EOF
+# The contents of this file are auto-generated by configure
+prefix = $PREFIX
+data_dir = $DATA
+view_dir = $VIEW
+user = $BIGCOUCH_USER
+EOF
+
+# finally, a few config files for local development nodes
+for i in 1 2 3; do
+cat > rel/dev$i.config << EOF
+{prefix, "$DIRPATH/rel/dev$i"}.
+{data_dir, "$DIRPATH/rel/tmpdata/dev$i"}.
+{view_dir, "$DIRPATH/rel/tmpdata/dev$i"}.
+{node_name, "-name dev$i@127.0.0.1"}.
+{cluster_port, `expr 10000 \* $i + 5984`}.
+{backend_port, `expr 10000 \* $i + 5986`}.
+EOF
+done
+
+mkdir -p apps/couch/ebin
+./rebar get-deps && ./rebar update-deps && cat rel/bigcouch.config
diff --git a/configure.ac b/configure.ac
deleted file mode 100644
index b776a258..00000000
--- a/configure.ac
+++ /dev/null
@@ -1,440 +0,0 @@
-dnl Licensed under the Apache License, Version 2.0 (the "License"); you may not
-dnl use this file except in compliance with the License. dnl You may obtain a
-dnl copy of the License at
-dnl
-dnl http://www.apache.org/licenses/LICENSE-2.0
-dnl
-dnl Unless required by applicable law or agreed to in writing, software
-dnl distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-dnl WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-dnl License for the specific language governing permissions and limitations
-dnl under the License.
-
-AC_INIT([LOCAL_PACKAGE_NAME], [LOCAL_VERSION], [], [LOCAL_PACKAGE_TARNAME])
-
-AC_PREREQ([2.59])
-
-AC_CONFIG_SRCDIR([CHANGES])
-AC_CONFIG_AUX_DIR([build-aux])
-AC_CONFIG_MACRO_DIR([m4])
-
-AM_CONFIG_HEADER([config.h])
-
-AM_INIT_AUTOMAKE([1.6.3 foreign])
-
-AC_GNU_SOURCE
-AC_ENABLE_SHARED
-AC_DISABLE_STATIC
-
-AC_PROG_CC
-AC_PROG_LIBTOOL
-AC_PROG_LN_S
-
-AC_MSG_CHECKING([for pthread_create in -lpthread])
-
-original_LIBS="$LIBS"
-LIBS="-lpthread $original_LIBS"
-
-AC_TRY_LINK([#include<pthread.h>],
- [pthread_create((void *)0, (void *)0, (void *)0, (void *)0)],
- [pthread=yes], [pthread=no])
-
-if test x${pthread} = xyes; then
- AC_MSG_RESULT([yes])
-else
- LIBS="$original_LIBS"
- AC_MSG_RESULT([no])
-fi
-
-AC_ARG_WITH([erlang], [AC_HELP_STRING([--with-erlang=PATH],
- [set PATH to the Erlang include directory])], [
- ERLANG_FLAGS="-I$withval"
-], [
- ERLANG_FLAGS="-I${libdir}/erlang/usr/include"
- ERLANG_FLAGS="$ERLANG_FLAGS -I/usr/lib/erlang/usr/include"
- ERLANG_FLAGS="$ERLANG_FLAGS -I/usr/local/lib/erlang/usr/include"
- ERLANG_FLAGS="$ERLANG_FLAGS -I/opt/local/lib/erlang/usr/include"
-])
-
-AC_ARG_WITH([js-include], [AC_HELP_STRING([--with-js-include=PATH],
- [set PATH to the SpiderMonkey include directory])], [
- JS_INCLUDE="$withval"
- JS_FLAGS="-I$JS_INCLUDE"
-], [
- JS_FLAGS="-I/usr/include"
- JS_FLAGS="$JS_FLAGS -I/usr/include/js"
- JS_FLAGS="$JS_FLAGS -I/usr/include/mozjs"
- JS_FLAGS="$JS_FLAGS -I/usr/local/include"
- JS_FLAGS="$JS_FLAGS -I/opt/local/include"
- JS_FLAGS="$JS_FLAGS -I/usr/local/include/js"
- JS_FLAGS="$JS_FLAGS -I/opt/local/include/js"
-])
-
-AC_ARG_WITH([js-lib], [AC_HELP_STRING([--with-js-lib=PATH],
- [set PATH to the SpiderMonkey library directory])],
- [
- JS_LIB_DIR=$withval
- JS_LIB_FLAGS="-L$withval"
-], [
- JS_LIB_DIR=
-])
-AC_SUBST(JS_LIB_DIR)
-
-AC_ARG_VAR([ERLC_FLAGS], [general flags to prepend to ERLC_FLAGS])
-AC_ARG_VAR([FLAGS], [general flags to prepend to LDFLAGS and CPPFLAGS])
-
-LIB_FLAGS="$JS_LIB_FLAGS -L/usr/local/lib -L/opt/local/lib"
-LIBS="$LIB_FLAGS $LIBS"
-
-case "$(uname -s)" in
- CYGWIN*)
- FLAGS="$LIB_FLAGS $ERLANG_FLAGS $JS_FLAGS -DXP_WIN $FLAGS"
- CPPFLAGS="$FLAGS $CPPFLAGS"
- LDFLAGS="$FLAGS $LDFLAGS"
- IS_WINDOWS="TRUE"
- # The erlang cc.sh/ld.sh scripts will convert a -O option
- # into the same optimization flags erlang itself uses.
- CFLAGS="-O2"
- LTCFLAGS="$CFLAGS"
- ;;
- *)
- # XP_UNIX required for jsapi.h and has been tested to work on Linux and Darwin.
- FLAGS="$LIB_FLAGS $ERLANG_FLAGS $JS_FLAGS -DXP_UNIX $FLAGS"
- CPPFLAGS="$FLAGS $CPPFLAGS"
- # manually linking libm is requred for FreeBSD 7.0
- LDFLAGS="$FLAGS -lm $LDFLAGS"
- ;;
-esac
-
-AM_CONDITIONAL([WINDOWS], [test x$IS_WINDOWS = xTRUE])
-
-AC_CHECK_LIB([mozjs], [JS_NewContext], [JS_LIB_BASE=mozjs], [
- AC_CHECK_LIB([js], [JS_NewContext], [JS_LIB_BASE=js], [
- AC_CHECK_LIB([js3250], [JS_NewContext], [JS_LIB_BASE=js3250], [
- AC_CHECK_LIB([js32], [JS_NewContext], [JS_LIB_BASE=js32], [
- AC_MSG_ERROR([Could not find the js library.
-
-Is the Mozilla SpiderMonkey library installed?])])])])])
-
-AC_SUBST(JS_LIB_BASE)
-
-if test x${IS_WINDOWS} = xTRUE; then
- if test -f "$JS_LIB_DIR/$JS_LIB_BASE.dll"; then
- # seamonkey 1.7- build layout on Windows
- JS_LIB_BINARY="$JS_LIB_DIR/$JS_LIB_BASE.dll"
- else
- # seamonkey 1.8+ build layout on Windows
- if test -f "$JS_LIB_DIR/../bin/$JS_LIB_BASE.dll"; then
- JS_LIB_BINARY="$JS_LIB_DIR/../bin/$JS_LIB_BASE.dll"
- else
- AC_MSG_ERROR([Could not find $JS_LIB_BASE.dll.])
- fi
- fi
- AC_SUBST(JS_LIB_BINARY)
-
- # On windows we need to know the path to the openssl binaries.
- AC_ARG_WITH([openssl-bin-dir], [AC_HELP_STRING([--with-openssl-bin-dir=PATH],
- [path to the open ssl binaries for distribution on Windows])], [
- openssl_bin_dir=`cygpath -m "$withval"`
- AC_SUBST(openssl_bin_dir)
- ], [])
-
- # Windows uses Inno setup - look for its compiler.
- AC_PATH_PROG([INNO_COMPILER_EXECUTABLE], [iscc])
- if test x${INNO_COMPILER_EXECUTABLE} = x; then
- AC_MSG_WARN([You will be unable to build the Windows installer.])
- fi
-
- # We need the msvc redistributables for this platform too
- # (in theory we could just install the assembly locally - but
- # there are at least 4 directories with binaries, meaning 4 copies;
- # so using the redist .exe means it ends up installed globally...)
- AC_ARG_WITH([msvc-redist-dir], [AC_HELP_STRING([--with-msvc-redist-dir=PATH],
- [path to the msvc redistributables for the Windows platform])], [
- msvc_redist_dir=`cygpath -m "$withval"`
- msvc_redist_name="vcredist_x86.exe"
- AC_SUBST(msvc_redist_dir)
- AC_SUBST(msvc_redist_name)
- ], [])
- if test ! -f ${msvc_redist_dir}/${msvc_redist_name}; then
- AC_MSG_WARN([The MSVC redistributable seems to be missing; expect the installer to fail.])
- fi
-fi
-
-JSLIB=-l$JS_LIB_BASE
-
-AC_CHECK_HEADER([jsapi.h], [], [
- AC_CHECK_HEADER([js/jsapi.h],
- [
- CPPFLAGS="$CPPFLAGS -I$JS_INCLUDE/js"
- ],
- [
- AC_MSG_ERROR([Could not find the jsapi header.
-
-Are the Mozilla SpiderMonkey headers installed?])
- ])])
-
-AC_SUBST(JSLIB)
-
-AC_LANG_PUSH(C)
-OLD_CFLAGS="$CFLAGS"
-CFLAGS="-Werror-implicit-function-declaration"
-AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM(
- [[#include <jsapi.h>]],
- [[JS_SetOperationCallback(0, 0);]]
- )],
- AC_DEFINE([USE_JS_SETOPCB], [], [Use new JS_SetOperationCallback])
-)
-CFLAGS="$OLD_CFLAGS"
-AC_LANG_POP(C)
-
-AC_ARG_WITH([win32-icu-binaries], [AC_HELP_STRING([--with-win32-icu-binaries=PATH],
- [set PATH to the Win32 native ICU binaries directory])], [
- ICU_CONFIG="" # supposed to be a command to query options...
- ICU_LOCAL_CFLAGS="-I$withval/include"
- ICU_LOCAL_LDFLAGS="-L$withval/lib"
- ICU_LOCAL_BIN=$withval/bin
-], [
- AC_CHECK_ICU([3.4.1])
- ICU_LOCAL_CFLAGS=`$ICU_CONFIG --cppflags-searchpath`
- ICU_LOCAL_LDFLAGS=`$ICU_CONFIG --ldflags-searchpath`
- ICU_LOCAL_BIN=
-])
-
-AC_SUBST(ICU_CONFIG)
-AC_SUBST(ICU_LOCAL_CFLAGS)
-AC_SUBST(ICU_LOCAL_LDFLAGS)
-AC_SUBST(ICU_LOCAL_BIN)
-
-AC_ARG_WITH([win32-curl], [AC_HELP_STRING([--with-win32-curl=PATH],
- [set PATH to the Win32 native curl directory])], [
- # default build on windows is a static lib, and that's what we want too
- CURL_CFLAGS="-I$withval/include -DCURL_STATICLIB"
- CURL_LIBS="$withval/lib/libcurl"
- CURL_LDFLAGS="-l$CURL_LIBS -lWs2_32 -lkernel32 -luser32 -ladvapi32 -lWldap32"
-], [
- AC_CHECK_CURL([7.18.0])
- CURL_LDFLAGS=-lcurl
-])
-
-AC_SUBST(CURL_CFLAGS)
-AC_SUBST(CURL_LIBS)
-AC_SUBST(CURL_LDFLAGS)
-
-case "$(uname -s)" in
- Linux)
- LIBS="$LIBS -lcrypt"
- CPPFLAGS="-D_XOPEN_SOURCE $CPPFLAGS"
- ;;
- FreeBSD)
- LIBS="$LIBS -lcrypt"
- ;;
- OpenBSD)
- LIBS="$LIBS -lcrypto"
- ;;
-esac
-
-AC_PATH_PROG([ERL], [erl])
-
-if test x${ERL} = x; then
- AC_MSG_ERROR([Could not find the `erl' executable. Is Erlang installed?])
-fi
-
-erlang_version_error="The installed Erlang version is less than 5.6.5 (R12B05)."
-
-version="`${ERL} -version 2>&1 | ${SED} "s/[[^0-9]]/ /g"`"
-
-if test `echo $version | ${AWK} "{print \\$1}"` -lt 5; then
- AC_MSG_ERROR([$erlang_version_error])
-fi
-
-if test `echo $version | ${AWK} "{print \\$2}"` -lt 6; then
- AC_MSG_ERROR([$erlang_version_error])
-fi
-
-if test `echo $version | ${AWK} "{print \\$2}"` -eq 6; then
- if test `echo $version | ${AWK} "{print \\$3}"` -lt 5; then
- AC_MSG_ERROR([$erlang_version_error])
- fi
-fi
-
-has_crypto=`${ERL} -eval "case application:load(crypto) of ok -> ok; _ -> exit(no_crypto) end." -noshell -s init stop`
-
-if test -n "$has_crypto"; then
- AC_MSG_ERROR([Could not find the Erlang crypto library. Has Erlang been compiled with OpenSSL support?])
-fi
-
-AC_PATH_PROG([ERLC], [erlc])
-
-if test x${ERLC} = x; then
- AC_MSG_ERROR([Could not find the `erlc' executable. Is Erlang installed?])
-fi
-
-AC_CHECK_HEADER([erl_driver.h], [], [
- AC_MSG_ERROR([Could not find the `erl_driver.h' header.
-
-Are the Erlang headers installed? Use the `--with-erlang' option to specify the
-path to the Erlang include directory.])])
-
-AC_PATH_PROG([HELP2MAN_EXECUTABLE], [help2man])
-if test x${HELP2MAN_EXECUTABLE} = x; then
- AC_MSG_WARN([You will be unable to regenerate any man pages.])
-fi
-
-use_init=yes
-use_launchd=yes
-
-AC_ARG_ENABLE([init], [AC_HELP_STRING([--disable-init],
- [don't install init script where applicable])], [
- use_init=$enableval
-], [])
-
-AC_ARG_ENABLE([launchd], [AC_HELP_STRING([--disable-launchd],
- [don't install launchd configuration where applicable])], [
- use_launchd=$enableval
-], [])
-
-init_enabled=false
-launchd_enabled=false
-
-if test "$use_init" = "yes"; then
- AC_MSG_CHECKING(location of init directory)
- if test -d /etc/rc.d; then
- init_enabled=true
- AC_SUBST([initdir], ['${sysconfdir}/rc.d'])
- AC_MSG_RESULT(${initdir})
- else
- if test -d /etc/init.d; then
- init_enabled=true
- AC_SUBST([initdir], ['${sysconfdir}/init.d'])
- AC_MSG_RESULT(${initdir})
- else
- AC_MSG_RESULT(not found)
- fi
- fi
-fi
-
-if test "$use_launchd" = "yes"; then
- AC_MSG_CHECKING(location of launchd directory)
- if test -d /Library/LaunchDaemons; then
- init_enabled=false
- launchd_enabled=true
- AC_SUBST([launchddir], ['${prefix}/Library/LaunchDaemons'])
- AC_MSG_RESULT(${launchddir})
- else
- AC_MSG_RESULT(not found)
- fi
-fi
-
-AC_ARG_VAR([ERL], [path to the `erl' executable])
-AC_ARG_VAR([ERLC], [path to the `erlc' executable])
-AC_ARG_VAR([HELP2MAN_EXECUTABLE], [path to the `help2man' program])
-
-if test -n "$HELP2MAN_EXECUTABLE"; then
- help2man_enabled=true
-else
- if test -f "$srcdir/bin/couchdb.1" -a -f "$srcdir/bin/couchjs.1"; then
- help2man_enabled=true
- else
- help2man_enabled=false
- fi
-fi
-
-AM_CONDITIONAL([INIT], [test x${init_enabled} = xtrue])
-AM_CONDITIONAL([LAUNCHD], [test x${launchd_enabled} = xtrue])
-AM_CONDITIONAL([HELP2MAN], [test x${help2man_enabled} = xtrue])
-
-AC_SUBST([package_author_name], ["LOCAL_PACKAGE_AUTHOR_NAME"])
-AC_SUBST([package_author_address], ["LOCAL_PACKAGE_AUTHOR_ADDRESS"])
-AC_SUBST([package_identifier], ["LOCAL_PACKAGE_IDENTIFIER"])
-AC_SUBST([package_tarname], ["LOCAL_PACKAGE_TARNAME"])
-AC_SUBST([package_name], ["LOCAL_PACKAGE_NAME"])
-
-AC_SUBST([version], ["LOCAL_VERSION"])
-AC_SUBST([version_major], ["LOCAL_VERSION_MAJOR"])
-AC_SUBST([version_minor], ["LOCAL_VERSION_MINOR"])
-AC_SUBST([version_revision], ["LOCAL_VERSION_REVISION"])
-AC_SUBST([version_stage], ["LOCAL_VERSION_STAGE"])
-AC_SUBST([version_release], ["LOCAL_VERSION_RELEASE"])
-
-AC_SUBST([bug_uri], ["LOCAL_BUG_URI"])
-
-AC_SUBST([localconfdir], [${sysconfdir}/${package_identifier}])
-AC_SUBST([localdatadir], [${datadir}/${package_identifier}])
-AC_SUBST([localdocdir], [${datadir}/doc/${package_identifier}])
-AC_SUBST([locallibdir], [${libdir}/${package_identifier}])
-AC_SUBST([localstatelibdir], [${localstatedir}/lib/${package_identifier}])
-AC_SUBST([localstatelogdir], [${localstatedir}/log/${package_identifier}])
-AC_SUBST([localstaterundir], [${localstatedir}/run/${package_identifier}])
-
-# On Windows we install directly into our erlang distribution.
-if test x${IS_WINDOWS} = xTRUE; then
- AC_SUBST([locallibbindir], [${prefix}/bin])
- AC_SUBST([localerlanglibdir], [${libdir}])
-else
- AC_SUBST([locallibbindir], [${locallibdir}/bin])
- AC_SUBST([localerlanglibdir], [${locallibdir}/erlang/lib])
-fi
-
-# fix for older autotools that don't define "abs_top_YYY" by default
-AC_SUBST(abs_top_srcdir)
-AC_SUBST(abs_top_builddir)
-
-AC_REVISION([LOCAL_VERSION])
-
-AC_CONFIG_FILES([Makefile])
-AC_CONFIG_FILES([bin/couchjs.tpl])
-AC_CONFIG_FILES([bin/couchdb.tpl])
-AC_CONFIG_FILES([bin/couchdb.bat.tpl])
-AC_CONFIG_FILES([bin/Makefile])
-AC_CONFIG_FILES([etc/couchdb/Makefile])
-AC_CONFIG_FILES([etc/couchdb/default.ini.tpl])
-AC_CONFIG_FILES([etc/default/Makefile])
-AC_CONFIG_FILES([etc/init/couchdb.tpl])
-AC_CONFIG_FILES([etc/init/Makefile])
-AC_CONFIG_FILES([etc/launchd/org.apache.couchdb.plist.tpl])
-AC_CONFIG_FILES([etc/launchd/Makefile])
-AC_CONFIG_FILES([etc/logrotate.d/couchdb.tpl])
-AC_CONFIG_FILES([etc/logrotate.d/Makefile])
-AC_CONFIG_FILES([etc/windows/Makefile])
-AC_CONFIG_FILES([etc/Makefile])
-AC_CONFIG_FILES([share/Makefile])
-AC_CONFIG_FILES([src/Makefile])
-AC_CONFIG_FILES([src/couchdb/couch.app.tpl])
-AC_CONFIG_FILES([src/couchdb/Makefile])
-AC_CONFIG_FILES([src/couchdb/priv/Makefile])
-AC_CONFIG_FILES([src/erlang-oauth/Makefile])
-AC_CONFIG_FILES([src/etap/Makefile])
-AC_CONFIG_FILES([src/ibrowse/Makefile])
-AC_CONFIG_FILES([src/mochiweb/Makefile])
-AC_CONFIG_FILES([test/Makefile])
-AC_CONFIG_FILES([test/bench/Makefile])
-AC_CONFIG_FILES([test/etap/Makefile])
-AC_CONFIG_FILES([test/etap/test_util.erl])
-AC_CONFIG_FILES([test/javascript/Makefile])
-AC_CONFIG_FILES([test/view_server/Makefile])
-AC_CONFIG_FILES([utils/Makefile])
-AC_CONFIG_FILES([var/Makefile])
-
-AC_OUTPUT
-
-# *sob* - on Windows libtool fails as 'libname_spec' isn't correct (it
-# expects GNU style lib names). I can't work out how to configure this
-# option sanely, so we pass the script through sed to modify it.
-# Also, the erlang cc.sh script doesn't cope well with the '-link' command
-# line option libtool provides.
-# PLEASE, someone help put this out of its misery!!
-# This hackery is being tracked via COUCHDB-440.
-if test x${IS_WINDOWS} = xTRUE; then
- sed -e 's,libname_spec="lib\\$name",libname_spec="\\\$name",' \
- -e 's,-link,,' \
- < libtool > libtool.tmp
- mv libtool.tmp libtool
- # probably would chmod +x if we weren't on windows...
-fi
-
-echo
-echo "You have configured Apache CouchDB, time to relax."
-echo
-echo "Run \`make && sudo make install' to install."
diff --git a/test/etap/172-os-daemon-errors.1.sh b/couchjs/SConstruct
index 345c8b40..2b57cb41 100644
--- a/test/etap/172-os-daemon-errors.1.sh
+++ b/couchjs/SConstruct
@@ -1,5 +1,5 @@
-#!/bin/sh -e
-#
+# Copyright 2010 Cloudant
+#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
@@ -11,7 +11,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-#
-# Please do not make this file executable as that's the error being tested.
-sleep 5
+SConscript(['c_src/SConscript'], variant_dir='build')
+SConscript(['js/SConscript'])
diff --git a/couchjs/c_src/SConscript b/couchjs/c_src/SConscript
new file mode 100644
index 00000000..cfce5605
--- /dev/null
+++ b/couchjs/c_src/SConscript
@@ -0,0 +1,75 @@
+# Copyright 2010 Cloudant
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+import os
+import commands
+
+def require_lib(name):
+ if not conf.CheckLib(name):
+ print 'Could not find required library', name
+ Exit(1)
+
+env = Environment(CCFLAGS='-g -O2 -DXP_UNIX')
+
+if os.uname()[0] == 'SunOS':
+ env['CC'] = '/usr/sfw/bin/gcc'
+ env['CCFLAGS'] += ' -I/opt/local/include'
+ env.Append(LINKFLAGS=['-L/opt/local/lib'])
+
+if os.uname()[0] == 'FreeBSD':
+ env['CCFLAGS'] += ' -I/usr/local/include'
+ env.Append(LINKFLAGS=['-L/usr/local/lib'])
+ env['LIB_DL'] = env['LIB_RT'] = ''
+ env['LIB_COMPAT'] = 'compat'
+
+if os.path.exists('/usr/bin/pkg-config'):
+ (status, output) = commands.getstatusoutput("/usr/bin/pkg-config mozilla-js --cflags")
+ if status == 0:
+ env['CCFLAGS'] += output
+ (status, output) = commands.getstatusoutput("/usr/bin/pkg-config mozilla-js --libs-only-L")
+ if status == 0:
+ env.Append(LINKFLAGS=output)
+
+if not env.GetOption('clean'):
+ conf = Configure(env, config_h='config.h')
+
+ require_lib('m')
+ require_lib('pthread')
+ require_lib('curl')
+
+ ## check for SpiderMonkey development header
+ if conf.CheckHeader('js/jsapi.h'):
+ jsapi = 'js/jsapi.h'
+ elif conf.CheckHeader('mozjs/jsapi.h'):
+ jsapi = 'mozjs/jsapi.h'
+ elif conf.CheckHeader('jsapi.h'):
+ jsapi = 'jsapi.h'
+ else:
+ print 'Could not find jsapi.h.', \
+ 'Are Mozilla SpiderMonkey headers installed?'
+ Exit(1)
+
+ ## check for SpiderMonkey library as libjs or libmozjs
+ if not conf.CheckLibWithHeader('mozjs', jsapi, 'c', autoadd=1):
+ if not conf.CheckLibWithHeader('js', jsapi, 'c', autoadd=1):
+ print 'Could not find JS library.', \
+ 'Is Mozilla SpiderMonkey installed?'
+ Exit(1)
+
+ ## SpiderMonkey 1.8 has this callback we use for memory management
+ if conf.CheckDeclaration('JS_SetOperationCallback', '#include <%s>' % jsapi):
+ conf.Define('USE_JS_SETOPCB')
+
+ env = conf.Finish()
+
+env.Program('couchjs', ['main.c', 'http.c', 'utf8.c'])
diff --git a/src/couchdb/priv/couch_js/http.c b/couchjs/c_src/http.c
index 6c2a8a82..b781f0ef 100644
--- a/src/couchdb/priv/couch_js/http.c
+++ b/couchjs/c_src/http.c
@@ -13,7 +13,16 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+
+#include "config.h"
+#ifdef HAVE_JS_JSAPI_H
+#include <js/jsapi.h>
+#elif HAVE_MOZJS_JSAPI_H
+#include <mozjs/jsapi.h>
+#else
#include <jsapi.h>
+#endif
+
#include <curl/curl.h>
#include "utf8.h"
@@ -72,7 +81,7 @@ constructor(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval)
JS_ReportError(cx, "Failed to set private CouchHTTP data.");
goto error;
}
-
+
ret = JS_TRUE;
goto success;
@@ -101,7 +110,7 @@ destructor(JSContext* cx, JSObject* obj)
static JSBool
open(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval)
-{
+{
HTTPData* http = (HTTPData*) JS_GetPrivate(cx, obj);
char* method = NULL;
char* url = NULL;
@@ -126,12 +135,12 @@ open(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval)
JS_ReportError(cx, "Failed to encode method.");
goto done;
}
-
+
for(methid = 0; METHODS[methid] != NULL; methid++)
{
if(strcasecmp(METHODS[methid], method) == 0) break;
}
-
+
if(methid > COPY)
{
JS_ReportError(cx, "Invalid method specified.");
@@ -158,19 +167,19 @@ open(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval)
JS_ReportError(cx, "Failed to encode URL.");
goto done;
}
-
+
if(argv[2] != JSVAL_VOID && argv[2] != JSVAL_FALSE)
{
JS_ReportError(cx, "Synchronous flag must be false if specified.");
goto done;
}
-
+
if(http->req_headers)
{
curl_slist_free_all(http->req_headers);
http->req_headers = NULL;
}
-
+
// Disable Expect: 100-continue
http->req_headers = curl_slist_append(http->req_headers, "Expect:");
@@ -183,7 +192,7 @@ done:
static JSBool
setheader(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval)
-{
+{
HTTPData* http = (HTTPData*) JS_GetPrivate(cx, obj);
char* keystr = NULL;
char* valstr = NULL;
@@ -209,20 +218,20 @@ setheader(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval)
JS_ReportError(cx, "Failed to encode header name.");
goto done;
}
-
+
if(argv[1] == JSVAL_VOID)
{
JS_ReportError(cx, "You must specify a header value.");
goto done;
}
-
+
valstr = enc_string(cx, argv[1], NULL);
if(!valstr)
{
JS_ReportError(cx, "Failed to encode header value.");
goto done;
}
-
+
hdrlen = strlen(keystr) + strlen(valstr) + 3;
hdrbuf = (char*) malloc(hdrlen * sizeof(char));
if(!hdrbuf)
@@ -230,7 +239,7 @@ setheader(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval)
JS_ReportError(cx, "Failed to allocate header buffer.");
goto done;
}
-
+
snprintf(hdrbuf, hdrlen, "%s: %s", keystr, valstr);
http->req_headers = curl_slist_append(http->req_headers, hdrbuf);
@@ -251,7 +260,7 @@ sendreq(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval)
char* body = NULL;
size_t bodylen = 0;
JSBool ret = JS_FALSE;
-
+
if(!http)
{
JS_ReportError(cx, "Invalid CouchHTTP instance.");
@@ -279,13 +288,13 @@ static JSBool
status(JSContext* cx, JSObject* obj, jsval idval, jsval* vp)
{
HTTPData* http = (HTTPData*) JS_GetPrivate(cx, obj);
-
+
if(!http)
{
JS_ReportError(cx, "Invalid CouchHTTP instance.");
return JS_FALSE;
}
-
+
if(INT_FITS_IN_JSVAL(http->last_status))
{
*vp = INT_TO_JSVAL(http->last_status);
@@ -350,7 +359,7 @@ install_http(JSContext* cx, JSObject* glbl)
fprintf(stderr, "Failed to initialize CouchHTTP class.\n");
return NULL;
}
-
+
return klass;
}
@@ -388,10 +397,10 @@ go(JSContext* cx, JSObject* obj, HTTPData* http, char* body, size_t bodylen)
JSString* jsbody;
JSBool ret = JS_FALSE;
jsval tmp;
-
+
state.cx = cx;
state.http = http;
-
+
state.sendbuf = body;
state.sendlen = bodylen;
state.sent = 0;
@@ -415,7 +424,7 @@ go(JSContext* cx, JSObject* obj, HTTPData* http, char* body, size_t bodylen)
curl_easy_setopt(HTTP_HANDLE, CURLOPT_USERAGENT,
"CouchHTTP Client - Relax");
}
-
+
if(!HTTP_HANDLE)
{
JS_ReportError(cx, "Failed to initialize cURL handle.");
@@ -432,7 +441,7 @@ go(JSContext* cx, JSObject* obj, HTTPData* http, char* body, size_t bodylen)
curl_easy_setopt(HTTP_HANDLE, CURLOPT_NOBODY, 0);
curl_easy_setopt(HTTP_HANDLE, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(HTTP_HANDLE, CURLOPT_UPLOAD, 0);
-
+
if(http->method == HEAD)
{
curl_easy_setopt(HTTP_HANDLE, CURLOPT_NOBODY, 1);
@@ -443,10 +452,10 @@ go(JSContext* cx, JSObject* obj, HTTPData* http, char* body, size_t bodylen)
curl_easy_setopt(HTTP_HANDLE, CURLOPT_UPLOAD, 1);
curl_easy_setopt(HTTP_HANDLE, CURLOPT_FOLLOWLOCATION, 0);
}
-
+
if(body && bodylen)
{
- curl_easy_setopt(HTTP_HANDLE, CURLOPT_INFILESIZE, bodylen);
+ curl_easy_setopt(HTTP_HANDLE, CURLOPT_INFILESIZE, bodylen);
}
else
{
@@ -467,7 +476,7 @@ go(JSContext* cx, JSObject* obj, HTTPData* http, char* body, size_t bodylen)
JS_ReportError(cx, "Failed to execute HTTP request: %s", ERRBUF);
goto done;
}
-
+
if(!state.resp_headers)
{
JS_ReportError(cx, "Failed to recieve HTTP headers.");
@@ -488,7 +497,7 @@ go(JSContext* cx, JSObject* obj, HTTPData* http, char* body, size_t bodylen)
JS_ReportError(cx, "INTERNAL: Failed to set response headers.");
goto done;
}
-
+
if(state.recvbuf) // Is good enough?
{
state.recvbuf[state.read] = '\0';
@@ -512,7 +521,7 @@ go(JSContext* cx, JSObject* obj, HTTPData* http, char* body, size_t bodylen)
{
tmp = JS_GetEmptyStringValue(cx);
}
-
+
if(!JS_DefineProperty(
cx,
obj,
@@ -526,7 +535,7 @@ go(JSContext* cx, JSObject* obj, HTTPData* http, char* body, size_t bodylen)
JS_ReportError(cx, "INTERNAL: Failed to set responseText.");
goto done;
}
-
+
ret = JS_TRUE;
done:
@@ -576,7 +585,7 @@ recv_header(void *ptr, size_t size, size_t nmem, void *data)
JSString* hdr = NULL;
jsuint hdrlen;
jsval hdrval;
-
+
if(length > 7 && strncasecmp(header, "HTTP/1.", 7) == 0)
{
if(length < 12)
@@ -630,14 +639,14 @@ recv_body(void *ptr, size_t size, size_t nmem, void *data)
CurlState* state = (CurlState*) data;
size_t length = size * nmem;
char* tmp = NULL;
-
+
if(!state->recvbuf)
{
state->recvlen = 4096;
state->read = 0;
state->recvbuf = JS_malloc(state->cx, state->recvlen);
}
-
+
if(!state->recvbuf)
{
return CURLE_WRITE_ERROR;
@@ -648,7 +657,7 @@ recv_body(void *ptr, size_t size, size_t nmem, void *data)
tmp = JS_realloc(state->cx, state->recvbuf, state->recvlen);
if(!tmp) return CURLE_WRITE_ERROR;
state->recvbuf = tmp;
-
+
memcpy(state->recvbuf + state->read, ptr, length);
state->read += length;
return length;
diff --git a/src/couchdb/priv/couch_js/http.h b/couchjs/c_src/http.h
index b5f8c70f..b5f8c70f 100644
--- a/src/couchdb/priv/couch_js/http.h
+++ b/couchjs/c_src/http.h
diff --git a/src/couchdb/priv/couch_js/main.c b/couchjs/c_src/main.c
index 376aa15b..25acaf55 100644
--- a/src/couchdb/priv/couch_js/main.c
+++ b/couchjs/c_src/main.c
@@ -13,8 +13,15 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <jsapi.h>
+
#include "config.h"
+#ifdef HAVE_JS_JSAPI_H
+#include <js/jsapi.h>
+#elif HAVE_MOZJS_JSAPI_H
+#include <mozjs/jsapi.h>
+#else
+#include <jsapi.h>
+#endif
#include "utf8.h"
#include "http.h"
@@ -76,7 +83,7 @@ evalcx(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
JS_EvaluateUCScript(subcx, sandbox, src, srclen, NULL, 0, rval);
}
-
+
ret = JS_TRUE;
done:
@@ -130,7 +137,7 @@ readfp(JSContext* cx, FILE* fp, size_t* buflen)
bytes = JS_malloc(cx, byteslen);
if(bytes == NULL) return NULL;
-
+
while((readlen = js_fgets(bytes+used, byteslen-used, stdin)) > 0)
{
used += readlen;
@@ -169,7 +176,7 @@ readline(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
bytes = readfp(cx, stdin, &byteslen);
if(!bytes) return JS_FALSE;
-
+
/* Treat the empty string specially */
if(byteslen == 0)
{
@@ -186,7 +193,7 @@ readline(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
return JS_FALSE;
}
bytes = tmp;
-
+
str = dec_string(cx, bytes, byteslen);
JS_free(cx, bytes);
@@ -279,7 +286,7 @@ main(int argc, const char * argv[])
JSObject* global = NULL;
JSFunctionSpec* sp = NULL;
int i = 0;
-
+
rt = JS_NewRuntime(64L * 1024L * 1024L);
if (!rt) return 1;
@@ -288,13 +295,13 @@ main(int argc, const char * argv[])
JS_SetErrorReporter(cx, printerror);
JS_ToggleOptions(cx, JSOPTION_XML);
-
+
SETUP_REQUEST(cx);
global = JS_NewObject(cx, &global_class, NULL, NULL);
if (!global) return 1;
if (!JS_InitStandardClasses(cx, global)) return 1;
-
+
for(sp = global_functions; sp->name != NULL; sp++)
{
if(!JS_DefineFunction(cx, global,
@@ -309,7 +316,7 @@ main(int argc, const char * argv[])
{
return 1;
}
-
+
JS_SetGlobalObject(cx, global);
if(argc > 2)
diff --git a/src/couchdb/priv/couch_js/utf8.c b/couchjs/c_src/utf8.c
index 699a6fee..57928ba9 100644
--- a/src/couchdb/priv/couch_js/utf8.c
+++ b/couchjs/c_src/utf8.c
@@ -10,7 +10,14 @@
// License for the specific language governing permissions and limitations under
// the License.
+#include "config.h"
+#ifdef HAVE_JS_JSAPI_H
+#include <js/jsapi.h>
+#elif HAVE_MOZJS_JSAPI_H
+#include <mozjs/jsapi.h>
+#else
#include <jsapi.h>
+#endif
static int
enc_char(uint8 *utf8Buffer, uint32 ucs4Char)
@@ -66,7 +73,7 @@ enc_charbuf(const jschar* src, size_t srclen, char* dst, size_t* dstlenp)
srclen--;
if((c >= 0xDC00) && (c <= 0xDFFF)) goto bad_surrogate;
-
+
if(c < 0xD800 || c > 0xDBFF)
{
v = c;
@@ -104,7 +111,7 @@ enc_charbuf(const jschar* src, size_t srclen, char* dst, size_t* dstlenp)
}
dstlen -= utf8Len;
}
-
+
*dstlenp = (origDstlen - dstlen);
return JS_TRUE;
@@ -125,7 +132,7 @@ enc_string(JSContext* cx, jsval arg, size_t* buflen)
char* bytes = NULL;
size_t srclen = 0;
size_t byteslen = 0;
-
+
str = JS_ValueToString(cx, arg);
if(!str) goto error;
@@ -133,10 +140,10 @@ enc_string(JSContext* cx, jsval arg, size_t* buflen)
srclen = JS_GetStringLength(str);
if(!enc_charbuf(src, srclen, NULL, &byteslen)) goto error;
-
+
bytes = JS_malloc(cx, (byteslen) + 1);
bytes[byteslen] = 0;
-
+
if(!enc_charbuf(src, srclen, bytes, &byteslen)) goto error;
if(buflen) *buflen = byteslen;
@@ -198,17 +205,17 @@ dec_charbuf(const char *src, size_t srclen, jschar *dst, size_t *dstlenp)
{
v = (uint8) *src;
n = 1;
-
+
if(v & 0x80)
{
while(v & (0x80 >> n))
{
n++;
}
-
+
if(n > srclen) goto buffer_too_small;
if(n == 1 || n > 6) goto bad_character;
-
+
for(j = 1; j < n; j++)
{
if((src[j] & 0xC0) != 0x80) goto bad_character;
@@ -218,13 +225,13 @@ dec_charbuf(const char *src, size_t srclen, jschar *dst, size_t *dstlenp)
if(v >= 0x10000)
{
v -= 0x10000;
-
+
if(v > 0xFFFFF || dstlen < 2)
{
*dstlenp = (origDstlen - dstlen);
return JS_FALSE;
}
-
+
if(dstlen < 2) goto buffer_too_small;
if(dst)
@@ -263,7 +270,7 @@ dec_string(JSContext* cx, const char* bytes, size_t byteslen)
JSString* str = NULL;
jschar* chars = NULL;
size_t charslen;
-
+
if(!dec_charbuf(bytes, byteslen, NULL, &charslen)) goto error;
chars = JS_malloc(cx, (charslen + 1) * sizeof(jschar));
@@ -283,4 +290,4 @@ error:
success:
return str;
-} \ No newline at end of file
+}
diff --git a/src/couchdb/priv/couch_js/utf8.h b/couchjs/c_src/utf8.h
index 00f6b736..00f6b736 100644
--- a/src/couchdb/priv/couch_js/utf8.h
+++ b/couchjs/c_src/utf8.h
diff --git a/test/etap/172-os-daemon-errors.2.sh b/couchjs/js/SConscript
index 256ee793..e403a0f7 100755..100644
--- a/test/etap/172-os-daemon-errors.2.sh
+++ b/couchjs/js/SConscript
@@ -1,5 +1,5 @@
-#!/bin/sh -e
-#
+# Copyright 2010 Cloudant
+#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
@@ -12,4 +12,12 @@
# License for the specific language governing permissions and limitations under
# the License.
-exit 1
+env = Environment()
+env['BUILDERS']['Cat'] = Builder(action = '''
+ echo "// DO NOT EDIT THIS FILE BY HAND\\n" > $TARGET && \
+ cat $SOURCES >> $TARGET
+''')
+
+## don't Glob() because loop.js must come last
+env.Cat('../build/main.js', ['json2.js', 'filter.js', 'mimeparse.js',
+ 'render.js', 'state.js', 'util.js', 'validate.js', 'views.js', 'loop.js'])
diff --git a/share/server/filter.js b/couchjs/js/filter.js
index 1e8556a4..1e8556a4 100644
--- a/share/server/filter.js
+++ b/couchjs/js/filter.js
diff --git a/share/server/json2.js b/couchjs/js/json2.js
index a1a3b170..a1a3b170 100644
--- a/share/server/json2.js
+++ b/couchjs/js/json2.js
diff --git a/share/server/loop.js b/couchjs/js/loop.js
index d2a07f61..d2a07f61 100644
--- a/share/server/loop.js
+++ b/couchjs/js/loop.js
diff --git a/share/server/mimeparse.js b/couchjs/js/mimeparse.js
index 3642a194..3642a194 100644
--- a/share/server/mimeparse.js
+++ b/couchjs/js/mimeparse.js
diff --git a/share/server/render.js b/couchjs/js/render.js
index d207db41..d207db41 100644
--- a/share/server/render.js
+++ b/couchjs/js/render.js
diff --git a/share/server/state.js b/couchjs/js/state.js
index e6416382..e6416382 100644
--- a/share/server/state.js
+++ b/couchjs/js/state.js
diff --git a/share/server/util.js b/couchjs/js/util.js
index e4386701..e4386701 100644
--- a/share/server/util.js
+++ b/couchjs/js/util.js
diff --git a/share/server/validate.js b/couchjs/js/validate.js
index 76a14129..76a14129 100644
--- a/share/server/validate.js
+++ b/couchjs/js/validate.js
diff --git a/share/server/views.js b/couchjs/js/views.js
index 2a15ee56..2a15ee56 100644
--- a/share/server/views.js
+++ b/couchjs/js/views.js
diff --git a/couchjs/scons/scons-LICENSE b/couchjs/scons/scons-LICENSE
new file mode 100644
index 00000000..790d9714
--- /dev/null
+++ b/couchjs/scons/scons-LICENSE
@@ -0,0 +1,25 @@
+ Copyright and license for SCons - a software construction tool
+
+ This copyright and license do not apply to any other software
+ with which this software may have been included.
+
+Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/couchjs/scons/scons-README b/couchjs/scons/scons-README
new file mode 100644
index 00000000..32b691cf
--- /dev/null
+++ b/couchjs/scons/scons-README
@@ -0,0 +1,204 @@
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+
+ SCons - a software construction tool
+
+This is the scons-README file for a version of SCons packaged for local
+execution--that is, execution out of a specific local directory, without
+having to install SCons as a system-wide utility.
+
+You are likely reading this file in one of the following two situations:
+
+ 1) You have unpacked an scons-local-{version} package and are
+ examining the contents.
+
+ In this case, you are presumably interested in using this
+ package to include a local copy of SCons with some other
+ software that you package, so that you can use SCons to build
+ your software without forcing all of your users to have it fully
+ installed. Instructions for this can be found below.
+
+ If you are not looking to use SCons in this way, then please
+ use either the scons-{version} package to install SCons on your
+ system, or the scons-src-{version} package if you want the full
+ source to SCons, including its packaging code and underlying
+ tests and testing infrastructure.
+
+ 2) This file was included in some other software package so that
+ the package could be built using SCons.
+
+ In this case, follow the instructions provided with the
+ rest of the software package for how to use SCons to build
+ and/or install the software. The file containing build and
+ installation instructions will typically be named README or
+ INSTALL.
+
+LATEST VERSION
+==============
+
+Before going further, you can check for the latest version of the
+scons-local package, or any SCons package, at the SCons download page:
+
+ http://www.scons.org/download.html
+
+
+EXECUTION REQUIREMENTS
+======================
+
+Running SCons requires Python version 2.4 or later. There should be
+no other dependencies or requirements to run SCons.
+
+The default SCons configuration assumes use of the Microsoft Visual C++
+compiler suite on WIN32 systems, and assumes a C compiler named 'cc',
+a C++ compiler named 'c++', and a Fortran compiler named 'g77' (such
+as found in the GNU C compiler suite) on any other type of system.
+You may, of course, override these default values by appropriate
+configuration of Environment construction variables.
+
+
+INSTALLATION
+============
+
+Installation of this package should be as simple as unpacking the
+archive (either .tar.gz or .zip) in any directory (top-level or a
+subdirectory) within the software package with which you want to ship
+SCons.
+
+Once you have installed this package, you should write an SConstruct
+file at the top level of your source tree to build your software as you
+see fit.
+
+Then modify the build/install instructions for your package to instruct
+your users to execute SCons as follows (if you installed this package in
+your top-level directory):
+
+ $ python scons.py
+
+Or (if, for example, you installed this package in a subdirectory named
+"scons"):
+
+ $ python scons/scons.py
+
+That should be all you have to do. (If it isn't that simple, please let
+us know!)
+
+
+CONTENTS OF THIS PACKAGE
+========================
+
+This scons-local package consists of the following:
+
+scons-LICENSE
+ A copy of the copyright and terms under which SCons is
+ distributed (the Open Source Initiative-approved MIT license).
+
+ A disclaimer has been added to the beginning to make clear that
+ this license applies only to SCons, and not to any separate
+ software you've written with which you're planning to package
+ SCons.
+
+scons-README
+ What you're looking at right now.
+
+scons-local-{version}/
+ The SCons build engine. This is structured as a Python
+ library.
+
+scons.py
+ The SCons script itself. The script sets up the Python
+ sys.path variable to use the build engine found in the
+ scons-local-{version}/ directory in preference to any other
+ SCons build engine installed on your system.
+
+
+DOCUMENTATION
+=============
+
+Because this package is intended to be included with other software by
+experienced users, we have not included any SCons documentation in this
+package (other than this scons-README file you're reading right now).
+
+If, however, you need documentation about SCons, then consult any of the
+following from the corresponding scons-{version} or scons-src-{version}
+package:
+
+ The RELEASE.txt file (src/RELEASE.txt file in the
+ scons-src-{version} package), which contains notes about this
+ specific release, including known problems.
+
+ The CHANGES.txt file (src/CHANGES.txt file in the
+ scons-src-{version} package), which contains a list of changes
+ since the previous release.
+
+ The scons.1 man page (doc/man/scons.1 in the scons-src-{version}
+ package), which contains a section of small examples for getting
+ started using SCons.
+
+Additional documentation for SCons is available at:
+
+ http://www.scons.org/doc.html
+
+
+LICENSING
+=========
+
+SCons is distributed under the MIT license, a full copy of which is
+available in the scons-LICENSE file in this package. The MIT license is
+an approved Open Source license, which means:
+
+ This software is OSI Certified Open Source Software. OSI
+ Certified is a certification mark of the Open Source Initiative.
+
+More information about OSI certifications and Open Source software is
+available at:
+
+ http://www.opensource.org/
+
+
+REPORTING BUGS
+==============
+
+You can report bugs either by following the "Tracker - Bugs" link
+on the SCons project page:
+
+ http://sourceforge.net/projects/scons/
+
+or by sending mail to the SCons developers mailing list:
+
+ scons-devel@lists.sourceforge.net
+
+
+MAILING LISTS
+=============
+
+A mailing list for users of SCons is available. You may send questions
+or comments to the list at:
+
+ scons-users@lists.sourceforge.net
+
+You may subscribe to the scons-users mailing list at:
+
+ http://lists.sourceforge.net/lists/listinfo/scons-users
+
+
+FOR MORE INFORMATION
+====================
+
+Check the SCons web site at:
+
+ http://www.scons.org/
+
+
+AUTHOR INFO
+===========
+
+Steven Knight
+knight at baldmt dot com
+http://www.baldmt.com/~knight/
+
+With plenty of help from the SCons Development team:
+ Chad Austin
+ Charles Crain
+ Steve Leblanc
+ Anthony Roach
+ Terrel Shumway
+
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Action.py b/couchjs/scons/scons-local-2.0.1/SCons/Action.py
new file mode 100644
index 00000000..4300dd49
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Action.py
@@ -0,0 +1,1241 @@
+"""SCons.Action
+
+This encapsulates information about executing any sort of action that
+can build one or more target Nodes (typically files) from one or more
+source Nodes (also typically files) given a specific Environment.
+
+The base class here is ActionBase. The base class supplies just a few
+OO utility methods and some generic methods for displaying information
+about an Action in response to the various commands that control printing.
+
+A second-level base class is _ActionAction. This extends ActionBase
+by providing the methods that can be used to show and perform an
+action. True Action objects will subclass _ActionAction; Action
+factory class objects will subclass ActionBase.
+
+The heavy lifting is handled by subclasses for the different types of
+actions we might execute:
+
+ CommandAction
+ CommandGeneratorAction
+ FunctionAction
+ ListAction
+
+The subclasses supply the following public interface methods used by
+other modules:
+
+ __call__()
+ THE public interface, "calling" an Action object executes the
+ command or Python function. This also takes care of printing
+ a pre-substitution command for debugging purposes.
+
+ get_contents()
+ Fetches the "contents" of an Action for signature calculation
+ plus the varlist. This is what gets MD5 checksummed to decide
+ if a target needs to be rebuilt because its action changed.
+
+ genstring()
+ Returns a string representation of the Action *without*
+ command substitution, but allows a CommandGeneratorAction to
+ generate the right action based on the specified target,
+ source and env. This is used by the Signature subsystem
+ (through the Executor) to obtain an (imprecise) representation
+ of the Action operation for informative purposes.
+
+
+Subclasses also supply the following methods for internal use within
+this module:
+
+ __str__()
+ Returns a string approximation of the Action; no variable
+ substitution is performed.
+
+ execute()
+ The internal method that really, truly, actually handles the
+ execution of a command or Python function. This is used so
+ that the __call__() methods can take care of displaying any
+ pre-substitution representations, and *then* execute an action
+ without worrying about the specific Actions involved.
+
+ get_presig()
+ Fetches the "contents" of a subclass for signature calculation.
+ The varlist is added to this to produce the Action's contents.
+
+ strfunction()
+ Returns a substituted string representation of the Action.
+ This is used by the _ActionAction.show() command to display the
+ command/function that will be executed to generate the target(s).
+
+There is a related independent ActionCaller class that looks like a
+regular Action, and which serves as a wrapper for arbitrary functions
+that we want to let the user specify the arguments to now, but actually
+execute later (when an out-of-date check determines that it's needed to
+be executed, for example). Objects of this class are returned by an
+ActionFactory class that provides a __call__() method as a convenient
+way for wrapping up the functions.
+
+"""
+
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Action.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.compat
+
+import dis
+import os
+# compat layer imports "cPickle" for us if it's available.
+import pickle
+import re
+import sys
+import subprocess
+
+from SCons.Debug import logInstanceCreation
+import SCons.Errors
+import SCons.Executor
+import SCons.Util
+import SCons.Subst
+
+# we use these a lot, so try to optimize them
+is_String = SCons.Util.is_String
+is_List = SCons.Util.is_List
+
+class _null(object):
+ pass
+
+print_actions = 1
+execute_actions = 1
+print_actions_presub = 0
+
+def rfile(n):
+ try:
+ return n.rfile()
+ except AttributeError:
+ return n
+
+def default_exitstatfunc(s):
+ return s
+
+try:
+ SET_LINENO = dis.SET_LINENO
+ HAVE_ARGUMENT = dis.HAVE_ARGUMENT
+except AttributeError:
+ remove_set_lineno_codes = lambda x: x
+else:
+ def remove_set_lineno_codes(code):
+ result = []
+ n = len(code)
+ i = 0
+ while i < n:
+ c = code[i]
+ op = ord(c)
+ if op >= HAVE_ARGUMENT:
+ if op != SET_LINENO:
+ result.append(code[i:i+3])
+ i = i+3
+ else:
+ result.append(c)
+ i = i+1
+ return ''.join(result)
+
+strip_quotes = re.compile('^[\'"](.*)[\'"]$')
+
+
+def _callable_contents(obj):
+ """Return the signature contents of a callable Python object.
+ """
+ try:
+ # Test if obj is a method.
+ return _function_contents(obj.im_func)
+
+ except AttributeError:
+ try:
+ # Test if obj is a callable object.
+ return _function_contents(obj.__call__.im_func)
+
+ except AttributeError:
+ try:
+ # Test if obj is a code object.
+ return _code_contents(obj)
+
+ except AttributeError:
+ # Test if obj is a function object.
+ return _function_contents(obj)
+
+
+def _object_contents(obj):
+ """Return the signature contents of any Python object.
+
+ We have to handle the case where object contains a code object
+ since it can be pickled directly.
+ """
+ try:
+ # Test if obj is a method.
+ return _function_contents(obj.im_func)
+
+ except AttributeError:
+ try:
+ # Test if obj is a callable object.
+ return _function_contents(obj.__call__.im_func)
+
+ except AttributeError:
+ try:
+ # Test if obj is a code object.
+ return _code_contents(obj)
+
+ except AttributeError:
+ try:
+ # Test if obj is a function object.
+ return _function_contents(obj)
+
+ except AttributeError:
+ # Should be a pickable Python object.
+ try:
+ return pickle.dumps(obj)
+ except (pickle.PicklingError, TypeError):
+ # This is weird, but it seems that nested classes
+ # are unpickable. The Python docs say it should
+ # always be a PicklingError, but some Python
+ # versions seem to return TypeError. Just do
+ # the best we can.
+ return str(obj)
+
+
+def _code_contents(code):
+ """Return the signature contents of a code object.
+
+ By providing direct access to the code object of the
+ function, Python makes this extremely easy. Hooray!
+
+ Unfortunately, older versions of Python include line
+ number indications in the compiled byte code. Boo!
+ So we remove the line number byte codes to prevent
+ recompilations from moving a Python function.
+ """
+
+ contents = []
+
+ # The code contents depends on the number of local variables
+ # but not their actual names.
+ contents.append("%s,%s" % (code.co_argcount, len(code.co_varnames)))
+ try:
+ contents.append(",%s,%s" % (len(code.co_cellvars), len(code.co_freevars)))
+ except AttributeError:
+ # Older versions of Python do not support closures.
+ contents.append(",0,0")
+
+ # The code contents depends on any constants accessed by the
+ # function. Note that we have to call _object_contents on each
+ # constants because the code object of nested functions can
+ # show-up among the constants.
+ #
+ # Note that we also always ignore the first entry of co_consts
+ # which contains the function doc string. We assume that the
+ # function does not access its doc string.
+ contents.append(',(' + ','.join(map(_object_contents,code.co_consts[1:])) + ')')
+
+ # The code contents depends on the variable names used to
+ # accessed global variable, as changing the variable name changes
+ # the variable actually accessed and therefore changes the
+ # function result.
+ contents.append(',(' + ','.join(map(_object_contents,code.co_names)) + ')')
+
+
+ # The code contents depends on its actual code!!!
+ contents.append(',(' + str(remove_set_lineno_codes(code.co_code)) + ')')
+
+ return ''.join(contents)
+
+
+def _function_contents(func):
+ """Return the signature contents of a function."""
+
+ contents = [_code_contents(func.func_code)]
+
+ # The function contents depends on the value of defaults arguments
+ if func.func_defaults:
+ contents.append(',(' + ','.join(map(_object_contents,func.func_defaults)) + ')')
+ else:
+ contents.append(',()')
+
+ # The function contents depends on the closure captured cell values.
+ try:
+ closure = func.func_closure or []
+ except AttributeError:
+ # Older versions of Python do not support closures.
+ closure = []
+
+ #xxx = [_object_contents(x.cell_contents) for x in closure]
+ try:
+ xxx = [_object_contents(x.cell_contents) for x in closure]
+ except AttributeError:
+ xxx = []
+ contents.append(',(' + ','.join(xxx) + ')')
+
+ return ''.join(contents)
+
+
+def _actionAppend(act1, act2):
+ # This function knows how to slap two actions together.
+ # Mainly, it handles ListActions by concatenating into
+ # a single ListAction.
+ a1 = Action(act1)
+ a2 = Action(act2)
+ if a1 is None or a2 is None:
+ raise TypeError("Cannot append %s to %s" % (type(act1), type(act2)))
+ if isinstance(a1, ListAction):
+ if isinstance(a2, ListAction):
+ return ListAction(a1.list + a2.list)
+ else:
+ return ListAction(a1.list + [ a2 ])
+ else:
+ if isinstance(a2, ListAction):
+ return ListAction([ a1 ] + a2.list)
+ else:
+ return ListAction([ a1, a2 ])
+
+def _do_create_keywords(args, kw):
+ """This converts any arguments after the action argument into
+ their equivalent keywords and adds them to the kw argument.
+ """
+ v = kw.get('varlist', ())
+ # prevent varlist="FOO" from being interpreted as ['F', 'O', 'O']
+ if is_String(v): v = (v,)
+ kw['varlist'] = tuple(v)
+ if args:
+ # turn positional args into equivalent keywords
+ cmdstrfunc = args[0]
+ if cmdstrfunc is None or is_String(cmdstrfunc):
+ kw['cmdstr'] = cmdstrfunc
+ elif callable(cmdstrfunc):
+ kw['strfunction'] = cmdstrfunc
+ else:
+ raise SCons.Errors.UserError(
+ 'Invalid command display variable type. '
+ 'You must either pass a string or a callback which '
+ 'accepts (target, source, env) as parameters.')
+ if len(args) > 1:
+ kw['varlist'] = args[1:] + kw['varlist']
+ if kw.get('strfunction', _null) is not _null \
+ and kw.get('cmdstr', _null) is not _null:
+ raise SCons.Errors.UserError(
+ 'Cannot have both strfunction and cmdstr args to Action()')
+
+def _do_create_action(act, kw):
+ """This is the actual "implementation" for the
+ Action factory method, below. This handles the
+ fact that passing lists to Action() itself has
+ different semantics than passing lists as elements
+ of lists.
+
+ The former will create a ListAction, the latter
+ will create a CommandAction by converting the inner
+ list elements to strings."""
+
+ if isinstance(act, ActionBase):
+ return act
+
+ if is_List(act):
+ return CommandAction(act, **kw)
+
+ if callable(act):
+ try:
+ gen = kw['generator']
+ del kw['generator']
+ except KeyError:
+ gen = 0
+ if gen:
+ action_type = CommandGeneratorAction
+ else:
+ action_type = FunctionAction
+ return action_type(act, kw)
+
+ if is_String(act):
+ var=SCons.Util.get_environment_var(act)
+ if var:
+ # This looks like a string that is purely an Environment
+ # variable reference, like "$FOO" or "${FOO}". We do
+ # something special here...we lazily evaluate the contents
+ # of that Environment variable, so a user could put something
+ # like a function or a CommandGenerator in that variable
+ # instead of a string.
+ return LazyAction(var, kw)
+ commands = str(act).split('\n')
+ if len(commands) == 1:
+ return CommandAction(commands[0], **kw)
+ # The list of string commands may include a LazyAction, so we
+ # reprocess them via _do_create_list_action.
+ return _do_create_list_action(commands, kw)
+ return None
+
+def _do_create_list_action(act, kw):
+ """A factory for list actions. Convert the input list into Actions
+ and then wrap them in a ListAction."""
+ acts = []
+ for a in act:
+ aa = _do_create_action(a, kw)
+ if aa is not None: acts.append(aa)
+ if not acts:
+ return ListAction([])
+ elif len(acts) == 1:
+ return acts[0]
+ else:
+ return ListAction(acts)
+
+def Action(act, *args, **kw):
+ """A factory for action objects."""
+ # Really simple: the _do_create_* routines do the heavy lifting.
+ _do_create_keywords(args, kw)
+ if is_List(act):
+ return _do_create_list_action(act, kw)
+ return _do_create_action(act, kw)
+
+class ActionBase(object):
+ """Base class for all types of action objects that can be held by
+ other objects (Builders, Executors, etc.) This provides the
+ common methods for manipulating and combining those actions."""
+
+ def __cmp__(self, other):
+ return cmp(self.__dict__, other)
+
+ def no_batch_key(self, env, target, source):
+ return None
+
+ batch_key = no_batch_key
+
+ def genstring(self, target, source, env):
+ return str(self)
+
+ def get_contents(self, target, source, env):
+ result = [ self.get_presig(target, source, env) ]
+ # This should never happen, as the Action() factory should wrap
+ # the varlist, but just in case an action is created directly,
+ # we duplicate this check here.
+ vl = self.get_varlist(target, source, env)
+ if is_String(vl): vl = (vl,)
+ for v in vl:
+ result.append(env.subst('${'+v+'}'))
+ return ''.join(result)
+
+ def __add__(self, other):
+ return _actionAppend(self, other)
+
+ def __radd__(self, other):
+ return _actionAppend(other, self)
+
+ def presub_lines(self, env):
+ # CommandGeneratorAction needs a real environment
+ # in order to return the proper string here, since
+ # it may call LazyAction, which looks up a key
+ # in that env. So we temporarily remember the env here,
+ # and CommandGeneratorAction will use this env
+ # when it calls its _generate method.
+ self.presub_env = env
+ lines = str(self).split('\n')
+ self.presub_env = None # don't need this any more
+ return lines
+
+ def get_varlist(self, target, source, env, executor=None):
+ return self.varlist
+
+ def get_targets(self, env, executor):
+ """
+ Returns the type of targets ($TARGETS, $CHANGED_TARGETS) used
+ by this action.
+ """
+ return self.targets
+
+class _ActionAction(ActionBase):
+ """Base class for actions that create output objects."""
+ def __init__(self, cmdstr=_null, strfunction=_null, varlist=(),
+ presub=_null, chdir=None, exitstatfunc=None,
+ batch_key=None, targets='$TARGETS',
+ **kw):
+ self.cmdstr = cmdstr
+ if strfunction is not _null:
+ if strfunction is None:
+ self.cmdstr = None
+ else:
+ self.strfunction = strfunction
+ self.varlist = varlist
+ self.presub = presub
+ self.chdir = chdir
+ if not exitstatfunc:
+ exitstatfunc = default_exitstatfunc
+ self.exitstatfunc = exitstatfunc
+
+ self.targets = targets
+
+ if batch_key:
+ if not callable(batch_key):
+ # They have set batch_key, but not to their own
+ # callable. The default behavior here will batch
+ # *all* targets+sources using this action, separated
+ # for each construction environment.
+ def default_batch_key(self, env, target, source):
+ return (id(self), id(env))
+ batch_key = default_batch_key
+ SCons.Util.AddMethod(self, batch_key, 'batch_key')
+
+ def print_cmd_line(self, s, target, source, env):
+ sys.stdout.write(s + u"\n")
+
+ def __call__(self, target, source, env,
+ exitstatfunc=_null,
+ presub=_null,
+ show=_null,
+ execute=_null,
+ chdir=_null,
+ executor=None):
+ if not is_List(target):
+ target = [target]
+ if not is_List(source):
+ source = [source]
+
+ if presub is _null:
+ presub = self.presub
+ if presub is _null:
+ presub = print_actions_presub
+ if exitstatfunc is _null: exitstatfunc = self.exitstatfunc
+ if show is _null: show = print_actions
+ if execute is _null: execute = execute_actions
+ if chdir is _null: chdir = self.chdir
+ save_cwd = None
+ if chdir:
+ save_cwd = os.getcwd()
+ try:
+ chdir = str(chdir.abspath)
+ except AttributeError:
+ if not is_String(chdir):
+ if executor:
+ chdir = str(executor.batches[0].targets[0].dir)
+ else:
+ chdir = str(target[0].dir)
+ if presub:
+ if executor:
+ target = executor.get_all_targets()
+ source = executor.get_all_sources()
+ t = ' and '.join(map(str, target))
+ l = '\n '.join(self.presub_lines(env))
+ out = u"Building %s with action:\n %s\n" % (t, l)
+ sys.stdout.write(out)
+ cmd = None
+ if show and self.strfunction:
+ if executor:
+ target = executor.get_all_targets()
+ source = executor.get_all_sources()
+ try:
+ cmd = self.strfunction(target, source, env, executor)
+ except TypeError:
+ cmd = self.strfunction(target, source, env)
+ if cmd:
+ if chdir:
+ cmd = ('os.chdir(%s)\n' % repr(chdir)) + cmd
+ try:
+ get = env.get
+ except AttributeError:
+ print_func = self.print_cmd_line
+ else:
+ print_func = get('PRINT_CMD_LINE_FUNC')
+ if not print_func:
+ print_func = self.print_cmd_line
+ print_func(cmd, target, source, env)
+ stat = 0
+ if execute:
+ if chdir:
+ os.chdir(chdir)
+ try:
+ stat = self.execute(target, source, env, executor=executor)
+ if isinstance(stat, SCons.Errors.BuildError):
+ s = exitstatfunc(stat.status)
+ if s:
+ stat.status = s
+ else:
+ stat = s
+ else:
+ stat = exitstatfunc(stat)
+ finally:
+ if save_cwd:
+ os.chdir(save_cwd)
+ if cmd and save_cwd:
+ print_func('os.chdir(%s)' % repr(save_cwd), target, source, env)
+
+ return stat
+
+
+def _string_from_cmd_list(cmd_list):
+ """Takes a list of command line arguments and returns a pretty
+ representation for printing."""
+ cl = []
+ for arg in map(str, cmd_list):
+ if ' ' in arg or '\t' in arg:
+ arg = '"' + arg + '"'
+ cl.append(arg)
+ return ' '.join(cl)
+
+# A fiddlin' little function that has an 'import SCons.Environment' which
+# can't be moved to the top level without creating an import loop. Since
+# this import creates a local variable named 'SCons', it blocks access to
+# the global variable, so we move it here to prevent complaints about local
+# variables being used uninitialized.
+default_ENV = None
+def get_default_ENV(env):
+ global default_ENV
+ try:
+ return env['ENV']
+ except KeyError:
+ if not default_ENV:
+ import SCons.Environment
+ # This is a hideously expensive way to get a default shell
+ # environment. What it really should do is run the platform
+ # setup to get the default ENV. Fortunately, it's incredibly
+ # rare for an Environment not to have a shell environment, so
+ # we're not going to worry about it overmuch.
+ default_ENV = SCons.Environment.Environment()['ENV']
+ return default_ENV
+
+# This function is still in draft mode. We're going to need something like
+# it in the long run as more and more places use subprocess, but I'm sure
+# it'll have to be tweaked to get the full desired functionality.
+# one special arg (so far?), 'error', to tell what to do with exceptions.
+def _subproc(scons_env, cmd, error = 'ignore', **kw):
+ """Do common setup for a subprocess.Popen() call"""
+ # allow std{in,out,err} to be "'devnull'"
+ io = kw.get('stdin')
+ if is_String(io) and io == 'devnull':
+ kw['stdin'] = open(os.devnull)
+ io = kw.get('stdout')
+ if is_String(io) and io == 'devnull':
+ kw['stdout'] = open(os.devnull, 'w')
+ io = kw.get('stderr')
+ if is_String(io) and io == 'devnull':
+ kw['stderr'] = open(os.devnull, 'w')
+
+ # Figure out what shell environment to use
+ ENV = kw.get('env', None)
+ if ENV is None: ENV = get_default_ENV(scons_env)
+
+ # Ensure that the ENV values are all strings:
+ new_env = {}
+ for key, value in ENV.items():
+ if is_List(value):
+ # If the value is a list, then we assume it is a path list,
+ # because that's a pretty common list-like value to stick
+ # in an environment variable:
+ value = SCons.Util.flatten_sequence(value)
+ new_env[key] = os.pathsep.join(map(str, value))
+ else:
+ # It's either a string or something else. If it's a string,
+ # we still want to call str() because it might be a *Unicode*
+ # string, which makes subprocess.Popen() gag. If it isn't a
+ # string or a list, then we just coerce it to a string, which
+ # is the proper way to handle Dir and File instances and will
+ # produce something reasonable for just about everything else:
+ new_env[key] = str(value)
+ kw['env'] = new_env
+
+ try:
+ #FUTURE return subprocess.Popen(cmd, **kw)
+ return subprocess.Popen(cmd, **kw)
+ except EnvironmentError, e:
+ if error == 'raise': raise
+ # return a dummy Popen instance that only returns error
+ class dummyPopen(object):
+ def __init__(self, e): self.exception = e
+ def communicate(self): return ('','')
+ def wait(self): return -self.exception.errno
+ stdin = None
+ class f(object):
+ def read(self): return ''
+ def readline(self): return ''
+ stdout = stderr = f()
+ return dummyPopen(e)
+
+class CommandAction(_ActionAction):
+ """Class for command-execution actions."""
+ def __init__(self, cmd, **kw):
+ # Cmd can actually be a list or a single item; if it's a
+ # single item it should be the command string to execute; if a
+ # list then it should be the words of the command string to
+ # execute. Only a single command should be executed by this
+ # object; lists of commands should be handled by embedding
+ # these objects in a ListAction object (which the Action()
+ # factory above does). cmd will be passed to
+ # Environment.subst_list() for substituting environment
+ # variables.
+ if __debug__: logInstanceCreation(self, 'Action.CommandAction')
+
+ _ActionAction.__init__(self, **kw)
+ if is_List(cmd):
+ if list(filter(is_List, cmd)):
+ raise TypeError("CommandAction should be given only " \
+ "a single command")
+ self.cmd_list = cmd
+
+ def __str__(self):
+ if is_List(self.cmd_list):
+ return ' '.join(map(str, self.cmd_list))
+ return str(self.cmd_list)
+
+ def process(self, target, source, env, executor=None):
+ if executor:
+ result = env.subst_list(self.cmd_list, 0, executor=executor)
+ else:
+ result = env.subst_list(self.cmd_list, 0, target, source)
+ silent = None
+ ignore = None
+ while True:
+ try: c = result[0][0][0]
+ except IndexError: c = None
+ if c == '@': silent = 1
+ elif c == '-': ignore = 1
+ else: break
+ result[0][0] = result[0][0][1:]
+ try:
+ if not result[0][0]:
+ result[0] = result[0][1:]
+ except IndexError:
+ pass
+ return result, ignore, silent
+
+ def strfunction(self, target, source, env, executor=None):
+ if self.cmdstr is None:
+ return None
+ if self.cmdstr is not _null:
+ from SCons.Subst import SUBST_RAW
+ if executor:
+ c = env.subst(self.cmdstr, SUBST_RAW, executor=executor)
+ else:
+ c = env.subst(self.cmdstr, SUBST_RAW, target, source)
+ if c:
+ return c
+ cmd_list, ignore, silent = self.process(target, source, env, executor)
+ if silent:
+ return ''
+ return _string_from_cmd_list(cmd_list[0])
+
+ def execute(self, target, source, env, executor=None):
+ """Execute a command action.
+
+ This will handle lists of commands as well as individual commands,
+ because construction variable substitution may turn a single
+ "command" into a list. This means that this class can actually
+ handle lists of commands, even though that's not how we use it
+ externally.
+ """
+ escape_list = SCons.Subst.escape_list
+ flatten_sequence = SCons.Util.flatten_sequence
+
+ try:
+ shell = env['SHELL']
+ except KeyError:
+ raise SCons.Errors.UserError('Missing SHELL construction variable.')
+
+ try:
+ spawn = env['SPAWN']
+ except KeyError:
+ raise SCons.Errors.UserError('Missing SPAWN construction variable.')
+ else:
+ if is_String(spawn):
+ spawn = env.subst(spawn, raw=1, conv=lambda x: x)
+
+ escape = env.get('ESCAPE', lambda x: x)
+
+ ENV = get_default_ENV(env)
+
+ # Ensure that the ENV values are all strings:
+ for key, value in ENV.items():
+ if not is_String(value):
+ if is_List(value):
+ # If the value is a list, then we assume it is a
+ # path list, because that's a pretty common list-like
+ # value to stick in an environment variable:
+ value = flatten_sequence(value)
+ ENV[key] = os.pathsep.join(map(str, value))
+ else:
+ # If it isn't a string or a list, then we just coerce
+ # it to a string, which is the proper way to handle
+ # Dir and File instances and will produce something
+ # reasonable for just about everything else:
+ ENV[key] = str(value)
+
+ if executor:
+ target = executor.get_all_targets()
+ source = executor.get_all_sources()
+ cmd_list, ignore, silent = self.process(target, list(map(rfile, source)), env, executor)
+
+ # Use len() to filter out any "command" that's zero-length.
+ for cmd_line in filter(len, cmd_list):
+ # Escape the command line for the interpreter we are using.
+ cmd_line = escape_list(cmd_line, escape)
+ result = spawn(shell, escape, cmd_line[0], cmd_line, ENV)
+ if not ignore and result:
+ msg = "Error %s" % result
+ return SCons.Errors.BuildError(errstr=msg,
+ status=result,
+ action=self,
+ command=cmd_line)
+ return 0
+
+ def get_presig(self, target, source, env, executor=None):
+ """Return the signature contents of this action's command line.
+
+ This strips $(-$) and everything in between the string,
+ since those parts don't affect signatures.
+ """
+ from SCons.Subst import SUBST_SIG
+ cmd = self.cmd_list
+ if is_List(cmd):
+ cmd = ' '.join(map(str, cmd))
+ else:
+ cmd = str(cmd)
+ if executor:
+ return env.subst_target_source(cmd, SUBST_SIG, executor=executor)
+ else:
+ return env.subst_target_source(cmd, SUBST_SIG, target, source)
+
+ def get_implicit_deps(self, target, source, env, executor=None):
+ icd = env.get('IMPLICIT_COMMAND_DEPENDENCIES', True)
+ if is_String(icd) and icd[:1] == '$':
+ icd = env.subst(icd)
+ if not icd or icd in ('0', 'None'):
+ return []
+ from SCons.Subst import SUBST_SIG
+ if executor:
+ cmd_list = env.subst_list(self.cmd_list, SUBST_SIG, executor=executor)
+ else:
+ cmd_list = env.subst_list(self.cmd_list, SUBST_SIG, target, source)
+ res = []
+ for cmd_line in cmd_list:
+ if cmd_line:
+ d = str(cmd_line[0])
+ m = strip_quotes.match(d)
+ if m:
+ d = m.group(1)
+ d = env.WhereIs(d)
+ if d:
+ res.append(env.fs.File(d))
+ return res
+
+class CommandGeneratorAction(ActionBase):
+ """Class for command-generator actions."""
+ def __init__(self, generator, kw):
+ if __debug__: logInstanceCreation(self, 'Action.CommandGeneratorAction')
+ self.generator = generator
+ self.gen_kw = kw
+ self.varlist = kw.get('varlist', ())
+ self.targets = kw.get('targets', '$TARGETS')
+
+ def _generate(self, target, source, env, for_signature, executor=None):
+ # ensure that target is a list, to make it easier to write
+ # generator functions:
+ if not is_List(target):
+ target = [target]
+
+ if executor:
+ target = executor.get_all_targets()
+ source = executor.get_all_sources()
+ ret = self.generator(target=target,
+ source=source,
+ env=env,
+ for_signature=for_signature)
+ gen_cmd = Action(ret, **self.gen_kw)
+ if not gen_cmd:
+ raise SCons.Errors.UserError("Object returned from command generator: %s cannot be used to create an Action." % repr(ret))
+ return gen_cmd
+
+ def __str__(self):
+ try:
+ env = self.presub_env
+ except AttributeError:
+ env = None
+ if env is None:
+ env = SCons.Defaults.DefaultEnvironment()
+ act = self._generate([], [], env, 1)
+ return str(act)
+
+ def batch_key(self, env, target, source):
+ return self._generate(target, source, env, 1).batch_key(env, target, source)
+
+ def genstring(self, target, source, env, executor=None):
+ return self._generate(target, source, env, 1, executor).genstring(target, source, env)
+
+ def __call__(self, target, source, env, exitstatfunc=_null, presub=_null,
+ show=_null, execute=_null, chdir=_null, executor=None):
+ act = self._generate(target, source, env, 0, executor)
+ if act is None:
+ raise UserError("While building `%s': "
+ "Cannot deduce file extension from source files: %s"
+ % (repr(list(map(str, target))), repr(list(map(str, source)))))
+ return act(target, source, env, exitstatfunc, presub,
+ show, execute, chdir, executor)
+
+ def get_presig(self, target, source, env, executor=None):
+ """Return the signature contents of this action's command line.
+
+ This strips $(-$) and everything in between the string,
+ since those parts don't affect signatures.
+ """
+ return self._generate(target, source, env, 1, executor).get_presig(target, source, env)
+
+ def get_implicit_deps(self, target, source, env, executor=None):
+ return self._generate(target, source, env, 1, executor).get_implicit_deps(target, source, env)
+
+ def get_varlist(self, target, source, env, executor=None):
+ return self._generate(target, source, env, 1, executor).get_varlist(target, source, env, executor)
+
+ def get_targets(self, env, executor):
+ return self._generate(None, None, env, 1, executor).get_targets(env, executor)
+
+
+
+# A LazyAction is a kind of hybrid generator and command action for
+# strings of the form "$VAR". These strings normally expand to other
+# strings (think "$CCCOM" to "$CC -c -o $TARGET $SOURCE"), but we also
+# want to be able to replace them with functions in the construction
+# environment. Consequently, we want lazy evaluation and creation of
+# an Action in the case of the function, but that's overkill in the more
+# normal case of expansion to other strings.
+#
+# So we do this with a subclass that's both a generator *and*
+# a command action. The overridden methods all do a quick check
+# of the construction variable, and if it's a string we just call
+# the corresponding CommandAction method to do the heavy lifting.
+# If not, then we call the same-named CommandGeneratorAction method.
+# The CommandGeneratorAction methods work by using the overridden
+# _generate() method, that is, our own way of handling "generation" of
+# an action based on what's in the construction variable.
+
+class LazyAction(CommandGeneratorAction, CommandAction):
+
+ def __init__(self, var, kw):
+ if __debug__: logInstanceCreation(self, 'Action.LazyAction')
+ #FUTURE CommandAction.__init__(self, '${'+var+'}', **kw)
+ CommandAction.__init__(self, '${'+var+'}', **kw)
+ self.var = SCons.Util.to_String(var)
+ self.gen_kw = kw
+
+ def get_parent_class(self, env):
+ c = env.get(self.var)
+ if is_String(c) and not '\n' in c:
+ return CommandAction
+ return CommandGeneratorAction
+
+ def _generate_cache(self, env):
+ if env:
+ c = env.get(self.var, '')
+ else:
+ c = ''
+ gen_cmd = Action(c, **self.gen_kw)
+ if not gen_cmd:
+ raise SCons.Errors.UserError("$%s value %s cannot be used to create an Action." % (self.var, repr(c)))
+ return gen_cmd
+
+ def _generate(self, target, source, env, for_signature, executor=None):
+ return self._generate_cache(env)
+
+ def __call__(self, target, source, env, *args, **kw):
+ c = self.get_parent_class(env)
+ return c.__call__(self, target, source, env, *args, **kw)
+
+ def get_presig(self, target, source, env):
+ c = self.get_parent_class(env)
+ return c.get_presig(self, target, source, env)
+
+ def get_varlist(self, target, source, env, executor=None):
+ c = self.get_parent_class(env)
+ return c.get_varlist(self, target, source, env, executor)
+
+
+class FunctionAction(_ActionAction):
+ """Class for Python function actions."""
+
+ def __init__(self, execfunction, kw):
+ if __debug__: logInstanceCreation(self, 'Action.FunctionAction')
+
+ self.execfunction = execfunction
+ try:
+ self.funccontents = _callable_contents(execfunction)
+ except AttributeError:
+ try:
+ # See if execfunction will do the heavy lifting for us.
+ self.gc = execfunction.get_contents
+ except AttributeError:
+ # This is weird, just do the best we can.
+ self.funccontents = _object_contents(execfunction)
+
+ _ActionAction.__init__(self, **kw)
+
+ def function_name(self):
+ try:
+ return self.execfunction.__name__
+ except AttributeError:
+ try:
+ return self.execfunction.__class__.__name__
+ except AttributeError:
+ return "unknown_python_function"
+
+ def strfunction(self, target, source, env, executor=None):
+ if self.cmdstr is None:
+ return None
+ if self.cmdstr is not _null:
+ from SCons.Subst import SUBST_RAW
+ if executor:
+ c = env.subst(self.cmdstr, SUBST_RAW, executor=executor)
+ else:
+ c = env.subst(self.cmdstr, SUBST_RAW, target, source)
+ if c:
+ return c
+ def array(a):
+ def quote(s):
+ try:
+ str_for_display = s.str_for_display
+ except AttributeError:
+ s = repr(s)
+ else:
+ s = str_for_display()
+ return s
+ return '[' + ", ".join(map(quote, a)) + ']'
+ try:
+ strfunc = self.execfunction.strfunction
+ except AttributeError:
+ pass
+ else:
+ if strfunc is None:
+ return None
+ if callable(strfunc):
+ return strfunc(target, source, env)
+ name = self.function_name()
+ tstr = array(target)
+ sstr = array(source)
+ return "%s(%s, %s)" % (name, tstr, sstr)
+
+ def __str__(self):
+ name = self.function_name()
+ if name == 'ActionCaller':
+ return str(self.execfunction)
+ return "%s(target, source, env)" % name
+
+ def execute(self, target, source, env, executor=None):
+ exc_info = (None,None,None)
+ try:
+ if executor:
+ target = executor.get_all_targets()
+ source = executor.get_all_sources()
+ rsources = list(map(rfile, source))
+ try:
+ result = self.execfunction(target=target, source=rsources, env=env)
+ except KeyboardInterrupt, e:
+ raise
+ except SystemExit, e:
+ raise
+ except Exception, e:
+ result = e
+ exc_info = sys.exc_info()
+
+ if result:
+ result = SCons.Errors.convert_to_BuildError(result, exc_info)
+ result.node=target
+ result.action=self
+ try:
+ result.command=self.strfunction(target, source, env, executor)
+ except TypeError:
+ result.command=self.strfunction(target, source, env)
+
+ # FIXME: This maintains backward compatibility with respect to
+ # which type of exceptions were returned by raising an
+ # exception and which ones were returned by value. It would
+ # probably be best to always return them by value here, but
+ # some codes do not check the return value of Actions and I do
+ # not have the time to modify them at this point.
+ if (exc_info[1] and
+ not isinstance(exc_info[1],EnvironmentError)):
+ raise result
+
+ return result
+ finally:
+ # Break the cycle between the traceback object and this
+ # function stack frame. See the sys.exc_info() doc info for
+ # more information about this issue.
+ del exc_info
+
+
+ def get_presig(self, target, source, env):
+ """Return the signature contents of this callable action."""
+ try:
+ return self.gc(target, source, env)
+ except AttributeError:
+ return self.funccontents
+
+ def get_implicit_deps(self, target, source, env):
+ return []
+
+class ListAction(ActionBase):
+ """Class for lists of other actions."""
+ def __init__(self, actionlist):
+ if __debug__: logInstanceCreation(self, 'Action.ListAction')
+ def list_of_actions(x):
+ if isinstance(x, ActionBase):
+ return x
+ return Action(x)
+ self.list = list(map(list_of_actions, actionlist))
+ # our children will have had any varlist
+ # applied; we don't need to do it again
+ self.varlist = ()
+ self.targets = '$TARGETS'
+
+ def genstring(self, target, source, env):
+ return '\n'.join([a.genstring(target, source, env) for a in self.list])
+
+ def __str__(self):
+ return '\n'.join(map(str, self.list))
+
+ def presub_lines(self, env):
+ return SCons.Util.flatten_sequence(
+ [a.presub_lines(env) for a in self.list])
+
+ def get_presig(self, target, source, env):
+ """Return the signature contents of this action list.
+
+ Simple concatenation of the signatures of the elements.
+ """
+ return "".join([x.get_contents(target, source, env) for x in self.list])
+
+ def __call__(self, target, source, env, exitstatfunc=_null, presub=_null,
+ show=_null, execute=_null, chdir=_null, executor=None):
+ if executor:
+ target = executor.get_all_targets()
+ source = executor.get_all_sources()
+ for act in self.list:
+ stat = act(target, source, env, exitstatfunc, presub,
+ show, execute, chdir, executor)
+ if stat:
+ return stat
+ return 0
+
+ def get_implicit_deps(self, target, source, env):
+ result = []
+ for act in self.list:
+ result.extend(act.get_implicit_deps(target, source, env))
+ return result
+
+ def get_varlist(self, target, source, env, executor=None):
+ result = SCons.Util.OrderedDict()
+ for act in self.list:
+ for var in act.get_varlist(target, source, env, executor):
+ result[var] = True
+ return list(result.keys())
+
+class ActionCaller(object):
+ """A class for delaying calling an Action function with specific
+ (positional and keyword) arguments until the Action is actually
+ executed.
+
+ This class looks to the rest of the world like a normal Action object,
+ but what it's really doing is hanging on to the arguments until we
+ have a target, source and env to use for the expansion.
+ """
+ def __init__(self, parent, args, kw):
+ self.parent = parent
+ self.args = args
+ self.kw = kw
+
+ def get_contents(self, target, source, env):
+ actfunc = self.parent.actfunc
+ try:
+ # "self.actfunc" is a function.
+ contents = str(actfunc.func_code.co_code)
+ except AttributeError:
+ # "self.actfunc" is a callable object.
+ try:
+ contents = str(actfunc.__call__.im_func.func_code.co_code)
+ except AttributeError:
+ # No __call__() method, so it might be a builtin
+ # or something like that. Do the best we can.
+ contents = str(actfunc)
+ contents = remove_set_lineno_codes(contents)
+ return contents
+
+ def subst(self, s, target, source, env):
+ # If s is a list, recursively apply subst()
+ # to every element in the list
+ if is_List(s):
+ result = []
+ for elem in s:
+ result.append(self.subst(elem, target, source, env))
+ return self.parent.convert(result)
+
+ # Special-case hack: Let a custom function wrapped in an
+ # ActionCaller get at the environment through which the action
+ # was called by using this hard-coded value as a special return.
+ if s == '$__env__':
+ return env
+ elif is_String(s):
+ return env.subst(s, 1, target, source)
+ return self.parent.convert(s)
+
+ def subst_args(self, target, source, env):
+ return [self.subst(x, target, source, env) for x in self.args]
+
+ def subst_kw(self, target, source, env):
+ kw = {}
+ for key in self.kw.keys():
+ kw[key] = self.subst(self.kw[key], target, source, env)
+ return kw
+
+ def __call__(self, target, source, env, executor=None):
+ args = self.subst_args(target, source, env)
+ kw = self.subst_kw(target, source, env)
+ return self.parent.actfunc(*args, **kw)
+
+ def strfunction(self, target, source, env):
+ args = self.subst_args(target, source, env)
+ kw = self.subst_kw(target, source, env)
+ return self.parent.strfunc(*args, **kw)
+
+ def __str__(self):
+ return self.parent.strfunc(*self.args, **self.kw)
+
+class ActionFactory(object):
+ """A factory class that will wrap up an arbitrary function
+ as an SCons-executable Action object.
+
+ The real heavy lifting here is done by the ActionCaller class.
+ We just collect the (positional and keyword) arguments that we're
+ called with and give them to the ActionCaller object we create,
+ so it can hang onto them until it needs them.
+ """
+ def __init__(self, actfunc, strfunc, convert=lambda x: x):
+ self.actfunc = actfunc
+ self.strfunc = strfunc
+ self.convert = convert
+
+ def __call__(self, *args, **kw):
+ ac = ActionCaller(self, args, kw)
+ action = Action(ac, strfunction=ac.strfunction)
+ return action
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Builder.py b/couchjs/scons/scons-local-2.0.1/SCons/Builder.py
new file mode 100644
index 00000000..0592bb49
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Builder.py
@@ -0,0 +1,877 @@
+"""SCons.Builder
+
+Builder object subsystem.
+
+A Builder object is a callable that encapsulates information about how
+to execute actions to create a target Node (file) from source Nodes
+(files), and how to create those dependencies for tracking.
+
+The main entry point here is the Builder() factory method. This provides
+a procedural interface that creates the right underlying Builder object
+based on the keyword arguments supplied and the types of the arguments.
+
+The goal is for this external interface to be simple enough that the
+vast majority of users can create new Builders as necessary to support
+building new types of files in their configurations, without having to
+dive any deeper into this subsystem.
+
+The base class here is BuilderBase. This is a concrete base class which
+does, in fact, represent the Builder objects that we (or users) create.
+
+There is also a proxy that looks like a Builder:
+
+ CompositeBuilder
+
+ This proxies for a Builder with an action that is actually a
+ dictionary that knows how to map file suffixes to a specific
+ action. This is so that we can invoke different actions
+ (compilers, compile options) for different flavors of source
+ files.
+
+Builders and their proxies have the following public interface methods
+used by other modules:
+
+ __call__()
+ THE public interface. Calling a Builder object (with the
+ use of internal helper methods) sets up the target and source
+ dependencies, appropriate mapping to a specific action, and the
+ environment manipulation necessary for overridden construction
+ variable. This also takes care of warning about possible mistakes
+ in keyword arguments.
+
+ add_emitter()
+ Adds an emitter for a specific file suffix, used by some Tool
+ modules to specify that (for example) a yacc invocation on a .y
+ can create a .h *and* a .c file.
+
+ add_action()
+ Adds an action for a specific file suffix, heavily used by
+ Tool modules to add their specific action(s) for turning
+ a source file into an object file to the global static
+ and shared object file Builders.
+
+There are the following methods for internal use within this module:
+
+ _execute()
+ The internal method that handles the heavily lifting when a
+ Builder is called. This is used so that the __call__() methods
+ can set up warning about possible mistakes in keyword-argument
+ overrides, and *then* execute all of the steps necessary so that
+ the warnings only occur once.
+
+ get_name()
+ Returns the Builder's name within a specific Environment,
+ primarily used to try to return helpful information in error
+ messages.
+
+ adjust_suffix()
+ get_prefix()
+ get_suffix()
+ get_src_suffix()
+ set_src_suffix()
+ Miscellaneous stuff for handling the prefix and suffix
+ manipulation we use in turning source file names into target
+ file names.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Builder.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import collections
+
+import SCons.Action
+from SCons.Debug import logInstanceCreation
+from SCons.Errors import InternalError, UserError
+import SCons.Executor
+import SCons.Memoize
+import SCons.Node
+import SCons.Node.FS
+import SCons.Util
+import SCons.Warnings
+
+class _Null(object):
+ pass
+
+_null = _Null
+
+def match_splitext(path, suffixes = []):
+ if suffixes:
+ matchsuf = [S for S in suffixes if path[-len(S):] == S]
+ if matchsuf:
+ suf = max([(len(_f),_f) for _f in matchsuf])[1]
+ return [path[:-len(suf)], path[-len(suf):]]
+ return SCons.Util.splitext(path)
+
+class DictCmdGenerator(SCons.Util.Selector):
+ """This is a callable class that can be used as a
+ command generator function. It holds on to a dictionary
+ mapping file suffixes to Actions. It uses that dictionary
+ to return the proper action based on the file suffix of
+ the source file."""
+
+ def __init__(self, dict=None, source_ext_match=1):
+ SCons.Util.Selector.__init__(self, dict)
+ self.source_ext_match = source_ext_match
+
+ def src_suffixes(self):
+ return list(self.keys())
+
+ def add_action(self, suffix, action):
+ """Add a suffix-action pair to the mapping.
+ """
+ self[suffix] = action
+
+ def __call__(self, target, source, env, for_signature):
+ if not source:
+ return []
+
+ if self.source_ext_match:
+ suffixes = self.src_suffixes()
+ ext = None
+ for src in map(str, source):
+ my_ext = match_splitext(src, suffixes)[1]
+ if ext and my_ext != ext:
+ raise UserError("While building `%s' from `%s': Cannot build multiple sources with different extensions: %s, %s"
+ % (repr(list(map(str, target))), src, ext, my_ext))
+ ext = my_ext
+ else:
+ ext = match_splitext(str(source[0]), self.src_suffixes())[1]
+
+ if not ext:
+ #return ext
+ raise UserError("While building `%s': "
+ "Cannot deduce file extension from source files: %s"
+ % (repr(list(map(str, target))), repr(list(map(str, source)))))
+
+ try:
+ ret = SCons.Util.Selector.__call__(self, env, source, ext)
+ except KeyError, e:
+ raise UserError("Ambiguous suffixes after environment substitution: %s == %s == %s" % (e.args[0], e.args[1], e.args[2]))
+ if ret is None:
+ raise UserError("While building `%s' from `%s': Don't know how to build from a source file with suffix `%s'. Expected a suffix in this list: %s." % \
+ (repr(list(map(str, target))), repr(list(map(str, source))), ext, repr(list(self.keys()))))
+ return ret
+
+class CallableSelector(SCons.Util.Selector):
+ """A callable dictionary that will, in turn, call the value it
+ finds if it can."""
+ def __call__(self, env, source):
+ value = SCons.Util.Selector.__call__(self, env, source)
+ if callable(value):
+ value = value(env, source)
+ return value
+
+class DictEmitter(SCons.Util.Selector):
+ """A callable dictionary that maps file suffixes to emitters.
+ When called, it finds the right emitter in its dictionary for the
+ suffix of the first source file, and calls that emitter to get the
+ right lists of targets and sources to return. If there's no emitter
+ for the suffix in its dictionary, the original target and source are
+ returned.
+ """
+ def __call__(self, target, source, env):
+ emitter = SCons.Util.Selector.__call__(self, env, source)
+ if emitter:
+ target, source = emitter(target, source, env)
+ return (target, source)
+
+class ListEmitter(collections.UserList):
+ """A callable list of emitters that calls each in sequence,
+ returning the result.
+ """
+ def __call__(self, target, source, env):
+ for e in self.data:
+ target, source = e(target, source, env)
+ return (target, source)
+
+# These are a common errors when calling a Builder;
+# they are similar to the 'target' and 'source' keyword args to builders,
+# so we issue warnings when we see them. The warnings can, of course,
+# be disabled.
+misleading_keywords = {
+ 'targets' : 'target',
+ 'sources' : 'source',
+}
+
+class OverrideWarner(collections.UserDict):
+ """A class for warning about keyword arguments that we use as
+ overrides in a Builder call.
+
+ This class exists to handle the fact that a single Builder call
+ can actually invoke multiple builders. This class only emits the
+ warnings once, no matter how many Builders are invoked.
+ """
+ def __init__(self, dict):
+ collections.UserDict.__init__(self, dict)
+ if __debug__: logInstanceCreation(self, 'Builder.OverrideWarner')
+ self.already_warned = None
+ def warn(self):
+ if self.already_warned:
+ return
+ for k in self.keys():
+ if k in misleading_keywords:
+ alt = misleading_keywords[k]
+ msg = "Did you mean to use `%s' instead of `%s'?" % (alt, k)
+ SCons.Warnings.warn(SCons.Warnings.MisleadingKeywordsWarning, msg)
+ self.already_warned = 1
+
+def Builder(**kw):
+ """A factory for builder objects."""
+ composite = None
+ if 'generator' in kw:
+ if 'action' in kw:
+ raise UserError("You must not specify both an action and a generator.")
+ kw['action'] = SCons.Action.CommandGeneratorAction(kw['generator'], {})
+ del kw['generator']
+ elif 'action' in kw:
+ source_ext_match = kw.get('source_ext_match', 1)
+ if 'source_ext_match' in kw:
+ del kw['source_ext_match']
+ if SCons.Util.is_Dict(kw['action']):
+ composite = DictCmdGenerator(kw['action'], source_ext_match)
+ kw['action'] = SCons.Action.CommandGeneratorAction(composite, {})
+ kw['src_suffix'] = composite.src_suffixes()
+ else:
+ kw['action'] = SCons.Action.Action(kw['action'])
+
+ if 'emitter' in kw:
+ emitter = kw['emitter']
+ if SCons.Util.is_String(emitter):
+ # This allows users to pass in an Environment
+ # variable reference (like "$FOO") as an emitter.
+ # We will look in that Environment variable for
+ # a callable to use as the actual emitter.
+ var = SCons.Util.get_environment_var(emitter)
+ if not var:
+ raise UserError("Supplied emitter '%s' does not appear to refer to an Environment variable" % emitter)
+ kw['emitter'] = EmitterProxy(var)
+ elif SCons.Util.is_Dict(emitter):
+ kw['emitter'] = DictEmitter(emitter)
+ elif SCons.Util.is_List(emitter):
+ kw['emitter'] = ListEmitter(emitter)
+
+ result = BuilderBase(**kw)
+
+ if not composite is None:
+ result = CompositeBuilder(result, composite)
+
+ return result
+
+def _node_errors(builder, env, tlist, slist):
+ """Validate that the lists of target and source nodes are
+ legal for this builder and environment. Raise errors or
+ issue warnings as appropriate.
+ """
+
+ # First, figure out if there are any errors in the way the targets
+ # were specified.
+ for t in tlist:
+ if t.side_effect:
+ raise UserError("Multiple ways to build the same target were specified for: %s" % t)
+ if t.has_explicit_builder():
+ if not t.env is None and not t.env is env:
+ action = t.builder.action
+ t_contents = action.get_contents(tlist, slist, t.env)
+ contents = action.get_contents(tlist, slist, env)
+
+ if t_contents == contents:
+ msg = "Two different environments were specified for target %s,\n\tbut they appear to have the same action: %s" % (t, action.genstring(tlist, slist, t.env))
+ SCons.Warnings.warn(SCons.Warnings.DuplicateEnvironmentWarning, msg)
+ else:
+ msg = "Two environments with different actions were specified for the same target: %s" % t
+ raise UserError(msg)
+ if builder.multi:
+ if t.builder != builder:
+ msg = "Two different builders (%s and %s) were specified for the same target: %s" % (t.builder.get_name(env), builder.get_name(env), t)
+ raise UserError(msg)
+ # TODO(batch): list constructed each time!
+ if t.get_executor().get_all_targets() != tlist:
+ msg = "Two different target lists have a target in common: %s (from %s and from %s)" % (t, list(map(str, t.get_executor().get_all_targets())), list(map(str, tlist)))
+ raise UserError(msg)
+ elif t.sources != slist:
+ msg = "Multiple ways to build the same target were specified for: %s (from %s and from %s)" % (t, list(map(str, t.sources)), list(map(str, slist)))
+ raise UserError(msg)
+
+ if builder.single_source:
+ if len(slist) > 1:
+ raise UserError("More than one source given for single-source builder: targets=%s sources=%s" % (list(map(str,tlist)), list(map(str,slist))))
+
+class EmitterProxy(object):
+ """This is a callable class that can act as a
+ Builder emitter. It holds on to a string that
+ is a key into an Environment dictionary, and will
+ look there at actual build time to see if it holds
+ a callable. If so, we will call that as the actual
+ emitter."""
+ def __init__(self, var):
+ self.var = SCons.Util.to_String(var)
+
+ def __call__(self, target, source, env):
+ emitter = self.var
+
+ # Recursively substitute the variable.
+ # We can't use env.subst() because it deals only
+ # in strings. Maybe we should change that?
+ while SCons.Util.is_String(emitter) and emitter in env:
+ emitter = env[emitter]
+ if callable(emitter):
+ target, source = emitter(target, source, env)
+ elif SCons.Util.is_List(emitter):
+ for e in emitter:
+ target, source = e(target, source, env)
+
+ return (target, source)
+
+
+ def __cmp__(self, other):
+ return cmp(self.var, other.var)
+
+class BuilderBase(object):
+ """Base class for Builders, objects that create output
+ nodes (files) from input nodes (files).
+ """
+
+ if SCons.Memoize.use_memoizer:
+ __metaclass__ = SCons.Memoize.Memoized_Metaclass
+
+ memoizer_counters = []
+
+ def __init__(self, action = None,
+ prefix = '',
+ suffix = '',
+ src_suffix = '',
+ target_factory = None,
+ source_factory = None,
+ target_scanner = None,
+ source_scanner = None,
+ emitter = None,
+ multi = 0,
+ env = None,
+ single_source = 0,
+ name = None,
+ chdir = _null,
+ is_explicit = 1,
+ src_builder = None,
+ ensure_suffix = False,
+ **overrides):
+ if __debug__: logInstanceCreation(self, 'Builder.BuilderBase')
+ self._memo = {}
+ self.action = action
+ self.multi = multi
+ if SCons.Util.is_Dict(prefix):
+ prefix = CallableSelector(prefix)
+ self.prefix = prefix
+ if SCons.Util.is_Dict(suffix):
+ suffix = CallableSelector(suffix)
+ self.env = env
+ self.single_source = single_source
+ if 'overrides' in overrides:
+ SCons.Warnings.warn(SCons.Warnings.DeprecatedBuilderKeywordsWarning,
+ "The \"overrides\" keyword to Builder() creation has been deprecated;\n" +\
+ "\tspecify the items as keyword arguments to the Builder() call instead.")
+ overrides.update(overrides['overrides'])
+ del overrides['overrides']
+ if 'scanner' in overrides:
+ SCons.Warnings.warn(SCons.Warnings.DeprecatedBuilderKeywordsWarning,
+ "The \"scanner\" keyword to Builder() creation has been deprecated;\n"
+ "\tuse: source_scanner or target_scanner as appropriate.")
+ del overrides['scanner']
+ self.overrides = overrides
+
+ self.set_suffix(suffix)
+ self.set_src_suffix(src_suffix)
+ self.ensure_suffix = ensure_suffix
+
+ self.target_factory = target_factory
+ self.source_factory = source_factory
+ self.target_scanner = target_scanner
+ self.source_scanner = source_scanner
+
+ self.emitter = emitter
+
+ # Optional Builder name should only be used for Builders
+ # that don't get attached to construction environments.
+ if name:
+ self.name = name
+ self.executor_kw = {}
+ if not chdir is _null:
+ self.executor_kw['chdir'] = chdir
+ self.is_explicit = is_explicit
+
+ if src_builder is None:
+ src_builder = []
+ elif not SCons.Util.is_List(src_builder):
+ src_builder = [ src_builder ]
+ self.src_builder = src_builder
+
+ def __nonzero__(self):
+ raise InternalError("Do not test for the Node.builder attribute directly; use Node.has_builder() instead")
+
+ def get_name(self, env):
+ """Attempts to get the name of the Builder.
+
+ Look at the BUILDERS variable of env, expecting it to be a
+ dictionary containing this Builder, and return the key of the
+ dictionary. If there's no key, then return a directly-configured
+ name (if there is one) or the name of the class (by default)."""
+
+ try:
+ index = list(env['BUILDERS'].values()).index(self)
+ return list(env['BUILDERS'].keys())[index]
+ except (AttributeError, KeyError, TypeError, ValueError):
+ try:
+ return self.name
+ except AttributeError:
+ return str(self.__class__)
+
+ def __cmp__(self, other):
+ return cmp(self.__dict__, other.__dict__)
+
+ def splitext(self, path, env=None):
+ if not env:
+ env = self.env
+ if env:
+ suffixes = self.src_suffixes(env)
+ else:
+ suffixes = []
+ return match_splitext(path, suffixes)
+
+ def _adjustixes(self, files, pre, suf, ensure_suffix=False):
+ if not files:
+ return []
+ result = []
+ if not SCons.Util.is_List(files):
+ files = [files]
+
+ for f in files:
+ if SCons.Util.is_String(f):
+ f = SCons.Util.adjustixes(f, pre, suf, ensure_suffix)
+ result.append(f)
+ return result
+
+ def _create_nodes(self, env, target = None, source = None):
+ """Create and return lists of target and source nodes.
+ """
+ src_suf = self.get_src_suffix(env)
+
+ target_factory = env.get_factory(self.target_factory)
+ source_factory = env.get_factory(self.source_factory)
+
+ source = self._adjustixes(source, None, src_suf)
+ slist = env.arg2nodes(source, source_factory)
+
+ pre = self.get_prefix(env, slist)
+ suf = self.get_suffix(env, slist)
+
+ if target is None:
+ try:
+ t_from_s = slist[0].target_from_source
+ except AttributeError:
+ raise UserError("Do not know how to create a target from source `%s'" % slist[0])
+ except IndexError:
+ tlist = []
+ else:
+ splitext = lambda S: self.splitext(S,env)
+ tlist = [ t_from_s(pre, suf, splitext) ]
+ else:
+ target = self._adjustixes(target, pre, suf, self.ensure_suffix)
+ tlist = env.arg2nodes(target, target_factory, target=target, source=source)
+
+ if self.emitter:
+ # The emitter is going to do str(node), but because we're
+ # being called *from* a builder invocation, the new targets
+ # don't yet have a builder set on them and will look like
+ # source files. Fool the emitter's str() calls by setting
+ # up a temporary builder on the new targets.
+ new_targets = []
+ for t in tlist:
+ if not t.is_derived():
+ t.builder_set(self)
+ new_targets.append(t)
+
+ orig_tlist = tlist[:]
+ orig_slist = slist[:]
+
+ target, source = self.emitter(target=tlist, source=slist, env=env)
+
+ # Now delete the temporary builders that we attached to any
+ # new targets, so that _node_errors() doesn't do weird stuff
+ # to them because it thinks they already have builders.
+ for t in new_targets:
+ if t.builder is self:
+ # Only delete the temporary builder if the emitter
+ # didn't change it on us.
+ t.builder_set(None)
+
+ # Have to call arg2nodes yet again, since it is legal for
+ # emitters to spit out strings as well as Node instances.
+ tlist = env.arg2nodes(target, target_factory,
+ target=orig_tlist, source=orig_slist)
+ slist = env.arg2nodes(source, source_factory,
+ target=orig_tlist, source=orig_slist)
+
+ return tlist, slist
+
+ def _execute(self, env, target, source, overwarn={}, executor_kw={}):
+ # We now assume that target and source are lists or None.
+ if self.src_builder:
+ source = self.src_builder_sources(env, source, overwarn)
+
+ if self.single_source and len(source) > 1 and target is None:
+ result = []
+ if target is None: target = [None]*len(source)
+ for tgt, src in zip(target, source):
+ if not tgt is None: tgt = [tgt]
+ if not src is None: src = [src]
+ result.extend(self._execute(env, tgt, src, overwarn))
+ return SCons.Node.NodeList(result)
+
+ overwarn.warn()
+
+ tlist, slist = self._create_nodes(env, target, source)
+
+ # Check for errors with the specified target/source lists.
+ _node_errors(self, env, tlist, slist)
+
+ # The targets are fine, so find or make the appropriate Executor to
+ # build this particular list of targets from this particular list of
+ # sources.
+
+ executor = None
+ key = None
+
+ if self.multi:
+ try:
+ executor = tlist[0].get_executor(create = 0)
+ except (AttributeError, IndexError):
+ pass
+ else:
+ executor.add_sources(slist)
+
+ if executor is None:
+ if not self.action:
+ fmt = "Builder %s must have an action to build %s."
+ raise UserError(fmt % (self.get_name(env or self.env),
+ list(map(str,tlist))))
+ key = self.action.batch_key(env or self.env, tlist, slist)
+ if key:
+ try:
+ executor = SCons.Executor.GetBatchExecutor(key)
+ except KeyError:
+ pass
+ else:
+ executor.add_batch(tlist, slist)
+
+ if executor is None:
+ executor = SCons.Executor.Executor(self.action, env, [],
+ tlist, slist, executor_kw)
+ if key:
+ SCons.Executor.AddBatchExecutor(key, executor)
+
+ # Now set up the relevant information in the target Nodes themselves.
+ for t in tlist:
+ t.cwd = env.fs.getcwd()
+ t.builder_set(self)
+ t.env_set(env)
+ t.add_source(slist)
+ t.set_executor(executor)
+ t.set_explicit(self.is_explicit)
+
+ return SCons.Node.NodeList(tlist)
+
+ def __call__(self, env, target=None, source=None, chdir=_null, **kw):
+ # We now assume that target and source are lists or None.
+ # The caller (typically Environment.BuilderWrapper) is
+ # responsible for converting any scalar values to lists.
+ if chdir is _null:
+ ekw = self.executor_kw
+ else:
+ ekw = self.executor_kw.copy()
+ ekw['chdir'] = chdir
+ if kw:
+ if 'srcdir' in kw:
+ def prependDirIfRelative(f, srcdir=kw['srcdir']):
+ import os.path
+ if SCons.Util.is_String(f) and not os.path.isabs(f):
+ f = os.path.join(srcdir, f)
+ return f
+ if not SCons.Util.is_List(source):
+ source = [source]
+ source = list(map(prependDirIfRelative, source))
+ del kw['srcdir']
+ if self.overrides:
+ env_kw = self.overrides.copy()
+ env_kw.update(kw)
+ else:
+ env_kw = kw
+ else:
+ env_kw = self.overrides
+ env = env.Override(env_kw)
+ return self._execute(env, target, source, OverrideWarner(kw), ekw)
+
+ def adjust_suffix(self, suff):
+ if suff and not suff[0] in [ '.', '_', '$' ]:
+ return '.' + suff
+ return suff
+
+ def get_prefix(self, env, sources=[]):
+ prefix = self.prefix
+ if callable(prefix):
+ prefix = prefix(env, sources)
+ return env.subst(prefix)
+
+ def set_suffix(self, suffix):
+ if not callable(suffix):
+ suffix = self.adjust_suffix(suffix)
+ self.suffix = suffix
+
+ def get_suffix(self, env, sources=[]):
+ suffix = self.suffix
+ if callable(suffix):
+ suffix = suffix(env, sources)
+ return env.subst(suffix)
+
+ def set_src_suffix(self, src_suffix):
+ if not src_suffix:
+ src_suffix = []
+ elif not SCons.Util.is_List(src_suffix):
+ src_suffix = [ src_suffix ]
+ self.src_suffix = [callable(suf) and suf or self.adjust_suffix(suf) for suf in src_suffix]
+
+ def get_src_suffix(self, env):
+ """Get the first src_suffix in the list of src_suffixes."""
+ ret = self.src_suffixes(env)
+ if not ret:
+ return ''
+ return ret[0]
+
+ def add_emitter(self, suffix, emitter):
+ """Add a suffix-emitter mapping to this Builder.
+
+ This assumes that emitter has been initialized with an
+ appropriate dictionary type, and will throw a TypeError if
+ not, so the caller is responsible for knowing that this is an
+ appropriate method to call for the Builder in question.
+ """
+ self.emitter[suffix] = emitter
+
+ def add_src_builder(self, builder):
+ """
+ Add a new Builder to the list of src_builders.
+
+ This requires wiping out cached values so that the computed
+ lists of source suffixes get re-calculated.
+ """
+ self._memo = {}
+ self.src_builder.append(builder)
+
+ def _get_sdict(self, env):
+ """
+ Returns a dictionary mapping all of the source suffixes of all
+ src_builders of this Builder to the underlying Builder that
+ should be called first.
+
+ This dictionary is used for each target specified, so we save a
+ lot of extra computation by memoizing it for each construction
+ environment.
+
+ Note that this is re-computed each time, not cached, because there
+ might be changes to one of our source Builders (or one of their
+ source Builders, and so on, and so on...) that we can't "see."
+
+ The underlying methods we call cache their computed values,
+ though, so we hope repeatedly aggregating them into a dictionary
+ like this won't be too big a hit. We may need to look for a
+ better way to do this if performance data show this has turned
+ into a significant bottleneck.
+ """
+ sdict = {}
+ for bld in self.get_src_builders(env):
+ for suf in bld.src_suffixes(env):
+ sdict[suf] = bld
+ return sdict
+
+ def src_builder_sources(self, env, source, overwarn={}):
+ sdict = self._get_sdict(env)
+
+ src_suffixes = self.src_suffixes(env)
+
+ lengths = list(set(map(len, src_suffixes)))
+
+ def match_src_suffix(name, src_suffixes=src_suffixes, lengths=lengths):
+ node_suffixes = [name[-l:] for l in lengths]
+ for suf in src_suffixes:
+ if suf in node_suffixes:
+ return suf
+ return None
+
+ result = []
+ for s in SCons.Util.flatten(source):
+ if SCons.Util.is_String(s):
+ match_suffix = match_src_suffix(env.subst(s))
+ if not match_suffix and not '.' in s:
+ src_suf = self.get_src_suffix(env)
+ s = self._adjustixes(s, None, src_suf)[0]
+ else:
+ match_suffix = match_src_suffix(s.name)
+ if match_suffix:
+ try:
+ bld = sdict[match_suffix]
+ except KeyError:
+ result.append(s)
+ else:
+ tlist = bld._execute(env, None, [s], overwarn)
+ # If the subsidiary Builder returned more than one
+ # target, then filter out any sources that this
+ # Builder isn't capable of building.
+ if len(tlist) > 1:
+ tlist = [t for t in tlist if match_src_suffix(t.name)]
+ result.extend(tlist)
+ else:
+ result.append(s)
+
+ source_factory = env.get_factory(self.source_factory)
+
+ return env.arg2nodes(result, source_factory)
+
+ def _get_src_builders_key(self, env):
+ return id(env)
+
+ memoizer_counters.append(SCons.Memoize.CountDict('get_src_builders', _get_src_builders_key))
+
+ def get_src_builders(self, env):
+ """
+ Returns the list of source Builders for this Builder.
+
+ This exists mainly to look up Builders referenced as
+ strings in the 'BUILDER' variable of the construction
+ environment and cache the result.
+ """
+ memo_key = id(env)
+ try:
+ memo_dict = self._memo['get_src_builders']
+ except KeyError:
+ memo_dict = {}
+ self._memo['get_src_builders'] = memo_dict
+ else:
+ try:
+ return memo_dict[memo_key]
+ except KeyError:
+ pass
+
+ builders = []
+ for bld in self.src_builder:
+ if SCons.Util.is_String(bld):
+ try:
+ bld = env['BUILDERS'][bld]
+ except KeyError:
+ continue
+ builders.append(bld)
+
+ memo_dict[memo_key] = builders
+ return builders
+
+ def _subst_src_suffixes_key(self, env):
+ return id(env)
+
+ memoizer_counters.append(SCons.Memoize.CountDict('subst_src_suffixes', _subst_src_suffixes_key))
+
+ def subst_src_suffixes(self, env):
+ """
+ The suffix list may contain construction variable expansions,
+ so we have to evaluate the individual strings. To avoid doing
+ this over and over, we memoize the results for each construction
+ environment.
+ """
+ memo_key = id(env)
+ try:
+ memo_dict = self._memo['subst_src_suffixes']
+ except KeyError:
+ memo_dict = {}
+ self._memo['subst_src_suffixes'] = memo_dict
+ else:
+ try:
+ return memo_dict[memo_key]
+ except KeyError:
+ pass
+ suffixes = [env.subst(x) for x in self.src_suffix]
+ memo_dict[memo_key] = suffixes
+ return suffixes
+
+ def src_suffixes(self, env):
+ """
+ Returns the list of source suffixes for all src_builders of this
+ Builder.
+
+ This is essentially a recursive descent of the src_builder "tree."
+ (This value isn't cached because there may be changes in a
+ src_builder many levels deep that we can't see.)
+ """
+ sdict = {}
+ suffixes = self.subst_src_suffixes(env)
+ for s in suffixes:
+ sdict[s] = 1
+ for builder in self.get_src_builders(env):
+ for s in builder.src_suffixes(env):
+ if s not in sdict:
+ sdict[s] = 1
+ suffixes.append(s)
+ return suffixes
+
+class CompositeBuilder(SCons.Util.Proxy):
+ """A Builder Proxy whose main purpose is to always have
+ a DictCmdGenerator as its action, and to provide access
+ to the DictCmdGenerator's add_action() method.
+ """
+
+ def __init__(self, builder, cmdgen):
+ if __debug__: logInstanceCreation(self, 'Builder.CompositeBuilder')
+ SCons.Util.Proxy.__init__(self, builder)
+
+ # cmdgen should always be an instance of DictCmdGenerator.
+ self.cmdgen = cmdgen
+ self.builder = builder
+
+ __call__ = SCons.Util.Delegate('__call__')
+
+ def add_action(self, suffix, action):
+ self.cmdgen.add_action(suffix, action)
+ self.set_src_suffix(self.cmdgen.src_suffixes())
+
+def is_a_Builder(obj):
+ """"Returns True iff the specified obj is one of our Builder classes.
+
+ The test is complicated a bit by the fact that CompositeBuilder
+ is a proxy, not a subclass of BuilderBase.
+ """
+ return (isinstance(obj, BuilderBase)
+ or isinstance(obj, CompositeBuilder)
+ or callable(obj))
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/CacheDir.py b/couchjs/scons/scons-local-2.0.1/SCons/CacheDir.py
new file mode 100644
index 00000000..68ee1ca6
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/CacheDir.py
@@ -0,0 +1,216 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/CacheDir.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__doc__ = """
+CacheDir support
+"""
+
+import os.path
+import stat
+import sys
+
+import SCons.Action
+
+cache_enabled = True
+cache_debug = False
+cache_force = False
+cache_show = False
+
+def CacheRetrieveFunc(target, source, env):
+ t = target[0]
+ fs = t.fs
+ cd = env.get_CacheDir()
+ cachedir, cachefile = cd.cachepath(t)
+ if not fs.exists(cachefile):
+ cd.CacheDebug('CacheRetrieve(%s): %s not in cache\n', t, cachefile)
+ return 1
+ cd.CacheDebug('CacheRetrieve(%s): retrieving from %s\n', t, cachefile)
+ if SCons.Action.execute_actions:
+ if fs.islink(cachefile):
+ fs.symlink(fs.readlink(cachefile), t.path)
+ else:
+ env.copy_from_cache(cachefile, t.path)
+ st = fs.stat(cachefile)
+ fs.chmod(t.path, stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)
+ return 0
+
+def CacheRetrieveString(target, source, env):
+ t = target[0]
+ fs = t.fs
+ cd = env.get_CacheDir()
+ cachedir, cachefile = cd.cachepath(t)
+ if t.fs.exists(cachefile):
+ return "Retrieved `%s' from cache" % t.path
+ return None
+
+CacheRetrieve = SCons.Action.Action(CacheRetrieveFunc, CacheRetrieveString)
+
+CacheRetrieveSilent = SCons.Action.Action(CacheRetrieveFunc, None)
+
+def CachePushFunc(target, source, env):
+ t = target[0]
+ if t.nocache:
+ return
+ fs = t.fs
+ cd = env.get_CacheDir()
+ cachedir, cachefile = cd.cachepath(t)
+ if fs.exists(cachefile):
+ # Don't bother copying it if it's already there. Note that
+ # usually this "shouldn't happen" because if the file already
+ # existed in cache, we'd have retrieved the file from there,
+ # not built it. This can happen, though, in a race, if some
+ # other person running the same build pushes their copy to
+ # the cache after we decide we need to build it but before our
+ # build completes.
+ cd.CacheDebug('CachePush(%s): %s already exists in cache\n', t, cachefile)
+ return
+
+ cd.CacheDebug('CachePush(%s): pushing to %s\n', t, cachefile)
+
+ tempfile = cachefile+'.tmp'+str(os.getpid())
+ errfmt = "Unable to copy %s to cache. Cache file is %s"
+
+ if not fs.isdir(cachedir):
+ try:
+ fs.makedirs(cachedir)
+ except EnvironmentError:
+ # We may have received an exception because another process
+ # has beaten us creating the directory.
+ if not fs.isdir(cachedir):
+ msg = errfmt % (str(target), cachefile)
+ raise SCons.Errors.EnvironmentError(msg)
+
+ try:
+ if fs.islink(t.path):
+ fs.symlink(fs.readlink(t.path), tempfile)
+ else:
+ fs.copy2(t.path, tempfile)
+ fs.rename(tempfile, cachefile)
+ st = fs.stat(t.path)
+ fs.chmod(cachefile, stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)
+ except EnvironmentError:
+ # It's possible someone else tried writing the file at the
+ # same time we did, or else that there was some problem like
+ # the CacheDir being on a separate file system that's full.
+ # In any case, inability to push a file to cache doesn't affect
+ # the correctness of the build, so just print a warning.
+ msg = errfmt % (str(target), cachefile)
+ SCons.Warnings.warn(SCons.Warnings.CacheWriteErrorWarning, msg)
+
+CachePush = SCons.Action.Action(CachePushFunc, None)
+
+class CacheDir(object):
+
+ def __init__(self, path):
+ try:
+ import hashlib
+ except ImportError:
+ msg = "No hashlib or MD5 module available, CacheDir() not supported"
+ SCons.Warnings.warn(SCons.Warnings.NoMD5ModuleWarning, msg)
+ self.path = None
+ else:
+ self.path = path
+ self.current_cache_debug = None
+ self.debugFP = None
+
+ def CacheDebug(self, fmt, target, cachefile):
+ if cache_debug != self.current_cache_debug:
+ if cache_debug == '-':
+ self.debugFP = sys.stdout
+ elif cache_debug:
+ self.debugFP = open(cache_debug, 'w')
+ else:
+ self.debugFP = None
+ self.current_cache_debug = cache_debug
+ if self.debugFP:
+ self.debugFP.write(fmt % (target, os.path.split(cachefile)[1]))
+
+ def is_enabled(self):
+ return (cache_enabled and not self.path is None)
+
+ def cachepath(self, node):
+ """
+ """
+ if not self.is_enabled():
+ return None, None
+
+ sig = node.get_cachedir_bsig()
+ subdir = sig[0].upper()
+ dir = os.path.join(self.path, subdir)
+ return dir, os.path.join(dir, sig)
+
+ def retrieve(self, node):
+ """
+ This method is called from multiple threads in a parallel build,
+ so only do thread safe stuff here. Do thread unsafe stuff in
+ built().
+
+ Note that there's a special trick here with the execute flag
+ (one that's not normally done for other actions). Basically
+ if the user requested a no_exec (-n) build, then
+ SCons.Action.execute_actions is set to 0 and when any action
+ is called, it does its showing but then just returns zero
+ instead of actually calling the action execution operation.
+ The problem for caching is that if the file does NOT exist in
+ cache then the CacheRetrieveString won't return anything to
+ show for the task, but the Action.__call__ won't call
+ CacheRetrieveFunc; instead it just returns zero, which makes
+ the code below think that the file *was* successfully
+ retrieved from the cache, therefore it doesn't do any
+ subsequent building. However, the CacheRetrieveString didn't
+ print anything because it didn't actually exist in the cache,
+ and no more build actions will be performed, so the user just
+ sees nothing. The fix is to tell Action.__call__ to always
+ execute the CacheRetrieveFunc and then have the latter
+ explicitly check SCons.Action.execute_actions itself.
+ """
+ if not self.is_enabled():
+ return False
+
+ env = node.get_build_env()
+ if cache_show:
+ if CacheRetrieveSilent(node, [], env, execute=1) == 0:
+ node.build(presub=0, execute=0)
+ return True
+ else:
+ if CacheRetrieve(node, [], env, execute=1) == 0:
+ return True
+
+ return False
+
+ def push(self, node):
+ if not self.is_enabled():
+ return
+ return CachePush(node, [], node.get_build_env())
+
+ def push_if_forced(self, node):
+ if cache_force:
+ return self.push(node)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Conftest.py b/couchjs/scons/scons-local-2.0.1/SCons/Conftest.py
new file mode 100644
index 00000000..04a6bc2a
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Conftest.py
@@ -0,0 +1,793 @@
+"""SCons.Conftest
+
+Autoconf-like configuration support; low level implementation of tests.
+"""
+
+#
+# Copyright (c) 2003 Stichting NLnet Labs
+# Copyright (c) 2001, 2002, 2003 Steven Knight
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+#
+# The purpose of this module is to define how a check is to be performed.
+# Use one of the Check...() functions below.
+#
+
+#
+# A context class is used that defines functions for carrying out the tests,
+# logging and messages. The following methods and members must be present:
+#
+# context.Display(msg) Function called to print messages that are normally
+# displayed for the user. Newlines are explicitly used.
+# The text should also be written to the logfile!
+#
+# context.Log(msg) Function called to write to a log file.
+#
+# context.BuildProg(text, ext)
+# Function called to build a program, using "ext" for the
+# file extention. Must return an empty string for
+# success, an error message for failure.
+# For reliable test results building should be done just
+# like an actual program would be build, using the same
+# command and arguments (including configure results so
+# far).
+#
+# context.CompileProg(text, ext)
+# Function called to compile a program, using "ext" for
+# the file extention. Must return an empty string for
+# success, an error message for failure.
+# For reliable test results compiling should be done just
+# like an actual source file would be compiled, using the
+# same command and arguments (including configure results
+# so far).
+#
+# context.AppendLIBS(lib_name_list)
+# Append "lib_name_list" to the value of LIBS.
+# "lib_namelist" is a list of strings.
+# Return the value of LIBS before changing it (any type
+# can be used, it is passed to SetLIBS() later.)
+#
+# context.PrependLIBS(lib_name_list)
+# Prepend "lib_name_list" to the value of LIBS.
+# "lib_namelist" is a list of strings.
+# Return the value of LIBS before changing it (any type
+# can be used, it is passed to SetLIBS() later.)
+#
+# context.SetLIBS(value)
+# Set LIBS to "value". The type of "value" is what
+# AppendLIBS() returned.
+# Return the value of LIBS before changing it (any type
+# can be used, it is passed to SetLIBS() later.)
+#
+# context.headerfilename
+# Name of file to append configure results to, usually
+# "confdefs.h".
+# The file must not exist or be empty when starting.
+# Empty or None to skip this (some tests will not work!).
+#
+# context.config_h (may be missing). If present, must be a string, which
+# will be filled with the contents of a config_h file.
+#
+# context.vardict Dictionary holding variables used for the tests and
+# stores results from the tests, used for the build
+# commands.
+# Normally contains "CC", "LIBS", "CPPFLAGS", etc.
+#
+# context.havedict Dictionary holding results from the tests that are to
+# be used inside a program.
+# Names often start with "HAVE_". These are zero
+# (feature not present) or one (feature present). Other
+# variables may have any value, e.g., "PERLVERSION" can
+# be a number and "SYSTEMNAME" a string.
+#
+
+import re
+from types import IntType
+
+#
+# PUBLIC VARIABLES
+#
+
+LogInputFiles = 1 # Set that to log the input files in case of a failed test
+LogErrorMessages = 1 # Set that to log Conftest-generated error messages
+
+#
+# PUBLIC FUNCTIONS
+#
+
+# Generic remarks:
+# - When a language is specified which is not supported the test fails. The
+# message is a bit different, because not all the arguments for the normal
+# message are available yet (chicken-egg problem).
+
+
+def CheckBuilder(context, text = None, language = None):
+ """
+ Configure check to see if the compiler works.
+ Note that this uses the current value of compiler and linker flags, make
+ sure $CFLAGS, $CPPFLAGS and $LIBS are set correctly.
+ "language" should be "C" or "C++" and is used to select the compiler.
+ Default is "C".
+ "text" may be used to specify the code to be build.
+ Returns an empty string for success, an error message for failure.
+ """
+ lang, suffix, msg = _lang2suffix(language)
+ if msg:
+ context.Display("%s\n" % msg)
+ return msg
+
+ if not text:
+ text = """
+int main() {
+ return 0;
+}
+"""
+
+ context.Display("Checking if building a %s file works... " % lang)
+ ret = context.BuildProg(text, suffix)
+ _YesNoResult(context, ret, None, text)
+ return ret
+
+def CheckCC(context):
+ """
+ Configure check for a working C compiler.
+
+ This checks whether the C compiler, as defined in the $CC construction
+ variable, can compile a C source file. It uses the current $CCCOM value
+ too, so that it can test against non working flags.
+
+ """
+ context.Display("Checking whether the C compiler works")
+ text = """
+int main()
+{
+ return 0;
+}
+"""
+ ret = _check_empty_program(context, 'CC', text, 'C')
+ _YesNoResult(context, ret, None, text)
+ return ret
+
+def CheckSHCC(context):
+ """
+ Configure check for a working shared C compiler.
+
+ This checks whether the C compiler, as defined in the $SHCC construction
+ variable, can compile a C source file. It uses the current $SHCCCOM value
+ too, so that it can test against non working flags.
+
+ """
+ context.Display("Checking whether the (shared) C compiler works")
+ text = """
+int foo()
+{
+ return 0;
+}
+"""
+ ret = _check_empty_program(context, 'SHCC', text, 'C', use_shared = True)
+ _YesNoResult(context, ret, None, text)
+ return ret
+
+def CheckCXX(context):
+ """
+ Configure check for a working CXX compiler.
+
+ This checks whether the CXX compiler, as defined in the $CXX construction
+ variable, can compile a CXX source file. It uses the current $CXXCOM value
+ too, so that it can test against non working flags.
+
+ """
+ context.Display("Checking whether the C++ compiler works")
+ text = """
+int main()
+{
+ return 0;
+}
+"""
+ ret = _check_empty_program(context, 'CXX', text, 'C++')
+ _YesNoResult(context, ret, None, text)
+ return ret
+
+def CheckSHCXX(context):
+ """
+ Configure check for a working shared CXX compiler.
+
+ This checks whether the CXX compiler, as defined in the $SHCXX construction
+ variable, can compile a CXX source file. It uses the current $SHCXXCOM value
+ too, so that it can test against non working flags.
+
+ """
+ context.Display("Checking whether the (shared) C++ compiler works")
+ text = """
+int main()
+{
+ return 0;
+}
+"""
+ ret = _check_empty_program(context, 'SHCXX', text, 'C++', use_shared = True)
+ _YesNoResult(context, ret, None, text)
+ return ret
+
+def _check_empty_program(context, comp, text, language, use_shared = False):
+ """Return 0 on success, 1 otherwise."""
+ if comp not in context.env or not context.env[comp]:
+ # The compiler construction variable is not set or empty
+ return 1
+
+ lang, suffix, msg = _lang2suffix(language)
+ if msg:
+ return 1
+
+ if use_shared:
+ return context.CompileSharedObject(text, suffix)
+ else:
+ return context.CompileProg(text, suffix)
+
+
+def CheckFunc(context, function_name, header = None, language = None):
+ """
+ Configure check for a function "function_name".
+ "language" should be "C" or "C++" and is used to select the compiler.
+ Default is "C".
+ Optional "header" can be defined to define a function prototype, include a
+ header file or anything else that comes before main().
+ Sets HAVE_function_name in context.havedict according to the result.
+ Note that this uses the current value of compiler and linker flags, make
+ sure $CFLAGS, $CPPFLAGS and $LIBS are set correctly.
+ Returns an empty string for success, an error message for failure.
+ """
+
+ # Remarks from autoconf:
+ # - Don't include <ctype.h> because on OSF/1 3.0 it includes <sys/types.h>
+ # which includes <sys/select.h> which contains a prototype for select.
+ # Similarly for bzero.
+ # - assert.h is included to define __stub macros and hopefully few
+ # prototypes, which can conflict with char $1(); below.
+ # - Override any gcc2 internal prototype to avoid an error.
+ # - We use char for the function declaration because int might match the
+ # return type of a gcc2 builtin and then its argument prototype would
+ # still apply.
+ # - The GNU C library defines this for functions which it implements to
+ # always fail with ENOSYS. Some functions are actually named something
+ # starting with __ and the normal name is an alias.
+
+ if context.headerfilename:
+ includetext = '#include "%s"' % context.headerfilename
+ else:
+ includetext = ''
+ if not header:
+ header = """
+#ifdef __cplusplus
+extern "C"
+#endif
+char %s();""" % function_name
+
+ lang, suffix, msg = _lang2suffix(language)
+ if msg:
+ context.Display("Cannot check for %s(): %s\n" % (function_name, msg))
+ return msg
+
+ text = """
+%(include)s
+#include <assert.h>
+%(hdr)s
+
+int main() {
+#if defined (__stub_%(name)s) || defined (__stub___%(name)s)
+ fail fail fail
+#else
+ %(name)s();
+#endif
+
+ return 0;
+}
+""" % { 'name': function_name,
+ 'include': includetext,
+ 'hdr': header }
+
+ context.Display("Checking for %s function %s()... " % (lang, function_name))
+ ret = context.BuildProg(text, suffix)
+ _YesNoResult(context, ret, "HAVE_" + function_name, text,
+ "Define to 1 if the system has the function `%s'." %\
+ function_name)
+ return ret
+
+
+def CheckHeader(context, header_name, header = None, language = None,
+ include_quotes = None):
+ """
+ Configure check for a C or C++ header file "header_name".
+ Optional "header" can be defined to do something before including the
+ header file (unusual, supported for consistency).
+ "language" should be "C" or "C++" and is used to select the compiler.
+ Default is "C".
+ Sets HAVE_header_name in context.havedict according to the result.
+ Note that this uses the current value of compiler and linker flags, make
+ sure $CFLAGS and $CPPFLAGS are set correctly.
+ Returns an empty string for success, an error message for failure.
+ """
+ # Why compile the program instead of just running the preprocessor?
+ # It is possible that the header file exists, but actually using it may
+ # fail (e.g., because it depends on other header files). Thus this test is
+ # more strict. It may require using the "header" argument.
+ #
+ # Use <> by default, because the check is normally used for system header
+ # files. SCons passes '""' to overrule this.
+
+ # Include "confdefs.h" first, so that the header can use HAVE_HEADER_H.
+ if context.headerfilename:
+ includetext = '#include "%s"\n' % context.headerfilename
+ else:
+ includetext = ''
+ if not header:
+ header = ""
+
+ lang, suffix, msg = _lang2suffix(language)
+ if msg:
+ context.Display("Cannot check for header file %s: %s\n"
+ % (header_name, msg))
+ return msg
+
+ if not include_quotes:
+ include_quotes = "<>"
+
+ text = "%s%s\n#include %s%s%s\n\n" % (includetext, header,
+ include_quotes[0], header_name, include_quotes[1])
+
+ context.Display("Checking for %s header file %s... " % (lang, header_name))
+ ret = context.CompileProg(text, suffix)
+ _YesNoResult(context, ret, "HAVE_" + header_name, text,
+ "Define to 1 if you have the <%s> header file." % header_name)
+ return ret
+
+
+def CheckType(context, type_name, fallback = None,
+ header = None, language = None):
+ """
+ Configure check for a C or C++ type "type_name".
+ Optional "header" can be defined to include a header file.
+ "language" should be "C" or "C++" and is used to select the compiler.
+ Default is "C".
+ Sets HAVE_type_name in context.havedict according to the result.
+ Note that this uses the current value of compiler and linker flags, make
+ sure $CFLAGS, $CPPFLAGS and $LIBS are set correctly.
+ Returns an empty string for success, an error message for failure.
+ """
+
+ # Include "confdefs.h" first, so that the header can use HAVE_HEADER_H.
+ if context.headerfilename:
+ includetext = '#include "%s"' % context.headerfilename
+ else:
+ includetext = ''
+ if not header:
+ header = ""
+
+ lang, suffix, msg = _lang2suffix(language)
+ if msg:
+ context.Display("Cannot check for %s type: %s\n" % (type_name, msg))
+ return msg
+
+ # Remarks from autoconf about this test:
+ # - Grepping for the type in include files is not reliable (grep isn't
+ # portable anyway).
+ # - Using "TYPE my_var;" doesn't work for const qualified types in C++.
+ # Adding an initializer is not valid for some C++ classes.
+ # - Using the type as parameter to a function either fails for K&$ C or for
+ # C++.
+ # - Using "TYPE *my_var;" is valid in C for some types that are not
+ # declared (struct something).
+ # - Using "sizeof(TYPE)" is valid when TYPE is actually a variable.
+ # - Using the previous two together works reliably.
+ text = """
+%(include)s
+%(header)s
+
+int main() {
+ if ((%(name)s *) 0)
+ return 0;
+ if (sizeof (%(name)s))
+ return 0;
+}
+""" % { 'include': includetext,
+ 'header': header,
+ 'name': type_name }
+
+ context.Display("Checking for %s type %s... " % (lang, type_name))
+ ret = context.BuildProg(text, suffix)
+ _YesNoResult(context, ret, "HAVE_" + type_name, text,
+ "Define to 1 if the system has the type `%s'." % type_name)
+ if ret and fallback and context.headerfilename:
+ f = open(context.headerfilename, "a")
+ f.write("typedef %s %s;\n" % (fallback, type_name))
+ f.close()
+
+ return ret
+
+def CheckTypeSize(context, type_name, header = None, language = None, expect = None):
+ """This check can be used to get the size of a given type, or to check whether
+ the type is of expected size.
+
+ Arguments:
+ - type : str
+ the type to check
+ - includes : sequence
+ list of headers to include in the test code before testing the type
+ - language : str
+ 'C' or 'C++'
+ - expect : int
+ if given, will test wether the type has the given number of bytes.
+ If not given, will automatically find the size.
+
+ Returns:
+ status : int
+ 0 if the check failed, or the found size of the type if the check succeeded."""
+
+ # Include "confdefs.h" first, so that the header can use HAVE_HEADER_H.
+ if context.headerfilename:
+ includetext = '#include "%s"' % context.headerfilename
+ else:
+ includetext = ''
+
+ if not header:
+ header = ""
+
+ lang, suffix, msg = _lang2suffix(language)
+ if msg:
+ context.Display("Cannot check for %s type: %s\n" % (type_name, msg))
+ return msg
+
+ src = includetext + header
+ if not expect is None:
+ # Only check if the given size is the right one
+ context.Display('Checking %s is %d bytes... ' % (type_name, expect))
+
+ # test code taken from autoconf: this is a pretty clever hack to find that
+ # a type is of a given size using only compilation. This speeds things up
+ # quite a bit compared to straightforward code using TryRun
+ src = src + r"""
+typedef %s scons_check_type;
+
+int main()
+{
+ static int test_array[1 - 2 * !(((long int) (sizeof(scons_check_type))) == %d)];
+ test_array[0] = 0;
+
+ return 0;
+}
+"""
+
+ st = context.CompileProg(src % (type_name, expect), suffix)
+ if not st:
+ context.Display("yes\n")
+ _Have(context, "SIZEOF_%s" % type_name, expect,
+ "The size of `%s', as computed by sizeof." % type_name)
+ return expect
+ else:
+ context.Display("no\n")
+ _LogFailed(context, src, st)
+ return 0
+ else:
+ # Only check if the given size is the right one
+ context.Message('Checking size of %s ... ' % type_name)
+
+ # We have to be careful with the program we wish to test here since
+ # compilation will be attempted using the current environment's flags.
+ # So make sure that the program will compile without any warning. For
+ # example using: 'int main(int argc, char** argv)' will fail with the
+ # '-Wall -Werror' flags since the variables argc and argv would not be
+ # used in the program...
+ #
+ src = src + """
+#include <stdlib.h>
+#include <stdio.h>
+int main() {
+ printf("%d", (int)sizeof(""" + type_name + """));
+ return 0;
+}
+ """
+ st, out = context.RunProg(src, suffix)
+ try:
+ size = int(out)
+ except ValueError:
+ # If cannot convert output of test prog to an integer (the size),
+ # something went wront, so just fail
+ st = 1
+ size = 0
+
+ if not st:
+ context.Display("yes\n")
+ _Have(context, "SIZEOF_%s" % type_name, size,
+ "The size of `%s', as computed by sizeof." % type_name)
+ return size
+ else:
+ context.Display("no\n")
+ _LogFailed(context, src, st)
+ return 0
+
+ return 0
+
+def CheckDeclaration(context, symbol, includes = None, language = None):
+ """Checks whether symbol is declared.
+
+ Use the same test as autoconf, that is test whether the symbol is defined
+ as a macro or can be used as an r-value.
+
+ Arguments:
+ symbol : str
+ the symbol to check
+ includes : str
+ Optional "header" can be defined to include a header file.
+ language : str
+ only C and C++ supported.
+
+ Returns:
+ status : bool
+ True if the check failed, False if succeeded."""
+
+ # Include "confdefs.h" first, so that the header can use HAVE_HEADER_H.
+ if context.headerfilename:
+ includetext = '#include "%s"' % context.headerfilename
+ else:
+ includetext = ''
+
+ if not includes:
+ includes = ""
+
+ lang, suffix, msg = _lang2suffix(language)
+ if msg:
+ context.Display("Cannot check for declaration %s: %s\n" % (type_name, msg))
+ return msg
+
+ src = includetext + includes
+ context.Display('Checking whether %s is declared... ' % symbol)
+
+ src = src + r"""
+int main()
+{
+#ifndef %s
+ (void) %s;
+#endif
+ ;
+ return 0;
+}
+""" % (symbol, symbol)
+
+ st = context.CompileProg(src, suffix)
+ _YesNoResult(context, st, "HAVE_DECL_" + symbol, src,
+ "Set to 1 if %s is defined." % symbol)
+ return st
+
+def CheckLib(context, libs, func_name = None, header = None,
+ extra_libs = None, call = None, language = None, autoadd = 1,
+ append = True):
+ """
+ Configure check for a C or C++ libraries "libs". Searches through
+ the list of libraries, until one is found where the test succeeds.
+ Tests if "func_name" or "call" exists in the library. Note: if it exists
+ in another library the test succeeds anyway!
+ Optional "header" can be defined to include a header file. If not given a
+ default prototype for "func_name" is added.
+ Optional "extra_libs" is a list of library names to be added after
+ "lib_name" in the build command. To be used for libraries that "lib_name"
+ depends on.
+ Optional "call" replaces the call to "func_name" in the test code. It must
+ consist of complete C statements, including a trailing ";".
+ Both "func_name" and "call" arguments are optional, and in that case, just
+ linking against the libs is tested.
+ "language" should be "C" or "C++" and is used to select the compiler.
+ Default is "C".
+ Note that this uses the current value of compiler and linker flags, make
+ sure $CFLAGS, $CPPFLAGS and $LIBS are set correctly.
+ Returns an empty string for success, an error message for failure.
+ """
+ # Include "confdefs.h" first, so that the header can use HAVE_HEADER_H.
+ if context.headerfilename:
+ includetext = '#include "%s"' % context.headerfilename
+ else:
+ includetext = ''
+ if not header:
+ header = ""
+
+ text = """
+%s
+%s""" % (includetext, header)
+
+ # Add a function declaration if needed.
+ if func_name and func_name != "main":
+ if not header:
+ text = text + """
+#ifdef __cplusplus
+extern "C"
+#endif
+char %s();
+""" % func_name
+
+ # The actual test code.
+ if not call:
+ call = "%s();" % func_name
+
+ # if no function to test, leave main() blank
+ text = text + """
+int
+main() {
+ %s
+return 0;
+}
+""" % (call or "")
+
+ if call:
+ i = call.find("\n")
+ if i > 0:
+ calltext = call[:i] + ".."
+ elif call[-1] == ';':
+ calltext = call[:-1]
+ else:
+ calltext = call
+
+ for lib_name in libs:
+
+ lang, suffix, msg = _lang2suffix(language)
+ if msg:
+ context.Display("Cannot check for library %s: %s\n" % (lib_name, msg))
+ return msg
+
+ # if a function was specified to run in main(), say it
+ if call:
+ context.Display("Checking for %s in %s library %s... "
+ % (calltext, lang, lib_name))
+ # otherwise, just say the name of library and language
+ else:
+ context.Display("Checking for %s library %s... "
+ % (lang, lib_name))
+
+ if lib_name:
+ l = [ lib_name ]
+ if extra_libs:
+ l.extend(extra_libs)
+ if append:
+ oldLIBS = context.AppendLIBS(l)
+ else:
+ oldLIBS = context.PrependLIBS(l)
+ sym = "HAVE_LIB" + lib_name
+ else:
+ oldLIBS = -1
+ sym = None
+
+ ret = context.BuildProg(text, suffix)
+
+ _YesNoResult(context, ret, sym, text,
+ "Define to 1 if you have the `%s' library." % lib_name)
+ if oldLIBS != -1 and (ret or not autoadd):
+ context.SetLIBS(oldLIBS)
+
+ if not ret:
+ return ret
+
+ return ret
+
+#
+# END OF PUBLIC FUNCTIONS
+#
+
+def _YesNoResult(context, ret, key, text, comment = None):
+ """
+ Handle the result of a test with a "yes" or "no" result.
+ "ret" is the return value: empty if OK, error message when not.
+ "key" is the name of the symbol to be defined (HAVE_foo).
+ "text" is the source code of the program used for testing.
+ "comment" is the C comment to add above the line defining the symbol (the
+ comment is automatically put inside a /* */). If None, no comment is added.
+ """
+ if key:
+ _Have(context, key, not ret, comment)
+ if ret:
+ context.Display("no\n")
+ _LogFailed(context, text, ret)
+ else:
+ context.Display("yes\n")
+
+
+def _Have(context, key, have, comment = None):
+ """
+ Store result of a test in context.havedict and context.headerfilename.
+ "key" is a "HAVE_abc" name. It is turned into all CAPITALS and non-
+ alphanumerics are replaced by an underscore.
+ The value of "have" can be:
+ 1 - Feature is defined, add "#define key".
+ 0 - Feature is not defined, add "/* #undef key */".
+ Adding "undef" is what autoconf does. Not useful for the
+ compiler, but it shows that the test was done.
+ number - Feature is defined to this number "#define key have".
+ Doesn't work for 0 or 1, use a string then.
+ string - Feature is defined to this string "#define key have".
+ Give "have" as is should appear in the header file, include quotes
+ when desired and escape special characters!
+ """
+ key_up = key.upper()
+ key_up = re.sub('[^A-Z0-9_]', '_', key_up)
+ context.havedict[key_up] = have
+ if have == 1:
+ line = "#define %s 1\n" % key_up
+ elif have == 0:
+ line = "/* #undef %s */\n" % key_up
+ elif isinstance(have, IntType):
+ line = "#define %s %d\n" % (key_up, have)
+ else:
+ line = "#define %s %s\n" % (key_up, str(have))
+
+ if comment is not None:
+ lines = "\n/* %s */\n" % comment + line
+ else:
+ lines = "\n" + line
+
+ if context.headerfilename:
+ f = open(context.headerfilename, "a")
+ f.write(lines)
+ f.close()
+ elif hasattr(context,'config_h'):
+ context.config_h = context.config_h + lines
+
+
+def _LogFailed(context, text, msg):
+ """
+ Write to the log about a failed program.
+ Add line numbers, so that error messages can be understood.
+ """
+ if LogInputFiles:
+ context.Log("Failed program was:\n")
+ lines = text.split('\n')
+ if len(lines) and lines[-1] == '':
+ lines = lines[:-1] # remove trailing empty line
+ n = 1
+ for line in lines:
+ context.Log("%d: %s\n" % (n, line))
+ n = n + 1
+ if LogErrorMessages:
+ context.Log("Error message: %s\n" % msg)
+
+
+def _lang2suffix(lang):
+ """
+ Convert a language name to a suffix.
+ When "lang" is empty or None C is assumed.
+ Returns a tuple (lang, suffix, None) when it works.
+ For an unrecognized language returns (None, None, msg).
+ Where:
+ lang = the unified language name
+ suffix = the suffix, including the leading dot
+ msg = an error message
+ """
+ if not lang or lang in ["C", "c"]:
+ return ("C", ".c", None)
+ if lang in ["c++", "C++", "cpp", "CXX", "cxx"]:
+ return ("C++", ".cpp", None)
+
+ return None, None, "Unsupported language: %s" % lang
+
+
+# vim: set sw=4 et sts=4 tw=79 fo+=l:
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Debug.py b/couchjs/scons/scons-local-2.0.1/SCons/Debug.py
new file mode 100644
index 00000000..f4eb65f2
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Debug.py
@@ -0,0 +1,220 @@
+"""SCons.Debug
+
+Code for debugging SCons internal things. Shouldn't be
+needed by most users.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Debug.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+import sys
+import time
+import weakref
+
+tracked_classes = {}
+
+def logInstanceCreation(instance, name=None):
+ if name is None:
+ name = instance.__class__.__name__
+ if name not in tracked_classes:
+ tracked_classes[name] = []
+ tracked_classes[name].append(weakref.ref(instance))
+
+def string_to_classes(s):
+ if s == '*':
+ return sorted(tracked_classes.keys())
+ else:
+ return s.split()
+
+def fetchLoggedInstances(classes="*"):
+ classnames = string_to_classes(classes)
+ return [(cn, len(tracked_classes[cn])) for cn in classnames]
+
+def countLoggedInstances(classes, file=sys.stdout):
+ for classname in string_to_classes(classes):
+ file.write("%s: %d\n" % (classname, len(tracked_classes[classname])))
+
+def listLoggedInstances(classes, file=sys.stdout):
+ for classname in string_to_classes(classes):
+ file.write('\n%s:\n' % classname)
+ for ref in tracked_classes[classname]:
+ obj = ref()
+ if obj is not None:
+ file.write(' %s\n' % repr(obj))
+
+def dumpLoggedInstances(classes, file=sys.stdout):
+ for classname in string_to_classes(classes):
+ file.write('\n%s:\n' % classname)
+ for ref in tracked_classes[classname]:
+ obj = ref()
+ if obj is not None:
+ file.write(' %s:\n' % obj)
+ for key, value in obj.__dict__.items():
+ file.write(' %20s : %s\n' % (key, value))
+
+
+
+if sys.platform[:5] == "linux":
+ # Linux doesn't actually support memory usage stats from getrusage().
+ def memory():
+ mstr = open('/proc/self/stat').read()
+ mstr = mstr.split()[22]
+ return int(mstr)
+elif sys.platform[:6] == 'darwin':
+ #TODO really get memory stats for OS X
+ def memory():
+ return 0
+else:
+ try:
+ import resource
+ except ImportError:
+ try:
+ import win32process
+ import win32api
+ except ImportError:
+ def memory():
+ return 0
+ else:
+ def memory():
+ process_handle = win32api.GetCurrentProcess()
+ memory_info = win32process.GetProcessMemoryInfo( process_handle )
+ return memory_info['PeakWorkingSetSize']
+ else:
+ def memory():
+ res = resource.getrusage(resource.RUSAGE_SELF)
+ return res[4]
+
+# returns caller's stack
+def caller_stack(*backlist):
+ import traceback
+ if not backlist:
+ backlist = [0]
+ result = []
+ for back in backlist:
+ tb = traceback.extract_stack(limit=3+back)
+ key = tb[0][:3]
+ result.append('%s:%d(%s)' % func_shorten(key))
+ return result
+
+caller_bases = {}
+caller_dicts = {}
+
+# trace a caller's stack
+def caller_trace(back=0):
+ import traceback
+ tb = traceback.extract_stack(limit=3+back)
+ tb.reverse()
+ callee = tb[1][:3]
+ caller_bases[callee] = caller_bases.get(callee, 0) + 1
+ for caller in tb[2:]:
+ caller = callee + caller[:3]
+ try:
+ entry = caller_dicts[callee]
+ except KeyError:
+ caller_dicts[callee] = entry = {}
+ entry[caller] = entry.get(caller, 0) + 1
+ callee = caller
+
+# print a single caller and its callers, if any
+def _dump_one_caller(key, file, level=0):
+ leader = ' '*level
+ for v,c in sorted([(-v,c) for c,v in caller_dicts[key].items()]):
+ file.write("%s %6d %s:%d(%s)\n" % ((leader,-v) + func_shorten(c[-3:])))
+ if c in caller_dicts:
+ _dump_one_caller(c, file, level+1)
+
+# print each call tree
+def dump_caller_counts(file=sys.stdout):
+ for k in sorted(caller_bases.keys()):
+ file.write("Callers of %s:%d(%s), %d calls:\n"
+ % (func_shorten(k) + (caller_bases[k],)))
+ _dump_one_caller(k, file)
+
+shorten_list = [
+ ( '/scons/SCons/', 1),
+ ( '/src/engine/SCons/', 1),
+ ( '/usr/lib/python', 0),
+]
+
+if os.sep != '/':
+ shorten_list = [(t[0].replace('/', os.sep), t[1]) for t in shorten_list]
+
+def func_shorten(func_tuple):
+ f = func_tuple[0]
+ for t in shorten_list:
+ i = f.find(t[0])
+ if i >= 0:
+ if t[1]:
+ i = i + len(t[0])
+ return (f[i:],)+func_tuple[1:]
+ return func_tuple
+
+
+TraceFP = {}
+if sys.platform == 'win32':
+ TraceDefault = 'con'
+else:
+ TraceDefault = '/dev/tty'
+
+TimeStampDefault = None
+StartTime = time.time()
+PreviousTime = StartTime
+
+def Trace(msg, file=None, mode='w', tstamp=None):
+ """Write a trace message to a file. Whenever a file is specified,
+ it becomes the default for the next call to Trace()."""
+ global TraceDefault
+ global TimeStampDefault
+ global PreviousTime
+ if file is None:
+ file = TraceDefault
+ else:
+ TraceDefault = file
+ if tstamp is None:
+ tstamp = TimeStampDefault
+ else:
+ TimeStampDefault = tstamp
+ try:
+ fp = TraceFP[file]
+ except KeyError:
+ try:
+ fp = TraceFP[file] = open(file, mode)
+ except TypeError:
+ # Assume we were passed an open file pointer.
+ fp = file
+ if tstamp:
+ now = time.time()
+ fp.write('%8.4f %8.4f: ' % (now - StartTime, now - PreviousTime))
+ PreviousTime = now
+ fp.write(msg)
+ fp.flush()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Defaults.py b/couchjs/scons/scons-local-2.0.1/SCons/Defaults.py
new file mode 100644
index 00000000..f6b0fd11
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Defaults.py
@@ -0,0 +1,480 @@
+"""SCons.Defaults
+
+Builders and other things for the local site. Here's where we'll
+duplicate the functionality of autoconf until we move it into the
+installation procedure or use something like qmconf.
+
+The code that reads the registry to find MSVC components was borrowed
+from distutils.msvccompiler.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+from __future__ import division
+
+__revision__ = "src/engine/SCons/Defaults.py 5134 2010/08/16 23:02:40 bdeegan"
+
+
+import os
+import errno
+import shutil
+import stat
+import time
+import sys
+
+import SCons.Action
+import SCons.Builder
+import SCons.CacheDir
+import SCons.Environment
+import SCons.PathList
+import SCons.Subst
+import SCons.Tool
+
+# A placeholder for a default Environment (for fetching source files
+# from source code management systems and the like). This must be
+# initialized later, after the top-level directory is set by the calling
+# interface.
+_default_env = None
+
+# Lazily instantiate the default environment so the overhead of creating
+# it doesn't apply when it's not needed.
+def _fetch_DefaultEnvironment(*args, **kw):
+ """
+ Returns the already-created default construction environment.
+ """
+ global _default_env
+ return _default_env
+
+def DefaultEnvironment(*args, **kw):
+ """
+ Initial public entry point for creating the default construction
+ Environment.
+
+ After creating the environment, we overwrite our name
+ (DefaultEnvironment) with the _fetch_DefaultEnvironment() function,
+ which more efficiently returns the initialized default construction
+ environment without checking for its existence.
+
+ (This function still exists with its _default_check because someone
+ else (*cough* Script/__init__.py *cough*) may keep a reference
+ to this function. So we can't use the fully functional idiom of
+ having the name originally be a something that *only* creates the
+ construction environment and then overwrites the name.)
+ """
+ global _default_env
+ if not _default_env:
+ import SCons.Util
+ _default_env = SCons.Environment.Environment(*args, **kw)
+ if SCons.Util.md5:
+ _default_env.Decider('MD5')
+ else:
+ _default_env.Decider('timestamp-match')
+ global DefaultEnvironment
+ DefaultEnvironment = _fetch_DefaultEnvironment
+ _default_env._CacheDir_path = None
+ return _default_env
+
+# Emitters for setting the shared attribute on object files,
+# and an action for checking that all of the source files
+# going into a shared library are, in fact, shared.
+def StaticObjectEmitter(target, source, env):
+ for tgt in target:
+ tgt.attributes.shared = None
+ return (target, source)
+
+def SharedObjectEmitter(target, source, env):
+ for tgt in target:
+ tgt.attributes.shared = 1
+ return (target, source)
+
+def SharedFlagChecker(source, target, env):
+ same = env.subst('$STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME')
+ if same == '0' or same == '' or same == 'False':
+ for src in source:
+ try:
+ shared = src.attributes.shared
+ except AttributeError:
+ shared = None
+ if not shared:
+ raise SCons.Errors.UserError("Source file: %s is static and is not compatible with shared target: %s" % (src, target[0]))
+
+SharedCheck = SCons.Action.Action(SharedFlagChecker, None)
+
+# Some people were using these variable name before we made
+# SourceFileScanner part of the public interface. Don't break their
+# SConscript files until we've given them some fair warning and a
+# transition period.
+CScan = SCons.Tool.CScanner
+DScan = SCons.Tool.DScanner
+LaTeXScan = SCons.Tool.LaTeXScanner
+ObjSourceScan = SCons.Tool.SourceFileScanner
+ProgScan = SCons.Tool.ProgramScanner
+
+# These aren't really tool scanners, so they don't quite belong with
+# the rest of those in Tool/__init__.py, but I'm not sure where else
+# they should go. Leave them here for now.
+import SCons.Scanner.Dir
+DirScanner = SCons.Scanner.Dir.DirScanner()
+DirEntryScanner = SCons.Scanner.Dir.DirEntryScanner()
+
+# Actions for common languages.
+CAction = SCons.Action.Action("$CCCOM", "$CCCOMSTR")
+ShCAction = SCons.Action.Action("$SHCCCOM", "$SHCCCOMSTR")
+CXXAction = SCons.Action.Action("$CXXCOM", "$CXXCOMSTR")
+ShCXXAction = SCons.Action.Action("$SHCXXCOM", "$SHCXXCOMSTR")
+
+ASAction = SCons.Action.Action("$ASCOM", "$ASCOMSTR")
+ASPPAction = SCons.Action.Action("$ASPPCOM", "$ASPPCOMSTR")
+
+LinkAction = SCons.Action.Action("$LINKCOM", "$LINKCOMSTR")
+ShLinkAction = SCons.Action.Action("$SHLINKCOM", "$SHLINKCOMSTR")
+
+LdModuleLinkAction = SCons.Action.Action("$LDMODULECOM", "$LDMODULECOMSTR")
+
+# Common tasks that we allow users to perform in platform-independent
+# ways by creating ActionFactory instances.
+ActionFactory = SCons.Action.ActionFactory
+
+def get_paths_str(dest):
+ # If dest is a list, we need to manually call str() on each element
+ if SCons.Util.is_List(dest):
+ elem_strs = []
+ for element in dest:
+ elem_strs.append('"' + str(element) + '"')
+ return '[' + ', '.join(elem_strs) + ']'
+ else:
+ return '"' + str(dest) + '"'
+
+def chmod_func(dest, mode):
+ SCons.Node.FS.invalidate_node_memos(dest)
+ if not SCons.Util.is_List(dest):
+ dest = [dest]
+ for element in dest:
+ os.chmod(str(element), mode)
+
+def chmod_strfunc(dest, mode):
+ return 'Chmod(%s, 0%o)' % (get_paths_str(dest), mode)
+
+Chmod = ActionFactory(chmod_func, chmod_strfunc)
+
+def copy_func(dest, src):
+ SCons.Node.FS.invalidate_node_memos(dest)
+ if SCons.Util.is_List(src) and os.path.isdir(dest):
+ for file in src:
+ shutil.copy2(file, dest)
+ return 0
+ elif os.path.isfile(src):
+ return shutil.copy2(src, dest)
+ else:
+ return shutil.copytree(src, dest, 1)
+
+Copy = ActionFactory(copy_func,
+ lambda dest, src: 'Copy("%s", "%s")' % (dest, src),
+ convert=str)
+
+def delete_func(dest, must_exist=0):
+ SCons.Node.FS.invalidate_node_memos(dest)
+ if not SCons.Util.is_List(dest):
+ dest = [dest]
+ for entry in dest:
+ entry = str(entry)
+ if not must_exist and not os.path.exists(entry):
+ continue
+ if not os.path.exists(entry) or os.path.isfile(entry):
+ os.unlink(entry)
+ continue
+ else:
+ shutil.rmtree(entry, 1)
+ continue
+
+def delete_strfunc(dest, must_exist=0):
+ return 'Delete(%s)' % get_paths_str(dest)
+
+Delete = ActionFactory(delete_func, delete_strfunc)
+
+def mkdir_func(dest):
+ SCons.Node.FS.invalidate_node_memos(dest)
+ if not SCons.Util.is_List(dest):
+ dest = [dest]
+ for entry in dest:
+ try:
+ os.makedirs(str(entry))
+ except os.error, e:
+ p = str(entry)
+ if (e.args[0] == errno.EEXIST or
+ (sys.platform=='win32' and e.args[0]==183)) \
+ and os.path.isdir(str(entry)):
+ pass # not an error if already exists
+ else:
+ raise
+
+Mkdir = ActionFactory(mkdir_func,
+ lambda dir: 'Mkdir(%s)' % get_paths_str(dir))
+
+def move_func(dest, src):
+ SCons.Node.FS.invalidate_node_memos(dest)
+ SCons.Node.FS.invalidate_node_memos(src)
+ shutil.move(src, dest)
+
+Move = ActionFactory(move_func,
+ lambda dest, src: 'Move("%s", "%s")' % (dest, src),
+ convert=str)
+
+def touch_func(dest):
+ SCons.Node.FS.invalidate_node_memos(dest)
+ if not SCons.Util.is_List(dest):
+ dest = [dest]
+ for file in dest:
+ file = str(file)
+ mtime = int(time.time())
+ if os.path.exists(file):
+ atime = os.path.getatime(file)
+ else:
+ open(file, 'w')
+ atime = mtime
+ os.utime(file, (atime, mtime))
+
+Touch = ActionFactory(touch_func,
+ lambda file: 'Touch(%s)' % get_paths_str(file))
+
+# Internal utility functions
+
+def _concat(prefix, list, suffix, env, f=lambda x: x, target=None, source=None):
+ """
+ Creates a new list from 'list' by first interpolating each element
+ in the list using the 'env' dictionary and then calling f on the
+ list, and finally calling _concat_ixes to concatenate 'prefix' and
+ 'suffix' onto each element of the list.
+ """
+ if not list:
+ return list
+
+ l = f(SCons.PathList.PathList(list).subst_path(env, target, source))
+ if l is not None:
+ list = l
+
+ return _concat_ixes(prefix, list, suffix, env)
+
+def _concat_ixes(prefix, list, suffix, env):
+ """
+ Creates a new list from 'list' by concatenating the 'prefix' and
+ 'suffix' arguments onto each element of the list. A trailing space
+ on 'prefix' or leading space on 'suffix' will cause them to be put
+ into separate list elements rather than being concatenated.
+ """
+
+ result = []
+
+ # ensure that prefix and suffix are strings
+ prefix = str(env.subst(prefix, SCons.Subst.SUBST_RAW))
+ suffix = str(env.subst(suffix, SCons.Subst.SUBST_RAW))
+
+ for x in list:
+ if isinstance(x, SCons.Node.FS.File):
+ result.append(x)
+ continue
+ x = str(x)
+ if x:
+
+ if prefix:
+ if prefix[-1] == ' ':
+ result.append(prefix[:-1])
+ elif x[:len(prefix)] != prefix:
+ x = prefix + x
+
+ result.append(x)
+
+ if suffix:
+ if suffix[0] == ' ':
+ result.append(suffix[1:])
+ elif x[-len(suffix):] != suffix:
+ result[-1] = result[-1]+suffix
+
+ return result
+
+def _stripixes(prefix, itms, suffix, stripprefixes, stripsuffixes, env, c=None):
+ """
+ This is a wrapper around _concat()/_concat_ixes() that checks for
+ the existence of prefixes or suffixes on list items and strips them
+ where it finds them. This is used by tools (like the GNU linker)
+ that need to turn something like 'libfoo.a' into '-lfoo'.
+ """
+
+ if not itms:
+ return itms
+
+ if not callable(c):
+ env_c = env['_concat']
+ if env_c != _concat and callable(env_c):
+ # There's a custom _concat() method in the construction
+ # environment, and we've allowed people to set that in
+ # the past (see test/custom-concat.py), so preserve the
+ # backwards compatibility.
+ c = env_c
+ else:
+ c = _concat_ixes
+
+ stripprefixes = list(map(env.subst, SCons.Util.flatten(stripprefixes)))
+ stripsuffixes = list(map(env.subst, SCons.Util.flatten(stripsuffixes)))
+
+ stripped = []
+ for l in SCons.PathList.PathList(itms).subst_path(env, None, None):
+ if isinstance(l, SCons.Node.FS.File):
+ stripped.append(l)
+ continue
+
+ if not SCons.Util.is_String(l):
+ l = str(l)
+
+ for stripprefix in stripprefixes:
+ lsp = len(stripprefix)
+ if l[:lsp] == stripprefix:
+ l = l[lsp:]
+ # Do not strip more than one prefix
+ break
+
+ for stripsuffix in stripsuffixes:
+ lss = len(stripsuffix)
+ if l[-lss:] == stripsuffix:
+ l = l[:-lss]
+ # Do not strip more than one suffix
+ break
+
+ stripped.append(l)
+
+ return c(prefix, stripped, suffix, env)
+
+def processDefines(defs):
+ """process defines, resolving strings, lists, dictionaries, into a list of
+ strings
+ """
+ if SCons.Util.is_List(defs):
+ l = []
+ for d in defs:
+ if SCons.Util.is_List(d) or isinstance(d, tuple):
+ l.append(str(d[0]) + '=' + str(d[1]))
+ else:
+ l.append(str(d))
+ elif SCons.Util.is_Dict(defs):
+ # The items in a dictionary are stored in random order, but
+ # if the order of the command-line options changes from
+ # invocation to invocation, then the signature of the command
+ # line will change and we'll get random unnecessary rebuilds.
+ # Consequently, we have to sort the keys to ensure a
+ # consistent order...
+ l = []
+ for k,v in sorted(defs.items()):
+ if v is None:
+ l.append(str(k))
+ else:
+ l.append(str(k) + '=' + str(v))
+ else:
+ l = [str(defs)]
+ return l
+
+def _defines(prefix, defs, suffix, env, c=_concat_ixes):
+ """A wrapper around _concat_ixes that turns a list or string
+ into a list of C preprocessor command-line definitions.
+ """
+
+ return c(prefix, env.subst_path(processDefines(defs)), suffix, env)
+
+class NullCmdGenerator(object):
+ """This is a callable class that can be used in place of other
+ command generators if you don't want them to do anything.
+
+ The __call__ method for this class simply returns the thing
+ you instantiated it with.
+
+ Example usage:
+ env["DO_NOTHING"] = NullCmdGenerator
+ env["LINKCOM"] = "${DO_NOTHING('$LINK $SOURCES $TARGET')}"
+ """
+
+ def __init__(self, cmd):
+ self.cmd = cmd
+
+ def __call__(self, target, source, env, for_signature=None):
+ return self.cmd
+
+class Variable_Method_Caller(object):
+ """A class for finding a construction variable on the stack and
+ calling one of its methods.
+
+ We use this to support "construction variables" in our string
+ eval()s that actually stand in for methods--specifically, use
+ of "RDirs" in call to _concat that should actually execute the
+ "TARGET.RDirs" method. (We used to support this by creating a little
+ "build dictionary" that mapped RDirs to the method, but this got in
+ the way of Memoizing construction environments, because we had to
+ create new environment objects to hold the variables.)
+ """
+ def __init__(self, variable, method):
+ self.variable = variable
+ self.method = method
+ def __call__(self, *args, **kw):
+ try: 1//0
+ except ZeroDivisionError:
+ # Don't start iterating with the current stack-frame to
+ # prevent creating reference cycles (f_back is safe).
+ frame = sys.exc_info()[2].tb_frame.f_back
+ variable = self.variable
+ while frame:
+ if variable in frame.f_locals:
+ v = frame.f_locals[variable]
+ if v:
+ method = getattr(v, self.method)
+ return method(*args, **kw)
+ frame = frame.f_back
+ return None
+
+ConstructionEnvironment = {
+ 'BUILDERS' : {},
+ 'SCANNERS' : [],
+ 'CONFIGUREDIR' : '#/.sconf_temp',
+ 'CONFIGURELOG' : '#/config.log',
+ 'CPPSUFFIXES' : SCons.Tool.CSuffixes,
+ 'DSUFFIXES' : SCons.Tool.DSuffixes,
+ 'ENV' : {},
+ 'IDLSUFFIXES' : SCons.Tool.IDLSuffixes,
+# 'LATEXSUFFIXES' : SCons.Tool.LaTeXSuffixes, # moved to the TeX tools generate functions
+ '_concat' : _concat,
+ '_defines' : _defines,
+ '_stripixes' : _stripixes,
+ '_LIBFLAGS' : '${_concat(LIBLINKPREFIX, LIBS, LIBLINKSUFFIX, __env__)}',
+ '_LIBDIRFLAGS' : '$( ${_concat(LIBDIRPREFIX, LIBPATH, LIBDIRSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)',
+ '_CPPINCFLAGS' : '$( ${_concat(INCPREFIX, CPPPATH, INCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)',
+ '_CPPDEFFLAGS' : '${_defines(CPPDEFPREFIX, CPPDEFINES, CPPDEFSUFFIX, __env__)}',
+ 'TEMPFILE' : NullCmdGenerator,
+ 'Dir' : Variable_Method_Caller('TARGET', 'Dir'),
+ 'Dirs' : Variable_Method_Caller('TARGET', 'Dirs'),
+ 'File' : Variable_Method_Caller('TARGET', 'File'),
+ 'RDirs' : Variable_Method_Caller('TARGET', 'RDirs'),
+}
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Environment.py b/couchjs/scons/scons-local-2.0.1/SCons/Environment.py
new file mode 100644
index 00000000..d5206fae
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Environment.py
@@ -0,0 +1,2318 @@
+"""SCons.Environment
+
+Base class for construction Environments. These are
+the primary objects used to communicate dependency and
+construction information to the build engine.
+
+Keyword arguments supplied when the construction Environment
+is created are construction variables used to initialize the
+Environment
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Environment.py 5134 2010/08/16 23:02:40 bdeegan"
+
+
+import copy
+import os
+import sys
+import re
+import shlex
+from collections import UserDict
+
+import SCons.Action
+import SCons.Builder
+from SCons.Debug import logInstanceCreation
+import SCons.Defaults
+import SCons.Errors
+import SCons.Memoize
+import SCons.Node
+import SCons.Node.Alias
+import SCons.Node.FS
+import SCons.Node.Python
+import SCons.Platform
+import SCons.SConf
+import SCons.SConsign
+import SCons.Subst
+import SCons.Tool
+import SCons.Util
+import SCons.Warnings
+
+class _Null(object):
+ pass
+
+_null = _Null
+
+_warn_copy_deprecated = True
+_warn_source_signatures_deprecated = True
+_warn_target_signatures_deprecated = True
+
+CleanTargets = {}
+CalculatorArgs = {}
+
+semi_deepcopy = SCons.Util.semi_deepcopy
+
+# Pull UserError into the global name space for the benefit of
+# Environment().SourceSignatures(), which has some import statements
+# which seem to mess up its ability to reference SCons directly.
+UserError = SCons.Errors.UserError
+
+def alias_builder(env, target, source):
+ pass
+
+AliasBuilder = SCons.Builder.Builder(action = alias_builder,
+ target_factory = SCons.Node.Alias.default_ans.Alias,
+ source_factory = SCons.Node.FS.Entry,
+ multi = 1,
+ is_explicit = None,
+ name='AliasBuilder')
+
+def apply_tools(env, tools, toolpath):
+ # Store the toolpath in the Environment.
+ if toolpath is not None:
+ env['toolpath'] = toolpath
+
+ if not tools:
+ return
+ # Filter out null tools from the list.
+ for tool in [_f for _f in tools if _f]:
+ if SCons.Util.is_List(tool) or isinstance(tool, tuple):
+ toolname = tool[0]
+ toolargs = tool[1] # should be a dict of kw args
+ tool = env.Tool(toolname, **toolargs)
+ else:
+ env.Tool(tool)
+
+# These names are (or will be) controlled by SCons; users should never
+# set or override them. This warning can optionally be turned off,
+# but scons will still ignore the illegal variable names even if it's off.
+reserved_construction_var_names = [
+ 'CHANGED_SOURCES',
+ 'CHANGED_TARGETS',
+ 'SOURCE',
+ 'SOURCES',
+ 'TARGET',
+ 'TARGETS',
+ 'UNCHANGED_SOURCES',
+ 'UNCHANGED_TARGETS',
+]
+
+future_reserved_construction_var_names = [
+ #'HOST_OS',
+ #'HOST_ARCH',
+ #'HOST_CPU',
+ ]
+
+def copy_non_reserved_keywords(dict):
+ result = semi_deepcopy(dict)
+ for k in result.keys():
+ if k in reserved_construction_var_names:
+ msg = "Ignoring attempt to set reserved variable `$%s'"
+ SCons.Warnings.warn(SCons.Warnings.ReservedVariableWarning, msg % k)
+ del result[k]
+ return result
+
+def _set_reserved(env, key, value):
+ msg = "Ignoring attempt to set reserved variable `$%s'"
+ SCons.Warnings.warn(SCons.Warnings.ReservedVariableWarning, msg % key)
+
+def _set_future_reserved(env, key, value):
+ env._dict[key] = value
+ msg = "`$%s' will be reserved in a future release and setting it will become ignored"
+ SCons.Warnings.warn(SCons.Warnings.FutureReservedVariableWarning, msg % key)
+
+def _set_BUILDERS(env, key, value):
+ try:
+ bd = env._dict[key]
+ for k in bd.keys():
+ del bd[k]
+ except KeyError:
+ bd = BuilderDict(kwbd, env)
+ env._dict[key] = bd
+ for k, v in value.items():
+ if not SCons.Builder.is_a_Builder(v):
+ raise SCons.Errors.UserError('%s is not a Builder.' % repr(v))
+ bd.update(value)
+
+def _del_SCANNERS(env, key):
+ del env._dict[key]
+ env.scanner_map_delete()
+
+def _set_SCANNERS(env, key, value):
+ env._dict[key] = value
+ env.scanner_map_delete()
+
+def _delete_duplicates(l, keep_last):
+ """Delete duplicates from a sequence, keeping the first or last."""
+ seen={}
+ result=[]
+ if keep_last: # reverse in & out, then keep first
+ l.reverse()
+ for i in l:
+ try:
+ if i not in seen:
+ result.append(i)
+ seen[i]=1
+ except TypeError:
+ # probably unhashable. Just keep it.
+ result.append(i)
+ if keep_last:
+ result.reverse()
+ return result
+
+
+
+# The following is partly based on code in a comment added by Peter
+# Shannon at the following page (there called the "transplant" class):
+#
+# ASPN : Python Cookbook : Dynamically added methods to a class
+# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81732
+#
+# We had independently been using the idiom as BuilderWrapper, but
+# factoring out the common parts into this base class, and making
+# BuilderWrapper a subclass that overrides __call__() to enforce specific
+# Builder calling conventions, simplified some of our higher-layer code.
+
+class MethodWrapper(object):
+ """
+ A generic Wrapper class that associates a method (which can
+ actually be any callable) with an object. As part of creating this
+ MethodWrapper object an attribute with the specified (by default,
+ the name of the supplied method) is added to the underlying object.
+ When that new "method" is called, our __call__() method adds the
+ object as the first argument, simulating the Python behavior of
+ supplying "self" on method calls.
+
+ We hang on to the name by which the method was added to the underlying
+ base class so that we can provide a method to "clone" ourselves onto
+ a new underlying object being copied (without which we wouldn't need
+ to save that info).
+ """
+ def __init__(self, object, method, name=None):
+ if name is None:
+ name = method.__name__
+ self.object = object
+ self.method = method
+ self.name = name
+ setattr(self.object, name, self)
+
+ def __call__(self, *args, **kwargs):
+ nargs = (self.object,) + args
+ return self.method(*nargs, **kwargs)
+
+ def clone(self, new_object):
+ """
+ Returns an object that re-binds the underlying "method" to
+ the specified new object.
+ """
+ return self.__class__(new_object, self.method, self.name)
+
+class BuilderWrapper(MethodWrapper):
+ """
+ A MethodWrapper subclass that that associates an environment with
+ a Builder.
+
+ This mainly exists to wrap the __call__() function so that all calls
+ to Builders can have their argument lists massaged in the same way
+ (treat a lone argument as the source, treat two arguments as target
+ then source, make sure both target and source are lists) without
+ having to have cut-and-paste code to do it.
+
+ As a bit of obsessive backwards compatibility, we also intercept
+ attempts to get or set the "env" or "builder" attributes, which were
+ the names we used before we put the common functionality into the
+ MethodWrapper base class. We'll keep this around for a while in case
+ people shipped Tool modules that reached into the wrapper (like the
+ Tool/qt.py module does, or did). There shouldn't be a lot attribute
+ fetching or setting on these, so a little extra work shouldn't hurt.
+ """
+ def __call__(self, target=None, source=_null, *args, **kw):
+ if source is _null:
+ source = target
+ target = None
+ if target is not None and not SCons.Util.is_List(target):
+ target = [target]
+ if source is not None and not SCons.Util.is_List(source):
+ source = [source]
+ return MethodWrapper.__call__(self, target, source, *args, **kw)
+
+ def __repr__(self):
+ return '<BuilderWrapper %s>' % repr(self.name)
+
+ def __str__(self):
+ return self.__repr__()
+
+ def __getattr__(self, name):
+ if name == 'env':
+ return self.object
+ elif name == 'builder':
+ return self.method
+ else:
+ raise AttributeError(name)
+
+ def __setattr__(self, name, value):
+ if name == 'env':
+ self.object = value
+ elif name == 'builder':
+ self.method = value
+ else:
+ self.__dict__[name] = value
+
+ # This allows a Builder to be executed directly
+ # through the Environment to which it's attached.
+ # In practice, we shouldn't need this, because
+ # builders actually get executed through a Node.
+ # But we do have a unit test for this, and can't
+ # yet rule out that it would be useful in the
+ # future, so leave it for now.
+ #def execute(self, **kw):
+ # kw['env'] = self.env
+ # self.builder.execute(**kw)
+
+class BuilderDict(UserDict):
+ """This is a dictionary-like class used by an Environment to hold
+ the Builders. We need to do this because every time someone changes
+ the Builders in the Environment's BUILDERS dictionary, we must
+ update the Environment's attributes."""
+ def __init__(self, dict, env):
+ # Set self.env before calling the superclass initialization,
+ # because it will end up calling our other methods, which will
+ # need to point the values in this dictionary to self.env.
+ self.env = env
+ UserDict.__init__(self, dict)
+
+ def __semi_deepcopy__(self):
+ return self.__class__(self.data, self.env)
+
+ def __setitem__(self, item, val):
+ try:
+ method = getattr(self.env, item).method
+ except AttributeError:
+ pass
+ else:
+ self.env.RemoveMethod(method)
+ UserDict.__setitem__(self, item, val)
+ BuilderWrapper(self.env, val, item)
+
+ def __delitem__(self, item):
+ UserDict.__delitem__(self, item)
+ delattr(self.env, item)
+
+ def update(self, dict):
+ for i, v in dict.items():
+ self.__setitem__(i, v)
+
+
+
+_is_valid_var = re.compile(r'[_a-zA-Z]\w*$')
+
+def is_valid_construction_var(varstr):
+ """Return if the specified string is a legitimate construction
+ variable.
+ """
+ return _is_valid_var.match(varstr)
+
+
+
+class SubstitutionEnvironment(object):
+ """Base class for different flavors of construction environments.
+
+ This class contains a minimal set of methods that handle contruction
+ variable expansion and conversion of strings to Nodes, which may or
+ may not be actually useful as a stand-alone class. Which methods
+ ended up in this class is pretty arbitrary right now. They're
+ basically the ones which we've empirically determined are common to
+ the different construction environment subclasses, and most of the
+ others that use or touch the underlying dictionary of construction
+ variables.
+
+ Eventually, this class should contain all the methods that we
+ determine are necessary for a "minimal" interface to the build engine.
+ A full "native Python" SCons environment has gotten pretty heavyweight
+ with all of the methods and Tools and construction variables we've
+ jammed in there, so it would be nice to have a lighter weight
+ alternative for interfaces that don't need all of the bells and
+ whistles. (At some point, we'll also probably rename this class
+ "Base," since that more reflects what we want this class to become,
+ but because we've released comments that tell people to subclass
+ Environment.Base to create their own flavors of construction
+ environment, we'll save that for a future refactoring when this
+ class actually becomes useful.)
+ """
+
+ if SCons.Memoize.use_memoizer:
+ __metaclass__ = SCons.Memoize.Memoized_Metaclass
+
+ def __init__(self, **kw):
+ """Initialization of an underlying SubstitutionEnvironment class.
+ """
+ if __debug__: logInstanceCreation(self, 'Environment.SubstitutionEnvironment')
+ self.fs = SCons.Node.FS.get_default_fs()
+ self.ans = SCons.Node.Alias.default_ans
+ self.lookup_list = SCons.Node.arg2nodes_lookups
+ self._dict = kw.copy()
+ self._init_special()
+ self.added_methods = []
+ #self._memo = {}
+
+ def _init_special(self):
+ """Initial the dispatch tables for special handling of
+ special construction variables."""
+ self._special_del = {}
+ self._special_del['SCANNERS'] = _del_SCANNERS
+
+ self._special_set = {}
+ for key in reserved_construction_var_names:
+ self._special_set[key] = _set_reserved
+ for key in future_reserved_construction_var_names:
+ self._special_set[key] = _set_future_reserved
+ self._special_set['BUILDERS'] = _set_BUILDERS
+ self._special_set['SCANNERS'] = _set_SCANNERS
+
+ # Freeze the keys of self._special_set in a list for use by
+ # methods that need to check. (Empirically, list scanning has
+ # gotten better than dict.has_key() in Python 2.5.)
+ self._special_set_keys = list(self._special_set.keys())
+
+ def __cmp__(self, other):
+ return cmp(self._dict, other._dict)
+
+ def __delitem__(self, key):
+ special = self._special_del.get(key)
+ if special:
+ special(self, key)
+ else:
+ del self._dict[key]
+
+ def __getitem__(self, key):
+ return self._dict[key]
+
+ def __setitem__(self, key, value):
+ # This is heavily used. This implementation is the best we have
+ # according to the timings in bench/env.__setitem__.py.
+ #
+ # The "key in self._special_set_keys" test here seems to perform
+ # pretty well for the number of keys we have. A hard-coded
+ # list works a little better in Python 2.5, but that has the
+ # disadvantage of maybe getting out of sync if we ever add more
+ # variable names. Using self._special_set.has_key() works a
+ # little better in Python 2.4, but is worse than this test.
+ # So right now it seems like a good trade-off, but feel free to
+ # revisit this with bench/env.__setitem__.py as needed (and
+ # as newer versions of Python come out).
+ if key in self._special_set_keys:
+ self._special_set[key](self, key, value)
+ else:
+ # If we already have the entry, then it's obviously a valid
+ # key and we don't need to check. If we do check, using a
+ # global, pre-compiled regular expression directly is more
+ # efficient than calling another function or a method.
+ if key not in self._dict \
+ and not _is_valid_var.match(key):
+ raise SCons.Errors.UserError("Illegal construction variable `%s'" % key)
+ self._dict[key] = value
+
+ def get(self, key, default=None):
+ """Emulates the get() method of dictionaries."""
+ return self._dict.get(key, default)
+
+ def has_key(self, key):
+ return key in self._dict
+
+ def __contains__(self, key):
+ return self._dict.__contains__(key)
+
+ def items(self):
+ return list(self._dict.items())
+
+ def arg2nodes(self, args, node_factory=_null, lookup_list=_null, **kw):
+ if node_factory is _null:
+ node_factory = self.fs.File
+ if lookup_list is _null:
+ lookup_list = self.lookup_list
+
+ if not args:
+ return []
+
+ args = SCons.Util.flatten(args)
+
+ nodes = []
+ for v in args:
+ if SCons.Util.is_String(v):
+ n = None
+ for l in lookup_list:
+ n = l(v)
+ if n is not None:
+ break
+ if n is not None:
+ if SCons.Util.is_String(n):
+ # n = self.subst(n, raw=1, **kw)
+ kw['raw'] = 1
+ n = self.subst(n, **kw)
+ if node_factory:
+ n = node_factory(n)
+ if SCons.Util.is_List(n):
+ nodes.extend(n)
+ else:
+ nodes.append(n)
+ elif node_factory:
+ # v = node_factory(self.subst(v, raw=1, **kw))
+ kw['raw'] = 1
+ v = node_factory(self.subst(v, **kw))
+ if SCons.Util.is_List(v):
+ nodes.extend(v)
+ else:
+ nodes.append(v)
+ else:
+ nodes.append(v)
+
+ return nodes
+
+ def gvars(self):
+ return self._dict
+
+ def lvars(self):
+ return {}
+
+ def subst(self, string, raw=0, target=None, source=None, conv=None, executor=None):
+ """Recursively interpolates construction variables from the
+ Environment into the specified string, returning the expanded
+ result. Construction variables are specified by a $ prefix
+ in the string and begin with an initial underscore or
+ alphabetic character followed by any number of underscores
+ or alphanumeric characters. The construction variable names
+ may be surrounded by curly braces to separate the name from
+ trailing characters.
+ """
+ gvars = self.gvars()
+ lvars = self.lvars()
+ lvars['__env__'] = self
+ if executor:
+ lvars.update(executor.get_lvars())
+ return SCons.Subst.scons_subst(string, self, raw, target, source, gvars, lvars, conv)
+
+ def subst_kw(self, kw, raw=0, target=None, source=None):
+ nkw = {}
+ for k, v in kw.items():
+ k = self.subst(k, raw, target, source)
+ if SCons.Util.is_String(v):
+ v = self.subst(v, raw, target, source)
+ nkw[k] = v
+ return nkw
+
+ def subst_list(self, string, raw=0, target=None, source=None, conv=None, executor=None):
+ """Calls through to SCons.Subst.scons_subst_list(). See
+ the documentation for that function."""
+ gvars = self.gvars()
+ lvars = self.lvars()
+ lvars['__env__'] = self
+ if executor:
+ lvars.update(executor.get_lvars())
+ return SCons.Subst.scons_subst_list(string, self, raw, target, source, gvars, lvars, conv)
+
+ def subst_path(self, path, target=None, source=None):
+ """Substitute a path list, turning EntryProxies into Nodes
+ and leaving Nodes (and other objects) as-is."""
+
+ if not SCons.Util.is_List(path):
+ path = [path]
+
+ def s(obj):
+ """This is the "string conversion" routine that we have our
+ substitutions use to return Nodes, not strings. This relies
+ on the fact that an EntryProxy object has a get() method that
+ returns the underlying Node that it wraps, which is a bit of
+ architectural dependence that we might need to break or modify
+ in the future in response to additional requirements."""
+ try:
+ get = obj.get
+ except AttributeError:
+ obj = SCons.Util.to_String_for_subst(obj)
+ else:
+ obj = get()
+ return obj
+
+ r = []
+ for p in path:
+ if SCons.Util.is_String(p):
+ p = self.subst(p, target=target, source=source, conv=s)
+ if SCons.Util.is_List(p):
+ if len(p) == 1:
+ p = p[0]
+ else:
+ # We have an object plus a string, or multiple
+ # objects that we need to smush together. No choice
+ # but to make them into a string.
+ p = ''.join(map(SCons.Util.to_String_for_subst, p))
+ else:
+ p = s(p)
+ r.append(p)
+ return r
+
+ subst_target_source = subst
+
+ def backtick(self, command):
+ import subprocess
+ # common arguments
+ kw = { 'stdin' : 'devnull',
+ 'stdout' : subprocess.PIPE,
+ 'stderr' : subprocess.PIPE,
+ 'universal_newlines' : True,
+ }
+ # if the command is a list, assume it's been quoted
+ # othewise force a shell
+ if not SCons.Util.is_List(command): kw['shell'] = True
+ # run constructed command
+ p = SCons.Action._subproc(self, command, **kw)
+ out,err = p.communicate()
+ status = p.wait()
+ if err:
+ sys.stderr.write(unicode(err))
+ if status:
+ raise OSError("'%s' exited %d" % (command, status))
+ return out
+
+ def AddMethod(self, function, name=None):
+ """
+ Adds the specified function as a method of this construction
+ environment with the specified name. If the name is omitted,
+ the default name is the name of the function itself.
+ """
+ method = MethodWrapper(self, function, name)
+ self.added_methods.append(method)
+
+ def RemoveMethod(self, function):
+ """
+ Removes the specified function's MethodWrapper from the
+ added_methods list, so we don't re-bind it when making a clone.
+ """
+ self.added_methods = [dm for dm in self.added_methods if not dm.method is function]
+
+ def Override(self, overrides):
+ """
+ Produce a modified environment whose variables are overriden by
+ the overrides dictionaries. "overrides" is a dictionary that
+ will override the variables of this environment.
+
+ This function is much more efficient than Clone() or creating
+ a new Environment because it doesn't copy the construction
+ environment dictionary, it just wraps the underlying construction
+ environment, and doesn't even create a wrapper object if there
+ are no overrides.
+ """
+ if not overrides: return self
+ o = copy_non_reserved_keywords(overrides)
+ if not o: return self
+ overrides = {}
+ merges = None
+ for key, value in o.items():
+ if key == 'parse_flags':
+ merges = value
+ else:
+ overrides[key] = SCons.Subst.scons_subst_once(value, self, key)
+ env = OverrideEnvironment(self, overrides)
+ if merges: env.MergeFlags(merges)
+ return env
+
+ def ParseFlags(self, *flags):
+ """
+ Parse the set of flags and return a dict with the flags placed
+ in the appropriate entry. The flags are treated as a typical
+ set of command-line flags for a GNU-like toolchain and used to
+ populate the entries in the dict immediately below. If one of
+ the flag strings begins with a bang (exclamation mark), it is
+ assumed to be a command and the rest of the string is executed;
+ the result of that evaluation is then added to the dict.
+ """
+ dict = {
+ 'ASFLAGS' : SCons.Util.CLVar(''),
+ 'CFLAGS' : SCons.Util.CLVar(''),
+ 'CCFLAGS' : SCons.Util.CLVar(''),
+ 'CPPDEFINES' : [],
+ 'CPPFLAGS' : SCons.Util.CLVar(''),
+ 'CPPPATH' : [],
+ 'FRAMEWORKPATH' : SCons.Util.CLVar(''),
+ 'FRAMEWORKS' : SCons.Util.CLVar(''),
+ 'LIBPATH' : [],
+ 'LIBS' : [],
+ 'LINKFLAGS' : SCons.Util.CLVar(''),
+ 'RPATH' : [],
+ }
+
+ def do_parse(arg):
+ # if arg is a sequence, recurse with each element
+ if not arg:
+ return
+
+ if not SCons.Util.is_String(arg):
+ for t in arg: do_parse(t)
+ return
+
+ # if arg is a command, execute it
+ if arg[0] == '!':
+ arg = self.backtick(arg[1:])
+
+ # utility function to deal with -D option
+ def append_define(name, dict = dict):
+ t = name.split('=')
+ if len(t) == 1:
+ dict['CPPDEFINES'].append(name)
+ else:
+ dict['CPPDEFINES'].append([t[0], '='.join(t[1:])])
+
+ # Loop through the flags and add them to the appropriate option.
+ # This tries to strike a balance between checking for all possible
+ # flags and keeping the logic to a finite size, so it doesn't
+ # check for some that don't occur often. It particular, if the
+ # flag is not known to occur in a config script and there's a way
+ # of passing the flag to the right place (by wrapping it in a -W
+ # flag, for example) we don't check for it. Note that most
+ # preprocessor options are not handled, since unhandled options
+ # are placed in CCFLAGS, so unless the preprocessor is invoked
+ # separately, these flags will still get to the preprocessor.
+ # Other options not currently handled:
+ # -iqoutedir (preprocessor search path)
+ # -u symbol (linker undefined symbol)
+ # -s (linker strip files)
+ # -static* (linker static binding)
+ # -shared* (linker dynamic binding)
+ # -symbolic (linker global binding)
+ # -R dir (deprecated linker rpath)
+ # IBM compilers may also accept -qframeworkdir=foo
+
+ params = shlex.split(arg)
+ append_next_arg_to = None # for multi-word args
+ for arg in params:
+ if append_next_arg_to:
+ if append_next_arg_to == 'CPPDEFINES':
+ append_define(arg)
+ elif append_next_arg_to == '-include':
+ t = ('-include', self.fs.File(arg))
+ dict['CCFLAGS'].append(t)
+ elif append_next_arg_to == '-isysroot':
+ t = ('-isysroot', arg)
+ dict['CCFLAGS'].append(t)
+ dict['LINKFLAGS'].append(t)
+ elif append_next_arg_to == '-arch':
+ t = ('-arch', arg)
+ dict['CCFLAGS'].append(t)
+ dict['LINKFLAGS'].append(t)
+ else:
+ dict[append_next_arg_to].append(arg)
+ append_next_arg_to = None
+ elif not arg[0] in ['-', '+']:
+ dict['LIBS'].append(self.fs.File(arg))
+ elif arg[:2] == '-L':
+ if arg[2:]:
+ dict['LIBPATH'].append(arg[2:])
+ else:
+ append_next_arg_to = 'LIBPATH'
+ elif arg[:2] == '-l':
+ if arg[2:]:
+ dict['LIBS'].append(arg[2:])
+ else:
+ append_next_arg_to = 'LIBS'
+ elif arg[:2] == '-I':
+ if arg[2:]:
+ dict['CPPPATH'].append(arg[2:])
+ else:
+ append_next_arg_to = 'CPPPATH'
+ elif arg[:4] == '-Wa,':
+ dict['ASFLAGS'].append(arg[4:])
+ dict['CCFLAGS'].append(arg)
+ elif arg[:4] == '-Wl,':
+ if arg[:11] == '-Wl,-rpath=':
+ dict['RPATH'].append(arg[11:])
+ elif arg[:7] == '-Wl,-R,':
+ dict['RPATH'].append(arg[7:])
+ elif arg[:6] == '-Wl,-R':
+ dict['RPATH'].append(arg[6:])
+ else:
+ dict['LINKFLAGS'].append(arg)
+ elif arg[:4] == '-Wp,':
+ dict['CPPFLAGS'].append(arg)
+ elif arg[:2] == '-D':
+ if arg[2:]:
+ append_define(arg[2:])
+ else:
+ append_next_arg_to = 'CPPDEFINES'
+ elif arg == '-framework':
+ append_next_arg_to = 'FRAMEWORKS'
+ elif arg[:14] == '-frameworkdir=':
+ dict['FRAMEWORKPATH'].append(arg[14:])
+ elif arg[:2] == '-F':
+ if arg[2:]:
+ dict['FRAMEWORKPATH'].append(arg[2:])
+ else:
+ append_next_arg_to = 'FRAMEWORKPATH'
+ elif arg == '-mno-cygwin':
+ dict['CCFLAGS'].append(arg)
+ dict['LINKFLAGS'].append(arg)
+ elif arg == '-mwindows':
+ dict['LINKFLAGS'].append(arg)
+ elif arg == '-pthread':
+ dict['CCFLAGS'].append(arg)
+ dict['LINKFLAGS'].append(arg)
+ elif arg[:5] == '-std=':
+ dict['CFLAGS'].append(arg) # C only
+ elif arg[0] == '+':
+ dict['CCFLAGS'].append(arg)
+ dict['LINKFLAGS'].append(arg)
+ elif arg in ['-include', '-isysroot', '-arch']:
+ append_next_arg_to = arg
+ else:
+ dict['CCFLAGS'].append(arg)
+
+ for arg in flags:
+ do_parse(arg)
+ return dict
+
+ def MergeFlags(self, args, unique=1, dict=None):
+ """
+ Merge the dict in args into the construction variables of this
+ env, or the passed-in dict. If args is not a dict, it is
+ converted into a dict using ParseFlags. If unique is not set,
+ the flags are appended rather than merged.
+ """
+
+ if dict is None:
+ dict = self
+ if not SCons.Util.is_Dict(args):
+ args = self.ParseFlags(args)
+ if not unique:
+ self.Append(**args)
+ return self
+ for key, value in args.items():
+ if not value:
+ continue
+ try:
+ orig = self[key]
+ except KeyError:
+ orig = value
+ else:
+ if not orig:
+ orig = value
+ elif value:
+ # Add orig and value. The logic here was lifted from
+ # part of env.Append() (see there for a lot of comments
+ # about the order in which things are tried) and is
+ # used mainly to handle coercion of strings to CLVar to
+ # "do the right thing" given (e.g.) an original CCFLAGS
+ # string variable like '-pipe -Wall'.
+ try:
+ orig = orig + value
+ except (KeyError, TypeError):
+ try:
+ add_to_orig = orig.append
+ except AttributeError:
+ value.insert(0, orig)
+ orig = value
+ else:
+ add_to_orig(value)
+ t = []
+ if key[-4:] == 'PATH':
+ ### keep left-most occurence
+ for v in orig:
+ if v not in t:
+ t.append(v)
+ else:
+ ### keep right-most occurence
+ orig.reverse()
+ for v in orig:
+ if v not in t:
+ t.insert(0, v)
+ self[key] = t
+ return self
+
+# def MergeShellPaths(self, args, prepend=1):
+# """
+# Merge the dict in args into the shell environment in env['ENV'].
+# Shell path elements are appended or prepended according to prepend.
+
+# Uses Pre/AppendENVPath, so it always appends or prepends uniquely.
+
+# Example: env.MergeShellPaths({'LIBPATH': '/usr/local/lib'})
+# prepends /usr/local/lib to env['ENV']['LIBPATH'].
+# """
+
+# for pathname, pathval in args.items():
+# if not pathval:
+# continue
+# if prepend:
+# self.PrependENVPath(pathname, pathval)
+# else:
+# self.AppendENVPath(pathname, pathval)
+
+
+def default_decide_source(dependency, target, prev_ni):
+ f = SCons.Defaults.DefaultEnvironment().decide_source
+ return f(dependency, target, prev_ni)
+
+def default_decide_target(dependency, target, prev_ni):
+ f = SCons.Defaults.DefaultEnvironment().decide_target
+ return f(dependency, target, prev_ni)
+
+def default_copy_from_cache(src, dst):
+ f = SCons.Defaults.DefaultEnvironment().copy_from_cache
+ return f(src, dst)
+
+class Base(SubstitutionEnvironment):
+ """Base class for "real" construction Environments. These are the
+ primary objects used to communicate dependency and construction
+ information to the build engine.
+
+ Keyword arguments supplied when the construction Environment
+ is created are construction variables used to initialize the
+ Environment.
+ """
+
+ memoizer_counters = []
+
+ #######################################################################
+ # This is THE class for interacting with the SCons build engine,
+ # and it contains a lot of stuff, so we're going to try to keep this
+ # a little organized by grouping the methods.
+ #######################################################################
+
+ #######################################################################
+ # Methods that make an Environment act like a dictionary. These have
+ # the expected standard names for Python mapping objects. Note that
+ # we don't actually make an Environment a subclass of UserDict for
+ # performance reasons. Note also that we only supply methods for
+ # dictionary functionality that we actually need and use.
+ #######################################################################
+
+ def __init__(self,
+ platform=None,
+ tools=None,
+ toolpath=None,
+ variables=None,
+ parse_flags = None,
+ **kw):
+ """
+ Initialization of a basic SCons construction environment,
+ including setting up special construction variables like BUILDER,
+ PLATFORM, etc., and searching for and applying available Tools.
+
+ Note that we do *not* call the underlying base class
+ (SubsitutionEnvironment) initialization, because we need to
+ initialize things in a very specific order that doesn't work
+ with the much simpler base class initialization.
+ """
+ if __debug__: logInstanceCreation(self, 'Environment.Base')
+ self._memo = {}
+ self.fs = SCons.Node.FS.get_default_fs()
+ self.ans = SCons.Node.Alias.default_ans
+ self.lookup_list = SCons.Node.arg2nodes_lookups
+ self._dict = semi_deepcopy(SCons.Defaults.ConstructionEnvironment)
+ self._init_special()
+ self.added_methods = []
+
+ # We don't use AddMethod, or define these as methods in this
+ # class, because we *don't* want these functions to be bound
+ # methods. They need to operate independently so that the
+ # settings will work properly regardless of whether a given
+ # target ends up being built with a Base environment or an
+ # OverrideEnvironment or what have you.
+ self.decide_target = default_decide_target
+ self.decide_source = default_decide_source
+
+ self.copy_from_cache = default_copy_from_cache
+
+ self._dict['BUILDERS'] = BuilderDict(self._dict['BUILDERS'], self)
+
+ if platform is None:
+ platform = self._dict.get('PLATFORM', None)
+ if platform is None:
+ platform = SCons.Platform.Platform()
+ if SCons.Util.is_String(platform):
+ platform = SCons.Platform.Platform(platform)
+ self._dict['PLATFORM'] = str(platform)
+ platform(self)
+
+ self._dict['HOST_OS'] = self._dict.get('HOST_OS',None)
+ self._dict['HOST_ARCH'] = self._dict.get('HOST_ARCH',None)
+
+ # Now set defaults for TARGET_{OS|ARCH}
+ self._dict['TARGET_OS'] = self._dict.get('HOST_OS',None)
+ self._dict['TARGET_ARCH'] = self._dict.get('HOST_ARCH',None)
+
+
+ # Apply the passed-in and customizable variables to the
+ # environment before calling the tools, because they may use
+ # some of them during initialization.
+ if 'options' in kw:
+ # Backwards compatibility: they may stll be using the
+ # old "options" keyword.
+ variables = kw['options']
+ del kw['options']
+ self.Replace(**kw)
+ keys = list(kw.keys())
+ if variables:
+ keys = keys + list(variables.keys())
+ variables.Update(self)
+
+ save = {}
+ for k in keys:
+ try:
+ save[k] = self._dict[k]
+ except KeyError:
+ # No value may have been set if they tried to pass in a
+ # reserved variable name like TARGETS.
+ pass
+
+ SCons.Tool.Initializers(self)
+
+ if tools is None:
+ tools = self._dict.get('TOOLS', None)
+ if tools is None:
+ tools = ['default']
+ apply_tools(self, tools, toolpath)
+
+ # Now restore the passed-in and customized variables
+ # to the environment, since the values the user set explicitly
+ # should override any values set by the tools.
+ for key, val in save.items():
+ self._dict[key] = val
+
+ # Finally, apply any flags to be merged in
+ if parse_flags: self.MergeFlags(parse_flags)
+
+ #######################################################################
+ # Utility methods that are primarily for internal use by SCons.
+ # These begin with lower-case letters.
+ #######################################################################
+
+ def get_builder(self, name):
+ """Fetch the builder with the specified name from the environment.
+ """
+ try:
+ return self._dict['BUILDERS'][name]
+ except KeyError:
+ return None
+
+ def get_CacheDir(self):
+ try:
+ path = self._CacheDir_path
+ except AttributeError:
+ path = SCons.Defaults.DefaultEnvironment()._CacheDir_path
+ try:
+ if path == self._last_CacheDir_path:
+ return self._last_CacheDir
+ except AttributeError:
+ pass
+ cd = SCons.CacheDir.CacheDir(path)
+ self._last_CacheDir_path = path
+ self._last_CacheDir = cd
+ return cd
+
+ def get_factory(self, factory, default='File'):
+ """Return a factory function for creating Nodes for this
+ construction environment.
+ """
+ name = default
+ try:
+ is_node = issubclass(factory, SCons.Node.FS.Base)
+ except TypeError:
+ # The specified factory isn't a Node itself--it's
+ # most likely None, or possibly a callable.
+ pass
+ else:
+ if is_node:
+ # The specified factory is a Node (sub)class. Try to
+ # return the FS method that corresponds to the Node's
+ # name--that is, we return self.fs.Dir if they want a Dir,
+ # self.fs.File for a File, etc.
+ try: name = factory.__name__
+ except AttributeError: pass
+ else: factory = None
+ if not factory:
+ # They passed us None, or we picked up a name from a specified
+ # class, so return the FS method. (Note that we *don't*
+ # use our own self.{Dir,File} methods because that would
+ # cause env.subst() to be called twice on the file name,
+ # interfering with files that have $$ in them.)
+ factory = getattr(self.fs, name)
+ return factory
+
+ memoizer_counters.append(SCons.Memoize.CountValue('_gsm'))
+
+ def _gsm(self):
+ try:
+ return self._memo['_gsm']
+ except KeyError:
+ pass
+
+ result = {}
+
+ try:
+ scanners = self._dict['SCANNERS']
+ except KeyError:
+ pass
+ else:
+ # Reverse the scanner list so that, if multiple scanners
+ # claim they can scan the same suffix, earlier scanners
+ # in the list will overwrite later scanners, so that
+ # the result looks like a "first match" to the user.
+ if not SCons.Util.is_List(scanners):
+ scanners = [scanners]
+ else:
+ scanners = scanners[:] # copy so reverse() doesn't mod original
+ scanners.reverse()
+ for scanner in scanners:
+ for k in scanner.get_skeys(self):
+ if k and self['PLATFORM'] == 'win32':
+ k = k.lower()
+ result[k] = scanner
+
+ self._memo['_gsm'] = result
+
+ return result
+
+ def get_scanner(self, skey):
+ """Find the appropriate scanner given a key (usually a file suffix).
+ """
+ if skey and self['PLATFORM'] == 'win32':
+ skey = skey.lower()
+ return self._gsm().get(skey)
+
+ def scanner_map_delete(self, kw=None):
+ """Delete the cached scanner map (if we need to).
+ """
+ try:
+ del self._memo['_gsm']
+ except KeyError:
+ pass
+
+ def _update(self, dict):
+ """Update an environment's values directly, bypassing the normal
+ checks that occur when users try to set items.
+ """
+ self._dict.update(dict)
+
+ def get_src_sig_type(self):
+ try:
+ return self.src_sig_type
+ except AttributeError:
+ t = SCons.Defaults.DefaultEnvironment().src_sig_type
+ self.src_sig_type = t
+ return t
+
+ def get_tgt_sig_type(self):
+ try:
+ return self.tgt_sig_type
+ except AttributeError:
+ t = SCons.Defaults.DefaultEnvironment().tgt_sig_type
+ self.tgt_sig_type = t
+ return t
+
+ #######################################################################
+ # Public methods for manipulating an Environment. These begin with
+ # upper-case letters. The essential characteristic of methods in
+ # this section is that they do *not* have corresponding same-named
+ # global functions. For example, a stand-alone Append() function
+ # makes no sense, because Append() is all about appending values to
+ # an Environment's construction variables.
+ #######################################################################
+
+ def Append(self, **kw):
+ """Append values to existing construction variables
+ in an Environment.
+ """
+ kw = copy_non_reserved_keywords(kw)
+ for key, val in kw.items():
+ # It would be easier on the eyes to write this using
+ # "continue" statements whenever we finish processing an item,
+ # but Python 1.5.2 apparently doesn't let you use "continue"
+ # within try:-except: blocks, so we have to nest our code.
+ try:
+ orig = self._dict[key]
+ except KeyError:
+ # No existing variable in the environment, so just set
+ # it to the new value.
+ self._dict[key] = val
+ else:
+ try:
+ # Check if the original looks like a dictionary.
+ # If it is, we can't just try adding the value because
+ # dictionaries don't have __add__() methods, and
+ # things like UserList will incorrectly coerce the
+ # original dict to a list (which we don't want).
+ update_dict = orig.update
+ except AttributeError:
+ try:
+ # Most straightforward: just try to add them
+ # together. This will work in most cases, when the
+ # original and new values are of compatible types.
+ self._dict[key] = orig + val
+ except (KeyError, TypeError):
+ try:
+ # Check if the original is a list.
+ add_to_orig = orig.append
+ except AttributeError:
+ # The original isn't a list, but the new
+ # value is (by process of elimination),
+ # so insert the original in the new value
+ # (if there's one to insert) and replace
+ # the variable with it.
+ if orig:
+ val.insert(0, orig)
+ self._dict[key] = val
+ else:
+ # The original is a list, so append the new
+ # value to it (if there's a value to append).
+ if val:
+ add_to_orig(val)
+ else:
+ # The original looks like a dictionary, so update it
+ # based on what we think the value looks like.
+ if SCons.Util.is_List(val):
+ for v in val:
+ orig[v] = None
+ else:
+ try:
+ update_dict(val)
+ except (AttributeError, TypeError, ValueError):
+ if SCons.Util.is_Dict(val):
+ for k, v in val.items():
+ orig[k] = v
+ else:
+ orig[val] = None
+ self.scanner_map_delete(kw)
+
+ # allow Dirs and strings beginning with # for top-relative
+ # Note this uses the current env's fs (in self).
+ def _canonicalize(self, path):
+ if not SCons.Util.is_String(path): # typically a Dir
+ path = str(path)
+ if path and path[0] == '#':
+ path = str(self.fs.Dir(path))
+ return path
+
+ def AppendENVPath(self, name, newpath, envname = 'ENV',
+ sep = os.pathsep, delete_existing=1):
+ """Append path elements to the path 'name' in the 'ENV'
+ dictionary for this environment. Will only add any particular
+ path once, and will normpath and normcase all paths to help
+ assure this. This can also handle the case where the env
+ variable is a list instead of a string.
+
+ If delete_existing is 0, a newpath which is already in the path
+ will not be moved to the end (it will be left where it is).
+ """
+
+ orig = ''
+ if envname in self._dict and name in self._dict[envname]:
+ orig = self._dict[envname][name]
+
+ nv = SCons.Util.AppendPath(orig, newpath, sep, delete_existing,
+ canonicalize=self._canonicalize)
+
+ if envname not in self._dict:
+ self._dict[envname] = {}
+
+ self._dict[envname][name] = nv
+
+ def AppendUnique(self, delete_existing=0, **kw):
+ """Append values to existing construction variables
+ in an Environment, if they're not already there.
+ If delete_existing is 1, removes existing values first, so
+ values move to end.
+ """
+ kw = copy_non_reserved_keywords(kw)
+ for key, val in kw.items():
+ if SCons.Util.is_List(val):
+ val = _delete_duplicates(val, delete_existing)
+ if key not in self._dict or self._dict[key] in ('', None):
+ self._dict[key] = val
+ elif SCons.Util.is_Dict(self._dict[key]) and \
+ SCons.Util.is_Dict(val):
+ self._dict[key].update(val)
+ elif SCons.Util.is_List(val):
+ dk = self._dict[key]
+ if not SCons.Util.is_List(dk):
+ dk = [dk]
+ if delete_existing:
+ dk = [x for x in dk if x not in val]
+ else:
+ val = [x for x in val if x not in dk]
+ self._dict[key] = dk + val
+ else:
+ dk = self._dict[key]
+ if SCons.Util.is_List(dk):
+ # By elimination, val is not a list. Since dk is a
+ # list, wrap val in a list first.
+ if delete_existing:
+ dk = [x for x in dk if x not in val]
+ self._dict[key] = dk + [val]
+ else:
+ if not val in dk:
+ self._dict[key] = dk + [val]
+ else:
+ if delete_existing:
+ dk = [x for x in dk if x not in val]
+ self._dict[key] = dk + val
+ self.scanner_map_delete(kw)
+
+ def Clone(self, tools=[], toolpath=None, parse_flags = None, **kw):
+ """Return a copy of a construction Environment. The
+ copy is like a Python "deep copy"--that is, independent
+ copies are made recursively of each objects--except that
+ a reference is copied when an object is not deep-copyable
+ (like a function). There are no references to any mutable
+ objects in the original Environment.
+ """
+ clone = copy.copy(self)
+ clone._dict = semi_deepcopy(self._dict)
+
+ try:
+ cbd = clone._dict['BUILDERS']
+ except KeyError:
+ pass
+ else:
+ clone._dict['BUILDERS'] = BuilderDict(cbd, clone)
+
+ # Check the methods added via AddMethod() and re-bind them to
+ # the cloned environment. Only do this if the attribute hasn't
+ # been overwritten by the user explicitly and still points to
+ # the added method.
+ clone.added_methods = []
+ for mw in self.added_methods:
+ if mw == getattr(self, mw.name):
+ clone.added_methods.append(mw.clone(clone))
+
+ clone._memo = {}
+
+ # Apply passed-in variables before the tools
+ # so the tools can use the new variables
+ kw = copy_non_reserved_keywords(kw)
+ new = {}
+ for key, value in kw.items():
+ new[key] = SCons.Subst.scons_subst_once(value, self, key)
+ clone.Replace(**new)
+
+ apply_tools(clone, tools, toolpath)
+
+ # apply them again in case the tools overwrote them
+ clone.Replace(**new)
+
+ # Finally, apply any flags to be merged in
+ if parse_flags: clone.MergeFlags(parse_flags)
+
+ if __debug__: logInstanceCreation(self, 'Environment.EnvironmentClone')
+ return clone
+
+ def Copy(self, *args, **kw):
+ global _warn_copy_deprecated
+ if _warn_copy_deprecated:
+ msg = "The env.Copy() method is deprecated; use the env.Clone() method instead."
+ SCons.Warnings.warn(SCons.Warnings.DeprecatedCopyWarning, msg)
+ _warn_copy_deprecated = False
+ return self.Clone(*args, **kw)
+
+ def _changed_build(self, dependency, target, prev_ni):
+ if dependency.changed_state(target, prev_ni):
+ return 1
+ return self.decide_source(dependency, target, prev_ni)
+
+ def _changed_content(self, dependency, target, prev_ni):
+ return dependency.changed_content(target, prev_ni)
+
+ def _changed_source(self, dependency, target, prev_ni):
+ target_env = dependency.get_build_env()
+ type = target_env.get_tgt_sig_type()
+ if type == 'source':
+ return target_env.decide_source(dependency, target, prev_ni)
+ else:
+ return target_env.decide_target(dependency, target, prev_ni)
+
+ def _changed_timestamp_then_content(self, dependency, target, prev_ni):
+ return dependency.changed_timestamp_then_content(target, prev_ni)
+
+ def _changed_timestamp_newer(self, dependency, target, prev_ni):
+ return dependency.changed_timestamp_newer(target, prev_ni)
+
+ def _changed_timestamp_match(self, dependency, target, prev_ni):
+ return dependency.changed_timestamp_match(target, prev_ni)
+
+ def _copy_from_cache(self, src, dst):
+ return self.fs.copy(src, dst)
+
+ def _copy2_from_cache(self, src, dst):
+ return self.fs.copy2(src, dst)
+
+ def Decider(self, function):
+ copy_function = self._copy2_from_cache
+ if function in ('MD5', 'content'):
+ if not SCons.Util.md5:
+ raise UserError("MD5 signatures are not available in this version of Python.")
+ function = self._changed_content
+ elif function == 'MD5-timestamp':
+ function = self._changed_timestamp_then_content
+ elif function in ('timestamp-newer', 'make'):
+ function = self._changed_timestamp_newer
+ copy_function = self._copy_from_cache
+ elif function == 'timestamp-match':
+ function = self._changed_timestamp_match
+ elif not callable(function):
+ raise UserError("Unknown Decider value %s" % repr(function))
+
+ # We don't use AddMethod because we don't want to turn the
+ # function, which only expects three arguments, into a bound
+ # method, which would add self as an initial, fourth argument.
+ self.decide_target = function
+ self.decide_source = function
+
+ self.copy_from_cache = copy_function
+
+ def Detect(self, progs):
+ """Return the first available program in progs.
+ """
+ if not SCons.Util.is_List(progs):
+ progs = [ progs ]
+ for prog in progs:
+ path = self.WhereIs(prog)
+ if path: return prog
+ return None
+
+ def Dictionary(self, *args):
+ if not args:
+ return self._dict
+ dlist = [self._dict[x] for x in args]
+ if len(dlist) == 1:
+ dlist = dlist[0]
+ return dlist
+
+ def Dump(self, key = None):
+ """
+ Using the standard Python pretty printer, dump the contents of the
+ scons build environment to stdout.
+
+ If the key passed in is anything other than None, then that will
+ be used as an index into the build environment dictionary and
+ whatever is found there will be fed into the pretty printer. Note
+ that this key is case sensitive.
+ """
+ import pprint
+ pp = pprint.PrettyPrinter(indent=2)
+ if key:
+ dict = self.Dictionary(key)
+ else:
+ dict = self.Dictionary()
+ return pp.pformat(dict)
+
+ def FindIxes(self, paths, prefix, suffix):
+ """
+ Search a list of paths for something that matches the prefix and suffix.
+
+ paths - the list of paths or nodes.
+ prefix - construction variable for the prefix.
+ suffix - construction variable for the suffix.
+ """
+
+ suffix = self.subst('$'+suffix)
+ prefix = self.subst('$'+prefix)
+
+ for path in paths:
+ dir,name = os.path.split(str(path))
+ if name[:len(prefix)] == prefix and name[-len(suffix):] == suffix:
+ return path
+
+ def ParseConfig(self, command, function=None, unique=1):
+ """
+ Use the specified function to parse the output of the command
+ in order to modify the current environment. The 'command' can
+ be a string or a list of strings representing a command and
+ its arguments. 'Function' is an optional argument that takes
+ the environment, the output of the command, and the unique flag.
+ If no function is specified, MergeFlags, which treats the output
+ as the result of a typical 'X-config' command (i.e. gtk-config),
+ will merge the output into the appropriate variables.
+ """
+ if function is None:
+ def parse_conf(env, cmd, unique=unique):
+ return env.MergeFlags(cmd, unique)
+ function = parse_conf
+ if SCons.Util.is_List(command):
+ command = ' '.join(command)
+ command = self.subst(command)
+ return function(self, self.backtick(command))
+
+ def ParseDepends(self, filename, must_exist=None, only_one=0):
+ """
+ Parse a mkdep-style file for explicit dependencies. This is
+ completely abusable, and should be unnecessary in the "normal"
+ case of proper SCons configuration, but it may help make
+ the transition from a Make hierarchy easier for some people
+ to swallow. It can also be genuinely useful when using a tool
+ that can write a .d file, but for which writing a scanner would
+ be too complicated.
+ """
+ filename = self.subst(filename)
+ try:
+ fp = open(filename, 'r')
+ except IOError:
+ if must_exist:
+ raise
+ return
+ lines = SCons.Util.LogicalLines(fp).readlines()
+ lines = [l for l in lines if l[0] != '#']
+ tdlist = []
+ for line in lines:
+ try:
+ target, depends = line.split(':', 1)
+ except (AttributeError, ValueError):
+ # Throws AttributeError if line isn't a string. Can throw
+ # ValueError if line doesn't split into two or more elements.
+ pass
+ else:
+ tdlist.append((target.split(), depends.split()))
+ if only_one:
+ targets = []
+ for td in tdlist:
+ targets.extend(td[0])
+ if len(targets) > 1:
+ raise SCons.Errors.UserError(
+ "More than one dependency target found in `%s': %s"
+ % (filename, targets))
+ for target, depends in tdlist:
+ self.Depends(target, depends)
+
+ def Platform(self, platform):
+ platform = self.subst(platform)
+ return SCons.Platform.Platform(platform)(self)
+
+ def Prepend(self, **kw):
+ """Prepend values to existing construction variables
+ in an Environment.
+ """
+ kw = copy_non_reserved_keywords(kw)
+ for key, val in kw.items():
+ # It would be easier on the eyes to write this using
+ # "continue" statements whenever we finish processing an item,
+ # but Python 1.5.2 apparently doesn't let you use "continue"
+ # within try:-except: blocks, so we have to nest our code.
+ try:
+ orig = self._dict[key]
+ except KeyError:
+ # No existing variable in the environment, so just set
+ # it to the new value.
+ self._dict[key] = val
+ else:
+ try:
+ # Check if the original looks like a dictionary.
+ # If it is, we can't just try adding the value because
+ # dictionaries don't have __add__() methods, and
+ # things like UserList will incorrectly coerce the
+ # original dict to a list (which we don't want).
+ update_dict = orig.update
+ except AttributeError:
+ try:
+ # Most straightforward: just try to add them
+ # together. This will work in most cases, when the
+ # original and new values are of compatible types.
+ self._dict[key] = val + orig
+ except (KeyError, TypeError):
+ try:
+ # Check if the added value is a list.
+ add_to_val = val.append
+ except AttributeError:
+ # The added value isn't a list, but the
+ # original is (by process of elimination),
+ # so insert the the new value in the original
+ # (if there's one to insert).
+ if val:
+ orig.insert(0, val)
+ else:
+ # The added value is a list, so append
+ # the original to it (if there's a value
+ # to append).
+ if orig:
+ add_to_val(orig)
+ self._dict[key] = val
+ else:
+ # The original looks like a dictionary, so update it
+ # based on what we think the value looks like.
+ if SCons.Util.is_List(val):
+ for v in val:
+ orig[v] = None
+ else:
+ try:
+ update_dict(val)
+ except (AttributeError, TypeError, ValueError):
+ if SCons.Util.is_Dict(val):
+ for k, v in val.items():
+ orig[k] = v
+ else:
+ orig[val] = None
+ self.scanner_map_delete(kw)
+
+ def PrependENVPath(self, name, newpath, envname = 'ENV', sep = os.pathsep,
+ delete_existing=1):
+ """Prepend path elements to the path 'name' in the 'ENV'
+ dictionary for this environment. Will only add any particular
+ path once, and will normpath and normcase all paths to help
+ assure this. This can also handle the case where the env
+ variable is a list instead of a string.
+
+ If delete_existing is 0, a newpath which is already in the path
+ will not be moved to the front (it will be left where it is).
+ """
+
+ orig = ''
+ if envname in self._dict and name in self._dict[envname]:
+ orig = self._dict[envname][name]
+
+ nv = SCons.Util.PrependPath(orig, newpath, sep, delete_existing,
+ canonicalize=self._canonicalize)
+
+ if envname not in self._dict:
+ self._dict[envname] = {}
+
+ self._dict[envname][name] = nv
+
+ def PrependUnique(self, delete_existing=0, **kw):
+ """Prepend values to existing construction variables
+ in an Environment, if they're not already there.
+ If delete_existing is 1, removes existing values first, so
+ values move to front.
+ """
+ kw = copy_non_reserved_keywords(kw)
+ for key, val in kw.items():
+ if SCons.Util.is_List(val):
+ val = _delete_duplicates(val, not delete_existing)
+ if key not in self._dict or self._dict[key] in ('', None):
+ self._dict[key] = val
+ elif SCons.Util.is_Dict(self._dict[key]) and \
+ SCons.Util.is_Dict(val):
+ self._dict[key].update(val)
+ elif SCons.Util.is_List(val):
+ dk = self._dict[key]
+ if not SCons.Util.is_List(dk):
+ dk = [dk]
+ if delete_existing:
+ dk = [x for x in dk if x not in val]
+ else:
+ val = [x for x in val if x not in dk]
+ self._dict[key] = val + dk
+ else:
+ dk = self._dict[key]
+ if SCons.Util.is_List(dk):
+ # By elimination, val is not a list. Since dk is a
+ # list, wrap val in a list first.
+ if delete_existing:
+ dk = [x for x in dk if x not in val]
+ self._dict[key] = [val] + dk
+ else:
+ if not val in dk:
+ self._dict[key] = [val] + dk
+ else:
+ if delete_existing:
+ dk = [x for x in dk if x not in val]
+ self._dict[key] = val + dk
+ self.scanner_map_delete(kw)
+
+ def Replace(self, **kw):
+ """Replace existing construction variables in an Environment
+ with new construction variables and/or values.
+ """
+ try:
+ kwbd = kw['BUILDERS']
+ except KeyError:
+ pass
+ else:
+ kwbd = semi_deepcopy(kwbd)
+ del kw['BUILDERS']
+ self.__setitem__('BUILDERS', kwbd)
+ kw = copy_non_reserved_keywords(kw)
+ self._update(semi_deepcopy(kw))
+ self.scanner_map_delete(kw)
+
+ def ReplaceIxes(self, path, old_prefix, old_suffix, new_prefix, new_suffix):
+ """
+ Replace old_prefix with new_prefix and old_suffix with new_suffix.
+
+ env - Environment used to interpolate variables.
+ path - the path that will be modified.
+ old_prefix - construction variable for the old prefix.
+ old_suffix - construction variable for the old suffix.
+ new_prefix - construction variable for the new prefix.
+ new_suffix - construction variable for the new suffix.
+ """
+ old_prefix = self.subst('$'+old_prefix)
+ old_suffix = self.subst('$'+old_suffix)
+
+ new_prefix = self.subst('$'+new_prefix)
+ new_suffix = self.subst('$'+new_suffix)
+
+ dir,name = os.path.split(str(path))
+ if name[:len(old_prefix)] == old_prefix:
+ name = name[len(old_prefix):]
+ if name[-len(old_suffix):] == old_suffix:
+ name = name[:-len(old_suffix)]
+ return os.path.join(dir, new_prefix+name+new_suffix)
+
+ def SetDefault(self, **kw):
+ for k in kw.keys():
+ if k in self._dict:
+ del kw[k]
+ self.Replace(**kw)
+
+ def _find_toolpath_dir(self, tp):
+ return self.fs.Dir(self.subst(tp)).srcnode().abspath
+
+ def Tool(self, tool, toolpath=None, **kw):
+ if SCons.Util.is_String(tool):
+ tool = self.subst(tool)
+ if toolpath is None:
+ toolpath = self.get('toolpath', [])
+ toolpath = list(map(self._find_toolpath_dir, toolpath))
+ tool = SCons.Tool.Tool(tool, toolpath, **kw)
+ tool(self)
+
+ def WhereIs(self, prog, path=None, pathext=None, reject=[]):
+ """Find prog in the path.
+ """
+ if path is None:
+ try:
+ path = self['ENV']['PATH']
+ except KeyError:
+ pass
+ elif SCons.Util.is_String(path):
+ path = self.subst(path)
+ if pathext is None:
+ try:
+ pathext = self['ENV']['PATHEXT']
+ except KeyError:
+ pass
+ elif SCons.Util.is_String(pathext):
+ pathext = self.subst(pathext)
+ prog = self.subst(prog)
+ path = SCons.Util.WhereIs(prog, path, pathext, reject)
+ if path: return path
+ return None
+
+ #######################################################################
+ # Public methods for doing real "SCons stuff" (manipulating
+ # dependencies, setting attributes on targets, etc.). These begin
+ # with upper-case letters. The essential characteristic of methods
+ # in this section is that they all *should* have corresponding
+ # same-named global functions.
+ #######################################################################
+
+ def Action(self, *args, **kw):
+ def subst_string(a, self=self):
+ if SCons.Util.is_String(a):
+ a = self.subst(a)
+ return a
+ nargs = list(map(subst_string, args))
+ nkw = self.subst_kw(kw)
+ return SCons.Action.Action(*nargs, **nkw)
+
+ def AddPreAction(self, files, action):
+ nodes = self.arg2nodes(files, self.fs.Entry)
+ action = SCons.Action.Action(action)
+ uniq = {}
+ for executor in [n.get_executor() for n in nodes]:
+ uniq[executor] = 1
+ for executor in uniq.keys():
+ executor.add_pre_action(action)
+ return nodes
+
+ def AddPostAction(self, files, action):
+ nodes = self.arg2nodes(files, self.fs.Entry)
+ action = SCons.Action.Action(action)
+ uniq = {}
+ for executor in [n.get_executor() for n in nodes]:
+ uniq[executor] = 1
+ for executor in uniq.keys():
+ executor.add_post_action(action)
+ return nodes
+
+ def Alias(self, target, source=[], action=None, **kw):
+ tlist = self.arg2nodes(target, self.ans.Alias)
+ if not SCons.Util.is_List(source):
+ source = [source]
+ source = [_f for _f in source if _f]
+
+ if not action:
+ if not source:
+ # There are no source files and no action, so just
+ # return a target list of classic Alias Nodes, without
+ # any builder. The externally visible effect is that
+ # this will make the wrapping Script.BuildTask class
+ # say that there's "Nothing to be done" for this Alias,
+ # instead of that it's "up to date."
+ return tlist
+
+ # No action, but there are sources. Re-call all the target
+ # builders to add the sources to each target.
+ result = []
+ for t in tlist:
+ bld = t.get_builder(AliasBuilder)
+ result.extend(bld(self, t, source))
+ return result
+
+ nkw = self.subst_kw(kw)
+ nkw.update({
+ 'action' : SCons.Action.Action(action),
+ 'source_factory' : self.fs.Entry,
+ 'multi' : 1,
+ 'is_explicit' : None,
+ })
+ bld = SCons.Builder.Builder(**nkw)
+
+ # Apply the Builder separately to each target so that the Aliases
+ # stay separate. If we did one "normal" Builder call with the
+ # whole target list, then all of the target Aliases would be
+ # associated under a single Executor.
+ result = []
+ for t in tlist:
+ # Calling the convert() method will cause a new Executor to be
+ # created from scratch, so we have to explicitly initialize
+ # it with the target's existing sources, plus our new ones,
+ # so nothing gets lost.
+ b = t.get_builder()
+ if b is None or b is AliasBuilder:
+ b = bld
+ else:
+ nkw['action'] = b.action + action
+ b = SCons.Builder.Builder(**nkw)
+ t.convert()
+ result.extend(b(self, t, t.sources + source))
+ return result
+
+ def AlwaysBuild(self, *targets):
+ tlist = []
+ for t in targets:
+ tlist.extend(self.arg2nodes(t, self.fs.Entry))
+ for t in tlist:
+ t.set_always_build()
+ return tlist
+
+ def BuildDir(self, *args, **kw):
+ msg = """BuildDir() and the build_dir keyword have been deprecated;\n\tuse VariantDir() and the variant_dir keyword instead."""
+ SCons.Warnings.warn(SCons.Warnings.DeprecatedBuildDirWarning, msg)
+ if 'build_dir' in kw:
+ kw['variant_dir'] = kw['build_dir']
+ del kw['build_dir']
+ return self.VariantDir(*args, **kw)
+
+ def Builder(self, **kw):
+ nkw = self.subst_kw(kw)
+ return SCons.Builder.Builder(**nkw)
+
+ def CacheDir(self, path):
+ import SCons.CacheDir
+ if path is not None:
+ path = self.subst(path)
+ self._CacheDir_path = path
+
+ def Clean(self, targets, files):
+ global CleanTargets
+ tlist = self.arg2nodes(targets, self.fs.Entry)
+ flist = self.arg2nodes(files, self.fs.Entry)
+ for t in tlist:
+ try:
+ CleanTargets[t].extend(flist)
+ except KeyError:
+ CleanTargets[t] = flist
+
+ def Configure(self, *args, **kw):
+ nargs = [self]
+ if args:
+ nargs = nargs + self.subst_list(args)[0]
+ nkw = self.subst_kw(kw)
+ nkw['_depth'] = kw.get('_depth', 0) + 1
+ try:
+ nkw['custom_tests'] = self.subst_kw(nkw['custom_tests'])
+ except KeyError:
+ pass
+ return SCons.SConf.SConf(*nargs, **nkw)
+
+ def Command(self, target, source, action, **kw):
+ """Builds the supplied target files from the supplied
+ source files using the supplied action. Action may
+ be any type that the Builder constructor will accept
+ for an action."""
+ bkw = {
+ 'action' : action,
+ 'target_factory' : self.fs.Entry,
+ 'source_factory' : self.fs.Entry,
+ }
+ try: bkw['source_scanner'] = kw['source_scanner']
+ except KeyError: pass
+ else: del kw['source_scanner']
+ bld = SCons.Builder.Builder(**bkw)
+ return bld(self, target, source, **kw)
+
+ def Depends(self, target, dependency):
+ """Explicity specify that 'target's depend on 'dependency'."""
+ tlist = self.arg2nodes(target, self.fs.Entry)
+ dlist = self.arg2nodes(dependency, self.fs.Entry)
+ for t in tlist:
+ t.add_dependency(dlist)
+ return tlist
+
+ def Dir(self, name, *args, **kw):
+ """
+ """
+ s = self.subst(name)
+ if SCons.Util.is_Sequence(s):
+ result=[]
+ for e in s:
+ result.append(self.fs.Dir(e, *args, **kw))
+ return result
+ return self.fs.Dir(s, *args, **kw)
+
+ def NoClean(self, *targets):
+ """Tags a target so that it will not be cleaned by -c"""
+ tlist = []
+ for t in targets:
+ tlist.extend(self.arg2nodes(t, self.fs.Entry))
+ for t in tlist:
+ t.set_noclean()
+ return tlist
+
+ def NoCache(self, *targets):
+ """Tags a target so that it will not be cached"""
+ tlist = []
+ for t in targets:
+ tlist.extend(self.arg2nodes(t, self.fs.Entry))
+ for t in tlist:
+ t.set_nocache()
+ return tlist
+
+ def Entry(self, name, *args, **kw):
+ """
+ """
+ s = self.subst(name)
+ if SCons.Util.is_Sequence(s):
+ result=[]
+ for e in s:
+ result.append(self.fs.Entry(e, *args, **kw))
+ return result
+ return self.fs.Entry(s, *args, **kw)
+
+ def Environment(self, **kw):
+ return SCons.Environment.Environment(**self.subst_kw(kw))
+
+ def Execute(self, action, *args, **kw):
+ """Directly execute an action through an Environment
+ """
+ action = self.Action(action, *args, **kw)
+ result = action([], [], self)
+ if isinstance(result, SCons.Errors.BuildError):
+ errstr = result.errstr
+ if result.filename:
+ errstr = result.filename + ': ' + errstr
+ sys.stderr.write("scons: *** %s\n" % errstr)
+ return result.status
+ else:
+ return result
+
+ def File(self, name, *args, **kw):
+ """
+ """
+ s = self.subst(name)
+ if SCons.Util.is_Sequence(s):
+ result=[]
+ for e in s:
+ result.append(self.fs.File(e, *args, **kw))
+ return result
+ return self.fs.File(s, *args, **kw)
+
+ def FindFile(self, file, dirs):
+ file = self.subst(file)
+ nodes = self.arg2nodes(dirs, self.fs.Dir)
+ return SCons.Node.FS.find_file(file, tuple(nodes))
+
+ def Flatten(self, sequence):
+ return SCons.Util.flatten(sequence)
+
+ def GetBuildPath(self, files):
+ result = list(map(str, self.arg2nodes(files, self.fs.Entry)))
+ if SCons.Util.is_List(files):
+ return result
+ else:
+ return result[0]
+
+ def Glob(self, pattern, ondisk=True, source=False, strings=False):
+ return self.fs.Glob(self.subst(pattern), ondisk, source, strings)
+
+ def Ignore(self, target, dependency):
+ """Ignore a dependency."""
+ tlist = self.arg2nodes(target, self.fs.Entry)
+ dlist = self.arg2nodes(dependency, self.fs.Entry)
+ for t in tlist:
+ t.add_ignore(dlist)
+ return tlist
+
+ def Literal(self, string):
+ return SCons.Subst.Literal(string)
+
+ def Local(self, *targets):
+ ret = []
+ for targ in targets:
+ if isinstance(targ, SCons.Node.Node):
+ targ.set_local()
+ ret.append(targ)
+ else:
+ for t in self.arg2nodes(targ, self.fs.Entry):
+ t.set_local()
+ ret.append(t)
+ return ret
+
+ def Precious(self, *targets):
+ tlist = []
+ for t in targets:
+ tlist.extend(self.arg2nodes(t, self.fs.Entry))
+ for t in tlist:
+ t.set_precious()
+ return tlist
+
+ def Repository(self, *dirs, **kw):
+ dirs = self.arg2nodes(list(dirs), self.fs.Dir)
+ self.fs.Repository(*dirs, **kw)
+
+ def Requires(self, target, prerequisite):
+ """Specify that 'prerequisite' must be built before 'target',
+ (but 'target' does not actually depend on 'prerequisite'
+ and need not be rebuilt if it changes)."""
+ tlist = self.arg2nodes(target, self.fs.Entry)
+ plist = self.arg2nodes(prerequisite, self.fs.Entry)
+ for t in tlist:
+ t.add_prerequisite(plist)
+ return tlist
+
+ def Scanner(self, *args, **kw):
+ nargs = []
+ for arg in args:
+ if SCons.Util.is_String(arg):
+ arg = self.subst(arg)
+ nargs.append(arg)
+ nkw = self.subst_kw(kw)
+ return SCons.Scanner.Base(*nargs, **nkw)
+
+ def SConsignFile(self, name=".sconsign", dbm_module=None):
+ if name is not None:
+ name = self.subst(name)
+ if not os.path.isabs(name):
+ name = os.path.join(str(self.fs.SConstruct_dir), name)
+ if name:
+ name = os.path.normpath(name)
+ sconsign_dir = os.path.dirname(name)
+ if sconsign_dir and not os.path.exists(sconsign_dir):
+ self.Execute(SCons.Defaults.Mkdir(sconsign_dir))
+ SCons.SConsign.File(name, dbm_module)
+
+ def SideEffect(self, side_effect, target):
+ """Tell scons that side_effects are built as side
+ effects of building targets."""
+ side_effects = self.arg2nodes(side_effect, self.fs.Entry)
+ targets = self.arg2nodes(target, self.fs.Entry)
+
+ for side_effect in side_effects:
+ if side_effect.multiple_side_effect_has_builder():
+ raise SCons.Errors.UserError("Multiple ways to build the same target were specified for: %s" % str(side_effect))
+ side_effect.add_source(targets)
+ side_effect.side_effect = 1
+ self.Precious(side_effect)
+ for target in targets:
+ target.side_effects.append(side_effect)
+ return side_effects
+
+ def SourceCode(self, entry, builder):
+ """Arrange for a source code builder for (part of) a tree."""
+ msg = """SourceCode() has been deprecated and there is no replacement.
+\tIf you need this function, please contact dev@scons.tigris.org."""
+ SCons.Warnings.warn(SCons.Warnings.DeprecatedSourceCodeWarning, msg)
+ entries = self.arg2nodes(entry, self.fs.Entry)
+ for entry in entries:
+ entry.set_src_builder(builder)
+ return entries
+
+ def SourceSignatures(self, type):
+ global _warn_source_signatures_deprecated
+ if _warn_source_signatures_deprecated:
+ msg = "The env.SourceSignatures() method is deprecated;\n" + \
+ "\tconvert your build to use the env.Decider() method instead."
+ SCons.Warnings.warn(SCons.Warnings.DeprecatedSourceSignaturesWarning, msg)
+ _warn_source_signatures_deprecated = False
+ type = self.subst(type)
+ self.src_sig_type = type
+ if type == 'MD5':
+ if not SCons.Util.md5:
+ raise UserError("MD5 signatures are not available in this version of Python.")
+ self.decide_source = self._changed_content
+ elif type == 'timestamp':
+ self.decide_source = self._changed_timestamp_match
+ else:
+ raise UserError("Unknown source signature type '%s'" % type)
+
+ def Split(self, arg):
+ """This function converts a string or list into a list of strings
+ or Nodes. This makes things easier for users by allowing files to
+ be specified as a white-space separated list to be split.
+ The input rules are:
+ - A single string containing names separated by spaces. These will be
+ split apart at the spaces.
+ - A single Node instance
+ - A list containing either strings or Node instances. Any strings
+ in the list are not split at spaces.
+ In all cases, the function returns a list of Nodes and strings."""
+ if SCons.Util.is_List(arg):
+ return list(map(self.subst, arg))
+ elif SCons.Util.is_String(arg):
+ return self.subst(arg).split()
+ else:
+ return [self.subst(arg)]
+
+ def TargetSignatures(self, type):
+ global _warn_target_signatures_deprecated
+ if _warn_target_signatures_deprecated:
+ msg = "The env.TargetSignatures() method is deprecated;\n" + \
+ "\tconvert your build to use the env.Decider() method instead."
+ SCons.Warnings.warn(SCons.Warnings.DeprecatedTargetSignaturesWarning, msg)
+ _warn_target_signatures_deprecated = False
+ type = self.subst(type)
+ self.tgt_sig_type = type
+ if type in ('MD5', 'content'):
+ if not SCons.Util.md5:
+ raise UserError("MD5 signatures are not available in this version of Python.")
+ self.decide_target = self._changed_content
+ elif type == 'timestamp':
+ self.decide_target = self._changed_timestamp_match
+ elif type == 'build':
+ self.decide_target = self._changed_build
+ elif type == 'source':
+ self.decide_target = self._changed_source
+ else:
+ raise UserError("Unknown target signature type '%s'"%type)
+
+ def Value(self, value, built_value=None):
+ """
+ """
+ return SCons.Node.Python.Value(value, built_value)
+
+ def VariantDir(self, variant_dir, src_dir, duplicate=1):
+ variant_dir = self.arg2nodes(variant_dir, self.fs.Dir)[0]
+ src_dir = self.arg2nodes(src_dir, self.fs.Dir)[0]
+ self.fs.VariantDir(variant_dir, src_dir, duplicate)
+
+ def FindSourceFiles(self, node='.'):
+ """ returns a list of all source files.
+ """
+ node = self.arg2nodes(node, self.fs.Entry)[0]
+
+ sources = []
+ def build_source(ss):
+ for s in ss:
+ if isinstance(s, SCons.Node.FS.Dir):
+ build_source(s.all_children())
+ elif s.has_builder():
+ build_source(s.sources)
+ elif isinstance(s.disambiguate(), SCons.Node.FS.File):
+ sources.append(s)
+ build_source(node.all_children())
+
+ # THIS CODE APPEARS TO HAVE NO EFFECT
+ # # get the final srcnode for all nodes, this means stripping any
+ # # attached build node by calling the srcnode function
+ # for file in sources:
+ # srcnode = file.srcnode()
+ # while srcnode != file.srcnode():
+ # srcnode = file.srcnode()
+
+ # remove duplicates
+ return list(set(sources))
+
+ def FindInstalledFiles(self):
+ """ returns the list of all targets of the Install and InstallAs Builder.
+ """
+ from SCons.Tool import install
+ if install._UNIQUE_INSTALLED_FILES is None:
+ install._UNIQUE_INSTALLED_FILES = SCons.Util.uniquer_hashables(install._INSTALLED_FILES)
+ return install._UNIQUE_INSTALLED_FILES
+
+class OverrideEnvironment(Base):
+ """A proxy that overrides variables in a wrapped construction
+ environment by returning values from an overrides dictionary in
+ preference to values from the underlying subject environment.
+
+ This is a lightweight (I hope) proxy that passes through most use of
+ attributes to the underlying Environment.Base class, but has just
+ enough additional methods defined to act like a real construction
+ environment with overridden values. It can wrap either a Base
+ construction environment, or another OverrideEnvironment, which
+ can in turn nest arbitrary OverrideEnvironments...
+
+ Note that we do *not* call the underlying base class
+ (SubsitutionEnvironment) initialization, because we get most of those
+ from proxying the attributes of the subject construction environment.
+ But because we subclass SubstitutionEnvironment, this class also
+ has inherited arg2nodes() and subst*() methods; those methods can't
+ be proxied because they need *this* object's methods to fetch the
+ values from the overrides dictionary.
+ """
+
+ def __init__(self, subject, overrides={}):
+ if __debug__: logInstanceCreation(self, 'Environment.OverrideEnvironment')
+ self.__dict__['__subject'] = subject
+ self.__dict__['overrides'] = overrides
+
+ # Methods that make this class act like a proxy.
+ def __getattr__(self, name):
+ return getattr(self.__dict__['__subject'], name)
+ def __setattr__(self, name, value):
+ setattr(self.__dict__['__subject'], name, value)
+
+ # Methods that make this class act like a dictionary.
+ def __getitem__(self, key):
+ try:
+ return self.__dict__['overrides'][key]
+ except KeyError:
+ return self.__dict__['__subject'].__getitem__(key)
+ def __setitem__(self, key, value):
+ if not is_valid_construction_var(key):
+ raise SCons.Errors.UserError("Illegal construction variable `%s'" % key)
+ self.__dict__['overrides'][key] = value
+ def __delitem__(self, key):
+ try:
+ del self.__dict__['overrides'][key]
+ except KeyError:
+ deleted = 0
+ else:
+ deleted = 1
+ try:
+ result = self.__dict__['__subject'].__delitem__(key)
+ except KeyError:
+ if not deleted:
+ raise
+ result = None
+ return result
+ def get(self, key, default=None):
+ """Emulates the get() method of dictionaries."""
+ try:
+ return self.__dict__['overrides'][key]
+ except KeyError:
+ return self.__dict__['__subject'].get(key, default)
+ def has_key(self, key):
+ try:
+ self.__dict__['overrides'][key]
+ return 1
+ except KeyError:
+ return key in self.__dict__['__subject']
+ def __contains__(self, key):
+ if self.__dict__['overrides'].__contains__(key):
+ return 1
+ return self.__dict__['__subject'].__contains__(key)
+ def Dictionary(self):
+ """Emulates the items() method of dictionaries."""
+ d = self.__dict__['__subject'].Dictionary().copy()
+ d.update(self.__dict__['overrides'])
+ return d
+ def items(self):
+ """Emulates the items() method of dictionaries."""
+ return list(self.Dictionary().items())
+
+ # Overridden private construction environment methods.
+ def _update(self, dict):
+ """Update an environment's values directly, bypassing the normal
+ checks that occur when users try to set items.
+ """
+ self.__dict__['overrides'].update(dict)
+
+ def gvars(self):
+ return self.__dict__['__subject'].gvars()
+
+ def lvars(self):
+ lvars = self.__dict__['__subject'].lvars()
+ lvars.update(self.__dict__['overrides'])
+ return lvars
+
+ # Overridden public construction environment methods.
+ def Replace(self, **kw):
+ kw = copy_non_reserved_keywords(kw)
+ self.__dict__['overrides'].update(semi_deepcopy(kw))
+
+# The entry point that will be used by the external world
+# to refer to a construction environment. This allows the wrapper
+# interface to extend a construction environment for its own purposes
+# by subclassing SCons.Environment.Base and then assigning the
+# class to SCons.Environment.Environment.
+
+Environment = Base
+
+# An entry point for returning a proxy subclass instance that overrides
+# the subst*() methods so they don't actually perform construction
+# variable substitution. This is specifically intended to be the shim
+# layer in between global function calls (which don't want construction
+# variable substitution) and the DefaultEnvironment() (which would
+# substitute variables if left to its own devices)."""
+#
+# We have to wrap this in a function that allows us to delay definition of
+# the class until it's necessary, so that when it subclasses Environment
+# it will pick up whatever Environment subclass the wrapper interface
+# might have assigned to SCons.Environment.Environment.
+
+def NoSubstitutionProxy(subject):
+ class _NoSubstitutionProxy(Environment):
+ def __init__(self, subject):
+ self.__dict__['__subject'] = subject
+ def __getattr__(self, name):
+ return getattr(self.__dict__['__subject'], name)
+ def __setattr__(self, name, value):
+ return setattr(self.__dict__['__subject'], name, value)
+ def raw_to_mode(self, dict):
+ try:
+ raw = dict['raw']
+ except KeyError:
+ pass
+ else:
+ del dict['raw']
+ dict['mode'] = raw
+ def subst(self, string, *args, **kwargs):
+ return string
+ def subst_kw(self, kw, *args, **kwargs):
+ return kw
+ def subst_list(self, string, *args, **kwargs):
+ nargs = (string, self,) + args
+ nkw = kwargs.copy()
+ nkw['gvars'] = {}
+ self.raw_to_mode(nkw)
+ return SCons.Subst.scons_subst_list(*nargs, **nkw)
+ def subst_target_source(self, string, *args, **kwargs):
+ nargs = (string, self,) + args
+ nkw = kwargs.copy()
+ nkw['gvars'] = {}
+ self.raw_to_mode(nkw)
+ return SCons.Subst.scons_subst(*nargs, **nkw)
+ return _NoSubstitutionProxy(subject)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Errors.py b/couchjs/scons/scons-local-2.0.1/SCons/Errors.py
new file mode 100644
index 00000000..63f9d417
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Errors.py
@@ -0,0 +1,205 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+"""SCons.Errors
+
+This file contains the exception classes used to handle internal
+and user errors in SCons.
+
+"""
+
+__revision__ = "src/engine/SCons/Errors.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Util
+
+import exceptions
+
+class BuildError(Exception):
+ """ Errors occuring while building.
+
+ BuildError have the following attributes:
+
+ Information about the cause of the build error:
+ -----------------------------------------------
+
+ errstr : a description of the error message
+
+ status : the return code of the action that caused the build
+ error. Must be set to a non-zero value even if the
+ build error is not due to an action returning a
+ non-zero returned code.
+
+ exitstatus : SCons exit status due to this build error.
+ Must be nonzero unless due to an explicit Exit()
+ call. Not always the same as status, since
+ actions return a status code that should be
+ respected, but SCons typically exits with 2
+ irrespective of the return value of the failed
+ action.
+
+ filename : The name of the file or directory that caused the
+ build error. Set to None if no files are associated with
+ this error. This might be different from the target
+ being built. For example, failure to create the
+ directory in which the target file will appear. It
+ can be None if the error is not due to a particular
+ filename.
+
+ exc_info : Info about exception that caused the build
+ error. Set to (None, None, None) if this build
+ error is not due to an exception.
+
+
+ Information about the cause of the location of the error:
+ ---------------------------------------------------------
+
+ node : the error occured while building this target node(s)
+
+ executor : the executor that caused the build to fail (might
+ be None if the build failures is not due to the
+ executor failing)
+
+ action : the action that caused the build to fail (might be
+ None if the build failures is not due to the an
+ action failure)
+
+ command : the command line for the action that caused the
+ build to fail (might be None if the build failures
+ is not due to the an action failure)
+ """
+
+ def __init__(self,
+ node=None, errstr="Unknown error", status=2, exitstatus=2,
+ filename=None, executor=None, action=None, command=None,
+ exc_info=(None, None, None)):
+
+ self.errstr = errstr
+ self.status = status
+ self.exitstatus = exitstatus
+ self.filename = filename
+ self.exc_info = exc_info
+
+ self.node = node
+ self.executor = executor
+ self.action = action
+ self.command = command
+
+ Exception.__init__(self, node, errstr, status, exitstatus, filename,
+ executor, action, command, exc_info)
+
+ def __str__(self):
+ if self.filename:
+ return self.filename + ': ' + self.errstr
+ else:
+ return self.errstr
+
+class InternalError(Exception):
+ pass
+
+class UserError(Exception):
+ pass
+
+class StopError(Exception):
+ pass
+
+class EnvironmentError(Exception):
+ pass
+
+class MSVCError(IOError):
+ pass
+
+class ExplicitExit(Exception):
+ def __init__(self, node=None, status=None, *args):
+ self.node = node
+ self.status = status
+ self.exitstatus = status
+ Exception.__init__(self, *args)
+
+def convert_to_BuildError(status, exc_info=None):
+ """
+ Convert any return code a BuildError Exception.
+
+ `status' can either be a return code or an Exception.
+ The buildError.status we set here will normally be
+ used as the exit status of the "scons" process.
+ """
+ if not exc_info and isinstance(status, Exception):
+ exc_info = (status.__class__, status, None)
+
+ if isinstance(status, BuildError):
+ buildError = status
+ buildError.exitstatus = 2 # always exit with 2 on build errors
+ elif isinstance(status, ExplicitExit):
+ status = status.status
+ errstr = 'Explicit exit, status %s' % status
+ buildError = BuildError(
+ errstr=errstr,
+ status=status, # might be 0, OK here
+ exitstatus=status, # might be 0, OK here
+ exc_info=exc_info)
+ elif isinstance(status, (StopError, UserError)):
+ buildError = BuildError(
+ errstr=str(status),
+ status=2,
+ exitstatus=2,
+ exc_info=exc_info)
+ elif isinstance(status, exceptions.EnvironmentError):
+ # If an IOError/OSError happens, raise a BuildError.
+ # Report the name of the file or directory that caused the
+ # error, which might be different from the target being built
+ # (for example, failure to create the directory in which the
+ # target file will appear).
+ try: filename = status.filename
+ except AttributeError: filename = None
+ buildError = BuildError(
+ errstr=status.strerror,
+ status=status.errno,
+ exitstatus=2,
+ filename=filename,
+ exc_info=exc_info)
+ elif isinstance(status, Exception):
+ buildError = BuildError(
+ errstr='%s : %s' % (status.__class__.__name__, status),
+ status=2,
+ exitstatus=2,
+ exc_info=exc_info)
+ elif SCons.Util.is_String(status):
+ buildError = BuildError(
+ errstr=status,
+ status=2,
+ exitstatus=2)
+ else:
+ buildError = BuildError(
+ errstr="Error %s" % status,
+ status=status,
+ exitstatus=2)
+
+ #import sys
+ #sys.stderr.write("convert_to_BuildError: status %s => (errstr %s, status %s)"%(status,buildError.errstr, buildError.status))
+ return buildError
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Executor.py b/couchjs/scons/scons-local-2.0.1/SCons/Executor.py
new file mode 100644
index 00000000..b31e3483
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Executor.py
@@ -0,0 +1,633 @@
+"""SCons.Executor
+
+A module for executing actions with specific lists of target and source
+Nodes.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Executor.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import collections
+
+from SCons.Debug import logInstanceCreation
+import SCons.Errors
+import SCons.Memoize
+
+
+class Batch(object):
+ """Remembers exact association between targets
+ and sources of executor."""
+ def __init__(self, targets=[], sources=[]):
+ self.targets = targets
+ self.sources = sources
+
+
+
+class TSList(collections.UserList):
+ """A class that implements $TARGETS or $SOURCES expansions by wrapping
+ an executor Method. This class is used in the Executor.lvars()
+ to delay creation of NodeList objects until they're needed.
+
+ Note that we subclass collections.UserList purely so that the
+ is_Sequence() function will identify an object of this class as
+ a list during variable expansion. We're not really using any
+ collections.UserList methods in practice.
+ """
+ def __init__(self, func):
+ self.func = func
+ def __getattr__(self, attr):
+ nl = self.func()
+ return getattr(nl, attr)
+ def __getitem__(self, i):
+ nl = self.func()
+ return nl[i]
+ def __getslice__(self, i, j):
+ nl = self.func()
+ i = max(i, 0); j = max(j, 0)
+ return nl[i:j]
+ def __str__(self):
+ nl = self.func()
+ return str(nl)
+ def __repr__(self):
+ nl = self.func()
+ return repr(nl)
+
+class TSObject(object):
+ """A class that implements $TARGET or $SOURCE expansions by wrapping
+ an Executor method.
+ """
+ def __init__(self, func):
+ self.func = func
+ def __getattr__(self, attr):
+ n = self.func()
+ return getattr(n, attr)
+ def __str__(self):
+ n = self.func()
+ if n:
+ return str(n)
+ return ''
+ def __repr__(self):
+ n = self.func()
+ if n:
+ return repr(n)
+ return ''
+
+def rfile(node):
+ """
+ A function to return the results of a Node's rfile() method,
+ if it exists, and the Node itself otherwise (if it's a Value
+ Node, e.g.).
+ """
+ try:
+ rfile = node.rfile
+ except AttributeError:
+ return node
+ else:
+ return rfile()
+
+
+class Executor(object):
+ """A class for controlling instances of executing an action.
+
+ This largely exists to hold a single association of an action,
+ environment, list of environment override dictionaries, targets
+ and sources for later processing as needed.
+ """
+
+ if SCons.Memoize.use_memoizer:
+ __metaclass__ = SCons.Memoize.Memoized_Metaclass
+
+ memoizer_counters = []
+
+ def __init__(self, action, env=None, overridelist=[{}],
+ targets=[], sources=[], builder_kw={}):
+ if __debug__: logInstanceCreation(self, 'Executor.Executor')
+ self.set_action_list(action)
+ self.pre_actions = []
+ self.post_actions = []
+ self.env = env
+ self.overridelist = overridelist
+ if targets or sources:
+ self.batches = [Batch(targets[:], sources[:])]
+ else:
+ self.batches = []
+ self.builder_kw = builder_kw
+ self._memo = {}
+
+ def get_lvars(self):
+ try:
+ return self.lvars
+ except AttributeError:
+ self.lvars = {
+ 'CHANGED_SOURCES' : TSList(self._get_changed_sources),
+ 'CHANGED_TARGETS' : TSList(self._get_changed_targets),
+ 'SOURCE' : TSObject(self._get_source),
+ 'SOURCES' : TSList(self._get_sources),
+ 'TARGET' : TSObject(self._get_target),
+ 'TARGETS' : TSList(self._get_targets),
+ 'UNCHANGED_SOURCES' : TSList(self._get_unchanged_sources),
+ 'UNCHANGED_TARGETS' : TSList(self._get_unchanged_targets),
+ }
+ return self.lvars
+
+ def _get_changes(self):
+ cs = []
+ ct = []
+ us = []
+ ut = []
+ for b in self.batches:
+ if b.targets[0].is_up_to_date():
+ us.extend(list(map(rfile, b.sources)))
+ ut.extend(b.targets)
+ else:
+ cs.extend(list(map(rfile, b.sources)))
+ ct.extend(b.targets)
+ self._changed_sources_list = SCons.Util.NodeList(cs)
+ self._changed_targets_list = SCons.Util.NodeList(ct)
+ self._unchanged_sources_list = SCons.Util.NodeList(us)
+ self._unchanged_targets_list = SCons.Util.NodeList(ut)
+
+ def _get_changed_sources(self, *args, **kw):
+ try:
+ return self._changed_sources_list
+ except AttributeError:
+ self._get_changes()
+ return self._changed_sources_list
+
+ def _get_changed_targets(self, *args, **kw):
+ try:
+ return self._changed_targets_list
+ except AttributeError:
+ self._get_changes()
+ return self._changed_targets_list
+
+ def _get_source(self, *args, **kw):
+ #return SCons.Util.NodeList([rfile(self.batches[0].sources[0]).get_subst_proxy()])
+ return rfile(self.batches[0].sources[0]).get_subst_proxy()
+
+ def _get_sources(self, *args, **kw):
+ return SCons.Util.NodeList([rfile(n).get_subst_proxy() for n in self.get_all_sources()])
+
+ def _get_target(self, *args, **kw):
+ #return SCons.Util.NodeList([self.batches[0].targets[0].get_subst_proxy()])
+ return self.batches[0].targets[0].get_subst_proxy()
+
+ def _get_targets(self, *args, **kw):
+ return SCons.Util.NodeList([n.get_subst_proxy() for n in self.get_all_targets()])
+
+ def _get_unchanged_sources(self, *args, **kw):
+ try:
+ return self._unchanged_sources_list
+ except AttributeError:
+ self._get_changes()
+ return self._unchanged_sources_list
+
+ def _get_unchanged_targets(self, *args, **kw):
+ try:
+ return self._unchanged_targets_list
+ except AttributeError:
+ self._get_changes()
+ return self._unchanged_targets_list
+
+ def get_action_targets(self):
+ if not self.action_list:
+ return []
+ targets_string = self.action_list[0].get_targets(self.env, self)
+ if targets_string[0] == '$':
+ targets_string = targets_string[1:]
+ return self.get_lvars()[targets_string]
+
+ def set_action_list(self, action):
+ import SCons.Util
+ if not SCons.Util.is_List(action):
+ if not action:
+ import SCons.Errors
+ raise SCons.Errors.UserError("Executor must have an action.")
+ action = [action]
+ self.action_list = action
+
+ def get_action_list(self):
+ return self.pre_actions + self.action_list + self.post_actions
+
+ def get_all_targets(self):
+ """Returns all targets for all batches of this Executor."""
+ result = []
+ for batch in self.batches:
+ result.extend(batch.targets)
+ return result
+
+ def get_all_sources(self):
+ """Returns all sources for all batches of this Executor."""
+ result = []
+ for batch in self.batches:
+ result.extend(batch.sources)
+ return result
+
+ def get_all_children(self):
+ """Returns all unique children (dependencies) for all batches
+ of this Executor.
+
+ The Taskmaster can recognize when it's already evaluated a
+ Node, so we don't have to make this list unique for its intended
+ canonical use case, but we expect there to be a lot of redundancy
+ (long lists of batched .cc files #including the same .h files
+ over and over), so removing the duplicates once up front should
+ save the Taskmaster a lot of work.
+ """
+ result = SCons.Util.UniqueList([])
+ for target in self.get_all_targets():
+ result.extend(target.children())
+ return result
+
+ def get_all_prerequisites(self):
+ """Returns all unique (order-only) prerequisites for all batches
+ of this Executor.
+ """
+ result = SCons.Util.UniqueList([])
+ for target in self.get_all_targets():
+ result.extend(target.prerequisites)
+ return result
+
+ def get_action_side_effects(self):
+
+ """Returns all side effects for all batches of this
+ Executor used by the underlying Action.
+ """
+ result = SCons.Util.UniqueList([])
+ for target in self.get_action_targets():
+ result.extend(target.side_effects)
+ return result
+
+ memoizer_counters.append(SCons.Memoize.CountValue('get_build_env'))
+
+ def get_build_env(self):
+ """Fetch or create the appropriate build Environment
+ for this Executor.
+ """
+ try:
+ return self._memo['get_build_env']
+ except KeyError:
+ pass
+
+ # Create the build environment instance with appropriate
+ # overrides. These get evaluated against the current
+ # environment's construction variables so that users can
+ # add to existing values by referencing the variable in
+ # the expansion.
+ overrides = {}
+ for odict in self.overridelist:
+ overrides.update(odict)
+
+ import SCons.Defaults
+ env = self.env or SCons.Defaults.DefaultEnvironment()
+ build_env = env.Override(overrides)
+
+ self._memo['get_build_env'] = build_env
+
+ return build_env
+
+ def get_build_scanner_path(self, scanner):
+ """Fetch the scanner path for this executor's targets and sources.
+ """
+ env = self.get_build_env()
+ try:
+ cwd = self.batches[0].targets[0].cwd
+ except (IndexError, AttributeError):
+ cwd = None
+ return scanner.path(env, cwd,
+ self.get_all_targets(),
+ self.get_all_sources())
+
+ def get_kw(self, kw={}):
+ result = self.builder_kw.copy()
+ result.update(kw)
+ result['executor'] = self
+ return result
+
+ def do_nothing(self, target, kw):
+ return 0
+
+ def do_execute(self, target, kw):
+ """Actually execute the action list."""
+ env = self.get_build_env()
+ kw = self.get_kw(kw)
+ status = 0
+ for act in self.get_action_list():
+ #args = (self.get_all_targets(), self.get_all_sources(), env)
+ args = ([], [], env)
+ status = act(*args, **kw)
+ if isinstance(status, SCons.Errors.BuildError):
+ status.executor = self
+ raise status
+ elif status:
+ msg = "Error %s" % status
+ raise SCons.Errors.BuildError(
+ errstr=msg,
+ node=self.batches[0].targets,
+ executor=self,
+ action=act)
+ return status
+
+ # use extra indirection because with new-style objects (Python 2.2
+ # and above) we can't override special methods, and nullify() needs
+ # to be able to do this.
+
+ def __call__(self, target, **kw):
+ return self.do_execute(target, kw)
+
+ def cleanup(self):
+ self._memo = {}
+
+ def add_sources(self, sources):
+ """Add source files to this Executor's list. This is necessary
+ for "multi" Builders that can be called repeatedly to build up
+ a source file list for a given target."""
+ # TODO(batch): extend to multiple batches
+ assert (len(self.batches) == 1)
+ # TODO(batch): remove duplicates?
+ sources = [x for x in sources if x not in self.batches[0].sources]
+ self.batches[0].sources.extend(sources)
+
+ def get_sources(self):
+ return self.batches[0].sources
+
+ def add_batch(self, targets, sources):
+ """Add pair of associated target and source to this Executor's list.
+ This is necessary for "batch" Builders that can be called repeatedly
+ to build up a list of matching target and source files that will be
+ used in order to update multiple target files at once from multiple
+ corresponding source files, for tools like MSVC that support it."""
+ self.batches.append(Batch(targets, sources))
+
+ def prepare(self):
+ """
+ Preparatory checks for whether this Executor can go ahead
+ and (try to) build its targets.
+ """
+ for s in self.get_all_sources():
+ if s.missing():
+ msg = "Source `%s' not found, needed by target `%s'."
+ raise SCons.Errors.StopError(msg % (s, self.batches[0].targets[0]))
+
+ def add_pre_action(self, action):
+ self.pre_actions.append(action)
+
+ def add_post_action(self, action):
+ self.post_actions.append(action)
+
+ # another extra indirection for new-style objects and nullify...
+
+ def my_str(self):
+ env = self.get_build_env()
+ return "\n".join([action.genstring(self.get_all_targets(),
+ self.get_all_sources(),
+ env)
+ for action in self.get_action_list()])
+
+
+ def __str__(self):
+ return self.my_str()
+
+ def nullify(self):
+ self.cleanup()
+ self.do_execute = self.do_nothing
+ self.my_str = lambda: ''
+
+ memoizer_counters.append(SCons.Memoize.CountValue('get_contents'))
+
+ def get_contents(self):
+ """Fetch the signature contents. This is the main reason this
+ class exists, so we can compute this once and cache it regardless
+ of how many target or source Nodes there are.
+ """
+ try:
+ return self._memo['get_contents']
+ except KeyError:
+ pass
+ env = self.get_build_env()
+ result = "".join([action.get_contents(self.get_all_targets(),
+ self.get_all_sources(),
+ env)
+ for action in self.get_action_list()])
+ self._memo['get_contents'] = result
+ return result
+
+ def get_timestamp(self):
+ """Fetch a time stamp for this Executor. We don't have one, of
+ course (only files do), but this is the interface used by the
+ timestamp module.
+ """
+ return 0
+
+ def scan_targets(self, scanner):
+ # TODO(batch): scan by batches
+ self.scan(scanner, self.get_all_targets())
+
+ def scan_sources(self, scanner):
+ # TODO(batch): scan by batches
+ if self.batches[0].sources:
+ self.scan(scanner, self.get_all_sources())
+
+ def scan(self, scanner, node_list):
+ """Scan a list of this Executor's files (targets or sources) for
+ implicit dependencies and update all of the targets with them.
+ This essentially short-circuits an N*M scan of the sources for
+ each individual target, which is a hell of a lot more efficient.
+ """
+ env = self.get_build_env()
+
+ # TODO(batch): scan by batches)
+ deps = []
+ if scanner:
+ for node in node_list:
+ node.disambiguate()
+ s = scanner.select(node)
+ if not s:
+ continue
+ path = self.get_build_scanner_path(s)
+ deps.extend(node.get_implicit_deps(env, s, path))
+ else:
+ kw = self.get_kw()
+ for node in node_list:
+ node.disambiguate()
+ scanner = node.get_env_scanner(env, kw)
+ if not scanner:
+ continue
+ scanner = scanner.select(node)
+ if not scanner:
+ continue
+ path = self.get_build_scanner_path(scanner)
+ deps.extend(node.get_implicit_deps(env, scanner, path))
+
+ deps.extend(self.get_implicit_deps())
+
+ for tgt in self.get_all_targets():
+ tgt.add_to_implicit(deps)
+
+ def _get_unignored_sources_key(self, node, ignore=()):
+ return (node,) + tuple(ignore)
+
+ memoizer_counters.append(SCons.Memoize.CountDict('get_unignored_sources', _get_unignored_sources_key))
+
+ def get_unignored_sources(self, node, ignore=()):
+ key = (node,) + tuple(ignore)
+ try:
+ memo_dict = self._memo['get_unignored_sources']
+ except KeyError:
+ memo_dict = {}
+ self._memo['get_unignored_sources'] = memo_dict
+ else:
+ try:
+ return memo_dict[key]
+ except KeyError:
+ pass
+
+ if node:
+ # TODO: better way to do this (it's a linear search,
+ # but it may not be critical path)?
+ sourcelist = []
+ for b in self.batches:
+ if node in b.targets:
+ sourcelist = b.sources
+ break
+ else:
+ sourcelist = self.get_all_sources()
+ if ignore:
+ idict = {}
+ for i in ignore:
+ idict[i] = 1
+ sourcelist = [s for s in sourcelist if s not in idict]
+
+ memo_dict[key] = sourcelist
+
+ return sourcelist
+
+ def get_implicit_deps(self):
+ """Return the executor's implicit dependencies, i.e. the nodes of
+ the commands to be executed."""
+ result = []
+ build_env = self.get_build_env()
+ for act in self.get_action_list():
+ deps = act.get_implicit_deps(self.get_all_targets(),
+ self.get_all_sources(),
+ build_env)
+ result.extend(deps)
+ return result
+
+
+
+_batch_executors = {}
+
+def GetBatchExecutor(key):
+ return _batch_executors[key]
+
+def AddBatchExecutor(key, executor):
+ assert key not in _batch_executors
+ _batch_executors[key] = executor
+
+nullenv = None
+
+
+def get_NullEnvironment():
+ """Use singleton pattern for Null Environments."""
+ global nullenv
+
+ import SCons.Util
+ class NullEnvironment(SCons.Util.Null):
+ import SCons.CacheDir
+ _CacheDir_path = None
+ _CacheDir = SCons.CacheDir.CacheDir(None)
+ def get_CacheDir(self):
+ return self._CacheDir
+
+ if not nullenv:
+ nullenv = NullEnvironment()
+ return nullenv
+
+class Null(object):
+ """A null Executor, with a null build Environment, that does
+ nothing when the rest of the methods call it.
+
+ This might be able to disapper when we refactor things to
+ disassociate Builders from Nodes entirely, so we're not
+ going to worry about unit tests for this--at least for now.
+ """
+ def __init__(self, *args, **kw):
+ if __debug__: logInstanceCreation(self, 'Executor.Null')
+ self.batches = [Batch(kw['targets'][:], [])]
+ def get_build_env(self):
+ return get_NullEnvironment()
+ def get_build_scanner_path(self):
+ return None
+ def cleanup(self):
+ pass
+ def prepare(self):
+ pass
+ def get_unignored_sources(self, *args, **kw):
+ return tuple(())
+ def get_action_targets(self):
+ return []
+ def get_action_list(self):
+ return []
+ def get_all_targets(self):
+ return self.batches[0].targets
+ def get_all_sources(self):
+ return self.batches[0].targets[0].sources
+ def get_all_children(self):
+ return self.batches[0].targets[0].children()
+ def get_all_prerequisites(self):
+ return []
+ def get_action_side_effects(self):
+ return []
+ def __call__(self, *args, **kw):
+ return 0
+ def get_contents(self):
+ return ''
+ def _morph(self):
+ """Morph this Null executor to a real Executor object."""
+ batches = self.batches
+ self.__class__ = Executor
+ self.__init__([])
+ self.batches = batches
+
+ # The following methods require morphing this Null Executor to a
+ # real Executor object.
+
+ def add_pre_action(self, action):
+ self._morph()
+ self.add_pre_action(action)
+ def add_post_action(self, action):
+ self._morph()
+ self.add_post_action(action)
+ def set_action_list(self, action):
+ self._morph()
+ self.set_action_list(action)
+
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Job.py b/couchjs/scons/scons-local-2.0.1/SCons/Job.py
new file mode 100644
index 00000000..7866bb40
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Job.py
@@ -0,0 +1,435 @@
+"""SCons.Job
+
+This module defines the Serial and Parallel classes that execute tasks to
+complete a build. The Jobs class provides a higher level interface to start,
+stop, and wait on jobs.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Job.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.compat
+
+import os
+import signal
+
+import SCons.Errors
+
+# The default stack size (in kilobytes) of the threads used to execute
+# jobs in parallel.
+#
+# We use a stack size of 256 kilobytes. The default on some platforms
+# is too large and prevents us from creating enough threads to fully
+# parallelized the build. For example, the default stack size on linux
+# is 8 MBytes.
+
+explicit_stack_size = None
+default_stack_size = 256
+
+interrupt_msg = 'Build interrupted.'
+
+
+class InterruptState(object):
+ def __init__(self):
+ self.interrupted = False
+
+ def set(self):
+ self.interrupted = True
+
+ def __call__(self):
+ return self.interrupted
+
+
+class Jobs(object):
+ """An instance of this class initializes N jobs, and provides
+ methods for starting, stopping, and waiting on all N jobs.
+ """
+
+ def __init__(self, num, taskmaster):
+ """
+ create 'num' jobs using the given taskmaster.
+
+ If 'num' is 1 or less, then a serial job will be used,
+ otherwise a parallel job with 'num' worker threads will
+ be used.
+
+ The 'num_jobs' attribute will be set to the actual number of jobs
+ allocated. If more than one job is requested but the Parallel
+ class can't do it, it gets reset to 1. Wrapping interfaces that
+ care should check the value of 'num_jobs' after initialization.
+ """
+
+ self.job = None
+ if num > 1:
+ stack_size = explicit_stack_size
+ if stack_size is None:
+ stack_size = default_stack_size
+
+ try:
+ self.job = Parallel(taskmaster, num, stack_size)
+ self.num_jobs = num
+ except NameError:
+ pass
+ if self.job is None:
+ self.job = Serial(taskmaster)
+ self.num_jobs = 1
+
+ def run(self, postfunc=lambda: None):
+ """Run the jobs.
+
+ postfunc() will be invoked after the jobs has run. It will be
+ invoked even if the jobs are interrupted by a keyboard
+ interrupt (well, in fact by a signal such as either SIGINT,
+ SIGTERM or SIGHUP). The execution of postfunc() is protected
+ against keyboard interrupts and is guaranteed to run to
+ completion."""
+ self._setup_sig_handler()
+ try:
+ self.job.start()
+ finally:
+ postfunc()
+ self._reset_sig_handler()
+
+ def were_interrupted(self):
+ """Returns whether the jobs were interrupted by a signal."""
+ return self.job.interrupted()
+
+ def _setup_sig_handler(self):
+ """Setup an interrupt handler so that SCons can shutdown cleanly in
+ various conditions:
+
+ a) SIGINT: Keyboard interrupt
+ b) SIGTERM: kill or system shutdown
+ c) SIGHUP: Controlling shell exiting
+
+ We handle all of these cases by stopping the taskmaster. It
+ turns out that it very difficult to stop the build process
+ by throwing asynchronously an exception such as
+ KeyboardInterrupt. For example, the python Condition
+ variables (threading.Condition) and queue's do not seem to
+ asynchronous-exception-safe. It would require adding a whole
+ bunch of try/finally block and except KeyboardInterrupt all
+ over the place.
+
+ Note also that we have to be careful to handle the case when
+ SCons forks before executing another process. In that case, we
+ want the child to exit immediately.
+ """
+ def handler(signum, stack, self=self, parentpid=os.getpid()):
+ if os.getpid() == parentpid:
+ self.job.taskmaster.stop()
+ self.job.interrupted.set()
+ else:
+ os._exit(2)
+
+ self.old_sigint = signal.signal(signal.SIGINT, handler)
+ self.old_sigterm = signal.signal(signal.SIGTERM, handler)
+ try:
+ self.old_sighup = signal.signal(signal.SIGHUP, handler)
+ except AttributeError:
+ pass
+
+ def _reset_sig_handler(self):
+ """Restore the signal handlers to their previous state (before the
+ call to _setup_sig_handler()."""
+
+ signal.signal(signal.SIGINT, self.old_sigint)
+ signal.signal(signal.SIGTERM, self.old_sigterm)
+ try:
+ signal.signal(signal.SIGHUP, self.old_sighup)
+ except AttributeError:
+ pass
+
+class Serial(object):
+ """This class is used to execute tasks in series, and is more efficient
+ than Parallel, but is only appropriate for non-parallel builds. Only
+ one instance of this class should be in existence at a time.
+
+ This class is not thread safe.
+ """
+
+ def __init__(self, taskmaster):
+ """Create a new serial job given a taskmaster.
+
+ The taskmaster's next_task() method should return the next task
+ that needs to be executed, or None if there are no more tasks. The
+ taskmaster's executed() method will be called for each task when it
+ is successfully executed or failed() will be called if it failed to
+ execute (e.g. execute() raised an exception)."""
+
+ self.taskmaster = taskmaster
+ self.interrupted = InterruptState()
+
+ def start(self):
+ """Start the job. This will begin pulling tasks from the taskmaster
+ and executing them, and return when there are no more tasks. If a task
+ fails to execute (i.e. execute() raises an exception), then the job will
+ stop."""
+
+ while True:
+ task = self.taskmaster.next_task()
+
+ if task is None:
+ break
+
+ try:
+ task.prepare()
+ if task.needs_execute():
+ task.execute()
+ except:
+ if self.interrupted():
+ try:
+ raise SCons.Errors.BuildError(
+ task.targets[0], errstr=interrupt_msg)
+ except:
+ task.exception_set()
+ else:
+ task.exception_set()
+
+ # Let the failed() callback function arrange for the
+ # build to stop if that's appropriate.
+ task.failed()
+ else:
+ task.executed()
+
+ task.postprocess()
+ self.taskmaster.cleanup()
+
+
+# Trap import failure so that everything in the Job module but the
+# Parallel class (and its dependent classes) will work if the interpreter
+# doesn't support threads.
+try:
+ import queue
+ import threading
+except ImportError:
+ pass
+else:
+ class Worker(threading.Thread):
+ """A worker thread waits on a task to be posted to its request queue,
+ dequeues the task, executes it, and posts a tuple including the task
+ and a boolean indicating whether the task executed successfully. """
+
+ def __init__(self, requestQueue, resultsQueue, interrupted):
+ threading.Thread.__init__(self)
+ self.setDaemon(1)
+ self.requestQueue = requestQueue
+ self.resultsQueue = resultsQueue
+ self.interrupted = interrupted
+ self.start()
+
+ def run(self):
+ while True:
+ task = self.requestQueue.get()
+
+ if task is None:
+ # The "None" value is used as a sentinel by
+ # ThreadPool.cleanup(). This indicates that there
+ # are no more tasks, so we should quit.
+ break
+
+ try:
+ if self.interrupted():
+ raise SCons.Errors.BuildError(
+ task.targets[0], errstr=interrupt_msg)
+ task.execute()
+ except:
+ task.exception_set()
+ ok = False
+ else:
+ ok = True
+
+ self.resultsQueue.put((task, ok))
+
+ class ThreadPool(object):
+ """This class is responsible for spawning and managing worker threads."""
+
+ def __init__(self, num, stack_size, interrupted):
+ """Create the request and reply queues, and 'num' worker threads.
+
+ One must specify the stack size of the worker threads. The
+ stack size is specified in kilobytes.
+ """
+ self.requestQueue = queue.Queue(0)
+ self.resultsQueue = queue.Queue(0)
+
+ try:
+ prev_size = threading.stack_size(stack_size*1024)
+ except AttributeError, e:
+ # Only print a warning if the stack size has been
+ # explicitly set.
+ if not explicit_stack_size is None:
+ msg = "Setting stack size is unsupported by this version of Python:\n " + \
+ e.args[0]
+ SCons.Warnings.warn(SCons.Warnings.StackSizeWarning, msg)
+ except ValueError, e:
+ msg = "Setting stack size failed:\n " + str(e)
+ SCons.Warnings.warn(SCons.Warnings.StackSizeWarning, msg)
+
+ # Create worker threads
+ self.workers = []
+ for _ in range(num):
+ worker = Worker(self.requestQueue, self.resultsQueue, interrupted)
+ self.workers.append(worker)
+
+ if 'prev_size' in locals():
+ threading.stack_size(prev_size)
+
+ def put(self, task):
+ """Put task into request queue."""
+ self.requestQueue.put(task)
+
+ def get(self):
+ """Remove and return a result tuple from the results queue."""
+ return self.resultsQueue.get()
+
+ def preparation_failed(self, task):
+ self.resultsQueue.put((task, False))
+
+ def cleanup(self):
+ """
+ Shuts down the thread pool, giving each worker thread a
+ chance to shut down gracefully.
+ """
+ # For each worker thread, put a sentinel "None" value
+ # on the requestQueue (indicating that there's no work
+ # to be done) so that each worker thread will get one and
+ # terminate gracefully.
+ for _ in self.workers:
+ self.requestQueue.put(None)
+
+ # Wait for all of the workers to terminate.
+ #
+ # If we don't do this, later Python versions (2.4, 2.5) often
+ # seem to raise exceptions during shutdown. This happens
+ # in requestQueue.get(), as an assertion failure that
+ # requestQueue.not_full is notified while not acquired,
+ # seemingly because the main thread has shut down (or is
+ # in the process of doing so) while the workers are still
+ # trying to pull sentinels off the requestQueue.
+ #
+ # Normally these terminations should happen fairly quickly,
+ # but we'll stick a one-second timeout on here just in case
+ # someone gets hung.
+ for worker in self.workers:
+ worker.join(1.0)
+ self.workers = []
+
+ class Parallel(object):
+ """This class is used to execute tasks in parallel, and is somewhat
+ less efficient than Serial, but is appropriate for parallel builds.
+
+ This class is thread safe.
+ """
+
+ def __init__(self, taskmaster, num, stack_size):
+ """Create a new parallel job given a taskmaster.
+
+ The taskmaster's next_task() method should return the next
+ task that needs to be executed, or None if there are no more
+ tasks. The taskmaster's executed() method will be called
+ for each task when it is successfully executed or failed()
+ will be called if the task failed to execute (i.e. execute()
+ raised an exception).
+
+ Note: calls to taskmaster are serialized, but calls to
+ execute() on distinct tasks are not serialized, because
+ that is the whole point of parallel jobs: they can execute
+ multiple tasks simultaneously. """
+
+ self.taskmaster = taskmaster
+ self.interrupted = InterruptState()
+ self.tp = ThreadPool(num, stack_size, self.interrupted)
+
+ self.maxjobs = num
+
+ def start(self):
+ """Start the job. This will begin pulling tasks from the
+ taskmaster and executing them, and return when there are no
+ more tasks. If a task fails to execute (i.e. execute() raises
+ an exception), then the job will stop."""
+
+ jobs = 0
+
+ while True:
+ # Start up as many available tasks as we're
+ # allowed to.
+ while jobs < self.maxjobs:
+ task = self.taskmaster.next_task()
+ if task is None:
+ break
+
+ try:
+ # prepare task for execution
+ task.prepare()
+ except:
+ task.exception_set()
+ task.failed()
+ task.postprocess()
+ else:
+ if task.needs_execute():
+ # dispatch task
+ self.tp.put(task)
+ jobs = jobs + 1
+ else:
+ task.executed()
+ task.postprocess()
+
+ if not task and not jobs: break
+
+ # Let any/all completed tasks finish up before we go
+ # back and put the next batch of tasks on the queue.
+ while True:
+ task, ok = self.tp.get()
+ jobs = jobs - 1
+
+ if ok:
+ task.executed()
+ else:
+ if self.interrupted():
+ try:
+ raise SCons.Errors.BuildError(
+ task.targets[0], errstr=interrupt_msg)
+ except:
+ task.exception_set()
+
+ # Let the failed() callback function arrange
+ # for the build to stop if that's appropriate.
+ task.failed()
+
+ task.postprocess()
+
+ if self.tp.resultsQueue.empty():
+ break
+
+ self.tp.cleanup()
+ self.taskmaster.cleanup()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Memoize.py b/couchjs/scons/scons-local-2.0.1/SCons/Memoize.py
new file mode 100644
index 00000000..c76d6a52
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Memoize.py
@@ -0,0 +1,244 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Memoize.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__doc__ = """Memoizer
+
+A metaclass implementation to count hits and misses of the computed
+values that various methods cache in memory.
+
+Use of this modules assumes that wrapped methods be coded to cache their
+values in a consistent way. Here is an example of wrapping a method
+that returns a computed value, with no input parameters:
+
+ memoizer_counters = [] # Memoization
+
+ memoizer_counters.append(SCons.Memoize.CountValue('foo')) # Memoization
+
+ def foo(self):
+
+ try: # Memoization
+ return self._memo['foo'] # Memoization
+ except KeyError: # Memoization
+ pass # Memoization
+
+ result = self.compute_foo_value()
+
+ self._memo['foo'] = result # Memoization
+
+ return result
+
+Here is an example of wrapping a method that will return different values
+based on one or more input arguments:
+
+ def _bar_key(self, argument): # Memoization
+ return argument # Memoization
+
+ memoizer_counters.append(SCons.Memoize.CountDict('bar', _bar_key)) # Memoization
+
+ def bar(self, argument):
+
+ memo_key = argument # Memoization
+ try: # Memoization
+ memo_dict = self._memo['bar'] # Memoization
+ except KeyError: # Memoization
+ memo_dict = {} # Memoization
+ self._memo['dict'] = memo_dict # Memoization
+ else: # Memoization
+ try: # Memoization
+ return memo_dict[memo_key] # Memoization
+ except KeyError: # Memoization
+ pass # Memoization
+
+ result = self.compute_bar_value(argument)
+
+ memo_dict[memo_key] = result # Memoization
+
+ return result
+
+At one point we avoided replicating this sort of logic in all the methods
+by putting it right into this module, but we've moved away from that at
+present (see the "Historical Note," below.).
+
+Deciding what to cache is tricky, because different configurations
+can have radically different performance tradeoffs, and because the
+tradeoffs involved are often so non-obvious. Consequently, deciding
+whether or not to cache a given method will likely be more of an art than
+a science, but should still be based on available data from this module.
+Here are some VERY GENERAL guidelines about deciding whether or not to
+cache return values from a method that's being called a lot:
+
+ -- The first question to ask is, "Can we change the calling code
+ so this method isn't called so often?" Sometimes this can be
+ done by changing the algorithm. Sometimes the *caller* should
+ be memoized, not the method you're looking at.
+
+ -- The memoized function should be timed with multiple configurations
+ to make sure it doesn't inadvertently slow down some other
+ configuration.
+
+ -- When memoizing values based on a dictionary key composed of
+ input arguments, you don't need to use all of the arguments
+ if some of them don't affect the return values.
+
+Historical Note: The initial Memoizer implementation actually handled
+the caching of values for the wrapped methods, based on a set of generic
+algorithms for computing hashable values based on the method's arguments.
+This collected caching logic nicely, but had two drawbacks:
+
+ Running arguments through a generic key-conversion mechanism is slower
+ (and less flexible) than just coding these things directly. Since the
+ methods that need memoized values are generally performance-critical,
+ slowing them down in order to collect the logic isn't the right
+ tradeoff.
+
+ Use of the memoizer really obscured what was being called, because
+ all the memoized methods were wrapped with re-used generic methods.
+ This made it more difficult, for example, to use the Python profiler
+ to figure out how to optimize the underlying methods.
+"""
+
+import types
+
+# A flag controlling whether or not we actually use memoization.
+use_memoizer = None
+
+CounterList = []
+
+class Counter(object):
+ """
+ Base class for counting memoization hits and misses.
+
+ We expect that the metaclass initialization will have filled in
+ the .name attribute that represents the name of the function
+ being counted.
+ """
+ def __init__(self, method_name):
+ """
+ """
+ self.method_name = method_name
+ self.hit = 0
+ self.miss = 0
+ CounterList.append(self)
+ def display(self):
+ fmt = " %7d hits %7d misses %s()"
+ print fmt % (self.hit, self.miss, self.name)
+ def __cmp__(self, other):
+ try:
+ return cmp(self.name, other.name)
+ except AttributeError:
+ return 0
+
+class CountValue(Counter):
+ """
+ A counter class for simple, atomic memoized values.
+
+ A CountValue object should be instantiated in a class for each of
+ the class's methods that memoizes its return value by simply storing
+ the return value in its _memo dictionary.
+
+ We expect that the metaclass initialization will fill in the
+ .underlying_method attribute with the method that we're wrapping.
+ We then call the underlying_method method after counting whether
+ its memoized value has already been set (a hit) or not (a miss).
+ """
+ def __call__(self, *args, **kw):
+ obj = args[0]
+ if self.method_name in obj._memo:
+ self.hit = self.hit + 1
+ else:
+ self.miss = self.miss + 1
+ return self.underlying_method(*args, **kw)
+
+class CountDict(Counter):
+ """
+ A counter class for memoized values stored in a dictionary, with
+ keys based on the method's input arguments.
+
+ A CountDict object is instantiated in a class for each of the
+ class's methods that memoizes its return value in a dictionary,
+ indexed by some key that can be computed from one or more of
+ its input arguments.
+
+ We expect that the metaclass initialization will fill in the
+ .underlying_method attribute with the method that we're wrapping.
+ We then call the underlying_method method after counting whether the
+ computed key value is already present in the memoization dictionary
+ (a hit) or not (a miss).
+ """
+ def __init__(self, method_name, keymaker):
+ """
+ """
+ Counter.__init__(self, method_name)
+ self.keymaker = keymaker
+ def __call__(self, *args, **kw):
+ obj = args[0]
+ try:
+ memo_dict = obj._memo[self.method_name]
+ except KeyError:
+ self.miss = self.miss + 1
+ else:
+ key = self.keymaker(*args, **kw)
+ if key in memo_dict:
+ self.hit = self.hit + 1
+ else:
+ self.miss = self.miss + 1
+ return self.underlying_method(*args, **kw)
+
+class Memoizer(object):
+ """Object which performs caching of method calls for its 'primary'
+ instance."""
+
+ def __init__(self):
+ pass
+
+def Dump(title=None):
+ if title:
+ print title
+ CounterList.sort()
+ for counter in CounterList:
+ counter.display()
+
+class Memoized_Metaclass(type):
+ def __init__(cls, name, bases, cls_dict):
+ super(Memoized_Metaclass, cls).__init__(name, bases, cls_dict)
+
+ for counter in cls_dict.get('memoizer_counters', []):
+ method_name = counter.method_name
+
+ counter.name = cls.__name__ + '.' + method_name
+ counter.underlying_method = cls_dict[method_name]
+
+ replacement_method = types.MethodType(counter, None, cls)
+ setattr(cls, method_name, replacement_method)
+
+def EnableMemoization():
+ global use_memoizer
+ use_memoizer = 1
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Node/Alias.py b/couchjs/scons/scons-local-2.0.1/SCons/Node/Alias.py
new file mode 100644
index 00000000..c0f3ecee
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Node/Alias.py
@@ -0,0 +1,152 @@
+
+"""scons.Node.Alias
+
+Alias nodes.
+
+This creates a hash of global Aliases (dummy targets).
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Node/Alias.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import collections
+
+import SCons.Errors
+import SCons.Node
+import SCons.Util
+
+class AliasNameSpace(collections.UserDict):
+ def Alias(self, name, **kw):
+ if isinstance(name, SCons.Node.Alias.Alias):
+ return name
+ try:
+ a = self[name]
+ except KeyError:
+ a = SCons.Node.Alias.Alias(name, **kw)
+ self[name] = a
+ return a
+
+ def lookup(self, name, **kw):
+ try:
+ return self[name]
+ except KeyError:
+ return None
+
+class AliasNodeInfo(SCons.Node.NodeInfoBase):
+ current_version_id = 1
+ field_list = ['csig']
+ def str_to_node(self, s):
+ return default_ans.Alias(s)
+
+class AliasBuildInfo(SCons.Node.BuildInfoBase):
+ current_version_id = 1
+
+class Alias(SCons.Node.Node):
+
+ NodeInfo = AliasNodeInfo
+ BuildInfo = AliasBuildInfo
+
+ def __init__(self, name):
+ SCons.Node.Node.__init__(self)
+ self.name = name
+
+ def str_for_display(self):
+ return '"' + self.__str__() + '"'
+
+ def __str__(self):
+ return self.name
+
+ def make_ready(self):
+ self.get_csig()
+
+ really_build = SCons.Node.Node.build
+ is_up_to_date = SCons.Node.Node.children_are_up_to_date
+
+ def is_under(self, dir):
+ # Make Alias nodes get built regardless of
+ # what directory scons was run from. Alias nodes
+ # are outside the filesystem:
+ return 1
+
+ def get_contents(self):
+ """The contents of an alias is the concatenation
+ of the content signatures of all its sources."""
+ childsigs = [n.get_csig() for n in self.children()]
+ return ''.join(childsigs)
+
+ def sconsign(self):
+ """An Alias is not recorded in .sconsign files"""
+ pass
+
+ #
+ #
+ #
+
+ def changed_since_last_build(self, target, prev_ni):
+ cur_csig = self.get_csig()
+ try:
+ return cur_csig != prev_ni.csig
+ except AttributeError:
+ return 1
+
+ def build(self):
+ """A "builder" for aliases."""
+ pass
+
+ def convert(self):
+ try: del self.builder
+ except AttributeError: pass
+ self.reset_executor()
+ self.build = self.really_build
+
+ def get_csig(self):
+ """
+ Generate a node's content signature, the digested signature
+ of its content.
+
+ node - the node
+ cache - alternate node to use for the signature cache
+ returns - the content signature
+ """
+ try:
+ return self.ninfo.csig
+ except AttributeError:
+ pass
+
+ contents = self.get_contents()
+ csig = SCons.Util.MD5signature(contents)
+ self.get_ninfo().csig = csig
+ return csig
+
+default_ans = AliasNameSpace()
+
+SCons.Node.arg2nodes_lookups.append(default_ans.lookup)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Node/FS.py b/couchjs/scons/scons-local-2.0.1/SCons/Node/FS.py
new file mode 100644
index 00000000..0997fc07
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Node/FS.py
@@ -0,0 +1,3142 @@
+"""scons.Node.FS
+
+File system nodes.
+
+These Nodes represent the canonical external objects that people think
+of when they think of building software: files and directories.
+
+This holds a "default_fs" variable that should be initialized with an FS
+that can be used by scripts or modules looking for the canonical default.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Node/FS.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import fnmatch
+import os
+import re
+import shutil
+import stat
+import sys
+import time
+import codecs
+
+import SCons.Action
+from SCons.Debug import logInstanceCreation
+import SCons.Errors
+import SCons.Memoize
+import SCons.Node
+import SCons.Node.Alias
+import SCons.Subst
+import SCons.Util
+import SCons.Warnings
+
+from SCons.Debug import Trace
+
+do_store_info = True
+
+
+class EntryProxyAttributeError(AttributeError):
+ """
+ An AttributeError subclass for recording and displaying the name
+ of the underlying Entry involved in an AttributeError exception.
+ """
+ def __init__(self, entry_proxy, attribute):
+ AttributeError.__init__(self)
+ self.entry_proxy = entry_proxy
+ self.attribute = attribute
+ def __str__(self):
+ entry = self.entry_proxy.get()
+ fmt = "%s instance %s has no attribute %s"
+ return fmt % (entry.__class__.__name__,
+ repr(entry.name),
+ repr(self.attribute))
+
+# The max_drift value: by default, use a cached signature value for
+# any file that's been untouched for more than two days.
+default_max_drift = 2*24*60*60
+
+#
+# We stringify these file system Nodes a lot. Turning a file system Node
+# into a string is non-trivial, because the final string representation
+# can depend on a lot of factors: whether it's a derived target or not,
+# whether it's linked to a repository or source directory, and whether
+# there's duplication going on. The normal technique for optimizing
+# calculations like this is to memoize (cache) the string value, so you
+# only have to do the calculation once.
+#
+# A number of the above factors, however, can be set after we've already
+# been asked to return a string for a Node, because a Repository() or
+# VariantDir() call or the like may not occur until later in SConscript
+# files. So this variable controls whether we bother trying to save
+# string values for Nodes. The wrapper interface can set this whenever
+# they're done mucking with Repository and VariantDir and the other stuff,
+# to let this module know it can start returning saved string values
+# for Nodes.
+#
+Save_Strings = None
+
+def save_strings(val):
+ global Save_Strings
+ Save_Strings = val
+
+#
+# Avoid unnecessary function calls by recording a Boolean value that
+# tells us whether or not os.path.splitdrive() actually does anything
+# on this system, and therefore whether we need to bother calling it
+# when looking up path names in various methods below.
+#
+
+do_splitdrive = None
+
+def initialize_do_splitdrive():
+ global do_splitdrive
+ drive, path = os.path.splitdrive('X:/foo')
+ do_splitdrive = not not drive
+
+initialize_do_splitdrive()
+
+#
+
+needs_normpath_check = None
+
+def initialize_normpath_check():
+ """
+ Initialize the normpath_check regular expression.
+
+ This function is used by the unit tests to re-initialize the pattern
+ when testing for behavior with different values of os.sep.
+ """
+ global needs_normpath_check
+ if os.sep == '/':
+ pattern = r'.*/|\.$|\.\.$'
+ else:
+ pattern = r'.*[/%s]|\.$|\.\.$' % re.escape(os.sep)
+ needs_normpath_check = re.compile(pattern)
+
+initialize_normpath_check()
+
+#
+# SCons.Action objects for interacting with the outside world.
+#
+# The Node.FS methods in this module should use these actions to
+# create and/or remove files and directories; they should *not* use
+# os.{link,symlink,unlink,mkdir}(), etc., directly.
+#
+# Using these SCons.Action objects ensures that descriptions of these
+# external activities are properly displayed, that the displays are
+# suppressed when the -s (silent) option is used, and (most importantly)
+# the actions are disabled when the the -n option is used, in which case
+# there should be *no* changes to the external file system(s)...
+#
+
+if hasattr(os, 'link'):
+ def _hardlink_func(fs, src, dst):
+ # If the source is a symlink, we can't just hard-link to it
+ # because a relative symlink may point somewhere completely
+ # different. We must disambiguate the symlink and then
+ # hard-link the final destination file.
+ while fs.islink(src):
+ link = fs.readlink(src)
+ if not os.path.isabs(link):
+ src = link
+ else:
+ src = os.path.join(os.path.dirname(src), link)
+ fs.link(src, dst)
+else:
+ _hardlink_func = None
+
+if hasattr(os, 'symlink'):
+ def _softlink_func(fs, src, dst):
+ fs.symlink(src, dst)
+else:
+ _softlink_func = None
+
+def _copy_func(fs, src, dest):
+ shutil.copy2(src, dest)
+ st = fs.stat(src)
+ fs.chmod(dest, stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)
+
+
+Valid_Duplicates = ['hard-soft-copy', 'soft-hard-copy',
+ 'hard-copy', 'soft-copy', 'copy']
+
+Link_Funcs = [] # contains the callables of the specified duplication style
+
+def set_duplicate(duplicate):
+ # Fill in the Link_Funcs list according to the argument
+ # (discarding those not available on the platform).
+
+ # Set up the dictionary that maps the argument names to the
+ # underlying implementations. We do this inside this function,
+ # not in the top-level module code, so that we can remap os.link
+ # and os.symlink for testing purposes.
+ link_dict = {
+ 'hard' : _hardlink_func,
+ 'soft' : _softlink_func,
+ 'copy' : _copy_func
+ }
+
+ if not duplicate in Valid_Duplicates:
+ raise SCons.Errors.InternalError("The argument of set_duplicate "
+ "should be in Valid_Duplicates")
+ global Link_Funcs
+ Link_Funcs = []
+ for func in duplicate.split('-'):
+ if link_dict[func]:
+ Link_Funcs.append(link_dict[func])
+
+def LinkFunc(target, source, env):
+ # Relative paths cause problems with symbolic links, so
+ # we use absolute paths, which may be a problem for people
+ # who want to move their soft-linked src-trees around. Those
+ # people should use the 'hard-copy' mode, softlinks cannot be
+ # used for that; at least I have no idea how ...
+ src = source[0].abspath
+ dest = target[0].abspath
+ dir, file = os.path.split(dest)
+ if dir and not target[0].fs.isdir(dir):
+ os.makedirs(dir)
+ if not Link_Funcs:
+ # Set a default order of link functions.
+ set_duplicate('hard-soft-copy')
+ fs = source[0].fs
+ # Now link the files with the previously specified order.
+ for func in Link_Funcs:
+ try:
+ func(fs, src, dest)
+ break
+ except (IOError, OSError):
+ # An OSError indicates something happened like a permissions
+ # problem or an attempt to symlink across file-system
+ # boundaries. An IOError indicates something like the file
+ # not existing. In either case, keeping trying additional
+ # functions in the list and only raise an error if the last
+ # one failed.
+ if func == Link_Funcs[-1]:
+ # exception of the last link method (copy) are fatal
+ raise
+ return 0
+
+Link = SCons.Action.Action(LinkFunc, None)
+def LocalString(target, source, env):
+ return 'Local copy of %s from %s' % (target[0], source[0])
+
+LocalCopy = SCons.Action.Action(LinkFunc, LocalString)
+
+def UnlinkFunc(target, source, env):
+ t = target[0]
+ t.fs.unlink(t.abspath)
+ return 0
+
+Unlink = SCons.Action.Action(UnlinkFunc, None)
+
+def MkdirFunc(target, source, env):
+ t = target[0]
+ if not t.exists():
+ t.fs.mkdir(t.abspath)
+ return 0
+
+Mkdir = SCons.Action.Action(MkdirFunc, None, presub=None)
+
+MkdirBuilder = None
+
+def get_MkdirBuilder():
+ global MkdirBuilder
+ if MkdirBuilder is None:
+ import SCons.Builder
+ import SCons.Defaults
+ # "env" will get filled in by Executor.get_build_env()
+ # calling SCons.Defaults.DefaultEnvironment() when necessary.
+ MkdirBuilder = SCons.Builder.Builder(action = Mkdir,
+ env = None,
+ explain = None,
+ is_explicit = None,
+ target_scanner = SCons.Defaults.DirEntryScanner,
+ name = "MkdirBuilder")
+ return MkdirBuilder
+
+class _Null(object):
+ pass
+
+_null = _Null()
+
+DefaultSCCSBuilder = None
+DefaultRCSBuilder = None
+
+def get_DefaultSCCSBuilder():
+ global DefaultSCCSBuilder
+ if DefaultSCCSBuilder is None:
+ import SCons.Builder
+ # "env" will get filled in by Executor.get_build_env()
+ # calling SCons.Defaults.DefaultEnvironment() when necessary.
+ act = SCons.Action.Action('$SCCSCOM', '$SCCSCOMSTR')
+ DefaultSCCSBuilder = SCons.Builder.Builder(action = act,
+ env = None,
+ name = "DefaultSCCSBuilder")
+ return DefaultSCCSBuilder
+
+def get_DefaultRCSBuilder():
+ global DefaultRCSBuilder
+ if DefaultRCSBuilder is None:
+ import SCons.Builder
+ # "env" will get filled in by Executor.get_build_env()
+ # calling SCons.Defaults.DefaultEnvironment() when necessary.
+ act = SCons.Action.Action('$RCS_COCOM', '$RCS_COCOMSTR')
+ DefaultRCSBuilder = SCons.Builder.Builder(action = act,
+ env = None,
+ name = "DefaultRCSBuilder")
+ return DefaultRCSBuilder
+
+# Cygwin's os.path.normcase pretends it's on a case-sensitive filesystem.
+_is_cygwin = sys.platform == "cygwin"
+if os.path.normcase("TeSt") == os.path.normpath("TeSt") and not _is_cygwin:
+ def _my_normcase(x):
+ return x
+else:
+ def _my_normcase(x):
+ return x.upper()
+
+
+
+class DiskChecker(object):
+ def __init__(self, type, do, ignore):
+ self.type = type
+ self.do = do
+ self.ignore = ignore
+ self.func = do
+ def __call__(self, *args, **kw):
+ return self.func(*args, **kw)
+ def set(self, list):
+ if self.type in list:
+ self.func = self.do
+ else:
+ self.func = self.ignore
+
+def do_diskcheck_match(node, predicate, errorfmt):
+ result = predicate()
+ try:
+ # If calling the predicate() cached a None value from stat(),
+ # remove it so it doesn't interfere with later attempts to
+ # build this Node as we walk the DAG. (This isn't a great way
+ # to do this, we're reaching into an interface that doesn't
+ # really belong to us, but it's all about performance, so
+ # for now we'll just document the dependency...)
+ if node._memo['stat'] is None:
+ del node._memo['stat']
+ except (AttributeError, KeyError):
+ pass
+ if result:
+ raise TypeError(errorfmt % node.abspath)
+
+def ignore_diskcheck_match(node, predicate, errorfmt):
+ pass
+
+def do_diskcheck_rcs(node, name):
+ try:
+ rcs_dir = node.rcs_dir
+ except AttributeError:
+ if node.entry_exists_on_disk('RCS'):
+ rcs_dir = node.Dir('RCS')
+ else:
+ rcs_dir = None
+ node.rcs_dir = rcs_dir
+ if rcs_dir:
+ return rcs_dir.entry_exists_on_disk(name+',v')
+ return None
+
+def ignore_diskcheck_rcs(node, name):
+ return None
+
+def do_diskcheck_sccs(node, name):
+ try:
+ sccs_dir = node.sccs_dir
+ except AttributeError:
+ if node.entry_exists_on_disk('SCCS'):
+ sccs_dir = node.Dir('SCCS')
+ else:
+ sccs_dir = None
+ node.sccs_dir = sccs_dir
+ if sccs_dir:
+ return sccs_dir.entry_exists_on_disk('s.'+name)
+ return None
+
+def ignore_diskcheck_sccs(node, name):
+ return None
+
+diskcheck_match = DiskChecker('match', do_diskcheck_match, ignore_diskcheck_match)
+diskcheck_rcs = DiskChecker('rcs', do_diskcheck_rcs, ignore_diskcheck_rcs)
+diskcheck_sccs = DiskChecker('sccs', do_diskcheck_sccs, ignore_diskcheck_sccs)
+
+diskcheckers = [
+ diskcheck_match,
+ diskcheck_rcs,
+ diskcheck_sccs,
+]
+
+def set_diskcheck(list):
+ for dc in diskcheckers:
+ dc.set(list)
+
+def diskcheck_types():
+ return [dc.type for dc in diskcheckers]
+
+
+
+class EntryProxy(SCons.Util.Proxy):
+
+ __str__ = SCons.Util.Delegate('__str__')
+
+ def __get_abspath(self):
+ entry = self.get()
+ return SCons.Subst.SpecialAttrWrapper(entry.get_abspath(),
+ entry.name + "_abspath")
+
+ def __get_filebase(self):
+ name = self.get().name
+ return SCons.Subst.SpecialAttrWrapper(SCons.Util.splitext(name)[0],
+ name + "_filebase")
+
+ def __get_suffix(self):
+ name = self.get().name
+ return SCons.Subst.SpecialAttrWrapper(SCons.Util.splitext(name)[1],
+ name + "_suffix")
+
+ def __get_file(self):
+ name = self.get().name
+ return SCons.Subst.SpecialAttrWrapper(name, name + "_file")
+
+ def __get_base_path(self):
+ """Return the file's directory and file name, with the
+ suffix stripped."""
+ entry = self.get()
+ return SCons.Subst.SpecialAttrWrapper(SCons.Util.splitext(entry.get_path())[0],
+ entry.name + "_base")
+
+ def __get_posix_path(self):
+ """Return the path with / as the path separator,
+ regardless of platform."""
+ if os.sep == '/':
+ return self
+ else:
+ entry = self.get()
+ r = entry.get_path().replace(os.sep, '/')
+ return SCons.Subst.SpecialAttrWrapper(r, entry.name + "_posix")
+
+ def __get_windows_path(self):
+ """Return the path with \ as the path separator,
+ regardless of platform."""
+ if os.sep == '\\':
+ return self
+ else:
+ entry = self.get()
+ r = entry.get_path().replace(os.sep, '\\')
+ return SCons.Subst.SpecialAttrWrapper(r, entry.name + "_windows")
+
+ def __get_srcnode(self):
+ return EntryProxy(self.get().srcnode())
+
+ def __get_srcdir(self):
+ """Returns the directory containing the source node linked to this
+ node via VariantDir(), or the directory of this node if not linked."""
+ return EntryProxy(self.get().srcnode().dir)
+
+ def __get_rsrcnode(self):
+ return EntryProxy(self.get().srcnode().rfile())
+
+ def __get_rsrcdir(self):
+ """Returns the directory containing the source node linked to this
+ node via VariantDir(), or the directory of this node if not linked."""
+ return EntryProxy(self.get().srcnode().rfile().dir)
+
+ def __get_dir(self):
+ return EntryProxy(self.get().dir)
+
+ dictSpecialAttrs = { "base" : __get_base_path,
+ "posix" : __get_posix_path,
+ "windows" : __get_windows_path,
+ "win32" : __get_windows_path,
+ "srcpath" : __get_srcnode,
+ "srcdir" : __get_srcdir,
+ "dir" : __get_dir,
+ "abspath" : __get_abspath,
+ "filebase" : __get_filebase,
+ "suffix" : __get_suffix,
+ "file" : __get_file,
+ "rsrcpath" : __get_rsrcnode,
+ "rsrcdir" : __get_rsrcdir,
+ }
+
+ def __getattr__(self, name):
+ # This is how we implement the "special" attributes
+ # such as base, posix, srcdir, etc.
+ try:
+ attr_function = self.dictSpecialAttrs[name]
+ except KeyError:
+ try:
+ attr = SCons.Util.Proxy.__getattr__(self, name)
+ except AttributeError, e:
+ # Raise our own AttributeError subclass with an
+ # overridden __str__() method that identifies the
+ # name of the entry that caused the exception.
+ raise EntryProxyAttributeError(self, name)
+ return attr
+ else:
+ return attr_function(self)
+
+class Base(SCons.Node.Node):
+ """A generic class for file system entries. This class is for
+ when we don't know yet whether the entry being looked up is a file
+ or a directory. Instances of this class can morph into either
+ Dir or File objects by a later, more precise lookup.
+
+ Note: this class does not define __cmp__ and __hash__ for
+ efficiency reasons. SCons does a lot of comparing of
+ Node.FS.{Base,Entry,File,Dir} objects, so those operations must be
+ as fast as possible, which means we want to use Python's built-in
+ object identity comparisons.
+ """
+
+ memoizer_counters = []
+
+ def __init__(self, name, directory, fs):
+ """Initialize a generic Node.FS.Base object.
+
+ Call the superclass initialization, take care of setting up
+ our relative and absolute paths, identify our parent
+ directory, and indicate that this node should use
+ signatures."""
+ if __debug__: logInstanceCreation(self, 'Node.FS.Base')
+ SCons.Node.Node.__init__(self)
+
+ # Filenames and paths are probably reused and are intern'ed to
+ # save some memory.
+ self.name = SCons.Util.silent_intern(name)
+ self.suffix = SCons.Util.silent_intern(SCons.Util.splitext(name)[1])
+ self.fs = fs
+
+ assert directory, "A directory must be provided"
+
+ self.abspath = SCons.Util.silent_intern(directory.entry_abspath(name))
+ self.labspath = SCons.Util.silent_intern(directory.entry_labspath(name))
+ if directory.path == '.':
+ self.path = SCons.Util.silent_intern(name)
+ else:
+ self.path = SCons.Util.silent_intern(directory.entry_path(name))
+ if directory.tpath == '.':
+ self.tpath = SCons.Util.silent_intern(name)
+ else:
+ self.tpath = SCons.Util.silent_intern(directory.entry_tpath(name))
+ self.path_elements = directory.path_elements + [self]
+
+ self.dir = directory
+ self.cwd = None # will hold the SConscript directory for target nodes
+ self.duplicate = directory.duplicate
+
+ def str_for_display(self):
+ return '"' + self.__str__() + '"'
+
+ def must_be_same(self, klass):
+ """
+ This node, which already existed, is being looked up as the
+ specified klass. Raise an exception if it isn't.
+ """
+ if isinstance(self, klass) or klass is Entry:
+ return
+ raise TypeError("Tried to lookup %s '%s' as a %s." %\
+ (self.__class__.__name__, self.path, klass.__name__))
+
+ def get_dir(self):
+ return self.dir
+
+ def get_suffix(self):
+ return self.suffix
+
+ def rfile(self):
+ return self
+
+ def __str__(self):
+ """A Node.FS.Base object's string representation is its path
+ name."""
+ global Save_Strings
+ if Save_Strings:
+ return self._save_str()
+ return self._get_str()
+
+ memoizer_counters.append(SCons.Memoize.CountValue('_save_str'))
+
+ def _save_str(self):
+ try:
+ return self._memo['_save_str']
+ except KeyError:
+ pass
+ result = sys.intern(self._get_str())
+ self._memo['_save_str'] = result
+ return result
+
+ def _get_str(self):
+ global Save_Strings
+ if self.duplicate or self.is_derived():
+ return self.get_path()
+ srcnode = self.srcnode()
+ if srcnode.stat() is None and self.stat() is not None:
+ result = self.get_path()
+ else:
+ result = srcnode.get_path()
+ if not Save_Strings:
+ # We're not at the point where we're saving the string string
+ # representations of FS Nodes (because we haven't finished
+ # reading the SConscript files and need to have str() return
+ # things relative to them). That also means we can't yet
+ # cache values returned (or not returned) by stat(), since
+ # Python code in the SConscript files might still create
+ # or otherwise affect the on-disk file. So get rid of the
+ # values that the underlying stat() method saved.
+ try: del self._memo['stat']
+ except KeyError: pass
+ if self is not srcnode:
+ try: del srcnode._memo['stat']
+ except KeyError: pass
+ return result
+
+ rstr = __str__
+
+ memoizer_counters.append(SCons.Memoize.CountValue('stat'))
+
+ def stat(self):
+ try: return self._memo['stat']
+ except KeyError: pass
+ try: result = self.fs.stat(self.abspath)
+ except os.error: result = None
+ self._memo['stat'] = result
+ return result
+
+ def exists(self):
+ return self.stat() is not None
+
+ def rexists(self):
+ return self.rfile().exists()
+
+ def getmtime(self):
+ st = self.stat()
+ if st: return st[stat.ST_MTIME]
+ else: return None
+
+ def getsize(self):
+ st = self.stat()
+ if st: return st[stat.ST_SIZE]
+ else: return None
+
+ def isdir(self):
+ st = self.stat()
+ return st is not None and stat.S_ISDIR(st[stat.ST_MODE])
+
+ def isfile(self):
+ st = self.stat()
+ return st is not None and stat.S_ISREG(st[stat.ST_MODE])
+
+ if hasattr(os, 'symlink'):
+ def islink(self):
+ try: st = self.fs.lstat(self.abspath)
+ except os.error: return 0
+ return stat.S_ISLNK(st[stat.ST_MODE])
+ else:
+ def islink(self):
+ return 0 # no symlinks
+
+ def is_under(self, dir):
+ if self is dir:
+ return 1
+ else:
+ return self.dir.is_under(dir)
+
+ def set_local(self):
+ self._local = 1
+
+ def srcnode(self):
+ """If this node is in a build path, return the node
+ corresponding to its source file. Otherwise, return
+ ourself.
+ """
+ srcdir_list = self.dir.srcdir_list()
+ if srcdir_list:
+ srcnode = srcdir_list[0].Entry(self.name)
+ srcnode.must_be_same(self.__class__)
+ return srcnode
+ return self
+
+ def get_path(self, dir=None):
+ """Return path relative to the current working directory of the
+ Node.FS.Base object that owns us."""
+ if not dir:
+ dir = self.fs.getcwd()
+ if self == dir:
+ return '.'
+ path_elems = self.path_elements
+ try: i = path_elems.index(dir)
+ except ValueError: pass
+ else: path_elems = path_elems[i+1:]
+ path_elems = [n.name for n in path_elems]
+ return os.sep.join(path_elems)
+
+ def set_src_builder(self, builder):
+ """Set the source code builder for this node."""
+ self.sbuilder = builder
+ if not self.has_builder():
+ self.builder_set(builder)
+
+ def src_builder(self):
+ """Fetch the source code builder for this node.
+
+ If there isn't one, we cache the source code builder specified
+ for the directory (which in turn will cache the value from its
+ parent directory, and so on up to the file system root).
+ """
+ try:
+ scb = self.sbuilder
+ except AttributeError:
+ scb = self.dir.src_builder()
+ self.sbuilder = scb
+ return scb
+
+ def get_abspath(self):
+ """Get the absolute path of the file."""
+ return self.abspath
+
+ def for_signature(self):
+ # Return just our name. Even an absolute path would not work,
+ # because that can change thanks to symlinks or remapped network
+ # paths.
+ return self.name
+
+ def get_subst_proxy(self):
+ try:
+ return self._proxy
+ except AttributeError:
+ ret = EntryProxy(self)
+ self._proxy = ret
+ return ret
+
+ def target_from_source(self, prefix, suffix, splitext=SCons.Util.splitext):
+ """
+
+ Generates a target entry that corresponds to this entry (usually
+ a source file) with the specified prefix and suffix.
+
+ Note that this method can be overridden dynamically for generated
+ files that need different behavior. See Tool/swig.py for
+ an example.
+ """
+ return self.dir.Entry(prefix + splitext(self.name)[0] + suffix)
+
+ def _Rfindalldirs_key(self, pathlist):
+ return pathlist
+
+ memoizer_counters.append(SCons.Memoize.CountDict('Rfindalldirs', _Rfindalldirs_key))
+
+ def Rfindalldirs(self, pathlist):
+ """
+ Return all of the directories for a given path list, including
+ corresponding "backing" directories in any repositories.
+
+ The Node lookups are relative to this Node (typically a
+ directory), so memoizing result saves cycles from looking
+ up the same path for each target in a given directory.
+ """
+ try:
+ memo_dict = self._memo['Rfindalldirs']
+ except KeyError:
+ memo_dict = {}
+ self._memo['Rfindalldirs'] = memo_dict
+ else:
+ try:
+ return memo_dict[pathlist]
+ except KeyError:
+ pass
+
+ create_dir_relative_to_self = self.Dir
+ result = []
+ for path in pathlist:
+ if isinstance(path, SCons.Node.Node):
+ result.append(path)
+ else:
+ dir = create_dir_relative_to_self(path)
+ result.extend(dir.get_all_rdirs())
+
+ memo_dict[pathlist] = result
+
+ return result
+
+ def RDirs(self, pathlist):
+ """Search for a list of directories in the Repository list."""
+ cwd = self.cwd or self.fs._cwd
+ return cwd.Rfindalldirs(pathlist)
+
+ memoizer_counters.append(SCons.Memoize.CountValue('rentry'))
+
+ def rentry(self):
+ try:
+ return self._memo['rentry']
+ except KeyError:
+ pass
+ result = self
+ if not self.exists():
+ norm_name = _my_normcase(self.name)
+ for dir in self.dir.get_all_rdirs():
+ try:
+ node = dir.entries[norm_name]
+ except KeyError:
+ if dir.entry_exists_on_disk(self.name):
+ result = dir.Entry(self.name)
+ break
+ self._memo['rentry'] = result
+ return result
+
+ def _glob1(self, pattern, ondisk=True, source=False, strings=False):
+ return []
+
+class Entry(Base):
+ """This is the class for generic Node.FS entries--that is, things
+ that could be a File or a Dir, but we're just not sure yet.
+ Consequently, the methods in this class really exist just to
+ transform their associated object into the right class when the
+ time comes, and then call the same-named method in the transformed
+ class."""
+
+ def diskcheck_match(self):
+ pass
+
+ def disambiguate(self, must_exist=None):
+ """
+ """
+ if self.isdir():
+ self.__class__ = Dir
+ self._morph()
+ elif self.isfile():
+ self.__class__ = File
+ self._morph()
+ self.clear()
+ else:
+ # There was nothing on-disk at this location, so look in
+ # the src directory.
+ #
+ # We can't just use self.srcnode() straight away because
+ # that would create an actual Node for this file in the src
+ # directory, and there might not be one. Instead, use the
+ # dir_on_disk() method to see if there's something on-disk
+ # with that name, in which case we can go ahead and call
+ # self.srcnode() to create the right type of entry.
+ srcdir = self.dir.srcnode()
+ if srcdir != self.dir and \
+ srcdir.entry_exists_on_disk(self.name) and \
+ self.srcnode().isdir():
+ self.__class__ = Dir
+ self._morph()
+ elif must_exist:
+ msg = "No such file or directory: '%s'" % self.abspath
+ raise SCons.Errors.UserError(msg)
+ else:
+ self.__class__ = File
+ self._morph()
+ self.clear()
+ return self
+
+ def rfile(self):
+ """We're a generic Entry, but the caller is actually looking for
+ a File at this point, so morph into one."""
+ self.__class__ = File
+ self._morph()
+ self.clear()
+ return File.rfile(self)
+
+ def scanner_key(self):
+ return self.get_suffix()
+
+ def get_contents(self):
+ """Fetch the contents of the entry. Returns the exact binary
+ contents of the file."""
+ try:
+ self = self.disambiguate(must_exist=1)
+ except SCons.Errors.UserError:
+ # There was nothing on disk with which to disambiguate
+ # this entry. Leave it as an Entry, but return a null
+ # string so calls to get_contents() in emitters and the
+ # like (e.g. in qt.py) don't have to disambiguate by hand
+ # or catch the exception.
+ return ''
+ else:
+ return self.get_contents()
+
+ def get_text_contents(self):
+ """Fetch the decoded text contents of a Unicode encoded Entry.
+
+ Since this should return the text contents from the file
+ system, we check to see into what sort of subclass we should
+ morph this Entry."""
+ try:
+ self = self.disambiguate(must_exist=1)
+ except SCons.Errors.UserError:
+ # There was nothing on disk with which to disambiguate
+ # this entry. Leave it as an Entry, but return a null
+ # string so calls to get_text_contents() in emitters and
+ # the like (e.g. in qt.py) don't have to disambiguate by
+ # hand or catch the exception.
+ return ''
+ else:
+ return self.get_text_contents()
+
+ def must_be_same(self, klass):
+ """Called to make sure a Node is a Dir. Since we're an
+ Entry, we can morph into one."""
+ if self.__class__ is not klass:
+ self.__class__ = klass
+ self._morph()
+ self.clear()
+
+ # The following methods can get called before the Taskmaster has
+ # had a chance to call disambiguate() directly to see if this Entry
+ # should really be a Dir or a File. We therefore use these to call
+ # disambiguate() transparently (from our caller's point of view).
+ #
+ # Right now, this minimal set of methods has been derived by just
+ # looking at some of the methods that will obviously be called early
+ # in any of the various Taskmasters' calling sequences, and then
+ # empirically figuring out which additional methods are necessary
+ # to make various tests pass.
+
+ def exists(self):
+ """Return if the Entry exists. Check the file system to see
+ what we should turn into first. Assume a file if there's no
+ directory."""
+ return self.disambiguate().exists()
+
+ def rel_path(self, other):
+ d = self.disambiguate()
+ if d.__class__ is Entry:
+ raise Exception("rel_path() could not disambiguate File/Dir")
+ return d.rel_path(other)
+
+ def new_ninfo(self):
+ return self.disambiguate().new_ninfo()
+
+ def changed_since_last_build(self, target, prev_ni):
+ return self.disambiguate().changed_since_last_build(target, prev_ni)
+
+ def _glob1(self, pattern, ondisk=True, source=False, strings=False):
+ return self.disambiguate()._glob1(pattern, ondisk, source, strings)
+
+ def get_subst_proxy(self):
+ return self.disambiguate().get_subst_proxy()
+
+# This is for later so we can differentiate between Entry the class and Entry
+# the method of the FS class.
+_classEntry = Entry
+
+
+class LocalFS(object):
+
+ if SCons.Memoize.use_memoizer:
+ __metaclass__ = SCons.Memoize.Memoized_Metaclass
+
+ # This class implements an abstraction layer for operations involving
+ # a local file system. Essentially, this wraps any function in
+ # the os, os.path or shutil modules that we use to actually go do
+ # anything with or to the local file system.
+ #
+ # Note that there's a very good chance we'll refactor this part of
+ # the architecture in some way as we really implement the interface(s)
+ # for remote file system Nodes. For example, the right architecture
+ # might be to have this be a subclass instead of a base class.
+ # Nevertheless, we're using this as a first step in that direction.
+ #
+ # We're not using chdir() yet because the calling subclass method
+ # needs to use os.chdir() directly to avoid recursion. Will we
+ # really need this one?
+ #def chdir(self, path):
+ # return os.chdir(path)
+ def chmod(self, path, mode):
+ return os.chmod(path, mode)
+ def copy(self, src, dst):
+ return shutil.copy(src, dst)
+ def copy2(self, src, dst):
+ return shutil.copy2(src, dst)
+ def exists(self, path):
+ return os.path.exists(path)
+ def getmtime(self, path):
+ return os.path.getmtime(path)
+ def getsize(self, path):
+ return os.path.getsize(path)
+ def isdir(self, path):
+ return os.path.isdir(path)
+ def isfile(self, path):
+ return os.path.isfile(path)
+ def link(self, src, dst):
+ return os.link(src, dst)
+ def lstat(self, path):
+ return os.lstat(path)
+ def listdir(self, path):
+ return os.listdir(path)
+ def makedirs(self, path):
+ return os.makedirs(path)
+ def mkdir(self, path):
+ return os.mkdir(path)
+ def rename(self, old, new):
+ return os.rename(old, new)
+ def stat(self, path):
+ return os.stat(path)
+ def symlink(self, src, dst):
+ return os.symlink(src, dst)
+ def open(self, path):
+ return open(path)
+ def unlink(self, path):
+ return os.unlink(path)
+
+ if hasattr(os, 'symlink'):
+ def islink(self, path):
+ return os.path.islink(path)
+ else:
+ def islink(self, path):
+ return 0 # no symlinks
+
+ if hasattr(os, 'readlink'):
+ def readlink(self, file):
+ return os.readlink(file)
+ else:
+ def readlink(self, file):
+ return ''
+
+
+#class RemoteFS:
+# # Skeleton for the obvious methods we might need from the
+# # abstraction layer for a remote filesystem.
+# def upload(self, local_src, remote_dst):
+# pass
+# def download(self, remote_src, local_dst):
+# pass
+
+
+class FS(LocalFS):
+
+ memoizer_counters = []
+
+ def __init__(self, path = None):
+ """Initialize the Node.FS subsystem.
+
+ The supplied path is the top of the source tree, where we
+ expect to find the top-level build file. If no path is
+ supplied, the current directory is the default.
+
+ The path argument must be a valid absolute path.
+ """
+ if __debug__: logInstanceCreation(self, 'Node.FS')
+
+ self._memo = {}
+
+ self.Root = {}
+ self.SConstruct_dir = None
+ self.max_drift = default_max_drift
+
+ self.Top = None
+ if path is None:
+ self.pathTop = os.getcwd()
+ else:
+ self.pathTop = path
+ self.defaultDrive = _my_normcase(os.path.splitdrive(self.pathTop)[0])
+
+ self.Top = self.Dir(self.pathTop)
+ self.Top.path = '.'
+ self.Top.tpath = '.'
+ self._cwd = self.Top
+
+ DirNodeInfo.fs = self
+ FileNodeInfo.fs = self
+
+ def set_SConstruct_dir(self, dir):
+ self.SConstruct_dir = dir
+
+ def get_max_drift(self):
+ return self.max_drift
+
+ def set_max_drift(self, max_drift):
+ self.max_drift = max_drift
+
+ def getcwd(self):
+ return self._cwd
+
+ def chdir(self, dir, change_os_dir=0):
+ """Change the current working directory for lookups.
+ If change_os_dir is true, we will also change the "real" cwd
+ to match.
+ """
+ curr=self._cwd
+ try:
+ if dir is not None:
+ self._cwd = dir
+ if change_os_dir:
+ os.chdir(dir.abspath)
+ except OSError:
+ self._cwd = curr
+ raise
+
+ def get_root(self, drive):
+ """
+ Returns the root directory for the specified drive, creating
+ it if necessary.
+ """
+ drive = _my_normcase(drive)
+ try:
+ return self.Root[drive]
+ except KeyError:
+ root = RootDir(drive, self)
+ self.Root[drive] = root
+ if not drive:
+ self.Root[self.defaultDrive] = root
+ elif drive == self.defaultDrive:
+ self.Root[''] = root
+ return root
+
+ def _lookup(self, p, directory, fsclass, create=1):
+ """
+ The generic entry point for Node lookup with user-supplied data.
+
+ This translates arbitrary input into a canonical Node.FS object
+ of the specified fsclass. The general approach for strings is
+ to turn it into a fully normalized absolute path and then call
+ the root directory's lookup_abs() method for the heavy lifting.
+
+ If the path name begins with '#', it is unconditionally
+ interpreted relative to the top-level directory of this FS. '#'
+ is treated as a synonym for the top-level SConstruct directory,
+ much like '~' is treated as a synonym for the user's home
+ directory in a UNIX shell. So both '#foo' and '#/foo' refer
+ to the 'foo' subdirectory underneath the top-level SConstruct
+ directory.
+
+ If the path name is relative, then the path is looked up relative
+ to the specified directory, or the current directory (self._cwd,
+ typically the SConscript directory) if the specified directory
+ is None.
+ """
+ if isinstance(p, Base):
+ # It's already a Node.FS object. Make sure it's the right
+ # class and return.
+ p.must_be_same(fsclass)
+ return p
+ # str(p) in case it's something like a proxy object
+ p = str(p)
+
+ initial_hash = (p[0:1] == '#')
+ if initial_hash:
+ # There was an initial '#', so we strip it and override
+ # whatever directory they may have specified with the
+ # top-level SConstruct directory.
+ p = p[1:]
+ directory = self.Top
+
+ if directory and not isinstance(directory, Dir):
+ directory = self.Dir(directory)
+
+ if do_splitdrive:
+ drive, p = os.path.splitdrive(p)
+ else:
+ drive = ''
+ if drive and not p:
+ # This causes a naked drive letter to be treated as a synonym
+ # for the root directory on that drive.
+ p = os.sep
+ absolute = os.path.isabs(p)
+
+ needs_normpath = needs_normpath_check.match(p)
+
+ if initial_hash or not absolute:
+ # This is a relative lookup, either to the top-level
+ # SConstruct directory (because of the initial '#') or to
+ # the current directory (the path name is not absolute).
+ # Add the string to the appropriate directory lookup path,
+ # after which the whole thing gets normalized.
+ if not directory:
+ directory = self._cwd
+ if p:
+ p = directory.labspath + '/' + p
+ else:
+ p = directory.labspath
+
+ if needs_normpath:
+ p = os.path.normpath(p)
+
+ if drive or absolute:
+ root = self.get_root(drive)
+ else:
+ if not directory:
+ directory = self._cwd
+ root = directory.root
+
+ if os.sep != '/':
+ p = p.replace(os.sep, '/')
+ return root._lookup_abs(p, fsclass, create)
+
+ def Entry(self, name, directory = None, create = 1):
+ """Look up or create a generic Entry node with the specified name.
+ If the name is a relative path (begins with ./, ../, or a file
+ name), then it is looked up relative to the supplied directory
+ node, or to the top level directory of the FS (supplied at
+ construction time) if no directory is supplied.
+ """
+ return self._lookup(name, directory, Entry, create)
+
+ def File(self, name, directory = None, create = 1):
+ """Look up or create a File node with the specified name. If
+ the name is a relative path (begins with ./, ../, or a file name),
+ then it is looked up relative to the supplied directory node,
+ or to the top level directory of the FS (supplied at construction
+ time) if no directory is supplied.
+
+ This method will raise TypeError if a directory is found at the
+ specified path.
+ """
+ return self._lookup(name, directory, File, create)
+
+ def Dir(self, name, directory = None, create = True):
+ """Look up or create a Dir node with the specified name. If
+ the name is a relative path (begins with ./, ../, or a file name),
+ then it is looked up relative to the supplied directory node,
+ or to the top level directory of the FS (supplied at construction
+ time) if no directory is supplied.
+
+ This method will raise TypeError if a normal file is found at the
+ specified path.
+ """
+ return self._lookup(name, directory, Dir, create)
+
+ def VariantDir(self, variant_dir, src_dir, duplicate=1):
+ """Link the supplied variant directory to the source directory
+ for purposes of building files."""
+
+ if not isinstance(src_dir, SCons.Node.Node):
+ src_dir = self.Dir(src_dir)
+ if not isinstance(variant_dir, SCons.Node.Node):
+ variant_dir = self.Dir(variant_dir)
+ if src_dir.is_under(variant_dir):
+ raise SCons.Errors.UserError("Source directory cannot be under variant directory.")
+ if variant_dir.srcdir:
+ if variant_dir.srcdir == src_dir:
+ return # We already did this.
+ raise SCons.Errors.UserError("'%s' already has a source directory: '%s'."%(variant_dir, variant_dir.srcdir))
+ variant_dir.link(src_dir, duplicate)
+
+ def Repository(self, *dirs):
+ """Specify Repository directories to search."""
+ for d in dirs:
+ if not isinstance(d, SCons.Node.Node):
+ d = self.Dir(d)
+ self.Top.addRepository(d)
+
+ def variant_dir_target_climb(self, orig, dir, tail):
+ """Create targets in corresponding variant directories
+
+ Climb the directory tree, and look up path names
+ relative to any linked variant directories we find.
+
+ Even though this loops and walks up the tree, we don't memoize
+ the return value because this is really only used to process
+ the command-line targets.
+ """
+ targets = []
+ message = None
+ fmt = "building associated VariantDir targets: %s"
+ start_dir = dir
+ while dir:
+ for bd in dir.variant_dirs:
+ if start_dir.is_under(bd):
+ # If already in the build-dir location, don't reflect
+ return [orig], fmt % str(orig)
+ p = os.path.join(bd.path, *tail)
+ targets.append(self.Entry(p))
+ tail = [dir.name] + tail
+ dir = dir.up()
+ if targets:
+ message = fmt % ' '.join(map(str, targets))
+ return targets, message
+
+ def Glob(self, pathname, ondisk=True, source=True, strings=False, cwd=None):
+ """
+ Globs
+
+ This is mainly a shim layer
+ """
+ if cwd is None:
+ cwd = self.getcwd()
+ return cwd.glob(pathname, ondisk, source, strings)
+
+class DirNodeInfo(SCons.Node.NodeInfoBase):
+ # This should get reset by the FS initialization.
+ current_version_id = 1
+
+ fs = None
+
+ def str_to_node(self, s):
+ top = self.fs.Top
+ root = top.root
+ if do_splitdrive:
+ drive, s = os.path.splitdrive(s)
+ if drive:
+ root = self.fs.get_root(drive)
+ if not os.path.isabs(s):
+ s = top.labspath + '/' + s
+ return root._lookup_abs(s, Entry)
+
+class DirBuildInfo(SCons.Node.BuildInfoBase):
+ current_version_id = 1
+
+glob_magic_check = re.compile('[*?[]')
+
+def has_glob_magic(s):
+ return glob_magic_check.search(s) is not None
+
+class Dir(Base):
+ """A class for directories in a file system.
+ """
+
+ memoizer_counters = []
+
+ NodeInfo = DirNodeInfo
+ BuildInfo = DirBuildInfo
+
+ def __init__(self, name, directory, fs):
+ if __debug__: logInstanceCreation(self, 'Node.FS.Dir')
+ Base.__init__(self, name, directory, fs)
+ self._morph()
+
+ def _morph(self):
+ """Turn a file system Node (either a freshly initialized directory
+ object or a separate Entry object) into a proper directory object.
+
+ Set up this directory's entries and hook it into the file
+ system tree. Specify that directories (this Node) don't use
+ signatures for calculating whether they're current.
+ """
+
+ self.repositories = []
+ self.srcdir = None
+
+ self.entries = {}
+ self.entries['.'] = self
+ self.entries['..'] = self.dir
+ self.cwd = self
+ self.searched = 0
+ self._sconsign = None
+ self.variant_dirs = []
+ self.root = self.dir.root
+
+ # Don't just reset the executor, replace its action list,
+ # because it might have some pre-or post-actions that need to
+ # be preserved.
+ self.builder = get_MkdirBuilder()
+ self.get_executor().set_action_list(self.builder.action)
+
+ def diskcheck_match(self):
+ diskcheck_match(self, self.isfile,
+ "File %s found where directory expected.")
+
+ def __clearRepositoryCache(self, duplicate=None):
+ """Called when we change the repository(ies) for a directory.
+ This clears any cached information that is invalidated by changing
+ the repository."""
+
+ for node in self.entries.values():
+ if node != self.dir:
+ if node != self and isinstance(node, Dir):
+ node.__clearRepositoryCache(duplicate)
+ else:
+ node.clear()
+ try:
+ del node._srcreps
+ except AttributeError:
+ pass
+ if duplicate is not None:
+ node.duplicate=duplicate
+
+ def __resetDuplicate(self, node):
+ if node != self:
+ node.duplicate = node.get_dir().duplicate
+
+ def Entry(self, name):
+ """
+ Looks up or creates an entry node named 'name' relative to
+ this directory.
+ """
+ return self.fs.Entry(name, self)
+
+ def Dir(self, name, create=True):
+ """
+ Looks up or creates a directory node named 'name' relative to
+ this directory.
+ """
+ return self.fs.Dir(name, self, create)
+
+ def File(self, name):
+ """
+ Looks up or creates a file node named 'name' relative to
+ this directory.
+ """
+ return self.fs.File(name, self)
+
+ def _lookup_rel(self, name, klass, create=1):
+ """
+ Looks up a *normalized* relative path name, relative to this
+ directory.
+
+ This method is intended for use by internal lookups with
+ already-normalized path data. For general-purpose lookups,
+ use the Entry(), Dir() and File() methods above.
+
+ This method does *no* input checking and will die or give
+ incorrect results if it's passed a non-normalized path name (e.g.,
+ a path containing '..'), an absolute path name, a top-relative
+ ('#foo') path name, or any kind of object.
+ """
+ name = self.entry_labspath(name)
+ return self.root._lookup_abs(name, klass, create)
+
+ def link(self, srcdir, duplicate):
+ """Set this directory as the variant directory for the
+ supplied source directory."""
+ self.srcdir = srcdir
+ self.duplicate = duplicate
+ self.__clearRepositoryCache(duplicate)
+ srcdir.variant_dirs.append(self)
+
+ def getRepositories(self):
+ """Returns a list of repositories for this directory.
+ """
+ if self.srcdir and not self.duplicate:
+ return self.srcdir.get_all_rdirs() + self.repositories
+ return self.repositories
+
+ memoizer_counters.append(SCons.Memoize.CountValue('get_all_rdirs'))
+
+ def get_all_rdirs(self):
+ try:
+ return list(self._memo['get_all_rdirs'])
+ except KeyError:
+ pass
+
+ result = [self]
+ fname = '.'
+ dir = self
+ while dir:
+ for rep in dir.getRepositories():
+ result.append(rep.Dir(fname))
+ if fname == '.':
+ fname = dir.name
+ else:
+ fname = dir.name + os.sep + fname
+ dir = dir.up()
+
+ self._memo['get_all_rdirs'] = list(result)
+
+ return result
+
+ def addRepository(self, dir):
+ if dir != self and not dir in self.repositories:
+ self.repositories.append(dir)
+ dir.tpath = '.'
+ self.__clearRepositoryCache()
+
+ def up(self):
+ return self.entries['..']
+
+ def _rel_path_key(self, other):
+ return str(other)
+
+ memoizer_counters.append(SCons.Memoize.CountDict('rel_path', _rel_path_key))
+
+ def rel_path(self, other):
+ """Return a path to "other" relative to this directory.
+ """
+
+ # This complicated and expensive method, which constructs relative
+ # paths between arbitrary Node.FS objects, is no longer used
+ # by SCons itself. It was introduced to store dependency paths
+ # in .sconsign files relative to the target, but that ended up
+ # being significantly inefficient.
+ #
+ # We're continuing to support the method because some SConstruct
+ # files out there started using it when it was available, and
+ # we're all about backwards compatibility..
+
+ try:
+ memo_dict = self._memo['rel_path']
+ except KeyError:
+ memo_dict = {}
+ self._memo['rel_path'] = memo_dict
+ else:
+ try:
+ return memo_dict[other]
+ except KeyError:
+ pass
+
+ if self is other:
+ result = '.'
+
+ elif not other in self.path_elements:
+ try:
+ other_dir = other.get_dir()
+ except AttributeError:
+ result = str(other)
+ else:
+ if other_dir is None:
+ result = other.name
+ else:
+ dir_rel_path = self.rel_path(other_dir)
+ if dir_rel_path == '.':
+ result = other.name
+ else:
+ result = dir_rel_path + os.sep + other.name
+ else:
+ i = self.path_elements.index(other) + 1
+
+ path_elems = ['..'] * (len(self.path_elements) - i) \
+ + [n.name for n in other.path_elements[i:]]
+
+ result = os.sep.join(path_elems)
+
+ memo_dict[other] = result
+
+ return result
+
+ def get_env_scanner(self, env, kw={}):
+ import SCons.Defaults
+ return SCons.Defaults.DirEntryScanner
+
+ def get_target_scanner(self):
+ import SCons.Defaults
+ return SCons.Defaults.DirEntryScanner
+
+ def get_found_includes(self, env, scanner, path):
+ """Return this directory's implicit dependencies.
+
+ We don't bother caching the results because the scan typically
+ shouldn't be requested more than once (as opposed to scanning
+ .h file contents, which can be requested as many times as the
+ files is #included by other files).
+ """
+ if not scanner:
+ return []
+ # Clear cached info for this Dir. If we already visited this
+ # directory on our walk down the tree (because we didn't know at
+ # that point it was being used as the source for another Node)
+ # then we may have calculated build signature before realizing
+ # we had to scan the disk. Now that we have to, though, we need
+ # to invalidate the old calculated signature so that any node
+ # dependent on our directory structure gets one that includes
+ # info about everything on disk.
+ self.clear()
+ return scanner(self, env, path)
+
+ #
+ # Taskmaster interface subsystem
+ #
+
+ def prepare(self):
+ pass
+
+ def build(self, **kw):
+ """A null "builder" for directories."""
+ global MkdirBuilder
+ if self.builder is not MkdirBuilder:
+ SCons.Node.Node.build(self, **kw)
+
+ #
+ #
+ #
+
+ def _create(self):
+ """Create this directory, silently and without worrying about
+ whether the builder is the default or not."""
+ listDirs = []
+ parent = self
+ while parent:
+ if parent.exists():
+ break
+ listDirs.append(parent)
+ p = parent.up()
+ if p is None:
+ # Don't use while: - else: for this condition because
+ # if so, then parent is None and has no .path attribute.
+ raise SCons.Errors.StopError(parent.path)
+ parent = p
+ listDirs.reverse()
+ for dirnode in listDirs:
+ try:
+ # Don't call dirnode.build(), call the base Node method
+ # directly because we definitely *must* create this
+ # directory. The dirnode.build() method will suppress
+ # the build if it's the default builder.
+ SCons.Node.Node.build(dirnode)
+ dirnode.get_executor().nullify()
+ # The build() action may or may not have actually
+ # created the directory, depending on whether the -n
+ # option was used or not. Delete the _exists and
+ # _rexists attributes so they can be reevaluated.
+ dirnode.clear()
+ except OSError:
+ pass
+
+ def multiple_side_effect_has_builder(self):
+ global MkdirBuilder
+ return self.builder is not MkdirBuilder and self.has_builder()
+
+ def alter_targets(self):
+ """Return any corresponding targets in a variant directory.
+ """
+ return self.fs.variant_dir_target_climb(self, self, [])
+
+ def scanner_key(self):
+ """A directory does not get scanned."""
+ return None
+
+ def get_text_contents(self):
+ """We already emit things in text, so just return the binary
+ version."""
+ return self.get_contents()
+
+ def get_contents(self):
+ """Return content signatures and names of all our children
+ separated by new-lines. Ensure that the nodes are sorted."""
+ contents = []
+ for node in sorted(self.children(), key=lambda t: t.name):
+ contents.append('%s %s\n' % (node.get_csig(), node.name))
+ return ''.join(contents)
+
+ def get_csig(self):
+ """Compute the content signature for Directory nodes. In
+ general, this is not needed and the content signature is not
+ stored in the DirNodeInfo. However, if get_contents on a Dir
+ node is called which has a child directory, the child
+ directory should return the hash of its contents."""
+ contents = self.get_contents()
+ return SCons.Util.MD5signature(contents)
+
+ def do_duplicate(self, src):
+ pass
+
+ changed_since_last_build = SCons.Node.Node.state_has_changed
+
+ def is_up_to_date(self):
+ """If any child is not up-to-date, then this directory isn't,
+ either."""
+ if self.builder is not MkdirBuilder and not self.exists():
+ return 0
+ up_to_date = SCons.Node.up_to_date
+ for kid in self.children():
+ if kid.get_state() > up_to_date:
+ return 0
+ return 1
+
+ def rdir(self):
+ if not self.exists():
+ norm_name = _my_normcase(self.name)
+ for dir in self.dir.get_all_rdirs():
+ try: node = dir.entries[norm_name]
+ except KeyError: node = dir.dir_on_disk(self.name)
+ if node and node.exists() and \
+ (isinstance(dir, Dir) or isinstance(dir, Entry)):
+ return node
+ return self
+
+ def sconsign(self):
+ """Return the .sconsign file info for this directory,
+ creating it first if necessary."""
+ if not self._sconsign:
+ import SCons.SConsign
+ self._sconsign = SCons.SConsign.ForDirectory(self)
+ return self._sconsign
+
+ def srcnode(self):
+ """Dir has a special need for srcnode()...if we
+ have a srcdir attribute set, then that *is* our srcnode."""
+ if self.srcdir:
+ return self.srcdir
+ return Base.srcnode(self)
+
+ def get_timestamp(self):
+ """Return the latest timestamp from among our children"""
+ stamp = 0
+ for kid in self.children():
+ if kid.get_timestamp() > stamp:
+ stamp = kid.get_timestamp()
+ return stamp
+
+ def entry_abspath(self, name):
+ return self.abspath + os.sep + name
+
+ def entry_labspath(self, name):
+ return self.labspath + '/' + name
+
+ def entry_path(self, name):
+ return self.path + os.sep + name
+
+ def entry_tpath(self, name):
+ return self.tpath + os.sep + name
+
+ def entry_exists_on_disk(self, name):
+ try:
+ d = self.on_disk_entries
+ except AttributeError:
+ d = {}
+ try:
+ entries = os.listdir(self.abspath)
+ except OSError:
+ pass
+ else:
+ for entry in map(_my_normcase, entries):
+ d[entry] = True
+ self.on_disk_entries = d
+ if sys.platform == 'win32':
+ name = _my_normcase(name)
+ result = d.get(name)
+ if result is None:
+ # Belt-and-suspenders for Windows: check directly for
+ # 8.3 file names that don't show up in os.listdir().
+ result = os.path.exists(self.abspath + os.sep + name)
+ d[name] = result
+ return result
+ else:
+ return name in d
+
+ memoizer_counters.append(SCons.Memoize.CountValue('srcdir_list'))
+
+ def srcdir_list(self):
+ try:
+ return self._memo['srcdir_list']
+ except KeyError:
+ pass
+
+ result = []
+
+ dirname = '.'
+ dir = self
+ while dir:
+ if dir.srcdir:
+ result.append(dir.srcdir.Dir(dirname))
+ dirname = dir.name + os.sep + dirname
+ dir = dir.up()
+
+ self._memo['srcdir_list'] = result
+
+ return result
+
+ def srcdir_duplicate(self, name):
+ for dir in self.srcdir_list():
+ if self.is_under(dir):
+ # We shouldn't source from something in the build path;
+ # variant_dir is probably under src_dir, in which case
+ # we are reflecting.
+ break
+ if dir.entry_exists_on_disk(name):
+ srcnode = dir.Entry(name).disambiguate()
+ if self.duplicate:
+ node = self.Entry(name).disambiguate()
+ node.do_duplicate(srcnode)
+ return node
+ else:
+ return srcnode
+ return None
+
+ def _srcdir_find_file_key(self, filename):
+ return filename
+
+ memoizer_counters.append(SCons.Memoize.CountDict('srcdir_find_file', _srcdir_find_file_key))
+
+ def srcdir_find_file(self, filename):
+ try:
+ memo_dict = self._memo['srcdir_find_file']
+ except KeyError:
+ memo_dict = {}
+ self._memo['srcdir_find_file'] = memo_dict
+ else:
+ try:
+ return memo_dict[filename]
+ except KeyError:
+ pass
+
+ def func(node):
+ if (isinstance(node, File) or isinstance(node, Entry)) and \
+ (node.is_derived() or node.exists()):
+ return node
+ return None
+
+ norm_name = _my_normcase(filename)
+
+ for rdir in self.get_all_rdirs():
+ try: node = rdir.entries[norm_name]
+ except KeyError: node = rdir.file_on_disk(filename)
+ else: node = func(node)
+ if node:
+ result = (node, self)
+ memo_dict[filename] = result
+ return result
+
+ for srcdir in self.srcdir_list():
+ for rdir in srcdir.get_all_rdirs():
+ try: node = rdir.entries[norm_name]
+ except KeyError: node = rdir.file_on_disk(filename)
+ else: node = func(node)
+ if node:
+ result = (File(filename, self, self.fs), srcdir)
+ memo_dict[filename] = result
+ return result
+
+ result = (None, None)
+ memo_dict[filename] = result
+ return result
+
+ def dir_on_disk(self, name):
+ if self.entry_exists_on_disk(name):
+ try: return self.Dir(name)
+ except TypeError: pass
+ node = self.srcdir_duplicate(name)
+ if isinstance(node, File):
+ return None
+ return node
+
+ def file_on_disk(self, name):
+ if self.entry_exists_on_disk(name) or \
+ diskcheck_rcs(self, name) or \
+ diskcheck_sccs(self, name):
+ try: return self.File(name)
+ except TypeError: pass
+ node = self.srcdir_duplicate(name)
+ if isinstance(node, Dir):
+ return None
+ return node
+
+ def walk(self, func, arg):
+ """
+ Walk this directory tree by calling the specified function
+ for each directory in the tree.
+
+ This behaves like the os.path.walk() function, but for in-memory
+ Node.FS.Dir objects. The function takes the same arguments as
+ the functions passed to os.path.walk():
+
+ func(arg, dirname, fnames)
+
+ Except that "dirname" will actually be the directory *Node*,
+ not the string. The '.' and '..' entries are excluded from
+ fnames. The fnames list may be modified in-place to filter the
+ subdirectories visited or otherwise impose a specific order.
+ The "arg" argument is always passed to func() and may be used
+ in any way (or ignored, passing None is common).
+ """
+ entries = self.entries
+ names = list(entries.keys())
+ names.remove('.')
+ names.remove('..')
+ func(arg, self, names)
+ for dirname in [n for n in names if isinstance(entries[n], Dir)]:
+ entries[dirname].walk(func, arg)
+
+ def glob(self, pathname, ondisk=True, source=False, strings=False):
+ """
+ Returns a list of Nodes (or strings) matching a specified
+ pathname pattern.
+
+ Pathname patterns follow UNIX shell semantics: * matches
+ any-length strings of any characters, ? matches any character,
+ and [] can enclose lists or ranges of characters. Matches do
+ not span directory separators.
+
+ The matches take into account Repositories, returning local
+ Nodes if a corresponding entry exists in a Repository (either
+ an in-memory Node or something on disk).
+
+ By defafult, the glob() function matches entries that exist
+ on-disk, in addition to in-memory Nodes. Setting the "ondisk"
+ argument to False (or some other non-true value) causes the glob()
+ function to only match in-memory Nodes. The default behavior is
+ to return both the on-disk and in-memory Nodes.
+
+ The "source" argument, when true, specifies that corresponding
+ source Nodes must be returned if you're globbing in a build
+ directory (initialized with VariantDir()). The default behavior
+ is to return Nodes local to the VariantDir().
+
+ The "strings" argument, when true, returns the matches as strings,
+ not Nodes. The strings are path names relative to this directory.
+
+ The underlying algorithm is adapted from the glob.glob() function
+ in the Python library (but heavily modified), and uses fnmatch()
+ under the covers.
+ """
+ dirname, basename = os.path.split(pathname)
+ if not dirname:
+ return sorted(self._glob1(basename, ondisk, source, strings),
+ key=lambda t: str(t))
+ if has_glob_magic(dirname):
+ list = self.glob(dirname, ondisk, source, strings=False)
+ else:
+ list = [self.Dir(dirname, create=True)]
+ result = []
+ for dir in list:
+ r = dir._glob1(basename, ondisk, source, strings)
+ if strings:
+ r = [os.path.join(str(dir), x) for x in r]
+ result.extend(r)
+ return sorted(result, key=lambda a: str(a))
+
+ def _glob1(self, pattern, ondisk=True, source=False, strings=False):
+ """
+ Globs for and returns a list of entry names matching a single
+ pattern in this directory.
+
+ This searches any repositories and source directories for
+ corresponding entries and returns a Node (or string) relative
+ to the current directory if an entry is found anywhere.
+
+ TODO: handle pattern with no wildcard
+ """
+ search_dir_list = self.get_all_rdirs()
+ for srcdir in self.srcdir_list():
+ search_dir_list.extend(srcdir.get_all_rdirs())
+
+ selfEntry = self.Entry
+ names = []
+ for dir in search_dir_list:
+ # We use the .name attribute from the Node because the keys of
+ # the dir.entries dictionary are normalized (that is, all upper
+ # case) on case-insensitive systems like Windows.
+ node_names = [ v.name for k, v in dir.entries.items()
+ if k not in ('.', '..') ]
+ names.extend(node_names)
+ if not strings:
+ # Make sure the working directory (self) actually has
+ # entries for all Nodes in repositories or variant dirs.
+ for name in node_names: selfEntry(name)
+ if ondisk:
+ try:
+ disk_names = os.listdir(dir.abspath)
+ except os.error:
+ continue
+ names.extend(disk_names)
+ if not strings:
+ # We're going to return corresponding Nodes in
+ # the local directory, so we need to make sure
+ # those Nodes exist. We only want to create
+ # Nodes for the entries that will match the
+ # specified pattern, though, which means we
+ # need to filter the list here, even though
+ # the overall list will also be filtered later,
+ # after we exit this loop.
+ if pattern[0] != '.':
+ #disk_names = [ d for d in disk_names if d[0] != '.' ]
+ disk_names = [x for x in disk_names if x[0] != '.']
+ disk_names = fnmatch.filter(disk_names, pattern)
+ dirEntry = dir.Entry
+ for name in disk_names:
+ # Add './' before disk filename so that '#' at
+ # beginning of filename isn't interpreted.
+ name = './' + name
+ node = dirEntry(name).disambiguate()
+ n = selfEntry(name)
+ if n.__class__ != node.__class__:
+ n.__class__ = node.__class__
+ n._morph()
+
+ names = set(names)
+ if pattern[0] != '.':
+ #names = [ n for n in names if n[0] != '.' ]
+ names = [x for x in names if x[0] != '.']
+ names = fnmatch.filter(names, pattern)
+
+ if strings:
+ return names
+
+ #return [ self.entries[_my_normcase(n)] for n in names ]
+ return [self.entries[_my_normcase(n)] for n in names]
+
+class RootDir(Dir):
+ """A class for the root directory of a file system.
+
+ This is the same as a Dir class, except that the path separator
+ ('/' or '\\') is actually part of the name, so we don't need to
+ add a separator when creating the path names of entries within
+ this directory.
+ """
+ def __init__(self, name, fs):
+ if __debug__: logInstanceCreation(self, 'Node.FS.RootDir')
+ # We're going to be our own parent directory (".." entry and .dir
+ # attribute) so we have to set up some values so Base.__init__()
+ # won't gag won't it calls some of our methods.
+ self.abspath = ''
+ self.labspath = ''
+ self.path = ''
+ self.tpath = ''
+ self.path_elements = []
+ self.duplicate = 0
+ self.root = self
+ Base.__init__(self, name, self, fs)
+
+ # Now set our paths to what we really want them to be: the
+ # initial drive letter (the name) plus the directory separator,
+ # except for the "lookup abspath," which does not have the
+ # drive letter.
+ self.abspath = name + os.sep
+ self.labspath = ''
+ self.path = name + os.sep
+ self.tpath = name + os.sep
+ self._morph()
+
+ self._lookupDict = {}
+
+ # The // and os.sep + os.sep entries are necessary because
+ # os.path.normpath() seems to preserve double slashes at the
+ # beginning of a path (presumably for UNC path names), but
+ # collapses triple slashes to a single slash.
+ self._lookupDict[''] = self
+ self._lookupDict['/'] = self
+ self._lookupDict['//'] = self
+ self._lookupDict[os.sep] = self
+ self._lookupDict[os.sep + os.sep] = self
+
+ def must_be_same(self, klass):
+ if klass is Dir:
+ return
+ Base.must_be_same(self, klass)
+
+ def _lookup_abs(self, p, klass, create=1):
+ """
+ Fast (?) lookup of a *normalized* absolute path.
+
+ This method is intended for use by internal lookups with
+ already-normalized path data. For general-purpose lookups,
+ use the FS.Entry(), FS.Dir() or FS.File() methods.
+
+ The caller is responsible for making sure we're passed a
+ normalized absolute path; we merely let Python's dictionary look
+ up and return the One True Node.FS object for the path.
+
+ If no Node for the specified "p" doesn't already exist, and
+ "create" is specified, the Node may be created after recursive
+ invocation to find or create the parent directory or directories.
+ """
+ k = _my_normcase(p)
+ try:
+ result = self._lookupDict[k]
+ except KeyError:
+ if not create:
+ msg = "No such file or directory: '%s' in '%s' (and create is False)" % (p, str(self))
+ raise SCons.Errors.UserError(msg)
+ # There is no Node for this path name, and we're allowed
+ # to create it.
+ dir_name, file_name = os.path.split(p)
+ dir_node = self._lookup_abs(dir_name, Dir)
+ result = klass(file_name, dir_node, self.fs)
+
+ # Double-check on disk (as configured) that the Node we
+ # created matches whatever is out there in the real world.
+ result.diskcheck_match()
+
+ self._lookupDict[k] = result
+ dir_node.entries[_my_normcase(file_name)] = result
+ dir_node.implicit = None
+ else:
+ # There is already a Node for this path name. Allow it to
+ # complain if we were looking for an inappropriate type.
+ result.must_be_same(klass)
+ return result
+
+ def __str__(self):
+ return self.abspath
+
+ def entry_abspath(self, name):
+ return self.abspath + name
+
+ def entry_labspath(self, name):
+ return '/' + name
+
+ def entry_path(self, name):
+ return self.path + name
+
+ def entry_tpath(self, name):
+ return self.tpath + name
+
+ def is_under(self, dir):
+ if self is dir:
+ return 1
+ else:
+ return 0
+
+ def up(self):
+ return None
+
+ def get_dir(self):
+ return None
+
+ def src_builder(self):
+ return _null
+
+class FileNodeInfo(SCons.Node.NodeInfoBase):
+ current_version_id = 1
+
+ field_list = ['csig', 'timestamp', 'size']
+
+ # This should get reset by the FS initialization.
+ fs = None
+
+ def str_to_node(self, s):
+ top = self.fs.Top
+ root = top.root
+ if do_splitdrive:
+ drive, s = os.path.splitdrive(s)
+ if drive:
+ root = self.fs.get_root(drive)
+ if not os.path.isabs(s):
+ s = top.labspath + '/' + s
+ return root._lookup_abs(s, Entry)
+
+class FileBuildInfo(SCons.Node.BuildInfoBase):
+ current_version_id = 1
+
+ def convert_to_sconsign(self):
+ """
+ Converts this FileBuildInfo object for writing to a .sconsign file
+
+ This replaces each Node in our various dependency lists with its
+ usual string representation: relative to the top-level SConstruct
+ directory, or an absolute path if it's outside.
+ """
+ if os.sep == '/':
+ node_to_str = str
+ else:
+ def node_to_str(n):
+ try:
+ s = n.path
+ except AttributeError:
+ s = str(n)
+ else:
+ s = s.replace(os.sep, '/')
+ return s
+ for attr in ['bsources', 'bdepends', 'bimplicit']:
+ try:
+ val = getattr(self, attr)
+ except AttributeError:
+ pass
+ else:
+ setattr(self, attr, list(map(node_to_str, val)))
+ def convert_from_sconsign(self, dir, name):
+ """
+ Converts a newly-read FileBuildInfo object for in-SCons use
+
+ For normal up-to-date checking, we don't have any conversion to
+ perform--but we're leaving this method here to make that clear.
+ """
+ pass
+ def prepare_dependencies(self):
+ """
+ Prepares a FileBuildInfo object for explaining what changed
+
+ The bsources, bdepends and bimplicit lists have all been
+ stored on disk as paths relative to the top-level SConstruct
+ directory. Convert the strings to actual Nodes (for use by the
+ --debug=explain code and --implicit-cache).
+ """
+ attrs = [
+ ('bsources', 'bsourcesigs'),
+ ('bdepends', 'bdependsigs'),
+ ('bimplicit', 'bimplicitsigs'),
+ ]
+ for (nattr, sattr) in attrs:
+ try:
+ strings = getattr(self, nattr)
+ nodeinfos = getattr(self, sattr)
+ except AttributeError:
+ continue
+ nodes = []
+ for s, ni in zip(strings, nodeinfos):
+ if not isinstance(s, SCons.Node.Node):
+ s = ni.str_to_node(s)
+ nodes.append(s)
+ setattr(self, nattr, nodes)
+ def format(self, names=0):
+ result = []
+ bkids = self.bsources + self.bdepends + self.bimplicit
+ bkidsigs = self.bsourcesigs + self.bdependsigs + self.bimplicitsigs
+ for bkid, bkidsig in zip(bkids, bkidsigs):
+ result.append(str(bkid) + ': ' +
+ ' '.join(bkidsig.format(names=names)))
+ result.append('%s [%s]' % (self.bactsig, self.bact))
+ return '\n'.join(result)
+
+class File(Base):
+ """A class for files in a file system.
+ """
+
+ memoizer_counters = []
+
+ NodeInfo = FileNodeInfo
+ BuildInfo = FileBuildInfo
+
+ md5_chunksize = 64
+
+ def diskcheck_match(self):
+ diskcheck_match(self, self.isdir,
+ "Directory %s found where file expected.")
+
+ def __init__(self, name, directory, fs):
+ if __debug__: logInstanceCreation(self, 'Node.FS.File')
+ Base.__init__(self, name, directory, fs)
+ self._morph()
+
+ def Entry(self, name):
+ """Create an entry node named 'name' relative to
+ the directory of this file."""
+ return self.dir.Entry(name)
+
+ def Dir(self, name, create=True):
+ """Create a directory node named 'name' relative to
+ the directory of this file."""
+ return self.dir.Dir(name, create=create)
+
+ def Dirs(self, pathlist):
+ """Create a list of directories relative to the SConscript
+ directory of this file."""
+ return [self.Dir(p) for p in pathlist]
+
+ def File(self, name):
+ """Create a file node named 'name' relative to
+ the directory of this file."""
+ return self.dir.File(name)
+
+ #def generate_build_dict(self):
+ # """Return an appropriate dictionary of values for building
+ # this File."""
+ # return {'Dir' : self.Dir,
+ # 'File' : self.File,
+ # 'RDirs' : self.RDirs}
+
+ def _morph(self):
+ """Turn a file system node into a File object."""
+ self.scanner_paths = {}
+ if not hasattr(self, '_local'):
+ self._local = 0
+
+ # If there was already a Builder set on this entry, then
+ # we need to make sure we call the target-decider function,
+ # not the source-decider. Reaching in and doing this by hand
+ # is a little bogus. We'd prefer to handle this by adding
+ # an Entry.builder_set() method that disambiguates like the
+ # other methods, but that starts running into problems with the
+ # fragile way we initialize Dir Nodes with their Mkdir builders,
+ # yet still allow them to be overridden by the user. Since it's
+ # not clear right now how to fix that, stick with what works
+ # until it becomes clear...
+ if self.has_builder():
+ self.changed_since_last_build = self.decide_target
+
+ def scanner_key(self):
+ return self.get_suffix()
+
+ def get_contents(self):
+ if not self.rexists():
+ return ''
+ fname = self.rfile().abspath
+ try:
+ contents = open(fname, "rb").read()
+ except EnvironmentError, e:
+ if not e.filename:
+ e.filename = fname
+ raise
+ return contents
+
+ # This attempts to figure out what the encoding of the text is
+ # based upon the BOM bytes, and then decodes the contents so that
+ # it's a valid python string.
+ def get_text_contents(self):
+ contents = self.get_contents()
+ # The behavior of various decode() methods and functions
+ # w.r.t. the initial BOM bytes is different for different
+ # encodings and/or Python versions. ('utf-8' does not strip
+ # them, but has a 'utf-8-sig' which does; 'utf-16' seems to
+ # strip them; etc.) Just sidestep all the complication by
+ # explicitly stripping the BOM before we decode().
+ if contents.startswith(codecs.BOM_UTF8):
+ return contents[len(codecs.BOM_UTF8):].decode('utf-8')
+ if contents.startswith(codecs.BOM_UTF16_LE):
+ return contents[len(codecs.BOM_UTF16_LE):].decode('utf-16-le')
+ if contents.startswith(codecs.BOM_UTF16_BE):
+ return contents[len(codecs.BOM_UTF16_BE):].decode('utf-16-be')
+ return contents
+
+ def get_content_hash(self):
+ """
+ Compute and return the MD5 hash for this file.
+ """
+ if not self.rexists():
+ return SCons.Util.MD5signature('')
+ fname = self.rfile().abspath
+ try:
+ cs = SCons.Util.MD5filesignature(fname,
+ chunksize=SCons.Node.FS.File.md5_chunksize*1024)
+ except EnvironmentError, e:
+ if not e.filename:
+ e.filename = fname
+ raise
+ return cs
+
+
+ memoizer_counters.append(SCons.Memoize.CountValue('get_size'))
+
+ def get_size(self):
+ try:
+ return self._memo['get_size']
+ except KeyError:
+ pass
+
+ if self.rexists():
+ size = self.rfile().getsize()
+ else:
+ size = 0
+
+ self._memo['get_size'] = size
+
+ return size
+
+ memoizer_counters.append(SCons.Memoize.CountValue('get_timestamp'))
+
+ def get_timestamp(self):
+ try:
+ return self._memo['get_timestamp']
+ except KeyError:
+ pass
+
+ if self.rexists():
+ timestamp = self.rfile().getmtime()
+ else:
+ timestamp = 0
+
+ self._memo['get_timestamp'] = timestamp
+
+ return timestamp
+
+ def store_info(self):
+ # Merge our build information into the already-stored entry.
+ # This accomodates "chained builds" where a file that's a target
+ # in one build (SConstruct file) is a source in a different build.
+ # See test/chained-build.py for the use case.
+ if do_store_info:
+ self.dir.sconsign().store_info(self.name, self)
+
+ convert_copy_attrs = [
+ 'bsources',
+ 'bimplicit',
+ 'bdepends',
+ 'bact',
+ 'bactsig',
+ 'ninfo',
+ ]
+
+
+ convert_sig_attrs = [
+ 'bsourcesigs',
+ 'bimplicitsigs',
+ 'bdependsigs',
+ ]
+
+ def convert_old_entry(self, old_entry):
+ # Convert a .sconsign entry from before the Big Signature
+ # Refactoring, doing what we can to convert its information
+ # to the new .sconsign entry format.
+ #
+ # The old format looked essentially like this:
+ #
+ # BuildInfo
+ # .ninfo (NodeInfo)
+ # .bsig
+ # .csig
+ # .timestamp
+ # .size
+ # .bsources
+ # .bsourcesigs ("signature" list)
+ # .bdepends
+ # .bdependsigs ("signature" list)
+ # .bimplicit
+ # .bimplicitsigs ("signature" list)
+ # .bact
+ # .bactsig
+ #
+ # The new format looks like this:
+ #
+ # .ninfo (NodeInfo)
+ # .bsig
+ # .csig
+ # .timestamp
+ # .size
+ # .binfo (BuildInfo)
+ # .bsources
+ # .bsourcesigs (NodeInfo list)
+ # .bsig
+ # .csig
+ # .timestamp
+ # .size
+ # .bdepends
+ # .bdependsigs (NodeInfo list)
+ # .bsig
+ # .csig
+ # .timestamp
+ # .size
+ # .bimplicit
+ # .bimplicitsigs (NodeInfo list)
+ # .bsig
+ # .csig
+ # .timestamp
+ # .size
+ # .bact
+ # .bactsig
+ #
+ # The basic idea of the new structure is that a NodeInfo always
+ # holds all available information about the state of a given Node
+ # at a certain point in time. The various .b*sigs lists can just
+ # be a list of pointers to the .ninfo attributes of the different
+ # dependent nodes, without any copying of information until it's
+ # time to pickle it for writing out to a .sconsign file.
+ #
+ # The complicating issue is that the *old* format only stored one
+ # "signature" per dependency, based on however the *last* build
+ # was configured. We don't know from just looking at it whether
+ # it was a build signature, a content signature, or a timestamp
+ # "signature". Since we no longer use build signatures, the
+ # best we can do is look at the length and if it's thirty two,
+ # assume that it was (or might have been) a content signature.
+ # If it was actually a build signature, then it will cause a
+ # rebuild anyway when it doesn't match the new content signature,
+ # but that's probably the best we can do.
+ import SCons.SConsign
+ new_entry = SCons.SConsign.SConsignEntry()
+ new_entry.binfo = self.new_binfo()
+ binfo = new_entry.binfo
+ for attr in self.convert_copy_attrs:
+ try:
+ value = getattr(old_entry, attr)
+ except AttributeError:
+ continue
+ setattr(binfo, attr, value)
+ delattr(old_entry, attr)
+ for attr in self.convert_sig_attrs:
+ try:
+ sig_list = getattr(old_entry, attr)
+ except AttributeError:
+ continue
+ value = []
+ for sig in sig_list:
+ ninfo = self.new_ninfo()
+ if len(sig) == 32:
+ ninfo.csig = sig
+ else:
+ ninfo.timestamp = sig
+ value.append(ninfo)
+ setattr(binfo, attr, value)
+ delattr(old_entry, attr)
+ return new_entry
+
+ memoizer_counters.append(SCons.Memoize.CountValue('get_stored_info'))
+
+ def get_stored_info(self):
+ try:
+ return self._memo['get_stored_info']
+ except KeyError:
+ pass
+
+ try:
+ sconsign_entry = self.dir.sconsign().get_entry(self.name)
+ except (KeyError, EnvironmentError):
+ import SCons.SConsign
+ sconsign_entry = SCons.SConsign.SConsignEntry()
+ sconsign_entry.binfo = self.new_binfo()
+ sconsign_entry.ninfo = self.new_ninfo()
+ else:
+ if isinstance(sconsign_entry, FileBuildInfo):
+ # This is a .sconsign file from before the Big Signature
+ # Refactoring; convert it as best we can.
+ sconsign_entry = self.convert_old_entry(sconsign_entry)
+ try:
+ delattr(sconsign_entry.ninfo, 'bsig')
+ except AttributeError:
+ pass
+
+ self._memo['get_stored_info'] = sconsign_entry
+
+ return sconsign_entry
+
+ def get_stored_implicit(self):
+ binfo = self.get_stored_info().binfo
+ binfo.prepare_dependencies()
+ try: return binfo.bimplicit
+ except AttributeError: return None
+
+ def rel_path(self, other):
+ return self.dir.rel_path(other)
+
+ def _get_found_includes_key(self, env, scanner, path):
+ return (id(env), id(scanner), path)
+
+ memoizer_counters.append(SCons.Memoize.CountDict('get_found_includes', _get_found_includes_key))
+
+ def get_found_includes(self, env, scanner, path):
+ """Return the included implicit dependencies in this file.
+ Cache results so we only scan the file once per path
+ regardless of how many times this information is requested.
+ """
+ memo_key = (id(env), id(scanner), path)
+ try:
+ memo_dict = self._memo['get_found_includes']
+ except KeyError:
+ memo_dict = {}
+ self._memo['get_found_includes'] = memo_dict
+ else:
+ try:
+ return memo_dict[memo_key]
+ except KeyError:
+ pass
+
+ if scanner:
+ # result = [n.disambiguate() for n in scanner(self, env, path)]
+ result = scanner(self, env, path)
+ result = [N.disambiguate() for N in result]
+ else:
+ result = []
+
+ memo_dict[memo_key] = result
+
+ return result
+
+ def _createDir(self):
+ # ensure that the directories for this node are
+ # created.
+ self.dir._create()
+
+ def push_to_cache(self):
+ """Try to push the node into a cache
+ """
+ # This should get called before the Nodes' .built() method is
+ # called, which would clear the build signature if the file has
+ # a source scanner.
+ #
+ # We have to clear the local memoized values *before* we push
+ # the node to cache so that the memoization of the self.exists()
+ # return value doesn't interfere.
+ if self.nocache:
+ return
+ self.clear_memoized_values()
+ if self.exists():
+ self.get_build_env().get_CacheDir().push(self)
+
+ def retrieve_from_cache(self):
+ """Try to retrieve the node's content from a cache
+
+ This method is called from multiple threads in a parallel build,
+ so only do thread safe stuff here. Do thread unsafe stuff in
+ built().
+
+ Returns true iff the node was successfully retrieved.
+ """
+ if self.nocache:
+ return None
+ if not self.is_derived():
+ return None
+ return self.get_build_env().get_CacheDir().retrieve(self)
+
+ def visited(self):
+ if self.exists():
+ self.get_build_env().get_CacheDir().push_if_forced(self)
+
+ ninfo = self.get_ninfo()
+
+ csig = self.get_max_drift_csig()
+ if csig:
+ ninfo.csig = csig
+
+ ninfo.timestamp = self.get_timestamp()
+ ninfo.size = self.get_size()
+
+ if not self.has_builder():
+ # This is a source file, but it might have been a target file
+ # in another build that included more of the DAG. Copy
+ # any build information that's stored in the .sconsign file
+ # into our binfo object so it doesn't get lost.
+ old = self.get_stored_info()
+ self.get_binfo().__dict__.update(old.binfo.__dict__)
+
+ self.store_info()
+
+ def find_src_builder(self):
+ if self.rexists():
+ return None
+ scb = self.dir.src_builder()
+ if scb is _null:
+ if diskcheck_sccs(self.dir, self.name):
+ scb = get_DefaultSCCSBuilder()
+ elif diskcheck_rcs(self.dir, self.name):
+ scb = get_DefaultRCSBuilder()
+ else:
+ scb = None
+ if scb is not None:
+ try:
+ b = self.builder
+ except AttributeError:
+ b = None
+ if b is None:
+ self.builder_set(scb)
+ return scb
+
+ def has_src_builder(self):
+ """Return whether this Node has a source builder or not.
+
+ If this Node doesn't have an explicit source code builder, this
+ is where we figure out, on the fly, if there's a transparent
+ source code builder for it.
+
+ Note that if we found a source builder, we also set the
+ self.builder attribute, so that all of the methods that actually
+ *build* this file don't have to do anything different.
+ """
+ try:
+ scb = self.sbuilder
+ except AttributeError:
+ scb = self.sbuilder = self.find_src_builder()
+ return scb is not None
+
+ def alter_targets(self):
+ """Return any corresponding targets in a variant directory.
+ """
+ if self.is_derived():
+ return [], None
+ return self.fs.variant_dir_target_climb(self, self.dir, [self.name])
+
+ def _rmv_existing(self):
+ self.clear_memoized_values()
+ e = Unlink(self, [], None)
+ if isinstance(e, SCons.Errors.BuildError):
+ raise e
+
+ #
+ # Taskmaster interface subsystem
+ #
+
+ def make_ready(self):
+ self.has_src_builder()
+ self.get_binfo()
+
+ def prepare(self):
+ """Prepare for this file to be created."""
+ SCons.Node.Node.prepare(self)
+
+ if self.get_state() != SCons.Node.up_to_date:
+ if self.exists():
+ if self.is_derived() and not self.precious:
+ self._rmv_existing()
+ else:
+ try:
+ self._createDir()
+ except SCons.Errors.StopError, drive:
+ desc = "No drive `%s' for target `%s'." % (drive, self)
+ raise SCons.Errors.StopError(desc)
+
+ #
+ #
+ #
+
+ def remove(self):
+ """Remove this file."""
+ if self.exists() or self.islink():
+ self.fs.unlink(self.path)
+ return 1
+ return None
+
+ def do_duplicate(self, src):
+ self._createDir()
+ Unlink(self, None, None)
+ e = Link(self, src, None)
+ if isinstance(e, SCons.Errors.BuildError):
+ desc = "Cannot duplicate `%s' in `%s': %s." % (src.path, self.dir.path, e.errstr)
+ raise SCons.Errors.StopError(desc)
+ self.linked = 1
+ # The Link() action may or may not have actually
+ # created the file, depending on whether the -n
+ # option was used or not. Delete the _exists and
+ # _rexists attributes so they can be reevaluated.
+ self.clear()
+
+ memoizer_counters.append(SCons.Memoize.CountValue('exists'))
+
+ def exists(self):
+ try:
+ return self._memo['exists']
+ except KeyError:
+ pass
+ # Duplicate from source path if we are set up to do this.
+ if self.duplicate and not self.is_derived() and not self.linked:
+ src = self.srcnode()
+ if src is not self:
+ # At this point, src is meant to be copied in a variant directory.
+ src = src.rfile()
+ if src.abspath != self.abspath:
+ if src.exists():
+ self.do_duplicate(src)
+ # Can't return 1 here because the duplication might
+ # not actually occur if the -n option is being used.
+ else:
+ # The source file does not exist. Make sure no old
+ # copy remains in the variant directory.
+ if Base.exists(self) or self.islink():
+ self.fs.unlink(self.path)
+ # Return None explicitly because the Base.exists() call
+ # above will have cached its value if the file existed.
+ self._memo['exists'] = None
+ return None
+ result = Base.exists(self)
+ self._memo['exists'] = result
+ return result
+
+ #
+ # SIGNATURE SUBSYSTEM
+ #
+
+ def get_max_drift_csig(self):
+ """
+ Returns the content signature currently stored for this node
+ if it's been unmodified longer than the max_drift value, or the
+ max_drift value is 0. Returns None otherwise.
+ """
+ old = self.get_stored_info()
+ mtime = self.get_timestamp()
+
+ max_drift = self.fs.max_drift
+ if max_drift > 0:
+ if (time.time() - mtime) > max_drift:
+ try:
+ n = old.ninfo
+ if n.timestamp and n.csig and n.timestamp == mtime:
+ return n.csig
+ except AttributeError:
+ pass
+ elif max_drift == 0:
+ try:
+ return old.ninfo.csig
+ except AttributeError:
+ pass
+
+ return None
+
+ def get_csig(self):
+ """
+ Generate a node's content signature, the digested signature
+ of its content.
+
+ node - the node
+ cache - alternate node to use for the signature cache
+ returns - the content signature
+ """
+ ninfo = self.get_ninfo()
+ try:
+ return ninfo.csig
+ except AttributeError:
+ pass
+
+ csig = self.get_max_drift_csig()
+ if csig is None:
+
+ try:
+ if self.get_size() < SCons.Node.FS.File.md5_chunksize:
+ contents = self.get_contents()
+ else:
+ csig = self.get_content_hash()
+ except IOError:
+ # This can happen if there's actually a directory on-disk,
+ # which can be the case if they've disabled disk checks,
+ # or if an action with a File target actually happens to
+ # create a same-named directory by mistake.
+ csig = ''
+ else:
+ if not csig:
+ csig = SCons.Util.MD5signature(contents)
+
+ ninfo.csig = csig
+
+ return csig
+
+ #
+ # DECISION SUBSYSTEM
+ #
+
+ def builder_set(self, builder):
+ SCons.Node.Node.builder_set(self, builder)
+ self.changed_since_last_build = self.decide_target
+
+ def changed_content(self, target, prev_ni):
+ cur_csig = self.get_csig()
+ try:
+ return cur_csig != prev_ni.csig
+ except AttributeError:
+ return 1
+
+ def changed_state(self, target, prev_ni):
+ return self.state != SCons.Node.up_to_date
+
+ def changed_timestamp_then_content(self, target, prev_ni):
+ if not self.changed_timestamp_match(target, prev_ni):
+ try:
+ self.get_ninfo().csig = prev_ni.csig
+ except AttributeError:
+ pass
+ return False
+ return self.changed_content(target, prev_ni)
+
+ def changed_timestamp_newer(self, target, prev_ni):
+ try:
+ return self.get_timestamp() > target.get_timestamp()
+ except AttributeError:
+ return 1
+
+ def changed_timestamp_match(self, target, prev_ni):
+ try:
+ return self.get_timestamp() != prev_ni.timestamp
+ except AttributeError:
+ return 1
+
+ def decide_source(self, target, prev_ni):
+ return target.get_build_env().decide_source(self, target, prev_ni)
+
+ def decide_target(self, target, prev_ni):
+ return target.get_build_env().decide_target(self, target, prev_ni)
+
+ # Initialize this Node's decider function to decide_source() because
+ # every file is a source file until it has a Builder attached...
+ changed_since_last_build = decide_source
+
+ def is_up_to_date(self):
+ T = 0
+ if T: Trace('is_up_to_date(%s):' % self)
+ if not self.exists():
+ if T: Trace(' not self.exists():')
+ # The file doesn't exist locally...
+ r = self.rfile()
+ if r != self:
+ # ...but there is one in a Repository...
+ if not self.changed(r):
+ if T: Trace(' changed(%s):' % r)
+ # ...and it's even up-to-date...
+ if self._local:
+ # ...and they'd like a local copy.
+ e = LocalCopy(self, r, None)
+ if isinstance(e, SCons.Errors.BuildError):
+ raise
+ self.store_info()
+ if T: Trace(' 1\n')
+ return 1
+ self.changed()
+ if T: Trace(' None\n')
+ return None
+ else:
+ r = self.changed()
+ if T: Trace(' self.exists(): %s\n' % r)
+ return not r
+
+ memoizer_counters.append(SCons.Memoize.CountValue('rfile'))
+
+ def rfile(self):
+ try:
+ return self._memo['rfile']
+ except KeyError:
+ pass
+ result = self
+ if not self.exists():
+ norm_name = _my_normcase(self.name)
+ for dir in self.dir.get_all_rdirs():
+ try: node = dir.entries[norm_name]
+ except KeyError: node = dir.file_on_disk(self.name)
+ if node and node.exists() and \
+ (isinstance(node, File) or isinstance(node, Entry) \
+ or not node.is_derived()):
+ result = node
+ # Copy over our local attributes to the repository
+ # Node so we identify shared object files in the
+ # repository and don't assume they're static.
+ #
+ # This isn't perfect; the attribute would ideally
+ # be attached to the object in the repository in
+ # case it was built statically in the repository
+ # and we changed it to shared locally, but that's
+ # rarely the case and would only occur if you
+ # intentionally used the same suffix for both
+ # shared and static objects anyway. So this
+ # should work well in practice.
+ result.attributes = self.attributes
+ break
+ self._memo['rfile'] = result
+ return result
+
+ def rstr(self):
+ return str(self.rfile())
+
+ def get_cachedir_csig(self):
+ """
+ Fetch a Node's content signature for purposes of computing
+ another Node's cachesig.
+
+ This is a wrapper around the normal get_csig() method that handles
+ the somewhat obscure case of using CacheDir with the -n option.
+ Any files that don't exist would normally be "built" by fetching
+ them from the cache, but the normal get_csig() method will try
+ to open up the local file, which doesn't exist because the -n
+ option meant we didn't actually pull the file from cachedir.
+ But since the file *does* actually exist in the cachedir, we
+ can use its contents for the csig.
+ """
+ try:
+ return self.cachedir_csig
+ except AttributeError:
+ pass
+
+ cachedir, cachefile = self.get_build_env().get_CacheDir().cachepath(self)
+ if not self.exists() and cachefile and os.path.exists(cachefile):
+ self.cachedir_csig = SCons.Util.MD5filesignature(cachefile, \
+ SCons.Node.FS.File.md5_chunksize * 1024)
+ else:
+ self.cachedir_csig = self.get_csig()
+ return self.cachedir_csig
+
+ def get_cachedir_bsig(self):
+ try:
+ return self.cachesig
+ except AttributeError:
+ pass
+
+ # Add the path to the cache signature, because multiple
+ # targets built by the same action will all have the same
+ # build signature, and we have to differentiate them somehow.
+ children = self.children()
+ executor = self.get_executor()
+ # sigs = [n.get_cachedir_csig() for n in children]
+ sigs = [n.get_cachedir_csig() for n in children]
+ sigs.append(SCons.Util.MD5signature(executor.get_contents()))
+ sigs.append(self.path)
+ result = self.cachesig = SCons.Util.MD5collect(sigs)
+ return result
+
+
+default_fs = None
+
+def get_default_fs():
+ global default_fs
+ if not default_fs:
+ default_fs = FS()
+ return default_fs
+
+class FileFinder(object):
+ """
+ """
+ if SCons.Memoize.use_memoizer:
+ __metaclass__ = SCons.Memoize.Memoized_Metaclass
+
+ memoizer_counters = []
+
+ def __init__(self):
+ self._memo = {}
+
+ def filedir_lookup(self, p, fd=None):
+ """
+ A helper method for find_file() that looks up a directory for
+ a file we're trying to find. This only creates the Dir Node if
+ it exists on-disk, since if the directory doesn't exist we know
+ we won't find any files in it... :-)
+
+ It would be more compact to just use this as a nested function
+ with a default keyword argument (see the commented-out version
+ below), but that doesn't work unless you have nested scopes,
+ so we define it here just so this work under Python 1.5.2.
+ """
+ if fd is None:
+ fd = self.default_filedir
+ dir, name = os.path.split(fd)
+ drive, d = os.path.splitdrive(dir)
+ if not name and d[:1] in ('/', os.sep):
+ #return p.fs.get_root(drive).dir_on_disk(name)
+ return p.fs.get_root(drive)
+ if dir:
+ p = self.filedir_lookup(p, dir)
+ if not p:
+ return None
+ norm_name = _my_normcase(name)
+ try:
+ node = p.entries[norm_name]
+ except KeyError:
+ return p.dir_on_disk(name)
+ if isinstance(node, Dir):
+ return node
+ if isinstance(node, Entry):
+ node.must_be_same(Dir)
+ return node
+ return None
+
+ def _find_file_key(self, filename, paths, verbose=None):
+ return (filename, paths)
+
+ memoizer_counters.append(SCons.Memoize.CountDict('find_file', _find_file_key))
+
+ def find_file(self, filename, paths, verbose=None):
+ """
+ find_file(str, [Dir()]) -> [nodes]
+
+ filename - a filename to find
+ paths - a list of directory path *nodes* to search in. Can be
+ represented as a list, a tuple, or a callable that is
+ called with no arguments and returns the list or tuple.
+
+ returns - the node created from the found file.
+
+ Find a node corresponding to either a derived file or a file
+ that exists already.
+
+ Only the first file found is returned, and none is returned
+ if no file is found.
+ """
+ memo_key = self._find_file_key(filename, paths)
+ try:
+ memo_dict = self._memo['find_file']
+ except KeyError:
+ memo_dict = {}
+ self._memo['find_file'] = memo_dict
+ else:
+ try:
+ return memo_dict[memo_key]
+ except KeyError:
+ pass
+
+ if verbose and not callable(verbose):
+ if not SCons.Util.is_String(verbose):
+ verbose = "find_file"
+ _verbose = u' %s: ' % verbose
+ verbose = lambda s: sys.stdout.write(_verbose + s)
+
+ filedir, filename = os.path.split(filename)
+ if filedir:
+ # More compact code that we can't use until we drop
+ # support for Python 1.5.2:
+ #
+ #def filedir_lookup(p, fd=filedir):
+ # """
+ # A helper function that looks up a directory for a file
+ # we're trying to find. This only creates the Dir Node
+ # if it exists on-disk, since if the directory doesn't
+ # exist we know we won't find any files in it... :-)
+ # """
+ # dir, name = os.path.split(fd)
+ # if dir:
+ # p = filedir_lookup(p, dir)
+ # if not p:
+ # return None
+ # norm_name = _my_normcase(name)
+ # try:
+ # node = p.entries[norm_name]
+ # except KeyError:
+ # return p.dir_on_disk(name)
+ # if isinstance(node, Dir):
+ # return node
+ # if isinstance(node, Entry):
+ # node.must_be_same(Dir)
+ # return node
+ # if isinstance(node, Dir) or isinstance(node, Entry):
+ # return node
+ # return None
+ #paths = [_f for _f in map(filedir_lookup, paths) if _f]
+
+ self.default_filedir = filedir
+ paths = [_f for _f in map(self.filedir_lookup, paths) if _f]
+
+ result = None
+ for dir in paths:
+ if verbose:
+ verbose("looking for '%s' in '%s' ...\n" % (filename, dir))
+ node, d = dir.srcdir_find_file(filename)
+ if node:
+ if verbose:
+ verbose("... FOUND '%s' in '%s'\n" % (filename, d))
+ result = node
+ break
+
+ memo_dict[memo_key] = result
+
+ return result
+
+find_file = FileFinder().find_file
+
+
+def invalidate_node_memos(targets):
+ """
+ Invalidate the memoized values of all Nodes (files or directories)
+ that are associated with the given entries. Has been added to
+ clear the cache of nodes affected by a direct execution of an
+ action (e.g. Delete/Copy/Chmod). Existing Node caches become
+ inconsistent if the action is run through Execute(). The argument
+ `targets` can be a single Node object or filename, or a sequence
+ of Nodes/filenames.
+ """
+ from traceback import extract_stack
+
+ # First check if the cache really needs to be flushed. Only
+ # actions run in the SConscript with Execute() seem to be
+ # affected. XXX The way to check if Execute() is in the stacktrace
+ # is a very dirty hack and should be replaced by a more sensible
+ # solution.
+ for f in extract_stack():
+ if f[2] == 'Execute' and f[0][-14:] == 'Environment.py':
+ break
+ else:
+ # Dont have to invalidate, so return
+ return
+
+ if not SCons.Util.is_List(targets):
+ targets = [targets]
+
+ for entry in targets:
+ # If the target is a Node object, clear the cache. If it is a
+ # filename, look up potentially existing Node object first.
+ try:
+ entry.clear_memoized_values()
+ except AttributeError:
+ # Not a Node object, try to look up Node by filename. XXX
+ # This creates Node objects even for those filenames which
+ # do not correspond to an existing Node object.
+ node = get_default_fs().Entry(entry)
+ if node:
+ node.clear_memoized_values()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Node/Python.py b/couchjs/scons/scons-local-2.0.1/SCons/Node/Python.py
new file mode 100644
index 00000000..32450059
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Node/Python.py
@@ -0,0 +1,128 @@
+"""scons.Node.Python
+
+Python nodes.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Node/Python.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Node
+
+class ValueNodeInfo(SCons.Node.NodeInfoBase):
+ current_version_id = 1
+
+ field_list = ['csig']
+
+ def str_to_node(self, s):
+ return Value(s)
+
+class ValueBuildInfo(SCons.Node.BuildInfoBase):
+ current_version_id = 1
+
+class Value(SCons.Node.Node):
+ """A class for Python variables, typically passed on the command line
+ or generated by a script, but not from a file or some other source.
+ """
+
+ NodeInfo = ValueNodeInfo
+ BuildInfo = ValueBuildInfo
+
+ def __init__(self, value, built_value=None):
+ SCons.Node.Node.__init__(self)
+ self.value = value
+ if built_value is not None:
+ self.built_value = built_value
+
+ def str_for_display(self):
+ return repr(self.value)
+
+ def __str__(self):
+ return str(self.value)
+
+ def make_ready(self):
+ self.get_csig()
+
+ def build(self, **kw):
+ if not hasattr(self, 'built_value'):
+ SCons.Node.Node.build(self, **kw)
+
+ is_up_to_date = SCons.Node.Node.children_are_up_to_date
+
+ def is_under(self, dir):
+ # Make Value nodes get built regardless of
+ # what directory scons was run from. Value nodes
+ # are outside the filesystem:
+ return 1
+
+ def write(self, built_value):
+ """Set the value of the node."""
+ self.built_value = built_value
+
+ def read(self):
+ """Return the value. If necessary, the value is built."""
+ self.build()
+ if not hasattr(self, 'built_value'):
+ self.built_value = self.value
+ return self.built_value
+
+ def get_text_contents(self):
+ """By the assumption that the node.built_value is a
+ deterministic product of the sources, the contents of a Value
+ are the concatenation of all the contents of its sources. As
+ the value need not be built when get_contents() is called, we
+ cannot use the actual node.built_value."""
+ ###TODO: something reasonable about universal newlines
+ contents = str(self.value)
+ for kid in self.children(None):
+ contents = contents + kid.get_contents()
+ return contents
+
+ get_contents = get_text_contents ###TODO should return 'bytes' value
+
+ def changed_since_last_build(self, target, prev_ni):
+ cur_csig = self.get_csig()
+ try:
+ return cur_csig != prev_ni.csig
+ except AttributeError:
+ return 1
+
+ def get_csig(self, calc=None):
+ """Because we're a Python value node and don't have a real
+ timestamp, we get to ignore the calculator and just use the
+ value contents."""
+ try:
+ return self.ninfo.csig
+ except AttributeError:
+ pass
+ contents = self.get_contents()
+ self.get_ninfo().csig = contents
+ return contents
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Node/__init__.py b/couchjs/scons/scons-local-2.0.1/SCons/Node/__init__.py
new file mode 100644
index 00000000..b7377987
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Node/__init__.py
@@ -0,0 +1,1328 @@
+"""SCons.Node
+
+The Node package for the SCons software construction utility.
+
+This is, in many ways, the heart of SCons.
+
+A Node is where we encapsulate all of the dependency information about
+any thing that SCons can build, or about any thing which SCons can use
+to build some other thing. The canonical "thing," of course, is a file,
+but a Node can also represent something remote (like a web page) or
+something completely abstract (like an Alias).
+
+Each specific type of "thing" is specifically represented by a subclass
+of the Node base class: Node.FS.File for files, Node.Alias for aliases,
+etc. Dependency information is kept here in the base class, and
+information specific to files/aliases/etc. is in the subclass. The
+goal, if we've done this correctly, is that any type of "thing" should
+be able to depend on any other type of "thing."
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Node/__init__.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import collections
+import copy
+from itertools import chain
+
+from SCons.Debug import logInstanceCreation
+import SCons.Executor
+import SCons.Memoize
+import SCons.Util
+
+from SCons.Debug import Trace
+
+def classname(obj):
+ return str(obj.__class__).split('.')[-1]
+
+# Node states
+#
+# These are in "priority" order, so that the maximum value for any
+# child/dependency of a node represents the state of that node if
+# it has no builder of its own. The canonical example is a file
+# system directory, which is only up to date if all of its children
+# were up to date.
+no_state = 0
+pending = 1
+executing = 2
+up_to_date = 3
+executed = 4
+failed = 5
+
+StateString = {
+ 0 : "no_state",
+ 1 : "pending",
+ 2 : "executing",
+ 3 : "up_to_date",
+ 4 : "executed",
+ 5 : "failed",
+}
+
+# controls whether implicit dependencies are cached:
+implicit_cache = 0
+
+# controls whether implicit dep changes are ignored:
+implicit_deps_unchanged = 0
+
+# controls whether the cached implicit deps are ignored:
+implicit_deps_changed = 0
+
+# A variable that can be set to an interface-specific function be called
+# to annotate a Node with information about its creation.
+def do_nothing(node): pass
+
+Annotate = do_nothing
+
+# Classes for signature info for Nodes.
+
+class NodeInfoBase(object):
+ """
+ The generic base class for signature information for a Node.
+
+ Node subclasses should subclass NodeInfoBase to provide their own
+ logic for dealing with their own Node-specific signature information.
+ """
+ current_version_id = 1
+ def __init__(self, node=None):
+ # Create an object attribute from the class attribute so it ends up
+ # in the pickled data in the .sconsign file.
+ self._version_id = self.current_version_id
+ def update(self, node):
+ try:
+ field_list = self.field_list
+ except AttributeError:
+ return
+ for f in field_list:
+ try:
+ delattr(self, f)
+ except AttributeError:
+ pass
+ try:
+ func = getattr(node, 'get_' + f)
+ except AttributeError:
+ pass
+ else:
+ setattr(self, f, func())
+ def convert(self, node, val):
+ pass
+ def merge(self, other):
+ self.__dict__.update(other.__dict__)
+ def format(self, field_list=None, names=0):
+ if field_list is None:
+ try:
+ field_list = self.field_list
+ except AttributeError:
+ field_list = sorted(self.__dict__.keys())
+ fields = []
+ for field in field_list:
+ try:
+ f = getattr(self, field)
+ except AttributeError:
+ f = None
+ f = str(f)
+ if names:
+ f = field + ': ' + f
+ fields.append(f)
+ return fields
+
+class BuildInfoBase(object):
+ """
+ The generic base class for build information for a Node.
+
+ This is what gets stored in a .sconsign file for each target file.
+ It contains a NodeInfo instance for this node (signature information
+ that's specific to the type of Node) and direct attributes for the
+ generic build stuff we have to track: sources, explicit dependencies,
+ implicit dependencies, and action information.
+ """
+ current_version_id = 1
+ def __init__(self, node=None):
+ # Create an object attribute from the class attribute so it ends up
+ # in the pickled data in the .sconsign file.
+ self._version_id = self.current_version_id
+ self.bsourcesigs = []
+ self.bdependsigs = []
+ self.bimplicitsigs = []
+ self.bactsig = None
+ def merge(self, other):
+ self.__dict__.update(other.__dict__)
+
+class Node(object):
+ """The base Node class, for entities that we know how to
+ build, or use to build other Nodes.
+ """
+
+ if SCons.Memoize.use_memoizer:
+ __metaclass__ = SCons.Memoize.Memoized_Metaclass
+
+ memoizer_counters = []
+
+ class Attrs(object):
+ pass
+
+ def __init__(self):
+ if __debug__: logInstanceCreation(self, 'Node.Node')
+ # Note that we no longer explicitly initialize a self.builder
+ # attribute to None here. That's because the self.builder
+ # attribute may be created on-the-fly later by a subclass (the
+ # canonical example being a builder to fetch a file from a
+ # source code system like CVS or Subversion).
+
+ # Each list of children that we maintain is accompanied by a
+ # dictionary used to look up quickly whether a node is already
+ # present in the list. Empirical tests showed that it was
+ # fastest to maintain them as side-by-side Node attributes in
+ # this way, instead of wrapping up each list+dictionary pair in
+ # a class. (Of course, we could always still do that in the
+ # future if we had a good reason to...).
+ self.sources = [] # source files used to build node
+ self.sources_set = set()
+ self._specific_sources = False
+ self.depends = [] # explicit dependencies (from Depends)
+ self.depends_set = set()
+ self.ignore = [] # dependencies to ignore
+ self.ignore_set = set()
+ self.prerequisites = SCons.Util.UniqueList()
+ self.implicit = None # implicit (scanned) dependencies (None means not scanned yet)
+ self.waiting_parents = set()
+ self.waiting_s_e = set()
+ self.ref_count = 0
+ self.wkids = None # Kids yet to walk, when it's an array
+
+ self.env = None
+ self.state = no_state
+ self.precious = None
+ self.noclean = 0
+ self.nocache = 0
+ self.always_build = None
+ self.includes = None
+ self.attributes = self.Attrs() # Generic place to stick information about the Node.
+ self.side_effect = 0 # true iff this node is a side effect
+ self.side_effects = [] # the side effects of building this target
+ self.linked = 0 # is this node linked to the variant directory?
+
+ self.clear_memoized_values()
+
+ # Let the interface in which the build engine is embedded
+ # annotate this Node with its own info (like a description of
+ # what line in what file created the node, for example).
+ Annotate(self)
+
+ def disambiguate(self, must_exist=None):
+ return self
+
+ def get_suffix(self):
+ return ''
+
+ memoizer_counters.append(SCons.Memoize.CountValue('get_build_env'))
+
+ def get_build_env(self):
+ """Fetch the appropriate Environment to build this node.
+ """
+ try:
+ return self._memo['get_build_env']
+ except KeyError:
+ pass
+ result = self.get_executor().get_build_env()
+ self._memo['get_build_env'] = result
+ return result
+
+ def get_build_scanner_path(self, scanner):
+ """Fetch the appropriate scanner path for this node."""
+ return self.get_executor().get_build_scanner_path(scanner)
+
+ def set_executor(self, executor):
+ """Set the action executor for this node."""
+ self.executor = executor
+
+ def get_executor(self, create=1):
+ """Fetch the action executor for this node. Create one if
+ there isn't already one, and requested to do so."""
+ try:
+ executor = self.executor
+ except AttributeError:
+ if not create:
+ raise
+ try:
+ act = self.builder.action
+ except AttributeError:
+ executor = SCons.Executor.Null(targets=[self])
+ else:
+ executor = SCons.Executor.Executor(act,
+ self.env or self.builder.env,
+ [self.builder.overrides],
+ [self],
+ self.sources)
+ self.executor = executor
+ return executor
+
+ def executor_cleanup(self):
+ """Let the executor clean up any cached information."""
+ try:
+ executor = self.get_executor(create=None)
+ except AttributeError:
+ pass
+ else:
+ executor.cleanup()
+
+ def reset_executor(self):
+ "Remove cached executor; forces recompute when needed."
+ try:
+ delattr(self, 'executor')
+ except AttributeError:
+ pass
+
+ def push_to_cache(self):
+ """Try to push a node into a cache
+ """
+ pass
+
+ def retrieve_from_cache(self):
+ """Try to retrieve the node's content from a cache
+
+ This method is called from multiple threads in a parallel build,
+ so only do thread safe stuff here. Do thread unsafe stuff in
+ built().
+
+ Returns true iff the node was successfully retrieved.
+ """
+ return 0
+
+ #
+ # Taskmaster interface subsystem
+ #
+
+ def make_ready(self):
+ """Get a Node ready for evaluation.
+
+ This is called before the Taskmaster decides if the Node is
+ up-to-date or not. Overriding this method allows for a Node
+ subclass to be disambiguated if necessary, or for an implicit
+ source builder to be attached.
+ """
+ pass
+
+ def prepare(self):
+ """Prepare for this Node to be built.
+
+ This is called after the Taskmaster has decided that the Node
+ is out-of-date and must be rebuilt, but before actually calling
+ the method to build the Node.
+
+ This default implementation checks that explicit or implicit
+ dependencies either exist or are derived, and initializes the
+ BuildInfo structure that will hold the information about how
+ this node is, uh, built.
+
+ (The existence of source files is checked separately by the
+ Executor, which aggregates checks for all of the targets built
+ by a specific action.)
+
+ Overriding this method allows for for a Node subclass to remove
+ the underlying file from the file system. Note that subclass
+ methods should call this base class method to get the child
+ check and the BuildInfo structure.
+ """
+ for d in self.depends:
+ if d.missing():
+ msg = "Explicit dependency `%s' not found, needed by target `%s'."
+ raise SCons.Errors.StopError(msg % (d, self))
+ if self.implicit is not None:
+ for i in self.implicit:
+ if i.missing():
+ msg = "Implicit dependency `%s' not found, needed by target `%s'."
+ raise SCons.Errors.StopError(msg % (i, self))
+ self.binfo = self.get_binfo()
+
+ def build(self, **kw):
+ """Actually build the node.
+
+ This is called by the Taskmaster after it's decided that the
+ Node is out-of-date and must be rebuilt, and after the prepare()
+ method has gotten everything, uh, prepared.
+
+ This method is called from multiple threads in a parallel build,
+ so only do thread safe stuff here. Do thread unsafe stuff
+ in built().
+
+ """
+ try:
+ self.get_executor()(self, **kw)
+ except SCons.Errors.BuildError, e:
+ e.node = self
+ raise
+
+ def built(self):
+ """Called just after this node is successfully built."""
+
+ # Clear the implicit dependency caches of any Nodes
+ # waiting for this Node to be built.
+ for parent in self.waiting_parents:
+ parent.implicit = None
+
+ self.clear()
+
+ self.ninfo.update(self)
+
+ def visited(self):
+ """Called just after this node has been visited (with or
+ without a build)."""
+ try:
+ binfo = self.binfo
+ except AttributeError:
+ # Apparently this node doesn't need build info, so
+ # don't bother calculating or storing it.
+ pass
+ else:
+ self.ninfo.update(self)
+ self.store_info()
+
+ #
+ #
+ #
+
+ def add_to_waiting_s_e(self, node):
+ self.waiting_s_e.add(node)
+
+ def add_to_waiting_parents(self, node):
+ """
+ Returns the number of nodes added to our waiting parents list:
+ 1 if we add a unique waiting parent, 0 if not. (Note that the
+ returned values are intended to be used to increment a reference
+ count, so don't think you can "clean up" this function by using
+ True and False instead...)
+ """
+ wp = self.waiting_parents
+ if node in wp:
+ return 0
+ wp.add(node)
+ return 1
+
+ def postprocess(self):
+ """Clean up anything we don't need to hang onto after we've
+ been built."""
+ self.executor_cleanup()
+ self.waiting_parents = set()
+
+ def clear(self):
+ """Completely clear a Node of all its cached state (so that it
+ can be re-evaluated by interfaces that do continuous integration
+ builds).
+ """
+ # The del_binfo() call here isn't necessary for normal execution,
+ # but is for interactive mode, where we might rebuild the same
+ # target and need to start from scratch.
+ self.del_binfo()
+ self.clear_memoized_values()
+ self.ninfo = self.new_ninfo()
+ self.executor_cleanup()
+ try:
+ delattr(self, '_calculated_sig')
+ except AttributeError:
+ pass
+ self.includes = None
+
+ def clear_memoized_values(self):
+ self._memo = {}
+
+ def builder_set(self, builder):
+ self.builder = builder
+ try:
+ del self.executor
+ except AttributeError:
+ pass
+
+ def has_builder(self):
+ """Return whether this Node has a builder or not.
+
+ In Boolean tests, this turns out to be a *lot* more efficient
+ than simply examining the builder attribute directly ("if
+ node.builder: ..."). When the builder attribute is examined
+ directly, it ends up calling __getattr__ for both the __len__
+ and __nonzero__ attributes on instances of our Builder Proxy
+ class(es), generating a bazillion extra calls and slowing
+ things down immensely.
+ """
+ try:
+ b = self.builder
+ except AttributeError:
+ # There was no explicit builder for this Node, so initialize
+ # the self.builder attribute to None now.
+ b = self.builder = None
+ return b is not None
+
+ def set_explicit(self, is_explicit):
+ self.is_explicit = is_explicit
+
+ def has_explicit_builder(self):
+ """Return whether this Node has an explicit builder
+
+ This allows an internal Builder created by SCons to be marked
+ non-explicit, so that it can be overridden by an explicit
+ builder that the user supplies (the canonical example being
+ directories)."""
+ try:
+ return self.is_explicit
+ except AttributeError:
+ self.is_explicit = None
+ return self.is_explicit
+
+ def get_builder(self, default_builder=None):
+ """Return the set builder, or a specified default value"""
+ try:
+ return self.builder
+ except AttributeError:
+ return default_builder
+
+ multiple_side_effect_has_builder = has_builder
+
+ def is_derived(self):
+ """
+ Returns true iff this node is derived (i.e. built).
+
+ This should return true only for nodes whose path should be in
+ the variant directory when duplicate=0 and should contribute their build
+ signatures when they are used as source files to other derived files. For
+ example: source with source builders are not derived in this sense,
+ and hence should not return true.
+ """
+ return self.has_builder() or self.side_effect
+
+ def alter_targets(self):
+ """Return a list of alternate targets for this Node.
+ """
+ return [], None
+
+ def get_found_includes(self, env, scanner, path):
+ """Return the scanned include lines (implicit dependencies)
+ found in this node.
+
+ The default is no implicit dependencies. We expect this method
+ to be overridden by any subclass that can be scanned for
+ implicit dependencies.
+ """
+ return []
+
+ def get_implicit_deps(self, env, scanner, path):
+ """Return a list of implicit dependencies for this node.
+
+ This method exists to handle recursive invocation of the scanner
+ on the implicit dependencies returned by the scanner, if the
+ scanner's recursive flag says that we should.
+ """
+ if not scanner:
+ return []
+
+ # Give the scanner a chance to select a more specific scanner
+ # for this Node.
+ #scanner = scanner.select(self)
+
+ nodes = [self]
+ seen = {}
+ seen[self] = 1
+ deps = []
+ while nodes:
+ n = nodes.pop(0)
+ d = [x for x in n.get_found_includes(env, scanner, path) if x not in seen]
+ if d:
+ deps.extend(d)
+ for n in d:
+ seen[n] = 1
+ nodes.extend(scanner.recurse_nodes(d))
+
+ return deps
+
+ def get_env_scanner(self, env, kw={}):
+ return env.get_scanner(self.scanner_key())
+
+ def get_target_scanner(self):
+ return self.builder.target_scanner
+
+ def get_source_scanner(self, node):
+ """Fetch the source scanner for the specified node
+
+ NOTE: "self" is the target being built, "node" is
+ the source file for which we want to fetch the scanner.
+
+ Implies self.has_builder() is true; again, expect to only be
+ called from locations where this is already verified.
+
+ This function may be called very often; it attempts to cache
+ the scanner found to improve performance.
+ """
+ scanner = None
+ try:
+ scanner = self.builder.source_scanner
+ except AttributeError:
+ pass
+ if not scanner:
+ # The builder didn't have an explicit scanner, so go look up
+ # a scanner from env['SCANNERS'] based on the node's scanner
+ # key (usually the file extension).
+ scanner = self.get_env_scanner(self.get_build_env())
+ if scanner:
+ scanner = scanner.select(node)
+ return scanner
+
+ def add_to_implicit(self, deps):
+ if not hasattr(self, 'implicit') or self.implicit is None:
+ self.implicit = []
+ self.implicit_set = set()
+ self._children_reset()
+ self._add_child(self.implicit, self.implicit_set, deps)
+
+ def scan(self):
+ """Scan this node's dependents for implicit dependencies."""
+ # Don't bother scanning non-derived files, because we don't
+ # care what their dependencies are.
+ # Don't scan again, if we already have scanned.
+ if self.implicit is not None:
+ return
+ self.implicit = []
+ self.implicit_set = set()
+ self._children_reset()
+ if not self.has_builder():
+ return
+
+ build_env = self.get_build_env()
+ executor = self.get_executor()
+
+ # Here's where we implement --implicit-cache.
+ if implicit_cache and not implicit_deps_changed:
+ implicit = self.get_stored_implicit()
+ if implicit is not None:
+ # We now add the implicit dependencies returned from the
+ # stored .sconsign entry to have already been converted
+ # to Nodes for us. (We used to run them through a
+ # source_factory function here.)
+
+ # Update all of the targets with them. This
+ # essentially short-circuits an N*M scan of the
+ # sources for each individual target, which is a hell
+ # of a lot more efficient.
+ for tgt in executor.get_all_targets():
+ tgt.add_to_implicit(implicit)
+
+ if implicit_deps_unchanged or self.is_up_to_date():
+ return
+ # one of this node's sources has changed,
+ # so we must recalculate the implicit deps:
+ self.implicit = []
+ self.implicit_set = set()
+
+ # Have the executor scan the sources.
+ executor.scan_sources(self.builder.source_scanner)
+
+ # If there's a target scanner, have the executor scan the target
+ # node itself and associated targets that might be built.
+ scanner = self.get_target_scanner()
+ if scanner:
+ executor.scan_targets(scanner)
+
+ def scanner_key(self):
+ return None
+
+ def select_scanner(self, scanner):
+ """Selects a scanner for this Node.
+
+ This is a separate method so it can be overridden by Node
+ subclasses (specifically, Node.FS.Dir) that *must* use their
+ own Scanner and don't select one the Scanner.Selector that's
+ configured for the target.
+ """
+ return scanner.select(self)
+
+ def env_set(self, env, safe=0):
+ if safe and self.env:
+ return
+ self.env = env
+
+ #
+ # SIGNATURE SUBSYSTEM
+ #
+
+ NodeInfo = NodeInfoBase
+ BuildInfo = BuildInfoBase
+
+ def new_ninfo(self):
+ ninfo = self.NodeInfo(self)
+ return ninfo
+
+ def get_ninfo(self):
+ try:
+ return self.ninfo
+ except AttributeError:
+ self.ninfo = self.new_ninfo()
+ return self.ninfo
+
+ def new_binfo(self):
+ binfo = self.BuildInfo(self)
+ return binfo
+
+ def get_binfo(self):
+ """
+ Fetch a node's build information.
+
+ node - the node whose sources will be collected
+ cache - alternate node to use for the signature cache
+ returns - the build signature
+
+ This no longer handles the recursive descent of the
+ node's children's signatures. We expect that they're
+ already built and updated by someone else, if that's
+ what's wanted.
+ """
+ try:
+ return self.binfo
+ except AttributeError:
+ pass
+
+ binfo = self.new_binfo()
+ self.binfo = binfo
+
+ executor = self.get_executor()
+ ignore_set = self.ignore_set
+
+ if self.has_builder():
+ binfo.bact = str(executor)
+ binfo.bactsig = SCons.Util.MD5signature(executor.get_contents())
+
+ if self._specific_sources:
+ sources = []
+ for s in self.sources:
+ if s not in ignore_set:
+ sources.append(s)
+ else:
+ sources = executor.get_unignored_sources(self, self.ignore)
+ seen = set()
+ bsources = []
+ bsourcesigs = []
+ for s in sources:
+ if not s in seen:
+ seen.add(s)
+ bsources.append(s)
+ bsourcesigs.append(s.get_ninfo())
+ binfo.bsources = bsources
+ binfo.bsourcesigs = bsourcesigs
+
+ depends = self.depends
+ dependsigs = []
+ for d in depends:
+ if d not in ignore_set:
+ dependsigs.append(d.get_ninfo())
+ binfo.bdepends = depends
+ binfo.bdependsigs = dependsigs
+
+ implicit = self.implicit or []
+ implicitsigs = []
+ for i in implicit:
+ if i not in ignore_set:
+ implicitsigs.append(i.get_ninfo())
+ binfo.bimplicit = implicit
+ binfo.bimplicitsigs = implicitsigs
+
+ return binfo
+
+ def del_binfo(self):
+ """Delete the build info from this node."""
+ try:
+ delattr(self, 'binfo')
+ except AttributeError:
+ pass
+
+ def get_csig(self):
+ try:
+ return self.ninfo.csig
+ except AttributeError:
+ ninfo = self.get_ninfo()
+ ninfo.csig = SCons.Util.MD5signature(self.get_contents())
+ return self.ninfo.csig
+
+ def get_cachedir_csig(self):
+ return self.get_csig()
+
+ def store_info(self):
+ """Make the build signature permanent (that is, store it in the
+ .sconsign file or equivalent)."""
+ pass
+
+ def do_not_store_info(self):
+ pass
+
+ def get_stored_info(self):
+ return None
+
+ def get_stored_implicit(self):
+ """Fetch the stored implicit dependencies"""
+ return None
+
+ #
+ #
+ #
+
+ def set_precious(self, precious = 1):
+ """Set the Node's precious value."""
+ self.precious = precious
+
+ def set_noclean(self, noclean = 1):
+ """Set the Node's noclean value."""
+ # Make sure noclean is an integer so the --debug=stree
+ # output in Util.py can use it as an index.
+ self.noclean = noclean and 1 or 0
+
+ def set_nocache(self, nocache = 1):
+ """Set the Node's nocache value."""
+ # Make sure nocache is an integer so the --debug=stree
+ # output in Util.py can use it as an index.
+ self.nocache = nocache and 1 or 0
+
+ def set_always_build(self, always_build = 1):
+ """Set the Node's always_build value."""
+ self.always_build = always_build
+
+ def exists(self):
+ """Does this node exists?"""
+ # All node exist by default:
+ return 1
+
+ def rexists(self):
+ """Does this node exist locally or in a repositiory?"""
+ # There are no repositories by default:
+ return self.exists()
+
+ def missing(self):
+ return not self.is_derived() and \
+ not self.linked and \
+ not self.rexists()
+
+ def remove(self):
+ """Remove this Node: no-op by default."""
+ return None
+
+ def add_dependency(self, depend):
+ """Adds dependencies."""
+ try:
+ self._add_child(self.depends, self.depends_set, depend)
+ except TypeError, e:
+ e = e.args[0]
+ if SCons.Util.is_List(e):
+ s = list(map(str, e))
+ else:
+ s = str(e)
+ raise SCons.Errors.UserError("attempted to add a non-Node dependency to %s:\n\t%s is a %s, not a Node" % (str(self), s, type(e)))
+
+ def add_prerequisite(self, prerequisite):
+ """Adds prerequisites"""
+ self.prerequisites.extend(prerequisite)
+ self._children_reset()
+
+ def add_ignore(self, depend):
+ """Adds dependencies to ignore."""
+ try:
+ self._add_child(self.ignore, self.ignore_set, depend)
+ except TypeError, e:
+ e = e.args[0]
+ if SCons.Util.is_List(e):
+ s = list(map(str, e))
+ else:
+ s = str(e)
+ raise SCons.Errors.UserError("attempted to ignore a non-Node dependency of %s:\n\t%s is a %s, not a Node" % (str(self), s, type(e)))
+
+ def add_source(self, source):
+ """Adds sources."""
+ if self._specific_sources:
+ return
+ try:
+ self._add_child(self.sources, self.sources_set, source)
+ except TypeError, e:
+ e = e.args[0]
+ if SCons.Util.is_List(e):
+ s = list(map(str, e))
+ else:
+ s = str(e)
+ raise SCons.Errors.UserError("attempted to add a non-Node as source of %s:\n\t%s is a %s, not a Node" % (str(self), s, type(e)))
+
+ def _add_child(self, collection, set, child):
+ """Adds 'child' to 'collection', first checking 'set' to see if it's
+ already present."""
+ #if type(child) is not type([]):
+ # child = [child]
+ #for c in child:
+ # if not isinstance(c, Node):
+ # raise TypeError, c
+ added = None
+ for c in child:
+ if c not in set:
+ set.add(c)
+ collection.append(c)
+ added = 1
+ if added:
+ self._children_reset()
+
+ def set_specific_source(self, source):
+ self.add_source(source)
+ self._specific_sources = True
+
+ def add_wkid(self, wkid):
+ """Add a node to the list of kids waiting to be evaluated"""
+ if self.wkids is not None:
+ self.wkids.append(wkid)
+
+ def _children_reset(self):
+ self.clear_memoized_values()
+ # We need to let the Executor clear out any calculated
+ # build info that it's cached so we can re-calculate it.
+ self.executor_cleanup()
+
+ memoizer_counters.append(SCons.Memoize.CountValue('_children_get'))
+
+ def _children_get(self):
+ try:
+ return self._memo['children_get']
+ except KeyError:
+ pass
+
+ # The return list may contain duplicate Nodes, especially in
+ # source trees where there are a lot of repeated #includes
+ # of a tangle of .h files. Profiling shows, however, that
+ # eliminating the duplicates with a brute-force approach that
+ # preserves the order (that is, something like:
+ #
+ # u = []
+ # for n in list:
+ # if n not in u:
+ # u.append(n)"
+ #
+ # takes more cycles than just letting the underlying methods
+ # hand back cached values if a Node's information is requested
+ # multiple times. (Other methods of removing duplicates, like
+ # using dictionary keys, lose the order, and the only ordered
+ # dictionary patterns I found all ended up using "not in"
+ # internally anyway...)
+ if self.ignore_set:
+ if self.implicit is None:
+ iter = chain(self.sources,self.depends)
+ else:
+ iter = chain(self.sources, self.depends, self.implicit)
+
+ children = []
+ for i in iter:
+ if i not in self.ignore_set:
+ children.append(i)
+ else:
+ if self.implicit is None:
+ children = self.sources + self.depends
+ else:
+ children = self.sources + self.depends + self.implicit
+
+ self._memo['children_get'] = children
+ return children
+
+ def all_children(self, scan=1):
+ """Return a list of all the node's direct children."""
+ if scan:
+ self.scan()
+
+ # The return list may contain duplicate Nodes, especially in
+ # source trees where there are a lot of repeated #includes
+ # of a tangle of .h files. Profiling shows, however, that
+ # eliminating the duplicates with a brute-force approach that
+ # preserves the order (that is, something like:
+ #
+ # u = []
+ # for n in list:
+ # if n not in u:
+ # u.append(n)"
+ #
+ # takes more cycles than just letting the underlying methods
+ # hand back cached values if a Node's information is requested
+ # multiple times. (Other methods of removing duplicates, like
+ # using dictionary keys, lose the order, and the only ordered
+ # dictionary patterns I found all ended up using "not in"
+ # internally anyway...)
+ if self.implicit is None:
+ return self.sources + self.depends
+ else:
+ return self.sources + self.depends + self.implicit
+
+ def children(self, scan=1):
+ """Return a list of the node's direct children, minus those
+ that are ignored by this node."""
+ if scan:
+ self.scan()
+ return self._children_get()
+
+ def set_state(self, state):
+ self.state = state
+
+ def get_state(self):
+ return self.state
+
+ def state_has_changed(self, target, prev_ni):
+ return (self.state != SCons.Node.up_to_date)
+
+ def get_env(self):
+ env = self.env
+ if not env:
+ import SCons.Defaults
+ env = SCons.Defaults.DefaultEnvironment()
+ return env
+
+ def changed_since_last_build(self, target, prev_ni):
+ """
+
+ Must be overridden in a specific subclass to return True if this
+ Node (a dependency) has changed since the last time it was used
+ to build the specified target. prev_ni is this Node's state (for
+ example, its file timestamp, length, maybe content signature)
+ as of the last time the target was built.
+
+ Note that this method is called through the dependency, not the
+ target, because a dependency Node must be able to use its own
+ logic to decide if it changed. For example, File Nodes need to
+ obey if we're configured to use timestamps, but Python Value Nodes
+ never use timestamps and always use the content. If this method
+ were called through the target, then each Node's implementation
+ of this method would have to have more complicated logic to
+ handle all the different Node types on which it might depend.
+ """
+ raise NotImplementedError
+
+ def Decider(self, function):
+ SCons.Util.AddMethod(self, function, 'changed_since_last_build')
+
+ def changed(self, node=None):
+ """
+ Returns if the node is up-to-date with respect to the BuildInfo
+ stored last time it was built. The default behavior is to compare
+ it against our own previously stored BuildInfo, but the stored
+ BuildInfo from another Node (typically one in a Repository)
+ can be used instead.
+
+ Note that we now *always* check every dependency. We used to
+ short-circuit the check by returning as soon as we detected
+ any difference, but we now rely on checking every dependency
+ to make sure that any necessary Node information (for example,
+ the content signature of an #included .h file) is updated.
+ """
+ t = 0
+ if t: Trace('changed(%s [%s], %s)' % (self, classname(self), node))
+ if node is None:
+ node = self
+
+ result = False
+
+ bi = node.get_stored_info().binfo
+ then = bi.bsourcesigs + bi.bdependsigs + bi.bimplicitsigs
+ children = self.children()
+
+ diff = len(children) - len(then)
+ if diff:
+ # The old and new dependency lists are different lengths.
+ # This always indicates that the Node must be rebuilt.
+ # We also extend the old dependency list with enough None
+ # entries to equal the new dependency list, for the benefit
+ # of the loop below that updates node information.
+ then.extend([None] * diff)
+ if t: Trace(': old %s new %s' % (len(then), len(children)))
+ result = True
+
+ for child, prev_ni in zip(children, then):
+ if child.changed_since_last_build(self, prev_ni):
+ if t: Trace(': %s changed' % child)
+ result = True
+
+ contents = self.get_executor().get_contents()
+ if self.has_builder():
+ import SCons.Util
+ newsig = SCons.Util.MD5signature(contents)
+ if bi.bactsig != newsig:
+ if t: Trace(': bactsig %s != newsig %s' % (bi.bactsig, newsig))
+ result = True
+
+ if not result:
+ if t: Trace(': up to date')
+
+ if t: Trace('\n')
+
+ return result
+
+ def is_up_to_date(self):
+ """Default check for whether the Node is current: unknown Node
+ subtypes are always out of date, so they will always get built."""
+ return None
+
+ def children_are_up_to_date(self):
+ """Alternate check for whether the Node is current: If all of
+ our children were up-to-date, then this Node was up-to-date, too.
+
+ The SCons.Node.Alias and SCons.Node.Python.Value subclasses
+ rebind their current() method to this method."""
+ # Allow the children to calculate their signatures.
+ self.binfo = self.get_binfo()
+ if self.always_build:
+ return None
+ state = 0
+ for kid in self.children(None):
+ s = kid.get_state()
+ if s and (not state or s > state):
+ state = s
+ return (state == 0 or state == SCons.Node.up_to_date)
+
+ def is_literal(self):
+ """Always pass the string representation of a Node to
+ the command interpreter literally."""
+ return 1
+
+ def render_include_tree(self):
+ """
+ Return a text representation, suitable for displaying to the
+ user, of the include tree for the sources of this node.
+ """
+ if self.is_derived() and self.env:
+ env = self.get_build_env()
+ for s in self.sources:
+ scanner = self.get_source_scanner(s)
+ if scanner:
+ path = self.get_build_scanner_path(scanner)
+ else:
+ path = None
+ def f(node, env=env, scanner=scanner, path=path):
+ return node.get_found_includes(env, scanner, path)
+ return SCons.Util.render_tree(s, f, 1)
+ else:
+ return None
+
+ def get_abspath(self):
+ """
+ Return an absolute path to the Node. This will return simply
+ str(Node) by default, but for Node types that have a concept of
+ relative path, this might return something different.
+ """
+ return str(self)
+
+ def for_signature(self):
+ """
+ Return a string representation of the Node that will always
+ be the same for this particular Node, no matter what. This
+ is by contrast to the __str__() method, which might, for
+ instance, return a relative path for a file Node. The purpose
+ of this method is to generate a value to be used in signature
+ calculation for the command line used to build a target, and
+ we use this method instead of str() to avoid unnecessary
+ rebuilds. This method does not need to return something that
+ would actually work in a command line; it can return any kind of
+ nonsense, so long as it does not change.
+ """
+ return str(self)
+
+ def get_string(self, for_signature):
+ """This is a convenience function designed primarily to be
+ used in command generators (i.e., CommandGeneratorActions or
+ Environment variables that are callable), which are called
+ with a for_signature argument that is nonzero if the command
+ generator is being called to generate a signature for the
+ command line, which determines if we should rebuild or not.
+
+ Such command generators should use this method in preference
+ to str(Node) when converting a Node to a string, passing
+ in the for_signature parameter, such that we will call
+ Node.for_signature() or str(Node) properly, depending on whether
+ we are calculating a signature or actually constructing a
+ command line."""
+ if for_signature:
+ return self.for_signature()
+ return str(self)
+
+ def get_subst_proxy(self):
+ """
+ This method is expected to return an object that will function
+ exactly like this Node, except that it implements any additional
+ special features that we would like to be in effect for
+ Environment variable substitution. The principle use is that
+ some Nodes would like to implement a __getattr__() method,
+ but putting that in the Node type itself has a tendency to kill
+ performance. We instead put it in a proxy and return it from
+ this method. It is legal for this method to return self
+ if no new functionality is needed for Environment substitution.
+ """
+ return self
+
+ def explain(self):
+ if not self.exists():
+ return "building `%s' because it doesn't exist\n" % self
+
+ if self.always_build:
+ return "rebuilding `%s' because AlwaysBuild() is specified\n" % self
+
+ old = self.get_stored_info()
+ if old is None:
+ return None
+
+ old = old.binfo
+ old.prepare_dependencies()
+
+ try:
+ old_bkids = old.bsources + old.bdepends + old.bimplicit
+ old_bkidsigs = old.bsourcesigs + old.bdependsigs + old.bimplicitsigs
+ except AttributeError:
+ return "Cannot explain why `%s' is being rebuilt: No previous build information found\n" % self
+
+ new = self.get_binfo()
+
+ new_bkids = new.bsources + new.bdepends + new.bimplicit
+ new_bkidsigs = new.bsourcesigs + new.bdependsigs + new.bimplicitsigs
+
+ osig = dict(zip(old_bkids, old_bkidsigs))
+ nsig = dict(zip(new_bkids, new_bkidsigs))
+
+ # The sources and dependencies we'll want to report are all stored
+ # as relative paths to this target's directory, but we want to
+ # report them relative to the top-level SConstruct directory,
+ # so we only print them after running them through this lambda
+ # to turn them into the right relative Node and then return
+ # its string.
+ def stringify( s, E=self.dir.Entry ) :
+ if hasattr( s, 'dir' ) :
+ return str(E(s))
+ return str(s)
+
+ lines = []
+
+ removed = [x for x in old_bkids if not x in new_bkids]
+ if removed:
+ removed = list(map(stringify, removed))
+ fmt = "`%s' is no longer a dependency\n"
+ lines.extend([fmt % s for s in removed])
+
+ for k in new_bkids:
+ if not k in old_bkids:
+ lines.append("`%s' is a new dependency\n" % stringify(k))
+ elif k.changed_since_last_build(self, osig[k]):
+ lines.append("`%s' changed\n" % stringify(k))
+
+ if len(lines) == 0 and old_bkids != new_bkids:
+ lines.append("the dependency order changed:\n" +
+ "%sold: %s\n" % (' '*15, list(map(stringify, old_bkids))) +
+ "%snew: %s\n" % (' '*15, list(map(stringify, new_bkids))))
+
+ if len(lines) == 0:
+ def fmt_with_title(title, strlines):
+ lines = strlines.split('\n')
+ sep = '\n' + ' '*(15 + len(title))
+ return ' '*15 + title + sep.join(lines) + '\n'
+ if old.bactsig != new.bactsig:
+ if old.bact == new.bact:
+ lines.append("the contents of the build action changed\n" +
+ fmt_with_title('action: ', new.bact))
+ else:
+ lines.append("the build action changed:\n" +
+ fmt_with_title('old: ', old.bact) +
+ fmt_with_title('new: ', new.bact))
+
+ if len(lines) == 0:
+ return "rebuilding `%s' for unknown reasons\n" % self
+
+ preamble = "rebuilding `%s' because" % self
+ if len(lines) == 1:
+ return "%s %s" % (preamble, lines[0])
+ else:
+ lines = ["%s:\n" % preamble] + lines
+ return ( ' '*11).join(lines)
+
+class NodeList(collections.UserList):
+ def __str__(self):
+ return str(list(map(str, self.data)))
+
+def get_children(node, parent): return node.children()
+def ignore_cycle(node, stack): pass
+def do_nothing(node, parent): pass
+
+class Walker(object):
+ """An iterator for walking a Node tree.
+
+ This is depth-first, children are visited before the parent.
+ The Walker object can be initialized with any node, and
+ returns the next node on the descent with each get_next() call.
+ 'kids_func' is an optional function that will be called to
+ get the children of a node instead of calling 'children'.
+ 'cycle_func' is an optional function that will be called
+ when a cycle is detected.
+
+ This class does not get caught in node cycles caused, for example,
+ by C header file include loops.
+ """
+ def __init__(self, node, kids_func=get_children,
+ cycle_func=ignore_cycle,
+ eval_func=do_nothing):
+ self.kids_func = kids_func
+ self.cycle_func = cycle_func
+ self.eval_func = eval_func
+ node.wkids = copy.copy(kids_func(node, None))
+ self.stack = [node]
+ self.history = {} # used to efficiently detect and avoid cycles
+ self.history[node] = None
+
+ def get_next(self):
+ """Return the next node for this walk of the tree.
+
+ This function is intentionally iterative, not recursive,
+ to sidestep any issues of stack size limitations.
+ """
+
+ while self.stack:
+ if self.stack[-1].wkids:
+ node = self.stack[-1].wkids.pop(0)
+ if not self.stack[-1].wkids:
+ self.stack[-1].wkids = None
+ if node in self.history:
+ self.cycle_func(node, self.stack)
+ else:
+ node.wkids = copy.copy(self.kids_func(node, self.stack[-1]))
+ self.stack.append(node)
+ self.history[node] = None
+ else:
+ node = self.stack.pop()
+ del self.history[node]
+ if node:
+ if self.stack:
+ parent = self.stack[-1]
+ else:
+ parent = None
+ self.eval_func(node, parent)
+ return node
+ return None
+
+ def is_done(self):
+ return not self.stack
+
+
+arg2nodes_lookups = []
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Options/BoolOption.py b/couchjs/scons/scons-local-2.0.1/SCons/Options/BoolOption.py
new file mode 100644
index 00000000..46099672
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Options/BoolOption.py
@@ -0,0 +1,50 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Options/BoolOption.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__doc__ = """Place-holder for the old SCons.Options module hierarchy
+
+This is for backwards compatibility. The new equivalent is the Variables/
+class hierarchy. These will have deprecation warnings added (some day),
+and will then be removed entirely (some day).
+"""
+
+import SCons.Variables
+import SCons.Warnings
+
+warned = False
+
+def BoolOption(*args, **kw):
+ global warned
+ if not warned:
+ msg = "The BoolOption() function is deprecated; use the BoolVariable() function instead."
+ SCons.Warnings.warn(SCons.Warnings.DeprecatedOptionsWarning, msg)
+ warned = True
+ return SCons.Variables.BoolVariable(*args, **kw)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Options/EnumOption.py b/couchjs/scons/scons-local-2.0.1/SCons/Options/EnumOption.py
new file mode 100644
index 00000000..1357984c
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Options/EnumOption.py
@@ -0,0 +1,50 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Options/EnumOption.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__doc__ = """Place-holder for the old SCons.Options module hierarchy
+
+This is for backwards compatibility. The new equivalent is the Variables/
+class hierarchy. These will have deprecation warnings added (some day),
+and will then be removed entirely (some day).
+"""
+
+import SCons.Variables
+import SCons.Warnings
+
+warned = False
+
+def EnumOption(*args, **kw):
+ global warned
+ if not warned:
+ msg = "The EnumOption() function is deprecated; use the EnumVariable() function instead."
+ SCons.Warnings.warn(SCons.Warnings.DeprecatedOptionsWarning, msg)
+ warned = True
+ return SCons.Variables.EnumVariable(*args, **kw)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Options/ListOption.py b/couchjs/scons/scons-local-2.0.1/SCons/Options/ListOption.py
new file mode 100644
index 00000000..1f34cd6d
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Options/ListOption.py
@@ -0,0 +1,50 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Options/ListOption.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__doc__ = """Place-holder for the old SCons.Options module hierarchy
+
+This is for backwards compatibility. The new equivalent is the Variables/
+class hierarchy. These will have deprecation warnings added (some day),
+and will then be removed entirely (some day).
+"""
+
+import SCons.Variables
+import SCons.Warnings
+
+warned = False
+
+def ListOption(*args, **kw):
+ global warned
+ if not warned:
+ msg = "The ListOption() function is deprecated; use the ListVariable() function instead."
+ SCons.Warnings.warn(SCons.Warnings.DeprecatedOptionsWarning, msg)
+ warned = True
+ return SCons.Variables.ListVariable(*args, **kw)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Options/PackageOption.py b/couchjs/scons/scons-local-2.0.1/SCons/Options/PackageOption.py
new file mode 100644
index 00000000..1bb88b1d
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Options/PackageOption.py
@@ -0,0 +1,50 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Options/PackageOption.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__doc__ = """Place-holder for the old SCons.Options module hierarchy
+
+This is for backwards compatibility. The new equivalent is the Variables/
+class hierarchy. These will have deprecation warnings added (some day),
+and will then be removed entirely (some day).
+"""
+
+import SCons.Variables
+import SCons.Warnings
+
+warned = False
+
+def PackageOption(*args, **kw):
+ global warned
+ if not warned:
+ msg = "The PackageOption() function is deprecated; use the PackageVariable() function instead."
+ SCons.Warnings.warn(SCons.Warnings.DeprecatedOptionsWarning, msg)
+ warned = True
+ return SCons.Variables.PackageVariable(*args, **kw)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Options/PathOption.py b/couchjs/scons/scons-local-2.0.1/SCons/Options/PathOption.py
new file mode 100644
index 00000000..2e38de3e
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Options/PathOption.py
@@ -0,0 +1,76 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Options/PathOption.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__doc__ = """Place-holder for the old SCons.Options module hierarchy
+
+This is for backwards compatibility. The new equivalent is the Variables/
+class hierarchy. These will have deprecation warnings added (some day),
+and will then be removed entirely (some day).
+"""
+
+import SCons.Variables
+import SCons.Warnings
+
+warned = False
+
+class _PathOptionClass(object):
+ def warn(self):
+ global warned
+ if not warned:
+ msg = "The PathOption() function is deprecated; use the PathVariable() function instead."
+ SCons.Warnings.warn(SCons.Warnings.DeprecatedOptionsWarning, msg)
+ warned = True
+
+ def __call__(self, *args, **kw):
+ self.warn()
+ return SCons.Variables.PathVariable(*args, **kw)
+
+ def PathAccept(self, *args, **kw):
+ self.warn()
+ return SCons.Variables.PathVariable.PathAccept(*args, **kw)
+
+ def PathIsDir(self, *args, **kw):
+ self.warn()
+ return SCons.Variables.PathVariable.PathIsDir(*args, **kw)
+
+ def PathIsDirCreate(self, *args, **kw):
+ self.warn()
+ return SCons.Variables.PathVariable.PathIsDirCreate(*args, **kw)
+
+ def PathIsFile(self, *args, **kw):
+ self.warn()
+ return SCons.Variables.PathVariable.PathIsFile(*args, **kw)
+
+ def PathExists(self, *args, **kw):
+ self.warn()
+ return SCons.Variables.PathVariable.PathExists(*args, **kw)
+
+PathOption = _PathOptionClass()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Options/__init__.py b/couchjs/scons/scons-local-2.0.1/SCons/Options/__init__.py
new file mode 100644
index 00000000..edb62732
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Options/__init__.py
@@ -0,0 +1,67 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Options/__init__.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__doc__ = """Place-holder for the old SCons.Options module hierarchy
+
+This is for backwards compatibility. The new equivalent is the Variables/
+class hierarchy. These will have deprecation warnings added (some day),
+and will then be removed entirely (some day).
+"""
+
+import SCons.Variables
+import SCons.Warnings
+
+from BoolOption import BoolOption # okay
+from EnumOption import EnumOption # okay
+from ListOption import ListOption # naja
+from PackageOption import PackageOption # naja
+from PathOption import PathOption # okay
+
+warned = False
+
+class Options(SCons.Variables.Variables):
+ def __init__(self, *args, **kw):
+ global warned
+ if not warned:
+ msg = "The Options class is deprecated; use the Variables class instead."
+ SCons.Warnings.warn(SCons.Warnings.DeprecatedOptionsWarning, msg)
+ warned = True
+ SCons.Variables.Variables.__init__(self, *args, **kw)
+
+ def AddOptions(self, *args, **kw):
+ return SCons.Variables.Variables.AddVariables(self, *args, **kw)
+
+ def UnknownOptions(self, *args, **kw):
+ return SCons.Variables.Variables.UnknownVariables(self, *args, **kw)
+
+ def FormatOptionHelpText(self, *args, **kw):
+ return SCons.Variables.Variables.FormatVariableHelpText(self, *args,
+ **kw)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/PathList.py b/couchjs/scons/scons-local-2.0.1/SCons/PathList.py
new file mode 100644
index 00000000..4b27193f
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/PathList.py
@@ -0,0 +1,231 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/PathList.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__doc__ = """SCons.PathList
+
+A module for handling lists of directory paths (the sort of things
+that get set as CPPPATH, LIBPATH, etc.) with as much caching of data and
+efficiency as we can while still keeping the evaluation delayed so that we
+Do the Right Thing (almost) regardless of how the variable is specified.
+
+"""
+
+import os
+
+import SCons.Memoize
+import SCons.Node
+import SCons.Util
+
+#
+# Variables to specify the different types of entries in a PathList object:
+#
+
+TYPE_STRING_NO_SUBST = 0 # string with no '$'
+TYPE_STRING_SUBST = 1 # string containing '$'
+TYPE_OBJECT = 2 # other object
+
+def node_conv(obj):
+ """
+ This is the "string conversion" routine that we have our substitutions
+ use to return Nodes, not strings. This relies on the fact that an
+ EntryProxy object has a get() method that returns the underlying
+ Node that it wraps, which is a bit of architectural dependence
+ that we might need to break or modify in the future in response to
+ additional requirements.
+ """
+ try:
+ get = obj.get
+ except AttributeError:
+ if isinstance(obj, SCons.Node.Node) or SCons.Util.is_Sequence( obj ):
+ result = obj
+ else:
+ result = str(obj)
+ else:
+ result = get()
+ return result
+
+class _PathList(object):
+ """
+ An actual PathList object.
+ """
+ def __init__(self, pathlist):
+ """
+ Initializes a PathList object, canonicalizing the input and
+ pre-processing it for quicker substitution later.
+
+ The stored representation of the PathList is a list of tuples
+ containing (type, value), where the "type" is one of the TYPE_*
+ variables defined above. We distinguish between:
+
+ strings that contain no '$' and therefore need no
+ delayed-evaluation string substitution (we expect that there
+ will be many of these and that we therefore get a pretty
+ big win from avoiding string substitution)
+
+ strings that contain '$' and therefore need substitution
+ (the hard case is things like '${TARGET.dir}/include',
+ which require re-evaluation for every target + source)
+
+ other objects (which may be something like an EntryProxy
+ that needs a method called to return a Node)
+
+ Pre-identifying the type of each element in the PathList up-front
+ and storing the type in the list of tuples is intended to reduce
+ the amount of calculation when we actually do the substitution
+ over and over for each target.
+ """
+ if SCons.Util.is_String(pathlist):
+ pathlist = pathlist.split(os.pathsep)
+ elif not SCons.Util.is_Sequence(pathlist):
+ pathlist = [pathlist]
+
+ pl = []
+ for p in pathlist:
+ try:
+ index = p.find('$')
+ except (AttributeError, TypeError):
+ type = TYPE_OBJECT
+ else:
+ if index == -1:
+ type = TYPE_STRING_NO_SUBST
+ else:
+ type = TYPE_STRING_SUBST
+ pl.append((type, p))
+
+ self.pathlist = tuple(pl)
+
+ def __len__(self): return len(self.pathlist)
+
+ def __getitem__(self, i): return self.pathlist[i]
+
+ def subst_path(self, env, target, source):
+ """
+ Performs construction variable substitution on a pre-digested
+ PathList for a specific target and source.
+ """
+ result = []
+ for type, value in self.pathlist:
+ if type == TYPE_STRING_SUBST:
+ value = env.subst(value, target=target, source=source,
+ conv=node_conv)
+ if SCons.Util.is_Sequence(value):
+ result.extend(value)
+ continue
+
+ elif type == TYPE_OBJECT:
+ value = node_conv(value)
+ if value:
+ result.append(value)
+ return tuple(result)
+
+
+class PathListCache(object):
+ """
+ A class to handle caching of PathList lookups.
+
+ This class gets instantiated once and then deleted from the namespace,
+ so it's used as a Singleton (although we don't enforce that in the
+ usual Pythonic ways). We could have just made the cache a dictionary
+ in the module namespace, but putting it in this class allows us to
+ use the same Memoizer pattern that we use elsewhere to count cache
+ hits and misses, which is very valuable.
+
+ Lookup keys in the cache are computed by the _PathList_key() method.
+ Cache lookup should be quick, so we don't spend cycles canonicalizing
+ all forms of the same lookup key. For example, 'x:y' and ['x',
+ 'y'] logically represent the same list, but we don't bother to
+ split string representations and treat those two equivalently.
+ (Note, however, that we do, treat lists and tuples the same.)
+
+ The main type of duplication we're trying to catch will come from
+ looking up the same path list from two different clones of the
+ same construction environment. That is, given
+
+ env2 = env1.Clone()
+
+ both env1 and env2 will have the same CPPPATH value, and we can
+ cheaply avoid re-parsing both values of CPPPATH by using the
+ common value from this cache.
+ """
+ if SCons.Memoize.use_memoizer:
+ __metaclass__ = SCons.Memoize.Memoized_Metaclass
+
+ memoizer_counters = []
+
+ def __init__(self):
+ self._memo = {}
+
+ def _PathList_key(self, pathlist):
+ """
+ Returns the key for memoization of PathLists.
+
+ Note that we want this to be pretty quick, so we don't completely
+ canonicalize all forms of the same list. For example,
+ 'dir1:$ROOT/dir2' and ['$ROOT/dir1', 'dir'] may logically
+ represent the same list if you're executing from $ROOT, but
+ we're not going to bother splitting strings into path elements,
+ or massaging strings into Nodes, to identify that equivalence.
+ We just want to eliminate obvious redundancy from the normal
+ case of re-using exactly the same cloned value for a path.
+ """
+ if SCons.Util.is_Sequence(pathlist):
+ pathlist = tuple(SCons.Util.flatten(pathlist))
+ return pathlist
+
+ memoizer_counters.append(SCons.Memoize.CountDict('PathList', _PathList_key))
+
+ def PathList(self, pathlist):
+ """
+ Returns the cached _PathList object for the specified pathlist,
+ creating and caching a new object as necessary.
+ """
+ pathlist = self._PathList_key(pathlist)
+ try:
+ memo_dict = self._memo['PathList']
+ except KeyError:
+ memo_dict = {}
+ self._memo['PathList'] = memo_dict
+ else:
+ try:
+ return memo_dict[pathlist]
+ except KeyError:
+ pass
+
+ result = _PathList(pathlist)
+
+ memo_dict[pathlist] = result
+
+ return result
+
+PathList = PathListCache().PathList
+
+
+del PathListCache
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Platform/__init__.py b/couchjs/scons/scons-local-2.0.1/SCons/Platform/__init__.py
new file mode 100644
index 00000000..7621e40a
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Platform/__init__.py
@@ -0,0 +1,241 @@
+"""SCons.Platform
+
+SCons platform selection.
+
+This looks for modules that define a callable object that can modify a
+construction environment as appropriate for a given platform.
+
+Note that we take a more simplistic view of "platform" than Python does.
+We're looking for a single string that determines a set of
+tool-independent variables with which to initialize a construction
+environment. Consequently, we'll examine both sys.platform and os.name
+(and anything else that might come in to play) in order to return some
+specification which is unique enough for our purposes.
+
+Note that because this subsysem just *selects* a callable that can
+modify a construction environment, it's possible for people to define
+their own "platform specification" in an arbitrary callable function.
+No one needs to use or tie in to this subsystem in order to roll
+their own platform definition.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Platform/__init__.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.compat
+
+import imp
+import os
+import sys
+import tempfile
+
+import SCons.Errors
+import SCons.Subst
+import SCons.Tool
+
+def platform_default():
+ """Return the platform string for our execution environment.
+
+ The returned value should map to one of the SCons/Platform/*.py
+ files. Since we're architecture independent, though, we don't
+ care about the machine architecture.
+ """
+ osname = os.name
+ if osname == 'java':
+ osname = os._osType
+ if osname == 'posix':
+ if sys.platform == 'cygwin':
+ return 'cygwin'
+ elif sys.platform.find('irix') != -1:
+ return 'irix'
+ elif sys.platform.find('sunos') != -1:
+ return 'sunos'
+ elif sys.platform.find('hp-ux') != -1:
+ return 'hpux'
+ elif sys.platform.find('aix') != -1:
+ return 'aix'
+ elif sys.platform.find('darwin') != -1:
+ return 'darwin'
+ else:
+ return 'posix'
+ elif os.name == 'os2':
+ return 'os2'
+ else:
+ return sys.platform
+
+def platform_module(name = platform_default()):
+ """Return the imported module for the platform.
+
+ This looks for a module name that matches the specified argument.
+ If the name is unspecified, we fetch the appropriate default for
+ our execution environment.
+ """
+ full_name = 'SCons.Platform.' + name
+ if full_name not in sys.modules:
+ if os.name == 'java':
+ eval(full_name)
+ else:
+ try:
+ file, path, desc = imp.find_module(name,
+ sys.modules['SCons.Platform'].__path__)
+ try:
+ mod = imp.load_module(full_name, file, path, desc)
+ finally:
+ if file:
+ file.close()
+ except ImportError:
+ try:
+ import zipimport
+ importer = zipimport.zipimporter( sys.modules['SCons.Platform'].__path__[0] )
+ mod = importer.load_module(full_name)
+ except ImportError:
+ raise SCons.Errors.UserError("No platform named '%s'" % name)
+ setattr(SCons.Platform, name, mod)
+ return sys.modules[full_name]
+
+def DefaultToolList(platform, env):
+ """Select a default tool list for the specified platform.
+ """
+ return SCons.Tool.tool_list(platform, env)
+
+class PlatformSpec(object):
+ def __init__(self, name, generate):
+ self.name = name
+ self.generate = generate
+
+ def __call__(self, *args, **kw):
+ return self.generate(*args, **kw)
+
+ def __str__(self):
+ return self.name
+
+class TempFileMunge(object):
+ """A callable class. You can set an Environment variable to this,
+ then call it with a string argument, then it will perform temporary
+ file substitution on it. This is used to circumvent the long command
+ line limitation.
+
+ Example usage:
+ env["TEMPFILE"] = TempFileMunge
+ env["LINKCOM"] = "${TEMPFILE('$LINK $TARGET $SOURCES')}"
+
+ By default, the name of the temporary file used begins with a
+ prefix of '@'. This may be configred for other tool chains by
+ setting '$TEMPFILEPREFIX'.
+
+ env["TEMPFILEPREFIX"] = '-@' # diab compiler
+ env["TEMPFILEPREFIX"] = '-via' # arm tool chain
+ """
+ def __init__(self, cmd):
+ self.cmd = cmd
+
+ def __call__(self, target, source, env, for_signature):
+ if for_signature:
+ # If we're being called for signature calculation, it's
+ # because we're being called by the string expansion in
+ # Subst.py, which has the logic to strip any $( $) that
+ # may be in the command line we squirreled away. So we
+ # just return the raw command line and let the upper
+ # string substitution layers do their thing.
+ return self.cmd
+
+ # Now we're actually being called because someone is actually
+ # going to try to execute the command, so we have to do our
+ # own expansion.
+ cmd = env.subst_list(self.cmd, SCons.Subst.SUBST_CMD, target, source)[0]
+ try:
+ maxline = int(env.subst('$MAXLINELENGTH'))
+ except ValueError:
+ maxline = 2048
+
+ length = 0
+ for c in cmd:
+ length += len(c)
+ if length <= maxline:
+ return self.cmd
+
+ # We do a normpath because mktemp() has what appears to be
+ # a bug in Windows that will use a forward slash as a path
+ # delimiter. Windows's link mistakes that for a command line
+ # switch and barfs.
+ #
+ # We use the .lnk suffix for the benefit of the Phar Lap
+ # linkloc linker, which likes to append an .lnk suffix if
+ # none is given.
+ (fd, tmp) = tempfile.mkstemp('.lnk', text=True)
+ native_tmp = SCons.Util.get_native_path(os.path.normpath(tmp))
+
+ if env['SHELL'] and env['SHELL'] == 'sh':
+ # The sh shell will try to escape the backslashes in the
+ # path, so unescape them.
+ native_tmp = native_tmp.replace('\\', r'\\\\')
+ # In Cygwin, we want to use rm to delete the temporary
+ # file, because del does not exist in the sh shell.
+ rm = env.Detect('rm') or 'del'
+ else:
+ # Don't use 'rm' if the shell is not sh, because rm won't
+ # work with the Windows shells (cmd.exe or command.com) or
+ # Windows path names.
+ rm = 'del'
+
+ prefix = env.subst('$TEMPFILEPREFIX')
+ if not prefix:
+ prefix = '@'
+
+ args = list(map(SCons.Subst.quote_spaces, cmd[1:]))
+ os.write(fd, " ".join(args) + "\n")
+ os.close(fd)
+ # XXX Using the SCons.Action.print_actions value directly
+ # like this is bogus, but expedient. This class should
+ # really be rewritten as an Action that defines the
+ # __call__() and strfunction() methods and lets the
+ # normal action-execution logic handle whether or not to
+ # print/execute the action. The problem, though, is all
+ # of that is decided before we execute this method as
+ # part of expanding the $TEMPFILE construction variable.
+ # Consequently, refactoring this will have to wait until
+ # we get more flexible with allowing Actions to exist
+ # independently and get strung together arbitrarily like
+ # Ant tasks. In the meantime, it's going to be more
+ # user-friendly to not let obsession with architectural
+ # purity get in the way of just being helpful, so we'll
+ # reach into SCons.Action directly.
+ if SCons.Action.print_actions:
+ print("Using tempfile "+native_tmp+" for command line:\n"+
+ str(cmd[0]) + " " + " ".join(args))
+ return [ cmd[0], prefix + native_tmp + '\n' + rm, native_tmp ]
+
+def Platform(name = platform_default()):
+ """Select a canned Platform specification.
+ """
+ module = platform_module(name)
+ spec = PlatformSpec(name, module.generate)
+ return spec
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Platform/aix.py b/couchjs/scons/scons-local-2.0.1/SCons/Platform/aix.py
new file mode 100644
index 00000000..821c9da9
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Platform/aix.py
@@ -0,0 +1,69 @@
+"""engine.SCons.Platform.aix
+
+Platform-specific initialization for IBM AIX systems.
+
+There normally shouldn't be any need to import this module directly. It
+will usually be imported through the generic SCons.Platform.Platform()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Platform/aix.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+
+import posix
+
+def get_xlc(env, xlc=None, xlc_r=None, packages=[]):
+ # Use the AIX package installer tool lslpp to figure out where a
+ # given xl* compiler is installed and what version it is.
+ xlcPath = None
+ xlcVersion = None
+
+ if xlc is None:
+ xlc = env.get('CC', 'xlc')
+ if xlc_r is None:
+ xlc_r = xlc + '_r'
+ for package in packages:
+ cmd = "lslpp -fc " + package + " 2>/dev/null | egrep '" + xlc + "([^-_a-zA-Z0-9].*)?$'"
+ line = os.popen(cmd).readline()
+ if line:
+ v, p = line.split(':')[1:3]
+ xlcVersion = v.split()[1]
+ xlcPath = p.split()[0]
+ xlcPath = xlcPath[:xlcPath.rindex('/')]
+ break
+ return (xlcPath, xlc, xlc_r, xlcVersion)
+
+def generate(env):
+ posix.generate(env)
+ #Based on AIX 5.2: ARG_MAX=24576 - 3000 for environment expansion
+ env['MAXLINELENGTH'] = 21576
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Platform/cygwin.py b/couchjs/scons/scons-local-2.0.1/SCons/Platform/cygwin.py
new file mode 100644
index 00000000..8370ea61
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Platform/cygwin.py
@@ -0,0 +1,55 @@
+"""SCons.Platform.cygwin
+
+Platform-specific initialization for Cygwin systems.
+
+There normally shouldn't be any need to import this module directly. It
+will usually be imported through the generic SCons.Platform.Platform()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Platform/cygwin.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import posix
+from SCons.Platform import TempFileMunge
+
+def generate(env):
+ posix.generate(env)
+
+ env['PROGPREFIX'] = ''
+ env['PROGSUFFIX'] = '.exe'
+ env['SHLIBPREFIX'] = ''
+ env['SHLIBSUFFIX'] = '.dll'
+ env['LIBPREFIXES'] = [ '$LIBPREFIX', '$SHLIBPREFIX' ]
+ env['LIBSUFFIXES'] = [ '$LIBSUFFIX', '$SHLIBSUFFIX' ]
+ env['TEMPFILE'] = TempFileMunge
+ env['TEMPFILEPREFIX'] = '@'
+ env['MAXLINELENGTH'] = 2048
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Platform/darwin.py b/couchjs/scons/scons-local-2.0.1/SCons/Platform/darwin.py
new file mode 100644
index 00000000..3a9c9eb4
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Platform/darwin.py
@@ -0,0 +1,46 @@
+"""engine.SCons.Platform.darwin
+
+Platform-specific initialization for Mac OS X systems.
+
+There normally shouldn't be any need to import this module directly. It
+will usually be imported through the generic SCons.Platform.Platform()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Platform/darwin.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import posix
+
+def generate(env):
+ posix.generate(env)
+ env['SHLIBSUFFIX'] = '.dylib'
+ env['ENV']['PATH'] = env['ENV']['PATH'] + ':/sw/bin'
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Platform/hpux.py b/couchjs/scons/scons-local-2.0.1/SCons/Platform/hpux.py
new file mode 100644
index 00000000..77d6db39
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Platform/hpux.py
@@ -0,0 +1,46 @@
+"""engine.SCons.Platform.hpux
+
+Platform-specific initialization for HP-UX systems.
+
+There normally shouldn't be any need to import this module directly. It
+will usually be imported through the generic SCons.Platform.Platform()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Platform/hpux.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import posix
+
+def generate(env):
+ posix.generate(env)
+ #Based on HP-UX11i: ARG_MAX=2048000 - 3000 for environment expansion
+ env['MAXLINELENGTH'] = 2045000
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Platform/irix.py b/couchjs/scons/scons-local-2.0.1/SCons/Platform/irix.py
new file mode 100644
index 00000000..ff0c323c
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Platform/irix.py
@@ -0,0 +1,44 @@
+"""SCons.Platform.irix
+
+Platform-specific initialization for SGI IRIX systems.
+
+There normally shouldn't be any need to import this module directly. It
+will usually be imported through the generic SCons.Platform.Platform()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Platform/irix.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import posix
+
+def generate(env):
+ posix.generate(env)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Platform/os2.py b/couchjs/scons/scons-local-2.0.1/SCons/Platform/os2.py
new file mode 100644
index 00000000..cdb4082b
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Platform/os2.py
@@ -0,0 +1,58 @@
+"""SCons.Platform.os2
+
+Platform-specific initialization for OS/2 systems.
+
+There normally shouldn't be any need to import this module directly. It
+will usually be imported through the generic SCons.Platform.Platform()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Platform/os2.py 5134 2010/08/16 23:02:40 bdeegan"
+import win32
+
+def generate(env):
+ if 'ENV' not in env:
+ env['ENV'] = {}
+ env['OBJPREFIX'] = ''
+ env['OBJSUFFIX'] = '.obj'
+ env['SHOBJPREFIX'] = '$OBJPREFIX'
+ env['SHOBJSUFFIX'] = '$OBJSUFFIX'
+ env['PROGPREFIX'] = ''
+ env['PROGSUFFIX'] = '.exe'
+ env['LIBPREFIX'] = ''
+ env['LIBSUFFIX'] = '.lib'
+ env['SHLIBPREFIX'] = ''
+ env['SHLIBSUFFIX'] = '.dll'
+ env['LIBPREFIXES'] = '$LIBPREFIX'
+ env['LIBSUFFIXES'] = [ '$LIBSUFFIX', '$SHLIBSUFFIX' ]
+ env['HOST_OS'] = 'os2'
+ env['HOST_ARCH'] = win32.get_architecture().arch
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Platform/posix.py b/couchjs/scons/scons-local-2.0.1/SCons/Platform/posix.py
new file mode 100644
index 00000000..87de9dfc
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Platform/posix.py
@@ -0,0 +1,263 @@
+"""SCons.Platform.posix
+
+Platform-specific initialization for POSIX (Linux, UNIX, etc.) systems.
+
+There normally shouldn't be any need to import this module directly. It
+will usually be imported through the generic SCons.Platform.Platform()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Platform/posix.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import errno
+import os
+import os.path
+import subprocess
+import sys
+import select
+
+import SCons.Util
+from SCons.Platform import TempFileMunge
+
+exitvalmap = {
+ 2 : 127,
+ 13 : 126,
+}
+
+def escape(arg):
+ "escape shell special characters"
+ slash = '\\'
+ special = '"$()'
+
+ arg = arg.replace(slash, slash+slash)
+ for c in special:
+ arg = arg.replace(c, slash+c)
+
+ return '"' + arg + '"'
+
+def exec_system(l, env):
+ stat = os.system(' '.join(l))
+ if stat & 0xff:
+ return stat | 0x80
+ return stat >> 8
+
+def exec_spawnvpe(l, env):
+ stat = os.spawnvpe(os.P_WAIT, l[0], l, env)
+ # os.spawnvpe() returns the actual exit code, not the encoding
+ # returned by os.waitpid() or os.system().
+ return stat
+
+def exec_fork(l, env):
+ pid = os.fork()
+ if not pid:
+ # Child process.
+ exitval = 127
+ try:
+ os.execvpe(l[0], l, env)
+ except OSError, e:
+ exitval = exitvalmap.get(e[0], e[0])
+ sys.stderr.write("scons: %s: %s\n" % (l[0], e[1]))
+ os._exit(exitval)
+ else:
+ # Parent process.
+ pid, stat = os.waitpid(pid, 0)
+ if stat & 0xff:
+ return stat | 0x80
+ return stat >> 8
+
+def _get_env_command(sh, escape, cmd, args, env):
+ s = ' '.join(args)
+ if env:
+ l = ['env', '-'] + \
+ [escape(t[0])+'='+escape(t[1]) for t in env.items()] + \
+ [sh, '-c', escape(s)]
+ s = ' '.join(l)
+ return s
+
+def env_spawn(sh, escape, cmd, args, env):
+ return exec_system([_get_env_command( sh, escape, cmd, args, env)], env)
+
+def spawnvpe_spawn(sh, escape, cmd, args, env):
+ return exec_spawnvpe([sh, '-c', ' '.join(args)], env)
+
+def fork_spawn(sh, escape, cmd, args, env):
+ return exec_fork([sh, '-c', ' '.join(args)], env)
+
+def process_cmd_output(cmd_stdout, cmd_stderr, stdout, stderr):
+ stdout_eof = stderr_eof = 0
+ while not (stdout_eof and stderr_eof):
+ try:
+ (i,o,e) = select.select([cmd_stdout, cmd_stderr], [], [])
+ if cmd_stdout in i:
+ str = cmd_stdout.read()
+ if len(str) == 0:
+ stdout_eof = 1
+ elif stdout is not None:
+ stdout.write(str)
+ if cmd_stderr in i:
+ str = cmd_stderr.read()
+ if len(str) == 0:
+ #sys.__stderr__.write( "stderr_eof=1\n" )
+ stderr_eof = 1
+ else:
+ #sys.__stderr__.write( "str(stderr) = %s\n" % str )
+ stderr.write(str)
+ except select.error, (_errno, _strerror):
+ if _errno != errno.EINTR:
+ raise
+
+def exec_popen3(l, env, stdout, stderr):
+ proc = subprocess.Popen(' '.join(l),
+ stdout=stdout,
+ stderr=stderr,
+ shell=True)
+ stat = proc.wait()
+ if stat & 0xff:
+ return stat | 0x80
+ return stat >> 8
+
+def exec_piped_fork(l, env, stdout, stderr):
+ # spawn using fork / exec and providing a pipe for the command's
+ # stdout / stderr stream
+ if stdout != stderr:
+ (rFdOut, wFdOut) = os.pipe()
+ (rFdErr, wFdErr) = os.pipe()
+ else:
+ (rFdOut, wFdOut) = os.pipe()
+ rFdErr = rFdOut
+ wFdErr = wFdOut
+ # do the fork
+ pid = os.fork()
+ if not pid:
+ # Child process
+ os.close( rFdOut )
+ if rFdOut != rFdErr:
+ os.close( rFdErr )
+ os.dup2( wFdOut, 1 ) # is there some symbolic way to do that ?
+ os.dup2( wFdErr, 2 )
+ os.close( wFdOut )
+ if stdout != stderr:
+ os.close( wFdErr )
+ exitval = 127
+ try:
+ os.execvpe(l[0], l, env)
+ except OSError, e:
+ exitval = exitvalmap.get(e[0], e[0])
+ stderr.write("scons: %s: %s\n" % (l[0], e[1]))
+ os._exit(exitval)
+ else:
+ # Parent process
+ pid, stat = os.waitpid(pid, 0)
+ os.close( wFdOut )
+ if stdout != stderr:
+ os.close( wFdErr )
+ childOut = os.fdopen( rFdOut )
+ if stdout != stderr:
+ childErr = os.fdopen( rFdErr )
+ else:
+ childErr = childOut
+ process_cmd_output(childOut, childErr, stdout, stderr)
+ os.close( rFdOut )
+ if stdout != stderr:
+ os.close( rFdErr )
+ if stat & 0xff:
+ return stat | 0x80
+ return stat >> 8
+
+def piped_env_spawn(sh, escape, cmd, args, env, stdout, stderr):
+ # spawn using Popen3 combined with the env command
+ # the command name and the command's stdout is written to stdout
+ # the command's stderr is written to stderr
+ return exec_popen3([_get_env_command(sh, escape, cmd, args, env)],
+ env, stdout, stderr)
+
+def piped_fork_spawn(sh, escape, cmd, args, env, stdout, stderr):
+ # spawn using fork / exec and providing a pipe for the command's
+ # stdout / stderr stream
+ return exec_piped_fork([sh, '-c', ' '.join(args)],
+ env, stdout, stderr)
+
+
+
+def generate(env):
+ # If os.spawnvpe() exists, we use it to spawn commands. Otherwise
+ # if the env utility exists, we use os.system() to spawn commands,
+ # finally we fall back on os.fork()/os.exec().
+ #
+ # os.spawnvpe() is prefered because it is the most efficient. But
+ # for Python versions without it, os.system() is prefered because it
+ # is claimed that it works better with threads (i.e. -j) and is more
+ # efficient than forking Python.
+ #
+ # NB: Other people on the scons-users mailing list have claimed that
+ # os.fork()/os.exec() works better than os.system(). There may just
+ # not be a default that works best for all users.
+
+ if 'spawnvpe' in os.__dict__:
+ spawn = spawnvpe_spawn
+ elif env.Detect('env'):
+ spawn = env_spawn
+ else:
+ spawn = fork_spawn
+
+ if env.Detect('env'):
+ pspawn = piped_env_spawn
+ else:
+ pspawn = piped_fork_spawn
+
+ if 'ENV' not in env:
+ env['ENV'] = {}
+ env['ENV']['PATH'] = '/usr/local/bin:/opt/bin:/bin:/usr/bin'
+ env['OBJPREFIX'] = ''
+ env['OBJSUFFIX'] = '.o'
+ env['SHOBJPREFIX'] = '$OBJPREFIX'
+ env['SHOBJSUFFIX'] = '$OBJSUFFIX'
+ env['PROGPREFIX'] = ''
+ env['PROGSUFFIX'] = ''
+ env['LIBPREFIX'] = 'lib'
+ env['LIBSUFFIX'] = '.a'
+ env['SHLIBPREFIX'] = '$LIBPREFIX'
+ env['SHLIBSUFFIX'] = '.so'
+ env['LIBPREFIXES'] = [ '$LIBPREFIX' ]
+ env['LIBSUFFIXES'] = [ '$LIBSUFFIX', '$SHLIBSUFFIX' ]
+ env['PSPAWN'] = pspawn
+ env['SPAWN'] = spawn
+ env['SHELL'] = 'sh'
+ env['ESCAPE'] = escape
+ env['TEMPFILE'] = TempFileMunge
+ env['TEMPFILEPREFIX'] = '@'
+ #Based on LINUX: ARG_MAX=ARG_MAX=131072 - 3000 for environment expansion
+ #Note: specific platforms might rise or lower this value
+ env['MAXLINELENGTH'] = 128072
+
+ # This platform supports RPATH specifications.
+ env['__RPATH'] = '$_RPATH'
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Platform/sunos.py b/couchjs/scons/scons-local-2.0.1/SCons/Platform/sunos.py
new file mode 100644
index 00000000..15011071
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Platform/sunos.py
@@ -0,0 +1,50 @@
+"""engine.SCons.Platform.sunos
+
+Platform-specific initialization for Sun systems.
+
+There normally shouldn't be any need to import this module directly. It
+will usually be imported through the generic SCons.Platform.Platform()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Platform/sunos.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import posix
+
+def generate(env):
+ posix.generate(env)
+ # Based on sunSparc 8:32bit
+ # ARG_MAX=1048320 - 3000 for environment expansion
+ env['MAXLINELENGTH'] = 1045320
+ env['PKGINFO'] = 'pkginfo'
+ env['PKGCHK'] = '/usr/sbin/pkgchk'
+ env['ENV']['PATH'] = env['ENV']['PATH'] + ':/opt/SUNWspro/bin:/usr/ccs/bin'
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Platform/win32.py b/couchjs/scons/scons-local-2.0.1/SCons/Platform/win32.py
new file mode 100644
index 00000000..7a232aef
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Platform/win32.py
@@ -0,0 +1,385 @@
+"""SCons.Platform.win32
+
+Platform-specific initialization for Win32 systems.
+
+There normally shouldn't be any need to import this module directly. It
+will usually be imported through the generic SCons.Platform.Platform()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Platform/win32.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+import os.path
+import sys
+import tempfile
+
+from SCons.Platform.posix import exitvalmap
+from SCons.Platform import TempFileMunge
+import SCons.Util
+
+try:
+ import msvcrt
+ import win32api
+ import win32con
+
+ msvcrt.get_osfhandle
+ win32api.SetHandleInformation
+ win32con.HANDLE_FLAG_INHERIT
+except ImportError:
+ parallel_msg = \
+ "you do not seem to have the pywin32 extensions installed;\n" + \
+ "\tparallel (-j) builds may not work reliably with open Python files."
+except AttributeError:
+ parallel_msg = \
+ "your pywin32 extensions do not support file handle operations;\n" + \
+ "\tparallel (-j) builds may not work reliably with open Python files."
+else:
+ parallel_msg = None
+
+ import builtins
+
+ _builtin_file = builtins.file
+ _builtin_open = builtins.open
+
+ def _scons_file(*args, **kw):
+ fp = _builtin_file(*args, **kw)
+ win32api.SetHandleInformation(msvcrt.get_osfhandle(fp.fileno()),
+ win32con.HANDLE_FLAG_INHERIT,
+ 0)
+ return fp
+
+ def _scons_open(*args, **kw):
+ fp = _builtin_open(*args, **kw)
+ win32api.SetHandleInformation(msvcrt.get_osfhandle(fp.fileno()),
+ win32con.HANDLE_FLAG_INHERIT,
+ 0)
+ return fp
+
+ builtins.file = _scons_file
+ builtins.open = _scons_open
+
+
+
+# The upshot of all this is that, if you are using Python 1.5.2,
+# you had better have cmd or command.com in your PATH when you run
+# scons.
+
+def piped_spawn(sh, escape, cmd, args, env, stdout, stderr):
+ # There is no direct way to do that in python. What we do
+ # here should work for most cases:
+ # In case stdout (stderr) is not redirected to a file,
+ # we redirect it into a temporary file tmpFileStdout
+ # (tmpFileStderr) and copy the contents of this file
+ # to stdout (stderr) given in the argument
+ if not sh:
+ sys.stderr.write("scons: Could not find command interpreter, is it in your PATH?\n")
+ return 127
+ else:
+ # one temporary file for stdout and stderr
+ tmpFileStdout = os.path.normpath(tempfile.mktemp())
+ tmpFileStderr = os.path.normpath(tempfile.mktemp())
+
+ # check if output is redirected
+ stdoutRedirected = 0
+ stderrRedirected = 0
+ for arg in args:
+ # are there more possibilities to redirect stdout ?
+ if (arg.find( ">", 0, 1 ) != -1 or
+ arg.find( "1>", 0, 2 ) != -1):
+ stdoutRedirected = 1
+ # are there more possibilities to redirect stderr ?
+ if arg.find( "2>", 0, 2 ) != -1:
+ stderrRedirected = 1
+
+ # redirect output of non-redirected streams to our tempfiles
+ if stdoutRedirected == 0:
+ args.append(">" + str(tmpFileStdout))
+ if stderrRedirected == 0:
+ args.append("2>" + str(tmpFileStderr))
+
+ # actually do the spawn
+ try:
+ args = [sh, '/C', escape(' '.join(args)) ]
+ ret = os.spawnve(os.P_WAIT, sh, args, env)
+ except OSError, e:
+ # catch any error
+ try:
+ ret = exitvalmap[e[0]]
+ except KeyError:
+ sys.stderr.write("scons: unknown OSError exception code %d - %s: %s\n" % (e[0], cmd, e[1]))
+ if stderr is not None:
+ stderr.write("scons: %s: %s\n" % (cmd, e[1]))
+ # copy child output from tempfiles to our streams
+ # and do clean up stuff
+ if stdout is not None and stdoutRedirected == 0:
+ try:
+ stdout.write(open( tmpFileStdout, "r" ).read())
+ os.remove( tmpFileStdout )
+ except (IOError, OSError):
+ pass
+
+ if stderr is not None and stderrRedirected == 0:
+ try:
+ stderr.write(open( tmpFileStderr, "r" ).read())
+ os.remove( tmpFileStderr )
+ except (IOError, OSError):
+ pass
+ return ret
+
+def exec_spawn(l, env):
+ try:
+ result = os.spawnve(os.P_WAIT, l[0], l, env)
+ except OSError, e:
+ try:
+ result = exitvalmap[e[0]]
+ sys.stderr.write("scons: %s: %s\n" % (l[0], e[1]))
+ except KeyError:
+ result = 127
+ if len(l) > 2:
+ if len(l[2]) < 1000:
+ command = ' '.join(l[0:3])
+ else:
+ command = l[0]
+ else:
+ command = l[0]
+ sys.stderr.write("scons: unknown OSError exception code %d - '%s': %s\n" % (e[0], command, e[1]))
+ return result
+
+def spawn(sh, escape, cmd, args, env):
+ if not sh:
+ sys.stderr.write("scons: Could not find command interpreter, is it in your PATH?\n")
+ return 127
+ return exec_spawn([sh, '/C', escape(' '.join(args))], env)
+
+# Windows does not allow special characters in file names anyway, so no
+# need for a complex escape function, we will just quote the arg, except
+# that "cmd /c" requires that if an argument ends with a backslash it
+# needs to be escaped so as not to interfere with closing double quote
+# that we add.
+def escape(x):
+ if x[-1] == '\\':
+ x = x + '\\'
+ return '"' + x + '"'
+
+# Get the windows system directory name
+_system_root = None
+
+def get_system_root():
+ global _system_root
+ if _system_root is not None:
+ return _system_root
+
+ # A resonable default if we can't read the registry
+ val = os.environ.get('SystemRoot', "C:\\WINDOWS")
+
+ if SCons.Util.can_read_reg:
+ try:
+ # Look for Windows NT system root
+ k=SCons.Util.RegOpenKeyEx(SCons.Util.hkey_mod.HKEY_LOCAL_MACHINE,
+ 'Software\\Microsoft\\Windows NT\\CurrentVersion')
+ val, tok = SCons.Util.RegQueryValueEx(k, 'SystemRoot')
+ except SCons.Util.RegError:
+ try:
+ # Okay, try the Windows 9x system root
+ k=SCons.Util.RegOpenKeyEx(SCons.Util.hkey_mod.HKEY_LOCAL_MACHINE,
+ 'Software\\Microsoft\\Windows\\CurrentVersion')
+ val, tok = SCons.Util.RegQueryValueEx(k, 'SystemRoot')
+ except KeyboardInterrupt:
+ raise
+ except:
+ pass
+ _system_root = val
+ return val
+
+# Get the location of the program files directory
+def get_program_files_dir():
+ # Now see if we can look in the registry...
+ val = ''
+ if SCons.Util.can_read_reg:
+ try:
+ # Look for Windows Program Files directory
+ k=SCons.Util.RegOpenKeyEx(SCons.Util.hkey_mod.HKEY_LOCAL_MACHINE,
+ 'Software\\Microsoft\\Windows\\CurrentVersion')
+ val, tok = SCons.Util.RegQueryValueEx(k, 'ProgramFilesDir')
+ except SCons.Util.RegError:
+ val = ''
+ pass
+
+ if val == '':
+ # A reasonable default if we can't read the registry
+ # (Actually, it's pretty reasonable even if we can :-)
+ val = os.path.join(os.path.dirname(get_system_root()),"Program Files")
+
+ return val
+
+
+
+# Determine which windows CPU were running on.
+class ArchDefinition(object):
+ """
+ A class for defining architecture-specific settings and logic.
+ """
+ def __init__(self, arch, synonyms=[]):
+ self.arch = arch
+ self.synonyms = synonyms
+
+SupportedArchitectureList = [
+ ArchDefinition(
+ 'x86',
+ ['i386', 'i486', 'i586', 'i686'],
+ ),
+
+ ArchDefinition(
+ 'x86_64',
+ ['AMD64', 'amd64', 'em64t', 'EM64T', 'x86_64'],
+ ),
+
+ ArchDefinition(
+ 'ia64',
+ ['IA64'],
+ ),
+]
+
+SupportedArchitectureMap = {}
+for a in SupportedArchitectureList:
+ SupportedArchitectureMap[a.arch] = a
+ for s in a.synonyms:
+ SupportedArchitectureMap[s] = a
+
+def get_architecture(arch=None):
+ """Returns the definition for the specified architecture string.
+
+ If no string is specified, the system default is returned (as defined
+ by the PROCESSOR_ARCHITEW6432 or PROCESSOR_ARCHITECTURE environment
+ variables).
+ """
+ if arch is None:
+ arch = os.environ.get('PROCESSOR_ARCHITEW6432')
+ if not arch:
+ arch = os.environ.get('PROCESSOR_ARCHITECTURE')
+ return SupportedArchitectureMap.get(arch, ArchDefinition('', ['']))
+
+def generate(env):
+ # Attempt to find cmd.exe (for WinNT/2k/XP) or
+ # command.com for Win9x
+ cmd_interp = ''
+ # First see if we can look in the registry...
+ if SCons.Util.can_read_reg:
+ try:
+ # Look for Windows NT system root
+ k=SCons.Util.RegOpenKeyEx(SCons.Util.hkey_mod.HKEY_LOCAL_MACHINE,
+ 'Software\\Microsoft\\Windows NT\\CurrentVersion')
+ val, tok = SCons.Util.RegQueryValueEx(k, 'SystemRoot')
+ cmd_interp = os.path.join(val, 'System32\\cmd.exe')
+ except SCons.Util.RegError:
+ try:
+ # Okay, try the Windows 9x system root
+ k=SCons.Util.RegOpenKeyEx(SCons.Util.hkey_mod.HKEY_LOCAL_MACHINE,
+ 'Software\\Microsoft\\Windows\\CurrentVersion')
+ val, tok = SCons.Util.RegQueryValueEx(k, 'SystemRoot')
+ cmd_interp = os.path.join(val, 'command.com')
+ except KeyboardInterrupt:
+ raise
+ except:
+ pass
+
+ # For the special case of not having access to the registry, we
+ # use a temporary path and pathext to attempt to find the command
+ # interpreter. If we fail, we try to find the interpreter through
+ # the env's PATH. The problem with that is that it might not
+ # contain an ENV and a PATH.
+ if not cmd_interp:
+ systemroot = get_system_root()
+ tmp_path = systemroot + os.pathsep + \
+ os.path.join(systemroot,'System32')
+ tmp_pathext = '.com;.exe;.bat;.cmd'
+ if 'PATHEXT' in os.environ:
+ tmp_pathext = os.environ['PATHEXT']
+ cmd_interp = SCons.Util.WhereIs('cmd', tmp_path, tmp_pathext)
+ if not cmd_interp:
+ cmd_interp = SCons.Util.WhereIs('command', tmp_path, tmp_pathext)
+
+ if not cmd_interp:
+ cmd_interp = env.Detect('cmd')
+ if not cmd_interp:
+ cmd_interp = env.Detect('command')
+
+
+ if 'ENV' not in env:
+ env['ENV'] = {}
+
+ # Import things from the external environment to the construction
+ # environment's ENV. This is a potential slippery slope, because we
+ # *don't* want to make builds dependent on the user's environment by
+ # default. We're doing this for SystemRoot, though, because it's
+ # needed for anything that uses sockets, and seldom changes, and
+ # for SystemDrive because it's related.
+ #
+ # Weigh the impact carefully before adding other variables to this list.
+ import_env = [ 'SystemDrive', 'SystemRoot', 'TEMP', 'TMP' ]
+ for var in import_env:
+ v = os.environ.get(var)
+ if v:
+ env['ENV'][var] = v
+
+ if 'COMSPEC' not in env['ENV']:
+ v = os.environ.get("COMSPEC")
+ if v:
+ env['ENV']['COMSPEC'] = v
+
+ env.AppendENVPath('PATH', get_system_root() + '\System32')
+
+ env['ENV']['PATHEXT'] = '.COM;.EXE;.BAT;.CMD'
+ env['OBJPREFIX'] = ''
+ env['OBJSUFFIX'] = '.obj'
+ env['SHOBJPREFIX'] = '$OBJPREFIX'
+ env['SHOBJSUFFIX'] = '$OBJSUFFIX'
+ env['PROGPREFIX'] = ''
+ env['PROGSUFFIX'] = '.exe'
+ env['LIBPREFIX'] = ''
+ env['LIBSUFFIX'] = '.lib'
+ env['SHLIBPREFIX'] = ''
+ env['SHLIBSUFFIX'] = '.dll'
+ env['LIBPREFIXES'] = [ '$LIBPREFIX' ]
+ env['LIBSUFFIXES'] = [ '$LIBSUFFIX' ]
+ env['PSPAWN'] = piped_spawn
+ env['SPAWN'] = spawn
+ env['SHELL'] = cmd_interp
+ env['TEMPFILE'] = TempFileMunge
+ env['TEMPFILEPREFIX'] = '@'
+ env['MAXLINELENGTH'] = 2048
+ env['ESCAPE'] = escape
+
+ env['HOST_OS'] = 'win32'
+ env['HOST_ARCH'] = get_architecture().arch
+
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/SConf.py b/couchjs/scons/scons-local-2.0.1/SCons/SConf.py
new file mode 100644
index 00000000..7b434367
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/SConf.py
@@ -0,0 +1,1030 @@
+"""SCons.SConf
+
+Autoconf-like configuration support.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/SConf.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.compat
+
+import io
+import os
+import re
+import sys
+import traceback
+
+import SCons.Action
+import SCons.Builder
+import SCons.Errors
+import SCons.Job
+import SCons.Node.FS
+import SCons.Taskmaster
+import SCons.Util
+import SCons.Warnings
+import SCons.Conftest
+
+from SCons.Debug import Trace
+
+# Turn off the Conftest error logging
+SCons.Conftest.LogInputFiles = 0
+SCons.Conftest.LogErrorMessages = 0
+
+# Set
+build_type = None
+build_types = ['clean', 'help']
+
+def SetBuildType(type):
+ global build_type
+ build_type = type
+
+# to be set, if we are in dry-run mode
+dryrun = 0
+
+AUTO=0 # use SCons dependency scanning for up-to-date checks
+FORCE=1 # force all tests to be rebuilt
+CACHE=2 # force all tests to be taken from cache (raise an error, if necessary)
+cache_mode = AUTO
+
+def SetCacheMode(mode):
+ """Set the Configure cache mode. mode must be one of "auto", "force",
+ or "cache"."""
+ global cache_mode
+ if mode == "auto":
+ cache_mode = AUTO
+ elif mode == "force":
+ cache_mode = FORCE
+ elif mode == "cache":
+ cache_mode = CACHE
+ else:
+ raise ValueError("SCons.SConf.SetCacheMode: Unknown mode " + mode)
+
+progress_display = SCons.Util.display # will be overwritten by SCons.Script
+def SetProgressDisplay(display):
+ """Set the progress display to use (called from SCons.Script)"""
+ global progress_display
+ progress_display = display
+
+SConfFS = None
+
+_ac_build_counter = 0 # incremented, whenever TryBuild is called
+_ac_config_logs = {} # all config.log files created in this build
+_ac_config_hs = {} # all config.h files created in this build
+sconf_global = None # current sconf object
+
+def _createConfigH(target, source, env):
+ t = open(str(target[0]), "w")
+ defname = re.sub('[^A-Za-z0-9_]', '_', str(target[0]).upper())
+ t.write("""#ifndef %(DEFNAME)s_SEEN
+#define %(DEFNAME)s_SEEN
+
+""" % {'DEFNAME' : defname})
+ t.write(source[0].get_contents())
+ t.write("""
+#endif /* %(DEFNAME)s_SEEN */
+""" % {'DEFNAME' : defname})
+ t.close()
+
+def _stringConfigH(target, source, env):
+ return "scons: Configure: creating " + str(target[0])
+
+def CreateConfigHBuilder(env):
+ """Called just before the building targets phase begins."""
+ if len(_ac_config_hs) == 0:
+ return
+ action = SCons.Action.Action(_createConfigH,
+ _stringConfigH)
+ sconfigHBld = SCons.Builder.Builder(action=action)
+ env.Append( BUILDERS={'SConfigHBuilder':sconfigHBld} )
+ for k in _ac_config_hs.keys():
+ env.SConfigHBuilder(k, env.Value(_ac_config_hs[k]))
+
+class SConfWarning(SCons.Warnings.Warning):
+ pass
+SCons.Warnings.enableWarningClass(SConfWarning)
+
+# some error definitions
+class SConfError(SCons.Errors.UserError):
+ def __init__(self,msg):
+ SCons.Errors.UserError.__init__(self,msg)
+
+class ConfigureDryRunError(SConfError):
+ """Raised when a file or directory needs to be updated during a Configure
+ process, but the user requested a dry-run"""
+ def __init__(self,target):
+ if not isinstance(target, SCons.Node.FS.File):
+ msg = 'Cannot create configure directory "%s" within a dry-run.' % str(target)
+ else:
+ msg = 'Cannot update configure test "%s" within a dry-run.' % str(target)
+ SConfError.__init__(self,msg)
+
+class ConfigureCacheError(SConfError):
+ """Raised when a use explicitely requested the cache feature, but the test
+ is run the first time."""
+ def __init__(self,target):
+ SConfError.__init__(self, '"%s" is not yet built and cache is forced.' % str(target))
+
+# define actions for building text files
+def _createSource( target, source, env ):
+ fd = open(str(target[0]), "w")
+ fd.write(source[0].get_contents())
+ fd.close()
+def _stringSource( target, source, env ):
+ return (str(target[0]) + ' <-\n |' +
+ source[0].get_contents().replace( '\n', "\n |" ) )
+
+class SConfBuildInfo(SCons.Node.FS.FileBuildInfo):
+ """
+ Special build info for targets of configure tests. Additional members
+ are result (did the builder succeed last time?) and string, which
+ contains messages of the original build phase.
+ """
+ result = None # -> 0/None -> no error, != 0 error
+ string = None # the stdout / stderr output when building the target
+
+ def set_build_result(self, result, string):
+ self.result = result
+ self.string = string
+
+
+class Streamer(object):
+ """
+ 'Sniffer' for a file-like writable object. Similar to the unix tool tee.
+ """
+ def __init__(self, orig):
+ self.orig = orig
+ self.s = io.StringIO()
+
+ def write(self, str):
+ if self.orig:
+ self.orig.write(str)
+ self.s.write(str)
+
+ def writelines(self, lines):
+ for l in lines:
+ self.write(l + '\n')
+
+ def getvalue(self):
+ """
+ Return everything written to orig since the Streamer was created.
+ """
+ return self.s.getvalue()
+
+ def flush(self):
+ if self.orig:
+ self.orig.flush()
+ self.s.flush()
+
+
+class SConfBuildTask(SCons.Taskmaster.AlwaysTask):
+ """
+ This is almost the same as SCons.Script.BuildTask. Handles SConfErrors
+ correctly and knows about the current cache_mode.
+ """
+ def display(self, message):
+ if sconf_global.logstream:
+ sconf_global.logstream.write("scons: Configure: " + message + "\n")
+
+ def display_cached_string(self, bi):
+ """
+ Logs the original builder messages, given the SConfBuildInfo instance
+ bi.
+ """
+ if not isinstance(bi, SConfBuildInfo):
+ SCons.Warnings.warn(SConfWarning,
+ "The stored build information has an unexpected class: %s" % bi.__class__)
+ else:
+ self.display("The original builder output was:\n" +
+ (" |" + str(bi.string)).replace("\n", "\n |"))
+
+ def failed(self):
+ # check, if the reason was a ConfigureDryRunError or a
+ # ConfigureCacheError and if yes, reraise the exception
+ exc_type = self.exc_info()[0]
+ if issubclass(exc_type, SConfError):
+ raise
+ elif issubclass(exc_type, SCons.Errors.BuildError):
+ # we ignore Build Errors (occurs, when a test doesn't pass)
+ # Clear the exception to prevent the contained traceback
+ # to build a reference cycle.
+ self.exc_clear()
+ else:
+ self.display('Caught exception while building "%s":\n' %
+ self.targets[0])
+ try:
+ excepthook = sys.excepthook
+ except AttributeError:
+ # Earlier versions of Python don't have sys.excepthook...
+ def excepthook(type, value, tb):
+ traceback.print_tb(tb)
+ print type, value
+ excepthook(*self.exc_info())
+ return SCons.Taskmaster.Task.failed(self)
+
+ def collect_node_states(self):
+ # returns (is_up_to_date, cached_error, cachable)
+ # where is_up_to_date is 1, if the node(s) are up_to_date
+ # cached_error is 1, if the node(s) are up_to_date, but the
+ # build will fail
+ # cachable is 0, if some nodes are not in our cache
+ T = 0
+ changed = False
+ cached_error = False
+ cachable = True
+ for t in self.targets:
+ if T: Trace('%s' % (t))
+ bi = t.get_stored_info().binfo
+ if isinstance(bi, SConfBuildInfo):
+ if T: Trace(': SConfBuildInfo')
+ if cache_mode == CACHE:
+ t.set_state(SCons.Node.up_to_date)
+ if T: Trace(': set_state(up_to-date)')
+ else:
+ if T: Trace(': get_state() %s' % t.get_state())
+ if T: Trace(': changed() %s' % t.changed())
+ if (t.get_state() != SCons.Node.up_to_date and t.changed()):
+ changed = True
+ if T: Trace(': changed %s' % changed)
+ cached_error = cached_error or bi.result
+ else:
+ if T: Trace(': else')
+ # the node hasn't been built in a SConf context or doesn't
+ # exist
+ cachable = False
+ changed = ( t.get_state() != SCons.Node.up_to_date )
+ if T: Trace(': changed %s' % changed)
+ if T: Trace('\n')
+ return (not changed, cached_error, cachable)
+
+ def execute(self):
+ if not self.targets[0].has_builder():
+ return
+
+ sconf = sconf_global
+
+ is_up_to_date, cached_error, cachable = self.collect_node_states()
+
+ if cache_mode == CACHE and not cachable:
+ raise ConfigureCacheError(self.targets[0])
+ elif cache_mode == FORCE:
+ is_up_to_date = 0
+
+ if cached_error and is_up_to_date:
+ self.display("Building \"%s\" failed in a previous run and all "
+ "its sources are up to date." % str(self.targets[0]))
+ binfo = self.targets[0].get_stored_info().binfo
+ self.display_cached_string(binfo)
+ raise SCons.Errors.BuildError # will be 'caught' in self.failed
+ elif is_up_to_date:
+ self.display("\"%s\" is up to date." % str(self.targets[0]))
+ binfo = self.targets[0].get_stored_info().binfo
+ self.display_cached_string(binfo)
+ elif dryrun:
+ raise ConfigureDryRunError(self.targets[0])
+ else:
+ # note stdout and stderr are the same here
+ s = sys.stdout = sys.stderr = Streamer(sys.stdout)
+ try:
+ env = self.targets[0].get_build_env()
+ if cache_mode == FORCE:
+ # Set up the Decider() to force rebuilds by saying
+ # that every source has changed. Note that we still
+ # call the environment's underlying source decider so
+ # that the correct .sconsign info will get calculated
+ # and keep the build state consistent.
+ def force_build(dependency, target, prev_ni,
+ env_decider=env.decide_source):
+ env_decider(dependency, target, prev_ni)
+ return True
+ if env.decide_source.func_code is not force_build.func_code:
+ env.Decider(force_build)
+ env['PSTDOUT'] = env['PSTDERR'] = s
+ try:
+ sconf.cached = 0
+ self.targets[0].build()
+ finally:
+ sys.stdout = sys.stderr = env['PSTDOUT'] = \
+ env['PSTDERR'] = sconf.logstream
+ except KeyboardInterrupt:
+ raise
+ except SystemExit:
+ exc_value = sys.exc_info()[1]
+ raise SCons.Errors.ExplicitExit(self.targets[0],exc_value.code)
+ except Exception, e:
+ for t in self.targets:
+ binfo = t.get_binfo()
+ binfo.__class__ = SConfBuildInfo
+ binfo.set_build_result(1, s.getvalue())
+ sconsign_entry = SCons.SConsign.SConsignEntry()
+ sconsign_entry.binfo = binfo
+ #sconsign_entry.ninfo = self.get_ninfo()
+ # We'd like to do this as follows:
+ # t.store_info(binfo)
+ # However, we need to store it as an SConfBuildInfo
+ # object, and store_info() will turn it into a
+ # regular FileNodeInfo if the target is itself a
+ # regular File.
+ sconsign = t.dir.sconsign()
+ sconsign.set_entry(t.name, sconsign_entry)
+ sconsign.merge()
+ raise e
+ else:
+ for t in self.targets:
+ binfo = t.get_binfo()
+ binfo.__class__ = SConfBuildInfo
+ binfo.set_build_result(0, s.getvalue())
+ sconsign_entry = SCons.SConsign.SConsignEntry()
+ sconsign_entry.binfo = binfo
+ #sconsign_entry.ninfo = self.get_ninfo()
+ # We'd like to do this as follows:
+ # t.store_info(binfo)
+ # However, we need to store it as an SConfBuildInfo
+ # object, and store_info() will turn it into a
+ # regular FileNodeInfo if the target is itself a
+ # regular File.
+ sconsign = t.dir.sconsign()
+ sconsign.set_entry(t.name, sconsign_entry)
+ sconsign.merge()
+
+class SConfBase(object):
+ """This is simply a class to represent a configure context. After
+ creating a SConf object, you can call any tests. After finished with your
+ tests, be sure to call the Finish() method, which returns the modified
+ environment.
+ Some words about caching: In most cases, it is not necessary to cache
+ Test results explicitely. Instead, we use the scons dependency checking
+ mechanism. For example, if one wants to compile a test program
+ (SConf.TryLink), the compiler is only called, if the program dependencies
+ have changed. However, if the program could not be compiled in a former
+ SConf run, we need to explicitely cache this error.
+ """
+
+ def __init__(self, env, custom_tests = {}, conf_dir='$CONFIGUREDIR',
+ log_file='$CONFIGURELOG', config_h = None, _depth = 0):
+ """Constructor. Pass additional tests in the custom_tests-dictinary,
+ e.g. custom_tests={'CheckPrivate':MyPrivateTest}, where MyPrivateTest
+ defines a custom test.
+ Note also the conf_dir and log_file arguments (you may want to
+ build tests in the VariantDir, not in the SourceDir)
+ """
+ global SConfFS
+ if not SConfFS:
+ SConfFS = SCons.Node.FS.default_fs or \
+ SCons.Node.FS.FS(env.fs.pathTop)
+ if sconf_global is not None:
+ raise SCons.Errors.UserError
+ self.env = env
+ if log_file is not None:
+ log_file = SConfFS.File(env.subst(log_file))
+ self.logfile = log_file
+ self.logstream = None
+ self.lastTarget = None
+ self.depth = _depth
+ self.cached = 0 # will be set, if all test results are cached
+
+ # add default tests
+ default_tests = {
+ 'CheckCC' : CheckCC,
+ 'CheckCXX' : CheckCXX,
+ 'CheckSHCC' : CheckSHCC,
+ 'CheckSHCXX' : CheckSHCXX,
+ 'CheckFunc' : CheckFunc,
+ 'CheckType' : CheckType,
+ 'CheckTypeSize' : CheckTypeSize,
+ 'CheckDeclaration' : CheckDeclaration,
+ 'CheckHeader' : CheckHeader,
+ 'CheckCHeader' : CheckCHeader,
+ 'CheckCXXHeader' : CheckCXXHeader,
+ 'CheckLib' : CheckLib,
+ 'CheckLibWithHeader' : CheckLibWithHeader,
+ }
+ self.AddTests(default_tests)
+ self.AddTests(custom_tests)
+ self.confdir = SConfFS.Dir(env.subst(conf_dir))
+ if config_h is not None:
+ config_h = SConfFS.File(config_h)
+ self.config_h = config_h
+ self._startup()
+
+ def Finish(self):
+ """Call this method after finished with your tests:
+ env = sconf.Finish()
+ """
+ self._shutdown()
+ return self.env
+
+ def Define(self, name, value = None, comment = None):
+ """
+ Define a pre processor symbol name, with the optional given value in the
+ current config header.
+
+ If value is None (default), then #define name is written. If value is not
+ none, then #define name value is written.
+
+ comment is a string which will be put as a C comment in the
+ header, to explain the meaning of the value (appropriate C comments /* and
+ */ will be put automatically."""
+ lines = []
+ if comment:
+ comment_str = "/* %s */" % comment
+ lines.append(comment_str)
+
+ if value is not None:
+ define_str = "#define %s %s" % (name, value)
+ else:
+ define_str = "#define %s" % name
+ lines.append(define_str)
+ lines.append('')
+
+ self.config_h_text = self.config_h_text + '\n'.join(lines)
+
+ def BuildNodes(self, nodes):
+ """
+ Tries to build the given nodes immediately. Returns 1 on success,
+ 0 on error.
+ """
+ if self.logstream is not None:
+ # override stdout / stderr to write in log file
+ oldStdout = sys.stdout
+ sys.stdout = self.logstream
+ oldStderr = sys.stderr
+ sys.stderr = self.logstream
+
+ # the engine assumes the current path is the SConstruct directory ...
+ old_fs_dir = SConfFS.getcwd()
+ old_os_dir = os.getcwd()
+ SConfFS.chdir(SConfFS.Top, change_os_dir=1)
+
+ # Because we take responsibility here for writing out our
+ # own .sconsign info (see SConfBuildTask.execute(), above),
+ # we override the store_info() method with a null place-holder
+ # so we really control how it gets written.
+ for n in nodes:
+ n.store_info = n.do_not_store_info
+
+ ret = 1
+
+ try:
+ # ToDo: use user options for calc
+ save_max_drift = SConfFS.get_max_drift()
+ SConfFS.set_max_drift(0)
+ tm = SCons.Taskmaster.Taskmaster(nodes, SConfBuildTask)
+ # we don't want to build tests in parallel
+ jobs = SCons.Job.Jobs(1, tm )
+ jobs.run()
+ for n in nodes:
+ state = n.get_state()
+ if (state != SCons.Node.executed and
+ state != SCons.Node.up_to_date):
+ # the node could not be built. we return 0 in this case
+ ret = 0
+ finally:
+ SConfFS.set_max_drift(save_max_drift)
+ os.chdir(old_os_dir)
+ SConfFS.chdir(old_fs_dir, change_os_dir=0)
+ if self.logstream is not None:
+ # restore stdout / stderr
+ sys.stdout = oldStdout
+ sys.stderr = oldStderr
+ return ret
+
+ def pspawn_wrapper(self, sh, escape, cmd, args, env):
+ """Wrapper function for handling piped spawns.
+
+ This looks to the calling interface (in Action.py) like a "normal"
+ spawn, but associates the call with the PSPAWN variable from
+ the construction environment and with the streams to which we
+ want the output logged. This gets slid into the construction
+ environment as the SPAWN variable so Action.py doesn't have to
+ know or care whether it's spawning a piped command or not.
+ """
+ return self.pspawn(sh, escape, cmd, args, env, self.logstream, self.logstream)
+
+
+ def TryBuild(self, builder, text = None, extension = ""):
+ """Low level TryBuild implementation. Normally you don't need to
+ call that - you can use TryCompile / TryLink / TryRun instead
+ """
+ global _ac_build_counter
+
+ # Make sure we have a PSPAWN value, and save the current
+ # SPAWN value.
+ try:
+ self.pspawn = self.env['PSPAWN']
+ except KeyError:
+ raise SCons.Errors.UserError('Missing PSPAWN construction variable.')
+ try:
+ save_spawn = self.env['SPAWN']
+ except KeyError:
+ raise SCons.Errors.UserError('Missing SPAWN construction variable.')
+
+ nodesToBeBuilt = []
+
+ f = "conftest_" + str(_ac_build_counter)
+ pref = self.env.subst( builder.builder.prefix )
+ suff = self.env.subst( builder.builder.suffix )
+ target = self.confdir.File(pref + f + suff)
+
+ try:
+ # Slide our wrapper into the construction environment as
+ # the SPAWN function.
+ self.env['SPAWN'] = self.pspawn_wrapper
+ sourcetext = self.env.Value(text)
+
+ if text is not None:
+ textFile = self.confdir.File(f + extension)
+ textFileNode = self.env.SConfSourceBuilder(target=textFile,
+ source=sourcetext)
+ nodesToBeBuilt.extend(textFileNode)
+ source = textFileNode
+ else:
+ source = None
+
+ nodes = builder(target = target, source = source)
+ if not SCons.Util.is_List(nodes):
+ nodes = [nodes]
+ nodesToBeBuilt.extend(nodes)
+ result = self.BuildNodes(nodesToBeBuilt)
+
+ finally:
+ self.env['SPAWN'] = save_spawn
+
+ _ac_build_counter = _ac_build_counter + 1
+ if result:
+ self.lastTarget = nodes[0]
+ else:
+ self.lastTarget = None
+
+ return result
+
+ def TryAction(self, action, text = None, extension = ""):
+ """Tries to execute the given action with optional source file
+ contents <text> and optional source file extension <extension>,
+ Returns the status (0 : failed, 1 : ok) and the contents of the
+ output file.
+ """
+ builder = SCons.Builder.Builder(action=action)
+ self.env.Append( BUILDERS = {'SConfActionBuilder' : builder} )
+ ok = self.TryBuild(self.env.SConfActionBuilder, text, extension)
+ del self.env['BUILDERS']['SConfActionBuilder']
+ if ok:
+ outputStr = self.lastTarget.get_contents()
+ return (1, outputStr)
+ return (0, "")
+
+ def TryCompile( self, text, extension):
+ """Compiles the program given in text to an env.Object, using extension
+ as file extension (e.g. '.c'). Returns 1, if compilation was
+ successful, 0 otherwise. The target is saved in self.lastTarget (for
+ further processing).
+ """
+ return self.TryBuild(self.env.Object, text, extension)
+
+ def TryLink( self, text, extension ):
+ """Compiles the program given in text to an executable env.Program,
+ using extension as file extension (e.g. '.c'). Returns 1, if
+ compilation was successful, 0 otherwise. The target is saved in
+ self.lastTarget (for further processing).
+ """
+ return self.TryBuild(self.env.Program, text, extension )
+
+ def TryRun(self, text, extension ):
+ """Compiles and runs the program given in text, using extension
+ as file extension (e.g. '.c'). Returns (1, outputStr) on success,
+ (0, '') otherwise. The target (a file containing the program's stdout)
+ is saved in self.lastTarget (for further processing).
+ """
+ ok = self.TryLink(text, extension)
+ if( ok ):
+ prog = self.lastTarget
+ pname = prog.path
+ output = self.confdir.File(os.path.basename(pname)+'.out')
+ node = self.env.Command(output, prog, [ [ pname, ">", "${TARGET}"] ])
+ ok = self.BuildNodes(node)
+ if ok:
+ outputStr = output.get_contents()
+ return( 1, outputStr)
+ return (0, "")
+
+ class TestWrapper(object):
+ """A wrapper around Tests (to ensure sanity)"""
+ def __init__(self, test, sconf):
+ self.test = test
+ self.sconf = sconf
+ def __call__(self, *args, **kw):
+ if not self.sconf.active:
+ raise SCons.Errors.UserError
+ context = CheckContext(self.sconf)
+ ret = self.test(context, *args, **kw)
+ if self.sconf.config_h is not None:
+ self.sconf.config_h_text = self.sconf.config_h_text + context.config_h
+ context.Result("error: no result")
+ return ret
+
+ def AddTest(self, test_name, test_instance):
+ """Adds test_class to this SConf instance. It can be called with
+ self.test_name(...)"""
+ setattr(self, test_name, SConfBase.TestWrapper(test_instance, self))
+
+ def AddTests(self, tests):
+ """Adds all the tests given in the tests dictionary to this SConf
+ instance
+ """
+ for name in tests.keys():
+ self.AddTest(name, tests[name])
+
+ def _createDir( self, node ):
+ dirName = str(node)
+ if dryrun:
+ if not os.path.isdir( dirName ):
+ raise ConfigureDryRunError(dirName)
+ else:
+ if not os.path.isdir( dirName ):
+ os.makedirs( dirName )
+ node._exists = 1
+
+ def _startup(self):
+ """Private method. Set up logstream, and set the environment
+ variables necessary for a piped build
+ """
+ global _ac_config_logs
+ global sconf_global
+ global SConfFS
+
+ self.lastEnvFs = self.env.fs
+ self.env.fs = SConfFS
+ self._createDir(self.confdir)
+ self.confdir.up().add_ignore( [self.confdir] )
+
+ if self.logfile is not None and not dryrun:
+ # truncate logfile, if SConf.Configure is called for the first time
+ # in a build
+ if self.logfile in _ac_config_logs:
+ log_mode = "a"
+ else:
+ _ac_config_logs[self.logfile] = None
+ log_mode = "w"
+ fp = open(str(self.logfile), log_mode)
+ self.logstream = SCons.Util.Unbuffered(fp)
+ # logfile may stay in a build directory, so we tell
+ # the build system not to override it with a eventually
+ # existing file with the same name in the source directory
+ self.logfile.dir.add_ignore( [self.logfile] )
+
+ tb = traceback.extract_stack()[-3-self.depth]
+ old_fs_dir = SConfFS.getcwd()
+ SConfFS.chdir(SConfFS.Top, change_os_dir=0)
+ self.logstream.write('file %s,line %d:\n\tConfigure(confdir = %s)\n' %
+ (tb[0], tb[1], str(self.confdir)) )
+ SConfFS.chdir(old_fs_dir)
+ else:
+ self.logstream = None
+ # we use a special builder to create source files from TEXT
+ action = SCons.Action.Action(_createSource,
+ _stringSource)
+ sconfSrcBld = SCons.Builder.Builder(action=action)
+ self.env.Append( BUILDERS={'SConfSourceBuilder':sconfSrcBld} )
+ self.config_h_text = _ac_config_hs.get(self.config_h, "")
+ self.active = 1
+ # only one SConf instance should be active at a time ...
+ sconf_global = self
+
+ def _shutdown(self):
+ """Private method. Reset to non-piped spawn"""
+ global sconf_global, _ac_config_hs
+
+ if not self.active:
+ raise SCons.Errors.UserError("Finish may be called only once!")
+ if self.logstream is not None and not dryrun:
+ self.logstream.write("\n")
+ self.logstream.close()
+ self.logstream = None
+ # remove the SConfSourceBuilder from the environment
+ blds = self.env['BUILDERS']
+ del blds['SConfSourceBuilder']
+ self.env.Replace( BUILDERS=blds )
+ self.active = 0
+ sconf_global = None
+ if not self.config_h is None:
+ _ac_config_hs[self.config_h] = self.config_h_text
+ self.env.fs = self.lastEnvFs
+
+class CheckContext(object):
+ """Provides a context for configure tests. Defines how a test writes to the
+ screen and log file.
+
+ A typical test is just a callable with an instance of CheckContext as
+ first argument:
+
+ def CheckCustom(context, ...)
+ context.Message('Checking my weird test ... ')
+ ret = myWeirdTestFunction(...)
+ context.Result(ret)
+
+ Often, myWeirdTestFunction will be one of
+ context.TryCompile/context.TryLink/context.TryRun. The results of
+ those are cached, for they are only rebuild, if the dependencies have
+ changed.
+ """
+
+ def __init__(self, sconf):
+ """Constructor. Pass the corresponding SConf instance."""
+ self.sconf = sconf
+ self.did_show_result = 0
+
+ # for Conftest.py:
+ self.vardict = {}
+ self.havedict = {}
+ self.headerfilename = None
+ self.config_h = "" # config_h text will be stored here
+ # we don't regenerate the config.h file after each test. That means,
+ # that tests won't be able to include the config.h file, and so
+ # they can't do an #ifdef HAVE_XXX_H. This shouldn't be a major
+ # issue, though. If it turns out, that we need to include config.h
+ # in tests, we must ensure, that the dependencies are worked out
+ # correctly. Note that we can't use Conftest.py's support for config.h,
+ # cause we will need to specify a builder for the config.h file ...
+
+ def Message(self, text):
+ """Inform about what we are doing right now, e.g.
+ 'Checking for SOMETHING ... '
+ """
+ self.Display(text)
+ self.sconf.cached = 1
+ self.did_show_result = 0
+
+ def Result(self, res):
+ """Inform about the result of the test. res may be an integer or a
+ string. In case of an integer, the written text will be 'yes' or 'no'.
+ The result is only displayed when self.did_show_result is not set.
+ """
+ if isinstance(res, (int, bool)):
+ if res:
+ text = "yes"
+ else:
+ text = "no"
+ elif isinstance(res, str):
+ text = res
+ else:
+ raise TypeError("Expected string, int or bool, got " + str(type(res)))
+
+ if self.did_show_result == 0:
+ # Didn't show result yet, do it now.
+ self.Display(text + "\n")
+ self.did_show_result = 1
+
+ def TryBuild(self, *args, **kw):
+ return self.sconf.TryBuild(*args, **kw)
+
+ def TryAction(self, *args, **kw):
+ return self.sconf.TryAction(*args, **kw)
+
+ def TryCompile(self, *args, **kw):
+ return self.sconf.TryCompile(*args, **kw)
+
+ def TryLink(self, *args, **kw):
+ return self.sconf.TryLink(*args, **kw)
+
+ def TryRun(self, *args, **kw):
+ return self.sconf.TryRun(*args, **kw)
+
+ def __getattr__( self, attr ):
+ if( attr == 'env' ):
+ return self.sconf.env
+ elif( attr == 'lastTarget' ):
+ return self.sconf.lastTarget
+ else:
+ raise AttributeError("CheckContext instance has no attribute '%s'" % attr)
+
+ #### Stuff used by Conftest.py (look there for explanations).
+
+ def BuildProg(self, text, ext):
+ self.sconf.cached = 1
+ # TODO: should use self.vardict for $CC, $CPPFLAGS, etc.
+ return not self.TryBuild(self.env.Program, text, ext)
+
+ def CompileProg(self, text, ext):
+ self.sconf.cached = 1
+ # TODO: should use self.vardict for $CC, $CPPFLAGS, etc.
+ return not self.TryBuild(self.env.Object, text, ext)
+
+ def CompileSharedObject(self, text, ext):
+ self.sconf.cached = 1
+ # TODO: should use self.vardict for $SHCC, $CPPFLAGS, etc.
+ return not self.TryBuild(self.env.SharedObject, text, ext)
+
+ def RunProg(self, text, ext):
+ self.sconf.cached = 1
+ # TODO: should use self.vardict for $CC, $CPPFLAGS, etc.
+ st, out = self.TryRun(text, ext)
+ return not st, out
+
+ def AppendLIBS(self, lib_name_list):
+ oldLIBS = self.env.get( 'LIBS', [] )
+ self.env.Append(LIBS = lib_name_list)
+ return oldLIBS
+
+ def PrependLIBS(self, lib_name_list):
+ oldLIBS = self.env.get( 'LIBS', [] )
+ self.env.Prepend(LIBS = lib_name_list)
+ return oldLIBS
+
+ def SetLIBS(self, val):
+ oldLIBS = self.env.get( 'LIBS', [] )
+ self.env.Replace(LIBS = val)
+ return oldLIBS
+
+ def Display(self, msg):
+ if self.sconf.cached:
+ # We assume that Display is called twice for each test here
+ # once for the Checking for ... message and once for the result.
+ # The self.sconf.cached flag can only be set between those calls
+ msg = "(cached) " + msg
+ self.sconf.cached = 0
+ progress_display(msg, append_newline=0)
+ self.Log("scons: Configure: " + msg + "\n")
+
+ def Log(self, msg):
+ if self.sconf.logstream is not None:
+ self.sconf.logstream.write(msg)
+
+ #### End of stuff used by Conftest.py.
+
+
+def SConf(*args, **kw):
+ if kw.get(build_type, True):
+ kw['_depth'] = kw.get('_depth', 0) + 1
+ for bt in build_types:
+ try:
+ del kw[bt]
+ except KeyError:
+ pass
+ return SConfBase(*args, **kw)
+ else:
+ return SCons.Util.Null()
+
+
+def CheckFunc(context, function_name, header = None, language = None):
+ res = SCons.Conftest.CheckFunc(context, function_name, header = header, language = language)
+ context.did_show_result = 1
+ return not res
+
+def CheckType(context, type_name, includes = "", language = None):
+ res = SCons.Conftest.CheckType(context, type_name,
+ header = includes, language = language)
+ context.did_show_result = 1
+ return not res
+
+def CheckTypeSize(context, type_name, includes = "", language = None, expect = None):
+ res = SCons.Conftest.CheckTypeSize(context, type_name,
+ header = includes, language = language,
+ expect = expect)
+ context.did_show_result = 1
+ return res
+
+def CheckDeclaration(context, declaration, includes = "", language = None):
+ res = SCons.Conftest.CheckDeclaration(context, declaration,
+ includes = includes,
+ language = language)
+ context.did_show_result = 1
+ return not res
+
+def createIncludesFromHeaders(headers, leaveLast, include_quotes = '""'):
+ # used by CheckHeader and CheckLibWithHeader to produce C - #include
+ # statements from the specified header (list)
+ if not SCons.Util.is_List(headers):
+ headers = [headers]
+ l = []
+ if leaveLast:
+ lastHeader = headers[-1]
+ headers = headers[:-1]
+ else:
+ lastHeader = None
+ for s in headers:
+ l.append("#include %s%s%s\n"
+ % (include_quotes[0], s, include_quotes[1]))
+ return ''.join(l), lastHeader
+
+def CheckHeader(context, header, include_quotes = '<>', language = None):
+ """
+ A test for a C or C++ header file.
+ """
+ prog_prefix, hdr_to_check = \
+ createIncludesFromHeaders(header, 1, include_quotes)
+ res = SCons.Conftest.CheckHeader(context, hdr_to_check, prog_prefix,
+ language = language,
+ include_quotes = include_quotes)
+ context.did_show_result = 1
+ return not res
+
+def CheckCC(context):
+ res = SCons.Conftest.CheckCC(context)
+ context.did_show_result = 1
+ return not res
+
+def CheckCXX(context):
+ res = SCons.Conftest.CheckCXX(context)
+ context.did_show_result = 1
+ return not res
+
+def CheckSHCC(context):
+ res = SCons.Conftest.CheckSHCC(context)
+ context.did_show_result = 1
+ return not res
+
+def CheckSHCXX(context):
+ res = SCons.Conftest.CheckSHCXX(context)
+ context.did_show_result = 1
+ return not res
+
+# Bram: Make this function obsolete? CheckHeader() is more generic.
+
+def CheckCHeader(context, header, include_quotes = '""'):
+ """
+ A test for a C header file.
+ """
+ return CheckHeader(context, header, include_quotes, language = "C")
+
+
+# Bram: Make this function obsolete? CheckHeader() is more generic.
+
+def CheckCXXHeader(context, header, include_quotes = '""'):
+ """
+ A test for a C++ header file.
+ """
+ return CheckHeader(context, header, include_quotes, language = "C++")
+
+
+def CheckLib(context, library = None, symbol = "main",
+ header = None, language = None, autoadd = 1):
+ """
+ A test for a library. See also CheckLibWithHeader.
+ Note that library may also be None to test whether the given symbol
+ compiles without flags.
+ """
+
+ if library == []:
+ library = [None]
+
+ if not SCons.Util.is_List(library):
+ library = [library]
+
+ # ToDo: accept path for the library
+ res = SCons.Conftest.CheckLib(context, library, symbol, header = header,
+ language = language, autoadd = autoadd)
+ context.did_show_result = 1
+ return not res
+
+# XXX
+# Bram: Can only include one header and can't use #ifdef HAVE_HEADER_H.
+
+def CheckLibWithHeader(context, libs, header, language,
+ call = None, autoadd = 1):
+ # ToDo: accept path for library. Support system header files.
+ """
+ Another (more sophisticated) test for a library.
+ Checks, if library and header is available for language (may be 'C'
+ or 'CXX'). Call maybe be a valid expression _with_ a trailing ';'.
+ As in CheckLib, we support library=None, to test if the call compiles
+ without extra link flags.
+ """
+ prog_prefix, dummy = \
+ createIncludesFromHeaders(header, 0)
+ if libs == []:
+ libs = [None]
+
+ if not SCons.Util.is_List(libs):
+ libs = [libs]
+
+ res = SCons.Conftest.CheckLib(context, libs, None, prog_prefix,
+ call = call, language = language, autoadd = autoadd)
+ context.did_show_result = 1
+ return not res
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/SConsign.py b/couchjs/scons/scons-local-2.0.1/SCons/SConsign.py
new file mode 100644
index 00000000..0d78a6d6
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/SConsign.py
@@ -0,0 +1,383 @@
+"""SCons.SConsign
+
+Writing and reading information to the .sconsign file or files.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/SConsign.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.compat
+
+import os
+# compat layer imports "cPickle" for us if it's available.
+import pickle
+
+import SCons.dblite
+import SCons.Warnings
+
+def corrupt_dblite_warning(filename):
+ SCons.Warnings.warn(SCons.Warnings.CorruptSConsignWarning,
+ "Ignoring corrupt .sconsign file: %s"%filename)
+
+SCons.dblite.ignore_corrupt_dbfiles = 1
+SCons.dblite.corruption_warning = corrupt_dblite_warning
+
+#XXX Get rid of the global array so this becomes re-entrant.
+sig_files = []
+
+# Info for the database SConsign implementation (now the default):
+# "DataBase" is a dictionary that maps top-level SConstruct directories
+# to open database handles.
+# "DB_Module" is the Python database module to create the handles.
+# "DB_Name" is the base name of the database file (minus any
+# extension the underlying DB module will add).
+DataBase = {}
+DB_Module = SCons.dblite
+DB_Name = ".sconsign"
+DB_sync_list = []
+
+def Get_DataBase(dir):
+ global DataBase, DB_Module, DB_Name
+ top = dir.fs.Top
+ if not os.path.isabs(DB_Name) and top.repositories:
+ mode = "c"
+ for d in [top] + top.repositories:
+ if dir.is_under(d):
+ try:
+ return DataBase[d], mode
+ except KeyError:
+ path = d.entry_abspath(DB_Name)
+ try: db = DataBase[d] = DB_Module.open(path, mode)
+ except (IOError, OSError): pass
+ else:
+ if mode != "r":
+ DB_sync_list.append(db)
+ return db, mode
+ mode = "r"
+ try:
+ return DataBase[top], "c"
+ except KeyError:
+ db = DataBase[top] = DB_Module.open(DB_Name, "c")
+ DB_sync_list.append(db)
+ return db, "c"
+ except TypeError:
+ print "DataBase =", DataBase
+ raise
+
+def Reset():
+ """Reset global state. Used by unit tests that end up using
+ SConsign multiple times to get a clean slate for each test."""
+ global sig_files, DB_sync_list
+ sig_files = []
+ DB_sync_list = []
+
+normcase = os.path.normcase
+
+def write():
+ global sig_files
+ for sig_file in sig_files:
+ sig_file.write(sync=0)
+ for db in DB_sync_list:
+ try:
+ syncmethod = db.sync
+ except AttributeError:
+ pass # Not all anydbm modules have sync() methods.
+ else:
+ syncmethod()
+
+class SConsignEntry(object):
+ """
+ Wrapper class for the generic entry in a .sconsign file.
+ The Node subclass populates it with attributes as it pleases.
+
+ XXX As coded below, we do expect a '.binfo' attribute to be added,
+ but we'll probably generalize this in the next refactorings.
+ """
+ current_version_id = 1
+ def __init__(self):
+ # Create an object attribute from the class attribute so it ends up
+ # in the pickled data in the .sconsign file.
+ _version_id = self.current_version_id
+ def convert_to_sconsign(self):
+ self.binfo.convert_to_sconsign()
+ def convert_from_sconsign(self, dir, name):
+ self.binfo.convert_from_sconsign(dir, name)
+
+class Base(object):
+ """
+ This is the controlling class for the signatures for the collection of
+ entries associated with a specific directory. The actual directory
+ association will be maintained by a subclass that is specific to
+ the underlying storage method. This class provides a common set of
+ methods for fetching and storing the individual bits of information
+ that make up signature entry.
+ """
+ def __init__(self):
+ self.entries = {}
+ self.dirty = False
+ self.to_be_merged = {}
+
+ def get_entry(self, filename):
+ """
+ Fetch the specified entry attribute.
+ """
+ return self.entries[filename]
+
+ def set_entry(self, filename, obj):
+ """
+ Set the entry.
+ """
+ self.entries[filename] = obj
+ self.dirty = True
+
+ def do_not_set_entry(self, filename, obj):
+ pass
+
+ def store_info(self, filename, node):
+ entry = node.get_stored_info()
+ entry.binfo.merge(node.get_binfo())
+ self.to_be_merged[filename] = node
+ self.dirty = True
+
+ def do_not_store_info(self, filename, node):
+ pass
+
+ def merge(self):
+ for key, node in self.to_be_merged.items():
+ entry = node.get_stored_info()
+ try:
+ ninfo = entry.ninfo
+ except AttributeError:
+ # This happens with SConf Nodes, because the configuration
+ # subsystem takes direct control over how the build decision
+ # is made and its information stored.
+ pass
+ else:
+ ninfo.merge(node.get_ninfo())
+ self.entries[key] = entry
+ self.to_be_merged = {}
+
+class DB(Base):
+ """
+ A Base subclass that reads and writes signature information
+ from a global .sconsign.db* file--the actual file suffix is
+ determined by the database module.
+ """
+ def __init__(self, dir):
+ Base.__init__(self)
+
+ self.dir = dir
+
+ db, mode = Get_DataBase(dir)
+
+ # Read using the path relative to the top of the Repository
+ # (self.dir.tpath) from which we're fetching the signature
+ # information.
+ path = normcase(dir.tpath)
+ try:
+ rawentries = db[path]
+ except KeyError:
+ pass
+ else:
+ try:
+ self.entries = pickle.loads(rawentries)
+ if not isinstance(self.entries, dict):
+ self.entries = {}
+ raise TypeError
+ except KeyboardInterrupt:
+ raise
+ except Exception, e:
+ SCons.Warnings.warn(SCons.Warnings.CorruptSConsignWarning,
+ "Ignoring corrupt sconsign entry : %s (%s)\n"%(self.dir.tpath, e))
+ for key, entry in self.entries.items():
+ entry.convert_from_sconsign(dir, key)
+
+ if mode == "r":
+ # This directory is actually under a repository, which means
+ # likely they're reaching in directly for a dependency on
+ # a file there. Don't actually set any entry info, so we
+ # won't try to write to that .sconsign.dblite file.
+ self.set_entry = self.do_not_set_entry
+ self.store_info = self.do_not_store_info
+
+ global sig_files
+ sig_files.append(self)
+
+ def write(self, sync=1):
+ if not self.dirty:
+ return
+
+ self.merge()
+
+ db, mode = Get_DataBase(self.dir)
+
+ # Write using the path relative to the top of the SConstruct
+ # directory (self.dir.path), not relative to the top of
+ # the Repository; we only write to our own .sconsign file,
+ # not to .sconsign files in Repositories.
+ path = normcase(self.dir.path)
+ for key, entry in self.entries.items():
+ entry.convert_to_sconsign()
+ db[path] = pickle.dumps(self.entries, 1)
+
+ if sync:
+ try:
+ syncmethod = db.sync
+ except AttributeError:
+ # Not all anydbm modules have sync() methods.
+ pass
+ else:
+ syncmethod()
+
+class Dir(Base):
+ def __init__(self, fp=None, dir=None):
+ """
+ fp - file pointer to read entries from
+ """
+ Base.__init__(self)
+
+ if not fp:
+ return
+
+ self.entries = pickle.load(fp)
+ if not isinstance(self.entries, dict):
+ self.entries = {}
+ raise TypeError
+
+ if dir:
+ for key, entry in self.entries.items():
+ entry.convert_from_sconsign(dir, key)
+
+class DirFile(Dir):
+ """
+ Encapsulates reading and writing a per-directory .sconsign file.
+ """
+ def __init__(self, dir):
+ """
+ dir - the directory for the file
+ """
+
+ self.dir = dir
+ self.sconsign = os.path.join(dir.path, '.sconsign')
+
+ try:
+ fp = open(self.sconsign, 'rb')
+ except IOError:
+ fp = None
+
+ try:
+ Dir.__init__(self, fp, dir)
+ except KeyboardInterrupt:
+ raise
+ except:
+ SCons.Warnings.warn(SCons.Warnings.CorruptSConsignWarning,
+ "Ignoring corrupt .sconsign file: %s"%self.sconsign)
+
+ global sig_files
+ sig_files.append(self)
+
+ def write(self, sync=1):
+ """
+ Write the .sconsign file to disk.
+
+ Try to write to a temporary file first, and rename it if we
+ succeed. If we can't write to the temporary file, it's
+ probably because the directory isn't writable (and if so,
+ how did we build anything in this directory, anyway?), so
+ try to write directly to the .sconsign file as a backup.
+ If we can't rename, try to copy the temporary contents back
+ to the .sconsign file. Either way, always try to remove
+ the temporary file at the end.
+ """
+ if not self.dirty:
+ return
+
+ self.merge()
+
+ temp = os.path.join(self.dir.path, '.scons%d' % os.getpid())
+ try:
+ file = open(temp, 'wb')
+ fname = temp
+ except IOError:
+ try:
+ file = open(self.sconsign, 'wb')
+ fname = self.sconsign
+ except IOError:
+ return
+ for key, entry in self.entries.items():
+ entry.convert_to_sconsign()
+ pickle.dump(self.entries, file, 1)
+ file.close()
+ if fname != self.sconsign:
+ try:
+ mode = os.stat(self.sconsign)[0]
+ os.chmod(self.sconsign, 0666)
+ os.unlink(self.sconsign)
+ except (IOError, OSError):
+ # Try to carry on in the face of either OSError
+ # (things like permission issues) or IOError (disk
+ # or network issues). If there's a really dangerous
+ # issue, it should get re-raised by the calls below.
+ pass
+ try:
+ os.rename(fname, self.sconsign)
+ except OSError:
+ # An OSError failure to rename may indicate something
+ # like the directory has no write permission, but
+ # the .sconsign file itself might still be writable,
+ # so try writing on top of it directly. An IOError
+ # here, or in any of the following calls, would get
+ # raised, indicating something like a potentially
+ # serious disk or network issue.
+ open(self.sconsign, 'wb').write(open(fname, 'rb').read())
+ os.chmod(self.sconsign, mode)
+ try:
+ os.unlink(temp)
+ except (IOError, OSError):
+ pass
+
+ForDirectory = DB
+
+def File(name, dbm_module=None):
+ """
+ Arrange for all signatures to be stored in a global .sconsign.db*
+ file.
+ """
+ global ForDirectory, DB_Name, DB_Module
+ if name is None:
+ ForDirectory = DirFile
+ DB_Module = None
+ else:
+ ForDirectory = DB
+ DB_Name = name
+ if not dbm_module is None:
+ DB_Module = dbm_module
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Scanner/C.py b/couchjs/scons/scons-local-2.0.1/SCons/Scanner/C.py
new file mode 100644
index 00000000..3ac769ae
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Scanner/C.py
@@ -0,0 +1,132 @@
+"""SCons.Scanner.C
+
+This module implements the depenency scanner for C/C++ code.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Scanner/C.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Node.FS
+import SCons.Scanner
+import SCons.Util
+
+import SCons.cpp
+
+class SConsCPPScanner(SCons.cpp.PreProcessor):
+ """
+ SCons-specific subclass of the cpp.py module's processing.
+
+ We subclass this so that: 1) we can deal with files represented
+ by Nodes, not strings; 2) we can keep track of the files that are
+ missing.
+ """
+ def __init__(self, *args, **kw):
+ SCons.cpp.PreProcessor.__init__(self, *args, **kw)
+ self.missing = []
+ def initialize_result(self, fname):
+ self.result = SCons.Util.UniqueList([fname])
+ def finalize_result(self, fname):
+ return self.result[1:]
+ def find_include_file(self, t):
+ keyword, quote, fname = t
+ result = SCons.Node.FS.find_file(fname, self.searchpath[quote])
+ if not result:
+ self.missing.append((fname, self.current_file))
+ return result
+ def read_file(self, file):
+ try:
+ fp = open(str(file.rfile()))
+ except EnvironmentError, e:
+ self.missing.append((file, self.current_file))
+ return ''
+ else:
+ return fp.read()
+
+def dictify_CPPDEFINES(env):
+ cppdefines = env.get('CPPDEFINES', {})
+ if cppdefines is None:
+ return {}
+ if SCons.Util.is_Sequence(cppdefines):
+ result = {}
+ for c in cppdefines:
+ if SCons.Util.is_Sequence(c):
+ result[c[0]] = c[1]
+ else:
+ result[c] = None
+ return result
+ if not SCons.Util.is_Dict(cppdefines):
+ return {cppdefines : None}
+ return cppdefines
+
+class SConsCPPScannerWrapper(object):
+ """
+ The SCons wrapper around a cpp.py scanner.
+
+ This is the actual glue between the calling conventions of generic
+ SCons scanners, and the (subclass of) cpp.py class that knows how
+ to look for #include lines with reasonably real C-preprocessor-like
+ evaluation of #if/#ifdef/#else/#elif lines.
+ """
+ def __init__(self, name, variable):
+ self.name = name
+ self.path = SCons.Scanner.FindPathDirs(variable)
+ def __call__(self, node, env, path = ()):
+ cpp = SConsCPPScanner(current = node.get_dir(),
+ cpppath = path,
+ dict = dictify_CPPDEFINES(env))
+ result = cpp(node)
+ for included, includer in cpp.missing:
+ fmt = "No dependency generated for file: %s (included from: %s) -- file not found"
+ SCons.Warnings.warn(SCons.Warnings.DependencyWarning,
+ fmt % (included, includer))
+ return result
+
+ def recurse_nodes(self, nodes):
+ return nodes
+ def select(self, node):
+ return self
+
+def CScanner():
+ """Return a prototype Scanner instance for scanning source files
+ that use the C pre-processor"""
+
+ # Here's how we would (or might) use the CPP scanner code above that
+ # knows how to evaluate #if/#ifdef/#else/#elif lines when searching
+ # for #includes. This is commented out for now until we add the
+ # right configurability to let users pick between the scanners.
+ #return SConsCPPScannerWrapper("CScanner", "CPPPATH")
+
+ cs = SCons.Scanner.ClassicCPP("CScanner",
+ "$CPPSUFFIXES",
+ "CPPPATH",
+ '^[ \t]*#[ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")')
+ return cs
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Scanner/D.py b/couchjs/scons/scons-local-2.0.1/SCons/Scanner/D.py
new file mode 100644
index 00000000..2293ddd0
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Scanner/D.py
@@ -0,0 +1,73 @@
+"""SCons.Scanner.D
+
+Scanner for the Digital Mars "D" programming language.
+
+Coded by Andy Friesen
+17 Nov 2003
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Scanner/D.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import re
+
+import SCons.Scanner
+
+def DScanner():
+ """Return a prototype Scanner instance for scanning D source files"""
+ ds = D()
+ return ds
+
+class D(SCons.Scanner.Classic):
+ def __init__ (self):
+ SCons.Scanner.Classic.__init__ (self,
+ name = "DScanner",
+ suffixes = '$DSUFFIXES',
+ path_variable = 'DPATH',
+ regex = 'import\s+(?:[a-zA-Z0-9_.]+)\s*(?:,\s*(?:[a-zA-Z0-9_.]+)\s*)*;')
+
+ self.cre2 = re.compile ('(?:import\s)?\s*([a-zA-Z0-9_.]+)\s*(?:,|;)', re.M)
+
+ def find_include(self, include, source_dir, path):
+ # translate dots (package separators) to slashes
+ inc = include.replace('.', '/')
+
+ i = SCons.Node.FS.find_file(inc + '.d', (source_dir,) + path)
+ if i is None:
+ i = SCons.Node.FS.find_file (inc + '.di', (source_dir,) + path)
+ return i, include
+
+ def find_include_names(self, node):
+ includes = []
+ for i in self.cre.findall(node.get_text_contents()):
+ includes = includes + self.cre2.findall(i)
+ return includes
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Scanner/Dir.py b/couchjs/scons/scons-local-2.0.1/SCons/Scanner/Dir.py
new file mode 100644
index 00000000..df0de4e6
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Scanner/Dir.py
@@ -0,0 +1,109 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Scanner/Dir.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Node.FS
+import SCons.Scanner
+
+def only_dirs(nodes):
+ is_Dir = lambda n: isinstance(n.disambiguate(), SCons.Node.FS.Dir)
+ return list(filter(is_Dir, nodes))
+
+def DirScanner(**kw):
+ """Return a prototype Scanner instance for scanning
+ directories for on-disk files"""
+ kw['node_factory'] = SCons.Node.FS.Entry
+ kw['recursive'] = only_dirs
+ return SCons.Scanner.Base(scan_on_disk, "DirScanner", **kw)
+
+def DirEntryScanner(**kw):
+ """Return a prototype Scanner instance for "scanning"
+ directory Nodes for their in-memory entries"""
+ kw['node_factory'] = SCons.Node.FS.Entry
+ kw['recursive'] = None
+ return SCons.Scanner.Base(scan_in_memory, "DirEntryScanner", **kw)
+
+skip_entry = {}
+
+skip_entry_list = [
+ '.',
+ '..',
+ '.sconsign',
+ # Used by the native dblite.py module.
+ '.sconsign.dblite',
+ # Used by dbm and dumbdbm.
+ '.sconsign.dir',
+ # Used by dbm.
+ '.sconsign.pag',
+ # Used by dumbdbm.
+ '.sconsign.dat',
+ '.sconsign.bak',
+ # Used by some dbm emulations using Berkeley DB.
+ '.sconsign.db',
+]
+
+for skip in skip_entry_list:
+ skip_entry[skip] = 1
+ skip_entry[SCons.Node.FS._my_normcase(skip)] = 1
+
+do_not_scan = lambda k: k not in skip_entry
+
+def scan_on_disk(node, env, path=()):
+ """
+ Scans a directory for on-disk files and directories therein.
+
+ Looking up the entries will add these to the in-memory Node tree
+ representation of the file system, so all we have to do is just
+ that and then call the in-memory scanning function.
+ """
+ try:
+ flist = node.fs.listdir(node.abspath)
+ except (IOError, OSError):
+ return []
+ e = node.Entry
+ for f in filter(do_not_scan, flist):
+ # Add ./ to the beginning of the file name so if it begins with a
+ # '#' we don't look it up relative to the top-level directory.
+ e('./' + f)
+ return scan_in_memory(node, env, path)
+
+def scan_in_memory(node, env, path=()):
+ """
+ "Scans" a Node.FS.Dir for its in-memory entries.
+ """
+ try:
+ entries = node.entries
+ except AttributeError:
+ # It's not a Node.FS.Dir (or doesn't look enough like one for
+ # our purposes), which can happen if a target list containing
+ # mixed Node types (Dirs and Files, for example) has a Dir as
+ # the first entry.
+ return []
+ entry_list = sorted(filter(do_not_scan, list(entries.keys())))
+ return [entries[n] for n in entry_list]
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Scanner/Fortran.py b/couchjs/scons/scons-local-2.0.1/SCons/Scanner/Fortran.py
new file mode 100644
index 00000000..63d34e49
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Scanner/Fortran.py
@@ -0,0 +1,316 @@
+"""SCons.Scanner.Fortran
+
+This module implements the dependency scanner for Fortran code.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Scanner/Fortran.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import re
+
+import SCons.Node
+import SCons.Node.FS
+import SCons.Scanner
+import SCons.Util
+import SCons.Warnings
+
+class F90Scanner(SCons.Scanner.Classic):
+ """
+ A Classic Scanner subclass for Fortran source files which takes
+ into account both USE and INCLUDE statements. This scanner will
+ work for both F77 and F90 (and beyond) compilers.
+
+ Currently, this scanner assumes that the include files do not contain
+ USE statements. To enable the ability to deal with USE statements
+ in include files, add logic right after the module names are found
+ to loop over each include file, search for and locate each USE
+ statement, and append each module name to the list of dependencies.
+ Caching the search results in a common dictionary somewhere so that
+ the same include file is not searched multiple times would be a
+ smart thing to do.
+ """
+
+ def __init__(self, name, suffixes, path_variable,
+ use_regex, incl_regex, def_regex, *args, **kw):
+
+ self.cre_use = re.compile(use_regex, re.M)
+ self.cre_incl = re.compile(incl_regex, re.M)
+ self.cre_def = re.compile(def_regex, re.M)
+
+ def _scan(node, env, path, self=self):
+ node = node.rfile()
+
+ if not node.exists():
+ return []
+
+ return self.scan(node, env, path)
+
+ kw['function'] = _scan
+ kw['path_function'] = SCons.Scanner.FindPathDirs(path_variable)
+ kw['recursive'] = 1
+ kw['skeys'] = suffixes
+ kw['name'] = name
+
+ SCons.Scanner.Current.__init__(self, *args, **kw)
+
+ def scan(self, node, env, path=()):
+
+ # cache the includes list in node so we only scan it once:
+ if node.includes != None:
+ mods_and_includes = node.includes
+ else:
+ # retrieve all included filenames
+ includes = self.cre_incl.findall(node.get_text_contents())
+ # retrieve all USE'd module names
+ modules = self.cre_use.findall(node.get_text_contents())
+ # retrieve all defined module names
+ defmodules = self.cre_def.findall(node.get_text_contents())
+
+ # Remove all USE'd module names that are defined in the same file
+ # (case-insensitively)
+ d = {}
+ for m in defmodules:
+ d[m.lower()] = 1
+ modules = [m for m in modules if m.lower() not in d]
+
+ # Convert module name to a .mod filename
+ suffix = env.subst('$FORTRANMODSUFFIX')
+ modules = [x.lower() + suffix for x in modules]
+ # Remove unique items from the list
+ mods_and_includes = SCons.Util.unique(includes+modules)
+ node.includes = mods_and_includes
+
+ # This is a hand-coded DSU (decorate-sort-undecorate, or
+ # Schwartzian transform) pattern. The sort key is the raw name
+ # of the file as specifed on the USE or INCLUDE line, which lets
+ # us keep the sort order constant regardless of whether the file
+ # is actually found in a Repository or locally.
+ nodes = []
+ source_dir = node.get_dir()
+ if callable(path):
+ path = path()
+ for dep in mods_and_includes:
+ n, i = self.find_include(dep, source_dir, path)
+
+ if n is None:
+ SCons.Warnings.warn(SCons.Warnings.DependencyWarning,
+ "No dependency generated for file: %s (referenced by: %s) -- file not found" % (i, node))
+ else:
+ sortkey = self.sort_key(dep)
+ nodes.append((sortkey, n))
+
+ return [pair[1] for pair in sorted(nodes)]
+
+def FortranScan(path_variable="FORTRANPATH"):
+ """Return a prototype Scanner instance for scanning source files
+ for Fortran USE & INCLUDE statements"""
+
+# The USE statement regex matches the following:
+#
+# USE module_name
+# USE :: module_name
+# USE, INTRINSIC :: module_name
+# USE, NON_INTRINSIC :: module_name
+#
+# Limitations
+#
+# -- While the regex can handle multiple USE statements on one line,
+# it cannot properly handle them if they are commented out.
+# In either of the following cases:
+#
+# ! USE mod_a ; USE mod_b [entire line is commented out]
+# USE mod_a ! ; USE mod_b [in-line comment of second USE statement]
+#
+# the second module name (mod_b) will be picked up as a dependency
+# even though it should be ignored. The only way I can see
+# to rectify this would be to modify the scanner to eliminate
+# the call to re.findall, read in the contents of the file,
+# treating the comment character as an end-of-line character
+# in addition to the normal linefeed, loop over each line,
+# weeding out the comments, and looking for the USE statements.
+# One advantage to this is that the regex passed to the scanner
+# would no longer need to match a semicolon.
+#
+# -- I question whether or not we need to detect dependencies to
+# INTRINSIC modules because these are built-in to the compiler.
+# If we consider them a dependency, will SCons look for them, not
+# find them, and kill the build? Or will we there be standard
+# compiler-specific directories we will need to point to so the
+# compiler and SCons can locate the proper object and mod files?
+
+# Here is a breakdown of the regex:
+#
+# (?i) : regex is case insensitive
+# ^ : start of line
+# (?: : group a collection of regex symbols without saving the match as a "group"
+# ^|; : matches either the start of the line or a semicolon - semicolon
+# ) : end the unsaved grouping
+# \s* : any amount of white space
+# USE : match the string USE, case insensitive
+# (?: : group a collection of regex symbols without saving the match as a "group"
+# \s+| : match one or more whitespace OR .... (the next entire grouped set of regex symbols)
+# (?: : group a collection of regex symbols without saving the match as a "group"
+# (?: : establish another unsaved grouping of regex symbols
+# \s* : any amount of white space
+# , : match a comma
+# \s* : any amount of white space
+# (?:NON_)? : optionally match the prefix NON_, case insensitive
+# INTRINSIC : match the string INTRINSIC, case insensitive
+# )? : optionally match the ", INTRINSIC/NON_INTRINSIC" grouped expression
+# \s* : any amount of white space
+# :: : match a double colon that must appear after the INTRINSIC/NON_INTRINSIC attribute
+# ) : end the unsaved grouping
+# ) : end the unsaved grouping
+# \s* : match any amount of white space
+# (\w+) : match the module name that is being USE'd
+#
+#
+ use_regex = "(?i)(?:^|;)\s*USE(?:\s+|(?:(?:\s*,\s*(?:NON_)?INTRINSIC)?\s*::))\s*(\w+)"
+
+
+# The INCLUDE statement regex matches the following:
+#
+# INCLUDE 'some_Text'
+# INCLUDE "some_Text"
+# INCLUDE "some_Text" ; INCLUDE "some_Text"
+# INCLUDE kind_"some_Text"
+# INCLUDE kind_'some_Text"
+#
+# where some_Text can include any alphanumeric and/or special character
+# as defined by the Fortran 2003 standard.
+#
+# Limitations:
+#
+# -- The Fortran standard dictates that a " or ' in the INCLUDE'd
+# string must be represented as a "" or '', if the quotes that wrap
+# the entire string are either a ' or ", respectively. While the
+# regular expression below can detect the ' or " characters just fine,
+# the scanning logic, presently is unable to detect them and reduce
+# them to a single instance. This probably isn't an issue since,
+# in practice, ' or " are not generally used in filenames.
+#
+# -- This regex will not properly deal with multiple INCLUDE statements
+# when the entire line has been commented out, ala
+#
+# ! INCLUDE 'some_file' ; INCLUDE 'some_file'
+#
+# In such cases, it will properly ignore the first INCLUDE file,
+# but will actually still pick up the second. Interestingly enough,
+# the regex will properly deal with these cases:
+#
+# INCLUDE 'some_file'
+# INCLUDE 'some_file' !; INCLUDE 'some_file'
+#
+# To get around the above limitation, the FORTRAN programmer could
+# simply comment each INCLUDE statement separately, like this
+#
+# ! INCLUDE 'some_file' !; INCLUDE 'some_file'
+#
+# The way I see it, the only way to get around this limitation would
+# be to modify the scanning logic to replace the calls to re.findall
+# with a custom loop that processes each line separately, throwing
+# away fully commented out lines before attempting to match against
+# the INCLUDE syntax.
+#
+# Here is a breakdown of the regex:
+#
+# (?i) : regex is case insensitive
+# (?: : begin a non-saving group that matches the following:
+# ^ : either the start of the line
+# | : or
+# ['">]\s*; : a semicolon that follows a single quote,
+# double quote or greater than symbol (with any
+# amount of whitespace in between). This will
+# allow the regex to match multiple INCLUDE
+# statements per line (although it also requires
+# the positive lookahead assertion that is
+# used below). It will even properly deal with
+# (i.e. ignore) cases in which the additional
+# INCLUDES are part of an in-line comment, ala
+# " INCLUDE 'someFile' ! ; INCLUDE 'someFile2' "
+# ) : end of non-saving group
+# \s* : any amount of white space
+# INCLUDE : match the string INCLUDE, case insensitive
+# \s+ : match one or more white space characters
+# (?\w+_)? : match the optional "kind-param _" prefix allowed by the standard
+# [<"'] : match the include delimiter - an apostrophe, double quote, or less than symbol
+# (.+?) : match one or more characters that make up
+# the included path and file name and save it
+# in a group. The Fortran standard allows for
+# any non-control character to be used. The dot
+# operator will pick up any character, including
+# control codes, but I can't conceive of anyone
+# putting control codes in their file names.
+# The question mark indicates it is non-greedy so
+# that regex will match only up to the next quote,
+# double quote, or greater than symbol
+# (?=["'>]) : positive lookahead assertion to match the include
+# delimiter - an apostrophe, double quote, or
+# greater than symbol. This level of complexity
+# is required so that the include delimiter is
+# not consumed by the match, thus allowing the
+# sub-regex discussed above to uniquely match a
+# set of semicolon-separated INCLUDE statements
+# (as allowed by the F2003 standard)
+
+ include_regex = """(?i)(?:^|['">]\s*;)\s*INCLUDE\s+(?:\w+_)?[<"'](.+?)(?=["'>])"""
+
+# The MODULE statement regex finds module definitions by matching
+# the following:
+#
+# MODULE module_name
+#
+# but *not* the following:
+#
+# MODULE PROCEDURE procedure_name
+#
+# Here is a breakdown of the regex:
+#
+# (?i) : regex is case insensitive
+# ^\s* : any amount of white space
+# MODULE : match the string MODULE, case insensitive
+# \s+ : match one or more white space characters
+# (?!PROCEDURE) : but *don't* match if the next word matches
+# PROCEDURE (negative lookahead assertion),
+# case insensitive
+# (\w+) : match one or more alphanumeric characters
+# that make up the defined module name and
+# save it in a group
+
+ def_regex = """(?i)^\s*MODULE\s+(?!PROCEDURE)(\w+)"""
+
+ scanner = F90Scanner("FortranScan",
+ "$FORTRANSUFFIXES",
+ path_variable,
+ use_regex,
+ include_regex,
+ def_regex)
+ return scanner
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Scanner/IDL.py b/couchjs/scons/scons-local-2.0.1/SCons/Scanner/IDL.py
new file mode 100644
index 00000000..8ccda1b4
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Scanner/IDL.py
@@ -0,0 +1,48 @@
+"""SCons.Scanner.IDL
+
+This module implements the depenency scanner for IDL (Interface
+Definition Language) files.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Scanner/IDL.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Node.FS
+import SCons.Scanner
+
+def IDLScan():
+ """Return a prototype Scanner instance for scanning IDL source files"""
+ cs = SCons.Scanner.ClassicCPP("IDLScan",
+ "$IDLSUFFIXES",
+ "CPPPATH",
+ '^[ \t]*(?:#[ \t]*include|[ \t]*import)[ \t]+(<|")([^>"]+)(>|")')
+ return cs
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Scanner/LaTeX.py b/couchjs/scons/scons-local-2.0.1/SCons/Scanner/LaTeX.py
new file mode 100644
index 00000000..ae542cf5
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Scanner/LaTeX.py
@@ -0,0 +1,384 @@
+"""SCons.Scanner.LaTeX
+
+This module implements the dependency scanner for LaTeX code.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Scanner/LaTeX.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+import re
+
+import SCons.Scanner
+import SCons.Util
+
+# list of graphics file extensions for TeX and LaTeX
+TexGraphics = ['.eps', '.ps']
+LatexGraphics = ['.pdf', '.png', '.jpg', '.gif', '.tif']
+
+# Used as a return value of modify_env_var if the variable is not set.
+class _Null(object):
+ pass
+_null = _Null
+
+# The user specifies the paths in env[variable], similar to other builders.
+# They may be relative and must be converted to absolute, as expected
+# by LaTeX and Co. The environment may already have some paths in
+# env['ENV'][var]. These paths are honored, but the env[var] paths have
+# higher precedence. All changes are un-done on exit.
+def modify_env_var(env, var, abspath):
+ try:
+ save = env['ENV'][var]
+ except KeyError:
+ save = _null
+ env.PrependENVPath(var, abspath)
+ try:
+ if SCons.Util.is_List(env[var]):
+ env.PrependENVPath(var, [os.path.abspath(str(p)) for p in env[var]])
+ else:
+ # Split at os.pathsep to convert into absolute path
+ env.PrependENVPath(var, [os.path.abspath(p) for p in str(env[var]).split(os.pathsep)])
+ except KeyError:
+ pass
+
+ # Convert into a string explicitly to append ":" (without which it won't search system
+ # paths as well). The problem is that env.AppendENVPath(var, ":")
+ # does not work, refuses to append ":" (os.pathsep).
+
+ if SCons.Util.is_List(env['ENV'][var]):
+ env['ENV'][var] = os.pathsep.join(env['ENV'][var])
+ # Append the trailing os.pathsep character here to catch the case with no env[var]
+ env['ENV'][var] = env['ENV'][var] + os.pathsep
+
+ return save
+
+class FindENVPathDirs(object):
+ """A class to bind a specific *PATH variable name to a function that
+ will return all of the *path directories."""
+ def __init__(self, variable):
+ self.variable = variable
+ def __call__(self, env, dir=None, target=None, source=None, argument=None):
+ import SCons.PathList
+ try:
+ path = env['ENV'][self.variable]
+ except KeyError:
+ return ()
+
+ dir = dir or env.fs._cwd
+ path = SCons.PathList.PathList(path).subst_path(env, target, source)
+ return tuple(dir.Rfindalldirs(path))
+
+
+
+def LaTeXScanner():
+ """Return a prototype Scanner instance for scanning LaTeX source files
+ when built with latex.
+ """
+ ds = LaTeX(name = "LaTeXScanner",
+ suffixes = '$LATEXSUFFIXES',
+ # in the search order, see below in LaTeX class docstring
+ graphics_extensions = TexGraphics,
+ recursive = 0)
+ return ds
+
+def PDFLaTeXScanner():
+ """Return a prototype Scanner instance for scanning LaTeX source files
+ when built with pdflatex.
+ """
+ ds = LaTeX(name = "PDFLaTeXScanner",
+ suffixes = '$LATEXSUFFIXES',
+ # in the search order, see below in LaTeX class docstring
+ graphics_extensions = LatexGraphics,
+ recursive = 0)
+ return ds
+
+class LaTeX(SCons.Scanner.Base):
+ """Class for scanning LaTeX files for included files.
+
+ Unlike most scanners, which use regular expressions that just
+ return the included file name, this returns a tuple consisting
+ of the keyword for the inclusion ("include", "includegraphics",
+ "input", or "bibliography"), and then the file name itself.
+ Based on a quick look at LaTeX documentation, it seems that we
+ should append .tex suffix for the "include" keywords, append .tex if
+ there is no extension for the "input" keyword, and need to add .bib
+ for the "bibliography" keyword that does not accept extensions by itself.
+
+ Finally, if there is no extension for an "includegraphics" keyword
+ latex will append .ps or .eps to find the file, while pdftex may use .pdf,
+ .jpg, .tif, .mps, or .png.
+
+ The actual subset and search order may be altered by
+ DeclareGraphicsExtensions command. This complication is ignored.
+ The default order corresponds to experimentation with teTeX
+ $ latex --version
+ pdfeTeX 3.141592-1.21a-2.2 (Web2C 7.5.4)
+ kpathsea version 3.5.4
+ The order is:
+ ['.eps', '.ps'] for latex
+ ['.png', '.pdf', '.jpg', '.tif'].
+
+ Another difference is that the search path is determined by the type
+ of the file being searched:
+ env['TEXINPUTS'] for "input" and "include" keywords
+ env['TEXINPUTS'] for "includegraphics" keyword
+ env['TEXINPUTS'] for "lstinputlisting" keyword
+ env['BIBINPUTS'] for "bibliography" keyword
+ env['BSTINPUTS'] for "bibliographystyle" keyword
+
+ FIXME: also look for the class or style in document[class|style]{}
+ FIXME: also look for the argument of bibliographystyle{}
+ """
+ keyword_paths = {'include': 'TEXINPUTS',
+ 'input': 'TEXINPUTS',
+ 'includegraphics': 'TEXINPUTS',
+ 'bibliography': 'BIBINPUTS',
+ 'bibliographystyle': 'BSTINPUTS',
+ 'usepackage': 'TEXINPUTS',
+ 'lstinputlisting': 'TEXINPUTS'}
+ env_variables = SCons.Util.unique(list(keyword_paths.values()))
+
+ def __init__(self, name, suffixes, graphics_extensions, *args, **kw):
+
+ # We have to include \n with the % we exclude from the first part
+ # part of the regex because the expression is compiled with re.M.
+ # Without the \n, the ^ could match the beginning of a *previous*
+ # line followed by one or more newline characters (i.e. blank
+ # lines), interfering with a match on the next line.
+ # add option for whitespace before the '[options]' or the '{filename}'
+ regex = r'^[^%\n]*\\(include|includegraphics(?:\s*\[[^\]]+\])?|lstinputlisting(?:\[[^\]]+\])?|input|bibliography|usepackage)\s*{([^}]*)}'
+ self.cre = re.compile(regex, re.M)
+ self.comment_re = re.compile(r'^((?:(?:\\%)|[^%\n])*)(.*)$', re.M)
+
+ self.graphics_extensions = graphics_extensions
+
+ def _scan(node, env, path=(), self=self):
+ node = node.rfile()
+ if not node.exists():
+ return []
+ return self.scan_recurse(node, path)
+
+ class FindMultiPathDirs(object):
+ """The stock FindPathDirs function has the wrong granularity:
+ it is called once per target, while we need the path that depends
+ on what kind of included files is being searched. This wrapper
+ hides multiple instances of FindPathDirs, one per the LaTeX path
+ variable in the environment. When invoked, the function calculates
+ and returns all the required paths as a dictionary (converted into
+ a tuple to become hashable). Then the scan function converts it
+ back and uses a dictionary of tuples rather than a single tuple
+ of paths.
+ """
+ def __init__(self, dictionary):
+ self.dictionary = {}
+ for k,n in dictionary.items():
+ self.dictionary[k] = ( SCons.Scanner.FindPathDirs(n),
+ FindENVPathDirs(n) )
+
+ def __call__(self, env, dir=None, target=None, source=None,
+ argument=None):
+ di = {}
+ for k,(c,cENV) in self.dictionary.items():
+ di[k] = ( c(env, dir=None, target=None, source=None,
+ argument=None) ,
+ cENV(env, dir=None, target=None, source=None,
+ argument=None) )
+ # To prevent "dict is not hashable error"
+ return tuple(di.items())
+
+ class LaTeXScanCheck(object):
+ """Skip all but LaTeX source files, i.e., do not scan *.eps,
+ *.pdf, *.jpg, etc.
+ """
+ def __init__(self, suffixes):
+ self.suffixes = suffixes
+ def __call__(self, node, env):
+ current = not node.has_builder() or node.is_up_to_date()
+ scannable = node.get_suffix() in env.subst_list(self.suffixes)[0]
+ # Returning false means that the file is not scanned.
+ return scannable and current
+
+ kw['function'] = _scan
+ kw['path_function'] = FindMultiPathDirs(LaTeX.keyword_paths)
+ kw['recursive'] = 0
+ kw['skeys'] = suffixes
+ kw['scan_check'] = LaTeXScanCheck(suffixes)
+ kw['name'] = name
+
+ SCons.Scanner.Base.__init__(self, *args, **kw)
+
+ def _latex_names(self, include):
+ filename = include[1]
+ if include[0] == 'input':
+ base, ext = os.path.splitext( filename )
+ if ext == "":
+ return [filename + '.tex']
+ if (include[0] == 'include'):
+ return [filename + '.tex']
+ if include[0] == 'bibliography':
+ base, ext = os.path.splitext( filename )
+ if ext == "":
+ return [filename + '.bib']
+ if include[0] == 'usepackage':
+ base, ext = os.path.splitext( filename )
+ if ext == "":
+ return [filename + '.sty']
+ if include[0] == 'includegraphics':
+ base, ext = os.path.splitext( filename )
+ if ext == "":
+ #return [filename+e for e in self.graphics_extensions + TexGraphics]
+ # use the line above to find dependencies for the PDF builder
+ # when only an .eps figure is present. Since it will be found
+ # if the user tells scons how to make the pdf figure, leave
+ # it out for now.
+ return [filename+e for e in self.graphics_extensions]
+ return [filename]
+
+ def sort_key(self, include):
+ return SCons.Node.FS._my_normcase(str(include))
+
+ def find_include(self, include, source_dir, path):
+ try:
+ sub_path = path[include[0]]
+ except (IndexError, KeyError):
+ sub_path = ()
+ try_names = self._latex_names(include)
+ for n in try_names:
+ # see if we find it using the path in env[var]
+ i = SCons.Node.FS.find_file(n, (source_dir,) + sub_path[0])
+ if i:
+ return i, include
+ # see if we find it using the path in env['ENV'][var]
+ i = SCons.Node.FS.find_file(n, (source_dir,) + sub_path[1])
+ if i:
+ return i, include
+ return i, include
+
+ def canonical_text(self, text):
+ """Standardize an input TeX-file contents.
+
+ Currently:
+ * removes comments, unwrapping comment-wrapped lines.
+ """
+ out = []
+ line_continues_a_comment = False
+ for line in text.splitlines():
+ line,comment = self.comment_re.findall(line)[0]
+ if line_continues_a_comment == True:
+ out[-1] = out[-1] + line.lstrip()
+ else:
+ out.append(line)
+ line_continues_a_comment = len(comment) > 0
+ return '\n'.join(out).rstrip()+'\n'
+
+ def scan(self, node):
+ # Modify the default scan function to allow for the regular
+ # expression to return a comma separated list of file names
+ # as can be the case with the bibliography keyword.
+
+ # Cache the includes list in node so we only scan it once:
+ # path_dict = dict(list(path))
+ # add option for whitespace (\s) before the '['
+ noopt_cre = re.compile('\s*\[.*$')
+ if node.includes != None:
+ includes = node.includes
+ else:
+ text = self.canonical_text(node.get_text_contents())
+ includes = self.cre.findall(text)
+ # 1. Split comma-separated lines, e.g.
+ # ('bibliography', 'phys,comp')
+ # should become two entries
+ # ('bibliography', 'phys')
+ # ('bibliography', 'comp')
+ # 2. Remove the options, e.g., such as
+ # ('includegraphics[clip,width=0.7\\linewidth]', 'picture.eps')
+ # should become
+ # ('includegraphics', 'picture.eps')
+ split_includes = []
+ for include in includes:
+ inc_type = noopt_cre.sub('', include[0])
+ inc_list = include[1].split(',')
+ for j in range(len(inc_list)):
+ split_includes.append( (inc_type, inc_list[j]) )
+ #
+ includes = split_includes
+ node.includes = includes
+
+ return includes
+
+ def scan_recurse(self, node, path=()):
+ """ do a recursive scan of the top level target file
+ This lets us search for included files based on the
+ directory of the main file just as latex does"""
+
+ path_dict = dict(list(path))
+
+ queue = []
+ queue.extend( self.scan(node) )
+ seen = {}
+
+ # This is a hand-coded DSU (decorate-sort-undecorate, or
+ # Schwartzian transform) pattern. The sort key is the raw name
+ # of the file as specifed on the \include, \input, etc. line.
+ # TODO: what about the comment in the original Classic scanner:
+ # """which lets
+ # us keep the sort order constant regardless of whether the file
+ # is actually found in a Repository or locally."""
+ nodes = []
+ source_dir = node.get_dir()
+ #for include in includes:
+ while queue:
+
+ include = queue.pop()
+ try:
+ if seen[include[1]] == 1:
+ continue
+ except KeyError:
+ seen[include[1]] = 1
+
+ #
+ # Handle multiple filenames in include[1]
+ #
+ n, i = self.find_include(include, source_dir, path_dict)
+ if n is None:
+ # Do not bother with 'usepackage' warnings, as they most
+ # likely refer to system-level files
+ if include[0] != 'usepackage':
+ SCons.Warnings.warn(SCons.Warnings.DependencyWarning,
+ "No dependency generated for file: %s (included from: %s) -- file not found" % (i, node))
+ else:
+ sortkey = self.sort_key(n)
+ nodes.append((sortkey, n))
+ # recurse down
+ queue.extend( self.scan(n) )
+
+ return [pair[1] for pair in sorted(nodes)]
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Scanner/Prog.py b/couchjs/scons/scons-local-2.0.1/SCons/Scanner/Prog.py
new file mode 100644
index 00000000..03121323
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Scanner/Prog.py
@@ -0,0 +1,101 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Scanner/Prog.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Node
+import SCons.Node.FS
+import SCons.Scanner
+import SCons.Util
+
+# global, set by --debug=findlibs
+print_find_libs = None
+
+def ProgramScanner(**kw):
+ """Return a prototype Scanner instance for scanning executable
+ files for static-lib dependencies"""
+ kw['path_function'] = SCons.Scanner.FindPathDirs('LIBPATH')
+ ps = SCons.Scanner.Base(scan, "ProgramScanner", **kw)
+ return ps
+
+def scan(node, env, libpath = ()):
+ """
+ This scanner scans program files for static-library
+ dependencies. It will search the LIBPATH environment variable
+ for libraries specified in the LIBS variable, returning any
+ files it finds as dependencies.
+ """
+ try:
+ libs = env['LIBS']
+ except KeyError:
+ # There are no LIBS in this environment, so just return a null list:
+ return []
+ if SCons.Util.is_String(libs):
+ libs = libs.split()
+ else:
+ libs = SCons.Util.flatten(libs)
+
+ try:
+ prefix = env['LIBPREFIXES']
+ if not SCons.Util.is_List(prefix):
+ prefix = [ prefix ]
+ except KeyError:
+ prefix = [ '' ]
+
+ try:
+ suffix = env['LIBSUFFIXES']
+ if not SCons.Util.is_List(suffix):
+ suffix = [ suffix ]
+ except KeyError:
+ suffix = [ '' ]
+
+ pairs = []
+ for suf in map(env.subst, suffix):
+ for pref in map(env.subst, prefix):
+ pairs.append((pref, suf))
+
+ result = []
+
+ if callable(libpath):
+ libpath = libpath()
+
+ find_file = SCons.Node.FS.find_file
+ adjustixes = SCons.Util.adjustixes
+ for lib in libs:
+ if SCons.Util.is_String(lib):
+ lib = env.subst(lib)
+ for pref, suf in pairs:
+ l = adjustixes(lib, pref, suf)
+ l = find_file(l, libpath, verbose=print_find_libs)
+ if l:
+ result.append(l)
+ else:
+ result.append(lib)
+
+ return result
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Scanner/RC.py b/couchjs/scons/scons-local-2.0.1/SCons/Scanner/RC.py
new file mode 100644
index 00000000..9013a093
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Scanner/RC.py
@@ -0,0 +1,55 @@
+"""SCons.Scanner.RC
+
+This module implements the depenency scanner for RC (Interface
+Definition Language) files.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Scanner/RC.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Node.FS
+import SCons.Scanner
+import re
+
+def RCScan():
+ """Return a prototype Scanner instance for scanning RC source files"""
+
+ res_re= r'^(?:\s*#\s*(?:include)|' \
+ '.*?\s+(?:ICON|BITMAP|CURSOR|HTML|FONT|MESSAGETABLE|TYPELIB|REGISTRY|D3DFX)' \
+ '\s*.*?)' \
+ '\s*(<|"| )([^>"\s]+)(?:[>" ])*$'
+ resScanner = SCons.Scanner.ClassicCPP( "ResourceScanner",
+ "$RCSUFFIXES",
+ "CPPPATH",
+ res_re )
+
+ return resScanner
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Scanner/__init__.py b/couchjs/scons/scons-local-2.0.1/SCons/Scanner/__init__.py
new file mode 100644
index 00000000..1a8dcbcb
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Scanner/__init__.py
@@ -0,0 +1,413 @@
+"""SCons.Scanner
+
+The Scanner package for the SCons software construction utility.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Scanner/__init__.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import re
+
+import SCons.Node.FS
+import SCons.Util
+
+
+class _Null(object):
+ pass
+
+# This is used instead of None as a default argument value so None can be
+# used as an actual argument value.
+_null = _Null
+
+def Scanner(function, *args, **kw):
+ """
+ Public interface factory function for creating different types
+ of Scanners based on the different types of "functions" that may
+ be supplied.
+
+ TODO: Deprecate this some day. We've moved the functionality
+ inside the Base class and really don't need this factory function
+ any more. It was, however, used by some of our Tool modules, so
+ the call probably ended up in various people's custom modules
+ patterned on SCons code.
+ """
+ if SCons.Util.is_Dict(function):
+ return Selector(function, *args, **kw)
+ else:
+ return Base(function, *args, **kw)
+
+
+
+class FindPathDirs(object):
+ """A class to bind a specific *PATH variable name to a function that
+ will return all of the *path directories."""
+ def __init__(self, variable):
+ self.variable = variable
+ def __call__(self, env, dir=None, target=None, source=None, argument=None):
+ import SCons.PathList
+ try:
+ path = env[self.variable]
+ except KeyError:
+ return ()
+
+ dir = dir or env.fs._cwd
+ path = SCons.PathList.PathList(path).subst_path(env, target, source)
+ return tuple(dir.Rfindalldirs(path))
+
+
+
+class Base(object):
+ """
+ The base class for dependency scanners. This implements
+ straightforward, single-pass scanning of a single file.
+ """
+
+ def __init__(self,
+ function,
+ name = "NONE",
+ argument = _null,
+ skeys = _null,
+ path_function = None,
+ # Node.FS.Base so that, by default, it's okay for a
+ # scanner to return a Dir, File or Entry.
+ node_class = SCons.Node.FS.Base,
+ node_factory = None,
+ scan_check = None,
+ recursive = None):
+ """
+ Construct a new scanner object given a scanner function.
+
+ 'function' - a scanner function taking two or three
+ arguments and returning a list of strings.
+
+ 'name' - a name for identifying this scanner object.
+
+ 'argument' - an optional argument that, if specified, will be
+ passed to both the scanner function and the path_function.
+
+ 'skeys' - an optional list argument that can be used to determine
+ which scanner should be used for a given Node. In the case of File
+ nodes, for example, the 'skeys' would be file suffixes.
+
+ 'path_function' - a function that takes four or five arguments
+ (a construction environment, Node for the directory containing
+ the SConscript file that defined the primary target, list of
+ target nodes, list of source nodes, and optional argument for
+ this instance) and returns a tuple of the directories that can
+ be searched for implicit dependency files. May also return a
+ callable() which is called with no args and returns the tuple
+ (supporting Bindable class).
+
+ 'node_class' - the class of Nodes which this scan will return.
+ If node_class is None, then this scanner will not enforce any
+ Node conversion and will return the raw results from the
+ underlying scanner function.
+
+ 'node_factory' - the factory function to be called to translate
+ the raw results returned by the scanner function into the
+ expected node_class objects.
+
+ 'scan_check' - a function to be called to first check whether
+ this node really needs to be scanned.
+
+ 'recursive' - specifies that this scanner should be invoked
+ recursively on all of the implicit dependencies it returns
+ (the canonical example being #include lines in C source files).
+ May be a callable, which will be called to filter the list
+ of nodes found to select a subset for recursive scanning
+ (the canonical example being only recursively scanning
+ subdirectories within a directory).
+
+ The scanner function's first argument will be a Node that should
+ be scanned for dependencies, the second argument will be an
+ Environment object, the third argument will be the tuple of paths
+ returned by the path_function, and the fourth argument will be
+ the value passed into 'argument', and the returned list should
+ contain the Nodes for all the direct dependencies of the file.
+
+ Examples:
+
+ s = Scanner(my_scanner_function)
+
+ s = Scanner(function = my_scanner_function)
+
+ s = Scanner(function = my_scanner_function, argument = 'foo')
+
+ """
+
+ # Note: this class could easily work with scanner functions that take
+ # something other than a filename as an argument (e.g. a database
+ # node) and a dependencies list that aren't file names. All that
+ # would need to be changed is the documentation.
+
+ self.function = function
+ self.path_function = path_function
+ self.name = name
+ self.argument = argument
+
+ if skeys is _null:
+ if SCons.Util.is_Dict(function):
+ skeys = list(function.keys())
+ else:
+ skeys = []
+ self.skeys = skeys
+
+ self.node_class = node_class
+ self.node_factory = node_factory
+ self.scan_check = scan_check
+ if callable(recursive):
+ self.recurse_nodes = recursive
+ elif recursive:
+ self.recurse_nodes = self._recurse_all_nodes
+ else:
+ self.recurse_nodes = self._recurse_no_nodes
+
+ def path(self, env, dir=None, target=None, source=None):
+ if not self.path_function:
+ return ()
+ if not self.argument is _null:
+ return self.path_function(env, dir, target, source, self.argument)
+ else:
+ return self.path_function(env, dir, target, source)
+
+ def __call__(self, node, env, path = ()):
+ """
+ This method scans a single object. 'node' is the node
+ that will be passed to the scanner function, and 'env' is the
+ environment that will be passed to the scanner function. A list of
+ direct dependency nodes for the specified node will be returned.
+ """
+ if self.scan_check and not self.scan_check(node, env):
+ return []
+
+ self = self.select(node)
+
+ if not self.argument is _null:
+ list = self.function(node, env, path, self.argument)
+ else:
+ list = self.function(node, env, path)
+
+ kw = {}
+ if hasattr(node, 'dir'):
+ kw['directory'] = node.dir
+ node_factory = env.get_factory(self.node_factory)
+ nodes = []
+ for l in list:
+ if self.node_class and not isinstance(l, self.node_class):
+ l = node_factory(l, **kw)
+ nodes.append(l)
+ return nodes
+
+ def __cmp__(self, other):
+ try:
+ return cmp(self.__dict__, other.__dict__)
+ except AttributeError:
+ # other probably doesn't have a __dict__
+ return cmp(self.__dict__, other)
+
+ def __hash__(self):
+ return id(self)
+
+ def __str__(self):
+ return self.name
+
+ def add_skey(self, skey):
+ """Add a skey to the list of skeys"""
+ self.skeys.append(skey)
+
+ def get_skeys(self, env=None):
+ if env and SCons.Util.is_String(self.skeys):
+ return env.subst_list(self.skeys)[0]
+ return self.skeys
+
+ def select(self, node):
+ if SCons.Util.is_Dict(self.function):
+ key = node.scanner_key()
+ try:
+ return self.function[key]
+ except KeyError:
+ return None
+ else:
+ return self
+
+ def _recurse_all_nodes(self, nodes):
+ return nodes
+
+ def _recurse_no_nodes(self, nodes):
+ return []
+
+ recurse_nodes = _recurse_no_nodes
+
+ def add_scanner(self, skey, scanner):
+ self.function[skey] = scanner
+ self.add_skey(skey)
+
+
+class Selector(Base):
+ """
+ A class for selecting a more specific scanner based on the
+ scanner_key() (suffix) for a specific Node.
+
+ TODO: This functionality has been moved into the inner workings of
+ the Base class, and this class will be deprecated at some point.
+ (It was never exposed directly as part of the public interface,
+ although it is used by the Scanner() factory function that was
+ used by various Tool modules and therefore was likely a template
+ for custom modules that may be out there.)
+ """
+ def __init__(self, dict, *args, **kw):
+ Base.__init__(self, None, *args, **kw)
+ self.dict = dict
+ self.skeys = list(dict.keys())
+
+ def __call__(self, node, env, path = ()):
+ return self.select(node)(node, env, path)
+
+ def select(self, node):
+ try:
+ return self.dict[node.scanner_key()]
+ except KeyError:
+ return None
+
+ def add_scanner(self, skey, scanner):
+ self.dict[skey] = scanner
+ self.add_skey(skey)
+
+
+class Current(Base):
+ """
+ A class for scanning files that are source files (have no builder)
+ or are derived files and are current (which implies that they exist,
+ either locally or in a repository).
+ """
+
+ def __init__(self, *args, **kw):
+ def current_check(node, env):
+ return not node.has_builder() or node.is_up_to_date()
+ kw['scan_check'] = current_check
+ Base.__init__(self, *args, **kw)
+
+class Classic(Current):
+ """
+ A Scanner subclass to contain the common logic for classic CPP-style
+ include scanning, but which can be customized to use different
+ regular expressions to find the includes.
+
+ Note that in order for this to work "out of the box" (without
+ overriding the find_include() and sort_key() methods), the regular
+ expression passed to the constructor must return the name of the
+ include file in group 0.
+ """
+
+ def __init__(self, name, suffixes, path_variable, regex, *args, **kw):
+
+ self.cre = re.compile(regex, re.M)
+
+ def _scan(node, env, path=(), self=self):
+ node = node.rfile()
+ if not node.exists():
+ return []
+ return self.scan(node, path)
+
+ kw['function'] = _scan
+ kw['path_function'] = FindPathDirs(path_variable)
+ kw['recursive'] = 1
+ kw['skeys'] = suffixes
+ kw['name'] = name
+
+ Current.__init__(self, *args, **kw)
+
+ def find_include(self, include, source_dir, path):
+ n = SCons.Node.FS.find_file(include, (source_dir,) + tuple(path))
+ return n, include
+
+ def sort_key(self, include):
+ return SCons.Node.FS._my_normcase(include)
+
+ def find_include_names(self, node):
+ return self.cre.findall(node.get_text_contents())
+
+ def scan(self, node, path=()):
+
+ # cache the includes list in node so we only scan it once:
+ if node.includes is not None:
+ includes = node.includes
+ else:
+ includes = self.find_include_names (node)
+ # Intern the names of the include files. Saves some memory
+ # if the same header is included many times.
+ node.includes = list(map(SCons.Util.silent_intern, includes))
+
+ # This is a hand-coded DSU (decorate-sort-undecorate, or
+ # Schwartzian transform) pattern. The sort key is the raw name
+ # of the file as specifed on the #include line (including the
+ # " or <, since that may affect what file is found), which lets
+ # us keep the sort order constant regardless of whether the file
+ # is actually found in a Repository or locally.
+ nodes = []
+ source_dir = node.get_dir()
+ if callable(path):
+ path = path()
+ for include in includes:
+ n, i = self.find_include(include, source_dir, path)
+
+ if n is None:
+ SCons.Warnings.warn(SCons.Warnings.DependencyWarning,
+ "No dependency generated for file: %s (included from: %s) -- file not found" % (i, node))
+ else:
+ nodes.append((self.sort_key(include), n))
+
+ return [pair[1] for pair in sorted(nodes)]
+
+class ClassicCPP(Classic):
+ """
+ A Classic Scanner subclass which takes into account the type of
+ bracketing used to include the file, and uses classic CPP rules
+ for searching for the files based on the bracketing.
+
+ Note that in order for this to work, the regular expression passed
+ to the constructor must return the leading bracket in group 0, and
+ the contained filename in group 1.
+ """
+ def find_include(self, include, source_dir, path):
+ if include[0] == '"':
+ paths = (source_dir,) + tuple(path)
+ else:
+ paths = tuple(path) + (source_dir,)
+
+ n = SCons.Node.FS.find_file(include[1], paths)
+
+ i = SCons.Util.silent_intern(include[1])
+ return n, i
+
+ def sort_key(self, include):
+ return SCons.Node.FS._my_normcase(' '.join(include))
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Script/Interactive.py b/couchjs/scons/scons-local-2.0.1/SCons/Script/Interactive.py
new file mode 100644
index 00000000..e2906d4e
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Script/Interactive.py
@@ -0,0 +1,384 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Script/Interactive.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__doc__ = """
+SCons interactive mode
+"""
+
+# TODO:
+#
+# This has the potential to grow into something with a really big life
+# of its own, which might or might not be a good thing. Nevertheless,
+# here are some enhancements that will probably be requested some day
+# and are worth keeping in mind (assuming this takes off):
+#
+# - A command to re-read / re-load the SConscript files. This may
+# involve allowing people to specify command-line options (e.g. -f,
+# -I, --no-site-dir) that affect how the SConscript files are read.
+#
+# - Additional command-line options on the "build" command.
+#
+# Of the supported options that seemed to make sense (after a quick
+# pass through the list), the ones that seemed likely enough to be
+# used are listed in the man page and have explicit test scripts.
+#
+# These had code changed in Script/Main.py to support them, but didn't
+# seem likely to be used regularly, so had no test scripts added:
+#
+# build --diskcheck=*
+# build --implicit-cache=*
+# build --implicit-deps-changed=*
+# build --implicit-deps-unchanged=*
+#
+# These look like they should "just work" with no changes to the
+# existing code, but like those above, look unlikely to be used and
+# therefore had no test scripts added:
+#
+# build --random
+#
+# These I'm not sure about. They might be useful for individual
+# "build" commands, and may even work, but they seem unlikely enough
+# that we'll wait until they're requested before spending any time on
+# writing test scripts for them, or investigating whether they work.
+#
+# build -q [??? is there a useful analog to the exit status?]
+# build --duplicate=
+# build --profile=
+# build --max-drift=
+# build --warn=*
+# build --Y
+#
+# - Most of the SCons command-line options that the "build" command
+# supports should be settable as default options that apply to all
+# subsequent "build" commands. Maybe a "set {option}" command that
+# maps to "SetOption('{option}')".
+#
+# - Need something in the 'help' command that prints the -h output.
+#
+# - A command to run the configure subsystem separately (must see how
+# this interacts with the new automake model).
+#
+# - Command-line completion of target names; maybe even of SCons options?
+# Completion is something that's supported by the Python cmd module,
+# so this should be doable without too much trouble.
+#
+
+import cmd
+import copy
+import os
+import re
+import shlex
+import sys
+
+try:
+ import readline
+except ImportError:
+ pass
+
+class SConsInteractiveCmd(cmd.Cmd):
+ """\
+ build [TARGETS] Build the specified TARGETS and their dependencies.
+ 'b' is a synonym.
+ clean [TARGETS] Clean (remove) the specified TARGETS and their
+ dependencies. 'c' is a synonym.
+ exit Exit SCons interactive mode.
+ help [COMMAND] Prints help for the specified COMMAND. 'h' and
+ '?' are synonyms.
+ shell [COMMANDLINE] Execute COMMANDLINE in a subshell. 'sh' and '!'
+ are synonyms.
+ version Prints SCons version information.
+ """
+
+ synonyms = {
+ 'b' : 'build',
+ 'c' : 'clean',
+ 'h' : 'help',
+ 'scons' : 'build',
+ 'sh' : 'shell',
+ }
+
+ def __init__(self, **kw):
+ cmd.Cmd.__init__(self)
+ for key, val in kw.items():
+ setattr(self, key, val)
+
+ if sys.platform == 'win32':
+ self.shell_variable = 'COMSPEC'
+ else:
+ self.shell_variable = 'SHELL'
+
+ def default(self, argv):
+ print "*** Unknown command: %s" % argv[0]
+
+ def onecmd(self, line):
+ line = line.strip()
+ if not line:
+ print self.lastcmd
+ return self.emptyline()
+ self.lastcmd = line
+ if line[0] == '!':
+ line = 'shell ' + line[1:]
+ elif line[0] == '?':
+ line = 'help ' + line[1:]
+ if os.sep == '\\':
+ line = line.replace('\\', '\\\\')
+ argv = shlex.split(line)
+ argv[0] = self.synonyms.get(argv[0], argv[0])
+ if not argv[0]:
+ return self.default(line)
+ else:
+ try:
+ func = getattr(self, 'do_' + argv[0])
+ except AttributeError:
+ return self.default(argv)
+ return func(argv)
+
+ def do_build(self, argv):
+ """\
+ build [TARGETS] Build the specified TARGETS and their
+ dependencies. 'b' is a synonym.
+ """
+ import SCons.Node
+ import SCons.SConsign
+ import SCons.Script.Main
+
+ options = copy.deepcopy(self.options)
+
+ options, targets = self.parser.parse_args(argv[1:], values=options)
+
+ SCons.Script.COMMAND_LINE_TARGETS = targets
+
+ if targets:
+ SCons.Script.BUILD_TARGETS = targets
+ else:
+ # If the user didn't specify any targets on the command line,
+ # use the list of default targets.
+ SCons.Script.BUILD_TARGETS = SCons.Script._build_plus_default
+
+ nodes = SCons.Script.Main._build_targets(self.fs,
+ options,
+ targets,
+ self.target_top)
+
+ if not nodes:
+ return
+
+ # Call each of the Node's alter_targets() methods, which may
+ # provide additional targets that ended up as part of the build
+ # (the canonical example being a VariantDir() when we're building
+ # from a source directory) and which we therefore need their
+ # state cleared, too.
+ x = []
+ for n in nodes:
+ x.extend(n.alter_targets()[0])
+ nodes.extend(x)
+
+ # Clean up so that we can perform the next build correctly.
+ #
+ # We do this by walking over all the children of the targets,
+ # and clearing their state.
+ #
+ # We currently have to re-scan each node to find their
+ # children, because built nodes have already been partially
+ # cleared and don't remember their children. (In scons
+ # 0.96.1 and earlier, this wasn't the case, and we didn't
+ # have to re-scan the nodes.)
+ #
+ # Because we have to re-scan each node, we can't clear the
+ # nodes as we walk over them, because we may end up rescanning
+ # a cleared node as we scan a later node. Therefore, only
+ # store the list of nodes that need to be cleared as we walk
+ # the tree, and clear them in a separate pass.
+ #
+ # XXX: Someone more familiar with the inner workings of scons
+ # may be able to point out a more efficient way to do this.
+
+ SCons.Script.Main.progress_display("scons: Clearing cached node information ...")
+
+ seen_nodes = {}
+
+ def get_unseen_children(node, parent, seen_nodes=seen_nodes):
+ def is_unseen(node, seen_nodes=seen_nodes):
+ return node not in seen_nodes
+ return list(filter(is_unseen, node.children(scan=1)))
+
+ def add_to_seen_nodes(node, parent, seen_nodes=seen_nodes):
+ seen_nodes[node] = 1
+
+ # If this file is in a VariantDir and has a
+ # corresponding source file in the source tree, remember the
+ # node in the source tree, too. This is needed in
+ # particular to clear cached implicit dependencies on the
+ # source file, since the scanner will scan it if the
+ # VariantDir was created with duplicate=0.
+ try:
+ rfile_method = node.rfile
+ except AttributeError:
+ return
+ else:
+ rfile = rfile_method()
+ if rfile != node:
+ seen_nodes[rfile] = 1
+
+ for node in nodes:
+ walker = SCons.Node.Walker(node,
+ kids_func=get_unseen_children,
+ eval_func=add_to_seen_nodes)
+ n = walker.get_next()
+ while n:
+ n = walker.get_next()
+
+ for node in seen_nodes.keys():
+ # Call node.clear() to clear most of the state
+ node.clear()
+ # node.clear() doesn't reset node.state, so call
+ # node.set_state() to reset it manually
+ node.set_state(SCons.Node.no_state)
+ node.implicit = None
+
+ # Debug: Uncomment to verify that all Taskmaster reference
+ # counts have been reset to zero.
+ #if node.ref_count != 0:
+ # from SCons.Debug import Trace
+ # Trace('node %s, ref_count %s !!!\n' % (node, node.ref_count))
+
+ SCons.SConsign.Reset()
+ SCons.Script.Main.progress_display("scons: done clearing node information.")
+
+ def do_clean(self, argv):
+ """\
+ clean [TARGETS] Clean (remove) the specified TARGETS
+ and their dependencies. 'c' is a synonym.
+ """
+ return self.do_build(['build', '--clean'] + argv[1:])
+
+ def do_EOF(self, argv):
+ print
+ self.do_exit(argv)
+
+ def _do_one_help(self, arg):
+ try:
+ # If help_<arg>() exists, then call it.
+ func = getattr(self, 'help_' + arg)
+ except AttributeError:
+ try:
+ func = getattr(self, 'do_' + arg)
+ except AttributeError:
+ doc = None
+ else:
+ doc = self._doc_to_help(func)
+ if doc:
+ sys.stdout.write(doc + '\n')
+ sys.stdout.flush()
+ else:
+ doc = self.strip_initial_spaces(func())
+ if doc:
+ sys.stdout.write(doc + '\n')
+ sys.stdout.flush()
+
+ def _doc_to_help(self, obj):
+ doc = obj.__doc__
+ if doc is None:
+ return ''
+ return self._strip_initial_spaces(doc)
+
+ def _strip_initial_spaces(self, s):
+ #lines = s.split('\n')
+ lines = s.split('\n')
+ spaces = re.match(' *', lines[0]).group(0)
+ #def strip_spaces(l):
+ # if l.startswith(spaces):
+ # l = l[len(spaces):]
+ # return l
+ #return '\n'.join([ strip_spaces(l) for l in lines ])
+ def strip_spaces(l, spaces=spaces):
+ if l[:len(spaces)] == spaces:
+ l = l[len(spaces):]
+ return l
+ lines = list(map(strip_spaces, lines))
+ return '\n'.join(lines)
+
+ def do_exit(self, argv):
+ """\
+ exit Exit SCons interactive mode.
+ """
+ sys.exit(0)
+
+ def do_help(self, argv):
+ """\
+ help [COMMAND] Prints help for the specified COMMAND. 'h'
+ and '?' are synonyms.
+ """
+ if argv[1:]:
+ for arg in argv[1:]:
+ if self._do_one_help(arg):
+ break
+ else:
+ # If bare 'help' is called, print this class's doc
+ # string (if it has one).
+ doc = self._doc_to_help(self.__class__)
+ if doc:
+ sys.stdout.write(doc + '\n')
+ sys.stdout.flush()
+
+ def do_shell(self, argv):
+ """\
+ shell [COMMANDLINE] Execute COMMANDLINE in a subshell. 'sh' and
+ '!' are synonyms.
+ """
+ import subprocess
+ argv = argv[1:]
+ if not argv:
+ argv = os.environ[self.shell_variable]
+ try:
+ # Per "[Python-Dev] subprocess insufficiently platform-independent?"
+ # http://mail.python.org/pipermail/python-dev/2008-August/081979.html "+
+ # Doing the right thing with an argument list currently
+ # requires different shell= values on Windows and Linux.
+ p = subprocess.Popen(argv, shell=(sys.platform=='win32'))
+ except EnvironmentError, e:
+ sys.stderr.write('scons: %s: %s\n' % (argv[0], e.strerror))
+ else:
+ p.wait()
+
+ def do_version(self, argv):
+ """\
+ version Prints SCons version information.
+ """
+ sys.stdout.write(self.parser.version + '\n')
+
+def interact(fs, parser, options, targets, target_top):
+ c = SConsInteractiveCmd(prompt = 'scons>>> ',
+ fs = fs,
+ parser = parser,
+ options = options,
+ targets = targets,
+ target_top = target_top)
+ c.cmdloop()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Script/Main.py b/couchjs/scons/scons-local-2.0.1/SCons/Script/Main.py
new file mode 100644
index 00000000..31bcff3d
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Script/Main.py
@@ -0,0 +1,1334 @@
+"""SCons.Script
+
+This file implements the main() function used by the scons script.
+
+Architecturally, this *is* the scons script, and will likely only be
+called from the external "scons" wrapper. Consequently, anything here
+should not be, or be considered, part of the build engine. If it's
+something that we expect other software to want to use, it should go in
+some other module. If it's specific to the "scons" script invocation,
+it goes here.
+"""
+
+unsupported_python_version = (2, 3, 0)
+deprecated_python_version = (2, 4, 0)
+
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Script/Main.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.compat
+
+import os
+import sys
+import time
+import traceback
+
+# Strip the script directory from sys.path() so on case-insensitive
+# (Windows) systems Python doesn't think that the "scons" script is the
+# "SCons" package. Replace it with our own version directory so, if
+# if they're there, we pick up the right version of the build engine
+# modules.
+#sys.path = [os.path.join(sys.prefix,
+# 'lib',
+# 'scons-%d' % SCons.__version__)] + sys.path[1:]
+
+import SCons.CacheDir
+import SCons.Debug
+import SCons.Defaults
+import SCons.Environment
+import SCons.Errors
+import SCons.Job
+import SCons.Node
+import SCons.Node.FS
+import SCons.SConf
+import SCons.Script
+import SCons.Taskmaster
+import SCons.Util
+import SCons.Warnings
+
+import SCons.Script.Interactive
+
+def fetch_win32_parallel_msg():
+ # A subsidiary function that exists solely to isolate this import
+ # so we don't have to pull it in on all platforms, and so that an
+ # in-line "import" statement in the _main() function below doesn't
+ # cause warnings about local names shadowing use of the 'SCons'
+ # globl in nest scopes and UnboundLocalErrors and the like in some
+ # versions (2.1) of Python.
+ import SCons.Platform.win32
+ return SCons.Platform.win32.parallel_msg
+
+#
+
+class SConsPrintHelpException(Exception):
+ pass
+
+display = SCons.Util.display
+progress_display = SCons.Util.DisplayEngine()
+
+first_command_start = None
+last_command_end = None
+
+class Progressor(object):
+ prev = ''
+ count = 0
+ target_string = '$TARGET'
+
+ def __init__(self, obj, interval=1, file=None, overwrite=False):
+ if file is None:
+ file = sys.stdout
+
+ self.obj = obj
+ self.file = file
+ self.interval = interval
+ self.overwrite = overwrite
+
+ if callable(obj):
+ self.func = obj
+ elif SCons.Util.is_List(obj):
+ self.func = self.spinner
+ elif obj.find(self.target_string) != -1:
+ self.func = self.replace_string
+ else:
+ self.func = self.string
+
+ def write(self, s):
+ self.file.write(s)
+ self.file.flush()
+ self.prev = s
+
+ def erase_previous(self):
+ if self.prev:
+ length = len(self.prev)
+ if self.prev[-1] in ('\n', '\r'):
+ length = length - 1
+ self.write(' ' * length + '\r')
+ self.prev = ''
+
+ def spinner(self, node):
+ self.write(self.obj[self.count % len(self.obj)])
+
+ def string(self, node):
+ self.write(self.obj)
+
+ def replace_string(self, node):
+ self.write(self.obj.replace(self.target_string, str(node)))
+
+ def __call__(self, node):
+ self.count = self.count + 1
+ if (self.count % self.interval) == 0:
+ if self.overwrite:
+ self.erase_previous()
+ self.func(node)
+
+ProgressObject = SCons.Util.Null()
+
+def Progress(*args, **kw):
+ global ProgressObject
+ ProgressObject = Progressor(*args, **kw)
+
+# Task control.
+#
+
+_BuildFailures = []
+
+def GetBuildFailures():
+ return _BuildFailures
+
+class BuildTask(SCons.Taskmaster.OutOfDateTask):
+ """An SCons build task."""
+ progress = ProgressObject
+
+ def display(self, message):
+ display('scons: ' + message)
+
+ def prepare(self):
+ self.progress(self.targets[0])
+ return SCons.Taskmaster.OutOfDateTask.prepare(self)
+
+ def needs_execute(self):
+ if SCons.Taskmaster.OutOfDateTask.needs_execute(self):
+ return True
+ if self.top and self.targets[0].has_builder():
+ display("scons: `%s' is up to date." % str(self.node))
+ return False
+
+ def execute(self):
+ if print_time:
+ start_time = time.time()
+ global first_command_start
+ if first_command_start is None:
+ first_command_start = start_time
+ SCons.Taskmaster.OutOfDateTask.execute(self)
+ if print_time:
+ global cumulative_command_time
+ global last_command_end
+ finish_time = time.time()
+ last_command_end = finish_time
+ cumulative_command_time = cumulative_command_time+finish_time-start_time
+ sys.stdout.write("Command execution time: %f seconds\n"%(finish_time-start_time))
+
+ def do_failed(self, status=2):
+ _BuildFailures.append(self.exception[1])
+ global exit_status
+ global this_build_status
+ if self.options.ignore_errors:
+ SCons.Taskmaster.OutOfDateTask.executed(self)
+ elif self.options.keep_going:
+ SCons.Taskmaster.OutOfDateTask.fail_continue(self)
+ exit_status = status
+ this_build_status = status
+ else:
+ SCons.Taskmaster.OutOfDateTask.fail_stop(self)
+ exit_status = status
+ this_build_status = status
+
+ def executed(self):
+ t = self.targets[0]
+ if self.top and not t.has_builder() and not t.side_effect:
+ if not t.exists():
+ if t.__class__.__name__ in ('File', 'Dir', 'Entry'):
+ errstr="Do not know how to make %s target `%s' (%s)." % (t.__class__.__name__, t, t.abspath)
+ else: # Alias or Python or ...
+ errstr="Do not know how to make %s target `%s'." % (t.__class__.__name__, t)
+ sys.stderr.write("scons: *** " + errstr)
+ if not self.options.keep_going:
+ sys.stderr.write(" Stop.")
+ sys.stderr.write("\n")
+ try:
+ raise SCons.Errors.BuildError(t, errstr)
+ except KeyboardInterrupt:
+ raise
+ except:
+ self.exception_set()
+ self.do_failed()
+ else:
+ print "scons: Nothing to be done for `%s'." % t
+ SCons.Taskmaster.OutOfDateTask.executed(self)
+ else:
+ SCons.Taskmaster.OutOfDateTask.executed(self)
+
+ def failed(self):
+ # Handle the failure of a build task. The primary purpose here
+ # is to display the various types of Errors and Exceptions
+ # appropriately.
+ exc_info = self.exc_info()
+ try:
+ t, e, tb = exc_info
+ except ValueError:
+ t, e = exc_info
+ tb = None
+
+ if t is None:
+ # The Taskmaster didn't record an exception for this Task;
+ # see if the sys module has one.
+ try:
+ t, e, tb = sys.exc_info()[:]
+ except ValueError:
+ t, e = exc_info
+ tb = None
+
+ # Deprecated string exceptions will have their string stored
+ # in the first entry of the tuple.
+ if e is None:
+ e = t
+
+ buildError = SCons.Errors.convert_to_BuildError(e)
+ if not buildError.node:
+ buildError.node = self.node
+
+ node = buildError.node
+ if not SCons.Util.is_List(node):
+ node = [ node ]
+ nodename = ', '.join(map(str, node))
+
+ errfmt = "scons: *** [%s] %s\n"
+ sys.stderr.write(errfmt % (nodename, buildError))
+
+ if (buildError.exc_info[2] and buildError.exc_info[1] and
+ not isinstance(
+ buildError.exc_info[1],
+ (EnvironmentError, SCons.Errors.StopError,
+ SCons.Errors.UserError))):
+ type, value, trace = buildError.exc_info
+ traceback.print_exception(type, value, trace)
+ elif tb and print_stacktrace:
+ sys.stderr.write("scons: internal stack trace:\n")
+ traceback.print_tb(tb, file=sys.stderr)
+
+ self.exception = (e, buildError, tb) # type, value, traceback
+ self.do_failed(buildError.exitstatus)
+
+ self.exc_clear()
+
+ def postprocess(self):
+ if self.top:
+ t = self.targets[0]
+ for tp in self.options.tree_printers:
+ tp.display(t)
+ if self.options.debug_includes:
+ tree = t.render_include_tree()
+ if tree:
+ print
+ print tree
+ SCons.Taskmaster.OutOfDateTask.postprocess(self)
+
+ def make_ready(self):
+ """Make a task ready for execution"""
+ SCons.Taskmaster.OutOfDateTask.make_ready(self)
+ if self.out_of_date and self.options.debug_explain:
+ explanation = self.out_of_date[0].explain()
+ if explanation:
+ sys.stdout.write("scons: " + explanation)
+
+class CleanTask(SCons.Taskmaster.AlwaysTask):
+ """An SCons clean task."""
+ def fs_delete(self, path, pathstr, remove=1):
+ try:
+ if os.path.lexists(path):
+ if os.path.isfile(path) or os.path.islink(path):
+ if remove: os.unlink(path)
+ display("Removed " + pathstr)
+ elif os.path.isdir(path) and not os.path.islink(path):
+ # delete everything in the dir
+ for e in sorted(os.listdir(path)):
+ p = os.path.join(path, e)
+ s = os.path.join(pathstr, e)
+ if os.path.isfile(p):
+ if remove: os.unlink(p)
+ display("Removed " + s)
+ else:
+ self.fs_delete(p, s, remove)
+ # then delete dir itself
+ if remove: os.rmdir(path)
+ display("Removed directory " + pathstr)
+ else:
+ errstr = "Path '%s' exists but isn't a file or directory."
+ raise SCons.Errors.UserError(errstr % (pathstr))
+ except SCons.Errors.UserError, e:
+ print e
+ except (IOError, OSError), e:
+ print "scons: Could not remove '%s':" % pathstr, e.strerror
+
+ def show(self):
+ target = self.targets[0]
+ if (target.has_builder() or target.side_effect) and not target.noclean:
+ for t in self.targets:
+ if not t.isdir():
+ display("Removed " + str(t))
+ if target in SCons.Environment.CleanTargets:
+ files = SCons.Environment.CleanTargets[target]
+ for f in files:
+ self.fs_delete(f.abspath, str(f), 0)
+
+ def remove(self):
+ target = self.targets[0]
+ if (target.has_builder() or target.side_effect) and not target.noclean:
+ for t in self.targets:
+ try:
+ removed = t.remove()
+ except OSError, e:
+ # An OSError may indicate something like a permissions
+ # issue, an IOError would indicate something like
+ # the file not existing. In either case, print a
+ # message and keep going to try to remove as many
+ # targets aa possible.
+ print "scons: Could not remove '%s':" % str(t), e.strerror
+ else:
+ if removed:
+ display("Removed " + str(t))
+ if target in SCons.Environment.CleanTargets:
+ files = SCons.Environment.CleanTargets[target]
+ for f in files:
+ self.fs_delete(f.abspath, str(f))
+
+ execute = remove
+
+ # We want the Taskmaster to update the Node states (and therefore
+ # handle reference counts, etc.), but we don't want to call
+ # back to the Node's post-build methods, which would do things
+ # we don't want, like store .sconsign information.
+ executed = SCons.Taskmaster.Task.executed_without_callbacks
+
+ # Have the taskmaster arrange to "execute" all of the targets, because
+ # we'll figure out ourselves (in remove() or show() above) whether
+ # anything really needs to be done.
+ make_ready = SCons.Taskmaster.Task.make_ready_all
+
+ def prepare(self):
+ pass
+
+class QuestionTask(SCons.Taskmaster.AlwaysTask):
+ """An SCons task for the -q (question) option."""
+ def prepare(self):
+ pass
+
+ def execute(self):
+ if self.targets[0].get_state() != SCons.Node.up_to_date or \
+ (self.top and not self.targets[0].exists()):
+ global exit_status
+ global this_build_status
+ exit_status = 1
+ this_build_status = 1
+ self.tm.stop()
+
+ def executed(self):
+ pass
+
+
+class TreePrinter(object):
+ def __init__(self, derived=False, prune=False, status=False):
+ self.derived = derived
+ self.prune = prune
+ self.status = status
+ def get_all_children(self, node):
+ return node.all_children()
+ def get_derived_children(self, node):
+ children = node.all_children(None)
+ return [x for x in children if x.has_builder()]
+ def display(self, t):
+ if self.derived:
+ func = self.get_derived_children
+ else:
+ func = self.get_all_children
+ s = self.status and 2 or 0
+ SCons.Util.print_tree(t, func, prune=self.prune, showtags=s)
+
+
+def python_version_string():
+ return sys.version.split()[0]
+
+def python_version_unsupported(version=sys.version_info):
+ return version < unsupported_python_version
+
+def python_version_deprecated(version=sys.version_info):
+ return version < deprecated_python_version
+
+
+# Global variables
+
+print_objects = 0
+print_memoizer = 0
+print_stacktrace = 0
+print_time = 0
+sconscript_time = 0
+cumulative_command_time = 0
+exit_status = 0 # final exit status, assume success by default
+this_build_status = 0 # "exit status" of an individual build
+num_jobs = None
+delayed_warnings = []
+
+class FakeOptionParser(object):
+ """
+ A do-nothing option parser, used for the initial OptionsParser variable.
+
+ During normal SCons operation, the OptionsParser is created right
+ away by the main() function. Certain tests scripts however, can
+ introspect on different Tool modules, the initialization of which
+ can try to add a new, local option to an otherwise uninitialized
+ OptionsParser object. This allows that introspection to happen
+ without blowing up.
+
+ """
+ class FakeOptionValues(object):
+ def __getattr__(self, attr):
+ return None
+ values = FakeOptionValues()
+ def add_local_option(self, *args, **kw):
+ pass
+
+OptionsParser = FakeOptionParser()
+
+def AddOption(*args, **kw):
+ if 'default' not in kw:
+ kw['default'] = None
+ result = OptionsParser.add_local_option(*args, **kw)
+ return result
+
+def GetOption(name):
+ return getattr(OptionsParser.values, name)
+
+def SetOption(name, value):
+ return OptionsParser.values.set_option(name, value)
+
+#
+class Stats(object):
+ def __init__(self):
+ self.stats = []
+ self.labels = []
+ self.append = self.do_nothing
+ self.print_stats = self.do_nothing
+ def enable(self, outfp):
+ self.outfp = outfp
+ self.append = self.do_append
+ self.print_stats = self.do_print
+ def do_nothing(self, *args, **kw):
+ pass
+
+class CountStats(Stats):
+ def do_append(self, label):
+ self.labels.append(label)
+ self.stats.append(SCons.Debug.fetchLoggedInstances())
+ def do_print(self):
+ stats_table = {}
+ for s in self.stats:
+ for n in [t[0] for t in s]:
+ stats_table[n] = [0, 0, 0, 0]
+ i = 0
+ for s in self.stats:
+ for n, c in s:
+ stats_table[n][i] = c
+ i = i + 1
+ self.outfp.write("Object counts:\n")
+ pre = [" "]
+ post = [" %s\n"]
+ l = len(self.stats)
+ fmt1 = ''.join(pre + [' %7s']*l + post)
+ fmt2 = ''.join(pre + [' %7d']*l + post)
+ labels = self.labels[:l]
+ labels.append(("", "Class"))
+ self.outfp.write(fmt1 % tuple([x[0] for x in labels]))
+ self.outfp.write(fmt1 % tuple([x[1] for x in labels]))
+ for k in sorted(stats_table.keys()):
+ r = stats_table[k][:l] + [k]
+ self.outfp.write(fmt2 % tuple(r))
+
+count_stats = CountStats()
+
+class MemStats(Stats):
+ def do_append(self, label):
+ self.labels.append(label)
+ self.stats.append(SCons.Debug.memory())
+ def do_print(self):
+ fmt = 'Memory %-32s %12d\n'
+ for label, stats in zip(self.labels, self.stats):
+ self.outfp.write(fmt % (label, stats))
+
+memory_stats = MemStats()
+
+# utility functions
+
+def _scons_syntax_error(e):
+ """Handle syntax errors. Print out a message and show where the error
+ occurred.
+ """
+ etype, value, tb = sys.exc_info()
+ lines = traceback.format_exception_only(etype, value)
+ for line in lines:
+ sys.stderr.write(line+'\n')
+ sys.exit(2)
+
+def find_deepest_user_frame(tb):
+ """
+ Find the deepest stack frame that is not part of SCons.
+
+ Input is a "pre-processed" stack trace in the form
+ returned by traceback.extract_tb() or traceback.extract_stack()
+ """
+
+ tb.reverse()
+
+ # find the deepest traceback frame that is not part
+ # of SCons:
+ for frame in tb:
+ filename = frame[0]
+ if filename.find(os.sep+'SCons'+os.sep) == -1:
+ return frame
+ return tb[0]
+
+def _scons_user_error(e):
+ """Handle user errors. Print out a message and a description of the
+ error, along with the line number and routine where it occured.
+ The file and line number will be the deepest stack frame that is
+ not part of SCons itself.
+ """
+ global print_stacktrace
+ etype, value, tb = sys.exc_info()
+ if print_stacktrace:
+ traceback.print_exception(etype, value, tb)
+ filename, lineno, routine, dummy = find_deepest_user_frame(traceback.extract_tb(tb))
+ sys.stderr.write("\nscons: *** %s\n" % value)
+ sys.stderr.write('File "%s", line %d, in %s\n' % (filename, lineno, routine))
+ sys.exit(2)
+
+def _scons_user_warning(e):
+ """Handle user warnings. Print out a message and a description of
+ the warning, along with the line number and routine where it occured.
+ The file and line number will be the deepest stack frame that is
+ not part of SCons itself.
+ """
+ etype, value, tb = sys.exc_info()
+ filename, lineno, routine, dummy = find_deepest_user_frame(traceback.extract_tb(tb))
+ sys.stderr.write("\nscons: warning: %s\n" % e)
+ sys.stderr.write('File "%s", line %d, in %s\n' % (filename, lineno, routine))
+
+def _scons_internal_warning(e):
+ """Slightly different from _scons_user_warning in that we use the
+ *current call stack* rather than sys.exc_info() to get our stack trace.
+ This is used by the warnings framework to print warnings."""
+ filename, lineno, routine, dummy = find_deepest_user_frame(traceback.extract_stack())
+ sys.stderr.write("\nscons: warning: %s\n" % e.args[0])
+ sys.stderr.write('File "%s", line %d, in %s\n' % (filename, lineno, routine))
+
+def _scons_internal_error():
+ """Handle all errors but user errors. Print out a message telling
+ the user what to do in this case and print a normal trace.
+ """
+ print 'internal error'
+ traceback.print_exc()
+ sys.exit(2)
+
+def _SConstruct_exists(dirname='', repositories=[], filelist=None):
+ """This function checks that an SConstruct file exists in a directory.
+ If so, it returns the path of the file. By default, it checks the
+ current directory.
+ """
+ if not filelist:
+ filelist = ['SConstruct', 'Sconstruct', 'sconstruct']
+ for file in filelist:
+ sfile = os.path.join(dirname, file)
+ if os.path.isfile(sfile):
+ return sfile
+ if not os.path.isabs(sfile):
+ for rep in repositories:
+ if os.path.isfile(os.path.join(rep, sfile)):
+ return sfile
+ return None
+
+def _set_debug_values(options):
+ global print_memoizer, print_objects, print_stacktrace, print_time
+
+ debug_values = options.debug
+
+ if "count" in debug_values:
+ # All of the object counts are within "if __debug__:" blocks,
+ # which get stripped when running optimized (with python -O or
+ # from compiled *.pyo files). Provide a warning if __debug__ is
+ # stripped, so it doesn't just look like --debug=count is broken.
+ enable_count = False
+ if __debug__: enable_count = True
+ if enable_count:
+ count_stats.enable(sys.stdout)
+ else:
+ msg = "--debug=count is not supported when running SCons\n" + \
+ "\twith the python -O option or optimized (.pyo) modules."
+ SCons.Warnings.warn(SCons.Warnings.NoObjectCountWarning, msg)
+ if "dtree" in debug_values:
+ options.tree_printers.append(TreePrinter(derived=True))
+ options.debug_explain = ("explain" in debug_values)
+ if "findlibs" in debug_values:
+ SCons.Scanner.Prog.print_find_libs = "findlibs"
+ options.debug_includes = ("includes" in debug_values)
+ print_memoizer = ("memoizer" in debug_values)
+ if "memory" in debug_values:
+ memory_stats.enable(sys.stdout)
+ print_objects = ("objects" in debug_values)
+ if "presub" in debug_values:
+ SCons.Action.print_actions_presub = 1
+ if "stacktrace" in debug_values:
+ print_stacktrace = 1
+ if "stree" in debug_values:
+ options.tree_printers.append(TreePrinter(status=True))
+ if "time" in debug_values:
+ print_time = 1
+ if "tree" in debug_values:
+ options.tree_printers.append(TreePrinter())
+
+def _create_path(plist):
+ path = '.'
+ for d in plist:
+ if os.path.isabs(d):
+ path = d
+ else:
+ path = path + '/' + d
+ return path
+
+def _load_site_scons_dir(topdir, site_dir_name=None):
+ """Load the site_scons dir under topdir.
+ Adds site_scons to sys.path, imports site_scons/site_init.py,
+ and adds site_scons/site_tools to default toolpath."""
+ if site_dir_name:
+ err_if_not_found = True # user specified: err if missing
+ else:
+ site_dir_name = "site_scons"
+ err_if_not_found = False
+
+ site_dir = os.path.join(topdir.path, site_dir_name)
+ if not os.path.exists(site_dir):
+ if err_if_not_found:
+ raise SCons.Errors.UserError("site dir %s not found."%site_dir)
+ return
+
+ site_init_filename = "site_init.py"
+ site_init_modname = "site_init"
+ site_tools_dirname = "site_tools"
+ sys.path = [os.path.abspath(site_dir)] + sys.path
+ site_init_file = os.path.join(site_dir, site_init_filename)
+ site_tools_dir = os.path.join(site_dir, site_tools_dirname)
+ if os.path.exists(site_init_file):
+ import imp
+ # TODO(2.4): turn this into try:-except:-finally:
+ try:
+ try:
+ fp, pathname, description = imp.find_module(site_init_modname,
+ [site_dir])
+ # Load the file into SCons.Script namespace. This is
+ # opaque and clever; m is the module object for the
+ # SCons.Script module, and the exec ... in call executes a
+ # file (or string containing code) in the context of the
+ # module's dictionary, so anything that code defines ends
+ # up adding to that module. This is really short, but all
+ # the error checking makes it longer.
+ try:
+ m = sys.modules['SCons.Script']
+ except Exception, e:
+ fmt = 'cannot import site_init.py: missing SCons.Script module %s'
+ raise SCons.Errors.InternalError(fmt % repr(e))
+ try:
+ # This is the magic.
+ exec fp in m.__dict__
+ except KeyboardInterrupt:
+ raise
+ except Exception, e:
+ fmt = '*** Error loading site_init file %s:\n'
+ sys.stderr.write(fmt % repr(site_init_file))
+ raise
+ except KeyboardInterrupt:
+ raise
+ except ImportError, e:
+ fmt = '*** cannot import site init file %s:\n'
+ sys.stderr.write(fmt % repr(site_init_file))
+ raise
+ finally:
+ if fp:
+ fp.close()
+ if os.path.exists(site_tools_dir):
+ SCons.Tool.DefaultToolpath.append(os.path.abspath(site_tools_dir))
+
+def version_string(label, module):
+ version = module.__version__
+ build = module.__build__
+ if build:
+ if build[0] != '.':
+ build = '.' + build
+ version = version + build
+ fmt = "\t%s: v%s, %s, by %s on %s\n"
+ return fmt % (label,
+ version,
+ module.__date__,
+ module.__developer__,
+ module.__buildsys__)
+
+def _main(parser):
+ global exit_status
+ global this_build_status
+
+ options = parser.values
+
+ # Here's where everything really happens.
+
+ # First order of business: set up default warnings and then
+ # handle the user's warning options, so that we can issue (or
+ # suppress) appropriate warnings about anything that might happen,
+ # as configured by the user.
+
+ default_warnings = [ SCons.Warnings.WarningOnByDefault,
+ SCons.Warnings.DeprecatedWarning,
+ ]
+
+ for warning in default_warnings:
+ SCons.Warnings.enableWarningClass(warning)
+ SCons.Warnings._warningOut = _scons_internal_warning
+ SCons.Warnings.process_warn_strings(options.warn)
+
+ # Now that we have the warnings configuration set up, we can actually
+ # issue (or suppress) any warnings about warning-worthy things that
+ # occurred while the command-line options were getting parsed.
+ try:
+ dw = options.delayed_warnings
+ except AttributeError:
+ pass
+ else:
+ delayed_warnings.extend(dw)
+ for warning_type, message in delayed_warnings:
+ SCons.Warnings.warn(warning_type, message)
+
+ if options.diskcheck:
+ SCons.Node.FS.set_diskcheck(options.diskcheck)
+
+ # Next, we want to create the FS object that represents the outside
+ # world's file system, as that's central to a lot of initialization.
+ # To do this, however, we need to be in the directory from which we
+ # want to start everything, which means first handling any relevant
+ # options that might cause us to chdir somewhere (-C, -D, -U, -u).
+ if options.directory:
+ script_dir = os.path.abspath(_create_path(options.directory))
+ else:
+ script_dir = os.getcwd()
+
+ target_top = None
+ if options.climb_up:
+ target_top = '.' # directory to prepend to targets
+ while script_dir and not _SConstruct_exists(script_dir,
+ options.repository,
+ options.file):
+ script_dir, last_part = os.path.split(script_dir)
+ if last_part:
+ target_top = os.path.join(last_part, target_top)
+ else:
+ script_dir = ''
+
+ if script_dir and script_dir != os.getcwd():
+ display("scons: Entering directory `%s'" % script_dir)
+ try:
+ os.chdir(script_dir)
+ except OSError:
+ sys.stderr.write("Could not change directory to %s\n" % script_dir)
+
+ # Now that we're in the top-level SConstruct directory, go ahead
+ # and initialize the FS object that represents the file system,
+ # and make it the build engine default.
+ fs = SCons.Node.FS.get_default_fs()
+
+ for rep in options.repository:
+ fs.Repository(rep)
+
+ # Now that we have the FS object, the next order of business is to
+ # check for an SConstruct file (or other specified config file).
+ # If there isn't one, we can bail before doing any more work.
+ scripts = []
+ if options.file:
+ scripts.extend(options.file)
+ if not scripts:
+ sfile = _SConstruct_exists(repositories=options.repository,
+ filelist=options.file)
+ if sfile:
+ scripts.append(sfile)
+
+ if not scripts:
+ if options.help:
+ # There's no SConstruct, but they specified -h.
+ # Give them the options usage now, before we fail
+ # trying to read a non-existent SConstruct file.
+ raise SConsPrintHelpException
+ raise SCons.Errors.UserError("No SConstruct file found.")
+
+ if scripts[0] == "-":
+ d = fs.getcwd()
+ else:
+ d = fs.File(scripts[0]).dir
+ fs.set_SConstruct_dir(d)
+
+ _set_debug_values(options)
+ SCons.Node.implicit_cache = options.implicit_cache
+ SCons.Node.implicit_deps_changed = options.implicit_deps_changed
+ SCons.Node.implicit_deps_unchanged = options.implicit_deps_unchanged
+
+ if options.no_exec:
+ SCons.SConf.dryrun = 1
+ SCons.Action.execute_actions = None
+ if options.question:
+ SCons.SConf.dryrun = 1
+ if options.clean:
+ SCons.SConf.SetBuildType('clean')
+ if options.help:
+ SCons.SConf.SetBuildType('help')
+ SCons.SConf.SetCacheMode(options.config)
+ SCons.SConf.SetProgressDisplay(progress_display)
+
+ if options.no_progress or options.silent:
+ progress_display.set_mode(0)
+
+ if options.site_dir:
+ _load_site_scons_dir(d, options.site_dir)
+ elif not options.no_site_dir:
+ _load_site_scons_dir(d)
+
+ if options.include_dir:
+ sys.path = options.include_dir + sys.path
+
+ # That should cover (most of) the options. Next, set up the variables
+ # that hold command-line arguments, so the SConscript files that we
+ # read and execute have access to them.
+ targets = []
+ xmit_args = []
+ for a in parser.largs:
+ if a[:1] == '-':
+ continue
+ if '=' in a:
+ xmit_args.append(a)
+ else:
+ targets.append(a)
+ SCons.Script._Add_Targets(targets + parser.rargs)
+ SCons.Script._Add_Arguments(xmit_args)
+
+ # If stdout is not a tty, replace it with a wrapper object to call flush
+ # after every write.
+ #
+ # Tty devices automatically flush after every newline, so the replacement
+ # isn't necessary. Furthermore, if we replace sys.stdout, the readline
+ # module will no longer work. This affects the behavior during
+ # --interactive mode. --interactive should only be used when stdin and
+ # stdout refer to a tty.
+ if not hasattr(sys.stdout, 'isatty') or not sys.stdout.isatty():
+ sys.stdout = SCons.Util.Unbuffered(sys.stdout)
+ if not hasattr(sys.stderr, 'isatty') or not sys.stderr.isatty():
+ sys.stderr = SCons.Util.Unbuffered(sys.stderr)
+
+ memory_stats.append('before reading SConscript files:')
+ count_stats.append(('pre-', 'read'))
+
+ # And here's where we (finally) read the SConscript files.
+
+ progress_display("scons: Reading SConscript files ...")
+
+ start_time = time.time()
+ try:
+ for script in scripts:
+ SCons.Script._SConscript._SConscript(fs, script)
+ except SCons.Errors.StopError, e:
+ # We had problems reading an SConscript file, such as it
+ # couldn't be copied in to the VariantDir. Since we're just
+ # reading SConscript files and haven't started building
+ # things yet, stop regardless of whether they used -i or -k
+ # or anything else.
+ sys.stderr.write("scons: *** %s Stop.\n" % e)
+ exit_status = 2
+ sys.exit(exit_status)
+ global sconscript_time
+ sconscript_time = time.time() - start_time
+
+ progress_display("scons: done reading SConscript files.")
+
+ memory_stats.append('after reading SConscript files:')
+ count_stats.append(('post-', 'read'))
+
+ # Re-{enable,disable} warnings in case they disabled some in
+ # the SConscript file.
+ #
+ # We delay enabling the PythonVersionWarning class until here so that,
+ # if they explicity disabled it in either in the command line or in
+ # $SCONSFLAGS, or in the SConscript file, then the search through
+ # the list of deprecated warning classes will find that disabling
+ # first and not issue the warning.
+ #SCons.Warnings.enableWarningClass(SCons.Warnings.PythonVersionWarning)
+ SCons.Warnings.process_warn_strings(options.warn)
+
+ # Now that we've read the SConscript files, we can check for the
+ # warning about deprecated Python versions--delayed until here
+ # in case they disabled the warning in the SConscript files.
+ if python_version_deprecated():
+ msg = "Support for pre-2.4 Python (%s) is deprecated.\n" + \
+ " If this will cause hardship, contact dev@scons.tigris.org."
+ SCons.Warnings.warn(SCons.Warnings.PythonVersionWarning,
+ msg % python_version_string())
+
+ if not options.help:
+ SCons.SConf.CreateConfigHBuilder(SCons.Defaults.DefaultEnvironment())
+
+ # Now re-parse the command-line options (any to the left of a '--'
+ # argument, that is) with any user-defined command-line options that
+ # the SConscript files may have added to the parser object. This will
+ # emit the appropriate error message and exit if any unknown option
+ # was specified on the command line.
+
+ parser.preserve_unknown_options = False
+ parser.parse_args(parser.largs, options)
+
+ if options.help:
+ help_text = SCons.Script.help_text
+ if help_text is None:
+ # They specified -h, but there was no Help() inside the
+ # SConscript files. Give them the options usage.
+ raise SConsPrintHelpException
+ else:
+ print help_text
+ print "Use scons -H for help about command-line options."
+ exit_status = 0
+ return
+
+ # Change directory to the top-level SConstruct directory, then tell
+ # the Node.FS subsystem that we're all done reading the SConscript
+ # files and calling Repository() and VariantDir() and changing
+ # directories and the like, so it can go ahead and start memoizing
+ # the string values of file system nodes.
+
+ fs.chdir(fs.Top)
+
+ SCons.Node.FS.save_strings(1)
+
+ # Now that we've read the SConscripts we can set the options
+ # that are SConscript settable:
+ SCons.Node.implicit_cache = options.implicit_cache
+ SCons.Node.FS.set_duplicate(options.duplicate)
+ fs.set_max_drift(options.max_drift)
+
+ SCons.Job.explicit_stack_size = options.stack_size
+
+ if options.md5_chunksize:
+ SCons.Node.FS.File.md5_chunksize = options.md5_chunksize
+
+ platform = SCons.Platform.platform_module()
+
+ if options.interactive:
+ SCons.Script.Interactive.interact(fs, OptionsParser, options,
+ targets, target_top)
+
+ else:
+
+ # Build the targets
+ nodes = _build_targets(fs, options, targets, target_top)
+ if not nodes:
+ exit_status = 2
+
+def _build_targets(fs, options, targets, target_top):
+
+ global this_build_status
+ this_build_status = 0
+
+ progress_display.set_mode(not (options.no_progress or options.silent))
+ display.set_mode(not options.silent)
+ SCons.Action.print_actions = not options.silent
+ SCons.Action.execute_actions = not options.no_exec
+ SCons.Node.FS.do_store_info = not options.no_exec
+ SCons.SConf.dryrun = options.no_exec
+
+ if options.diskcheck:
+ SCons.Node.FS.set_diskcheck(options.diskcheck)
+
+ SCons.CacheDir.cache_enabled = not options.cache_disable
+ SCons.CacheDir.cache_debug = options.cache_debug
+ SCons.CacheDir.cache_force = options.cache_force
+ SCons.CacheDir.cache_show = options.cache_show
+
+ if options.no_exec:
+ CleanTask.execute = CleanTask.show
+ else:
+ CleanTask.execute = CleanTask.remove
+
+ lookup_top = None
+ if targets or SCons.Script.BUILD_TARGETS != SCons.Script._build_plus_default:
+ # They specified targets on the command line or modified
+ # BUILD_TARGETS in the SConscript file(s), so if they used -u,
+ # -U or -D, we have to look up targets relative to the top,
+ # but we build whatever they specified.
+ if target_top:
+ lookup_top = fs.Dir(target_top)
+ target_top = None
+
+ targets = SCons.Script.BUILD_TARGETS
+ else:
+ # There are no targets specified on the command line,
+ # so if they used -u, -U or -D, we may have to restrict
+ # what actually gets built.
+ d = None
+ if target_top:
+ if options.climb_up == 1:
+ # -u, local directory and below
+ target_top = fs.Dir(target_top)
+ lookup_top = target_top
+ elif options.climb_up == 2:
+ # -D, all Default() targets
+ target_top = None
+ lookup_top = None
+ elif options.climb_up == 3:
+ # -U, local SConscript Default() targets
+ target_top = fs.Dir(target_top)
+ def check_dir(x, target_top=target_top):
+ if hasattr(x, 'cwd') and not x.cwd is None:
+ cwd = x.cwd.srcnode()
+ return cwd == target_top
+ else:
+ # x doesn't have a cwd, so it's either not a target,
+ # or not a file, so go ahead and keep it as a default
+ # target and let the engine sort it out:
+ return 1
+ d = list(filter(check_dir, SCons.Script.DEFAULT_TARGETS))
+ SCons.Script.DEFAULT_TARGETS[:] = d
+ target_top = None
+ lookup_top = None
+
+ targets = SCons.Script._Get_Default_Targets(d, fs)
+
+ if not targets:
+ sys.stderr.write("scons: *** No targets specified and no Default() targets found. Stop.\n")
+ return None
+
+ def Entry(x, ltop=lookup_top, ttop=target_top, fs=fs):
+ if isinstance(x, SCons.Node.Node):
+ node = x
+ else:
+ node = None
+ # Why would ltop be None? Unfortunately this happens.
+ if ltop is None: ltop = ''
+ # Curdir becomes important when SCons is called with -u, -C,
+ # or similar option that changes directory, and so the paths
+ # of targets given on the command line need to be adjusted.
+ curdir = os.path.join(os.getcwd(), str(ltop))
+ for lookup in SCons.Node.arg2nodes_lookups:
+ node = lookup(x, curdir=curdir)
+ if node is not None:
+ break
+ if node is None:
+ node = fs.Entry(x, directory=ltop, create=1)
+ if ttop and not node.is_under(ttop):
+ if isinstance(node, SCons.Node.FS.Dir) and ttop.is_under(node):
+ node = ttop
+ else:
+ node = None
+ return node
+
+ nodes = [_f for _f in map(Entry, targets) if _f]
+
+ task_class = BuildTask # default action is to build targets
+ opening_message = "Building targets ..."
+ closing_message = "done building targets."
+ if options.keep_going:
+ failure_message = "done building targets (errors occurred during build)."
+ else:
+ failure_message = "building terminated because of errors."
+ if options.question:
+ task_class = QuestionTask
+ try:
+ if options.clean:
+ task_class = CleanTask
+ opening_message = "Cleaning targets ..."
+ closing_message = "done cleaning targets."
+ if options.keep_going:
+ failure_message = "done cleaning targets (errors occurred during clean)."
+ else:
+ failure_message = "cleaning terminated because of errors."
+ except AttributeError:
+ pass
+
+ task_class.progress = ProgressObject
+
+ if options.random:
+ def order(dependencies):
+ """Randomize the dependencies."""
+ import random
+ # This is cribbed from the implementation of
+ # random.shuffle() in Python 2.X.
+ d = dependencies
+ for i in range(len(d)-1, 0, -1):
+ j = int(random.random() * (i+1))
+ d[i], d[j] = d[j], d[i]
+ return d
+ else:
+ def order(dependencies):
+ """Leave the order of dependencies alone."""
+ return dependencies
+
+ if options.taskmastertrace_file == '-':
+ tmtrace = sys.stdout
+ elif options.taskmastertrace_file:
+ tmtrace = open(options.taskmastertrace_file, 'wb')
+ else:
+ tmtrace = None
+ taskmaster = SCons.Taskmaster.Taskmaster(nodes, task_class, order, tmtrace)
+
+ # Let the BuildTask objects get at the options to respond to the
+ # various print_* settings, tree_printer list, etc.
+ BuildTask.options = options
+
+ global num_jobs
+ num_jobs = options.num_jobs
+ jobs = SCons.Job.Jobs(num_jobs, taskmaster)
+ if num_jobs > 1:
+ msg = None
+ if jobs.num_jobs == 1:
+ msg = "parallel builds are unsupported by this version of Python;\n" + \
+ "\tignoring -j or num_jobs option.\n"
+ elif sys.platform == 'win32':
+ msg = fetch_win32_parallel_msg()
+ if msg:
+ SCons.Warnings.warn(SCons.Warnings.NoParallelSupportWarning, msg)
+
+ memory_stats.append('before building targets:')
+ count_stats.append(('pre-', 'build'))
+
+ def jobs_postfunc(
+ jobs=jobs,
+ options=options,
+ closing_message=closing_message,
+ failure_message=failure_message
+ ):
+ if jobs.were_interrupted():
+ if not options.no_progress and not options.silent:
+ sys.stderr.write("scons: Build interrupted.\n")
+ global exit_status
+ global this_build_status
+ exit_status = 2
+ this_build_status = 2
+
+ if this_build_status:
+ progress_display("scons: " + failure_message)
+ else:
+ progress_display("scons: " + closing_message)
+ if not options.no_exec:
+ if jobs.were_interrupted():
+ progress_display("scons: writing .sconsign file.")
+ SCons.SConsign.write()
+
+ progress_display("scons: " + opening_message)
+ jobs.run(postfunc = jobs_postfunc)
+
+ memory_stats.append('after building targets:')
+ count_stats.append(('post-', 'build'))
+
+ return nodes
+
+def _exec_main(parser, values):
+ sconsflags = os.environ.get('SCONSFLAGS', '')
+ all_args = sconsflags.split() + sys.argv[1:]
+
+ options, args = parser.parse_args(all_args, values)
+
+ if isinstance(options.debug, list) and "pdb" in options.debug:
+ import pdb
+ pdb.Pdb().runcall(_main, parser)
+ elif options.profile_file:
+ # compat layer imports "cProfile" for us if it's available.
+ from profile import Profile
+
+ # Some versions of Python 2.4 shipped a profiler that had the
+ # wrong 'c_exception' entry in its dispatch table. Make sure
+ # we have the right one. (This may put an unnecessary entry
+ # in the table in earlier versions of Python, but its presence
+ # shouldn't hurt anything).
+ try:
+ dispatch = Profile.dispatch
+ except AttributeError:
+ pass
+ else:
+ dispatch['c_exception'] = Profile.trace_dispatch_return
+
+ prof = Profile()
+ try:
+ prof.runcall(_main, parser)
+ except SConsPrintHelpException, e:
+ prof.dump_stats(options.profile_file)
+ raise e
+ except SystemExit:
+ pass
+ prof.dump_stats(options.profile_file)
+ else:
+ _main(parser)
+
+def main():
+ global OptionsParser
+ global exit_status
+ global first_command_start
+
+ # Check up front for a Python version we do not support. We
+ # delay the check for deprecated Python versions until later,
+ # after the SConscript files have been read, in case they
+ # disable that warning.
+ if python_version_unsupported():
+ msg = "scons: *** SCons version %s does not run under Python version %s.\n"
+ sys.stderr.write(msg % (SCons.__version__, python_version_string()))
+ sys.exit(1)
+
+ parts = ["SCons by Steven Knight et al.:\n"]
+ try:
+ import __main__
+ parts.append(version_string("script", __main__))
+ except (ImportError, AttributeError):
+ # On Windows there is no scons.py, so there is no
+ # __main__.__version__, hence there is no script version.
+ pass
+ parts.append(version_string("engine", SCons))
+ parts.append("Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation")
+ version = ''.join(parts)
+
+ import SConsOptions
+ parser = SConsOptions.Parser(version)
+ values = SConsOptions.SConsValues(parser.get_default_values())
+
+ OptionsParser = parser
+
+ try:
+ _exec_main(parser, values)
+ except SystemExit, s:
+ if s:
+ exit_status = s
+ except KeyboardInterrupt:
+ print("scons: Build interrupted.")
+ sys.exit(2)
+ except SyntaxError, e:
+ _scons_syntax_error(e)
+ except SCons.Errors.InternalError:
+ _scons_internal_error()
+ except SCons.Errors.UserError, e:
+ _scons_user_error(e)
+ except SConsPrintHelpException:
+ parser.print_help()
+ exit_status = 0
+ except SCons.Errors.BuildError, e:
+ exit_status = e.exitstatus
+ except:
+ # An exception here is likely a builtin Python exception Python
+ # code in an SConscript file. Show them precisely what the
+ # problem was and where it happened.
+ SCons.Script._SConscript.SConscript_exception()
+ sys.exit(2)
+
+ memory_stats.print_stats()
+ count_stats.print_stats()
+
+ if print_objects:
+ SCons.Debug.listLoggedInstances('*')
+ #SCons.Debug.dumpLoggedInstances('*')
+
+ if print_memoizer:
+ SCons.Memoize.Dump("Memoizer (memory cache) hits and misses:")
+
+ # Dump any development debug info that may have been enabled.
+ # These are purely for internal debugging during development, so
+ # there's no need to control them with --debug= options; they're
+ # controlled by changing the source code.
+ SCons.Debug.dump_caller_counts()
+ SCons.Taskmaster.dump_stats()
+
+ if print_time:
+ total_time = time.time() - SCons.Script.start_time
+ if num_jobs == 1:
+ ct = cumulative_command_time
+ else:
+ if last_command_end is None or first_command_start is None:
+ ct = 0.0
+ else:
+ ct = last_command_end - first_command_start
+ scons_time = total_time - sconscript_time - ct
+ print "Total build time: %f seconds"%total_time
+ print "Total SConscript file execution time: %f seconds"%sconscript_time
+ print "Total SCons execution time: %f seconds"%scons_time
+ print "Total command execution time: %f seconds"%ct
+
+ sys.exit(exit_status)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Script/SConsOptions.py b/couchjs/scons/scons-local-2.0.1/SCons/Script/SConsOptions.py
new file mode 100644
index 00000000..8afedf63
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Script/SConsOptions.py
@@ -0,0 +1,939 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Script/SConsOptions.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import optparse
+import re
+import sys
+import textwrap
+
+no_hyphen_re = re.compile(r'(\s+|(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))')
+
+try:
+ from gettext import gettext
+except ImportError:
+ def gettext(message):
+ return message
+_ = gettext
+
+import SCons.Node.FS
+import SCons.Warnings
+
+OptionValueError = optparse.OptionValueError
+SUPPRESS_HELP = optparse.SUPPRESS_HELP
+
+diskcheck_all = SCons.Node.FS.diskcheck_types()
+
+def diskcheck_convert(value):
+ if value is None:
+ return []
+ if not SCons.Util.is_List(value):
+ value = value.split(',')
+ result = []
+ for v in value:
+ v = v.lower()
+ if v == 'all':
+ result = diskcheck_all
+ elif v == 'none':
+ result = []
+ elif v in diskcheck_all:
+ result.append(v)
+ else:
+ raise ValueError(v)
+ return result
+
+class SConsValues(optparse.Values):
+ """
+ Holder class for uniform access to SCons options, regardless
+ of whether or not they can be set on the command line or in the
+ SConscript files (using the SetOption() function).
+
+ A SCons option value can originate three different ways:
+
+ 1) set on the command line;
+ 2) set in an SConscript file;
+ 3) the default setting (from the the op.add_option()
+ calls in the Parser() function, below).
+
+ The command line always overrides a value set in a SConscript file,
+ which in turn always overrides default settings. Because we want
+ to support user-specified options in the SConscript file itself,
+ though, we may not know about all of the options when the command
+ line is first parsed, so we can't make all the necessary precedence
+ decisions at the time the option is configured.
+
+ The solution implemented in this class is to keep these different sets
+ of settings separate (command line, SConscript file, and default)
+ and to override the __getattr__() method to check them in turn.
+ This should allow the rest of the code to just fetch values as
+ attributes of an instance of this class, without having to worry
+ about where they came from.
+
+ Note that not all command line options are settable from SConscript
+ files, and the ones that are must be explicitly added to the
+ "settable" list in this class, and optionally validated and coerced
+ in the set_option() method.
+ """
+
+ def __init__(self, defaults):
+ self.__dict__['__defaults__'] = defaults
+ self.__dict__['__SConscript_settings__'] = {}
+
+ def __getattr__(self, attr):
+ """
+ Fetches an options value, checking first for explicit settings
+ from the command line (which are direct attributes), then the
+ SConscript file settings, then the default values.
+ """
+ try:
+ return self.__dict__[attr]
+ except KeyError:
+ try:
+ return self.__dict__['__SConscript_settings__'][attr]
+ except KeyError:
+ return getattr(self.__dict__['__defaults__'], attr)
+
+ settable = [
+ 'clean',
+ 'diskcheck',
+ 'duplicate',
+ 'help',
+ 'implicit_cache',
+ 'max_drift',
+ 'md5_chunksize',
+ 'no_exec',
+ 'num_jobs',
+ 'random',
+ 'stack_size',
+ 'warn',
+ ]
+
+ def set_option(self, name, value):
+ """
+ Sets an option from an SConscript file.
+ """
+ if not name in self.settable:
+ raise SCons.Errors.UserError("This option is not settable from a SConscript file: %s"%name)
+
+ if name == 'num_jobs':
+ try:
+ value = int(value)
+ if value < 1:
+ raise ValueError
+ except ValueError:
+ raise SCons.Errors.UserError("A positive integer is required: %s"%repr(value))
+ elif name == 'max_drift':
+ try:
+ value = int(value)
+ except ValueError:
+ raise SCons.Errors.UserError("An integer is required: %s"%repr(value))
+ elif name == 'duplicate':
+ try:
+ value = str(value)
+ except ValueError:
+ raise SCons.Errors.UserError("A string is required: %s"%repr(value))
+ if not value in SCons.Node.FS.Valid_Duplicates:
+ raise SCons.Errors.UserError("Not a valid duplication style: %s" % value)
+ # Set the duplicate style right away so it can affect linking
+ # of SConscript files.
+ SCons.Node.FS.set_duplicate(value)
+ elif name == 'diskcheck':
+ try:
+ value = diskcheck_convert(value)
+ except ValueError, v:
+ raise SCons.Errors.UserError("Not a valid diskcheck value: %s"%v)
+ if 'diskcheck' not in self.__dict__:
+ # No --diskcheck= option was specified on the command line.
+ # Set this right away so it can affect the rest of the
+ # file/Node lookups while processing the SConscript files.
+ SCons.Node.FS.set_diskcheck(value)
+ elif name == 'stack_size':
+ try:
+ value = int(value)
+ except ValueError:
+ raise SCons.Errors.UserError("An integer is required: %s"%repr(value))
+ elif name == 'md5_chunksize':
+ try:
+ value = int(value)
+ except ValueError:
+ raise SCons.Errors.UserError("An integer is required: %s"%repr(value))
+ elif name == 'warn':
+ if SCons.Util.is_String(value):
+ value = [value]
+ value = self.__SConscript_settings__.get(name, []) + value
+ SCons.Warnings.process_warn_strings(value)
+
+ self.__SConscript_settings__[name] = value
+
+class SConsOption(optparse.Option):
+ def convert_value(self, opt, value):
+ if value is not None:
+ if self.nargs in (1, '?'):
+ return self.check_value(opt, value)
+ else:
+ return tuple([self.check_value(opt, v) for v in value])
+
+ def process(self, opt, value, values, parser):
+
+ # First, convert the value(s) to the right type. Howl if any
+ # value(s) are bogus.
+ value = self.convert_value(opt, value)
+
+ # And then take whatever action is expected of us.
+ # This is a separate method to make life easier for
+ # subclasses to add new actions.
+ return self.take_action(
+ self.action, self.dest, opt, value, values, parser)
+
+ def _check_nargs_optional(self):
+ if self.nargs == '?' and self._short_opts:
+ fmt = "option %s: nargs='?' is incompatible with short options"
+ raise SCons.Errors.UserError(fmt % self._short_opts[0])
+
+ try:
+ _orig_CONST_ACTIONS = optparse.Option.CONST_ACTIONS
+
+ _orig_CHECK_METHODS = optparse.Option.CHECK_METHODS
+
+ except AttributeError:
+ # optparse.Option had no CONST_ACTIONS before Python 2.5.
+
+ _orig_CONST_ACTIONS = ("store_const",)
+
+ def _check_const(self):
+ if self.action not in self.CONST_ACTIONS and self.const is not None:
+ raise OptionError(
+ "'const' must not be supplied for action %r" % self.action,
+ self)
+
+ # optparse.Option collects its list of unbound check functions
+ # up front. This sucks because it means we can't just override
+ # the _check_const() function like a normal method, we have to
+ # actually replace it in the list. This seems to be the most
+ # straightforward way to do that.
+
+ _orig_CHECK_METHODS = [optparse.Option._check_action,
+ optparse.Option._check_type,
+ optparse.Option._check_choice,
+ optparse.Option._check_dest,
+ _check_const,
+ optparse.Option._check_nargs,
+ optparse.Option._check_callback]
+
+ CHECK_METHODS = _orig_CHECK_METHODS + [_check_nargs_optional]
+
+ CONST_ACTIONS = _orig_CONST_ACTIONS + optparse.Option.TYPED_ACTIONS
+
+class SConsOptionGroup(optparse.OptionGroup):
+ """
+ A subclass for SCons-specific option groups.
+
+ The only difference between this and the base class is that we print
+ the group's help text flush left, underneath their own title but
+ lined up with the normal "SCons Options".
+ """
+ def format_help(self, formatter):
+ """
+ Format an option group's help text, outdenting the title so it's
+ flush with the "SCons Options" title we print at the top.
+ """
+ formatter.dedent()
+ result = formatter.format_heading(self.title)
+ formatter.indent()
+ result = result + optparse.OptionContainer.format_help(self, formatter)
+ return result
+
+class SConsOptionParser(optparse.OptionParser):
+ preserve_unknown_options = False
+
+ def error(self, msg):
+ self.print_usage(sys.stderr)
+ sys.stderr.write("SCons error: %s\n" % msg)
+ sys.exit(2)
+
+ def _process_long_opt(self, rargs, values):
+ """
+ SCons-specific processing of long options.
+
+ This is copied directly from the normal
+ optparse._process_long_opt() method, except that, if configured
+ to do so, we catch the exception thrown when an unknown option
+ is encountered and just stick it back on the "leftover" arguments
+ for later (re-)processing.
+ """
+ arg = rargs.pop(0)
+
+ # Value explicitly attached to arg? Pretend it's the next
+ # argument.
+ if "=" in arg:
+ (opt, next_arg) = arg.split("=", 1)
+ rargs.insert(0, next_arg)
+ had_explicit_value = True
+ else:
+ opt = arg
+ had_explicit_value = False
+
+ try:
+ opt = self._match_long_opt(opt)
+ except optparse.BadOptionError:
+ if self.preserve_unknown_options:
+ # SCons-specific: if requested, add unknown options to
+ # the "leftover arguments" list for later processing.
+ self.largs.append(arg)
+ if had_explicit_value:
+ # The unknown option will be re-processed later,
+ # so undo the insertion of the explicit value.
+ rargs.pop(0)
+ return
+ raise
+
+ option = self._long_opt[opt]
+ if option.takes_value():
+ nargs = option.nargs
+ if nargs == '?':
+ if had_explicit_value:
+ value = rargs.pop(0)
+ else:
+ value = option.const
+ elif len(rargs) < nargs:
+ if nargs == 1:
+ self.error(_("%s option requires an argument") % opt)
+ else:
+ self.error(_("%s option requires %d arguments")
+ % (opt, nargs))
+ elif nargs == 1:
+ value = rargs.pop(0)
+ else:
+ value = tuple(rargs[0:nargs])
+ del rargs[0:nargs]
+
+ elif had_explicit_value:
+ self.error(_("%s option does not take a value") % opt)
+
+ else:
+ value = None
+
+ option.process(opt, value, values, self)
+
+ def add_local_option(self, *args, **kw):
+ """
+ Adds a local option to the parser.
+
+ This is initiated by a SetOption() call to add a user-defined
+ command-line option. We add the option to a separate option
+ group for the local options, creating the group if necessary.
+ """
+ try:
+ group = self.local_option_group
+ except AttributeError:
+ group = SConsOptionGroup(self, 'Local Options')
+ group = self.add_option_group(group)
+ self.local_option_group = group
+
+ result = group.add_option(*args, **kw)
+
+ if result:
+ # The option was added succesfully. We now have to add the
+ # default value to our object that holds the default values
+ # (so that an attempt to fetch the option's attribute will
+ # yield the default value when not overridden) and then
+ # we re-parse the leftover command-line options, so that
+ # any value overridden on the command line is immediately
+ # available if the user turns around and does a GetOption()
+ # right away.
+ setattr(self.values.__defaults__, result.dest, result.default)
+ self.parse_args(self.largs, self.values)
+
+ return result
+
+class SConsIndentedHelpFormatter(optparse.IndentedHelpFormatter):
+ def format_usage(self, usage):
+ return "usage: %s\n" % usage
+
+ def format_heading(self, heading):
+ """
+ This translates any heading of "options" or "Options" into
+ "SCons Options." Unfortunately, we have to do this here,
+ because those titles are hard-coded in the optparse calls.
+ """
+ if heading == 'options':
+ # The versions of optparse.py shipped with Pythons 2.3 and
+ # 2.4 pass this in uncapitalized; override that so we get
+ # consistent output on all versions.
+ heading = "Options"
+ if heading == 'Options':
+ heading = "SCons Options"
+ return optparse.IndentedHelpFormatter.format_heading(self, heading)
+
+ def format_option(self, option):
+ """
+ A copy of the normal optparse.IndentedHelpFormatter.format_option()
+ method. This has been snarfed so we can modify text wrapping to
+ out liking:
+
+ -- add our own regular expression that doesn't break on hyphens
+ (so things like --no-print-directory don't get broken);
+
+ -- wrap the list of options themselves when it's too long
+ (the wrapper.fill(opts) call below);
+
+ -- set the subsequent_indent when wrapping the help_text.
+ """
+ # The help for each option consists of two parts:
+ # * the opt strings and metavars
+ # eg. ("-x", or "-fFILENAME, --file=FILENAME")
+ # * the user-supplied help string
+ # eg. ("turn on expert mode", "read data from FILENAME")
+ #
+ # If possible, we write both of these on the same line:
+ # -x turn on expert mode
+ #
+ # But if the opt string list is too long, we put the help
+ # string on a second line, indented to the same column it would
+ # start in if it fit on the first line.
+ # -fFILENAME, --file=FILENAME
+ # read data from FILENAME
+ result = []
+
+ try:
+ opts = self.option_strings[option]
+ except AttributeError:
+ # The Python 2.3 version of optparse attaches this to
+ # to the option argument, not to this object.
+ opts = option.option_strings
+
+ opt_width = self.help_position - self.current_indent - 2
+ if len(opts) > opt_width:
+ wrapper = textwrap.TextWrapper(width=self.width,
+ initial_indent = ' ',
+ subsequent_indent = ' ')
+ wrapper.wordsep_re = no_hyphen_re
+ opts = wrapper.fill(opts) + '\n'
+ indent_first = self.help_position
+ else: # start help on same line as opts
+ opts = "%*s%-*s " % (self.current_indent, "", opt_width, opts)
+ indent_first = 0
+ result.append(opts)
+ if option.help:
+
+ try:
+ expand_default = self.expand_default
+ except AttributeError:
+ # The HelpFormatter base class in the Python 2.3 version
+ # of optparse has no expand_default() method.
+ help_text = option.help
+ else:
+ help_text = expand_default(option)
+
+ # SCons: indent every line of the help text but the first.
+ wrapper = textwrap.TextWrapper(width=self.help_width,
+ subsequent_indent = ' ')
+ wrapper.wordsep_re = no_hyphen_re
+ help_lines = wrapper.wrap(help_text)
+ result.append("%*s%s\n" % (indent_first, "", help_lines[0]))
+ for line in help_lines[1:]:
+ result.append("%*s%s\n" % (self.help_position, "", line))
+ elif opts[-1] != "\n":
+ result.append("\n")
+ return "".join(result)
+
+ # For consistent help output across Python versions, we provide a
+ # subclass copy of format_option_strings() and these two variables.
+ # This is necessary (?) for Python2.3, which otherwise concatenates
+ # a short option with its metavar.
+ _short_opt_fmt = "%s %s"
+ _long_opt_fmt = "%s=%s"
+
+ def format_option_strings(self, option):
+ """Return a comma-separated list of option strings & metavariables."""
+ if option.takes_value():
+ metavar = option.metavar or option.dest.upper()
+ short_opts = []
+ for sopt in option._short_opts:
+ short_opts.append(self._short_opt_fmt % (sopt, metavar))
+ long_opts = []
+ for lopt in option._long_opts:
+ long_opts.append(self._long_opt_fmt % (lopt, metavar))
+ else:
+ short_opts = option._short_opts
+ long_opts = option._long_opts
+
+ if self.short_first:
+ opts = short_opts + long_opts
+ else:
+ opts = long_opts + short_opts
+
+ return ", ".join(opts)
+
+def Parser(version):
+ """
+ Returns an options parser object initialized with the standard
+ SCons options.
+ """
+
+ formatter = SConsIndentedHelpFormatter(max_help_position=30)
+
+ op = SConsOptionParser(option_class=SConsOption,
+ add_help_option=False,
+ formatter=formatter,
+ usage="usage: scons [OPTION] [TARGET] ...",)
+
+ op.preserve_unknown_options = True
+ op.version = version
+
+ # Add the options to the parser we just created.
+ #
+ # These are in the order we want them to show up in the -H help
+ # text, basically alphabetical. Each op.add_option() call below
+ # should have a consistent format:
+ #
+ # op.add_option("-L", "--long-option-name",
+ # nargs=1, type="string",
+ # dest="long_option_name", default='foo',
+ # action="callback", callback=opt_long_option,
+ # help="help text goes here",
+ # metavar="VAR")
+ #
+ # Even though the optparse module constructs reasonable default
+ # destination names from the long option names, we're going to be
+ # explicit about each one for easier readability and so this code
+ # will at least show up when grepping the source for option attribute
+ # names, or otherwise browsing the source code.
+
+ # options ignored for compatibility
+ def opt_ignore(option, opt, value, parser):
+ sys.stderr.write("Warning: ignoring %s option\n" % opt)
+ op.add_option("-b", "-d", "-e", "-m", "-S", "-t", "-w",
+ "--environment-overrides",
+ "--no-keep-going",
+ "--no-print-directory",
+ "--print-directory",
+ "--stop",
+ "--touch",
+ action="callback", callback=opt_ignore,
+ help="Ignored for compatibility.")
+
+ op.add_option('-c', '--clean', '--remove',
+ dest="clean", default=False,
+ action="store_true",
+ help="Remove specified targets and dependencies.")
+
+ op.add_option('-C', '--directory',
+ nargs=1, type="string",
+ dest="directory", default=[],
+ action="append",
+ help="Change to DIR before doing anything.",
+ metavar="DIR")
+
+ op.add_option('--cache-debug',
+ nargs=1,
+ dest="cache_debug", default=None,
+ action="store",
+ help="Print CacheDir debug info to FILE.",
+ metavar="FILE")
+
+ op.add_option('--cache-disable', '--no-cache',
+ dest='cache_disable', default=False,
+ action="store_true",
+ help="Do not retrieve built targets from CacheDir.")
+
+ op.add_option('--cache-force', '--cache-populate',
+ dest='cache_force', default=False,
+ action="store_true",
+ help="Copy already-built targets into the CacheDir.")
+
+ op.add_option('--cache-show',
+ dest='cache_show', default=False,
+ action="store_true",
+ help="Print build actions for files from CacheDir.")
+
+ config_options = ["auto", "force" ,"cache"]
+
+ def opt_config(option, opt, value, parser, c_options=config_options):
+ if not value in c_options:
+ raise OptionValueError("Warning: %s is not a valid config type" % value)
+ setattr(parser.values, option.dest, value)
+ opt_config_help = "Controls Configure subsystem: %s." \
+ % ", ".join(config_options)
+ op.add_option('--config',
+ nargs=1, type="string",
+ dest="config", default="auto",
+ action="callback", callback=opt_config,
+ help = opt_config_help,
+ metavar="MODE")
+
+ op.add_option('-D',
+ dest="climb_up", default=None,
+ action="store_const", const=2,
+ help="Search up directory tree for SConstruct, "
+ "build all Default() targets.")
+
+ deprecated_debug_options = {
+ "dtree" : '; please use --tree=derived instead',
+ "nomemoizer" : ' and has no effect',
+ "stree" : '; please use --tree=all,status instead',
+ "tree" : '; please use --tree=all instead',
+ }
+
+ debug_options = ["count", "explain", "findlibs",
+ "includes", "memoizer", "memory", "objects",
+ "pdb", "presub", "stacktrace",
+ "time"] + list(deprecated_debug_options.keys())
+
+ def opt_debug(option, opt, value, parser,
+ debug_options=debug_options,
+ deprecated_debug_options=deprecated_debug_options):
+ if value in debug_options:
+ parser.values.debug.append(value)
+ if value in deprecated_debug_options.keys():
+ try:
+ parser.values.delayed_warnings
+ except AttributeError:
+ parser.values.delayed_warnings = []
+ msg = deprecated_debug_options[value]
+ w = "The --debug=%s option is deprecated%s." % (value, msg)
+ t = (SCons.Warnings.DeprecatedDebugOptionsWarning, w)
+ parser.values.delayed_warnings.append(t)
+ else:
+ raise OptionValueError("Warning: %s is not a valid debug type" % value)
+ opt_debug_help = "Print various types of debugging information: %s." \
+ % ", ".join(debug_options)
+ op.add_option('--debug',
+ nargs=1, type="string",
+ dest="debug", default=[],
+ action="callback", callback=opt_debug,
+ help=opt_debug_help,
+ metavar="TYPE")
+
+ def opt_diskcheck(option, opt, value, parser):
+ try:
+ diskcheck_value = diskcheck_convert(value)
+ except ValueError, e:
+ raise OptionValueError("Warning: `%s' is not a valid diskcheck type" % e)
+ setattr(parser.values, option.dest, diskcheck_value)
+
+ op.add_option('--diskcheck',
+ nargs=1, type="string",
+ dest='diskcheck', default=None,
+ action="callback", callback=opt_diskcheck,
+ help="Enable specific on-disk checks.",
+ metavar="TYPE")
+
+ def opt_duplicate(option, opt, value, parser):
+ if not value in SCons.Node.FS.Valid_Duplicates:
+ raise OptionValueError("`%s' is not a valid duplication style." % value)
+ setattr(parser.values, option.dest, value)
+ # Set the duplicate style right away so it can affect linking
+ # of SConscript files.
+ SCons.Node.FS.set_duplicate(value)
+
+ opt_duplicate_help = "Set the preferred duplication methods. Must be one of " \
+ + ", ".join(SCons.Node.FS.Valid_Duplicates)
+
+ op.add_option('--duplicate',
+ nargs=1, type="string",
+ dest="duplicate", default='hard-soft-copy',
+ action="callback", callback=opt_duplicate,
+ help=opt_duplicate_help)
+
+ op.add_option('-f', '--file', '--makefile', '--sconstruct',
+ nargs=1, type="string",
+ dest="file", default=[],
+ action="append",
+ help="Read FILE as the top-level SConstruct file.")
+
+ op.add_option('-h', '--help',
+ dest="help", default=False,
+ action="store_true",
+ help="Print defined help message, or this one.")
+
+ op.add_option("-H", "--help-options",
+ action="help",
+ help="Print this message and exit.")
+
+ op.add_option('-i', '--ignore-errors',
+ dest='ignore_errors', default=False,
+ action="store_true",
+ help="Ignore errors from build actions.")
+
+ op.add_option('-I', '--include-dir',
+ nargs=1,
+ dest='include_dir', default=[],
+ action="append",
+ help="Search DIR for imported Python modules.",
+ metavar="DIR")
+
+ op.add_option('--implicit-cache',
+ dest='implicit_cache', default=False,
+ action="store_true",
+ help="Cache implicit dependencies")
+
+ def opt_implicit_deps(option, opt, value, parser):
+ setattr(parser.values, 'implicit_cache', True)
+ setattr(parser.values, option.dest, True)
+
+ op.add_option('--implicit-deps-changed',
+ dest="implicit_deps_changed", default=False,
+ action="callback", callback=opt_implicit_deps,
+ help="Ignore cached implicit dependencies.")
+
+ op.add_option('--implicit-deps-unchanged',
+ dest="implicit_deps_unchanged", default=False,
+ action="callback", callback=opt_implicit_deps,
+ help="Ignore changes in implicit dependencies.")
+
+ op.add_option('--interact', '--interactive',
+ dest='interactive', default=False,
+ action="store_true",
+ help="Run in interactive mode.")
+
+ op.add_option('-j', '--jobs',
+ nargs=1, type="int",
+ dest="num_jobs", default=1,
+ action="store",
+ help="Allow N jobs at once.",
+ metavar="N")
+
+ op.add_option('-k', '--keep-going',
+ dest='keep_going', default=False,
+ action="store_true",
+ help="Keep going when a target can't be made.")
+
+ op.add_option('--max-drift',
+ nargs=1, type="int",
+ dest='max_drift', default=SCons.Node.FS.default_max_drift,
+ action="store",
+ help="Set maximum system clock drift to N seconds.",
+ metavar="N")
+
+ op.add_option('--md5-chunksize',
+ nargs=1, type="int",
+ dest='md5_chunksize', default=SCons.Node.FS.File.md5_chunksize,
+ action="store",
+ help="Set chunk-size for MD5 signature computation to N kilobytes.",
+ metavar="N")
+
+ op.add_option('-n', '--no-exec', '--just-print', '--dry-run', '--recon',
+ dest='no_exec', default=False,
+ action="store_true",
+ help="Don't build; just print commands.")
+
+ op.add_option('--no-site-dir',
+ dest='no_site_dir', default=False,
+ action="store_true",
+ help="Don't search or use the usual site_scons dir.")
+
+ op.add_option('--profile',
+ nargs=1,
+ dest="profile_file", default=None,
+ action="store",
+ help="Profile SCons and put results in FILE.",
+ metavar="FILE")
+
+ op.add_option('-q', '--question',
+ dest="question", default=False,
+ action="store_true",
+ help="Don't build; exit status says if up to date.")
+
+ op.add_option('-Q',
+ dest='no_progress', default=False,
+ action="store_true",
+ help="Suppress \"Reading/Building\" progress messages.")
+
+ op.add_option('--random',
+ dest="random", default=False,
+ action="store_true",
+ help="Build dependencies in random order.")
+
+ op.add_option('-s', '--silent', '--quiet',
+ dest="silent", default=False,
+ action="store_true",
+ help="Don't print commands.")
+
+ op.add_option('--site-dir',
+ nargs=1,
+ dest='site_dir', default=None,
+ action="store",
+ help="Use DIR instead of the usual site_scons dir.",
+ metavar="DIR")
+
+ op.add_option('--stack-size',
+ nargs=1, type="int",
+ dest='stack_size',
+ action="store",
+ help="Set the stack size of the threads used to run jobs to N kilobytes.",
+ metavar="N")
+
+ op.add_option('--taskmastertrace',
+ nargs=1,
+ dest="taskmastertrace_file", default=None,
+ action="store",
+ help="Trace Node evaluation to FILE.",
+ metavar="FILE")
+
+ tree_options = ["all", "derived", "prune", "status"]
+
+ def opt_tree(option, opt, value, parser, tree_options=tree_options):
+ import Main
+ tp = Main.TreePrinter()
+ for o in value.split(','):
+ if o == 'all':
+ tp.derived = False
+ elif o == 'derived':
+ tp.derived = True
+ elif o == 'prune':
+ tp.prune = True
+ elif o == 'status':
+ tp.status = True
+ else:
+ raise OptionValueError("Warning: %s is not a valid --tree option" % o)
+ parser.values.tree_printers.append(tp)
+
+ opt_tree_help = "Print a dependency tree in various formats: %s." \
+ % ", ".join(tree_options)
+
+ op.add_option('--tree',
+ nargs=1, type="string",
+ dest="tree_printers", default=[],
+ action="callback", callback=opt_tree,
+ help=opt_tree_help,
+ metavar="OPTIONS")
+
+ op.add_option('-u', '--up', '--search-up',
+ dest="climb_up", default=0,
+ action="store_const", const=1,
+ help="Search up directory tree for SConstruct, "
+ "build targets at or below current directory.")
+
+ op.add_option('-U',
+ dest="climb_up", default=0,
+ action="store_const", const=3,
+ help="Search up directory tree for SConstruct, "
+ "build Default() targets from local SConscript.")
+
+ def opt_version(option, opt, value, parser):
+ sys.stdout.write(parser.version + '\n')
+ sys.exit(0)
+ op.add_option("-v", "--version",
+ action="callback", callback=opt_version,
+ help="Print the SCons version number and exit.")
+
+ def opt_warn(option, opt, value, parser, tree_options=tree_options):
+ if SCons.Util.is_String(value):
+ value = value.split(',')
+ parser.values.warn.extend(value)
+
+ op.add_option('--warn', '--warning',
+ nargs=1, type="string",
+ dest="warn", default=[],
+ action="callback", callback=opt_warn,
+ help="Enable or disable warnings.",
+ metavar="WARNING-SPEC")
+
+ op.add_option('-Y', '--repository', '--srcdir',
+ nargs=1,
+ dest="repository", default=[],
+ action="append",
+ help="Search REPOSITORY for source and target files.")
+
+ # Options from Make and Cons classic that we do not yet support,
+ # but which we may support someday and whose (potential) meanings
+ # we don't want to change. These all get a "the -X option is not
+ # yet implemented" message and don't show up in the help output.
+
+ def opt_not_yet(option, opt, value, parser):
+ msg = "Warning: the %s option is not yet implemented\n" % opt
+ sys.stderr.write(msg)
+
+ op.add_option('-l', '--load-average', '--max-load',
+ nargs=1, type="int",
+ dest="load_average", default=0,
+ action="callback", callback=opt_not_yet,
+ # action="store",
+ # help="Don't start multiple jobs unless load is below "
+ # "LOAD-AVERAGE."
+ help=SUPPRESS_HELP)
+ op.add_option('--list-actions',
+ dest="list_actions",
+ action="callback", callback=opt_not_yet,
+ # help="Don't build; list files and build actions."
+ help=SUPPRESS_HELP)
+ op.add_option('--list-derived',
+ dest="list_derived",
+ action="callback", callback=opt_not_yet,
+ # help="Don't build; list files that would be built."
+ help=SUPPRESS_HELP)
+ op.add_option('--list-where',
+ dest="list_where",
+ action="callback", callback=opt_not_yet,
+ # help="Don't build; list files and where defined."
+ help=SUPPRESS_HELP)
+ op.add_option('-o', '--old-file', '--assume-old',
+ nargs=1, type="string",
+ dest="old_file", default=[],
+ action="callback", callback=opt_not_yet,
+ # action="append",
+ # help = "Consider FILE to be old; don't rebuild it."
+ help=SUPPRESS_HELP)
+ op.add_option('--override',
+ nargs=1, type="string",
+ action="callback", callback=opt_not_yet,
+ dest="override",
+ # help="Override variables as specified in FILE."
+ help=SUPPRESS_HELP)
+ op.add_option('-p',
+ action="callback", callback=opt_not_yet,
+ dest="p",
+ # help="Print internal environments/objects."
+ help=SUPPRESS_HELP)
+ op.add_option('-r', '-R', '--no-builtin-rules', '--no-builtin-variables',
+ action="callback", callback=opt_not_yet,
+ dest="no_builtin_rules",
+ # help="Clear default environments and variables."
+ help=SUPPRESS_HELP)
+ op.add_option('--write-filenames',
+ nargs=1, type="string",
+ dest="write_filenames",
+ action="callback", callback=opt_not_yet,
+ # help="Write all filenames examined into FILE."
+ help=SUPPRESS_HELP)
+ op.add_option('-W', '--new-file', '--assume-new', '--what-if',
+ nargs=1, type="string",
+ dest="new_file",
+ action="callback", callback=opt_not_yet,
+ # help="Consider FILE to be changed."
+ help=SUPPRESS_HELP)
+ op.add_option('--warn-undefined-variables',
+ dest="warn_undefined_variables",
+ action="callback", callback=opt_not_yet,
+ # help="Warn when an undefined variable is referenced."
+ help=SUPPRESS_HELP)
+
+ return op
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Script/SConscript.py b/couchjs/scons/scons-local-2.0.1/SCons/Script/SConscript.py
new file mode 100644
index 00000000..5e896f1f
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Script/SConscript.py
@@ -0,0 +1,640 @@
+"""SCons.Script.SConscript
+
+This module defines the Python API provided to SConscript and SConstruct
+files.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+from __future__ import division
+
+__revision__ = "src/engine/SCons/Script/SConscript.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons
+import SCons.Action
+import SCons.Builder
+import SCons.Defaults
+import SCons.Environment
+import SCons.Errors
+import SCons.Node
+import SCons.Node.Alias
+import SCons.Node.FS
+import SCons.Platform
+import SCons.SConf
+import SCons.Script.Main
+import SCons.Tool
+import SCons.Util
+
+import collections
+import os
+import os.path
+import re
+import sys
+import traceback
+
+# The following variables used to live in this module. Some
+# SConscript files out there may have referred to them directly as
+# SCons.Script.SConscript.*. This is now supported by some special
+# handling towards the bottom of the SConscript.__init__.py module.
+#Arguments = {}
+#ArgList = []
+#BuildTargets = TargetList()
+#CommandLineTargets = []
+#DefaultTargets = []
+
+class SConscriptReturn(Exception):
+ pass
+
+launch_dir = os.path.abspath(os.curdir)
+
+GlobalDict = None
+
+# global exports set by Export():
+global_exports = {}
+
+# chdir flag
+sconscript_chdir = 1
+
+def get_calling_namespaces():
+ """Return the locals and globals for the function that called
+ into this module in the current call stack."""
+ try: 1//0
+ except ZeroDivisionError:
+ # Don't start iterating with the current stack-frame to
+ # prevent creating reference cycles (f_back is safe).
+ frame = sys.exc_info()[2].tb_frame.f_back
+
+ # Find the first frame that *isn't* from this file. This means
+ # that we expect all of the SCons frames that implement an Export()
+ # or SConscript() call to be in this file, so that we can identify
+ # the first non-Script.SConscript frame as the user's local calling
+ # environment, and the locals and globals dictionaries from that
+ # frame as the calling namespaces. See the comment below preceding
+ # the DefaultEnvironmentCall block for even more explanation.
+ while frame.f_globals.get("__name__") == __name__:
+ frame = frame.f_back
+
+ return frame.f_locals, frame.f_globals
+
+
+def compute_exports(exports):
+ """Compute a dictionary of exports given one of the parameters
+ to the Export() function or the exports argument to SConscript()."""
+
+ loc, glob = get_calling_namespaces()
+
+ retval = {}
+ try:
+ for export in exports:
+ if SCons.Util.is_Dict(export):
+ retval.update(export)
+ else:
+ try:
+ retval[export] = loc[export]
+ except KeyError:
+ retval[export] = glob[export]
+ except KeyError, x:
+ raise SCons.Errors.UserError("Export of non-existent variable '%s'"%x)
+
+ return retval
+
+class Frame(object):
+ """A frame on the SConstruct/SConscript call stack"""
+ def __init__(self, fs, exports, sconscript):
+ self.globals = BuildDefaultGlobals()
+ self.retval = None
+ self.prev_dir = fs.getcwd()
+ self.exports = compute_exports(exports) # exports from the calling SConscript
+ # make sure the sconscript attr is a Node.
+ if isinstance(sconscript, SCons.Node.Node):
+ self.sconscript = sconscript
+ elif sconscript == '-':
+ self.sconscript = None
+ else:
+ self.sconscript = fs.File(str(sconscript))
+
+# the SConstruct/SConscript call stack:
+call_stack = []
+
+# For documentation on the methods in this file, see the scons man-page
+
+def Return(*vars, **kw):
+ retval = []
+ try:
+ fvars = SCons.Util.flatten(vars)
+ for var in fvars:
+ for v in var.split():
+ retval.append(call_stack[-1].globals[v])
+ except KeyError, x:
+ raise SCons.Errors.UserError("Return of non-existent variable '%s'"%x)
+
+ if len(retval) == 1:
+ call_stack[-1].retval = retval[0]
+ else:
+ call_stack[-1].retval = tuple(retval)
+
+ stop = kw.get('stop', True)
+
+ if stop:
+ raise SConscriptReturn
+
+
+stack_bottom = '% Stack boTTom %' # hard to define a variable w/this name :)
+
+def _SConscript(fs, *files, **kw):
+ top = fs.Top
+ sd = fs.SConstruct_dir.rdir()
+ exports = kw.get('exports', [])
+
+ # evaluate each SConscript file
+ results = []
+ for fn in files:
+ call_stack.append(Frame(fs, exports, fn))
+ old_sys_path = sys.path
+ try:
+ SCons.Script.sconscript_reading = SCons.Script.sconscript_reading + 1
+ if fn == "-":
+ exec sys.stdin in call_stack[-1].globals
+ else:
+ if isinstance(fn, SCons.Node.Node):
+ f = fn
+ else:
+ f = fs.File(str(fn))
+ _file_ = None
+
+ # Change directory to the top of the source
+ # tree to make sure the os's cwd and the cwd of
+ # fs match so we can open the SConscript.
+ fs.chdir(top, change_os_dir=1)
+ if f.rexists():
+ actual = f.rfile()
+ _file_ = open(actual.get_abspath(), "r")
+ elif f.srcnode().rexists():
+ actual = f.srcnode().rfile()
+ _file_ = open(actual.get_abspath(), "r")
+ elif f.has_src_builder():
+ # The SConscript file apparently exists in a source
+ # code management system. Build it, but then clear
+ # the builder so that it doesn't get built *again*
+ # during the actual build phase.
+ f.build()
+ f.built()
+ f.builder_set(None)
+ if f.exists():
+ _file_ = open(f.get_abspath(), "r")
+ if _file_:
+ # Chdir to the SConscript directory. Use a path
+ # name relative to the SConstruct file so that if
+ # we're using the -f option, we're essentially
+ # creating a parallel SConscript directory structure
+ # in our local directory tree.
+ #
+ # XXX This is broken for multiple-repository cases
+ # where the SConstruct and SConscript files might be
+ # in different Repositories. For now, cross that
+ # bridge when someone comes to it.
+ try:
+ src_dir = kw['src_dir']
+ except KeyError:
+ ldir = fs.Dir(f.dir.get_path(sd))
+ else:
+ ldir = fs.Dir(src_dir)
+ if not ldir.is_under(f.dir):
+ # They specified a source directory, but
+ # it's above the SConscript directory.
+ # Do the sensible thing and just use the
+ # SConcript directory.
+ ldir = fs.Dir(f.dir.get_path(sd))
+ try:
+ fs.chdir(ldir, change_os_dir=sconscript_chdir)
+ except OSError:
+ # There was no local directory, so we should be
+ # able to chdir to the Repository directory.
+ # Note that we do this directly, not through
+ # fs.chdir(), because we still need to
+ # interpret the stuff within the SConscript file
+ # relative to where we are logically.
+ fs.chdir(ldir, change_os_dir=0)
+ os.chdir(actual.dir.get_abspath())
+
+ # Append the SConscript directory to the beginning
+ # of sys.path so Python modules in the SConscript
+ # directory can be easily imported.
+ sys.path = [ f.dir.get_abspath() ] + sys.path
+
+ # This is the magic line that actually reads up
+ # and executes the stuff in the SConscript file.
+ # The locals for this frame contain the special
+ # bottom-of-the-stack marker so that any
+ # exceptions that occur when processing this
+ # SConscript can base the printed frames at this
+ # level and not show SCons internals as well.
+ call_stack[-1].globals.update({stack_bottom:1})
+ old_file = call_stack[-1].globals.get('__file__')
+ try:
+ del call_stack[-1].globals['__file__']
+ except KeyError:
+ pass
+ try:
+ try:
+ exec _file_ in call_stack[-1].globals
+ except SConscriptReturn:
+ pass
+ finally:
+ if old_file is not None:
+ call_stack[-1].globals.update({__file__:old_file})
+ else:
+ SCons.Warnings.warn(SCons.Warnings.MissingSConscriptWarning,
+ "Ignoring missing SConscript '%s'" % f.path)
+
+ finally:
+ SCons.Script.sconscript_reading = SCons.Script.sconscript_reading - 1
+ sys.path = old_sys_path
+ frame = call_stack.pop()
+ try:
+ fs.chdir(frame.prev_dir, change_os_dir=sconscript_chdir)
+ except OSError:
+ # There was no local directory, so chdir to the
+ # Repository directory. Like above, we do this
+ # directly.
+ fs.chdir(frame.prev_dir, change_os_dir=0)
+ rdir = frame.prev_dir.rdir()
+ rdir._create() # Make sure there's a directory there.
+ try:
+ os.chdir(rdir.get_abspath())
+ except OSError, e:
+ # We still couldn't chdir there, so raise the error,
+ # but only if actions are being executed.
+ #
+ # If the -n option was used, the directory would *not*
+ # have been created and we should just carry on and
+ # let things muddle through. This isn't guaranteed
+ # to work if the SConscript files are reading things
+ # from disk (for example), but it should work well
+ # enough for most configurations.
+ if SCons.Action.execute_actions:
+ raise e
+
+ results.append(frame.retval)
+
+ # if we only have one script, don't return a tuple
+ if len(results) == 1:
+ return results[0]
+ else:
+ return tuple(results)
+
+def SConscript_exception(file=sys.stderr):
+ """Print an exception stack trace just for the SConscript file(s).
+ This will show users who have Python errors where the problem is,
+ without cluttering the output with all of the internal calls leading
+ up to where we exec the SConscript."""
+ exc_type, exc_value, exc_tb = sys.exc_info()
+ tb = exc_tb
+ while tb and stack_bottom not in tb.tb_frame.f_locals:
+ tb = tb.tb_next
+ if not tb:
+ # We did not find our exec statement, so this was actually a bug
+ # in SCons itself. Show the whole stack.
+ tb = exc_tb
+ stack = traceback.extract_tb(tb)
+ try:
+ type = exc_type.__name__
+ except AttributeError:
+ type = str(exc_type)
+ if type[:11] == "exceptions.":
+ type = type[11:]
+ file.write('%s: %s:\n' % (type, exc_value))
+ for fname, line, func, text in stack:
+ file.write(' File "%s", line %d:\n' % (fname, line))
+ file.write(' %s\n' % text)
+
+def annotate(node):
+ """Annotate a node with the stack frame describing the
+ SConscript file and line number that created it."""
+ tb = sys.exc_info()[2]
+ while tb and stack_bottom not in tb.tb_frame.f_locals:
+ tb = tb.tb_next
+ if not tb:
+ # We did not find any exec of an SConscript file: what?!
+ raise SCons.Errors.InternalError("could not find SConscript stack frame")
+ node.creator = traceback.extract_stack(tb)[0]
+
+# The following line would cause each Node to be annotated using the
+# above function. Unfortunately, this is a *huge* performance hit, so
+# leave this disabled until we find a more efficient mechanism.
+#SCons.Node.Annotate = annotate
+
+class SConsEnvironment(SCons.Environment.Base):
+ """An Environment subclass that contains all of the methods that
+ are particular to the wrapper SCons interface and which aren't
+ (or shouldn't be) part of the build engine itself.
+
+ Note that not all of the methods of this class have corresponding
+ global functions, there are some private methods.
+ """
+
+ #
+ # Private methods of an SConsEnvironment.
+ #
+ def _exceeds_version(self, major, minor, v_major, v_minor):
+ """Return 1 if 'major' and 'minor' are greater than the version
+ in 'v_major' and 'v_minor', and 0 otherwise."""
+ return (major > v_major or (major == v_major and minor > v_minor))
+
+ def _get_major_minor_revision(self, version_string):
+ """Split a version string into major, minor and (optionally)
+ revision parts.
+
+ This is complicated by the fact that a version string can be
+ something like 3.2b1."""
+ version = version_string.split(' ')[0].split('.')
+ v_major = int(version[0])
+ v_minor = int(re.match('\d+', version[1]).group())
+ if len(version) >= 3:
+ v_revision = int(re.match('\d+', version[2]).group())
+ else:
+ v_revision = 0
+ return v_major, v_minor, v_revision
+
+ def _get_SConscript_filenames(self, ls, kw):
+ """
+ Convert the parameters passed to SConscript() calls into a list
+ of files and export variables. If the parameters are invalid,
+ throws SCons.Errors.UserError. Returns a tuple (l, e) where l
+ is a list of SConscript filenames and e is a list of exports.
+ """
+ exports = []
+
+ if len(ls) == 0:
+ try:
+ dirs = kw["dirs"]
+ except KeyError:
+ raise SCons.Errors.UserError("Invalid SConscript usage - no parameters")
+
+ if not SCons.Util.is_List(dirs):
+ dirs = [ dirs ]
+ dirs = list(map(str, dirs))
+
+ name = kw.get('name', 'SConscript')
+
+ files = [os.path.join(n, name) for n in dirs]
+
+ elif len(ls) == 1:
+
+ files = ls[0]
+
+ elif len(ls) == 2:
+
+ files = ls[0]
+ exports = self.Split(ls[1])
+
+ else:
+
+ raise SCons.Errors.UserError("Invalid SConscript() usage - too many arguments")
+
+ if not SCons.Util.is_List(files):
+ files = [ files ]
+
+ if kw.get('exports'):
+ exports.extend(self.Split(kw['exports']))
+
+ variant_dir = kw.get('variant_dir') or kw.get('build_dir')
+ if variant_dir:
+ if len(files) != 1:
+ raise SCons.Errors.UserError("Invalid SConscript() usage - can only specify one SConscript with a variant_dir")
+ duplicate = kw.get('duplicate', 1)
+ src_dir = kw.get('src_dir')
+ if not src_dir:
+ src_dir, fname = os.path.split(str(files[0]))
+ files = [os.path.join(str(variant_dir), fname)]
+ else:
+ if not isinstance(src_dir, SCons.Node.Node):
+ src_dir = self.fs.Dir(src_dir)
+ fn = files[0]
+ if not isinstance(fn, SCons.Node.Node):
+ fn = self.fs.File(fn)
+ if fn.is_under(src_dir):
+ # Get path relative to the source directory.
+ fname = fn.get_path(src_dir)
+ files = [os.path.join(str(variant_dir), fname)]
+ else:
+ files = [fn.abspath]
+ kw['src_dir'] = variant_dir
+ self.fs.VariantDir(variant_dir, src_dir, duplicate)
+
+ return (files, exports)
+
+ #
+ # Public methods of an SConsEnvironment. These get
+ # entry points in the global name space so they can be called
+ # as global functions.
+ #
+
+ def Configure(self, *args, **kw):
+ if not SCons.Script.sconscript_reading:
+ raise SCons.Errors.UserError("Calling Configure from Builders is not supported.")
+ kw['_depth'] = kw.get('_depth', 0) + 1
+ return SCons.Environment.Base.Configure(self, *args, **kw)
+
+ def Default(self, *targets):
+ SCons.Script._Set_Default_Targets(self, targets)
+
+ def EnsureSConsVersion(self, major, minor, revision=0):
+ """Exit abnormally if the SCons version is not late enough."""
+ scons_ver = self._get_major_minor_revision(SCons.__version__)
+ if scons_ver < (major, minor, revision):
+ if revision:
+ scons_ver_string = '%d.%d.%d' % (major, minor, revision)
+ else:
+ scons_ver_string = '%d.%d' % (major, minor)
+ print "SCons %s or greater required, but you have SCons %s" % \
+ (scons_ver_string, SCons.__version__)
+ sys.exit(2)
+
+ def EnsurePythonVersion(self, major, minor):
+ """Exit abnormally if the Python version is not late enough."""
+ try:
+ v_major, v_minor, v_micro, release, serial = sys.version_info
+ python_ver = (v_major, v_minor)
+ except AttributeError:
+ python_ver = self._get_major_minor_revision(sys.version)[:2]
+ if python_ver < (major, minor):
+ v = sys.version.split(" ", 1)[0]
+ print "Python %d.%d or greater required, but you have Python %s" %(major,minor,v)
+ sys.exit(2)
+
+ def Exit(self, value=0):
+ sys.exit(value)
+
+ def Export(self, *vars, **kw):
+ for var in vars:
+ global_exports.update(compute_exports(self.Split(var)))
+ global_exports.update(kw)
+
+ def GetLaunchDir(self):
+ global launch_dir
+ return launch_dir
+
+ def GetOption(self, name):
+ name = self.subst(name)
+ return SCons.Script.Main.GetOption(name)
+
+ def Help(self, text):
+ text = self.subst(text, raw=1)
+ SCons.Script.HelpFunction(text)
+
+ def Import(self, *vars):
+ try:
+ frame = call_stack[-1]
+ globals = frame.globals
+ exports = frame.exports
+ for var in vars:
+ var = self.Split(var)
+ for v in var:
+ if v == '*':
+ globals.update(global_exports)
+ globals.update(exports)
+ else:
+ if v in exports:
+ globals[v] = exports[v]
+ else:
+ globals[v] = global_exports[v]
+ except KeyError,x:
+ raise SCons.Errors.UserError("Import of non-existent variable '%s'"%x)
+
+ def SConscript(self, *ls, **kw):
+ if 'build_dir' in kw:
+ msg = """The build_dir keyword has been deprecated; use the variant_dir keyword instead."""
+ SCons.Warnings.warn(SCons.Warnings.DeprecatedBuildDirWarning, msg)
+ def subst_element(x, subst=self.subst):
+ if SCons.Util.is_List(x):
+ x = list(map(subst, x))
+ else:
+ x = subst(x)
+ return x
+ ls = list(map(subst_element, ls))
+ subst_kw = {}
+ for key, val in kw.items():
+ if SCons.Util.is_String(val):
+ val = self.subst(val)
+ elif SCons.Util.is_List(val):
+ result = []
+ for v in val:
+ if SCons.Util.is_String(v):
+ v = self.subst(v)
+ result.append(v)
+ val = result
+ subst_kw[key] = val
+
+ files, exports = self._get_SConscript_filenames(ls, subst_kw)
+ subst_kw['exports'] = exports
+ return _SConscript(self.fs, *files, **subst_kw)
+
+ def SConscriptChdir(self, flag):
+ global sconscript_chdir
+ sconscript_chdir = flag
+
+ def SetOption(self, name, value):
+ name = self.subst(name)
+ SCons.Script.Main.SetOption(name, value)
+
+#
+#
+#
+SCons.Environment.Environment = SConsEnvironment
+
+def Configure(*args, **kw):
+ if not SCons.Script.sconscript_reading:
+ raise SCons.Errors.UserError("Calling Configure from Builders is not supported.")
+ kw['_depth'] = 1
+ return SCons.SConf.SConf(*args, **kw)
+
+# It's very important that the DefaultEnvironmentCall() class stay in this
+# file, with the get_calling_namespaces() function, the compute_exports()
+# function, the Frame class and the SConsEnvironment.Export() method.
+# These things make up the calling stack leading up to the actual global
+# Export() or SConscript() call that the user issued. We want to allow
+# users to export local variables that they define, like so:
+#
+# def func():
+# x = 1
+# Export('x')
+#
+# To support this, the get_calling_namespaces() function assumes that
+# the *first* stack frame that's not from this file is the local frame
+# for the Export() or SConscript() call.
+
+_DefaultEnvironmentProxy = None
+
+def get_DefaultEnvironmentProxy():
+ global _DefaultEnvironmentProxy
+ if not _DefaultEnvironmentProxy:
+ default_env = SCons.Defaults.DefaultEnvironment()
+ _DefaultEnvironmentProxy = SCons.Environment.NoSubstitutionProxy(default_env)
+ return _DefaultEnvironmentProxy
+
+class DefaultEnvironmentCall(object):
+ """A class that implements "global function" calls of
+ Environment methods by fetching the specified method from the
+ DefaultEnvironment's class. Note that this uses an intermediate
+ proxy class instead of calling the DefaultEnvironment method
+ directly so that the proxy can override the subst() method and
+ thereby prevent expansion of construction variables (since from
+ the user's point of view this was called as a global function,
+ with no associated construction environment)."""
+ def __init__(self, method_name, subst=0):
+ self.method_name = method_name
+ if subst:
+ self.factory = SCons.Defaults.DefaultEnvironment
+ else:
+ self.factory = get_DefaultEnvironmentProxy
+ def __call__(self, *args, **kw):
+ env = self.factory()
+ method = getattr(env, self.method_name)
+ return method(*args, **kw)
+
+
+def BuildDefaultGlobals():
+ """
+ Create a dictionary containing all the default globals for
+ SConstruct and SConscript files.
+ """
+
+ global GlobalDict
+ if GlobalDict is None:
+ GlobalDict = {}
+
+ import SCons.Script
+ d = SCons.Script.__dict__
+ def not_a_module(m, d=d, mtype=type(SCons.Script)):
+ return not isinstance(d[m], mtype)
+ for m in filter(not_a_module, dir(SCons.Script)):
+ GlobalDict[m] = d[m]
+
+ return GlobalDict.copy()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Script/__init__.py b/couchjs/scons/scons-local-2.0.1/SCons/Script/__init__.py
new file mode 100644
index 00000000..b4545ecb
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Script/__init__.py
@@ -0,0 +1,412 @@
+"""SCons.Script
+
+This file implements the main() function used by the scons script.
+
+Architecturally, this *is* the scons script, and will likely only be
+called from the external "scons" wrapper. Consequently, anything here
+should not be, or be considered, part of the build engine. If it's
+something that we expect other software to want to use, it should go in
+some other module. If it's specific to the "scons" script invocation,
+it goes here.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Script/__init__.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import time
+start_time = time.time()
+
+import collections
+import os
+import sys
+
+# Special chicken-and-egg handling of the "--debug=memoizer" flag:
+#
+# SCons.Memoize contains a metaclass implementation that affects how
+# the other classes are instantiated. The Memoizer may add shim methods
+# to classes that have methods that cache computed values in order to
+# count and report the hits and misses.
+#
+# If we wait to enable the Memoization until after we've parsed the
+# command line options normally, it will be too late, because the Memoizer
+# will have already analyzed the classes that it's Memoizing and decided
+# to not add the shims. So we use a special-case, up-front check for
+# the "--debug=memoizer" flag and enable Memoizer before we import any
+# of the other modules that use it.
+
+_args = sys.argv + os.environ.get('SCONSFLAGS', '').split()
+if "--debug=memoizer" in _args:
+ import SCons.Memoize
+ import SCons.Warnings
+ try:
+ SCons.Memoize.EnableMemoization()
+ except SCons.Warnings.Warning:
+ # Some warning was thrown. Arrange for it to be displayed
+ # or not after warnings are configured.
+ import Main
+ exc_type, exc_value, tb = sys.exc_info()
+ Main.delayed_warnings.append((exc_type, exc_value))
+del _args
+
+import SCons.Action
+import SCons.Builder
+import SCons.Environment
+import SCons.Node.FS
+import SCons.Options
+import SCons.Platform
+import SCons.Scanner
+import SCons.SConf
+import SCons.Subst
+import SCons.Tool
+import SCons.Util
+import SCons.Variables
+import SCons.Defaults
+
+import Main
+
+main = Main.main
+
+# The following are global class definitions and variables that used to
+# live directly in this module back before 0.96.90, when it contained
+# a lot of code. Some SConscript files in widely-distributed packages
+# (Blender is the specific example) actually reached into SCons.Script
+# directly to use some of these. Rather than break those SConscript
+# files, we're going to propagate these names into the SCons.Script
+# namespace here.
+#
+# Some of these are commented out because it's *really* unlikely anyone
+# used them, but we're going to leave the comment here to try to make
+# it obvious what to do if the situation arises.
+BuildTask = Main.BuildTask
+CleanTask = Main.CleanTask
+QuestionTask = Main.QuestionTask
+#PrintHelp = Main.PrintHelp
+#SConscriptSettableOptions = Main.SConscriptSettableOptions
+
+AddOption = Main.AddOption
+GetOption = Main.GetOption
+SetOption = Main.SetOption
+Progress = Main.Progress
+GetBuildFailures = Main.GetBuildFailures
+
+#keep_going_on_error = Main.keep_going_on_error
+#print_dtree = Main.print_dtree
+#print_explanations = Main.print_explanations
+#print_includes = Main.print_includes
+#print_objects = Main.print_objects
+#print_time = Main.print_time
+#print_tree = Main.print_tree
+#memory_stats = Main.memory_stats
+#ignore_errors = Main.ignore_errors
+#sconscript_time = Main.sconscript_time
+#command_time = Main.command_time
+#exit_status = Main.exit_status
+#profiling = Main.profiling
+#repositories = Main.repositories
+
+#
+import SConscript
+_SConscript = SConscript
+
+call_stack = _SConscript.call_stack
+
+#
+Action = SCons.Action.Action
+AddMethod = SCons.Util.AddMethod
+AllowSubstExceptions = SCons.Subst.SetAllowableExceptions
+Builder = SCons.Builder.Builder
+Configure = _SConscript.Configure
+Environment = SCons.Environment.Environment
+#OptParser = SCons.SConsOptions.OptParser
+FindPathDirs = SCons.Scanner.FindPathDirs
+Platform = SCons.Platform.Platform
+Return = _SConscript.Return
+Scanner = SCons.Scanner.Base
+Tool = SCons.Tool.Tool
+WhereIs = SCons.Util.WhereIs
+
+#
+BoolVariable = SCons.Variables.BoolVariable
+EnumVariable = SCons.Variables.EnumVariable
+ListVariable = SCons.Variables.ListVariable
+PackageVariable = SCons.Variables.PackageVariable
+PathVariable = SCons.Variables.PathVariable
+
+# Deprecated names that will go away some day.
+BoolOption = SCons.Options.BoolOption
+EnumOption = SCons.Options.EnumOption
+ListOption = SCons.Options.ListOption
+PackageOption = SCons.Options.PackageOption
+PathOption = SCons.Options.PathOption
+
+# Action factories.
+Chmod = SCons.Defaults.Chmod
+Copy = SCons.Defaults.Copy
+Delete = SCons.Defaults.Delete
+Mkdir = SCons.Defaults.Mkdir
+Move = SCons.Defaults.Move
+Touch = SCons.Defaults.Touch
+
+# Pre-made, public scanners.
+CScanner = SCons.Tool.CScanner
+DScanner = SCons.Tool.DScanner
+DirScanner = SCons.Defaults.DirScanner
+ProgramScanner = SCons.Tool.ProgramScanner
+SourceFileScanner = SCons.Tool.SourceFileScanner
+
+# Functions we might still convert to Environment methods.
+CScan = SCons.Defaults.CScan
+DefaultEnvironment = SCons.Defaults.DefaultEnvironment
+
+# Other variables we provide.
+class TargetList(collections.UserList):
+ def _do_nothing(self, *args, **kw):
+ pass
+ def _add_Default(self, list):
+ self.extend(list)
+ def _clear(self):
+ del self[:]
+
+ARGUMENTS = {}
+ARGLIST = []
+BUILD_TARGETS = TargetList()
+COMMAND_LINE_TARGETS = []
+DEFAULT_TARGETS = []
+
+# BUILD_TARGETS can be modified in the SConscript files. If so, we
+# want to treat the modified BUILD_TARGETS list as if they specified
+# targets on the command line. To do that, though, we need to know if
+# BUILD_TARGETS was modified through "official" APIs or by hand. We do
+# this by updating two lists in parallel, the documented BUILD_TARGETS
+# list, above, and this internal _build_plus_default targets list which
+# should only have "official" API changes. Then Script/Main.py can
+# compare these two afterwards to figure out if the user added their
+# own targets to BUILD_TARGETS.
+_build_plus_default = TargetList()
+
+def _Add_Arguments(alist):
+ for arg in alist:
+ a, b = arg.split('=', 1)
+ ARGUMENTS[a] = b
+ ARGLIST.append((a, b))
+
+def _Add_Targets(tlist):
+ if tlist:
+ COMMAND_LINE_TARGETS.extend(tlist)
+ BUILD_TARGETS.extend(tlist)
+ BUILD_TARGETS._add_Default = BUILD_TARGETS._do_nothing
+ BUILD_TARGETS._clear = BUILD_TARGETS._do_nothing
+ _build_plus_default.extend(tlist)
+ _build_plus_default._add_Default = _build_plus_default._do_nothing
+ _build_plus_default._clear = _build_plus_default._do_nothing
+
+def _Set_Default_Targets_Has_Been_Called(d, fs):
+ return DEFAULT_TARGETS
+
+def _Set_Default_Targets_Has_Not_Been_Called(d, fs):
+ if d is None:
+ d = [fs.Dir('.')]
+ return d
+
+_Get_Default_Targets = _Set_Default_Targets_Has_Not_Been_Called
+
+def _Set_Default_Targets(env, tlist):
+ global DEFAULT_TARGETS
+ global _Get_Default_Targets
+ _Get_Default_Targets = _Set_Default_Targets_Has_Been_Called
+ for t in tlist:
+ if t is None:
+ # Delete the elements from the list in-place, don't
+ # reassign an empty list to DEFAULT_TARGETS, so that the
+ # variables will still point to the same object we point to.
+ del DEFAULT_TARGETS[:]
+ BUILD_TARGETS._clear()
+ _build_plus_default._clear()
+ elif isinstance(t, SCons.Node.Node):
+ DEFAULT_TARGETS.append(t)
+ BUILD_TARGETS._add_Default([t])
+ _build_plus_default._add_Default([t])
+ else:
+ nodes = env.arg2nodes(t, env.fs.Entry)
+ DEFAULT_TARGETS.extend(nodes)
+ BUILD_TARGETS._add_Default(nodes)
+ _build_plus_default._add_Default(nodes)
+
+#
+help_text = None
+
+def HelpFunction(text):
+ global help_text
+ if SCons.Script.help_text is None:
+ SCons.Script.help_text = text
+ else:
+ help_text = help_text + text
+
+#
+# Will be non-zero if we are reading an SConscript file.
+sconscript_reading = 0
+
+#
+def Variables(files=[], args=ARGUMENTS):
+ return SCons.Variables.Variables(files, args)
+
+def Options(files=[], args=ARGUMENTS):
+ return SCons.Options.Options(files, args)
+
+# The list of global functions to add to the SConscript name space
+# that end up calling corresponding methods or Builders in the
+# DefaultEnvironment().
+GlobalDefaultEnvironmentFunctions = [
+ # Methods from the SConsEnvironment class, above.
+ 'Default',
+ 'EnsurePythonVersion',
+ 'EnsureSConsVersion',
+ 'Exit',
+ 'Export',
+ 'GetLaunchDir',
+ 'Help',
+ 'Import',
+ #'SConscript', is handled separately, below.
+ 'SConscriptChdir',
+
+ # Methods from the Environment.Base class.
+ 'AddPostAction',
+ 'AddPreAction',
+ 'Alias',
+ 'AlwaysBuild',
+ 'BuildDir',
+ 'CacheDir',
+ 'Clean',
+ #The Command() method is handled separately, below.
+ 'Decider',
+ 'Depends',
+ 'Dir',
+ 'NoClean',
+ 'NoCache',
+ 'Entry',
+ 'Execute',
+ 'File',
+ 'FindFile',
+ 'FindInstalledFiles',
+ 'FindSourceFiles',
+ 'Flatten',
+ 'GetBuildPath',
+ 'Glob',
+ 'Ignore',
+ 'Install',
+ 'InstallAs',
+ 'Literal',
+ 'Local',
+ 'ParseDepends',
+ 'Precious',
+ 'Repository',
+ 'Requires',
+ 'SConsignFile',
+ 'SideEffect',
+ 'SourceCode',
+ 'SourceSignatures',
+ 'Split',
+ 'Tag',
+ 'TargetSignatures',
+ 'Value',
+ 'VariantDir',
+]
+
+GlobalDefaultBuilders = [
+ # Supported builders.
+ 'CFile',
+ 'CXXFile',
+ 'DVI',
+ 'Jar',
+ 'Java',
+ 'JavaH',
+ 'Library',
+ 'M4',
+ 'MSVSProject',
+ 'Object',
+ 'PCH',
+ 'PDF',
+ 'PostScript',
+ 'Program',
+ 'RES',
+ 'RMIC',
+ 'SharedLibrary',
+ 'SharedObject',
+ 'StaticLibrary',
+ 'StaticObject',
+ 'Tar',
+ 'TypeLibrary',
+ 'Zip',
+ 'Package',
+]
+
+for name in GlobalDefaultEnvironmentFunctions + GlobalDefaultBuilders:
+ exec "%s = _SConscript.DefaultEnvironmentCall(%s)" % (name, repr(name))
+del name
+
+# There are a handful of variables that used to live in the
+# Script/SConscript.py module that some SConscript files out there were
+# accessing directly as SCons.Script.SConscript.*. The problem is that
+# "SConscript" in this namespace is no longer a module, it's a global
+# function call--or more precisely, an object that implements a global
+# function call through the default Environment. Nevertheless, we can
+# maintain backwards compatibility for SConscripts that were reaching in
+# this way by hanging some attributes off the "SConscript" object here.
+SConscript = _SConscript.DefaultEnvironmentCall('SConscript')
+
+# Make SConscript look enough like the module it used to be so
+# that pychecker doesn't barf.
+SConscript.__name__ = 'SConscript'
+
+SConscript.Arguments = ARGUMENTS
+SConscript.ArgList = ARGLIST
+SConscript.BuildTargets = BUILD_TARGETS
+SConscript.CommandLineTargets = COMMAND_LINE_TARGETS
+SConscript.DefaultTargets = DEFAULT_TARGETS
+
+# The global Command() function must be handled differently than the
+# global functions for other construction environment methods because
+# we want people to be able to use Actions that must expand $TARGET
+# and $SOURCE later, when (and if) the Action is invoked to build
+# the target(s). We do this with the subst=1 argument, which creates
+# a DefaultEnvironmentCall instance that wraps up a normal default
+# construction environment that performs variable substitution, not a
+# proxy that doesn't.
+#
+# There's a flaw here, though, because any other $-variables on a command
+# line will *also* be expanded, each to a null string, but that should
+# only be a problem in the unusual case where someone was passing a '$'
+# on a command line and *expected* the $ to get through to the shell
+# because they were calling Command() and not env.Command()... This is
+# unlikely enough that we're going to leave this as is and cross that
+# bridge if someone actually comes to it.
+Command = _SConscript.DefaultEnvironmentCall('Command', subst=1)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Sig.py b/couchjs/scons/scons-local-2.0.1/SCons/Sig.py
new file mode 100644
index 00000000..2a9bc8ea
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Sig.py
@@ -0,0 +1,63 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Sig.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__doc__ = """Place-holder for the old SCons.Sig module hierarchy
+
+This is no longer used, but code out there (such as the NSIS module on
+the SCons wiki) may try to import SCons.Sig. If so, we generate a warning
+that points them to the line that caused the import, and don't die.
+
+If someone actually tried to use the sub-modules or functions within
+the package (for example, SCons.Sig.MD5.signature()), then they'll still
+get an AttributeError, but at least they'll know where to start looking.
+"""
+
+import SCons.Util
+import SCons.Warnings
+
+msg = 'The SCons.Sig module no longer exists.\n' \
+ ' Remove the following "import SCons.Sig" line to eliminate this warning:'
+
+SCons.Warnings.warn(SCons.Warnings.DeprecatedSigModuleWarning, msg)
+
+default_calc = None
+default_module = None
+
+class MD5Null(SCons.Util.Null):
+ def __repr__(self):
+ return "MD5Null()"
+
+class TimeStampNull(SCons.Util.Null):
+ def __repr__(self):
+ return "TimeStampNull()"
+
+MD5 = MD5Null()
+TimeStamp = TimeStampNull()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Subst.py b/couchjs/scons/scons-local-2.0.1/SCons/Subst.py
new file mode 100644
index 00000000..84e71503
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Subst.py
@@ -0,0 +1,904 @@
+"""SCons.Subst
+
+SCons string substitution.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Subst.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import collections
+import re
+
+import SCons.Errors
+
+from SCons.Util import is_String, is_Sequence
+
+# Indexed by the SUBST_* constants below.
+_strconv = [SCons.Util.to_String_for_subst,
+ SCons.Util.to_String_for_subst,
+ SCons.Util.to_String_for_signature]
+
+
+
+AllowableExceptions = (IndexError, NameError)
+
+def SetAllowableExceptions(*excepts):
+ global AllowableExceptions
+ AllowableExceptions = [_f for _f in excepts if _f]
+
+def raise_exception(exception, target, s):
+ name = exception.__class__.__name__
+ msg = "%s `%s' trying to evaluate `%s'" % (name, exception, s)
+ if target:
+ raise SCons.Errors.BuildError(target[0], msg)
+ else:
+ raise SCons.Errors.UserError(msg)
+
+
+
+class Literal(object):
+ """A wrapper for a string. If you use this object wrapped
+ around a string, then it will be interpreted as literal.
+ When passed to the command interpreter, all special
+ characters will be escaped."""
+ def __init__(self, lstr):
+ self.lstr = lstr
+
+ def __str__(self):
+ return self.lstr
+
+ def escape(self, escape_func):
+ return escape_func(self.lstr)
+
+ def for_signature(self):
+ return self.lstr
+
+ def is_literal(self):
+ return 1
+
+class SpecialAttrWrapper(object):
+ """This is a wrapper for what we call a 'Node special attribute.'
+ This is any of the attributes of a Node that we can reference from
+ Environment variable substitution, such as $TARGET.abspath or
+ $SOURCES[1].filebase. We implement the same methods as Literal
+ so we can handle special characters, plus a for_signature method,
+ such that we can return some canonical string during signature
+ calculation to avoid unnecessary rebuilds."""
+
+ def __init__(self, lstr, for_signature=None):
+ """The for_signature parameter, if supplied, will be the
+ canonical string we return from for_signature(). Else
+ we will simply return lstr."""
+ self.lstr = lstr
+ if for_signature:
+ self.forsig = for_signature
+ else:
+ self.forsig = lstr
+
+ def __str__(self):
+ return self.lstr
+
+ def escape(self, escape_func):
+ return escape_func(self.lstr)
+
+ def for_signature(self):
+ return self.forsig
+
+ def is_literal(self):
+ return 1
+
+def quote_spaces(arg):
+ """Generic function for putting double quotes around any string that
+ has white space in it."""
+ if ' ' in arg or '\t' in arg:
+ return '"%s"' % arg
+ else:
+ return str(arg)
+
+class CmdStringHolder(collections.UserString):
+ """This is a special class used to hold strings generated by
+ scons_subst() and scons_subst_list(). It defines a special method
+ escape(). When passed a function with an escape algorithm for a
+ particular platform, it will return the contained string with the
+ proper escape sequences inserted.
+ """
+ def __init__(self, cmd, literal=None):
+ collections.UserString.__init__(self, cmd)
+ self.literal = literal
+
+ def is_literal(self):
+ return self.literal
+
+ def escape(self, escape_func, quote_func=quote_spaces):
+ """Escape the string with the supplied function. The
+ function is expected to take an arbitrary string, then
+ return it with all special characters escaped and ready
+ for passing to the command interpreter.
+
+ After calling this function, the next call to str() will
+ return the escaped string.
+ """
+
+ if self.is_literal():
+ return escape_func(self.data)
+ elif ' ' in self.data or '\t' in self.data:
+ return quote_func(self.data)
+ else:
+ return self.data
+
+def escape_list(mylist, escape_func):
+ """Escape a list of arguments by running the specified escape_func
+ on every object in the list that has an escape() method."""
+ def escape(obj, escape_func=escape_func):
+ try:
+ e = obj.escape
+ except AttributeError:
+ return obj
+ else:
+ return e(escape_func)
+ return list(map(escape, mylist))
+
+class NLWrapper(object):
+ """A wrapper class that delays turning a list of sources or targets
+ into a NodeList until it's needed. The specified function supplied
+ when the object is initialized is responsible for turning raw nodes
+ into proxies that implement the special attributes like .abspath,
+ .source, etc. This way, we avoid creating those proxies just
+ "in case" someone is going to use $TARGET or the like, and only
+ go through the trouble if we really have to.
+
+ In practice, this might be a wash performance-wise, but it's a little
+ cleaner conceptually...
+ """
+
+ def __init__(self, list, func):
+ self.list = list
+ self.func = func
+ def _return_nodelist(self):
+ return self.nodelist
+ def _gen_nodelist(self):
+ mylist = self.list
+ if mylist is None:
+ mylist = []
+ elif not is_Sequence(mylist):
+ mylist = [mylist]
+ # The map(self.func) call is what actually turns
+ # a list into appropriate proxies.
+ self.nodelist = SCons.Util.NodeList(list(map(self.func, mylist)))
+ self._create_nodelist = self._return_nodelist
+ return self.nodelist
+ _create_nodelist = _gen_nodelist
+
+
+class Targets_or_Sources(collections.UserList):
+ """A class that implements $TARGETS or $SOURCES expansions by in turn
+ wrapping a NLWrapper. This class handles the different methods used
+ to access the list, calling the NLWrapper to create proxies on demand.
+
+ Note that we subclass collections.UserList purely so that the
+ is_Sequence() function will identify an object of this class as
+ a list during variable expansion. We're not really using any
+ collections.UserList methods in practice.
+ """
+ def __init__(self, nl):
+ self.nl = nl
+ def __getattr__(self, attr):
+ nl = self.nl._create_nodelist()
+ return getattr(nl, attr)
+ def __getitem__(self, i):
+ nl = self.nl._create_nodelist()
+ return nl[i]
+ def __getslice__(self, i, j):
+ nl = self.nl._create_nodelist()
+ i = max(i, 0); j = max(j, 0)
+ return nl[i:j]
+ def __str__(self):
+ nl = self.nl._create_nodelist()
+ return str(nl)
+ def __repr__(self):
+ nl = self.nl._create_nodelist()
+ return repr(nl)
+
+class Target_or_Source(object):
+ """A class that implements $TARGET or $SOURCE expansions by in turn
+ wrapping a NLWrapper. This class handles the different methods used
+ to access an individual proxy Node, calling the NLWrapper to create
+ a proxy on demand.
+ """
+ def __init__(self, nl):
+ self.nl = nl
+ def __getattr__(self, attr):
+ nl = self.nl._create_nodelist()
+ try:
+ nl0 = nl[0]
+ except IndexError:
+ # If there is nothing in the list, then we have no attributes to
+ # pass through, so raise AttributeError for everything.
+ raise AttributeError("NodeList has no attribute: %s" % attr)
+ return getattr(nl0, attr)
+ def __str__(self):
+ nl = self.nl._create_nodelist()
+ if nl:
+ return str(nl[0])
+ return ''
+ def __repr__(self):
+ nl = self.nl._create_nodelist()
+ if nl:
+ return repr(nl[0])
+ return ''
+
+class NullNodeList(SCons.Util.NullSeq):
+ def __call__(self, *args, **kwargs): return ''
+ def __str__(self): return ''
+
+NullNodesList = NullNodeList()
+
+def subst_dict(target, source):
+ """Create a dictionary for substitution of special
+ construction variables.
+
+ This translates the following special arguments:
+
+ target - the target (object or array of objects),
+ used to generate the TARGET and TARGETS
+ construction variables
+
+ source - the source (object or array of objects),
+ used to generate the SOURCES and SOURCE
+ construction variables
+ """
+ dict = {}
+
+ if target:
+ def get_tgt_subst_proxy(thing):
+ try:
+ subst_proxy = thing.get_subst_proxy()
+ except AttributeError:
+ subst_proxy = thing # probably a string, just return it
+ return subst_proxy
+ tnl = NLWrapper(target, get_tgt_subst_proxy)
+ dict['TARGETS'] = Targets_or_Sources(tnl)
+ dict['TARGET'] = Target_or_Source(tnl)
+
+ # This is a total cheat, but hopefully this dictionary goes
+ # away soon anyway. We just let these expand to $TARGETS
+ # because that's "good enough" for the use of ToolSurrogates
+ # (see test/ToolSurrogate.py) to generate documentation.
+ dict['CHANGED_TARGETS'] = '$TARGETS'
+ dict['UNCHANGED_TARGETS'] = '$TARGETS'
+ else:
+ dict['TARGETS'] = NullNodesList
+ dict['TARGET'] = NullNodesList
+
+ if source:
+ def get_src_subst_proxy(node):
+ try:
+ rfile = node.rfile
+ except AttributeError:
+ pass
+ else:
+ node = rfile()
+ try:
+ return node.get_subst_proxy()
+ except AttributeError:
+ return node # probably a String, just return it
+ snl = NLWrapper(source, get_src_subst_proxy)
+ dict['SOURCES'] = Targets_or_Sources(snl)
+ dict['SOURCE'] = Target_or_Source(snl)
+
+ # This is a total cheat, but hopefully this dictionary goes
+ # away soon anyway. We just let these expand to $TARGETS
+ # because that's "good enough" for the use of ToolSurrogates
+ # (see test/ToolSurrogate.py) to generate documentation.
+ dict['CHANGED_SOURCES'] = '$SOURCES'
+ dict['UNCHANGED_SOURCES'] = '$SOURCES'
+ else:
+ dict['SOURCES'] = NullNodesList
+ dict['SOURCE'] = NullNodesList
+
+ return dict
+
+# Constants for the "mode" parameter to scons_subst_list() and
+# scons_subst(). SUBST_RAW gives the raw command line. SUBST_CMD
+# gives a command line suitable for passing to a shell. SUBST_SIG
+# gives a command line appropriate for calculating the signature
+# of a command line...if this changes, we should rebuild.
+SUBST_CMD = 0
+SUBST_RAW = 1
+SUBST_SIG = 2
+
+_rm = re.compile(r'\$[()]')
+_remove = re.compile(r'\$\([^\$]*(\$[^\)][^\$]*)*\$\)')
+
+# Indexed by the SUBST_* constants above.
+_regex_remove = [ _rm, None, _remove ]
+
+def _rm_list(list):
+ #return [ l for l in list if not l in ('$(', '$)') ]
+ return [l for l in list if not l in ('$(', '$)')]
+
+def _remove_list(list):
+ result = []
+ do_append = result.append
+ for l in list:
+ if l == '$(':
+ do_append = lambda x: None
+ elif l == '$)':
+ do_append = result.append
+ else:
+ do_append(l)
+ return result
+
+# Indexed by the SUBST_* constants above.
+_list_remove = [ _rm_list, None, _remove_list ]
+
+# Regular expressions for splitting strings and handling substitutions,
+# for use by the scons_subst() and scons_subst_list() functions:
+#
+# The first expression compiled matches all of the $-introduced tokens
+# that we need to process in some way, and is used for substitutions.
+# The expressions it matches are:
+#
+# "$$"
+# "$("
+# "$)"
+# "$variable" [must begin with alphabetic or underscore]
+# "${any stuff}"
+#
+# The second expression compiled is used for splitting strings into tokens
+# to be processed, and it matches all of the tokens listed above, plus
+# the following that affect how arguments do or don't get joined together:
+#
+# " " [white space]
+# "non-white-space" [without any dollar signs]
+# "$" [single dollar sign]
+#
+_dollar_exps_str = r'\$[\$\(\)]|\$[_a-zA-Z][\.\w]*|\${[^}]*}'
+_dollar_exps = re.compile(r'(%s)' % _dollar_exps_str)
+_separate_args = re.compile(r'(%s|\s+|[^\s\$]+|\$)' % _dollar_exps_str)
+
+# This regular expression is used to replace strings of multiple white
+# space characters in the string result from the scons_subst() function.
+_space_sep = re.compile(r'[\t ]+(?![^{]*})')
+
+def scons_subst(strSubst, env, mode=SUBST_RAW, target=None, source=None, gvars={}, lvars={}, conv=None):
+ """Expand a string or list containing construction variable
+ substitutions.
+
+ This is the work-horse function for substitutions in file names
+ and the like. The companion scons_subst_list() function (below)
+ handles separating command lines into lists of arguments, so see
+ that function if that's what you're looking for.
+ """
+ if isinstance(strSubst, str) and strSubst.find('$') < 0:
+ return strSubst
+
+ class StringSubber(object):
+ """A class to construct the results of a scons_subst() call.
+
+ This binds a specific construction environment, mode, target and
+ source with two methods (substitute() and expand()) that handle
+ the expansion.
+ """
+ def __init__(self, env, mode, conv, gvars):
+ self.env = env
+ self.mode = mode
+ self.conv = conv
+ self.gvars = gvars
+
+ def expand(self, s, lvars):
+ """Expand a single "token" as necessary, returning an
+ appropriate string containing the expansion.
+
+ This handles expanding different types of things (strings,
+ lists, callables) appropriately. It calls the wrapper
+ substitute() method to re-expand things as necessary, so that
+ the results of expansions of side-by-side strings still get
+ re-evaluated separately, not smushed together.
+ """
+ if is_String(s):
+ try:
+ s0, s1 = s[:2]
+ except (IndexError, ValueError):
+ return s
+ if s0 != '$':
+ return s
+ if s1 == '$':
+ return '$'
+ elif s1 in '()':
+ return s
+ else:
+ key = s[1:]
+ if key[0] == '{' or key.find('.') >= 0:
+ if key[0] == '{':
+ key = key[1:-1]
+ try:
+ s = eval(key, self.gvars, lvars)
+ except KeyboardInterrupt:
+ raise
+ except Exception, e:
+ if e.__class__ in AllowableExceptions:
+ return ''
+ raise_exception(e, lvars['TARGETS'], s)
+ else:
+ if key in lvars:
+ s = lvars[key]
+ elif key in self.gvars:
+ s = self.gvars[key]
+ elif not NameError in AllowableExceptions:
+ raise_exception(NameError(key), lvars['TARGETS'], s)
+ else:
+ return ''
+
+ # Before re-expanding the result, handle
+ # recursive expansion by copying the local
+ # variable dictionary and overwriting a null
+ # string for the value of the variable name
+ # we just expanded.
+ #
+ # This could potentially be optimized by only
+ # copying lvars when s contains more expansions,
+ # but lvars is usually supposed to be pretty
+ # small, and deeply nested variable expansions
+ # are probably more the exception than the norm,
+ # so it should be tolerable for now.
+ lv = lvars.copy()
+ var = key.split('.')[0]
+ lv[var] = ''
+ return self.substitute(s, lv)
+ elif is_Sequence(s):
+ def func(l, conv=self.conv, substitute=self.substitute, lvars=lvars):
+ return conv(substitute(l, lvars))
+ return list(map(func, s))
+ elif callable(s):
+ try:
+ s = s(target=lvars['TARGETS'],
+ source=lvars['SOURCES'],
+ env=self.env,
+ for_signature=(self.mode != SUBST_CMD))
+ except TypeError:
+ # This probably indicates that it's a callable
+ # object that doesn't match our calling arguments
+ # (like an Action).
+ if self.mode == SUBST_RAW:
+ return s
+ s = self.conv(s)
+ return self.substitute(s, lvars)
+ elif s is None:
+ return ''
+ else:
+ return s
+
+ def substitute(self, args, lvars):
+ """Substitute expansions in an argument or list of arguments.
+
+ This serves as a wrapper for splitting up a string into
+ separate tokens.
+ """
+ if is_String(args) and not isinstance(args, CmdStringHolder):
+ args = str(args) # In case it's a UserString.
+ try:
+ def sub_match(match):
+ return self.conv(self.expand(match.group(1), lvars))
+ result = _dollar_exps.sub(sub_match, args)
+ except TypeError:
+ # If the internal conversion routine doesn't return
+ # strings (it could be overridden to return Nodes, for
+ # example), then the 1.5.2 re module will throw this
+ # exception. Back off to a slower, general-purpose
+ # algorithm that works for all data types.
+ args = _separate_args.findall(args)
+ result = []
+ for a in args:
+ result.append(self.conv(self.expand(a, lvars)))
+ if len(result) == 1:
+ result = result[0]
+ else:
+ result = ''.join(map(str, result))
+ return result
+ else:
+ return self.expand(args, lvars)
+
+ if conv is None:
+ conv = _strconv[mode]
+
+ # Doing this every time is a bit of a waste, since the Executor
+ # has typically already populated the OverrideEnvironment with
+ # $TARGET/$SOURCE variables. We're keeping this (for now), though,
+ # because it supports existing behavior that allows us to call
+ # an Action directly with an arbitrary target+source pair, which
+ # we use in Tool/tex.py to handle calling $BIBTEX when necessary.
+ # If we dropped that behavior (or found another way to cover it),
+ # we could get rid of this call completely and just rely on the
+ # Executor setting the variables.
+ if 'TARGET' not in lvars:
+ d = subst_dict(target, source)
+ if d:
+ lvars = lvars.copy()
+ lvars.update(d)
+
+ # We're (most likely) going to eval() things. If Python doesn't
+ # find a __builtins__ value in the global dictionary used for eval(),
+ # it copies the current global values for you. Avoid this by
+ # setting it explicitly and then deleting, so we don't pollute the
+ # construction environment Dictionary(ies) that are typically used
+ # for expansion.
+ gvars['__builtins__'] = __builtins__
+
+ ss = StringSubber(env, mode, conv, gvars)
+ result = ss.substitute(strSubst, lvars)
+
+ try:
+ del gvars['__builtins__']
+ except KeyError:
+ pass
+
+ if is_String(result):
+ # Remove $(-$) pairs and any stuff in between,
+ # if that's appropriate.
+ remove = _regex_remove[mode]
+ if remove:
+ result = remove.sub('', result)
+ if mode != SUBST_RAW:
+ # Compress strings of white space characters into
+ # a single space.
+ result = _space_sep.sub(' ', result).strip()
+ elif is_Sequence(result):
+ remove = _list_remove[mode]
+ if remove:
+ result = remove(result)
+
+ return result
+
+#Subst_List_Strings = {}
+
+def scons_subst_list(strSubst, env, mode=SUBST_RAW, target=None, source=None, gvars={}, lvars={}, conv=None):
+ """Substitute construction variables in a string (or list or other
+ object) and separate the arguments into a command list.
+
+ The companion scons_subst() function (above) handles basic
+ substitutions within strings, so see that function instead
+ if that's what you're looking for.
+ """
+# try:
+# Subst_List_Strings[strSubst] = Subst_List_Strings[strSubst] + 1
+# except KeyError:
+# Subst_List_Strings[strSubst] = 1
+# import SCons.Debug
+# SCons.Debug.caller_trace(1)
+ class ListSubber(collections.UserList):
+ """A class to construct the results of a scons_subst_list() call.
+
+ Like StringSubber, this class binds a specific construction
+ environment, mode, target and source with two methods
+ (substitute() and expand()) that handle the expansion.
+
+ In addition, however, this class is used to track the state of
+ the result(s) we're gathering so we can do the appropriate thing
+ whenever we have to append another word to the result--start a new
+ line, start a new word, append to the current word, etc. We do
+ this by setting the "append" attribute to the right method so
+ that our wrapper methods only need ever call ListSubber.append(),
+ and the rest of the object takes care of doing the right thing
+ internally.
+ """
+ def __init__(self, env, mode, conv, gvars):
+ collections.UserList.__init__(self, [])
+ self.env = env
+ self.mode = mode
+ self.conv = conv
+ self.gvars = gvars
+
+ if self.mode == SUBST_RAW:
+ self.add_strip = lambda x: self.append(x)
+ else:
+ self.add_strip = lambda x: None
+ self.in_strip = None
+ self.next_line()
+
+ def expand(self, s, lvars, within_list):
+ """Expand a single "token" as necessary, appending the
+ expansion to the current result.
+
+ This handles expanding different types of things (strings,
+ lists, callables) appropriately. It calls the wrapper
+ substitute() method to re-expand things as necessary, so that
+ the results of expansions of side-by-side strings still get
+ re-evaluated separately, not smushed together.
+ """
+
+ if is_String(s):
+ try:
+ s0, s1 = s[:2]
+ except (IndexError, ValueError):
+ self.append(s)
+ return
+ if s0 != '$':
+ self.append(s)
+ return
+ if s1 == '$':
+ self.append('$')
+ elif s1 == '(':
+ self.open_strip('$(')
+ elif s1 == ')':
+ self.close_strip('$)')
+ else:
+ key = s[1:]
+ if key[0] == '{' or key.find('.') >= 0:
+ if key[0] == '{':
+ key = key[1:-1]
+ try:
+ s = eval(key, self.gvars, lvars)
+ except KeyboardInterrupt:
+ raise
+ except Exception, e:
+ if e.__class__ in AllowableExceptions:
+ return
+ raise_exception(e, lvars['TARGETS'], s)
+ else:
+ if key in lvars:
+ s = lvars[key]
+ elif key in self.gvars:
+ s = self.gvars[key]
+ elif not NameError in AllowableExceptions:
+ raise_exception(NameError(), lvars['TARGETS'], s)
+ else:
+ return
+
+ # Before re-expanding the result, handle
+ # recursive expansion by copying the local
+ # variable dictionary and overwriting a null
+ # string for the value of the variable name
+ # we just expanded.
+ lv = lvars.copy()
+ var = key.split('.')[0]
+ lv[var] = ''
+ self.substitute(s, lv, 0)
+ self.this_word()
+ elif is_Sequence(s):
+ for a in s:
+ self.substitute(a, lvars, 1)
+ self.next_word()
+ elif callable(s):
+ try:
+ s = s(target=lvars['TARGETS'],
+ source=lvars['SOURCES'],
+ env=self.env,
+ for_signature=(self.mode != SUBST_CMD))
+ except TypeError:
+ # This probably indicates that it's a callable
+ # object that doesn't match our calling arguments
+ # (like an Action).
+ if self.mode == SUBST_RAW:
+ self.append(s)
+ return
+ s = self.conv(s)
+ self.substitute(s, lvars, within_list)
+ elif s is None:
+ self.this_word()
+ else:
+ self.append(s)
+
+ def substitute(self, args, lvars, within_list):
+ """Substitute expansions in an argument or list of arguments.
+
+ This serves as a wrapper for splitting up a string into
+ separate tokens.
+ """
+
+ if is_String(args) and not isinstance(args, CmdStringHolder):
+ args = str(args) # In case it's a UserString.
+ args = _separate_args.findall(args)
+ for a in args:
+ if a[0] in ' \t\n\r\f\v':
+ if '\n' in a:
+ self.next_line()
+ elif within_list:
+ self.append(a)
+ else:
+ self.next_word()
+ else:
+ self.expand(a, lvars, within_list)
+ else:
+ self.expand(args, lvars, within_list)
+
+ def next_line(self):
+ """Arrange for the next word to start a new line. This
+ is like starting a new word, except that we have to append
+ another line to the result."""
+ collections.UserList.append(self, [])
+ self.next_word()
+
+ def this_word(self):
+ """Arrange for the next word to append to the end of the
+ current last word in the result."""
+ self.append = self.add_to_current_word
+
+ def next_word(self):
+ """Arrange for the next word to start a new word."""
+ self.append = self.add_new_word
+
+ def add_to_current_word(self, x):
+ """Append the string x to the end of the current last word
+ in the result. If that is not possible, then just add
+ it as a new word. Make sure the entire concatenated string
+ inherits the object attributes of x (in particular, the
+ escape function) by wrapping it as CmdStringHolder."""
+
+ if not self.in_strip or self.mode != SUBST_SIG:
+ try:
+ current_word = self[-1][-1]
+ except IndexError:
+ self.add_new_word(x)
+ else:
+ # All right, this is a hack and it should probably
+ # be refactored out of existence in the future.
+ # The issue is that we want to smoosh words together
+ # and make one file name that gets escaped if
+ # we're expanding something like foo$EXTENSION,
+ # but we don't want to smoosh them together if
+ # it's something like >$TARGET, because then we'll
+ # treat the '>' like it's part of the file name.
+ # So for now, just hard-code looking for the special
+ # command-line redirection characters...
+ try:
+ last_char = str(current_word)[-1]
+ except IndexError:
+ last_char = '\0'
+ if last_char in '<>|':
+ self.add_new_word(x)
+ else:
+ y = current_word + x
+
+ # We used to treat a word appended to a literal
+ # as a literal itself, but this caused problems
+ # with interpreting quotes around space-separated
+ # targets on command lines. Removing this makes
+ # none of the "substantive" end-to-end tests fail,
+ # so we'll take this out but leave it commented
+ # for now in case there's a problem not covered
+ # by the test cases and we need to resurrect this.
+ #literal1 = self.literal(self[-1][-1])
+ #literal2 = self.literal(x)
+ y = self.conv(y)
+ if is_String(y):
+ #y = CmdStringHolder(y, literal1 or literal2)
+ y = CmdStringHolder(y, None)
+ self[-1][-1] = y
+
+ def add_new_word(self, x):
+ if not self.in_strip or self.mode != SUBST_SIG:
+ literal = self.literal(x)
+ x = self.conv(x)
+ if is_String(x):
+ x = CmdStringHolder(x, literal)
+ self[-1].append(x)
+ self.append = self.add_to_current_word
+
+ def literal(self, x):
+ try:
+ l = x.is_literal
+ except AttributeError:
+ return None
+ else:
+ return l()
+
+ def open_strip(self, x):
+ """Handle the "open strip" $( token."""
+ self.add_strip(x)
+ self.in_strip = 1
+
+ def close_strip(self, x):
+ """Handle the "close strip" $) token."""
+ self.add_strip(x)
+ self.in_strip = None
+
+ if conv is None:
+ conv = _strconv[mode]
+
+ # Doing this every time is a bit of a waste, since the Executor
+ # has typically already populated the OverrideEnvironment with
+ # $TARGET/$SOURCE variables. We're keeping this (for now), though,
+ # because it supports existing behavior that allows us to call
+ # an Action directly with an arbitrary target+source pair, which
+ # we use in Tool/tex.py to handle calling $BIBTEX when necessary.
+ # If we dropped that behavior (or found another way to cover it),
+ # we could get rid of this call completely and just rely on the
+ # Executor setting the variables.
+ if 'TARGET' not in lvars:
+ d = subst_dict(target, source)
+ if d:
+ lvars = lvars.copy()
+ lvars.update(d)
+
+ # We're (most likely) going to eval() things. If Python doesn't
+ # find a __builtins__ value in the global dictionary used for eval(),
+ # it copies the current global values for you. Avoid this by
+ # setting it explicitly and then deleting, so we don't pollute the
+ # construction environment Dictionary(ies) that are typically used
+ # for expansion.
+ gvars['__builtins__'] = __builtins__
+
+ ls = ListSubber(env, mode, conv, gvars)
+ ls.substitute(strSubst, lvars, 0)
+
+ try:
+ del gvars['__builtins__']
+ except KeyError:
+ pass
+
+ return ls.data
+
+def scons_subst_once(strSubst, env, key):
+ """Perform single (non-recursive) substitution of a single
+ construction variable keyword.
+
+ This is used when setting a variable when copying or overriding values
+ in an Environment. We want to capture (expand) the old value before
+ we override it, so people can do things like:
+
+ env2 = env.Clone(CCFLAGS = '$CCFLAGS -g')
+
+ We do this with some straightforward, brute-force code here...
+ """
+ if isinstance(strSubst, str) and strSubst.find('$') < 0:
+ return strSubst
+
+ matchlist = ['$' + key, '${' + key + '}']
+ val = env.get(key, '')
+ def sub_match(match, val=val, matchlist=matchlist):
+ a = match.group(1)
+ if a in matchlist:
+ a = val
+ if is_Sequence(a):
+ return ' '.join(map(str, a))
+ else:
+ return str(a)
+
+ if is_Sequence(strSubst):
+ result = []
+ for arg in strSubst:
+ if is_String(arg):
+ if arg in matchlist:
+ arg = val
+ if is_Sequence(arg):
+ result.extend(arg)
+ else:
+ result.append(arg)
+ else:
+ result.append(_dollar_exps.sub(sub_match, arg))
+ else:
+ result.append(arg)
+ return result
+ elif is_String(strSubst):
+ return _dollar_exps.sub(sub_match, strSubst)
+ else:
+ return strSubst
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Taskmaster.py b/couchjs/scons/scons-local-2.0.1/SCons/Taskmaster.py
new file mode 100644
index 00000000..019b2d74
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Taskmaster.py
@@ -0,0 +1,1017 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__doc__ = """
+Generic Taskmaster module for the SCons build engine.
+
+This module contains the primary interface(s) between a wrapping user
+interface and the SCons build engine. There are two key classes here:
+
+ Taskmaster
+ This is the main engine for walking the dependency graph and
+ calling things to decide what does or doesn't need to be built.
+
+ Task
+ This is the base class for allowing a wrapping interface to
+ decide what does or doesn't actually need to be done. The
+ intention is for a wrapping interface to subclass this as
+ appropriate for different types of behavior it may need.
+
+ The canonical example is the SCons native Python interface,
+ which has Task subclasses that handle its specific behavior,
+ like printing "`foo' is up to date" when a top-level target
+ doesn't need to be built, and handling the -c option by removing
+ targets as its "build" action. There is also a separate subclass
+ for suppressing this output when the -q option is used.
+
+ The Taskmaster instantiates a Task object for each (set of)
+ target(s) that it decides need to be evaluated and/or built.
+"""
+
+__revision__ = "src/engine/SCons/Taskmaster.py 5134 2010/08/16 23:02:40 bdeegan"
+
+from itertools import chain
+import operator
+import sys
+import traceback
+
+import SCons.Errors
+import SCons.Node
+import SCons.Warnings
+
+StateString = SCons.Node.StateString
+NODE_NO_STATE = SCons.Node.no_state
+NODE_PENDING = SCons.Node.pending
+NODE_EXECUTING = SCons.Node.executing
+NODE_UP_TO_DATE = SCons.Node.up_to_date
+NODE_EXECUTED = SCons.Node.executed
+NODE_FAILED = SCons.Node.failed
+
+
+# A subsystem for recording stats about how different Nodes are handled by
+# the main Taskmaster loop. There's no external control here (no need for
+# a --debug= option); enable it by changing the value of CollectStats.
+
+CollectStats = None
+
+class Stats(object):
+ """
+ A simple class for holding statistics about the disposition of a
+ Node by the Taskmaster. If we're collecting statistics, each Node
+ processed by the Taskmaster gets one of these attached, in which case
+ the Taskmaster records its decision each time it processes the Node.
+ (Ideally, that's just once per Node.)
+ """
+ def __init__(self):
+ """
+ Instantiates a Taskmaster.Stats object, initializing all
+ appropriate counters to zero.
+ """
+ self.considered = 0
+ self.already_handled = 0
+ self.problem = 0
+ self.child_failed = 0
+ self.not_built = 0
+ self.side_effects = 0
+ self.build = 0
+
+StatsNodes = []
+
+fmt = "%(considered)3d "\
+ "%(already_handled)3d " \
+ "%(problem)3d " \
+ "%(child_failed)3d " \
+ "%(not_built)3d " \
+ "%(side_effects)3d " \
+ "%(build)3d "
+
+def dump_stats():
+ for n in sorted(StatsNodes, key=lambda a: str(a)):
+ print (fmt % n.stats.__dict__) + str(n)
+
+
+
+class Task(object):
+ """
+ Default SCons build engine task.
+
+ This controls the interaction of the actual building of node
+ and the rest of the engine.
+
+ This is expected to handle all of the normally-customizable
+ aspects of controlling a build, so any given application
+ *should* be able to do what it wants by sub-classing this
+ class and overriding methods as appropriate. If an application
+ needs to customze something by sub-classing Taskmaster (or
+ some other build engine class), we should first try to migrate
+ that functionality into this class.
+
+ Note that it's generally a good idea for sub-classes to call
+ these methods explicitly to update state, etc., rather than
+ roll their own interaction with Taskmaster from scratch.
+ """
+ def __init__(self, tm, targets, top, node):
+ self.tm = tm
+ self.targets = targets
+ self.top = top
+ self.node = node
+ self.exc_clear()
+
+ def trace_message(self, method, node, description='node'):
+ fmt = '%-20s %s %s\n'
+ return fmt % (method + ':', description, self.tm.trace_node(node))
+
+ def display(self, message):
+ """
+ Hook to allow the calling interface to display a message.
+
+ This hook gets called as part of preparing a task for execution
+ (that is, a Node to be built). As part of figuring out what Node
+ should be built next, the actually target list may be altered,
+ along with a message describing the alteration. The calling
+ interface can subclass Task and provide a concrete implementation
+ of this method to see those messages.
+ """
+ pass
+
+ def prepare(self):
+ """
+ Called just before the task is executed.
+
+ This is mainly intended to give the target Nodes a chance to
+ unlink underlying files and make all necessary directories before
+ the Action is actually called to build the targets.
+ """
+ T = self.tm.trace
+ if T: T.write(self.trace_message(u'Task.prepare()', self.node))
+
+ # Now that it's the appropriate time, give the TaskMaster a
+ # chance to raise any exceptions it encountered while preparing
+ # this task.
+ self.exception_raise()
+
+ if self.tm.message:
+ self.display(self.tm.message)
+ self.tm.message = None
+
+ # Let the targets take care of any necessary preparations.
+ # This includes verifying that all of the necessary sources
+ # and dependencies exist, removing the target file(s), etc.
+ #
+ # As of April 2008, the get_executor().prepare() method makes
+ # sure that all of the aggregate sources necessary to build this
+ # Task's target(s) exist in one up-front check. The individual
+ # target t.prepare() methods check that each target's explicit
+ # or implicit dependencies exists, and also initialize the
+ # .sconsign info.
+ executor = self.targets[0].get_executor()
+ executor.prepare()
+ for t in executor.get_action_targets():
+ t.prepare()
+ for s in t.side_effects:
+ s.prepare()
+
+ def get_target(self):
+ """Fetch the target being built or updated by this task.
+ """
+ return self.node
+
+ def needs_execute(self):
+ # TODO(deprecate): "return True" is the old default behavior;
+ # change it to NotImplementedError (after running through the
+ # Deprecation Cycle) so the desired behavior is explicitly
+ # determined by which concrete subclass is used.
+ #raise NotImplementedError
+ msg = ('Taskmaster.Task is an abstract base class; instead of\n'
+ '\tusing it directly, '
+ 'derive from it and override the abstract methods.')
+ SCons.Warnings.warn(SCons.Warnings.TaskmasterNeedsExecuteWarning, msg)
+ return True
+
+ def execute(self):
+ """
+ Called to execute the task.
+
+ This method is called from multiple threads in a parallel build,
+ so only do thread safe stuff here. Do thread unsafe stuff in
+ prepare(), executed() or failed().
+ """
+ T = self.tm.trace
+ if T: T.write(self.trace_message(u'Task.execute()', self.node))
+
+ try:
+ everything_was_cached = 1
+ for t in self.targets:
+ if t.retrieve_from_cache():
+ # Call the .built() method without calling the
+ # .push_to_cache() method, since we just got the
+ # target from the cache and don't need to push
+ # it back there.
+ t.set_state(NODE_EXECUTED)
+ t.built()
+ else:
+ everything_was_cached = 0
+ break
+ if not everything_was_cached:
+ self.targets[0].build()
+ except SystemExit:
+ exc_value = sys.exc_info()[1]
+ raise SCons.Errors.ExplicitExit(self.targets[0], exc_value.code)
+ except SCons.Errors.UserError:
+ raise
+ except SCons.Errors.BuildError:
+ raise
+ except Exception, e:
+ buildError = SCons.Errors.convert_to_BuildError(e)
+ buildError.node = self.targets[0]
+ buildError.exc_info = sys.exc_info()
+ raise buildError
+
+ def executed_without_callbacks(self):
+ """
+ Called when the task has been successfully executed
+ and the Taskmaster instance doesn't want to call
+ the Node's callback methods.
+ """
+ T = self.tm.trace
+ if T: T.write(self.trace_message('Task.executed_without_callbacks()',
+ self.node))
+
+ for t in self.targets:
+ if t.get_state() == NODE_EXECUTING:
+ for side_effect in t.side_effects:
+ side_effect.set_state(NODE_NO_STATE)
+ t.set_state(NODE_EXECUTED)
+
+ def executed_with_callbacks(self):
+ """
+ Called when the task has been successfully executed and
+ the Taskmaster instance wants to call the Node's callback
+ methods.
+
+ This may have been a do-nothing operation (to preserve build
+ order), so we must check the node's state before deciding whether
+ it was "built", in which case we call the appropriate Node method.
+ In any event, we always call "visited()", which will handle any
+ post-visit actions that must take place regardless of whether
+ or not the target was an actual built target or a source Node.
+ """
+ T = self.tm.trace
+ if T: T.write(self.trace_message('Task.executed_with_callbacks()',
+ self.node))
+
+ for t in self.targets:
+ if t.get_state() == NODE_EXECUTING:
+ for side_effect in t.side_effects:
+ side_effect.set_state(NODE_NO_STATE)
+ t.set_state(NODE_EXECUTED)
+ t.push_to_cache()
+ t.built()
+ t.visited()
+
+ executed = executed_with_callbacks
+
+ def failed(self):
+ """
+ Default action when a task fails: stop the build.
+
+ Note: Although this function is normally invoked on nodes in
+ the executing state, it might also be invoked on up-to-date
+ nodes when using Configure().
+ """
+ self.fail_stop()
+
+ def fail_stop(self):
+ """
+ Explicit stop-the-build failure.
+
+ This sets failure status on the target nodes and all of
+ their dependent parent nodes.
+
+ Note: Although this function is normally invoked on nodes in
+ the executing state, it might also be invoked on up-to-date
+ nodes when using Configure().
+ """
+ T = self.tm.trace
+ if T: T.write(self.trace_message('Task.failed_stop()', self.node))
+
+ # Invoke will_not_build() to clean-up the pending children
+ # list.
+ self.tm.will_not_build(self.targets, lambda n: n.set_state(NODE_FAILED))
+
+ # Tell the taskmaster to not start any new tasks
+ self.tm.stop()
+
+ # We're stopping because of a build failure, but give the
+ # calling Task class a chance to postprocess() the top-level
+ # target under which the build failure occurred.
+ self.targets = [self.tm.current_top]
+ self.top = 1
+
+ def fail_continue(self):
+ """
+ Explicit continue-the-build failure.
+
+ This sets failure status on the target nodes and all of
+ their dependent parent nodes.
+
+ Note: Although this function is normally invoked on nodes in
+ the executing state, it might also be invoked on up-to-date
+ nodes when using Configure().
+ """
+ T = self.tm.trace
+ if T: T.write(self.trace_message('Task.failed_continue()', self.node))
+
+ self.tm.will_not_build(self.targets, lambda n: n.set_state(NODE_FAILED))
+
+ def make_ready_all(self):
+ """
+ Marks all targets in a task ready for execution.
+
+ This is used when the interface needs every target Node to be
+ visited--the canonical example being the "scons -c" option.
+ """
+ T = self.tm.trace
+ if T: T.write(self.trace_message('Task.make_ready_all()', self.node))
+
+ self.out_of_date = self.targets[:]
+ for t in self.targets:
+ t.disambiguate().set_state(NODE_EXECUTING)
+ for s in t.side_effects:
+ # add disambiguate here to mirror the call on targets above
+ s.disambiguate().set_state(NODE_EXECUTING)
+
+ def make_ready_current(self):
+ """
+ Marks all targets in a task ready for execution if any target
+ is not current.
+
+ This is the default behavior for building only what's necessary.
+ """
+ T = self.tm.trace
+ if T: T.write(self.trace_message(u'Task.make_ready_current()',
+ self.node))
+
+ self.out_of_date = []
+ needs_executing = False
+ for t in self.targets:
+ try:
+ t.disambiguate().make_ready()
+ is_up_to_date = not t.has_builder() or \
+ (not t.always_build and t.is_up_to_date())
+ except EnvironmentError, e:
+ raise SCons.Errors.BuildError(node=t, errstr=e.strerror, filename=e.filename)
+
+ if not is_up_to_date:
+ self.out_of_date.append(t)
+ needs_executing = True
+
+ if needs_executing:
+ for t in self.targets:
+ t.set_state(NODE_EXECUTING)
+ for s in t.side_effects:
+ # add disambiguate here to mirror the call on targets in first loop above
+ s.disambiguate().set_state(NODE_EXECUTING)
+ else:
+ for t in self.targets:
+ # We must invoke visited() to ensure that the node
+ # information has been computed before allowing the
+ # parent nodes to execute. (That could occur in a
+ # parallel build...)
+ t.visited()
+ t.set_state(NODE_UP_TO_DATE)
+
+ make_ready = make_ready_current
+
+ def postprocess(self):
+ """
+ Post-processes a task after it's been executed.
+
+ This examines all the targets just built (or not, we don't care
+ if the build was successful, or even if there was no build
+ because everything was up-to-date) to see if they have any
+ waiting parent Nodes, or Nodes waiting on a common side effect,
+ that can be put back on the candidates list.
+ """
+ T = self.tm.trace
+ if T: T.write(self.trace_message(u'Task.postprocess()', self.node))
+
+ # We may have built multiple targets, some of which may have
+ # common parents waiting for this build. Count up how many
+ # targets each parent was waiting for so we can subtract the
+ # values later, and so we *don't* put waiting side-effect Nodes
+ # back on the candidates list if the Node is also a waiting
+ # parent.
+
+ targets = set(self.targets)
+
+ pending_children = self.tm.pending_children
+ parents = {}
+ for t in targets:
+ # A node can only be in the pending_children set if it has
+ # some waiting_parents.
+ if t.waiting_parents:
+ if T: T.write(self.trace_message(u'Task.postprocess()',
+ t,
+ 'removing'))
+ pending_children.discard(t)
+ for p in t.waiting_parents:
+ parents[p] = parents.get(p, 0) + 1
+
+ for t in targets:
+ for s in t.side_effects:
+ if s.get_state() == NODE_EXECUTING:
+ s.set_state(NODE_NO_STATE)
+ for p in s.waiting_parents:
+ parents[p] = parents.get(p, 0) + 1
+ for p in s.waiting_s_e:
+ if p.ref_count == 0:
+ self.tm.candidates.append(p)
+
+ for p, subtract in parents.items():
+ p.ref_count = p.ref_count - subtract
+ if T: T.write(self.trace_message(u'Task.postprocess()',
+ p,
+ 'adjusted parent ref count'))
+ if p.ref_count == 0:
+ self.tm.candidates.append(p)
+
+ for t in targets:
+ t.postprocess()
+
+ # Exception handling subsystem.
+ #
+ # Exceptions that occur while walking the DAG or examining Nodes
+ # must be raised, but must be raised at an appropriate time and in
+ # a controlled manner so we can, if necessary, recover gracefully,
+ # possibly write out signature information for Nodes we've updated,
+ # etc. This is done by having the Taskmaster tell us about the
+ # exception, and letting
+
+ def exc_info(self):
+ """
+ Returns info about a recorded exception.
+ """
+ return self.exception
+
+ def exc_clear(self):
+ """
+ Clears any recorded exception.
+
+ This also changes the "exception_raise" attribute to point
+ to the appropriate do-nothing method.
+ """
+ self.exception = (None, None, None)
+ self.exception_raise = self._no_exception_to_raise
+
+ def exception_set(self, exception=None):
+ """
+ Records an exception to be raised at the appropriate time.
+
+ This also changes the "exception_raise" attribute to point
+ to the method that will, in fact
+ """
+ if not exception:
+ exception = sys.exc_info()
+ self.exception = exception
+ self.exception_raise = self._exception_raise
+
+ def _no_exception_to_raise(self):
+ pass
+
+ def _exception_raise(self):
+ """
+ Raises a pending exception that was recorded while getting a
+ Task ready for execution.
+ """
+ exc = self.exc_info()[:]
+ try:
+ exc_type, exc_value, exc_traceback = exc
+ except ValueError:
+ exc_type, exc_value = exc
+ exc_traceback = None
+ raise exc_type, exc_value, exc_traceback
+
+class AlwaysTask(Task):
+ def needs_execute(self):
+ """
+ Always returns True (indicating this Task should always
+ be executed).
+
+ Subclasses that need this behavior (as opposed to the default
+ of only executing Nodes that are out of date w.r.t. their
+ dependencies) can use this as follows:
+
+ class MyTaskSubclass(SCons.Taskmaster.Task):
+ needs_execute = SCons.Taskmaster.Task.execute_always
+ """
+ return True
+
+class OutOfDateTask(Task):
+ def needs_execute(self):
+ """
+ Returns True (indicating this Task should be executed) if this
+ Task's target state indicates it needs executing, which has
+ already been determined by an earlier up-to-date check.
+ """
+ return self.targets[0].get_state() == SCons.Node.executing
+
+
+def find_cycle(stack, visited):
+ if stack[-1] in visited:
+ return None
+ visited.add(stack[-1])
+ for n in stack[-1].waiting_parents:
+ stack.append(n)
+ if stack[0] == stack[-1]:
+ return stack
+ if find_cycle(stack, visited):
+ return stack
+ stack.pop()
+ return None
+
+
+class Taskmaster(object):
+ """
+ The Taskmaster for walking the dependency DAG.
+ """
+
+ def __init__(self, targets=[], tasker=None, order=None, trace=None):
+ self.original_top = targets
+ self.top_targets_left = targets[:]
+ self.top_targets_left.reverse()
+ self.candidates = []
+ if tasker is None:
+ tasker = OutOfDateTask
+ self.tasker = tasker
+ if not order:
+ order = lambda l: l
+ self.order = order
+ self.message = None
+ self.trace = trace
+ self.next_candidate = self.find_next_candidate
+ self.pending_children = set()
+
+ def find_next_candidate(self):
+ """
+ Returns the next candidate Node for (potential) evaluation.
+
+ The candidate list (really a stack) initially consists of all of
+ the top-level (command line) targets provided when the Taskmaster
+ was initialized. While we walk the DAG, visiting Nodes, all the
+ children that haven't finished processing get pushed on to the
+ candidate list. Each child can then be popped and examined in
+ turn for whether *their* children are all up-to-date, in which
+ case a Task will be created for their actual evaluation and
+ potential building.
+
+ Here is where we also allow candidate Nodes to alter the list of
+ Nodes that should be examined. This is used, for example, when
+ invoking SCons in a source directory. A source directory Node can
+ return its corresponding build directory Node, essentially saying,
+ "Hey, you really need to build this thing over here instead."
+ """
+ try:
+ return self.candidates.pop()
+ except IndexError:
+ pass
+ try:
+ node = self.top_targets_left.pop()
+ except IndexError:
+ return None
+ self.current_top = node
+ alt, message = node.alter_targets()
+ if alt:
+ self.message = message
+ self.candidates.append(node)
+ self.candidates.extend(self.order(alt))
+ node = self.candidates.pop()
+ return node
+
+ def no_next_candidate(self):
+ """
+ Stops Taskmaster processing by not returning a next candidate.
+
+ Note that we have to clean-up the Taskmaster candidate list
+ because the cycle detection depends on the fact all nodes have
+ been processed somehow.
+ """
+ while self.candidates:
+ candidates = self.candidates
+ self.candidates = []
+ self.will_not_build(candidates)
+ return None
+
+ def _validate_pending_children(self):
+ """
+ Validate the content of the pending_children set. Assert if an
+ internal error is found.
+
+ This function is used strictly for debugging the taskmaster by
+ checking that no invariants are violated. It is not used in
+ normal operation.
+
+ The pending_children set is used to detect cycles in the
+ dependency graph. We call a "pending child" a child that is
+ found in the "pending" state when checking the dependencies of
+ its parent node.
+
+ A pending child can occur when the Taskmaster completes a loop
+ through a cycle. For example, lets imagine a graph made of
+ three node (A, B and C) making a cycle. The evaluation starts
+ at node A. The taskmaster first consider whether node A's
+ child B is up-to-date. Then, recursively, node B needs to
+ check whether node C is up-to-date. This leaves us with a
+ dependency graph looking like:
+
+ Next candidate \
+ \
+ Node A (Pending) --> Node B(Pending) --> Node C (NoState)
+ ^ |
+ | |
+ +-------------------------------------+
+
+ Now, when the Taskmaster examines the Node C's child Node A,
+ it finds that Node A is in the "pending" state. Therefore,
+ Node A is a pending child of node C.
+
+ Pending children indicate that the Taskmaster has potentially
+ loop back through a cycle. We say potentially because it could
+ also occur when a DAG is evaluated in parallel. For example,
+ consider the following graph:
+
+
+ Node A (Pending) --> Node B(Pending) --> Node C (Pending) --> ...
+ | ^
+ | |
+ +----------> Node D (NoState) --------+
+ /
+ Next candidate /
+
+ The Taskmaster first evaluates the nodes A, B, and C and
+ starts building some children of node C. Assuming, that the
+ maximum parallel level has not been reached, the Taskmaster
+ will examine Node D. It will find that Node C is a pending
+ child of Node D.
+
+ In summary, evaluating a graph with a cycle will always
+ involve a pending child at one point. A pending child might
+ indicate either a cycle or a diamond-shaped DAG. Only a
+ fraction of the nodes ends-up being a "pending child" of
+ another node. This keeps the pending_children set small in
+ practice.
+
+ We can differentiate between the two cases if we wait until
+ the end of the build. At this point, all the pending children
+ nodes due to a diamond-shaped DAG will have been properly
+ built (or will have failed to build). But, the pending
+ children involved in a cycle will still be in the pending
+ state.
+
+ The taskmaster removes nodes from the pending_children set as
+ soon as a pending_children node moves out of the pending
+ state. This also helps to keep the pending_children set small.
+ """
+
+ for n in self.pending_children:
+ assert n.state in (NODE_PENDING, NODE_EXECUTING), \
+ (str(n), StateString[n.state])
+ assert len(n.waiting_parents) != 0, (str(n), len(n.waiting_parents))
+ for p in n.waiting_parents:
+ assert p.ref_count > 0, (str(n), str(p), p.ref_count)
+
+
+ def trace_message(self, message):
+ return 'Taskmaster: %s\n' % message
+
+ def trace_node(self, node):
+ return '<%-10s %-3s %s>' % (StateString[node.get_state()],
+ node.ref_count,
+ repr(str(node)))
+
+ def _find_next_ready_node(self):
+ """
+ Finds the next node that is ready to be built.
+
+ This is *the* main guts of the DAG walk. We loop through the
+ list of candidates, looking for something that has no un-built
+ children (i.e., that is a leaf Node or has dependencies that are
+ all leaf Nodes or up-to-date). Candidate Nodes are re-scanned
+ (both the target Node itself and its sources, which are always
+ scanned in the context of a given target) to discover implicit
+ dependencies. A Node that must wait for some children to be
+ built will be put back on the candidates list after the children
+ have finished building. A Node that has been put back on the
+ candidates list in this way may have itself (or its sources)
+ re-scanned, in order to handle generated header files (e.g.) and
+ the implicit dependencies therein.
+
+ Note that this method does not do any signature calculation or
+ up-to-date check itself. All of that is handled by the Task
+ class. This is purely concerned with the dependency graph walk.
+ """
+
+ self.ready_exc = None
+
+ T = self.trace
+ if T: T.write(u'\n' + self.trace_message('Looking for a node to evaluate'))
+
+ while True:
+ node = self.next_candidate()
+ if node is None:
+ if T: T.write(self.trace_message('No candidate anymore.') + u'\n')
+ return None
+
+ node = node.disambiguate()
+ state = node.get_state()
+
+ # For debugging only:
+ #
+ # try:
+ # self._validate_pending_children()
+ # except:
+ # self.ready_exc = sys.exc_info()
+ # return node
+
+ if CollectStats:
+ if not hasattr(node, 'stats'):
+ node.stats = Stats()
+ StatsNodes.append(node)
+ S = node.stats
+ S.considered = S.considered + 1
+ else:
+ S = None
+
+ if T: T.write(self.trace_message(u' Considering node %s and its children:' % self.trace_node(node)))
+
+ if state == NODE_NO_STATE:
+ # Mark this node as being on the execution stack:
+ node.set_state(NODE_PENDING)
+ elif state > NODE_PENDING:
+ # Skip this node if it has already been evaluated:
+ if S: S.already_handled = S.already_handled + 1
+ if T: T.write(self.trace_message(u' already handled (executed)'))
+ continue
+
+ executor = node.get_executor()
+
+ try:
+ children = executor.get_all_children()
+ except SystemExit:
+ exc_value = sys.exc_info()[1]
+ e = SCons.Errors.ExplicitExit(node, exc_value.code)
+ self.ready_exc = (SCons.Errors.ExplicitExit, e)
+ if T: T.write(self.trace_message(' SystemExit'))
+ return node
+ except Exception, e:
+ # We had a problem just trying to figure out the
+ # children (like a child couldn't be linked in to a
+ # VariantDir, or a Scanner threw something). Arrange to
+ # raise the exception when the Task is "executed."
+ self.ready_exc = sys.exc_info()
+ if S: S.problem = S.problem + 1
+ if T: T.write(self.trace_message(' exception %s while scanning children.\n' % e))
+ return node
+
+ children_not_visited = []
+ children_pending = set()
+ children_not_ready = []
+ children_failed = False
+
+ for child in chain(executor.get_all_prerequisites(), children):
+ childstate = child.get_state()
+
+ if T: T.write(self.trace_message(u' ' + self.trace_node(child)))
+
+ if childstate == NODE_NO_STATE:
+ children_not_visited.append(child)
+ elif childstate == NODE_PENDING:
+ children_pending.add(child)
+ elif childstate == NODE_FAILED:
+ children_failed = True
+
+ if childstate <= NODE_EXECUTING:
+ children_not_ready.append(child)
+
+
+ # These nodes have not even been visited yet. Add
+ # them to the list so that on some next pass we can
+ # take a stab at evaluating them (or their children).
+ children_not_visited.reverse()
+ self.candidates.extend(self.order(children_not_visited))
+ #if T and children_not_visited:
+ # T.write(self.trace_message(' adding to candidates: %s' % map(str, children_not_visited)))
+ # T.write(self.trace_message(' candidates now: %s\n' % map(str, self.candidates)))
+
+ # Skip this node if any of its children have failed.
+ #
+ # This catches the case where we're descending a top-level
+ # target and one of our children failed while trying to be
+ # built by a *previous* descent of an earlier top-level
+ # target.
+ #
+ # It can also occur if a node is reused in multiple
+ # targets. One first descends though the one of the
+ # target, the next time occurs through the other target.
+ #
+ # Note that we can only have failed_children if the
+ # --keep-going flag was used, because without it the build
+ # will stop before diving in the other branch.
+ #
+ # Note that even if one of the children fails, we still
+ # added the other children to the list of candidate nodes
+ # to keep on building (--keep-going).
+ if children_failed:
+ for n in executor.get_action_targets():
+ n.set_state(NODE_FAILED)
+
+ if S: S.child_failed = S.child_failed + 1
+ if T: T.write(self.trace_message('****** %s\n' % self.trace_node(node)))
+ continue
+
+ if children_not_ready:
+ for child in children_not_ready:
+ # We're waiting on one or more derived targets
+ # that have not yet finished building.
+ if S: S.not_built = S.not_built + 1
+
+ # Add this node to the waiting parents lists of
+ # anything we're waiting on, with a reference
+ # count so we can be put back on the list for
+ # re-evaluation when they've all finished.
+ node.ref_count = node.ref_count + child.add_to_waiting_parents(node)
+ if T: T.write(self.trace_message(u' adjusted ref count: %s, child %s' %
+ (self.trace_node(node), repr(str(child)))))
+
+ if T:
+ for pc in children_pending:
+ T.write(self.trace_message(' adding %s to the pending children set\n' %
+ self.trace_node(pc)))
+ self.pending_children = self.pending_children | children_pending
+
+ continue
+
+ # Skip this node if it has side-effects that are
+ # currently being built:
+ wait_side_effects = False
+ for se in executor.get_action_side_effects():
+ if se.get_state() == NODE_EXECUTING:
+ se.add_to_waiting_s_e(node)
+ wait_side_effects = True
+
+ if wait_side_effects:
+ if S: S.side_effects = S.side_effects + 1
+ continue
+
+ # The default when we've gotten through all of the checks above:
+ # this node is ready to be built.
+ if S: S.build = S.build + 1
+ if T: T.write(self.trace_message(u'Evaluating %s\n' %
+ self.trace_node(node)))
+
+ # For debugging only:
+ #
+ # try:
+ # self._validate_pending_children()
+ # except:
+ # self.ready_exc = sys.exc_info()
+ # return node
+
+ return node
+
+ return None
+
+ def next_task(self):
+ """
+ Returns the next task to be executed.
+
+ This simply asks for the next Node to be evaluated, and then wraps
+ it in the specific Task subclass with which we were initialized.
+ """
+ node = self._find_next_ready_node()
+
+ if node is None:
+ return None
+
+ tlist = node.get_executor().get_all_targets()
+
+ task = self.tasker(self, tlist, node in self.original_top, node)
+ try:
+ task.make_ready()
+ except:
+ # We had a problem just trying to get this task ready (like
+ # a child couldn't be linked in to a VariantDir when deciding
+ # whether this node is current). Arrange to raise the
+ # exception when the Task is "executed."
+ self.ready_exc = sys.exc_info()
+
+ if self.ready_exc:
+ task.exception_set(self.ready_exc)
+
+ self.ready_exc = None
+
+ return task
+
+ def will_not_build(self, nodes, node_func=lambda n: None):
+ """
+ Perform clean-up about nodes that will never be built. Invokes
+ a user defined function on all of these nodes (including all
+ of their parents).
+ """
+
+ T = self.trace
+
+ pending_children = self.pending_children
+
+ to_visit = set(nodes)
+ pending_children = pending_children - to_visit
+
+ if T:
+ for n in nodes:
+ T.write(self.trace_message(' removing node %s from the pending children set\n' %
+ self.trace_node(n)))
+ try:
+ while len(to_visit):
+ node = to_visit.pop()
+ node_func(node)
+
+ # Prune recursion by flushing the waiting children
+ # list immediately.
+ parents = node.waiting_parents
+ node.waiting_parents = set()
+
+ to_visit = to_visit | parents
+ pending_children = pending_children - parents
+
+ for p in parents:
+ p.ref_count = p.ref_count - 1
+ if T: T.write(self.trace_message(' removing parent %s from the pending children set\n' %
+ self.trace_node(p)))
+ except KeyError:
+ # The container to_visit has been emptied.
+ pass
+
+ # We have the stick back the pending_children list into the
+ # taskmaster because the python 1.5.2 compatibility does not
+ # allow us to use in-place updates
+ self.pending_children = pending_children
+
+ def stop(self):
+ """
+ Stops the current build completely.
+ """
+ self.next_candidate = self.no_next_candidate
+
+ def cleanup(self):
+ """
+ Check for dependency cycles.
+ """
+ if not self.pending_children:
+ return
+
+ nclist = [(n, find_cycle([n], set())) for n in self.pending_children]
+
+ genuine_cycles = [
+ node for node,cycle in nclist
+ if cycle or node.get_state() != NODE_EXECUTED
+ ]
+ if not genuine_cycles:
+ # All of the "cycles" found were single nodes in EXECUTED state,
+ # which is to say, they really weren't cycles. Just return.
+ return
+
+ desc = 'Found dependency cycle(s):\n'
+ for node, cycle in nclist:
+ if cycle:
+ desc = desc + " " + " -> ".join(map(str, cycle)) + "\n"
+ else:
+ desc = desc + \
+ " Internal Error: no cycle found for node %s (%s) in state %s\n" % \
+ (node, repr(node), StateString[node.get_state()])
+
+ raise SCons.Errors.UserError(desc)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/386asm.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/386asm.py
new file mode 100644
index 00000000..1ba99fa3
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/386asm.py
@@ -0,0 +1,61 @@
+"""SCons.Tool.386asm
+
+Tool specification for the 386ASM assembler for the Phar Lap ETS embedded
+operating system.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/386asm.py 5134 2010/08/16 23:02:40 bdeegan"
+
+from SCons.Tool.PharLapCommon import addPharLapPaths
+import SCons.Util
+
+as_module = __import__('as', globals(), locals(), [])
+
+def generate(env):
+ """Add Builders and construction variables for ar to an Environment."""
+ as_module.generate(env)
+
+ env['AS'] = '386asm'
+ env['ASFLAGS'] = SCons.Util.CLVar('')
+ env['ASPPFLAGS'] = '$ASFLAGS'
+ env['ASCOM'] = '$AS $ASFLAGS $SOURCES -o $TARGET'
+ env['ASPPCOM'] = '$CC $ASPPFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS $SOURCES -o $TARGET'
+
+ addPharLapPaths(env)
+
+def exists(env):
+ return env.Detect('386asm')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/BitKeeper.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/BitKeeper.py
new file mode 100644
index 00000000..8c8991a1
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/BitKeeper.py
@@ -0,0 +1,67 @@
+"""SCons.Tool.BitKeeper.py
+
+Tool-specific initialization for the BitKeeper source code control
+system.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/BitKeeper.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Action
+import SCons.Builder
+import SCons.Util
+
+def generate(env):
+ """Add a Builder factory function and construction variables for
+ BitKeeper to an Environment."""
+
+ def BitKeeperFactory(env=env):
+ """ """
+ import SCons.Warnings as W
+ W.warn(W.DeprecatedSourceCodeWarning, """The BitKeeper() factory is deprecated and there is no replacement.""")
+ act = SCons.Action.Action("$BITKEEPERCOM", "$BITKEEPERCOMSTR")
+ return SCons.Builder.Builder(action = act, env = env)
+
+ #setattr(env, 'BitKeeper', BitKeeperFactory)
+ env.BitKeeper = BitKeeperFactory
+
+ env['BITKEEPER'] = 'bk'
+ env['BITKEEPERGET'] = '$BITKEEPER get'
+ env['BITKEEPERGETFLAGS'] = SCons.Util.CLVar('')
+ env['BITKEEPERCOM'] = '$BITKEEPERGET $BITKEEPERGETFLAGS $TARGET'
+
+def exists(env):
+ return env.Detect('bk')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/CVS.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/CVS.py
new file mode 100644
index 00000000..5d511f05
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/CVS.py
@@ -0,0 +1,73 @@
+"""SCons.Tool.CVS.py
+
+Tool-specific initialization for CVS.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Tool/CVS.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Action
+import SCons.Builder
+import SCons.Util
+
+def generate(env):
+ """Add a Builder factory function and construction variables for
+ CVS to an Environment."""
+
+ def CVSFactory(repos, module='', env=env):
+ """ """
+ import SCons.Warnings as W
+ W.warn(W.DeprecatedSourceCodeWarning, """The CVS() factory is deprecated and there is no replacement.""")
+ # fail if repos is not an absolute path name?
+ if module != '':
+ # Don't use os.path.join() because the name we fetch might
+ # be across a network and must use POSIX slashes as separators.
+ module = module + '/'
+ env['CVSCOM'] = '$CVS $CVSFLAGS co $CVSCOFLAGS -d ${TARGET.dir} $CVSMODULE${TARGET.posix}'
+ act = SCons.Action.Action('$CVSCOM', '$CVSCOMSTR')
+ return SCons.Builder.Builder(action = act,
+ env = env,
+ CVSREPOSITORY = repos,
+ CVSMODULE = module)
+
+ #setattr(env, 'CVS', CVSFactory)
+ env.CVS = CVSFactory
+
+ env['CVS'] = 'cvs'
+ env['CVSFLAGS'] = SCons.Util.CLVar('-d $CVSREPOSITORY')
+ env['CVSCOFLAGS'] = SCons.Util.CLVar('')
+ env['CVSCOM'] = '$CVS $CVSFLAGS co $CVSCOFLAGS ${TARGET.posix}'
+
+def exists(env):
+ return env.Detect('cvs')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/FortranCommon.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/FortranCommon.py
new file mode 100644
index 00000000..21941582
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/FortranCommon.py
@@ -0,0 +1,246 @@
+"""SCons.Tool.FortranCommon
+
+Stuff for processing Fortran, common to all fortran dialects.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/FortranCommon.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import re
+import os.path
+
+import SCons.Action
+import SCons.Defaults
+import SCons.Scanner.Fortran
+import SCons.Tool
+import SCons.Util
+
+def isfortran(env, source):
+ """Return 1 if any of code in source has fortran files in it, 0
+ otherwise."""
+ try:
+ fsuffixes = env['FORTRANSUFFIXES']
+ except KeyError:
+ # If no FORTRANSUFFIXES, no fortran tool, so there is no need to look
+ # for fortran sources.
+ return 0
+
+ if not source:
+ # Source might be None for unusual cases like SConf.
+ return 0
+ for s in source:
+ if s.sources:
+ ext = os.path.splitext(str(s.sources[0]))[1]
+ if ext in fsuffixes:
+ return 1
+ return 0
+
+def _fortranEmitter(target, source, env):
+ node = source[0].rfile()
+ if not node.exists() and not node.is_derived():
+ print "Could not locate " + str(node.name)
+ return ([], [])
+ mod_regex = """(?i)^\s*MODULE\s+(?!PROCEDURE)(\w+)"""
+ cre = re.compile(mod_regex,re.M)
+ # Retrieve all USE'd module names
+ modules = cre.findall(node.get_text_contents())
+ # Remove unique items from the list
+ modules = SCons.Util.unique(modules)
+ # Convert module name to a .mod filename
+ suffix = env.subst('$FORTRANMODSUFFIX', target=target, source=source)
+ moddir = env.subst('$FORTRANMODDIR', target=target, source=source)
+ modules = [x.lower() + suffix for x in modules]
+ for m in modules:
+ target.append(env.fs.File(m, moddir))
+ return (target, source)
+
+def FortranEmitter(target, source, env):
+ target, source = _fortranEmitter(target, source, env)
+ return SCons.Defaults.StaticObjectEmitter(target, source, env)
+
+def ShFortranEmitter(target, source, env):
+ target, source = _fortranEmitter(target, source, env)
+ return SCons.Defaults.SharedObjectEmitter(target, source, env)
+
+def ComputeFortranSuffixes(suffixes, ppsuffixes):
+ """suffixes are fortran source files, and ppsuffixes the ones to be
+ pre-processed. Both should be sequences, not strings."""
+ assert len(suffixes) > 0
+ s = suffixes[0]
+ sup = s.upper()
+ upper_suffixes = [_.upper() for _ in suffixes]
+ if SCons.Util.case_sensitive_suffixes(s, sup):
+ ppsuffixes.extend(upper_suffixes)
+ else:
+ suffixes.extend(upper_suffixes)
+
+def CreateDialectActions(dialect):
+ """Create dialect specific actions."""
+ CompAction = SCons.Action.Action('$%sCOM ' % dialect, '$%sCOMSTR' % dialect)
+ CompPPAction = SCons.Action.Action('$%sPPCOM ' % dialect, '$%sPPCOMSTR' % dialect)
+ ShCompAction = SCons.Action.Action('$SH%sCOM ' % dialect, '$SH%sCOMSTR' % dialect)
+ ShCompPPAction = SCons.Action.Action('$SH%sPPCOM ' % dialect, '$SH%sPPCOMSTR' % dialect)
+
+ return CompAction, CompPPAction, ShCompAction, ShCompPPAction
+
+def DialectAddToEnv(env, dialect, suffixes, ppsuffixes, support_module = 0):
+ """Add dialect specific construction variables."""
+ ComputeFortranSuffixes(suffixes, ppsuffixes)
+
+ fscan = SCons.Scanner.Fortran.FortranScan("%sPATH" % dialect)
+
+ for suffix in suffixes + ppsuffixes:
+ SCons.Tool.SourceFileScanner.add_scanner(suffix, fscan)
+
+ env.AppendUnique(FORTRANSUFFIXES = suffixes + ppsuffixes)
+
+ compaction, compppaction, shcompaction, shcompppaction = \
+ CreateDialectActions(dialect)
+
+ static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
+
+ for suffix in suffixes:
+ static_obj.add_action(suffix, compaction)
+ shared_obj.add_action(suffix, shcompaction)
+ static_obj.add_emitter(suffix, FortranEmitter)
+ shared_obj.add_emitter(suffix, ShFortranEmitter)
+
+ for suffix in ppsuffixes:
+ static_obj.add_action(suffix, compppaction)
+ shared_obj.add_action(suffix, shcompppaction)
+ static_obj.add_emitter(suffix, FortranEmitter)
+ shared_obj.add_emitter(suffix, ShFortranEmitter)
+
+ if '%sFLAGS' % dialect not in env:
+ env['%sFLAGS' % dialect] = SCons.Util.CLVar('')
+
+ if 'SH%sFLAGS' % dialect not in env:
+ env['SH%sFLAGS' % dialect] = SCons.Util.CLVar('$%sFLAGS' % dialect)
+
+ # If a tool does not define fortran prefix/suffix for include path, use C ones
+ if 'INC%sPREFIX' % dialect not in env:
+ env['INC%sPREFIX' % dialect] = '$INCPREFIX'
+
+ if 'INC%sSUFFIX' % dialect not in env:
+ env['INC%sSUFFIX' % dialect] = '$INCSUFFIX'
+
+ env['_%sINCFLAGS' % dialect] = '$( ${_concat(INC%sPREFIX, %sPATH, INC%sSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)' % (dialect, dialect, dialect)
+
+ if support_module == 1:
+ env['%sCOM' % dialect] = '$%s -o $TARGET -c $%sFLAGS $_%sINCFLAGS $_FORTRANMODFLAG $SOURCES' % (dialect, dialect, dialect)
+ env['%sPPCOM' % dialect] = '$%s -o $TARGET -c $%sFLAGS $CPPFLAGS $_CPPDEFFLAGS $_%sINCFLAGS $_FORTRANMODFLAG $SOURCES' % (dialect, dialect, dialect)
+ env['SH%sCOM' % dialect] = '$SH%s -o $TARGET -c $SH%sFLAGS $_%sINCFLAGS $_FORTRANMODFLAG $SOURCES' % (dialect, dialect, dialect)
+ env['SH%sPPCOM' % dialect] = '$SH%s -o $TARGET -c $SH%sFLAGS $CPPFLAGS $_CPPDEFFLAGS $_%sINCFLAGS $_FORTRANMODFLAG $SOURCES' % (dialect, dialect, dialect)
+ else:
+ env['%sCOM' % dialect] = '$%s -o $TARGET -c $%sFLAGS $_%sINCFLAGS $SOURCES' % (dialect, dialect, dialect)
+ env['%sPPCOM' % dialect] = '$%s -o $TARGET -c $%sFLAGS $CPPFLAGS $_CPPDEFFLAGS $_%sINCFLAGS $SOURCES' % (dialect, dialect, dialect)
+ env['SH%sCOM' % dialect] = '$SH%s -o $TARGET -c $SH%sFLAGS $_%sINCFLAGS $SOURCES' % (dialect, dialect, dialect)
+ env['SH%sPPCOM' % dialect] = '$SH%s -o $TARGET -c $SH%sFLAGS $CPPFLAGS $_CPPDEFFLAGS $_%sINCFLAGS $SOURCES' % (dialect, dialect, dialect)
+
+def add_fortran_to_env(env):
+ """Add Builders and construction variables for Fortran to an Environment."""
+ try:
+ FortranSuffixes = env['FORTRANFILESUFFIXES']
+ except KeyError:
+ FortranSuffixes = ['.f', '.for', '.ftn']
+
+ #print "Adding %s to fortran suffixes" % FortranSuffixes
+ try:
+ FortranPPSuffixes = env['FORTRANPPFILESUFFIXES']
+ except KeyError:
+ FortranPPSuffixes = ['.fpp', '.FPP']
+
+ DialectAddToEnv(env, "FORTRAN", FortranSuffixes,
+ FortranPPSuffixes, support_module = 1)
+
+ env['FORTRANMODPREFIX'] = '' # like $LIBPREFIX
+ env['FORTRANMODSUFFIX'] = '.mod' # like $LIBSUFFIX
+
+ env['FORTRANMODDIR'] = '' # where the compiler should place .mod files
+ env['FORTRANMODDIRPREFIX'] = '' # some prefix to $FORTRANMODDIR - similar to $INCPREFIX
+ env['FORTRANMODDIRSUFFIX'] = '' # some suffix to $FORTRANMODDIR - similar to $INCSUFFIX
+ env['_FORTRANMODFLAG'] = '$( ${_concat(FORTRANMODDIRPREFIX, FORTRANMODDIR, FORTRANMODDIRSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
+
+def add_f77_to_env(env):
+ """Add Builders and construction variables for f77 to an Environment."""
+ try:
+ F77Suffixes = env['F77FILESUFFIXES']
+ except KeyError:
+ F77Suffixes = ['.f77']
+
+ #print "Adding %s to f77 suffixes" % F77Suffixes
+ try:
+ F77PPSuffixes = env['F77PPFILESUFFIXES']
+ except KeyError:
+ F77PPSuffixes = []
+
+ DialectAddToEnv(env, "F77", F77Suffixes, F77PPSuffixes)
+
+def add_f90_to_env(env):
+ """Add Builders and construction variables for f90 to an Environment."""
+ try:
+ F90Suffixes = env['F90FILESUFFIXES']
+ except KeyError:
+ F90Suffixes = ['.f90']
+
+ #print "Adding %s to f90 suffixes" % F90Suffixes
+ try:
+ F90PPSuffixes = env['F90PPFILESUFFIXES']
+ except KeyError:
+ F90PPSuffixes = []
+
+ DialectAddToEnv(env, "F90", F90Suffixes, F90PPSuffixes,
+ support_module = 1)
+
+def add_f95_to_env(env):
+ """Add Builders and construction variables for f95 to an Environment."""
+ try:
+ F95Suffixes = env['F95FILESUFFIXES']
+ except KeyError:
+ F95Suffixes = ['.f95']
+
+ #print "Adding %s to f95 suffixes" % F95Suffixes
+ try:
+ F95PPSuffixes = env['F95PPFILESUFFIXES']
+ except KeyError:
+ F95PPSuffixes = []
+
+ DialectAddToEnv(env, "F95", F95Suffixes, F95PPSuffixes,
+ support_module = 1)
+
+def add_all_to_env(env):
+ """Add builders and construction variables for all supported fortran
+ dialects."""
+ add_fortran_to_env(env)
+ add_f77_to_env(env)
+ add_f90_to_env(env)
+ add_f95_to_env(env)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/JavaCommon.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/JavaCommon.py
new file mode 100644
index 00000000..0a38409a
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/JavaCommon.py
@@ -0,0 +1,323 @@
+"""SCons.Tool.JavaCommon
+
+Stuff for processing Java.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/JavaCommon.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+import os.path
+import re
+
+java_parsing = 1
+
+default_java_version = '1.4'
+
+if java_parsing:
+ # Parse Java files for class names.
+ #
+ # This is a really cool parser from Charles Crain
+ # that finds appropriate class names in Java source.
+
+ # A regular expression that will find, in a java file:
+ # newlines;
+ # double-backslashes;
+ # a single-line comment "//";
+ # single or double quotes preceeded by a backslash;
+ # single quotes, double quotes, open or close braces, semi-colons,
+ # periods, open or close parentheses;
+ # floating-point numbers;
+ # any alphanumeric token (keyword, class name, specifier);
+ # any alphanumeric token surrounded by angle brackets (generics);
+ # the multi-line comment begin and end tokens /* and */;
+ # array declarations "[]".
+ _reToken = re.compile(r'(\n|\\\\|//|\\[\'"]|[\'"\{\}\;\.\(\)]|' +
+ r'\d*\.\d*|[A-Za-z_][\w\$\.]*|<[A-Za-z_]\w+>|' +
+ r'/\*|\*/|\[\])')
+
+ class OuterState(object):
+ """The initial state for parsing a Java file for classes,
+ interfaces, and anonymous inner classes."""
+ def __init__(self, version=default_java_version):
+
+ if not version in ('1.1', '1.2', '1.3','1.4', '1.5', '1.6',
+ '5', '6'):
+ msg = "Java version %s not supported" % version
+ raise NotImplementedError(msg)
+
+ self.version = version
+ self.listClasses = []
+ self.listOutputs = []
+ self.stackBrackets = []
+ self.brackets = 0
+ self.nextAnon = 1
+ self.localClasses = []
+ self.stackAnonClassBrackets = []
+ self.anonStacksStack = [[0]]
+ self.package = None
+
+ def trace(self):
+ pass
+
+ def __getClassState(self):
+ try:
+ return self.classState
+ except AttributeError:
+ ret = ClassState(self)
+ self.classState = ret
+ return ret
+
+ def __getPackageState(self):
+ try:
+ return self.packageState
+ except AttributeError:
+ ret = PackageState(self)
+ self.packageState = ret
+ return ret
+
+ def __getAnonClassState(self):
+ try:
+ return self.anonState
+ except AttributeError:
+ self.outer_state = self
+ ret = SkipState(1, AnonClassState(self))
+ self.anonState = ret
+ return ret
+
+ def __getSkipState(self):
+ try:
+ return self.skipState
+ except AttributeError:
+ ret = SkipState(1, self)
+ self.skipState = ret
+ return ret
+
+ def __getAnonStack(self):
+ return self.anonStacksStack[-1]
+
+ def openBracket(self):
+ self.brackets = self.brackets + 1
+
+ def closeBracket(self):
+ self.brackets = self.brackets - 1
+ if len(self.stackBrackets) and \
+ self.brackets == self.stackBrackets[-1]:
+ self.listOutputs.append('$'.join(self.listClasses))
+ self.localClasses.pop()
+ self.listClasses.pop()
+ self.anonStacksStack.pop()
+ self.stackBrackets.pop()
+ if len(self.stackAnonClassBrackets) and \
+ self.brackets == self.stackAnonClassBrackets[-1]:
+ self.__getAnonStack().pop()
+ self.stackAnonClassBrackets.pop()
+
+ def parseToken(self, token):
+ if token[:2] == '//':
+ return IgnoreState('\n', self)
+ elif token == '/*':
+ return IgnoreState('*/', self)
+ elif token == '{':
+ self.openBracket()
+ elif token == '}':
+ self.closeBracket()
+ elif token in [ '"', "'" ]:
+ return IgnoreState(token, self)
+ elif token == "new":
+ # anonymous inner class
+ if len(self.listClasses) > 0:
+ return self.__getAnonClassState()
+ return self.__getSkipState() # Skip the class name
+ elif token in ['class', 'interface', 'enum']:
+ if len(self.listClasses) == 0:
+ self.nextAnon = 1
+ self.stackBrackets.append(self.brackets)
+ return self.__getClassState()
+ elif token == 'package':
+ return self.__getPackageState()
+ elif token == '.':
+ # Skip the attribute, it might be named "class", in which
+ # case we don't want to treat the following token as
+ # an inner class name...
+ return self.__getSkipState()
+ return self
+
+ def addAnonClass(self):
+ """Add an anonymous inner class"""
+ if self.version in ('1.1', '1.2', '1.3', '1.4'):
+ clazz = self.listClasses[0]
+ self.listOutputs.append('%s$%d' % (clazz, self.nextAnon))
+ elif self.version in ('1.5', '1.6', '5', '6'):
+ self.stackAnonClassBrackets.append(self.brackets)
+ className = []
+ className.extend(self.listClasses)
+ self.__getAnonStack()[-1] = self.__getAnonStack()[-1] + 1
+ for anon in self.__getAnonStack():
+ className.append(str(anon))
+ self.listOutputs.append('$'.join(className))
+
+ self.nextAnon = self.nextAnon + 1
+ self.__getAnonStack().append(0)
+
+ def setPackage(self, package):
+ self.package = package
+
+ class AnonClassState(object):
+ """A state that looks for anonymous inner classes."""
+ def __init__(self, old_state):
+ # outer_state is always an instance of OuterState
+ self.outer_state = old_state.outer_state
+ self.old_state = old_state
+ self.brace_level = 0
+ def parseToken(self, token):
+ # This is an anonymous class if and only if the next
+ # non-whitespace token is a bracket. Everything between
+ # braces should be parsed as normal java code.
+ if token[:2] == '//':
+ return IgnoreState('\n', self)
+ elif token == '/*':
+ return IgnoreState('*/', self)
+ elif token == '\n':
+ return self
+ elif token[0] == '<' and token[-1] == '>':
+ return self
+ elif token == '(':
+ self.brace_level = self.brace_level + 1
+ return self
+ if self.brace_level > 0:
+ if token == 'new':
+ # look further for anonymous inner class
+ return SkipState(1, AnonClassState(self))
+ elif token in [ '"', "'" ]:
+ return IgnoreState(token, self)
+ elif token == ')':
+ self.brace_level = self.brace_level - 1
+ return self
+ if token == '{':
+ self.outer_state.addAnonClass()
+ return self.old_state.parseToken(token)
+
+ class SkipState(object):
+ """A state that will skip a specified number of tokens before
+ reverting to the previous state."""
+ def __init__(self, tokens_to_skip, old_state):
+ self.tokens_to_skip = tokens_to_skip
+ self.old_state = old_state
+ def parseToken(self, token):
+ self.tokens_to_skip = self.tokens_to_skip - 1
+ if self.tokens_to_skip < 1:
+ return self.old_state
+ return self
+
+ class ClassState(object):
+ """A state we go into when we hit a class or interface keyword."""
+ def __init__(self, outer_state):
+ # outer_state is always an instance of OuterState
+ self.outer_state = outer_state
+ def parseToken(self, token):
+ # the next non-whitespace token should be the name of the class
+ if token == '\n':
+ return self
+ # If that's an inner class which is declared in a method, it
+ # requires an index prepended to the class-name, e.g.
+ # 'Foo$1Inner' (Tigris Issue 2087)
+ if self.outer_state.localClasses and \
+ self.outer_state.stackBrackets[-1] > \
+ self.outer_state.stackBrackets[-2]+1:
+ locals = self.outer_state.localClasses[-1]
+ try:
+ idx = locals[token]
+ locals[token] = locals[token]+1
+ except KeyError:
+ locals[token] = 1
+ token = str(locals[token]) + token
+ self.outer_state.localClasses.append({})
+ self.outer_state.listClasses.append(token)
+ self.outer_state.anonStacksStack.append([0])
+ return self.outer_state
+
+ class IgnoreState(object):
+ """A state that will ignore all tokens until it gets to a
+ specified token."""
+ def __init__(self, ignore_until, old_state):
+ self.ignore_until = ignore_until
+ self.old_state = old_state
+ def parseToken(self, token):
+ if self.ignore_until == token:
+ return self.old_state
+ return self
+
+ class PackageState(object):
+ """The state we enter when we encounter the package keyword.
+ We assume the next token will be the package name."""
+ def __init__(self, outer_state):
+ # outer_state is always an instance of OuterState
+ self.outer_state = outer_state
+ def parseToken(self, token):
+ self.outer_state.setPackage(token)
+ return self.outer_state
+
+ def parse_java_file(fn, version=default_java_version):
+ return parse_java(open(fn, 'r').read(), version)
+
+ def parse_java(contents, version=default_java_version, trace=None):
+ """Parse a .java file and return a double of package directory,
+ plus a list of .class files that compiling that .java file will
+ produce"""
+ package = None
+ initial = OuterState(version)
+ currstate = initial
+ for token in _reToken.findall(contents):
+ # The regex produces a bunch of groups, but only one will
+ # have anything in it.
+ currstate = currstate.parseToken(token)
+ if trace: trace(token, currstate)
+ if initial.package:
+ package = initial.package.replace('.', os.sep)
+ return (package, initial.listOutputs)
+
+else:
+ # Don't actually parse Java files for class names.
+ #
+ # We might make this a configurable option in the future if
+ # Java-file parsing takes too long (although it shouldn't relative
+ # to how long the Java compiler itself seems to take...).
+
+ def parse_java_file(fn):
+ """ "Parse" a .java file.
+
+ This actually just splits the file name, so the assumption here
+ is that the file name matches the public class name, and that
+ the path to the file is the same as the package name.
+ """
+ return os.path.split(file)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/__init__.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/__init__.py
new file mode 100644
index 00000000..780a97cc
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/__init__.py
@@ -0,0 +1,56 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/MSCommon/__init__.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__doc__ = """
+Common functions for Microsoft Visual Studio and Visual C/C++.
+"""
+
+import copy
+import os
+import re
+import subprocess
+
+import SCons.Errors
+import SCons.Platform.win32
+import SCons.Util
+
+from SCons.Tool.MSCommon.sdk import mssdk_exists, \
+ mssdk_setup_env
+
+from SCons.Tool.MSCommon.vc import msvc_exists, \
+ msvc_setup_env, \
+ msvc_setup_env_once
+
+from SCons.Tool.MSCommon.vs import get_default_version, \
+ get_vs_by_version, \
+ merge_default_version, \
+ msvs_exists, \
+ query_versions
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/arch.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/arch.py
new file mode 100644
index 00000000..28ef0f17
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/arch.py
@@ -0,0 +1,61 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/MSCommon/arch.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__doc__ = """Module to define supported Windows chip architectures.
+"""
+
+import os
+
+class ArchDefinition(object):
+ """
+ A class for defining architecture-specific settings and logic.
+ """
+ def __init__(self, arch, synonyms=[]):
+ self.arch = arch
+ self.synonyms = synonyms
+
+SupportedArchitectureList = [
+ ArchitectureDefinition(
+ 'x86',
+ ['i386', 'i486', 'i586', 'i686'],
+ ),
+
+ ArchitectureDefinition(
+ 'x86_64',
+ ['AMD64', 'amd64', 'em64t', 'EM64T', 'x86_64'],
+ ),
+
+ ArchitectureDefinition(
+ 'ia64',
+ ['IA64'],
+ ),
+]
+
+SupportedArchitectureMap = {}
+for a in SupportedArchitectureList:
+ SupportedArchitectureMap[a.arch] = a
+ for s in a.synonyms:
+ SupportedArchitectureMap[s] = a
+
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/common.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/common.py
new file mode 100644
index 00000000..9f3df2d8
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/common.py
@@ -0,0 +1,240 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/MSCommon/common.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__doc__ = """
+Common helper functions for working with the Microsoft tool chain.
+"""
+
+import copy
+import os
+import subprocess
+import re
+
+import SCons.Util
+
+
+logfile = os.environ.get('SCONS_MSCOMMON_DEBUG')
+if logfile == '-':
+ def debug(x):
+ print x
+elif logfile:
+ try:
+ import logging
+ except ImportError:
+ debug = lambda x: open(logfile, 'a').write(x + '\n')
+ else:
+ logging.basicConfig(filename=logfile, level=logging.DEBUG)
+ debug = logging.debug
+else:
+ debug = lambda x: None
+
+
+_is_win64 = None
+
+def is_win64():
+ """Return true if running on windows 64 bits.
+
+ Works whether python itself runs in 64 bits or 32 bits."""
+ # Unfortunately, python does not provide a useful way to determine
+ # if the underlying Windows OS is 32-bit or 64-bit. Worse, whether
+ # the Python itself is 32-bit or 64-bit affects what it returns,
+ # so nothing in sys.* or os.* help.
+
+ # Apparently the best solution is to use env vars that Windows
+ # sets. If PROCESSOR_ARCHITECTURE is not x86, then the python
+ # process is running in 64 bit mode (on a 64-bit OS, 64-bit
+ # hardware, obviously).
+ # If this python is 32-bit but the OS is 64, Windows will set
+ # ProgramW6432 and PROCESSOR_ARCHITEW6432 to non-null.
+ # (Checking for HKLM\Software\Wow6432Node in the registry doesn't
+ # work, because some 32-bit installers create it.)
+ global _is_win64
+ if _is_win64 is None:
+ # I structured these tests to make it easy to add new ones or
+ # add exceptions in the future, because this is a bit fragile.
+ _is_win64 = False
+ if os.environ.get('PROCESSOR_ARCHITECTURE','x86') != 'x86':
+ _is_win64 = True
+ if os.environ.get('PROCESSOR_ARCHITEW6432'):
+ _is_win64 = True
+ if os.environ.get('ProgramW6432'):
+ _is_win64 = True
+ return _is_win64
+
+
+def read_reg(value):
+ return SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE, value)[0]
+
+def has_reg(value):
+ """Return True if the given key exists in HKEY_LOCAL_MACHINE, False
+ otherwise."""
+ try:
+ SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE, value)
+ ret = True
+ except WindowsError:
+ ret = False
+ return ret
+
+# Functions for fetching environment variable settings from batch files.
+
+def normalize_env(env, keys, force=False):
+ """Given a dictionary representing a shell environment, add the variables
+ from os.environ needed for the processing of .bat files; the keys are
+ controlled by the keys argument.
+
+ It also makes sure the environment values are correctly encoded.
+
+ If force=True, then all of the key values that exist are copied
+ into the returned dictionary. If force=false, values are only
+ copied if the key does not already exist in the copied dictionary.
+
+ Note: the environment is copied."""
+ normenv = {}
+ if env:
+ for k in env.keys():
+ normenv[k] = copy.deepcopy(env[k]).encode('mbcs')
+
+ for k in keys:
+ if k in os.environ and (force or not k in normenv):
+ normenv[k] = os.environ[k].encode('mbcs')
+
+ return normenv
+
+def get_output(vcbat, args = None, env = None):
+ """Parse the output of given bat file, with given args."""
+
+ if env is None:
+ # Create a blank environment, for use in launching the tools
+ env = SCons.Environment.Environment(tools=[])
+
+ # TODO: This is a hard-coded list of the variables that (may) need
+ # to be imported from os.environ[] for v[sc]*vars*.bat file
+ # execution to work. This list should really be either directly
+ # controlled by vc.py, or else derived from the common_tools_var
+ # settings in vs.py.
+ vars = [
+ 'COMSPEC',
+ 'VS90COMNTOOLS',
+ 'VS80COMNTOOLS',
+ 'VS71COMNTOOLS',
+ 'VS70COMNTOOLS',
+ 'VS60COMNTOOLS',
+ ]
+ env['ENV'] = normalize_env(env['ENV'], vars, force=False)
+
+ if args:
+ debug("Calling '%s %s'" % (vcbat, args))
+ popen = SCons.Action._subproc(env,
+ '"%s" %s & set' % (vcbat, args),
+ stdin = 'devnull',
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ else:
+ debug("Calling '%s'" % vcbat)
+ popen = SCons.Action._subproc(env,
+ '"%s" & set' % vcbat,
+ stdin = 'devnull',
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+
+ # Use the .stdout and .stderr attributes directly because the
+ # .communicate() method uses the threading module on Windows
+ # and won't work under Pythons not built with threading.
+ stdout = popen.stdout.read()
+ stderr = popen.stderr.read()
+ if stderr:
+ # TODO: find something better to do with stderr;
+ # this at least prevents errors from getting swallowed.
+ import sys
+ sys.stderr.write(stderr)
+ if popen.wait() != 0:
+ raise IOError(stderr.decode("mbcs"))
+
+ output = stdout.decode("mbcs")
+ return output
+
+def parse_output(output, keep = ("INCLUDE", "LIB", "LIBPATH", "PATH")):
+ # dkeep is a dict associating key: path_list, where key is one item from
+ # keep, and pat_list the associated list of paths
+
+ dkeep = dict([(i, []) for i in keep])
+
+ # rdk will keep the regex to match the .bat file output line starts
+ rdk = {}
+ for i in keep:
+ rdk[i] = re.compile('%s=(.*)' % i, re.I)
+
+ def add_env(rmatch, key, dkeep=dkeep):
+ plist = rmatch.group(1).split(os.pathsep)
+ for p in plist:
+ # Do not add empty paths (when a var ends with ;)
+ if p:
+ p = p.encode('mbcs')
+ # XXX: For some reason, VC98 .bat file adds "" around the PATH
+ # values, and it screws up the environment later, so we strip
+ # it.
+ p = p.strip('"')
+ dkeep[key].append(p)
+
+ for line in output.splitlines():
+ for k,v in rdk.items():
+ m = v.match(line)
+ if m:
+ add_env(m, k)
+
+ return dkeep
+
+# TODO(sgk): unused
+def output_to_dict(output):
+ """Given an output string, parse it to find env variables.
+
+ Return a dict where keys are variables names, and values their content"""
+ envlinem = re.compile(r'^([a-zA-z0-9]+)=([\S\s]*)$')
+ parsedenv = {}
+ for line in output.splitlines():
+ m = envlinem.match(line)
+ if m:
+ parsedenv[m.group(1)] = m.group(2)
+ return parsedenv
+
+# TODO(sgk): unused
+def get_new(l1, l2):
+ """Given two list l1 and l2, return the items in l2 which are not in l1.
+ Order is maintained."""
+
+ # We don't try to be smart: lists are small, and this is not the bottleneck
+ # is any case
+ new = []
+ for i in l2:
+ if i not in l1:
+ new.append(i)
+
+ return new
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/netframework.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/netframework.py
new file mode 100644
index 00000000..66c5586c
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/netframework.py
@@ -0,0 +1,82 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Tool/MSCommon/netframework.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__doc__ = """
+"""
+
+import os
+import re
+
+from common import read_reg, debug
+
+# Original value recorded by dcournapeau
+_FRAMEWORKDIR_HKEY_ROOT = r'Software\Microsoft\.NETFramework\InstallRoot'
+# On SGK's system
+_FRAMEWORKDIR_HKEY_ROOT = r'Software\Microsoft\Microsoft SDKs\.NETFramework\v2.0\InstallationFolder'
+
+def find_framework_root():
+ # XXX: find it from environment (FrameworkDir)
+ try:
+ froot = read_reg(_FRAMEWORKDIR_HKEY_ROOT)
+ debug("Found framework install root in registry: %s" % froot)
+ except WindowsError, e:
+ debug("Could not read reg key %s" % _FRAMEWORKDIR_HKEY_ROOT)
+ return None
+
+ if not os.path.exists(froot):
+ debug("%s not found on fs" % froot)
+ return None
+
+ return froot
+
+def query_versions():
+ froot = find_framework_root()
+ if froot:
+ contents = os.listdir(froot)
+
+ l = re.compile('v[0-9]+.*')
+ versions = [e for e in contents if l.match(e)]
+
+ def versrt(a,b):
+ # since version numbers aren't really floats...
+ aa = a[1:]
+ bb = b[1:]
+ aal = aa.split('.')
+ bbl = bb.split('.')
+ # sequence comparison in python is lexicographical
+ # which is exactly what we want.
+ # Note we sort backwards so the highest version is first.
+ return cmp(bbl,aal)
+
+ versions.sort(versrt)
+ else:
+ versions = []
+
+ return versions
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/sdk.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/sdk.py
new file mode 100644
index 00000000..63559983
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/sdk.py
@@ -0,0 +1,391 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/MSCommon/sdk.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__doc__ = """Module to detect the Platform/Windows SDK
+
+PSDK 2003 R1 is the earliest version detected.
+"""
+
+import os
+
+import SCons.Errors
+import SCons.Util
+
+import common
+
+debug = common.debug
+
+# SDK Checks. This is of course a mess as everything else on MS platforms. Here
+# is what we do to detect the SDK:
+#
+# For Windows SDK >= 6.0: just look into the registry entries:
+# HKLM\Software\Microsoft\Microsoft SDKs\Windows
+# All the keys in there are the available versions.
+#
+# For Platform SDK before 6.0 (2003 server R1 and R2, etc...), there does not
+# seem to be any sane registry key, so the precise location is hardcoded.
+#
+# For versions below 2003R1, it seems the PSDK is included with Visual Studio?
+#
+# Also, per the following:
+# http://benjamin.smedbergs.us/blog/tag/atl/
+# VC++ Professional comes with the SDK, VC++ Express does not.
+
+# Location of the SDK (checked for 6.1 only)
+_CURINSTALLED_SDK_HKEY_ROOT = \
+ r"Software\Microsoft\Microsoft SDKs\Windows\CurrentInstallFolder"
+
+
+class SDKDefinition(object):
+ """
+ An abstract base class for trying to find installed SDK directories.
+ """
+ def __init__(self, version, **kw):
+ self.version = version
+ self.__dict__.update(kw)
+
+ def find_sdk_dir(self):
+ """Try to find the MS SDK from the registry.
+
+ Return None if failed or the directory does not exist.
+ """
+ if not SCons.Util.can_read_reg:
+ debug('find_sdk_dir(): can not read registry')
+ return None
+
+ hkey = self.HKEY_FMT % self.hkey_data
+ debug('find_sdk_dir(): checking registry:%s'%hkey)
+
+ try:
+ sdk_dir = common.read_reg(hkey)
+ except WindowsError, e:
+ debug('find_sdk_dir(): no SDK registry key %s' % repr(hkey))
+ return None
+
+ debug('find_sdk_dir(): Trying SDK Dir: %s'%sdk_dir)
+
+ if not os.path.exists(sdk_dir):
+ debug('find_sdk_dir(): %s not on file system' % sdk_dir)
+ return None
+
+ ftc = os.path.join(sdk_dir, self.sanity_check_file)
+ if not os.path.exists(ftc):
+ debug("find_sdk_dir(): sanity check %s not found" % ftc)
+ return None
+
+ return sdk_dir
+
+ def get_sdk_dir(self):
+ """Return the MSSSDK given the version string."""
+ try:
+ return self._sdk_dir
+ except AttributeError:
+ sdk_dir = self.find_sdk_dir()
+ self._sdk_dir = sdk_dir
+ return sdk_dir
+
+ def get_sdk_vc_script(self,host_arch, target_arch):
+ """ Return the script to initialize the VC compiler installed by SDK
+ """
+
+ if (host_arch == 'amd64' and target_arch == 'x86'):
+ # No cross tools needed compiling 32 bits on 64 bit machine
+ host_arch=target_arch
+
+ arch_string=target_arch
+ if (host_arch != target_arch):
+ arch_string='%s_%s'%(host_arch,target_arch)
+
+ debug("sdk.py: get_sdk_vc_script():arch_string:%s host_arch:%s target_arch:%s"%(arch_string,
+ host_arch,
+ target_arch))
+ file=self.vc_setup_scripts.get(arch_string,None)
+ debug("sdk.py: get_sdk_vc_script():file:%s"%file)
+ return file
+
+class WindowsSDK(SDKDefinition):
+ """
+ A subclass for trying to find installed Windows SDK directories.
+ """
+ HKEY_FMT = r'Software\Microsoft\Microsoft SDKs\Windows\v%s\InstallationFolder'
+ def __init__(self, *args, **kw):
+ SDKDefinition.__init__(self, *args, **kw)
+ self.hkey_data = self.version
+
+class PlatformSDK(SDKDefinition):
+ """
+ A subclass for trying to find installed Platform SDK directories.
+ """
+ HKEY_FMT = r'Software\Microsoft\MicrosoftSDK\InstalledSDKS\%s\Install Dir'
+ def __init__(self, *args, **kw):
+ SDKDefinition.__init__(self, *args, **kw)
+ self.hkey_data = self.uuid
+
+#
+# The list of VC initialization scripts installed by the SDK
+# These should be tried if the vcvarsall.bat TARGET_ARCH fails
+preSDK61VCSetupScripts = { 'x86' : r'bin\vcvars32.bat',
+ 'amd64' : r'bin\vcvarsamd64.bat',
+ 'x86_amd64': r'bin\vcvarsx86_amd64.bat',
+ 'x86_ia64' : r'bin\vcvarsx86_ia64.bat',
+ 'ia64' : r'bin\vcvarsia64.bat'}
+
+SDK61VCSetupScripts = {'x86' : r'bin\vcvars32.bat',
+ 'amd64' : r'bin\amd64\vcvarsamd64.bat',
+ 'x86_amd64': r'bin\x86_amd64\vcvarsx86_amd64.bat',
+ 'x86_ia64' : r'bin\x86_ia64\vcvarsx86_ia64.bat',
+ 'ia64' : r'bin\ia64\vcvarsia64.bat'}
+
+SDK70VCSetupScripts = { 'x86' : r'bin\vcvars32.bat',
+ 'amd64' : r'bin\vcvars64.bat',
+ 'x86_amd64': r'bin\vcvarsx86_amd64.bat',
+ 'x86_ia64' : r'bin\vcvarsx86_ia64.bat',
+ 'ia64' : r'bin\vcvarsia64.bat'}
+
+# The list of support SDKs which we know how to detect.
+#
+# The first SDK found in the list is the one used by default if there
+# are multiple SDKs installed. Barring good reasons to the contrary,
+# this means we should list SDKs with from most recent to oldest.
+#
+# If you update this list, update the documentation in Tool/mssdk.xml.
+SupportedSDKList = [
+ WindowsSDK('7.0',
+ sanity_check_file=r'bin\SetEnv.Cmd',
+ include_subdir='include',
+ lib_subdir={
+ 'x86' : ['lib'],
+ 'x86_64' : [r'lib\x64'],
+ 'ia64' : [r'lib\ia64'],
+ },
+ vc_setup_scripts = SDK70VCSetupScripts,
+ ),
+ WindowsSDK('6.1',
+ sanity_check_file=r'bin\SetEnv.Cmd',
+ include_subdir='include',
+ lib_subdir={
+ 'x86' : ['lib'],
+ 'x86_64' : [r'lib\x64'],
+ 'ia64' : [r'lib\ia64'],
+ },
+ vc_setup_scripts = SDK61VCSetupScripts,
+ ),
+
+ WindowsSDK('6.0A',
+ sanity_check_file=r'include\windows.h',
+ include_subdir='include',
+ lib_subdir={
+ 'x86' : ['lib'],
+ 'x86_64' : [r'lib\x64'],
+ 'ia64' : [r'lib\ia64'],
+ },
+ vc_setup_scripts = preSDK61VCSetupScripts,
+ ),
+
+ WindowsSDK('6.0',
+ sanity_check_file=r'bin\gacutil.exe',
+ include_subdir='include',
+ lib_subdir='lib',
+ vc_setup_scripts = preSDK61VCSetupScripts,
+ ),
+
+ PlatformSDK('2003R2',
+ sanity_check_file=r'SetEnv.Cmd',
+ uuid="D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1",
+ vc_setup_scripts = preSDK61VCSetupScripts,
+ ),
+
+ PlatformSDK('2003R1',
+ sanity_check_file=r'SetEnv.Cmd',
+ uuid="8F9E5EF3-A9A5-491B-A889-C58EFFECE8B3",
+ vc_setup_scripts = preSDK61VCSetupScripts,
+ ),
+]
+
+SupportedSDKMap = {}
+for sdk in SupportedSDKList:
+ SupportedSDKMap[sdk.version] = sdk
+
+
+# Finding installed SDKs isn't cheap, because it goes not only to the
+# registry but also to the disk to sanity-check that there is, in fact,
+# an SDK installed there and that the registry entry isn't just stale.
+# Find this information once, when requested, and cache it.
+
+InstalledSDKList = None
+InstalledSDKMap = None
+
+def get_installed_sdks():
+ global InstalledSDKList
+ global InstalledSDKMap
+ debug('sdk.py:get_installed_sdks()')
+ if InstalledSDKList is None:
+ InstalledSDKList = []
+ InstalledSDKMap = {}
+ for sdk in SupportedSDKList:
+ debug('MSCommon/sdk.py: trying to find SDK %s' % sdk.version)
+ if sdk.get_sdk_dir():
+ debug('MSCommon/sdk.py:found SDK %s' % sdk.version)
+ InstalledSDKList.append(sdk)
+ InstalledSDKMap[sdk.version] = sdk
+ return InstalledSDKList
+
+
+# We may be asked to update multiple construction environments with
+# SDK information. When doing this, we check on-disk for whether
+# the SDK has 'mfc' and 'atl' subdirectories. Since going to disk
+# is expensive, cache results by directory.
+
+SDKEnvironmentUpdates = {}
+
+def set_sdk_by_directory(env, sdk_dir):
+ global SDKEnvironmentUpdates
+ debug('set_sdk_by_directory: Using dir:%s'%sdk_dir)
+ try:
+ env_tuple_list = SDKEnvironmentUpdates[sdk_dir]
+ except KeyError:
+ env_tuple_list = []
+ SDKEnvironmentUpdates[sdk_dir] = env_tuple_list
+
+ include_path = os.path.join(sdk_dir, 'include')
+ mfc_path = os.path.join(include_path, 'mfc')
+ atl_path = os.path.join(include_path, 'atl')
+
+ if os.path.exists(mfc_path):
+ env_tuple_list.append(('INCLUDE', mfc_path))
+ if os.path.exists(atl_path):
+ env_tuple_list.append(('INCLUDE', atl_path))
+ env_tuple_list.append(('INCLUDE', include_path))
+
+ env_tuple_list.append(('LIB', os.path.join(sdk_dir, 'lib')))
+ env_tuple_list.append(('LIBPATH', os.path.join(sdk_dir, 'lib')))
+ env_tuple_list.append(('PATH', os.path.join(sdk_dir, 'bin')))
+
+ for variable, directory in env_tuple_list:
+ env.PrependENVPath(variable, directory)
+
+
+# TODO(sgk): currently unused; remove?
+def get_cur_sdk_dir_from_reg():
+ """Try to find the platform sdk directory from the registry.
+
+ Return None if failed or the directory does not exist"""
+ if not SCons.Util.can_read_reg:
+ debug('SCons cannot read registry')
+ return None
+
+ try:
+ val = common.read_reg(_CURINSTALLED_SDK_HKEY_ROOT)
+ debug("Found current sdk dir in registry: %s" % val)
+ except WindowsError, e:
+ debug("Did not find current sdk in registry")
+ return None
+
+ if not os.path.exists(val):
+ debug("Current sdk dir %s not on fs" % val)
+ return None
+
+ return val
+
+def get_sdk_by_version(mssdk):
+ if mssdk not in SupportedSDKMap:
+ msg = "SDK version %s is not supported" % repr(mssdk)
+ raise SCons.Errors.UserError(msg)
+ get_installed_sdks()
+ return InstalledSDKMap.get(mssdk)
+
+def get_default_sdk():
+ """Set up the default Platform/Windows SDK."""
+ get_installed_sdks()
+ if not InstalledSDKList:
+ return None
+ return InstalledSDKList[0]
+
+
+
+
+def mssdk_setup_env(env):
+ debug('sdk.py:mssdk_setup_env()')
+ if 'MSSDK_DIR' in env:
+ sdk_dir = env['MSSDK_DIR']
+ if sdk_dir is None:
+ return
+ sdk_dir = env.subst(sdk_dir)
+ debug('sdk.py:mssdk_setup_env: Using MSSDK_DIR:%s'%sdk_dir)
+ elif 'MSSDK_VERSION' in env:
+ sdk_version = env['MSSDK_VERSION']
+ if sdk_version is None:
+ msg = "SDK version %s is not installed" % repr(mssdk)
+ raise SCons.Errors.UserError(msg)
+ sdk_version = env.subst(sdk_version)
+ mssdk = get_sdk_by_version(sdk_version)
+ sdk_dir = mssdk.get_sdk_dir()
+ debug('sdk.py:mssdk_setup_env: Using MSSDK_VERSION:%s'%sdk_dir)
+ elif 'MSVS_VERSION' in env:
+ msvs_version = env['MSVS_VERSION']
+ debug('sdk.py:mssdk_setup_env:Getting MSVS_VERSION from env:%s'%msvs_version)
+ if msvs_version is None:
+ debug('sdk.py:mssdk_setup_env thinks msvs_version is None')
+ return
+ msvs_version = env.subst(msvs_version)
+ import vs
+ msvs = vs.get_vs_by_version(msvs_version)
+ debug('sdk.py:mssdk_setup_env:msvs is :%s'%msvs)
+ if not msvs:
+ debug('sdk.py:mssdk_setup_env: no VS version detected, bailingout:%s'%msvs)
+ return
+ sdk_version = msvs.sdk_version
+ debug('sdk.py:msvs.sdk_version is %s'%sdk_version)
+ if not sdk_version:
+ return
+ mssdk = get_sdk_by_version(sdk_version)
+ if not mssdk:
+ mssdk = get_default_sdk()
+ if not mssdk:
+ return
+ sdk_dir = mssdk.get_sdk_dir()
+ debug('sdk.py:mssdk_setup_env: Using MSVS_VERSION:%s'%sdk_dir)
+ else:
+ mssdk = get_default_sdk()
+ if not mssdk:
+ return
+ sdk_dir = mssdk.get_sdk_dir()
+ debug('sdk.py:mssdk_setup_env: not using any env values. sdk_dir:%s'%sdk_dir)
+
+ set_sdk_by_directory(env, sdk_dir)
+
+ #print "No MSVS_VERSION: this is likely to be a bug"
+
+def mssdk_exists(version=None):
+ sdks = get_installed_sdks()
+ if version is None:
+ return len(sdks) > 0
+ return version in sdks
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/vc.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/vc.py
new file mode 100644
index 00000000..0aeb3e78
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/vc.py
@@ -0,0 +1,456 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+# TODO:
+# * supported arch for versions: for old versions of batch file without
+# argument, giving bogus argument cannot be detected, so we have to hardcode
+# this here
+# * print warning when msvc version specified but not found
+# * find out why warning do not print
+# * test on 64 bits XP + VS 2005 (and VS 6 if possible)
+# * SDK
+# * Assembly
+__revision__ = "src/engine/SCons/Tool/MSCommon/vc.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__doc__ = """Module for Visual C/C++ detection and configuration.
+"""
+import SCons.compat
+
+import os
+import platform
+from string import digits as string_digits
+
+import SCons.Warnings
+
+import common
+
+debug = common.debug
+
+import sdk
+
+get_installed_sdks = sdk.get_installed_sdks
+
+
+class VisualCException(Exception):
+ pass
+
+class UnsupportedVersion(VisualCException):
+ pass
+
+class UnsupportedArch(VisualCException):
+ pass
+
+class MissingConfiguration(VisualCException):
+ pass
+
+class NoVersionFound(VisualCException):
+ pass
+
+class BatchFileExecutionError(VisualCException):
+ pass
+
+# Dict to 'canonalize' the arch
+_ARCH_TO_CANONICAL = {
+ "amd64" : "amd64",
+ "emt64" : "amd64",
+ "i386" : "x86",
+ "i486" : "x86",
+ "i586" : "x86",
+ "i686" : "x86",
+ "ia64" : "ia64",
+ "itanium" : "ia64",
+ "x86" : "x86",
+ "x86_64" : "amd64",
+}
+
+# Given a (host, target) tuple, return the argument for the bat file. Both host
+# and targets should be canonalized.
+_HOST_TARGET_ARCH_TO_BAT_ARCH = {
+ ("x86", "x86"): "x86",
+ ("x86", "amd64"): "x86_amd64",
+ ("amd64", "amd64"): "amd64",
+ ("amd64", "x86"): "x86",
+ ("x86", "ia64"): "x86_ia64"
+}
+
+def get_host_target(env):
+ debug('vc.py:get_host_target()')
+
+ host_platform = env.get('HOST_ARCH')
+ if not host_platform:
+ host_platform = platform.machine()
+ # TODO(2.5): the native Python platform.machine() function returns
+ # '' on all Python versions before 2.6, after which it also uses
+ # PROCESSOR_ARCHITECTURE.
+ if not host_platform:
+ host_platform = os.environ.get('PROCESSOR_ARCHITECTURE', '')
+
+ # Retain user requested TARGET_ARCH
+ req_target_platform = env.get('TARGET_ARCH')
+ debug('vc.py:get_host_target() req_target_platform:%s'%req_target_platform)
+
+ if req_target_platform:
+ # If user requested a specific platform then only try that one.
+ target_platform = req_target_platform
+ else:
+ target_platform = host_platform
+
+ try:
+ host = _ARCH_TO_CANONICAL[host_platform.lower()]
+ except KeyError, e:
+ msg = "Unrecognized host architecture %s"
+ raise ValueError(msg % repr(host_platform))
+
+ try:
+ target = _ARCH_TO_CANONICAL[target_platform.lower()]
+ except KeyError, e:
+ raise ValueError("Unrecognized target architecture %s" % target_platform)
+
+ return (host, target,req_target_platform)
+
+_VCVER = ["10.0", "9.0", "9.0Exp","8.0", "8.0Exp","7.1", "7.0", "6.0"]
+
+_VCVER_TO_PRODUCT_DIR = {
+ '10.0': [
+ r'Microsoft\VisualStudio\10.0\Setup\VC\ProductDir'],
+ '9.0': [
+ r'Microsoft\VisualStudio\9.0\Setup\VC\ProductDir'],
+ '9.0Exp' : [
+ r'Microsoft\VCExpress\9.0\Setup\VC\ProductDir'],
+ '8.0': [
+ r'Microsoft\VisualStudio\8.0\Setup\VC\ProductDir'],
+ '8.0Exp': [
+ r'Microsoft\VCExpress\8.0\Setup\VC\ProductDir'],
+ '7.1': [
+ r'Microsoft\VisualStudio\7.1\Setup\VC\ProductDir'],
+ '7.0': [
+ r'Microsoft\VisualStudio\7.0\Setup\VC\ProductDir'],
+ '6.0': [
+ r'Microsoft\VisualStudio\6.0\Setup\Microsoft Visual C++\ProductDir']
+}
+
+def msvc_version_to_maj_min(msvc_version):
+ msvc_version_numeric = ''.join([x for x in msvc_version if x in string_digits + '.'])
+
+ t = msvc_version_numeric.split(".")
+ if not len(t) == 2:
+ raise ValueError("Unrecognized version %s (%s)" % (msvc_version,msvc_version_numeric))
+ try:
+ maj = int(t[0])
+ min = int(t[1])
+ return maj, min
+ except ValueError, e:
+ raise ValueError("Unrecognized version %s (%s)" % (msvc_version,msvc_version_numeric))
+
+def is_host_target_supported(host_target, msvc_version):
+ """Return True if the given (host, target) tuple is supported given the
+ msvc version.
+
+ Parameters
+ ----------
+ host_target: tuple
+ tuple of (canonalized) host-target, e.g. ("x86", "amd64") for cross
+ compilation from 32 bits windows to 64 bits.
+ msvc_version: str
+ msvc version (major.minor, e.g. 10.0)
+
+ Note
+ ----
+ This only check whether a given version *may* support the given (host,
+ target), not that the toolchain is actually present on the machine.
+ """
+ # We assume that any Visual Studio version supports x86 as a target
+ if host_target[1] != "x86":
+ maj, min = msvc_version_to_maj_min(msvc_version)
+ if maj < 8:
+ return False
+
+ return True
+
+def find_vc_pdir(msvc_version):
+ """Try to find the product directory for the given
+ version.
+
+ Note
+ ----
+ If for some reason the requested version could not be found, an
+ exception which inherits from VisualCException will be raised."""
+ root = 'Software\\'
+ if common.is_win64():
+ root = root + 'Wow6432Node\\'
+ try:
+ hkeys = _VCVER_TO_PRODUCT_DIR[msvc_version]
+ except KeyError:
+ debug("Unknown version of MSVC: %s" % msvc_version)
+ raise UnsupportedVersion("Unknown version %s" % msvc_version)
+
+ for key in hkeys:
+ key = root + key
+ try:
+ comps = common.read_reg(key)
+ except WindowsError, e:
+ debug('find_vc_dir(): no VC registry key %s' % repr(key))
+ else:
+ debug('find_vc_dir(): found VC in registry: %s' % comps)
+ if os.path.exists(comps):
+ return comps
+ else:
+ debug('find_vc_dir(): reg says dir is %s, but it does not exist. (ignoring)'\
+ % comps)
+ raise MissingConfiguration("registry dir %s not found on the filesystem" % comps)
+ return None
+
+def find_batch_file(env,msvc_version,host_arch,target_arch):
+ """
+ Find the location of the batch script which should set up the compiler
+ for any TARGET_ARCH whose compilers were installed by Visual Studio/VCExpress
+ """
+ pdir = find_vc_pdir(msvc_version)
+ if pdir is None:
+ raise NoVersionFound("No version of Visual Studio found")
+
+ debug('vc.py: find_batch_file() pdir:%s'%pdir)
+
+ # filter out e.g. "Exp" from the version name
+ msvc_ver_numeric = ''.join([x for x in msvc_version if x in string_digits + "."])
+ vernum = float(msvc_ver_numeric)
+ if 7 <= vernum < 8:
+ pdir = os.path.join(pdir, os.pardir, "Common7", "Tools")
+ batfilename = os.path.join(pdir, "vsvars32.bat")
+ elif vernum < 7:
+ pdir = os.path.join(pdir, "Bin")
+ batfilename = os.path.join(pdir, "vcvars32.bat")
+ else: # >= 8
+ batfilename = os.path.join(pdir, "vcvarsall.bat")
+
+ if not os.path.exists(batfilename):
+ debug("Not found: %s" % batfilename)
+ batfilename = None
+
+ installed_sdks=get_installed_sdks()
+ for _sdk in installed_sdks:
+ sdk_bat_file=_sdk.get_sdk_vc_script(host_arch,target_arch)
+ sdk_bat_file_path=os.path.join(pdir,sdk_bat_file)
+ debug('vc.py:find_batch_file() sdk_bat_file_path:%s'%sdk_bat_file_path)
+ if os.path.exists(sdk_bat_file_path):
+ return (batfilename,sdk_bat_file_path)
+ else:
+ debug("vc.py:find_batch_file() not found:%s"%sdk_bat_file_path)
+ else:
+ return (batfilename,None)
+
+__INSTALLED_VCS_RUN = None
+
+def cached_get_installed_vcs():
+ global __INSTALLED_VCS_RUN
+
+ if __INSTALLED_VCS_RUN is None:
+ ret = get_installed_vcs()
+ __INSTALLED_VCS_RUN = ret
+
+ return __INSTALLED_VCS_RUN
+
+def get_installed_vcs():
+ installed_versions = []
+ for ver in _VCVER:
+ debug('trying to find VC %s' % ver)
+ try:
+ if find_vc_pdir(ver):
+ debug('found VC %s' % ver)
+ installed_versions.append(ver)
+ else:
+ debug('find_vc_pdir return None for ver %s' % ver)
+ except VisualCException, e:
+ debug('did not find VC %s: caught exception %s' % (ver, str(e)))
+ return installed_versions
+
+def reset_installed_vcs():
+ """Make it try again to find VC. This is just for the tests."""
+ __INSTALLED_VCS_RUN = None
+
+def script_env(script, args=None):
+ stdout = common.get_output(script, args)
+ # Stupid batch files do not set return code: we take a look at the
+ # beginning of the output for an error message instead
+ olines = stdout.splitlines()
+ if olines[0].startswith("The specified configuration type is missing"):
+ raise BatchFileExecutionError("\n".join(olines[:2]))
+
+ return common.parse_output(stdout)
+
+def get_default_version(env):
+ debug('get_default_version()')
+
+ msvc_version = env.get('MSVC_VERSION')
+ msvs_version = env.get('MSVS_VERSION')
+
+ debug('get_default_version(): msvc_version:%s msvs_version:%s'%(msvc_version,msvs_version))
+
+ if msvs_version and not msvc_version:
+ SCons.Warnings.warn(
+ SCons.Warnings.DeprecatedWarning,
+ "MSVS_VERSION is deprecated: please use MSVC_VERSION instead ")
+ return msvs_version
+ elif msvc_version and msvs_version:
+ if not msvc_version == msvs_version:
+ SCons.Warnings.warn(
+ SCons.Warnings.VisualVersionMismatch,
+ "Requested msvc version (%s) and msvs version (%s) do " \
+ "not match: please use MSVC_VERSION only to request a " \
+ "visual studio version, MSVS_VERSION is deprecated" \
+ % (msvc_version, msvs_version))
+ return msvs_version
+ if not msvc_version:
+ installed_vcs = cached_get_installed_vcs()
+ debug('installed_vcs:%s' % installed_vcs)
+ if not installed_vcs:
+ msg = 'No installed VCs'
+ debug('msv %s\n' % repr(msg))
+ SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning, msg)
+ return None
+ msvc_version = installed_vcs[0]
+ debug('msvc_setup_env: using default installed MSVC version %s\n' % repr(msvc_version))
+
+ return msvc_version
+
+def msvc_setup_env_once(env):
+ try:
+ has_run = env["MSVC_SETUP_RUN"]
+ except KeyError:
+ has_run = False
+
+ if not has_run:
+ msvc_setup_env(env)
+ env["MSVC_SETUP_RUN"] = True
+
+def msvc_find_valid_batch_script(env,version):
+ debug('vc.py:msvc_find_valid_batch_script()')
+ # Find the host platform, target platform, and if present the requested
+ # target platform
+ (host_platform, target_platform,req_target_platform) = get_host_target(env)
+
+ # If the user hasn't specifically requested a TARGET_ARCH, and
+ # The TARGET_ARCH is amd64 then also try 32 bits if there are no viable
+ # 64 bit tools installed
+ try_target_archs = [target_platform]
+ if not req_target_platform and target_platform=='amd64':
+ try_target_archs.append('x86')
+
+ d = None
+ for tp in try_target_archs:
+ # Set to current arch.
+ env['TARGET_ARCH']=tp
+
+ debug("vc.py:msvc_find_valid_batch_script() trying target_platform:%s"%tp)
+ host_target = (host_platform, tp)
+ if not is_host_target_supported(host_target, version):
+ warn_msg = "host, target = %s not supported for MSVC version %s" % \
+ (host_target, version)
+ SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning, warn_msg)
+ arg = _HOST_TARGET_ARCH_TO_BAT_ARCH[host_target]
+
+ # Try to locate a batch file for this host/target platform combo
+ try:
+ (vc_script,sdk_script) = find_batch_file(env,version,host_platform,tp)
+ debug('vc.py:msvc_find_valid_batch_script() vc_script:%s sdk_script:%s'%(vc_script,sdk_script))
+ except VisualCException, e:
+ msg = str(e)
+ debug('Caught exception while looking for batch file (%s)' % msg)
+ warn_msg = "VC version %s not installed. " + \
+ "C/C++ compilers are most likely not set correctly.\n" + \
+ " Installed versions are: %s"
+ warn_msg = warn_msg % (version, cached_get_installed_vcs())
+ SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning, warn_msg)
+ continue
+
+ # Try to use the located batch file for this host/target platform combo
+ debug('vc.py:msvc_find_valid_batch_script() use_script 2 %s, args:%s\n' % (repr(vc_script), arg))
+ if vc_script:
+ try:
+ d = script_env(vc_script, args=arg)
+ except BatchFileExecutionError, e:
+ debug('vc.py:msvc_find_valid_batch_script() use_script 3: failed running VC script %s: %s: Error:%s'%(repr(vc_script),arg,e))
+ vc_script=None
+ if not vc_script and sdk_script:
+ debug('vc.py:msvc_find_valid_batch_script() use_script 4: trying sdk script: %s'%(sdk_script))
+ try:
+ d = script_env(sdk_script,args=[])
+ except BatchFileExecutionError,e:
+ debug('vc.py:msvc_find_valid_batch_script() use_script 5: failed running SDK script %s: Error:%s'%(repr(sdk_script),e))
+ continue
+ elif not vc_script and not sdk_script:
+ debug('vc.py:msvc_find_valid_batch_script() use_script 6: Neither VC script nor SDK script found')
+ continue
+
+ # If we cannot find a viable installed compiler, reset the TARGET_ARCH
+ # To it's initial value
+ if not d:
+ env['TARGET_ARCH']=req_target_platform
+
+ return d
+
+
+def msvc_setup_env(env):
+ debug('msvc_setup_env()')
+
+ version = get_default_version(env)
+ if version is None:
+ warn_msg = "No version of Visual Studio compiler found - C/C++ " \
+ "compilers most likely not set correctly"
+ SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning, warn_msg)
+ return None
+ debug('msvc_setup_env: using specified MSVC version %s\n' % repr(version))
+
+ # XXX: we set-up both MSVS version for backward
+ # compatibility with the msvs tool
+ env['MSVC_VERSION'] = version
+ env['MSVS_VERSION'] = version
+ env['MSVS'] = {}
+
+
+ use_script = env.get('MSVC_USE_SCRIPT', True)
+ if SCons.Util.is_String(use_script):
+ debug('vc.py:msvc_setup_env() use_script 1 %s\n' % repr(use_script))
+ d = script_env(use_script)
+ elif use_script:
+ d = msvc_find_valid_batch_script(env,version)
+ debug('vc.py:msvc_setup_env() use_script 2 %s\n' % d)
+ if not d:
+ return d
+ else:
+ debug('MSVC_USE_SCRIPT set to False')
+ warn_msg = "MSVC_USE_SCRIPT set to False, assuming environment " \
+ "set correctly."
+ SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning, warn_msg)
+ return None
+
+ for k, v in d.items():
+ debug('vc.py:msvc_setup_env() env:%s -> %s'%(k,v))
+ env.PrependENVPath(k, v, delete_existing=True)
+
+def msvc_exists(version=None):
+ vcs = cached_get_installed_vcs()
+ if version is None:
+ return len(vcs) > 0
+ return version in vcs
+
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/vs.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/vs.py
new file mode 100644
index 00000000..529d443a
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/MSCommon/vs.py
@@ -0,0 +1,499 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/MSCommon/vs.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__doc__ = """Module to detect Visual Studio and/or Visual C/C++
+"""
+
+import os
+
+import SCons.Errors
+import SCons.Util
+
+from common import debug, \
+ get_output, \
+ is_win64, \
+ normalize_env, \
+ parse_output, \
+ read_reg
+
+import SCons.Tool.MSCommon.vc
+
+class VisualStudio(object):
+ """
+ An abstract base class for trying to find installed versions of
+ Visual Studio.
+ """
+ def __init__(self, version, **kw):
+ self.version = version
+ kw['vc_version'] = kw.get('vc_version', version)
+ kw['sdk_version'] = kw.get('sdk_version', version)
+ self.__dict__.update(kw)
+ self._cache = {}
+
+ #
+
+ def find_batch_file(self):
+ vs_dir = self.get_vs_dir()
+ if not vs_dir:
+ debug('find_executable(): no vs_dir')
+ return None
+ batch_file = os.path.join(vs_dir, self.batch_file_path)
+ batch_file = os.path.normpath(batch_file)
+ if not os.path.isfile(batch_file):
+ debug('find_batch_file(): %s not on file system' % batch_file)
+ return None
+ return batch_file
+
+ def find_vs_dir_by_vc(self):
+ SCons.Tool.MSCommon.vc.get_installed_vcs()
+ dir = SCons.Tool.MSCommon.vc.find_vc_pdir(self.vc_version)
+ if not dir:
+ debug('find_vs_dir(): no installed VC %s' % self.vc_version)
+ return None
+ return dir
+
+ def find_vs_dir_by_reg(self):
+ root = 'Software\\'
+
+ if is_win64():
+ root = root + 'Wow6432Node\\'
+ for key in self.hkeys:
+ if key=='use_dir':
+ return self.find_vs_dir_by_vc()
+ key = root + key
+ try:
+ comps = read_reg(key)
+ except WindowsError, e:
+ debug('find_vs_dir_by_reg(): no VS registry key %s' % repr(key))
+ else:
+ debug('find_vs_dir_by_reg(): found VS in registry: %s' % comps)
+ return comps
+ return None
+
+ def find_vs_dir(self):
+ """ Can use registry or location of VC to find vs dir
+ First try to find by registry, and if that fails find via VC dir
+ """
+
+
+ if True:
+ vs_dir=self.find_vs_dir_by_reg()
+ return vs_dir
+ else:
+ return self.find_vs_dir_by_vc()
+
+ def find_executable(self):
+ vs_dir = self.get_vs_dir()
+ if not vs_dir:
+ debug('find_executable(): no vs_dir (%s)'%vs_dir)
+ return None
+ executable = os.path.join(vs_dir, self.executable_path)
+ executable = os.path.normpath(executable)
+ if not os.path.isfile(executable):
+ debug('find_executable(): %s not on file system' % executable)
+ return None
+ return executable
+
+ #
+
+ def get_batch_file(self):
+ try:
+ return self._cache['batch_file']
+ except KeyError:
+ batch_file = self.find_batch_file()
+ self._cache['batch_file'] = batch_file
+ return batch_file
+
+ def get_executable(self):
+ try:
+ debug('get_executable using cache:%s'%self._cache['executable'])
+ return self._cache['executable']
+ except KeyError:
+ executable = self.find_executable()
+ self._cache['executable'] = executable
+ debug('get_executable not in cache:%s'%executable)
+ return executable
+
+ def get_vs_dir(self):
+ try:
+ return self._cache['vs_dir']
+ except KeyError:
+ vs_dir = self.find_vs_dir()
+ self._cache['vs_dir'] = vs_dir
+ return vs_dir
+
+ def get_supported_arch(self):
+ try:
+ return self._cache['supported_arch']
+ except KeyError:
+ # RDEVE: for the time being use hardcoded lists
+ # supported_arch = self.find_supported_arch()
+ self._cache['supported_arch'] = self.supported_arch
+ return self.supported_arch
+
+ def reset(self):
+ self._cache = {}
+
+# The list of supported Visual Studio versions we know how to detect.
+#
+# How to look for .bat file ?
+# - VS 2008 Express (x86):
+# * from registry key productdir, gives the full path to vsvarsall.bat. In
+# HKEY_LOCAL_MACHINE):
+# Software\Microsoft\VCEpress\9.0\Setup\VC\productdir
+# * from environmnent variable VS90COMNTOOLS: the path is then ..\..\VC
+# relatively to the path given by the variable.
+#
+# - VS 2008 Express (WoW6432: 32 bits on windows x64):
+# Software\Wow6432Node\Microsoft\VCEpress\9.0\Setup\VC\productdir
+#
+# - VS 2005 Express (x86):
+# * from registry key productdir, gives the full path to vsvarsall.bat. In
+# HKEY_LOCAL_MACHINE):
+# Software\Microsoft\VCEpress\8.0\Setup\VC\productdir
+# * from environmnent variable VS80COMNTOOLS: the path is then ..\..\VC
+# relatively to the path given by the variable.
+#
+# - VS 2005 Express (WoW6432: 32 bits on windows x64): does not seem to have a
+# productdir ?
+#
+# - VS 2003 .Net (pro edition ? x86):
+# * from registry key productdir. The path is then ..\Common7\Tools\
+# relatively to the key. The key is in HKEY_LOCAL_MACHINE):
+# Software\Microsoft\VisualStudio\7.1\Setup\VC\productdir
+# * from environmnent variable VS71COMNTOOLS: the path is the full path to
+# vsvars32.bat
+#
+# - VS 98 (VS 6):
+# * from registry key productdir. The path is then Bin
+# relatively to the key. The key is in HKEY_LOCAL_MACHINE):
+# Software\Microsoft\VisualStudio\6.0\Setup\VC98\productdir
+#
+# The first version found in the list is the one used by default if
+# there are multiple versions installed. Barring good reasons to
+# the contrary, this means we should list versions from most recent
+# to oldest. Pro versions get listed before Express versions on the
+# assumption that, by default, you'd rather use the version you paid
+# good money for in preference to whatever Microsoft makes available
+# for free.
+#
+# If you update this list, update the documentation in Tool/msvs.xml.
+
+SupportedVSList = [
+ # Visual Studio 2010
+ # TODO: find the settings, perhaps from someone with a CTP copy?
+ #VisualStudio('TBD',
+ # hkey_root=r'TBD',
+ # common_tools_var='TBD',
+ # executable_path=r'TBD',
+ # default_dirname='TBD',
+ #),
+
+ # Visual Studio 2008
+ # The batch file we look for is in the VC directory,
+ # so the devenv.com executable is up in ..\..\Common7\IDE.
+ VisualStudio('9.0',
+ sdk_version='6.1',
+ hkeys=[r'Microsoft\VisualStudio\9.0\Setup\VS\ProductDir'],
+ common_tools_var='VS90COMNTOOLS',
+ executable_path=r'Common7\IDE\devenv.com',
+ batch_file_path=r'Common7\Tools\vsvars32.bat',
+ default_dirname='Microsoft Visual Studio 9',
+ supported_arch=['x86', 'amd64'],
+ ),
+
+ # Visual C++ 2008 Express Edition
+ # The batch file we look for is in the VC directory,
+ # so the VCExpress.exe executable is up in ..\..\Common7\IDE.
+ VisualStudio('9.0Exp',
+ vc_version='9.0',
+ sdk_version='6.1',
+ hkeys=[r'Microsoft\VCExpress\9.0\Setup\VS\ProductDir'],
+ common_tools_var='VS90COMNTOOLS',
+ executable_path=r'Common7\IDE\VCExpress.exe',
+ batch_file_path=r'Common7\Tools\vsvars32.bat',
+ default_dirname='Microsoft Visual Studio 9',
+ supported_arch=['x86'],
+ ),
+
+ # Visual Studio 2005
+ # The batch file we look for is in the VC directory,
+ # so the devenv.com executable is up in ..\..\Common7\IDE.
+ VisualStudio('8.0',
+ sdk_version='6.0A',
+ hkeys=[r'Microsoft\VisualStudio\8.0\Setup\VS\ProductDir'],
+ common_tools_var='VS80COMNTOOLS',
+ executable_path=r'Common7\IDE\devenv.com',
+ batch_file_path=r'Common7\Tools\vsvars32.bat',
+ default_dirname='Microsoft Visual Studio 8',
+ supported_arch=['x86', 'amd64'],
+ ),
+
+ # Visual C++ 2005 Express Edition
+ # The batch file we look for is in the VC directory,
+ # so the VCExpress.exe executable is up in ..\..\Common7\IDE.
+ VisualStudio('8.0Exp',
+ vc_version='8.0Exp',
+ sdk_version='6.0A',
+ hkeys=[r'Microsoft\VCExpress\8.0\Setup\VS\ProductDir'],
+ common_tools_var='VS80COMNTOOLS',
+ executable_path=r'Common7\IDE\VCExpress.exe',
+ batch_file_path=r'Common7\Tools\vsvars32.bat',
+ default_dirname='Microsoft Visual Studio 8',
+ supported_arch=['x86'],
+ ),
+
+ # Visual Studio .NET 2003
+ # The batch file we look for is in the Common7\Tools directory,
+ # so the devenv.com executable is next door in ..\IDE.
+ VisualStudio('7.1',
+ sdk_version='6.0',
+ hkeys=[r'Microsoft\VisualStudio\7.1\Setup\VS\ProductDir'],
+ common_tools_var='VS71COMNTOOLS',
+ executable_path=r'Common7\IDE\devenv.com',
+ batch_file_path=r'Common7\Tools\vsvars32.bat',
+ default_dirname='Microsoft Visual Studio .NET 2003',
+ supported_arch=['x86'],
+ ),
+
+ # Visual Studio .NET
+ # The batch file we look for is in the Common7\Tools directory,
+ # so the devenv.com executable is next door in ..\IDE.
+ VisualStudio('7.0',
+ sdk_version='2003R2',
+ hkeys=[r'Microsoft\VisualStudio\7.0\Setup\VS\ProductDir'],
+ common_tools_var='VS70COMNTOOLS',
+ executable_path=r'IDE\devenv.com',
+ batch_file_path=r'Common7\Tools\vsvars32.bat',
+ default_dirname='Microsoft Visual Studio .NET',
+ supported_arch=['x86'],
+ ),
+
+ # Visual Studio 6.0
+ VisualStudio('6.0',
+ sdk_version='2003R1',
+ hkeys=[r'Microsoft\VisualStudio\6.0\Setup\Microsoft Visual Studio\ProductDir',
+ 'use_dir'],
+ common_tools_var='VS60COMNTOOLS',
+ executable_path=r'Common\MSDev98\Bin\MSDEV.COM',
+ batch_file_path=r'Common7\Tools\vsvars32.bat',
+ default_dirname='Microsoft Visual Studio',
+ supported_arch=['x86'],
+ ),
+]
+
+SupportedVSMap = {}
+for vs in SupportedVSList:
+ SupportedVSMap[vs.version] = vs
+
+
+# Finding installed versions of Visual Studio isn't cheap, because it
+# goes not only to the registry but also to the disk to sanity-check
+# that there is, in fact, a Visual Studio directory there and that the
+# registry entry isn't just stale. Find this information once, when
+# requested, and cache it.
+
+InstalledVSList = None
+InstalledVSMap = None
+
+def get_installed_visual_studios():
+ global InstalledVSList
+ global InstalledVSMap
+ if InstalledVSList is None:
+ InstalledVSList = []
+ InstalledVSMap = {}
+ for vs in SupportedVSList:
+ debug('trying to find VS %s' % vs.version)
+ if vs.get_executable():
+ debug('found VS %s' % vs.version)
+ InstalledVSList.append(vs)
+ InstalledVSMap[vs.version] = vs
+ return InstalledVSList
+
+def reset_installed_visual_studios():
+ global InstalledVSList
+ global InstalledVSMap
+ InstalledVSList = None
+ InstalledVSMap = None
+ for vs in SupportedVSList:
+ vs.reset()
+
+ # Need to clear installed VC's as well as they are used in finding
+ # installed VS's
+ SCons.Tool.MSCommon.vc.reset_installed_vcs()
+
+
+# We may be asked to update multiple construction environments with
+# SDK information. When doing this, we check on-disk for whether
+# the SDK has 'mfc' and 'atl' subdirectories. Since going to disk
+# is expensive, cache results by directory.
+
+#SDKEnvironmentUpdates = {}
+#
+#def set_sdk_by_directory(env, sdk_dir):
+# global SDKEnvironmentUpdates
+# try:
+# env_tuple_list = SDKEnvironmentUpdates[sdk_dir]
+# except KeyError:
+# env_tuple_list = []
+# SDKEnvironmentUpdates[sdk_dir] = env_tuple_list
+#
+# include_path = os.path.join(sdk_dir, 'include')
+# mfc_path = os.path.join(include_path, 'mfc')
+# atl_path = os.path.join(include_path, 'atl')
+#
+# if os.path.exists(mfc_path):
+# env_tuple_list.append(('INCLUDE', mfc_path))
+# if os.path.exists(atl_path):
+# env_tuple_list.append(('INCLUDE', atl_path))
+# env_tuple_list.append(('INCLUDE', include_path))
+#
+# env_tuple_list.append(('LIB', os.path.join(sdk_dir, 'lib')))
+# env_tuple_list.append(('LIBPATH', os.path.join(sdk_dir, 'lib')))
+# env_tuple_list.append(('PATH', os.path.join(sdk_dir, 'bin')))
+#
+# for variable, directory in env_tuple_list:
+# env.PrependENVPath(variable, directory)
+
+def msvs_exists():
+ return (len(get_installed_visual_studios()) > 0)
+
+def get_vs_by_version(msvs):
+ global InstalledVSMap
+ global SupportedVSMap
+
+ debug('vs.py:get_vs_by_version()')
+ if msvs not in SupportedVSMap:
+ msg = "Visual Studio version %s is not supported" % repr(msvs)
+ raise SCons.Errors.UserError(msg)
+ get_installed_visual_studios()
+ vs = InstalledVSMap.get(msvs)
+ debug('InstalledVSMap:%s'%InstalledVSMap)
+ debug('vs.py:get_vs_by_version: found vs:%s'%vs)
+ # Some check like this would let us provide a useful error message
+ # if they try to set a Visual Studio version that's not installed.
+ # However, we also want to be able to run tests (like the unit
+ # tests) on systems that don't, or won't ever, have it installed.
+ # It might be worth resurrecting this, with some configurable
+ # setting that the tests can use to bypass the check.
+ #if not vs:
+ # msg = "Visual Studio version %s is not installed" % repr(msvs)
+ # raise SCons.Errors.UserError, msg
+ return vs
+
+def get_default_version(env):
+ """Returns the default version string to use for MSVS.
+
+ If no version was requested by the user through the MSVS environment
+ variable, query all the available the visual studios through
+ query_versions, and take the highest one.
+
+ Return
+ ------
+ version: str
+ the default version.
+ """
+ if 'MSVS' not in env or not SCons.Util.is_Dict(env['MSVS']):
+ versions = [vs.version for vs in get_installed_visual_studios()]
+ env['MSVS'] = {'VERSIONS' : versions}
+ else:
+ versions = env['MSVS'].get('VERSIONS', [])
+
+ if 'MSVS_VERSION' not in env:
+ if versions:
+ env['MSVS_VERSION'] = versions[0] #use highest version by default
+ else:
+ env['MSVS_VERSION'] = SupportedVSList[0].version
+
+ env['MSVS']['VERSION'] = env['MSVS_VERSION']
+
+ return env['MSVS_VERSION']
+
+def get_default_arch(env):
+ """Return the default arch to use for MSVS
+
+ if no version was requested by the user through the MSVS_ARCH environment
+ variable, select x86
+
+ Return
+ ------
+ arch: str
+ """
+ arch = env.get('MSVS_ARCH', 'x86')
+
+ msvs = InstalledVSMap.get(env['MSVS_VERSION'])
+
+ if not msvs:
+ arch = 'x86'
+ elif not arch in msvs.get_supported_arch():
+ fmt = "Visual Studio version %s does not support architecture %s"
+ raise SCons.Errors.UserError(fmt % (env['MSVS_VERSION'], arch))
+
+ return arch
+
+def merge_default_version(env):
+ version = get_default_version(env)
+ arch = get_default_arch(env)
+
+def msvs_setup_env(env):
+ batfilename = msvs.get_batch_file()
+ msvs = get_vs_by_version(version)
+ if msvs is None:
+ return
+
+ # XXX: I think this is broken. This will silently set a bogus tool instead
+ # of failing, but there is no other way with the current scons tool
+ # framework
+ if batfilename is not None:
+
+ vars = ('LIB', 'LIBPATH', 'PATH', 'INCLUDE')
+
+ msvs_list = get_installed_visual_studios()
+ vscommonvarnames = [vs.common_tools_var for vs in msvs_list]
+ save_ENV = env['ENV']
+ nenv = normalize_env(env['ENV'],
+ ['COMSPEC'] + vscommonvarnames,
+ force=True)
+ try:
+ output = get_output(batfilename, arch, env=nenv)
+ finally:
+ env['ENV'] = save_ENV
+ vars = parse_output(output, vars)
+
+ for k, v in vars.items():
+ env.PrependENVPath(k, v, delete_existing=1)
+
+def query_versions():
+ """Query the system to get available versions of VS. A version is
+ considered when a batfile is found."""
+ msvs_list = get_installed_visual_studios()
+ versions = [msvs.version for msvs in msvs_list]
+ return versions
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/Perforce.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/Perforce.py
new file mode 100644
index 00000000..9ae64b87
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/Perforce.py
@@ -0,0 +1,103 @@
+"""SCons.Tool.Perforce.py
+
+Tool-specific initialization for Perforce Source Code Management system.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Tool/Perforce.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+
+import SCons.Action
+import SCons.Builder
+import SCons.Node.FS
+import SCons.Util
+
+# This function should maybe be moved to SCons.Util?
+from SCons.Tool.PharLapCommon import addPathIfNotExists
+
+
+# Variables that we want to import from the base OS environment.
+_import_env = [ 'P4PORT', 'P4CLIENT', 'P4USER', 'USER', 'USERNAME', 'P4PASSWD',
+ 'P4CHARSET', 'P4LANGUAGE', 'SystemRoot' ]
+
+PerforceAction = SCons.Action.Action('$P4COM', '$P4COMSTR')
+
+def generate(env):
+ """Add a Builder factory function and construction variables for
+ Perforce to an Environment."""
+
+ def PerforceFactory(env=env):
+ """ """
+ import SCons.Warnings as W
+ W.warn(W.DeprecatedSourceCodeWarning, """The Perforce() factory is deprecated and there is no replacement.""")
+ return SCons.Builder.Builder(action = PerforceAction, env = env)
+
+ #setattr(env, 'Perforce', PerforceFactory)
+ env.Perforce = PerforceFactory
+
+ env['P4'] = 'p4'
+ env['P4FLAGS'] = SCons.Util.CLVar('')
+ env['P4COM'] = '$P4 $P4FLAGS sync $TARGET'
+ try:
+ environ = env['ENV']
+ except KeyError:
+ environ = {}
+ env['ENV'] = environ
+
+ # Perforce seems to use the PWD environment variable rather than
+ # calling getcwd() for itself, which is odd. If no PWD variable
+ # is present, p4 WILL call getcwd, but this seems to cause problems
+ # with good ol' Windows's tilde-mangling for long file names.
+ environ['PWD'] = env.Dir('#').get_abspath()
+
+ for var in _import_env:
+ v = os.environ.get(var)
+ if v:
+ environ[var] = v
+
+ if SCons.Util.can_read_reg:
+ # If we can read the registry, add the path to Perforce to our environment.
+ try:
+ k=SCons.Util.RegOpenKeyEx(SCons.Util.hkey_mod.HKEY_LOCAL_MACHINE,
+ 'Software\\Perforce\\environment')
+ val, tok = SCons.Util.RegQueryValueEx(k, 'P4INSTROOT')
+ addPathIfNotExists(environ, 'PATH', val)
+ except SCons.Util.RegError:
+ # Can't detect where Perforce is, hope the user has it set in the
+ # PATH.
+ pass
+
+def exists(env):
+ return env.Detect('p4')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/PharLapCommon.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/PharLapCommon.py
new file mode 100644
index 00000000..7d7a0225
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/PharLapCommon.py
@@ -0,0 +1,137 @@
+"""SCons.Tool.PharLapCommon
+
+This module contains common code used by all Tools for the
+Phar Lap ETS tool chain. Right now, this is linkloc and
+386asm.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/PharLapCommon.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+import os.path
+import SCons.Errors
+import SCons.Util
+import re
+
+def getPharLapPath():
+ """Reads the registry to find the installed path of the Phar Lap ETS
+ development kit.
+
+ Raises UserError if no installed version of Phar Lap can
+ be found."""
+
+ if not SCons.Util.can_read_reg:
+ raise SCons.Errors.InternalError("No Windows registry module was found")
+ try:
+ k=SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE,
+ 'SOFTWARE\\Pharlap\\ETS')
+ val, type = SCons.Util.RegQueryValueEx(k, 'BaseDir')
+
+ # The following is a hack...there is (not surprisingly)
+ # an odd issue in the Phar Lap plug in that inserts
+ # a bunch of junk data after the phar lap path in the
+ # registry. We must trim it.
+ idx=val.find('\0')
+ if idx >= 0:
+ val = val[:idx]
+
+ return os.path.normpath(val)
+ except SCons.Util.RegError:
+ raise SCons.Errors.UserError("Cannot find Phar Lap ETS path in the registry. Is it installed properly?")
+
+REGEX_ETS_VER = re.compile(r'#define\s+ETS_VER\s+([0-9]+)')
+
+def getPharLapVersion():
+ """Returns the version of the installed ETS Tool Suite as a
+ decimal number. This version comes from the ETS_VER #define in
+ the embkern.h header. For example, '#define ETS_VER 1010' (which
+ is what Phar Lap 10.1 defines) would cause this method to return
+ 1010. Phar Lap 9.1 does not have such a #define, but this method
+ will return 910 as a default.
+
+ Raises UserError if no installed version of Phar Lap can
+ be found."""
+
+ include_path = os.path.join(getPharLapPath(), os.path.normpath("include/embkern.h"))
+ if not os.path.exists(include_path):
+ raise SCons.Errors.UserError("Cannot find embkern.h in ETS include directory.\nIs Phar Lap ETS installed properly?")
+ mo = REGEX_ETS_VER.search(open(include_path, 'r').read())
+ if mo:
+ return int(mo.group(1))
+ # Default return for Phar Lap 9.1
+ return 910
+
+def addPathIfNotExists(env_dict, key, path, sep=os.pathsep):
+ """This function will take 'key' out of the dictionary
+ 'env_dict', then add the path 'path' to that key if it is not
+ already there. This treats the value of env_dict[key] as if it
+ has a similar format to the PATH variable...a list of paths
+ separated by tokens. The 'path' will get added to the list if it
+ is not already there."""
+ try:
+ is_list = 1
+ paths = env_dict[key]
+ if not SCons.Util.is_List(env_dict[key]):
+ paths = paths.split(sep)
+ is_list = 0
+ if os.path.normcase(path) not in list(map(os.path.normcase, paths)):
+ paths = [ path ] + paths
+ if is_list:
+ env_dict[key] = paths
+ else:
+ env_dict[key] = sep.join(paths)
+ except KeyError:
+ env_dict[key] = path
+
+def addPharLapPaths(env):
+ """This function adds the path to the Phar Lap binaries, includes,
+ and libraries, if they are not already there."""
+ ph_path = getPharLapPath()
+
+ try:
+ env_dict = env['ENV']
+ except KeyError:
+ env_dict = {}
+ env['ENV'] = env_dict
+ addPathIfNotExists(env_dict, 'PATH',
+ os.path.join(ph_path, 'bin'))
+ addPathIfNotExists(env_dict, 'INCLUDE',
+ os.path.join(ph_path, 'include'))
+ addPathIfNotExists(env_dict, 'LIB',
+ os.path.join(ph_path, 'lib'))
+ addPathIfNotExists(env_dict, 'LIB',
+ os.path.join(ph_path, os.path.normpath('lib/vclib')))
+
+ env['PHARLAP_PATH'] = getPharLapPath()
+ env['PHARLAP_VERSION'] = str(getPharLapVersion())
+
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/RCS.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/RCS.py
new file mode 100644
index 00000000..10e3e715
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/RCS.py
@@ -0,0 +1,64 @@
+"""SCons.Tool.RCS.py
+
+Tool-specific initialization for RCS.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Tool/RCS.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Action
+import SCons.Builder
+import SCons.Util
+
+def generate(env):
+ """Add a Builder factory function and construction variables for
+ RCS to an Environment."""
+
+ def RCSFactory(env=env):
+ """ """
+ import SCons.Warnings as W
+ W.warn(W.DeprecatedSourceCodeWarning, """The RCS() factory is deprecated and there is no replacement.""")
+ act = SCons.Action.Action('$RCS_COCOM', '$RCS_COCOMSTR')
+ return SCons.Builder.Builder(action = act, env = env)
+
+ #setattr(env, 'RCS', RCSFactory)
+ env.RCS = RCSFactory
+
+ env['RCS'] = 'rcs'
+ env['RCS_CO'] = 'co'
+ env['RCS_COFLAGS'] = SCons.Util.CLVar('')
+ env['RCS_COCOM'] = '$RCS_CO $RCS_COFLAGS $TARGET'
+
+def exists(env):
+ return env.Detect('rcs')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/SCCS.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/SCCS.py
new file mode 100644
index 00000000..1cedb0ad
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/SCCS.py
@@ -0,0 +1,64 @@
+"""SCons.Tool.SCCS.py
+
+Tool-specific initialization for SCCS.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Tool/SCCS.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Action
+import SCons.Builder
+import SCons.Util
+
+def generate(env):
+ """Add a Builder factory function and construction variables for
+ SCCS to an Environment."""
+
+ def SCCSFactory(env=env):
+ """ """
+ import SCons.Warnings as W
+ W.warn(W.DeprecatedSourceCodeWarning, """The SCCS() factory is deprecated and there is no replacement.""")
+ act = SCons.Action.Action('$SCCSCOM', '$SCCSCOMSTR')
+ return SCons.Builder.Builder(action = act, env = env)
+
+ #setattr(env, 'SCCS', SCCSFactory)
+ env.SCCS = SCCSFactory
+
+ env['SCCS'] = 'sccs'
+ env['SCCSFLAGS'] = SCons.Util.CLVar('')
+ env['SCCSGETFLAGS'] = SCons.Util.CLVar('')
+ env['SCCSCOM'] = '$SCCS $SCCSFLAGS get $SCCSGETFLAGS $TARGET'
+
+def exists(env):
+ return env.Detect('sccs')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/Subversion.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/Subversion.py
new file mode 100644
index 00000000..57081846
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/Subversion.py
@@ -0,0 +1,71 @@
+"""SCons.Tool.Subversion.py
+
+Tool-specific initialization for Subversion.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Tool/Subversion.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+
+import SCons.Action
+import SCons.Builder
+import SCons.Util
+
+def generate(env):
+ """Add a Builder factory function and construction variables for
+ Subversion to an Environment."""
+
+ def SubversionFactory(repos, module='', env=env):
+ """ """
+ # fail if repos is not an absolute path name?
+ import SCons.Warnings as W
+ W.warn(W.DeprecatedSourceCodeWarning, """The Subversion() factory is deprecated and there is no replacement.""")
+ if module != '':
+ module = os.path.join(module, '')
+ act = SCons.Action.Action('$SVNCOM', '$SVNCOMSTR')
+ return SCons.Builder.Builder(action = act,
+ env = env,
+ SVNREPOSITORY = repos,
+ SVNMODULE = module)
+
+ #setattr(env, 'Subversion', SubversionFactory)
+ env.Subversion = SubversionFactory
+
+ env['SVN'] = 'svn'
+ env['SVNFLAGS'] = SCons.Util.CLVar('')
+ env['SVNCOM'] = '$SVN $SVNFLAGS cat $SVNREPOSITORY/$SVNMODULE$TARGET > $TARGET'
+
+def exists(env):
+ return env.Detect('svn')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/__init__.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/__init__.py
new file mode 100644
index 00000000..416d8de2
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/__init__.py
@@ -0,0 +1,681 @@
+"""SCons.Tool
+
+SCons tool selection.
+
+This looks for modules that define a callable object that can modify
+a construction environment as appropriate for a given tool (or tool
+chain).
+
+Note that because this subsystem just *selects* a callable that can
+modify a construction environment, it's possible for people to define
+their own "tool specification" in an arbitrary callable function. No
+one needs to use or tie in to this subsystem in order to roll their own
+tool definition.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Tool/__init__.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import imp
+import sys
+
+import SCons.Builder
+import SCons.Errors
+import SCons.Node.FS
+import SCons.Scanner
+import SCons.Scanner.C
+import SCons.Scanner.D
+import SCons.Scanner.LaTeX
+import SCons.Scanner.Prog
+
+DefaultToolpath=[]
+
+CScanner = SCons.Scanner.C.CScanner()
+DScanner = SCons.Scanner.D.DScanner()
+LaTeXScanner = SCons.Scanner.LaTeX.LaTeXScanner()
+PDFLaTeXScanner = SCons.Scanner.LaTeX.PDFLaTeXScanner()
+ProgramScanner = SCons.Scanner.Prog.ProgramScanner()
+SourceFileScanner = SCons.Scanner.Base({}, name='SourceFileScanner')
+
+CSuffixes = [".c", ".C", ".cxx", ".cpp", ".c++", ".cc",
+ ".h", ".H", ".hxx", ".hpp", ".hh",
+ ".F", ".fpp", ".FPP",
+ ".m", ".mm",
+ ".S", ".spp", ".SPP"]
+
+DSuffixes = ['.d']
+
+IDLSuffixes = [".idl", ".IDL"]
+
+LaTeXSuffixes = [".tex", ".ltx", ".latex"]
+
+for suffix in CSuffixes:
+ SourceFileScanner.add_scanner(suffix, CScanner)
+
+for suffix in DSuffixes:
+ SourceFileScanner.add_scanner(suffix, DScanner)
+
+# FIXME: what should be done here? Two scanners scan the same extensions,
+# but look for different files, e.g., "picture.eps" vs. "picture.pdf".
+# The builders for DVI and PDF explicitly reference their scanners
+# I think that means this is not needed???
+for suffix in LaTeXSuffixes:
+ SourceFileScanner.add_scanner(suffix, LaTeXScanner)
+ SourceFileScanner.add_scanner(suffix, PDFLaTeXScanner)
+
+class Tool(object):
+ def __init__(self, name, toolpath=[], **kw):
+ self.name = name
+ self.toolpath = toolpath + DefaultToolpath
+ # remember these so we can merge them into the call
+ self.init_kw = kw
+
+ module = self._tool_module()
+ self.generate = module.generate
+ self.exists = module.exists
+ if hasattr(module, 'options'):
+ self.options = module.options
+
+ def _tool_module(self):
+ # TODO: Interchange zipimport with normal initilization for better error reporting
+ oldpythonpath = sys.path
+ sys.path = self.toolpath + sys.path
+
+ try:
+ try:
+ file, path, desc = imp.find_module(self.name, self.toolpath)
+ try:
+ return imp.load_module(self.name, file, path, desc)
+ finally:
+ if file:
+ file.close()
+ except ImportError, e:
+ if str(e)!="No module named %s"%self.name:
+ raise SCons.Errors.EnvironmentError(e)
+ try:
+ import zipimport
+ except ImportError:
+ pass
+ else:
+ for aPath in self.toolpath:
+ try:
+ importer = zipimport.zipimporter(aPath)
+ return importer.load_module(self.name)
+ except ImportError, e:
+ pass
+ finally:
+ sys.path = oldpythonpath
+
+ full_name = 'SCons.Tool.' + self.name
+ try:
+ return sys.modules[full_name]
+ except KeyError:
+ try:
+ smpath = sys.modules['SCons.Tool'].__path__
+ try:
+ file, path, desc = imp.find_module(self.name, smpath)
+ module = imp.load_module(full_name, file, path, desc)
+ setattr(SCons.Tool, self.name, module)
+ if file:
+ file.close()
+ return module
+ except ImportError, e:
+ if str(e)!="No module named %s"%self.name:
+ raise SCons.Errors.EnvironmentError(e)
+ try:
+ import zipimport
+ importer = zipimport.zipimporter( sys.modules['SCons.Tool'].__path__[0] )
+ module = importer.load_module(full_name)
+ setattr(SCons.Tool, self.name, module)
+ return module
+ except ImportError, e:
+ m = "No tool named '%s': %s" % (self.name, e)
+ raise SCons.Errors.EnvironmentError(m)
+ except ImportError, e:
+ m = "No tool named '%s': %s" % (self.name, e)
+ raise SCons.Errors.EnvironmentError(m)
+
+ def __call__(self, env, *args, **kw):
+ if self.init_kw is not None:
+ # Merge call kws into init kws;
+ # but don't bash self.init_kw.
+ if kw is not None:
+ call_kw = kw
+ kw = self.init_kw.copy()
+ kw.update(call_kw)
+ else:
+ kw = self.init_kw
+ env.Append(TOOLS = [ self.name ])
+ if hasattr(self, 'options'):
+ import SCons.Variables
+ if 'options' not in env:
+ from SCons.Script import ARGUMENTS
+ env['options']=SCons.Variables.Variables(args=ARGUMENTS)
+ opts=env['options']
+
+ self.options(opts)
+ opts.Update(env)
+
+ self.generate(env, *args, **kw)
+
+ def __str__(self):
+ return self.name
+
+##########################################################################
+# Create common executable program / library / object builders
+
+def createProgBuilder(env):
+ """This is a utility function that creates the Program
+ Builder in an Environment if it is not there already.
+
+ If it is already there, we return the existing one.
+ """
+
+ try:
+ program = env['BUILDERS']['Program']
+ except KeyError:
+ import SCons.Defaults
+ program = SCons.Builder.Builder(action = SCons.Defaults.LinkAction,
+ emitter = '$PROGEMITTER',
+ prefix = '$PROGPREFIX',
+ suffix = '$PROGSUFFIX',
+ src_suffix = '$OBJSUFFIX',
+ src_builder = 'Object',
+ target_scanner = ProgramScanner)
+ env['BUILDERS']['Program'] = program
+
+ return program
+
+def createStaticLibBuilder(env):
+ """This is a utility function that creates the StaticLibrary
+ Builder in an Environment if it is not there already.
+
+ If it is already there, we return the existing one.
+ """
+
+ try:
+ static_lib = env['BUILDERS']['StaticLibrary']
+ except KeyError:
+ action_list = [ SCons.Action.Action("$ARCOM", "$ARCOMSTR") ]
+ if env.Detect('ranlib'):
+ ranlib_action = SCons.Action.Action("$RANLIBCOM", "$RANLIBCOMSTR")
+ action_list.append(ranlib_action)
+
+ static_lib = SCons.Builder.Builder(action = action_list,
+ emitter = '$LIBEMITTER',
+ prefix = '$LIBPREFIX',
+ suffix = '$LIBSUFFIX',
+ src_suffix = '$OBJSUFFIX',
+ src_builder = 'StaticObject')
+ env['BUILDERS']['StaticLibrary'] = static_lib
+ env['BUILDERS']['Library'] = static_lib
+
+ return static_lib
+
+def createSharedLibBuilder(env):
+ """This is a utility function that creates the SharedLibrary
+ Builder in an Environment if it is not there already.
+
+ If it is already there, we return the existing one.
+ """
+
+ try:
+ shared_lib = env['BUILDERS']['SharedLibrary']
+ except KeyError:
+ import SCons.Defaults
+ action_list = [ SCons.Defaults.SharedCheck,
+ SCons.Defaults.ShLinkAction ]
+ shared_lib = SCons.Builder.Builder(action = action_list,
+ emitter = "$SHLIBEMITTER",
+ prefix = '$SHLIBPREFIX',
+ suffix = '$SHLIBSUFFIX',
+ target_scanner = ProgramScanner,
+ src_suffix = '$SHOBJSUFFIX',
+ src_builder = 'SharedObject')
+ env['BUILDERS']['SharedLibrary'] = shared_lib
+
+ return shared_lib
+
+def createLoadableModuleBuilder(env):
+ """This is a utility function that creates the LoadableModule
+ Builder in an Environment if it is not there already.
+
+ If it is already there, we return the existing one.
+ """
+
+ try:
+ ld_module = env['BUILDERS']['LoadableModule']
+ except KeyError:
+ import SCons.Defaults
+ action_list = [ SCons.Defaults.SharedCheck,
+ SCons.Defaults.LdModuleLinkAction ]
+ ld_module = SCons.Builder.Builder(action = action_list,
+ emitter = "$LDMODULEEMITTER",
+ prefix = '$LDMODULEPREFIX',
+ suffix = '$LDMODULESUFFIX',
+ target_scanner = ProgramScanner,
+ src_suffix = '$SHOBJSUFFIX',
+ src_builder = 'SharedObject')
+ env['BUILDERS']['LoadableModule'] = ld_module
+
+ return ld_module
+
+def createObjBuilders(env):
+ """This is a utility function that creates the StaticObject
+ and SharedObject Builders in an Environment if they
+ are not there already.
+
+ If they are there already, we return the existing ones.
+
+ This is a separate function because soooo many Tools
+ use this functionality.
+
+ The return is a 2-tuple of (StaticObject, SharedObject)
+ """
+
+
+ try:
+ static_obj = env['BUILDERS']['StaticObject']
+ except KeyError:
+ static_obj = SCons.Builder.Builder(action = {},
+ emitter = {},
+ prefix = '$OBJPREFIX',
+ suffix = '$OBJSUFFIX',
+ src_builder = ['CFile', 'CXXFile'],
+ source_scanner = SourceFileScanner,
+ single_source = 1)
+ env['BUILDERS']['StaticObject'] = static_obj
+ env['BUILDERS']['Object'] = static_obj
+
+ try:
+ shared_obj = env['BUILDERS']['SharedObject']
+ except KeyError:
+ shared_obj = SCons.Builder.Builder(action = {},
+ emitter = {},
+ prefix = '$SHOBJPREFIX',
+ suffix = '$SHOBJSUFFIX',
+ src_builder = ['CFile', 'CXXFile'],
+ source_scanner = SourceFileScanner,
+ single_source = 1)
+ env['BUILDERS']['SharedObject'] = shared_obj
+
+ return (static_obj, shared_obj)
+
+def createCFileBuilders(env):
+ """This is a utility function that creates the CFile/CXXFile
+ Builders in an Environment if they
+ are not there already.
+
+ If they are there already, we return the existing ones.
+
+ This is a separate function because soooo many Tools
+ use this functionality.
+
+ The return is a 2-tuple of (CFile, CXXFile)
+ """
+
+ try:
+ c_file = env['BUILDERS']['CFile']
+ except KeyError:
+ c_file = SCons.Builder.Builder(action = {},
+ emitter = {},
+ suffix = {None:'$CFILESUFFIX'})
+ env['BUILDERS']['CFile'] = c_file
+
+ env.SetDefault(CFILESUFFIX = '.c')
+
+ try:
+ cxx_file = env['BUILDERS']['CXXFile']
+ except KeyError:
+ cxx_file = SCons.Builder.Builder(action = {},
+ emitter = {},
+ suffix = {None:'$CXXFILESUFFIX'})
+ env['BUILDERS']['CXXFile'] = cxx_file
+ env.SetDefault(CXXFILESUFFIX = '.cc')
+
+ return (c_file, cxx_file)
+
+##########################################################################
+# Create common Java builders
+
+def CreateJarBuilder(env):
+ try:
+ java_jar = env['BUILDERS']['Jar']
+ except KeyError:
+ fs = SCons.Node.FS.get_default_fs()
+ jar_com = SCons.Action.Action('$JARCOM', '$JARCOMSTR')
+ java_jar = SCons.Builder.Builder(action = jar_com,
+ suffix = '$JARSUFFIX',
+ src_suffix = '$JAVACLASSSUFIX',
+ src_builder = 'JavaClassFile',
+ source_factory = fs.Entry)
+ env['BUILDERS']['Jar'] = java_jar
+ return java_jar
+
+def CreateJavaHBuilder(env):
+ try:
+ java_javah = env['BUILDERS']['JavaH']
+ except KeyError:
+ fs = SCons.Node.FS.get_default_fs()
+ java_javah_com = SCons.Action.Action('$JAVAHCOM', '$JAVAHCOMSTR')
+ java_javah = SCons.Builder.Builder(action = java_javah_com,
+ src_suffix = '$JAVACLASSSUFFIX',
+ target_factory = fs.Entry,
+ source_factory = fs.File,
+ src_builder = 'JavaClassFile')
+ env['BUILDERS']['JavaH'] = java_javah
+ return java_javah
+
+def CreateJavaClassFileBuilder(env):
+ try:
+ java_class_file = env['BUILDERS']['JavaClassFile']
+ except KeyError:
+ fs = SCons.Node.FS.get_default_fs()
+ javac_com = SCons.Action.Action('$JAVACCOM', '$JAVACCOMSTR')
+ java_class_file = SCons.Builder.Builder(action = javac_com,
+ emitter = {},
+ #suffix = '$JAVACLASSSUFFIX',
+ src_suffix = '$JAVASUFFIX',
+ src_builder = ['JavaFile'],
+ target_factory = fs.Entry,
+ source_factory = fs.File)
+ env['BUILDERS']['JavaClassFile'] = java_class_file
+ return java_class_file
+
+def CreateJavaClassDirBuilder(env):
+ try:
+ java_class_dir = env['BUILDERS']['JavaClassDir']
+ except KeyError:
+ fs = SCons.Node.FS.get_default_fs()
+ javac_com = SCons.Action.Action('$JAVACCOM', '$JAVACCOMSTR')
+ java_class_dir = SCons.Builder.Builder(action = javac_com,
+ emitter = {},
+ target_factory = fs.Dir,
+ source_factory = fs.Dir)
+ env['BUILDERS']['JavaClassDir'] = java_class_dir
+ return java_class_dir
+
+def CreateJavaFileBuilder(env):
+ try:
+ java_file = env['BUILDERS']['JavaFile']
+ except KeyError:
+ java_file = SCons.Builder.Builder(action = {},
+ emitter = {},
+ suffix = {None:'$JAVASUFFIX'})
+ env['BUILDERS']['JavaFile'] = java_file
+ env['JAVASUFFIX'] = '.java'
+ return java_file
+
+class ToolInitializerMethod(object):
+ """
+ This is added to a construction environment in place of a
+ method(s) normally called for a Builder (env.Object, env.StaticObject,
+ etc.). When called, it has its associated ToolInitializer
+ object search the specified list of tools and apply the first
+ one that exists to the construction environment. It then calls
+ whatever builder was (presumably) added to the construction
+ environment in place of this particular instance.
+ """
+ def __init__(self, name, initializer):
+ """
+ Note: we store the tool name as __name__ so it can be used by
+ the class that attaches this to a construction environment.
+ """
+ self.__name__ = name
+ self.initializer = initializer
+
+ def get_builder(self, env):
+ """
+ Returns the appropriate real Builder for this method name
+ after having the associated ToolInitializer object apply
+ the appropriate Tool module.
+ """
+ builder = getattr(env, self.__name__)
+
+ self.initializer.apply_tools(env)
+
+ builder = getattr(env, self.__name__)
+ if builder is self:
+ # There was no Builder added, which means no valid Tool
+ # for this name was found (or possibly there's a mismatch
+ # between the name we were called by and the Builder name
+ # added by the Tool module).
+ return None
+
+ self.initializer.remove_methods(env)
+
+ return builder
+
+ def __call__(self, env, *args, **kw):
+ """
+ """
+ builder = self.get_builder(env)
+ if builder is None:
+ return [], []
+ return builder(*args, **kw)
+
+class ToolInitializer(object):
+ """
+ A class for delayed initialization of Tools modules.
+
+ Instances of this class associate a list of Tool modules with
+ a list of Builder method names that will be added by those Tool
+ modules. As part of instantiating this object for a particular
+ construction environment, we also add the appropriate
+ ToolInitializerMethod objects for the various Builder methods
+ that we want to use to delay Tool searches until necessary.
+ """
+ def __init__(self, env, tools, names):
+ if not SCons.Util.is_List(tools):
+ tools = [tools]
+ if not SCons.Util.is_List(names):
+ names = [names]
+ self.env = env
+ self.tools = tools
+ self.names = names
+ self.methods = {}
+ for name in names:
+ method = ToolInitializerMethod(name, self)
+ self.methods[name] = method
+ env.AddMethod(method)
+
+ def remove_methods(self, env):
+ """
+ Removes the methods that were added by the tool initialization
+ so we no longer copy and re-bind them when the construction
+ environment gets cloned.
+ """
+ for method in self.methods.values():
+ env.RemoveMethod(method)
+
+ def apply_tools(self, env):
+ """
+ Searches the list of associated Tool modules for one that
+ exists, and applies that to the construction environment.
+ """
+ for t in self.tools:
+ tool = SCons.Tool.Tool(t)
+ if tool.exists(env):
+ env.Tool(tool)
+ return
+
+ # If we fall through here, there was no tool module found.
+ # This is where we can put an informative error message
+ # about the inability to find the tool. We'll start doing
+ # this as we cut over more pre-defined Builder+Tools to use
+ # the ToolInitializer class.
+
+def Initializers(env):
+ ToolInitializer(env, ['install'], ['_InternalInstall', '_InternalInstallAs'])
+ def Install(self, *args, **kw):
+ return self._InternalInstall(*args, **kw)
+ def InstallAs(self, *args, **kw):
+ return self._InternalInstallAs(*args, **kw)
+ env.AddMethod(Install)
+ env.AddMethod(InstallAs)
+
+def FindTool(tools, env):
+ for tool in tools:
+ t = Tool(tool)
+ if t.exists(env):
+ return tool
+ return None
+
+def FindAllTools(tools, env):
+ def ToolExists(tool, env=env):
+ return Tool(tool).exists(env)
+ return list(filter (ToolExists, tools))
+
+def tool_list(platform, env):
+
+ other_plat_tools=[]
+ # XXX this logic about what tool to prefer on which platform
+ # should be moved into either the platform files or
+ # the tool files themselves.
+ # The search orders here are described in the man page. If you
+ # change these search orders, update the man page as well.
+ if str(platform) == 'win32':
+ "prefer Microsoft tools on Windows"
+ linkers = ['mslink', 'gnulink', 'ilink', 'linkloc', 'ilink32' ]
+ c_compilers = ['msvc', 'mingw', 'gcc', 'intelc', 'icl', 'icc', 'cc', 'bcc32' ]
+ cxx_compilers = ['msvc', 'intelc', 'icc', 'g++', 'c++', 'bcc32' ]
+ assemblers = ['masm', 'nasm', 'gas', '386asm' ]
+ fortran_compilers = ['gfortran', 'g77', 'ifl', 'cvf', 'f95', 'f90', 'fortran']
+ ars = ['mslib', 'ar', 'tlib']
+ other_plat_tools=['msvs','midl']
+ elif str(platform) == 'os2':
+ "prefer IBM tools on OS/2"
+ linkers = ['ilink', 'gnulink', ]#'mslink']
+ c_compilers = ['icc', 'gcc',]# 'msvc', 'cc']
+ cxx_compilers = ['icc', 'g++',]# 'msvc', 'c++']
+ assemblers = ['nasm',]# 'masm', 'gas']
+ fortran_compilers = ['ifl', 'g77']
+ ars = ['ar',]# 'mslib']
+ elif str(platform) == 'irix':
+ "prefer MIPSPro on IRIX"
+ linkers = ['sgilink', 'gnulink']
+ c_compilers = ['sgicc', 'gcc', 'cc']
+ cxx_compilers = ['sgic++', 'g++', 'c++']
+ assemblers = ['as', 'gas']
+ fortran_compilers = ['f95', 'f90', 'f77', 'g77', 'fortran']
+ ars = ['sgiar']
+ elif str(platform) == 'sunos':
+ "prefer Forte tools on SunOS"
+ linkers = ['sunlink', 'gnulink']
+ c_compilers = ['suncc', 'gcc', 'cc']
+ cxx_compilers = ['sunc++', 'g++', 'c++']
+ assemblers = ['as', 'gas']
+ fortran_compilers = ['sunf95', 'sunf90', 'sunf77', 'f95', 'f90', 'f77',
+ 'gfortran', 'g77', 'fortran']
+ ars = ['sunar']
+ elif str(platform) == 'hpux':
+ "prefer aCC tools on HP-UX"
+ linkers = ['hplink', 'gnulink']
+ c_compilers = ['hpcc', 'gcc', 'cc']
+ cxx_compilers = ['hpc++', 'g++', 'c++']
+ assemblers = ['as', 'gas']
+ fortran_compilers = ['f95', 'f90', 'f77', 'g77', 'fortran']
+ ars = ['ar']
+ elif str(platform) == 'aix':
+ "prefer AIX Visual Age tools on AIX"
+ linkers = ['aixlink', 'gnulink']
+ c_compilers = ['aixcc', 'gcc', 'cc']
+ cxx_compilers = ['aixc++', 'g++', 'c++']
+ assemblers = ['as', 'gas']
+ fortran_compilers = ['f95', 'f90', 'aixf77', 'g77', 'fortran']
+ ars = ['ar']
+ elif str(platform) == 'darwin':
+ "prefer GNU tools on Mac OS X, except for some linkers and IBM tools"
+ linkers = ['applelink', 'gnulink']
+ c_compilers = ['gcc', 'cc']
+ cxx_compilers = ['g++', 'c++']
+ assemblers = ['as']
+ fortran_compilers = ['gfortran', 'f95', 'f90', 'g77']
+ ars = ['ar']
+ else:
+ "prefer GNU tools on all other platforms"
+ linkers = ['gnulink', 'mslink', 'ilink']
+ c_compilers = ['gcc', 'msvc', 'intelc', 'icc', 'cc']
+ cxx_compilers = ['g++', 'msvc', 'intelc', 'icc', 'c++']
+ assemblers = ['gas', 'nasm', 'masm']
+ fortran_compilers = ['gfortran', 'g77', 'ifort', 'ifl', 'f95', 'f90', 'f77']
+ ars = ['ar', 'mslib']
+
+ c_compiler = FindTool(c_compilers, env) or c_compilers[0]
+
+ # XXX this logic about what tool provides what should somehow be
+ # moved into the tool files themselves.
+ if c_compiler and c_compiler == 'mingw':
+ # MinGW contains a linker, C compiler, C++ compiler,
+ # Fortran compiler, archiver and assembler:
+ cxx_compiler = None
+ linker = None
+ assembler = None
+ fortran_compiler = None
+ ar = None
+ else:
+ # Don't use g++ if the C compiler has built-in C++ support:
+ if c_compiler in ('msvc', 'intelc', 'icc'):
+ cxx_compiler = None
+ else:
+ cxx_compiler = FindTool(cxx_compilers, env) or cxx_compilers[0]
+ linker = FindTool(linkers, env) or linkers[0]
+ assembler = FindTool(assemblers, env) or assemblers[0]
+ fortran_compiler = FindTool(fortran_compilers, env) or fortran_compilers[0]
+ ar = FindTool(ars, env) or ars[0]
+
+ other_tools = FindAllTools(other_plat_tools + [
+ 'dmd',
+ #TODO: merge 'install' into 'filesystem' and
+ # make 'filesystem' the default
+ 'filesystem',
+ 'm4',
+ 'wix', #'midl', 'msvs',
+ # Parser generators
+ 'lex', 'yacc',
+ # Foreign function interface
+ 'rpcgen', 'swig',
+ # Java
+ 'jar', 'javac', 'javah', 'rmic',
+ # TeX
+ 'dvipdf', 'dvips', 'gs',
+ 'tex', 'latex', 'pdflatex', 'pdftex',
+ # Archivers
+ 'tar', 'zip', 'rpm',
+ # SourceCode factories
+ 'BitKeeper', 'CVS', 'Perforce',
+ 'RCS', 'SCCS', # 'Subversion',
+ ], env)
+
+ tools = ([linker, c_compiler, cxx_compiler,
+ fortran_compiler, assembler, ar]
+ + other_tools)
+
+ return [x for x in tools if x]
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/aixc++.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/aixc++.py
new file mode 100644
index 00000000..bc2d0e8b
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/aixc++.py
@@ -0,0 +1,82 @@
+"""SCons.Tool.aixc++
+
+Tool-specific initialization for IBM xlC / Visual Age C++ compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/aixc++.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+
+import SCons.Platform.aix
+
+cplusplus = __import__('c++', globals(), locals(), [])
+
+packages = ['vacpp.cmp.core', 'vacpp.cmp.batch', 'vacpp.cmp.C', 'ibmcxx.cmp']
+
+def get_xlc(env):
+ xlc = env.get('CXX', 'xlC')
+ xlc_r = env.get('SHCXX', 'xlC_r')
+ return SCons.Platform.aix.get_xlc(env, xlc, xlc_r, packages)
+
+def smart_cxxflags(source, target, env, for_signature):
+ build_dir = env.GetBuildPath()
+ if build_dir:
+ return '-qtempinc=' + os.path.join(build_dir, 'tempinc')
+ return ''
+
+def generate(env):
+ """Add Builders and construction variables for xlC / Visual Age
+ suite to an Environment."""
+ path, _cxx, _shcxx, version = get_xlc(env)
+ if path:
+ _cxx = os.path.join(path, _cxx)
+ _shcxx = os.path.join(path, _shcxx)
+
+ cplusplus.generate(env)
+
+ env['CXX'] = _cxx
+ env['SHCXX'] = _shcxx
+ env['CXXVERSION'] = version
+ env['SHOBJSUFFIX'] = '.pic.o'
+
+def exists(env):
+ path, _cxx, _shcxx, version = get_xlc(env)
+ if path and _cxx:
+ xlc = os.path.join(path, _cxx)
+ if os.path.exists(xlc):
+ return xlc
+ return None
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/aixcc.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/aixcc.py
new file mode 100644
index 00000000..c1dcb168
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/aixcc.py
@@ -0,0 +1,74 @@
+"""SCons.Tool.aixcc
+
+Tool-specific initialization for IBM xlc / Visual Age C compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/aixcc.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+
+import SCons.Platform.aix
+
+import cc
+
+packages = ['vac.C', 'ibmcxx.cmp']
+
+def get_xlc(env):
+ xlc = env.get('CC', 'xlc')
+ xlc_r = env.get('SHCC', 'xlc_r')
+ return SCons.Platform.aix.get_xlc(env, xlc, xlc_r, packages)
+
+def generate(env):
+ """Add Builders and construction variables for xlc / Visual Age
+ suite to an Environment."""
+ path, _cc, _shcc, version = get_xlc(env)
+ if path:
+ _cc = os.path.join(path, _cc)
+ _shcc = os.path.join(path, _shcc)
+
+ cc.generate(env)
+
+ env['CC'] = _cc
+ env['SHCC'] = _shcc
+ env['CCVERSION'] = version
+
+def exists(env):
+ path, _cc, _shcc, version = get_xlc(env)
+ if path and _cc:
+ xlc = os.path.join(path, _cc)
+ if os.path.exists(xlc):
+ return xlc
+ return None
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/aixf77.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/aixf77.py
new file mode 100644
index 00000000..477ec302
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/aixf77.py
@@ -0,0 +1,80 @@
+"""engine.SCons.Tool.aixf77
+
+Tool-specific initialization for IBM Visual Age f77 Fortran compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/aixf77.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+
+#import SCons.Platform.aix
+
+import f77
+
+# It would be good to look for the AIX F77 package the same way we're now
+# looking for the C and C++ packages. This should be as easy as supplying
+# the correct package names in the following list and uncommenting the
+# SCons.Platform.aix_get_xlc() call the in the function below.
+packages = []
+
+def get_xlf77(env):
+ xlf77 = env.get('F77', 'xlf77')
+ xlf77_r = env.get('SHF77', 'xlf77_r')
+ #return SCons.Platform.aix.get_xlc(env, xlf77, xlf77_r, packages)
+ return (None, xlf77, xlf77_r, None)
+
+def generate(env):
+ """
+ Add Builders and construction variables for the Visual Age FORTRAN
+ compiler to an Environment.
+ """
+ path, _f77, _shf77, version = get_xlf77(env)
+ if path:
+ _f77 = os.path.join(path, _f77)
+ _shf77 = os.path.join(path, _shf77)
+
+ f77.generate(env)
+
+ env['F77'] = _f77
+ env['SHF77'] = _shf77
+
+def exists(env):
+ path, _f77, _shf77, version = get_xlf77(env)
+ if path and _f77:
+ xlf77 = os.path.join(path, _f77)
+ if os.path.exists(xlf77):
+ return xlf77
+ return None
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/aixlink.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/aixlink.py
new file mode 100644
index 00000000..eba4916a
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/aixlink.py
@@ -0,0 +1,76 @@
+"""SCons.Tool.aixlink
+
+Tool-specific initialization for the IBM Visual Age linker.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/aixlink.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+import os.path
+
+import SCons.Util
+
+import aixcc
+import link
+
+cplusplus = __import__('c++', globals(), locals(), [])
+
+def smart_linkflags(source, target, env, for_signature):
+ if cplusplus.iscplusplus(source):
+ build_dir = env.subst('$BUILDDIR', target=target, source=source)
+ if build_dir:
+ return '-qtempinc=' + os.path.join(build_dir, 'tempinc')
+ return ''
+
+def generate(env):
+ """
+ Add Builders and construction variables for Visual Age linker to
+ an Environment.
+ """
+ link.generate(env)
+
+ env['SMARTLINKFLAGS'] = smart_linkflags
+ env['LINKFLAGS'] = SCons.Util.CLVar('$SMARTLINKFLAGS')
+ env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -qmkshrobj -qsuppress=1501-218')
+ env['SHLIBSUFFIX'] = '.a'
+
+def exists(env):
+ path, _cc, _shcc, version = aixcc.get_xlc(env)
+ if path and _cc:
+ xlc = os.path.join(path, _cc)
+ if os.path.exists(xlc):
+ return xlc
+ return None
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/applelink.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/applelink.py
new file mode 100644
index 00000000..a23a4378
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/applelink.py
@@ -0,0 +1,71 @@
+"""SCons.Tool.applelink
+
+Tool-specific initialization for the Apple gnu-like linker.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/applelink.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Util
+
+# Even though the Mac is based on the GNU toolchain, it doesn't understand
+# the -rpath option, so we use the "link" tool instead of "gnulink".
+import link
+
+def generate(env):
+ """Add Builders and construction variables for applelink to an
+ Environment."""
+ link.generate(env)
+
+ env['FRAMEWORKPATHPREFIX'] = '-F'
+ env['_FRAMEWORKPATH'] = '${_concat(FRAMEWORKPATHPREFIX, FRAMEWORKPATH, "", __env__)}'
+ env['_FRAMEWORKS'] = '${_concat("-framework ", FRAMEWORKS, "", __env__)}'
+ env['LINKCOM'] = env['LINKCOM'] + ' $_FRAMEWORKPATH $_FRAMEWORKS $FRAMEWORKSFLAGS'
+ env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -dynamiclib')
+ env['SHLINKCOM'] = env['SHLINKCOM'] + ' $_FRAMEWORKPATH $_FRAMEWORKS $FRAMEWORKSFLAGS'
+
+ # override the default for loadable modules, which are different
+ # on OS X than dynamic shared libs. echoing what XCode does for
+ # pre/suffixes:
+ env['LDMODULEPREFIX'] = ''
+ env['LDMODULESUFFIX'] = ''
+ env['LDMODULEFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -bundle')
+ env['LDMODULECOM'] = '$LDMODULE -o ${TARGET} $LDMODULEFLAGS $SOURCES $_LIBDIRFLAGS $_LIBFLAGS $_FRAMEWORKPATH $_FRAMEWORKS $FRAMEWORKSFLAGS'
+
+
+
+def exists(env):
+ return env['PLATFORM'] == 'darwin'
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/ar.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/ar.py
new file mode 100644
index 00000000..dab95868
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/ar.py
@@ -0,0 +1,63 @@
+"""SCons.Tool.ar
+
+Tool-specific initialization for ar (library archive).
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/ar.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Defaults
+import SCons.Tool
+import SCons.Util
+
+
+def generate(env):
+ """Add Builders and construction variables for ar to an Environment."""
+ SCons.Tool.createStaticLibBuilder(env)
+
+ env['AR'] = 'ar'
+ env['ARFLAGS'] = SCons.Util.CLVar('rc')
+ env['ARCOM'] = '$AR $ARFLAGS $TARGET $SOURCES'
+ env['LIBPREFIX'] = 'lib'
+ env['LIBSUFFIX'] = '.a'
+
+ if env.Detect('ranlib'):
+ env['RANLIB'] = 'ranlib'
+ env['RANLIBFLAGS'] = SCons.Util.CLVar('')
+ env['RANLIBCOM'] = '$RANLIB $RANLIBFLAGS $TARGET'
+
+def exists(env):
+ return env.Detect('ar')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/as.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/as.py
new file mode 100644
index 00000000..7d5f8722
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/as.py
@@ -0,0 +1,78 @@
+"""SCons.Tool.as
+
+Tool-specific initialization for as, the generic Posix assembler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/as.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Defaults
+import SCons.Tool
+import SCons.Util
+
+assemblers = ['as']
+
+ASSuffixes = ['.s', '.asm', '.ASM']
+ASPPSuffixes = ['.spp', '.SPP', '.sx']
+if SCons.Util.case_sensitive_suffixes('.s', '.S'):
+ ASPPSuffixes.extend(['.S'])
+else:
+ ASSuffixes.extend(['.S'])
+
+def generate(env):
+ """Add Builders and construction variables for as to an Environment."""
+ static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
+
+ for suffix in ASSuffixes:
+ static_obj.add_action(suffix, SCons.Defaults.ASAction)
+ shared_obj.add_action(suffix, SCons.Defaults.ASAction)
+ static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter)
+ shared_obj.add_emitter(suffix, SCons.Defaults.SharedObjectEmitter)
+
+ for suffix in ASPPSuffixes:
+ static_obj.add_action(suffix, SCons.Defaults.ASPPAction)
+ shared_obj.add_action(suffix, SCons.Defaults.ASPPAction)
+ static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter)
+ shared_obj.add_emitter(suffix, SCons.Defaults.SharedObjectEmitter)
+
+ env['AS'] = env.Detect(assemblers) or 'as'
+ env['ASFLAGS'] = SCons.Util.CLVar('')
+ env['ASCOM'] = '$AS $ASFLAGS -o $TARGET $SOURCES'
+ env['ASPPFLAGS'] = '$ASFLAGS'
+ env['ASPPCOM'] = '$CC $ASPPFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES'
+
+def exists(env):
+ return env.Detect(assemblers)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/bcc32.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/bcc32.py
new file mode 100644
index 00000000..664c3de0
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/bcc32.py
@@ -0,0 +1,81 @@
+"""SCons.Tool.bcc32
+
+XXX
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/bcc32.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+import os.path
+
+import SCons.Defaults
+import SCons.Tool
+import SCons.Util
+
+def findIt(program, env):
+ # First search in the SCons path and then the OS path:
+ borwin = env.WhereIs(program) or SCons.Util.WhereIs(program)
+ if borwin:
+ dir = os.path.dirname(borwin)
+ env.PrependENVPath('PATH', dir)
+ return borwin
+
+def generate(env):
+ findIt('bcc32', env)
+ """Add Builders and construction variables for bcc to an
+ Environment."""
+ static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
+ for suffix in ['.c', '.cpp']:
+ static_obj.add_action(suffix, SCons.Defaults.CAction)
+ shared_obj.add_action(suffix, SCons.Defaults.ShCAction)
+ static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter)
+ shared_obj.add_emitter(suffix, SCons.Defaults.SharedObjectEmitter)
+
+ env['CC'] = 'bcc32'
+ env['CCFLAGS'] = SCons.Util.CLVar('')
+ env['CFLAGS'] = SCons.Util.CLVar('')
+ env['CCCOM'] = '$CC -q $CFLAGS $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -c -o$TARGET $SOURCES'
+ env['SHCC'] = '$CC'
+ env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
+ env['SHCFLAGS'] = SCons.Util.CLVar('$CFLAGS')
+ env['SHCCCOM'] = '$SHCC -WD $SHCFLAGS $SHCCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -c -o$TARGET $SOURCES'
+ env['CPPDEFPREFIX'] = '-D'
+ env['CPPDEFSUFFIX'] = ''
+ env['INCPREFIX'] = '-I'
+ env['INCSUFFIX'] = ''
+ env['SHOBJSUFFIX'] = '.dll'
+ env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 0
+ env['CFILESUFFIX'] = '.cpp'
+
+def exists(env):
+ return findIt('bcc32', env)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/c++.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/c++.py
new file mode 100644
index 00000000..e19523be
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/c++.py
@@ -0,0 +1,99 @@
+"""SCons.Tool.c++
+
+Tool-specific initialization for generic Posix C++ compilers.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/c++.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+
+import SCons.Tool
+import SCons.Defaults
+import SCons.Util
+
+compilers = ['CC', 'c++']
+
+CXXSuffixes = ['.cpp', '.cc', '.cxx', '.c++', '.C++', '.mm']
+if SCons.Util.case_sensitive_suffixes('.c', '.C'):
+ CXXSuffixes.append('.C')
+
+def iscplusplus(source):
+ if not source:
+ # Source might be None for unusual cases like SConf.
+ return 0
+ for s in source:
+ if s.sources:
+ ext = os.path.splitext(str(s.sources[0]))[1]
+ if ext in CXXSuffixes:
+ return 1
+ return 0
+
+def generate(env):
+ """
+ Add Builders and construction variables for Visual Age C++ compilers
+ to an Environment.
+ """
+ import SCons.Tool
+ import SCons.Tool.cc
+ static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
+
+ for suffix in CXXSuffixes:
+ static_obj.add_action(suffix, SCons.Defaults.CXXAction)
+ shared_obj.add_action(suffix, SCons.Defaults.ShCXXAction)
+ static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter)
+ shared_obj.add_emitter(suffix, SCons.Defaults.SharedObjectEmitter)
+
+ SCons.Tool.cc.add_common_cc_variables(env)
+
+ env['CXX'] = 'c++'
+ env['CXXFLAGS'] = SCons.Util.CLVar('')
+ env['CXXCOM'] = '$CXX -o $TARGET -c $CXXFLAGS $CCFLAGS $_CCCOMCOM $SOURCES'
+ env['SHCXX'] = '$CXX'
+ env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
+ env['SHCXXCOM'] = '$SHCXX -o $TARGET -c $SHCXXFLAGS $SHCCFLAGS $_CCCOMCOM $SOURCES'
+
+ env['CPPDEFPREFIX'] = '-D'
+ env['CPPDEFSUFFIX'] = ''
+ env['INCPREFIX'] = '-I'
+ env['INCSUFFIX'] = ''
+ env['SHOBJSUFFIX'] = '.os'
+ env['OBJSUFFIX'] = '.o'
+ env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 0
+
+ env['CXXFILESUFFIX'] = '.cc'
+
+def exists(env):
+ return env.Detect(compilers)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/cc.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/cc.py
new file mode 100644
index 00000000..291673f4
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/cc.py
@@ -0,0 +1,102 @@
+"""SCons.Tool.cc
+
+Tool-specific initialization for generic Posix C compilers.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/cc.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Tool
+import SCons.Defaults
+import SCons.Util
+
+CSuffixes = ['.c', '.m']
+if not SCons.Util.case_sensitive_suffixes('.c', '.C'):
+ CSuffixes.append('.C')
+
+def add_common_cc_variables(env):
+ """
+ Add underlying common "C compiler" variables that
+ are used by multiple tools (specifically, c++).
+ """
+ if '_CCCOMCOM' not in env:
+ env['_CCCOMCOM'] = '$CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS'
+ # It's a hack to test for darwin here, but the alternative
+ # of creating an applecc.py to contain this seems overkill.
+ # Maybe someday the Apple platform will require more setup and
+ # this logic will be moved.
+ env['FRAMEWORKS'] = SCons.Util.CLVar('')
+ env['FRAMEWORKPATH'] = SCons.Util.CLVar('')
+ if env['PLATFORM'] == 'darwin':
+ env['_CCCOMCOM'] = env['_CCCOMCOM'] + ' $_FRAMEWORKPATH'
+
+ if 'CCFLAGS' not in env:
+ env['CCFLAGS'] = SCons.Util.CLVar('')
+
+ if 'SHCCFLAGS' not in env:
+ env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
+
+def generate(env):
+ """
+ Add Builders and construction variables for C compilers to an Environment.
+ """
+ static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
+
+ for suffix in CSuffixes:
+ static_obj.add_action(suffix, SCons.Defaults.CAction)
+ shared_obj.add_action(suffix, SCons.Defaults.ShCAction)
+ static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter)
+ shared_obj.add_emitter(suffix, SCons.Defaults.SharedObjectEmitter)
+
+ add_common_cc_variables(env)
+
+ env['CC'] = 'cc'
+ env['CFLAGS'] = SCons.Util.CLVar('')
+ env['CCCOM'] = '$CC -o $TARGET -c $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES'
+ env['SHCC'] = '$CC'
+ env['SHCFLAGS'] = SCons.Util.CLVar('$CFLAGS')
+ env['SHCCCOM'] = '$SHCC -o $TARGET -c $SHCFLAGS $SHCCFLAGS $_CCCOMCOM $SOURCES'
+
+ env['CPPDEFPREFIX'] = '-D'
+ env['CPPDEFSUFFIX'] = ''
+ env['INCPREFIX'] = '-I'
+ env['INCSUFFIX'] = ''
+ env['SHOBJSUFFIX'] = '.os'
+ env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 0
+
+ env['CFILESUFFIX'] = '.c'
+
+def exists(env):
+ return env.Detect('cc')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/cvf.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/cvf.py
new file mode 100644
index 00000000..7c2114df
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/cvf.py
@@ -0,0 +1,58 @@
+"""engine.SCons.Tool.cvf
+
+Tool-specific initialization for the Compaq Visual Fortran compiler.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/cvf.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import fortran
+
+compilers = ['f90']
+
+def generate(env):
+ """Add Builders and construction variables for compaq visual fortran to an Environment."""
+
+ fortran.generate(env)
+
+ env['FORTRAN'] = 'f90'
+ env['FORTRANCOM'] = '$FORTRAN $FORTRANFLAGS $_FORTRANMODFLAG $_FORTRANINCFLAGS /compile_only ${SOURCES.windows} /object:${TARGET.windows}'
+ env['FORTRANPPCOM'] = '$FORTRAN $FORTRANFLAGS $CPPFLAGS $_CPPDEFFLAGS $_FORTRANMODFLAG $_FORTRANINCFLAGS /compile_only ${SOURCES.windows} /object:${TARGET.windows}'
+ env['SHFORTRANCOM'] = '$SHFORTRAN $SHFORTRANFLAGS $_FORTRANMODFLAG $_FORTRANINCFLAGS /compile_only ${SOURCES.windows} /object:${TARGET.windows}'
+ env['SHFORTRANPPCOM'] = '$SHFORTRAN $SHFORTRANFLAGS $CPPFLAGS $_CPPDEFFLAGS $_FORTRANMODFLAG $_FORTRANINCFLAGS /compile_only ${SOURCES.windows} /object:${TARGET.windows}'
+ env['OBJSUFFIX'] = '.obj'
+ env['FORTRANMODDIR'] = '${TARGET.dir}'
+ env['FORTRANMODDIRPREFIX'] = '/module:'
+ env['FORTRANMODDIRSUFFIX'] = ''
+
+def exists(env):
+ return env.Detect(compilers)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/default.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/default.py
new file mode 100644
index 00000000..ddd5c347
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/default.py
@@ -0,0 +1,50 @@
+"""SCons.Tool.default
+
+Initialization with a default tool list.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/default.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Tool
+
+def generate(env):
+ """Add default tools."""
+ for t in SCons.Tool.tool_list(env['PLATFORM'], env):
+ SCons.Tool.Tool(t)(env)
+
+def exists(env):
+ return 1
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/dmd.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/dmd.py
new file mode 100644
index 00000000..2a48b95f
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/dmd.py
@@ -0,0 +1,223 @@
+"""SCons.Tool.dmd
+
+Tool-specific initialization for the Digital Mars D compiler.
+(http://digitalmars.com/d)
+
+Coded by Andy Friesen (andy@ikagames.com)
+15 November 2003
+
+There are a number of problems with this script at this point in time.
+The one that irritates me the most is the Windows linker setup. The D
+linker doesn't have a way to add lib paths on the commandline, as far
+as I can see. You have to specify paths relative to the SConscript or
+use absolute paths. To hack around it, add '#/blah'. This will link
+blah.lib from the directory where SConstruct resides.
+
+Compiler variables:
+ DC - The name of the D compiler to use. Defaults to dmd or gdmd,
+ whichever is found.
+ DPATH - List of paths to search for import modules.
+ DVERSIONS - List of version tags to enable when compiling.
+ DDEBUG - List of debug tags to enable when compiling.
+
+Linker related variables:
+ LIBS - List of library files to link in.
+ DLINK - Name of the linker to use. Defaults to dmd or gdmd.
+ DLINKFLAGS - List of linker flags.
+
+Lib tool variables:
+ DLIB - Name of the lib tool to use. Defaults to lib.
+ DLIBFLAGS - List of flags to pass to the lib tool.
+ LIBS - Same as for the linker. (libraries to pull into the .lib)
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/dmd.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+
+import SCons.Action
+import SCons.Builder
+import SCons.Defaults
+import SCons.Scanner.D
+import SCons.Tool
+
+# Adapted from c++.py
+def isD(source):
+ if not source:
+ return 0
+
+ for s in source:
+ if s.sources:
+ ext = os.path.splitext(str(s.sources[0]))[1]
+ if ext == '.d':
+ return 1
+ return 0
+
+smart_link = {}
+
+smart_lib = {}
+
+def generate(env):
+ global smart_link
+ global smart_lib
+
+ static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
+
+ DAction = SCons.Action.Action('$DCOM', '$DCOMSTR')
+
+ static_obj.add_action('.d', DAction)
+ shared_obj.add_action('.d', DAction)
+ static_obj.add_emitter('.d', SCons.Defaults.StaticObjectEmitter)
+ shared_obj.add_emitter('.d', SCons.Defaults.SharedObjectEmitter)
+
+ dc = env.Detect(['dmd', 'gdmd'])
+ env['DC'] = dc
+ env['DCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS -c -of$TARGET $SOURCES'
+ env['_DINCFLAGS'] = '$( ${_concat(DINCPREFIX, DPATH, DINCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
+ env['_DVERFLAGS'] = '$( ${_concat(DVERPREFIX, DVERSIONS, DVERSUFFIX, __env__)} $)'
+ env['_DDEBUGFLAGS'] = '$( ${_concat(DDEBUGPREFIX, DDEBUG, DDEBUGSUFFIX, __env__)} $)'
+ env['_DFLAGS'] = '$( ${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)} $)'
+
+ env['DPATH'] = ['#/']
+ env['DFLAGS'] = []
+ env['DVERSIONS'] = []
+ env['DDEBUG'] = []
+
+ if dc:
+ # Add the path to the standard library.
+ # This is merely for the convenience of the dependency scanner.
+ dmd_path = env.WhereIs(dc)
+ if dmd_path:
+ x = dmd_path.rindex(dc)
+ phobosDir = dmd_path[:x] + '/../src/phobos'
+ if os.path.isdir(phobosDir):
+ env.Append(DPATH = [phobosDir])
+
+ env['DINCPREFIX'] = '-I'
+ env['DINCSUFFIX'] = ''
+ env['DVERPREFIX'] = '-version='
+ env['DVERSUFFIX'] = ''
+ env['DDEBUGPREFIX'] = '-debug='
+ env['DDEBUGSUFFIX'] = ''
+ env['DFLAGPREFIX'] = '-'
+ env['DFLAGSUFFIX'] = ''
+ env['DFILESUFFIX'] = '.d'
+
+ # Need to use the Digital Mars linker/lib on windows.
+ # *nix can just use GNU link.
+ if env['PLATFORM'] == 'win32':
+ env['DLINK'] = '$DC'
+ env['DLINKCOM'] = '$DLINK -of$TARGET $SOURCES $DFLAGS $DLINKFLAGS $_DLINKLIBFLAGS'
+ env['DLIB'] = 'lib'
+ env['DLIBCOM'] = '$DLIB $_DLIBFLAGS -c $TARGET $SOURCES $_DLINKLIBFLAGS'
+
+ env['_DLINKLIBFLAGS'] = '$( ${_concat(DLIBLINKPREFIX, LIBS, DLIBLINKSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
+ env['_DLIBFLAGS'] = '$( ${_concat(DLIBFLAGPREFIX, DLIBFLAGS, DLIBFLAGSUFFIX, __env__)} $)'
+ env['DLINKFLAGS'] = []
+ env['DLIBLINKPREFIX'] = ''
+ env['DLIBLINKSUFFIX'] = '.lib'
+ env['DLIBFLAGPREFIX'] = '-'
+ env['DLIBFLAGSUFFIX'] = ''
+ env['DLINKFLAGPREFIX'] = '-'
+ env['DLINKFLAGSUFFIX'] = ''
+
+ SCons.Tool.createStaticLibBuilder(env)
+
+ # Basically, we hijack the link and ar builders with our own.
+ # these builders check for the presence of D source, and swap out
+ # the system's defaults for the Digital Mars tools. If there's no D
+ # source, then we silently return the previous settings.
+ linkcom = env.get('LINKCOM')
+ try:
+ env['SMART_LINKCOM'] = smart_link[linkcom]
+ except KeyError:
+ def _smartLink(source, target, env, for_signature,
+ defaultLinker=linkcom):
+ if isD(source):
+ # XXX I'm not sure how to add a $DLINKCOMSTR variable
+ # so that it works with this _smartLink() logic,
+ # and I don't have a D compiler/linker to try it out,
+ # so we'll leave it alone for now.
+ return '$DLINKCOM'
+ else:
+ return defaultLinker
+ env['SMART_LINKCOM'] = smart_link[linkcom] = _smartLink
+
+ arcom = env.get('ARCOM')
+ try:
+ env['SMART_ARCOM'] = smart_lib[arcom]
+ except KeyError:
+ def _smartLib(source, target, env, for_signature,
+ defaultLib=arcom):
+ if isD(source):
+ # XXX I'm not sure how to add a $DLIBCOMSTR variable
+ # so that it works with this _smartLib() logic, and
+ # I don't have a D compiler/archiver to try it out,
+ # so we'll leave it alone for now.
+ return '$DLIBCOM'
+ else:
+ return defaultLib
+ env['SMART_ARCOM'] = smart_lib[arcom] = _smartLib
+
+ # It is worth noting that the final space in these strings is
+ # absolutely pivotal. SCons sees these as actions and not generators
+ # if it is not there. (very bad)
+ env['ARCOM'] = '$SMART_ARCOM '
+ env['LINKCOM'] = '$SMART_LINKCOM '
+ else: # assuming linux
+ linkcom = env.get('LINKCOM')
+ try:
+ env['SMART_LINKCOM'] = smart_link[linkcom]
+ except KeyError:
+ def _smartLink(source, target, env, for_signature,
+ defaultLinker=linkcom, dc=dc):
+ if isD(source):
+ try:
+ libs = env['LIBS']
+ except KeyError:
+ libs = []
+ if 'phobos' not in libs and 'gphobos' not in libs:
+ if dc is 'dmd':
+ env.Append(LIBS = ['phobos'])
+ elif dc is 'gdmd':
+ env.Append(LIBS = ['gphobos'])
+ if 'pthread' not in libs:
+ env.Append(LIBS = ['pthread'])
+ if 'm' not in libs:
+ env.Append(LIBS = ['m'])
+ return defaultLinker
+ env['SMART_LINKCOM'] = smart_link[linkcom] = _smartLink
+
+ env['LINKCOM'] = '$SMART_LINKCOM '
+
+def exists(env):
+ return env.Detect(['dmd', 'gdmd'])
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/dvi.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/dvi.py
new file mode 100644
index 00000000..6fcb96dd
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/dvi.py
@@ -0,0 +1,64 @@
+"""SCons.Tool.dvi
+
+Common DVI Builder definition for various other Tool modules that use it.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/dvi.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Builder
+import SCons.Tool
+
+DVIBuilder = None
+
+def generate(env):
+ try:
+ env['BUILDERS']['DVI']
+ except KeyError:
+ global DVIBuilder
+
+ if DVIBuilder is None:
+ # The suffix is hard-coded to '.dvi', not configurable via a
+ # construction variable like $DVISUFFIX, because the output
+ # file name is hard-coded within TeX.
+ DVIBuilder = SCons.Builder.Builder(action = {},
+ source_scanner = SCons.Tool.LaTeXScanner,
+ suffix = '.dvi',
+ emitter = {},
+ source_ext_match = None)
+
+ env['BUILDERS']['DVI'] = DVIBuilder
+
+def exists(env):
+ # This only puts a skeleton Builder in place, so if someone
+ # references this Tool directly, it's always "available."
+ return 1
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/dvipdf.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/dvipdf.py
new file mode 100644
index 00000000..fb5627e3
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/dvipdf.py
@@ -0,0 +1,124 @@
+"""SCons.Tool.dvipdf
+
+Tool-specific initialization for dvipdf.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Tool/dvipdf.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Action
+import SCons.Defaults
+import SCons.Tool.pdf
+import SCons.Tool.tex
+import SCons.Util
+
+_null = SCons.Scanner.LaTeX._null
+
+def DviPdfPsFunction(XXXDviAction, target = None, source= None, env=None):
+ """A builder for DVI files that sets the TEXPICTS environment
+ variable before running dvi2ps or dvipdf."""
+
+ try:
+ abspath = source[0].attributes.path
+ except AttributeError :
+ abspath = ''
+
+ saved_env = SCons.Scanner.LaTeX.modify_env_var(env, 'TEXPICTS', abspath)
+
+ result = XXXDviAction(target, source, env)
+
+ if saved_env is _null:
+ try:
+ del env['ENV']['TEXPICTS']
+ except KeyError:
+ pass # was never set
+ else:
+ env['ENV']['TEXPICTS'] = saved_env
+
+ return result
+
+def DviPdfFunction(target = None, source= None, env=None):
+ result = DviPdfPsFunction(PDFAction,target,source,env)
+ return result
+
+def DviPdfStrFunction(target = None, source= None, env=None):
+ """A strfunction for dvipdf that returns the appropriate
+ command string for the no_exec options."""
+ if env.GetOption("no_exec"):
+ result = env.subst('$DVIPDFCOM',0,target,source)
+ else:
+ result = ''
+ return result
+
+PDFAction = None
+DVIPDFAction = None
+
+def PDFEmitter(target, source, env):
+ """Strips any .aux or .log files from the input source list.
+ These are created by the TeX Builder that in all likelihood was
+ used to generate the .dvi file we're using as input, and we only
+ care about the .dvi file.
+ """
+ def strip_suffixes(n):
+ return not SCons.Util.splitext(str(n))[1] in ['.aux', '.log']
+ source = list(filter(strip_suffixes, source))
+ return (target, source)
+
+def generate(env):
+ """Add Builders and construction variables for dvipdf to an Environment."""
+ global PDFAction
+ if PDFAction is None:
+ PDFAction = SCons.Action.Action('$DVIPDFCOM', '$DVIPDFCOMSTR')
+
+ global DVIPDFAction
+ if DVIPDFAction is None:
+ DVIPDFAction = SCons.Action.Action(DviPdfFunction, strfunction = DviPdfStrFunction)
+
+ import pdf
+ pdf.generate(env)
+
+ bld = env['BUILDERS']['PDF']
+ bld.add_action('.dvi', DVIPDFAction)
+ bld.add_emitter('.dvi', PDFEmitter)
+
+ env['DVIPDF'] = 'dvipdf'
+ env['DVIPDFFLAGS'] = SCons.Util.CLVar('')
+ env['DVIPDFCOM'] = 'cd ${TARGET.dir} && $DVIPDF $DVIPDFFLAGS ${SOURCE.file} ${TARGET.file}'
+
+ # Deprecated synonym.
+ env['PDFCOM'] = ['$DVIPDFCOM']
+
+def exists(env):
+ return env.Detect('dvipdf')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/dvips.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/dvips.py
new file mode 100644
index 00000000..de840533
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/dvips.py
@@ -0,0 +1,94 @@
+"""SCons.Tool.dvips
+
+Tool-specific initialization for dvips.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/dvips.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Action
+import SCons.Builder
+import SCons.Tool.dvipdf
+import SCons.Util
+
+def DviPsFunction(target = None, source= None, env=None):
+ result = SCons.Tool.dvipdf.DviPdfPsFunction(PSAction,target,source,env)
+ return result
+
+def DviPsStrFunction(target = None, source= None, env=None):
+ """A strfunction for dvipdf that returns the appropriate
+ command string for the no_exec options."""
+ if env.GetOption("no_exec"):
+ result = env.subst('$PSCOM',0,target,source)
+ else:
+ result = ''
+ return result
+
+PSAction = None
+DVIPSAction = None
+PSBuilder = None
+
+def generate(env):
+ """Add Builders and construction variables for dvips to an Environment."""
+ global PSAction
+ if PSAction is None:
+ PSAction = SCons.Action.Action('$PSCOM', '$PSCOMSTR')
+
+ global DVIPSAction
+ if DVIPSAction is None:
+ DVIPSAction = SCons.Action.Action(DviPsFunction, strfunction = DviPsStrFunction)
+
+ global PSBuilder
+ if PSBuilder is None:
+ PSBuilder = SCons.Builder.Builder(action = PSAction,
+ prefix = '$PSPREFIX',
+ suffix = '$PSSUFFIX',
+ src_suffix = '.dvi',
+ src_builder = 'DVI',
+ single_source=True)
+
+ env['BUILDERS']['PostScript'] = PSBuilder
+
+ env['DVIPS'] = 'dvips'
+ env['DVIPSFLAGS'] = SCons.Util.CLVar('')
+ # I'm not quite sure I got the directories and filenames right for variant_dir
+ # We need to be in the correct directory for the sake of latex \includegraphics eps included files.
+ env['PSCOM'] = 'cd ${TARGET.dir} && $DVIPS $DVIPSFLAGS -o ${TARGET.file} ${SOURCE.file}'
+ env['PSPREFIX'] = ''
+ env['PSSUFFIX'] = '.ps'
+
+def exists(env):
+ return env.Detect('dvips')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/f77.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/f77.py
new file mode 100644
index 00000000..cc2c8522
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/f77.py
@@ -0,0 +1,62 @@
+"""engine.SCons.Tool.f77
+
+Tool-specific initialization for the generic Posix f77 Fortran compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/f77.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Defaults
+import SCons.Scanner.Fortran
+import SCons.Tool
+import SCons.Util
+from SCons.Tool.FortranCommon import add_all_to_env, add_f77_to_env
+
+compilers = ['f77']
+
+def generate(env):
+ add_all_to_env(env)
+ add_f77_to_env(env)
+
+ fcomp = env.Detect(compilers) or 'f77'
+ env['F77'] = fcomp
+ env['SHF77'] = fcomp
+
+ env['FORTRAN'] = fcomp
+ env['SHFORTRAN'] = fcomp
+
+def exists(env):
+ return env.Detect(compilers)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/f90.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/f90.py
new file mode 100644
index 00000000..a2c61472
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/f90.py
@@ -0,0 +1,62 @@
+"""engine.SCons.Tool.f90
+
+Tool-specific initialization for the generic Posix f90 Fortran compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/f90.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Defaults
+import SCons.Scanner.Fortran
+import SCons.Tool
+import SCons.Util
+from SCons.Tool.FortranCommon import add_all_to_env, add_f90_to_env
+
+compilers = ['f90']
+
+def generate(env):
+ add_all_to_env(env)
+ add_f90_to_env(env)
+
+ fc = env.Detect(compilers) or 'f90'
+ env['F90'] = fc
+ env['SHF90'] = fc
+
+ env['FORTRAN'] = fc
+ env['SHFORTRAN'] = fc
+
+def exists(env):
+ return env.Detect(compilers)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/f95.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/f95.py
new file mode 100644
index 00000000..cadf23ee
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/f95.py
@@ -0,0 +1,63 @@
+"""engine.SCons.Tool.f95
+
+Tool-specific initialization for the generic Posix f95 Fortran compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/f95.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Defaults
+import SCons.Tool
+import SCons.Util
+import fortran
+from SCons.Tool.FortranCommon import add_all_to_env, add_f95_to_env
+
+compilers = ['f95']
+
+def generate(env):
+ add_all_to_env(env)
+ add_f95_to_env(env)
+
+ fcomp = env.Detect(compilers) or 'f95'
+ env['F95'] = fcomp
+ env['SHF95'] = fcomp
+
+ env['FORTRAN'] = fcomp
+ env['SHFORTRAN'] = fcomp
+
+
+def exists(env):
+ return env.Detect(compilers)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/filesystem.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/filesystem.py
new file mode 100644
index 00000000..290d8d5d
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/filesystem.py
@@ -0,0 +1,98 @@
+"""SCons.Tool.filesystem
+
+Tool-specific initialization for the filesystem tools.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/filesystem.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons
+from SCons.Tool.install import copyFunc
+
+copyToBuilder, copyAsBuilder = None, None
+
+def copyto_emitter(target, source, env):
+ """ changes the path of the source to be under the target (which
+ are assumed to be directories.
+ """
+ n_target = []
+
+ for t in target:
+ n_target = n_target + [t.File( str( s ) ) for s in source]
+
+ return (n_target, source)
+
+def copy_action_func(target, source, env):
+ assert( len(target) == len(source) ), "\ntarget: %s\nsource: %s" %(list(map(str, target)),list(map(str, source)))
+
+ for t, s in zip(target, source):
+ if copyFunc(t.get_path(), s.get_path(), env):
+ return 1
+
+ return 0
+
+def copy_action_str(target, source, env):
+ return env.subst_target_source(env['COPYSTR'], 0, target, source)
+
+copy_action = SCons.Action.Action( copy_action_func, copy_action_str )
+
+def generate(env):
+ try:
+ env['BUILDERS']['CopyTo']
+ env['BUILDERS']['CopyAs']
+ except KeyError, e:
+ global copyToBuilder
+ if copyToBuilder is None:
+ copyToBuilder = SCons.Builder.Builder(
+ action = copy_action,
+ target_factory = env.fs.Dir,
+ source_factory = env.fs.Entry,
+ multi = 1,
+ emitter = [ copyto_emitter, ] )
+
+ global copyAsBuilder
+ if copyAsBuilder is None:
+ copyAsBuilder = SCons.Builder.Builder(
+ action = copy_action,
+ target_factory = env.fs.Entry,
+ source_factory = env.fs.Entry )
+
+ env['BUILDERS']['CopyTo'] = copyToBuilder
+ env['BUILDERS']['CopyAs'] = copyAsBuilder
+
+ env['COPYSTR'] = 'Copy file(s): "$SOURCES" to "$TARGETS"'
+
+def exists(env):
+ return 1
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/fortran.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/fortran.py
new file mode 100644
index 00000000..ae0960ad
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/fortran.py
@@ -0,0 +1,62 @@
+"""SCons.Tool.fortran
+
+Tool-specific initialization for a generic Posix f77/f90 Fortran compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/fortran.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import re
+
+import SCons.Action
+import SCons.Defaults
+import SCons.Scanner.Fortran
+import SCons.Tool
+import SCons.Util
+from SCons.Tool.FortranCommon import add_all_to_env, add_fortran_to_env
+
+compilers = ['f95', 'f90', 'f77']
+
+def generate(env):
+ add_all_to_env(env)
+ add_fortran_to_env(env)
+
+ fc = env.Detect(compilers) or 'f77'
+ env['SHFORTRAN'] = fc
+ env['FORTRAN'] = fc
+
+def exists(env):
+ return env.Detect(compilers)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/g++.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/g++.py
new file mode 100644
index 00000000..dcd24064
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/g++.py
@@ -0,0 +1,90 @@
+"""SCons.Tool.g++
+
+Tool-specific initialization for g++.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/g++.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+import re
+import subprocess
+
+import SCons.Tool
+import SCons.Util
+
+cplusplus = __import__('c++', globals(), locals(), [])
+
+compilers = ['g++']
+
+def generate(env):
+ """Add Builders and construction variables for g++ to an Environment."""
+ static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
+
+ cplusplus.generate(env)
+
+ env['CXX'] = env.Detect(compilers)
+
+ # platform specific settings
+ if env['PLATFORM'] == 'aix':
+ env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS -mminimal-toc')
+ env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
+ env['SHOBJSUFFIX'] = '$OBJSUFFIX'
+ elif env['PLATFORM'] == 'hpux':
+ env['SHOBJSUFFIX'] = '.pic.o'
+ elif env['PLATFORM'] == 'sunos':
+ env['SHOBJSUFFIX'] = '.pic.o'
+ # determine compiler version
+ if env['CXX']:
+ #pipe = SCons.Action._subproc(env, [env['CXX'], '-dumpversion'],
+ pipe = SCons.Action._subproc(env, [env['CXX'], '--version'],
+ stdin = 'devnull',
+ stderr = 'devnull',
+ stdout = subprocess.PIPE)
+ if pipe.wait() != 0: return
+ # -dumpversion was added in GCC 3.0. As long as we're supporting
+ # GCC versions older than that, we should use --version and a
+ # regular expression.
+ #line = pipe.stdout.read().strip()
+ #if line:
+ # env['CXXVERSION'] = line
+ line = pipe.stdout.readline()
+ match = re.search(r'[0-9]+(\.[0-9]+)+', line)
+ if match:
+ env['CXXVERSION'] = match.group(0)
+
+def exists(env):
+ return env.Detect(compilers)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/g77.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/g77.py
new file mode 100644
index 00000000..f5bea8bf
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/g77.py
@@ -0,0 +1,73 @@
+"""engine.SCons.Tool.g77
+
+Tool-specific initialization for g77.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/g77.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Util
+from SCons.Tool.FortranCommon import add_all_to_env, add_f77_to_env
+
+compilers = ['g77', 'f77']
+
+def generate(env):
+ """Add Builders and construction variables for g77 to an Environment."""
+ add_all_to_env(env)
+ add_f77_to_env(env)
+
+ fcomp = env.Detect(compilers) or 'g77'
+ if env['PLATFORM'] in ['cygwin', 'win32']:
+ env['SHFORTRANFLAGS'] = SCons.Util.CLVar('$FORTRANFLAGS')
+ env['SHF77FLAGS'] = SCons.Util.CLVar('$F77FLAGS')
+ else:
+ env['SHFORTRANFLAGS'] = SCons.Util.CLVar('$FORTRANFLAGS -fPIC')
+ env['SHF77FLAGS'] = SCons.Util.CLVar('$F77FLAGS -fPIC')
+
+ env['FORTRAN'] = fcomp
+ env['SHFORTRAN'] = '$FORTRAN'
+
+ env['F77'] = fcomp
+ env['SHF77'] = '$F77'
+
+ env['INCFORTRANPREFIX'] = "-I"
+ env['INCFORTRANSUFFIX'] = ""
+
+ env['INCF77PREFIX'] = "-I"
+ env['INCF77SUFFIX'] = ""
+
+def exists(env):
+ return env.Detect(compilers)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/gas.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/gas.py
new file mode 100644
index 00000000..637a111c
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/gas.py
@@ -0,0 +1,53 @@
+"""SCons.Tool.gas
+
+Tool-specific initialization for as, the Gnu assembler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/gas.py 5134 2010/08/16 23:02:40 bdeegan"
+
+as_module = __import__('as', globals(), locals(), [])
+
+assemblers = ['as', 'gas']
+
+def generate(env):
+ """Add Builders and construction variables for as to an Environment."""
+ as_module.generate(env)
+
+ env['AS'] = env.Detect(assemblers) or 'as'
+
+def exists(env):
+ return env.Detect(assemblers)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/gcc.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/gcc.py
new file mode 100644
index 00000000..c93c05f3
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/gcc.py
@@ -0,0 +1,80 @@
+"""SCons.Tool.gcc
+
+Tool-specific initialization for gcc.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/gcc.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import cc
+import os
+import re
+import subprocess
+
+import SCons.Util
+
+compilers = ['gcc', 'cc']
+
+def generate(env):
+ """Add Builders and construction variables for gcc to an Environment."""
+ cc.generate(env)
+
+ env['CC'] = env.Detect(compilers) or 'gcc'
+ if env['PLATFORM'] in ['cygwin', 'win32']:
+ env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
+ else:
+ env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS -fPIC')
+ # determine compiler version
+ if env['CC']:
+ #pipe = SCons.Action._subproc(env, [env['CC'], '-dumpversion'],
+ pipe = SCons.Action._subproc(env, [env['CC'], '--version'],
+ stdin = 'devnull',
+ stderr = 'devnull',
+ stdout = subprocess.PIPE)
+ if pipe.wait() != 0: return
+ # -dumpversion was added in GCC 3.0. As long as we're supporting
+ # GCC versions older than that, we should use --version and a
+ # regular expression.
+ #line = pipe.stdout.read().strip()
+ #if line:
+ # env['CCVERSION'] = line
+ line = pipe.stdout.readline()
+ match = re.search(r'[0-9]+(\.[0-9]+)+', line)
+ if match:
+ env['CCVERSION'] = match.group(0)
+
+def exists(env):
+ return env.Detect(compilers)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/gfortran.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/gfortran.py
new file mode 100644
index 00000000..ed522f42
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/gfortran.py
@@ -0,0 +1,64 @@
+"""SCons.Tool.gfortran
+
+Tool-specific initialization for gfortran, the GNU Fortran 95/Fortran
+2003 compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/gfortran.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Util
+
+import fortran
+
+def generate(env):
+ """Add Builders and construction variables for gfortran to an
+ Environment."""
+ fortran.generate(env)
+
+ for dialect in ['F77', 'F90', 'FORTRAN', 'F95']:
+ env['%s' % dialect] = 'gfortran'
+ env['SH%s' % dialect] = '$%s' % dialect
+ if env['PLATFORM'] in ['cygwin', 'win32']:
+ env['SH%sFLAGS' % dialect] = SCons.Util.CLVar('$%sFLAGS' % dialect)
+ else:
+ env['SH%sFLAGS' % dialect] = SCons.Util.CLVar('$%sFLAGS -fPIC' % dialect)
+
+ env['INC%sPREFIX' % dialect] = "-I"
+ env['INC%sSUFFIX' % dialect] = ""
+
+def exists(env):
+ return env.Detect('gfortran')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/gnulink.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/gnulink.py
new file mode 100644
index 00000000..12045352
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/gnulink.py
@@ -0,0 +1,63 @@
+"""SCons.Tool.gnulink
+
+Tool-specific initialization for the gnu linker.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/gnulink.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Util
+
+import link
+
+linkers = ['g++', 'gcc']
+
+def generate(env):
+ """Add Builders and construction variables for gnulink to an Environment."""
+ link.generate(env)
+
+ if env['PLATFORM'] == 'hpux':
+ env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared -fPIC')
+
+ # __RPATH is set to $_RPATH in the platform specification if that
+ # platform supports it.
+ env.Append(LINKFLAGS=['$__RPATH'])
+ env['RPATHPREFIX'] = '-Wl,-rpath='
+ env['RPATHSUFFIX'] = ''
+ env['_RPATH'] = '${_concat(RPATHPREFIX, RPATH, RPATHSUFFIX, __env__)}'
+
+def exists(env):
+ return env.Detect(linkers)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/gs.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/gs.py
new file mode 100644
index 00000000..ac0247f1
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/gs.py
@@ -0,0 +1,81 @@
+"""SCons.Tool.gs
+
+Tool-specific initialization for Ghostscript.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/gs.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Action
+import SCons.Platform
+import SCons.Util
+
+# Ghostscript goes by different names on different platforms...
+platform = SCons.Platform.platform_default()
+
+if platform == 'os2':
+ gs = 'gsos2'
+elif platform == 'win32':
+ gs = 'gswin32c'
+else:
+ gs = 'gs'
+
+GhostscriptAction = None
+
+def generate(env):
+ """Add Builders and construction variables for Ghostscript to an
+ Environment."""
+
+ global GhostscriptAction
+ if GhostscriptAction is None:
+ GhostscriptAction = SCons.Action.Action('$GSCOM', '$GSCOMSTR')
+
+ import pdf
+ pdf.generate(env)
+
+ bld = env['BUILDERS']['PDF']
+ bld.add_action('.ps', GhostscriptAction)
+
+ env['GS'] = gs
+ env['GSFLAGS'] = SCons.Util.CLVar('-dNOPAUSE -dBATCH -sDEVICE=pdfwrite')
+ env['GSCOM'] = '$GS $GSFLAGS -sOutputFile=$TARGET $SOURCES'
+
+
+def exists(env):
+ if 'PS2PDF' in env:
+ return env.Detect(env['PS2PDF'])
+ else:
+ return env.Detect(gs) or SCons.Util.WhereIs(gs)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/hpc++.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/hpc++.py
new file mode 100644
index 00000000..d34f6008
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/hpc++.py
@@ -0,0 +1,84 @@
+"""SCons.Tool.hpc++
+
+Tool-specific initialization for c++ on HP/UX.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/hpc++.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+
+import SCons.Util
+
+cplusplus = __import__('c++', globals(), locals(), [])
+
+acc = None
+
+# search for the acc compiler and linker front end
+
+try:
+ dirs = os.listdir('/opt')
+except (IOError, OSError):
+ # Not being able to read the directory because it doesn't exist
+ # (IOError) or isn't readable (OSError) is okay.
+ dirs = []
+
+for dir in dirs:
+ cc = '/opt/' + dir + '/bin/aCC'
+ if os.path.exists(cc):
+ acc = cc
+ break
+
+
+def generate(env):
+ """Add Builders and construction variables for g++ to an Environment."""
+ cplusplus.generate(env)
+
+ if acc:
+ env['CXX'] = acc or 'aCC'
+ env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS +Z')
+ # determine version of aCC
+ line = os.popen(acc + ' -V 2>&1').readline().rstrip()
+ if line.find('aCC: HP ANSI C++') == 0:
+ env['CXXVERSION'] = line.split()[-1]
+
+ if env['PLATFORM'] == 'cygwin':
+ env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
+ else:
+ env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS +Z')
+
+def exists(env):
+ return acc
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/hpcc.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/hpcc.py
new file mode 100644
index 00000000..1503c572
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/hpcc.py
@@ -0,0 +1,53 @@
+"""SCons.Tool.hpcc
+
+Tool-specific initialization for HP aCC and cc.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/hpcc.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Util
+
+import cc
+
+def generate(env):
+ """Add Builders and construction variables for aCC & cc to an Environment."""
+ cc.generate(env)
+
+ env['CXX'] = 'aCC'
+ env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS +Z')
+
+def exists(env):
+ return env.Detect('aCC')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/hplink.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/hplink.py
new file mode 100644
index 00000000..db5ff007
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/hplink.py
@@ -0,0 +1,77 @@
+"""SCons.Tool.hplink
+
+Tool-specific initialization for the HP linker.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/hplink.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+import os.path
+
+import SCons.Util
+
+import link
+
+ccLinker = None
+
+# search for the acc compiler and linker front end
+
+try:
+ dirs = os.listdir('/opt')
+except (IOError, OSError):
+ # Not being able to read the directory because it doesn't exist
+ # (IOError) or isn't readable (OSError) is okay.
+ dirs = []
+
+for dir in dirs:
+ linker = '/opt/' + dir + '/bin/aCC'
+ if os.path.exists(linker):
+ ccLinker = linker
+ break
+
+def generate(env):
+ """
+ Add Builders and construction variables for Visual Age linker to
+ an Environment.
+ """
+ link.generate(env)
+
+ env['LINKFLAGS'] = SCons.Util.CLVar('-Wl,+s -Wl,+vnocompatwarnings')
+ env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -b')
+ env['SHLIBSUFFIX'] = '.sl'
+
+def exists(env):
+ return ccLinker
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/icc.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/icc.py
new file mode 100644
index 00000000..0accbf6f
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/icc.py
@@ -0,0 +1,59 @@
+"""engine.SCons.Tool.icc
+
+Tool-specific initialization for the OS/2 icc compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/icc.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import cc
+
+def generate(env):
+ """Add Builders and construction variables for the OS/2 to an Environment."""
+ cc.generate(env)
+
+ env['CC'] = 'icc'
+ env['CCCOM'] = '$CC $CFLAGS $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Fo$TARGET'
+ env['CXXCOM'] = '$CXX $CXXFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Fo$TARGET'
+ env['CPPDEFPREFIX'] = '/D'
+ env['CPPDEFSUFFIX'] = ''
+ env['INCPREFIX'] = '/I'
+ env['INCSUFFIX'] = ''
+ env['CFILESUFFIX'] = '.c'
+ env['CXXFILESUFFIX'] = '.cc'
+
+def exists(env):
+ return env.Detect('icc')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/icl.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/icl.py
new file mode 100644
index 00000000..ded400d0
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/icl.py
@@ -0,0 +1,52 @@
+"""engine.SCons.Tool.icl
+
+Tool-specific initialization for the Intel C/C++ compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/icl.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Tool.intelc
+
+# This has been completely superceded by intelc.py, which can
+# handle both Windows and Linux versions.
+
+def generate(*args, **kw):
+ """Add Builders and construction variables for icl to an Environment."""
+ return SCons.Tool.intelc.generate(*args, **kw)
+
+def exists(*args, **kw):
+ return SCons.Tool.intelc.exists(*args, **kw)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/ifl.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/ifl.py
new file mode 100644
index 00000000..fabf8644
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/ifl.py
@@ -0,0 +1,72 @@
+"""SCons.Tool.ifl
+
+Tool-specific initialization for the Intel Fortran compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/ifl.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Defaults
+from SCons.Scanner.Fortran import FortranScan
+from FortranCommon import add_all_to_env
+
+def generate(env):
+ """Add Builders and construction variables for ifl to an Environment."""
+ fscan = FortranScan("FORTRANPATH")
+ SCons.Tool.SourceFileScanner.add_scanner('.i', fscan)
+ SCons.Tool.SourceFileScanner.add_scanner('.i90', fscan)
+
+ if 'FORTRANFILESUFFIXES' not in env:
+ env['FORTRANFILESUFFIXES'] = ['.i']
+ else:
+ env['FORTRANFILESUFFIXES'].append('.i')
+
+ if 'F90FILESUFFIXES' not in env:
+ env['F90FILESUFFIXES'] = ['.i90']
+ else:
+ env['F90FILESUFFIXES'].append('.i90')
+
+ add_all_to_env(env)
+
+ env['FORTRAN'] = 'ifl'
+ env['SHFORTRAN'] = '$FORTRAN'
+ env['FORTRANCOM'] = '$FORTRAN $FORTRANFLAGS $_FORTRANINCFLAGS /c $SOURCES /Fo$TARGET'
+ env['FORTRANPPCOM'] = '$FORTRAN $FORTRANFLAGS $CPPFLAGS $_CPPDEFFLAGS $_FORTRANINCFLAGS /c $SOURCES /Fo$TARGET'
+ env['SHFORTRANCOM'] = '$SHFORTRAN $SHFORTRANFLAGS $_FORTRANINCFLAGS /c $SOURCES /Fo$TARGET'
+ env['SHFORTRANPPCOM'] = '$SHFORTRAN $SHFORTRANFLAGS $CPPFLAGS $_CPPDEFFLAGS $_FORTRANINCFLAGS /c $SOURCES /Fo$TARGET'
+
+def exists(env):
+ return env.Detect('ifl')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/ifort.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/ifort.py
new file mode 100644
index 00000000..7d50c5aa
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/ifort.py
@@ -0,0 +1,88 @@
+"""SCons.Tool.ifort
+
+Tool-specific initialization for newer versions of the Intel Fortran Compiler
+for Linux/Windows (and possibly Mac OS X).
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/ifort.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Defaults
+from SCons.Scanner.Fortran import FortranScan
+from FortranCommon import add_all_to_env
+
+def generate(env):
+ """Add Builders and construction variables for ifort to an Environment."""
+ # ifort supports Fortran 90 and Fortran 95
+ # Additionally, ifort recognizes more file extensions.
+ fscan = FortranScan("FORTRANPATH")
+ SCons.Tool.SourceFileScanner.add_scanner('.i', fscan)
+ SCons.Tool.SourceFileScanner.add_scanner('.i90', fscan)
+
+ if 'FORTRANFILESUFFIXES' not in env:
+ env['FORTRANFILESUFFIXES'] = ['.i']
+ else:
+ env['FORTRANFILESUFFIXES'].append('.i')
+
+ if 'F90FILESUFFIXES' not in env:
+ env['F90FILESUFFIXES'] = ['.i90']
+ else:
+ env['F90FILESUFFIXES'].append('.i90')
+
+ add_all_to_env(env)
+
+ fc = 'ifort'
+
+ for dialect in ['F77', 'F90', 'FORTRAN', 'F95']:
+ env['%s' % dialect] = fc
+ env['SH%s' % dialect] = '$%s' % dialect
+ if env['PLATFORM'] == 'posix':
+ env['SH%sFLAGS' % dialect] = SCons.Util.CLVar('$%sFLAGS -fPIC' % dialect)
+
+ if env['PLATFORM'] == 'win32':
+ # On Windows, the ifort compiler specifies the object on the
+ # command line with -object:, not -o. Massage the necessary
+ # command-line construction variables.
+ for dialect in ['F77', 'F90', 'FORTRAN', 'F95']:
+ for var in ['%sCOM' % dialect, '%sPPCOM' % dialect,
+ 'SH%sCOM' % dialect, 'SH%sPPCOM' % dialect]:
+ env[var] = env[var].replace('-o $TARGET', '-object:$TARGET')
+ env['FORTRANMODDIRPREFIX'] = "/module:"
+ else:
+ env['FORTRANMODDIRPREFIX'] = "-module "
+
+def exists(env):
+ return env.Detect('ifort')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/ilink.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/ilink.py
new file mode 100644
index 00000000..7a255a73
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/ilink.py
@@ -0,0 +1,59 @@
+"""SCons.Tool.ilink
+
+Tool-specific initialization for the OS/2 ilink linker.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/ilink.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Defaults
+import SCons.Tool
+import SCons.Util
+
+def generate(env):
+ """Add Builders and construction variables for ilink to an Environment."""
+ SCons.Tool.createProgBuilder(env)
+
+ env['LINK'] = 'ilink'
+ env['LINKFLAGS'] = SCons.Util.CLVar('')
+ env['LINKCOM'] = '$LINK $LINKFLAGS /O:$TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS'
+ env['LIBDIRPREFIX']='/LIBPATH:'
+ env['LIBDIRSUFFIX']=''
+ env['LIBLINKPREFIX']=''
+ env['LIBLINKSUFFIX']='$LIBSUFFIX'
+
+def exists(env):
+ return env.Detect('ilink')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/ilink32.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/ilink32.py
new file mode 100644
index 00000000..1af9af10
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/ilink32.py
@@ -0,0 +1,60 @@
+"""SCons.Tool.ilink32
+
+XXX
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/ilink32.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Tool
+import SCons.Tool.bcc32
+import SCons.Util
+
+def generate(env):
+ """Add Builders and construction variables for Borland ilink to an
+ Environment."""
+ SCons.Tool.createSharedLibBuilder(env)
+ SCons.Tool.createProgBuilder(env)
+
+ env['LINK'] = '$CC'
+ env['LINKFLAGS'] = SCons.Util.CLVar('')
+ env['LINKCOM'] = '$LINK -q $LINKFLAGS -e$TARGET $SOURCES $LIBS'
+ env['LIBDIRPREFIX']=''
+ env['LIBDIRSUFFIX']=''
+ env['LIBLINKPREFIX']=''
+ env['LIBLINKSUFFIX']='$LIBSUFFIX'
+
+
+def exists(env):
+ # Uses bcc32 to do linking as it generally knows where the standard
+ # LIBS are and set up the linking correctly
+ return SCons.Tool.bcc32.findIt('bcc32', env)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/install.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/install.py
new file mode 100644
index 00000000..9c047100
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/install.py
@@ -0,0 +1,229 @@
+"""SCons.Tool.install
+
+Tool-specific initialization for the install tool.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/install.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+import shutil
+import stat
+
+import SCons.Action
+from SCons.Util import make_path_relative
+
+#
+# We keep track of *all* installed files.
+_INSTALLED_FILES = []
+_UNIQUE_INSTALLED_FILES = None
+
+#
+# Functions doing the actual work of the Install Builder.
+#
+def copyFunc(dest, source, env):
+ """Install a source file or directory into a destination by copying,
+ (including copying permission/mode bits)."""
+
+ if os.path.isdir(source):
+ if os.path.exists(dest):
+ if not os.path.isdir(dest):
+ raise SCons.Errors.UserError("cannot overwrite non-directory `%s' with a directory `%s'" % (str(dest), str(source)))
+ else:
+ parent = os.path.split(dest)[0]
+ if not os.path.exists(parent):
+ os.makedirs(parent)
+ shutil.copytree(source, dest)
+ else:
+ shutil.copy2(source, dest)
+ st = os.stat(source)
+ os.chmod(dest, stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)
+
+ return 0
+
+def installFunc(target, source, env):
+ """Install a source file into a target using the function specified
+ as the INSTALL construction variable."""
+ try:
+ install = env['INSTALL']
+ except KeyError:
+ raise SCons.Errors.UserError('Missing INSTALL construction variable.')
+
+ assert len(target)==len(source), \
+ "Installing source %s into target %s: target and source lists must have same length."%(list(map(str, source)), list(map(str, target)))
+ for t,s in zip(target,source):
+ if install(t.get_path(),s.get_path(),env):
+ return 1
+
+ return 0
+
+def stringFunc(target, source, env):
+ installstr = env.get('INSTALLSTR')
+ if installstr:
+ return env.subst_target_source(installstr, 0, target, source)
+ target = str(target[0])
+ source = str(source[0])
+ if os.path.isdir(source):
+ type = 'directory'
+ else:
+ type = 'file'
+ return 'Install %s: "%s" as "%s"' % (type, source, target)
+
+#
+# Emitter functions
+#
+def add_targets_to_INSTALLED_FILES(target, source, env):
+ """ an emitter that adds all target files to the list stored in the
+ _INSTALLED_FILES global variable. This way all installed files of one
+ scons call will be collected.
+ """
+ global _INSTALLED_FILES, _UNIQUE_INSTALLED_FILES
+ _INSTALLED_FILES.extend(target)
+ _UNIQUE_INSTALLED_FILES = None
+ return (target, source)
+
+class DESTDIR_factory(object):
+ """ a node factory, where all files will be relative to the dir supplied
+ in the constructor.
+ """
+ def __init__(self, env, dir):
+ self.env = env
+ self.dir = env.arg2nodes( dir, env.fs.Dir )[0]
+
+ def Entry(self, name):
+ name = make_path_relative(name)
+ return self.dir.Entry(name)
+
+ def Dir(self, name):
+ name = make_path_relative(name)
+ return self.dir.Dir(name)
+
+#
+# The Builder Definition
+#
+install_action = SCons.Action.Action(installFunc, stringFunc)
+installas_action = SCons.Action.Action(installFunc, stringFunc)
+
+BaseInstallBuilder = None
+
+def InstallBuilderWrapper(env, target=None, source=None, dir=None, **kw):
+ if target and dir:
+ import SCons.Errors
+ raise SCons.Errors.UserError("Both target and dir defined for Install(), only one may be defined.")
+ if not dir:
+ dir=target
+
+ import SCons.Script
+ install_sandbox = SCons.Script.GetOption('install_sandbox')
+ if install_sandbox:
+ target_factory = DESTDIR_factory(env, install_sandbox)
+ else:
+ target_factory = env.fs
+
+ try:
+ dnodes = env.arg2nodes(dir, target_factory.Dir)
+ except TypeError:
+ raise SCons.Errors.UserError("Target `%s' of Install() is a file, but should be a directory. Perhaps you have the Install() arguments backwards?" % str(dir))
+ sources = env.arg2nodes(source, env.fs.Entry)
+ tgt = []
+ for dnode in dnodes:
+ for src in sources:
+ # Prepend './' so the lookup doesn't interpret an initial
+ # '#' on the file name portion as meaning the Node should
+ # be relative to the top-level SConstruct directory.
+ target = env.fs.Entry('.'+os.sep+src.name, dnode)
+ #tgt.extend(BaseInstallBuilder(env, target, src, **kw))
+ tgt.extend(BaseInstallBuilder(env, target, src, **kw))
+ return tgt
+
+def InstallAsBuilderWrapper(env, target=None, source=None, **kw):
+ result = []
+ for src, tgt in map(lambda x, y: (x, y), source, target):
+ #result.extend(BaseInstallBuilder(env, tgt, src, **kw))
+ result.extend(BaseInstallBuilder(env, tgt, src, **kw))
+ return result
+
+added = None
+
+def generate(env):
+
+ from SCons.Script import AddOption, GetOption
+ global added
+ if not added:
+ added = 1
+ AddOption('--install-sandbox',
+ dest='install_sandbox',
+ type="string",
+ action="store",
+ help='A directory under which all installed files will be placed.')
+
+ global BaseInstallBuilder
+ if BaseInstallBuilder is None:
+ install_sandbox = GetOption('install_sandbox')
+ if install_sandbox:
+ target_factory = DESTDIR_factory(env, install_sandbox)
+ else:
+ target_factory = env.fs
+
+ BaseInstallBuilder = SCons.Builder.Builder(
+ action = install_action,
+ target_factory = target_factory.Entry,
+ source_factory = env.fs.Entry,
+ multi = 1,
+ emitter = [ add_targets_to_INSTALLED_FILES, ],
+ name = 'InstallBuilder')
+
+ env['BUILDERS']['_InternalInstall'] = InstallBuilderWrapper
+ env['BUILDERS']['_InternalInstallAs'] = InstallAsBuilderWrapper
+
+ # We'd like to initialize this doing something like the following,
+ # but there isn't yet support for a ${SOURCE.type} expansion that
+ # will print "file" or "directory" depending on what's being
+ # installed. For now we punt by not initializing it, and letting
+ # the stringFunc() that we put in the action fall back to the
+ # hand-crafted default string if it's not set.
+ #
+ #try:
+ # env['INSTALLSTR']
+ #except KeyError:
+ # env['INSTALLSTR'] = 'Install ${SOURCE.type}: "$SOURCES" as "$TARGETS"'
+
+ try:
+ env['INSTALL']
+ except KeyError:
+ env['INSTALL'] = copyFunc
+
+def exists(env):
+ return 1
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/intelc.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/intelc.py
new file mode 100644
index 00000000..08f97c07
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/intelc.py
@@ -0,0 +1,482 @@
+"""SCons.Tool.icl
+
+Tool-specific initialization for the Intel C/C++ compiler.
+Supports Linux and Windows compilers, v7 and up.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+from __future__ import division
+
+__revision__ = "src/engine/SCons/Tool/intelc.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import math, sys, os.path, glob, string, re
+
+is_windows = sys.platform == 'win32'
+is_win64 = is_windows and (os.environ['PROCESSOR_ARCHITECTURE'] == 'AMD64' or
+ ('PROCESSOR_ARCHITEW6432' in os.environ and
+ os.environ['PROCESSOR_ARCHITEW6432'] == 'AMD64'))
+is_linux = sys.platform == 'linux2'
+is_mac = sys.platform == 'darwin'
+
+if is_windows:
+ import SCons.Tool.msvc
+elif is_linux:
+ import SCons.Tool.gcc
+elif is_mac:
+ import SCons.Tool.gcc
+import SCons.Util
+import SCons.Warnings
+
+# Exceptions for this tool
+class IntelCError(SCons.Errors.InternalError):
+ pass
+class MissingRegistryError(IntelCError): # missing registry entry
+ pass
+class MissingDirError(IntelCError): # dir not found
+ pass
+class NoRegistryModuleError(IntelCError): # can't read registry at all
+ pass
+
+def uniquify(s):
+ """Return a sequence containing only one copy of each unique element from input sequence s.
+ Does not preserve order.
+ Input sequence must be hashable (i.e. must be usable as a dictionary key)."""
+ u = {}
+ for x in s:
+ u[x] = 1
+ return list(u.keys())
+
+def linux_ver_normalize(vstr):
+ """Normalize a Linux compiler version number.
+ Intel changed from "80" to "9.0" in 2005, so we assume if the number
+ is greater than 60 it's an old-style number and otherwise new-style.
+ Always returns an old-style float like 80 or 90 for compatibility with Windows.
+ Shades of Y2K!"""
+ # Check for version number like 9.1.026: return 91.026
+ m = re.match(r'([0-9]+)\.([0-9]+)\.([0-9]+)', vstr)
+ if m:
+ vmaj,vmin,build = m.groups()
+ return float(vmaj) * 10. + float(vmin) + float(build) / 1000.;
+ else:
+ f = float(vstr)
+ if is_windows:
+ return f
+ else:
+ if f < 60: return f * 10.0
+ else: return f
+
+def check_abi(abi):
+ """Check for valid ABI (application binary interface) name,
+ and map into canonical one"""
+ if not abi:
+ return None
+ abi = abi.lower()
+ # valid_abis maps input name to canonical name
+ if is_windows:
+ valid_abis = {'ia32' : 'ia32',
+ 'x86' : 'ia32',
+ 'ia64' : 'ia64',
+ 'em64t' : 'em64t',
+ 'amd64' : 'em64t'}
+ if is_linux:
+ valid_abis = {'ia32' : 'ia32',
+ 'x86' : 'ia32',
+ 'x86_64' : 'x86_64',
+ 'em64t' : 'x86_64',
+ 'amd64' : 'x86_64'}
+ if is_mac:
+ valid_abis = {'ia32' : 'ia32',
+ 'x86' : 'ia32',
+ 'x86_64' : 'x86_64',
+ 'em64t' : 'x86_64'}
+ try:
+ abi = valid_abis[abi]
+ except KeyError:
+ raise SCons.Errors.UserError("Intel compiler: Invalid ABI %s, valid values are %s"% \
+ (abi, list(valid_abis.keys())))
+ return abi
+
+def vercmp(a, b):
+ """Compare strings as floats,
+ but Intel changed Linux naming convention at 9.0"""
+ return cmp(linux_ver_normalize(b), linux_ver_normalize(a))
+
+def get_version_from_list(v, vlist):
+ """See if we can match v (string) in vlist (list of strings)
+ Linux has to match in a fuzzy way."""
+ if is_windows:
+ # Simple case, just find it in the list
+ if v in vlist: return v
+ else: return None
+ else:
+ # Fuzzy match: normalize version number first, but still return
+ # original non-normalized form.
+ fuzz = 0.001
+ for vi in vlist:
+ if math.fabs(linux_ver_normalize(vi) - linux_ver_normalize(v)) < fuzz:
+ return vi
+ # Not found
+ return None
+
+def get_intel_registry_value(valuename, version=None, abi=None):
+ """
+ Return a value from the Intel compiler registry tree. (Windows only)
+ """
+ # Open the key:
+ if is_win64:
+ K = 'Software\\Wow6432Node\\Intel\\Compilers\\C++\\' + version + '\\'+abi.upper()
+ else:
+ K = 'Software\\Intel\\Compilers\\C++\\' + version + '\\'+abi.upper()
+ try:
+ k = SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE, K)
+ except SCons.Util.RegError:
+ raise MissingRegistryError("%s was not found in the registry, for Intel compiler version %s, abi='%s'"%(K, version,abi))
+
+ # Get the value:
+ try:
+ v = SCons.Util.RegQueryValueEx(k, valuename)[0]
+ return v # or v.encode('iso-8859-1', 'replace') to remove unicode?
+ except SCons.Util.RegError:
+ raise MissingRegistryError("%s\\%s was not found in the registry."%(K, valuename))
+
+
+def get_all_compiler_versions():
+ """Returns a sorted list of strings, like "70" or "80" or "9.0"
+ with most recent compiler version first.
+ """
+ versions=[]
+ if is_windows:
+ if is_win64:
+ keyname = 'Software\\WoW6432Node\\Intel\\Compilers\\C++'
+ else:
+ keyname = 'Software\\Intel\\Compilers\\C++'
+ try:
+ k = SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE,
+ keyname)
+ except WindowsError:
+ return []
+ i = 0
+ versions = []
+ try:
+ while i < 100:
+ subkey = SCons.Util.RegEnumKey(k, i) # raises EnvironmentError
+ # Check that this refers to an existing dir.
+ # This is not 100% perfect but should catch common
+ # installation issues like when the compiler was installed
+ # and then the install directory deleted or moved (rather
+ # than uninstalling properly), so the registry values
+ # are still there.
+ ok = False
+ for try_abi in ('IA32', 'IA32e', 'IA64', 'EM64T'):
+ try:
+ d = get_intel_registry_value('ProductDir', subkey, try_abi)
+ except MissingRegistryError:
+ continue # not found in reg, keep going
+ if os.path.exists(d): ok = True
+ if ok:
+ versions.append(subkey)
+ else:
+ try:
+ # Registry points to nonexistent dir. Ignore this
+ # version.
+ value = get_intel_registry_value('ProductDir', subkey, 'IA32')
+ except MissingRegistryError, e:
+
+ # Registry key is left dangling (potentially
+ # after uninstalling).
+
+ print \
+ "scons: *** Ignoring the registry key for the Intel compiler version %s.\n" \
+ "scons: *** It seems that the compiler was uninstalled and that the registry\n" \
+ "scons: *** was not cleaned up properly.\n" % subkey
+ else:
+ print "scons: *** Ignoring "+str(value)
+
+ i = i + 1
+ except EnvironmentError:
+ # no more subkeys
+ pass
+ elif is_linux:
+ for d in glob.glob('/opt/intel_cc_*'):
+ # Typical dir here is /opt/intel_cc_80.
+ m = re.search(r'cc_(.*)$', d)
+ if m:
+ versions.append(m.group(1))
+ for d in glob.glob('/opt/intel/cc*/*'):
+ # Typical dir here is /opt/intel/cc/9.0 for IA32,
+ # /opt/intel/cce/9.0 for EMT64 (AMD64)
+ m = re.search(r'([0-9.]+)$', d)
+ if m:
+ versions.append(m.group(1))
+ elif is_mac:
+ for d in glob.glob('/opt/intel/cc*/*'):
+ # Typical dir here is /opt/intel/cc/9.0 for IA32,
+ # /opt/intel/cce/9.0 for EMT64 (AMD64)
+ m = re.search(r'([0-9.]+)$', d)
+ if m:
+ versions.append(m.group(1))
+ return sorted(uniquify(versions)) # remove dups
+
+def get_intel_compiler_top(version, abi):
+ """
+ Return the main path to the top-level dir of the Intel compiler,
+ using the given version.
+ The compiler will be in <top>/bin/icl.exe (icc on linux),
+ the include dir is <top>/include, etc.
+ """
+
+ if is_windows:
+ if not SCons.Util.can_read_reg:
+ raise NoRegistryModuleError("No Windows registry module was found")
+ top = get_intel_registry_value('ProductDir', version, abi)
+ # pre-11, icl was in Bin. 11 and later, it's in Bin/<abi> apparently.
+ if not os.path.exists(os.path.join(top, "Bin", "icl.exe")) \
+ and not os.path.exists(os.path.join(top, "Bin", abi, "icl.exe")):
+ raise MissingDirError("Can't find Intel compiler in %s"%(top))
+ elif is_mac or is_linux:
+ # first dir is new (>=9.0) style, second is old (8.0) style.
+ dirs=('/opt/intel/cc/%s', '/opt/intel_cc_%s')
+ if abi == 'x86_64':
+ dirs=('/opt/intel/cce/%s',) # 'e' stands for 'em64t', aka x86_64 aka amd64
+ top=None
+ for d in dirs:
+ if os.path.exists(os.path.join(d%version, "bin", "icc")):
+ top = d%version
+ break
+ if not top:
+ raise MissingDirError("Can't find version %s Intel compiler in %s (abi='%s')"%(version,top, abi))
+ return top
+
+
+def generate(env, version=None, abi=None, topdir=None, verbose=0):
+ """Add Builders and construction variables for Intel C/C++ compiler
+ to an Environment.
+ args:
+ version: (string) compiler version to use, like "80"
+ abi: (string) 'win32' or whatever Itanium version wants
+ topdir: (string) compiler top dir, like
+ "c:\Program Files\Intel\Compiler70"
+ If topdir is used, version and abi are ignored.
+ verbose: (int) if >0, prints compiler version used.
+ """
+ if not (is_mac or is_linux or is_windows):
+ # can't handle this platform
+ return
+
+ if is_windows:
+ SCons.Tool.msvc.generate(env)
+ elif is_linux:
+ SCons.Tool.gcc.generate(env)
+ elif is_mac:
+ SCons.Tool.gcc.generate(env)
+
+ # if version is unspecified, use latest
+ vlist = get_all_compiler_versions()
+ if not version:
+ if vlist:
+ version = vlist[0]
+ else:
+ # User may have specified '90' but we need to get actual dirname '9.0'.
+ # get_version_from_list does that mapping.
+ v = get_version_from_list(version, vlist)
+ if not v:
+ raise SCons.Errors.UserError("Invalid Intel compiler version %s: "%version + \
+ "installed versions are %s"%(', '.join(vlist)))
+ version = v
+
+ # if abi is unspecified, use ia32
+ # alternatives are ia64 for Itanium, or amd64 or em64t or x86_64 (all synonyms here)
+ abi = check_abi(abi)
+ if abi is None:
+ if is_mac or is_linux:
+ # Check if we are on 64-bit linux, default to 64 then.
+ uname_m = os.uname()[4]
+ if uname_m == 'x86_64':
+ abi = 'x86_64'
+ else:
+ abi = 'ia32'
+ else:
+ if is_win64:
+ abi = 'em64t'
+ else:
+ abi = 'ia32'
+
+ if version and not topdir:
+ try:
+ topdir = get_intel_compiler_top(version, abi)
+ except (SCons.Util.RegError, IntelCError):
+ topdir = None
+
+ if not topdir:
+ # Normally this is an error, but it might not be if the compiler is
+ # on $PATH and the user is importing their env.
+ class ICLTopDirWarning(SCons.Warnings.Warning):
+ pass
+ if (is_mac or is_linux) and not env.Detect('icc') or \
+ is_windows and not env.Detect('icl'):
+
+ SCons.Warnings.enableWarningClass(ICLTopDirWarning)
+ SCons.Warnings.warn(ICLTopDirWarning,
+ "Failed to find Intel compiler for version='%s', abi='%s'"%
+ (str(version), str(abi)))
+ else:
+ # should be cleaned up to say what this other version is
+ # since in this case we have some other Intel compiler installed
+ SCons.Warnings.enableWarningClass(ICLTopDirWarning)
+ SCons.Warnings.warn(ICLTopDirWarning,
+ "Can't find Intel compiler top dir for version='%s', abi='%s'"%
+ (str(version), str(abi)))
+
+ if topdir:
+ if verbose:
+ print "Intel C compiler: using version %s (%g), abi %s, in '%s'"%\
+ (repr(version), linux_ver_normalize(version),abi,topdir)
+ if is_linux:
+ # Show the actual compiler version by running the compiler.
+ os.system('%s/bin/icc --version'%topdir)
+ if is_mac:
+ # Show the actual compiler version by running the compiler.
+ os.system('%s/bin/icc --version'%topdir)
+
+ env['INTEL_C_COMPILER_TOP'] = topdir
+ if is_linux:
+ paths={'INCLUDE' : 'include',
+ 'LIB' : 'lib',
+ 'PATH' : 'bin',
+ 'LD_LIBRARY_PATH' : 'lib'}
+ for p in paths.keys():
+ env.PrependENVPath(p, os.path.join(topdir, paths[p]))
+ if is_mac:
+ paths={'INCLUDE' : 'include',
+ 'LIB' : 'lib',
+ 'PATH' : 'bin',
+ 'LD_LIBRARY_PATH' : 'lib'}
+ for p in paths.keys():
+ env.PrependENVPath(p, os.path.join(topdir, paths[p]))
+ if is_windows:
+ # env key reg valname default subdir of top
+ paths=(('INCLUDE', 'IncludeDir', 'Include'),
+ ('LIB' , 'LibDir', 'Lib'),
+ ('PATH' , 'BinDir', 'Bin'))
+ # We are supposed to ignore version if topdir is set, so set
+ # it to the emptry string if it's not already set.
+ if version is None:
+ version = ''
+ # Each path has a registry entry, use that or default to subdir
+ for p in paths:
+ try:
+ path=get_intel_registry_value(p[1], version, abi)
+ # These paths may have $(ICInstallDir)
+ # which needs to be substituted with the topdir.
+ path=path.replace('$(ICInstallDir)', topdir + os.sep)
+ except IntelCError:
+ # Couldn't get it from registry: use default subdir of topdir
+ env.PrependENVPath(p[0], os.path.join(topdir, p[2]))
+ else:
+ env.PrependENVPath(p[0], path.split(os.pathsep))
+ # print "ICL %s: %s, final=%s"%(p[0], path, str(env['ENV'][p[0]]))
+
+ if is_windows:
+ env['CC'] = 'icl'
+ env['CXX'] = 'icl'
+ env['LINK'] = 'xilink'
+ else:
+ env['CC'] = 'icc'
+ env['CXX'] = 'icpc'
+ # Don't reset LINK here;
+ # use smart_link which should already be here from link.py.
+ #env['LINK'] = '$CC'
+ env['AR'] = 'xiar'
+ env['LD'] = 'xild' # not used by default
+
+ # This is not the exact (detailed) compiler version,
+ # just the major version as determined above or specified
+ # by the user. It is a float like 80 or 90, in normalized form for Linux
+ # (i.e. even for Linux 9.0 compiler, still returns 90 rather than 9.0)
+ if version:
+ env['INTEL_C_COMPILER_VERSION']=linux_ver_normalize(version)
+
+ if is_windows:
+ # Look for license file dir
+ # in system environment, registry, and default location.
+ envlicdir = os.environ.get("INTEL_LICENSE_FILE", '')
+ K = ('SOFTWARE\Intel\Licenses')
+ try:
+ k = SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE, K)
+ reglicdir = SCons.Util.RegQueryValueEx(k, "w_cpp")[0]
+ except (AttributeError, SCons.Util.RegError):
+ reglicdir = ""
+ defaultlicdir = r'C:\Program Files\Common Files\Intel\Licenses'
+
+ licdir = None
+ for ld in [envlicdir, reglicdir]:
+ # If the string contains an '@', then assume it's a network
+ # license (port@system) and good by definition.
+ if ld and (ld.find('@') != -1 or os.path.exists(ld)):
+ licdir = ld
+ break
+ if not licdir:
+ licdir = defaultlicdir
+ if not os.path.exists(licdir):
+ class ICLLicenseDirWarning(SCons.Warnings.Warning):
+ pass
+ SCons.Warnings.enableWarningClass(ICLLicenseDirWarning)
+ SCons.Warnings.warn(ICLLicenseDirWarning,
+ "Intel license dir was not found."
+ " Tried using the INTEL_LICENSE_FILE environment variable (%s), the registry (%s) and the default path (%s)."
+ " Using the default path as a last resort."
+ % (envlicdir, reglicdir, defaultlicdir))
+ env['ENV']['INTEL_LICENSE_FILE'] = licdir
+
+def exists(env):
+ if not (is_mac or is_linux or is_windows):
+ # can't handle this platform
+ return 0
+
+ try:
+ versions = get_all_compiler_versions()
+ except (SCons.Util.RegError, IntelCError):
+ versions = None
+ detected = versions is not None and len(versions) > 0
+ if not detected:
+ # try env.Detect, maybe that will work
+ if is_windows:
+ return env.Detect('icl')
+ elif is_linux:
+ return env.Detect('icc')
+ elif is_mac:
+ return env.Detect('icc')
+ return detected
+
+# end of file
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/ipkg.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/ipkg.py
new file mode 100644
index 00000000..7558bd26
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/ipkg.py
@@ -0,0 +1,67 @@
+"""SCons.Tool.ipkg
+
+Tool-specific initialization for ipkg.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+The ipkg tool calls the ipkg-build. Its only argument should be the
+packages fake_root.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/ipkg.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+
+import SCons.Builder
+
+def generate(env):
+ """Add Builders and construction variables for ipkg to an Environment."""
+ try:
+ bld = env['BUILDERS']['Ipkg']
+ except KeyError:
+ bld = SCons.Builder.Builder( action = '$IPKGCOM',
+ suffix = '$IPKGSUFFIX',
+ source_scanner = None,
+ target_scanner = None)
+ env['BUILDERS']['Ipkg'] = bld
+
+ env['IPKG'] = 'ipkg-build'
+ env['IPKGCOM'] = '$IPKG $IPKGFLAGS ${SOURCE}'
+ env['IPKGUSER'] = os.popen('id -un').read().strip()
+ env['IPKGGROUP'] = os.popen('id -gn').read().strip()
+ env['IPKGFLAGS'] = SCons.Util.CLVar('-o $IPKGUSER -g $IPKGGROUP')
+ env['IPKGSUFFIX'] = '.ipk'
+
+def exists(env):
+ return env.Detect('ipkg-build')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/jar.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/jar.py
new file mode 100644
index 00000000..21c5ce41
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/jar.py
@@ -0,0 +1,110 @@
+"""SCons.Tool.jar
+
+Tool-specific initialization for jar.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/jar.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Subst
+import SCons.Util
+
+def jarSources(target, source, env, for_signature):
+ """Only include sources that are not a manifest file."""
+ try:
+ env['JARCHDIR']
+ except KeyError:
+ jarchdir_set = False
+ else:
+ jarchdir_set = True
+ jarchdir = env.subst('$JARCHDIR', target=target, source=source)
+ if jarchdir:
+ jarchdir = env.fs.Dir(jarchdir)
+ result = []
+ for src in source:
+ contents = src.get_text_contents()
+ if contents[:16] != "Manifest-Version":
+ if jarchdir_set:
+ _chdir = jarchdir
+ else:
+ try:
+ _chdir = src.attributes.java_classdir
+ except AttributeError:
+ _chdir = None
+ if _chdir:
+ # If we are changing the dir with -C, then sources should
+ # be relative to that directory.
+ src = SCons.Subst.Literal(src.get_path(_chdir))
+ result.append('-C')
+ result.append(_chdir)
+ result.append(src)
+ return result
+
+def jarManifest(target, source, env, for_signature):
+ """Look in sources for a manifest file, if any."""
+ for src in source:
+ contents = src.get_text_contents()
+ if contents[:16] == "Manifest-Version":
+ return src
+ return ''
+
+def jarFlags(target, source, env, for_signature):
+ """If we have a manifest, make sure that the 'm'
+ flag is specified."""
+ jarflags = env.subst('$JARFLAGS', target=target, source=source)
+ for src in source:
+ contents = src.get_text_contents()
+ if contents[:16] == "Manifest-Version":
+ if not 'm' in jarflags:
+ return jarflags + 'm'
+ break
+ return jarflags
+
+def generate(env):
+ """Add Builders and construction variables for jar to an Environment."""
+ SCons.Tool.CreateJarBuilder(env)
+
+ env['JAR'] = 'jar'
+ env['JARFLAGS'] = SCons.Util.CLVar('cf')
+ env['_JARFLAGS'] = jarFlags
+ env['_JARMANIFEST'] = jarManifest
+ env['_JARSOURCES'] = jarSources
+ env['_JARCOM'] = '$JAR $_JARFLAGS $TARGET $_JARMANIFEST $_JARSOURCES'
+ env['JARCOM'] = "${TEMPFILE('$_JARCOM')}"
+ env['JARSUFFIX'] = '.jar'
+
+def exists(env):
+ return env.Detect('jar')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/javac.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/javac.py
new file mode 100644
index 00000000..df3c0306
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/javac.py
@@ -0,0 +1,230 @@
+"""SCons.Tool.javac
+
+Tool-specific initialization for javac.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Tool/javac.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+import os.path
+
+import SCons.Action
+import SCons.Builder
+from SCons.Node.FS import _my_normcase
+from SCons.Tool.JavaCommon import parse_java_file
+import SCons.Util
+
+def classname(path):
+ """Turn a string (path name) into a Java class name."""
+ return os.path.normpath(path).replace(os.sep, '.')
+
+def emit_java_classes(target, source, env):
+ """Create and return lists of source java files
+ and their corresponding target class files.
+ """
+ java_suffix = env.get('JAVASUFFIX', '.java')
+ class_suffix = env.get('JAVACLASSSUFFIX', '.class')
+
+ target[0].must_be_same(SCons.Node.FS.Dir)
+ classdir = target[0]
+
+ s = source[0].rentry().disambiguate()
+ if isinstance(s, SCons.Node.FS.File):
+ sourcedir = s.dir.rdir()
+ elif isinstance(s, SCons.Node.FS.Dir):
+ sourcedir = s.rdir()
+ else:
+ raise SCons.Errors.UserError("Java source must be File or Dir, not '%s'" % s.__class__)
+
+ slist = []
+ js = _my_normcase(java_suffix)
+ for entry in source:
+ entry = entry.rentry().disambiguate()
+ if isinstance(entry, SCons.Node.FS.File):
+ slist.append(entry)
+ elif isinstance(entry, SCons.Node.FS.Dir):
+ result = SCons.Util.OrderedDict()
+ dirnode = entry.rdir()
+ def find_java_files(arg, dirpath, filenames):
+ java_files = sorted([n for n in filenames
+ if _my_normcase(n).endswith(js)])
+ mydir = dirnode.Dir(dirpath)
+ java_paths = [mydir.File(f) for f in java_files]
+ for jp in java_paths:
+ arg[jp] = True
+ for dirpath, dirnames, filenames in os.walk(dirnode.get_abspath()):
+ find_java_files(result, dirpath, filenames)
+ entry.walk(find_java_files, result)
+
+ slist.extend(list(result.keys()))
+ else:
+ raise SCons.Errors.UserError("Java source must be File or Dir, not '%s'" % entry.__class__)
+
+ version = env.get('JAVAVERSION', '1.4')
+ full_tlist = []
+ for f in slist:
+ tlist = []
+ source_file_based = True
+ pkg_dir = None
+ if not f.is_derived():
+ pkg_dir, classes = parse_java_file(f.rfile().get_abspath(), version)
+ if classes:
+ source_file_based = False
+ if pkg_dir:
+ d = target[0].Dir(pkg_dir)
+ p = pkg_dir + os.sep
+ else:
+ d = target[0]
+ p = ''
+ for c in classes:
+ t = d.File(c + class_suffix)
+ t.attributes.java_classdir = classdir
+ t.attributes.java_sourcedir = sourcedir
+ t.attributes.java_classname = classname(p + c)
+ tlist.append(t)
+
+ if source_file_based:
+ base = f.name[:-len(java_suffix)]
+ if pkg_dir:
+ t = target[0].Dir(pkg_dir).File(base + class_suffix)
+ else:
+ t = target[0].File(base + class_suffix)
+ t.attributes.java_classdir = classdir
+ t.attributes.java_sourcedir = f.dir
+ t.attributes.java_classname = classname(base)
+ tlist.append(t)
+
+ for t in tlist:
+ t.set_specific_source([f])
+
+ full_tlist.extend(tlist)
+
+ return full_tlist, slist
+
+JavaAction = SCons.Action.Action('$JAVACCOM', '$JAVACCOMSTR')
+
+JavaBuilder = SCons.Builder.Builder(action = JavaAction,
+ emitter = emit_java_classes,
+ target_factory = SCons.Node.FS.Entry,
+ source_factory = SCons.Node.FS.Entry)
+
+class pathopt(object):
+ """
+ Callable object for generating javac-style path options from
+ a construction variable (e.g. -classpath, -sourcepath).
+ """
+ def __init__(self, opt, var, default=None):
+ self.opt = opt
+ self.var = var
+ self.default = default
+
+ def __call__(self, target, source, env, for_signature):
+ path = env[self.var]
+ if path and not SCons.Util.is_List(path):
+ path = [path]
+ if self.default:
+ path = path + [ env[self.default] ]
+ if path:
+ return [self.opt, os.pathsep.join(path)]
+ #return self.opt + " " + os.pathsep.join(path)
+ else:
+ return []
+ #return ""
+
+def Java(env, target, source, *args, **kw):
+ """
+ A pseudo-Builder wrapper around the separate JavaClass{File,Dir}
+ Builders.
+ """
+ if not SCons.Util.is_List(target):
+ target = [target]
+ if not SCons.Util.is_List(source):
+ source = [source]
+
+ # Pad the target list with repetitions of the last element in the
+ # list so we have a target for every source element.
+ target = target + ([target[-1]] * (len(source) - len(target)))
+
+ java_suffix = env.subst('$JAVASUFFIX')
+ result = []
+
+ for t, s in zip(target, source):
+ if isinstance(s, SCons.Node.FS.Base):
+ if isinstance(s, SCons.Node.FS.File):
+ b = env.JavaClassFile
+ else:
+ b = env.JavaClassDir
+ else:
+ if os.path.isfile(s):
+ b = env.JavaClassFile
+ elif os.path.isdir(s):
+ b = env.JavaClassDir
+ elif s[-len(java_suffix):] == java_suffix:
+ b = env.JavaClassFile
+ else:
+ b = env.JavaClassDir
+ result.extend(b(t, s, *args, **kw))
+
+ return result
+
+def generate(env):
+ """Add Builders and construction variables for javac to an Environment."""
+ java_file = SCons.Tool.CreateJavaFileBuilder(env)
+ java_class = SCons.Tool.CreateJavaClassFileBuilder(env)
+ java_class_dir = SCons.Tool.CreateJavaClassDirBuilder(env)
+ java_class.add_emitter(None, emit_java_classes)
+ java_class.add_emitter(env.subst('$JAVASUFFIX'), emit_java_classes)
+ java_class_dir.emitter = emit_java_classes
+
+ env.AddMethod(Java)
+
+ env['JAVAC'] = 'javac'
+ env['JAVACFLAGS'] = SCons.Util.CLVar('')
+ env['JAVABOOTCLASSPATH'] = []
+ env['JAVACLASSPATH'] = []
+ env['JAVASOURCEPATH'] = []
+ env['_javapathopt'] = pathopt
+ env['_JAVABOOTCLASSPATH'] = '${_javapathopt("-bootclasspath", "JAVABOOTCLASSPATH")} '
+ env['_JAVACLASSPATH'] = '${_javapathopt("-classpath", "JAVACLASSPATH")} '
+ env['_JAVASOURCEPATH'] = '${_javapathopt("-sourcepath", "JAVASOURCEPATH", "_JAVASOURCEPATHDEFAULT")} '
+ env['_JAVASOURCEPATHDEFAULT'] = '${TARGET.attributes.java_sourcedir}'
+ env['_JAVACCOM'] = '$JAVAC $JAVACFLAGS $_JAVABOOTCLASSPATH $_JAVACLASSPATH -d ${TARGET.attributes.java_classdir} $_JAVASOURCEPATH $SOURCES'
+ env['JAVACCOM'] = "${TEMPFILE('$_JAVACCOM')}"
+ env['JAVACLASSSUFFIX'] = '.class'
+ env['JAVASUFFIX'] = '.java'
+
+def exists(env):
+ return 1
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/javah.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/javah.py
new file mode 100644
index 00000000..a0228840
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/javah.py
@@ -0,0 +1,137 @@
+"""SCons.Tool.javah
+
+Tool-specific initialization for javah.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/javah.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+
+import SCons.Action
+import SCons.Builder
+import SCons.Node.FS
+import SCons.Tool.javac
+import SCons.Util
+
+def emit_java_headers(target, source, env):
+ """Create and return lists of Java stub header files that will
+ be created from a set of class files.
+ """
+ class_suffix = env.get('JAVACLASSSUFFIX', '.class')
+ classdir = env.get('JAVACLASSDIR')
+
+ if not classdir:
+ try:
+ s = source[0]
+ except IndexError:
+ classdir = '.'
+ else:
+ try:
+ classdir = s.attributes.java_classdir
+ except AttributeError:
+ classdir = '.'
+ classdir = env.Dir(classdir).rdir()
+
+ if str(classdir) == '.':
+ c_ = None
+ else:
+ c_ = str(classdir) + os.sep
+
+ slist = []
+ for src in source:
+ try:
+ classname = src.attributes.java_classname
+ except AttributeError:
+ classname = str(src)
+ if c_ and classname[:len(c_)] == c_:
+ classname = classname[len(c_):]
+ if class_suffix and classname[-len(class_suffix):] == class_suffix:
+ classname = classname[:-len(class_suffix)]
+ classname = SCons.Tool.javac.classname(classname)
+ s = src.rfile()
+ s.attributes.java_classname = classname
+ slist.append(s)
+
+ s = source[0].rfile()
+ if not hasattr(s.attributes, 'java_classdir'):
+ s.attributes.java_classdir = classdir
+
+ if target[0].__class__ is SCons.Node.FS.File:
+ tlist = target
+ else:
+ if not isinstance(target[0], SCons.Node.FS.Dir):
+ target[0].__class__ = SCons.Node.FS.Dir
+ target[0]._morph()
+ tlist = []
+ for s in source:
+ fname = s.attributes.java_classname.replace('.', '_') + '.h'
+ t = target[0].File(fname)
+ t.attributes.java_lookupdir = target[0]
+ tlist.append(t)
+
+ return tlist, source
+
+def JavaHOutFlagGenerator(target, source, env, for_signature):
+ try:
+ t = target[0]
+ except (AttributeError, IndexError, TypeError):
+ t = target
+ try:
+ return '-d ' + str(t.attributes.java_lookupdir)
+ except AttributeError:
+ return '-o ' + str(t)
+
+def getJavaHClassPath(env,target, source, for_signature):
+ path = "${SOURCE.attributes.java_classdir}"
+ if 'JAVACLASSPATH' in env and env['JAVACLASSPATH']:
+ path = SCons.Util.AppendPath(path, env['JAVACLASSPATH'])
+ return "-classpath %s" % (path)
+
+def generate(env):
+ """Add Builders and construction variables for javah to an Environment."""
+ java_javah = SCons.Tool.CreateJavaHBuilder(env)
+ java_javah.emitter = emit_java_headers
+
+ env['_JAVAHOUTFLAG'] = JavaHOutFlagGenerator
+ env['JAVAH'] = 'javah'
+ env['JAVAHFLAGS'] = SCons.Util.CLVar('')
+ env['_JAVAHCLASSPATH'] = getJavaHClassPath
+ env['JAVAHCOM'] = '$JAVAH $JAVAHFLAGS $_JAVAHOUTFLAG $_JAVAHCLASSPATH ${SOURCES.attributes.java_classname}'
+ env['JAVACLASSSUFFIX'] = '.class'
+
+def exists(env):
+ return env.Detect('javah')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/latex.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/latex.py
new file mode 100644
index 00000000..65ff78af
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/latex.py
@@ -0,0 +1,79 @@
+"""SCons.Tool.latex
+
+Tool-specific initialization for LaTeX.
+Generates .dvi files from .latex or .ltx files
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/latex.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Action
+import SCons.Defaults
+import SCons.Scanner.LaTeX
+import SCons.Util
+import SCons.Tool
+import SCons.Tool.tex
+
+def LaTeXAuxFunction(target = None, source= None, env=None):
+ result = SCons.Tool.tex.InternalLaTeXAuxAction( SCons.Tool.tex.LaTeXAction, target, source, env )
+ if result != 0:
+ SCons.Tool.tex.check_file_error_message(env['LATEX'])
+ return result
+
+LaTeXAuxAction = SCons.Action.Action(LaTeXAuxFunction,
+ strfunction=SCons.Tool.tex.TeXLaTeXStrFunction)
+
+def generate(env):
+ """Add Builders and construction variables for LaTeX to an Environment."""
+
+ env.AppendUnique(LATEXSUFFIXES=SCons.Tool.LaTeXSuffixes)
+
+ import dvi
+ dvi.generate(env)
+
+ import pdf
+ pdf.generate(env)
+
+ bld = env['BUILDERS']['DVI']
+ bld.add_action('.ltx', LaTeXAuxAction)
+ bld.add_action('.latex', LaTeXAuxAction)
+ bld.add_emitter('.ltx', SCons.Tool.tex.tex_eps_emitter)
+ bld.add_emitter('.latex', SCons.Tool.tex.tex_eps_emitter)
+
+ SCons.Tool.tex.generate_common(env)
+
+def exists(env):
+ return env.Detect('latex')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/lex.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/lex.py
new file mode 100644
index 00000000..9344173e
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/lex.py
@@ -0,0 +1,97 @@
+"""SCons.Tool.lex
+
+Tool-specific initialization for lex.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/lex.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+
+import SCons.Action
+import SCons.Tool
+import SCons.Util
+
+LexAction = SCons.Action.Action("$LEXCOM", "$LEXCOMSTR")
+
+def lexEmitter(target, source, env):
+ sourceBase, sourceExt = os.path.splitext(SCons.Util.to_String(source[0]))
+
+ if sourceExt == ".lm": # If using Objective-C
+ target = [sourceBase + ".m"] # the extension is ".m".
+
+ # This emitter essentially tries to add to the target all extra
+ # files generated by flex.
+
+ # Different options that are used to trigger the creation of extra files.
+ fileGenOptions = ["--header-file=", "--tables-file="]
+
+ lexflags = env.subst("$LEXFLAGS", target=target, source=source)
+ for option in SCons.Util.CLVar(lexflags):
+ for fileGenOption in fileGenOptions:
+ l = len(fileGenOption)
+ if option[:l] == fileGenOption:
+ # A file generating option is present, so add the
+ # file name to the target list.
+ fileName = option[l:].strip()
+ target.append(fileName)
+ return (target, source)
+
+def generate(env):
+ """Add Builders and construction variables for lex to an Environment."""
+ c_file, cxx_file = SCons.Tool.createCFileBuilders(env)
+
+ # C
+ c_file.add_action(".l", LexAction)
+ c_file.add_emitter(".l", lexEmitter)
+
+ c_file.add_action(".lex", LexAction)
+ c_file.add_emitter(".lex", lexEmitter)
+
+ # Objective-C
+ cxx_file.add_action(".lm", LexAction)
+ cxx_file.add_emitter(".lm", lexEmitter)
+
+ # C++
+ cxx_file.add_action(".ll", LexAction)
+ cxx_file.add_emitter(".ll", lexEmitter)
+
+ env["LEX"] = env.Detect("flex") or "lex"
+ env["LEXFLAGS"] = SCons.Util.CLVar("")
+ env["LEXCOM"] = "$LEX $LEXFLAGS -t $SOURCES > $TARGET"
+
+def exists(env):
+ return env.Detect(["flex", "lex"])
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/link.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/link.py
new file mode 100644
index 00000000..0210d7e1
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/link.py
@@ -0,0 +1,121 @@
+"""SCons.Tool.link
+
+Tool-specific initialization for the generic Posix linker.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/link.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Defaults
+import SCons.Tool
+import SCons.Util
+import SCons.Warnings
+
+from SCons.Tool.FortranCommon import isfortran
+
+cplusplus = __import__('c++', globals(), locals(), [])
+
+issued_mixed_link_warning = False
+
+def smart_link(source, target, env, for_signature):
+ has_cplusplus = cplusplus.iscplusplus(source)
+ has_fortran = isfortran(env, source)
+ if has_cplusplus and has_fortran:
+ global issued_mixed_link_warning
+ if not issued_mixed_link_warning:
+ msg = "Using $CXX to link Fortran and C++ code together.\n\t" + \
+ "This may generate a buggy executable if the '%s'\n\t" + \
+ "compiler does not know how to deal with Fortran runtimes."
+ SCons.Warnings.warn(SCons.Warnings.FortranCxxMixWarning,
+ msg % env.subst('$CXX'))
+ issued_mixed_link_warning = True
+ return '$CXX'
+ elif has_fortran:
+ return '$FORTRAN'
+ elif has_cplusplus:
+ return '$CXX'
+ return '$CC'
+
+def shlib_emitter(target, source, env):
+ for tgt in target:
+ tgt.attributes.shared = 1
+ return (target, source)
+
+def generate(env):
+ """Add Builders and construction variables for gnulink to an Environment."""
+ SCons.Tool.createSharedLibBuilder(env)
+ SCons.Tool.createProgBuilder(env)
+
+ env['SHLINK'] = '$LINK'
+ env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared')
+ env['SHLINKCOM'] = '$SHLINK -o $TARGET $SHLINKFLAGS $SOURCES $_LIBDIRFLAGS $_LIBFLAGS'
+ # don't set up the emitter, cause AppendUnique will generate a list
+ # starting with None :-(
+ env.Append(SHLIBEMITTER = [shlib_emitter])
+ env['SMARTLINK'] = smart_link
+ env['LINK'] = "$SMARTLINK"
+ env['LINKFLAGS'] = SCons.Util.CLVar('')
+ env['LINKCOM'] = '$LINK -o $TARGET $LINKFLAGS $SOURCES $_LIBDIRFLAGS $_LIBFLAGS'
+ env['LIBDIRPREFIX']='-L'
+ env['LIBDIRSUFFIX']=''
+ env['_LIBFLAGS']='${_stripixes(LIBLINKPREFIX, LIBS, LIBLINKSUFFIX, LIBPREFIXES, LIBSUFFIXES, __env__)}'
+ env['LIBLINKPREFIX']='-l'
+ env['LIBLINKSUFFIX']=''
+
+ if env['PLATFORM'] == 'hpux':
+ env['SHLIBSUFFIX'] = '.sl'
+ elif env['PLATFORM'] == 'aix':
+ env['SHLIBSUFFIX'] = '.a'
+
+ # For most platforms, a loadable module is the same as a shared
+ # library. Platforms which are different can override these, but
+ # setting them the same means that LoadableModule works everywhere.
+ SCons.Tool.createLoadableModuleBuilder(env)
+ env['LDMODULE'] = '$SHLINK'
+ # don't set up the emitter, cause AppendUnique will generate a list
+ # starting with None :-(
+ env.Append(LDMODULEEMITTER='$SHLIBEMITTER')
+ env['LDMODULEPREFIX'] = '$SHLIBPREFIX'
+ env['LDMODULESUFFIX'] = '$SHLIBSUFFIX'
+ env['LDMODULEFLAGS'] = '$SHLINKFLAGS'
+ env['LDMODULECOM'] = '$LDMODULE -o $TARGET $LDMODULEFLAGS $SOURCES $_LIBDIRFLAGS $_LIBFLAGS'
+
+
+
+def exists(env):
+ # This module isn't really a Tool on its own, it's common logic for
+ # other linkers.
+ return None
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/linkloc.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/linkloc.py
new file mode 100644
index 00000000..283eacb6
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/linkloc.py
@@ -0,0 +1,112 @@
+"""SCons.Tool.linkloc
+
+Tool specification for the LinkLoc linker for the Phar Lap ETS embedded
+operating system.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/linkloc.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+import re
+
+import SCons.Action
+import SCons.Defaults
+import SCons.Errors
+import SCons.Tool
+import SCons.Util
+
+from SCons.Tool.MSCommon import msvs_exists, merge_default_version
+from SCons.Tool.PharLapCommon import addPharLapPaths
+
+_re_linker_command = re.compile(r'(\s)@\s*([^\s]+)')
+
+def repl_linker_command(m):
+ # Replaces any linker command file directives (e.g. "@foo.lnk") with
+ # the actual contents of the file.
+ try:
+ f=open(m.group(2), "r")
+ return m.group(1) + f.read()
+ except IOError:
+ # the linker should return an error if it can't
+ # find the linker command file so we will remain quiet.
+ # However, we will replace the @ with a # so we will not continue
+ # to find it with recursive substitution
+ return m.group(1) + '#' + m.group(2)
+
+class LinklocGenerator(object):
+ def __init__(self, cmdline):
+ self.cmdline = cmdline
+
+ def __call__(self, env, target, source, for_signature):
+ if for_signature:
+ # Expand the contents of any linker command files recursively
+ subs = 1
+ strsub = env.subst(self.cmdline, target=target, source=source)
+ while subs:
+ strsub, subs = _re_linker_command.subn(repl_linker_command, strsub)
+ return strsub
+ else:
+ return "${TEMPFILE('" + self.cmdline + "')}"
+
+def generate(env):
+ """Add Builders and construction variables for ar to an Environment."""
+ SCons.Tool.createSharedLibBuilder(env)
+ SCons.Tool.createProgBuilder(env)
+
+ env['SUBST_CMD_FILE'] = LinklocGenerator
+ env['SHLINK'] = '$LINK'
+ env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS')
+ env['SHLINKCOM'] = '${SUBST_CMD_FILE("$SHLINK $SHLINKFLAGS $_LIBDIRFLAGS $_LIBFLAGS -dll $TARGET $SOURCES")}'
+ env['SHLIBEMITTER']= None
+ env['LINK'] = "linkloc"
+ env['LINKFLAGS'] = SCons.Util.CLVar('')
+ env['LINKCOM'] = '${SUBST_CMD_FILE("$LINK $LINKFLAGS $_LIBDIRFLAGS $_LIBFLAGS -exe $TARGET $SOURCES")}'
+ env['LIBDIRPREFIX']='-libpath '
+ env['LIBDIRSUFFIX']=''
+ env['LIBLINKPREFIX']='-lib '
+ env['LIBLINKSUFFIX']='$LIBSUFFIX'
+
+ # Set-up ms tools paths for default version
+ merge_default_version(env)
+
+ addPharLapPaths(env)
+
+def exists(env):
+ if msvs_exists():
+ return env.Detect('linkloc')
+ else:
+ return 0
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/m4.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/m4.py
new file mode 100644
index 00000000..ac59e481
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/m4.py
@@ -0,0 +1,63 @@
+"""SCons.Tool.m4
+
+Tool-specific initialization for m4.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/m4.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Action
+import SCons.Builder
+import SCons.Util
+
+def generate(env):
+ """Add Builders and construction variables for m4 to an Environment."""
+ M4Action = SCons.Action.Action('$M4COM', '$M4COMSTR')
+ bld = SCons.Builder.Builder(action = M4Action, src_suffix = '.m4')
+
+ env['BUILDERS']['M4'] = bld
+
+ # .m4 files might include other files, and it would be pretty hard
+ # to write a scanner for it, so let's just cd to the dir of the m4
+ # file and run from there.
+ # The src_suffix setup is like so: file.c.m4 -> file.c,
+ # file.cpp.m4 -> file.cpp etc.
+ env['M4'] = 'm4'
+ env['M4FLAGS'] = SCons.Util.CLVar('-E')
+ env['M4COM'] = 'cd ${SOURCE.rsrcdir} && $M4 $M4FLAGS < ${SOURCE.file} > ${TARGET.abspath}'
+
+def exists(env):
+ return env.Detect('m4')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/masm.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/masm.py
new file mode 100644
index 00000000..2d02440d
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/masm.py
@@ -0,0 +1,77 @@
+"""SCons.Tool.masm
+
+Tool-specific initialization for the Microsoft Assembler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/masm.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Defaults
+import SCons.Tool
+import SCons.Util
+
+ASSuffixes = ['.s', '.asm', '.ASM']
+ASPPSuffixes = ['.spp', '.SPP', '.sx']
+if SCons.Util.case_sensitive_suffixes('.s', '.S'):
+ ASPPSuffixes.extend(['.S'])
+else:
+ ASSuffixes.extend(['.S'])
+
+def generate(env):
+ """Add Builders and construction variables for masm to an Environment."""
+ static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
+
+ for suffix in ASSuffixes:
+ static_obj.add_action(suffix, SCons.Defaults.ASAction)
+ shared_obj.add_action(suffix, SCons.Defaults.ASAction)
+ static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter)
+ shared_obj.add_emitter(suffix, SCons.Defaults.SharedObjectEmitter)
+
+ for suffix in ASPPSuffixes:
+ static_obj.add_action(suffix, SCons.Defaults.ASPPAction)
+ shared_obj.add_action(suffix, SCons.Defaults.ASPPAction)
+ static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter)
+ shared_obj.add_emitter(suffix, SCons.Defaults.SharedObjectEmitter)
+
+ env['AS'] = 'ml'
+ env['ASFLAGS'] = SCons.Util.CLVar('/nologo')
+ env['ASPPFLAGS'] = '$ASFLAGS'
+ env['ASCOM'] = '$AS $ASFLAGS /c /Fo$TARGET $SOURCES'
+ env['ASPPCOM'] = '$CC $ASPPFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c /Fo$TARGET $SOURCES'
+ env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
+
+def exists(env):
+ return env.Detect('ml')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/midl.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/midl.py
new file mode 100644
index 00000000..65a4f12a
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/midl.py
@@ -0,0 +1,88 @@
+"""SCons.Tool.midl
+
+Tool-specific initialization for midl (Microsoft IDL compiler).
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/midl.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Action
+import SCons.Builder
+import SCons.Defaults
+import SCons.Scanner.IDL
+import SCons.Util
+
+from MSCommon import msvc_exists
+
+def midl_emitter(target, source, env):
+ """Produces a list of outputs from the MIDL compiler"""
+ base, ext = SCons.Util.splitext(str(target[0]))
+ tlb = target[0]
+ incl = base + '.h'
+ interface = base + '_i.c'
+ t = [tlb, incl, interface]
+
+ midlcom = env['MIDLCOM']
+
+ if midlcom.find('/proxy') != -1:
+ proxy = base + '_p.c'
+ t.append(proxy)
+ if midlcom.find('/dlldata') != -1:
+ dlldata = base + '_data.c'
+ t.append(dlldata)
+
+ return (t,source)
+
+idl_scanner = SCons.Scanner.IDL.IDLScan()
+
+midl_action = SCons.Action.Action('$MIDLCOM', '$MIDLCOMSTR')
+
+midl_builder = SCons.Builder.Builder(action = midl_action,
+ src_suffix = '.idl',
+ suffix='.tlb',
+ emitter = midl_emitter,
+ source_scanner = idl_scanner)
+
+def generate(env):
+ """Add Builders and construction variables for midl to an Environment."""
+
+ env['MIDL'] = 'MIDL.EXE'
+ env['MIDLFLAGS'] = SCons.Util.CLVar('/nologo')
+ env['MIDLCOM'] = '$MIDL $MIDLFLAGS /tlb ${TARGETS[0]} /h ${TARGETS[1]} /iid ${TARGETS[2]} /proxy ${TARGETS[3]} /dlldata ${TARGETS[4]} $SOURCE 2> NUL'
+ env['BUILDERS']['TypeLibrary'] = midl_builder
+
+def exists(env):
+ return msvc_exists()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/mingw.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/mingw.py
new file mode 100644
index 00000000..4344bc12
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/mingw.py
@@ -0,0 +1,158 @@
+"""SCons.Tool.gcc
+
+Tool-specific initialization for MinGW (http://www.mingw.org/)
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/mingw.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+import os.path
+
+import SCons.Action
+import SCons.Builder
+import SCons.Defaults
+import SCons.Tool
+import SCons.Util
+
+# This is what we search for to find mingw:
+key_program = 'mingw32-gcc'
+
+def find(env):
+ # First search in the SCons path and then the OS path:
+ return env.WhereIs(key_program) or SCons.Util.WhereIs(key_program)
+
+def shlib_generator(target, source, env, for_signature):
+ cmd = SCons.Util.CLVar(['$SHLINK', '$SHLINKFLAGS'])
+
+ dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
+ if dll: cmd.extend(['-o', dll])
+
+ cmd.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS'])
+
+ implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
+ if implib: cmd.append('-Wl,--out-implib,'+implib.get_string(for_signature))
+
+ def_target = env.FindIxes(target, 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
+ insert_def = env.subst("$WINDOWS_INSERT_DEF")
+ if not insert_def in ['', '0', 0] and def_target: \
+ cmd.append('-Wl,--output-def,'+def_target.get_string(for_signature))
+
+ return [cmd]
+
+def shlib_emitter(target, source, env):
+ dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
+ no_import_lib = env.get('no_import_lib', 0)
+
+ if not dll:
+ raise SCons.Errors.UserError("A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX"))
+
+ if not no_import_lib and \
+ not env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX'):
+
+ # Append an import library to the list of targets.
+ target.append(env.ReplaceIxes(dll,
+ 'SHLIBPREFIX', 'SHLIBSUFFIX',
+ 'LIBPREFIX', 'LIBSUFFIX'))
+
+ # Append a def file target if there isn't already a def file target
+ # or a def file source. There is no option to disable def file
+ # target emitting, because I can't figure out why someone would ever
+ # want to turn it off.
+ def_source = env.FindIxes(source, 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
+ def_target = env.FindIxes(target, 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
+ if not def_source and not def_target:
+ target.append(env.ReplaceIxes(dll,
+ 'SHLIBPREFIX', 'SHLIBSUFFIX',
+ 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX'))
+
+ return (target, source)
+
+
+shlib_action = SCons.Action.Action(shlib_generator, generator=1)
+
+res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR')
+
+res_builder = SCons.Builder.Builder(action=res_action, suffix='.o',
+ source_scanner=SCons.Tool.SourceFileScanner)
+SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan)
+
+def generate(env):
+ mingw = find(env)
+ if mingw:
+ dir = os.path.dirname(mingw)
+ env.PrependENVPath('PATH', dir )
+
+
+ # Most of mingw is the same as gcc and friends...
+ gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas', 'm4']
+ for tool in gnu_tools:
+ SCons.Tool.Tool(tool)(env)
+
+ #... but a few things differ:
+ env['CC'] = 'gcc'
+ env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
+ env['CXX'] = 'g++'
+ env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
+ env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared')
+ env['SHLINKCOM'] = shlib_action
+ env['LDMODULECOM'] = shlib_action
+ env.Append(SHLIBEMITTER = [shlib_emitter])
+ env['AS'] = 'as'
+
+ env['WIN32DEFPREFIX'] = ''
+ env['WIN32DEFSUFFIX'] = '.def'
+ env['WINDOWSDEFPREFIX'] = '${WIN32DEFPREFIX}'
+ env['WINDOWSDEFSUFFIX'] = '${WIN32DEFSUFFIX}'
+
+ env['SHOBJSUFFIX'] = '.o'
+ env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
+
+ env['RC'] = 'windres'
+ env['RCFLAGS'] = SCons.Util.CLVar('')
+ env['RCINCFLAGS'] = '$( ${_concat(RCINCPREFIX, CPPPATH, RCINCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
+ env['RCINCPREFIX'] = '--include-dir '
+ env['RCINCSUFFIX'] = ''
+ env['RCCOM'] = '$RC $_CPPDEFFLAGS $RCINCFLAGS ${RCINCPREFIX} ${SOURCE.dir} $RCFLAGS -i $SOURCE -o $TARGET'
+ env['BUILDERS']['RES'] = res_builder
+
+ # Some setting from the platform also have to be overridden:
+ env['OBJSUFFIX'] = '.o'
+ env['LIBPREFIX'] = 'lib'
+ env['LIBSUFFIX'] = '.a'
+
+def exists(env):
+ return find(env)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/mslib.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/mslib.py
new file mode 100644
index 00000000..d3ed3dcf
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/mslib.py
@@ -0,0 +1,64 @@
+"""SCons.Tool.mslib
+
+Tool-specific initialization for lib (MicroSoft library archiver).
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/mslib.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Defaults
+import SCons.Tool
+import SCons.Tool.msvs
+import SCons.Tool.msvc
+import SCons.Util
+
+from MSCommon import msvc_exists, msvc_setup_env_once
+
+def generate(env):
+ """Add Builders and construction variables for lib to an Environment."""
+ SCons.Tool.createStaticLibBuilder(env)
+
+ # Set-up ms tools paths
+ msvc_setup_env_once(env)
+
+ env['AR'] = 'lib'
+ env['ARFLAGS'] = SCons.Util.CLVar('/nologo')
+ env['ARCOM'] = "${TEMPFILE('$AR $ARFLAGS /OUT:$TARGET $SOURCES')}"
+ env['LIBPREFIX'] = ''
+ env['LIBSUFFIX'] = '.lib'
+
+def exists(env):
+ return msvc_exists()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/mslink.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/mslink.py
new file mode 100644
index 00000000..1d1bc089
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/mslink.py
@@ -0,0 +1,266 @@
+"""SCons.Tool.mslink
+
+Tool-specific initialization for the Microsoft linker.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/mslink.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+
+import SCons.Action
+import SCons.Defaults
+import SCons.Errors
+import SCons.Platform.win32
+import SCons.Tool
+import SCons.Tool.msvc
+import SCons.Tool.msvs
+import SCons.Util
+
+from MSCommon import msvc_setup_env_once, msvc_exists
+
+def pdbGenerator(env, target, source, for_signature):
+ try:
+ return ['/PDB:%s' % target[0].attributes.pdb, '/DEBUG']
+ except (AttributeError, IndexError):
+ return None
+
+def _dllTargets(target, source, env, for_signature, paramtp):
+ listCmd = []
+ dll = env.FindIxes(target, '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp)
+ if dll: listCmd.append("/out:%s"%dll.get_string(for_signature))
+
+ implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
+ if implib: listCmd.append("/implib:%s"%implib.get_string(for_signature))
+
+ return listCmd
+
+def _dllSources(target, source, env, for_signature, paramtp):
+ listCmd = []
+
+ deffile = env.FindIxes(source, "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX")
+ for src in source:
+ # Check explicitly for a non-None deffile so that the __cmp__
+ # method of the base SCons.Util.Proxy class used for some Node
+ # proxies doesn't try to use a non-existent __dict__ attribute.
+ if deffile and src == deffile:
+ # Treat this source as a .def file.
+ listCmd.append("/def:%s" % src.get_string(for_signature))
+ else:
+ # Just treat it as a generic source file.
+ listCmd.append(src)
+ return listCmd
+
+def windowsShlinkTargets(target, source, env, for_signature):
+ return _dllTargets(target, source, env, for_signature, 'SHLIB')
+
+def windowsShlinkSources(target, source, env, for_signature):
+ return _dllSources(target, source, env, for_signature, 'SHLIB')
+
+def _windowsLdmodTargets(target, source, env, for_signature):
+ """Get targets for loadable modules."""
+ return _dllTargets(target, source, env, for_signature, 'LDMODULE')
+
+def _windowsLdmodSources(target, source, env, for_signature):
+ """Get sources for loadable modules."""
+ return _dllSources(target, source, env, for_signature, 'LDMODULE')
+
+def _dllEmitter(target, source, env, paramtp):
+ """Common implementation of dll emitter."""
+ SCons.Tool.msvc.validate_vars(env)
+
+ extratargets = []
+ extrasources = []
+
+ dll = env.FindIxes(target, '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp)
+ no_import_lib = env.get('no_import_lib', 0)
+
+ if not dll:
+ raise SCons.Errors.UserError('A shared library should have exactly one target with the suffix: %s' % env.subst('$%sSUFFIX' % paramtp))
+
+ insert_def = env.subst("$WINDOWS_INSERT_DEF")
+ if not insert_def in ['', '0', 0] and \
+ not env.FindIxes(source, "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX"):
+
+ # append a def file to the list of sources
+ extrasources.append(
+ env.ReplaceIxes(dll,
+ '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp,
+ "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX"))
+
+ version_num, suite = SCons.Tool.msvs.msvs_parse_version(env.get('MSVS_VERSION', '6.0'))
+ if version_num >= 8.0 and env.get('WINDOWS_INSERT_MANIFEST', 0):
+ # MSVC 8 automatically generates .manifest files that must be installed
+ extratargets.append(
+ env.ReplaceIxes(dll,
+ '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp,
+ "WINDOWSSHLIBMANIFESTPREFIX", "WINDOWSSHLIBMANIFESTSUFFIX"))
+
+ if 'PDB' in env and env['PDB']:
+ pdb = env.arg2nodes('$PDB', target=target, source=source)[0]
+ extratargets.append(pdb)
+ target[0].attributes.pdb = pdb
+
+ if not no_import_lib and \
+ not env.FindIxes(target, "LIBPREFIX", "LIBSUFFIX"):
+ # Append an import library to the list of targets.
+ extratargets.append(
+ env.ReplaceIxes(dll,
+ '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp,
+ "LIBPREFIX", "LIBSUFFIX"))
+ # and .exp file is created if there are exports from a DLL
+ extratargets.append(
+ env.ReplaceIxes(dll,
+ '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp,
+ "WINDOWSEXPPREFIX", "WINDOWSEXPSUFFIX"))
+
+ return (target+extratargets, source+extrasources)
+
+def windowsLibEmitter(target, source, env):
+ return _dllEmitter(target, source, env, 'SHLIB')
+
+def ldmodEmitter(target, source, env):
+ """Emitter for loadable modules.
+
+ Loadable modules are identical to shared libraries on Windows, but building
+ them is subject to different parameters (LDMODULE*).
+ """
+ return _dllEmitter(target, source, env, 'LDMODULE')
+
+def prog_emitter(target, source, env):
+ SCons.Tool.msvc.validate_vars(env)
+
+ extratargets = []
+
+ exe = env.FindIxes(target, "PROGPREFIX", "PROGSUFFIX")
+ if not exe:
+ raise SCons.Errors.UserError("An executable should have exactly one target with the suffix: %s" % env.subst("$PROGSUFFIX"))
+
+ version_num, suite = SCons.Tool.msvs.msvs_parse_version(env.get('MSVS_VERSION', '6.0'))
+ if version_num >= 8.0 and env.get('WINDOWS_INSERT_MANIFEST', 0):
+ # MSVC 8 automatically generates .manifest files that have to be installed
+ extratargets.append(
+ env.ReplaceIxes(exe,
+ "PROGPREFIX", "PROGSUFFIX",
+ "WINDOWSPROGMANIFESTPREFIX", "WINDOWSPROGMANIFESTSUFFIX"))
+
+ if 'PDB' in env and env['PDB']:
+ pdb = env.arg2nodes('$PDB', target=target, source=source)[0]
+ extratargets.append(pdb)
+ target[0].attributes.pdb = pdb
+
+ return (target+extratargets,source)
+
+def RegServerFunc(target, source, env):
+ if 'register' in env and env['register']:
+ ret = regServerAction([target[0]], [source[0]], env)
+ if ret:
+ raise SCons.Errors.UserError("Unable to register %s" % target[0])
+ else:
+ print "Registered %s sucessfully" % target[0]
+ return ret
+ return 0
+
+regServerAction = SCons.Action.Action("$REGSVRCOM", "$REGSVRCOMSTR")
+regServerCheck = SCons.Action.Action(RegServerFunc, None)
+shlibLinkAction = SCons.Action.Action('${TEMPFILE("$SHLINK $SHLINKFLAGS $_SHLINK_TARGETS $_LIBDIRFLAGS $_LIBFLAGS $_PDB $_SHLINK_SOURCES")}')
+compositeShLinkAction = shlibLinkAction + regServerCheck
+ldmodLinkAction = SCons.Action.Action('${TEMPFILE("$LDMODULE $LDMODULEFLAGS $_LDMODULE_TARGETS $_LIBDIRFLAGS $_LIBFLAGS $_PDB $_LDMODULE_SOURCES")}')
+compositeLdmodAction = ldmodLinkAction + regServerCheck
+
+def generate(env):
+ """Add Builders and construction variables for ar to an Environment."""
+ SCons.Tool.createSharedLibBuilder(env)
+ SCons.Tool.createProgBuilder(env)
+
+ env['SHLINK'] = '$LINK'
+ env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS /dll')
+ env['_SHLINK_TARGETS'] = windowsShlinkTargets
+ env['_SHLINK_SOURCES'] = windowsShlinkSources
+ env['SHLINKCOM'] = compositeShLinkAction
+ env.Append(SHLIBEMITTER = [windowsLibEmitter])
+ env['LINK'] = 'link'
+ env['LINKFLAGS'] = SCons.Util.CLVar('/nologo')
+ env['_PDB'] = pdbGenerator
+ env['LINKCOM'] = '${TEMPFILE("$LINK $LINKFLAGS /OUT:$TARGET.windows $_LIBDIRFLAGS $_LIBFLAGS $_PDB $SOURCES.windows")}'
+ env.Append(PROGEMITTER = [prog_emitter])
+ env['LIBDIRPREFIX']='/LIBPATH:'
+ env['LIBDIRSUFFIX']=''
+ env['LIBLINKPREFIX']=''
+ env['LIBLINKSUFFIX']='$LIBSUFFIX'
+
+ env['WIN32DEFPREFIX'] = ''
+ env['WIN32DEFSUFFIX'] = '.def'
+ env['WIN32_INSERT_DEF'] = 0
+ env['WINDOWSDEFPREFIX'] = '${WIN32DEFPREFIX}'
+ env['WINDOWSDEFSUFFIX'] = '${WIN32DEFSUFFIX}'
+ env['WINDOWS_INSERT_DEF'] = '${WIN32_INSERT_DEF}'
+
+ env['WIN32EXPPREFIX'] = ''
+ env['WIN32EXPSUFFIX'] = '.exp'
+ env['WINDOWSEXPPREFIX'] = '${WIN32EXPPREFIX}'
+ env['WINDOWSEXPSUFFIX'] = '${WIN32EXPSUFFIX}'
+
+ env['WINDOWSSHLIBMANIFESTPREFIX'] = ''
+ env['WINDOWSSHLIBMANIFESTSUFFIX'] = '${SHLIBSUFFIX}.manifest'
+ env['WINDOWSPROGMANIFESTPREFIX'] = ''
+ env['WINDOWSPROGMANIFESTSUFFIX'] = '${PROGSUFFIX}.manifest'
+
+ env['REGSVRACTION'] = regServerCheck
+ env['REGSVR'] = os.path.join(SCons.Platform.win32.get_system_root(),'System32','regsvr32')
+ env['REGSVRFLAGS'] = '/s '
+ env['REGSVRCOM'] = '$REGSVR $REGSVRFLAGS ${TARGET.windows}'
+
+ # Set-up ms tools paths
+ msvc_setup_env_once(env)
+
+
+ # Loadable modules are on Windows the same as shared libraries, but they
+ # are subject to different build parameters (LDMODULE* variables).
+ # Therefore LDMODULE* variables correspond as much as possible to
+ # SHLINK*/SHLIB* ones.
+ SCons.Tool.createLoadableModuleBuilder(env)
+ env['LDMODULE'] = '$SHLINK'
+ env['LDMODULEPREFIX'] = '$SHLIBPREFIX'
+ env['LDMODULESUFFIX'] = '$SHLIBSUFFIX'
+ env['LDMODULEFLAGS'] = '$SHLINKFLAGS'
+ env['_LDMODULE_TARGETS'] = _windowsLdmodTargets
+ env['_LDMODULE_SOURCES'] = _windowsLdmodSources
+ env['LDMODULEEMITTER'] = [ldmodEmitter]
+ env['LDMODULECOM'] = compositeLdmodAction
+
+def exists(env):
+ return msvc_exists()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/mssdk.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/mssdk.py
new file mode 100644
index 00000000..6b89873b
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/mssdk.py
@@ -0,0 +1,50 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/mssdk.py 5134 2010/08/16 23:02:40 bdeegan"
+
+"""engine.SCons.Tool.mssdk
+
+Tool-specific initialization for Microsoft SDKs, both Platform
+SDKs and Windows SDKs.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+"""
+
+from MSCommon import mssdk_exists, \
+ mssdk_setup_env
+
+def generate(env):
+ """Add construction variables for an MS SDK to an Environment."""
+ mssdk_setup_env(env)
+
+def exists(env):
+ return mssdk_exists()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/msvc.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/msvc.py
new file mode 100644
index 00000000..66c3e108
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/msvc.py
@@ -0,0 +1,268 @@
+"""engine.SCons.Tool.msvc
+
+Tool-specific initialization for Microsoft Visual C/C++.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/msvc.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+import re
+import sys
+
+import SCons.Action
+import SCons.Builder
+import SCons.Errors
+import SCons.Platform.win32
+import SCons.Tool
+import SCons.Tool.msvs
+import SCons.Util
+import SCons.Warnings
+import SCons.Scanner.RC
+
+from MSCommon import msvc_exists, msvc_setup_env_once
+
+CSuffixes = ['.c', '.C']
+CXXSuffixes = ['.cc', '.cpp', '.cxx', '.c++', '.C++']
+
+def validate_vars(env):
+ """Validate the PCH and PCHSTOP construction variables."""
+ if 'PCH' in env and env['PCH']:
+ if 'PCHSTOP' not in env:
+ raise SCons.Errors.UserError("The PCHSTOP construction must be defined if PCH is defined.")
+ if not SCons.Util.is_String(env['PCHSTOP']):
+ raise SCons.Errors.UserError("The PCHSTOP construction variable must be a string: %r"%env['PCHSTOP'])
+
+def pch_emitter(target, source, env):
+ """Adds the object file target."""
+
+ validate_vars(env)
+
+ pch = None
+ obj = None
+
+ for t in target:
+ if SCons.Util.splitext(str(t))[1] == '.pch':
+ pch = t
+ if SCons.Util.splitext(str(t))[1] == '.obj':
+ obj = t
+
+ if not obj:
+ obj = SCons.Util.splitext(str(pch))[0]+'.obj'
+
+ target = [pch, obj] # pch must be first, and obj second for the PCHCOM to work
+
+ return (target, source)
+
+def object_emitter(target, source, env, parent_emitter):
+ """Sets up the PCH dependencies for an object file."""
+
+ validate_vars(env)
+
+ parent_emitter(target, source, env)
+
+ # Add a dependency, but only if the target (e.g. 'Source1.obj')
+ # doesn't correspond to the pre-compiled header ('Source1.pch').
+ # If the basenames match, then this was most likely caused by
+ # someone adding the source file to both the env.PCH() and the
+ # env.Program() calls, and adding the explicit dependency would
+ # cause a cycle on the .pch file itself.
+ #
+ # See issue #2505 for a discussion of what to do if it turns
+ # out this assumption causes trouble in the wild:
+ # http://scons.tigris.org/issues/show_bug.cgi?id=2505
+ if 'PCH' in env:
+ pch = env['PCH']
+ if str(target[0]) != SCons.Util.splitext(str(pch))[0] + '.obj':
+ env.Depends(target, pch)
+
+ return (target, source)
+
+def static_object_emitter(target, source, env):
+ return object_emitter(target, source, env,
+ SCons.Defaults.StaticObjectEmitter)
+
+def shared_object_emitter(target, source, env):
+ return object_emitter(target, source, env,
+ SCons.Defaults.SharedObjectEmitter)
+
+pch_action = SCons.Action.Action('$PCHCOM', '$PCHCOMSTR')
+pch_builder = SCons.Builder.Builder(action=pch_action, suffix='.pch',
+ emitter=pch_emitter,
+ source_scanner=SCons.Tool.SourceFileScanner)
+
+
+# Logic to build .rc files into .res files (resource files)
+res_scanner = SCons.Scanner.RC.RCScan()
+res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR')
+res_builder = SCons.Builder.Builder(action=res_action,
+ src_suffix='.rc',
+ suffix='.res',
+ src_builder=[],
+ source_scanner=res_scanner)
+
+def msvc_batch_key(action, env, target, source):
+ """
+ Returns a key to identify unique batches of sources for compilation.
+
+ If batching is enabled (via the $MSVC_BATCH setting), then all
+ target+source pairs that use the same action, defined by the same
+ environment, and have the same target and source directories, will
+ be batched.
+
+ Returning None specifies that the specified target+source should not
+ be batched with other compilations.
+ """
+ b = env.subst('$MSVC_BATCH')
+ if b in (None, '', '0'):
+ # We're not using batching; return no key.
+ return None
+ t = target[0]
+ s = source[0]
+ if os.path.splitext(t.name)[0] != os.path.splitext(s.name)[0]:
+ # The base names are different, so this *must* be compiled
+ # separately; return no key.
+ return None
+ return (id(action), id(env), t.dir, s.dir)
+
+def msvc_output_flag(target, source, env, for_signature):
+ """
+ Returns the correct /Fo flag for batching.
+
+ If batching is disabled or there's only one source file, then we
+ return an /Fo string that specifies the target explicitly. Otherwise,
+ we return an /Fo string that just specifies the first target's
+ directory (where the Visual C/C++ compiler will put the .obj files).
+ """
+ b = env.subst('$MSVC_BATCH')
+ if b in (None, '', '0') or len(source) == 1:
+ return '/Fo$TARGET'
+ else:
+ # The Visual C/C++ compiler requires a \ at the end of the /Fo
+ # option to indicate an output directory. We use os.sep here so
+ # that the test(s) for this can be run on non-Windows systems
+ # without having a hard-coded backslash mess up command-line
+ # argument parsing.
+ return '/Fo${TARGET.dir}' + os.sep
+
+CAction = SCons.Action.Action("$CCCOM", "$CCCOMSTR",
+ batch_key=msvc_batch_key,
+ targets='$CHANGED_TARGETS')
+ShCAction = SCons.Action.Action("$SHCCCOM", "$SHCCCOMSTR",
+ batch_key=msvc_batch_key,
+ targets='$CHANGED_TARGETS')
+CXXAction = SCons.Action.Action("$CXXCOM", "$CXXCOMSTR",
+ batch_key=msvc_batch_key,
+ targets='$CHANGED_TARGETS')
+ShCXXAction = SCons.Action.Action("$SHCXXCOM", "$SHCXXCOMSTR",
+ batch_key=msvc_batch_key,
+ targets='$CHANGED_TARGETS')
+
+def generate(env):
+ """Add Builders and construction variables for MSVC++ to an Environment."""
+ static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
+
+ # TODO(batch): shouldn't reach in to cmdgen this way; necessary
+ # for now to bypass the checks in Builder.DictCmdGenerator.__call__()
+ # and allow .cc and .cpp to be compiled in the same command line.
+ static_obj.cmdgen.source_ext_match = False
+ shared_obj.cmdgen.source_ext_match = False
+
+ for suffix in CSuffixes:
+ static_obj.add_action(suffix, CAction)
+ shared_obj.add_action(suffix, ShCAction)
+ static_obj.add_emitter(suffix, static_object_emitter)
+ shared_obj.add_emitter(suffix, shared_object_emitter)
+
+ for suffix in CXXSuffixes:
+ static_obj.add_action(suffix, CXXAction)
+ shared_obj.add_action(suffix, ShCXXAction)
+ static_obj.add_emitter(suffix, static_object_emitter)
+ shared_obj.add_emitter(suffix, shared_object_emitter)
+
+ env['CCPDBFLAGS'] = SCons.Util.CLVar(['${(PDB and "/Z7") or ""}'])
+ env['CCPCHFLAGS'] = SCons.Util.CLVar(['${(PCH and "/Yu%s /Fp%s"%(PCHSTOP or "",File(PCH))) or ""}'])
+ env['_MSVC_OUTPUT_FLAG'] = msvc_output_flag
+ env['_CCCOMCOM'] = '$CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS $CCPCHFLAGS $CCPDBFLAGS'
+ env['CC'] = 'cl'
+ env['CCFLAGS'] = SCons.Util.CLVar('/nologo')
+ env['CFLAGS'] = SCons.Util.CLVar('')
+ env['CCCOM'] = '$CC $_MSVC_OUTPUT_FLAG /c $CHANGED_SOURCES $CFLAGS $CCFLAGS $_CCCOMCOM'
+ env['SHCC'] = '$CC'
+ env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
+ env['SHCFLAGS'] = SCons.Util.CLVar('$CFLAGS')
+ env['SHCCCOM'] = '$SHCC $_MSVC_OUTPUT_FLAG /c $CHANGED_SOURCES $SHCFLAGS $SHCCFLAGS $_CCCOMCOM'
+ env['CXX'] = '$CC'
+ env['CXXFLAGS'] = SCons.Util.CLVar('$( /TP $)')
+ env['CXXCOM'] = '$CXX $_MSVC_OUTPUT_FLAG /c $CHANGED_SOURCES $CXXFLAGS $CCFLAGS $_CCCOMCOM'
+ env['SHCXX'] = '$CXX'
+ env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
+ env['SHCXXCOM'] = '$SHCXX $_MSVC_OUTPUT_FLAG /c $CHANGED_SOURCES $SHCXXFLAGS $SHCCFLAGS $_CCCOMCOM'
+ env['CPPDEFPREFIX'] = '/D'
+ env['CPPDEFSUFFIX'] = ''
+ env['INCPREFIX'] = '/I'
+ env['INCSUFFIX'] = ''
+# env.Append(OBJEMITTER = [static_object_emitter])
+# env.Append(SHOBJEMITTER = [shared_object_emitter])
+ env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
+
+ env['RC'] = 'rc'
+ env['RCFLAGS'] = SCons.Util.CLVar('')
+ env['RCSUFFIXES']=['.rc','.rc2']
+ env['RCCOM'] = '$RC $_CPPDEFFLAGS $_CPPINCFLAGS $RCFLAGS /fo$TARGET $SOURCES'
+ env['BUILDERS']['RES'] = res_builder
+ env['OBJPREFIX'] = ''
+ env['OBJSUFFIX'] = '.obj'
+ env['SHOBJPREFIX'] = '$OBJPREFIX'
+ env['SHOBJSUFFIX'] = '$OBJSUFFIX'
+
+ # Set-up ms tools paths
+ msvc_setup_env_once(env)
+
+ env['CFILESUFFIX'] = '.c'
+ env['CXXFILESUFFIX'] = '.cc'
+
+ env['PCHPDBFLAGS'] = SCons.Util.CLVar(['${(PDB and "/Yd") or ""}'])
+ env['PCHCOM'] = '$CXX /Fo${TARGETS[1]} $CXXFLAGS $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Yc$PCHSTOP /Fp${TARGETS[0]} $CCPDBFLAGS $PCHPDBFLAGS'
+ env['BUILDERS']['PCH'] = pch_builder
+
+ if 'ENV' not in env:
+ env['ENV'] = {}
+ if 'SystemRoot' not in env['ENV']: # required for dlls in the winsxs folders
+ env['ENV']['SystemRoot'] = SCons.Platform.win32.get_system_root()
+
+def exists(env):
+ return msvc_exists()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/msvs.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/msvs.py
new file mode 100644
index 00000000..e6f07e5d
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/msvs.py
@@ -0,0 +1,1388 @@
+"""SCons.Tool.msvs
+
+Tool-specific initialization for Microsoft Visual Studio project files.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Tool/msvs.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.compat
+
+import base64
+import hashlib
+import ntpath
+import os
+# compat layer imports "cPickle" for us if it's available.
+import pickle
+import re
+import sys
+
+import SCons.Builder
+import SCons.Node.FS
+import SCons.Platform.win32
+import SCons.Script.SConscript
+import SCons.Util
+import SCons.Warnings
+
+from MSCommon import msvc_exists, msvc_setup_env_once
+from SCons.Defaults import processDefines
+
+##############################################################################
+# Below here are the classes and functions for generation of
+# DSP/DSW/SLN/VCPROJ files.
+##############################################################################
+
+def xmlify(s):
+ s = s.replace("&", "&amp;") # do this first
+ s = s.replace("'", "&apos;")
+ s = s.replace('"', "&quot;")
+ return s
+
+external_makefile_guid = '{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}'
+
+def _generateGUID(slnfile, name):
+ """This generates a dummy GUID for the sln file to use. It is
+ based on the MD5 signatures of the sln filename plus the name of
+ the project. It basically just needs to be unique, and not
+ change with each invocation."""
+ m = hashlib.md5()
+ # Normalize the slnfile path to a Windows path (\ separators) so
+ # the generated file has a consistent GUID even if we generate
+ # it on a non-Windows platform.
+ m.update(ntpath.normpath(str(slnfile)) + str(name))
+ solution = m.hexdigest().upper()
+ # convert most of the signature to GUID form (discard the rest)
+ solution = "{" + solution[:8] + "-" + solution[8:12] + "-" + solution[12:16] + "-" + solution[16:20] + "-" + solution[20:32] + "}"
+ return solution
+
+version_re = re.compile(r'(\d+\.\d+)(.*)')
+
+def msvs_parse_version(s):
+ """
+ Split a Visual Studio version, which may in fact be something like
+ '7.0Exp', into is version number (returned as a float) and trailing
+ "suite" portion.
+ """
+ num, suite = version_re.match(s).groups()
+ return float(num), suite
+
+# This is how we re-invoke SCons from inside MSVS Project files.
+# The problem is that we might have been invoked as either scons.bat
+# or scons.py. If we were invoked directly as scons.py, then we could
+# use sys.argv[0] to find the SCons "executable," but that doesn't work
+# if we were invoked as scons.bat, which uses "python -c" to execute
+# things and ends up with "-c" as sys.argv[0]. Consequently, we have
+# the MSVS Project file invoke SCons the same way that scons.bat does,
+# which works regardless of how we were invoked.
+def getExecScriptMain(env, xml=None):
+ scons_home = env.get('SCONS_HOME')
+ if not scons_home and 'SCONS_LIB_DIR' in os.environ:
+ scons_home = os.environ['SCONS_LIB_DIR']
+ if scons_home:
+ exec_script_main = "from os.path import join; import sys; sys.path = [ r'%s' ] + sys.path; import SCons.Script; SCons.Script.main()" % scons_home
+ else:
+ version = SCons.__version__
+ exec_script_main = "from os.path import join; import sys; sys.path = [ join(sys.prefix, 'Lib', 'site-packages', 'scons-%(version)s'), join(sys.prefix, 'scons-%(version)s'), join(sys.prefix, 'Lib', 'site-packages', 'scons'), join(sys.prefix, 'scons') ] + sys.path; import SCons.Script; SCons.Script.main()" % locals()
+ if xml:
+ exec_script_main = xmlify(exec_script_main)
+ return exec_script_main
+
+# The string for the Python executable we tell the Project file to use
+# is either sys.executable or, if an external PYTHON_ROOT environment
+# variable exists, $(PYTHON)ROOT\\python.exe (generalized a little to
+# pluck the actual executable name from sys.executable).
+try:
+ python_root = os.environ['PYTHON_ROOT']
+except KeyError:
+ python_executable = sys.executable
+else:
+ python_executable = os.path.join('$$(PYTHON_ROOT)',
+ os.path.split(sys.executable)[1])
+
+class Config(object):
+ pass
+
+def splitFully(path):
+ dir, base = os.path.split(path)
+ if dir and dir != '' and dir != path:
+ return splitFully(dir)+[base]
+ if base == '':
+ return []
+ return [base]
+
+def makeHierarchy(sources):
+ '''Break a list of files into a hierarchy; for each value, if it is a string,
+ then it is a file. If it is a dictionary, it is a folder. The string is
+ the original path of the file.'''
+
+ hierarchy = {}
+ for file in sources:
+ path = splitFully(file)
+ if len(path):
+ dict = hierarchy
+ for part in path[:-1]:
+ if part not in dict:
+ dict[part] = {}
+ dict = dict[part]
+ dict[path[-1]] = file
+ #else:
+ # print 'Warning: failed to decompose path for '+str(file)
+ return hierarchy
+
+class _DSPGenerator(object):
+ """ Base class for DSP generators """
+
+ srcargs = [
+ 'srcs',
+ 'incs',
+ 'localincs',
+ 'resources',
+ 'misc']
+
+ def __init__(self, dspfile, source, env):
+ self.dspfile = str(dspfile)
+ try:
+ get_abspath = dspfile.get_abspath
+ except AttributeError:
+ self.dspabs = os.path.abspath(dspfile)
+ else:
+ self.dspabs = get_abspath()
+
+ if 'variant' not in env:
+ raise SCons.Errors.InternalError("You must specify a 'variant' argument (i.e. 'Debug' or " +\
+ "'Release') to create an MSVSProject.")
+ elif SCons.Util.is_String(env['variant']):
+ variants = [env['variant']]
+ elif SCons.Util.is_List(env['variant']):
+ variants = env['variant']
+
+ if 'buildtarget' not in env or env['buildtarget'] == None:
+ buildtarget = ['']
+ elif SCons.Util.is_String(env['buildtarget']):
+ buildtarget = [env['buildtarget']]
+ elif SCons.Util.is_List(env['buildtarget']):
+ if len(env['buildtarget']) != len(variants):
+ raise SCons.Errors.InternalError("Sizes of 'buildtarget' and 'variant' lists must be the same.")
+ buildtarget = []
+ for bt in env['buildtarget']:
+ if SCons.Util.is_String(bt):
+ buildtarget.append(bt)
+ else:
+ buildtarget.append(bt.get_abspath())
+ else:
+ buildtarget = [env['buildtarget'].get_abspath()]
+ if len(buildtarget) == 1:
+ bt = buildtarget[0]
+ buildtarget = []
+ for _ in variants:
+ buildtarget.append(bt)
+
+ if 'outdir' not in env or env['outdir'] == None:
+ outdir = ['']
+ elif SCons.Util.is_String(env['outdir']):
+ outdir = [env['outdir']]
+ elif SCons.Util.is_List(env['outdir']):
+ if len(env['outdir']) != len(variants):
+ raise SCons.Errors.InternalError("Sizes of 'outdir' and 'variant' lists must be the same.")
+ outdir = []
+ for s in env['outdir']:
+ if SCons.Util.is_String(s):
+ outdir.append(s)
+ else:
+ outdir.append(s.get_abspath())
+ else:
+ outdir = [env['outdir'].get_abspath()]
+ if len(outdir) == 1:
+ s = outdir[0]
+ outdir = []
+ for v in variants:
+ outdir.append(s)
+
+ if 'runfile' not in env or env['runfile'] == None:
+ runfile = buildtarget[-1:]
+ elif SCons.Util.is_String(env['runfile']):
+ runfile = [env['runfile']]
+ elif SCons.Util.is_List(env['runfile']):
+ if len(env['runfile']) != len(variants):
+ raise SCons.Errors.InternalError("Sizes of 'runfile' and 'variant' lists must be the same.")
+ runfile = []
+ for s in env['runfile']:
+ if SCons.Util.is_String(s):
+ runfile.append(s)
+ else:
+ runfile.append(s.get_abspath())
+ else:
+ runfile = [env['runfile'].get_abspath()]
+ if len(runfile) == 1:
+ s = runfile[0]
+ runfile = []
+ for v in variants:
+ runfile.append(s)
+
+ self.sconscript = env['MSVSSCONSCRIPT']
+
+ cmdargs = env.get('cmdargs', '')
+
+ self.env = env
+
+ if 'name' in self.env:
+ self.name = self.env['name']
+ else:
+ self.name = os.path.basename(SCons.Util.splitext(self.dspfile)[0])
+ self.name = self.env.subst(self.name)
+
+ sourcenames = [
+ 'Source Files',
+ 'Header Files',
+ 'Local Headers',
+ 'Resource Files',
+ 'Other Files']
+
+ self.sources = {}
+ for n in sourcenames:
+ self.sources[n] = []
+
+ self.configs = {}
+
+ self.nokeep = 0
+ if 'nokeep' in env and env['variant'] != 0:
+ self.nokeep = 1
+
+ if self.nokeep == 0 and os.path.exists(self.dspabs):
+ self.Parse()
+
+ for t in zip(sourcenames,self.srcargs):
+ if t[1] in self.env:
+ if SCons.Util.is_List(self.env[t[1]]):
+ for i in self.env[t[1]]:
+ if not i in self.sources[t[0]]:
+ self.sources[t[0]].append(i)
+ else:
+ if not self.env[t[1]] in self.sources[t[0]]:
+ self.sources[t[0]].append(self.env[t[1]])
+
+ for n in sourcenames:
+ #TODO 2.4: compat layer supports sorted(key=) but not sort(key=)
+ #TODO 2.4: self.sources[n].sort(key=lambda a: a.lower())
+ self.sources[n] = sorted(self.sources[n], key=lambda a: a.lower())
+
+ def AddConfig(self, variant, buildtarget, outdir, runfile, cmdargs, dspfile=dspfile):
+ config = Config()
+ config.buildtarget = buildtarget
+ config.outdir = outdir
+ config.cmdargs = cmdargs
+ config.runfile = runfile
+
+ match = re.match('(.*)\|(.*)', variant)
+ if match:
+ config.variant = match.group(1)
+ config.platform = match.group(2)
+ else:
+ config.variant = variant
+ config.platform = 'Win32'
+
+ self.configs[variant] = config
+ print "Adding '" + self.name + ' - ' + config.variant + '|' + config.platform + "' to '" + str(dspfile) + "'"
+
+ for i in range(len(variants)):
+ AddConfig(self, variants[i], buildtarget[i], outdir[i], runfile[i], cmdargs)
+
+ self.platforms = []
+ for key in self.configs.keys():
+ platform = self.configs[key].platform
+ if not platform in self.platforms:
+ self.platforms.append(platform)
+
+ def Build(self):
+ pass
+
+V6DSPHeader = """\
+# Microsoft Developer Studio Project File - Name="%(name)s" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) External Target" 0x0106
+
+CFG=%(name)s - Win32 %(confkey)s
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "%(name)s.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "%(name)s.mak" CFG="%(name)s - Win32 %(confkey)s"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+"""
+
+class _GenerateV6DSP(_DSPGenerator):
+ """Generates a Project file for MSVS 6.0"""
+
+ def PrintHeader(self):
+ # pick a default config
+ confkeys = sorted(self.configs.keys())
+
+ name = self.name
+ confkey = confkeys[0]
+
+ self.file.write(V6DSPHeader % locals())
+
+ for kind in confkeys:
+ self.file.write('!MESSAGE "%s - Win32 %s" (based on "Win32 (x86) External Target")\n' % (name, kind))
+
+ self.file.write('!MESSAGE \n\n')
+
+ def PrintProject(self):
+ name = self.name
+ self.file.write('# Begin Project\n'
+ '# PROP AllowPerConfigDependencies 0\n'
+ '# PROP Scc_ProjName ""\n'
+ '# PROP Scc_LocalPath ""\n\n')
+
+ first = 1
+ confkeys = sorted(self.configs.keys())
+ for kind in confkeys:
+ outdir = self.configs[kind].outdir
+ buildtarget = self.configs[kind].buildtarget
+ if first == 1:
+ self.file.write('!IF "$(CFG)" == "%s - Win32 %s"\n\n' % (name, kind))
+ first = 0
+ else:
+ self.file.write('\n!ELSEIF "$(CFG)" == "%s - Win32 %s"\n\n' % (name, kind))
+
+ env_has_buildtarget = 'MSVSBUILDTARGET' in self.env
+ if not env_has_buildtarget:
+ self.env['MSVSBUILDTARGET'] = buildtarget
+
+ # have to write this twice, once with the BASE settings, and once without
+ for base in ("BASE ",""):
+ self.file.write('# PROP %sUse_MFC 0\n'
+ '# PROP %sUse_Debug_Libraries ' % (base, base))
+ if kind.lower().find('debug') < 0:
+ self.file.write('0\n')
+ else:
+ self.file.write('1\n')
+ self.file.write('# PROP %sOutput_Dir "%s"\n'
+ '# PROP %sIntermediate_Dir "%s"\n' % (base,outdir,base,outdir))
+ cmd = 'echo Starting SCons && ' + self.env.subst('$MSVSBUILDCOM', 1)
+ self.file.write('# PROP %sCmd_Line "%s"\n'
+ '# PROP %sRebuild_Opt "-c && %s"\n'
+ '# PROP %sTarget_File "%s"\n'
+ '# PROP %sBsc_Name ""\n'
+ '# PROP %sTarget_Dir ""\n'\
+ %(base,cmd,base,cmd,base,buildtarget,base,base))
+
+ if not env_has_buildtarget:
+ del self.env['MSVSBUILDTARGET']
+
+ self.file.write('\n!ENDIF\n\n'
+ '# Begin Target\n\n')
+ for kind in confkeys:
+ self.file.write('# Name "%s - Win32 %s"\n' % (name,kind))
+ self.file.write('\n')
+ first = 0
+ for kind in confkeys:
+ if first == 0:
+ self.file.write('!IF "$(CFG)" == "%s - Win32 %s"\n\n' % (name,kind))
+ first = 1
+ else:
+ self.file.write('!ELSEIF "$(CFG)" == "%s - Win32 %s"\n\n' % (name,kind))
+ self.file.write('!ENDIF \n\n')
+ self.PrintSourceFiles()
+ self.file.write('# End Target\n'
+ '# End Project\n')
+
+ if self.nokeep == 0:
+ # now we pickle some data and add it to the file -- MSDEV will ignore it.
+ pdata = pickle.dumps(self.configs,1)
+ pdata = base64.encodestring(pdata)
+ self.file.write(pdata + '\n')
+ pdata = pickle.dumps(self.sources,1)
+ pdata = base64.encodestring(pdata)
+ self.file.write(pdata + '\n')
+
+ def PrintSourceFiles(self):
+ categories = {'Source Files': 'cpp|c|cxx|l|y|def|odl|idl|hpj|bat',
+ 'Header Files': 'h|hpp|hxx|hm|inl',
+ 'Local Headers': 'h|hpp|hxx|hm|inl',
+ 'Resource Files': 'r|rc|ico|cur|bmp|dlg|rc2|rct|bin|cnt|rtf|gif|jpg|jpeg|jpe',
+ 'Other Files': ''}
+
+ for kind in sorted(categories.keys(), key=lambda a: a.lower()):
+ if not self.sources[kind]:
+ continue # skip empty groups
+
+ self.file.write('# Begin Group "' + kind + '"\n\n')
+ typelist = categories[kind].replace('|', ';')
+ self.file.write('# PROP Default_Filter "' + typelist + '"\n')
+
+ for file in self.sources[kind]:
+ file = os.path.normpath(file)
+ self.file.write('# Begin Source File\n\n'
+ 'SOURCE="' + file + '"\n'
+ '# End Source File\n')
+ self.file.write('# End Group\n')
+
+ # add the SConscript file outside of the groups
+ self.file.write('# Begin Source File\n\n'
+ 'SOURCE="' + str(self.sconscript) + '"\n'
+ '# End Source File\n')
+
+ def Parse(self):
+ try:
+ dspfile = open(self.dspabs,'r')
+ except IOError:
+ return # doesn't exist yet, so can't add anything to configs.
+
+ line = dspfile.readline()
+ while line:
+ if line.find("# End Project") > -1:
+ break
+ line = dspfile.readline()
+
+ line = dspfile.readline()
+ datas = line
+ while line and line != '\n':
+ line = dspfile.readline()
+ datas = datas + line
+
+ # OK, we've found our little pickled cache of data.
+ try:
+ datas = base64.decodestring(datas)
+ data = pickle.loads(datas)
+ except KeyboardInterrupt:
+ raise
+ except:
+ return # unable to unpickle any data for some reason
+
+ self.configs.update(data)
+
+ data = None
+ line = dspfile.readline()
+ datas = line
+ while line and line != '\n':
+ line = dspfile.readline()
+ datas = datas + line
+
+ # OK, we've found our little pickled cache of data.
+ # it has a "# " in front of it, so we strip that.
+ try:
+ datas = base64.decodestring(datas)
+ data = pickle.loads(datas)
+ except KeyboardInterrupt:
+ raise
+ except:
+ return # unable to unpickle any data for some reason
+
+ self.sources.update(data)
+
+ def Build(self):
+ try:
+ self.file = open(self.dspabs,'w')
+ except IOError, detail:
+ raise SCons.Errors.InternalError('Unable to open "' + self.dspabs + '" for writing:' + str(detail))
+ else:
+ self.PrintHeader()
+ self.PrintProject()
+ self.file.close()
+
+V7DSPHeader = """\
+<?xml version="1.0" encoding = "%(encoding)s"?>
+<VisualStudioProject
+\tProjectType="Visual C++"
+\tVersion="%(versionstr)s"
+\tName="%(name)s"
+%(scc_attrs)s
+\tKeyword="MakeFileProj">
+"""
+
+V7DSPConfiguration = """\
+\t\t<Configuration
+\t\t\tName="%(variant)s|%(platform)s"
+\t\t\tOutputDirectory="%(outdir)s"
+\t\t\tIntermediateDirectory="%(outdir)s"
+\t\t\tConfigurationType="0"
+\t\t\tUseOfMFC="0"
+\t\t\tATLMinimizesCRunTimeLibraryUsage="FALSE">
+\t\t\t<Tool
+\t\t\t\tName="VCNMakeTool"
+\t\t\t\tBuildCommandLine="%(buildcmd)s"
+\t\t\t\tCleanCommandLine="%(cleancmd)s"
+\t\t\t\tRebuildCommandLine="%(rebuildcmd)s"
+\t\t\t\tOutput="%(runfile)s"/>
+\t\t</Configuration>
+"""
+
+V8DSPHeader = """\
+<?xml version="1.0" encoding="%(encoding)s"?>
+<VisualStudioProject
+\tProjectType="Visual C++"
+\tVersion="%(versionstr)s"
+\tName="%(name)s"
+%(scc_attrs)s
+\tRootNamespace="%(name)s"
+\tKeyword="MakeFileProj">
+"""
+
+V8DSPConfiguration = """\
+\t\t<Configuration
+\t\t\tName="%(variant)s|%(platform)s"
+\t\t\tConfigurationType="0"
+\t\t\tUseOfMFC="0"
+\t\t\tATLMinimizesCRunTimeLibraryUsage="false"
+\t\t\t>
+\t\t\t<Tool
+\t\t\t\tName="VCNMakeTool"
+\t\t\t\tBuildCommandLine="%(buildcmd)s"
+\t\t\t\tReBuildCommandLine="%(rebuildcmd)s"
+\t\t\t\tCleanCommandLine="%(cleancmd)s"
+\t\t\t\tOutput="%(runfile)s"
+\t\t\t\tPreprocessorDefinitions="%(preprocdefs)s"
+\t\t\t\tIncludeSearchPath="%(includepath)s"
+\t\t\t\tForcedIncludes=""
+\t\t\t\tAssemblySearchPath=""
+\t\t\t\tForcedUsingAssemblies=""
+\t\t\t\tCompileAsManaged=""
+\t\t\t/>
+\t\t</Configuration>
+"""
+class _GenerateV7DSP(_DSPGenerator):
+ """Generates a Project file for MSVS .NET"""
+
+ def __init__(self, dspfile, source, env):
+ _DSPGenerator.__init__(self, dspfile, source, env)
+ self.version = env['MSVS_VERSION']
+ self.version_num, self.suite = msvs_parse_version(self.version)
+ if self.version_num >= 8.0:
+ self.versionstr = '8.00'
+ self.dspheader = V8DSPHeader
+ self.dspconfiguration = V8DSPConfiguration
+ else:
+ if self.version_num >= 7.1:
+ self.versionstr = '7.10'
+ else:
+ self.versionstr = '7.00'
+ self.dspheader = V7DSPHeader
+ self.dspconfiguration = V7DSPConfiguration
+ self.file = None
+
+ def PrintHeader(self):
+ env = self.env
+ versionstr = self.versionstr
+ name = self.name
+ encoding = self.env.subst('$MSVSENCODING')
+ scc_provider = env.get('MSVS_SCC_PROVIDER', '')
+ scc_project_name = env.get('MSVS_SCC_PROJECT_NAME', '')
+ scc_aux_path = env.get('MSVS_SCC_AUX_PATH', '')
+ scc_local_path = env.get('MSVS_SCC_LOCAL_PATH', '')
+ project_guid = env.get('MSVS_PROJECT_GUID', '')
+ if self.version_num >= 8.0 and not project_guid:
+ project_guid = _generateGUID(self.dspfile, '')
+ if scc_provider != '':
+ scc_attrs = ('\tProjectGUID="%s"\n'
+ '\tSccProjectName="%s"\n'
+ '\tSccAuxPath="%s"\n'
+ '\tSccLocalPath="%s"\n'
+ '\tSccProvider="%s"' % (project_guid, scc_project_name, scc_aux_path, scc_local_path, scc_provider))
+ else:
+ scc_attrs = ('\tProjectGUID="%s"\n'
+ '\tSccProjectName="%s"\n'
+ '\tSccLocalPath="%s"' % (project_guid, scc_project_name, scc_local_path))
+
+ self.file.write(self.dspheader % locals())
+
+ self.file.write('\t<Platforms>\n')
+ for platform in self.platforms:
+ self.file.write(
+ '\t\t<Platform\n'
+ '\t\t\tName="%s"/>\n' % platform)
+ self.file.write('\t</Platforms>\n')
+
+ if self.version_num >= 8.0:
+ self.file.write('\t<ToolFiles>\n'
+ '\t</ToolFiles>\n')
+
+ def PrintProject(self):
+ self.file.write('\t<Configurations>\n')
+
+ confkeys = sorted(self.configs.keys())
+ for kind in confkeys:
+ variant = self.configs[kind].variant
+ platform = self.configs[kind].platform
+ outdir = self.configs[kind].outdir
+ buildtarget = self.configs[kind].buildtarget
+ runfile = self.configs[kind].runfile
+ cmdargs = self.configs[kind].cmdargs
+
+ env_has_buildtarget = 'MSVSBUILDTARGET' in self.env
+ if not env_has_buildtarget:
+ self.env['MSVSBUILDTARGET'] = buildtarget
+
+ starting = 'echo Starting SCons && '
+ if cmdargs:
+ cmdargs = ' ' + cmdargs
+ else:
+ cmdargs = ''
+ buildcmd = xmlify(starting + self.env.subst('$MSVSBUILDCOM', 1) + cmdargs)
+ rebuildcmd = xmlify(starting + self.env.subst('$MSVSREBUILDCOM', 1) + cmdargs)
+ cleancmd = xmlify(starting + self.env.subst('$MSVSCLEANCOM', 1) + cmdargs)
+
+ preprocdefs = xmlify(';'.join(processDefines(self.env.get('CPPDEFINES', []))))
+ includepath = xmlify(';'.join(self.env.get('CPPPATH', [])))
+
+ if not env_has_buildtarget:
+ del self.env['MSVSBUILDTARGET']
+
+ self.file.write(self.dspconfiguration % locals())
+
+ self.file.write('\t</Configurations>\n')
+
+ if self.version_num >= 7.1:
+ self.file.write('\t<References>\n'
+ '\t</References>\n')
+
+ self.PrintSourceFiles()
+
+ self.file.write('</VisualStudioProject>\n')
+
+ if self.nokeep == 0:
+ # now we pickle some data and add it to the file -- MSDEV will ignore it.
+ pdata = pickle.dumps(self.configs,1)
+ pdata = base64.encodestring(pdata)
+ self.file.write('<!-- SCons Data:\n' + pdata + '\n')
+ pdata = pickle.dumps(self.sources,1)
+ pdata = base64.encodestring(pdata)
+ self.file.write(pdata + '-->\n')
+
+ def printSources(self, hierarchy, commonprefix):
+ sorteditems = sorted(hierarchy.items(), key=lambda a: a[0].lower())
+
+ # First folders, then files
+ for key, value in sorteditems:
+ if SCons.Util.is_Dict(value):
+ self.file.write('\t\t\t<Filter\n'
+ '\t\t\t\tName="%s"\n'
+ '\t\t\t\tFilter="">\n' % (key))
+ self.printSources(value, commonprefix)
+ self.file.write('\t\t\t</Filter>\n')
+
+ for key, value in sorteditems:
+ if SCons.Util.is_String(value):
+ file = value
+ if commonprefix:
+ file = os.path.join(commonprefix, value)
+ file = os.path.normpath(file)
+ self.file.write('\t\t\t<File\n'
+ '\t\t\t\tRelativePath="%s">\n'
+ '\t\t\t</File>\n' % (file))
+
+ def PrintSourceFiles(self):
+ categories = {'Source Files': 'cpp;c;cxx;l;y;def;odl;idl;hpj;bat',
+ 'Header Files': 'h;hpp;hxx;hm;inl',
+ 'Local Headers': 'h;hpp;hxx;hm;inl',
+ 'Resource Files': 'r;rc;ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe',
+ 'Other Files': ''}
+
+ self.file.write('\t<Files>\n')
+
+ cats = sorted([k for k in categories.keys() if self.sources[k]],
+ key=lambda a: a.lower())
+ for kind in cats:
+ if len(cats) > 1:
+ self.file.write('\t\t<Filter\n'
+ '\t\t\tName="%s"\n'
+ '\t\t\tFilter="%s">\n' % (kind, categories[kind]))
+
+ sources = self.sources[kind]
+
+ # First remove any common prefix
+ commonprefix = None
+ if len(sources) > 1:
+ s = list(map(os.path.normpath, sources))
+ # take the dirname because the prefix may include parts
+ # of the filenames (e.g. if you have 'dir\abcd' and
+ # 'dir\acde' then the cp will be 'dir\a' )
+ cp = os.path.dirname( os.path.commonprefix(s) )
+ if cp and s[0][len(cp)] == os.sep:
+ # +1 because the filename starts after the separator
+ sources = [s[len(cp)+1:] for s in sources]
+ commonprefix = cp
+ elif len(sources) == 1:
+ commonprefix = os.path.dirname( sources[0] )
+ sources[0] = os.path.basename( sources[0] )
+
+ hierarchy = makeHierarchy(sources)
+ self.printSources(hierarchy, commonprefix=commonprefix)
+
+ if len(cats)>1:
+ self.file.write('\t\t</Filter>\n')
+
+ # add the SConscript file outside of the groups
+ self.file.write('\t\t<File\n'
+ '\t\t\tRelativePath="%s">\n'
+ '\t\t</File>\n' % str(self.sconscript))
+
+ self.file.write('\t</Files>\n'
+ '\t<Globals>\n'
+ '\t</Globals>\n')
+
+ def Parse(self):
+ try:
+ dspfile = open(self.dspabs,'r')
+ except IOError:
+ return # doesn't exist yet, so can't add anything to configs.
+
+ line = dspfile.readline()
+ while line:
+ if line.find('<!-- SCons Data:') > -1:
+ break
+ line = dspfile.readline()
+
+ line = dspfile.readline()
+ datas = line
+ while line and line != '\n':
+ line = dspfile.readline()
+ datas = datas + line
+
+ # OK, we've found our little pickled cache of data.
+ try:
+ datas = base64.decodestring(datas)
+ data = pickle.loads(datas)
+ except KeyboardInterrupt:
+ raise
+ except:
+ return # unable to unpickle any data for some reason
+
+ self.configs.update(data)
+
+ data = None
+ line = dspfile.readline()
+ datas = line
+ while line and line != '\n':
+ line = dspfile.readline()
+ datas = datas + line
+
+ # OK, we've found our little pickled cache of data.
+ try:
+ datas = base64.decodestring(datas)
+ data = pickle.loads(datas)
+ except KeyboardInterrupt:
+ raise
+ except:
+ return # unable to unpickle any data for some reason
+
+ self.sources.update(data)
+
+ def Build(self):
+ try:
+ self.file = open(self.dspabs,'w')
+ except IOError, detail:
+ raise SCons.Errors.InternalError('Unable to open "' + self.dspabs + '" for writing:' + str(detail))
+ else:
+ self.PrintHeader()
+ self.PrintProject()
+ self.file.close()
+
+class _DSWGenerator(object):
+ """ Base class for DSW generators """
+ def __init__(self, dswfile, source, env):
+ self.dswfile = os.path.normpath(str(dswfile))
+ self.env = env
+
+ if 'projects' not in env:
+ raise SCons.Errors.UserError("You must specify a 'projects' argument to create an MSVSSolution.")
+ projects = env['projects']
+ if not SCons.Util.is_List(projects):
+ raise SCons.Errors.InternalError("The 'projects' argument must be a list of nodes.")
+ projects = SCons.Util.flatten(projects)
+ if len(projects) < 1:
+ raise SCons.Errors.UserError("You must specify at least one project to create an MSVSSolution.")
+ self.dspfiles = list(map(str, projects))
+
+ if 'name' in self.env:
+ self.name = self.env['name']
+ else:
+ self.name = os.path.basename(SCons.Util.splitext(self.dswfile)[0])
+ self.name = self.env.subst(self.name)
+
+ def Build(self):
+ pass
+
+class _GenerateV7DSW(_DSWGenerator):
+ """Generates a Solution file for MSVS .NET"""
+ def __init__(self, dswfile, source, env):
+ _DSWGenerator.__init__(self, dswfile, source, env)
+
+ self.file = None
+ self.version = self.env['MSVS_VERSION']
+ self.version_num, self.suite = msvs_parse_version(self.version)
+ self.versionstr = '7.00'
+ if self.version_num >= 8.0:
+ self.versionstr = '9.00'
+ elif self.version_num >= 7.1:
+ self.versionstr = '8.00'
+ if self.version_num >= 8.0:
+ self.versionstr = '9.00'
+
+ if 'slnguid' in env and env['slnguid']:
+ self.slnguid = env['slnguid']
+ else:
+ self.slnguid = _generateGUID(dswfile, self.name)
+
+ self.configs = {}
+
+ self.nokeep = 0
+ if 'nokeep' in env and env['variant'] != 0:
+ self.nokeep = 1
+
+ if self.nokeep == 0 and os.path.exists(self.dswfile):
+ self.Parse()
+
+ def AddConfig(self, variant, dswfile=dswfile):
+ config = Config()
+
+ match = re.match('(.*)\|(.*)', variant)
+ if match:
+ config.variant = match.group(1)
+ config.platform = match.group(2)
+ else:
+ config.variant = variant
+ config.platform = 'Win32'
+
+ self.configs[variant] = config
+ print "Adding '" + self.name + ' - ' + config.variant + '|' + config.platform + "' to '" + str(dswfile) + "'"
+
+ if 'variant' not in env:
+ raise SCons.Errors.InternalError("You must specify a 'variant' argument (i.e. 'Debug' or " +\
+ "'Release') to create an MSVS Solution File.")
+ elif SCons.Util.is_String(env['variant']):
+ AddConfig(self, env['variant'])
+ elif SCons.Util.is_List(env['variant']):
+ for variant in env['variant']:
+ AddConfig(self, variant)
+
+ self.platforms = []
+ for key in self.configs.keys():
+ platform = self.configs[key].platform
+ if not platform in self.platforms:
+ self.platforms.append(platform)
+
+ def Parse(self):
+ try:
+ dswfile = open(self.dswfile,'r')
+ except IOError:
+ return # doesn't exist yet, so can't add anything to configs.
+
+ line = dswfile.readline()
+ while line:
+ if line[:9] == "EndGlobal":
+ break
+ line = dswfile.readline()
+
+ line = dswfile.readline()
+ datas = line
+ while line:
+ line = dswfile.readline()
+ datas = datas + line
+
+ # OK, we've found our little pickled cache of data.
+ try:
+ datas = base64.decodestring(datas)
+ data = pickle.loads(datas)
+ except KeyboardInterrupt:
+ raise
+ except:
+ return # unable to unpickle any data for some reason
+
+ self.configs.update(data)
+
+ def PrintSolution(self):
+ """Writes a solution file"""
+ self.file.write('Microsoft Visual Studio Solution File, Format Version %s\n' % self.versionstr )
+ if self.version_num >= 8.0:
+ self.file.write('# Visual Studio 2005\n')
+ for p in self.dspfiles:
+ name = os.path.basename(p)
+ base, suffix = SCons.Util.splitext(name)
+ if suffix == '.vcproj':
+ name = base
+ guid = _generateGUID(p, '')
+ self.file.write('Project("%s") = "%s", "%s", "%s"\n'
+ % ( external_makefile_guid, name, p, guid ) )
+ if self.version_num >= 7.1 and self.version_num < 8.0:
+ self.file.write('\tProjectSection(ProjectDependencies) = postProject\n'
+ '\tEndProjectSection\n')
+ self.file.write('EndProject\n')
+
+ self.file.write('Global\n')
+
+ env = self.env
+ if 'MSVS_SCC_PROVIDER' in env:
+ dspfile_base = os.path.basename(self.dspfile)
+ slnguid = self.slnguid
+ scc_provider = env.get('MSVS_SCC_PROVIDER', '')
+ scc_provider = scc_provider.replace(' ', r'\u0020')
+ scc_project_name = env.get('MSVS_SCC_PROJECT_NAME', '')
+ # scc_aux_path = env.get('MSVS_SCC_AUX_PATH', '')
+ scc_local_path = env.get('MSVS_SCC_LOCAL_PATH', '')
+ scc_project_base_path = env.get('MSVS_SCC_PROJECT_BASE_PATH', '')
+ # project_guid = env.get('MSVS_PROJECT_GUID', '')
+
+ self.file.write('\tGlobalSection(SourceCodeControl) = preSolution\n'
+ '\t\tSccNumberOfProjects = 2\n'
+ '\t\tSccProjectUniqueName0 = %(dspfile_base)s\n'
+ '\t\tSccLocalPath0 = %(scc_local_path)s\n'
+ '\t\tCanCheckoutShared = true\n'
+ '\t\tSccProjectFilePathRelativizedFromConnection0 = %(scc_project_base_path)s\n'
+ '\t\tSccProjectName1 = %(scc_project_name)s\n'
+ '\t\tSccLocalPath1 = %(scc_local_path)s\n'
+ '\t\tSccProvider1 = %(scc_provider)s\n'
+ '\t\tCanCheckoutShared = true\n'
+ '\t\tSccProjectFilePathRelativizedFromConnection1 = %(scc_project_base_path)s\n'
+ '\t\tSolutionUniqueID = %(slnguid)s\n'
+ '\tEndGlobalSection\n' % locals())
+
+ if self.version_num >= 8.0:
+ self.file.write('\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n')
+ else:
+ self.file.write('\tGlobalSection(SolutionConfiguration) = preSolution\n')
+
+ confkeys = sorted(self.configs.keys())
+ cnt = 0
+ for name in confkeys:
+ variant = self.configs[name].variant
+ platform = self.configs[name].platform
+ if self.version_num >= 8.0:
+ self.file.write('\t\t%s|%s = %s|%s\n' % (variant, platform, variant, platform))
+ else:
+ self.file.write('\t\tConfigName.%d = %s\n' % (cnt, variant))
+ cnt = cnt + 1
+ self.file.write('\tEndGlobalSection\n')
+ if self.version_num < 7.1:
+ self.file.write('\tGlobalSection(ProjectDependencies) = postSolution\n'
+ '\tEndGlobalSection\n')
+ if self.version_num >= 8.0:
+ self.file.write('\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n')
+ else:
+ self.file.write('\tGlobalSection(ProjectConfiguration) = postSolution\n')
+
+ for name in confkeys:
+ variant = self.configs[name].variant
+ platform = self.configs[name].platform
+ if self.version_num >= 8.0:
+ for p in self.dspfiles:
+ guid = _generateGUID(p, '')
+ self.file.write('\t\t%s.%s|%s.ActiveCfg = %s|%s\n'
+ '\t\t%s.%s|%s.Build.0 = %s|%s\n' % (guid,variant,platform,variant,platform,guid,variant,platform,variant,platform))
+ else:
+ for p in self.dspfiles:
+ guid = _generateGUID(p, '')
+ self.file.write('\t\t%s.%s.ActiveCfg = %s|%s\n'
+ '\t\t%s.%s.Build.0 = %s|%s\n' %(guid,variant,variant,platform,guid,variant,variant,platform))
+
+ self.file.write('\tEndGlobalSection\n')
+
+ if self.version_num >= 8.0:
+ self.file.write('\tGlobalSection(SolutionProperties) = preSolution\n'
+ '\t\tHideSolutionNode = FALSE\n'
+ '\tEndGlobalSection\n')
+ else:
+ self.file.write('\tGlobalSection(ExtensibilityGlobals) = postSolution\n'
+ '\tEndGlobalSection\n'
+ '\tGlobalSection(ExtensibilityAddIns) = postSolution\n'
+ '\tEndGlobalSection\n')
+ self.file.write('EndGlobal\n')
+ if self.nokeep == 0:
+ pdata = pickle.dumps(self.configs,1)
+ pdata = base64.encodestring(pdata)
+ self.file.write(pdata + '\n')
+
+ def Build(self):
+ try:
+ self.file = open(self.dswfile,'w')
+ except IOError, detail:
+ raise SCons.Errors.InternalError('Unable to open "' + self.dswfile + '" for writing:' + str(detail))
+ else:
+ self.PrintSolution()
+ self.file.close()
+
+V6DSWHeader = """\
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "%(name)s"="%(dspfile)s" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+"""
+
+class _GenerateV6DSW(_DSWGenerator):
+ """Generates a Workspace file for MSVS 6.0"""
+
+ def PrintWorkspace(self):
+ """ writes a DSW file """
+ name = self.name
+ dspfile = self.dspfiles[0]
+ self.file.write(V6DSWHeader % locals())
+
+ def Build(self):
+ try:
+ self.file = open(self.dswfile,'w')
+ except IOError, detail:
+ raise SCons.Errors.InternalError('Unable to open "' + self.dswfile + '" for writing:' + str(detail))
+ else:
+ self.PrintWorkspace()
+ self.file.close()
+
+
+def GenerateDSP(dspfile, source, env):
+ """Generates a Project file based on the version of MSVS that is being used"""
+
+ version_num = 6.0
+ if 'MSVS_VERSION' in env:
+ version_num, suite = msvs_parse_version(env['MSVS_VERSION'])
+ if version_num >= 7.0:
+ g = _GenerateV7DSP(dspfile, source, env)
+ g.Build()
+ else:
+ g = _GenerateV6DSP(dspfile, source, env)
+ g.Build()
+
+def GenerateDSW(dswfile, source, env):
+ """Generates a Solution/Workspace file based on the version of MSVS that is being used"""
+
+ version_num = 6.0
+ if 'MSVS_VERSION' in env:
+ version_num, suite = msvs_parse_version(env['MSVS_VERSION'])
+ if version_num >= 7.0:
+ g = _GenerateV7DSW(dswfile, source, env)
+ g.Build()
+ else:
+ g = _GenerateV6DSW(dswfile, source, env)
+ g.Build()
+
+
+##############################################################################
+# Above here are the classes and functions for generation of
+# DSP/DSW/SLN/VCPROJ files.
+##############################################################################
+
+def GetMSVSProjectSuffix(target, source, env, for_signature):
+ return env['MSVS']['PROJECTSUFFIX']
+
+def GetMSVSSolutionSuffix(target, source, env, for_signature):
+ return env['MSVS']['SOLUTIONSUFFIX']
+
+def GenerateProject(target, source, env):
+ # generate the dsp file, according to the version of MSVS.
+ builddspfile = target[0]
+ dspfile = builddspfile.srcnode()
+
+ # this detects whether or not we're using a VariantDir
+ if not dspfile is builddspfile:
+ try:
+ bdsp = open(str(builddspfile), "w+")
+ except IOError, detail:
+ print 'Unable to open "' + str(dspfile) + '" for writing:',detail,'\n'
+ raise
+
+ bdsp.write("This is just a placeholder file.\nThe real project file is here:\n%s\n" % dspfile.get_abspath())
+
+ GenerateDSP(dspfile, source, env)
+
+ if env.get('auto_build_solution', 1):
+ builddswfile = target[1]
+ dswfile = builddswfile.srcnode()
+
+ if not dswfile is builddswfile:
+
+ try:
+ bdsw = open(str(builddswfile), "w+")
+ except IOError, detail:
+ print 'Unable to open "' + str(dspfile) + '" for writing:',detail,'\n'
+ raise
+
+ bdsw.write("This is just a placeholder file.\nThe real workspace file is here:\n%s\n" % dswfile.get_abspath())
+
+ GenerateDSW(dswfile, source, env)
+
+def GenerateSolution(target, source, env):
+ GenerateDSW(target[0], source, env)
+
+def projectEmitter(target, source, env):
+ """Sets up the DSP dependencies."""
+
+ # todo: Not sure what sets source to what user has passed as target,
+ # but this is what happens. When that is fixed, we also won't have
+ # to make the user always append env['MSVSPROJECTSUFFIX'] to target.
+ if source[0] == target[0]:
+ source = []
+
+ # make sure the suffix is correct for the version of MSVS we're running.
+ (base, suff) = SCons.Util.splitext(str(target[0]))
+ suff = env.subst('$MSVSPROJECTSUFFIX')
+ target[0] = base + suff
+
+ if not source:
+ source = 'prj_inputs:'
+ source = source + env.subst('$MSVSSCONSCOM', 1)
+ source = source + env.subst('$MSVSENCODING', 1)
+
+ if 'buildtarget' in env and env['buildtarget'] != None:
+ if SCons.Util.is_String(env['buildtarget']):
+ source = source + ' "%s"' % env['buildtarget']
+ elif SCons.Util.is_List(env['buildtarget']):
+ for bt in env['buildtarget']:
+ if SCons.Util.is_String(bt):
+ source = source + ' "%s"' % bt
+ else:
+ try: source = source + ' "%s"' % bt.get_abspath()
+ except AttributeError: raise SCons.Errors.InternalError("buildtarget can be a string, a node, a list of strings or nodes, or None")
+ else:
+ try: source = source + ' "%s"' % env['buildtarget'].get_abspath()
+ except AttributeError: raise SCons.Errors.InternalError("buildtarget can be a string, a node, a list of strings or nodes, or None")
+
+ if 'outdir' in env and env['outdir'] != None:
+ if SCons.Util.is_String(env['outdir']):
+ source = source + ' "%s"' % env['outdir']
+ elif SCons.Util.is_List(env['outdir']):
+ for s in env['outdir']:
+ if SCons.Util.is_String(s):
+ source = source + ' "%s"' % s
+ else:
+ try: source = source + ' "%s"' % s.get_abspath()
+ except AttributeError: raise SCons.Errors.InternalError("outdir can be a string, a node, a list of strings or nodes, or None")
+ else:
+ try: source = source + ' "%s"' % env['outdir'].get_abspath()
+ except AttributeError: raise SCons.Errors.InternalError("outdir can be a string, a node, a list of strings or nodes, or None")
+
+ if 'name' in env:
+ if SCons.Util.is_String(env['name']):
+ source = source + ' "%s"' % env['name']
+ else:
+ raise SCons.Errors.InternalError("name must be a string")
+
+ if 'variant' in env:
+ if SCons.Util.is_String(env['variant']):
+ source = source + ' "%s"' % env['variant']
+ elif SCons.Util.is_List(env['variant']):
+ for variant in env['variant']:
+ if SCons.Util.is_String(variant):
+ source = source + ' "%s"' % variant
+ else:
+ raise SCons.Errors.InternalError("name must be a string or a list of strings")
+ else:
+ raise SCons.Errors.InternalError("variant must be a string or a list of strings")
+ else:
+ raise SCons.Errors.InternalError("variant must be specified")
+
+ for s in _DSPGenerator.srcargs:
+ if s in env:
+ if SCons.Util.is_String(env[s]):
+ source = source + ' "%s' % env[s]
+ elif SCons.Util.is_List(env[s]):
+ for t in env[s]:
+ if SCons.Util.is_String(t):
+ source = source + ' "%s"' % t
+ else:
+ raise SCons.Errors.InternalError(s + " must be a string or a list of strings")
+ else:
+ raise SCons.Errors.InternalError(s + " must be a string or a list of strings")
+
+ source = source + ' "%s"' % str(target[0])
+ source = [SCons.Node.Python.Value(source)]
+
+ targetlist = [target[0]]
+ sourcelist = source
+
+ if env.get('auto_build_solution', 1):
+ env['projects'] = targetlist
+ t, s = solutionEmitter(target, target, env)
+ targetlist = targetlist + t
+
+ return (targetlist, sourcelist)
+
+def solutionEmitter(target, source, env):
+ """Sets up the DSW dependencies."""
+
+ # todo: Not sure what sets source to what user has passed as target,
+ # but this is what happens. When that is fixed, we also won't have
+ # to make the user always append env['MSVSSOLUTIONSUFFIX'] to target.
+ if source[0] == target[0]:
+ source = []
+
+ # make sure the suffix is correct for the version of MSVS we're running.
+ (base, suff) = SCons.Util.splitext(str(target[0]))
+ suff = env.subst('$MSVSSOLUTIONSUFFIX')
+ target[0] = base + suff
+
+ if not source:
+ source = 'sln_inputs:'
+
+ if 'name' in env:
+ if SCons.Util.is_String(env['name']):
+ source = source + ' "%s"' % env['name']
+ else:
+ raise SCons.Errors.InternalError("name must be a string")
+
+ if 'variant' in env:
+ if SCons.Util.is_String(env['variant']):
+ source = source + ' "%s"' % env['variant']
+ elif SCons.Util.is_List(env['variant']):
+ for variant in env['variant']:
+ if SCons.Util.is_String(variant):
+ source = source + ' "%s"' % variant
+ else:
+ raise SCons.Errors.InternalError("name must be a string or a list of strings")
+ else:
+ raise SCons.Errors.InternalError("variant must be a string or a list of strings")
+ else:
+ raise SCons.Errors.InternalError("variant must be specified")
+
+ if 'slnguid' in env:
+ if SCons.Util.is_String(env['slnguid']):
+ source = source + ' "%s"' % env['slnguid']
+ else:
+ raise SCons.Errors.InternalError("slnguid must be a string")
+
+ if 'projects' in env:
+ if SCons.Util.is_String(env['projects']):
+ source = source + ' "%s"' % env['projects']
+ elif SCons.Util.is_List(env['projects']):
+ for t in env['projects']:
+ if SCons.Util.is_String(t):
+ source = source + ' "%s"' % t
+
+ source = source + ' "%s"' % str(target[0])
+ source = [SCons.Node.Python.Value(source)]
+
+ return ([target[0]], source)
+
+projectAction = SCons.Action.Action(GenerateProject, None)
+
+solutionAction = SCons.Action.Action(GenerateSolution, None)
+
+projectBuilder = SCons.Builder.Builder(action = '$MSVSPROJECTCOM',
+ suffix = '$MSVSPROJECTSUFFIX',
+ emitter = projectEmitter)
+
+solutionBuilder = SCons.Builder.Builder(action = '$MSVSSOLUTIONCOM',
+ suffix = '$MSVSSOLUTIONSUFFIX',
+ emitter = solutionEmitter)
+
+default_MSVS_SConscript = None
+
+def generate(env):
+ """Add Builders and construction variables for Microsoft Visual
+ Studio project files to an Environment."""
+ try:
+ env['BUILDERS']['MSVSProject']
+ except KeyError:
+ env['BUILDERS']['MSVSProject'] = projectBuilder
+
+ try:
+ env['BUILDERS']['MSVSSolution']
+ except KeyError:
+ env['BUILDERS']['MSVSSolution'] = solutionBuilder
+
+ env['MSVSPROJECTCOM'] = projectAction
+ env['MSVSSOLUTIONCOM'] = solutionAction
+
+ if SCons.Script.call_stack:
+ # XXX Need to find a way to abstract this; the build engine
+ # shouldn't depend on anything in SCons.Script.
+ env['MSVSSCONSCRIPT'] = SCons.Script.call_stack[0].sconscript
+ else:
+ global default_MSVS_SConscript
+ if default_MSVS_SConscript is None:
+ default_MSVS_SConscript = env.File('SConstruct')
+ env['MSVSSCONSCRIPT'] = default_MSVS_SConscript
+
+ env['MSVSSCONS'] = '"%s" -c "%s"' % (python_executable, getExecScriptMain(env))
+ env['MSVSSCONSFLAGS'] = '-C "${MSVSSCONSCRIPT.dir.abspath}" -f ${MSVSSCONSCRIPT.name}'
+ env['MSVSSCONSCOM'] = '$MSVSSCONS $MSVSSCONSFLAGS'
+ env['MSVSBUILDCOM'] = '$MSVSSCONSCOM "$MSVSBUILDTARGET"'
+ env['MSVSREBUILDCOM'] = '$MSVSSCONSCOM "$MSVSBUILDTARGET"'
+ env['MSVSCLEANCOM'] = '$MSVSSCONSCOM -c "$MSVSBUILDTARGET"'
+ env['MSVSENCODING'] = 'Windows-1252'
+
+ # Set-up ms tools paths for default version
+ msvc_setup_env_once(env)
+
+ if 'MSVS_VERSION' in env:
+ version_num, suite = msvs_parse_version(env['MSVS_VERSION'])
+ else:
+ (version_num, suite) = (7.0, None) # guess at a default
+ if 'MSVS' not in env:
+ env['MSVS'] = {}
+ if (version_num < 7.0):
+ env['MSVS']['PROJECTSUFFIX'] = '.dsp'
+ env['MSVS']['SOLUTIONSUFFIX'] = '.dsw'
+ else:
+ env['MSVS']['PROJECTSUFFIX'] = '.vcproj'
+ env['MSVS']['SOLUTIONSUFFIX'] = '.sln'
+
+ env['GET_MSVSPROJECTSUFFIX'] = GetMSVSProjectSuffix
+ env['GET_MSVSSOLUTIONSUFFIX'] = GetMSVSSolutionSuffix
+ env['MSVSPROJECTSUFFIX'] = '${GET_MSVSPROJECTSUFFIX}'
+ env['MSVSSOLUTIONSUFFIX'] = '${GET_MSVSSOLUTIONSUFFIX}'
+ env['SCONS_HOME'] = os.environ.get('SCONS_HOME')
+
+def exists(env):
+ return msvc_exists()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/mwcc.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/mwcc.py
new file mode 100644
index 00000000..d61510ef
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/mwcc.py
@@ -0,0 +1,207 @@
+"""SCons.Tool.mwcc
+
+Tool-specific initialization for the Metrowerks CodeWarrior compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/mwcc.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+import os.path
+
+import SCons.Util
+
+def set_vars(env):
+ """Set MWCW_VERSION, MWCW_VERSIONS, and some codewarrior environment vars
+
+ MWCW_VERSIONS is set to a list of objects representing installed versions
+
+ MWCW_VERSION is set to the version object that will be used for building.
+ MWCW_VERSION can be set to a string during Environment
+ construction to influence which version is chosen, otherwise
+ the latest one from MWCW_VERSIONS is used.
+
+ Returns true if at least one version is found, false otherwise
+ """
+ desired = env.get('MWCW_VERSION', '')
+
+ # return right away if the variables are already set
+ if isinstance(desired, MWVersion):
+ return 1
+ elif desired is None:
+ return 0
+
+ versions = find_versions()
+ version = None
+
+ if desired:
+ for v in versions:
+ if str(v) == desired:
+ version = v
+ elif versions:
+ version = versions[-1]
+
+ env['MWCW_VERSIONS'] = versions
+ env['MWCW_VERSION'] = version
+
+ if version is None:
+ return 0
+
+ env.PrependENVPath('PATH', version.clpath)
+ env.PrependENVPath('PATH', version.dllpath)
+ ENV = env['ENV']
+ ENV['CWFolder'] = version.path
+ ENV['LM_LICENSE_FILE'] = version.license
+ plus = lambda x: '+%s' % x
+ ENV['MWCIncludes'] = os.pathsep.join(map(plus, version.includes))
+ ENV['MWLibraries'] = os.pathsep.join(map(plus, version.libs))
+ return 1
+
+
+def find_versions():
+ """Return a list of MWVersion objects representing installed versions"""
+ versions = []
+
+ ### This function finds CodeWarrior by reading from the registry on
+ ### Windows. Some other method needs to be implemented for other
+ ### platforms, maybe something that calls env.WhereIs('mwcc')
+
+ if SCons.Util.can_read_reg:
+ try:
+ HLM = SCons.Util.HKEY_LOCAL_MACHINE
+ product = 'SOFTWARE\\Metrowerks\\CodeWarrior\\Product Versions'
+ product_key = SCons.Util.RegOpenKeyEx(HLM, product)
+
+ i = 0
+ while True:
+ name = product + '\\' + SCons.Util.RegEnumKey(product_key, i)
+ name_key = SCons.Util.RegOpenKeyEx(HLM, name)
+
+ try:
+ version = SCons.Util.RegQueryValueEx(name_key, 'VERSION')
+ path = SCons.Util.RegQueryValueEx(name_key, 'PATH')
+ mwv = MWVersion(version[0], path[0], 'Win32-X86')
+ versions.append(mwv)
+ except SCons.Util.RegError:
+ pass
+
+ i = i + 1
+
+ except SCons.Util.RegError:
+ pass
+
+ return versions
+
+
+class MWVersion(object):
+ def __init__(self, version, path, platform):
+ self.version = version
+ self.path = path
+ self.platform = platform
+ self.clpath = os.path.join(path, 'Other Metrowerks Tools',
+ 'Command Line Tools')
+ self.dllpath = os.path.join(path, 'Bin')
+
+ # The Metrowerks tools don't store any configuration data so they
+ # are totally dumb when it comes to locating standard headers,
+ # libraries, and other files, expecting all the information
+ # to be handed to them in environment variables. The members set
+ # below control what information scons injects into the environment
+
+ ### The paths below give a normal build environment in CodeWarrior for
+ ### Windows, other versions of CodeWarrior might need different paths.
+
+ msl = os.path.join(path, 'MSL')
+ support = os.path.join(path, '%s Support' % platform)
+
+ self.license = os.path.join(path, 'license.dat')
+ self.includes = [msl, support]
+ self.libs = [msl, support]
+
+ def __str__(self):
+ return self.version
+
+
+CSuffixes = ['.c', '.C']
+CXXSuffixes = ['.cc', '.cpp', '.cxx', '.c++', '.C++']
+
+
+def generate(env):
+ """Add Builders and construction variables for the mwcc to an Environment."""
+ import SCons.Defaults
+ import SCons.Tool
+
+ set_vars(env)
+
+ static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
+
+ for suffix in CSuffixes:
+ static_obj.add_action(suffix, SCons.Defaults.CAction)
+ shared_obj.add_action(suffix, SCons.Defaults.ShCAction)
+
+ for suffix in CXXSuffixes:
+ static_obj.add_action(suffix, SCons.Defaults.CXXAction)
+ shared_obj.add_action(suffix, SCons.Defaults.ShCXXAction)
+
+ env['CCCOMFLAGS'] = '$CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -nolink -o $TARGET $SOURCES'
+
+ env['CC'] = 'mwcc'
+ env['CCCOM'] = '$CC $CFLAGS $CCFLAGS $CCCOMFLAGS'
+
+ env['CXX'] = 'mwcc'
+ env['CXXCOM'] = '$CXX $CXXFLAGS $CCCOMFLAGS'
+
+ env['SHCC'] = '$CC'
+ env['SHCCFLAGS'] = '$CCFLAGS'
+ env['SHCFLAGS'] = '$CFLAGS'
+ env['SHCCCOM'] = '$SHCC $SHCFLAGS $SHCCFLAGS $CCCOMFLAGS'
+
+ env['SHCXX'] = '$CXX'
+ env['SHCXXFLAGS'] = '$CXXFLAGS'
+ env['SHCXXCOM'] = '$SHCXX $SHCXXFLAGS $CCCOMFLAGS'
+
+ env['CFILESUFFIX'] = '.c'
+ env['CXXFILESUFFIX'] = '.cpp'
+ env['CPPDEFPREFIX'] = '-D'
+ env['CPPDEFSUFFIX'] = ''
+ env['INCPREFIX'] = '-I'
+ env['INCSUFFIX'] = ''
+
+ #env['PCH'] = ?
+ #env['PCHSTOP'] = ?
+
+
+def exists(env):
+ return set_vars(env)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/mwld.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/mwld.py
new file mode 100644
index 00000000..d8816278
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/mwld.py
@@ -0,0 +1,107 @@
+"""SCons.Tool.mwld
+
+Tool-specific initialization for the Metrowerks CodeWarrior linker.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/mwld.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Tool
+
+
+def generate(env):
+ """Add Builders and construction variables for lib to an Environment."""
+ SCons.Tool.createStaticLibBuilder(env)
+ SCons.Tool.createSharedLibBuilder(env)
+ SCons.Tool.createProgBuilder(env)
+
+ env['AR'] = 'mwld'
+ env['ARCOM'] = '$AR $ARFLAGS -library -o $TARGET $SOURCES'
+
+ env['LIBDIRPREFIX'] = '-L'
+ env['LIBDIRSUFFIX'] = ''
+ env['LIBLINKPREFIX'] = '-l'
+ env['LIBLINKSUFFIX'] = '.lib'
+
+ env['LINK'] = 'mwld'
+ env['LINKCOM'] = '$LINK $LINKFLAGS -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS'
+
+ env['SHLINK'] = '$LINK'
+ env['SHLINKFLAGS'] = '$LINKFLAGS'
+ env['SHLINKCOM'] = shlib_action
+ env['SHLIBEMITTER']= shlib_emitter
+
+
+def exists(env):
+ import SCons.Tool.mwcc
+ return SCons.Tool.mwcc.set_vars(env)
+
+
+def shlib_generator(target, source, env, for_signature):
+ cmd = ['$SHLINK', '$SHLINKFLAGS', '-shared']
+
+ no_import_lib = env.get('no_import_lib', 0)
+ if no_import_lib: cmd.extend('-noimplib')
+
+ dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
+ if dll: cmd.extend(['-o', dll])
+
+ implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
+ if implib: cmd.extend(['-implib', implib.get_string(for_signature)])
+
+ cmd.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS'])
+
+ return [cmd]
+
+
+def shlib_emitter(target, source, env):
+ dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
+ no_import_lib = env.get('no_import_lib', 0)
+
+ if not dll:
+ raise SCons.Errors.UserError("A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX"))
+
+ if not no_import_lib and \
+ not env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX'):
+
+ # Append an import library to the list of targets.
+ target.append(env.ReplaceIxes(dll,
+ 'SHLIBPREFIX', 'SHLIBSUFFIX',
+ 'LIBPREFIX', 'LIBSUFFIX'))
+
+ return target, source
+
+
+shlib_action = SCons.Action.Action(shlib_generator, generator=1)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/nasm.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/nasm.py
new file mode 100644
index 00000000..d759e41f
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/nasm.py
@@ -0,0 +1,72 @@
+"""SCons.Tool.nasm
+
+Tool-specific initialization for nasm, the famous Netwide Assembler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/nasm.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Defaults
+import SCons.Tool
+import SCons.Util
+
+ASSuffixes = ['.s', '.asm', '.ASM']
+ASPPSuffixes = ['.spp', '.SPP', '.sx']
+if SCons.Util.case_sensitive_suffixes('.s', '.S'):
+ ASPPSuffixes.extend(['.S'])
+else:
+ ASSuffixes.extend(['.S'])
+
+def generate(env):
+ """Add Builders and construction variables for nasm to an Environment."""
+ static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
+
+ for suffix in ASSuffixes:
+ static_obj.add_action(suffix, SCons.Defaults.ASAction)
+ static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter)
+
+ for suffix in ASPPSuffixes:
+ static_obj.add_action(suffix, SCons.Defaults.ASPPAction)
+ static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter)
+
+ env['AS'] = 'nasm'
+ env['ASFLAGS'] = SCons.Util.CLVar('')
+ env['ASPPFLAGS'] = '$ASFLAGS'
+ env['ASCOM'] = '$AS $ASFLAGS -o $TARGET $SOURCES'
+ env['ASPPCOM'] = '$CC $ASPPFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES'
+
+def exists(env):
+ return env.Detect('nasm')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/__init__.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/__init__.py
new file mode 100644
index 00000000..35029f2c
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/__init__.py
@@ -0,0 +1,312 @@
+"""SCons.Tool.Packaging
+
+SCons Packaging Tool.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Tool/packaging/__init__.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Environment
+from SCons.Variables import *
+from SCons.Errors import *
+from SCons.Util import is_List, make_path_relative
+from SCons.Warnings import warn, Warning
+
+import os, imp
+import SCons.Defaults
+
+__all__ = [ 'src_targz', 'src_tarbz2', 'src_zip', 'tarbz2', 'targz', 'zip', 'rpm', 'msi', 'ipk' ]
+
+#
+# Utility and Builder function
+#
+def Tag(env, target, source, *more_tags, **kw_tags):
+ """ Tag a file with the given arguments, just sets the accordingly named
+ attribute on the file object.
+
+ TODO: FIXME
+ """
+ if not target:
+ target=source
+ first_tag=None
+ else:
+ first_tag=source
+
+ if first_tag:
+ kw_tags[first_tag[0]] = ''
+
+ if len(kw_tags) == 0 and len(more_tags) == 0:
+ raise UserError("No tags given.")
+
+ # XXX: sanity checks
+ for x in more_tags:
+ kw_tags[x] = ''
+
+ if not SCons.Util.is_List(target):
+ target=[target]
+ else:
+ # hmm, sometimes the target list, is a list of a list
+ # make sure it is flattened prior to processing.
+ # TODO: perhaps some bug ?!?
+ target=env.Flatten(target)
+
+ for t in target:
+ for (k,v) in kw_tags.items():
+ # all file tags have to start with PACKAGING_, so we can later
+ # differentiate between "normal" object attributes and the
+ # packaging attributes. As the user should not be bothered with
+ # that, the prefix will be added here if missing.
+ #if not k.startswith('PACKAGING_'):
+ if k[:10] != 'PACKAGING_':
+ k='PACKAGING_'+k
+ setattr(t, k, v)
+
+def Package(env, target=None, source=None, **kw):
+ """ Entry point for the package tool.
+ """
+ # check if we need to find the source files ourself
+ if not source:
+ source = env.FindInstalledFiles()
+
+ if len(source)==0:
+ raise UserError("No source for Package() given")
+
+ # decide which types of packages shall be built. Can be defined through
+ # four mechanisms: command line argument, keyword argument,
+ # environment argument and default selection( zip or tar.gz ) in that
+ # order.
+ try: kw['PACKAGETYPE']=env['PACKAGETYPE']
+ except KeyError: pass
+
+ if not kw.get('PACKAGETYPE'):
+ from SCons.Script import GetOption
+ kw['PACKAGETYPE'] = GetOption('package_type')
+
+ if kw['PACKAGETYPE'] == None:
+ if 'Tar' in env['BUILDERS']:
+ kw['PACKAGETYPE']='targz'
+ elif 'Zip' in env['BUILDERS']:
+ kw['PACKAGETYPE']='zip'
+ else:
+ raise UserError("No type for Package() given")
+
+ PACKAGETYPE=kw['PACKAGETYPE']
+ if not is_List(PACKAGETYPE):
+ PACKAGETYPE=PACKAGETYPE.split(',')
+
+ # load the needed packagers.
+ def load_packager(type):
+ try:
+ file,path,desc=imp.find_module(type, __path__)
+ return imp.load_module(type, file, path, desc)
+ except ImportError, e:
+ raise EnvironmentError("packager %s not available: %s"%(type,str(e)))
+
+ packagers=list(map(load_packager, PACKAGETYPE))
+
+ # set up targets and the PACKAGEROOT
+ try:
+ # fill up the target list with a default target name until the PACKAGETYPE
+ # list is of the same size as the target list.
+ if not target: target = []
+
+ size_diff = len(PACKAGETYPE)-len(target)
+ default_name = "%(NAME)s-%(VERSION)s"
+
+ if size_diff>0:
+ default_target = default_name%kw
+ target.extend( [default_target]*size_diff )
+
+ if 'PACKAGEROOT' not in kw:
+ kw['PACKAGEROOT'] = default_name%kw
+
+ except KeyError, e:
+ raise SCons.Errors.UserError( "Missing Packagetag '%s'"%e.args[0] )
+
+ # setup the source files
+ source=env.arg2nodes(source, env.fs.Entry)
+
+ # call the packager to setup the dependencies.
+ targets=[]
+ try:
+ for packager in packagers:
+ t=[target.pop(0)]
+ t=packager.package(env,t,source, **kw)
+ targets.extend(t)
+
+ assert( len(target) == 0 )
+
+ except KeyError, e:
+ raise SCons.Errors.UserError( "Missing Packagetag '%s' for %s packager"\
+ % (e.args[0],packager.__name__) )
+ except TypeError, e:
+ # this exception means that a needed argument for the packager is
+ # missing. As our packagers get their "tags" as named function
+ # arguments we need to find out which one is missing.
+ from inspect import getargspec
+ args,varargs,varkw,defaults=getargspec(packager.package)
+ if defaults!=None:
+ args=args[:-len(defaults)] # throw away arguments with default values
+ args.remove('env')
+ args.remove('target')
+ args.remove('source')
+ # now remove any args for which we have a value in kw.
+ args=[x for x in args if x not in kw]
+
+ if len(args)==0:
+ raise # must be a different error, so reraise
+ elif len(args)==1:
+ raise SCons.Errors.UserError( "Missing Packagetag '%s' for %s packager"\
+ % (args[0],packager.__name__) )
+ else:
+ raise SCons.Errors.UserError( "Missing Packagetags '%s' for %s packager"\
+ % (", ".join(args),packager.__name__) )
+
+ target=env.arg2nodes(target, env.fs.Entry)
+ targets.extend(env.Alias( 'package', targets ))
+ return targets
+
+#
+# SCons tool initialization functions
+#
+
+added = None
+
+def generate(env):
+ from SCons.Script import AddOption
+ global added
+ if not added:
+ added = 1
+ AddOption('--package-type',
+ dest='package_type',
+ default=None,
+ type="string",
+ action="store",
+ help='The type of package to create.')
+
+ try:
+ env['BUILDERS']['Package']
+ env['BUILDERS']['Tag']
+ except KeyError:
+ env['BUILDERS']['Package'] = Package
+ env['BUILDERS']['Tag'] = Tag
+
+def exists(env):
+ return 1
+
+# XXX
+def options(opts):
+ opts.AddVariables(
+ EnumVariable( 'PACKAGETYPE',
+ 'the type of package to create.',
+ None, allowed_values=list(map( str, __all__ )),
+ ignorecase=2
+ )
+ )
+
+#
+# Internal utility functions
+#
+
+def copy_attr(f1, f2):
+ """ copies the special packaging file attributes from f1 to f2.
+ """
+ #pattrs = [x for x in dir(f1) if not hasattr(f2, x) and\
+ # x.startswith('PACKAGING_')]
+ copyit = lambda x: not hasattr(f2, x) and x[:10] == 'PACKAGING_'
+ pattrs = list(filter(copyit, dir(f1)))
+ for attr in pattrs:
+ setattr(f2, attr, getattr(f1, attr))
+def putintopackageroot(target, source, env, pkgroot, honor_install_location=1):
+ """ Uses the CopyAs builder to copy all source files to the directory given
+ in pkgroot.
+
+ If honor_install_location is set and the copied source file has an
+ PACKAGING_INSTALL_LOCATION attribute, the PACKAGING_INSTALL_LOCATION is
+ used as the new name of the source file under pkgroot.
+
+ The source file will not be copied if it is already under the the pkgroot
+ directory.
+
+ All attributes of the source file will be copied to the new file.
+ """
+ # make sure the packageroot is a Dir object.
+ if SCons.Util.is_String(pkgroot): pkgroot=env.Dir(pkgroot)
+ if not SCons.Util.is_List(source): source=[source]
+
+ new_source = []
+ for file in source:
+ if SCons.Util.is_String(file): file = env.File(file)
+
+ if file.is_under(pkgroot):
+ new_source.append(file)
+ else:
+ if hasattr(file, 'PACKAGING_INSTALL_LOCATION') and\
+ honor_install_location:
+ new_name=make_path_relative(file.PACKAGING_INSTALL_LOCATION)
+ else:
+ new_name=make_path_relative(file.get_path())
+
+ new_file=pkgroot.File(new_name)
+ new_file=env.CopyAs(new_file, file)[0]
+ copy_attr(file, new_file)
+ new_source.append(new_file)
+
+ return (target, new_source)
+
+def stripinstallbuilder(target, source, env):
+ """ strips the install builder action from the source list and stores
+ the final installation location as the "PACKAGING_INSTALL_LOCATION" of
+ the source of the source file. This effectively removes the final installed
+ files from the source list while remembering the installation location.
+
+ It also warns about files which have no install builder attached.
+ """
+ def has_no_install_location(file):
+ return not (file.has_builder() and\
+ hasattr(file.builder, 'name') and\
+ (file.builder.name=="InstallBuilder" or\
+ file.builder.name=="InstallAsBuilder"))
+
+ if len(list(filter(has_no_install_location, source))):
+ warn(Warning, "there are files to package which have no\
+ InstallBuilder attached, this might lead to irreproducible packages")
+
+ n_source=[]
+ for s in source:
+ if has_no_install_location(s):
+ n_source.append(s)
+ else:
+ for ss in s.sources:
+ n_source.append(ss)
+ copy_attr(s, ss)
+ setattr(ss, 'PACKAGING_INSTALL_LOCATION', s.get_path())
+
+ return (target, n_source)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/ipk.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/ipk.py
new file mode 100644
index 00000000..09fc7795
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/ipk.py
@@ -0,0 +1,185 @@
+"""SCons.Tool.Packaging.ipk
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/packaging/ipk.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Builder
+import SCons.Node.FS
+import os
+
+from SCons.Tool.packaging import stripinstallbuilder, putintopackageroot
+
+def package(env, target, source, PACKAGEROOT, NAME, VERSION, DESCRIPTION,
+ SUMMARY, X_IPK_PRIORITY, X_IPK_SECTION, SOURCE_URL,
+ X_IPK_MAINTAINER, X_IPK_DEPENDS, **kw):
+ """ this function prepares the packageroot directory for packaging with the
+ ipkg builder.
+ """
+ SCons.Tool.Tool('ipkg').generate(env)
+
+ # setup the Ipkg builder
+ bld = env['BUILDERS']['Ipkg']
+ target, source = stripinstallbuilder(target, source, env)
+ target, source = putintopackageroot(target, source, env, PACKAGEROOT)
+
+ # This should be overridable from the construction environment,
+ # which it is by using ARCHITECTURE=.
+ # Guessing based on what os.uname() returns at least allows it
+ # to work for both i386 and x86_64 Linux systems.
+ archmap = {
+ 'i686' : 'i386',
+ 'i586' : 'i386',
+ 'i486' : 'i386',
+ }
+
+ buildarchitecture = os.uname()[4]
+ buildarchitecture = archmap.get(buildarchitecture, buildarchitecture)
+
+ if 'ARCHITECTURE' in kw:
+ buildarchitecture = kw['ARCHITECTURE']
+
+ # setup the kw to contain the mandatory arguments to this fucntion.
+ # do this before calling any builder or setup function
+ loc=locals()
+ del loc['kw']
+ kw.update(loc)
+ del kw['source'], kw['target'], kw['env']
+
+ # generate the specfile
+ specfile = gen_ipk_dir(PACKAGEROOT, source, env, kw)
+
+ # override the default target.
+ if str(target[0])=="%s-%s"%(NAME, VERSION):
+ target=[ "%s_%s_%s.ipk"%(NAME, VERSION, buildarchitecture) ]
+
+ # now apply the Ipkg builder
+ return bld(env, target, specfile, **kw)
+
+def gen_ipk_dir(proot, source, env, kw):
+ # make sure the packageroot is a Dir object.
+ if SCons.Util.is_String(proot): proot=env.Dir(proot)
+
+ # create the specfile builder
+ s_bld=SCons.Builder.Builder(
+ action = build_specfiles,
+ )
+
+ # create the specfile targets
+ spec_target=[]
+ control=proot.Dir('CONTROL')
+ spec_target.append(control.File('control'))
+ spec_target.append(control.File('conffiles'))
+ spec_target.append(control.File('postrm'))
+ spec_target.append(control.File('prerm'))
+ spec_target.append(control.File('postinst'))
+ spec_target.append(control.File('preinst'))
+
+ # apply the builder to the specfile targets
+ s_bld(env, spec_target, source, **kw)
+
+ # the packageroot directory does now contain the specfiles.
+ return proot
+
+def build_specfiles(source, target, env):
+ """ filter the targets for the needed files and use the variables in env
+ to create the specfile.
+ """
+ #
+ # At first we care for the CONTROL/control file, which is the main file for ipk.
+ #
+ # For this we need to open multiple files in random order, so we store into
+ # a dict so they can be easily accessed.
+ #
+ #
+ opened_files={}
+ def open_file(needle, haystack):
+ try:
+ return opened_files[needle]
+ except KeyError:
+ file=filter(lambda x: x.get_path().rfind(needle)!=-1, haystack)[0]
+ opened_files[needle]=open(file.abspath, 'w')
+ return opened_files[needle]
+
+ control_file=open_file('control', target)
+
+ if 'X_IPK_DESCRIPTION' not in env:
+ env['X_IPK_DESCRIPTION']="%s\n %s"%(env['SUMMARY'],
+ env['DESCRIPTION'].replace('\n', '\n '))
+
+
+ content = """
+Package: $NAME
+Version: $VERSION
+Priority: $X_IPK_PRIORITY
+Section: $X_IPK_SECTION
+Source: $SOURCE_URL
+Architecture: $ARCHITECTURE
+Maintainer: $X_IPK_MAINTAINER
+Depends: $X_IPK_DEPENDS
+Description: $X_IPK_DESCRIPTION
+"""
+
+ control_file.write(env.subst(content))
+
+ #
+ # now handle the various other files, which purpose it is to set post-,
+ # pre-scripts and mark files as config files.
+ #
+ # We do so by filtering the source files for files which are marked with
+ # the "config" tag and afterwards we do the same for x_ipk_postrm,
+ # x_ipk_prerm, x_ipk_postinst and x_ipk_preinst tags.
+ #
+ # The first one will write the name of the file into the file
+ # CONTROL/configfiles, the latter add the content of the x_ipk_* variable
+ # into the same named file.
+ #
+ for f in [x for x in source if 'PACKAGING_CONFIG' in dir(x)]:
+ config=open_file('conffiles')
+ config.write(f.PACKAGING_INSTALL_LOCATION)
+ config.write('\n')
+
+ for str in 'POSTRM PRERM POSTINST PREINST'.split():
+ name="PACKAGING_X_IPK_%s"%str
+ for f in [x for x in source if name in dir(x)]:
+ file=open_file(name)
+ file.write(env[str])
+
+ #
+ # close all opened files
+ for f in opened_files.values():
+ f.close()
+
+ # call a user specified function
+ if 'CHANGE_SPECFILE' in env:
+ content += env['CHANGE_SPECFILE'](target)
+
+ return 0
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/msi.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/msi.py
new file mode 100644
index 00000000..4cc80718
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/msi.py
@@ -0,0 +1,527 @@
+"""SCons.Tool.packaging.msi
+
+The msi packager.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Tool/packaging/msi.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+import SCons
+from SCons.Action import Action
+from SCons.Builder import Builder
+
+from xml.dom.minidom import *
+from xml.sax.saxutils import escape
+
+from SCons.Tool.packaging import stripinstallbuilder
+
+#
+# Utility functions
+#
+def convert_to_id(s, id_set):
+ """ Some parts of .wxs need an Id attribute (for example: The File and
+ Directory directives. The charset is limited to A-Z, a-z, digits,
+ underscores, periods. Each Id must begin with a letter or with a
+ underscore. Google for "CNDL0015" for information about this.
+
+ Requirements:
+ * the string created must only contain chars from the target charset.
+ * the string created must have a minimal editing distance from the
+ original string.
+ * the string created must be unique for the whole .wxs file.
+
+ Observation:
+ * There are 62 chars in the charset.
+
+ Idea:
+ * filter out forbidden characters. Check for a collision with the help
+ of the id_set. Add the number of the number of the collision at the
+ end of the created string. Furthermore care for a correct start of
+ the string.
+ """
+ charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxyz0123456789_.'
+ if s[0] in '0123456789.':
+ s += '_'+s
+ id = [c for c in s if c in charset]
+
+ # did we already generate an id for this file?
+ try:
+ return id_set[id][s]
+ except KeyError:
+ # no we did not so initialize with the id
+ if id not in id_set: id_set[id] = { s : id }
+ # there is a collision, generate an id which is unique by appending
+ # the collision number
+ else: id_set[id][s] = id + str(len(id_set[id]))
+
+ return id_set[id][s]
+
+def is_dos_short_file_name(file):
+ """ examine if the given file is in the 8.3 form.
+ """
+ fname, ext = os.path.splitext(file)
+ proper_ext = len(ext) == 0 or (2 <= len(ext) <= 4) # the ext contains the dot
+ proper_fname = file.isupper() and len(fname) <= 8
+
+ return proper_ext and proper_fname
+
+def gen_dos_short_file_name(file, filename_set):
+ """ see http://support.microsoft.com/default.aspx?scid=kb;en-us;Q142982
+
+ These are no complete 8.3 dos short names. The ~ char is missing and
+ replaced with one character from the filename. WiX warns about such
+ filenames, since a collision might occur. Google for "CNDL1014" for
+ more information.
+ """
+ # guard this to not confuse the generation
+ if is_dos_short_file_name(file):
+ return file
+
+ fname, ext = os.path.splitext(file) # ext contains the dot
+
+ # first try if it suffices to convert to upper
+ file = file.upper()
+ if is_dos_short_file_name(file):
+ return file
+
+ # strip forbidden characters.
+ forbidden = '."/[]:;=, '
+ fname = [c for c in fname if c not in forbidden]
+
+ # check if we already generated a filename with the same number:
+ # thisis1.txt, thisis2.txt etc.
+ duplicate, num = not None, 1
+ while duplicate:
+ shortname = "%s%s" % (fname[:8-len(str(num))].upper(),\
+ str(num))
+ if len(ext) >= 2:
+ shortname = "%s%s" % (shortname, ext[:4].upper())
+
+ duplicate, num = shortname in filename_set, num+1
+
+ assert( is_dos_short_file_name(shortname) ), 'shortname is %s, longname is %s' % (shortname, file)
+ filename_set.append(shortname)
+ return shortname
+
+def create_feature_dict(files):
+ """ X_MSI_FEATURE and doc FileTag's can be used to collect files in a
+ hierarchy. This function collects the files into this hierarchy.
+ """
+ dict = {}
+
+ def add_to_dict( feature, file ):
+ if not SCons.Util.is_List( feature ):
+ feature = [ feature ]
+
+ for f in feature:
+ if f not in dict:
+ dict[ f ] = [ file ]
+ else:
+ dict[ f ].append( file )
+
+ for file in files:
+ if hasattr( file, 'PACKAGING_X_MSI_FEATURE' ):
+ add_to_dict(file.PACKAGING_X_MSI_FEATURE, file)
+ elif hasattr( file, 'PACKAGING_DOC' ):
+ add_to_dict( 'PACKAGING_DOC', file )
+ else:
+ add_to_dict( 'default', file )
+
+ return dict
+
+def generate_guids(root):
+ """ generates globally unique identifiers for parts of the xml which need
+ them.
+
+ Component tags have a special requirement. Their UUID is only allowed to
+ change if the list of their contained resources has changed. This allows
+ for clean removal and proper updates.
+
+ To handle this requirement, the uuid is generated with an md5 hashing the
+ whole subtree of a xml node.
+ """
+ from hashlib import md5
+
+ # specify which tags need a guid and in which attribute this should be stored.
+ needs_id = { 'Product' : 'Id',
+ 'Package' : 'Id',
+ 'Component' : 'Guid',
+ }
+
+ # find all XMl nodes matching the key, retrieve their attribute, hash their
+ # subtree, convert hash to string and add as a attribute to the xml node.
+ for (key,value) in needs_id.items():
+ node_list = root.getElementsByTagName(key)
+ attribute = value
+ for node in node_list:
+ hash = md5(node.toxml()).hexdigest()
+ hash_str = '%s-%s-%s-%s-%s' % ( hash[:8], hash[8:12], hash[12:16], hash[16:20], hash[20:] )
+ node.attributes[attribute] = hash_str
+
+
+
+def string_wxsfile(target, source, env):
+ return "building WiX file %s"%( target[0].path )
+
+def build_wxsfile(target, source, env):
+ """ compiles a .wxs file from the keywords given in env['msi_spec'] and
+ by analyzing the tree of source nodes and their tags.
+ """
+ file = open(target[0].abspath, 'w')
+
+ try:
+ # Create a document with the Wix root tag
+ doc = Document()
+ root = doc.createElement( 'Wix' )
+ root.attributes['xmlns']='http://schemas.microsoft.com/wix/2003/01/wi'
+ doc.appendChild( root )
+
+ filename_set = [] # this is to circumvent duplicates in the shortnames
+ id_set = {} # this is to circumvent duplicates in the ids
+
+ # Create the content
+ build_wxsfile_header_section(root, env)
+ build_wxsfile_file_section(root, source, env['NAME'], env['VERSION'], env['VENDOR'], filename_set, id_set)
+ generate_guids(root)
+ build_wxsfile_features_section(root, source, env['NAME'], env['VERSION'], env['SUMMARY'], id_set)
+ build_wxsfile_default_gui(root)
+ build_license_file(target[0].get_dir(), env)
+
+ # write the xml to a file
+ file.write( doc.toprettyxml() )
+
+ # call a user specified function
+ if 'CHANGE_SPECFILE' in env:
+ env['CHANGE_SPECFILE'](target, source)
+
+ except KeyError, e:
+ raise SCons.Errors.UserError( '"%s" package field for MSI is missing.' % e.args[0] )
+
+#
+# setup function
+#
+def create_default_directory_layout(root, NAME, VERSION, VENDOR, filename_set):
+ """ Create the wix default target directory layout and return the innermost
+ directory.
+
+ We assume that the XML tree delivered in the root argument already contains
+ the Product tag.
+
+ Everything is put under the PFiles directory property defined by WiX.
+ After that a directory with the 'VENDOR' tag is placed and then a
+ directory with the name of the project and its VERSION. This leads to the
+ following TARGET Directory Layout:
+ C:\<PFiles>\<Vendor>\<Projectname-Version>\
+ Example: C:\Programme\Company\Product-1.2\
+ """
+ doc = Document()
+ d1 = doc.createElement( 'Directory' )
+ d1.attributes['Id'] = 'TARGETDIR'
+ d1.attributes['Name'] = 'SourceDir'
+
+ d2 = doc.createElement( 'Directory' )
+ d2.attributes['Id'] = 'ProgramFilesFolder'
+ d2.attributes['Name'] = 'PFiles'
+
+ d3 = doc.createElement( 'Directory' )
+ d3.attributes['Id'] = 'VENDOR_folder'
+ d3.attributes['Name'] = escape( gen_dos_short_file_name( VENDOR, filename_set ) )
+ d3.attributes['LongName'] = escape( VENDOR )
+
+ d4 = doc.createElement( 'Directory' )
+ project_folder = "%s-%s" % ( NAME, VERSION )
+ d4.attributes['Id'] = 'MY_DEFAULT_FOLDER'
+ d4.attributes['Name'] = escape( gen_dos_short_file_name( project_folder, filename_set ) )
+ d4.attributes['LongName'] = escape( project_folder )
+
+ d1.childNodes.append( d2 )
+ d2.childNodes.append( d3 )
+ d3.childNodes.append( d4 )
+
+ root.getElementsByTagName('Product')[0].childNodes.append( d1 )
+
+ return d4
+
+#
+# mandatory and optional file tags
+#
+def build_wxsfile_file_section(root, files, NAME, VERSION, VENDOR, filename_set, id_set):
+ """ builds the Component sections of the wxs file with their included files.
+
+ Files need to be specified in 8.3 format and in the long name format, long
+ filenames will be converted automatically.
+
+ Features are specficied with the 'X_MSI_FEATURE' or 'DOC' FileTag.
+ """
+ root = create_default_directory_layout( root, NAME, VERSION, VENDOR, filename_set )
+ components = create_feature_dict( files )
+ factory = Document()
+
+ def get_directory( node, dir ):
+ """ returns the node under the given node representing the directory.
+
+ Returns the component node if dir is None or empty.
+ """
+ if dir == '' or not dir:
+ return node
+
+ Directory = node
+ dir_parts = dir.split(os.path.sep)
+
+ # to make sure that our directory ids are unique, the parent folders are
+ # consecutively added to upper_dir
+ upper_dir = ''
+
+ # walk down the xml tree finding parts of the directory
+ dir_parts = [d for d in dir_parts if d != '']
+ for d in dir_parts[:]:
+ already_created = [c for c in Directory.childNodes
+ if c.nodeName == 'Directory'
+ and c.attributes['LongName'].value == escape(d)]
+
+ if already_created != []:
+ Directory = already_created[0]
+ dir_parts.remove(d)
+ upper_dir += d
+ else:
+ break
+
+ for d in dir_parts:
+ nDirectory = factory.createElement( 'Directory' )
+ nDirectory.attributes['LongName'] = escape( d )
+ nDirectory.attributes['Name'] = escape( gen_dos_short_file_name( d, filename_set ) )
+ upper_dir += d
+ nDirectory.attributes['Id'] = convert_to_id( upper_dir, id_set )
+
+ Directory.childNodes.append( nDirectory )
+ Directory = nDirectory
+
+ return Directory
+
+ for file in files:
+ drive, path = os.path.splitdrive( file.PACKAGING_INSTALL_LOCATION )
+ filename = os.path.basename( path )
+ dirname = os.path.dirname( path )
+
+ h = {
+ # tagname : default value
+ 'PACKAGING_X_MSI_VITAL' : 'yes',
+ 'PACKAGING_X_MSI_FILEID' : convert_to_id(filename, id_set),
+ 'PACKAGING_X_MSI_LONGNAME' : filename,
+ 'PACKAGING_X_MSI_SHORTNAME' : gen_dos_short_file_name(filename, filename_set),
+ 'PACKAGING_X_MSI_SOURCE' : file.get_path(),
+ }
+
+ # fill in the default tags given above.
+ for k,v in [ (k, v) for (k,v) in h.items() if not hasattr(file, k) ]:
+ setattr( file, k, v )
+
+ File = factory.createElement( 'File' )
+ File.attributes['LongName'] = escape( file.PACKAGING_X_MSI_LONGNAME )
+ File.attributes['Name'] = escape( file.PACKAGING_X_MSI_SHORTNAME )
+ File.attributes['Source'] = escape( file.PACKAGING_X_MSI_SOURCE )
+ File.attributes['Id'] = escape( file.PACKAGING_X_MSI_FILEID )
+ File.attributes['Vital'] = escape( file.PACKAGING_X_MSI_VITAL )
+
+ # create the <Component> Tag under which this file should appear
+ Component = factory.createElement('Component')
+ Component.attributes['DiskId'] = '1'
+ Component.attributes['Id'] = convert_to_id( filename, id_set )
+
+ # hang the component node under the root node and the file node
+ # under the component node.
+ Directory = get_directory( root, dirname )
+ Directory.childNodes.append( Component )
+ Component.childNodes.append( File )
+
+#
+# additional functions
+#
+def build_wxsfile_features_section(root, files, NAME, VERSION, SUMMARY, id_set):
+ """ This function creates the <features> tag based on the supplied xml tree.
+
+ This is achieved by finding all <component>s and adding them to a default target.
+
+ It should be called after the tree has been built completly. We assume
+ that a MY_DEFAULT_FOLDER Property is defined in the wxs file tree.
+
+ Furthermore a top-level with the name and VERSION of the software will be created.
+
+ An PACKAGING_X_MSI_FEATURE can either be a string, where the feature
+ DESCRIPTION will be the same as its title or a Tuple, where the first
+ part will be its title and the second its DESCRIPTION.
+ """
+ factory = Document()
+ Feature = factory.createElement('Feature')
+ Feature.attributes['Id'] = 'complete'
+ Feature.attributes['ConfigurableDirectory'] = 'MY_DEFAULT_FOLDER'
+ Feature.attributes['Level'] = '1'
+ Feature.attributes['Title'] = escape( '%s %s' % (NAME, VERSION) )
+ Feature.attributes['Description'] = escape( SUMMARY )
+ Feature.attributes['Display'] = 'expand'
+
+ for (feature, files) in create_feature_dict(files).items():
+ SubFeature = factory.createElement('Feature')
+ SubFeature.attributes['Level'] = '1'
+
+ if SCons.Util.is_Tuple(feature):
+ SubFeature.attributes['Id'] = convert_to_id( feature[0], id_set )
+ SubFeature.attributes['Title'] = escape(feature[0])
+ SubFeature.attributes['Description'] = escape(feature[1])
+ else:
+ SubFeature.attributes['Id'] = convert_to_id( feature, id_set )
+ if feature=='default':
+ SubFeature.attributes['Description'] = 'Main Part'
+ SubFeature.attributes['Title'] = 'Main Part'
+ elif feature=='PACKAGING_DOC':
+ SubFeature.attributes['Description'] = 'Documentation'
+ SubFeature.attributes['Title'] = 'Documentation'
+ else:
+ SubFeature.attributes['Description'] = escape(feature)
+ SubFeature.attributes['Title'] = escape(feature)
+
+ # build the componentrefs. As one of the design decision is that every
+ # file is also a component we walk the list of files and create a
+ # reference.
+ for f in files:
+ ComponentRef = factory.createElement('ComponentRef')
+ ComponentRef.attributes['Id'] = convert_to_id( os.path.basename(f.get_path()), id_set )
+ SubFeature.childNodes.append(ComponentRef)
+
+ Feature.childNodes.append(SubFeature)
+
+ root.getElementsByTagName('Product')[0].childNodes.append(Feature)
+
+def build_wxsfile_default_gui(root):
+ """ this function adds a default GUI to the wxs file
+ """
+ factory = Document()
+ Product = root.getElementsByTagName('Product')[0]
+
+ UIRef = factory.createElement('UIRef')
+ UIRef.attributes['Id'] = 'WixUI_Mondo'
+ Product.childNodes.append(UIRef)
+
+ UIRef = factory.createElement('UIRef')
+ UIRef.attributes['Id'] = 'WixUI_ErrorProgressText'
+ Product.childNodes.append(UIRef)
+
+def build_license_file(directory, spec):
+ """ creates a License.rtf file with the content of "X_MSI_LICENSE_TEXT"
+ in the given directory
+ """
+ name, text = '', ''
+
+ try:
+ name = spec['LICENSE']
+ text = spec['X_MSI_LICENSE_TEXT']
+ except KeyError:
+ pass # ignore this as X_MSI_LICENSE_TEXT is optional
+
+ if name!='' or text!='':
+ file = open( os.path.join(directory.get_path(), 'License.rtf'), 'w' )
+ file.write('{\\rtf')
+ if text!='':
+ file.write(text.replace('\n', '\\par '))
+ else:
+ file.write(name+'\\par\\par')
+ file.write('}')
+ file.close()
+
+#
+# mandatory and optional package tags
+#
+def build_wxsfile_header_section(root, spec):
+ """ Adds the xml file node which define the package meta-data.
+ """
+ # Create the needed DOM nodes and add them at the correct position in the tree.
+ factory = Document()
+ Product = factory.createElement( 'Product' )
+ Package = factory.createElement( 'Package' )
+
+ root.childNodes.append( Product )
+ Product.childNodes.append( Package )
+
+ # set "mandatory" default values
+ if 'X_MSI_LANGUAGE' not in spec:
+ spec['X_MSI_LANGUAGE'] = '1033' # select english
+
+ # mandatory sections, will throw a KeyError if the tag is not available
+ Product.attributes['Name'] = escape( spec['NAME'] )
+ Product.attributes['Version'] = escape( spec['VERSION'] )
+ Product.attributes['Manufacturer'] = escape( spec['VENDOR'] )
+ Product.attributes['Language'] = escape( spec['X_MSI_LANGUAGE'] )
+ Package.attributes['Description'] = escape( spec['SUMMARY'] )
+
+ # now the optional tags, for which we avoid the KeyErrror exception
+ if 'DESCRIPTION' in spec:
+ Package.attributes['Comments'] = escape( spec['DESCRIPTION'] )
+
+ if 'X_MSI_UPGRADE_CODE' in spec:
+ Package.attributes['X_MSI_UPGRADE_CODE'] = escape( spec['X_MSI_UPGRADE_CODE'] )
+
+ # We hardcode the media tag as our current model cannot handle it.
+ Media = factory.createElement('Media')
+ Media.attributes['Id'] = '1'
+ Media.attributes['Cabinet'] = 'default.cab'
+ Media.attributes['EmbedCab'] = 'yes'
+ root.getElementsByTagName('Product')[0].childNodes.append(Media)
+
+# this builder is the entry-point for .wxs file compiler.
+wxs_builder = Builder(
+ action = Action( build_wxsfile, string_wxsfile ),
+ ensure_suffix = '.wxs' )
+
+def package(env, target, source, PACKAGEROOT, NAME, VERSION,
+ DESCRIPTION, SUMMARY, VENDOR, X_MSI_LANGUAGE, **kw):
+ # make sure that the Wix Builder is in the environment
+ SCons.Tool.Tool('wix').generate(env)
+
+ # get put the keywords for the specfile compiler. These are the arguments
+ # given to the package function and all optional ones stored in kw, minus
+ # the the source, target and env one.
+ loc = locals()
+ del loc['kw']
+ kw.update(loc)
+ del kw['source'], kw['target'], kw['env']
+
+ # strip the install builder from the source files
+ target, source = stripinstallbuilder(target, source, env)
+
+ # put the arguments into the env and call the specfile builder.
+ env['msi_spec'] = kw
+ specfile = wxs_builder(* [env, target, source], **kw)
+
+ # now call the WiX Tool with the built specfile added as a source.
+ msifile = env.WiX(target, specfile)
+
+ # return the target and source tuple.
+ return (msifile, source+[specfile])
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/rpm.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/rpm.py
new file mode 100644
index 00000000..a09457b6
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/rpm.py
@@ -0,0 +1,365 @@
+"""SCons.Tool.Packaging.rpm
+
+The rpm packager.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Tool/packaging/rpm.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+
+import SCons.Builder
+
+from SCons.Environment import OverrideEnvironment
+from SCons.Tool.packaging import stripinstallbuilder, src_targz
+from SCons.Errors import UserError
+
+def package(env, target, source, PACKAGEROOT, NAME, VERSION,
+ PACKAGEVERSION, DESCRIPTION, SUMMARY, X_RPM_GROUP, LICENSE,
+ **kw):
+ # initialize the rpm tool
+ SCons.Tool.Tool('rpm').generate(env)
+
+ bld = env['BUILDERS']['Rpm']
+
+ # Generate a UserError whenever the target name has been set explicitly,
+ # since rpm does not allow for controlling it. This is detected by
+ # checking if the target has been set to the default by the Package()
+ # Environment function.
+ if str(target[0])!="%s-%s"%(NAME, VERSION):
+ raise UserError( "Setting target is not supported for rpm." )
+ else:
+ # This should be overridable from the construction environment,
+ # which it is by using ARCHITECTURE=.
+ # Guessing based on what os.uname() returns at least allows it
+ # to work for both i386 and x86_64 Linux systems.
+ archmap = {
+ 'i686' : 'i386',
+ 'i586' : 'i386',
+ 'i486' : 'i386',
+ }
+
+ buildarchitecture = os.uname()[4]
+ buildarchitecture = archmap.get(buildarchitecture, buildarchitecture)
+
+ if 'ARCHITECTURE' in kw:
+ buildarchitecture = kw['ARCHITECTURE']
+
+ fmt = '%s-%s-%s.%s.rpm'
+ srcrpm = fmt % (NAME, VERSION, PACKAGEVERSION, 'src')
+ binrpm = fmt % (NAME, VERSION, PACKAGEVERSION, buildarchitecture)
+
+ target = [ srcrpm, binrpm ]
+
+ # get the correct arguments into the kw hash
+ loc=locals()
+ del loc['kw']
+ kw.update(loc)
+ del kw['source'], kw['target'], kw['env']
+
+ # if no "SOURCE_URL" tag is given add a default one.
+ if 'SOURCE_URL' not in kw:
+ #kw['SOURCE_URL']=(str(target[0])+".tar.gz").replace('.rpm', '')
+ kw['SOURCE_URL']=(str(target[0])+".tar.gz").replace('.rpm', '')
+
+ # mangle the source and target list for the rpmbuild
+ env = OverrideEnvironment(env, kw)
+ target, source = stripinstallbuilder(target, source, env)
+ target, source = addspecfile(target, source, env)
+ target, source = collectintargz(target, source, env)
+
+ # now call the rpm builder to actually build the packet.
+ return bld(env, target, source, **kw)
+
+def collectintargz(target, source, env):
+ """ Puts all source files into a tar.gz file. """
+ # the rpm tool depends on a source package, until this is chagned
+ # this hack needs to be here that tries to pack all sources in.
+ sources = env.FindSourceFiles()
+
+ # filter out the target we are building the source list for.
+ #sources = [s for s in sources if not (s in target)]
+ sources = [s for s in sources if s not in target]
+
+ # find the .spec file for rpm and add it since it is not necessarily found
+ # by the FindSourceFiles function.
+ #sources.extend( [s for s in source if str(s).rfind('.spec')!=-1] )
+ spec_file = lambda s: str(s).rfind('.spec') != -1
+ sources.extend( list(filter(spec_file, source)) )
+
+ # as the source contains the url of the source package this rpm package
+ # is built from, we extract the target name
+ #tarball = (str(target[0])+".tar.gz").replace('.rpm', '')
+ tarball = (str(target[0])+".tar.gz").replace('.rpm', '')
+ try:
+ #tarball = env['SOURCE_URL'].split('/')[-1]
+ tarball = env['SOURCE_URL'].split('/')[-1]
+ except KeyError, e:
+ raise SCons.Errors.UserError( "Missing PackageTag '%s' for RPM packager" % e.args[0] )
+
+ tarball = src_targz.package(env, source=sources, target=tarball,
+ PACKAGEROOT=env['PACKAGEROOT'], )
+
+ return (target, tarball)
+
+def addspecfile(target, source, env):
+ specfile = "%s-%s" % (env['NAME'], env['VERSION'])
+
+ bld = SCons.Builder.Builder(action = build_specfile,
+ suffix = '.spec',
+ target_factory = SCons.Node.FS.File)
+
+ source.extend(bld(env, specfile, source))
+
+ return (target,source)
+
+def build_specfile(target, source, env):
+ """ Builds a RPM specfile from a dictionary with string metadata and
+ by analyzing a tree of nodes.
+ """
+ file = open(target[0].abspath, 'w')
+ str = ""
+
+ try:
+ file.write( build_specfile_header(env) )
+ file.write( build_specfile_sections(env) )
+ file.write( build_specfile_filesection(env, source) )
+ file.close()
+
+ # call a user specified function
+ if 'CHANGE_SPECFILE' in env:
+ env['CHANGE_SPECFILE'](target, source)
+
+ except KeyError, e:
+ raise SCons.Errors.UserError( '"%s" package field for RPM is missing.' % e.args[0] )
+
+
+#
+# mandatory and optional package tag section
+#
+def build_specfile_sections(spec):
+ """ Builds the sections of a rpm specfile.
+ """
+ str = ""
+
+ mandatory_sections = {
+ 'DESCRIPTION' : '\n%%description\n%s\n\n', }
+
+ str = str + SimpleTagCompiler(mandatory_sections).compile( spec )
+
+ optional_sections = {
+ 'DESCRIPTION_' : '%%description -l %s\n%s\n\n',
+ 'CHANGELOG' : '%%changelog\n%s\n\n',
+ 'X_RPM_PREINSTALL' : '%%pre\n%s\n\n',
+ 'X_RPM_POSTINSTALL' : '%%post\n%s\n\n',
+ 'X_RPM_PREUNINSTALL' : '%%preun\n%s\n\n',
+ 'X_RPM_POSTUNINSTALL' : '%%postun\n%s\n\n',
+ 'X_RPM_VERIFY' : '%%verify\n%s\n\n',
+
+ # These are for internal use but could possibly be overriden
+ 'X_RPM_PREP' : '%%prep\n%s\n\n',
+ 'X_RPM_BUILD' : '%%build\n%s\n\n',
+ 'X_RPM_INSTALL' : '%%install\n%s\n\n',
+ 'X_RPM_CLEAN' : '%%clean\n%s\n\n',
+ }
+
+ # Default prep, build, install and clean rules
+ # TODO: optimize those build steps, to not compile the project a second time
+ if 'X_RPM_PREP' not in spec:
+ spec['X_RPM_PREP'] = '[ -n "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != / ] && rm -rf "$RPM_BUILD_ROOT"' + '\n%setup -q'
+
+ if 'X_RPM_BUILD' not in spec:
+ spec['X_RPM_BUILD'] = 'mkdir "$RPM_BUILD_ROOT"'
+
+ if 'X_RPM_INSTALL' not in spec:
+ spec['X_RPM_INSTALL'] = 'scons --install-sandbox="$RPM_BUILD_ROOT" "$RPM_BUILD_ROOT"'
+
+ if 'X_RPM_CLEAN' not in spec:
+ spec['X_RPM_CLEAN'] = '[ -n "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != / ] && rm -rf "$RPM_BUILD_ROOT"'
+
+ str = str + SimpleTagCompiler(optional_sections, mandatory=0).compile( spec )
+
+ return str
+
+def build_specfile_header(spec):
+ """ Builds all section but the %file of a rpm specfile
+ """
+ str = ""
+
+ # first the mandatory sections
+ mandatory_header_fields = {
+ 'NAME' : '%%define name %s\nName: %%{name}\n',
+ 'VERSION' : '%%define version %s\nVersion: %%{version}\n',
+ 'PACKAGEVERSION' : '%%define release %s\nRelease: %%{release}\n',
+ 'X_RPM_GROUP' : 'Group: %s\n',
+ 'SUMMARY' : 'Summary: %s\n',
+ 'LICENSE' : 'License: %s\n', }
+
+ str = str + SimpleTagCompiler(mandatory_header_fields).compile( spec )
+
+ # now the optional tags
+ optional_header_fields = {
+ 'VENDOR' : 'Vendor: %s\n',
+ 'X_RPM_URL' : 'Url: %s\n',
+ 'SOURCE_URL' : 'Source: %s\n',
+ 'SUMMARY_' : 'Summary(%s): %s\n',
+ 'X_RPM_DISTRIBUTION' : 'Distribution: %s\n',
+ 'X_RPM_ICON' : 'Icon: %s\n',
+ 'X_RPM_PACKAGER' : 'Packager: %s\n',
+ 'X_RPM_GROUP_' : 'Group(%s): %s\n',
+
+ 'X_RPM_REQUIRES' : 'Requires: %s\n',
+ 'X_RPM_PROVIDES' : 'Provides: %s\n',
+ 'X_RPM_CONFLICTS' : 'Conflicts: %s\n',
+ 'X_RPM_BUILDREQUIRES' : 'BuildRequires: %s\n',
+
+ 'X_RPM_SERIAL' : 'Serial: %s\n',
+ 'X_RPM_EPOCH' : 'Epoch: %s\n',
+ 'X_RPM_AUTOREQPROV' : 'AutoReqProv: %s\n',
+ 'X_RPM_EXCLUDEARCH' : 'ExcludeArch: %s\n',
+ 'X_RPM_EXCLUSIVEARCH' : 'ExclusiveArch: %s\n',
+ 'X_RPM_PREFIX' : 'Prefix: %s\n',
+ 'X_RPM_CONFLICTS' : 'Conflicts: %s\n',
+
+ # internal use
+ 'X_RPM_BUILDROOT' : 'BuildRoot: %s\n', }
+
+ # fill in default values:
+ # Adding a BuildRequires renders the .rpm unbuildable under System, which
+ # are not managed by rpm, since the database to resolve this dependency is
+ # missing (take Gentoo as an example)
+# if not s.has_key('x_rpm_BuildRequires'):
+# s['x_rpm_BuildRequires'] = 'scons'
+
+ if 'X_RPM_BUILDROOT' not in spec:
+ spec['X_RPM_BUILDROOT'] = '%{_tmppath}/%{name}-%{version}-%{release}'
+
+ str = str + SimpleTagCompiler(optional_header_fields, mandatory=0).compile( spec )
+ return str
+
+#
+# mandatory and optional file tags
+#
+def build_specfile_filesection(spec, files):
+ """ builds the %file section of the specfile
+ """
+ str = '%files\n'
+
+ if 'X_RPM_DEFATTR' not in spec:
+ spec['X_RPM_DEFATTR'] = '(-,root,root)'
+
+ str = str + '%%defattr %s\n' % spec['X_RPM_DEFATTR']
+
+ supported_tags = {
+ 'PACKAGING_CONFIG' : '%%config %s',
+ 'PACKAGING_CONFIG_NOREPLACE' : '%%config(noreplace) %s',
+ 'PACKAGING_DOC' : '%%doc %s',
+ 'PACKAGING_UNIX_ATTR' : '%%attr %s',
+ 'PACKAGING_LANG_' : '%%lang(%s) %s',
+ 'PACKAGING_X_RPM_VERIFY' : '%%verify %s',
+ 'PACKAGING_X_RPM_DIR' : '%%dir %s',
+ 'PACKAGING_X_RPM_DOCDIR' : '%%docdir %s',
+ 'PACKAGING_X_RPM_GHOST' : '%%ghost %s', }
+
+ for file in files:
+ # build the tagset
+ tags = {}
+ for k in supported_tags.keys():
+ try:
+ tags[k]=getattr(file, k)
+ except AttributeError:
+ pass
+
+ # compile the tagset
+ str = str + SimpleTagCompiler(supported_tags, mandatory=0).compile( tags )
+
+ str = str + ' '
+ str = str + file.PACKAGING_INSTALL_LOCATION
+ str = str + '\n\n'
+
+ return str
+
+class SimpleTagCompiler(object):
+ """ This class is a simple string substition utility:
+ the replacement specfication is stored in the tagset dictionary, something
+ like:
+ { "abc" : "cdef %s ",
+ "abc_" : "cdef %s %s" }
+
+ the compile function gets a value dictionary, which may look like:
+ { "abc" : "ghij",
+ "abc_gh" : "ij" }
+
+ The resulting string will be:
+ "cdef ghij cdef gh ij"
+ """
+ def __init__(self, tagset, mandatory=1):
+ self.tagset = tagset
+ self.mandatory = mandatory
+
+ def compile(self, values):
+ """ compiles the tagset and returns a str containing the result
+ """
+ def is_international(tag):
+ #return tag.endswith('_')
+ return tag[-1:] == '_'
+
+ def get_country_code(tag):
+ return tag[-2:]
+
+ def strip_country_code(tag):
+ return tag[:-2]
+
+ replacements = list(self.tagset.items())
+
+ str = ""
+ #domestic = [ (k,v) for k,v in replacements if not is_international(k) ]
+ domestic = [t for t in replacements if not is_international(t[0])]
+ for key, replacement in domestic:
+ try:
+ str = str + replacement % values[key]
+ except KeyError, e:
+ if self.mandatory:
+ raise e
+
+ #international = [ (k,v) for k,v in replacements if is_international(k) ]
+ international = [t for t in replacements if is_international(t[0])]
+ for key, replacement in international:
+ try:
+ #int_values_for_key = [ (get_country_code(k),v) for k,v in values.items() if strip_country_code(k) == key ]
+ x = [t for t in values.items() if strip_country_code(t[0]) == key]
+ int_values_for_key = [(get_country_code(t[0]),t[1]) for t in x]
+ for v in int_values_for_key:
+ str = str + replacement % v
+ except KeyError, e:
+ if self.mandatory:
+ raise e
+
+ return str
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/src_tarbz2.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/src_tarbz2.py
new file mode 100644
index 00000000..a6ea7500
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/src_tarbz2.py
@@ -0,0 +1,43 @@
+"""SCons.Tool.Packaging.tarbz2
+
+The tarbz2 SRC packager.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/packaging/src_tarbz2.py 5134 2010/08/16 23:02:40 bdeegan"
+
+from SCons.Tool.packaging import putintopackageroot
+
+def package(env, target, source, PACKAGEROOT, **kw):
+ bld = env['BUILDERS']['Tar']
+ bld.set_suffix('.tar.bz2')
+ target, source = putintopackageroot(target, source, env, PACKAGEROOT, honor_install_location=0)
+ return bld(env, target, source, TARFLAGS='-jc')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/src_targz.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/src_targz.py
new file mode 100644
index 00000000..7474ea6c
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/src_targz.py
@@ -0,0 +1,43 @@
+"""SCons.Tool.Packaging.targz
+
+The targz SRC packager.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/packaging/src_targz.py 5134 2010/08/16 23:02:40 bdeegan"
+
+from SCons.Tool.packaging import putintopackageroot
+
+def package(env, target, source, PACKAGEROOT, **kw):
+ bld = env['BUILDERS']['Tar']
+ bld.set_suffix('.tar.gz')
+ target, source = putintopackageroot(target, source, env, PACKAGEROOT, honor_install_location=0)
+ return bld(env, target, source, TARFLAGS='-zc')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/src_zip.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/src_zip.py
new file mode 100644
index 00000000..d81f54c5
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/src_zip.py
@@ -0,0 +1,43 @@
+"""SCons.Tool.Packaging.zip
+
+The zip SRC packager.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/packaging/src_zip.py 5134 2010/08/16 23:02:40 bdeegan"
+
+from SCons.Tool.packaging import putintopackageroot
+
+def package(env, target, source, PACKAGEROOT, **kw):
+ bld = env['BUILDERS']['Zip']
+ bld.set_suffix('.zip')
+ target, source = putintopackageroot(target, source, env, PACKAGEROOT, honor_install_location=0)
+ return bld(env, target, source)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/tarbz2.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/tarbz2.py
new file mode 100644
index 00000000..c01d7bcb
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/tarbz2.py
@@ -0,0 +1,44 @@
+"""SCons.Tool.Packaging.tarbz2
+
+The tarbz2 SRC packager.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/packaging/tarbz2.py 5134 2010/08/16 23:02:40 bdeegan"
+
+from SCons.Tool.packaging import stripinstallbuilder, putintopackageroot
+
+def package(env, target, source, PACKAGEROOT, **kw):
+ bld = env['BUILDERS']['Tar']
+ bld.set_suffix('.tar.gz')
+ target, source = putintopackageroot(target, source, env, PACKAGEROOT)
+ target, source = stripinstallbuilder(target, source, env)
+ return bld(env, target, source, TARFLAGS='-jc')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/targz.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/targz.py
new file mode 100644
index 00000000..6a3282d5
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/targz.py
@@ -0,0 +1,44 @@
+"""SCons.Tool.Packaging.targz
+
+The targz SRC packager.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/packaging/targz.py 5134 2010/08/16 23:02:40 bdeegan"
+
+from SCons.Tool.packaging import stripinstallbuilder, putintopackageroot
+
+def package(env, target, source, PACKAGEROOT, **kw):
+ bld = env['BUILDERS']['Tar']
+ bld.set_suffix('.tar.gz')
+ target, source = stripinstallbuilder(target, source, env)
+ target, source = putintopackageroot(target, source, env, PACKAGEROOT)
+ return bld(env, target, source, TARFLAGS='-zc')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/zip.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/zip.py
new file mode 100644
index 00000000..462aa47e
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/packaging/zip.py
@@ -0,0 +1,44 @@
+"""SCons.Tool.Packaging.zip
+
+The zip SRC packager.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/packaging/zip.py 5134 2010/08/16 23:02:40 bdeegan"
+
+from SCons.Tool.packaging import stripinstallbuilder, putintopackageroot
+
+def package(env, target, source, PACKAGEROOT, **kw):
+ bld = env['BUILDERS']['Zip']
+ bld.set_suffix('.zip')
+ target, source = stripinstallbuilder(target, source, env)
+ target, source = putintopackageroot(target, source, env, PACKAGEROOT)
+ return bld(env, target, source)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/pdf.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/pdf.py
new file mode 100644
index 00000000..e0221055
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/pdf.py
@@ -0,0 +1,78 @@
+"""SCons.Tool.pdf
+
+Common PDF Builder definition for various other Tool modules that use it.
+Add an explicit action to run epstopdf to convert .eps files to .pdf
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/pdf.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Builder
+import SCons.Tool
+
+PDFBuilder = None
+
+EpsPdfAction = SCons.Action.Action('$EPSTOPDFCOM', '$EPSTOPDFCOMSTR')
+
+def generate(env):
+ try:
+ env['BUILDERS']['PDF']
+ except KeyError:
+ global PDFBuilder
+ if PDFBuilder is None:
+ PDFBuilder = SCons.Builder.Builder(action = {},
+ source_scanner = SCons.Tool.PDFLaTeXScanner,
+ prefix = '$PDFPREFIX',
+ suffix = '$PDFSUFFIX',
+ emitter = {},
+ source_ext_match = None,
+ single_source=True)
+ env['BUILDERS']['PDF'] = PDFBuilder
+
+ env['PDFPREFIX'] = ''
+ env['PDFSUFFIX'] = '.pdf'
+
+# put the epstopdf builder in this routine so we can add it after
+# the pdftex builder so that one is the default for no source suffix
+def generate2(env):
+ bld = env['BUILDERS']['PDF']
+ #bld.add_action('.ps', EpsPdfAction) # this is covered by direct Ghostcript action in gs.py
+ bld.add_action('.eps', EpsPdfAction)
+
+ env['EPSTOPDF'] = 'epstopdf'
+ env['EPSTOPDFFLAGS'] = SCons.Util.CLVar('')
+ env['EPSTOPDFCOM'] = '$EPSTOPDF $EPSTOPDFFLAGS ${SOURCE} --outfile=${TARGET}'
+
+def exists(env):
+ # This only puts a skeleton Builder in place, so if someone
+ # references this Tool directly, it's always "available."
+ return 1
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/pdflatex.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/pdflatex.py
new file mode 100644
index 00000000..203b635d
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/pdflatex.py
@@ -0,0 +1,83 @@
+"""SCons.Tool.pdflatex
+
+Tool-specific initialization for pdflatex.
+Generates .pdf files from .latex or .ltx files
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/pdflatex.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Action
+import SCons.Util
+import SCons.Tool.pdf
+import SCons.Tool.tex
+
+PDFLaTeXAction = None
+
+def PDFLaTeXAuxFunction(target = None, source= None, env=None):
+ result = SCons.Tool.tex.InternalLaTeXAuxAction( PDFLaTeXAction, target, source, env )
+ if result != 0:
+ SCons.Tool.tex.check_file_error_message(env['PDFLATEX'])
+ return result
+
+PDFLaTeXAuxAction = None
+
+def generate(env):
+ """Add Builders and construction variables for pdflatex to an Environment."""
+ global PDFLaTeXAction
+ if PDFLaTeXAction is None:
+ PDFLaTeXAction = SCons.Action.Action('$PDFLATEXCOM', '$PDFLATEXCOMSTR')
+
+ global PDFLaTeXAuxAction
+ if PDFLaTeXAuxAction is None:
+ PDFLaTeXAuxAction = SCons.Action.Action(PDFLaTeXAuxFunction,
+ strfunction=SCons.Tool.tex.TeXLaTeXStrFunction)
+
+ env.AppendUnique(LATEXSUFFIXES=SCons.Tool.LaTeXSuffixes)
+
+ import pdf
+ pdf.generate(env)
+
+ bld = env['BUILDERS']['PDF']
+ bld.add_action('.ltx', PDFLaTeXAuxAction)
+ bld.add_action('.latex', PDFLaTeXAuxAction)
+ bld.add_emitter('.ltx', SCons.Tool.tex.tex_pdf_emitter)
+ bld.add_emitter('.latex', SCons.Tool.tex.tex_pdf_emitter)
+
+ SCons.Tool.tex.generate_common(env)
+
+def exists(env):
+ return env.Detect('pdflatex')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/pdftex.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/pdftex.py
new file mode 100644
index 00000000..b31c966d
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/pdftex.py
@@ -0,0 +1,108 @@
+"""SCons.Tool.pdftex
+
+Tool-specific initialization for pdftex.
+Generates .pdf files from .tex files
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/pdftex.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+import SCons.Action
+import SCons.Util
+import SCons.Tool.tex
+
+PDFTeXAction = None
+
+# This action might be needed more than once if we are dealing with
+# labels and bibtex.
+PDFLaTeXAction = None
+
+def PDFLaTeXAuxAction(target = None, source= None, env=None):
+ result = SCons.Tool.tex.InternalLaTeXAuxAction( PDFLaTeXAction, target, source, env )
+ return result
+
+def PDFTeXLaTeXFunction(target = None, source= None, env=None):
+ """A builder for TeX and LaTeX that scans the source file to
+ decide the "flavor" of the source and then executes the appropriate
+ program."""
+ basedir = os.path.split(str(source[0]))[0]
+ abspath = os.path.abspath(basedir)
+
+ if SCons.Tool.tex.is_LaTeX(source,env,abspath):
+ result = PDFLaTeXAuxAction(target,source,env)
+ if result != 0:
+ SCons.Tool.tex.check_file_error_message(env['PDFLATEX'])
+ else:
+ result = PDFTeXAction(target,source,env)
+ if result != 0:
+ SCons.Tool.tex.check_file_error_message(env['PDFTEX'])
+ return result
+
+PDFTeXLaTeXAction = None
+
+def generate(env):
+ """Add Builders and construction variables for pdftex to an Environment."""
+ global PDFTeXAction
+ if PDFTeXAction is None:
+ PDFTeXAction = SCons.Action.Action('$PDFTEXCOM', '$PDFTEXCOMSTR')
+
+ global PDFLaTeXAction
+ if PDFLaTeXAction is None:
+ PDFLaTeXAction = SCons.Action.Action("$PDFLATEXCOM", "$PDFLATEXCOMSTR")
+
+ global PDFTeXLaTeXAction
+ if PDFTeXLaTeXAction is None:
+ PDFTeXLaTeXAction = SCons.Action.Action(PDFTeXLaTeXFunction,
+ strfunction=SCons.Tool.tex.TeXLaTeXStrFunction)
+
+ env.AppendUnique(LATEXSUFFIXES=SCons.Tool.LaTeXSuffixes)
+
+ import pdf
+ pdf.generate(env)
+
+ bld = env['BUILDERS']['PDF']
+ bld.add_action('.tex', PDFTeXLaTeXAction)
+ bld.add_emitter('.tex', SCons.Tool.tex.tex_pdf_emitter)
+
+ # Add the epstopdf builder after the pdftex builder
+ # so pdftex is the default for no source suffix
+ pdf.generate2(env)
+
+ SCons.Tool.tex.generate_common(env)
+
+def exists(env):
+ return env.Detect('pdftex')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/qt.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/qt.py
new file mode 100644
index 00000000..7ce6c99c
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/qt.py
@@ -0,0 +1,336 @@
+
+"""SCons.Tool.qt
+
+Tool-specific initialization for Qt.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/qt.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+import re
+
+import SCons.Action
+import SCons.Builder
+import SCons.Defaults
+import SCons.Scanner
+import SCons.Tool
+import SCons.Util
+
+class ToolQtWarning(SCons.Warnings.Warning):
+ pass
+
+class GeneratedMocFileNotIncluded(ToolQtWarning):
+ pass
+
+class QtdirNotFound(ToolQtWarning):
+ pass
+
+SCons.Warnings.enableWarningClass(ToolQtWarning)
+
+header_extensions = [".h", ".hxx", ".hpp", ".hh"]
+if SCons.Util.case_sensitive_suffixes('.h', '.H'):
+ header_extensions.append('.H')
+cplusplus = __import__('c++', globals(), locals(), [])
+cxx_suffixes = cplusplus.CXXSuffixes
+
+def checkMocIncluded(target, source, env):
+ moc = target[0]
+ cpp = source[0]
+ # looks like cpp.includes is cleared before the build stage :-(
+ # not really sure about the path transformations (moc.cwd? cpp.cwd?) :-/
+ path = SCons.Defaults.CScan.path(env, moc.cwd)
+ includes = SCons.Defaults.CScan(cpp, env, path)
+ if not moc in includes:
+ SCons.Warnings.warn(
+ GeneratedMocFileNotIncluded,
+ "Generated moc file '%s' is not included by '%s'" %
+ (str(moc), str(cpp)))
+
+def find_file(filename, paths, node_factory):
+ for dir in paths:
+ node = node_factory(filename, dir)
+ if node.rexists():
+ return node
+ return None
+
+class _Automoc(object):
+ """
+ Callable class, which works as an emitter for Programs, SharedLibraries and
+ StaticLibraries.
+ """
+
+ def __init__(self, objBuilderName):
+ self.objBuilderName = objBuilderName
+
+ def __call__(self, target, source, env):
+ """
+ Smart autoscan function. Gets the list of objects for the Program
+ or Lib. Adds objects and builders for the special qt files.
+ """
+ try:
+ if int(env.subst('$QT_AUTOSCAN')) == 0:
+ return target, source
+ except ValueError:
+ pass
+ try:
+ debug = int(env.subst('$QT_DEBUG'))
+ except ValueError:
+ debug = 0
+
+ # some shortcuts used in the scanner
+ splitext = SCons.Util.splitext
+ objBuilder = getattr(env, self.objBuilderName)
+
+ # some regular expressions:
+ # Q_OBJECT detection
+ q_object_search = re.compile(r'[^A-Za-z0-9]Q_OBJECT[^A-Za-z0-9]')
+ # cxx and c comment 'eater'
+ #comment = re.compile(r'(//.*)|(/\*(([^*])|(\*[^/]))*\*/)')
+ # CW: something must be wrong with the regexp. See also bug #998222
+ # CURRENTLY THERE IS NO TEST CASE FOR THAT
+
+ # The following is kind of hacky to get builders working properly (FIXME)
+ objBuilderEnv = objBuilder.env
+ objBuilder.env = env
+ mocBuilderEnv = env.Moc.env
+ env.Moc.env = env
+
+ # make a deep copy for the result; MocH objects will be appended
+ out_sources = source[:]
+
+ for obj in source:
+ if not obj.has_builder():
+ # binary obj file provided
+ if debug:
+ print "scons: qt: '%s' seems to be a binary. Discarded." % str(obj)
+ continue
+ cpp = obj.sources[0]
+ if not splitext(str(cpp))[1] in cxx_suffixes:
+ if debug:
+ print "scons: qt: '%s' is no cxx file. Discarded." % str(cpp)
+ # c or fortran source
+ continue
+ #cpp_contents = comment.sub('', cpp.get_text_contents())
+ cpp_contents = cpp.get_text_contents()
+ h=None
+ for h_ext in header_extensions:
+ # try to find the header file in the corresponding source
+ # directory
+ hname = splitext(cpp.name)[0] + h_ext
+ h = find_file(hname, (cpp.get_dir(),), env.File)
+ if h:
+ if debug:
+ print "scons: qt: Scanning '%s' (header of '%s')" % (str(h), str(cpp))
+ #h_contents = comment.sub('', h.get_text_contents())
+ h_contents = h.get_text_contents()
+ break
+ if not h and debug:
+ print "scons: qt: no header for '%s'." % (str(cpp))
+ if h and q_object_search.search(h_contents):
+ # h file with the Q_OBJECT macro found -> add moc_cpp
+ moc_cpp = env.Moc(h)
+ moc_o = objBuilder(moc_cpp)
+ out_sources.append(moc_o)
+ #moc_cpp.target_scanner = SCons.Defaults.CScan
+ if debug:
+ print "scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(h), str(moc_cpp))
+ if cpp and q_object_search.search(cpp_contents):
+ # cpp file with Q_OBJECT macro found -> add moc
+ # (to be included in cpp)
+ moc = env.Moc(cpp)
+ env.Ignore(moc, moc)
+ if debug:
+ print "scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(cpp), str(moc))
+ #moc.source_scanner = SCons.Defaults.CScan
+ # restore the original env attributes (FIXME)
+ objBuilder.env = objBuilderEnv
+ env.Moc.env = mocBuilderEnv
+
+ return (target, out_sources)
+
+AutomocShared = _Automoc('SharedObject')
+AutomocStatic = _Automoc('StaticObject')
+
+def _detect(env):
+ """Not really safe, but fast method to detect the QT library"""
+ QTDIR = None
+ if not QTDIR:
+ QTDIR = env.get('QTDIR',None)
+ if not QTDIR:
+ QTDIR = os.environ.get('QTDIR',None)
+ if not QTDIR:
+ moc = env.WhereIs('moc')
+ if moc:
+ QTDIR = os.path.dirname(os.path.dirname(moc))
+ SCons.Warnings.warn(
+ QtdirNotFound,
+ "Could not detect qt, using moc executable as a hint (QTDIR=%s)" % QTDIR)
+ else:
+ QTDIR = None
+ SCons.Warnings.warn(
+ QtdirNotFound,
+ "Could not detect qt, using empty QTDIR")
+ return QTDIR
+
+def uicEmitter(target, source, env):
+ adjustixes = SCons.Util.adjustixes
+ bs = SCons.Util.splitext(str(source[0].name))[0]
+ bs = os.path.join(str(target[0].get_dir()),bs)
+ # first target (header) is automatically added by builder
+ if len(target) < 2:
+ # second target is implementation
+ target.append(adjustixes(bs,
+ env.subst('$QT_UICIMPLPREFIX'),
+ env.subst('$QT_UICIMPLSUFFIX')))
+ if len(target) < 3:
+ # third target is moc file
+ target.append(adjustixes(bs,
+ env.subst('$QT_MOCHPREFIX'),
+ env.subst('$QT_MOCHSUFFIX')))
+ return target, source
+
+def uicScannerFunc(node, env, path):
+ lookout = []
+ lookout.extend(env['CPPPATH'])
+ lookout.append(str(node.rfile().dir))
+ includes = re.findall("<include.*?>(.*?)</include>", node.get_text_contents())
+ result = []
+ for incFile in includes:
+ dep = env.FindFile(incFile,lookout)
+ if dep:
+ result.append(dep)
+ return result
+
+uicScanner = SCons.Scanner.Base(uicScannerFunc,
+ name = "UicScanner",
+ node_class = SCons.Node.FS.File,
+ node_factory = SCons.Node.FS.File,
+ recursive = 0)
+
+def generate(env):
+ """Add Builders and construction variables for qt to an Environment."""
+ CLVar = SCons.Util.CLVar
+ Action = SCons.Action.Action
+ Builder = SCons.Builder.Builder
+
+ env.SetDefault(QTDIR = _detect(env),
+ QT_BINPATH = os.path.join('$QTDIR', 'bin'),
+ QT_CPPPATH = os.path.join('$QTDIR', 'include'),
+ QT_LIBPATH = os.path.join('$QTDIR', 'lib'),
+ QT_MOC = os.path.join('$QT_BINPATH','moc'),
+ QT_UIC = os.path.join('$QT_BINPATH','uic'),
+ QT_LIB = 'qt', # may be set to qt-mt
+
+ QT_AUTOSCAN = 1, # scan for moc'able sources
+
+ # Some QT specific flags. I don't expect someone wants to
+ # manipulate those ...
+ QT_UICIMPLFLAGS = CLVar(''),
+ QT_UICDECLFLAGS = CLVar(''),
+ QT_MOCFROMHFLAGS = CLVar(''),
+ QT_MOCFROMCXXFLAGS = CLVar('-i'),
+
+ # suffixes/prefixes for the headers / sources to generate
+ QT_UICDECLPREFIX = '',
+ QT_UICDECLSUFFIX = '.h',
+ QT_UICIMPLPREFIX = 'uic_',
+ QT_UICIMPLSUFFIX = '$CXXFILESUFFIX',
+ QT_MOCHPREFIX = 'moc_',
+ QT_MOCHSUFFIX = '$CXXFILESUFFIX',
+ QT_MOCCXXPREFIX = '',
+ QT_MOCCXXSUFFIX = '.moc',
+ QT_UISUFFIX = '.ui',
+
+ # Commands for the qt support ...
+ # command to generate header, implementation and moc-file
+ # from a .ui file
+ QT_UICCOM = [
+ CLVar('$QT_UIC $QT_UICDECLFLAGS -o ${TARGETS[0]} $SOURCE'),
+ CLVar('$QT_UIC $QT_UICIMPLFLAGS -impl ${TARGETS[0].file} '
+ '-o ${TARGETS[1]} $SOURCE'),
+ CLVar('$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[2]} ${TARGETS[0]}')],
+ # command to generate meta object information for a class
+ # declarated in a header
+ QT_MOCFROMHCOM = (
+ '$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[0]} $SOURCE'),
+ # command to generate meta object information for a class
+ # declarated in a cpp file
+ QT_MOCFROMCXXCOM = [
+ CLVar('$QT_MOC $QT_MOCFROMCXXFLAGS -o ${TARGETS[0]} $SOURCE'),
+ Action(checkMocIncluded,None)])
+
+ # ... and the corresponding builders
+ uicBld = Builder(action=SCons.Action.Action('$QT_UICCOM', '$QT_UICCOMSTR'),
+ emitter=uicEmitter,
+ src_suffix='$QT_UISUFFIX',
+ suffix='$QT_UICDECLSUFFIX',
+ prefix='$QT_UICDECLPREFIX',
+ source_scanner=uicScanner)
+ mocBld = Builder(action={}, prefix={}, suffix={})
+ for h in header_extensions:
+ act = SCons.Action.Action('$QT_MOCFROMHCOM', '$QT_MOCFROMHCOMSTR')
+ mocBld.add_action(h, act)
+ mocBld.prefix[h] = '$QT_MOCHPREFIX'
+ mocBld.suffix[h] = '$QT_MOCHSUFFIX'
+ for cxx in cxx_suffixes:
+ act = SCons.Action.Action('$QT_MOCFROMCXXCOM', '$QT_MOCFROMCXXCOMSTR')
+ mocBld.add_action(cxx, act)
+ mocBld.prefix[cxx] = '$QT_MOCCXXPREFIX'
+ mocBld.suffix[cxx] = '$QT_MOCCXXSUFFIX'
+
+ # register the builders
+ env['BUILDERS']['Uic'] = uicBld
+ env['BUILDERS']['Moc'] = mocBld
+ static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
+ static_obj.add_src_builder('Uic')
+ shared_obj.add_src_builder('Uic')
+
+ # We use the emitters of Program / StaticLibrary / SharedLibrary
+ # to scan for moc'able files
+ # We can't refer to the builders directly, we have to fetch them
+ # as Environment attributes because that sets them up to be called
+ # correctly later by our emitter.
+ env.AppendUnique(PROGEMITTER =[AutomocStatic],
+ SHLIBEMITTER=[AutomocShared],
+ LIBEMITTER =[AutomocStatic],
+ # Of course, we need to link against the qt libraries
+ CPPPATH=["$QT_CPPPATH"],
+ LIBPATH=["$QT_LIBPATH"],
+ LIBS=['$QT_LIB'])
+
+def exists(env):
+ return _detect(env)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/rmic.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/rmic.py
new file mode 100644
index 00000000..92623361
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/rmic.py
@@ -0,0 +1,120 @@
+"""SCons.Tool.rmic
+
+Tool-specific initialization for rmic.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/rmic.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+
+import SCons.Action
+import SCons.Builder
+import SCons.Node.FS
+import SCons.Util
+
+def emit_rmic_classes(target, source, env):
+ """Create and return lists of Java RMI stub and skeleton
+ class files to be created from a set of class files.
+ """
+ class_suffix = env.get('JAVACLASSSUFFIX', '.class')
+ classdir = env.get('JAVACLASSDIR')
+
+ if not classdir:
+ try:
+ s = source[0]
+ except IndexError:
+ classdir = '.'
+ else:
+ try:
+ classdir = s.attributes.java_classdir
+ except AttributeError:
+ classdir = '.'
+ classdir = env.Dir(classdir).rdir()
+ if str(classdir) == '.':
+ c_ = None
+ else:
+ c_ = str(classdir) + os.sep
+
+ slist = []
+ for src in source:
+ try:
+ classname = src.attributes.java_classname
+ except AttributeError:
+ classname = str(src)
+ if c_ and classname[:len(c_)] == c_:
+ classname = classname[len(c_):]
+ if class_suffix and classname[:-len(class_suffix)] == class_suffix:
+ classname = classname[-len(class_suffix):]
+ s = src.rfile()
+ s.attributes.java_classdir = classdir
+ s.attributes.java_classname = classname
+ slist.append(s)
+
+ stub_suffixes = ['_Stub']
+ if env.get('JAVAVERSION') == '1.4':
+ stub_suffixes.append('_Skel')
+
+ tlist = []
+ for s in source:
+ for suff in stub_suffixes:
+ fname = s.attributes.java_classname.replace('.', os.sep) + \
+ suff + class_suffix
+ t = target[0].File(fname)
+ t.attributes.java_lookupdir = target[0]
+ tlist.append(t)
+
+ return tlist, source
+
+RMICAction = SCons.Action.Action('$RMICCOM', '$RMICCOMSTR')
+
+RMICBuilder = SCons.Builder.Builder(action = RMICAction,
+ emitter = emit_rmic_classes,
+ src_suffix = '$JAVACLASSSUFFIX',
+ target_factory = SCons.Node.FS.Dir,
+ source_factory = SCons.Node.FS.File)
+
+def generate(env):
+ """Add Builders and construction variables for rmic to an Environment."""
+ env['BUILDERS']['RMIC'] = RMICBuilder
+
+ env['RMIC'] = 'rmic'
+ env['RMICFLAGS'] = SCons.Util.CLVar('')
+ env['RMICCOM'] = '$RMIC $RMICFLAGS -d ${TARGET.attributes.java_lookupdir} -classpath ${SOURCE.attributes.java_classdir} ${SOURCES.attributes.java_classname}'
+ env['JAVACLASSSUFFIX'] = '.class'
+
+def exists(env):
+ return env.Detect('rmic')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/rpcgen.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/rpcgen.py
new file mode 100644
index 00000000..46f12097
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/rpcgen.py
@@ -0,0 +1,70 @@
+"""SCons.Tool.rpcgen
+
+Tool-specific initialization for RPCGEN tools.
+
+Three normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/rpcgen.py 5134 2010/08/16 23:02:40 bdeegan"
+
+from SCons.Builder import Builder
+import SCons.Util
+
+cmd = "cd ${SOURCE.dir} && $RPCGEN -%s $RPCGENFLAGS %s -o ${TARGET.abspath} ${SOURCE.file}"
+
+rpcgen_client = cmd % ('l', '$RPCGENCLIENTFLAGS')
+rpcgen_header = cmd % ('h', '$RPCGENHEADERFLAGS')
+rpcgen_service = cmd % ('m', '$RPCGENSERVICEFLAGS')
+rpcgen_xdr = cmd % ('c', '$RPCGENXDRFLAGS')
+
+def generate(env):
+ "Add RPCGEN Builders and construction variables for an Environment."
+
+ client = Builder(action=rpcgen_client, suffix='_clnt.c', src_suffix='.x')
+ header = Builder(action=rpcgen_header, suffix='.h', src_suffix='.x')
+ service = Builder(action=rpcgen_service, suffix='_svc.c', src_suffix='.x')
+ xdr = Builder(action=rpcgen_xdr, suffix='_xdr.c', src_suffix='.x')
+ env.Append(BUILDERS={'RPCGenClient' : client,
+ 'RPCGenHeader' : header,
+ 'RPCGenService' : service,
+ 'RPCGenXDR' : xdr})
+ env['RPCGEN'] = 'rpcgen'
+ env['RPCGENFLAGS'] = SCons.Util.CLVar('')
+ env['RPCGENCLIENTFLAGS'] = SCons.Util.CLVar('')
+ env['RPCGENHEADERFLAGS'] = SCons.Util.CLVar('')
+ env['RPCGENSERVICEFLAGS'] = SCons.Util.CLVar('')
+ env['RPCGENXDRFLAGS'] = SCons.Util.CLVar('')
+
+def exists(env):
+ return env.Detect('rpcgen')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/rpm.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/rpm.py
new file mode 100644
index 00000000..d9a661a6
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/rpm.py
@@ -0,0 +1,132 @@
+"""SCons.Tool.rpm
+
+Tool-specific initialization for rpm.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+The rpm tool calls the rpmbuild command. The first and only argument should a
+tar.gz consisting of the source file and a specfile.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/rpm.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+import re
+import shutil
+import subprocess
+
+import SCons.Builder
+import SCons.Node.FS
+import SCons.Util
+import SCons.Action
+import SCons.Defaults
+
+def get_cmd(source, env):
+ tar_file_with_included_specfile = source
+ if SCons.Util.is_List(source):
+ tar_file_with_included_specfile = source[0]
+ return "%s %s %s"%(env['RPM'], env['RPMFLAGS'],
+ tar_file_with_included_specfile.abspath )
+
+def build_rpm(target, source, env):
+ # create a temporary rpm build root.
+ tmpdir = os.path.join( os.path.dirname( target[0].abspath ), 'rpmtemp' )
+ if os.path.exists(tmpdir):
+ shutil.rmtree(tmpdir)
+
+ # now create the mandatory rpm directory structure.
+ for d in ['RPMS', 'SRPMS', 'SPECS', 'BUILD']:
+ os.makedirs( os.path.join( tmpdir, d ) )
+
+ # set the topdir as an rpmflag.
+ env.Prepend( RPMFLAGS = '--define \'_topdir %s\'' % tmpdir )
+
+ # now call rpmbuild to create the rpm package.
+ handle = subprocess.Popen(get_cmd(source, env),
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ shell=True)
+ output = handle.stdout.read()
+ status = handle.wait()
+
+ if status:
+ raise SCons.Errors.BuildError( node=target[0],
+ errstr=output,
+ filename=str(target[0]) )
+ else:
+ # XXX: assume that LC_ALL=c is set while running rpmbuild
+ output_files = re.compile( 'Wrote: (.*)' ).findall( output )
+
+ for output, input in zip( output_files, target ):
+ rpm_output = os.path.basename(output)
+ expected = os.path.basename(input.get_path())
+
+ assert expected == rpm_output, "got %s but expected %s" % (rpm_output, expected)
+ shutil.copy( output, input.abspath )
+
+
+ # cleanup before leaving.
+ shutil.rmtree(tmpdir)
+
+ return status
+
+def string_rpm(target, source, env):
+ try:
+ return env['RPMCOMSTR']
+ except KeyError:
+ return get_cmd(source, env)
+
+rpmAction = SCons.Action.Action(build_rpm, string_rpm)
+
+RpmBuilder = SCons.Builder.Builder(action = SCons.Action.Action('$RPMCOM', '$RPMCOMSTR'),
+ source_scanner = SCons.Defaults.DirScanner,
+ suffix = '$RPMSUFFIX')
+
+
+
+def generate(env):
+ """Add Builders and construction variables for rpm to an Environment."""
+ try:
+ bld = env['BUILDERS']['Rpm']
+ except KeyError:
+ bld = RpmBuilder
+ env['BUILDERS']['Rpm'] = bld
+
+ env.SetDefault(RPM = 'LC_ALL=c rpmbuild')
+ env.SetDefault(RPMFLAGS = SCons.Util.CLVar('-ta'))
+ env.SetDefault(RPMCOM = rpmAction)
+ env.SetDefault(RPMSUFFIX = '.rpm')
+
+def exists(env):
+ return env.Detect('rpmbuild')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/sgiar.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sgiar.py
new file mode 100644
index 00000000..b56de2b9
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sgiar.py
@@ -0,0 +1,68 @@
+"""SCons.Tool.sgiar
+
+Tool-specific initialization for SGI ar (library archive). If CC
+exists, static libraries should be built with it, so the prelinker has
+a chance to resolve C++ template instantiations.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/sgiar.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Defaults
+import SCons.Tool
+import SCons.Util
+
+def generate(env):
+ """Add Builders and construction variables for ar to an Environment."""
+ SCons.Tool.createStaticLibBuilder(env)
+
+ if env.Detect('CC'):
+ env['AR'] = 'CC'
+ env['ARFLAGS'] = SCons.Util.CLVar('-ar')
+ env['ARCOM'] = '$AR $ARFLAGS -o $TARGET $SOURCES'
+ else:
+ env['AR'] = 'ar'
+ env['ARFLAGS'] = SCons.Util.CLVar('r')
+ env['ARCOM'] = '$AR $ARFLAGS $TARGET $SOURCES'
+
+ env['SHLINK'] = '$LINK'
+ env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared')
+ env['SHLINKCOM'] = '$SHLINK $SHLINKFLAGS -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS'
+ env['LIBPREFIX'] = 'lib'
+ env['LIBSUFFIX'] = '.a'
+
+def exists(env):
+ return env.Detect('CC') or env.Detect('ar')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/sgic++.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sgic++.py
new file mode 100644
index 00000000..45c64cf0
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sgic++.py
@@ -0,0 +1,58 @@
+"""SCons.Tool.sgic++
+
+Tool-specific initialization for MIPSpro C++ on SGI.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/sgic++.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Util
+
+cplusplus = __import__('c++', globals(), locals(), [])
+
+def generate(env):
+ """Add Builders and construction variables for SGI MIPS C++ to an Environment."""
+
+ cplusplus.generate(env)
+
+ env['CXX'] = 'CC'
+ env['CXXFLAGS'] = SCons.Util.CLVar('-LANG:std')
+ env['SHCXX'] = '$CXX'
+ env['SHOBJSUFFIX'] = '.o'
+ env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
+
+def exists(env):
+ return env.Detect('CC')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/sgicc.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sgicc.py
new file mode 100644
index 00000000..27f83175
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sgicc.py
@@ -0,0 +1,53 @@
+"""SCons.Tool.sgicc
+
+Tool-specific initialization for MIPSPro cc on SGI.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/sgicc.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import cc
+
+def generate(env):
+ """Add Builders and construction variables for gcc to an Environment."""
+ cc.generate(env)
+
+ env['CXX'] = 'CC'
+ env['SHOBJSUFFIX'] = '.o'
+ env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
+
+def exists(env):
+ return env.Detect('cc')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/sgilink.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sgilink.py
new file mode 100644
index 00000000..7aef1fe9
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sgilink.py
@@ -0,0 +1,63 @@
+"""SCons.Tool.sgilink
+
+Tool-specific initialization for the SGI MIPSPro linker on SGI.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/sgilink.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Util
+
+import link
+
+linkers = ['CC', 'cc']
+
+def generate(env):
+ """Add Builders and construction variables for MIPSPro to an Environment."""
+ link.generate(env)
+
+ env['LINK'] = env.Detect(linkers) or 'cc'
+ env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared')
+
+ # __RPATH is set to $_RPATH in the platform specification if that
+ # platform supports it.
+ env.Append(LINKFLAGS=['$__RPATH'])
+ env['RPATHPREFIX'] = '-rpath '
+ env['RPATHSUFFIX'] = ''
+ env['_RPATH'] = '${_concat(RPATHPREFIX, RPATH, RPATHSUFFIX, __env__)}'
+
+def exists(env):
+ return env.Detect(linkers)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/sunar.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sunar.py
new file mode 100644
index 00000000..30e5dd6f
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sunar.py
@@ -0,0 +1,67 @@
+"""engine.SCons.Tool.sunar
+
+Tool-specific initialization for Solaris (Forte) ar (library archive). If CC
+exists, static libraries should be built with it, so that template
+instantians can be resolved.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/sunar.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Defaults
+import SCons.Tool
+import SCons.Util
+
+def generate(env):
+ """Add Builders and construction variables for ar to an Environment."""
+ SCons.Tool.createStaticLibBuilder(env)
+
+ if env.Detect('CC'):
+ env['AR'] = 'CC'
+ env['ARFLAGS'] = SCons.Util.CLVar('-xar')
+ env['ARCOM'] = '$AR $ARFLAGS -o $TARGET $SOURCES'
+ else:
+ env['AR'] = 'ar'
+ env['ARFLAGS'] = SCons.Util.CLVar('r')
+ env['ARCOM'] = '$AR $ARFLAGS $TARGET $SOURCES'
+
+ env['SHLINK'] = '$LINK'
+ env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -G')
+ env['SHLINKCOM'] = '$SHLINK $SHLINKFLAGS -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS'
+ env['LIBPREFIX'] = 'lib'
+ env['LIBSUFFIX'] = '.a'
+
+def exists(env):
+ return env.Detect('CC') or env.Detect('ar')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/sunc++.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sunc++.py
new file mode 100644
index 00000000..d127e161
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sunc++.py
@@ -0,0 +1,142 @@
+"""SCons.Tool.sunc++
+
+Tool-specific initialization for C++ on SunOS / Solaris.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/sunc++.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons
+
+import os
+import re
+import subprocess
+
+cplusplus = __import__('c++', globals(), locals(), [])
+
+package_info = {}
+
+def get_package_info(package_name, pkginfo, pkgchk):
+ try:
+ return package_info[package_name]
+ except KeyError:
+ version = None
+ pathname = None
+ try:
+ sadm_contents = open('/var/sadm/install/contents', 'r').read()
+ except EnvironmentError:
+ pass
+ else:
+ sadm_re = re.compile('^(\S*/bin/CC)(=\S*)? %s$' % package_name, re.M)
+ sadm_match = sadm_re.search(sadm_contents)
+ if sadm_match:
+ pathname = os.path.dirname(sadm_match.group(1))
+
+ try:
+ p = subprocess.Popen([pkginfo, '-l', package_name],
+ stdout=subprocess.PIPE,
+ stderr=open('/dev/null', 'w'))
+ except EnvironmentError:
+ pass
+ else:
+ pkginfo_contents = p.communicate()[0]
+ version_re = re.compile('^ *VERSION:\s*(.*)$', re.M)
+ version_match = version_re.search(pkginfo_contents)
+ if version_match:
+ version = version_match.group(1)
+
+ if pathname is None:
+ try:
+ p = subprocess.Popen([pkgchk, '-l', package_name],
+ stdout=subprocess.PIPE,
+ stderr=open('/dev/null', 'w'))
+ except EnvironmentError:
+ pass
+ else:
+ pkgchk_contents = p.communicate()[0]
+ pathname_re = re.compile(r'^Pathname:\s*(.*/bin/CC)$', re.M)
+ pathname_match = pathname_re.search(pkgchk_contents)
+ if pathname_match:
+ pathname = os.path.dirname(pathname_match.group(1))
+
+ package_info[package_name] = (pathname, version)
+ return package_info[package_name]
+
+# use the package installer tool lslpp to figure out where cppc and what
+# version of it is installed
+def get_cppc(env):
+ cxx = env.subst('$CXX')
+ if cxx:
+ cppcPath = os.path.dirname(cxx)
+ else:
+ cppcPath = None
+
+ cppcVersion = None
+
+ pkginfo = env.subst('$PKGINFO')
+ pkgchk = env.subst('$PKGCHK')
+
+ for package in ['SPROcpl']:
+ path, version = get_package_info(package, pkginfo, pkgchk)
+ if path and version:
+ cppcPath, cppcVersion = path, version
+ break
+
+ return (cppcPath, 'CC', 'CC', cppcVersion)
+
+def generate(env):
+ """Add Builders and construction variables for SunPRO C++."""
+ path, cxx, shcxx, version = get_cppc(env)
+ if path:
+ cxx = os.path.join(path, cxx)
+ shcxx = os.path.join(path, shcxx)
+
+ cplusplus.generate(env)
+
+ env['CXX'] = cxx
+ env['SHCXX'] = shcxx
+ env['CXXVERSION'] = version
+ env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS -KPIC')
+ env['SHOBJPREFIX'] = 'so_'
+ env['SHOBJSUFFIX'] = '.o'
+
+def exists(env):
+ path, cxx, shcxx, version = get_cppc(env)
+ if path and cxx:
+ cppc = os.path.join(path, cxx)
+ if os.path.exists(cppc):
+ return cppc
+ return None
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/suncc.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/suncc.py
new file mode 100644
index 00000000..14898c74
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/suncc.py
@@ -0,0 +1,58 @@
+"""SCons.Tool.suncc
+
+Tool-specific initialization for Sun Solaris (Forte) CC and cc.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/suncc.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Util
+
+import cc
+
+def generate(env):
+ """
+ Add Builders and construction variables for Forte C and C++ compilers
+ to an Environment.
+ """
+ cc.generate(env)
+
+ env['CXX'] = 'CC'
+ env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS -KPIC')
+ env['SHOBJPREFIX'] = 'so_'
+ env['SHOBJSUFFIX'] = '.o'
+
+def exists(env):
+ return env.Detect('CC')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/sunf77.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sunf77.py
new file mode 100644
index 00000000..499a3a73
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sunf77.py
@@ -0,0 +1,63 @@
+"""SCons.Tool.sunf77
+
+Tool-specific initialization for sunf77, the Sun Studio F77 compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/sunf77.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Util
+
+from FortranCommon import add_all_to_env
+
+compilers = ['sunf77', 'f77']
+
+def generate(env):
+ """Add Builders and construction variables for sunf77 to an Environment."""
+ add_all_to_env(env)
+
+ fcomp = env.Detect(compilers) or 'f77'
+ env['FORTRAN'] = fcomp
+ env['F77'] = fcomp
+
+ env['SHFORTRAN'] = '$FORTRAN'
+ env['SHF77'] = '$F77'
+
+ env['SHFORTRANFLAGS'] = SCons.Util.CLVar('$FORTRANFLAGS -KPIC')
+ env['SHF77FLAGS'] = SCons.Util.CLVar('$F77FLAGS -KPIC')
+
+def exists(env):
+ return env.Detect(compilers)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/sunf90.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sunf90.py
new file mode 100644
index 00000000..9fa91912
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sunf90.py
@@ -0,0 +1,64 @@
+"""SCons.Tool.sunf90
+
+Tool-specific initialization for sunf90, the Sun Studio F90 compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/sunf90.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Util
+
+from FortranCommon import add_all_to_env
+
+compilers = ['sunf90', 'f90']
+
+def generate(env):
+ """Add Builders and construction variables for sun f90 compiler to an
+ Environment."""
+ add_all_to_env(env)
+
+ fcomp = env.Detect(compilers) or 'f90'
+ env['FORTRAN'] = fcomp
+ env['F90'] = fcomp
+
+ env['SHFORTRAN'] = '$FORTRAN'
+ env['SHF90'] = '$F90'
+
+ env['SHFORTRANFLAGS'] = SCons.Util.CLVar('$FORTRANFLAGS -KPIC')
+ env['SHF90FLAGS'] = SCons.Util.CLVar('$F90FLAGS -KPIC')
+
+def exists(env):
+ return env.Detect(compilers)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/sunf95.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sunf95.py
new file mode 100644
index 00000000..13e5ef9d
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sunf95.py
@@ -0,0 +1,64 @@
+"""SCons.Tool.sunf95
+
+Tool-specific initialization for sunf95, the Sun Studio F95 compiler.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/sunf95.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Util
+
+from FortranCommon import add_all_to_env
+
+compilers = ['sunf95', 'f95']
+
+def generate(env):
+ """Add Builders and construction variables for sunf95 to an
+ Environment."""
+ add_all_to_env(env)
+
+ fcomp = env.Detect(compilers) or 'f95'
+ env['FORTRAN'] = fcomp
+ env['F95'] = fcomp
+
+ env['SHFORTRAN'] = '$FORTRAN'
+ env['SHF95'] = '$F95'
+
+ env['SHFORTRANFLAGS'] = SCons.Util.CLVar('$FORTRANFLAGS -KPIC')
+ env['SHF95FLAGS'] = SCons.Util.CLVar('$F95FLAGS -KPIC')
+
+def exists(env):
+ return env.Detect(compilers)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/sunlink.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sunlink.py
new file mode 100644
index 00000000..502008de
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/sunlink.py
@@ -0,0 +1,77 @@
+"""SCons.Tool.sunlink
+
+Tool-specific initialization for the Sun Solaris (Forte) linker.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/sunlink.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+import os.path
+
+import SCons.Util
+
+import link
+
+ccLinker = None
+
+# search for the acc compiler and linker front end
+
+try:
+ dirs = os.listdir('/opt')
+except (IOError, OSError):
+ # Not being able to read the directory because it doesn't exist
+ # (IOError) or isn't readable (OSError) is okay.
+ dirs = []
+
+for d in dirs:
+ linker = '/opt/' + d + '/bin/CC'
+ if os.path.exists(linker):
+ ccLinker = linker
+ break
+
+def generate(env):
+ """Add Builders and construction variables for Forte to an Environment."""
+ link.generate(env)
+
+ env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -G')
+
+ env.Append(LINKFLAGS=['$__RPATH'])
+ env['RPATHPREFIX'] = '-R'
+ env['RPATHSUFFIX'] = ''
+ env['_RPATH'] = '${_concat(RPATHPREFIX, RPATH, RPATHSUFFIX, __env__)}'
+
+def exists(env):
+ return ccLinker
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/swig.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/swig.py
new file mode 100644
index 00000000..d02bbe8c
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/swig.py
@@ -0,0 +1,182 @@
+"""SCons.Tool.swig
+
+Tool-specific initialization for swig.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/swig.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+import re
+import subprocess
+
+import SCons.Action
+import SCons.Defaults
+import SCons.Scanner
+import SCons.Tool
+import SCons.Util
+
+SwigAction = SCons.Action.Action('$SWIGCOM', '$SWIGCOMSTR')
+
+def swigSuffixEmitter(env, source):
+ if '-c++' in SCons.Util.CLVar(env.subst("$SWIGFLAGS", source=source)):
+ return '$SWIGCXXFILESUFFIX'
+ else:
+ return '$SWIGCFILESUFFIX'
+
+# Match '%module test', as well as '%module(directors="1") test'
+# Also allow for test to be quoted (SWIG permits double quotes, but not single)
+_reModule = re.compile(r'%module(\s*\(.*\))?\s+("?)(.+)\2')
+
+def _find_modules(src):
+ """Find all modules referenced by %module lines in `src`, a SWIG .i file.
+ Returns a list of all modules, and a flag set if SWIG directors have
+ been requested (SWIG will generate an additional header file in this
+ case.)"""
+ directors = 0
+ mnames = []
+ try:
+ matches = _reModule.findall(open(src).read())
+ except IOError:
+ # If the file's not yet generated, guess the module name from the filename
+ matches = []
+ mnames.append(os.path.splitext(src)[0])
+
+ for m in matches:
+ mnames.append(m[2])
+ directors = directors or m[0].find('directors') >= 0
+ return mnames, directors
+
+def _add_director_header_targets(target, env):
+ # Directors only work with C++ code, not C
+ suffix = env.subst(env['SWIGCXXFILESUFFIX'])
+ # For each file ending in SWIGCXXFILESUFFIX, add a new target director
+ # header by replacing the ending with SWIGDIRECTORSUFFIX.
+ for x in target[:]:
+ n = x.name
+ d = x.dir
+ if n[-len(suffix):] == suffix:
+ target.append(d.File(n[:-len(suffix)] + env['SWIGDIRECTORSUFFIX']))
+
+def _swigEmitter(target, source, env):
+ swigflags = env.subst("$SWIGFLAGS", target=target, source=source)
+ flags = SCons.Util.CLVar(swigflags)
+ for src in source:
+ src = str(src.rfile())
+ mnames = None
+ if "-python" in flags and "-noproxy" not in flags:
+ if mnames is None:
+ mnames, directors = _find_modules(src)
+ if directors:
+ _add_director_header_targets(target, env)
+ python_files = [m + ".py" for m in mnames]
+ outdir = env.subst('$SWIGOUTDIR', target=target, source=source)
+ # .py files should be generated in SWIGOUTDIR if specified,
+ # otherwise in the same directory as the target
+ if outdir:
+ python_files = [env.fs.File(os.path.join(outdir, j)) for j in python_files]
+ else:
+ python_files = [target[0].dir.File(m) for m in python_files]
+ target.extend(python_files)
+ if "-java" in flags:
+ if mnames is None:
+ mnames, directors = _find_modules(src)
+ if directors:
+ _add_director_header_targets(target, env)
+ java_files = [[m + ".java", m + "JNI.java"] for m in mnames]
+ java_files = SCons.Util.flatten(java_files)
+ outdir = env.subst('$SWIGOUTDIR', target=target, source=source)
+ if outdir:
+ java_files = [os.path.join(outdir, j) for j in java_files]
+ java_files = list(map(env.fs.File, java_files))
+ for jf in java_files:
+ t_from_s = lambda t, p, s, x: t.dir
+ SCons.Util.AddMethod(jf, t_from_s, 'target_from_source')
+ target.extend(java_files)
+ return (target, source)
+
+def _get_swig_version(env):
+ """Run the SWIG command line tool to get and return the version number"""
+ pipe = SCons.Action._subproc(env, [env['SWIG'], '-version'],
+ stdin = 'devnull',
+ stderr = 'devnull',
+ stdout = subprocess.PIPE)
+ if pipe.wait() != 0: return
+
+ out = pipe.stdout.read()
+ match = re.search(r'SWIG Version\s+(\S+)$', out, re.MULTILINE)
+ if match:
+ return match.group(1)
+
+def generate(env):
+ """Add Builders and construction variables for swig to an Environment."""
+ c_file, cxx_file = SCons.Tool.createCFileBuilders(env)
+
+ c_file.suffix['.i'] = swigSuffixEmitter
+ cxx_file.suffix['.i'] = swigSuffixEmitter
+
+ c_file.add_action('.i', SwigAction)
+ c_file.add_emitter('.i', _swigEmitter)
+ cxx_file.add_action('.i', SwigAction)
+ cxx_file.add_emitter('.i', _swigEmitter)
+
+ java_file = SCons.Tool.CreateJavaFileBuilder(env)
+
+ java_file.suffix['.i'] = swigSuffixEmitter
+
+ java_file.add_action('.i', SwigAction)
+ java_file.add_emitter('.i', _swigEmitter)
+
+ env['SWIG'] = 'swig'
+ env['SWIGVERSION'] = _get_swig_version(env)
+ env['SWIGFLAGS'] = SCons.Util.CLVar('')
+ env['SWIGDIRECTORSUFFIX'] = '_wrap.h'
+ env['SWIGCFILESUFFIX'] = '_wrap$CFILESUFFIX'
+ env['SWIGCXXFILESUFFIX'] = '_wrap$CXXFILESUFFIX'
+ env['_SWIGOUTDIR'] = r'${"-outdir \"%s\"" % SWIGOUTDIR}'
+ env['SWIGPATH'] = []
+ env['SWIGINCPREFIX'] = '-I'
+ env['SWIGINCSUFFIX'] = ''
+ env['_SWIGINCFLAGS'] = '$( ${_concat(SWIGINCPREFIX, SWIGPATH, SWIGINCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
+ env['SWIGCOM'] = '$SWIG -o $TARGET ${_SWIGOUTDIR} ${_SWIGINCFLAGS} $SWIGFLAGS $SOURCES'
+
+ expr = '^[ \t]*%[ \t]*(?:include|import|extern)[ \t]*(<|"?)([^>\s"]+)(?:>|"?)'
+ scanner = SCons.Scanner.ClassicCPP("SWIGScan", ".i", "SWIGPATH", expr)
+
+ env.Append(SCANNERS = scanner)
+
+def exists(env):
+ return env.Detect(['swig'])
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/tar.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/tar.py
new file mode 100644
index 00000000..55a405b2
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/tar.py
@@ -0,0 +1,73 @@
+"""SCons.Tool.tar
+
+Tool-specific initialization for tar.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/tar.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Action
+import SCons.Builder
+import SCons.Defaults
+import SCons.Node.FS
+import SCons.Util
+
+tars = ['tar', 'gtar']
+
+TarAction = SCons.Action.Action('$TARCOM', '$TARCOMSTR')
+
+TarBuilder = SCons.Builder.Builder(action = TarAction,
+ source_factory = SCons.Node.FS.Entry,
+ source_scanner = SCons.Defaults.DirScanner,
+ suffix = '$TARSUFFIX',
+ multi = 1)
+
+
+def generate(env):
+ """Add Builders and construction variables for tar to an Environment."""
+ try:
+ bld = env['BUILDERS']['Tar']
+ except KeyError:
+ bld = TarBuilder
+ env['BUILDERS']['Tar'] = bld
+
+ env['TAR'] = env.Detect(tars) or 'gtar'
+ env['TARFLAGS'] = SCons.Util.CLVar('-c')
+ env['TARCOM'] = '$TAR $TARFLAGS -f $TARGET $SOURCES'
+ env['TARSUFFIX'] = '.tar'
+
+def exists(env):
+ return env.Detect(tars)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/tex.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/tex.py
new file mode 100644
index 00000000..23226db7
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/tex.py
@@ -0,0 +1,813 @@
+"""SCons.Tool.tex
+
+Tool-specific initialization for TeX.
+Generates .dvi files from .tex files
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/tex.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+import re
+import shutil
+import sys
+import platform
+
+import SCons.Action
+import SCons.Node
+import SCons.Node.FS
+import SCons.Util
+import SCons.Scanner.LaTeX
+
+Verbose = False
+
+must_rerun_latex = True
+
+# these are files that just need to be checked for changes and then rerun latex
+check_suffixes = ['.toc', '.lof', '.lot', '.out', '.nav', '.snm']
+
+# these are files that require bibtex or makeindex to be run when they change
+all_suffixes = check_suffixes + ['.bbl', '.idx', '.nlo', '.glo', '.acn']
+
+#
+# regular expressions used to search for Latex features
+# or outputs that require rerunning latex
+#
+# search for all .aux files opened by latex (recorded in the .fls file)
+openout_aux_re = re.compile(r"INPUT *(.*\.aux)")
+
+#printindex_re = re.compile(r"^[^%]*\\printindex", re.MULTILINE)
+#printnomenclature_re = re.compile(r"^[^%]*\\printnomenclature", re.MULTILINE)
+#printglossary_re = re.compile(r"^[^%]*\\printglossary", re.MULTILINE)
+
+# search to find rerun warnings
+warning_rerun_str = '(^LaTeX Warning:.*Rerun)|(^Package \w+ Warning:.*Rerun)'
+warning_rerun_re = re.compile(warning_rerun_str, re.MULTILINE)
+
+# search to find citation rerun warnings
+rerun_citations_str = "^LaTeX Warning:.*\n.*Rerun to get citations correct"
+rerun_citations_re = re.compile(rerun_citations_str, re.MULTILINE)
+
+# search to find undefined references or citations warnings
+undefined_references_str = '(^LaTeX Warning:.*undefined references)|(^Package \w+ Warning:.*undefined citations)'
+undefined_references_re = re.compile(undefined_references_str, re.MULTILINE)
+
+# used by the emitter
+auxfile_re = re.compile(r".", re.MULTILINE)
+tableofcontents_re = re.compile(r"^[^%\n]*\\tableofcontents", re.MULTILINE)
+makeindex_re = re.compile(r"^[^%\n]*\\makeindex", re.MULTILINE)
+bibliography_re = re.compile(r"^[^%\n]*\\bibliography", re.MULTILINE)
+listoffigures_re = re.compile(r"^[^%\n]*\\listoffigures", re.MULTILINE)
+listoftables_re = re.compile(r"^[^%\n]*\\listoftables", re.MULTILINE)
+hyperref_re = re.compile(r"^[^%\n]*\\usepackage.*\{hyperref\}", re.MULTILINE)
+makenomenclature_re = re.compile(r"^[^%\n]*\\makenomenclature", re.MULTILINE)
+makeglossary_re = re.compile(r"^[^%\n]*\\makeglossary", re.MULTILINE)
+makeglossaries_re = re.compile(r"^[^%\n]*\\makeglossaries", re.MULTILINE)
+makeacronyms_re = re.compile(r"^[^%\n]*\\makeglossaries", re.MULTILINE)
+beamer_re = re.compile(r"^[^%\n]*\\documentclass\{beamer\}", re.MULTILINE)
+
+# search to find all files included by Latex
+include_re = re.compile(r'^[^%\n]*\\(?:include|input){([^}]*)}', re.MULTILINE)
+includeOnly_re = re.compile(r'^[^%\n]*\\(?:include){([^}]*)}', re.MULTILINE)
+
+# search to find all graphics files included by Latex
+includegraphics_re = re.compile(r'^[^%\n]*\\(?:includegraphics(?:\[[^\]]+\])?){([^}]*)}', re.MULTILINE)
+
+# search to find all files opened by Latex (recorded in .log file)
+openout_re = re.compile(r"OUTPUT *(.*)")
+
+# list of graphics file extensions for TeX and LaTeX
+TexGraphics = SCons.Scanner.LaTeX.TexGraphics
+LatexGraphics = SCons.Scanner.LaTeX.LatexGraphics
+
+# An Action sufficient to build any generic tex file.
+TeXAction = None
+
+# An action to build a latex file. This action might be needed more
+# than once if we are dealing with labels and bibtex.
+LaTeXAction = None
+
+# An action to run BibTeX on a file.
+BibTeXAction = None
+
+# An action to run MakeIndex on a file.
+MakeIndexAction = None
+
+# An action to run MakeIndex (for nomencl) on a file.
+MakeNclAction = None
+
+# An action to run MakeIndex (for glossary) on a file.
+MakeGlossaryAction = None
+
+# An action to run MakeIndex (for acronyms) on a file.
+MakeAcronymsAction = None
+
+# Used as a return value of modify_env_var if the variable is not set.
+_null = SCons.Scanner.LaTeX._null
+
+modify_env_var = SCons.Scanner.LaTeX.modify_env_var
+
+def check_file_error_message(utility, filename='log'):
+ msg = '%s returned an error, check the %s file\n' % (utility, filename)
+ sys.stdout.write(msg)
+
+def FindFile(name,suffixes,paths,env,requireExt=False):
+ if requireExt:
+ name,ext = SCons.Util.splitext(name)
+ # if the user gave an extension use it.
+ if ext:
+ name = name + ext
+ if Verbose:
+ print " searching for '%s' with extensions: " % name,suffixes
+
+ for path in paths:
+ testName = os.path.join(path,name)
+ if Verbose:
+ print " look for '%s'" % testName
+ if os.path.exists(testName):
+ if Verbose:
+ print " found '%s'" % testName
+ return env.fs.File(testName)
+ else:
+ name_ext = SCons.Util.splitext(testName)[1]
+ if name_ext:
+ continue
+
+ # if no suffix try adding those passed in
+ for suffix in suffixes:
+ testNameExt = testName + suffix
+ if Verbose:
+ print " look for '%s'" % testNameExt
+
+ if os.path.exists(testNameExt):
+ if Verbose:
+ print " found '%s'" % testNameExt
+ return env.fs.File(testNameExt)
+ if Verbose:
+ print " did not find '%s'" % name
+ return None
+
+def InternalLaTeXAuxAction(XXXLaTeXAction, target = None, source= None, env=None):
+ """A builder for LaTeX files that checks the output in the aux file
+ and decides how many times to use LaTeXAction, and BibTeXAction."""
+
+ global must_rerun_latex
+
+ # This routine is called with two actions. In this file for DVI builds
+ # with LaTeXAction and from the pdflatex.py with PDFLaTeXAction
+ # set this up now for the case where the user requests a different extension
+ # for the target filename
+ if (XXXLaTeXAction == LaTeXAction):
+ callerSuffix = ".dvi"
+ else:
+ callerSuffix = env['PDFSUFFIX']
+
+ basename = SCons.Util.splitext(str(source[0]))[0]
+ basedir = os.path.split(str(source[0]))[0]
+ basefile = os.path.split(str(basename))[1]
+ abspath = os.path.abspath(basedir)
+
+ targetext = os.path.splitext(str(target[0]))[1]
+ targetdir = os.path.split(str(target[0]))[0]
+
+ saved_env = {}
+ for var in SCons.Scanner.LaTeX.LaTeX.env_variables:
+ saved_env[var] = modify_env_var(env, var, abspath)
+
+ # Create base file names with the target directory since the auxiliary files
+ # will be made there. That's because the *COM variables have the cd
+ # command in the prolog. We check
+ # for the existence of files before opening them--even ones like the
+ # aux file that TeX always creates--to make it possible to write tests
+ # with stubs that don't necessarily generate all of the same files.
+
+ targetbase = os.path.join(targetdir, basefile)
+
+ # if there is a \makeindex there will be a .idx and thus
+ # we have to run makeindex at least once to keep the build
+ # happy even if there is no index.
+ # Same for glossaries and nomenclature
+ src_content = source[0].get_text_contents()
+ run_makeindex = makeindex_re.search(src_content) and not os.path.exists(targetbase + '.idx')
+ run_nomenclature = makenomenclature_re.search(src_content) and not os.path.exists(targetbase + '.nlo')
+ run_glossary = makeglossary_re.search(src_content) and not os.path.exists(targetbase + '.glo')
+ run_glossaries = makeglossaries_re.search(src_content) and not os.path.exists(targetbase + '.glo')
+ run_acronyms = makeacronyms_re.search(src_content) and not os.path.exists(targetbase + '.acn')
+
+ saved_hashes = {}
+ suffix_nodes = {}
+
+ for suffix in all_suffixes:
+ theNode = env.fs.File(targetbase + suffix)
+ suffix_nodes[suffix] = theNode
+ saved_hashes[suffix] = theNode.get_csig()
+
+ if Verbose:
+ print "hashes: ",saved_hashes
+
+ must_rerun_latex = True
+
+ #
+ # routine to update MD5 hash and compare
+ #
+ def check_MD5(filenode, suffix):
+ global must_rerun_latex
+ # two calls to clear old csig
+ filenode.clear_memoized_values()
+ filenode.ninfo = filenode.new_ninfo()
+ new_md5 = filenode.get_csig()
+
+ if saved_hashes[suffix] == new_md5:
+ if Verbose:
+ print "file %s not changed" % (targetbase+suffix)
+ return False # unchanged
+ saved_hashes[suffix] = new_md5
+ must_rerun_latex = True
+ if Verbose:
+ print "file %s changed, rerunning Latex, new hash = " % (targetbase+suffix), new_md5
+ return True # changed
+
+ # generate the file name that latex will generate
+ resultfilename = targetbase + callerSuffix
+
+ count = 0
+
+ while (must_rerun_latex and count < int(env.subst('$LATEXRETRIES'))) :
+ result = XXXLaTeXAction(target, source, env)
+ if result != 0:
+ return result
+
+ count = count + 1
+
+ must_rerun_latex = False
+ # Decide if various things need to be run, or run again.
+
+ # Read the log file to find warnings/errors
+ logfilename = targetbase + '.log'
+ logContent = ''
+ if os.path.exists(logfilename):
+ logContent = open(logfilename, "rb").read()
+
+
+ # Read the fls file to find all .aux files
+ flsfilename = targetbase + '.fls'
+ flsContent = ''
+ auxfiles = []
+ if os.path.exists(flsfilename):
+ flsContent = open(flsfilename, "rb").read()
+ auxfiles = openout_aux_re.findall(flsContent)
+ if Verbose:
+ print "auxfiles ",auxfiles
+
+ # Now decide if bibtex will need to be run.
+ # The information that bibtex reads from the .aux file is
+ # pass-independent. If we find (below) that the .bbl file is unchanged,
+ # then the last latex saw a correct bibliography.
+ # Therefore only do this on the first pass
+ if count == 1:
+ for auxfilename in auxfiles:
+ target_aux = os.path.join(targetdir, auxfilename)
+ if os.path.exists(target_aux):
+ content = open(target_aux, "rb").read()
+ if content.find("bibdata") != -1:
+ if Verbose:
+ print "Need to run bibtex"
+ bibfile = env.fs.File(targetbase)
+ result = BibTeXAction(bibfile, bibfile, env)
+ if result != 0:
+ check_file_error_message(env['BIBTEX'], 'blg')
+ return result
+ must_rerun_latex = check_MD5(suffix_nodes['.bbl'],'.bbl')
+ break
+
+ # Now decide if latex will need to be run again due to index.
+ if check_MD5(suffix_nodes['.idx'],'.idx') or (count == 1 and run_makeindex):
+ # We must run makeindex
+ if Verbose:
+ print "Need to run makeindex"
+ idxfile = suffix_nodes['.idx']
+ result = MakeIndexAction(idxfile, idxfile, env)
+ if result != 0:
+ check_file_error_message(env['MAKEINDEX'], 'ilg')
+ return result
+
+ # TO-DO: need to add a way for the user to extend this list for whatever
+ # auxiliary files they create in other (or their own) packages
+ # Harder is case is where an action needs to be called -- that should be rare (I hope?)
+
+ for index in check_suffixes:
+ check_MD5(suffix_nodes[index],index)
+
+ # Now decide if latex will need to be run again due to nomenclature.
+ if check_MD5(suffix_nodes['.nlo'],'.nlo') or (count == 1 and run_nomenclature):
+ # We must run makeindex
+ if Verbose:
+ print "Need to run makeindex for nomenclature"
+ nclfile = suffix_nodes['.nlo']
+ result = MakeNclAction(nclfile, nclfile, env)
+ if result != 0:
+ check_file_error_message('%s (nomenclature)' % env['MAKENCL'],
+ 'nlg')
+ #return result
+
+ # Now decide if latex will need to be run again due to glossary.
+ if check_MD5(suffix_nodes['.glo'],'.glo') or (count == 1 and run_glossaries) or (count == 1 and run_glossary):
+ # We must run makeindex
+ if Verbose:
+ print "Need to run makeindex for glossary"
+ glofile = suffix_nodes['.glo']
+ result = MakeGlossaryAction(glofile, glofile, env)
+ if result != 0:
+ check_file_error_message('%s (glossary)' % env['MAKEGLOSSARY'],
+ 'glg')
+ #return result
+
+ # Now decide if latex will need to be run again due to acronyms.
+ if check_MD5(suffix_nodes['.acn'],'.acn') or (count == 1 and run_acronyms):
+ # We must run makeindex
+ if Verbose:
+ print "Need to run makeindex for acronyms"
+ acrfile = suffix_nodes['.acn']
+ result = MakeAcronymsAction(acrfile, acrfile, env)
+ if result != 0:
+ check_file_error_message('%s (acronyms)' % env['MAKEACRONYMS'],
+ 'alg')
+ return result
+
+ # Now decide if latex needs to be run yet again to resolve warnings.
+ if warning_rerun_re.search(logContent):
+ must_rerun_latex = True
+ if Verbose:
+ print "rerun Latex due to latex or package rerun warning"
+
+ if rerun_citations_re.search(logContent):
+ must_rerun_latex = True
+ if Verbose:
+ print "rerun Latex due to 'Rerun to get citations correct' warning"
+
+ if undefined_references_re.search(logContent):
+ must_rerun_latex = True
+ if Verbose:
+ print "rerun Latex due to undefined references or citations"
+
+ if (count >= int(env.subst('$LATEXRETRIES')) and must_rerun_latex):
+ print "reached max number of retries on Latex ,",int(env.subst('$LATEXRETRIES'))
+# end of while loop
+
+ # rename Latex's output to what the target name is
+ if not (str(target[0]) == resultfilename and os.path.exists(resultfilename)):
+ if os.path.exists(resultfilename):
+ print "move %s to %s" % (resultfilename, str(target[0]), )
+ shutil.move(resultfilename,str(target[0]))
+
+ # Original comment (when TEXPICTS was not restored):
+ # The TEXPICTS enviroment variable is needed by a dvi -> pdf step
+ # later on Mac OSX so leave it
+ #
+ # It is also used when searching for pictures (implicit dependencies).
+ # Why not set the variable again in the respective builder instead
+ # of leaving local modifications in the environment? What if multiple
+ # latex builds in different directories need different TEXPICTS?
+ for var in SCons.Scanner.LaTeX.LaTeX.env_variables:
+ if var == 'TEXPICTS':
+ continue
+ if saved_env[var] is _null:
+ try:
+ del env['ENV'][var]
+ except KeyError:
+ pass # was never set
+ else:
+ env['ENV'][var] = saved_env[var]
+
+ return result
+
+def LaTeXAuxAction(target = None, source= None, env=None):
+ result = InternalLaTeXAuxAction( LaTeXAction, target, source, env )
+ return result
+
+LaTeX_re = re.compile("\\\\document(style|class)")
+
+def is_LaTeX(flist,env,abspath):
+ """Scan a file list to decide if it's TeX- or LaTeX-flavored."""
+
+ # We need to scan files that are included in case the
+ # \documentclass command is in them.
+
+ # get path list from both env['TEXINPUTS'] and env['ENV']['TEXINPUTS']
+ savedpath = modify_env_var(env, 'TEXINPUTS', abspath)
+ paths = env['ENV']['TEXINPUTS']
+ if SCons.Util.is_List(paths):
+ pass
+ else:
+ # Split at os.pathsep to convert into absolute path
+ paths = paths.split(os.pathsep)
+
+ # now that we have the path list restore the env
+ if savedpath is _null:
+ try:
+ del env['ENV']['TEXINPUTS']
+ except KeyError:
+ pass # was never set
+ else:
+ env['ENV']['TEXINPUTS'] = savedpath
+ if Verbose:
+ print "is_LaTeX search path ",paths
+ print "files to search :",flist
+
+ # Now that we have the search path and file list, check each one
+ for f in flist:
+ if Verbose:
+ print " checking for Latex source ",str(f)
+
+ content = f.get_text_contents()
+ if LaTeX_re.search(content):
+ if Verbose:
+ print "file %s is a LaTeX file" % str(f)
+ return 1
+ if Verbose:
+ print "file %s is not a LaTeX file" % str(f)
+
+ # now find included files
+ inc_files = [ ]
+ inc_files.extend( include_re.findall(content) )
+ if Verbose:
+ print "files included by '%s': "%str(f),inc_files
+ # inc_files is list of file names as given. need to find them
+ # using TEXINPUTS paths.
+
+ # search the included files
+ for src in inc_files:
+ srcNode = FindFile(src,['.tex','.ltx','.latex'],paths,env,requireExt=False)
+ # make this a list since is_LaTeX takes a list.
+ fileList = [srcNode,]
+ if Verbose:
+ print "FindFile found ",srcNode
+ if srcNode is not None:
+ file_test = is_LaTeX(fileList, env, abspath)
+
+ # return on first file that finds latex is needed.
+ if file_test:
+ return file_test
+
+ if Verbose:
+ print " done scanning ",str(f)
+
+ return 0
+
+def TeXLaTeXFunction(target = None, source= None, env=None):
+ """A builder for TeX and LaTeX that scans the source file to
+ decide the "flavor" of the source and then executes the appropriate
+ program."""
+
+ # find these paths for use in is_LaTeX to search for included files
+ basedir = os.path.split(str(source[0]))[0]
+ abspath = os.path.abspath(basedir)
+
+ if is_LaTeX(source,env,abspath):
+ result = LaTeXAuxAction(target,source,env)
+ if result != 0:
+ check_file_error_message(env['LATEX'])
+ else:
+ result = TeXAction(target,source,env)
+ if result != 0:
+ check_file_error_message(env['TEX'])
+ return result
+
+def TeXLaTeXStrFunction(target = None, source= None, env=None):
+ """A strfunction for TeX and LaTeX that scans the source file to
+ decide the "flavor" of the source and then returns the appropriate
+ command string."""
+ if env.GetOption("no_exec"):
+
+ # find these paths for use in is_LaTeX to search for included files
+ basedir = os.path.split(str(source[0]))[0]
+ abspath = os.path.abspath(basedir)
+
+ if is_LaTeX(source,env,abspath):
+ result = env.subst('$LATEXCOM',0,target,source)+" ..."
+ else:
+ result = env.subst("$TEXCOM",0,target,source)+" ..."
+ else:
+ result = ''
+ return result
+
+def tex_eps_emitter(target, source, env):
+ """An emitter for TeX and LaTeX sources when
+ executing tex or latex. It will accept .ps and .eps
+ graphics files
+ """
+ (target, source) = tex_emitter_core(target, source, env, TexGraphics)
+
+ return (target, source)
+
+def tex_pdf_emitter(target, source, env):
+ """An emitter for TeX and LaTeX sources when
+ executing pdftex or pdflatex. It will accept graphics
+ files of types .pdf, .jpg, .png, .gif, and .tif
+ """
+ (target, source) = tex_emitter_core(target, source, env, LatexGraphics)
+
+ return (target, source)
+
+def ScanFiles(theFile, target, paths, file_tests, file_tests_search, env, graphics_extensions, targetdir, aux_files):
+ """ For theFile (a Node) update any file_tests and search for graphics files
+ then find all included files and call ScanFiles recursively for each of them"""
+
+ content = theFile.get_text_contents()
+ if Verbose:
+ print " scanning ",str(theFile)
+
+ for i in range(len(file_tests_search)):
+ if file_tests[i][0] is None:
+ file_tests[i][0] = file_tests_search[i].search(content)
+
+ incResult = includeOnly_re.search(content)
+ if incResult:
+ aux_files.append(os.path.join(targetdir, incResult.group(1)))
+ if Verbose:
+ print "\include file names : ", aux_files
+ # recursively call this on each of the included files
+ inc_files = [ ]
+ inc_files.extend( include_re.findall(content) )
+ if Verbose:
+ print "files included by '%s': "%str(theFile),inc_files
+ # inc_files is list of file names as given. need to find them
+ # using TEXINPUTS paths.
+
+ for src in inc_files:
+ srcNode = FindFile(src,['.tex','.ltx','.latex'],paths,env,requireExt=False)
+ if srcNode is not None:
+ file_tests = ScanFiles(srcNode, target, paths, file_tests, file_tests_search, env, graphics_extensions, targetdir, aux_files)
+ if Verbose:
+ print " done scanning ",str(theFile)
+ return file_tests
+
+def tex_emitter_core(target, source, env, graphics_extensions):
+ """An emitter for TeX and LaTeX sources.
+ For LaTeX sources we try and find the common created files that
+ are needed on subsequent runs of latex to finish tables of contents,
+ bibliographies, indices, lists of figures, and hyperlink references.
+ """
+ basename = SCons.Util.splitext(str(source[0]))[0]
+ basefile = os.path.split(str(basename))[1]
+ targetdir = os.path.split(str(target[0]))[0]
+ targetbase = os.path.join(targetdir, basefile)
+
+ basedir = os.path.split(str(source[0]))[0]
+ abspath = os.path.abspath(basedir)
+ target[0].attributes.path = abspath
+
+ #
+ # file names we will make use of in searching the sources and log file
+ #
+ emit_suffixes = ['.aux', '.log', '.ilg', '.blg', '.nls', '.nlg', '.gls', '.glg', '.alg'] + all_suffixes
+ auxfilename = targetbase + '.aux'
+ logfilename = targetbase + '.log'
+ flsfilename = targetbase + '.fls'
+
+ env.SideEffect(auxfilename,target[0])
+ env.SideEffect(logfilename,target[0])
+ env.SideEffect(flsfilename,target[0])
+ if Verbose:
+ print "side effect :",auxfilename,logfilename,flsfilename
+ env.Clean(target[0],auxfilename)
+ env.Clean(target[0],logfilename)
+ env.Clean(target[0],flsfilename)
+
+ content = source[0].get_text_contents()
+
+ idx_exists = os.path.exists(targetbase + '.idx')
+ nlo_exists = os.path.exists(targetbase + '.nlo')
+ glo_exists = os.path.exists(targetbase + '.glo')
+ acr_exists = os.path.exists(targetbase + '.acn')
+
+ # set up list with the regular expressions
+ # we use to find features used
+ file_tests_search = [auxfile_re,
+ makeindex_re,
+ bibliography_re,
+ tableofcontents_re,
+ listoffigures_re,
+ listoftables_re,
+ hyperref_re,
+ makenomenclature_re,
+ makeglossary_re,
+ makeglossaries_re,
+ makeacronyms_re,
+ beamer_re ]
+ # set up list with the file suffixes that need emitting
+ # when a feature is found
+ file_tests_suff = [['.aux'],
+ ['.idx', '.ind', '.ilg'],
+ ['.bbl', '.blg'],
+ ['.toc'],
+ ['.lof'],
+ ['.lot'],
+ ['.out'],
+ ['.nlo', '.nls', '.nlg'],
+ ['.glo', '.gls', '.glg'],
+ ['.glo', '.gls', '.glg'],
+ ['.acn', '.acr', '.alg'],
+ ['.nav', '.snm', '.out', '.toc'] ]
+ # build the list of lists
+ file_tests = []
+ for i in range(len(file_tests_search)):
+ file_tests.append( [None, file_tests_suff[i]] )
+
+ # TO-DO: need to add a way for the user to extend this list for whatever
+ # auxiliary files they create in other (or their own) packages
+
+ # get path list from both env['TEXINPUTS'] and env['ENV']['TEXINPUTS']
+ savedpath = modify_env_var(env, 'TEXINPUTS', abspath)
+ paths = env['ENV']['TEXINPUTS']
+ if SCons.Util.is_List(paths):
+ pass
+ else:
+ # Split at os.pathsep to convert into absolute path
+ paths = paths.split(os.pathsep)
+
+ # now that we have the path list restore the env
+ if savedpath is _null:
+ try:
+ del env['ENV']['TEXINPUTS']
+ except KeyError:
+ pass # was never set
+ else:
+ env['ENV']['TEXINPUTS'] = savedpath
+ if Verbose:
+ print "search path ",paths
+
+ aux_files = []
+ file_tests = ScanFiles(source[0], target, paths, file_tests, file_tests_search, env, graphics_extensions, targetdir, aux_files)
+
+ for (theSearch,suffix_list) in file_tests:
+ if theSearch:
+ for suffix in suffix_list:
+ env.SideEffect(targetbase + suffix,target[0])
+ if Verbose:
+ print "side effect :",targetbase + suffix
+ env.Clean(target[0],targetbase + suffix)
+
+ for aFile in aux_files:
+ aFile_base = SCons.Util.splitext(aFile)[0]
+ env.SideEffect(aFile_base + '.aux',target[0])
+ if Verbose:
+ print "side effect :",aFile_base + '.aux'
+ env.Clean(target[0],aFile_base + '.aux')
+ # read fls file to get all other files that latex creates and will read on the next pass
+ # remove files from list that we explicitly dealt with above
+ if os.path.exists(flsfilename):
+ content = open(flsfilename, "rb").read()
+ out_files = openout_re.findall(content)
+ myfiles = [auxfilename, logfilename, flsfilename, targetbase+'.dvi',targetbase+'.pdf']
+ for filename in out_files[:]:
+ if filename in myfiles:
+ out_files.remove(filename)
+ env.SideEffect(out_files,target[0])
+ if Verbose:
+ print "side effect :",out_files
+ env.Clean(target[0],out_files)
+
+ return (target, source)
+
+
+TeXLaTeXAction = None
+
+def generate(env):
+ """Add Builders and construction variables for TeX to an Environment."""
+
+ global TeXLaTeXAction
+ if TeXLaTeXAction is None:
+ TeXLaTeXAction = SCons.Action.Action(TeXLaTeXFunction,
+ strfunction=TeXLaTeXStrFunction)
+
+ env.AppendUnique(LATEXSUFFIXES=SCons.Tool.LaTeXSuffixes)
+
+ generate_common(env)
+
+ import dvi
+ dvi.generate(env)
+
+ bld = env['BUILDERS']['DVI']
+ bld.add_action('.tex', TeXLaTeXAction)
+ bld.add_emitter('.tex', tex_eps_emitter)
+
+def generate_common(env):
+ """Add internal Builders and construction variables for LaTeX to an Environment."""
+
+ # A generic tex file Action, sufficient for all tex files.
+ global TeXAction
+ if TeXAction is None:
+ TeXAction = SCons.Action.Action("$TEXCOM", "$TEXCOMSTR")
+
+ # An Action to build a latex file. This might be needed more
+ # than once if we are dealing with labels and bibtex.
+ global LaTeXAction
+ if LaTeXAction is None:
+ LaTeXAction = SCons.Action.Action("$LATEXCOM", "$LATEXCOMSTR")
+
+ # Define an action to run BibTeX on a file.
+ global BibTeXAction
+ if BibTeXAction is None:
+ BibTeXAction = SCons.Action.Action("$BIBTEXCOM", "$BIBTEXCOMSTR")
+
+ # Define an action to run MakeIndex on a file.
+ global MakeIndexAction
+ if MakeIndexAction is None:
+ MakeIndexAction = SCons.Action.Action("$MAKEINDEXCOM", "$MAKEINDEXCOMSTR")
+
+ # Define an action to run MakeIndex on a file for nomenclatures.
+ global MakeNclAction
+ if MakeNclAction is None:
+ MakeNclAction = SCons.Action.Action("$MAKENCLCOM", "$MAKENCLCOMSTR")
+
+ # Define an action to run MakeIndex on a file for glossaries.
+ global MakeGlossaryAction
+ if MakeGlossaryAction is None:
+ MakeGlossaryAction = SCons.Action.Action("$MAKEGLOSSARYCOM", "$MAKEGLOSSARYCOMSTR")
+
+ # Define an action to run MakeIndex on a file for acronyms.
+ global MakeAcronymsAction
+ if MakeAcronymsAction is None:
+ MakeAcronymsAction = SCons.Action.Action("$MAKEACRONYMSCOM", "$MAKEACRONYMSCOMSTR")
+
+ CDCOM = 'cd '
+ if platform.system() == 'Windows':
+ # allow cd command to change drives on Windows
+ CDCOM = 'cd /D '
+
+ env['TEX'] = 'tex'
+ env['TEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode -recorder')
+ env['TEXCOM'] = CDCOM + '${TARGET.dir} && $TEX $TEXFLAGS ${SOURCE.file}'
+
+ env['PDFTEX'] = 'pdftex'
+ env['PDFTEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode -recorder')
+ env['PDFTEXCOM'] = CDCOM + '${TARGET.dir} && $PDFTEX $PDFTEXFLAGS ${SOURCE.file}'
+
+ env['LATEX'] = 'latex'
+ env['LATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode -recorder')
+ env['LATEXCOM'] = CDCOM + '${TARGET.dir} && $LATEX $LATEXFLAGS ${SOURCE.file}'
+ env['LATEXRETRIES'] = 3
+
+ env['PDFLATEX'] = 'pdflatex'
+ env['PDFLATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode -recorder')
+ env['PDFLATEXCOM'] = CDCOM + '${TARGET.dir} && $PDFLATEX $PDFLATEXFLAGS ${SOURCE.file}'
+
+ env['BIBTEX'] = 'bibtex'
+ env['BIBTEXFLAGS'] = SCons.Util.CLVar('')
+ env['BIBTEXCOM'] = CDCOM + '${TARGET.dir} && $BIBTEX $BIBTEXFLAGS ${SOURCE.filebase}'
+
+ env['MAKEINDEX'] = 'makeindex'
+ env['MAKEINDEXFLAGS'] = SCons.Util.CLVar('')
+ env['MAKEINDEXCOM'] = CDCOM + '${TARGET.dir} && $MAKEINDEX $MAKEINDEXFLAGS ${SOURCE.file}'
+
+ env['MAKEGLOSSARY'] = 'makeindex'
+ env['MAKEGLOSSARYSTYLE'] = '${SOURCE.filebase}.ist'
+ env['MAKEGLOSSARYFLAGS'] = SCons.Util.CLVar('-s ${MAKEGLOSSARYSTYLE} -t ${SOURCE.filebase}.glg')
+ env['MAKEGLOSSARYCOM'] = CDCOM + '${TARGET.dir} && $MAKEGLOSSARY ${SOURCE.filebase}.glo $MAKEGLOSSARYFLAGS -o ${SOURCE.filebase}.gls'
+
+ env['MAKEACRONYMS'] = 'makeindex'
+ env['MAKEACRONYMSSTYLE'] = '${SOURCE.filebase}.ist'
+ env['MAKEACRONYMSFLAGS'] = SCons.Util.CLVar('-s ${MAKEACRONYMSSTYLE} -t ${SOURCE.filebase}.alg')
+ env['MAKEACRONYMSCOM'] = CDCOM + '${TARGET.dir} && $MAKEACRONYMS ${SOURCE.filebase}.acn $MAKEACRONYMSFLAGS -o ${SOURCE.filebase}.acr'
+
+ env['MAKENCL'] = 'makeindex'
+ env['MAKENCLSTYLE'] = 'nomencl.ist'
+ env['MAKENCLFLAGS'] = '-s ${MAKENCLSTYLE} -t ${SOURCE.filebase}.nlg'
+ env['MAKENCLCOM'] = CDCOM + '${TARGET.dir} && $MAKENCL ${SOURCE.filebase}.nlo $MAKENCLFLAGS -o ${SOURCE.filebase}.nls'
+
+def exists(env):
+ return env.Detect('tex')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/textfile.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/textfile.py
new file mode 100644
index 00000000..d4b1b0fb
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/textfile.py
@@ -0,0 +1,175 @@
+# -*- python -*-
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__doc__ = """
+Textfile/Substfile builder for SCons.
+
+ Create file 'target' which typically is a textfile. The 'source'
+ may be any combination of strings, Nodes, or lists of same. A
+ 'linesep' will be put between any part written and defaults to
+ os.linesep.
+
+ The only difference between the Textfile builder and the Substfile
+ builder is that strings are converted to Value() nodes for the
+ former and File() nodes for the latter. To insert files in the
+ former or strings in the latter, wrap them in a File() or Value(),
+ respectively.
+
+ The values of SUBST_DICT first have any construction variables
+ expanded (its keys are not expanded). If a value of SUBST_DICT is
+ a python callable function, it is called and the result is expanded
+ as the value. Values are substituted in a "random" order; if any
+ substitution could be further expanded by another subsitition, it
+ is unpredictible whether the expansion will occur.
+"""
+
+__revision__ = "src/engine/SCons/Tool/textfile.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons
+
+import os
+import re
+
+from SCons.Node import Node
+from SCons.Node.Python import Value
+from SCons.Util import is_String, is_Sequence, is_Dict
+
+def _do_subst(node, subs):
+ """
+ Fetch the node contents and replace all instances of the keys with
+ their values. For example, if subs is
+ {'%VERSION%': '1.2345', '%BASE%': 'MyProg', '%prefix%': '/bin'},
+ then all instances of %VERSION% in the file will be replaced with
+ 1.2345 and so forth.
+ """
+ contents = node.get_text_contents()
+ if not subs: return contents
+ for (k,v) in subs:
+ contents = re.sub(k, v, contents)
+ return contents
+
+def _action(target, source, env):
+ # prepare the line separator
+ linesep = env['LINESEPARATOR']
+ if linesep is None:
+ linesep = os.linesep
+ elif is_String(linesep):
+ pass
+ elif isinstance(linesep, Value):
+ linesep = linesep.get_text_contents()
+ else:
+ raise SCons.Errors.UserError(
+ 'unexpected type/class for LINESEPARATOR: %s'
+ % repr(linesep), None)
+
+ # create a dictionary to use for the substitutions
+ if 'SUBST_DICT' not in env:
+ subs = None # no substitutions
+ else:
+ d = env['SUBST_DICT']
+ if is_Dict(d):
+ d = list(d.items())
+ elif is_Sequence(d):
+ pass
+ else:
+ raise SCons.Errors.UserError('SUBST_DICT must be dict or sequence')
+ subs = []
+ for (k,v) in d:
+ if callable(v):
+ v = v()
+ if is_String(v):
+ v = env.subst(v)
+ else:
+ v = str(v)
+ subs.append((k,v))
+
+ # write the file
+ try:
+ fd = open(target[0].get_path(), "wb")
+ except (OSError,IOError), e:
+ raise SCons.Errors.UserError("Can't write target file %s" % target[0])
+ # separate lines by 'linesep' only if linesep is not empty
+ lsep = None
+ for s in source:
+ if lsep: fd.write(lsep)
+ fd.write(_do_subst(s, subs))
+ lsep = linesep
+ fd.close()
+
+def _strfunc(target, source, env):
+ return "Creating '%s'" % target[0]
+
+def _convert_list_R(newlist, sources):
+ for elem in sources:
+ if is_Sequence(elem):
+ _convert_list_R(newlist, elem)
+ elif isinstance(elem, Node):
+ newlist.append(elem)
+ else:
+ newlist.append(Value(elem))
+def _convert_list(target, source, env):
+ if len(target) != 1:
+ raise SCons.Errors.UserError("Only one target file allowed")
+ newlist = []
+ _convert_list_R(newlist, source)
+ return target, newlist
+
+_common_varlist = ['SUBST_DICT', 'LINESEPARATOR']
+
+_text_varlist = _common_varlist + ['TEXTFILEPREFIX', 'TEXTFILESUFFIX']
+_text_builder = SCons.Builder.Builder(
+ action = SCons.Action.Action(_action, _strfunc, varlist = _text_varlist),
+ source_factory = Value,
+ emitter = _convert_list,
+ prefix = '$TEXTFILEPREFIX',
+ suffix = '$TEXTFILESUFFIX',
+ )
+
+_subst_varlist = _common_varlist + ['SUBSTFILEPREFIX', 'TEXTFILESUFFIX']
+_subst_builder = SCons.Builder.Builder(
+ action = SCons.Action.Action(_action, _strfunc, varlist = _subst_varlist),
+ source_factory = SCons.Node.FS.File,
+ emitter = _convert_list,
+ prefix = '$SUBSTFILEPREFIX',
+ suffix = '$SUBSTFILESUFFIX',
+ src_suffix = ['.in'],
+ )
+
+def generate(env):
+ env['LINESEPARATOR'] = os.linesep
+ env['BUILDERS']['Textfile'] = _text_builder
+ env['TEXTFILEPREFIX'] = ''
+ env['TEXTFILESUFFIX'] = '.txt'
+ env['BUILDERS']['Substfile'] = _subst_builder
+ env['SUBSTFILEPREFIX'] = ''
+ env['SUBSTFILESUFFIX'] = ''
+
+def exists(env):
+ return 1
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/tlib.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/tlib.py
new file mode 100644
index 00000000..157c2100
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/tlib.py
@@ -0,0 +1,53 @@
+"""SCons.Tool.tlib
+
+XXX
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/tlib.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Tool
+import SCons.Tool.bcc32
+import SCons.Util
+
+def generate(env):
+ SCons.Tool.bcc32.findIt('tlib', env)
+ """Add Builders and construction variables for ar to an Environment."""
+ SCons.Tool.createStaticLibBuilder(env)
+ env['AR'] = 'tlib'
+ env['ARFLAGS'] = SCons.Util.CLVar('')
+ env['ARCOM'] = '$AR $TARGET $ARFLAGS /a $SOURCES'
+ env['LIBPREFIX'] = ''
+ env['LIBSUFFIX'] = '.lib'
+
+def exists(env):
+ return SCons.Tool.bcc32.findIt('tlib', env)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/wix.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/wix.py
new file mode 100644
index 00000000..44b5d0f2
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/wix.py
@@ -0,0 +1,99 @@
+"""SCons.Tool.wix
+
+Tool-specific initialization for wix, the Windows Installer XML Tool.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/wix.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import SCons.Builder
+import SCons.Action
+import os
+
+def generate(env):
+ """Add Builders and construction variables for WiX to an Environment."""
+ if not exists(env):
+ return
+
+ env['WIXCANDLEFLAGS'] = ['-nologo']
+ env['WIXCANDLEINCLUDE'] = []
+ env['WIXCANDLECOM'] = '$WIXCANDLE $WIXCANDLEFLAGS -I $WIXCANDLEINCLUDE -o ${TARGET} ${SOURCE}'
+
+ env['WIXLIGHTFLAGS'].append( '-nologo' )
+ env['WIXLIGHTCOM'] = "$WIXLIGHT $WIXLIGHTFLAGS -out ${TARGET} ${SOURCES}"
+
+ object_builder = SCons.Builder.Builder(
+ action = '$WIXCANDLECOM',
+ suffix = '.wxiobj',
+ src_suffix = '.wxs')
+
+ linker_builder = SCons.Builder.Builder(
+ action = '$WIXLIGHTCOM',
+ src_suffix = '.wxiobj',
+ src_builder = object_builder)
+
+ env['BUILDERS']['WiX'] = linker_builder
+
+def exists(env):
+ env['WIXCANDLE'] = 'candle.exe'
+ env['WIXLIGHT'] = 'light.exe'
+
+ # try to find the candle.exe and light.exe tools and
+ # add the install directory to light libpath.
+ #for path in os.environ['PATH'].split(os.pathsep):
+ for path in os.environ['PATH'].split(os.pathsep):
+ if not path:
+ continue
+
+ # workaround for some weird python win32 bug.
+ if path[0] == '"' and path[-1:]=='"':
+ path = path[1:-1]
+
+ # normalize the path
+ path = os.path.normpath(path)
+
+ # search for the tools in the PATH environment variable
+ try:
+ if env['WIXCANDLE'] in os.listdir(path) and\
+ env['WIXLIGHT'] in os.listdir(path):
+ env.PrependENVPath('PATH', path)
+ env['WIXLIGHTFLAGS'] = [ os.path.join( path, 'wixui.wixlib' ),
+ '-loc',
+ os.path.join( path, 'WixUI_en-us.wxl' ) ]
+ return 1
+ except OSError:
+ pass # ignore this, could be a stale PATH entry.
+
+ return None
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/yacc.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/yacc.py
new file mode 100644
index 00000000..9f95bd12
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/yacc.py
@@ -0,0 +1,130 @@
+"""SCons.Tool.yacc
+
+Tool-specific initialization for yacc.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/yacc.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+
+import SCons.Defaults
+import SCons.Tool
+import SCons.Util
+
+YaccAction = SCons.Action.Action("$YACCCOM", "$YACCCOMSTR")
+
+def _yaccEmitter(target, source, env, ysuf, hsuf):
+ yaccflags = env.subst("$YACCFLAGS", target=target, source=source)
+ flags = SCons.Util.CLVar(yaccflags)
+ targetBase, targetExt = os.path.splitext(SCons.Util.to_String(target[0]))
+
+ if '.ym' in ysuf: # If using Objective-C
+ target = [targetBase + ".m"] # the extension is ".m".
+
+
+ # If -d is specified on the command line, yacc will emit a .h
+ # or .hpp file with the same name as the .c or .cpp output file.
+ if '-d' in flags:
+ target.append(targetBase + env.subst(hsuf, target=target, source=source))
+
+ # If -g is specified on the command line, yacc will emit a .vcg
+ # file with the same base name as the .y, .yacc, .ym or .yy file.
+ if "-g" in flags:
+ base, ext = os.path.splitext(SCons.Util.to_String(source[0]))
+ target.append(base + env.subst("$YACCVCGFILESUFFIX"))
+
+ # With --defines and --graph, the name of the file is totally defined
+ # in the options.
+ fileGenOptions = ["--defines=", "--graph="]
+ for option in flags:
+ for fileGenOption in fileGenOptions:
+ l = len(fileGenOption)
+ if option[:l] == fileGenOption:
+ # A file generating option is present, so add the file
+ # name to the list of targets.
+ fileName = option[l:].strip()
+ target.append(fileName)
+
+ return (target, source)
+
+def yEmitter(target, source, env):
+ return _yaccEmitter(target, source, env, ['.y', '.yacc'], '$YACCHFILESUFFIX')
+
+def ymEmitter(target, source, env):
+ return _yaccEmitter(target, source, env, ['.ym'], '$YACCHFILESUFFIX')
+
+def yyEmitter(target, source, env):
+ return _yaccEmitter(target, source, env, ['.yy'], '$YACCHXXFILESUFFIX')
+
+def generate(env):
+ """Add Builders and construction variables for yacc to an Environment."""
+ c_file, cxx_file = SCons.Tool.createCFileBuilders(env)
+
+ # C
+ c_file.add_action('.y', YaccAction)
+ c_file.add_emitter('.y', yEmitter)
+
+ c_file.add_action('.yacc', YaccAction)
+ c_file.add_emitter('.yacc', yEmitter)
+
+ # Objective-C
+ c_file.add_action('.ym', YaccAction)
+ c_file.add_emitter('.ym', ymEmitter)
+
+ # C++
+ cxx_file.add_action('.yy', YaccAction)
+ cxx_file.add_emitter('.yy', yyEmitter)
+
+ env['YACC'] = env.Detect('bison') or 'yacc'
+ env['YACCFLAGS'] = SCons.Util.CLVar('')
+ env['YACCCOM'] = '$YACC $YACCFLAGS -o $TARGET $SOURCES'
+ env['YACCHFILESUFFIX'] = '.h'
+
+ # Apparently, OS X now creates file.hpp like everybody else
+ # I have no idea when it changed; it was fixed in 10.4
+ #if env['PLATFORM'] == 'darwin':
+ # # Bison on Mac OS X just appends ".h" to the generated target .cc
+ # # or .cpp file name. Hooray for delayed expansion of variables.
+ # env['YACCHXXFILESUFFIX'] = '${TARGET.suffix}.h'
+ #else:
+ # env['YACCHXXFILESUFFIX'] = '.hpp'
+ env['YACCHXXFILESUFFIX'] = '.hpp'
+
+ env['YACCVCGFILESUFFIX'] = '.vcg'
+
+def exists(env):
+ return env.Detect(['bison', 'yacc'])
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Tool/zip.py b/couchjs/scons/scons-local-2.0.1/SCons/Tool/zip.py
new file mode 100644
index 00000000..0f301470
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Tool/zip.py
@@ -0,0 +1,99 @@
+"""SCons.Tool.zip
+
+Tool-specific initialization for zip.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Tool/zip.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+
+import SCons.Builder
+import SCons.Defaults
+import SCons.Node.FS
+import SCons.Util
+
+try:
+ import zipfile
+ internal_zip = 1
+except ImportError:
+ internal_zip = 0
+
+if internal_zip:
+ zipcompression = zipfile.ZIP_DEFLATED
+ def zip(target, source, env):
+ compression = env.get('ZIPCOMPRESSION', 0)
+ zf = zipfile.ZipFile(str(target[0]), 'w', compression)
+ for s in source:
+ if s.isdir():
+ for dirpath, dirnames, filenames in os.walk(str(s)):
+ for fname in filenames:
+ path = os.path.join(dirpath, fname)
+ if os.path.isfile(path):
+ zf.write(path)
+ else:
+ zf.write(str(s))
+ zf.close()
+else:
+ zipcompression = 0
+ zip = "$ZIP $ZIPFLAGS ${TARGET.abspath} $SOURCES"
+
+
+zipAction = SCons.Action.Action(zip, varlist=['ZIPCOMPRESSION'])
+
+ZipBuilder = SCons.Builder.Builder(action = SCons.Action.Action('$ZIPCOM', '$ZIPCOMSTR'),
+ source_factory = SCons.Node.FS.Entry,
+ source_scanner = SCons.Defaults.DirScanner,
+ suffix = '$ZIPSUFFIX',
+ multi = 1)
+
+
+def generate(env):
+ """Add Builders and construction variables for zip to an Environment."""
+ try:
+ bld = env['BUILDERS']['Zip']
+ except KeyError:
+ bld = ZipBuilder
+ env['BUILDERS']['Zip'] = bld
+
+ env['ZIP'] = 'zip'
+ env['ZIPFLAGS'] = SCons.Util.CLVar('')
+ env['ZIPCOM'] = zipAction
+ env['ZIPCOMPRESSION'] = zipcompression
+ env['ZIPSUFFIX'] = '.zip'
+
+def exists(env):
+ return internal_zip or env.Detect('zip')
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Util.py b/couchjs/scons/scons-local-2.0.1/SCons/Util.py
new file mode 100644
index 00000000..1ffbd032
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Util.py
@@ -0,0 +1,1492 @@
+"""SCons.Util
+
+Various utility functions go here.
+"""
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Util.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+import sys
+import copy
+import re
+import types
+
+from collections import UserDict, UserList, UserString
+
+# Don't "from types import ..." these because we need to get at the
+# types module later to look for UnicodeType.
+InstanceType = types.InstanceType
+MethodType = types.MethodType
+FunctionType = types.FunctionType
+try: unicode
+except NameError: UnicodeType = None
+else: UnicodeType = unicode
+
+def dictify(keys, values, result={}):
+ for k, v in zip(keys, values):
+ result[k] = v
+ return result
+
+_altsep = os.altsep
+if _altsep is None and sys.platform == 'win32':
+ # My ActivePython 2.0.1 doesn't set os.altsep! What gives?
+ _altsep = '/'
+if _altsep:
+ def rightmost_separator(path, sep):
+ return max(path.rfind(sep), path.rfind(_altsep))
+else:
+ def rightmost_separator(path, sep):
+ return path.rfind(sep)
+
+# First two from the Python Cookbook, just for completeness.
+# (Yeah, yeah, YAGNI...)
+def containsAny(str, set):
+ """Check whether sequence str contains ANY of the items in set."""
+ for c in set:
+ if c in str: return 1
+ return 0
+
+def containsAll(str, set):
+ """Check whether sequence str contains ALL of the items in set."""
+ for c in set:
+ if c not in str: return 0
+ return 1
+
+def containsOnly(str, set):
+ """Check whether sequence str contains ONLY items in set."""
+ for c in str:
+ if c not in set: return 0
+ return 1
+
+def splitext(path):
+ "Same as os.path.splitext() but faster."
+ sep = rightmost_separator(path, os.sep)
+ dot = path.rfind('.')
+ # An ext is only real if it has at least one non-digit char
+ if dot > sep and not containsOnly(path[dot:], "0123456789."):
+ return path[:dot],path[dot:]
+ else:
+ return path,""
+
+def updrive(path):
+ """
+ Make the drive letter (if any) upper case.
+ This is useful because Windows is inconsitent on the case
+ of the drive letter, which can cause inconsistencies when
+ calculating command signatures.
+ """
+ drive, rest = os.path.splitdrive(path)
+ if drive:
+ path = drive.upper() + rest
+ return path
+
+class NodeList(UserList):
+ """This class is almost exactly like a regular list of Nodes
+ (actually it can hold any object), with one important difference.
+ If you try to get an attribute from this list, it will return that
+ attribute from every item in the list. For example:
+
+ >>> someList = NodeList([ ' foo ', ' bar ' ])
+ >>> someList.strip()
+ [ 'foo', 'bar' ]
+ """
+ def __nonzero__(self):
+ return len(self.data) != 0
+
+ def __str__(self):
+ return ' '.join(map(str, self.data))
+
+ def __iter__(self):
+ return iter(self.data)
+
+ def __call__(self, *args, **kwargs):
+ result = [x(*args, **kwargs) for x in self.data]
+ return self.__class__(result)
+
+ def __getattr__(self, name):
+ result = [getattr(x, name) for x in self.data]
+ return self.__class__(result)
+
+
+_get_env_var = re.compile(r'^\$([_a-zA-Z]\w*|{[_a-zA-Z]\w*})$')
+
+def get_environment_var(varstr):
+ """Given a string, first determine if it looks like a reference
+ to a single environment variable, like "$FOO" or "${FOO}".
+ If so, return that variable with no decorations ("FOO").
+ If not, return None."""
+ mo=_get_env_var.match(to_String(varstr))
+ if mo:
+ var = mo.group(1)
+ if var[0] == '{':
+ return var[1:-1]
+ else:
+ return var
+ else:
+ return None
+
+class DisplayEngine(object):
+ print_it = True
+ def __call__(self, text, append_newline=1):
+ if not self.print_it:
+ return
+ if append_newline: text = text + '\n'
+ try:
+ sys.stdout.write(unicode(text))
+ except IOError:
+ # Stdout might be connected to a pipe that has been closed
+ # by now. The most likely reason for the pipe being closed
+ # is that the user has press ctrl-c. It this is the case,
+ # then SCons is currently shutdown. We therefore ignore
+ # IOError's here so that SCons can continue and shutdown
+ # properly so that the .sconsign is correctly written
+ # before SCons exits.
+ pass
+
+ def set_mode(self, mode):
+ self.print_it = mode
+
+def render_tree(root, child_func, prune=0, margin=[0], visited={}):
+ """
+ Render a tree of nodes into an ASCII tree view.
+ root - the root node of the tree
+ child_func - the function called to get the children of a node
+ prune - don't visit the same node twice
+ margin - the format of the left margin to use for children of root.
+ 1 results in a pipe, and 0 results in no pipe.
+ visited - a dictionary of visited nodes in the current branch if not prune,
+ or in the whole tree if prune.
+ """
+
+ rname = str(root)
+
+ children = child_func(root)
+ retval = ""
+ for pipe in margin[:-1]:
+ if pipe:
+ retval = retval + "| "
+ else:
+ retval = retval + " "
+
+ if rname in visited:
+ return retval + "+-[" + rname + "]\n"
+
+ retval = retval + "+-" + rname + "\n"
+ if not prune:
+ visited = copy.copy(visited)
+ visited[rname] = 1
+
+ for i in range(len(children)):
+ margin.append(i<len(children)-1)
+ retval = retval + render_tree(children[i], child_func, prune, margin, visited
+)
+ margin.pop()
+
+ return retval
+
+IDX = lambda N: N and 1 or 0
+
+def print_tree(root, child_func, prune=0, showtags=0, margin=[0], visited={}):
+ """
+ Print a tree of nodes. This is like render_tree, except it prints
+ lines directly instead of creating a string representation in memory,
+ so that huge trees can be printed.
+
+ root - the root node of the tree
+ child_func - the function called to get the children of a node
+ prune - don't visit the same node twice
+ showtags - print status information to the left of each node line
+ margin - the format of the left margin to use for children of root.
+ 1 results in a pipe, and 0 results in no pipe.
+ visited - a dictionary of visited nodes in the current branch if not prune,
+ or in the whole tree if prune.
+ """
+
+ rname = str(root)
+
+ if showtags:
+
+ if showtags == 2:
+ legend = (' E = exists\n' +
+ ' R = exists in repository only\n' +
+ ' b = implicit builder\n' +
+ ' B = explicit builder\n' +
+ ' S = side effect\n' +
+ ' P = precious\n' +
+ ' A = always build\n' +
+ ' C = current\n' +
+ ' N = no clean\n' +
+ ' H = no cache\n' +
+ '\n')
+ sys.stdout.write(unicode(legend))
+
+ tags = ['[']
+ tags.append(' E'[IDX(root.exists())])
+ tags.append(' R'[IDX(root.rexists() and not root.exists())])
+ tags.append(' BbB'[[0,1][IDX(root.has_explicit_builder())] +
+ [0,2][IDX(root.has_builder())]])
+ tags.append(' S'[IDX(root.side_effect)])
+ tags.append(' P'[IDX(root.precious)])
+ tags.append(' A'[IDX(root.always_build)])
+ tags.append(' C'[IDX(root.is_up_to_date())])
+ tags.append(' N'[IDX(root.noclean)])
+ tags.append(' H'[IDX(root.nocache)])
+ tags.append(']')
+
+ else:
+ tags = []
+
+ def MMM(m):
+ return [" ","| "][m]
+ margins = list(map(MMM, margin[:-1]))
+
+ children = child_func(root)
+
+ if prune and rname in visited and children:
+ sys.stdout.write(''.join(tags + margins + ['+-[', rname, ']']) + u'\n')
+ return
+
+ sys.stdout.write(''.join(tags + margins + ['+-', rname]) + u'\n')
+
+ visited[rname] = 1
+
+ if children:
+ margin.append(1)
+ idx = IDX(showtags)
+ for C in children[:-1]:
+ print_tree(C, child_func, prune, idx, margin, visited)
+ margin[-1] = 0
+ print_tree(children[-1], child_func, prune, idx, margin, visited)
+ margin.pop()
+
+
+
+# Functions for deciding if things are like various types, mainly to
+# handle UserDict, UserList and UserString like their underlying types.
+#
+# Yes, all of this manual testing breaks polymorphism, and the real
+# Pythonic way to do all of this would be to just try it and handle the
+# exception, but handling the exception when it's not the right type is
+# often too slow.
+
+# We are using the following trick to speed up these
+# functions. Default arguments are used to take a snapshot of the
+# the global functions and constants used by these functions. This
+# transforms accesses to global variable into local variables
+# accesses (i.e. LOAD_FAST instead of LOAD_GLOBAL).
+
+DictTypes = (dict, UserDict)
+ListTypes = (list, UserList)
+SequenceTypes = (list, tuple, UserList)
+
+# Note that profiling data shows a speed-up when comparing
+# explicitely with str and unicode instead of simply comparing
+# with basestring. (at least on Python 2.5.1)
+StringTypes = (str, unicode, UserString)
+
+# Empirically, it is faster to check explicitely for str and
+# unicode than for basestring.
+BaseStringTypes = (str, unicode)
+
+def is_Dict(obj, isinstance=isinstance, DictTypes=DictTypes):
+ return isinstance(obj, DictTypes)
+
+def is_List(obj, isinstance=isinstance, ListTypes=ListTypes):
+ return isinstance(obj, ListTypes)
+
+def is_Sequence(obj, isinstance=isinstance, SequenceTypes=SequenceTypes):
+ return isinstance(obj, SequenceTypes)
+
+def is_Tuple(obj, isinstance=isinstance, tuple=tuple):
+ return isinstance(obj, tuple)
+
+def is_String(obj, isinstance=isinstance, StringTypes=StringTypes):
+ return isinstance(obj, StringTypes)
+
+def is_Scalar(obj, isinstance=isinstance, StringTypes=StringTypes, SequenceTypes=SequenceTypes):
+ # Profiling shows that there is an impressive speed-up of 2x
+ # when explicitely checking for strings instead of just not
+ # sequence when the argument (i.e. obj) is already a string.
+ # But, if obj is a not string then it is twice as fast to
+ # check only for 'not sequence'. The following code therefore
+ # assumes that the obj argument is a string must of the time.
+ return isinstance(obj, StringTypes) or not isinstance(obj, SequenceTypes)
+
+def do_flatten(sequence, result, isinstance=isinstance,
+ StringTypes=StringTypes, SequenceTypes=SequenceTypes):
+ for item in sequence:
+ if isinstance(item, StringTypes) or not isinstance(item, SequenceTypes):
+ result.append(item)
+ else:
+ do_flatten(item, result)
+
+def flatten(obj, isinstance=isinstance, StringTypes=StringTypes,
+ SequenceTypes=SequenceTypes, do_flatten=do_flatten):
+ """Flatten a sequence to a non-nested list.
+
+ Flatten() converts either a single scalar or a nested sequence
+ to a non-nested list. Note that flatten() considers strings
+ to be scalars instead of sequences like Python would.
+ """
+ if isinstance(obj, StringTypes) or not isinstance(obj, SequenceTypes):
+ return [obj]
+ result = []
+ for item in obj:
+ if isinstance(item, StringTypes) or not isinstance(item, SequenceTypes):
+ result.append(item)
+ else:
+ do_flatten(item, result)
+ return result
+
+def flatten_sequence(sequence, isinstance=isinstance, StringTypes=StringTypes,
+ SequenceTypes=SequenceTypes, do_flatten=do_flatten):
+ """Flatten a sequence to a non-nested list.
+
+ Same as flatten(), but it does not handle the single scalar
+ case. This is slightly more efficient when one knows that
+ the sequence to flatten can not be a scalar.
+ """
+ result = []
+ for item in sequence:
+ if isinstance(item, StringTypes) or not isinstance(item, SequenceTypes):
+ result.append(item)
+ else:
+ do_flatten(item, result)
+ return result
+
+# Generic convert-to-string functions that abstract away whether or
+# not the Python we're executing has Unicode support. The wrapper
+# to_String_for_signature() will use a for_signature() method if the
+# specified object has one.
+#
+def to_String(s,
+ isinstance=isinstance, str=str,
+ UserString=UserString, BaseStringTypes=BaseStringTypes):
+ if isinstance(s,BaseStringTypes):
+ # Early out when already a string!
+ return s
+ elif isinstance(s, UserString):
+ # s.data can only be either a unicode or a regular
+ # string. Please see the UserString initializer.
+ return s.data
+ else:
+ return str(s)
+
+def to_String_for_subst(s,
+ isinstance=isinstance, str=str, to_String=to_String,
+ BaseStringTypes=BaseStringTypes, SequenceTypes=SequenceTypes,
+ UserString=UserString):
+
+ # Note that the test cases are sorted by order of probability.
+ if isinstance(s, BaseStringTypes):
+ return s
+ elif isinstance(s, SequenceTypes):
+ l = []
+ for e in s:
+ l.append(to_String_for_subst(e))
+ return ' '.join( s )
+ elif isinstance(s, UserString):
+ # s.data can only be either a unicode or a regular
+ # string. Please see the UserString initializer.
+ return s.data
+ else:
+ return str(s)
+
+def to_String_for_signature(obj, to_String_for_subst=to_String_for_subst,
+ AttributeError=AttributeError):
+ try:
+ f = obj.for_signature
+ except AttributeError:
+ return to_String_for_subst(obj)
+ else:
+ return f()
+
+
+# The SCons "semi-deep" copy.
+#
+# This makes separate copies of lists (including UserList objects)
+# dictionaries (including UserDict objects) and tuples, but just copies
+# references to anything else it finds.
+#
+# A special case is any object that has a __semi_deepcopy__() method,
+# which we invoke to create the copy, which is used by the BuilderDict
+# class because of its extra initialization argument.
+#
+# The dispatch table approach used here is a direct rip-off from the
+# normal Python copy module.
+
+_semi_deepcopy_dispatch = d = {}
+
+def _semi_deepcopy_dict(x):
+ copy = {}
+ for key, val in x.items():
+ # The regular Python copy.deepcopy() also deepcopies the key,
+ # as follows:
+ #
+ # copy[semi_deepcopy(key)] = semi_deepcopy(val)
+ #
+ # Doesn't seem like we need to, but we'll comment it just in case.
+ copy[key] = semi_deepcopy(val)
+ return copy
+d[dict] = _semi_deepcopy_dict
+
+def _semi_deepcopy_list(x):
+ return list(map(semi_deepcopy, x))
+d[list] = _semi_deepcopy_list
+
+def _semi_deepcopy_tuple(x):
+ return tuple(map(semi_deepcopy, x))
+d[tuple] = _semi_deepcopy_tuple
+
+def semi_deepcopy(x):
+ copier = _semi_deepcopy_dispatch.get(type(x))
+ if copier:
+ return copier(x)
+ else:
+ if hasattr(x, '__semi_deepcopy__'):
+ return x.__semi_deepcopy__()
+ elif isinstance(x, UserDict):
+ return x.__class__(_semi_deepcopy_dict(x))
+ elif isinstance(x, UserList):
+ return x.__class__(_semi_deepcopy_list(x))
+
+ return x
+
+
+
+class Proxy(object):
+ """A simple generic Proxy class, forwarding all calls to
+ subject. So, for the benefit of the python newbie, what does
+ this really mean? Well, it means that you can take an object, let's
+ call it 'objA', and wrap it in this Proxy class, with a statement
+ like this
+
+ proxyObj = Proxy(objA),
+
+ Then, if in the future, you do something like this
+
+ x = proxyObj.var1,
+
+ since Proxy does not have a 'var1' attribute (but presumably objA does),
+ the request actually is equivalent to saying
+
+ x = objA.var1
+
+ Inherit from this class to create a Proxy.
+
+ Note that, with new-style classes, this does *not* work transparently
+ for Proxy subclasses that use special .__*__() method names, because
+ those names are now bound to the class, not the individual instances.
+ You now need to know in advance which .__*__() method names you want
+ to pass on to the underlying Proxy object, and specifically delegate
+ their calls like this:
+
+ class Foo(Proxy):
+ __str__ = Delegate('__str__')
+ """
+
+ def __init__(self, subject):
+ """Wrap an object as a Proxy object"""
+ self._subject = subject
+
+ def __getattr__(self, name):
+ """Retrieve an attribute from the wrapped object. If the named
+ attribute doesn't exist, AttributeError is raised"""
+ return getattr(self._subject, name)
+
+ def get(self):
+ """Retrieve the entire wrapped object"""
+ return self._subject
+
+ def __cmp__(self, other):
+ if issubclass(other.__class__, self._subject.__class__):
+ return cmp(self._subject, other)
+ return cmp(self.__dict__, other.__dict__)
+
+class Delegate(object):
+ """A Python Descriptor class that delegates attribute fetches
+ to an underlying wrapped subject of a Proxy. Typical use:
+
+ class Foo(Proxy):
+ __str__ = Delegate('__str__')
+ """
+ def __init__(self, attribute):
+ self.attribute = attribute
+ def __get__(self, obj, cls):
+ if isinstance(obj, cls):
+ return getattr(obj._subject, self.attribute)
+ else:
+ return self
+
+# attempt to load the windows registry module:
+can_read_reg = 0
+try:
+ import winreg
+
+ can_read_reg = 1
+ hkey_mod = winreg
+
+ RegOpenKeyEx = winreg.OpenKeyEx
+ RegEnumKey = winreg.EnumKey
+ RegEnumValue = winreg.EnumValue
+ RegQueryValueEx = winreg.QueryValueEx
+ RegError = winreg.error
+
+except ImportError:
+ try:
+ import win32api
+ import win32con
+ can_read_reg = 1
+ hkey_mod = win32con
+
+ RegOpenKeyEx = win32api.RegOpenKeyEx
+ RegEnumKey = win32api.RegEnumKey
+ RegEnumValue = win32api.RegEnumValue
+ RegQueryValueEx = win32api.RegQueryValueEx
+ RegError = win32api.error
+
+ except ImportError:
+ class _NoError(Exception):
+ pass
+ RegError = _NoError
+
+if can_read_reg:
+ HKEY_CLASSES_ROOT = hkey_mod.HKEY_CLASSES_ROOT
+ HKEY_LOCAL_MACHINE = hkey_mod.HKEY_LOCAL_MACHINE
+ HKEY_CURRENT_USER = hkey_mod.HKEY_CURRENT_USER
+ HKEY_USERS = hkey_mod.HKEY_USERS
+
+ def RegGetValue(root, key):
+ """This utility function returns a value in the registry
+ without having to open the key first. Only available on
+ Windows platforms with a version of Python that can read the
+ registry. Returns the same thing as
+ SCons.Util.RegQueryValueEx, except you just specify the entire
+ path to the value, and don't have to bother opening the key
+ first. So:
+
+ Instead of:
+ k = SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE,
+ r'SOFTWARE\Microsoft\Windows\CurrentVersion')
+ out = SCons.Util.RegQueryValueEx(k,
+ 'ProgramFilesDir')
+
+ You can write:
+ out = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE,
+ r'SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramFilesDir')
+ """
+ # I would use os.path.split here, but it's not a filesystem
+ # path...
+ p = key.rfind('\\') + 1
+ keyp = key[:p-1] # -1 to omit trailing slash
+ val = key[p:]
+ k = RegOpenKeyEx(root, keyp)
+ return RegQueryValueEx(k,val)
+else:
+ try:
+ e = WindowsError
+ except NameError:
+ # Make sure we have a definition of WindowsError so we can
+ # run platform-independent tests of Windows functionality on
+ # platforms other than Windows. (WindowsError is, in fact, an
+ # OSError subclass on Windows.)
+ class WindowsError(OSError):
+ pass
+ import builtins
+ builtins.WindowsError = WindowsError
+ else:
+ del e
+
+ HKEY_CLASSES_ROOT = None
+ HKEY_LOCAL_MACHINE = None
+ HKEY_CURRENT_USER = None
+ HKEY_USERS = None
+
+ def RegGetValue(root, key):
+ raise WindowsError
+
+ def RegOpenKeyEx(root, key):
+ raise WindowsError
+
+if sys.platform == 'win32':
+
+ def WhereIs(file, path=None, pathext=None, reject=[]):
+ if path is None:
+ try:
+ path = os.environ['PATH']
+ except KeyError:
+ return None
+ if is_String(path):
+ path = path.split(os.pathsep)
+ if pathext is None:
+ try:
+ pathext = os.environ['PATHEXT']
+ except KeyError:
+ pathext = '.COM;.EXE;.BAT;.CMD'
+ if is_String(pathext):
+ pathext = pathext.split(os.pathsep)
+ for ext in pathext:
+ if ext.lower() == file[-len(ext):].lower():
+ pathext = ['']
+ break
+ if not is_List(reject) and not is_Tuple(reject):
+ reject = [reject]
+ for dir in path:
+ f = os.path.join(dir, file)
+ for ext in pathext:
+ fext = f + ext
+ if os.path.isfile(fext):
+ try:
+ reject.index(fext)
+ except ValueError:
+ return os.path.normpath(fext)
+ continue
+ return None
+
+elif os.name == 'os2':
+
+ def WhereIs(file, path=None, pathext=None, reject=[]):
+ if path is None:
+ try:
+ path = os.environ['PATH']
+ except KeyError:
+ return None
+ if is_String(path):
+ path = path.split(os.pathsep)
+ if pathext is None:
+ pathext = ['.exe', '.cmd']
+ for ext in pathext:
+ if ext.lower() == file[-len(ext):].lower():
+ pathext = ['']
+ break
+ if not is_List(reject) and not is_Tuple(reject):
+ reject = [reject]
+ for dir in path:
+ f = os.path.join(dir, file)
+ for ext in pathext:
+ fext = f + ext
+ if os.path.isfile(fext):
+ try:
+ reject.index(fext)
+ except ValueError:
+ return os.path.normpath(fext)
+ continue
+ return None
+
+else:
+
+ def WhereIs(file, path=None, pathext=None, reject=[]):
+ import stat
+ if path is None:
+ try:
+ path = os.environ['PATH']
+ except KeyError:
+ return None
+ if is_String(path):
+ path = path.split(os.pathsep)
+ if not is_List(reject) and not is_Tuple(reject):
+ reject = [reject]
+ for d in path:
+ f = os.path.join(d, file)
+ if os.path.isfile(f):
+ try:
+ st = os.stat(f)
+ except OSError:
+ # os.stat() raises OSError, not IOError if the file
+ # doesn't exist, so in this case we let IOError get
+ # raised so as to not mask possibly serious disk or
+ # network issues.
+ continue
+ if stat.S_IMODE(st[stat.ST_MODE]) & 0111:
+ try:
+ reject.index(f)
+ except ValueError:
+ return os.path.normpath(f)
+ continue
+ return None
+
+def PrependPath(oldpath, newpath, sep = os.pathsep,
+ delete_existing=1, canonicalize=None):
+ """This prepends newpath elements to the given oldpath. Will only
+ add any particular path once (leaving the first one it encounters
+ and ignoring the rest, to preserve path order), and will
+ os.path.normpath and os.path.normcase all paths to help assure
+ this. This can also handle the case where the given old path
+ variable is a list instead of a string, in which case a list will
+ be returned instead of a string.
+
+ Example:
+ Old Path: "/foo/bar:/foo"
+ New Path: "/biz/boom:/foo"
+ Result: "/biz/boom:/foo:/foo/bar"
+
+ If delete_existing is 0, then adding a path that exists will
+ not move it to the beginning; it will stay where it is in the
+ list.
+
+ If canonicalize is not None, it is applied to each element of
+ newpath before use.
+ """
+
+ orig = oldpath
+ is_list = 1
+ paths = orig
+ if not is_List(orig) and not is_Tuple(orig):
+ paths = paths.split(sep)
+ is_list = 0
+
+ if is_String(newpath):
+ newpaths = newpath.split(sep)
+ elif not is_List(newpath) and not is_Tuple(newpath):
+ newpaths = [ newpath ] # might be a Dir
+ else:
+ newpaths = newpath
+
+ if canonicalize:
+ newpaths=list(map(canonicalize, newpaths))
+
+ if not delete_existing:
+ # First uniquify the old paths, making sure to
+ # preserve the first instance (in Unix/Linux,
+ # the first one wins), and remembering them in normpaths.
+ # Then insert the new paths at the head of the list
+ # if they're not already in the normpaths list.
+ result = []
+ normpaths = []
+ for path in paths:
+ if not path:
+ continue
+ normpath = os.path.normpath(os.path.normcase(path))
+ if normpath not in normpaths:
+ result.append(path)
+ normpaths.append(normpath)
+ newpaths.reverse() # since we're inserting at the head
+ for path in newpaths:
+ if not path:
+ continue
+ normpath = os.path.normpath(os.path.normcase(path))
+ if normpath not in normpaths:
+ result.insert(0, path)
+ normpaths.append(normpath)
+ paths = result
+
+ else:
+ newpaths = newpaths + paths # prepend new paths
+
+ normpaths = []
+ paths = []
+ # now we add them only if they are unique
+ for path in newpaths:
+ normpath = os.path.normpath(os.path.normcase(path))
+ if path and not normpath in normpaths:
+ paths.append(path)
+ normpaths.append(normpath)
+
+ if is_list:
+ return paths
+ else:
+ return sep.join(paths)
+
+def AppendPath(oldpath, newpath, sep = os.pathsep,
+ delete_existing=1, canonicalize=None):
+ """This appends new path elements to the given old path. Will
+ only add any particular path once (leaving the last one it
+ encounters and ignoring the rest, to preserve path order), and
+ will os.path.normpath and os.path.normcase all paths to help
+ assure this. This can also handle the case where the given old
+ path variable is a list instead of a string, in which case a list
+ will be returned instead of a string.
+
+ Example:
+ Old Path: "/foo/bar:/foo"
+ New Path: "/biz/boom:/foo"
+ Result: "/foo/bar:/biz/boom:/foo"
+
+ If delete_existing is 0, then adding a path that exists
+ will not move it to the end; it will stay where it is in the list.
+
+ If canonicalize is not None, it is applied to each element of
+ newpath before use.
+ """
+
+ orig = oldpath
+ is_list = 1
+ paths = orig
+ if not is_List(orig) and not is_Tuple(orig):
+ paths = paths.split(sep)
+ is_list = 0
+
+ if is_String(newpath):
+ newpaths = newpath.split(sep)
+ elif not is_List(newpath) and not is_Tuple(newpath):
+ newpaths = [ newpath ] # might be a Dir
+ else:
+ newpaths = newpath
+
+ if canonicalize:
+ newpaths=list(map(canonicalize, newpaths))
+
+ if not delete_existing:
+ # add old paths to result, then
+ # add new paths if not already present
+ # (I thought about using a dict for normpaths for speed,
+ # but it's not clear hashing the strings would be faster
+ # than linear searching these typically short lists.)
+ result = []
+ normpaths = []
+ for path in paths:
+ if not path:
+ continue
+ result.append(path)
+ normpaths.append(os.path.normpath(os.path.normcase(path)))
+ for path in newpaths:
+ if not path:
+ continue
+ normpath = os.path.normpath(os.path.normcase(path))
+ if normpath not in normpaths:
+ result.append(path)
+ normpaths.append(normpath)
+ paths = result
+ else:
+ # start w/ new paths, add old ones if not present,
+ # then reverse.
+ newpaths = paths + newpaths # append new paths
+ newpaths.reverse()
+
+ normpaths = []
+ paths = []
+ # now we add them only if they are unique
+ for path in newpaths:
+ normpath = os.path.normpath(os.path.normcase(path))
+ if path and not normpath in normpaths:
+ paths.append(path)
+ normpaths.append(normpath)
+ paths.reverse()
+
+ if is_list:
+ return paths
+ else:
+ return sep.join(paths)
+
+if sys.platform == 'cygwin':
+ def get_native_path(path):
+ """Transforms an absolute path into a native path for the system. In
+ Cygwin, this converts from a Cygwin path to a Windows one."""
+ return os.popen('cygpath -w ' + path).read().replace('\n', '')
+else:
+ def get_native_path(path):
+ """Transforms an absolute path into a native path for the system.
+ Non-Cygwin version, just leave the path alone."""
+ return path
+
+display = DisplayEngine()
+
+def Split(arg):
+ if is_List(arg) or is_Tuple(arg):
+ return arg
+ elif is_String(arg):
+ return arg.split()
+ else:
+ return [arg]
+
+class CLVar(UserList):
+ """A class for command-line construction variables.
+
+ This is a list that uses Split() to split an initial string along
+ white-space arguments, and similarly to split any strings that get
+ added. This allows us to Do the Right Thing with Append() and
+ Prepend() (as well as straight Python foo = env['VAR'] + 'arg1
+ arg2') regardless of whether a user adds a list or a string to a
+ command-line construction variable.
+ """
+ def __init__(self, seq = []):
+ UserList.__init__(self, Split(seq))
+ def __add__(self, other):
+ return UserList.__add__(self, CLVar(other))
+ def __radd__(self, other):
+ return UserList.__radd__(self, CLVar(other))
+ def __coerce__(self, other):
+ return (self, CLVar(other))
+ def __str__(self):
+ return ' '.join(self.data)
+
+# A dictionary that preserves the order in which items are added.
+# Submitted by David Benjamin to ActiveState's Python Cookbook web site:
+# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747
+# Including fixes/enhancements from the follow-on discussions.
+class OrderedDict(UserDict):
+ def __init__(self, dict = None):
+ self._keys = []
+ UserDict.__init__(self, dict)
+
+ def __delitem__(self, key):
+ UserDict.__delitem__(self, key)
+ self._keys.remove(key)
+
+ def __setitem__(self, key, item):
+ UserDict.__setitem__(self, key, item)
+ if key not in self._keys: self._keys.append(key)
+
+ def clear(self):
+ UserDict.clear(self)
+ self._keys = []
+
+ def copy(self):
+ dict = OrderedDict()
+ dict.update(self)
+ return dict
+
+ def items(self):
+ return list(zip(self._keys, list(self.values())))
+
+ def keys(self):
+ return self._keys[:]
+
+ def popitem(self):
+ try:
+ key = self._keys[-1]
+ except IndexError:
+ raise KeyError('dictionary is empty')
+
+ val = self[key]
+ del self[key]
+
+ return (key, val)
+
+ def setdefault(self, key, failobj = None):
+ UserDict.setdefault(self, key, failobj)
+ if key not in self._keys: self._keys.append(key)
+
+ def update(self, dict):
+ for (key, val) in dict.items():
+ self.__setitem__(key, val)
+
+ def values(self):
+ return list(map(self.get, self._keys))
+
+class Selector(OrderedDict):
+ """A callable ordered dictionary that maps file suffixes to
+ dictionary values. We preserve the order in which items are added
+ so that get_suffix() calls always return the first suffix added."""
+ def __call__(self, env, source, ext=None):
+ if ext is None:
+ try:
+ ext = source[0].suffix
+ except IndexError:
+ ext = ""
+ try:
+ return self[ext]
+ except KeyError:
+ # Try to perform Environment substitution on the keys of
+ # the dictionary before giving up.
+ s_dict = {}
+ for (k,v) in self.items():
+ if k is not None:
+ s_k = env.subst(k)
+ if s_k in s_dict:
+ # We only raise an error when variables point
+ # to the same suffix. If one suffix is literal
+ # and a variable suffix contains this literal,
+ # the literal wins and we don't raise an error.
+ raise KeyError(s_dict[s_k][0], k, s_k)
+ s_dict[s_k] = (k,v)
+ try:
+ return s_dict[ext][1]
+ except KeyError:
+ try:
+ return self[None]
+ except KeyError:
+ return None
+
+
+if sys.platform == 'cygwin':
+ # On Cygwin, os.path.normcase() lies, so just report back the
+ # fact that the underlying Windows OS is case-insensitive.
+ def case_sensitive_suffixes(s1, s2):
+ return 0
+else:
+ def case_sensitive_suffixes(s1, s2):
+ return (os.path.normcase(s1) != os.path.normcase(s2))
+
+def adjustixes(fname, pre, suf, ensure_suffix=False):
+ if pre:
+ path, fn = os.path.split(os.path.normpath(fname))
+ if fn[:len(pre)] != pre:
+ fname = os.path.join(path, pre + fn)
+ # Only append a suffix if the suffix we're going to add isn't already
+ # there, and if either we've been asked to ensure the specific suffix
+ # is present or there's no suffix on it at all.
+ if suf and fname[-len(suf):] != suf and \
+ (ensure_suffix or not splitext(fname)[1]):
+ fname = fname + suf
+ return fname
+
+
+
+# From Tim Peters,
+# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560
+# ASPN: Python Cookbook: Remove duplicates from a sequence
+# (Also in the printed Python Cookbook.)
+
+def unique(s):
+ """Return a list of the elements in s, but without duplicates.
+
+ For example, unique([1,2,3,1,2,3]) is some permutation of [1,2,3],
+ unique("abcabc") some permutation of ["a", "b", "c"], and
+ unique(([1, 2], [2, 3], [1, 2])) some permutation of
+ [[2, 3], [1, 2]].
+
+ For best speed, all sequence elements should be hashable. Then
+ unique() will usually work in linear time.
+
+ If not possible, the sequence elements should enjoy a total
+ ordering, and if list(s).sort() doesn't raise TypeError it's
+ assumed that they do enjoy a total ordering. Then unique() will
+ usually work in O(N*log2(N)) time.
+
+ If that's not possible either, the sequence elements must support
+ equality-testing. Then unique() will usually work in quadratic
+ time.
+ """
+
+ n = len(s)
+ if n == 0:
+ return []
+
+ # Try using a dict first, as that's the fastest and will usually
+ # work. If it doesn't work, it will usually fail quickly, so it
+ # usually doesn't cost much to *try* it. It requires that all the
+ # sequence elements be hashable, and support equality comparison.
+ u = {}
+ try:
+ for x in s:
+ u[x] = 1
+ except TypeError:
+ pass # move on to the next method
+ else:
+ return list(u.keys())
+ del u
+
+ # We can't hash all the elements. Second fastest is to sort,
+ # which brings the equal elements together; then duplicates are
+ # easy to weed out in a single pass.
+ # NOTE: Python's list.sort() was designed to be efficient in the
+ # presence of many duplicate elements. This isn't true of all
+ # sort functions in all languages or libraries, so this approach
+ # is more effective in Python than it may be elsewhere.
+ try:
+ t = sorted(s)
+ except TypeError:
+ pass # move on to the next method
+ else:
+ assert n > 0
+ last = t[0]
+ lasti = i = 1
+ while i < n:
+ if t[i] != last:
+ t[lasti] = last = t[i]
+ lasti = lasti + 1
+ i = i + 1
+ return t[:lasti]
+ del t
+
+ # Brute force is all that's left.
+ u = []
+ for x in s:
+ if x not in u:
+ u.append(x)
+ return u
+
+
+
+# From Alex Martelli,
+# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560
+# ASPN: Python Cookbook: Remove duplicates from a sequence
+# First comment, dated 2001/10/13.
+# (Also in the printed Python Cookbook.)
+
+def uniquer(seq, idfun=None):
+ if idfun is None:
+ def idfun(x): return x
+ seen = {}
+ result = []
+ for item in seq:
+ marker = idfun(item)
+ # in old Python versions:
+ # if seen.has_key(marker)
+ # but in new ones:
+ if marker in seen: continue
+ seen[marker] = 1
+ result.append(item)
+ return result
+
+# A more efficient implementation of Alex's uniquer(), this avoids the
+# idfun() argument and function-call overhead by assuming that all
+# items in the sequence are hashable.
+
+def uniquer_hashables(seq):
+ seen = {}
+ result = []
+ for item in seq:
+ #if not item in seen:
+ if item not in seen:
+ seen[item] = 1
+ result.append(item)
+ return result
+
+
+
+# Much of the logic here was originally based on recipe 4.9 from the
+# Python CookBook, but we had to dumb it way down for Python 1.5.2.
+class LogicalLines(object):
+
+ def __init__(self, fileobj):
+ self.fileobj = fileobj
+
+ def readline(self):
+ result = []
+ while True:
+ line = self.fileobj.readline()
+ if not line:
+ break
+ if line[-2:] == '\\\n':
+ result.append(line[:-2])
+ else:
+ result.append(line)
+ break
+ return ''.join(result)
+
+ def readlines(self):
+ result = []
+ while True:
+ line = self.readline()
+ if not line:
+ break
+ result.append(line)
+ return result
+
+
+
+class UniqueList(UserList):
+ def __init__(self, seq = []):
+ UserList.__init__(self, seq)
+ self.unique = True
+ def __make_unique(self):
+ if not self.unique:
+ self.data = uniquer_hashables(self.data)
+ self.unique = True
+ def __lt__(self, other):
+ self.__make_unique()
+ return UserList.__lt__(self, other)
+ def __le__(self, other):
+ self.__make_unique()
+ return UserList.__le__(self, other)
+ def __eq__(self, other):
+ self.__make_unique()
+ return UserList.__eq__(self, other)
+ def __ne__(self, other):
+ self.__make_unique()
+ return UserList.__ne__(self, other)
+ def __gt__(self, other):
+ self.__make_unique()
+ return UserList.__gt__(self, other)
+ def __ge__(self, other):
+ self.__make_unique()
+ return UserList.__ge__(self, other)
+ def __cmp__(self, other):
+ self.__make_unique()
+ return UserList.__cmp__(self, other)
+ def __len__(self):
+ self.__make_unique()
+ return UserList.__len__(self)
+ def __getitem__(self, i):
+ self.__make_unique()
+ return UserList.__getitem__(self, i)
+ def __setitem__(self, i, item):
+ UserList.__setitem__(self, i, item)
+ self.unique = False
+ def __getslice__(self, i, j):
+ self.__make_unique()
+ return UserList.__getslice__(self, i, j)
+ def __setslice__(self, i, j, other):
+ UserList.__setslice__(self, i, j, other)
+ self.unique = False
+ def __add__(self, other):
+ result = UserList.__add__(self, other)
+ result.unique = False
+ return result
+ def __radd__(self, other):
+ result = UserList.__radd__(self, other)
+ result.unique = False
+ return result
+ def __iadd__(self, other):
+ result = UserList.__iadd__(self, other)
+ result.unique = False
+ return result
+ def __mul__(self, other):
+ result = UserList.__mul__(self, other)
+ result.unique = False
+ return result
+ def __rmul__(self, other):
+ result = UserList.__rmul__(self, other)
+ result.unique = False
+ return result
+ def __imul__(self, other):
+ result = UserList.__imul__(self, other)
+ result.unique = False
+ return result
+ def append(self, item):
+ UserList.append(self, item)
+ self.unique = False
+ def insert(self, i):
+ UserList.insert(self, i)
+ self.unique = False
+ def count(self, item):
+ self.__make_unique()
+ return UserList.count(self, item)
+ def index(self, item):
+ self.__make_unique()
+ return UserList.index(self, item)
+ def reverse(self):
+ self.__make_unique()
+ UserList.reverse(self)
+ def sort(self, *args, **kwds):
+ self.__make_unique()
+ return UserList.sort(self, *args, **kwds)
+ def extend(self, other):
+ UserList.extend(self, other)
+ self.unique = False
+
+
+class Unbuffered(object):
+ """
+ A proxy class that wraps a file object, flushing after every write,
+ and delegating everything else to the wrapped object.
+ """
+ def __init__(self, file):
+ self.file = file
+ self.softspace = 0 ## backward compatibility; not supported in Py3k
+ def write(self, arg):
+ try:
+ self.file.write(arg)
+ self.file.flush()
+ except IOError:
+ # Stdout might be connected to a pipe that has been closed
+ # by now. The most likely reason for the pipe being closed
+ # is that the user has press ctrl-c. It this is the case,
+ # then SCons is currently shutdown. We therefore ignore
+ # IOError's here so that SCons can continue and shutdown
+ # properly so that the .sconsign is correctly written
+ # before SCons exits.
+ pass
+ def __getattr__(self, attr):
+ return getattr(self.file, attr)
+
+def make_path_relative(path):
+ """ makes an absolute path name to a relative pathname.
+ """
+ if os.path.isabs(path):
+ drive_s,path = os.path.splitdrive(path)
+
+ import re
+ if not drive_s:
+ path=re.compile("/*(.*)").findall(path)[0]
+ else:
+ path=path[1:]
+
+ assert( not os.path.isabs( path ) ), path
+ return path
+
+
+
+# The original idea for AddMethod() and RenameFunction() come from the
+# following post to the ActiveState Python Cookbook:
+#
+# ASPN: Python Cookbook : Install bound methods in an instance
+# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/223613
+#
+# That code was a little fragile, though, so the following changes
+# have been wrung on it:
+#
+# * Switched the installmethod() "object" and "function" arguments,
+# so the order reflects that the left-hand side is the thing being
+# "assigned to" and the right-hand side is the value being assigned.
+#
+# * Changed explicit type-checking to the "try: klass = object.__class__"
+# block in installmethod() below so that it still works with the
+# old-style classes that SCons uses.
+#
+# * Replaced the by-hand creation of methods and functions with use of
+# the "new" module, as alluded to in Alex Martelli's response to the
+# following Cookbook post:
+#
+# ASPN: Python Cookbook : Dynamically added methods to a class
+# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81732
+
+def AddMethod(obj, function, name=None):
+ """
+ Adds either a bound method to an instance or an unbound method to
+ a class. If name is ommited the name of the specified function
+ is used by default.
+ Example:
+ a = A()
+ def f(self, x, y):
+ self.z = x + y
+ AddMethod(f, A, "add")
+ a.add(2, 4)
+ print a.z
+ AddMethod(lambda self, i: self.l[i], a, "listIndex")
+ print a.listIndex(5)
+ """
+ if name is None:
+ name = function.func_name
+ else:
+ function = RenameFunction(function, name)
+
+ if hasattr(obj, '__class__') and obj.__class__ is not type:
+ # "obj" is an instance, so it gets a bound method.
+ setattr(obj, name, MethodType(function, obj, obj.__class__))
+ else:
+ # "obj" is a class, so it gets an unbound method.
+ setattr(obj, name, MethodType(function, None, obj))
+
+def RenameFunction(function, name):
+ """
+ Returns a function identical to the specified function, but with
+ the specified name.
+ """
+ return FunctionType(function.func_code,
+ function.func_globals,
+ name,
+ function.func_defaults)
+
+
+md5 = False
+def MD5signature(s):
+ return str(s)
+
+def MD5filesignature(fname, chunksize=65536):
+ f = open(fname, "rb")
+ result = f.read()
+ f.close()
+ return result
+
+try:
+ import hashlib
+except ImportError:
+ pass
+else:
+ if hasattr(hashlib, 'md5'):
+ md5 = True
+ def MD5signature(s):
+ m = hashlib.md5()
+ m.update(str(s))
+ return m.hexdigest()
+
+ def MD5filesignature(fname, chunksize=65536):
+ m = hashlib.md5()
+ f = open(fname, "rb")
+ while True:
+ blck = f.read(chunksize)
+ if not blck:
+ break
+ m.update(str(blck))
+ f.close()
+ return m.hexdigest()
+
+def MD5collect(signatures):
+ """
+ Collects a list of signatures into an aggregate signature.
+
+ signatures - a list of signatures
+ returns - the aggregate signature
+ """
+ if len(signatures) == 1:
+ return signatures[0]
+ else:
+ return MD5signature(', '.join(signatures))
+
+
+
+def silent_intern(x):
+ """
+ Perform sys.intern() on the passed argument and return the result.
+ If the input is ineligible (e.g. a unicode string) the original argument is
+ returned and no exception is thrown.
+ """
+ try:
+ return sys.intern(x)
+ except TypeError:
+ return x
+
+
+
+# From Dinu C. Gherman,
+# Python Cookbook, second edition, recipe 6.17, p. 277.
+# Also:
+# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/68205
+# ASPN: Python Cookbook: Null Object Design Pattern
+
+#TODO??? class Null(object):
+class Null(object):
+ """ Null objects always and reliably "do nothing." """
+ def __new__(cls, *args, **kwargs):
+ if not '_instance' in vars(cls):
+ cls._instance = super(Null, cls).__new__(cls, *args, **kwargs)
+ return cls._instance
+ def __init__(self, *args, **kwargs):
+ pass
+ def __call__(self, *args, **kwargs):
+ return self
+ def __repr__(self):
+ return "Null(0x%08X)" % id(self)
+ def __nonzero__(self):
+ return False
+ def __getattr__(self, name):
+ return self
+ def __setattr__(self, name, value):
+ return self
+ def __delattr__(self, name):
+ return self
+
+class NullSeq(Null):
+ def __len__(self):
+ return 0
+ def __iter__(self):
+ return iter(())
+ def __getitem__(self, i):
+ return self
+ def __delitem__(self, i):
+ return self
+ def __setitem__(self, i, v):
+ return self
+
+
+del __revision__
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Variables/BoolVariable.py b/couchjs/scons/scons-local-2.0.1/SCons/Variables/BoolVariable.py
new file mode 100644
index 00000000..f41537b5
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Variables/BoolVariable.py
@@ -0,0 +1,89 @@
+"""engine.SCons.Variables.BoolVariable
+
+This file defines the option type for SCons implementing true/false values.
+
+Usage example:
+
+ opts = Variables()
+ opts.Add(BoolVariable('embedded', 'build for an embedded system', 0))
+ ...
+ if env['embedded'] == 1:
+ ...
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Variables/BoolVariable.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__all__ = ['BoolVariable',]
+
+import SCons.Errors
+
+__true_strings = ('y', 'yes', 'true', 't', '1', 'on' , 'all' )
+__false_strings = ('n', 'no', 'false', 'f', '0', 'off', 'none')
+
+
+def _text2bool(val):
+ """
+ Converts strings to True/False depending on the 'truth' expressed by
+ the string. If the string can't be converted, the original value
+ will be returned.
+
+ See '__true_strings' and '__false_strings' for values considered
+ 'true' or 'false respectivly.
+
+ This is usable as 'converter' for SCons' Variables.
+ """
+ lval = val.lower()
+ if lval in __true_strings: return True
+ if lval in __false_strings: return False
+ raise ValueError("Invalid value for boolean option: %s" % val)
+
+
+def _validator(key, val, env):
+ """
+ Validates the given value to be either '0' or '1'.
+
+ This is usable as 'validator' for SCons' Variables.
+ """
+ if not env[key] in (True, False):
+ raise SCons.Errors.UserError(
+ 'Invalid value for boolean option %s: %s' % (key, env[key]))
+
+
+def BoolVariable(key, help, default):
+ """
+ The input parameters describe a boolen option, thus they are
+ returned with the correct converter and validator appended. The
+ 'help' text will by appended by '(yes|no) to show the valid
+ valued. The result is usable for input to opts.Add().
+ """
+ return (key, '%s (yes|no)' % help, default,
+ _validator, _text2bool)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Variables/EnumVariable.py b/couchjs/scons/scons-local-2.0.1/SCons/Variables/EnumVariable.py
new file mode 100644
index 00000000..c9cdbb74
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Variables/EnumVariable.py
@@ -0,0 +1,103 @@
+"""engine.SCons.Variables.EnumVariable
+
+This file defines the option type for SCons allowing only specified
+input-values.
+
+Usage example:
+
+ opts = Variables()
+ opts.Add(EnumVariable('debug', 'debug output and symbols', 'no',
+ allowed_values=('yes', 'no', 'full'),
+ map={}, ignorecase=2))
+ ...
+ if env['debug'] == 'full':
+ ...
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Variables/EnumVariable.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__all__ = ['EnumVariable',]
+
+
+import SCons.Errors
+
+def _validator(key, val, env, vals):
+ if not val in vals:
+ raise SCons.Errors.UserError(
+ 'Invalid value for option %s: %s' % (key, val))
+
+
+def EnumVariable(key, help, default, allowed_values, map={}, ignorecase=0):
+ """
+ The input parameters describe a option with only certain values
+ allowed. They are returned with an appropriate converter and
+ validator appended. The result is usable for input to
+ Variables.Add().
+
+ 'key' and 'default' are the values to be passed on to Variables.Add().
+
+ 'help' will be appended by the allowed values automatically
+
+ 'allowed_values' is a list of strings, which are allowed as values
+ for this option.
+
+ The 'map'-dictionary may be used for converting the input value
+ into canonical values (eg. for aliases).
+
+ 'ignorecase' defines the behaviour of the validator:
+
+ If ignorecase == 0, the validator/converter are case-sensitive.
+ If ignorecase == 1, the validator/converter are case-insensitive.
+ If ignorecase == 2, the validator/converter is case-insensitive and
+ the converted value will always be lower-case.
+
+ The 'validator' tests whether the value is in the list of allowed
+ values. The 'converter' converts input values according to the
+ given 'map'-dictionary (unmapped input values are returned
+ unchanged).
+ """
+ help = '%s (%s)' % (help, '|'.join(allowed_values))
+ # define validator
+ if ignorecase >= 1:
+ validator = lambda key, val, env: \
+ _validator(key, val.lower(), env, allowed_values)
+ else:
+ validator = lambda key, val, env: \
+ _validator(key, val, env, allowed_values)
+ # define converter
+ if ignorecase == 2:
+ converter = lambda val: map.get(val.lower(), val).lower()
+ elif ignorecase == 1:
+ converter = lambda val: map.get(val.lower(), val)
+ else:
+ converter = lambda val: map.get(val, val)
+ return (key, help, default, validator, converter)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Variables/ListVariable.py b/couchjs/scons/scons-local-2.0.1/SCons/Variables/ListVariable.py
new file mode 100644
index 00000000..8f28706d
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Variables/ListVariable.py
@@ -0,0 +1,135 @@
+"""engine.SCons.Variables.ListVariable
+
+This file defines the option type for SCons implementing 'lists'.
+
+A 'list' option may either be 'all', 'none' or a list of names
+separated by comma. After the option has been processed, the option
+value holds either the named list elements, all list elemens or no
+list elements at all.
+
+Usage example:
+
+ list_of_libs = Split('x11 gl qt ical')
+
+ opts = Variables()
+ opts.Add(ListVariable('shared',
+ 'libraries to build as shared libraries',
+ 'all',
+ elems = list_of_libs))
+ ...
+ for lib in list_of_libs:
+ if lib in env['shared']:
+ env.SharedObject(...)
+ else:
+ env.Object(...)
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Variables/ListVariable.py 5134 2010/08/16 23:02:40 bdeegan"
+
+# Know Bug: This should behave like a Set-Type, but does not really,
+# since elements can occur twice.
+
+__all__ = ['ListVariable',]
+
+import collections
+
+import SCons.Util
+
+
+class _ListVariable(collections.UserList):
+ def __init__(self, initlist=[], allowedElems=[]):
+ collections.UserList.__init__(self, [_f for _f in initlist if _f])
+ self.allowedElems = sorted(allowedElems)
+
+ def __cmp__(self, other):
+ raise NotImplementedError
+ def __eq__(self, other):
+ raise NotImplementedError
+ def __ge__(self, other):
+ raise NotImplementedError
+ def __gt__(self, other):
+ raise NotImplementedError
+ def __le__(self, other):
+ raise NotImplementedError
+ def __lt__(self, other):
+ raise NotImplementedError
+ def __str__(self):
+ if len(self) == 0:
+ return 'none'
+ self.data.sort()
+ if self.data == self.allowedElems:
+ return 'all'
+ else:
+ return ','.join(self)
+ def prepare_to_store(self):
+ return self.__str__()
+
+def _converter(val, allowedElems, mapdict):
+ """
+ """
+ if val == 'none':
+ val = []
+ elif val == 'all':
+ val = allowedElems
+ else:
+ val = [_f for _f in val.split(',') if _f]
+ val = [mapdict.get(v, v) for v in val]
+ notAllowed = [v for v in val if not v in allowedElems]
+ if notAllowed:
+ raise ValueError("Invalid value(s) for option: %s" %
+ ','.join(notAllowed))
+ return _ListVariable(val, allowedElems)
+
+
+## def _validator(key, val, env):
+## """
+## """
+## # todo: write validater for pgk list
+## return 1
+
+
+def ListVariable(key, help, default, names, map={}):
+ """
+ The input parameters describe a 'package list' option, thus they
+ are returned with the correct converter and validater appended. The
+ result is usable for input to opts.Add() .
+
+ A 'package list' option may either be 'all', 'none' or a list of
+ package names (separated by space).
+ """
+ names_str = 'allowed names: %s' % ' '.join(names)
+ if SCons.Util.is_List(default):
+ default = ','.join(default)
+ help = '\n '.join(
+ (help, '(all|none|comma-separated list of names)', names_str))
+ return (key, help, default,
+ None, #_validator,
+ lambda val: _converter(val, names, map))
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Variables/PackageVariable.py b/couchjs/scons/scons-local-2.0.1/SCons/Variables/PackageVariable.py
new file mode 100644
index 00000000..c8bfeb83
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Variables/PackageVariable.py
@@ -0,0 +1,106 @@
+"""engine.SCons.Variables.PackageVariable
+
+This file defines the option type for SCons implementing 'package
+activation'.
+
+To be used whenever a 'package' may be enabled/disabled and the
+package path may be specified.
+
+Usage example:
+
+ Examples:
+ x11=no (disables X11 support)
+ x11=yes (will search for the package installation dir)
+ x11=/usr/local/X11 (will check this path for existance)
+
+ To replace autoconf's --with-xxx=yyy
+
+ opts = Variables()
+ opts.Add(PackageVariable('x11',
+ 'use X11 installed here (yes = search some places',
+ 'yes'))
+ ...
+ if env['x11'] == True:
+ dir = ... search X11 in some standard places ...
+ env['x11'] = dir
+ if env['x11']:
+ ... build with x11 ...
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Variables/PackageVariable.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__all__ = ['PackageVariable',]
+
+import SCons.Errors
+
+__enable_strings = ('1', 'yes', 'true', 'on', 'enable', 'search')
+__disable_strings = ('0', 'no', 'false', 'off', 'disable')
+
+def _converter(val):
+ """
+ """
+ lval = val.lower()
+ if lval in __enable_strings: return True
+ if lval in __disable_strings: return False
+ #raise ValueError("Invalid value for boolean option: %s" % val)
+ return val
+
+
+def _validator(key, val, env, searchfunc):
+ # NB: searchfunc is currenty undocumented and unsupported
+ """
+ """
+ # todo: write validator, check for path
+ import os
+ if env[key] is True:
+ if searchfunc:
+ env[key] = searchfunc(key, val)
+ elif env[key] and not os.path.exists(val):
+ raise SCons.Errors.UserError(
+ 'Path does not exist for option %s: %s' % (key, val))
+
+
+def PackageVariable(key, help, default, searchfunc=None):
+ # NB: searchfunc is currenty undocumented and unsupported
+ """
+ The input parameters describe a 'package list' option, thus they
+ are returned with the correct converter and validator appended. The
+ result is usable for input to opts.Add() .
+
+ A 'package list' option may either be 'all', 'none' or a list of
+ package names (seperated by space).
+ """
+ help = '\n '.join(
+ (help, '( yes | no | /path/to/%s )' % key))
+ return (key, help, default,
+ lambda k, v, e: _validator(k,v,e,searchfunc),
+ _converter)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Variables/PathVariable.py b/couchjs/scons/scons-local-2.0.1/SCons/Variables/PathVariable.py
new file mode 100644
index 00000000..0cf8cd35
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Variables/PathVariable.py
@@ -0,0 +1,147 @@
+"""SCons.Variables.PathVariable
+
+This file defines an option type for SCons implementing path settings.
+
+To be used whenever a a user-specified path override should be allowed.
+
+Arguments to PathVariable are:
+ option-name = name of this option on the command line (e.g. "prefix")
+ option-help = help string for option
+ option-dflt = default value for this option
+ validator = [optional] validator for option value. Predefined
+ validators are:
+
+ PathAccept -- accepts any path setting; no validation
+ PathIsDir -- path must be an existing directory
+ PathIsDirCreate -- path must be a dir; will create
+ PathIsFile -- path must be a file
+ PathExists -- path must exist (any type) [default]
+
+ The validator is a function that is called and which
+ should return True or False to indicate if the path
+ is valid. The arguments to the validator function
+ are: (key, val, env). The key is the name of the
+ option, the val is the path specified for the option,
+ and the env is the env to which the Otions have been
+ added.
+
+Usage example:
+
+ Examples:
+ prefix=/usr/local
+
+ opts = Variables()
+
+ opts = Variables()
+ opts.Add(PathVariable('qtdir',
+ 'where the root of Qt is installed',
+ qtdir, PathIsDir))
+ opts.Add(PathVariable('qt_includes',
+ 'where the Qt includes are installed',
+ '$qtdir/includes', PathIsDirCreate))
+ opts.Add(PathVariable('qt_libraries',
+ 'where the Qt library is installed',
+ '$qtdir/lib'))
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/Variables/PathVariable.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__all__ = ['PathVariable',]
+
+import os
+import os.path
+
+import SCons.Errors
+
+class _PathVariableClass(object):
+
+ def PathAccept(self, key, val, env):
+ """Accepts any path, no checking done."""
+ pass
+
+ def PathIsDir(self, key, val, env):
+ """Validator to check if Path is a directory."""
+ if not os.path.isdir(val):
+ if os.path.isfile(val):
+ m = 'Directory path for option %s is a file: %s'
+ else:
+ m = 'Directory path for option %s does not exist: %s'
+ raise SCons.Errors.UserError(m % (key, val))
+
+ def PathIsDirCreate(self, key, val, env):
+ """Validator to check if Path is a directory,
+ creating it if it does not exist."""
+ if os.path.isfile(val):
+ m = 'Path for option %s is a file, not a directory: %s'
+ raise SCons.Errors.UserError(m % (key, val))
+ if not os.path.isdir(val):
+ os.makedirs(val)
+
+ def PathIsFile(self, key, val, env):
+ """validator to check if Path is a file"""
+ if not os.path.isfile(val):
+ if os.path.isdir(val):
+ m = 'File path for option %s is a directory: %s'
+ else:
+ m = 'File path for option %s does not exist: %s'
+ raise SCons.Errors.UserError(m % (key, val))
+
+ def PathExists(self, key, val, env):
+ """validator to check if Path exists"""
+ if not os.path.exists(val):
+ m = 'Path for option %s does not exist: %s'
+ raise SCons.Errors.UserError(m % (key, val))
+
+ def __call__(self, key, help, default, validator=None):
+ # NB: searchfunc is currenty undocumented and unsupported
+ """
+ The input parameters describe a 'path list' option, thus they
+ are returned with the correct converter and validator appended. The
+ result is usable for input to opts.Add() .
+
+ The 'default' option specifies the default path to use if the
+ user does not specify an override with this option.
+
+ validator is a validator, see this file for examples
+ """
+ if validator is None:
+ validator = self.PathExists
+
+ if SCons.Util.is_List(key) or SCons.Util.is_Tuple(key):
+ return (key, '%s ( /path/to/%s )' % (help, key[0]), default,
+ validator, None)
+ else:
+ return (key, '%s ( /path/to/%s )' % (help, key), default,
+ validator, None)
+
+PathVariable = _PathVariableClass()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Variables/__init__.py b/couchjs/scons/scons-local-2.0.1/SCons/Variables/__init__.py
new file mode 100644
index 00000000..a2c42187
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Variables/__init__.py
@@ -0,0 +1,312 @@
+"""engine.SCons.Variables
+
+This file defines the Variables class that is used to add user-friendly
+customizable variables to an SCons build.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/engine/SCons/Variables/__init__.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os.path
+import sys
+
+import SCons.Environment
+import SCons.Errors
+import SCons.Util
+import SCons.Warnings
+
+from BoolVariable import BoolVariable # okay
+from EnumVariable import EnumVariable # okay
+from ListVariable import ListVariable # naja
+from PackageVariable import PackageVariable # naja
+from PathVariable import PathVariable # okay
+
+
+class Variables(object):
+ instance=None
+
+ """
+ Holds all the options, updates the environment with the variables,
+ and renders the help text.
+ """
+ def __init__(self, files=[], args={}, is_global=1):
+ """
+ files - [optional] List of option configuration files to load
+ (backward compatibility) If a single string is passed it is
+ automatically placed in a file list
+ """
+ self.options = []
+ self.args = args
+ if not SCons.Util.is_List(files):
+ if files:
+ files = [ files ]
+ else:
+ files = []
+ self.files = files
+ self.unknown = {}
+
+ # create the singleton instance
+ if is_global:
+ self=Variables.instance
+
+ if not Variables.instance:
+ Variables.instance=self
+
+ def _do_add(self, key, help="", default=None, validator=None, converter=None):
+ class Variable(object):
+ pass
+
+ option = Variable()
+
+ # if we get a list or a tuple, we take the first element as the
+ # option key and store the remaining in aliases.
+ if SCons.Util.is_List(key) or SCons.Util.is_Tuple(key):
+ option.key = key[0]
+ option.aliases = key[1:]
+ else:
+ option.key = key
+ option.aliases = [ key ]
+ option.help = help
+ option.default = default
+ option.validator = validator
+ option.converter = converter
+
+ self.options.append(option)
+
+ # options might be added after the 'unknown' dict has been set up,
+ # so we remove the key and all its aliases from that dict
+ for alias in list(option.aliases) + [ option.key ]:
+ if alias in self.unknown:
+ del self.unknown[alias]
+
+ def keys(self):
+ """
+ Returns the keywords for the options
+ """
+ return [o.key for o in self.options]
+
+ def Add(self, key, help="", default=None, validator=None, converter=None, **kw):
+ """
+ Add an option.
+
+ key - the name of the variable, or a list or tuple of arguments
+ help - optional help text for the options
+ default - optional default value
+ validator - optional function that is called to validate the option's value
+ Called with (key, value, environment)
+ converter - optional function that is called to convert the option's value before
+ putting it in the environment.
+ """
+
+ if SCons.Util.is_List(key) or isinstance(key, tuple):
+ self._do_add(*key)
+ return
+
+ if not SCons.Util.is_String(key) or \
+ not SCons.Environment.is_valid_construction_var(key):
+ raise SCons.Errors.UserError("Illegal Variables.Add() key `%s'" % str(key))
+
+ self._do_add(key, help, default, validator, converter)
+
+ def AddVariables(self, *optlist):
+ """
+ Add a list of options.
+
+ Each list element is a tuple/list of arguments to be passed on
+ to the underlying method for adding options.
+
+ Example:
+ opt.AddVariables(
+ ('debug', '', 0),
+ ('CC', 'The C compiler'),
+ ('VALIDATE', 'An option for testing validation', 'notset',
+ validator, None),
+ )
+ """
+ for o in optlist:
+ self._do_add(*o)
+
+
+ def Update(self, env, args=None):
+ """
+ Update an environment with the option variables.
+
+ env - the environment to update.
+ """
+
+ values = {}
+
+ # first set the defaults:
+ for option in self.options:
+ if not option.default is None:
+ values[option.key] = option.default
+
+ # next set the value specified in the options file
+ for filename in self.files:
+ if os.path.exists(filename):
+ dir = os.path.split(os.path.abspath(filename))[0]
+ if dir:
+ sys.path.insert(0, dir)
+ try:
+ values['__name__'] = filename
+ exec open(filename, 'rU').read() in {}, values
+ finally:
+ if dir:
+ del sys.path[0]
+ del values['__name__']
+
+ # set the values specified on the command line
+ if args is None:
+ args = self.args
+
+ for arg, value in args.items():
+ added = False
+ for option in self.options:
+ if arg in list(option.aliases) + [ option.key ]:
+ values[option.key] = value
+ added = True
+ if not added:
+ self.unknown[arg] = value
+
+ # put the variables in the environment:
+ # (don't copy over variables that are not declared as options)
+ for option in self.options:
+ try:
+ env[option.key] = values[option.key]
+ except KeyError:
+ pass
+
+ # Call the convert functions:
+ for option in self.options:
+ if option.converter and option.key in values:
+ value = env.subst('${%s}'%option.key)
+ try:
+ try:
+ env[option.key] = option.converter(value)
+ except TypeError:
+ env[option.key] = option.converter(value, env)
+ except ValueError, x:
+ raise SCons.Errors.UserError('Error converting option: %s\n%s'%(option.key, x))
+
+
+ # Finally validate the values:
+ for option in self.options:
+ if option.validator and option.key in values:
+ option.validator(option.key, env.subst('${%s}'%option.key), env)
+
+ def UnknownVariables(self):
+ """
+ Returns any options in the specified arguments lists that
+ were not known, declared options in this object.
+ """
+ return self.unknown
+
+ def Save(self, filename, env):
+ """
+ Saves all the options in the given file. This file can
+ then be used to load the options next run. This can be used
+ to create an option cache file.
+
+ filename - Name of the file to save into
+ env - the environment get the option values from
+ """
+
+ # Create the file and write out the header
+ try:
+ fh = open(filename, 'w')
+
+ try:
+ # Make an assignment in the file for each option
+ # within the environment that was assigned a value
+ # other than the default.
+ for option in self.options:
+ try:
+ value = env[option.key]
+ try:
+ prepare = value.prepare_to_store
+ except AttributeError:
+ try:
+ eval(repr(value))
+ except KeyboardInterrupt:
+ raise
+ except:
+ # Convert stuff that has a repr() that
+ # cannot be evaluated into a string
+ value = SCons.Util.to_String(value)
+ else:
+ value = prepare()
+
+ defaultVal = env.subst(SCons.Util.to_String(option.default))
+ if option.converter:
+ defaultVal = option.converter(defaultVal)
+
+ if str(env.subst('${%s}' % option.key)) != str(defaultVal):
+ fh.write('%s = %s\n' % (option.key, repr(value)))
+ except KeyError:
+ pass
+ finally:
+ fh.close()
+
+ except IOError, x:
+ raise SCons.Errors.UserError('Error writing options to file: %s\n%s' % (filename, x))
+
+ def GenerateHelpText(self, env, sort=None):
+ """
+ Generate the help text for the options.
+
+ env - an environment that is used to get the current values
+ of the options.
+ """
+
+ if sort:
+ options = sorted(self.options, key=lambda x: x.key)
+ else:
+ options = self.options
+
+ def format(opt, self=self, env=env):
+ if opt.key in env:
+ actual = env.subst('${%s}' % opt.key)
+ else:
+ actual = None
+ return self.FormatVariableHelpText(env, opt.key, opt.help, opt.default, actual, opt.aliases)
+ lines = [_f for _f in map(format, options) if _f]
+
+ return ''.join(lines)
+
+ format = '\n%s: %s\n default: %s\n actual: %s\n'
+ format_ = '\n%s: %s\n default: %s\n actual: %s\n aliases: %s\n'
+
+ def FormatVariableHelpText(self, env, key, help, default, actual, aliases=[]):
+ # Don't display the key name itself as an alias.
+ aliases = [a for a in aliases if a != key]
+ if len(aliases)==0:
+ return self.format % (key, help, default, actual)
+ else:
+ return self.format_ % (key, help, default, actual, aliases)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/Warnings.py b/couchjs/scons/scons-local-2.0.1/SCons/Warnings.py
new file mode 100644
index 00000000..89f7ce93
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/Warnings.py
@@ -0,0 +1,246 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+"""SCons.Warnings
+
+This file implements the warnings framework for SCons.
+
+"""
+
+__revision__ = "src/engine/SCons/Warnings.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import sys
+
+import SCons.Errors
+
+class Warning(SCons.Errors.UserError):
+ pass
+
+class WarningOnByDefault(Warning):
+ pass
+
+
+# NOTE: If you add a new warning class, add it to the man page, too!
+
+class CacheWriteErrorWarning(Warning):
+ pass
+
+class CorruptSConsignWarning(WarningOnByDefault):
+ pass
+
+class DependencyWarning(Warning):
+ pass
+
+class DuplicateEnvironmentWarning(WarningOnByDefault):
+ pass
+
+class FutureReservedVariableWarning(WarningOnByDefault):
+ pass
+
+class LinkWarning(WarningOnByDefault):
+ pass
+
+class MisleadingKeywordsWarning(WarningOnByDefault):
+ pass
+
+class MissingSConscriptWarning(WarningOnByDefault):
+ pass
+
+class NoMD5ModuleWarning(WarningOnByDefault):
+ pass
+
+class NoMetaclassSupportWarning(WarningOnByDefault):
+ pass
+
+class NoObjectCountWarning(WarningOnByDefault):
+ pass
+
+class NoParallelSupportWarning(WarningOnByDefault):
+ pass
+
+class ReservedVariableWarning(WarningOnByDefault):
+ pass
+
+class StackSizeWarning(WarningOnByDefault):
+ pass
+
+class VisualCMissingWarning(WarningOnByDefault):
+ pass
+
+# Used when MSVC_VERSION and MSVS_VERSION do not point to the
+# same version (MSVS_VERSION is deprecated)
+class VisualVersionMismatch(WarningOnByDefault):
+ pass
+
+class VisualStudioMissingWarning(Warning):
+ pass
+
+class FortranCxxMixWarning(LinkWarning):
+ pass
+
+
+# Deprecation warnings
+
+class FutureDeprecatedWarning(Warning):
+ pass
+
+class DeprecatedWarning(Warning):
+ pass
+
+class MandatoryDeprecatedWarning(DeprecatedWarning):
+ pass
+
+
+# Special case; base always stays DeprecatedWarning
+class PythonVersionWarning(DeprecatedWarning):
+ pass
+
+class DeprecatedSourceCodeWarning(FutureDeprecatedWarning):
+ pass
+
+class DeprecatedBuildDirWarning(DeprecatedWarning):
+ pass
+
+class TaskmasterNeedsExecuteWarning(DeprecatedWarning):
+ pass
+
+class DeprecatedCopyWarning(MandatoryDeprecatedWarning):
+ pass
+
+class DeprecatedOptionsWarning(MandatoryDeprecatedWarning):
+ pass
+
+class DeprecatedSourceSignaturesWarning(MandatoryDeprecatedWarning):
+ pass
+
+class DeprecatedTargetSignaturesWarning(MandatoryDeprecatedWarning):
+ pass
+
+class DeprecatedDebugOptionsWarning(MandatoryDeprecatedWarning):
+ pass
+
+class DeprecatedSigModuleWarning(MandatoryDeprecatedWarning):
+ pass
+
+class DeprecatedBuilderKeywordsWarning(MandatoryDeprecatedWarning):
+ pass
+
+
+# The below is a list of 2-tuples. The first element is a class object.
+# The second element is true if that class is enabled, false if it is disabled.
+_enabled = []
+
+# If set, raise the warning as an exception
+_warningAsException = 0
+
+# If not None, a function to call with the warning
+_warningOut = None
+
+def suppressWarningClass(clazz):
+ """Suppresses all warnings that are of type clazz or
+ derived from clazz."""
+ _enabled.insert(0, (clazz, 0))
+
+def enableWarningClass(clazz):
+ """Enables all warnings that are of type clazz or
+ derived from clazz."""
+ _enabled.insert(0, (clazz, 1))
+
+def warningAsException(flag=1):
+ """Turn warnings into exceptions. Returns the old value of the flag."""
+ global _warningAsException
+ old = _warningAsException
+ _warningAsException = flag
+ return old
+
+def warn(clazz, *args):
+ global _enabled, _warningAsException, _warningOut
+
+ warning = clazz(args)
+ for clazz, flag in _enabled:
+ if isinstance(warning, clazz):
+ if flag:
+ if _warningAsException:
+ raise warning
+
+ if _warningOut:
+ _warningOut(warning)
+ break
+
+def process_warn_strings(arguments):
+ """Process string specifications of enabling/disabling warnings,
+ as passed to the --warn option or the SetOption('warn') function.
+
+
+ An argument to this option should be of the form <warning-class>
+ or no-<warning-class>. The warning class is munged in order
+ to get an actual class name from the classes above, which we
+ need to pass to the {enable,disable}WarningClass() functions.
+ The supplied <warning-class> is split on hyphens, each element
+ is capitalized, then smushed back together. Then the string
+ "Warning" is appended to get the class name.
+
+ For example, 'deprecated' will enable the DeprecatedWarning
+ class. 'no-dependency' will disable the DependencyWarning class.
+
+ As a special case, --warn=all and --warn=no-all will enable or
+ disable (respectively) the base Warning class of all warnings.
+
+ """
+
+ def _capitalize(s):
+ if s[:5] == "scons":
+ return "SCons" + s[5:]
+ else:
+ return s.capitalize()
+
+ for arg in arguments:
+
+ elems = arg.lower().split('-')
+ enable = 1
+ if elems[0] == 'no':
+ enable = 0
+ del elems[0]
+
+ if len(elems) == 1 and elems[0] == 'all':
+ class_name = "Warning"
+ else:
+ class_name = ''.join(map(_capitalize, elems)) + "Warning"
+ try:
+ clazz = globals()[class_name]
+ except KeyError:
+ sys.stderr.write("No warning type: '%s'\n" % arg)
+ else:
+ if enable:
+ enableWarningClass(clazz)
+ elif issubclass(clazz, MandatoryDeprecatedWarning):
+ fmt = "Can not disable mandataory warning: '%s'\n"
+ sys.stderr.write(fmt % arg)
+ else:
+ suppressWarningClass(clazz)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/__init__.py b/couchjs/scons/scons-local-2.0.1/SCons/__init__.py
new file mode 100644
index 00000000..f6232251
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/__init__.py
@@ -0,0 +1,49 @@
+"""SCons
+
+The main package for the SCons software construction utility.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/__init__.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__version__ = "2.0.1"
+
+__build__ = "r5134"
+
+__buildsys__ = "cooldog"
+
+__date__ = "2010/08/16 23:02:40"
+
+__developer__ = "bdeegan"
+
+# make sure compatibility is always in place
+import SCons.compat
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/compat/__init__.py b/couchjs/scons/scons-local-2.0.1/SCons/compat/__init__.py
new file mode 100644
index 00000000..1dc5cc56
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/compat/__init__.py
@@ -0,0 +1,237 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__doc__ = """
+SCons compatibility package for old Python versions
+
+This subpackage holds modules that provide backwards-compatible
+implementations of various things that we'd like to use in SCons but which
+only show up in later versions of Python than the early, old version(s)
+we still support.
+
+Other code will not generally reference things in this package through
+the SCons.compat namespace. The modules included here add things to
+the builtins namespace or the global module list so that the rest
+of our code can use the objects and names imported here regardless of
+Python version.
+
+Simply enough, things that go in the builtins name space come from
+our _scons_builtins module.
+
+The rest of the things here will be in individual compatibility modules
+that are either: 1) suitably modified copies of the future modules that
+we want to use; or 2) backwards compatible re-implementations of the
+specific portions of a future module's API that we want to use.
+
+GENERAL WARNINGS: Implementations of functions in the SCons.compat
+modules are *NOT* guaranteed to be fully compliant with these functions in
+later versions of Python. We are only concerned with adding functionality
+that we actually use in SCons, so be wary if you lift this code for
+other uses. (That said, making these more nearly the same as later,
+official versions is still a desirable goal, we just don't need to be
+obsessive about it.)
+
+We name the compatibility modules with an initial '_scons_' (for example,
+_scons_subprocess.py is our compatibility module for subprocess) so
+that we can still try to import the real module name and fall back to
+our compatibility module if we get an ImportError. The import_as()
+function defined below loads the module as the "real" name (without the
+'_scons'), after which all of the "import {module}" statements in the
+rest of our code will find our pre-loaded compatibility module.
+"""
+
+__revision__ = "src/engine/SCons/compat/__init__.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import os
+import sys
+import imp # Use the "imp" module to protect imports from fixers.
+
+def import_as(module, name):
+ """
+ Imports the specified module (from our local directory) as the
+ specified name, returning the loaded module object.
+ """
+ dir = os.path.split(__file__)[0]
+ return imp.load_module(name, *imp.find_module(module, [dir]))
+
+def rename_module(new, old):
+ """
+ Attempts to import the old module and load it under the new name.
+ Used for purely cosmetic name changes in Python 3.x.
+ """
+ try:
+ sys.modules[new] = imp.load_module(old, *imp.find_module(old))
+ return True
+ except ImportError:
+ return False
+
+
+rename_module('builtins', '__builtin__')
+import _scons_builtins
+
+
+try:
+ import hashlib
+except ImportError:
+ # Pre-2.5 Python has no hashlib module.
+ try:
+ import_as('_scons_hashlib', 'hashlib')
+ except ImportError:
+ # If we failed importing our compatibility module, it probably
+ # means this version of Python has no md5 module. Don't do
+ # anything and let the higher layer discover this fact, so it
+ # can fall back to using timestamp.
+ pass
+
+try:
+ set
+except NameError:
+ # Pre-2.4 Python has no native set type
+ import_as('_scons_sets', 'sets')
+ import builtins, sets
+ builtins.set = sets.Set
+
+
+try:
+ import collections
+except ImportError:
+ # Pre-2.4 Python has no collections module.
+ import_as('_scons_collections', 'collections')
+else:
+ try:
+ collections.UserDict
+ except AttributeError:
+ exec('from UserDict import UserDict as _UserDict')
+ collections.UserDict = _UserDict
+ del _UserDict
+ try:
+ collections.UserList
+ except AttributeError:
+ exec('from UserList import UserList as _UserList')
+ collections.UserList = _UserList
+ del _UserList
+ try:
+ collections.UserString
+ except AttributeError:
+ exec('from UserString import UserString as _UserString')
+ collections.UserString = _UserString
+ del _UserString
+
+
+try:
+ import io
+except ImportError:
+ # Pre-2.6 Python has no io module.
+ import_as('_scons_io', 'io')
+
+
+try:
+ os.devnull
+except AttributeError:
+ # Pre-2.4 Python has no os.devnull attribute
+ _names = sys.builtin_module_names
+ if 'posix' in _names:
+ os.devnull = '/dev/null'
+ elif 'nt' in _names:
+ os.devnull = 'nul'
+ os.path.devnull = os.devnull
+try:
+ os.path.lexists
+except AttributeError:
+ # Pre-2.4 Python has no os.path.lexists function
+ def lexists(path):
+ return os.path.exists(path) or os.path.islink(path)
+ os.path.lexists = lexists
+
+
+# When we're using the '-3' option during regression tests, importing
+# cPickle gives a warning no matter how it's done, so always use the
+# real profile module, whether it's fast or not.
+if os.environ.get('SCONS_HORRIBLE_REGRESSION_TEST_HACK') is None:
+ # Not a regression test with '-3', so try to use faster version.
+ # In 3.x, 'pickle' automatically loads the fast version if available.
+ rename_module('pickle', 'cPickle')
+
+
+# In 3.x, 'profile' automatically loads the fast version if available.
+rename_module('profile', 'cProfile')
+
+
+# Before Python 3.0, the 'queue' module was named 'Queue'.
+rename_module('queue', 'Queue')
+
+
+# Before Python 3.0, the 'winreg' module was named '_winreg'
+rename_module('winreg', '_winreg')
+
+
+try:
+ import subprocess
+except ImportError:
+ # Pre-2.4 Python has no subprocess module.
+ import_as('_scons_subprocess', 'subprocess')
+
+try:
+ sys.intern
+except AttributeError:
+ # Pre-2.6 Python has no sys.intern() function.
+ import builtins
+ try:
+ sys.intern = builtins.intern
+ except AttributeError:
+ # Pre-2.x Python has no builtin intern() function.
+ def intern(x):
+ return x
+ sys.intern = intern
+ del intern
+try:
+ sys.maxsize
+except AttributeError:
+ # Pre-2.6 Python has no sys.maxsize attribute
+ # Wrapping sys in () is silly, but protects it from 2to3 renames fixer
+ sys.maxsize = (sys).maxint
+
+
+if os.environ.get('SCONS_HORRIBLE_REGRESSION_TEST_HACK') is not None:
+ # We can't apply the 'callable' fixer until the floor is 2.6, but the
+ # '-3' option to Python 2.6 and 2.7 generates almost ten thousand
+ # warnings. This hack allows us to run regression tests with the '-3'
+ # option by replacing the callable() built-in function with a hack
+ # that performs the same function but doesn't generate the warning.
+ # Note that this hack is ONLY intended to be used for regression
+ # testing, and should NEVER be used for real runs.
+ from types import ClassType
+ def callable(obj):
+ if hasattr(obj, '__call__'): return True
+ if isinstance(obj, (ClassType, type)): return True
+ return False
+ import builtins
+ builtins.callable = callable
+ del callable
+
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_builtins.py b/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_builtins.py
new file mode 100644
index 00000000..5daae958
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_builtins.py
@@ -0,0 +1,150 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+# Portions of the following are derived from the compat.py file in
+# Twisted, under the following copyright:
+#
+# Copyright (c) 2001-2004 Twisted Matrix Laboratories
+
+__doc__ = """
+Compatibility idioms for builtins names
+
+This module adds names to the builtins module for things that we want
+to use in SCons but which don't show up until later Python versions than
+the earliest ones we support.
+
+This module checks for the following builtins names:
+
+ all()
+ any()
+ sorted()
+ memoryview()
+
+Implementations of functions are *NOT* guaranteed to be fully compliant
+with these functions in later versions of Python. We are only concerned
+with adding functionality that we actually use in SCons, so be wary
+if you lift this code for other uses. (That said, making these more
+nearly the same as later, official versions is still a desirable goal,
+we just don't need to be obsessive about it.)
+
+If you're looking at this with pydoc and various names don't show up in
+the FUNCTIONS or DATA output, that means those names are already built in
+to this version of Python and we don't need to add them from this module.
+"""
+
+__revision__ = "src/engine/SCons/compat/_scons_builtins.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import builtins
+
+try:
+ all
+except NameError:
+ # Pre-2.5 Python has no all() function.
+ def all(iterable):
+ """
+ Returns True if all elements of the iterable are true.
+ """
+ for element in iterable:
+ if not element:
+ return False
+ return True
+ builtins.all = all
+ all = all
+
+try:
+ any
+except NameError:
+ # Pre-2.5 Python has no any() function.
+ def any(iterable):
+ """
+ Returns True if any element of the iterable is true.
+ """
+ for element in iterable:
+ if element:
+ return True
+ return False
+ builtins.any = any
+ any = any
+
+try:
+ memoryview
+except NameError:
+ # Pre-2.7 doesn't have the memoryview() built-in.
+ class memoryview(object):
+ def __init__(self, obj):
+ # wrapping buffer in () keeps the fixer from changing it
+ self.obj = (buffer)(obj)
+ def __getitem__(self, indx):
+ if isinstance(indx, slice):
+ return self.obj[indx.start:indx.stop]
+ else:
+ return self.obj[indx]
+ builtins.memoryview = memoryview
+
+try:
+ sorted
+except NameError:
+ # Pre-2.4 Python has no sorted() function.
+ #
+ # The pre-2.4 Python list.sort() method does not support
+ # list.sort(key=) nor list.sort(reverse=) keyword arguments, so
+ # we must implement the functionality of those keyword arguments
+ # by hand instead of passing them to list.sort().
+ def sorted(iterable, cmp=None, key=None, reverse=False):
+ if key is not None:
+ result = [(key(x), x) for x in iterable]
+ else:
+ result = iterable[:]
+ if cmp is None:
+ # Pre-2.3 Python does not support list.sort(None).
+ result.sort()
+ else:
+ result.sort(cmp)
+ if key is not None:
+ result = [t1 for t0,t1 in result]
+ if reverse:
+ result.reverse()
+ return result
+ builtins.sorted = sorted
+
+#if sys.version_info[:3] in ((2, 2, 0), (2, 2, 1)):
+# def lstrip(s, c=string.whitespace):
+# while s and s[0] in c:
+# s = s[1:]
+# return s
+# def rstrip(s, c=string.whitespace):
+# while s and s[-1] in c:
+# s = s[:-1]
+# return s
+# def strip(s, c=string.whitespace, l=lstrip, r=rstrip):
+# return l(r(s, c), c)
+#
+# object.__setattr__(str, 'lstrip', lstrip)
+# object.__setattr__(str, 'rstrip', rstrip)
+# object.__setattr__(str, 'strip', strip)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_collections.py b/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_collections.py
new file mode 100644
index 00000000..8cae2683
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_collections.py
@@ -0,0 +1,45 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__doc__ = """
+collections compatibility module for older (pre-2.4) Python versions
+
+This does not not NOT (repeat, *NOT*) provide complete collections
+functionality. It only wraps the portions of collections functionality
+used by SCons, in an interface that looks enough like collections for
+our purposes.
+"""
+
+__revision__ = "src/engine/SCons/compat/_scons_collections.py 5134 2010/08/16 23:02:40 bdeegan"
+
+# Use exec to hide old names from fixers.
+exec("""if True:
+ from UserDict import UserDict
+ from UserList import UserList
+ from UserString import UserString""")
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_dbm.py b/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_dbm.py
new file mode 100644
index 00000000..8c53b8c5
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_dbm.py
@@ -0,0 +1,45 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__doc__ = """
+dbm compatibility module for Python versions that don't have dbm.
+
+This does not not NOT (repeat, *NOT*) provide complete dbm functionality.
+It's just a stub on which to hang just enough pieces of dbm functionality
+that the whichdb.whichdb() implementstation in the various 2.X versions of
+Python won't blow up even if dbm wasn't compiled in.
+"""
+
+__revision__ = "src/engine/SCons/compat/_scons_dbm.py 5134 2010/08/16 23:02:40 bdeegan"
+
+class error(Exception):
+ pass
+
+def open(*args, **kw):
+ raise error()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_hashlib.py b/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_hashlib.py
new file mode 100644
index 00000000..e38f6a8b
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_hashlib.py
@@ -0,0 +1,76 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__doc__ = """
+hashlib backwards-compatibility module for older (pre-2.5) Python versions
+
+This does not not NOT (repeat, *NOT*) provide complete hashlib
+functionality. It only wraps the portions of MD5 functionality used
+by SCons, in an interface that looks like hashlib (or enough for our
+purposes, anyway). In fact, this module will raise an ImportError if
+the underlying md5 module isn't available.
+"""
+
+__revision__ = "src/engine/SCons/compat/_scons_hashlib.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import md5
+from string import hexdigits
+
+class md5obj(object):
+
+ md5_module = md5
+
+ def __init__(self, name, string=''):
+ if not name in ('MD5', 'md5'):
+ raise ValueError("unsupported hash type")
+ self.name = 'md5'
+ self.m = self.md5_module.md5()
+
+ def __repr__(self):
+ return '<%s HASH object @ %#x>' % (self.name, id(self))
+
+ def copy(self):
+ import copy
+ result = copy.copy(self)
+ result.m = self.m.copy()
+ return result
+
+ def digest(self):
+ return self.m.digest()
+
+ def update(self, arg):
+ return self.m.update(arg)
+
+ def hexdigest(self):
+ return self.m.hexdigest()
+
+new = md5obj
+
+def md5(string=''):
+ return md5obj('md5', string)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_io.py b/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_io.py
new file mode 100644
index 00000000..e7eb5ee7
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_io.py
@@ -0,0 +1,45 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__doc__ = """
+io compatibility module for older (pre-2.6) Python versions
+
+This does not not NOT (repeat, *NOT*) provide complete io
+functionality. It only wraps the portions of io functionality used
+by SCons, in an interface that looks enough like io for our purposes.
+"""
+
+__revision__ = "src/engine/SCons/compat/_scons_io.py 5134 2010/08/16 23:02:40 bdeegan"
+
+# Use the "imp" module to protect the imports below from fixers.
+import imp
+
+_cStringIO = imp.load_module('cStringIO', *imp.find_module('cStringIO'))
+StringIO = _cStringIO.StringIO
+del _cStringIO
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_sets.py b/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_sets.py
new file mode 100644
index 00000000..0fde9941
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_sets.py
@@ -0,0 +1,563 @@
+"""Classes to represent arbitrary sets (including sets of sets).
+
+This module implements sets using dictionaries whose values are
+ignored. The usual operations (union, intersection, deletion, etc.)
+are provided as both methods and operators.
+
+Important: sets are not sequences! While they support 'x in s',
+'len(s)', and 'for x in s', none of those operations are unique for
+sequences; for example, mappings support all three as well. The
+characteristic operation for sequences is subscripting with small
+integers: s[i], for i in range(len(s)). Sets don't support
+subscripting at all. Also, sequences allow multiple occurrences and
+their elements have a definite order; sets on the other hand don't
+record multiple occurrences and don't remember the order of element
+insertion (which is why they don't support s[i]).
+
+The following classes are provided:
+
+BaseSet -- All the operations common to both mutable and immutable
+ sets. This is an abstract class, not meant to be directly
+ instantiated.
+
+Set -- Mutable sets, subclass of BaseSet; not hashable.
+
+ImmutableSet -- Immutable sets, subclass of BaseSet; hashable.
+ An iterable argument is mandatory to create an ImmutableSet.
+
+_TemporarilyImmutableSet -- A wrapper around a Set, hashable,
+ giving the same hash value as the immutable set equivalent
+ would have. Do not use this class directly.
+
+Only hashable objects can be added to a Set. In particular, you cannot
+really add a Set as an element to another Set; if you try, what is
+actually added is an ImmutableSet built from it (it compares equal to
+the one you tried adding).
+
+When you ask if `x in y' where x is a Set and y is a Set or
+ImmutableSet, x is wrapped into a _TemporarilyImmutableSet z, and
+what's tested is actually `z in y'.
+
+"""
+
+# Code history:
+#
+# - Greg V. Wilson wrote the first version, using a different approach
+# to the mutable/immutable problem, and inheriting from dict.
+#
+# - Alex Martelli modified Greg's version to implement the current
+# Set/ImmutableSet approach, and make the data an attribute.
+#
+# - Guido van Rossum rewrote much of the code, made some API changes,
+# and cleaned up the docstrings.
+#
+# - Raymond Hettinger added a number of speedups and other
+# improvements.
+
+# protect this import from the fixers...
+exec('from itertools import ifilterfalse as filterfalse')
+
+__all__ = ['BaseSet', 'Set', 'ImmutableSet']
+
+class BaseSet(object):
+ """Common base class for mutable and immutable sets."""
+
+ __slots__ = ['_data']
+
+ # Constructor
+
+ def __init__(self):
+ """This is an abstract class."""
+ # Don't call this from a concrete subclass!
+ if self.__class__ is BaseSet:
+ raise TypeError("BaseSet is an abstract class. "
+ "Use Set or ImmutableSet.")
+
+ # Standard protocols: __len__, __repr__, __str__, __iter__
+
+ def __len__(self):
+ """Return the number of elements of a set."""
+ return len(self._data)
+
+ def __repr__(self):
+ """Return string representation of a set.
+
+ This looks like 'Set([<list of elements>])'.
+ """
+ return self._repr()
+
+ # __str__ is the same as __repr__
+ __str__ = __repr__
+
+ def _repr(self, sort_them=False):
+ elements = list(self._data.keys())
+ if sort_them:
+ elements.sort()
+ return '%s(%r)' % (self.__class__.__name__, elements)
+
+ def __iter__(self):
+ """Return an iterator over the elements or a set.
+
+ This is the keys iterator for the underlying dict.
+ """
+ # Wrapping name in () prevents fixer from "fixing" this
+ return (self._data.iterkeys)()
+
+ # Three-way comparison is not supported. However, because __eq__ is
+ # tried before __cmp__, if Set x == Set y, x.__eq__(y) returns True and
+ # then cmp(x, y) returns 0 (Python doesn't actually call __cmp__ in this
+ # case).
+
+ def __cmp__(self, other):
+ raise TypeError("can't compare sets using cmp()")
+
+ # Equality comparisons using the underlying dicts. Mixed-type comparisons
+ # are allowed here, where Set == z for non-Set z always returns False,
+ # and Set != z always True. This allows expressions like "x in y" to
+ # give the expected result when y is a sequence of mixed types, not
+ # raising a pointless TypeError just because y contains a Set, or x is
+ # a Set and y contain's a non-set ("in" invokes only __eq__).
+ # Subtle: it would be nicer if __eq__ and __ne__ could return
+ # NotImplemented instead of True or False. Then the other comparand
+ # would get a chance to determine the result, and if the other comparand
+ # also returned NotImplemented then it would fall back to object address
+ # comparison (which would always return False for __eq__ and always
+ # True for __ne__). However, that doesn't work, because this type
+ # *also* implements __cmp__: if, e.g., __eq__ returns NotImplemented,
+ # Python tries __cmp__ next, and the __cmp__ here then raises TypeError.
+
+ def __eq__(self, other):
+ if isinstance(other, BaseSet):
+ return self._data == other._data
+ else:
+ return False
+
+ def __ne__(self, other):
+ if isinstance(other, BaseSet):
+ return self._data != other._data
+ else:
+ return True
+
+ # Copying operations
+
+ def copy(self):
+ """Return a shallow copy of a set."""
+ result = self.__class__()
+ result._data.update(self._data)
+ return result
+
+ __copy__ = copy # For the copy module
+
+ def __deepcopy__(self, memo):
+ """Return a deep copy of a set; used by copy module."""
+ # This pre-creates the result and inserts it in the memo
+ # early, in case the deep copy recurses into another reference
+ # to this same set. A set can't be an element of itself, but
+ # it can certainly contain an object that has a reference to
+ # itself.
+ from copy import deepcopy
+ result = self.__class__()
+ memo[id(self)] = result
+ data = result._data
+ value = True
+ for elt in self:
+ data[deepcopy(elt, memo)] = value
+ return result
+
+ # Standard set operations: union, intersection, both differences.
+ # Each has an operator version (e.g. __or__, invoked with |) and a
+ # method version (e.g. union).
+ # Subtle: Each pair requires distinct code so that the outcome is
+ # correct when the type of other isn't suitable. For example, if
+ # we did "union = __or__" instead, then Set().union(3) would return
+ # NotImplemented instead of raising TypeError (albeit that *why* it
+ # raises TypeError as-is is also a bit subtle).
+
+ def __or__(self, other):
+ """Return the union of two sets as a new set.
+
+ (I.e. all elements that are in either set.)
+ """
+ if not isinstance(other, BaseSet):
+ return NotImplemented
+ return self.union(other)
+
+ def union(self, other):
+ """Return the union of two sets as a new set.
+
+ (I.e. all elements that are in either set.)
+ """
+ result = self.__class__(self)
+ result._update(other)
+ return result
+
+ def __and__(self, other):
+ """Return the intersection of two sets as a new set.
+
+ (I.e. all elements that are in both sets.)
+ """
+ if not isinstance(other, BaseSet):
+ return NotImplemented
+ return self.intersection(other)
+
+ def intersection(self, other):
+ """Return the intersection of two sets as a new set.
+
+ (I.e. all elements that are in both sets.)
+ """
+ if not isinstance(other, BaseSet):
+ other = Set(other)
+ if len(self) <= len(other):
+ little, big = self, other
+ else:
+ little, big = other, self
+ common = iter(filter(big._data.has_key, little))
+ return self.__class__(common)
+
+ def __xor__(self, other):
+ """Return the symmetric difference of two sets as a new set.
+
+ (I.e. all elements that are in exactly one of the sets.)
+ """
+ if not isinstance(other, BaseSet):
+ return NotImplemented
+ return self.symmetric_difference(other)
+
+ def symmetric_difference(self, other):
+ """Return the symmetric difference of two sets as a new set.
+
+ (I.e. all elements that are in exactly one of the sets.)
+ """
+ result = self.__class__()
+ data = result._data
+ value = True
+ selfdata = self._data
+ try:
+ otherdata = other._data
+ except AttributeError:
+ otherdata = Set(other)._data
+ for elt in filterfalse(otherdata.has_key, selfdata):
+ data[elt] = value
+ for elt in filterfalse(selfdata.has_key, otherdata):
+ data[elt] = value
+ return result
+
+ def __sub__(self, other):
+ """Return the difference of two sets as a new Set.
+
+ (I.e. all elements that are in this set and not in the other.)
+ """
+ if not isinstance(other, BaseSet):
+ return NotImplemented
+ return self.difference(other)
+
+ def difference(self, other):
+ """Return the difference of two sets as a new Set.
+
+ (I.e. all elements that are in this set and not in the other.)
+ """
+ result = self.__class__()
+ data = result._data
+ try:
+ otherdata = other._data
+ except AttributeError:
+ otherdata = Set(other)._data
+ value = True
+ for elt in filterfalse(otherdata.has_key, self):
+ data[elt] = value
+ return result
+
+ # Membership test
+
+ def __contains__(self, element):
+ """Report whether an element is a member of a set.
+
+ (Called in response to the expression `element in self'.)
+ """
+ try:
+ return element in self._data
+ except TypeError:
+ transform = getattr(element, "__as_temporarily_immutable__", None)
+ if transform is None:
+ raise # re-raise the TypeError exception we caught
+ return transform() in self._data
+
+ # Subset and superset test
+
+ def issubset(self, other):
+ """Report whether another set contains this set."""
+ self._binary_sanity_check(other)
+ if len(self) > len(other): # Fast check for obvious cases
+ return False
+ for elt in filterfalse(other._data.has_key, self):
+ return False
+ return True
+
+ def issuperset(self, other):
+ """Report whether this set contains another set."""
+ self._binary_sanity_check(other)
+ if len(self) < len(other): # Fast check for obvious cases
+ return False
+ for elt in filterfalse(self._data.has_key, other):
+ return False
+ return True
+
+ # Inequality comparisons using the is-subset relation.
+ __le__ = issubset
+ __ge__ = issuperset
+
+ def __lt__(self, other):
+ self._binary_sanity_check(other)
+ return len(self) < len(other) and self.issubset(other)
+
+ def __gt__(self, other):
+ self._binary_sanity_check(other)
+ return len(self) > len(other) and self.issuperset(other)
+
+ # Assorted helpers
+
+ def _binary_sanity_check(self, other):
+ # Check that the other argument to a binary operation is also
+ # a set, raising a TypeError otherwise.
+ if not isinstance(other, BaseSet):
+ raise TypeError("Binary operation only permitted between sets")
+
+ def _compute_hash(self):
+ # Calculate hash code for a set by xor'ing the hash codes of
+ # the elements. This ensures that the hash code does not depend
+ # on the order in which elements are added to the set. This is
+ # not called __hash__ because a BaseSet should not be hashable;
+ # only an ImmutableSet is hashable.
+ result = 0
+ for elt in self:
+ result ^= hash(elt)
+ return result
+
+ def _update(self, iterable):
+ # The main loop for update() and the subclass __init__() methods.
+ data = self._data
+
+ # Use the fast update() method when a dictionary is available.
+ if isinstance(iterable, BaseSet):
+ data.update(iterable._data)
+ return
+
+ value = True
+
+ if type(iterable) in (list, tuple, xrange):
+ # Optimized: we know that __iter__() and next() can't
+ # raise TypeError, so we can move 'try:' out of the loop.
+ it = iter(iterable)
+ while True:
+ try:
+ for element in it:
+ data[element] = value
+ return
+ except TypeError:
+ transform = getattr(element, "__as_immutable__", None)
+ if transform is None:
+ raise # re-raise the TypeError exception we caught
+ data[transform()] = value
+ else:
+ # Safe: only catch TypeError where intended
+ for element in iterable:
+ try:
+ data[element] = value
+ except TypeError:
+ transform = getattr(element, "__as_immutable__", None)
+ if transform is None:
+ raise # re-raise the TypeError exception we caught
+ data[transform()] = value
+
+
+class ImmutableSet(BaseSet):
+ """Immutable set class."""
+
+ __slots__ = ['_hashcode']
+
+ # BaseSet + hashing
+
+ def __init__(self, iterable=None):
+ """Construct an immutable set from an optional iterable."""
+ self._hashcode = None
+ self._data = {}
+ if iterable is not None:
+ self._update(iterable)
+
+ def __hash__(self):
+ if self._hashcode is None:
+ self._hashcode = self._compute_hash()
+ return self._hashcode
+
+ def __getstate__(self):
+ return self._data, self._hashcode
+
+ def __setstate__(self, state):
+ self._data, self._hashcode = state
+
+class Set(BaseSet):
+ """ Mutable set class."""
+
+ __slots__ = []
+
+ # BaseSet + operations requiring mutability; no hashing
+
+ def __init__(self, iterable=None):
+ """Construct a set from an optional iterable."""
+ self._data = {}
+ if iterable is not None:
+ self._update(iterable)
+
+ def __getstate__(self):
+ # getstate's results are ignored if it is not
+ return self._data,
+
+ def __setstate__(self, data):
+ self._data, = data
+
+ def __hash__(self):
+ """A Set cannot be hashed."""
+ # We inherit object.__hash__, so we must deny this explicitly
+ raise TypeError("Can't hash a Set, only an ImmutableSet.")
+
+ # In-place union, intersection, differences.
+ # Subtle: The xyz_update() functions deliberately return None,
+ # as do all mutating operations on built-in container types.
+ # The __xyz__ spellings have to return self, though.
+
+ def __ior__(self, other):
+ """Update a set with the union of itself and another."""
+ self._binary_sanity_check(other)
+ self._data.update(other._data)
+ return self
+
+ def union_update(self, other):
+ """Update a set with the union of itself and another."""
+ self._update(other)
+
+ def __iand__(self, other):
+ """Update a set with the intersection of itself and another."""
+ self._binary_sanity_check(other)
+ self._data = (self & other)._data
+ return self
+
+ def intersection_update(self, other):
+ """Update a set with the intersection of itself and another."""
+ if isinstance(other, BaseSet):
+ self &= other
+ else:
+ self._data = (self.intersection(other))._data
+
+ def __ixor__(self, other):
+ """Update a set with the symmetric difference of itself and another."""
+ self._binary_sanity_check(other)
+ self.symmetric_difference_update(other)
+ return self
+
+ def symmetric_difference_update(self, other):
+ """Update a set with the symmetric difference of itself and another."""
+ data = self._data
+ value = True
+ if not isinstance(other, BaseSet):
+ other = Set(other)
+ if self is other:
+ self.clear()
+ for elt in other:
+ if elt in data:
+ del data[elt]
+ else:
+ data[elt] = value
+
+ def __isub__(self, other):
+ """Remove all elements of another set from this set."""
+ self._binary_sanity_check(other)
+ self.difference_update(other)
+ return self
+
+ def difference_update(self, other):
+ """Remove all elements of another set from this set."""
+ data = self._data
+ if not isinstance(other, BaseSet):
+ other = Set(other)
+ if self is other:
+ self.clear()
+ for elt in filter(data.has_key, other):
+ del data[elt]
+
+ # Python dict-like mass mutations: update, clear
+
+ def update(self, iterable):
+ """Add all values from an iterable (such as a list or file)."""
+ self._update(iterable)
+
+ def clear(self):
+ """Remove all elements from this set."""
+ self._data.clear()
+
+ # Single-element mutations: add, remove, discard
+
+ def add(self, element):
+ """Add an element to a set.
+
+ This has no effect if the element is already present.
+ """
+ try:
+ self._data[element] = True
+ except TypeError:
+ transform = getattr(element, "__as_immutable__", None)
+ if transform is None:
+ raise # re-raise the TypeError exception we caught
+ self._data[transform()] = True
+
+ def remove(self, element):
+ """Remove an element from a set; it must be a member.
+
+ If the element is not a member, raise a KeyError.
+ """
+ try:
+ del self._data[element]
+ except TypeError:
+ transform = getattr(element, "__as_temporarily_immutable__", None)
+ if transform is None:
+ raise # re-raise the TypeError exception we caught
+ del self._data[transform()]
+
+ def discard(self, element):
+ """Remove an element from a set if it is a member.
+
+ If the element is not a member, do nothing.
+ """
+ try:
+ self.remove(element)
+ except KeyError:
+ pass
+
+ def pop(self):
+ """Remove and return an arbitrary set element."""
+ return self._data.popitem()[0]
+
+ def __as_immutable__(self):
+ # Return a copy of self as an immutable set
+ return ImmutableSet(self)
+
+ def __as_temporarily_immutable__(self):
+ # Return self wrapped in a temporarily immutable set
+ return _TemporarilyImmutableSet(self)
+
+
+class _TemporarilyImmutableSet(BaseSet):
+ # Wrap a mutable set as if it was temporarily immutable.
+ # This only supplies hashing and equality comparisons.
+
+ def __init__(self, set):
+ self._set = set
+ self._data = set._data # Needed by ImmutableSet.__eq__()
+
+ def __hash__(self):
+ return self._set._compute_hash()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_subprocess.py b/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_subprocess.py
new file mode 100644
index 00000000..eebe53d3
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/compat/_scons_subprocess.py
@@ -0,0 +1,1281 @@
+# subprocess - Subprocesses with accessible I/O streams
+#
+# For more information about this module, see PEP 324.
+#
+# This module should remain compatible with Python 2.2, see PEP 291.
+#
+# Copyright (c) 2003-2005 by Peter Astrand <astrand@lysator.liu.se>
+#
+# Licensed to PSF under a Contributor Agreement.
+# See http://www.python.org/2.4/license for licensing details.
+
+r"""subprocess - Subprocesses with accessible I/O streams
+
+This module allows you to spawn processes, connect to their
+input/output/error pipes, and obtain their return codes. This module
+intends to replace several other, older modules and functions, like:
+
+os.system
+os.spawn*
+os.popen*
+popen2.*
+commands.*
+
+Information about how the subprocess module can be used to replace these
+modules and functions can be found below.
+
+
+
+Using the subprocess module
+===========================
+This module defines one class called Popen:
+
+class Popen(args, bufsize=0, executable=None,
+ stdin=None, stdout=None, stderr=None,
+ preexec_fn=None, close_fds=False, shell=False,
+ cwd=None, env=None, universal_newlines=False,
+ startupinfo=None, creationflags=0):
+
+
+Arguments are:
+
+args should be a string, or a sequence of program arguments. The
+program to execute is normally the first item in the args sequence or
+string, but can be explicitly set by using the executable argument.
+
+On UNIX, with shell=False (default): In this case, the Popen class
+uses os.execvp() to execute the child program. args should normally
+be a sequence. A string will be treated as a sequence with the string
+as the only item (the program to execute).
+
+On UNIX, with shell=True: If args is a string, it specifies the
+command string to execute through the shell. If args is a sequence,
+the first item specifies the command string, and any additional items
+will be treated as additional shell arguments.
+
+On Windows: the Popen class uses CreateProcess() to execute the child
+program, which operates on strings. If args is a sequence, it will be
+converted to a string using the list2cmdline method. Please note that
+not all MS Windows applications interpret the command line the same
+way: The list2cmdline is designed for applications using the same
+rules as the MS C runtime.
+
+bufsize, if given, has the same meaning as the corresponding argument
+to the built-in open() function: 0 means unbuffered, 1 means line
+buffered, any other positive value means use a buffer of
+(approximately) that size. A negative bufsize means to use the system
+default, which usually means fully buffered. The default value for
+bufsize is 0 (unbuffered).
+
+stdin, stdout and stderr specify the executed programs' standard
+input, standard output and standard error file handles, respectively.
+Valid values are PIPE, an existing file descriptor (a positive
+integer), an existing file object, and None. PIPE indicates that a
+new pipe to the child should be created. With None, no redirection
+will occur; the child's file handles will be inherited from the
+parent. Additionally, stderr can be STDOUT, which indicates that the
+stderr data from the applications should be captured into the same
+file handle as for stdout.
+
+If preexec_fn is set to a callable object, this object will be called
+in the child process just before the child is executed.
+
+If close_fds is true, all file descriptors except 0, 1 and 2 will be
+closed before the child process is executed.
+
+if shell is true, the specified command will be executed through the
+shell.
+
+If cwd is not None, the current directory will be changed to cwd
+before the child is executed.
+
+If env is not None, it defines the environment variables for the new
+process.
+
+If universal_newlines is true, the file objects stdout and stderr are
+opened as a text files, but lines may be terminated by any of '\n',
+the Unix end-of-line convention, '\r', the Macintosh convention or
+'\r\n', the Windows convention. All of these external representations
+are seen as '\n' by the Python program. Note: This feature is only
+available if Python is built with universal newline support (the
+default). Also, the newlines attribute of the file objects stdout,
+stdin and stderr are not updated by the communicate() method.
+
+The startupinfo and creationflags, if given, will be passed to the
+underlying CreateProcess() function. They can specify things such as
+appearance of the main window and priority for the new process.
+(Windows only)
+
+
+This module also defines two shortcut functions:
+
+call(*popenargs, **kwargs):
+ Run command with arguments. Wait for command to complete, then
+ return the returncode attribute.
+
+ The arguments are the same as for the Popen constructor. Example:
+
+ retcode = call(["ls", "-l"])
+
+check_call(*popenargs, **kwargs):
+ Run command with arguments. Wait for command to complete. If the
+ exit code was zero then return, otherwise raise
+ CalledProcessError. The CalledProcessError object will have the
+ return code in the returncode attribute.
+
+ The arguments are the same as for the Popen constructor. Example:
+
+ check_call(["ls", "-l"])
+
+Exceptions
+----------
+Exceptions raised in the child process, before the new program has
+started to execute, will be re-raised in the parent. Additionally,
+the exception object will have one extra attribute called
+'child_traceback', which is a string containing traceback information
+from the childs point of view.
+
+The most common exception raised is OSError. This occurs, for
+example, when trying to execute a non-existent file. Applications
+should prepare for OSErrors.
+
+A ValueError will be raised if Popen is called with invalid arguments.
+
+check_call() will raise CalledProcessError, if the called process
+returns a non-zero return code.
+
+
+Security
+--------
+Unlike some other popen functions, this implementation will never call
+/bin/sh implicitly. This means that all characters, including shell
+metacharacters, can safely be passed to child processes.
+
+
+Popen objects
+=============
+Instances of the Popen class have the following methods:
+
+poll()
+ Check if child process has terminated. Returns returncode
+ attribute.
+
+wait()
+ Wait for child process to terminate. Returns returncode attribute.
+
+communicate(input=None)
+ Interact with process: Send data to stdin. Read data from stdout
+ and stderr, until end-of-file is reached. Wait for process to
+ terminate. The optional stdin argument should be a string to be
+ sent to the child process, or None, if no data should be sent to
+ the child.
+
+ communicate() returns a tuple (stdout, stderr).
+
+ Note: The data read is buffered in memory, so do not use this
+ method if the data size is large or unlimited.
+
+The following attributes are also available:
+
+stdin
+ If the stdin argument is PIPE, this attribute is a file object
+ that provides input to the child process. Otherwise, it is None.
+
+stdout
+ If the stdout argument is PIPE, this attribute is a file object
+ that provides output from the child process. Otherwise, it is
+ None.
+
+stderr
+ If the stderr argument is PIPE, this attribute is file object that
+ provides error output from the child process. Otherwise, it is
+ None.
+
+pid
+ The process ID of the child process.
+
+returncode
+ The child return code. A None value indicates that the process
+ hasn't terminated yet. A negative value -N indicates that the
+ child was terminated by signal N (UNIX only).
+
+
+Replacing older functions with the subprocess module
+====================================================
+In this section, "a ==> b" means that b can be used as a replacement
+for a.
+
+Note: All functions in this section fail (more or less) silently if
+the executed program cannot be found; this module raises an OSError
+exception.
+
+In the following examples, we assume that the subprocess module is
+imported with "from subprocess import *".
+
+
+Replacing /bin/sh shell backquote
+---------------------------------
+output=`mycmd myarg`
+==>
+output = Popen(["mycmd", "myarg"], stdout=PIPE).communicate()[0]
+
+
+Replacing shell pipe line
+-------------------------
+output=`dmesg | grep hda`
+==>
+p1 = Popen(["dmesg"], stdout=PIPE)
+p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
+output = p2.communicate()[0]
+
+
+Replacing os.system()
+---------------------
+sts = os.system("mycmd" + " myarg")
+==>
+p = Popen("mycmd" + " myarg", shell=True)
+pid, sts = os.waitpid(p.pid, 0)
+
+Note:
+
+* Calling the program through the shell is usually not required.
+
+* It's easier to look at the returncode attribute than the
+ exitstatus.
+
+A more real-world example would look like this:
+
+try:
+ retcode = call("mycmd" + " myarg", shell=True)
+ if retcode < 0:
+ print >>sys.stderr, "Child was terminated by signal", -retcode
+ else:
+ print >>sys.stderr, "Child returned", retcode
+except OSError, e:
+ print >>sys.stderr, "Execution failed:", e
+
+
+Replacing os.spawn*
+-------------------
+P_NOWAIT example:
+
+pid = os.spawnlp(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg")
+==>
+pid = Popen(["/bin/mycmd", "myarg"]).pid
+
+
+P_WAIT example:
+
+retcode = os.spawnlp(os.P_WAIT, "/bin/mycmd", "mycmd", "myarg")
+==>
+retcode = call(["/bin/mycmd", "myarg"])
+
+
+Vector example:
+
+os.spawnvp(os.P_NOWAIT, path, args)
+==>
+Popen([path] + args[1:])
+
+
+Environment example:
+
+os.spawnlpe(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg", env)
+==>
+Popen(["/bin/mycmd", "myarg"], env={"PATH": "/usr/bin"})
+
+
+Replacing os.popen*
+-------------------
+pipe = os.popen(cmd, mode='r', bufsize)
+==>
+pipe = Popen(cmd, shell=True, bufsize=bufsize, stdout=PIPE).stdout
+
+pipe = os.popen(cmd, mode='w', bufsize)
+==>
+pipe = Popen(cmd, shell=True, bufsize=bufsize, stdin=PIPE).stdin
+
+
+(child_stdin, child_stdout) = os.popen2(cmd, mode, bufsize)
+==>
+p = Popen(cmd, shell=True, bufsize=bufsize,
+ stdin=PIPE, stdout=PIPE, close_fds=True)
+(child_stdin, child_stdout) = (p.stdin, p.stdout)
+
+
+(child_stdin,
+ child_stdout,
+ child_stderr) = os.popen3(cmd, mode, bufsize)
+==>
+p = Popen(cmd, shell=True, bufsize=bufsize,
+ stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
+(child_stdin,
+ child_stdout,
+ child_stderr) = (p.stdin, p.stdout, p.stderr)
+
+
+(child_stdin, child_stdout_and_stderr) = os.popen4(cmd, mode, bufsize)
+==>
+p = Popen(cmd, shell=True, bufsize=bufsize,
+ stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
+(child_stdin, child_stdout_and_stderr) = (p.stdin, p.stdout)
+
+
+Replacing popen2.*
+------------------
+Note: If the cmd argument to popen2 functions is a string, the command
+is executed through /bin/sh. If it is a list, the command is directly
+executed.
+
+(child_stdout, child_stdin) = popen2.popen2("somestring", bufsize, mode)
+==>
+p = Popen(["somestring"], shell=True, bufsize=bufsize
+ stdin=PIPE, stdout=PIPE, close_fds=True)
+(child_stdout, child_stdin) = (p.stdout, p.stdin)
+
+
+(child_stdout, child_stdin) = popen2.popen2(["mycmd", "myarg"], bufsize, mode)
+==>
+p = Popen(["mycmd", "myarg"], bufsize=bufsize,
+ stdin=PIPE, stdout=PIPE, close_fds=True)
+(child_stdout, child_stdin) = (p.stdout, p.stdin)
+
+The popen2.Popen3 and popen3.Popen4 basically works as subprocess.Popen,
+except that:
+
+* subprocess.Popen raises an exception if the execution fails
+* the capturestderr argument is replaced with the stderr argument.
+* stdin=PIPE and stdout=PIPE must be specified.
+* popen2 closes all filedescriptors by default, but you have to specify
+ close_fds=True with subprocess.Popen.
+
+
+"""
+
+import sys
+mswindows = (sys.platform == "win32")
+
+import os
+import types
+import traceback
+
+# Exception classes used by this module.
+class CalledProcessError(Exception):
+ """This exception is raised when a process run by check_call() returns
+ a non-zero exit status. The exit status will be stored in the
+ returncode attribute."""
+ def __init__(self, returncode, cmd):
+ self.returncode = returncode
+ self.cmd = cmd
+ def __str__(self):
+ return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode)
+
+
+if mswindows:
+ try:
+ import threading
+ except ImportError:
+ # SCons: the threading module is only used by the communicate()
+ # method, which we don't actually use, so don't worry if we
+ # can't import it.
+ pass
+ import msvcrt
+ try:
+ # Try to get _subprocess
+ from _subprocess import *
+ class STARTUPINFO(object):
+ dwFlags = 0
+ hStdInput = None
+ hStdOutput = None
+ hStdError = None
+ wShowWindow = 0
+ class pywintypes(object):
+ error = IOError
+ except ImportError:
+ # If not there, then drop back to requiring pywin32
+ # TODO: Should this be wrapped in try as well? To notify user to install
+ # pywin32 ? With URL to it?
+ import pywintypes
+ from win32api import GetStdHandle, STD_INPUT_HANDLE, \
+ STD_OUTPUT_HANDLE, STD_ERROR_HANDLE
+ from win32api import GetCurrentProcess, DuplicateHandle, \
+ GetModuleFileName, GetVersion
+ from win32con import DUPLICATE_SAME_ACCESS, SW_HIDE
+ from win32pipe import CreatePipe
+ from win32process import CreateProcess, STARTUPINFO, \
+ GetExitCodeProcess, STARTF_USESTDHANDLES, \
+ STARTF_USESHOWWINDOW, CREATE_NEW_CONSOLE
+ from win32event import WaitForSingleObject, INFINITE, WAIT_OBJECT_0
+
+
+else:
+ import select
+ import errno
+ import fcntl
+ import pickle
+
+ try:
+ fcntl.F_GETFD
+ except AttributeError:
+ fcntl.F_GETFD = 1
+
+ try:
+ fcntl.F_SETFD
+ except AttributeError:
+ fcntl.F_SETFD = 2
+
+__all__ = ["Popen", "PIPE", "STDOUT", "call", "check_call", "CalledProcessError"]
+
+try:
+ MAXFD = os.sysconf("SC_OPEN_MAX")
+except KeyboardInterrupt:
+ raise # SCons: don't swallow keyboard interrupts
+except:
+ MAXFD = 256
+
+try:
+ isinstance(1, int)
+except TypeError:
+ def is_int(obj):
+ return isinstance(obj, type(1))
+ def is_int_or_long(obj):
+ return type(obj) in (type(1), type(1L))
+else:
+ def is_int(obj):
+ return isinstance(obj, int)
+ def is_int_or_long(obj):
+ return isinstance(obj, (int, long))
+
+try:
+ types.StringTypes
+except AttributeError:
+ try:
+ types.StringTypes = (str, unicode)
+ except NameError:
+ types.StringTypes = (str,)
+def is_string(obj):
+ return isinstance(obj, types.StringTypes)
+
+_active = []
+
+def _cleanup():
+ for inst in _active[:]:
+ if inst.poll(_deadstate=sys.maxsize) >= 0:
+ try:
+ _active.remove(inst)
+ except ValueError:
+ # This can happen if two threads create a new Popen instance.
+ # It's harmless that it was already removed, so ignore.
+ pass
+
+PIPE = -1
+STDOUT = -2
+
+
+def call(*popenargs, **kwargs):
+ """Run command with arguments. Wait for command to complete, then
+ return the returncode attribute.
+
+ The arguments are the same as for the Popen constructor. Example:
+
+ retcode = call(["ls", "-l"])
+ """
+ return apply(Popen, popenargs, kwargs).wait()
+
+
+def check_call(*popenargs, **kwargs):
+ """Run command with arguments. Wait for command to complete. If
+ the exit code was zero then return, otherwise raise
+ CalledProcessError. The CalledProcessError object will have the
+ return code in the returncode attribute.
+
+ The arguments are the same as for the Popen constructor. Example:
+
+ check_call(["ls", "-l"])
+ """
+ retcode = call(*popenargs, **kwargs)
+ cmd = kwargs.get("args")
+ if cmd is None:
+ cmd = popenargs[0]
+ if retcode:
+ raise CalledProcessError(retcode, cmd)
+ return retcode
+
+
+def list2cmdline(seq):
+ """
+ Translate a sequence of arguments into a command line
+ string, using the same rules as the MS C runtime:
+
+ 1) Arguments are delimited by white space, which is either a
+ space or a tab.
+
+ 2) A string surrounded by double quotation marks is
+ interpreted as a single argument, regardless of white space
+ contained within. A quoted string can be embedded in an
+ argument.
+
+ 3) A double quotation mark preceded by a backslash is
+ interpreted as a literal double quotation mark.
+
+ 4) Backslashes are interpreted literally, unless they
+ immediately precede a double quotation mark.
+
+ 5) If backslashes immediately precede a double quotation mark,
+ every pair of backslashes is interpreted as a literal
+ backslash. If the number of backslashes is odd, the last
+ backslash escapes the next double quotation mark as
+ described in rule 3.
+ """
+
+ # See
+ # http://msdn.microsoft.com/library/en-us/vccelng/htm/progs_12.asp
+ result = []
+ needquote = False
+ for arg in seq:
+ bs_buf = []
+
+ # Add a space to separate this argument from the others
+ if result:
+ result.append(' ')
+
+ needquote = (" " in arg) or ("\t" in arg)
+ if needquote:
+ result.append('"')
+
+ for c in arg:
+ if c == '\\':
+ # Don't know if we need to double yet.
+ bs_buf.append(c)
+ elif c == '"':
+ # Double backspaces.
+ result.append('\\' * len(bs_buf)*2)
+ bs_buf = []
+ result.append('\\"')
+ else:
+ # Normal char
+ if bs_buf:
+ result.extend(bs_buf)
+ bs_buf = []
+ result.append(c)
+
+ # Add remaining backspaces, if any.
+ if bs_buf:
+ result.extend(bs_buf)
+
+ if needquote:
+ result.extend(bs_buf)
+ result.append('"')
+
+ return ''.join(result)
+
+class Popen(object):
+ def __init__(self, args, bufsize=0, executable=None,
+ stdin=None, stdout=None, stderr=None,
+ preexec_fn=None, close_fds=False, shell=False,
+ cwd=None, env=None, universal_newlines=False,
+ startupinfo=None, creationflags=0):
+ """Create new Popen instance."""
+ _cleanup()
+
+ self._child_created = False
+ if not is_int_or_long(bufsize):
+ raise TypeError("bufsize must be an integer")
+
+ if mswindows:
+ if preexec_fn is not None:
+ raise ValueError("preexec_fn is not supported on Windows "
+ "platforms")
+ if close_fds:
+ raise ValueError("close_fds is not supported on Windows "
+ "platforms")
+ else:
+ # POSIX
+ if startupinfo is not None:
+ raise ValueError("startupinfo is only supported on Windows "
+ "platforms")
+ if creationflags != 0:
+ raise ValueError("creationflags is only supported on Windows "
+ "platforms")
+
+ self.stdin = None
+ self.stdout = None
+ self.stderr = None
+ self.pid = None
+ self.returncode = None
+ self.universal_newlines = universal_newlines
+
+ # Input and output objects. The general principle is like
+ # this:
+ #
+ # Parent Child
+ # ------ -----
+ # p2cwrite ---stdin---> p2cread
+ # c2pread <--stdout--- c2pwrite
+ # errread <--stderr--- errwrite
+ #
+ # On POSIX, the child objects are file descriptors. On
+ # Windows, these are Windows file handles. The parent objects
+ # are file descriptors on both platforms. The parent objects
+ # are None when not using PIPEs. The child objects are None
+ # when not redirecting.
+
+ (p2cread, p2cwrite,
+ c2pread, c2pwrite,
+ errread, errwrite) = self._get_handles(stdin, stdout, stderr)
+
+ self._execute_child(args, executable, preexec_fn, close_fds,
+ cwd, env, universal_newlines,
+ startupinfo, creationflags, shell,
+ p2cread, p2cwrite,
+ c2pread, c2pwrite,
+ errread, errwrite)
+
+ if p2cwrite:
+ self.stdin = os.fdopen(p2cwrite, 'wb', bufsize)
+ if c2pread:
+ if universal_newlines:
+ self.stdout = os.fdopen(c2pread, 'rU', bufsize)
+ else:
+ self.stdout = os.fdopen(c2pread, 'rb', bufsize)
+ if errread:
+ if universal_newlines:
+ self.stderr = os.fdopen(errread, 'rU', bufsize)
+ else:
+ self.stderr = os.fdopen(errread, 'rb', bufsize)
+
+
+ def _translate_newlines(self, data):
+ data = data.replace("\r\n", "\n")
+ data = data.replace("\r", "\n")
+ return data
+
+
+ def __del__(self):
+ if not self._child_created:
+ # We didn't get to successfully create a child process.
+ return
+ # In case the child hasn't been waited on, check if it's done.
+ self.poll(_deadstate=sys.maxsize)
+ if self.returncode is None and _active is not None:
+ # Child is still running, keep us alive until we can wait on it.
+ _active.append(self)
+
+
+ def communicate(self, input=None):
+ """Interact with process: Send data to stdin. Read data from
+ stdout and stderr, until end-of-file is reached. Wait for
+ process to terminate. The optional input argument should be a
+ string to be sent to the child process, or None, if no data
+ should be sent to the child.
+
+ communicate() returns a tuple (stdout, stderr)."""
+
+ # Optimization: If we are only using one pipe, or no pipe at
+ # all, using select() or threads is unnecessary.
+ if [self.stdin, self.stdout, self.stderr].count(None) >= 2:
+ stdout = None
+ stderr = None
+ if self.stdin:
+ if input:
+ self.stdin.write(input)
+ self.stdin.close()
+ elif self.stdout:
+ stdout = self.stdout.read()
+ elif self.stderr:
+ stderr = self.stderr.read()
+ self.wait()
+ return (stdout, stderr)
+
+ return self._communicate(input)
+
+
+ if mswindows:
+ #
+ # Windows methods
+ #
+ def _get_handles(self, stdin, stdout, stderr):
+ """Construct and return tupel with IO objects:
+ p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
+ """
+ if stdin is None and stdout is None and stderr is None:
+ return (None, None, None, None, None, None)
+
+ p2cread, p2cwrite = None, None
+ c2pread, c2pwrite = None, None
+ errread, errwrite = None, None
+
+ if stdin is None:
+ p2cread = GetStdHandle(STD_INPUT_HANDLE)
+ elif stdin == PIPE:
+ p2cread, p2cwrite = CreatePipe(None, 0)
+ # Detach and turn into fd
+ p2cwrite = p2cwrite.Detach()
+ p2cwrite = msvcrt.open_osfhandle(p2cwrite, 0)
+ elif is_int(stdin):
+ p2cread = msvcrt.get_osfhandle(stdin)
+ else:
+ # Assuming file-like object
+ p2cread = msvcrt.get_osfhandle(stdin.fileno())
+ p2cread = self._make_inheritable(p2cread)
+
+ if stdout is None:
+ c2pwrite = GetStdHandle(STD_OUTPUT_HANDLE)
+ elif stdout == PIPE:
+ c2pread, c2pwrite = CreatePipe(None, 0)
+ # Detach and turn into fd
+ c2pread = c2pread.Detach()
+ c2pread = msvcrt.open_osfhandle(c2pread, 0)
+ elif is_int(stdout):
+ c2pwrite = msvcrt.get_osfhandle(stdout)
+ else:
+ # Assuming file-like object
+ c2pwrite = msvcrt.get_osfhandle(stdout.fileno())
+ c2pwrite = self._make_inheritable(c2pwrite)
+
+ if stderr is None:
+ errwrite = GetStdHandle(STD_ERROR_HANDLE)
+ elif stderr == PIPE:
+ errread, errwrite = CreatePipe(None, 0)
+ # Detach and turn into fd
+ errread = errread.Detach()
+ errread = msvcrt.open_osfhandle(errread, 0)
+ elif stderr == STDOUT:
+ errwrite = c2pwrite
+ elif is_int(stderr):
+ errwrite = msvcrt.get_osfhandle(stderr)
+ else:
+ # Assuming file-like object
+ errwrite = msvcrt.get_osfhandle(stderr.fileno())
+ errwrite = self._make_inheritable(errwrite)
+
+ return (p2cread, p2cwrite,
+ c2pread, c2pwrite,
+ errread, errwrite)
+
+
+ def _make_inheritable(self, handle):
+ """Return a duplicate of handle, which is inheritable"""
+ return DuplicateHandle(GetCurrentProcess(), handle,
+ GetCurrentProcess(), 0, 1,
+ DUPLICATE_SAME_ACCESS)
+
+
+ def _find_w9xpopen(self):
+ """Find and return absolut path to w9xpopen.exe"""
+ w9xpopen = os.path.join(os.path.dirname(GetModuleFileName(0)),
+ "w9xpopen.exe")
+ if not os.path.exists(w9xpopen):
+ # Eeek - file-not-found - possibly an embedding
+ # situation - see if we can locate it in sys.exec_prefix
+ w9xpopen = os.path.join(os.path.dirname(sys.exec_prefix),
+ "w9xpopen.exe")
+ if not os.path.exists(w9xpopen):
+ raise RuntimeError("Cannot locate w9xpopen.exe, which is "
+ "needed for Popen to work with your "
+ "shell or platform.")
+ return w9xpopen
+
+
+ def _execute_child(self, args, executable, preexec_fn, close_fds,
+ cwd, env, universal_newlines,
+ startupinfo, creationflags, shell,
+ p2cread, p2cwrite,
+ c2pread, c2pwrite,
+ errread, errwrite):
+ """Execute program (MS Windows version)"""
+
+ if not isinstance(args, types.StringTypes):
+ args = list2cmdline(args)
+
+ # Process startup details
+ if startupinfo is None:
+ startupinfo = STARTUPINFO()
+ if None not in (p2cread, c2pwrite, errwrite):
+ startupinfo.dwFlags = startupinfo.dwFlags | STARTF_USESTDHANDLES
+ startupinfo.hStdInput = p2cread
+ startupinfo.hStdOutput = c2pwrite
+ startupinfo.hStdError = errwrite
+
+ if shell:
+ startupinfo.dwFlags = startupinfo.dwFlags | STARTF_USESHOWWINDOW
+ startupinfo.wShowWindow = SW_HIDE
+ comspec = os.environ.get("COMSPEC", "cmd.exe")
+ args = comspec + " /c " + args
+ if (GetVersion() >= 0x80000000L or
+ os.path.basename(comspec).lower() == "command.com"):
+ # Win9x, or using command.com on NT. We need to
+ # use the w9xpopen intermediate program. For more
+ # information, see KB Q150956
+ # (http://web.archive.org/web/20011105084002/http://support.microsoft.com/support/kb/articles/Q150/9/56.asp)
+ w9xpopen = self._find_w9xpopen()
+ args = '"%s" %s' % (w9xpopen, args)
+ # Not passing CREATE_NEW_CONSOLE has been known to
+ # cause random failures on win9x. Specifically a
+ # dialog: "Your program accessed mem currently in
+ # use at xxx" and a hopeful warning about the
+ # stability of your system. Cost is Ctrl+C wont
+ # kill children.
+ creationflags = creationflags | CREATE_NEW_CONSOLE
+
+ # Start the process
+ try:
+ hp, ht, pid, tid = CreateProcess(executable, args,
+ # no special security
+ None, None,
+ # must inherit handles to pass std
+ # handles
+ 1,
+ creationflags,
+ env,
+ cwd,
+ startupinfo)
+ except pywintypes.error, e:
+ # Translate pywintypes.error to WindowsError, which is
+ # a subclass of OSError. FIXME: We should really
+ # translate errno using _sys_errlist (or simliar), but
+ # how can this be done from Python?
+ raise WindowsError(*e.args)
+
+ # Retain the process handle, but close the thread handle
+ self._child_created = True
+ self._handle = hp
+ self.pid = pid
+ ht.Close()
+
+ # Child is launched. Close the parent's copy of those pipe
+ # handles that only the child should have open. You need
+ # to make sure that no handles to the write end of the
+ # output pipe are maintained in this process or else the
+ # pipe will not close when the child process exits and the
+ # ReadFile will hang.
+ if p2cread is not None:
+ p2cread.Close()
+ if c2pwrite is not None:
+ c2pwrite.Close()
+ if errwrite is not None:
+ errwrite.Close()
+
+
+ def poll(self, _deadstate=None):
+ """Check if child process has terminated. Returns returncode
+ attribute."""
+ if self.returncode is None:
+ if WaitForSingleObject(self._handle, 0) == WAIT_OBJECT_0:
+ self.returncode = GetExitCodeProcess(self._handle)
+ return self.returncode
+
+
+ def wait(self):
+ """Wait for child process to terminate. Returns returncode
+ attribute."""
+ if self.returncode is None:
+ obj = WaitForSingleObject(self._handle, INFINITE)
+ self.returncode = GetExitCodeProcess(self._handle)
+ return self.returncode
+
+
+ def _readerthread(self, fh, buffer):
+ buffer.append(fh.read())
+
+
+ def _communicate(self, input):
+ stdout = None # Return
+ stderr = None # Return
+
+ if self.stdout:
+ stdout = []
+ stdout_thread = threading.Thread(target=self._readerthread,
+ args=(self.stdout, stdout))
+ stdout_thread.setDaemon(True)
+ stdout_thread.start()
+ if self.stderr:
+ stderr = []
+ stderr_thread = threading.Thread(target=self._readerthread,
+ args=(self.stderr, stderr))
+ stderr_thread.setDaemon(True)
+ stderr_thread.start()
+
+ if self.stdin:
+ if input is not None:
+ self.stdin.write(input)
+ self.stdin.close()
+
+ if self.stdout:
+ stdout_thread.join()
+ if self.stderr:
+ stderr_thread.join()
+
+ # All data exchanged. Translate lists into strings.
+ if stdout is not None:
+ stdout = stdout[0]
+ if stderr is not None:
+ stderr = stderr[0]
+
+ # Translate newlines, if requested. We cannot let the file
+ # object do the translation: It is based on stdio, which is
+ # impossible to combine with select (unless forcing no
+ # buffering).
+ if self.universal_newlines and hasattr(file, 'newlines'):
+ if stdout:
+ stdout = self._translate_newlines(stdout)
+ if stderr:
+ stderr = self._translate_newlines(stderr)
+
+ self.wait()
+ return (stdout, stderr)
+
+ else:
+ #
+ # POSIX methods
+ #
+ def _get_handles(self, stdin, stdout, stderr):
+ """Construct and return tupel with IO objects:
+ p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
+ """
+ p2cread, p2cwrite = None, None
+ c2pread, c2pwrite = None, None
+ errread, errwrite = None, None
+
+ if stdin is None:
+ pass
+ elif stdin == PIPE:
+ p2cread, p2cwrite = os.pipe()
+ elif is_int(stdin):
+ p2cread = stdin
+ else:
+ # Assuming file-like object
+ p2cread = stdin.fileno()
+
+ if stdout is None:
+ pass
+ elif stdout == PIPE:
+ c2pread, c2pwrite = os.pipe()
+ elif is_int(stdout):
+ c2pwrite = stdout
+ else:
+ # Assuming file-like object
+ c2pwrite = stdout.fileno()
+
+ if stderr is None:
+ pass
+ elif stderr == PIPE:
+ errread, errwrite = os.pipe()
+ elif stderr == STDOUT:
+ errwrite = c2pwrite
+ elif is_int(stderr):
+ errwrite = stderr
+ else:
+ # Assuming file-like object
+ errwrite = stderr.fileno()
+
+ return (p2cread, p2cwrite,
+ c2pread, c2pwrite,
+ errread, errwrite)
+
+
+ def _set_cloexec_flag(self, fd):
+ try:
+ cloexec_flag = fcntl.FD_CLOEXEC
+ except AttributeError:
+ cloexec_flag = 1
+
+ old = fcntl.fcntl(fd, fcntl.F_GETFD)
+ fcntl.fcntl(fd, fcntl.F_SETFD, old | cloexec_flag)
+
+
+ def _close_fds(self, but):
+ for i in range(3, MAXFD):
+ if i == but:
+ continue
+ try:
+ os.close(i)
+ except KeyboardInterrupt:
+ raise # SCons: don't swallow keyboard interrupts
+ except:
+ pass
+
+
+ def _execute_child(self, args, executable, preexec_fn, close_fds,
+ cwd, env, universal_newlines,
+ startupinfo, creationflags, shell,
+ p2cread, p2cwrite,
+ c2pread, c2pwrite,
+ errread, errwrite):
+ """Execute program (POSIX version)"""
+
+ if is_string(args):
+ args = [args]
+
+ if shell:
+ args = ["/bin/sh", "-c"] + args
+
+ if executable is None:
+ executable = args[0]
+
+ # For transferring possible exec failure from child to parent
+ # The first char specifies the exception type: 0 means
+ # OSError, 1 means some other error.
+ errpipe_read, errpipe_write = os.pipe()
+ self._set_cloexec_flag(errpipe_write)
+
+ self.pid = os.fork()
+ self._child_created = True
+ if self.pid == 0:
+ # Child
+ try:
+ # Close parent's pipe ends
+ if p2cwrite:
+ os.close(p2cwrite)
+ if c2pread:
+ os.close(c2pread)
+ if errread:
+ os.close(errread)
+ os.close(errpipe_read)
+
+ # Dup fds for child
+ if p2cread:
+ os.dup2(p2cread, 0)
+ if c2pwrite:
+ os.dup2(c2pwrite, 1)
+ if errwrite:
+ os.dup2(errwrite, 2)
+
+ # Close pipe fds. Make sure we don't close the same
+ # fd more than once, or standard fds.
+ try:
+ set
+ except NameError:
+ # Fall-back for earlier Python versions, so epydoc
+ # can use this module directly to execute things.
+ if p2cread:
+ os.close(p2cread)
+ if c2pwrite and c2pwrite not in (p2cread,):
+ os.close(c2pwrite)
+ if errwrite and errwrite not in (p2cread, c2pwrite):
+ os.close(errwrite)
+ else:
+ for fd in set((p2cread, c2pwrite, errwrite))-set((0,1,2)):
+ if fd: os.close(fd)
+
+ # Close all other fds, if asked for
+ if close_fds:
+ self._close_fds(but=errpipe_write)
+
+ if cwd is not None:
+ os.chdir(cwd)
+
+ if preexec_fn:
+ apply(preexec_fn)
+
+ if env is None:
+ os.execvp(executable, args)
+ else:
+ os.execvpe(executable, args, env)
+
+ except KeyboardInterrupt:
+ raise # SCons: don't swallow keyboard interrupts
+
+ except:
+ exc_type, exc_value, tb = sys.exc_info()
+ # Save the traceback and attach it to the exception object
+ exc_lines = traceback.format_exception(exc_type,
+ exc_value,
+ tb)
+ exc_value.child_traceback = ''.join(exc_lines)
+ os.write(errpipe_write, pickle.dumps(exc_value))
+
+ # This exitcode won't be reported to applications, so it
+ # really doesn't matter what we return.
+ os._exit(255)
+
+ # Parent
+ os.close(errpipe_write)
+ if p2cread and p2cwrite:
+ os.close(p2cread)
+ if c2pwrite and c2pread:
+ os.close(c2pwrite)
+ if errwrite and errread:
+ os.close(errwrite)
+
+ # Wait for exec to fail or succeed; possibly raising exception
+ data = os.read(errpipe_read, 1048576) # Exceptions limited to 1 MB
+ os.close(errpipe_read)
+ if data != "":
+ os.waitpid(self.pid, 0)
+ child_exception = pickle.loads(data)
+ raise child_exception
+
+
+ def _handle_exitstatus(self, sts):
+ if os.WIFSIGNALED(sts):
+ self.returncode = -os.WTERMSIG(sts)
+ elif os.WIFEXITED(sts):
+ self.returncode = os.WEXITSTATUS(sts)
+ else:
+ # Should never happen
+ raise RuntimeError("Unknown child exit status!")
+
+
+ def poll(self, _deadstate=None):
+ """Check if child process has terminated. Returns returncode
+ attribute."""
+ if self.returncode is None:
+ try:
+ pid, sts = os.waitpid(self.pid, os.WNOHANG)
+ if pid == self.pid:
+ self._handle_exitstatus(sts)
+ except os.error:
+ if _deadstate is not None:
+ self.returncode = _deadstate
+ return self.returncode
+
+
+ def wait(self):
+ """Wait for child process to terminate. Returns returncode
+ attribute."""
+ if self.returncode is None:
+ pid, sts = os.waitpid(self.pid, 0)
+ self._handle_exitstatus(sts)
+ return self.returncode
+
+
+ def _communicate(self, input):
+ read_set = []
+ write_set = []
+ stdout = None # Return
+ stderr = None # Return
+
+ if self.stdin:
+ # Flush stdio buffer. This might block, if the user has
+ # been writing to .stdin in an uncontrolled fashion.
+ self.stdin.flush()
+ if input:
+ write_set.append(self.stdin)
+ else:
+ self.stdin.close()
+ if self.stdout:
+ read_set.append(self.stdout)
+ stdout = []
+ if self.stderr:
+ read_set.append(self.stderr)
+ stderr = []
+
+ input_offset = 0
+ while read_set or write_set:
+ rlist, wlist, xlist = select.select(read_set, write_set, [])
+
+ if self.stdin in wlist:
+ # When select has indicated that the file is writable,
+ # we can write up to PIPE_BUF bytes without risk
+ # blocking. POSIX defines PIPE_BUF >= 512
+ m = memoryview(input)[input_offset:input_offset+512]
+ bytes_written = os.write(self.stdin.fileno(), m)
+ input_offset = input_offset + bytes_written
+ if input_offset >= len(input):
+ self.stdin.close()
+ write_set.remove(self.stdin)
+
+ if self.stdout in rlist:
+ data = os.read(self.stdout.fileno(), 1024)
+ if data == "":
+ self.stdout.close()
+ read_set.remove(self.stdout)
+ stdout.append(data)
+
+ if self.stderr in rlist:
+ data = os.read(self.stderr.fileno(), 1024)
+ if data == "":
+ self.stderr.close()
+ read_set.remove(self.stderr)
+ stderr.append(data)
+
+ # All data exchanged. Translate lists into strings.
+ if stdout is not None:
+ stdout = ''.join(stdout)
+ if stderr is not None:
+ stderr = ''.join(stderr)
+
+ # Translate newlines, if requested. We cannot let the file
+ # object do the translation: It is based on stdio, which is
+ # impossible to combine with select (unless forcing no
+ # buffering).
+ if self.universal_newlines and hasattr(file, 'newlines'):
+ if stdout:
+ stdout = self._translate_newlines(stdout)
+ if stderr:
+ stderr = self._translate_newlines(stderr)
+
+ self.wait()
+ return (stdout, stderr)
+
+
+def _demo_posix():
+ #
+ # Example 1: Simple redirection: Get process list
+ #
+ plist = Popen(["ps"], stdout=PIPE).communicate()[0]
+ print "Process list:"
+ print plist
+
+ #
+ # Example 2: Change uid before executing child
+ #
+ if os.getuid() == 0:
+ p = Popen(["id"], preexec_fn=lambda: os.setuid(100))
+ p.wait()
+
+ #
+ # Example 3: Connecting several subprocesses
+ #
+ print "Looking for 'hda'..."
+ p1 = Popen(["dmesg"], stdout=PIPE)
+ p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
+ print repr(p2.communicate()[0])
+
+ #
+ # Example 4: Catch execution error
+ #
+ print
+ print "Trying a weird file..."
+ try:
+ print Popen(["/this/path/does/not/exist"]).communicate()
+ except OSError, e:
+ if e.errno == errno.ENOENT:
+ print "The file didn't exist. I thought so..."
+ print "Child traceback:"
+ print e.child_traceback
+ else:
+ print "Error", e.errno
+ else:
+ sys.stderr.write( "Gosh. No error.\n" )
+
+
+def _demo_windows():
+ #
+ # Example 1: Connecting several subprocesses
+ #
+ print "Looking for 'PROMPT' in set output..."
+ p1 = Popen("set", stdout=PIPE, shell=True)
+ p2 = Popen('find "PROMPT"', stdin=p1.stdout, stdout=PIPE)
+ print repr(p2.communicate()[0])
+
+ #
+ # Example 2: Simple execution of program
+ #
+ print "Executing calc..."
+ p = Popen("calc")
+ p.wait()
+
+
+if __name__ == "__main__":
+ if mswindows:
+ _demo_windows()
+ else:
+ _demo_posix()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/cpp.py b/couchjs/scons/scons-local-2.0.1/SCons/cpp.py
new file mode 100644
index 00000000..496d3f48
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/cpp.py
@@ -0,0 +1,589 @@
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/cpp.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__doc__ = """
+SCons C Pre-Processor module
+"""
+#TODO 2.3 and before has no sorted()
+import SCons.compat
+
+import os
+import re
+
+#
+# First "subsystem" of regular expressions that we set up:
+#
+# Stuff to turn the C preprocessor directives in a file's contents into
+# a list of tuples that we can process easily.
+#
+
+# A table of regular expressions that fetch the arguments from the rest of
+# a C preprocessor line. Different directives have different arguments
+# that we want to fetch, using the regular expressions to which the lists
+# of preprocessor directives map.
+cpp_lines_dict = {
+ # Fetch the rest of a #if/#elif/#ifdef/#ifndef as one argument,
+ # separated from the keyword by white space.
+ ('if', 'elif', 'ifdef', 'ifndef',)
+ : '\s+(.+)',
+
+ # Fetch the rest of a #import/#include/#include_next line as one
+ # argument, with white space optional.
+ ('import', 'include', 'include_next',)
+ : '\s*(.+)',
+
+ # We don't care what comes after a #else or #endif line.
+ ('else', 'endif',) : '',
+
+ # Fetch three arguments from a #define line:
+ # 1) The #defined keyword.
+ # 2) The optional parentheses and arguments (if it's a function-like
+ # macro, '' if it's not).
+ # 3) The expansion value.
+ ('define',) : '\s+([_A-Za-z][_A-Za-z0-9_]*)(\([^)]*\))?\s*(.*)',
+
+ # Fetch the #undefed keyword from a #undef line.
+ ('undef',) : '\s+([_A-Za-z][A-Za-z0-9_]*)',
+}
+
+# Create a table that maps each individual C preprocessor directive to
+# the corresponding compiled regular expression that fetches the arguments
+# we care about.
+Table = {}
+for op_list, expr in cpp_lines_dict.items():
+ e = re.compile(expr)
+ for op in op_list:
+ Table[op] = e
+del e
+del op
+del op_list
+
+# Create a list of the expressions we'll use to match all of the
+# preprocessor directives. These are the same as the directives
+# themselves *except* that we must use a negative lookahead assertion
+# when matching "if" so it doesn't match the "if" in "ifdef."
+override = {
+ 'if' : 'if(?!def)',
+}
+l = [override.get(x, x) for x in Table.keys()]
+
+
+# Turn the list of expressions into one big honkin' regular expression
+# that will match all the preprocessor lines at once. This will return
+# a list of tuples, one for each preprocessor line. The preprocessor
+# directive will be the first element in each tuple, and the rest of
+# the line will be the second element.
+e = '^\s*#\s*(' + '|'.join(l) + ')(.*)$'
+
+# And last but not least, compile the expression.
+CPP_Expression = re.compile(e, re.M)
+
+
+
+
+#
+# Second "subsystem" of regular expressions that we set up:
+#
+# Stuff to translate a C preprocessor expression (as found on a #if or
+# #elif line) into an equivalent Python expression that we can eval().
+#
+
+# A dictionary that maps the C representation of Boolean operators
+# to their Python equivalents.
+CPP_to_Python_Ops_Dict = {
+ '!' : ' not ',
+ '!=' : ' != ',
+ '&&' : ' and ',
+ '||' : ' or ',
+ '?' : ' and ',
+ ':' : ' or ',
+ '\r' : '',
+}
+
+CPP_to_Python_Ops_Sub = lambda m: CPP_to_Python_Ops_Dict[m.group(0)]
+
+# We have to sort the keys by length so that longer expressions
+# come *before* shorter expressions--in particular, "!=" must
+# come before "!" in the alternation. Without this, the Python
+# re module, as late as version 2.2.2, empirically matches the
+# "!" in "!=" first, instead of finding the longest match.
+# What's up with that?
+l = sorted(CPP_to_Python_Ops_Dict.keys(), key=lambda a: len(a), reverse=True)
+
+# Turn the list of keys into one regular expression that will allow us
+# to substitute all of the operators at once.
+expr = '|'.join(map(re.escape, l))
+
+# ...and compile the expression.
+CPP_to_Python_Ops_Expression = re.compile(expr)
+
+# A separate list of expressions to be evaluated and substituted
+# sequentially, not all at once.
+CPP_to_Python_Eval_List = [
+ ['defined\s+(\w+)', '"\\1" in __dict__'],
+ ['defined\s*\((\w+)\)', '"\\1" in __dict__'],
+ ['/\*.*\*/', ''],
+ ['/\*.*', ''],
+ ['//.*', ''],
+ ['(0x[0-9A-Fa-f]*)[UL]+', '\\1'],
+]
+
+# Replace the string representations of the regular expressions in the
+# list with compiled versions.
+for l in CPP_to_Python_Eval_List:
+ l[0] = re.compile(l[0])
+
+# Wrap up all of the above into a handy function.
+def CPP_to_Python(s):
+ """
+ Converts a C pre-processor expression into an equivalent
+ Python expression that can be evaluated.
+ """
+ s = CPP_to_Python_Ops_Expression.sub(CPP_to_Python_Ops_Sub, s)
+ for expr, repl in CPP_to_Python_Eval_List:
+ s = expr.sub(repl, s)
+ return s
+
+
+
+del expr
+del l
+del override
+
+
+
+class FunctionEvaluator(object):
+ """
+ Handles delayed evaluation of a #define function call.
+ """
+ def __init__(self, name, args, expansion):
+ """
+ Squirrels away the arguments and expansion value of a #define
+ macro function for later evaluation when we must actually expand
+ a value that uses it.
+ """
+ self.name = name
+ self.args = function_arg_separator.split(args)
+ try:
+ expansion = expansion.split('##')
+ except AttributeError:
+ pass
+ self.expansion = expansion
+ def __call__(self, *values):
+ """
+ Evaluates the expansion of a #define macro function called
+ with the specified values.
+ """
+ if len(self.args) != len(values):
+ raise ValueError("Incorrect number of arguments to `%s'" % self.name)
+ # Create a dictionary that maps the macro arguments to the
+ # corresponding values in this "call." We'll use this when we
+ # eval() the expansion so that arguments will get expanded to
+ # the right values.
+ locals = {}
+ for k, v in zip(self.args, values):
+ locals[k] = v
+
+ parts = []
+ for s in self.expansion:
+ if not s in self.args:
+ s = repr(s)
+ parts.append(s)
+ statement = ' + '.join(parts)
+
+ return eval(statement, globals(), locals)
+
+
+
+# Find line continuations.
+line_continuations = re.compile('\\\\\r?\n')
+
+# Search for a "function call" macro on an expansion. Returns the
+# two-tuple of the "function" name itself, and a string containing the
+# arguments within the call parentheses.
+function_name = re.compile('(\S+)\(([^)]*)\)')
+
+# Split a string containing comma-separated function call arguments into
+# the separate arguments.
+function_arg_separator = re.compile(',\s*')
+
+
+
+class PreProcessor(object):
+ """
+ The main workhorse class for handling C pre-processing.
+ """
+ def __init__(self, current=os.curdir, cpppath=(), dict={}, all=0):
+ global Table
+
+ cpppath = tuple(cpppath)
+
+ self.searchpath = {
+ '"' : (current,) + cpppath,
+ '<' : cpppath + (current,),
+ }
+
+ # Initialize our C preprocessor namespace for tracking the
+ # values of #defined keywords. We use this namespace to look
+ # for keywords on #ifdef/#ifndef lines, and to eval() the
+ # expressions on #if/#elif lines (after massaging them from C to
+ # Python).
+ self.cpp_namespace = dict.copy()
+ self.cpp_namespace['__dict__'] = self.cpp_namespace
+
+ if all:
+ self.do_include = self.all_include
+
+ # For efficiency, a dispatch table maps each C preprocessor
+ # directive (#if, #define, etc.) to the method that should be
+ # called when we see it. We accomodate state changes (#if,
+ # #ifdef, #ifndef) by pushing the current dispatch table on a
+ # stack and changing what method gets called for each relevant
+ # directive we might see next at this level (#else, #elif).
+ # #endif will simply pop the stack.
+ d = {
+ 'scons_current_file' : self.scons_current_file
+ }
+ for op in Table.keys():
+ d[op] = getattr(self, 'do_' + op)
+ self.default_table = d
+
+ # Controlling methods.
+
+ def tupleize(self, contents):
+ """
+ Turns the contents of a file into a list of easily-processed
+ tuples describing the CPP lines in the file.
+
+ The first element of each tuple is the line's preprocessor
+ directive (#if, #include, #define, etc., minus the initial '#').
+ The remaining elements are specific to the type of directive, as
+ pulled apart by the regular expression.
+ """
+ global CPP_Expression, Table
+ contents = line_continuations.sub('', contents)
+ cpp_tuples = CPP_Expression.findall(contents)
+ return [(m[0],) + Table[m[0]].match(m[1]).groups() for m in cpp_tuples]
+
+ def __call__(self, file):
+ """
+ Pre-processes a file.
+
+ This is the main public entry point.
+ """
+ self.current_file = file
+ return self.process_contents(self.read_file(file), file)
+
+ def process_contents(self, contents, fname=None):
+ """
+ Pre-processes a file contents.
+
+ This is the main internal entry point.
+ """
+ self.stack = []
+ self.dispatch_table = self.default_table.copy()
+ self.current_file = fname
+ self.tuples = self.tupleize(contents)
+
+ self.initialize_result(fname)
+ while self.tuples:
+ t = self.tuples.pop(0)
+ # Uncomment to see the list of tuples being processed (e.g.,
+ # to validate the CPP lines are being translated correctly).
+ #print t
+ self.dispatch_table[t[0]](t)
+ return self.finalize_result(fname)
+
+ # Dispatch table stack manipulation methods.
+
+ def save(self):
+ """
+ Pushes the current dispatch table on the stack and re-initializes
+ the current dispatch table to the default.
+ """
+ self.stack.append(self.dispatch_table)
+ self.dispatch_table = self.default_table.copy()
+
+ def restore(self):
+ """
+ Pops the previous dispatch table off the stack and makes it the
+ current one.
+ """
+ try: self.dispatch_table = self.stack.pop()
+ except IndexError: pass
+
+ # Utility methods.
+
+ def do_nothing(self, t):
+ """
+ Null method for when we explicitly want the action for a
+ specific preprocessor directive to do nothing.
+ """
+ pass
+
+ def scons_current_file(self, t):
+ self.current_file = t[1]
+
+ def eval_expression(self, t):
+ """
+ Evaluates a C preprocessor expression.
+
+ This is done by converting it to a Python equivalent and
+ eval()ing it in the C preprocessor namespace we use to
+ track #define values.
+ """
+ t = CPP_to_Python(' '.join(t[1:]))
+ try: return eval(t, self.cpp_namespace)
+ except (NameError, TypeError): return 0
+
+ def initialize_result(self, fname):
+ self.result = [fname]
+
+ def finalize_result(self, fname):
+ return self.result[1:]
+
+ def find_include_file(self, t):
+ """
+ Finds the #include file for a given preprocessor tuple.
+ """
+ fname = t[2]
+ for d in self.searchpath[t[1]]:
+ if d == os.curdir:
+ f = fname
+ else:
+ f = os.path.join(d, fname)
+ if os.path.isfile(f):
+ return f
+ return None
+
+ def read_file(self, file):
+ return open(file).read()
+
+ # Start and stop processing include lines.
+
+ def start_handling_includes(self, t=None):
+ """
+ Causes the PreProcessor object to start processing #import,
+ #include and #include_next lines.
+
+ This method will be called when a #if, #ifdef, #ifndef or #elif
+ evaluates True, or when we reach the #else in a #if, #ifdef,
+ #ifndef or #elif block where a condition already evaluated
+ False.
+
+ """
+ d = self.dispatch_table
+ d['import'] = self.do_import
+ d['include'] = self.do_include
+ d['include_next'] = self.do_include
+
+ def stop_handling_includes(self, t=None):
+ """
+ Causes the PreProcessor object to stop processing #import,
+ #include and #include_next lines.
+
+ This method will be called when a #if, #ifdef, #ifndef or #elif
+ evaluates False, or when we reach the #else in a #if, #ifdef,
+ #ifndef or #elif block where a condition already evaluated True.
+ """
+ d = self.dispatch_table
+ d['import'] = self.do_nothing
+ d['include'] = self.do_nothing
+ d['include_next'] = self.do_nothing
+
+ # Default methods for handling all of the preprocessor directives.
+ # (Note that what actually gets called for a given directive at any
+ # point in time is really controlled by the dispatch_table.)
+
+ def _do_if_else_condition(self, condition):
+ """
+ Common logic for evaluating the conditions on #if, #ifdef and
+ #ifndef lines.
+ """
+ self.save()
+ d = self.dispatch_table
+ if condition:
+ self.start_handling_includes()
+ d['elif'] = self.stop_handling_includes
+ d['else'] = self.stop_handling_includes
+ else:
+ self.stop_handling_includes()
+ d['elif'] = self.do_elif
+ d['else'] = self.start_handling_includes
+
+ def do_ifdef(self, t):
+ """
+ Default handling of a #ifdef line.
+ """
+ self._do_if_else_condition(t[1] in self.cpp_namespace)
+
+ def do_ifndef(self, t):
+ """
+ Default handling of a #ifndef line.
+ """
+ self._do_if_else_condition(t[1] not in self.cpp_namespace)
+
+ def do_if(self, t):
+ """
+ Default handling of a #if line.
+ """
+ self._do_if_else_condition(self.eval_expression(t))
+
+ def do_elif(self, t):
+ """
+ Default handling of a #elif line.
+ """
+ d = self.dispatch_table
+ if self.eval_expression(t):
+ self.start_handling_includes()
+ d['elif'] = self.stop_handling_includes
+ d['else'] = self.stop_handling_includes
+
+ def do_else(self, t):
+ """
+ Default handling of a #else line.
+ """
+ pass
+
+ def do_endif(self, t):
+ """
+ Default handling of a #endif line.
+ """
+ self.restore()
+
+ def do_define(self, t):
+ """
+ Default handling of a #define line.
+ """
+ _, name, args, expansion = t
+ try:
+ expansion = int(expansion)
+ except (TypeError, ValueError):
+ pass
+ if args:
+ evaluator = FunctionEvaluator(name, args[1:-1], expansion)
+ self.cpp_namespace[name] = evaluator
+ else:
+ self.cpp_namespace[name] = expansion
+
+ def do_undef(self, t):
+ """
+ Default handling of a #undef line.
+ """
+ try: del self.cpp_namespace[t[1]]
+ except KeyError: pass
+
+ def do_import(self, t):
+ """
+ Default handling of a #import line.
+ """
+ # XXX finish this -- maybe borrow/share logic from do_include()...?
+ pass
+
+ def do_include(self, t):
+ """
+ Default handling of a #include line.
+ """
+ t = self.resolve_include(t)
+ include_file = self.find_include_file(t)
+ if include_file:
+ #print "include_file =", include_file
+ self.result.append(include_file)
+ contents = self.read_file(include_file)
+ new_tuples = [('scons_current_file', include_file)] + \
+ self.tupleize(contents) + \
+ [('scons_current_file', self.current_file)]
+ self.tuples[:] = new_tuples + self.tuples
+
+ # Date: Tue, 22 Nov 2005 20:26:09 -0500
+ # From: Stefan Seefeld <seefeld@sympatico.ca>
+ #
+ # By the way, #include_next is not the same as #include. The difference
+ # being that #include_next starts its search in the path following the
+ # path that let to the including file. In other words, if your system
+ # include paths are ['/foo', '/bar'], and you are looking at a header
+ # '/foo/baz.h', it might issue an '#include_next <baz.h>' which would
+ # correctly resolve to '/bar/baz.h' (if that exists), but *not* see
+ # '/foo/baz.h' again. See http://www.delorie.com/gnu/docs/gcc/cpp_11.html
+ # for more reasoning.
+ #
+ # I have no idea in what context 'import' might be used.
+
+ # XXX is #include_next really the same as #include ?
+ do_include_next = do_include
+
+ # Utility methods for handling resolution of include files.
+
+ def resolve_include(self, t):
+ """Resolve a tuple-ized #include line.
+
+ This handles recursive expansion of values without "" or <>
+ surrounding the name until an initial " or < is found, to handle
+ #include FILE
+ where FILE is a #define somewhere else.
+ """
+ s = t[1]
+ while not s[0] in '<"':
+ #print "s =", s
+ try:
+ s = self.cpp_namespace[s]
+ except KeyError:
+ m = function_name.search(s)
+ s = self.cpp_namespace[m.group(1)]
+ if callable(s):
+ args = function_arg_separator.split(m.group(2))
+ s = s(*args)
+ if not s:
+ return None
+ return (t[0], s[0], s[1:-1])
+
+ def all_include(self, t):
+ """
+ """
+ self.result.append(self.resolve_include(t))
+
+class DumbPreProcessor(PreProcessor):
+ """A preprocessor that ignores all #if/#elif/#else/#endif directives
+ and just reports back *all* of the #include files (like the classic
+ SCons scanner did).
+
+ This is functionally equivalent to using a regular expression to
+ find all of the #include lines, only slower. It exists mainly as
+ an example of how the main PreProcessor class can be sub-classed
+ to tailor its behavior.
+ """
+ def __init__(self, *args, **kw):
+ PreProcessor.__init__(self, *args, **kw)
+ d = self.default_table
+ for func in ['if', 'elif', 'else', 'endif', 'ifdef', 'ifndef']:
+ d[func] = d[func] = self.do_nothing
+
+del __revision__
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/dblite.py b/couchjs/scons/scons-local-2.0.1/SCons/dblite.py
new file mode 100644
index 00000000..ea24e6a3
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/dblite.py
@@ -0,0 +1,251 @@
+# dblite.py module contributed by Ralf W. Grosse-Kunstleve.
+# Extended for Unicode by Steven Knight.
+
+import SCons.compat
+
+import builtins
+import os
+# compat layer imports "cPickle" for us if it's available.
+import pickle
+import shutil
+import time
+
+keep_all_files = 00000
+ignore_corrupt_dbfiles = 0
+
+def corruption_warning(filename):
+ print "Warning: Discarding corrupt database:", filename
+
+try: unicode
+except NameError:
+ def is_string(s):
+ return isinstance(s, str)
+else:
+ def is_string(s):
+ return type(s) in (str, unicode)
+
+try:
+ unicode('a')
+except NameError:
+ def unicode(s): return s
+
+dblite_suffix = '.dblite'
+tmp_suffix = '.tmp'
+
+class dblite(object):
+
+ # Squirrel away references to the functions in various modules
+ # that we'll use when our __del__() method calls our sync() method
+ # during shutdown. We might get destroyed when Python is in the midst
+ # of tearing down the different modules we import in an essentially
+ # arbitrary order, and some of the various modules's global attributes
+ # may already be wiped out from under us.
+ #
+ # See the discussion at:
+ # http://mail.python.org/pipermail/python-bugs-list/2003-March/016877.html
+
+ _open = builtins.open
+ _pickle_dump = staticmethod(pickle.dump)
+ _os_chmod = os.chmod
+ try:
+ _os_chown = os.chown
+ except AttributeError:
+ _os_chown = None
+ _os_rename = os.rename
+ _os_unlink = os.unlink
+ _shutil_copyfile = shutil.copyfile
+ _time_time = time.time
+
+ def __init__(self, file_base_name, flag, mode):
+ assert flag in (None, "r", "w", "c", "n")
+ if (flag is None): flag = "r"
+ base, ext = os.path.splitext(file_base_name)
+ if ext == dblite_suffix:
+ # There's already a suffix on the file name, don't add one.
+ self._file_name = file_base_name
+ self._tmp_name = base + tmp_suffix
+ else:
+ self._file_name = file_base_name + dblite_suffix
+ self._tmp_name = file_base_name + tmp_suffix
+ self._flag = flag
+ self._mode = mode
+ self._dict = {}
+ self._needs_sync = 00000
+ if self._os_chown is not None and (os.geteuid()==0 or os.getuid()==0):
+ # running as root; chown back to current owner/group when done
+ try:
+ statinfo = os.stat(self._file_name)
+ self._chown_to = statinfo.st_uid
+ self._chgrp_to = statinfo.st_gid
+ except OSError, e:
+ # db file doesn't exist yet.
+ # Check os.environ for SUDO_UID, use if set
+ self._chown_to = int(os.environ.get('SUDO_UID', -1))
+ self._chgrp_to = int(os.environ.get('SUDO_GID', -1))
+ else:
+ self._chown_to = -1 # don't chown
+ self._chgrp_to = -1 # don't chgrp
+ if (self._flag == "n"):
+ self._open(self._file_name, "wb", self._mode)
+ else:
+ try:
+ f = self._open(self._file_name, "rb")
+ except IOError, e:
+ if (self._flag != "c"):
+ raise e
+ self._open(self._file_name, "wb", self._mode)
+ else:
+ p = f.read()
+ if (len(p) > 0):
+ try:
+ self._dict = pickle.loads(p)
+ except (pickle.UnpicklingError, EOFError):
+ if (ignore_corrupt_dbfiles == 0): raise
+ if (ignore_corrupt_dbfiles == 1):
+ corruption_warning(self._file_name)
+
+ def __del__(self):
+ if (self._needs_sync):
+ self.sync()
+
+ def sync(self):
+ self._check_writable()
+ f = self._open(self._tmp_name, "wb", self._mode)
+ self._pickle_dump(self._dict, f, 1)
+ f.close()
+ # Windows doesn't allow renaming if the file exists, so unlink
+ # it first, chmod'ing it to make sure we can do so. On UNIX, we
+ # may not be able to chmod the file if it's owned by someone else
+ # (e.g. from a previous run as root). We should still be able to
+ # unlink() the file if the directory's writable, though, so ignore
+ # any OSError exception thrown by the chmod() call.
+ try: self._os_chmod(self._file_name, 0777)
+ except OSError: pass
+ self._os_unlink(self._file_name)
+ self._os_rename(self._tmp_name, self._file_name)
+ if self._os_chown is not None and self._chown_to > 0: # don't chown to root or -1
+ try:
+ self._os_chown(self._file_name, self._chown_to, self._chgrp_to)
+ except OSError:
+ pass
+ self._needs_sync = 00000
+ if (keep_all_files):
+ self._shutil_copyfile(
+ self._file_name,
+ self._file_name + "_" + str(int(self._time_time())))
+
+ def _check_writable(self):
+ if (self._flag == "r"):
+ raise IOError("Read-only database: %s" % self._file_name)
+
+ def __getitem__(self, key):
+ return self._dict[key]
+
+ def __setitem__(self, key, value):
+ self._check_writable()
+ if (not is_string(key)):
+ raise TypeError("key `%s' must be a string but is %s" % (key, type(key)))
+ if (not is_string(value)):
+ raise TypeError("value `%s' must be a string but is %s" % (value, type(value)))
+ self._dict[key] = value
+ self._needs_sync = 0001
+
+ def keys(self):
+ return list(self._dict.keys())
+
+ def has_key(self, key):
+ return key in self._dict
+
+ def __contains__(self, key):
+ return key in self._dict
+
+ def iterkeys(self):
+ # Wrapping name in () prevents fixer from "fixing" this
+ return (self._dict.iterkeys)()
+
+ __iter__ = iterkeys
+
+ def __len__(self):
+ return len(self._dict)
+
+def open(file, flag=None, mode=0666):
+ return dblite(file, flag, mode)
+
+def _exercise():
+ db = open("tmp", "n")
+ assert len(db) == 0
+ db["foo"] = "bar"
+ assert db["foo"] == "bar"
+ db[unicode("ufoo")] = unicode("ubar")
+ assert db[unicode("ufoo")] == unicode("ubar")
+ db.sync()
+ db = open("tmp", "c")
+ assert len(db) == 2, len(db)
+ assert db["foo"] == "bar"
+ db["bar"] = "foo"
+ assert db["bar"] == "foo"
+ db[unicode("ubar")] = unicode("ufoo")
+ assert db[unicode("ubar")] == unicode("ufoo")
+ db.sync()
+ db = open("tmp", "r")
+ assert len(db) == 4, len(db)
+ assert db["foo"] == "bar"
+ assert db["bar"] == "foo"
+ assert db[unicode("ufoo")] == unicode("ubar")
+ assert db[unicode("ubar")] == unicode("ufoo")
+ try:
+ db.sync()
+ except IOError, e:
+ assert str(e) == "Read-only database: tmp.dblite"
+ else:
+ raise RuntimeError("IOError expected.")
+ db = open("tmp", "w")
+ assert len(db) == 4
+ db["ping"] = "pong"
+ db.sync()
+ try:
+ db[(1,2)] = "tuple"
+ except TypeError, e:
+ assert str(e) == "key `(1, 2)' must be a string but is <type 'tuple'>", str(e)
+ else:
+ raise RuntimeError("TypeError exception expected")
+ try:
+ db["list"] = [1,2]
+ except TypeError, e:
+ assert str(e) == "value `[1, 2]' must be a string but is <type 'list'>", str(e)
+ else:
+ raise RuntimeError("TypeError exception expected")
+ db = open("tmp", "r")
+ assert len(db) == 5
+ db = open("tmp", "n")
+ assert len(db) == 0
+ dblite._open("tmp.dblite", "w")
+ db = open("tmp", "r")
+ dblite._open("tmp.dblite", "w").write("x")
+ try:
+ db = open("tmp", "r")
+ except pickle.UnpicklingError:
+ pass
+ else:
+ raise RuntimeError("pickle exception expected.")
+ global ignore_corrupt_dbfiles
+ ignore_corrupt_dbfiles = 2
+ db = open("tmp", "r")
+ assert len(db) == 0
+ os.unlink("tmp.dblite")
+ try:
+ db = open("tmp", "w")
+ except IOError, e:
+ assert str(e) == "[Errno 2] No such file or directory: 'tmp.dblite'", str(e)
+ else:
+ raise RuntimeError("IOError expected.")
+ print "OK"
+
+if (__name__ == "__main__"):
+ _exercise()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/SCons/exitfuncs.py b/couchjs/scons/scons-local-2.0.1/SCons/exitfuncs.py
new file mode 100644
index 00000000..a72fe03d
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/SCons/exitfuncs.py
@@ -0,0 +1,77 @@
+"""SCons.exitfuncs
+
+Register functions which are executed when SCons exits for any reason.
+
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/engine/SCons/exitfuncs.py 5134 2010/08/16 23:02:40 bdeegan"
+
+
+
+_exithandlers = []
+def _run_exitfuncs():
+ """run any registered exit functions
+
+ _exithandlers is traversed in reverse order so functions are executed
+ last in, first out.
+ """
+
+ while _exithandlers:
+ func, targs, kargs = _exithandlers.pop()
+ func(*targs, **kargs)
+
+def register(func, *targs, **kargs):
+ """register a function to be executed upon normal program termination
+
+ func - function to be called at exit
+ targs - optional arguments to pass to func
+ kargs - optional keyword arguments to pass to func
+ """
+ _exithandlers.append((func, targs, kargs))
+
+import sys
+
+try:
+ x = sys.exitfunc
+
+ # if x isn't our own exit func executive, assume it's another
+ # registered exit function - append it to our list...
+ if x != _run_exitfuncs:
+ register(x)
+
+except AttributeError:
+ pass
+
+# make our exit function get run by python when it exits:
+sys.exitfunc = _run_exitfuncs
+
+del sys
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons-local-2.0.1/scons-2.0.1.egg-info b/couchjs/scons/scons-local-2.0.1/scons-2.0.1.egg-info
new file mode 100644
index 00000000..e5e2216e
--- /dev/null
+++ b/couchjs/scons/scons-local-2.0.1/scons-2.0.1.egg-info
@@ -0,0 +1,13 @@
+Metadata-Version: 1.0
+Name: scons
+Version: 2.0.1
+Summary: Open Source next-generation build tool.
+Home-page: http://www.scons.org/
+Author: Steven Knight
+Author-email: knight@baldmt.com
+License: UNKNOWN
+Description: Open Source next-generation build tool.
+ Improved, cross-platform substitute for the classic Make
+ utility. In short, SCons is an easier, more reliable
+ and faster way to build software.
+Platform: UNKNOWN
diff --git a/couchjs/scons/scons-time.py b/couchjs/scons/scons-time.py
new file mode 100755
index 00000000..36bdeb58
--- /dev/null
+++ b/couchjs/scons/scons-time.py
@@ -0,0 +1,1544 @@
+#!/usr/bin/env python
+#
+# scons-time - run SCons timings and collect statistics
+#
+# A script for running a configuration through SCons with a standard
+# set of invocations to collect timing and memory statistics and to
+# capture the results in a consistent set of output files for display
+# and analysis.
+#
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+from __future__ import division
+from __future__ import nested_scopes
+
+__revision__ = "src/script/scons-time.py 5134 2010/08/16 23:02:40 bdeegan"
+
+import getopt
+import glob
+import os
+import re
+import shutil
+import sys
+import tempfile
+import time
+
+try:
+ sorted
+except NameError:
+ # Pre-2.4 Python has no sorted() function.
+ #
+ # The pre-2.4 Python list.sort() method does not support
+ # list.sort(key=) nor list.sort(reverse=) keyword arguments, so
+ # we must implement the functionality of those keyword arguments
+ # by hand instead of passing them to list.sort().
+ def sorted(iterable, cmp=None, key=None, reverse=False):
+ if key is not None:
+ result = [(key(x), x) for x in iterable]
+ else:
+ result = iterable[:]
+ if cmp is None:
+ # Pre-2.3 Python does not support list.sort(None).
+ result.sort()
+ else:
+ result.sort(cmp)
+ if key is not None:
+ result = [t1 for t0,t1 in result]
+ if reverse:
+ result.reverse()
+ return result
+
+if os.environ.get('SCONS_HORRIBLE_REGRESSION_TEST_HACK') is not None:
+ # We can't apply the 'callable' fixer until the floor is 2.6, but the
+ # '-3' option to Python 2.6 and 2.7 generates almost ten thousand
+ # warnings. This hack allows us to run regression tests with the '-3'
+ # option by replacing the callable() built-in function with a hack
+ # that performs the same function but doesn't generate the warning.
+ # Note that this hack is ONLY intended to be used for regression
+ # testing, and should NEVER be used for real runs.
+ from types import ClassType
+ def callable(obj):
+ if hasattr(obj, '__call__'): return True
+ if isinstance(obj, (ClassType, type)): return True
+ return False
+
+def make_temp_file(**kw):
+ try:
+ result = tempfile.mktemp(**kw)
+ try:
+ result = os.path.realpath(result)
+ except AttributeError:
+ # Python 2.1 has no os.path.realpath() method.
+ pass
+ except TypeError:
+ try:
+ save_template = tempfile.template
+ prefix = kw['prefix']
+ del kw['prefix']
+ tempfile.template = prefix
+ result = tempfile.mktemp(**kw)
+ finally:
+ tempfile.template = save_template
+ return result
+
+def HACK_for_exec(cmd, *args):
+ '''
+ For some reason, Python won't allow an exec() within a function
+ that also declares an internal function (including lambda functions).
+ This function is a hack that calls exec() in a function with no
+ internal functions.
+ '''
+ if not args: exec(cmd)
+ elif len(args) == 1: exec cmd in args[0]
+ else: exec cmd in args[0], args[1]
+
+class Plotter(object):
+ def increment_size(self, largest):
+ """
+ Return the size of each horizontal increment line for a specified
+ maximum value. This returns a value that will provide somewhere
+ between 5 and 9 horizontal lines on the graph, on some set of
+ boundaries that are multiples of 10/100/1000/etc.
+ """
+ i = largest // 5
+ if not i:
+ return largest
+ multiplier = 1
+ while i >= 10:
+ i = i // 10
+ multiplier = multiplier * 10
+ return i * multiplier
+
+ def max_graph_value(self, largest):
+ # Round up to next integer.
+ largest = int(largest) + 1
+ increment = self.increment_size(largest)
+ return ((largest + increment - 1) // increment) * increment
+
+class Line(object):
+ def __init__(self, points, type, title, label, comment, fmt="%s %s"):
+ self.points = points
+ self.type = type
+ self.title = title
+ self.label = label
+ self.comment = comment
+ self.fmt = fmt
+
+ def print_label(self, inx, x, y):
+ if self.label:
+ print 'set label %s "%s" at %s,%s right' % (inx, self.label, x, y)
+
+ def plot_string(self):
+ if self.title:
+ title_string = 'title "%s"' % self.title
+ else:
+ title_string = 'notitle'
+ return "'-' %s with lines lt %s" % (title_string, self.type)
+
+ def print_points(self, fmt=None):
+ if fmt is None:
+ fmt = self.fmt
+ if self.comment:
+ print '# %s' % self.comment
+ for x, y in self.points:
+ # If y is None, it usually represents some kind of break
+ # in the line's index number. We might want to represent
+ # this some way rather than just drawing the line straight
+ # between the two points on either side.
+ if not y is None:
+ print fmt % (x, y)
+ print 'e'
+
+ def get_x_values(self):
+ return [ p[0] for p in self.points ]
+
+ def get_y_values(self):
+ return [ p[1] for p in self.points ]
+
+class Gnuplotter(Plotter):
+
+ def __init__(self, title, key_location):
+ self.lines = []
+ self.title = title
+ self.key_location = key_location
+
+ def line(self, points, type, title=None, label=None, comment=None, fmt='%s %s'):
+ if points:
+ line = Line(points, type, title, label, comment, fmt)
+ self.lines.append(line)
+
+ def plot_string(self, line):
+ return line.plot_string()
+
+ def vertical_bar(self, x, type, label, comment):
+ if self.get_min_x() <= x and x <= self.get_max_x():
+ points = [(x, 0), (x, self.max_graph_value(self.get_max_y()))]
+ self.line(points, type, label, comment)
+
+ def get_all_x_values(self):
+ result = []
+ for line in self.lines:
+ result.extend(line.get_x_values())
+ return [r for r in result if not r is None]
+
+ def get_all_y_values(self):
+ result = []
+ for line in self.lines:
+ result.extend(line.get_y_values())
+ return [r for r in result if not r is None]
+
+ def get_min_x(self):
+ try:
+ return self.min_x
+ except AttributeError:
+ try:
+ self.min_x = min(self.get_all_x_values())
+ except ValueError:
+ self.min_x = 0
+ return self.min_x
+
+ def get_max_x(self):
+ try:
+ return self.max_x
+ except AttributeError:
+ try:
+ self.max_x = max(self.get_all_x_values())
+ except ValueError:
+ self.max_x = 0
+ return self.max_x
+
+ def get_min_y(self):
+ try:
+ return self.min_y
+ except AttributeError:
+ try:
+ self.min_y = min(self.get_all_y_values())
+ except ValueError:
+ self.min_y = 0
+ return self.min_y
+
+ def get_max_y(self):
+ try:
+ return self.max_y
+ except AttributeError:
+ try:
+ self.max_y = max(self.get_all_y_values())
+ except ValueError:
+ self.max_y = 0
+ return self.max_y
+
+ def draw(self):
+
+ if not self.lines:
+ return
+
+ if self.title:
+ print 'set title "%s"' % self.title
+ print 'set key %s' % self.key_location
+
+ min_y = self.get_min_y()
+ max_y = self.max_graph_value(self.get_max_y())
+ incr = (max_y - min_y) / 10.0
+ start = min_y + (max_y / 2.0) + (2.0 * incr)
+ position = [ start - (i * incr) for i in range(5) ]
+
+ inx = 1
+ for line in self.lines:
+ line.print_label(inx, line.points[0][0]-1,
+ position[(inx-1) % len(position)])
+ inx += 1
+
+ plot_strings = [ self.plot_string(l) for l in self.lines ]
+ print 'plot ' + ', \\\n '.join(plot_strings)
+
+ for line in self.lines:
+ line.print_points()
+
+
+
+def untar(fname):
+ import tarfile
+ tar = tarfile.open(name=fname, mode='r')
+ for tarinfo in tar:
+ tar.extract(tarinfo)
+ tar.close()
+
+def unzip(fname):
+ import zipfile
+ zf = zipfile.ZipFile(fname, 'r')
+ for name in zf.namelist():
+ dir = os.path.dirname(name)
+ try:
+ os.makedirs(dir)
+ except:
+ pass
+ open(name, 'w').write(zf.read(name))
+
+def read_tree(dir):
+ for dirpath, dirnames, filenames in os.walk(dir):
+ for fn in filenames:
+ fn = os.path.join(dirpath, fn)
+ if os.path.isfile(fn):
+ open(fn, 'rb').read()
+
+def redirect_to_file(command, log):
+ return '%s > %s 2>&1' % (command, log)
+
+def tee_to_file(command, log):
+ return '%s 2>&1 | tee %s' % (command, log)
+
+
+
+class SConsTimer(object):
+ """
+ Usage: scons-time SUBCOMMAND [ARGUMENTS]
+ Type "scons-time help SUBCOMMAND" for help on a specific subcommand.
+
+ Available subcommands:
+ func Extract test-run data for a function
+ help Provides help
+ mem Extract --debug=memory data from test runs
+ obj Extract --debug=count data from test runs
+ time Extract --debug=time data from test runs
+ run Runs a test configuration
+ """
+
+ name = 'scons-time'
+ name_spaces = ' '*len(name)
+
+ def makedict(**kw):
+ return kw
+
+ default_settings = makedict(
+ aegis = 'aegis',
+ aegis_project = None,
+ chdir = None,
+ config_file = None,
+ initial_commands = [],
+ key_location = 'bottom left',
+ orig_cwd = os.getcwd(),
+ outdir = None,
+ prefix = '',
+ python = '"%s"' % sys.executable,
+ redirect = redirect_to_file,
+ scons = None,
+ scons_flags = '--debug=count --debug=memory --debug=time --debug=memoizer',
+ scons_lib_dir = None,
+ scons_wrapper = None,
+ startup_targets = '--help',
+ subdir = None,
+ subversion_url = None,
+ svn = 'svn',
+ svn_co_flag = '-q',
+ tar = 'tar',
+ targets = '',
+ targets0 = None,
+ targets1 = None,
+ targets2 = None,
+ title = None,
+ unzip = 'unzip',
+ verbose = False,
+ vertical_bars = [],
+
+ unpack_map = {
+ '.tar.gz' : (untar, '%(tar)s xzf %%s'),
+ '.tgz' : (untar, '%(tar)s xzf %%s'),
+ '.tar' : (untar, '%(tar)s xf %%s'),
+ '.zip' : (unzip, '%(unzip)s %%s'),
+ },
+ )
+
+ run_titles = [
+ 'Startup',
+ 'Full build',
+ 'Up-to-date build',
+ ]
+
+ run_commands = [
+ '%(python)s %(scons_wrapper)s %(scons_flags)s --profile=%(prof0)s %(targets0)s',
+ '%(python)s %(scons_wrapper)s %(scons_flags)s --profile=%(prof1)s %(targets1)s',
+ '%(python)s %(scons_wrapper)s %(scons_flags)s --profile=%(prof2)s %(targets2)s',
+ ]
+
+ stages = [
+ 'pre-read',
+ 'post-read',
+ 'pre-build',
+ 'post-build',
+ ]
+
+ stage_strings = {
+ 'pre-read' : 'Memory before reading SConscript files:',
+ 'post-read' : 'Memory after reading SConscript files:',
+ 'pre-build' : 'Memory before building targets:',
+ 'post-build' : 'Memory after building targets:',
+ }
+
+ memory_string_all = 'Memory '
+
+ default_stage = stages[-1]
+
+ time_strings = {
+ 'total' : 'Total build time',
+ 'SConscripts' : 'Total SConscript file execution time',
+ 'SCons' : 'Total SCons execution time',
+ 'commands' : 'Total command execution time',
+ }
+
+ time_string_all = 'Total .* time'
+
+ #
+
+ def __init__(self):
+ self.__dict__.update(self.default_settings)
+
+ # Functions for displaying and executing commands.
+
+ def subst(self, x, dictionary):
+ try:
+ return x % dictionary
+ except TypeError:
+ # x isn't a string (it's probably a Python function),
+ # so just return it.
+ return x
+
+ def subst_variables(self, command, dictionary):
+ """
+ Substitutes (via the format operator) the values in the specified
+ dictionary into the specified command.
+
+ The command can be an (action, string) tuple. In all cases, we
+ perform substitution on strings and don't worry if something isn't
+ a string. (It's probably a Python function to be executed.)
+ """
+ try:
+ command + ''
+ except TypeError:
+ action = command[0]
+ string = command[1]
+ args = command[2:]
+ else:
+ action = command
+ string = action
+ args = (())
+ action = self.subst(action, dictionary)
+ string = self.subst(string, dictionary)
+ return (action, string, args)
+
+ def _do_not_display(self, msg, *args):
+ pass
+
+ def display(self, msg, *args):
+ """
+ Displays the specified message.
+
+ Each message is prepended with a standard prefix of our name
+ plus the time.
+ """
+ if callable(msg):
+ msg = msg(*args)
+ else:
+ msg = msg % args
+ if msg is None:
+ return
+ fmt = '%s[%s]: %s\n'
+ sys.stdout.write(fmt % (self.name, time.strftime('%H:%M:%S'), msg))
+
+ def _do_not_execute(self, action, *args):
+ pass
+
+ def execute(self, action, *args):
+ """
+ Executes the specified action.
+
+ The action is called if it's a callable Python function, and
+ otherwise passed to os.system().
+ """
+ if callable(action):
+ action(*args)
+ else:
+ os.system(action % args)
+
+ def run_command_list(self, commands, dict):
+ """
+ Executes a list of commands, substituting values from the
+ specified dictionary.
+ """
+ commands = [ self.subst_variables(c, dict) for c in commands ]
+ for action, string, args in commands:
+ self.display(string, *args)
+ sys.stdout.flush()
+ status = self.execute(action, *args)
+ if status:
+ sys.exit(status)
+
+ def log_display(self, command, log):
+ command = self.subst(command, self.__dict__)
+ if log:
+ command = self.redirect(command, log)
+ return command
+
+ def log_execute(self, command, log):
+ command = self.subst(command, self.__dict__)
+ output = os.popen(command).read()
+ if self.verbose:
+ sys.stdout.write(output)
+ open(log, 'wb').write(output)
+
+ #
+
+ def archive_splitext(self, path):
+ """
+ Splits an archive name into a filename base and extension.
+
+ This is like os.path.splitext() (which it calls) except that it
+ also looks for '.tar.gz' and treats it as an atomic extensions.
+ """
+ if path.endswith('.tar.gz'):
+ return path[:-7], path[-7:]
+ else:
+ return os.path.splitext(path)
+
+ def args_to_files(self, args, tail=None):
+ """
+ Takes a list of arguments, expands any glob patterns, and
+ returns the last "tail" files from the list.
+ """
+ files = []
+ for a in args:
+ files.extend(sorted(glob.glob(a)))
+
+ if tail:
+ files = files[-tail:]
+
+ return files
+
+ def ascii_table(self, files, columns,
+ line_function, file_function=lambda x: x,
+ *args, **kw):
+
+ header_fmt = ' '.join(['%12s'] * len(columns))
+ line_fmt = header_fmt + ' %s'
+
+ print header_fmt % columns
+
+ for file in files:
+ t = line_function(file, *args, **kw)
+ if t is None:
+ t = []
+ diff = len(columns) - len(t)
+ if diff > 0:
+ t += [''] * diff
+ t.append(file_function(file))
+ print line_fmt % tuple(t)
+
+ def collect_results(self, files, function, *args, **kw):
+ results = {}
+
+ for file in files:
+ base = os.path.splitext(file)[0]
+ run, index = base.split('-')[-2:]
+
+ run = int(run)
+ index = int(index)
+
+ value = function(file, *args, **kw)
+
+ try:
+ r = results[index]
+ except KeyError:
+ r = []
+ results[index] = r
+ r.append((run, value))
+
+ return results
+
+ def doc_to_help(self, obj):
+ """
+ Translates an object's __doc__ string into help text.
+
+ This strips a consistent number of spaces from each line in the
+ help text, essentially "outdenting" the text to the left-most
+ column.
+ """
+ doc = obj.__doc__
+ if doc is None:
+ return ''
+ return self.outdent(doc)
+
+ def find_next_run_number(self, dir, prefix):
+ """
+ Returns the next run number in a directory for the specified prefix.
+
+ Examines the contents the specified directory for files with the
+ specified prefix, extracts the run numbers from each file name,
+ and returns the next run number after the largest it finds.
+ """
+ x = re.compile(re.escape(prefix) + '-([0-9]+).*')
+ matches = [x.match(e) for e in os.listdir(dir)]
+ matches = [_f for _f in matches if _f]
+ if not matches:
+ return 0
+ run_numbers = [int(m.group(1)) for m in matches]
+ return int(max(run_numbers)) + 1
+
+ def gnuplot_results(self, results, fmt='%s %.3f'):
+ """
+ Prints out a set of results in Gnuplot format.
+ """
+ gp = Gnuplotter(self.title, self.key_location)
+
+ for i in sorted(results.keys()):
+ try:
+ t = self.run_titles[i]
+ except IndexError:
+ t = '??? %s ???' % i
+ results[i].sort()
+ gp.line(results[i], i+1, t, None, t, fmt=fmt)
+
+ for bar_tuple in self.vertical_bars:
+ try:
+ x, type, label, comment = bar_tuple
+ except ValueError:
+ x, type, label = bar_tuple
+ comment = label
+ gp.vertical_bar(x, type, label, comment)
+
+ gp.draw()
+
+ def logfile_name(self, invocation):
+ """
+ Returns the absolute path of a log file for the specificed
+ invocation number.
+ """
+ name = self.prefix_run + '-%d.log' % invocation
+ return os.path.join(self.outdir, name)
+
+ def outdent(self, s):
+ """
+ Strip as many spaces from each line as are found at the beginning
+ of the first line in the list.
+ """
+ lines = s.split('\n')
+ if lines[0] == '':
+ lines = lines[1:]
+ spaces = re.match(' *', lines[0]).group(0)
+ def strip_initial_spaces(l, s=spaces):
+ if l.startswith(spaces):
+ l = l[len(spaces):]
+ return l
+ return '\n'.join([ strip_initial_spaces(l) for l in lines ]) + '\n'
+
+ def profile_name(self, invocation):
+ """
+ Returns the absolute path of a profile file for the specified
+ invocation number.
+ """
+ name = self.prefix_run + '-%d.prof' % invocation
+ return os.path.join(self.outdir, name)
+
+ def set_env(self, key, value):
+ os.environ[key] = value
+
+ #
+
+ def get_debug_times(self, file, time_string=None):
+ """
+ Fetch times from the --debug=time strings in the specified file.
+ """
+ if time_string is None:
+ search_string = self.time_string_all
+ else:
+ search_string = time_string
+ contents = open(file).read()
+ if not contents:
+ sys.stderr.write('file %s has no contents!\n' % repr(file))
+ return None
+ result = re.findall(r'%s: ([\d\.]*)' % search_string, contents)[-4:]
+ result = [ float(r) for r in result ]
+ if not time_string is None:
+ try:
+ result = result[0]
+ except IndexError:
+ sys.stderr.write('file %s has no results!\n' % repr(file))
+ return None
+ return result
+
+ def get_function_profile(self, file, function):
+ """
+ Returns the file, line number, function name, and cumulative time.
+ """
+ try:
+ import pstats
+ except ImportError, e:
+ sys.stderr.write('%s: func: %s\n' % (self.name, e))
+ sys.stderr.write('%s This version of Python is missing the profiler.\n' % self.name_spaces)
+ sys.stderr.write('%s Cannot use the "func" subcommand.\n' % self.name_spaces)
+ sys.exit(1)
+ statistics = pstats.Stats(file).stats
+ matches = [ e for e in statistics.items() if e[0][2] == function ]
+ r = matches[0]
+ return r[0][0], r[0][1], r[0][2], r[1][3]
+
+ def get_function_time(self, file, function):
+ """
+ Returns just the cumulative time for the specified function.
+ """
+ return self.get_function_profile(file, function)[3]
+
+ def get_memory(self, file, memory_string=None):
+ """
+ Returns a list of integers of the amount of memory used. The
+ default behavior is to return all the stages.
+ """
+ if memory_string is None:
+ search_string = self.memory_string_all
+ else:
+ search_string = memory_string
+ lines = open(file).readlines()
+ lines = [ l for l in lines if l.startswith(search_string) ][-4:]
+ result = [ int(l.split()[-1]) for l in lines[-4:] ]
+ if len(result) == 1:
+ result = result[0]
+ return result
+
+ def get_object_counts(self, file, object_name, index=None):
+ """
+ Returns the counts of the specified object_name.
+ """
+ object_string = ' ' + object_name + '\n'
+ lines = open(file).readlines()
+ line = [ l for l in lines if l.endswith(object_string) ][0]
+ result = [ int(field) for field in line.split()[:4] ]
+ if index is not None:
+ result = result[index]
+ return result
+
+ #
+
+ command_alias = {}
+
+ def execute_subcommand(self, argv):
+ """
+ Executes the do_*() function for the specified subcommand (argv[0]).
+ """
+ if not argv:
+ return
+ cmdName = self.command_alias.get(argv[0], argv[0])
+ try:
+ func = getattr(self, 'do_' + cmdName)
+ except AttributeError:
+ return self.default(argv)
+ try:
+ return func(argv)
+ except TypeError, e:
+ sys.stderr.write("%s %s: %s\n" % (self.name, cmdName, e))
+ import traceback
+ traceback.print_exc(file=sys.stderr)
+ sys.stderr.write("Try '%s help %s'\n" % (self.name, cmdName))
+
+ def default(self, argv):
+ """
+ The default behavior for an unknown subcommand. Prints an
+ error message and exits.
+ """
+ sys.stderr.write('%s: Unknown subcommand "%s".\n' % (self.name, argv[0]))
+ sys.stderr.write('Type "%s help" for usage.\n' % self.name)
+ sys.exit(1)
+
+ #
+
+ def do_help(self, argv):
+ """
+ """
+ if argv[1:]:
+ for arg in argv[1:]:
+ try:
+ func = getattr(self, 'do_' + arg)
+ except AttributeError:
+ sys.stderr.write('%s: No help for "%s"\n' % (self.name, arg))
+ else:
+ try:
+ help = getattr(self, 'help_' + arg)
+ except AttributeError:
+ sys.stdout.write(self.doc_to_help(func))
+ sys.stdout.flush()
+ else:
+ help()
+ else:
+ doc = self.doc_to_help(self.__class__)
+ if doc:
+ sys.stdout.write(doc)
+ sys.stdout.flush()
+ return None
+
+ #
+
+ def help_func(self):
+ help = """\
+ Usage: scons-time func [OPTIONS] FILE [...]
+
+ -C DIR, --chdir=DIR Change to DIR before looking for files
+ -f FILE, --file=FILE Read configuration from specified FILE
+ --fmt=FORMAT, --format=FORMAT Print data in specified FORMAT
+ --func=NAME, --function=NAME Report time for function NAME
+ -h, --help Print this help and exit
+ -p STRING, --prefix=STRING Use STRING as log file/profile prefix
+ -t NUMBER, --tail=NUMBER Only report the last NUMBER files
+ --title=TITLE Specify the output plot TITLE
+ """
+ sys.stdout.write(self.outdent(help))
+ sys.stdout.flush()
+
+ def do_func(self, argv):
+ """
+ """
+ format = 'ascii'
+ function_name = '_main'
+ tail = None
+
+ short_opts = '?C:f:hp:t:'
+
+ long_opts = [
+ 'chdir=',
+ 'file=',
+ 'fmt=',
+ 'format=',
+ 'func=',
+ 'function=',
+ 'help',
+ 'prefix=',
+ 'tail=',
+ 'title=',
+ ]
+
+ opts, args = getopt.getopt(argv[1:], short_opts, long_opts)
+
+ for o, a in opts:
+ if o in ('-C', '--chdir'):
+ self.chdir = a
+ elif o in ('-f', '--file'):
+ self.config_file = a
+ elif o in ('--fmt', '--format'):
+ format = a
+ elif o in ('--func', '--function'):
+ function_name = a
+ elif o in ('-?', '-h', '--help'):
+ self.do_help(['help', 'func'])
+ sys.exit(0)
+ elif o in ('--max',):
+ max_time = int(a)
+ elif o in ('-p', '--prefix'):
+ self.prefix = a
+ elif o in ('-t', '--tail'):
+ tail = int(a)
+ elif o in ('--title',):
+ self.title = a
+
+ if self.config_file:
+ exec open(self.config_file, 'rU').read() in self.__dict__
+
+ if self.chdir:
+ os.chdir(self.chdir)
+
+ if not args:
+
+ pattern = '%s*.prof' % self.prefix
+ args = self.args_to_files([pattern], tail)
+
+ if not args:
+ if self.chdir:
+ directory = self.chdir
+ else:
+ directory = os.getcwd()
+
+ sys.stderr.write('%s: func: No arguments specified.\n' % self.name)
+ sys.stderr.write('%s No %s*.prof files found in "%s".\n' % (self.name_spaces, self.prefix, directory))
+ sys.stderr.write('%s Type "%s help func" for help.\n' % (self.name_spaces, self.name))
+ sys.exit(1)
+
+ else:
+
+ args = self.args_to_files(args, tail)
+
+ cwd_ = os.getcwd() + os.sep
+
+ if format == 'ascii':
+
+ for file in args:
+ try:
+ f, line, func, time = \
+ self.get_function_profile(file, function_name)
+ except ValueError, e:
+ sys.stderr.write("%s: func: %s: %s\n" %
+ (self.name, file, e))
+ else:
+ if f.startswith(cwd_):
+ f = f[len(cwd_):]
+ print "%.3f %s:%d(%s)" % (time, f, line, func)
+
+ elif format == 'gnuplot':
+
+ results = self.collect_results(args, self.get_function_time,
+ function_name)
+
+ self.gnuplot_results(results)
+
+ else:
+
+ sys.stderr.write('%s: func: Unknown format "%s".\n' % (self.name, format))
+ sys.exit(1)
+
+ #
+
+ def help_mem(self):
+ help = """\
+ Usage: scons-time mem [OPTIONS] FILE [...]
+
+ -C DIR, --chdir=DIR Change to DIR before looking for files
+ -f FILE, --file=FILE Read configuration from specified FILE
+ --fmt=FORMAT, --format=FORMAT Print data in specified FORMAT
+ -h, --help Print this help and exit
+ -p STRING, --prefix=STRING Use STRING as log file/profile prefix
+ --stage=STAGE Plot memory at the specified stage:
+ pre-read, post-read, pre-build,
+ post-build (default: post-build)
+ -t NUMBER, --tail=NUMBER Only report the last NUMBER files
+ --title=TITLE Specify the output plot TITLE
+ """
+ sys.stdout.write(self.outdent(help))
+ sys.stdout.flush()
+
+ def do_mem(self, argv):
+
+ format = 'ascii'
+ logfile_path = lambda x: x
+ stage = self.default_stage
+ tail = None
+
+ short_opts = '?C:f:hp:t:'
+
+ long_opts = [
+ 'chdir=',
+ 'file=',
+ 'fmt=',
+ 'format=',
+ 'help',
+ 'prefix=',
+ 'stage=',
+ 'tail=',
+ 'title=',
+ ]
+
+ opts, args = getopt.getopt(argv[1:], short_opts, long_opts)
+
+ for o, a in opts:
+ if o in ('-C', '--chdir'):
+ self.chdir = a
+ elif o in ('-f', '--file'):
+ self.config_file = a
+ elif o in ('--fmt', '--format'):
+ format = a
+ elif o in ('-?', '-h', '--help'):
+ self.do_help(['help', 'mem'])
+ sys.exit(0)
+ elif o in ('-p', '--prefix'):
+ self.prefix = a
+ elif o in ('--stage',):
+ if not a in self.stages:
+ sys.stderr.write('%s: mem: Unrecognized stage "%s".\n' % (self.name, a))
+ sys.exit(1)
+ stage = a
+ elif o in ('-t', '--tail'):
+ tail = int(a)
+ elif o in ('--title',):
+ self.title = a
+
+ if self.config_file:
+ HACK_for_exec(open(self.config_file, 'rU').read(), self.__dict__)
+
+ if self.chdir:
+ os.chdir(self.chdir)
+ logfile_path = lambda x: os.path.join(self.chdir, x)
+
+ if not args:
+
+ pattern = '%s*.log' % self.prefix
+ args = self.args_to_files([pattern], tail)
+
+ if not args:
+ if self.chdir:
+ directory = self.chdir
+ else:
+ directory = os.getcwd()
+
+ sys.stderr.write('%s: mem: No arguments specified.\n' % self.name)
+ sys.stderr.write('%s No %s*.log files found in "%s".\n' % (self.name_spaces, self.prefix, directory))
+ sys.stderr.write('%s Type "%s help mem" for help.\n' % (self.name_spaces, self.name))
+ sys.exit(1)
+
+ else:
+
+ args = self.args_to_files(args, tail)
+
+ cwd_ = os.getcwd() + os.sep
+
+ if format == 'ascii':
+
+ self.ascii_table(args, tuple(self.stages), self.get_memory, logfile_path)
+
+ elif format == 'gnuplot':
+
+ results = self.collect_results(args, self.get_memory,
+ self.stage_strings[stage])
+
+ self.gnuplot_results(results)
+
+ else:
+
+ sys.stderr.write('%s: mem: Unknown format "%s".\n' % (self.name, format))
+ sys.exit(1)
+
+ return 0
+
+ #
+
+ def help_obj(self):
+ help = """\
+ Usage: scons-time obj [OPTIONS] OBJECT FILE [...]
+
+ -C DIR, --chdir=DIR Change to DIR before looking for files
+ -f FILE, --file=FILE Read configuration from specified FILE
+ --fmt=FORMAT, --format=FORMAT Print data in specified FORMAT
+ -h, --help Print this help and exit
+ -p STRING, --prefix=STRING Use STRING as log file/profile prefix
+ --stage=STAGE Plot memory at the specified stage:
+ pre-read, post-read, pre-build,
+ post-build (default: post-build)
+ -t NUMBER, --tail=NUMBER Only report the last NUMBER files
+ --title=TITLE Specify the output plot TITLE
+ """
+ sys.stdout.write(self.outdent(help))
+ sys.stdout.flush()
+
+ def do_obj(self, argv):
+
+ format = 'ascii'
+ logfile_path = lambda x: x
+ stage = self.default_stage
+ tail = None
+
+ short_opts = '?C:f:hp:t:'
+
+ long_opts = [
+ 'chdir=',
+ 'file=',
+ 'fmt=',
+ 'format=',
+ 'help',
+ 'prefix=',
+ 'stage=',
+ 'tail=',
+ 'title=',
+ ]
+
+ opts, args = getopt.getopt(argv[1:], short_opts, long_opts)
+
+ for o, a in opts:
+ if o in ('-C', '--chdir'):
+ self.chdir = a
+ elif o in ('-f', '--file'):
+ self.config_file = a
+ elif o in ('--fmt', '--format'):
+ format = a
+ elif o in ('-?', '-h', '--help'):
+ self.do_help(['help', 'obj'])
+ sys.exit(0)
+ elif o in ('-p', '--prefix'):
+ self.prefix = a
+ elif o in ('--stage',):
+ if not a in self.stages:
+ sys.stderr.write('%s: obj: Unrecognized stage "%s".\n' % (self.name, a))
+ sys.stderr.write('%s Type "%s help obj" for help.\n' % (self.name_spaces, self.name))
+ sys.exit(1)
+ stage = a
+ elif o in ('-t', '--tail'):
+ tail = int(a)
+ elif o in ('--title',):
+ self.title = a
+
+ if not args:
+ sys.stderr.write('%s: obj: Must specify an object name.\n' % self.name)
+ sys.stderr.write('%s Type "%s help obj" for help.\n' % (self.name_spaces, self.name))
+ sys.exit(1)
+
+ object_name = args.pop(0)
+
+ if self.config_file:
+ HACK_for_exec(open(self.config_file, 'rU').read(), self.__dict__)
+
+ if self.chdir:
+ os.chdir(self.chdir)
+ logfile_path = lambda x: os.path.join(self.chdir, x)
+
+ if not args:
+
+ pattern = '%s*.log' % self.prefix
+ args = self.args_to_files([pattern], tail)
+
+ if not args:
+ if self.chdir:
+ directory = self.chdir
+ else:
+ directory = os.getcwd()
+
+ sys.stderr.write('%s: obj: No arguments specified.\n' % self.name)
+ sys.stderr.write('%s No %s*.log files found in "%s".\n' % (self.name_spaces, self.prefix, directory))
+ sys.stderr.write('%s Type "%s help obj" for help.\n' % (self.name_spaces, self.name))
+ sys.exit(1)
+
+ else:
+
+ args = self.args_to_files(args, tail)
+
+ cwd_ = os.getcwd() + os.sep
+
+ if format == 'ascii':
+
+ self.ascii_table(args, tuple(self.stages), self.get_object_counts, logfile_path, object_name)
+
+ elif format == 'gnuplot':
+
+ stage_index = 0
+ for s in self.stages:
+ if stage == s:
+ break
+ stage_index = stage_index + 1
+
+ results = self.collect_results(args, self.get_object_counts,
+ object_name, stage_index)
+
+ self.gnuplot_results(results)
+
+ else:
+
+ sys.stderr.write('%s: obj: Unknown format "%s".\n' % (self.name, format))
+ sys.exit(1)
+
+ return 0
+
+ #
+
+ def help_run(self):
+ help = """\
+ Usage: scons-time run [OPTIONS] [FILE ...]
+
+ --aegis=PROJECT Use SCons from the Aegis PROJECT
+ --chdir=DIR Name of unpacked directory for chdir
+ -f FILE, --file=FILE Read configuration from specified FILE
+ -h, --help Print this help and exit
+ -n, --no-exec No execute, just print command lines
+ --number=NUMBER Put output in files for run NUMBER
+ --outdir=OUTDIR Put output files in OUTDIR
+ -p STRING, --prefix=STRING Use STRING as log file/profile prefix
+ --python=PYTHON Time using the specified PYTHON
+ -q, --quiet Don't print command lines
+ --scons=SCONS Time using the specified SCONS
+ --svn=URL, --subversion=URL Use SCons from Subversion URL
+ -v, --verbose Display output of commands
+ """
+ sys.stdout.write(self.outdent(help))
+ sys.stdout.flush()
+
+ def do_run(self, argv):
+ """
+ """
+ run_number_list = [None]
+
+ short_opts = '?f:hnp:qs:v'
+
+ long_opts = [
+ 'aegis=',
+ 'file=',
+ 'help',
+ 'no-exec',
+ 'number=',
+ 'outdir=',
+ 'prefix=',
+ 'python=',
+ 'quiet',
+ 'scons=',
+ 'svn=',
+ 'subdir=',
+ 'subversion=',
+ 'verbose',
+ ]
+
+ opts, args = getopt.getopt(argv[1:], short_opts, long_opts)
+
+ for o, a in opts:
+ if o in ('--aegis',):
+ self.aegis_project = a
+ elif o in ('-f', '--file'):
+ self.config_file = a
+ elif o in ('-?', '-h', '--help'):
+ self.do_help(['help', 'run'])
+ sys.exit(0)
+ elif o in ('-n', '--no-exec'):
+ self.execute = self._do_not_execute
+ elif o in ('--number',):
+ run_number_list = self.split_run_numbers(a)
+ elif o in ('--outdir',):
+ self.outdir = a
+ elif o in ('-p', '--prefix'):
+ self.prefix = a
+ elif o in ('--python',):
+ self.python = a
+ elif o in ('-q', '--quiet'):
+ self.display = self._do_not_display
+ elif o in ('-s', '--subdir'):
+ self.subdir = a
+ elif o in ('--scons',):
+ self.scons = a
+ elif o in ('--svn', '--subversion'):
+ self.subversion_url = a
+ elif o in ('-v', '--verbose'):
+ self.redirect = tee_to_file
+ self.verbose = True
+ self.svn_co_flag = ''
+
+ if not args and not self.config_file:
+ sys.stderr.write('%s: run: No arguments or -f config file specified.\n' % self.name)
+ sys.stderr.write('%s Type "%s help run" for help.\n' % (self.name_spaces, self.name))
+ sys.exit(1)
+
+ if self.config_file:
+ exec open(self.config_file, 'rU').read() in self.__dict__
+
+ if args:
+ self.archive_list = args
+
+ archive_file_name = os.path.split(self.archive_list[0])[1]
+
+ if not self.subdir:
+ self.subdir = self.archive_splitext(archive_file_name)[0]
+
+ if not self.prefix:
+ self.prefix = self.archive_splitext(archive_file_name)[0]
+
+ prepare = None
+ if self.subversion_url:
+ prepare = self.prep_subversion_run
+ elif self.aegis_project:
+ prepare = self.prep_aegis_run
+
+ for run_number in run_number_list:
+ self.individual_run(run_number, self.archive_list, prepare)
+
+ def split_run_numbers(self, s):
+ result = []
+ for n in s.split(','):
+ try:
+ x, y = n.split('-')
+ except ValueError:
+ result.append(int(n))
+ else:
+ result.extend(list(range(int(x), int(y)+1)))
+ return result
+
+ def scons_path(self, dir):
+ return os.path.join(dir, 'src', 'script', 'scons.py')
+
+ def scons_lib_dir_path(self, dir):
+ return os.path.join(dir, 'src', 'engine')
+
+ def prep_aegis_run(self, commands, removals):
+ self.aegis_tmpdir = make_temp_file(prefix = self.name + '-aegis-')
+ removals.append((shutil.rmtree, 'rm -rf %%s', self.aegis_tmpdir))
+
+ self.aegis_parent_project = os.path.splitext(self.aegis_project)[0]
+ self.scons = self.scons_path(self.aegis_tmpdir)
+ self.scons_lib_dir = self.scons_lib_dir_path(self.aegis_tmpdir)
+
+ commands.extend([
+ 'mkdir %(aegis_tmpdir)s',
+ (lambda: os.chdir(self.aegis_tmpdir), 'cd %(aegis_tmpdir)s'),
+ '%(aegis)s -cp -ind -p %(aegis_parent_project)s .',
+ '%(aegis)s -cp -ind -p %(aegis_project)s -delta %(run_number)s .',
+ ])
+
+ def prep_subversion_run(self, commands, removals):
+ self.svn_tmpdir = make_temp_file(prefix = self.name + '-svn-')
+ removals.append((shutil.rmtree, 'rm -rf %%s', self.svn_tmpdir))
+
+ self.scons = self.scons_path(self.svn_tmpdir)
+ self.scons_lib_dir = self.scons_lib_dir_path(self.svn_tmpdir)
+
+ commands.extend([
+ 'mkdir %(svn_tmpdir)s',
+ '%(svn)s co %(svn_co_flag)s -r %(run_number)s %(subversion_url)s %(svn_tmpdir)s',
+ ])
+
+ def individual_run(self, run_number, archive_list, prepare=None):
+ """
+ Performs an individual run of the default SCons invocations.
+ """
+
+ commands = []
+ removals = []
+
+ if prepare:
+ prepare(commands, removals)
+
+ save_scons = self.scons
+ save_scons_wrapper = self.scons_wrapper
+ save_scons_lib_dir = self.scons_lib_dir
+
+ if self.outdir is None:
+ self.outdir = self.orig_cwd
+ elif not os.path.isabs(self.outdir):
+ self.outdir = os.path.join(self.orig_cwd, self.outdir)
+
+ if self.scons is None:
+ self.scons = self.scons_path(self.orig_cwd)
+
+ if self.scons_lib_dir is None:
+ self.scons_lib_dir = self.scons_lib_dir_path(self.orig_cwd)
+
+ if self.scons_wrapper is None:
+ self.scons_wrapper = self.scons
+
+ if not run_number:
+ run_number = self.find_next_run_number(self.outdir, self.prefix)
+
+ self.run_number = str(run_number)
+
+ self.prefix_run = self.prefix + '-%03d' % run_number
+
+ if self.targets0 is None:
+ self.targets0 = self.startup_targets
+ if self.targets1 is None:
+ self.targets1 = self.targets
+ if self.targets2 is None:
+ self.targets2 = self.targets
+
+ self.tmpdir = make_temp_file(prefix = self.name + '-')
+
+ commands.extend([
+ 'mkdir %(tmpdir)s',
+
+ (os.chdir, 'cd %%s', self.tmpdir),
+ ])
+
+ for archive in archive_list:
+ if not os.path.isabs(archive):
+ archive = os.path.join(self.orig_cwd, archive)
+ if os.path.isdir(archive):
+ dest = os.path.split(archive)[1]
+ commands.append((shutil.copytree, 'cp -r %%s %%s', archive, dest))
+ else:
+ suffix = self.archive_splitext(archive)[1]
+ unpack_command = self.unpack_map.get(suffix)
+ if not unpack_command:
+ dest = os.path.split(archive)[1]
+ commands.append((shutil.copyfile, 'cp %%s %%s', archive, dest))
+ else:
+ commands.append(unpack_command + (archive,))
+
+ commands.extend([
+ (os.chdir, 'cd %%s', self.subdir),
+ ])
+
+ commands.extend(self.initial_commands)
+
+ commands.extend([
+ (lambda: read_tree('.'),
+ 'find * -type f | xargs cat > /dev/null'),
+
+ (self.set_env, 'export %%s=%%s',
+ 'SCONS_LIB_DIR', self.scons_lib_dir),
+
+ '%(python)s %(scons_wrapper)s --version',
+ ])
+
+ index = 0
+ for run_command in self.run_commands:
+ setattr(self, 'prof%d' % index, self.profile_name(index))
+ c = (
+ self.log_execute,
+ self.log_display,
+ run_command,
+ self.logfile_name(index),
+ )
+ commands.append(c)
+ index = index + 1
+
+ commands.extend([
+ (os.chdir, 'cd %%s', self.orig_cwd),
+ ])
+
+ if not os.environ.get('PRESERVE'):
+ commands.extend(removals)
+
+ commands.append((shutil.rmtree, 'rm -rf %%s', self.tmpdir))
+
+ self.run_command_list(commands, self.__dict__)
+
+ self.scons = save_scons
+ self.scons_lib_dir = save_scons_lib_dir
+ self.scons_wrapper = save_scons_wrapper
+
+ #
+
+ def help_time(self):
+ help = """\
+ Usage: scons-time time [OPTIONS] FILE [...]
+
+ -C DIR, --chdir=DIR Change to DIR before looking for files
+ -f FILE, --file=FILE Read configuration from specified FILE
+ --fmt=FORMAT, --format=FORMAT Print data in specified FORMAT
+ -h, --help Print this help and exit
+ -p STRING, --prefix=STRING Use STRING as log file/profile prefix
+ -t NUMBER, --tail=NUMBER Only report the last NUMBER files
+ --which=TIMER Plot timings for TIMER: total,
+ SConscripts, SCons, commands.
+ """
+ sys.stdout.write(self.outdent(help))
+ sys.stdout.flush()
+
+ def do_time(self, argv):
+
+ format = 'ascii'
+ logfile_path = lambda x: x
+ tail = None
+ which = 'total'
+
+ short_opts = '?C:f:hp:t:'
+
+ long_opts = [
+ 'chdir=',
+ 'file=',
+ 'fmt=',
+ 'format=',
+ 'help',
+ 'prefix=',
+ 'tail=',
+ 'title=',
+ 'which=',
+ ]
+
+ opts, args = getopt.getopt(argv[1:], short_opts, long_opts)
+
+ for o, a in opts:
+ if o in ('-C', '--chdir'):
+ self.chdir = a
+ elif o in ('-f', '--file'):
+ self.config_file = a
+ elif o in ('--fmt', '--format'):
+ format = a
+ elif o in ('-?', '-h', '--help'):
+ self.do_help(['help', 'time'])
+ sys.exit(0)
+ elif o in ('-p', '--prefix'):
+ self.prefix = a
+ elif o in ('-t', '--tail'):
+ tail = int(a)
+ elif o in ('--title',):
+ self.title = a
+ elif o in ('--which',):
+ if not a in self.time_strings.keys():
+ sys.stderr.write('%s: time: Unrecognized timer "%s".\n' % (self.name, a))
+ sys.stderr.write('%s Type "%s help time" for help.\n' % (self.name_spaces, self.name))
+ sys.exit(1)
+ which = a
+
+ if self.config_file:
+ HACK_for_exec(open(self.config_file, 'rU').read(), self.__dict__)
+
+ if self.chdir:
+ os.chdir(self.chdir)
+ logfile_path = lambda x: os.path.join(self.chdir, x)
+
+ if not args:
+
+ pattern = '%s*.log' % self.prefix
+ args = self.args_to_files([pattern], tail)
+
+ if not args:
+ if self.chdir:
+ directory = self.chdir
+ else:
+ directory = os.getcwd()
+
+ sys.stderr.write('%s: time: No arguments specified.\n' % self.name)
+ sys.stderr.write('%s No %s*.log files found in "%s".\n' % (self.name_spaces, self.prefix, directory))
+ sys.stderr.write('%s Type "%s help time" for help.\n' % (self.name_spaces, self.name))
+ sys.exit(1)
+
+ else:
+
+ args = self.args_to_files(args, tail)
+
+ cwd_ = os.getcwd() + os.sep
+
+ if format == 'ascii':
+
+ columns = ("Total", "SConscripts", "SCons", "commands")
+ self.ascii_table(args, columns, self.get_debug_times, logfile_path)
+
+ elif format == 'gnuplot':
+
+ results = self.collect_results(args, self.get_debug_times,
+ self.time_strings[which])
+
+ self.gnuplot_results(results, fmt='%s %.6f')
+
+ else:
+
+ sys.stderr.write('%s: time: Unknown format "%s".\n' % (self.name, format))
+ sys.exit(1)
+
+if __name__ == '__main__':
+ opts, args = getopt.getopt(sys.argv[1:], 'h?V', ['help', 'version'])
+
+ ST = SConsTimer()
+
+ for o, a in opts:
+ if o in ('-?', '-h', '--help'):
+ ST.do_help(['help'])
+ sys.exit(0)
+ elif o in ('-V', '--version'):
+ sys.stdout.write('scons-time version\n')
+ sys.exit(0)
+
+ if not args:
+ sys.stderr.write('Type "%s help" for usage.\n' % ST.name)
+ sys.exit(1)
+
+ ST.execute_subcommand(args)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/scons.py b/couchjs/scons/scons.py
new file mode 100755
index 00000000..bf84bf0e
--- /dev/null
+++ b/couchjs/scons/scons.py
@@ -0,0 +1,196 @@
+#! /usr/bin/env python
+#
+# SCons - a Software Constructor
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "src/script/scons.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__version__ = "2.0.1"
+
+__build__ = "r5134"
+
+__buildsys__ = "cooldog"
+
+__date__ = "2010/08/16 23:02:40"
+
+__developer__ = "bdeegan"
+
+import os
+import os.path
+import sys
+
+##############################################################################
+# BEGIN STANDARD SCons SCRIPT HEADER
+#
+# This is the cut-and-paste logic so that a self-contained script can
+# interoperate correctly with different SCons versions and installation
+# locations for the engine. If you modify anything in this section, you
+# should also change other scripts that use this same header.
+##############################################################################
+
+# Strip the script directory from sys.path() so on case-insensitive
+# (WIN32) systems Python doesn't think that the "scons" script is the
+# "SCons" package. Replace it with our own library directories
+# (version-specific first, in case they installed by hand there,
+# followed by generic) so we pick up the right version of the build
+# engine modules if they're in either directory.
+
+
+# Check to see if the python version is > 3.0 which is currently unsupported
+# If so exit with error message
+try:
+ if sys.version_info >= (3,0,0):
+ msg = "scons: *** SCons version %s does not run under Python version %s.\n"
+ sys.stderr.write(msg % (__version__, sys.version.split()[0]))
+ sys.exit(1)
+except AttributeError:
+ # Pre-1.6 Python has no sys.version_info
+ # No need to check version as we then know the version is < 3.0.0 and supported
+ pass
+
+script_dir = sys.path[0]
+
+if script_dir in sys.path:
+ sys.path.remove(script_dir)
+
+libs = []
+
+if "SCONS_LIB_DIR" in os.environ:
+ libs.append(os.environ["SCONS_LIB_DIR"])
+
+local_version = 'scons-local-' + __version__
+local = 'scons-local'
+if script_dir:
+ local_version = os.path.join(script_dir, local_version)
+ local = os.path.join(script_dir, local)
+libs.append(os.path.abspath(local_version))
+libs.append(os.path.abspath(local))
+
+scons_version = 'scons-%s' % __version__
+
+prefs = []
+
+if sys.platform == 'win32':
+ # sys.prefix is (likely) C:\Python*;
+ # check only C:\Python*.
+ prefs.append(sys.prefix)
+ prefs.append(os.path.join(sys.prefix, 'Lib', 'site-packages'))
+else:
+ # On other (POSIX) platforms, things are more complicated due to
+ # the variety of path names and library locations. Try to be smart
+ # about it.
+ if script_dir == 'bin':
+ # script_dir is `pwd`/bin;
+ # check `pwd`/lib/scons*.
+ prefs.append(os.getcwd())
+ else:
+ if script_dir == '.' or script_dir == '':
+ script_dir = os.getcwd()
+ head, tail = os.path.split(script_dir)
+ if tail == "bin":
+ # script_dir is /foo/bin;
+ # check /foo/lib/scons*.
+ prefs.append(head)
+
+ head, tail = os.path.split(sys.prefix)
+ if tail == "usr":
+ # sys.prefix is /foo/usr;
+ # check /foo/usr/lib/scons* first,
+ # then /foo/usr/local/lib/scons*.
+ prefs.append(sys.prefix)
+ prefs.append(os.path.join(sys.prefix, "local"))
+ elif tail == "local":
+ h, t = os.path.split(head)
+ if t == "usr":
+ # sys.prefix is /foo/usr/local;
+ # check /foo/usr/local/lib/scons* first,
+ # then /foo/usr/lib/scons*.
+ prefs.append(sys.prefix)
+ prefs.append(head)
+ else:
+ # sys.prefix is /foo/local;
+ # check only /foo/local/lib/scons*.
+ prefs.append(sys.prefix)
+ else:
+ # sys.prefix is /foo (ends in neither /usr or /local);
+ # check only /foo/lib/scons*.
+ prefs.append(sys.prefix)
+
+ temp = [os.path.join(x, 'lib') for x in prefs]
+ temp.extend([os.path.join(x,
+ 'lib',
+ 'python' + sys.version[:3],
+ 'site-packages') for x in prefs])
+ prefs = temp
+
+ # Add the parent directory of the current python's library to the
+ # preferences. On SuSE-91/AMD64, for example, this is /usr/lib64,
+ # not /usr/lib.
+ try:
+ libpath = os.__file__
+ except AttributeError:
+ pass
+ else:
+ # Split /usr/libfoo/python*/os.py to /usr/libfoo/python*.
+ libpath, tail = os.path.split(libpath)
+ # Split /usr/libfoo/python* to /usr/libfoo
+ libpath, tail = os.path.split(libpath)
+ # Check /usr/libfoo/scons*.
+ prefs.append(libpath)
+
+ try:
+ import pkg_resources
+ except ImportError:
+ pass
+ else:
+ # when running from an egg add the egg's directory
+ try:
+ d = pkg_resources.get_distribution('scons')
+ except pkg_resources.DistributionNotFound:
+ pass
+ else:
+ prefs.append(d.location)
+
+# Look first for 'scons-__version__' in all of our preference libs,
+# then for 'scons'.
+libs.extend([os.path.join(x, scons_version) for x in prefs])
+libs.extend([os.path.join(x, 'scons') for x in prefs])
+
+sys.path = libs + sys.path
+
+##############################################################################
+# END STANDARD SCons SCRIPT HEADER
+##############################################################################
+
+if __name__ == "__main__":
+ import SCons.Script
+ # this does all the work, and calls sys.exit
+ # with the proper exit status when done.
+ SCons.Script.main()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/couchjs/scons/sconsign.py b/couchjs/scons/sconsign.py
new file mode 100755
index 00000000..adf3d283
--- /dev/null
+++ b/couchjs/scons/sconsign.py
@@ -0,0 +1,513 @@
+#! /usr/bin/env python
+#
+# SCons - a Software Constructor
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+__revision__ = "src/script/sconsign.py 5134 2010/08/16 23:02:40 bdeegan"
+
+__version__ = "2.0.1"
+
+__build__ = "r5134"
+
+__buildsys__ = "cooldog"
+
+__date__ = "2010/08/16 23:02:40"
+
+__developer__ = "bdeegan"
+
+import os
+import sys
+import time
+
+##############################################################################
+# BEGIN STANDARD SCons SCRIPT HEADER
+#
+# This is the cut-and-paste logic so that a self-contained script can
+# interoperate correctly with different SCons versions and installation
+# locations for the engine. If you modify anything in this section, you
+# should also change other scripts that use this same header.
+##############################################################################
+
+# Strip the script directory from sys.path() so on case-insensitive
+# (WIN32) systems Python doesn't think that the "scons" script is the
+# "SCons" package. Replace it with our own library directories
+# (version-specific first, in case they installed by hand there,
+# followed by generic) so we pick up the right version of the build
+# engine modules if they're in either directory.
+
+script_dir = sys.path[0]
+
+if script_dir in sys.path:
+ sys.path.remove(script_dir)
+
+libs = []
+
+if "SCONS_LIB_DIR" in os.environ:
+ libs.append(os.environ["SCONS_LIB_DIR"])
+
+local_version = 'scons-local-' + __version__
+local = 'scons-local'
+if script_dir:
+ local_version = os.path.join(script_dir, local_version)
+ local = os.path.join(script_dir, local)
+libs.append(os.path.abspath(local_version))
+libs.append(os.path.abspath(local))
+
+scons_version = 'scons-%s' % __version__
+
+prefs = []
+
+if sys.platform == 'win32':
+ # sys.prefix is (likely) C:\Python*;
+ # check only C:\Python*.
+ prefs.append(sys.prefix)
+ prefs.append(os.path.join(sys.prefix, 'Lib', 'site-packages'))
+else:
+ # On other (POSIX) platforms, things are more complicated due to
+ # the variety of path names and library locations. Try to be smart
+ # about it.
+ if script_dir == 'bin':
+ # script_dir is `pwd`/bin;
+ # check `pwd`/lib/scons*.
+ prefs.append(os.getcwd())
+ else:
+ if script_dir == '.' or script_dir == '':
+ script_dir = os.getcwd()
+ head, tail = os.path.split(script_dir)
+ if tail == "bin":
+ # script_dir is /foo/bin;
+ # check /foo/lib/scons*.
+ prefs.append(head)
+
+ head, tail = os.path.split(sys.prefix)
+ if tail == "usr":
+ # sys.prefix is /foo/usr;
+ # check /foo/usr/lib/scons* first,
+ # then /foo/usr/local/lib/scons*.
+ prefs.append(sys.prefix)
+ prefs.append(os.path.join(sys.prefix, "local"))
+ elif tail == "local":
+ h, t = os.path.split(head)
+ if t == "usr":
+ # sys.prefix is /foo/usr/local;
+ # check /foo/usr/local/lib/scons* first,
+ # then /foo/usr/lib/scons*.
+ prefs.append(sys.prefix)
+ prefs.append(head)
+ else:
+ # sys.prefix is /foo/local;
+ # check only /foo/local/lib/scons*.
+ prefs.append(sys.prefix)
+ else:
+ # sys.prefix is /foo (ends in neither /usr or /local);
+ # check only /foo/lib/scons*.
+ prefs.append(sys.prefix)
+
+ temp = [os.path.join(x, 'lib') for x in prefs]
+ temp.extend([os.path.join(x,
+ 'lib',
+ 'python' + sys.version[:3],
+ 'site-packages') for x in prefs])
+ prefs = temp
+
+ # Add the parent directory of the current python's library to the
+ # preferences. On SuSE-91/AMD64, for example, this is /usr/lib64,
+ # not /usr/lib.
+ try:
+ libpath = os.__file__
+ except AttributeError:
+ pass
+ else:
+ # Split /usr/libfoo/python*/os.py to /usr/libfoo/python*.
+ libpath, tail = os.path.split(libpath)
+ # Split /usr/libfoo/python* to /usr/libfoo
+ libpath, tail = os.path.split(libpath)
+ # Check /usr/libfoo/scons*.
+ prefs.append(libpath)
+
+ try:
+ import pkg_resources
+ except ImportError:
+ pass
+ else:
+ # when running from an egg add the egg's directory
+ try:
+ d = pkg_resources.get_distribution('scons')
+ except pkg_resources.DistributionNotFound:
+ pass
+ else:
+ prefs.append(d.location)
+
+# Look first for 'scons-__version__' in all of our preference libs,
+# then for 'scons'.
+libs.extend([os.path.join(x, scons_version) for x in prefs])
+libs.extend([os.path.join(x, 'scons') for x in prefs])
+
+sys.path = libs + sys.path
+
+##############################################################################
+# END STANDARD SCons SCRIPT HEADER
+##############################################################################
+
+import SCons.compat # so pickle will import cPickle instead
+
+import whichdb
+import pickle
+import imp
+
+import SCons.SConsign
+
+def my_whichdb(filename):
+ if filename[-7:] == ".dblite":
+ return "SCons.dblite"
+ try:
+ f = open(filename + ".dblite", "rb")
+ f.close()
+ return "SCons.dblite"
+ except IOError:
+ pass
+ return _orig_whichdb(filename)
+
+_orig_whichdb = whichdb.whichdb
+whichdb.whichdb = my_whichdb
+
+def my_import(mname):
+ if '.' in mname:
+ i = mname.rfind('.')
+ parent = my_import(mname[:i])
+ fp, pathname, description = imp.find_module(mname[i+1:],
+ parent.__path__)
+ else:
+ fp, pathname, description = imp.find_module(mname)
+ return imp.load_module(mname, fp, pathname, description)
+
+class Flagger(object):
+ default_value = 1
+ def __setitem__(self, item, value):
+ self.__dict__[item] = value
+ self.default_value = 0
+ def __getitem__(self, item):
+ return self.__dict__.get(item, self.default_value)
+
+Do_Call = None
+Print_Directories = []
+Print_Entries = []
+Print_Flags = Flagger()
+Verbose = 0
+Readable = 0
+
+def default_mapper(entry, name):
+ try:
+ val = eval("entry."+name)
+ except:
+ val = None
+ return str(val)
+
+def map_action(entry, name):
+ try:
+ bact = entry.bact
+ bactsig = entry.bactsig
+ except AttributeError:
+ return None
+ return '%s [%s]' % (bactsig, bact)
+
+def map_timestamp(entry, name):
+ try:
+ timestamp = entry.timestamp
+ except AttributeError:
+ timestamp = None
+ if Readable and timestamp:
+ return "'" + time.ctime(timestamp) + "'"
+ else:
+ return str(timestamp)
+
+def map_bkids(entry, name):
+ try:
+ bkids = entry.bsources + entry.bdepends + entry.bimplicit
+ bkidsigs = entry.bsourcesigs + entry.bdependsigs + entry.bimplicitsigs
+ except AttributeError:
+ return None
+ result = []
+ for i in range(len(bkids)):
+ result.append(nodeinfo_string(bkids[i], bkidsigs[i], " "))
+ if result == []:
+ return None
+ return "\n ".join(result)
+
+map_field = {
+ 'action' : map_action,
+ 'timestamp' : map_timestamp,
+ 'bkids' : map_bkids,
+}
+
+map_name = {
+ 'implicit' : 'bkids',
+}
+
+def field(name, entry, verbose=Verbose):
+ if not Print_Flags[name]:
+ return None
+ fieldname = map_name.get(name, name)
+ mapper = map_field.get(fieldname, default_mapper)
+ val = mapper(entry, name)
+ if verbose:
+ val = name + ": " + val
+ return val
+
+def nodeinfo_raw(name, ninfo, prefix=""):
+ # This just formats the dictionary, which we would normally use str()
+ # to do, except that we want the keys sorted for deterministic output.
+ d = ninfo.__dict__
+ try:
+ keys = ninfo.field_list + ['_version_id']
+ except AttributeError:
+ keys = sorted(d.keys())
+ l = []
+ for k in keys:
+ l.append('%s: %s' % (repr(k), repr(d.get(k))))
+ if '\n' in name:
+ name = repr(name)
+ return name + ': {' + ', '.join(l) + '}'
+
+def nodeinfo_cooked(name, ninfo, prefix=""):
+ try:
+ field_list = ninfo.field_list
+ except AttributeError:
+ field_list = []
+ if '\n' in name:
+ name = repr(name)
+ outlist = [name+':'] + [_f for _f in [field(x, ninfo, Verbose) for x in field_list] if _f]
+ if Verbose:
+ sep = '\n ' + prefix
+ else:
+ sep = ' '
+ return sep.join(outlist)
+
+nodeinfo_string = nodeinfo_cooked
+
+def printfield(name, entry, prefix=""):
+ outlist = field("implicit", entry, 0)
+ if outlist:
+ if Verbose:
+ print " implicit:"
+ print " " + outlist
+ outact = field("action", entry, 0)
+ if outact:
+ if Verbose:
+ print " action: " + outact
+ else:
+ print " " + outact
+
+def printentries(entries, location):
+ if Print_Entries:
+ for name in Print_Entries:
+ try:
+ entry = entries[name]
+ except KeyError:
+ sys.stderr.write("sconsign: no entry `%s' in `%s'\n" % (name, location))
+ else:
+ try:
+ ninfo = entry.ninfo
+ except AttributeError:
+ print name + ":"
+ else:
+ print nodeinfo_string(name, entry.ninfo)
+ printfield(name, entry.binfo)
+ else:
+ for name in sorted(entries.keys()):
+ entry = entries[name]
+ try:
+ ninfo = entry.ninfo
+ except AttributeError:
+ print name + ":"
+ else:
+ print nodeinfo_string(name, entry.ninfo)
+ printfield(name, entry.binfo)
+
+class Do_SConsignDB(object):
+ def __init__(self, dbm_name, dbm):
+ self.dbm_name = dbm_name
+ self.dbm = dbm
+
+ def __call__(self, fname):
+ # The *dbm modules stick their own file suffixes on the names
+ # that are passed in. This is causes us to jump through some
+ # hoops here to be able to allow the user
+ try:
+ # Try opening the specified file name. Example:
+ # SPECIFIED OPENED BY self.dbm.open()
+ # --------- -------------------------
+ # .sconsign => .sconsign.dblite
+ # .sconsign.dblite => .sconsign.dblite.dblite
+ db = self.dbm.open(fname, "r")
+ except (IOError, OSError), e:
+ print_e = e
+ try:
+ # That didn't work, so try opening the base name,
+ # so that if the actually passed in 'sconsign.dblite'
+ # (for example), the dbm module will put the suffix back
+ # on for us and open it anyway.
+ db = self.dbm.open(os.path.splitext(fname)[0], "r")
+ except (IOError, OSError):
+ # That didn't work either. See if the file name
+ # they specified just exists (independent of the dbm
+ # suffix-mangling).
+ try:
+ open(fname, "r")
+ except (IOError, OSError), e:
+ # Nope, that file doesn't even exist, so report that
+ # fact back.
+ print_e = e
+ sys.stderr.write("sconsign: %s\n" % (print_e))
+ return
+ except KeyboardInterrupt:
+ raise
+ except pickle.UnpicklingError:
+ sys.stderr.write("sconsign: ignoring invalid `%s' file `%s'\n" % (self.dbm_name, fname))
+ return
+ except Exception, e:
+ sys.stderr.write("sconsign: ignoring invalid `%s' file `%s': %s\n" % (self.dbm_name, fname, e))
+ return
+
+ if Print_Directories:
+ for dir in Print_Directories:
+ try:
+ val = db[dir]
+ except KeyError:
+ sys.stderr.write("sconsign: no dir `%s' in `%s'\n" % (dir, args[0]))
+ else:
+ self.printentries(dir, val)
+ else:
+ for dir in sorted(db.keys()):
+ self.printentries(dir, db[dir])
+
+ def printentries(self, dir, val):
+ print '=== ' + dir + ':'
+ printentries(pickle.loads(val), dir)
+
+def Do_SConsignDir(name):
+ try:
+ fp = open(name, 'rb')
+ except (IOError, OSError), e:
+ sys.stderr.write("sconsign: %s\n" % (e))
+ return
+ try:
+ sconsign = SCons.SConsign.Dir(fp)
+ except KeyboardInterrupt:
+ raise
+ except pickle.UnpicklingError:
+ sys.stderr.write("sconsign: ignoring invalid .sconsign file `%s'\n" % (name))
+ return
+ except Exception, e:
+ sys.stderr.write("sconsign: ignoring invalid .sconsign file `%s': %s\n" % (name, e))
+ return
+ printentries(sconsign.entries, args[0])
+
+##############################################################################
+
+import getopt
+
+helpstr = """\
+Usage: sconsign [OPTIONS] FILE [...]
+Options:
+ -a, --act, --action Print build action information.
+ -c, --csig Print content signature information.
+ -d DIR, --dir=DIR Print only info about DIR.
+ -e ENTRY, --entry=ENTRY Print only info about ENTRY.
+ -f FORMAT, --format=FORMAT FILE is in the specified FORMAT.
+ -h, --help Print this message and exit.
+ -i, --implicit Print implicit dependency information.
+ -r, --readable Print timestamps in human-readable form.
+ --raw Print raw Python object representations.
+ -s, --size Print file sizes.
+ -t, --timestamp Print timestamp information.
+ -v, --verbose Verbose, describe each field.
+"""
+
+opts, args = getopt.getopt(sys.argv[1:], "acd:e:f:hirstv",
+ ['act', 'action',
+ 'csig', 'dir=', 'entry=',
+ 'format=', 'help', 'implicit',
+ 'raw', 'readable',
+ 'size', 'timestamp', 'verbose'])
+
+
+for o, a in opts:
+ if o in ('-a', '--act', '--action'):
+ Print_Flags['action'] = 1
+ elif o in ('-c', '--csig'):
+ Print_Flags['csig'] = 1
+ elif o in ('-d', '--dir'):
+ Print_Directories.append(a)
+ elif o in ('-e', '--entry'):
+ Print_Entries.append(a)
+ elif o in ('-f', '--format'):
+ Module_Map = {'dblite' : 'SCons.dblite',
+ 'sconsign' : None}
+ dbm_name = Module_Map.get(a, a)
+ if dbm_name:
+ try:
+ dbm = my_import(dbm_name)
+ except:
+ sys.stderr.write("sconsign: illegal file format `%s'\n" % a)
+ print helpstr
+ sys.exit(2)
+ Do_Call = Do_SConsignDB(a, dbm)
+ else:
+ Do_Call = Do_SConsignDir
+ elif o in ('-h', '--help'):
+ print helpstr
+ sys.exit(0)
+ elif o in ('-i', '--implicit'):
+ Print_Flags['implicit'] = 1
+ elif o in ('--raw',):
+ nodeinfo_string = nodeinfo_raw
+ elif o in ('-r', '--readable'):
+ Readable = 1
+ elif o in ('-s', '--size'):
+ Print_Flags['size'] = 1
+ elif o in ('-t', '--timestamp'):
+ Print_Flags['timestamp'] = 1
+ elif o in ('-v', '--verbose'):
+ Verbose = 1
+
+if Do_Call:
+ for a in args:
+ Do_Call(a)
+else:
+ for a in args:
+ dbm_name = whichdb.whichdb(a)
+ if dbm_name:
+ Map_Module = {'SCons.dblite' : 'dblite'}
+ dbm = my_import(dbm_name)
+ Do_SConsignDB(Map_Module.get(dbm_name, dbm_name), dbm)(a)
+ else:
+ Do_SConsignDir(a)
+
+sys.exit(0)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/etc/Makefile.am b/etc/Makefile.am
deleted file mode 100644
index 148f7015..00000000
--- a/etc/Makefile.am
+++ /dev/null
@@ -1,117 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-SUBDIRS = couchdb default init launchd logrotate.d windows
-
-default_sysconf_data = logrotate.d/couchdb
-
-if INIT
-init_sysconf_data = default/couchdb
-init_DATA = init/couchdb
-endif
-
-if LAUNCHD
-launchd_DATA = launchd/org.apache.couchdb.plist
-endif
-
-nobase_sysconf_DATA = $(default_sysconf_data) $(init_sysconf_data)
-
-EXTRA_DIST = \
- default/couchdb \
- windows/couchdb.iss.tpl \
- windows/README.txt.tpl
-
-if WINDOWS
-EXTRA_DIST += \
- windows/setup-couchdb-@version@.exe.md5 \
- windows/setup-couchdb-@version@.exe.sha
-endif
-
-CLEANFILES = $(init_DATA) $(default_sysconf_data) $(launchd_DATA)
-
-transform = @program_transform_name@
-couchdb_command_name = `echo couchdb | sed '$(transform)'`
-
-init/couchdb: init/couchdb.tpl
- if test "$(mkdir_p)"; then \
- $(mkdir_p) init; \
- else \
- if test ! -d init; then \
- mkdir init; \
- fi \
- fi
- sed -e "s|%configure_input%|$@. Generated from $< by configure.|" \
- -e "s|%bindir%|$(bindir)|" \
- -e "s|%sysconfdir%|$(sysconfdir)|" \
- -e "s|%localstaterundir%|$(localstaterundir)|" \
- -e "s|%couchdb_command_name%|$(couchdb_command_name)|" \
- < $< > $@
-
-logrotate.d/couchdb: logrotate.d/couchdb.tpl
- sed -e "s|%localstatelogdir%|@localstatelogdir@|g" < $< > $@
-
-launchd/org.apache.couchdb.plist: launchd/org.apache.couchdb.plist.tpl
- if test "$(mkdir_p)"; then \
- $(mkdir_p) launchd; \
- else \
- if test ! -d launchd; then \
- mkdir launchd; \
- fi \
- fi
- sed -e "s|%configure_input%|$@. Generated from $< by configure.|" \
- -e "s|%bindir%|$(bindir)|" \
- -e "s|%couchdb_command_name%|$(couchdb_command_name)|" \
- < $< > $@
-
-if WINDOWS
-
-# README.txt has \n line endings in the repo and must have \r\n
-# when installed as notepad is used to view it.
-# Also: the targets below don't seem to update after an svn-up (which
-# changes the version string in the generated files) so we trick make
-# into always building it with the FORCE pattern...
-windows/README.txt: windows/README.txt.tpl FORCE
- sed -e "s|%package_name%|@package_name@|g" \
- -e "s|%version%|@version@|g" \
- < $< | unix2dos > $@
-
-windows/couchdb.iss: windows/couchdb.iss.tpl FORCE
- sed -e "s|%configure_input%|$@. Generated from $< by configure.|" \
- -e "s|%package_name%|@package_name@|g" \
- -e "s|%locallibbindir%|`cygpath -m @locallibbindir@`|g" \
- -e "s|%version%|@version@|g" \
- -e "s|%erts_version%|`$(ERL) -version 2>&1 | $(SED) 's/[^0-9\.]//g'`|g" \
- -e "s|%openssl_bin_dir%|@openssl_bin_dir@|g" \
- -e "s|%msvc_redist_dir%|@msvc_redist_dir@|g" \
- -e "s|%msvc_redist_name%|@msvc_redist_name@|g" \
- < $< > $@
-
-# The installer depends on all files, not just the source .iss file,
-# so we trick make into always building it with the FORCE pattern...
-windows/setup-couchdb-@version@.exe: windows/couchdb.iss windows/README.txt FORCE
- "$(INNO_COMPILER_EXECUTABLE)" /q $<
- @echo Windows Installer is at: `cygpath -a -w windows/setup-couchdb-@version@.exe`
-
-windows/setup-couchdb-@version@.exe.md5: windows/setup-couchdb-@version@.exe
- cd windows && md5sum ./$(<F) > $(@F)
-
-windows/setup-couchdb-@version@.exe.sha: windows/setup-couchdb-@version@.exe
- cd windows && sha1sum ./$(<F) > $(@F)
-
-FORCE:
-
-endif
-
-install-data-hook:
- if test -n "$(init_DATA)"; then \
- chmod +x "$(DESTDIR)$(initdir)/couchdb"; \
- fi
diff --git a/etc/couchdb/Makefile.am b/etc/couchdb/Makefile.am
deleted file mode 100644
index 9367ceac..00000000
--- a/etc/couchdb/Makefile.am
+++ /dev/null
@@ -1,86 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-couchprivlibdir = $(localerlanglibdir)/couch-$(version)/priv/lib
-devcouchprivlibdir = $(abs_top_builddir)/src/couchdb/priv/.libs
-
-localconf_DATA = default.ini
-noinst_DATA = default_dev.ini local_dev.ini
-
-EXTRA_DIST = local.ini
-
-CLEANFILES = $(localconf_DATA) $(noinst_DATA)
-
-transform = @program_transform_name@
-couchjs_command_name = `echo couchjs | sed '$(transform)'`
-couchjs_dev_command_name = `echo couchjs_dev | sed '$(transform)'`
-
-if WINDOWS
-default.ini: default.ini.tpl
- sed -e "s|%bindir%|.|g" \
- -e "s|%localconfdir%|$(localconfdir)|g" \
- -e "s|%localdatadir%|../share/couchdb|g" \
- -e "s|%localbuilddatadir%|../share/couchdb|g" \
- -e "s|%localstatelibdir%|../var/lib/couchdb|g" \
- -e "s|%localstatelogdir%|../var/log/couchdb|g" \
- -e "s|%localstaterundir%|../var/run/couchdb|g" \
- -e "s|%couchprivlibdir%|../lib/couch-$(version)/priv/lib|g" \
- -e "s|%couchjs_command_name%|couchjs.exe|g" \
- < $< > $@
-else
-default.ini: default.ini.tpl
- sed -e "s|%bindir%|$(bindir)|g" \
- -e "s|%localconfdir%|$(localconfdir)|g" \
- -e "s|%localdatadir%|$(localdatadir)|g" \
- -e "s|%localbuilddatadir%|$(localdatadir)|g" \
- -e "s|%localstatelibdir%|$(localstatelibdir)|g" \
- -e "s|%localstatelogdir%|$(localstatelogdir)|g" \
- -e "s|%localstaterundir%|$(localstaterundir)|g" \
- -e "s|%couchprivlibdir%|$(couchprivlibdir)|g" \
- -e "s|%couchjs_command_name%|$(couchjs_command_name)|g" \
- < $< > $@
-endif
-
-default_dev.ini: default.ini.tpl
- sed -e "s|%bindir%|$(abs_top_builddir)/bin|g" \
- -e "s|%localconfdir%|$(abs_top_builddir)/etc/couchdb|g" \
- -e "s|%localdatadir%|$(abs_top_srcdir)/share|g" \
- -e "s|%localbuilddatadir%|$(abs_top_builddir)/share|g" \
- -e "s|%localstatelibdir%|$(abs_top_builddir)/tmp/lib|g" \
- -e "s|%localstatelogdir%|$(abs_top_builddir)/tmp/log|g" \
- -e "s|%localstaterundir%|$(abs_top_builddir)/tmp/run|g" \
- -e "s|%couchprivlibdir%|$(devcouchprivlibdir)|g" \
- -e "s|%couchjs_command_name%|$(couchjs_dev_command_name)|g" \
- < $< > $@
-
-# Noah said to not specify local.ini but it borks
-# VPATH builds that make distcheck uses.
-local_dev.ini: local.ini
- if test ! -f "$@"; then \
- cp $< $@; \
- fi
-
-install-data-hook:
- if test ! -f "$(DESTDIR)$(localconfdir)/local.ini"; then \
- cp $(srcdir)/local.ini "$(DESTDIR)$(localconfdir)/local.ini"; \
- fi
- if test ! "$(mkdir_p)" = ""; then \
- $(mkdir_p) "$(DESTDIR)$(localconfdir)/default.d"; \
- $(mkdir_p) "$(DESTDIR)$(localconfdir)/local.d"; \
- else \
- echo "WARNING: You may have to create these directories by hand."; \
- mkdir -p "$(DESTDIR)$(localconfdir)/default.d"; \
- mkdir -p "$(DESTDIR)$(localconfdir)/local.d"; \
- fi
-
-uninstall-local:
- rm -f "$(DESTDIR)/$(localconfdir)/local.ini"
diff --git a/etc/couchdb/local.ini b/etc/couchdb/local.ini
deleted file mode 100644
index 33380a32..00000000
--- a/etc/couchdb/local.ini
+++ /dev/null
@@ -1,74 +0,0 @@
-; CouchDB Configuration Settings
-
-; Custom settings should be made in this file. They will override settings
-; in default.ini, but unlike changes made to default.ini, this file won't be
-; overwritten on server upgrade.
-
-[couchdb]
-;max_document_size = 4294967296 ; bytes
-
-[httpd]
-;port = 5984
-;bind_address = 127.0.0.1
-; Options for the MochiWeb HTTP server.
-;server_options = [{backlog, 128}, {acceptor_pool_size, 16}]
-; For more socket options, consult Erlang's module 'inet' man page.
-;socket_options = [{recbuf, 262144}, {sndbuf, 262144}, {nodelay, true}]
-
-; Uncomment next line to trigger basic-auth popup on unauthorized requests.
-;WWW-Authenticate = Basic realm="administrator"
-
-; Uncomment next line to set the configuration modification whitelist. Only
-; whitelisted values may be changed via the /_config URLs. To allow the admin
-; to change this value over HTTP, remember to include {httpd,config_whitelist}
-; itself. Excluding it from the list would require editing this file to update
-; the whitelist.
-;config_whitelist = [{httpd,config_whitelist}, {log,level}, {etc,etc}]
-
-[httpd_global_handlers]
-;_google = {couch_httpd_proxy, handle_proxy_req, <<"http://www.google.com">>}
-
-[couch_httpd_auth]
-; If you set this to true, you should also uncomment the WWW-Authenticate line
-; above. If you don't configure a WWW-Authenticate header, CouchDB will send
-; Basic realm="server" in order to prevent you getting logged out.
-; require_valid_user = false
-
-[log]
-;level = debug
-
-[os_daemons]
-; For any commands listed here, CouchDB will attempt to ensure that
-; the process remains alive while CouchDB runs as well as shut them
-; down when CouchDB exits.
-;foo = /path/to/command -with args
-
-[daemons]
-; enable SSL support by uncommenting the following line and supply the PEM's below.
-; the default ssl port CouchDB listens on is 6984
-; httpsd = {couch_httpd, start_link, [https]}
-
-[ssl]
-;cert_file = /full/path/to/server_cert.pem
-;key_file = /full/path/to/server_key.pem
-
-; To enable Virtual Hosts in CouchDB, add a vhost = path directive. All requests to
-; the Virual Host will be redirected to the path. In the example below all requests
-; to http://example.com/ are redirected to /database.
-; If you run CouchDB on a specific port, include the port number in the vhost:
-; example.com:5984 = /database
-
-[vhosts]
-;example.com = /database/
-
-[update_notification]
-;unique notifier name=/full/path/to/exe -with "cmd line arg"
-
-; To create an admin account uncomment the '[admins]' section below and add a
-; line in the format 'username = password'. When you next start CouchDB, it
-; will change the password to a hash (so that your passwords don't linger
-; around in plain-text files). You can add more admin accounts with more
-; 'username = password' lines. Don't forget to restart CouchDB after
-; changing this.
-[admins]
-;admin = mysecretpassword
diff --git a/etc/default/Makefile.am b/etc/default/Makefile.am
deleted file mode 100644
index 5b4faae0..00000000
--- a/etc/default/Makefile.am
+++ /dev/null
@@ -1,13 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-## This file intentionally left blank.
diff --git a/etc/default/couchdb b/etc/default/couchdb
deleted file mode 100644
index c2a3f2ae..00000000
--- a/etc/default/couchdb
+++ /dev/null
@@ -1,7 +0,0 @@
-# Sourced by init script for configuration.
-
-COUCHDB_USER=couchdb
-COUCHDB_STDOUT_FILE=/dev/null
-COUCHDB_STDERR_FILE=/dev/null
-COUCHDB_RESPAWN_TIMEOUT=5
-COUCHDB_OPTIONS=
diff --git a/etc/init/Makefile.am b/etc/init/Makefile.am
deleted file mode 100644
index 5b4faae0..00000000
--- a/etc/init/Makefile.am
+++ /dev/null
@@ -1,13 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-## This file intentionally left blank.
diff --git a/etc/init/couchdb.tpl.in b/etc/init/couchdb.tpl.in
deleted file mode 100644
index 3b8d17ea..00000000
--- a/etc/init/couchdb.tpl.in
+++ /dev/null
@@ -1,168 +0,0 @@
-#!/bin/sh -e
-
-# Licensed under the Apache License, Version 2.0 (the "License"); you may not
-# use this file except in compliance with the License. You may obtain a copy of
-# the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations under
-# the License.
-
-### BEGIN INIT INFO
-# Provides: couchdb
-# Required-Start: $local_fs $remote_fs
-# Required-Stop: $local_fs $remote_fs
-# Default-Start: 2 3 4 5
-# Default-Stop: 0 1 6
-# Short-Description: Apache CouchDB init script
-# Description: Apache CouchDB init script for the database server.
-### END INIT INFO
-
-SCRIPT_OK=0
-SCRIPT_ERROR=1
-
-DESCRIPTION="database server"
-NAME=couchdb
-SCRIPT_NAME=`basename $0`
-COUCHDB=%bindir%/%couchdb_command_name%
-CONFIGURATION_FILE=%sysconfdir%/default/couchdb
-RUN_DIR=%localstaterundir%
-LSB_LIBRARY=/lib/lsb/init-functions
-
-if test ! -x $COUCHDB; then
- exit $SCRIPT_ERROR
-fi
-
-if test -r $CONFIGURATION_FILE; then
- . $CONFIGURATION_FILE
-fi
-
-log_daemon_msg () {
- # Dummy function to be replaced by LSB library.
-
- echo $@
-}
-
-log_end_msg () {
- # Dummy function to be replaced by LSB library.
-
- if test "$1" != "0"; then
- echo "Error with $DESCRIPTION: $NAME"
- fi
- return $1
-}
-
-if test -r $LSB_LIBRARY; then
- . $LSB_LIBRARY
-fi
-
-start_couchdb () {
- # Start Apache CouchDB as a background process.
-
- command="$COUCHDB -b"
- if test -n "$COUCHDB_STDOUT_FILE"; then
- command="$command -o $COUCHDB_STDOUT_FILE"
- fi
- if test -n "$COUCHDB_STDERR_FILE"; then
- command="$command -e $COUCHDB_STDERR_FILE"
- fi
- if test -n "$COUCHDB_RESPAWN_TIMEOUT"; then
- command="$command -r $COUCHDB_RESPAWN_TIMEOUT"
- fi
- if test -n "$COUCHDB_OPTIONS"; then
- command="$command $COUCHDB_OPTIONS"
- fi
- mkdir -p "$RUN_DIR"
- if test -n "$COUCHDB_USER"; then
- chown $COUCHDB_USER "$RUN_DIR"
- if su $COUCHDB_USER -c "$command" > /dev/null; then
- return $SCRIPT_OK
- else
- return $SCRIPT_ERROR
- fi
- else
- if $command > /dev/null; then
- return $SCRIPT_OK
- else
- return $SCRIPT_ERROR
- fi
- fi
-}
-
-stop_couchdb () {
- # Stop the running Apache CouchDB process.
-
- command="$COUCHDB -d"
- if test -n "$COUCHDB_OPTIONS"; then
- command="$command $COUCHDB_OPTIONS"
- fi
- if test -n "$COUCHDB_USER"; then
- if su $COUCHDB_USER -c "$command" > /dev/null; then
- return $SCRIPT_OK
- else
- return $SCRIPT_ERROR
- fi
- else
- if $command > /dev/null; then
- return $SCRIPT_OK
- else
- return $SCRIPT_ERROR
- fi
- fi
-}
-
-display_status () {
- # Display the status of the running Apache CouchDB process.
-
- $COUCHDB -s
-}
-
-parse_script_option_list () {
- # Parse arguments passed to the script and take appropriate action.
-
- case "$1" in
- start)
- log_daemon_msg "Starting $DESCRIPTION" $NAME
- if start_couchdb; then
- log_end_msg $SCRIPT_OK
- else
- log_end_msg $SCRIPT_ERROR
- fi
- ;;
- stop)
- log_daemon_msg "Stopping $DESCRIPTION" $NAME
- if stop_couchdb; then
- log_end_msg $SCRIPT_OK
- else
- log_end_msg $SCRIPT_ERROR
- fi
- ;;
- restart)
- log_daemon_msg "Restarting $DESCRIPTION" $NAME
- if stop_couchdb; then
- if start_couchdb; then
- log_end_msg $SCRIPT_OK
- else
- log_end_msg $SCRIPT_ERROR
- fi
- else
- log_end_msg $SCRIPT_ERROR
- fi
- ;;
- status)
- display_status
- ;;
- *)
- cat << EOF >&2
-Usage: $SCRIPT_NAME {start|stop|restart|status}
-EOF
- exit $SCRIPT_ERROR
- ;;
- esac
-}
-
-parse_script_option_list $@
diff --git a/etc/launchd/Makefile.am b/etc/launchd/Makefile.am
deleted file mode 100644
index 5b4faae0..00000000
--- a/etc/launchd/Makefile.am
+++ /dev/null
@@ -1,13 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-## This file intentionally left blank.
diff --git a/etc/launchd/org.apache.couchdb.plist.tpl.in b/etc/launchd/org.apache.couchdb.plist.tpl.in
deleted file mode 100644
index c72f3480..00000000
--- a/etc/launchd/org.apache.couchdb.plist.tpl.in
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
- "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
- <dict>
- <key>Label</key>
- <string>org.apache.couchdb</string>
- <key>EnvironmentVariables</key>
- <dict>
- <key>HOME</key>
- <string>~</string>
- <key>DYLD_LIBRARY_PATH</key>
- <string>/opt/local/lib:$DYLD_LIBRARY_PATH</string>
- </dict>
- <key>ProgramArguments</key>
- <array>
- <string>%bindir%/%couchdb_command_name%</string>
- </array>
- <key>UserName</key>
- <string>couchdb</string>
- <key>StandardOutPath</key>
- <string>/dev/null</string>
- <key>StandardErrorPath</key>
- <string>/dev/null</string>
- <key>RunAtLoad</key>
- <true/>
- <key>KeepAlive</key>
- <true/>
- </dict>
-</plist>
diff --git a/etc/logrotate.d/Makefile.am b/etc/logrotate.d/Makefile.am
deleted file mode 100644
index 5b4faae0..00000000
--- a/etc/logrotate.d/Makefile.am
+++ /dev/null
@@ -1,13 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-## This file intentionally left blank.
diff --git a/etc/logrotate.d/couchdb.tpl.in b/etc/logrotate.d/couchdb.tpl.in
deleted file mode 100644
index 0bb07e13..00000000
--- a/etc/logrotate.d/couchdb.tpl.in
+++ /dev/null
@@ -1,9 +0,0 @@
-%localstatelogdir%/*.log {
- weekly
- rotate 10
- copytruncate
- delaycompress
- compress
- notifempty
- missingok
-}
diff --git a/etc/windows/Makefile.am b/etc/windows/Makefile.am
deleted file mode 100644
index 5b4faae0..00000000
--- a/etc/windows/Makefile.am
+++ /dev/null
@@ -1,13 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-## This file intentionally left blank.
diff --git a/etc/windows/README.txt.tpl b/etc/windows/README.txt.tpl
deleted file mode 100644
index 791bcc85..00000000
--- a/etc/windows/README.txt.tpl
+++ /dev/null
@@ -1,29 +0,0 @@
-This is the README for the %package_name% binary distribution for
-Windows, version %version%.
-
-* Although CouchDB defaults to installing into your "Program Files" directory,
- the permissions on the 'var' and 'etc' sub-directories have been adjusted
- to allow modification by any authorized user so the couchdb databases, logs
- and .ini files can be written. You may like to further restrict these
- permissions to only the user who will be running couchdb.
-
-* The installer offers to install CouchDB as a Windows Service. If you select
- this option, the service will run as the "LocalSystem" user and be
- configured to start automatically. You can configure the service properties
- via the Windows 'Services' applet.
-
-* To start CouchDB in a "console" environment, execute couchdb.bat in the
- 'bin' directory. A shortcut to this batch file should have been installed.
- Don't try and start couchdb this way if the service is running - it will
- fail.
-
-* The Futon application which comes with CouchDB does not work with
- Internet Explorer - Mozilla Firefox is generally recommended.
-
-* The test suite is known to fail on Windows due to what appear to be
- permissions errors; this is due to couch being unable to delete a
- file while it is in use on Windows.
- See also https://issues.apache.org/jira/browse/COUCHDB-326
-
-* Additional help with the Windows support is needed - please contact the
- couchdb-dev list if you can help.
diff --git a/etc/windows/couchdb.iss.tpl b/etc/windows/couchdb.iss.tpl
deleted file mode 100644
index 8a32561d..00000000
--- a/etc/windows/couchdb.iss.tpl
+++ /dev/null
@@ -1,87 +0,0 @@
-; Licensed under the Apache License, Version 2.0 (the "License"); you may not
-; use this file except in compliance with the License. You may obtain a copy of
-; the License at
-;
-; http://www.apache.org/licenses/LICENSE-2.0
-;
-; Unless required by applicable law or agreed to in writing, software
-; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-; License for the specific language governing permissions and limitations under
-; the License.
-
-; CouchDB inno installer script
-; %configure_input%
-
-[Setup]
-AppID=ApacheCouchDB
-AppName=%package_name%
-AppVerName=%package_name% %version%
-AppPublisher=Apache Software Foundation
-AppPublisherURL=http://couchdb.apache.org/
-LicenseFile=../../LICENSE
-DefaultDirName={pf}\Apache Software Foundation\CouchDB
-DefaultGroupName=%package_name%
-OutputBaseFilename=setup-couchdb-%version%
-OutputDir=.
-
-[Files]
-Source: "%locallibbindir%\..\*.*"; DestDir: "{app}"; Flags: ignoreversion uninsrestartdelete restartreplace
-; bin dir
-Source: "%locallibbindir%\*.*"; DestDir: "{app}\bin"; Flags: ignoreversion uninsrestartdelete restartreplace recursesubdirs
-; other dirs copied '*.*'
-Source: "%locallibbindir%\..\erts-%erts_version%\*.*"; DestDir: "{app}\erts-%erts_version%"; Flags: ignoreversion uninsrestartdelete restartreplace recursesubdirs
-Source: "%locallibbindir%\..\lib\*.*"; DestDir: "{app}\lib"; Flags: ignoreversion uninsrestartdelete restartreplace recursesubdirs
-Source: "%locallibbindir%\..\share\*.*"; DestDir: "{app}\share"; Flags: ignoreversion uninsrestartdelete restartreplace recursesubdirs
-Source: "%locallibbindir%\..\releases\*.*"; DestDir: "{app}\releases"; Flags: ignoreversion uninsrestartdelete restartreplace recursesubdirs
-; skip ./usr, ./var
-
-; custom stuff...
-; ./etc/default.ini is unconditional
-Source: "%locallibbindir%\..\etc\couchdb\default.ini"; DestDir: "{app}\etc\couchdb"; Flags: ignoreversion uninsrestartdelete restartreplace
-; ./etc/local.ini is preserved and should not be updated if it exists
-Source: "%locallibbindir%\..\etc\couchdb\local.ini"; DestDir: "{app}\etc\couchdb"; Flags: onlyifdoesntexist uninsneveruninstall
-; readme
-Source: "README.txt"; DestDir: "{app}"; Flags: isreadme
-
-; msvc redists - see comments in configure.ac for notes about these...
-; ( deleteafterinstall - not needed - {tmp} auto cleaned????
-Source: "%msvc_redist_dir%\%msvc_redist_name%"; DestDir: "{tmp}"; Flags: deleteafterinstall
-
-; These are erlang requirements and not copied by our makefiles.
-Source: "%openssl_bin_dir%\ssleay32.dll"; DestDir: "{app}\bin"; Flags: ignoreversion uninsrestartdelete restartreplace
-Source: "%openssl_bin_dir%\libeay32.dll"; DestDir: "{app}\bin"; Flags: ignoreversion uninsrestartdelete restartreplace
-
-[Dirs]
-Name: "{app}\var\lib\couchdb"; Permissions: authusers-modify
-Name: "{app}\var\log\couchdb"; Permissions: authusers-modify
-Name: "{app}\etc\couchdb"; Permissions: authusers-modify
-
-[Icons]
-Name: "{group}\Start CouchDB"; Filename: "{app}\bin\couchdb.bat"
-Name: "{group}\Futon (CouchDB web interface)"; Filename: "http://127.0.0.1:5984/_utils"
-Name: "{group}\CouchDB Web Site"; Filename: "http://couchdb.apache.org/"
-
-[Tasks]
-Name: service; Description: "Install couchdb as a Windows service"
-Name: service\start; Description: "Start the service after installation"
-
-[Run]
-Filename: "{tmp}\%msvc_redist_name%"; Parameters: "/q"
-; This is erlang's Install.exe which updates erl.ini correctly.
-Filename: "{app}\Install.exe"; Parameters: "-s"; Flags: runhidden
-
-; Commands for a service
-; First attempt to nuke an existing service of this name, incase they are
-; reinstalling without uninstalling
-Filename: "{app}\erts-%erts_version%\bin\erlsrv.exe"; Parameters: "remove ""%package_name%"""; Flags: runhidden; Tasks: service
-; add a new service, including automatic restart by default on failure
-Filename: "{app}\erts-%erts_version%\bin\erlsrv.exe"; Parameters: "add ""%package_name%"" -workdir ""{app}\bin"" -onfail restart_always -args ""-sasl errlog_type error -s couch +A 4 +W w"" -comment ""%package_name% %version%"""; Flags: runhidden; Tasks: service
-; and start it if requested
-Filename: "{app}\erts-%erts_version%\bin\erlsrv.exe"; Parameters: "start ""%package_name%"""; Flags: runhidden; Tasks: service\start
-
-[UninstallRun]
-; erlsrv stops services prior to removing them
-Filename: "{app}\erts-%erts_version%\bin\erlsrv.exe"; Parameters: "remove ""%package_name%"""; Flags: runhidden; Tasks: service
-; kill epmd.exe if running to ensure uninstaller is not prevented from removing all binaries
-Filename: "{app}\erts-%erts_version%\bin\epmd.exe"; Parameters: "-kill"; Flags: runhidden
diff --git a/m4/ac_check_curl.m4.gz b/m4/ac_check_curl.m4.gz
deleted file mode 100644
index 020e646f..00000000
--- a/m4/ac_check_curl.m4.gz
+++ /dev/null
Binary files differ
diff --git a/m4/ac_check_icu.m4.gz b/m4/ac_check_icu.m4.gz
deleted file mode 100644
index 8af50ff9..00000000
--- a/m4/ac_check_icu.m4.gz
+++ /dev/null
Binary files differ
diff --git a/rebar b/rebar
new file mode 100755
index 00000000..98f23676
--- /dev/null
+++ b/rebar
Binary files differ
diff --git a/rebar.config b/rebar.config
new file mode 100644
index 00000000..332ca15f
--- /dev/null
+++ b/rebar.config
@@ -0,0 +1,49 @@
+% Copyright 2010 Cloudant
+%
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+{deps, [
+ {oauth, ".*", {git, "https://github.com/cloudant/erlang-oauth.git",
+ {branch, "couch"}}},
+ {ibrowse, ".*", {git, "https://github.com/cloudant/ibrowse.git",
+ {branch, "couch_1.1"}}},
+ {mochiweb, ".*", {git, "https://github.com/cloudant/mochiweb.git",
+ {branch, "couch_1.1"}}},
+ {rexi, ".*", {git, "https://github.com/cloudant/rexi.git",
+ master}},
+ {fabric, ".*", {git, "https://github.com/cloudant/fabric.git",
+ master}},
+ {mem3, ".*", {git, "https://github.com/cloudant/mem3.git",
+ {branch, "couch_1.1"}}},
+ {chttpd, ".*", {git, "https://github.com/cloudant/chttpd.git",
+ {branch, "couch_1.1"}}}
+]}.
+% needed for a clean transition to the deps model
+{clean_files, [
+ "apps/oauth/ebin",
+ "apps/ibrowse/ebin",
+ "apps/mochiweb/ebin",
+ "apps/rexi/ebin",
+ "apps/fabric/ebin",
+ "apps/mem3/ebin",
+ "apps/chttpd/ebin",
+ "apps/etap/ebin"
+]}.
+{sub_dirs, [
+ "apps/couch",
+ "rel"
+]}.
+{cover_enabled, true}.
+{eunit_opts, [{report,{eunit_surefire,[{dir,"."}]}}]}.
+{erl_opts, [debug_info]}.
+{lib_dirs, ["apps"]}.
diff --git a/rel/overlay/bin/bigcouch b/rel/overlay/bin/bigcouch
new file mode 100755
index 00000000..22275daf
--- /dev/null
+++ b/rel/overlay/bin/bigcouch
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+ERTS_BIN_DIR=$(cd ${0%/*} && pwd)
+
+export ROOTDIR=${ERTS_BIN_DIR%/*}
+
+START_ERL=`cat $ROOTDIR/releases/start_erl.data`
+ERTS_VSN=${START_ERL% *}
+APP_VSN=${START_ERL#* }
+
+export BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
+export EMU=beam
+export PROGNAME=`echo $0 | sed 's/.*\///'`
+
+exec $BINDIR/erlexec -boot $ROOTDIR/releases/$APP_VSN/bigcouch \
+ -args_file $ROOTDIR/etc/vm.args
diff --git a/rel/overlay/erts-vsn/bin/erl b/rel/overlay/erts-vsn/bin/erl
new file mode 100644
index 00000000..635744ce
--- /dev/null
+++ b/rel/overlay/erts-vsn/bin/erl
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+
+## This script replaces the default "erl" in erts-VSN/bin. This is necessary
+## as escript depends on erl and in turn, erl depends on having access to a
+## bootscript (start.boot). Note that this script is ONLY invoked as a side-effect
+## of running escript -- the embedded node bypasses erl and uses erlexec directly
+## (as it should).
+##
+## Note that this script makes the assumption that there is a start_clean.boot
+## file available in $ROOTDIR/release/VSN.
+
+# Determine the abspath of where this script is executing from.
+ERTS_BIN_DIR=$(cd ${0%/*} && pwd)
+
+# Now determine the root directory -- this script runs from erts-VSN/bin,
+# so we simply need to strip off two dirs from the end of the ERTS_BIN_DIR
+# path.
+ROOTDIR=${ERTS_BIN_DIR%/*/*}
+
+# Parse out release and erts info
+START_ERL=`cat $ROOTDIR/releases/start_erl.data`
+ERTS_VSN=${START_ERL% *}
+APP_VSN=${START_ERL#* }
+
+BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
+EMU=beam
+PROGNAME=`echo $0 | sed 's/.*\///'`
+CMD="$BINDIR/erlexec"
+export EMU
+export ROOTDIR
+export BINDIR
+export PROGNAME
+
+exec $CMD -boot $ROOTDIR/releases/$APP_VSN/start_clean ${1+"$@"}
diff --git a/etc/couchdb/default.ini.tpl.in b/rel/overlay/etc/default.ini
index f5dc24af..88bddd70 100644
--- a/etc/couchdb/default.ini.tpl.in
+++ b/rel/overlay/etc/default.ini
@@ -1,20 +1,26 @@
-; @configure_input@
-
-; Upgrading CouchDB will overwrite this file.
-
[couchdb]
-database_dir = %localstatelibdir%
-view_index_dir = %localstatelibdir%
-util_driver_dir = %couchprivlibdir%
-max_document_size = 4294967296 ; 4 GB
-os_process_timeout = 5000 ; 5 seconds. for view and external servers.
-max_dbs_open = 100
-delayed_commits = true ; set this to false to ensure an fsync before 201 Created is returned
-uri_file = %localstaterundir%/couch.uri
+database_dir = {{data_dir}}
+view_index_dir = {{view_dir}}
+max_document_size = 67108864
+os_process_timeout = 5000
+max_dbs_open = 500
+delayed_commits = false
+
+[cluster]
+q=8
+r=2
+w=2
+n=3
+
+[chttpd]
+port = {{cluster_port}}
+backlog = 512
+docroot = {{prefix}}/share/www
[httpd]
-port = 5984
+port = {{backend_port}}
bind_address = 127.0.0.1
+max_connections = 2048
authentication_handlers = {couch_httpd_oauth, oauth_authentication_handler}, {couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}
default_handler = {couch_httpd_db, handle_request}
secure_rewrites = true
@@ -29,7 +35,7 @@ allow_jsonp = false
port = 6984
[log]
-file = %localstatelogdir%/couch.log
+file = {{prefix}}/var/log/bigcouch.log
level = info
include_sasl = true
@@ -41,11 +47,8 @@ timeout = 43200 ; (default to 12 hours) number of seconds before automatic logou
auth_cache_size = 50 ; size is number of cache entries
[query_servers]
-javascript = %bindir%/%couchjs_command_name% %localbuilddatadir%/server/main.js
+javascript = {{prefix}}/bin/couchjs {{prefix}}/share/couchjs/main.js
-; Changing reduce_limit to false will disable reduce_limit.
-; If you think you're hitting reduce_limit with a "good" reduce function,
-; please let us know on the mailing list so we can fine tune the heuristic.
[query_server_config]
reduce_limit = true
os_process_limit = 25
@@ -53,8 +56,7 @@ os_process_limit = 25
[daemons]
view_manager={couch_view, start_link, []}
external_manager={couch_external_manager, start_link, []}
-db_update_notifier={couch_db_update_notifier_sup, start_link, []}
-query_servers={couch_query_servers, start_link, []}
+query_servers={couch_proc_manager, start_link, []}
httpd={couch_httpd, start_link, []}
stats_aggregator={couch_stats_aggregator, start, []}
stats_collector={couch_stats_collector, start, []}
@@ -66,9 +68,9 @@ os_daemons={couch_os_daemons, start_link, []}
[httpd_global_handlers]
/ = {couch_httpd_misc_handlers, handle_welcome_req, <<"Welcome">>}
-favicon.ico = {couch_httpd_misc_handlers, handle_favicon_req, "%localdatadir%/www"}
+favicon.ico = {couch_httpd_misc_handlers, handle_favicon_req, "{{prefix}}/share/www"}
-_utils = {couch_httpd_misc_handlers, handle_utils_dir_req, "%localdatadir%/www"}
+_utils = {couch_httpd_misc_handlers, handle_utils_dir_req, "{{prefix}}/share/www"}
_all_dbs = {couch_httpd_misc_handlers, handle_all_dbs_req}
_active_tasks = {couch_httpd_misc_handlers, handle_task_status_req}
_config = {couch_httpd_misc_handlers, handle_config_req}
@@ -79,6 +81,7 @@ _stats = {couch_httpd_stats_handlers, handle_stats_req}
_log = {couch_httpd_misc_handlers, handle_log_req}
_session = {couch_httpd_auth, handle_session_req}
_oauth = {couch_httpd_oauth, handle_oauth_req}
+_system = {chttpd_misc, handle_system_req}
[httpd_db_handlers]
_view_cleanup = {couch_httpd_db, handle_view_cleanup_req}
@@ -87,12 +90,6 @@ _design = {couch_httpd_db, handle_design_req}
_temp_view = {couch_httpd_view, handle_temp_view_req}
_changes = {couch_httpd_db, handle_changes_req}
-; The external module takes an optional argument allowing you to narrow it to a
-; single script. Otherwise the script name is inferred from the first path section
-; after _external's own path.
-; _mypath = {couch_httpd_external, handle_external_req, <<"mykey">>}
-; _external = {couch_httpd_external, handle_external_req}
-
[httpd_design_handlers]
_view = {couch_httpd_view, handle_view_req}
_show = {couch_httpd_show, handle_doc_show_req}
diff --git a/rel/overlay/etc/local.ini b/rel/overlay/etc/local.ini
new file mode 100644
index 00000000..3146ea25
--- /dev/null
+++ b/rel/overlay/etc/local.ini
@@ -0,0 +1 @@
+; local customizations are stored here
diff --git a/rel/overlay/etc/vm.args b/rel/overlay/etc/vm.args
new file mode 100644
index 00000000..bb143502
--- /dev/null
+++ b/rel/overlay/etc/vm.args
@@ -0,0 +1,22 @@
+# Each node in the system must have a unique name. A name can be short
+# (specified using -sname) or it can by fully qualified (-name). There can be
+# no communication between nodes running with the -sname flag and those running
+# with the -name flag.
+{{node_name}}
+
+# All nodes must share the same magic cookie for distributed Erlang to work.
+# Comment out this line if you synchronized the cookies by other means (using
+# the ~/.erlang.cookie file, for example).
+-setcookie monster
+
+# Tell SASL not to log progress reports
+-sasl errlog_type error
+
+# Use kernel poll functionality if supported by emulator
++K true
+
+# Start a pool of asynchronous IO threads
++A 16
+
+# Comment this line out to enable the interactive Erlang shell on startup
++Bd -noinput
diff --git a/share/www/_sidebar.html b/rel/overlay/share/www/_sidebar.html
index 563a85c8..563a85c8 100644
--- a/share/www/_sidebar.html
+++ b/rel/overlay/share/www/_sidebar.html
diff --git a/share/www/config.html b/rel/overlay/share/www/config.html
index 9863c8b5..9863c8b5 100644
--- a/share/www/config.html
+++ b/rel/overlay/share/www/config.html
diff --git a/share/www/couch_tests.html b/rel/overlay/share/www/couch_tests.html
index f10bad23..f10bad23 100644
--- a/share/www/couch_tests.html
+++ b/rel/overlay/share/www/couch_tests.html
diff --git a/share/www/custom_test.html b/rel/overlay/share/www/custom_test.html
index 2566a000..2566a000 100644
--- a/share/www/custom_test.html
+++ b/rel/overlay/share/www/custom_test.html
diff --git a/share/www/database.html b/rel/overlay/share/www/database.html
index 9a9f121e..9a9f121e 100644
--- a/share/www/database.html
+++ b/rel/overlay/share/www/database.html
diff --git a/share/www/dialog/_admin_party.html b/rel/overlay/share/www/dialog/_admin_party.html
index ea9fb15a..ea9fb15a 100644
--- a/share/www/dialog/_admin_party.html
+++ b/rel/overlay/share/www/dialog/_admin_party.html
diff --git a/share/www/dialog/_compact_cleanup.html b/rel/overlay/share/www/dialog/_compact_cleanup.html
index 506417f4..506417f4 100644
--- a/share/www/dialog/_compact_cleanup.html
+++ b/rel/overlay/share/www/dialog/_compact_cleanup.html
diff --git a/share/www/dialog/_create_admin.html b/rel/overlay/share/www/dialog/_create_admin.html
index d4aec95a..d4aec95a 100644
--- a/share/www/dialog/_create_admin.html
+++ b/rel/overlay/share/www/dialog/_create_admin.html
diff --git a/share/www/dialog/_create_config.html b/rel/overlay/share/www/dialog/_create_config.html
index 79e08b08..79e08b08 100644
--- a/share/www/dialog/_create_config.html
+++ b/rel/overlay/share/www/dialog/_create_config.html
diff --git a/share/www/dialog/_create_database.html b/rel/overlay/share/www/dialog/_create_database.html
index 74e7ea61..74e7ea61 100644
--- a/share/www/dialog/_create_database.html
+++ b/rel/overlay/share/www/dialog/_create_database.html
diff --git a/share/www/dialog/_database_security.html b/rel/overlay/share/www/dialog/_database_security.html
index d63fa787..d63fa787 100644
--- a/share/www/dialog/_database_security.html
+++ b/rel/overlay/share/www/dialog/_database_security.html
diff --git a/share/www/dialog/_delete_database.html b/rel/overlay/share/www/dialog/_delete_database.html
index 039ba39b..039ba39b 100644
--- a/share/www/dialog/_delete_database.html
+++ b/rel/overlay/share/www/dialog/_delete_database.html
diff --git a/share/www/dialog/_delete_document.html b/rel/overlay/share/www/dialog/_delete_document.html
index 8ae89710..8ae89710 100644
--- a/share/www/dialog/_delete_document.html
+++ b/rel/overlay/share/www/dialog/_delete_document.html
diff --git a/share/www/dialog/_login.html b/rel/overlay/share/www/dialog/_login.html
index f05a5fdc..f05a5fdc 100644
--- a/share/www/dialog/_login.html
+++ b/rel/overlay/share/www/dialog/_login.html
diff --git a/share/www/dialog/_save_view_as.html b/rel/overlay/share/www/dialog/_save_view_as.html
index d59122bf..d59122bf 100644
--- a/share/www/dialog/_save_view_as.html
+++ b/rel/overlay/share/www/dialog/_save_view_as.html
diff --git a/share/www/dialog/_share_test_reports.html b/rel/overlay/share/www/dialog/_share_test_reports.html
index 82b49a74..82b49a74 100644
--- a/share/www/dialog/_share_test_reports.html
+++ b/rel/overlay/share/www/dialog/_share_test_reports.html
diff --git a/share/www/dialog/_signup.html b/rel/overlay/share/www/dialog/_signup.html
index 7ba3448a..7ba3448a 100644
--- a/share/www/dialog/_signup.html
+++ b/rel/overlay/share/www/dialog/_signup.html
diff --git a/share/www/dialog/_upload_attachment.html b/rel/overlay/share/www/dialog/_upload_attachment.html
index 50b7e1fa..50b7e1fa 100644
--- a/share/www/dialog/_upload_attachment.html
+++ b/rel/overlay/share/www/dialog/_upload_attachment.html
diff --git a/share/www/document.html b/rel/overlay/share/www/document.html
index b6f42018..b6f42018 100644
--- a/share/www/document.html
+++ b/rel/overlay/share/www/document.html
diff --git a/share/www/favicon.ico b/rel/overlay/share/www/favicon.ico
index 34bfaa86..34bfaa86 100644
--- a/share/www/favicon.ico
+++ b/rel/overlay/share/www/favicon.ico
Binary files differ
diff --git a/share/www/image/add.png b/rel/overlay/share/www/image/add.png
index 34e8c7d7..34e8c7d7 100644
--- a/share/www/image/add.png
+++ b/rel/overlay/share/www/image/add.png
Binary files differ
diff --git a/share/www/image/apply.gif b/rel/overlay/share/www/image/apply.gif
index 63de0d53..63de0d53 100644
--- a/share/www/image/apply.gif
+++ b/rel/overlay/share/www/image/apply.gif
Binary files differ
diff --git a/share/www/image/bg.png b/rel/overlay/share/www/image/bg.png
index ec815244..ec815244 100644
--- a/share/www/image/bg.png
+++ b/rel/overlay/share/www/image/bg.png
Binary files differ
diff --git a/share/www/image/cancel.gif b/rel/overlay/share/www/image/cancel.gif
index 4329076e..4329076e 100644
--- a/share/www/image/cancel.gif
+++ b/rel/overlay/share/www/image/cancel.gif
Binary files differ
diff --git a/share/www/image/compact.png b/rel/overlay/share/www/image/compact.png
index ea8985dc..ea8985dc 100644
--- a/share/www/image/compact.png
+++ b/rel/overlay/share/www/image/compact.png
Binary files differ
diff --git a/share/www/image/delete-mini.png b/rel/overlay/share/www/image/delete-mini.png
index ad5588d9..ad5588d9 100644
--- a/share/www/image/delete-mini.png
+++ b/rel/overlay/share/www/image/delete-mini.png
Binary files differ
diff --git a/share/www/image/delete.png b/rel/overlay/share/www/image/delete.png
index e8384017..e8384017 100644
--- a/share/www/image/delete.png
+++ b/rel/overlay/share/www/image/delete.png
Binary files differ
diff --git a/share/www/image/grippie.gif b/rel/overlay/share/www/image/grippie.gif
index a8807896..a8807896 100644
--- a/share/www/image/grippie.gif
+++ b/rel/overlay/share/www/image/grippie.gif
Binary files differ
diff --git a/share/www/image/hgrad.gif b/rel/overlay/share/www/image/hgrad.gif
index 08aa80ca..08aa80ca 100644
--- a/share/www/image/hgrad.gif
+++ b/rel/overlay/share/www/image/hgrad.gif
Binary files differ
diff --git a/share/www/image/key.png b/rel/overlay/share/www/image/key.png
index e04ed108..e04ed108 100644
--- a/share/www/image/key.png
+++ b/rel/overlay/share/www/image/key.png
Binary files differ
diff --git a/share/www/image/load.png b/rel/overlay/share/www/image/load.png
index 07b4f791..07b4f791 100644
--- a/share/www/image/load.png
+++ b/rel/overlay/share/www/image/load.png
Binary files differ
diff --git a/share/www/image/logo.png b/rel/overlay/share/www/image/logo.png
index d21ac025..d21ac025 100644
--- a/share/www/image/logo.png
+++ b/rel/overlay/share/www/image/logo.png
Binary files differ
diff --git a/share/www/image/order-asc.gif b/rel/overlay/share/www/image/order-asc.gif
index d2a237ae..d2a237ae 100644
--- a/share/www/image/order-asc.gif
+++ b/rel/overlay/share/www/image/order-asc.gif
Binary files differ
diff --git a/share/www/image/order-desc.gif b/rel/overlay/share/www/image/order-desc.gif
index 1043b499..1043b499 100644
--- a/share/www/image/order-desc.gif
+++ b/rel/overlay/share/www/image/order-desc.gif
Binary files differ
diff --git a/share/www/image/path.gif b/rel/overlay/share/www/image/path.gif
index 01ec717e..01ec717e 100644
--- a/share/www/image/path.gif
+++ b/rel/overlay/share/www/image/path.gif
Binary files differ
diff --git a/share/www/image/progress.gif b/rel/overlay/share/www/image/progress.gif
index d84f6537..d84f6537 100644
--- a/share/www/image/progress.gif
+++ b/rel/overlay/share/www/image/progress.gif
Binary files differ
diff --git a/share/www/image/rarrow.png b/rel/overlay/share/www/image/rarrow.png
index 507e87e7..507e87e7 100644
--- a/share/www/image/rarrow.png
+++ b/rel/overlay/share/www/image/rarrow.png
Binary files differ
diff --git a/share/www/image/run-mini.png b/rel/overlay/share/www/image/run-mini.png
index b2fcbd82..b2fcbd82 100644
--- a/share/www/image/run-mini.png
+++ b/rel/overlay/share/www/image/run-mini.png
Binary files differ
diff --git a/share/www/image/run.png b/rel/overlay/share/www/image/run.png
index a1d79f65..a1d79f65 100644
--- a/share/www/image/run.png
+++ b/rel/overlay/share/www/image/run.png
Binary files differ
diff --git a/share/www/image/running.png b/rel/overlay/share/www/image/running.png
index 9b50cd67..9b50cd67 100644
--- a/share/www/image/running.png
+++ b/rel/overlay/share/www/image/running.png
Binary files differ
diff --git a/share/www/image/save.png b/rel/overlay/share/www/image/save.png
index a04e4bcc..a04e4bcc 100644
--- a/share/www/image/save.png
+++ b/rel/overlay/share/www/image/save.png
Binary files differ
diff --git a/share/www/image/sidebar-toggle.png b/rel/overlay/share/www/image/sidebar-toggle.png
index 3ea32ffe..3ea32ffe 100644
--- a/share/www/image/sidebar-toggle.png
+++ b/rel/overlay/share/www/image/sidebar-toggle.png
Binary files differ
diff --git a/share/www/image/spinner.gif b/rel/overlay/share/www/image/spinner.gif
index 6239655e..6239655e 100644
--- a/share/www/image/spinner.gif
+++ b/rel/overlay/share/www/image/spinner.gif
Binary files differ
diff --git a/share/www/image/test_failure.gif b/rel/overlay/share/www/image/test_failure.gif
index 2a873b24..2a873b24 100644
--- a/share/www/image/test_failure.gif
+++ b/rel/overlay/share/www/image/test_failure.gif
Binary files differ
diff --git a/share/www/image/test_success.gif b/rel/overlay/share/www/image/test_success.gif
index 6df8bae2..6df8bae2 100644
--- a/share/www/image/test_success.gif
+++ b/rel/overlay/share/www/image/test_success.gif
Binary files differ
diff --git a/share/www/image/thead-key.gif b/rel/overlay/share/www/image/thead-key.gif
index 42a43b58..42a43b58 100644
--- a/share/www/image/thead-key.gif
+++ b/rel/overlay/share/www/image/thead-key.gif
Binary files differ
diff --git a/share/www/image/thead.gif b/rel/overlay/share/www/image/thead.gif
index 1587b1f2..1587b1f2 100644
--- a/share/www/image/thead.gif
+++ b/rel/overlay/share/www/image/thead.gif
Binary files differ
diff --git a/share/www/image/toggle-collapse.gif b/rel/overlay/share/www/image/toggle-collapse.gif
index f0979304..f0979304 100644
--- a/share/www/image/toggle-collapse.gif
+++ b/rel/overlay/share/www/image/toggle-collapse.gif
Binary files differ
diff --git a/share/www/image/toggle-expand.gif b/rel/overlay/share/www/image/toggle-expand.gif
index 03fa8360..03fa8360 100644
--- a/share/www/image/toggle-expand.gif
+++ b/rel/overlay/share/www/image/toggle-expand.gif
Binary files differ
diff --git a/share/www/image/twisty.gif b/rel/overlay/share/www/image/twisty.gif
index 5ba57a1a..5ba57a1a 100644
--- a/share/www/image/twisty.gif
+++ b/rel/overlay/share/www/image/twisty.gif
Binary files differ
diff --git a/share/www/index.html b/rel/overlay/share/www/index.html
index 975f5986..975f5986 100644
--- a/share/www/index.html
+++ b/rel/overlay/share/www/index.html
diff --git a/share/www/replicator.html b/rel/overlay/share/www/replicator.html
index 16c0940b..dced6f9c 100644
--- a/share/www/replicator.html
+++ b/rel/overlay/share/www/replicator.html
@@ -44,21 +44,21 @@ specific language governing permissions and limitations under the License.
});
var getDatabases = function() {
- $.couch.allDbs({
- success: function(dbs) {
+ $.couch.allDbs({
+ success: function(dbs) {
allDatabases = dbs.sort();
- $("fieldset select").each(function() {
- var select = this;
- $.each(dbs, function(idx, dbName) {
- $("<option></option>").text(dbName).appendTo(select);
- });
- select.selectedIndex = 0;
+ $("fieldset select").each(function() {
+ var select = this;
+ $.each(dbs, function(idx, dbName) {
+ $("<option></option>").text(dbName).appendTo(select);
});
+ select.selectedIndex = 0;
+ });
$('#to_name').autocomplete({ source: dbs });
- }
- });
+ }
+ });
};
getDatabases();
diff --git a/share/www/script/base64.js b/rel/overlay/share/www/script/base64.js
index e0aab303..e0aab303 100644
--- a/share/www/script/base64.js
+++ b/rel/overlay/share/www/script/base64.js
diff --git a/share/www/script/couch.js b/rel/overlay/share/www/script/couch.js
index bcc19652..6a997cff 100644
--- a/share/www/script/couch.js
+++ b/rel/overlay/share/www/script/couch.js
@@ -318,7 +318,7 @@ CouchDB.login = function(name, password) {
+ encodeURIComponent(password)
});
return JSON.parse(CouchDB.last_req.responseText);
-}
+};
CouchDB.logout = function() {
CouchDB.last_req = CouchDB.request("DELETE", "/_session", {
@@ -460,7 +460,7 @@ CouchDB.maybeThrowError = function(req) {
}
throw result;
}
-}
+};
CouchDB.params = function(options) {
options = options || {};
diff --git a/share/www/script/couch_test_runner.js b/rel/overlay/share/www/script/couch_test_runner.js
index 55a6533f..55a6533f 100644
--- a/share/www/script/couch_test_runner.js
+++ b/rel/overlay/share/www/script/couch_test_runner.js
diff --git a/share/www/script/couch_tests.js b/rel/overlay/share/www/script/couch_tests.js
index eb573526..eb573526 100644
--- a/share/www/script/couch_tests.js
+++ b/rel/overlay/share/www/script/couch_tests.js
diff --git a/share/www/script/futon.browse.js b/rel/overlay/share/www/script/futon.browse.js
index 56435ae4..b981feec 100644
--- a/share/www/script/futon.browse.js
+++ b/rel/overlay/share/www/script/futon.browse.js
@@ -61,7 +61,7 @@
$("#databases tbody.content tr:eq(" + idx + ")")
.find("td.size").text($.futon.formatSize(info.disk_size)).end()
.find("td.count").text(info.doc_count).end()
- .find("td.seq").text(info.update_seq);
+ .find("td.seq").text(info.update_seq.split("-")[0]);
},
error : function() {}
});
diff --git a/share/www/script/futon.format.js b/rel/overlay/share/www/script/futon.format.js
index 0eb9b104..0eb9b104 100644
--- a/share/www/script/futon.format.js
+++ b/rel/overlay/share/www/script/futon.format.js
diff --git a/share/www/script/futon.js b/rel/overlay/share/www/script/futon.js
index fb73e3c9..fb73e3c9 100644
--- a/share/www/script/futon.js
+++ b/rel/overlay/share/www/script/futon.js
diff --git a/share/www/script/jquery.couch.js b/rel/overlay/share/www/script/jquery.couch.js
index 9bc1363b..634a03fe 100644
--- a/share/www/script/jquery.couch.js
+++ b/rel/overlay/share/www/script/jquery.couch.js
@@ -56,7 +56,7 @@
req.type = "PUT";
req.data = toJSON(value);
req.contentType = "application/json";
- req.processData = false
+ req.processData = false;
}
ajax(req, options,
diff --git a/share/www/script/jquery.dialog.js b/rel/overlay/share/www/script/jquery.dialog.js
index 02c0c497..02c0c497 100644
--- a/share/www/script/jquery.dialog.js
+++ b/rel/overlay/share/www/script/jquery.dialog.js
diff --git a/share/www/script/jquery.editinline.js b/rel/overlay/share/www/script/jquery.editinline.js
index b48607d4..b48607d4 100644
--- a/share/www/script/jquery.editinline.js
+++ b/rel/overlay/share/www/script/jquery.editinline.js
diff --git a/share/www/script/jquery.form.js b/rel/overlay/share/www/script/jquery.form.js
index dde39427..dde39427 100644
--- a/share/www/script/jquery.form.js
+++ b/rel/overlay/share/www/script/jquery.form.js
diff --git a/share/www/script/jquery.js b/rel/overlay/share/www/script/jquery.js
index fff67764..fff67764 100644
--- a/share/www/script/jquery.js
+++ b/rel/overlay/share/www/script/jquery.js
diff --git a/share/www/script/jquery.resizer.js b/rel/overlay/share/www/script/jquery.resizer.js
index 42f0cc77..42f0cc77 100644
--- a/share/www/script/jquery.resizer.js
+++ b/rel/overlay/share/www/script/jquery.resizer.js
diff --git a/share/www/script/jquery.suggest.js b/rel/overlay/share/www/script/jquery.suggest.js
index fd94375a..fd94375a 100644
--- a/share/www/script/jquery.suggest.js
+++ b/rel/overlay/share/www/script/jquery.suggest.js
diff --git a/share/www/script/json2.js b/rel/overlay/share/www/script/json2.js
index a1a3b170..a1a3b170 100644
--- a/share/www/script/json2.js
+++ b/rel/overlay/share/www/script/json2.js
diff --git a/share/www/script/jspec/jspec.css b/rel/overlay/share/www/script/jspec/jspec.css
index 629d41c5..629d41c5 100644
--- a/share/www/script/jspec/jspec.css
+++ b/rel/overlay/share/www/script/jspec/jspec.css
diff --git a/share/www/script/jspec/jspec.jquery.js b/rel/overlay/share/www/script/jspec/jspec.jquery.js
index fcad7ab9..fcad7ab9 100644
--- a/share/www/script/jspec/jspec.jquery.js
+++ b/rel/overlay/share/www/script/jspec/jspec.jquery.js
diff --git a/share/www/script/jspec/jspec.js b/rel/overlay/share/www/script/jspec/jspec.js
index b2ea4768..b2ea4768 100644
--- a/share/www/script/jspec/jspec.js
+++ b/rel/overlay/share/www/script/jspec/jspec.js
diff --git a/share/www/script/jspec/jspec.xhr.js b/rel/overlay/share/www/script/jspec/jspec.xhr.js
index 61648795..61648795 100644
--- a/share/www/script/jspec/jspec.xhr.js
+++ b/rel/overlay/share/www/script/jspec/jspec.xhr.js
diff --git a/share/www/script/oauth.js b/rel/overlay/share/www/script/oauth.js
index ada00a27..ada00a27 100644
--- a/share/www/script/oauth.js
+++ b/rel/overlay/share/www/script/oauth.js
diff --git a/share/www/script/sha1.js b/rel/overlay/share/www/script/sha1.js
index ee73a634..ee73a634 100644
--- a/share/www/script/sha1.js
+++ b/rel/overlay/share/www/script/sha1.js
diff --git a/share/www/script/test/all_docs.js b/rel/overlay/share/www/script/test/all_docs.js
index 1d83aa95..1d83aa95 100644
--- a/share/www/script/test/all_docs.js
+++ b/rel/overlay/share/www/script/test/all_docs.js
diff --git a/share/www/script/test/attachment_conflicts.js b/rel/overlay/share/www/script/test/attachment_conflicts.js
index c400277e..c400277e 100644
--- a/share/www/script/test/attachment_conflicts.js
+++ b/rel/overlay/share/www/script/test/attachment_conflicts.js
diff --git a/share/www/script/test/attachment_names.js b/rel/overlay/share/www/script/test/attachment_names.js
index 777b5ece..777b5ece 100644
--- a/share/www/script/test/attachment_names.js
+++ b/rel/overlay/share/www/script/test/attachment_names.js
diff --git a/share/www/script/test/attachment_paths.js b/rel/overlay/share/www/script/test/attachment_paths.js
index 3f6ffb7c..3f6ffb7c 100644
--- a/share/www/script/test/attachment_paths.js
+++ b/rel/overlay/share/www/script/test/attachment_paths.js
diff --git a/share/www/script/test/attachment_views.js b/rel/overlay/share/www/script/test/attachment_views.js
index a92a8ad0..a92a8ad0 100644
--- a/share/www/script/test/attachment_views.js
+++ b/rel/overlay/share/www/script/test/attachment_views.js
diff --git a/share/www/script/test/attachments.js b/rel/overlay/share/www/script/test/attachments.js
index b0cfd2c5..826373dc 100644
--- a/share/www/script/test/attachments.js
+++ b/rel/overlay/share/www/script/test/attachments.js
@@ -43,7 +43,7 @@ couchTests.attachments= function(debug) {
data: ""
}
}
- }
+ };
T(db.save(binAttDoc2).ok);
diff --git a/share/www/script/test/attachments_multipart.js b/rel/overlay/share/www/script/test/attachments_multipart.js
index 4f4590fc..2fc8e3bd 100644
--- a/share/www/script/test/attachments_multipart.js
+++ b/rel/overlay/share/www/script/test/attachments_multipart.js
@@ -39,7 +39,7 @@ couchTests.attachments_multipart= function(debug) {
},
"baz.txt": {
"follows":true,
- "content_type":"text/plain",
+ "content_type":"application/test",
"length":19
}
}
@@ -121,7 +121,7 @@ couchTests.attachments_multipart= function(debug) {
function getBoundary(xhr) {
if (xhr instanceof XMLHttpRequest) {
- var ctype = xhr.getResponseHeader("Content-Type");
+ var ctype = xhr.getResponseHeader("Content-Type");
} else {
var ctype = xhr.headers['Content-Type'];
}
@@ -143,7 +143,7 @@ couchTests.attachments_multipart= function(debug) {
function parseMultipart(xhr) {
var boundary = getBoundary(xhr);
if (xhr instanceof XMLHttpRequest) {
- var mimetext = xhr.responseText;
+ var mimetext = xhr.responseText;
} else {
var mimetext = xhr.body;
}
@@ -219,7 +219,7 @@ couchTests.attachments_multipart= function(debug) {
T(doc._attachments['bar.txt'].follows == true);
T(sections[1].body == "this is 18 chars l");
-
+
// try the atts_since parameter together with the open_revs parameter
xhr = CouchDB.request(
"GET",
@@ -283,7 +283,7 @@ couchTests.attachments_multipart= function(debug) {
T(doc._attachments['bar.txt'].follows == true);
T(sections[1].body == "this is 18 chars l");
-
+
// check that with the document multipart/mixed API it's possible to receive
// attachments in compressed form (if they're stored in compressed form)
diff --git a/share/www/script/test/auth_cache.js b/rel/overlay/share/www/script/test/auth_cache.js
index e48f7370..e48f7370 100644
--- a/share/www/script/test/auth_cache.js
+++ b/rel/overlay/share/www/script/test/auth_cache.js
diff --git a/share/www/script/test/basics.js b/rel/overlay/share/www/script/test/basics.js
index 30c27c11..30c27c11 100644
--- a/share/www/script/test/basics.js
+++ b/rel/overlay/share/www/script/test/basics.js
diff --git a/share/www/script/test/batch_save.js b/rel/overlay/share/www/script/test/batch_save.js
index a1b00192..a1b00192 100644
--- a/share/www/script/test/batch_save.js
+++ b/rel/overlay/share/www/script/test/batch_save.js
diff --git a/share/www/script/test/bulk_docs.js b/rel/overlay/share/www/script/test/bulk_docs.js
index 9095e6b3..9095e6b3 100644
--- a/share/www/script/test/bulk_docs.js
+++ b/rel/overlay/share/www/script/test/bulk_docs.js
diff --git a/share/www/script/test/changes.js b/rel/overlay/share/www/script/test/changes.js
index ea22bfb3..ea22bfb3 100644
--- a/share/www/script/test/changes.js
+++ b/rel/overlay/share/www/script/test/changes.js
diff --git a/share/www/script/test/compact.js b/rel/overlay/share/www/script/test/compact.js
index 805a3b08..805a3b08 100644
--- a/share/www/script/test/compact.js
+++ b/rel/overlay/share/www/script/test/compact.js
diff --git a/share/www/script/test/config.js b/rel/overlay/share/www/script/test/config.js
index e83ecfd9..e83ecfd9 100644
--- a/share/www/script/test/config.js
+++ b/rel/overlay/share/www/script/test/config.js
diff --git a/share/www/script/test/conflicts.js b/rel/overlay/share/www/script/test/conflicts.js
index 65122581..65122581 100644
--- a/share/www/script/test/conflicts.js
+++ b/rel/overlay/share/www/script/test/conflicts.js
diff --git a/share/www/script/test/content_negotiation.js b/rel/overlay/share/www/script/test/content_negotiation.js
index c79df948..c79df948 100644
--- a/share/www/script/test/content_negotiation.js
+++ b/rel/overlay/share/www/script/test/content_negotiation.js
diff --git a/share/www/script/test/cookie_auth.js b/rel/overlay/share/www/script/test/cookie_auth.js
index 8ad993cc..e3548640 100644
--- a/share/www/script/test/cookie_auth.js
+++ b/rel/overlay/share/www/script/test/cookie_auth.js
@@ -137,7 +137,7 @@ couchTests.cookie_auth = function(debug) {
T(CouchDB.session().userCtx.name != 'Jason Davies');
// test redirect
- xhr = CouchDB.request("POST", "/_session?next=/", {
+ var xhr = CouchDB.request("POST", "/_session?next=/", {
headers: {"Content-Type": "application/x-www-form-urlencoded"},
body: "name=Jason%20Davies&password="+encodeURIComponent(password)
});
diff --git a/share/www/script/test/copy_doc.js b/rel/overlay/share/www/script/test/copy_doc.js
index 99e3c7fe..99e3c7fe 100644
--- a/share/www/script/test/copy_doc.js
+++ b/rel/overlay/share/www/script/test/copy_doc.js
diff --git a/share/www/script/test/delayed_commits.js b/rel/overlay/share/www/script/test/delayed_commits.js
index dbb072fb..dbb072fb 100644
--- a/share/www/script/test/delayed_commits.js
+++ b/rel/overlay/share/www/script/test/delayed_commits.js
diff --git a/share/www/script/test/design_docs.js b/rel/overlay/share/www/script/test/design_docs.js
index 702f0441..702f0441 100644
--- a/share/www/script/test/design_docs.js
+++ b/rel/overlay/share/www/script/test/design_docs.js
diff --git a/share/www/script/test/design_options.js b/rel/overlay/share/www/script/test/design_options.js
index 05764e24..05764e24 100644
--- a/share/www/script/test/design_options.js
+++ b/rel/overlay/share/www/script/test/design_options.js
diff --git a/share/www/script/test/design_paths.js b/rel/overlay/share/www/script/test/design_paths.js
index 426a252c..426a252c 100644
--- a/share/www/script/test/design_paths.js
+++ b/rel/overlay/share/www/script/test/design_paths.js
diff --git a/share/www/script/test/erlang_views.js b/rel/overlay/share/www/script/test/erlang_views.js
index 7eddab40..7eddab40 100644
--- a/share/www/script/test/erlang_views.js
+++ b/rel/overlay/share/www/script/test/erlang_views.js
diff --git a/share/www/script/test/etags_head.js b/rel/overlay/share/www/script/test/etags_head.js
index 63e29994..63e29994 100644
--- a/share/www/script/test/etags_head.js
+++ b/rel/overlay/share/www/script/test/etags_head.js
diff --git a/share/www/script/test/etags_views.js b/rel/overlay/share/www/script/test/etags_views.js
index f556d6ac..34116f71 100644
--- a/share/www/script/test/etags_views.js
+++ b/rel/overlay/share/www/script/test/etags_views.js
@@ -30,14 +30,14 @@ couchTests.etags_views = function(debug) {
basicView : {
map : stringFun(function(doc) {
if(doc.integer && doc.string) {
- emit(doc.integer, doc.string);
+ emit(doc.integer, doc.string);
}
})
},
withReduce : {
map : stringFun(function(doc) {
if(doc.integer && doc.string) {
- emit(doc.integer, doc.string);
+ emit(doc.integer, doc.string);
}
}),
reduce : stringFun(function(keys, values, rereduce) {
diff --git a/share/www/script/test/form_submit.js b/rel/overlay/share/www/script/test/form_submit.js
index 39833d1a..39833d1a 100644
--- a/share/www/script/test/form_submit.js
+++ b/rel/overlay/share/www/script/test/form_submit.js
diff --git a/share/www/script/test/http.js b/rel/overlay/share/www/script/test/http.js
index 5f46af52..5f46af52 100644
--- a/share/www/script/test/http.js
+++ b/rel/overlay/share/www/script/test/http.js
diff --git a/share/www/script/test/invalid_docids.js b/rel/overlay/share/www/script/test/invalid_docids.js
index d0195b02..d0195b02 100644
--- a/share/www/script/test/invalid_docids.js
+++ b/rel/overlay/share/www/script/test/invalid_docids.js
diff --git a/share/www/script/test/jsonp.js b/rel/overlay/share/www/script/test/jsonp.js
index 9aba7189..9aba7189 100644
--- a/share/www/script/test/jsonp.js
+++ b/rel/overlay/share/www/script/test/jsonp.js
diff --git a/share/www/script/test/large_docs.js b/rel/overlay/share/www/script/test/large_docs.js
index b84648b7..b84648b7 100644
--- a/share/www/script/test/large_docs.js
+++ b/rel/overlay/share/www/script/test/large_docs.js
diff --git a/share/www/script/test/list_views.js b/rel/overlay/share/www/script/test/list_views.js
index 2c1ac321..2c1ac321 100644
--- a/share/www/script/test/list_views.js
+++ b/rel/overlay/share/www/script/test/list_views.js
diff --git a/share/www/script/test/lorem.txt b/rel/overlay/share/www/script/test/lorem.txt
index 0ef85bab..0ef85bab 100644
--- a/share/www/script/test/lorem.txt
+++ b/rel/overlay/share/www/script/test/lorem.txt
diff --git a/share/www/script/test/lorem_b64.txt b/rel/overlay/share/www/script/test/lorem_b64.txt
index 8a21d79e..8a21d79e 100644
--- a/share/www/script/test/lorem_b64.txt
+++ b/rel/overlay/share/www/script/test/lorem_b64.txt
diff --git a/share/www/script/test/lots_of_docs.js b/rel/overlay/share/www/script/test/lots_of_docs.js
index 2fe702b1..2fe702b1 100644
--- a/share/www/script/test/lots_of_docs.js
+++ b/rel/overlay/share/www/script/test/lots_of_docs.js
diff --git a/share/www/script/test/method_override.js b/rel/overlay/share/www/script/test/method_override.js
index 0bb4c61f..0bb4c61f 100644
--- a/share/www/script/test/method_override.js
+++ b/rel/overlay/share/www/script/test/method_override.js
diff --git a/share/www/script/test/multiple_rows.js b/rel/overlay/share/www/script/test/multiple_rows.js
index 4f6fcd3b..4f6fcd3b 100644
--- a/share/www/script/test/multiple_rows.js
+++ b/rel/overlay/share/www/script/test/multiple_rows.js
diff --git a/share/www/script/test/oauth.js b/rel/overlay/share/www/script/test/oauth.js
index 82ebe8a4..82ebe8a4 100644
--- a/share/www/script/test/oauth.js
+++ b/rel/overlay/share/www/script/test/oauth.js
diff --git a/share/www/script/test/proxyauth.js b/rel/overlay/share/www/script/test/proxyauth.js
index 40af0089..dff39415 100644
--- a/share/www/script/test/proxyauth.js
+++ b/rel/overlay/share/www/script/test/proxyauth.js
@@ -127,4 +127,4 @@ couchTests.proxyauth = function(debug) {
TestFun
);
-}; \ No newline at end of file
+};
diff --git a/share/www/script/test/purge.js b/rel/overlay/share/www/script/test/purge.js
index 29689137..29689137 100644
--- a/share/www/script/test/purge.js
+++ b/rel/overlay/share/www/script/test/purge.js
diff --git a/share/www/script/test/reader_acl.js b/rel/overlay/share/www/script/test/reader_acl.js
index cc249ea4..cc249ea4 100644
--- a/share/www/script/test/reader_acl.js
+++ b/rel/overlay/share/www/script/test/reader_acl.js
diff --git a/share/www/script/test/recreate_doc.js b/rel/overlay/share/www/script/test/recreate_doc.js
index 05843558..05843558 100644
--- a/share/www/script/test/recreate_doc.js
+++ b/rel/overlay/share/www/script/test/recreate_doc.js
diff --git a/share/www/script/test/reduce.js b/rel/overlay/share/www/script/test/reduce.js
index 16c7a7bf..16c7a7bf 100644
--- a/share/www/script/test/reduce.js
+++ b/rel/overlay/share/www/script/test/reduce.js
diff --git a/share/www/script/test/reduce_builtin.js b/rel/overlay/share/www/script/test/reduce_builtin.js
index b3cc3cc7..b3cc3cc7 100644
--- a/share/www/script/test/reduce_builtin.js
+++ b/rel/overlay/share/www/script/test/reduce_builtin.js
diff --git a/share/www/script/test/reduce_false.js b/rel/overlay/share/www/script/test/reduce_false.js
index 699b258f..699b258f 100644
--- a/share/www/script/test/reduce_false.js
+++ b/rel/overlay/share/www/script/test/reduce_false.js
diff --git a/share/www/script/test/reduce_false_temp.js b/rel/overlay/share/www/script/test/reduce_false_temp.js
index d45f05b2..d45f05b2 100644
--- a/share/www/script/test/reduce_false_temp.js
+++ b/rel/overlay/share/www/script/test/reduce_false_temp.js
diff --git a/share/www/script/test/replication.js b/rel/overlay/share/www/script/test/replication.js
index 25746625..25746625 100644
--- a/share/www/script/test/replication.js
+++ b/rel/overlay/share/www/script/test/replication.js
diff --git a/share/www/script/test/rev_stemming.js b/rel/overlay/share/www/script/test/rev_stemming.js
index 03d91c2a..03d91c2a 100644
--- a/share/www/script/test/rev_stemming.js
+++ b/rel/overlay/share/www/script/test/rev_stemming.js
diff --git a/share/www/script/test/rewrite.js b/rel/overlay/share/www/script/test/rewrite.js
index bb188773..ac5257da 100644
--- a/share/www/script/test/rewrite.js
+++ b/rel/overlay/share/www/script/test/rewrite.js
@@ -329,7 +329,7 @@ couchTests.rewrite = function(debug) {
xhr = CouchDB.request("GET", "/test_suite_db/_design/test/_rewrite/welcome3/test");
T(xhr.responseText == "Welcome test");
-
+
req = CouchDB.request("GET", "/test_suite_db/_design/test/_rewrite/welcome4/user");
T(req.responseText == "Welcome user");
@@ -364,14 +364,14 @@ couchTests.rewrite = function(debug) {
T(!(/Key: 1/.test(xhr.responseText)));
T(/FirstKey: 3/.test(xhr.responseText));
T(/LastKey: 8/.test(xhr.responseText));
-
+
// get with query params
xhr = CouchDB.request("GET", "/test_suite_db/_design/test/_rewrite/simpleForm/basicViewPath/3/8");
T(xhr.status == 200, "with query params");
T(!(/Key: 1/.test(xhr.responseText)));
T(/FirstKey: 3/.test(xhr.responseText));
T(/LastKey: 8/.test(xhr.responseText));
-
+
// get with query params
xhr = CouchDB.request("GET", "/test_suite_db/_design/test/_rewrite/simpleForm/complexView");
T(xhr.status == 200, "with query params");
@@ -396,7 +396,7 @@ couchTests.rewrite = function(debug) {
xhr = CouchDB.request("GET", "/test_suite_db/_design/test/_rewrite/simpleForm/complexView6?a=test&b=essai");
T(xhr.status == 200, "with query params");
T(/Value: doc 4/.test(xhr.responseText));
-
+
xhr = CouchDB.request("GET", "/test_suite_db/_design/test/_rewrite/simpleForm/complexView7/test/essai?doc=true");
T(xhr.status == 200, "with query params");
var result = JSON.parse(xhr.responseText);
@@ -425,7 +425,16 @@ couchTests.rewrite = function(debug) {
T(result.uuids.length == 1);
var first = result.uuids[0];
});
-
});
-
+
+ // test invalid rewrites
+ // string
+ var ddoc = {
+ _id: "_design/invalid",
+ rewrites: "[{\"from\":\"foo\",\"to\":\"bar\"}]"
+ }
+ db.save(ddoc);
+ var res = CouchDB.request("GET", "/test_suite_db/_design/invalid/_rewrite/foo");
+ TEquals(400, res.status, "should return 400");
+
}
diff --git a/share/www/script/test/security_validation.js b/rel/overlay/share/www/script/test/security_validation.js
index 42aa11c9..42aa11c9 100644
--- a/share/www/script/test/security_validation.js
+++ b/rel/overlay/share/www/script/test/security_validation.js
diff --git a/share/www/script/test/show_documents.js b/rel/overlay/share/www/script/test/show_documents.js
index 55ed9698..55ed9698 100644
--- a/share/www/script/test/show_documents.js
+++ b/rel/overlay/share/www/script/test/show_documents.js
diff --git a/share/www/script/test/stats.js b/rel/overlay/share/www/script/test/stats.js
index 6fb0fbba..6fb0fbba 100644
--- a/share/www/script/test/stats.js
+++ b/rel/overlay/share/www/script/test/stats.js
diff --git a/share/www/script/test/update_documents.js b/rel/overlay/share/www/script/test/update_documents.js
index 49d3b68a..49d3b68a 100644
--- a/share/www/script/test/update_documents.js
+++ b/rel/overlay/share/www/script/test/update_documents.js
diff --git a/share/www/script/test/users_db.js b/rel/overlay/share/www/script/test/users_db.js
index 1e13e5d7..1e13e5d7 100644
--- a/share/www/script/test/users_db.js
+++ b/rel/overlay/share/www/script/test/users_db.js
diff --git a/share/www/script/test/utf8.js b/rel/overlay/share/www/script/test/utf8.js
index b77845d3..b77845d3 100644
--- a/share/www/script/test/utf8.js
+++ b/rel/overlay/share/www/script/test/utf8.js
diff --git a/share/www/script/test/uuids.js b/rel/overlay/share/www/script/test/uuids.js
index fc33a105..fc33a105 100644
--- a/share/www/script/test/uuids.js
+++ b/rel/overlay/share/www/script/test/uuids.js
diff --git a/share/www/script/test/view_collation.js b/rel/overlay/share/www/script/test/view_collation.js
index b01a5c50..b01a5c50 100644
--- a/share/www/script/test/view_collation.js
+++ b/rel/overlay/share/www/script/test/view_collation.js
diff --git a/share/www/script/test/view_collation_raw.js b/rel/overlay/share/www/script/test/view_collation_raw.js
index 31624cdb..31624cdb 100644
--- a/share/www/script/test/view_collation_raw.js
+++ b/rel/overlay/share/www/script/test/view_collation_raw.js
diff --git a/share/www/script/test/view_compaction.js b/rel/overlay/share/www/script/test/view_compaction.js
index a11fb7bd..a11fb7bd 100644
--- a/share/www/script/test/view_compaction.js
+++ b/rel/overlay/share/www/script/test/view_compaction.js
diff --git a/share/www/script/test/view_conflicts.js b/rel/overlay/share/www/script/test/view_conflicts.js
index 96f97d56..96f97d56 100644
--- a/share/www/script/test/view_conflicts.js
+++ b/rel/overlay/share/www/script/test/view_conflicts.js
diff --git a/share/www/script/test/view_errors.js b/rel/overlay/share/www/script/test/view_errors.js
index e8bd08e4..e8bd08e4 100644
--- a/share/www/script/test/view_errors.js
+++ b/rel/overlay/share/www/script/test/view_errors.js
diff --git a/share/www/script/test/view_include_docs.js b/rel/overlay/share/www/script/test/view_include_docs.js
index 944c9103..944c9103 100644
--- a/share/www/script/test/view_include_docs.js
+++ b/rel/overlay/share/www/script/test/view_include_docs.js
diff --git a/share/www/script/test/view_multi_key_all_docs.js b/rel/overlay/share/www/script/test/view_multi_key_all_docs.js
index 1113be4d..1113be4d 100644
--- a/share/www/script/test/view_multi_key_all_docs.js
+++ b/rel/overlay/share/www/script/test/view_multi_key_all_docs.js
diff --git a/share/www/script/test/view_multi_key_design.js b/rel/overlay/share/www/script/test/view_multi_key_design.js
index 38396955..38396955 100644
--- a/share/www/script/test/view_multi_key_design.js
+++ b/rel/overlay/share/www/script/test/view_multi_key_design.js
diff --git a/share/www/script/test/view_multi_key_temp.js b/rel/overlay/share/www/script/test/view_multi_key_temp.js
index 55eefda5..55eefda5 100644
--- a/share/www/script/test/view_multi_key_temp.js
+++ b/rel/overlay/share/www/script/test/view_multi_key_temp.js
diff --git a/share/www/script/test/view_offsets.js b/rel/overlay/share/www/script/test/view_offsets.js
index 464a1ae2..464a1ae2 100644
--- a/share/www/script/test/view_offsets.js
+++ b/rel/overlay/share/www/script/test/view_offsets.js
diff --git a/share/www/script/test/view_pagination.js b/rel/overlay/share/www/script/test/view_pagination.js
index ed3a7ee1..ed3a7ee1 100644
--- a/share/www/script/test/view_pagination.js
+++ b/rel/overlay/share/www/script/test/view_pagination.js
diff --git a/share/www/script/test/view_sandboxing.js b/rel/overlay/share/www/script/test/view_sandboxing.js
index 02951d9f..02951d9f 100644
--- a/share/www/script/test/view_sandboxing.js
+++ b/rel/overlay/share/www/script/test/view_sandboxing.js
diff --git a/share/www/script/test/view_update_seq.js b/rel/overlay/share/www/script/test/view_update_seq.js
index 69b8c42d..69b8c42d 100644
--- a/share/www/script/test/view_update_seq.js
+++ b/rel/overlay/share/www/script/test/view_update_seq.js
diff --git a/share/www/script/test/view_xml.js b/rel/overlay/share/www/script/test/view_xml.js
index 3403b47c..3403b47c 100644
--- a/share/www/script/test/view_xml.js
+++ b/rel/overlay/share/www/script/test/view_xml.js
diff --git a/share/www/session.html b/rel/overlay/share/www/session.html
index 0ebd943d..0ebd943d 100644
--- a/share/www/session.html
+++ b/rel/overlay/share/www/session.html
diff --git a/share/www/spec/couch_js_class_methods_spec.js b/rel/overlay/share/www/spec/couch_js_class_methods_spec.js
index 7eac2348..7eac2348 100644
--- a/share/www/spec/couch_js_class_methods_spec.js
+++ b/rel/overlay/share/www/spec/couch_js_class_methods_spec.js
diff --git a/share/www/spec/couch_js_instance_methods_1_spec.js b/rel/overlay/share/www/spec/couch_js_instance_methods_1_spec.js
index 7f23bd2c..7f23bd2c 100644
--- a/share/www/spec/couch_js_instance_methods_1_spec.js
+++ b/rel/overlay/share/www/spec/couch_js_instance_methods_1_spec.js
diff --git a/share/www/spec/couch_js_instance_methods_2_spec.js b/rel/overlay/share/www/spec/couch_js_instance_methods_2_spec.js
index 76df6368..76df6368 100644
--- a/share/www/spec/couch_js_instance_methods_2_spec.js
+++ b/rel/overlay/share/www/spec/couch_js_instance_methods_2_spec.js
diff --git a/share/www/spec/couch_js_instance_methods_3_spec.js b/rel/overlay/share/www/spec/couch_js_instance_methods_3_spec.js
index b7464c01..b7464c01 100644
--- a/share/www/spec/couch_js_instance_methods_3_spec.js
+++ b/rel/overlay/share/www/spec/couch_js_instance_methods_3_spec.js
diff --git a/share/www/spec/custom_helpers.js b/rel/overlay/share/www/spec/custom_helpers.js
index d29ee87b..d29ee87b 100644
--- a/share/www/spec/custom_helpers.js
+++ b/rel/overlay/share/www/spec/custom_helpers.js
diff --git a/share/www/spec/jquery_couch_js_class_methods_spec.js b/rel/overlay/share/www/spec/jquery_couch_js_class_methods_spec.js
index f2df81b3..f2df81b3 100644
--- a/share/www/spec/jquery_couch_js_class_methods_spec.js
+++ b/rel/overlay/share/www/spec/jquery_couch_js_class_methods_spec.js
diff --git a/share/www/spec/jquery_couch_js_instance_methods_1_spec.js b/rel/overlay/share/www/spec/jquery_couch_js_instance_methods_1_spec.js
index 8538c856..8538c856 100644
--- a/share/www/spec/jquery_couch_js_instance_methods_1_spec.js
+++ b/rel/overlay/share/www/spec/jquery_couch_js_instance_methods_1_spec.js
diff --git a/share/www/spec/jquery_couch_js_instance_methods_2_spec.js b/rel/overlay/share/www/spec/jquery_couch_js_instance_methods_2_spec.js
index 8f35affa..8f35affa 100644
--- a/share/www/spec/jquery_couch_js_instance_methods_2_spec.js
+++ b/rel/overlay/share/www/spec/jquery_couch_js_instance_methods_2_spec.js
diff --git a/share/www/spec/jquery_couch_js_instance_methods_3_spec.js b/rel/overlay/share/www/spec/jquery_couch_js_instance_methods_3_spec.js
index 5d27d817..5d27d817 100644
--- a/share/www/spec/jquery_couch_js_instance_methods_3_spec.js
+++ b/rel/overlay/share/www/spec/jquery_couch_js_instance_methods_3_spec.js
diff --git a/share/www/spec/run.html b/rel/overlay/share/www/spec/run.html
index e438333d..e438333d 100644
--- a/share/www/spec/run.html
+++ b/rel/overlay/share/www/spec/run.html
diff --git a/share/www/status.html b/rel/overlay/share/www/status.html
index 2067ab9b..2067ab9b 100644
--- a/share/www/status.html
+++ b/rel/overlay/share/www/status.html
diff --git a/share/www/style/layout.css b/rel/overlay/share/www/style/layout.css
index 25195e8a..331e0369 100644
--- a/share/www/style/layout.css
+++ b/rel/overlay/share/www/style/layout.css
@@ -615,4 +615,4 @@ form#replicator p.actions { padding: 1px; clear: left; margin: 0;
/* Session */
#loginSignup {
font-size:200%;
-}
+} \ No newline at end of file
diff --git a/rel/reltool.config b/rel/reltool.config
new file mode 100644
index 00000000..36c207eb
--- /dev/null
+++ b/rel/reltool.config
@@ -0,0 +1,61 @@
+% Copyright 2010 Cloudant
+%
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+{sys, [
+ {lib_dirs, ["../apps", "../deps"]},
+ {rel, "bigcouch", "0.4a", [
+ kernel,
+ stdlib,
+ sasl,
+ crypto,
+ ssl,
+ inets,
+ xmerl,
+ runtime_tools,
+ mochiweb,
+ ibrowse,
+ oauth,
+ couch,
+ rexi,
+ fabric,
+ mem3,
+ chttpd
+ ]},
+ {rel, "start_clean", "", [kernel, stdlib]},
+ {boot_rel, "bigcouch"},
+ {profile, embedded},
+ {excl_sys_filters, ["^bin/.*", "^erts.*/bin/(dialyzer|typer)"]},
+ {excl_archive_filters, [".*"]},
+
+ % It's sufficient to list 'chttpd' here, as reltool will pull in all
+ % dependencies. But we'll be explicit and list everything actively
+ % developed in this repository.
+ {app, rexi, [{incl_cond, include}]},
+ {app, fabric, [{incl_cond, include}]},
+ {app, mem3, [{incl_cond, include}]},
+ {app, couch, [{incl_cond, include}]},
+ {app, chttpd, [{incl_cond, include}]}
+]}.
+
+{overlay_vars, "bigcouch.config"}.
+{overlay, [
+ {mkdir, "var/log"},
+ {copy, "overlay/bin"},
+ {copy, "overlay/etc"},
+ {copy, "overlay/share"},
+ {copy, "../couchjs/build/couchjs", "bin/couchjs"},
+ {copy, "../couchjs/build/main.js", "share/couchjs/main.js"},
+ {template, "overlay/etc/default.ini", "etc/default.ini"},
+ {template, "overlay/etc/vm.args", "etc/vm.args"}
+]}.
diff --git a/rel/sv/README b/rel/sv/README
new file mode 100644
index 00000000..b5cc7404
--- /dev/null
+++ b/rel/sv/README
@@ -0,0 +1 @@
+This is an example of a BigCouch runit (http://smarden.org/runit/) service. Use it to start/stop/restart BigCouch. You may need to adjust the "run" script for install location and the home directory BigCouch will run as.
diff --git a/rel/sv/bigcouch/log/main/current b/rel/sv/bigcouch/log/main/current
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/rel/sv/bigcouch/log/main/current
diff --git a/rel/sv/bigcouch/log/run b/rel/sv/bigcouch/log/run
new file mode 100755
index 00000000..3195b018
--- /dev/null
+++ b/rel/sv/bigcouch/log/run
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec chpst svlogd -tt ./main
diff --git a/rel/sv/bigcouch/run b/rel/sv/bigcouch/run
new file mode 100755
index 00000000..875c3f02
--- /dev/null
+++ b/rel/sv/bigcouch/run
@@ -0,0 +1,4 @@
+#!/bin/bash
+exec 2>&1
+export HOME=/home/bigcouch
+exec chpst -u bigcouch /opt/bigcouch/bin/bigcouch
diff --git a/share/Makefile.am b/share/Makefile.am
deleted file mode 100644
index 15f77fae..00000000
--- a/share/Makefile.am
+++ /dev/null
@@ -1,202 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-JS_FILE = server/main.js
-
-JS_FILE_COMPONENTS = \
- server/json2.js \
- server/filter.js \
- server/mimeparse.js \
- server/render.js \
- server/state.js \
- server/util.js \
- server/validate.js \
- server/views.js
-
-JS_FILE_COMPONENTS_LAST = server/loop.js
-
-$(JS_FILE): $(JS_FILE_COMPONENTS) $(JS_FILE_COMPONENTS_LAST)
- mkdir -p `dirname $(JS_FILE)`
- echo "// DO NOT EDIT THIS FILE BY HAND" > $@
- echo >> $@
- cat $^ >> $@
-
-CLEANFILES = $(JS_FILE)
-
-EXTRA_DIST = $(JS_FILE_COMPONENTS) $(JS_FILE_COMPONENTS_LAST)
-
-nobase_localdata_SCRIPTS = \
- $(JS_FILE)
-
-nobase_dist_localdata_DATA = \
- www/config.html \
- www/couch_tests.html \
- www/custom_test.html \
- www/database.html \
- www/session.html \
- www/dialog/_admin_party.html \
- www/dialog/_change_password.html \
- www/dialog/_compact_cleanup.html \
- www/dialog/_create_admin.html \
- www/dialog/_login.html \
- www/dialog/_signup.html \
- www/dialog/_create_database.html \
- www/dialog/_create_config.html \
- www/dialog/_delete_database.html \
- www/dialog/_delete_document.html \
- www/dialog/_database_security.html \
- www/dialog/_share_test_reports.html \
- www/dialog/_save_view_as.html \
- www/dialog/_upload_attachment.html \
- www/document.html \
- www/favicon.ico \
- www/image/add.png \
- www/image/apply.gif \
- www/image/bg.png \
- www/image/cancel.gif \
- www/image/compact.png \
- www/image/delete-mini.png \
- www/image/delete.png \
- www/image/grippie.gif \
- www/image/hgrad.gif \
- www/image/key.png \
- www/image/load.png \
- www/image/logo.png \
- www/image/order-asc.gif \
- www/image/order-desc.gif \
- www/image/path.gif \
- www/image/progress.gif \
- www/image/rarrow.png \
- www/image/run-mini.png \
- www/image/run.png \
- www/image/running.png \
- www/image/save.png \
- www/image/sidebar-toggle.png \
- www/image/spinner.gif \
- www/image/spinner_33.gif \
- www/image/spinner_6b.gif \
- www/image/test_failure.gif \
- www/image/test_success.gif \
- www/image/thead-key.gif \
- www/image/thead.gif \
- www/image/toggle-collapse.gif \
- www/image/toggle-expand.gif \
- www/image/twisty.gif \
- www/index.html \
- www/replicator.html \
- www/script/couch.js \
- www/script/couch_tests.js \
- www/script/couch_test_runner.js \
- www/script/futon.browse.js \
- www/script/futon.format.js \
- www/script/futon.js \
- www/script/jquery.couch.js \
- www/script/jquery.dialog.js \
- www/script/jquery.editinline.js \
- www/script/jquery.form.js \
- www/script/jquery.js \
- www/script/jquery-ui-1.8.11.custom.min.js \
- www/script/jquery.resizer.js \
- www/script/jquery.suggest.js \
- www/script/json2.js \
- www/script/jspec/jspec.css \
- www/script/jspec/jspec.jquery.js \
- www/script/jspec/jspec.js \
- www/script/jspec/jspec.xhr.js \
- www/script/oauth.js \
- www/script/sha1.js \
- www/script/base64.js \
- www/script/test/all_docs.js \
- www/script/test/attachments.js \
- www/script/test/attachments_multipart.js \
- www/script/test/attachment_conflicts.js \
- www/script/test/attachment_names.js \
- www/script/test/attachment_paths.js \
- www/script/test/attachment_ranges.js \
- www/script/test/attachment_views.js \
- www/script/test/auth_cache.js \
- www/script/test/basics.js \
- www/script/test/batch_save.js \
- www/script/test/bulk_docs.js \
- www/script/test/changes.js \
- www/script/test/compact.js \
- www/script/test/config.js \
- www/script/test/conflicts.js \
- www/script/test/content_negotiation.js \
- www/script/test/cookie_auth.js \
- www/script/test/copy_doc.js \
- www/script/test/delayed_commits.js \
- www/script/test/design_docs.js \
- www/script/test/design_options.js \
- www/script/test/design_paths.js \
- www/script/test/erlang_views.js \
- www/script/test/etags_head.js \
- www/script/test/etags_views.js \
- www/script/test/form_submit.js \
- www/script/test/http.js \
- www/script/test/invalid_docids.js \
- www/script/test/jsonp.js \
- www/script/test/large_docs.js \
- www/script/test/list_views.js \
- www/script/test/lorem.txt \
- www/script/test/lorem_b64.txt \
- www/script/test/lots_of_docs.js \
- www/script/test/method_override.js \
- www/script/test/multiple_rows.js \
- www/script/test/oauth.js \
- www/script/test/proxyauth.js \
- www/script/test/purge.js \
- www/script/test/reader_acl.js \
- www/script/test/recreate_doc.js \
- www/script/test/reduce.js \
- www/script/test/reduce_builtin.js \
- www/script/test/reduce_false.js \
- www/script/test/reduce_false_temp.js \
- www/script/test/replication.js \
- www/script/test/replicator_db.js \
- www/script/test/rev_stemming.js \
- www/script/test/rewrite.js \
- www/script/test/security_validation.js \
- www/script/test/show_documents.js \
- www/script/test/stats.js \
- www/script/test/update_documents.js \
- www/script/test/users_db.js \
- www/script/test/utf8.js \
- www/script/test/uuids.js \
- www/script/test/view_collation.js \
- www/script/test/view_collation_raw.js \
- www/script/test/view_conflicts.js \
- www/script/test/view_compaction.js \
- www/script/test/view_errors.js \
- www/script/test/view_include_docs.js \
- www/script/test/view_multi_key_all_docs.js \
- www/script/test/view_multi_key_design.js \
- www/script/test/view_multi_key_temp.js \
- www/script/test/view_offsets.js \
- www/script/test/view_update_seq.js \
- www/script/test/view_pagination.js \
- www/script/test/view_sandboxing.js \
- www/script/test/view_xml.js \
- www/spec/couch_js_class_methods_spec.js \
- www/spec/couch_js_instance_methods_1_spec.js \
- www/spec/couch_js_instance_methods_2_spec.js \
- www/spec/couch_js_instance_methods_3_spec.js \
- www/spec/custom_helpers.js \
- www/spec/jquery_couch_js_class_methods_spec.js \
- www/spec/jquery_couch_js_instance_methods_1_spec.js \
- www/spec/jquery_couch_js_instance_methods_2_spec.js \
- www/spec/jquery_couch_js_instance_methods_3_spec.js \
- www/spec/run.html \
- www/status.html \
- www/style/jquery-ui-1.8.11.custom.css \
- www/style/layout.css \
- www/_sidebar.html
diff --git a/share/www/dialog/_change_password.html b/share/www/dialog/_change_password.html
deleted file mode 100644
index 40601d9a..00000000
--- a/share/www/dialog/_change_password.html
+++ /dev/null
@@ -1,31 +0,0 @@
-<!--
-
-Licensed under the Apache License, Version 2.0 (the "License"); you may not use
-this file except in compliance with the License. You may obtain a copy of the
-License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software distributed
-under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-CONDITIONS OF ANY KIND, either express or implied. See the License for the
-specific language governing permissions and limitations under the License.
-
--->
-<form action="" method="post">
- <h2>Change Password</h2>
- <fieldset>
- <table summary=""><tbody><tr>
- <th><label>New Password:</label></th>
- <td><input type="password" name="password" size="24" /></td>
- </tr><tr>
- <th><label>Verify New Password:</label></th>
- <td><input type="password" name="verify_password" size="24" /></td>
- </tr>
- </tbody></table>
- </fieldset>
- <div class="buttons">
- <button type="submit">Login</button>
- <button type="button" class="cancel">Cancel</button>
- </div>
-</form>
diff --git a/share/www/image/spinner_33.gif b/share/www/image/spinner_33.gif
deleted file mode 100644
index 5ad51927..00000000
--- a/share/www/image/spinner_33.gif
+++ /dev/null
Binary files differ
diff --git a/share/www/image/spinner_6b.gif b/share/www/image/spinner_6b.gif
deleted file mode 100644
index 4e3d9725..00000000
--- a/share/www/image/spinner_6b.gif
+++ /dev/null
Binary files differ
diff --git a/share/www/script/jquery-ui-1.8.11.custom.min.js b/share/www/script/jquery-ui-1.8.11.custom.min.js
deleted file mode 100644
index 45b927e0..00000000
--- a/share/www/script/jquery-ui-1.8.11.custom.min.js
+++ /dev/null
@@ -1,81 +0,0 @@
-/*!
- * jQuery UI 1.8.11
- *
- * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
- * Dual licensed under the MIT or GPL Version 2 licenses.
- * http://jquery.org/license
- *
- * http://docs.jquery.com/UI
- */
-(function(c,j){function k(a){return!c(a).parents().andSelf().filter(function(){return c.curCSS(this,"visibility")==="hidden"||c.expr.filters.hidden(this)}).length}c.ui=c.ui||{};if(!c.ui.version){c.extend(c.ui,{version:"1.8.11",keyCode:{ALT:18,BACKSPACE:8,CAPS_LOCK:20,COMMA:188,COMMAND:91,COMMAND_LEFT:91,COMMAND_RIGHT:93,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,MENU:93,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,
-NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38,WINDOWS:91}});c.fn.extend({_focus:c.fn.focus,focus:function(a,b){return typeof a==="number"?this.each(function(){var d=this;setTimeout(function(){c(d).focus();b&&b.call(d)},a)}):this._focus.apply(this,arguments)},scrollParent:function(){var a;a=c.browser.msie&&/(static|relative)/.test(this.css("position"))||/absolute/.test(this.css("position"))?this.parents().filter(function(){return/(relative|absolute|fixed)/.test(c.curCSS(this,
-"position",1))&&/(auto|scroll)/.test(c.curCSS(this,"overflow",1)+c.curCSS(this,"overflow-y",1)+c.curCSS(this,"overflow-x",1))}).eq(0):this.parents().filter(function(){return/(auto|scroll)/.test(c.curCSS(this,"overflow",1)+c.curCSS(this,"overflow-y",1)+c.curCSS(this,"overflow-x",1))}).eq(0);return/fixed/.test(this.css("position"))||!a.length?c(document):a},zIndex:function(a){if(a!==j)return this.css("zIndex",a);if(this.length){a=c(this[0]);for(var b;a.length&&a[0]!==document;){b=a.css("position");
-if(b==="absolute"||b==="relative"||b==="fixed"){b=parseInt(a.css("zIndex"),10);if(!isNaN(b)&&b!==0)return b}a=a.parent()}}return 0},disableSelection:function(){return this.bind((c.support.selectstart?"selectstart":"mousedown")+".ui-disableSelection",function(a){a.preventDefault()})},enableSelection:function(){return this.unbind(".ui-disableSelection")}});c.each(["Width","Height"],function(a,b){function d(f,g,l,m){c.each(e,function(){g-=parseFloat(c.curCSS(f,"padding"+this,true))||0;if(l)g-=parseFloat(c.curCSS(f,
-"border"+this+"Width",true))||0;if(m)g-=parseFloat(c.curCSS(f,"margin"+this,true))||0});return g}var e=b==="Width"?["Left","Right"]:["Top","Bottom"],h=b.toLowerCase(),i={innerWidth:c.fn.innerWidth,innerHeight:c.fn.innerHeight,outerWidth:c.fn.outerWidth,outerHeight:c.fn.outerHeight};c.fn["inner"+b]=function(f){if(f===j)return i["inner"+b].call(this);return this.each(function(){c(this).css(h,d(this,f)+"px")})};c.fn["outer"+b]=function(f,g){if(typeof f!=="number")return i["outer"+b].call(this,f);return this.each(function(){c(this).css(h,
-d(this,f,true,g)+"px")})}});c.extend(c.expr[":"],{data:function(a,b,d){return!!c.data(a,d[3])},focusable:function(a){var b=a.nodeName.toLowerCase(),d=c.attr(a,"tabindex");if("area"===b){b=a.parentNode;d=b.name;if(!a.href||!d||b.nodeName.toLowerCase()!=="map")return false;a=c("img[usemap=#"+d+"]")[0];return!!a&&k(a)}return(/input|select|textarea|button|object/.test(b)?!a.disabled:"a"==b?a.href||!isNaN(d):!isNaN(d))&&k(a)},tabbable:function(a){var b=c.attr(a,"tabindex");return(isNaN(b)||b>=0)&&c(a).is(":focusable")}});
-c(function(){var a=document.body,b=a.appendChild(b=document.createElement("div"));c.extend(b.style,{minHeight:"100px",height:"auto",padding:0,borderWidth:0});c.support.minHeight=b.offsetHeight===100;c.support.selectstart="onselectstart"in b;a.removeChild(b).style.display="none"});c.extend(c.ui,{plugin:{add:function(a,b,d){a=c.ui[a].prototype;for(var e in d){a.plugins[e]=a.plugins[e]||[];a.plugins[e].push([b,d[e]])}},call:function(a,b,d){if((b=a.plugins[b])&&a.element[0].parentNode)for(var e=0;e<b.length;e++)a.options[b[e][0]]&&
-b[e][1].apply(a.element,d)}},contains:function(a,b){return document.compareDocumentPosition?a.compareDocumentPosition(b)&16:a!==b&&a.contains(b)},hasScroll:function(a,b){if(c(a).css("overflow")==="hidden")return false;b=b&&b==="left"?"scrollLeft":"scrollTop";var d=false;if(a[b]>0)return true;a[b]=1;d=a[b]>0;a[b]=0;return d},isOverAxis:function(a,b,d){return a>b&&a<b+d},isOver:function(a,b,d,e,h,i){return c.ui.isOverAxis(a,d,h)&&c.ui.isOverAxis(b,e,i)}})}})(jQuery);
-;/*!
- * jQuery UI Widget 1.8.11
- *
- * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
- * Dual licensed under the MIT or GPL Version 2 licenses.
- * http://jquery.org/license
- *
- * http://docs.jquery.com/UI/Widget
- */
-(function(b,j){if(b.cleanData){var k=b.cleanData;b.cleanData=function(a){for(var c=0,d;(d=a[c])!=null;c++)b(d).triggerHandler("remove");k(a)}}else{var l=b.fn.remove;b.fn.remove=function(a,c){return this.each(function(){if(!c)if(!a||b.filter(a,[this]).length)b("*",this).add([this]).each(function(){b(this).triggerHandler("remove")});return l.call(b(this),a,c)})}}b.widget=function(a,c,d){var e=a.split(".")[0],f;a=a.split(".")[1];f=e+"-"+a;if(!d){d=c;c=b.Widget}b.expr[":"][f]=function(h){return!!b.data(h,
-a)};b[e]=b[e]||{};b[e][a]=function(h,g){arguments.length&&this._createWidget(h,g)};c=new c;c.options=b.extend(true,{},c.options);b[e][a].prototype=b.extend(true,c,{namespace:e,widgetName:a,widgetEventPrefix:b[e][a].prototype.widgetEventPrefix||a,widgetBaseClass:f},d);b.widget.bridge(a,b[e][a])};b.widget.bridge=function(a,c){b.fn[a]=function(d){var e=typeof d==="string",f=Array.prototype.slice.call(arguments,1),h=this;d=!e&&f.length?b.extend.apply(null,[true,d].concat(f)):d;if(e&&d.charAt(0)==="_")return h;
-e?this.each(function(){var g=b.data(this,a),i=g&&b.isFunction(g[d])?g[d].apply(g,f):g;if(i!==g&&i!==j){h=i;return false}}):this.each(function(){var g=b.data(this,a);g?g.option(d||{})._init():b.data(this,a,new c(d,this))});return h}};b.Widget=function(a,c){arguments.length&&this._createWidget(a,c)};b.Widget.prototype={widgetName:"widget",widgetEventPrefix:"",options:{disabled:false},_createWidget:function(a,c){b.data(c,this.widgetName,this);this.element=b(c);this.options=b.extend(true,{},this.options,
-this._getCreateOptions(),a);var d=this;this.element.bind("remove."+this.widgetName,function(){d.destroy()});this._create();this._trigger("create");this._init()},_getCreateOptions:function(){return b.metadata&&b.metadata.get(this.element[0])[this.widgetName]},_create:function(){},_init:function(){},destroy:function(){this.element.unbind("."+this.widgetName).removeData(this.widgetName);this.widget().unbind("."+this.widgetName).removeAttr("aria-disabled").removeClass(this.widgetBaseClass+"-disabled ui-state-disabled")},
-widget:function(){return this.element},option:function(a,c){var d=a;if(arguments.length===0)return b.extend({},this.options);if(typeof a==="string"){if(c===j)return this.options[a];d={};d[a]=c}this._setOptions(d);return this},_setOptions:function(a){var c=this;b.each(a,function(d,e){c._setOption(d,e)});return this},_setOption:function(a,c){this.options[a]=c;if(a==="disabled")this.widget()[c?"addClass":"removeClass"](this.widgetBaseClass+"-disabled ui-state-disabled").attr("aria-disabled",c);return this},
-enable:function(){return this._setOption("disabled",false)},disable:function(){return this._setOption("disabled",true)},_trigger:function(a,c,d){var e=this.options[a];c=b.Event(c);c.type=(a===this.widgetEventPrefix?a:this.widgetEventPrefix+a).toLowerCase();d=d||{};if(c.originalEvent){a=b.event.props.length;for(var f;a;){f=b.event.props[--a];c[f]=c.originalEvent[f]}}this.element.trigger(c,d);return!(b.isFunction(e)&&e.call(this.element[0],c,d)===false||c.isDefaultPrevented())}}})(jQuery);
-;/*
- * jQuery UI Position 1.8.11
- *
- * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
- * Dual licensed under the MIT or GPL Version 2 licenses.
- * http://jquery.org/license
- *
- * http://docs.jquery.com/UI/Position
- */
-(function(c){c.ui=c.ui||{};var n=/left|center|right/,o=/top|center|bottom/,t=c.fn.position,u=c.fn.offset;c.fn.position=function(b){if(!b||!b.of)return t.apply(this,arguments);b=c.extend({},b);var a=c(b.of),d=a[0],g=(b.collision||"flip").split(" "),e=b.offset?b.offset.split(" "):[0,0],h,k,j;if(d.nodeType===9){h=a.width();k=a.height();j={top:0,left:0}}else if(d.setTimeout){h=a.width();k=a.height();j={top:a.scrollTop(),left:a.scrollLeft()}}else if(d.preventDefault){b.at="left top";h=k=0;j={top:b.of.pageY,
-left:b.of.pageX}}else{h=a.outerWidth();k=a.outerHeight();j=a.offset()}c.each(["my","at"],function(){var f=(b[this]||"").split(" ");if(f.length===1)f=n.test(f[0])?f.concat(["center"]):o.test(f[0])?["center"].concat(f):["center","center"];f[0]=n.test(f[0])?f[0]:"center";f[1]=o.test(f[1])?f[1]:"center";b[this]=f});if(g.length===1)g[1]=g[0];e[0]=parseInt(e[0],10)||0;if(e.length===1)e[1]=e[0];e[1]=parseInt(e[1],10)||0;if(b.at[0]==="right")j.left+=h;else if(b.at[0]==="center")j.left+=h/2;if(b.at[1]==="bottom")j.top+=
-k;else if(b.at[1]==="center")j.top+=k/2;j.left+=e[0];j.top+=e[1];return this.each(function(){var f=c(this),l=f.outerWidth(),m=f.outerHeight(),p=parseInt(c.curCSS(this,"marginLeft",true))||0,q=parseInt(c.curCSS(this,"marginTop",true))||0,v=l+p+(parseInt(c.curCSS(this,"marginRight",true))||0),w=m+q+(parseInt(c.curCSS(this,"marginBottom",true))||0),i=c.extend({},j),r;if(b.my[0]==="right")i.left-=l;else if(b.my[0]==="center")i.left-=l/2;if(b.my[1]==="bottom")i.top-=m;else if(b.my[1]==="center")i.top-=
-m/2;i.left=Math.round(i.left);i.top=Math.round(i.top);r={left:i.left-p,top:i.top-q};c.each(["left","top"],function(s,x){c.ui.position[g[s]]&&c.ui.position[g[s]][x](i,{targetWidth:h,targetHeight:k,elemWidth:l,elemHeight:m,collisionPosition:r,collisionWidth:v,collisionHeight:w,offset:e,my:b.my,at:b.at})});c.fn.bgiframe&&f.bgiframe();f.offset(c.extend(i,{using:b.using}))})};c.ui.position={fit:{left:function(b,a){var d=c(window);d=a.collisionPosition.left+a.collisionWidth-d.width()-d.scrollLeft();b.left=
-d>0?b.left-d:Math.max(b.left-a.collisionPosition.left,b.left)},top:function(b,a){var d=c(window);d=a.collisionPosition.top+a.collisionHeight-d.height()-d.scrollTop();b.top=d>0?b.top-d:Math.max(b.top-a.collisionPosition.top,b.top)}},flip:{left:function(b,a){if(a.at[0]!=="center"){var d=c(window);d=a.collisionPosition.left+a.collisionWidth-d.width()-d.scrollLeft();var g=a.my[0]==="left"?-a.elemWidth:a.my[0]==="right"?a.elemWidth:0,e=a.at[0]==="left"?a.targetWidth:-a.targetWidth,h=-2*a.offset[0];b.left+=
-a.collisionPosition.left<0?g+e+h:d>0?g+e+h:0}},top:function(b,a){if(a.at[1]!=="center"){var d=c(window);d=a.collisionPosition.top+a.collisionHeight-d.height()-d.scrollTop();var g=a.my[1]==="top"?-a.elemHeight:a.my[1]==="bottom"?a.elemHeight:0,e=a.at[1]==="top"?a.targetHeight:-a.targetHeight,h=-2*a.offset[1];b.top+=a.collisionPosition.top<0?g+e+h:d>0?g+e+h:0}}}};if(!c.offset.setOffset){c.offset.setOffset=function(b,a){if(/static/.test(c.curCSS(b,"position")))b.style.position="relative";var d=c(b),
-g=d.offset(),e=parseInt(c.curCSS(b,"top",true),10)||0,h=parseInt(c.curCSS(b,"left",true),10)||0;g={top:a.top-g.top+e,left:a.left-g.left+h};"using"in a?a.using.call(b,g):d.css(g)};c.fn.offset=function(b){var a=this[0];if(!a||!a.ownerDocument)return null;if(b)return this.each(function(){c.offset.setOffset(this,b)});return u.call(this)}}})(jQuery);
-;/*
- * jQuery UI Autocomplete 1.8.11
- *
- * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
- * Dual licensed under the MIT or GPL Version 2 licenses.
- * http://jquery.org/license
- *
- * http://docs.jquery.com/UI/Autocomplete
- *
- * Depends:
- * jquery.ui.core.js
- * jquery.ui.widget.js
- * jquery.ui.position.js
- */
-(function(d){var e=0;d.widget("ui.autocomplete",{options:{appendTo:"body",autoFocus:false,delay:300,minLength:1,position:{my:"left top",at:"left bottom",collision:"none"},source:null},pending:0,_create:function(){var a=this,b=this.element[0].ownerDocument,g;this.element.addClass("ui-autocomplete-input").attr("autocomplete","off").attr({role:"textbox","aria-autocomplete":"list","aria-haspopup":"true"}).bind("keydown.autocomplete",function(c){if(!(a.options.disabled||a.element.attr("readonly"))){g=
-false;var f=d.ui.keyCode;switch(c.keyCode){case f.PAGE_UP:a._move("previousPage",c);break;case f.PAGE_DOWN:a._move("nextPage",c);break;case f.UP:a._move("previous",c);c.preventDefault();break;case f.DOWN:a._move("next",c);c.preventDefault();break;case f.ENTER:case f.NUMPAD_ENTER:if(a.menu.active){g=true;c.preventDefault()}case f.TAB:if(!a.menu.active)return;a.menu.select(c);break;case f.ESCAPE:a.element.val(a.term);a.close(c);break;default:clearTimeout(a.searching);a.searching=setTimeout(function(){if(a.term!=
-a.element.val()){a.selectedItem=null;a.search(null,c)}},a.options.delay);break}}}).bind("keypress.autocomplete",function(c){if(g){g=false;c.preventDefault()}}).bind("focus.autocomplete",function(){if(!a.options.disabled){a.selectedItem=null;a.previous=a.element.val()}}).bind("blur.autocomplete",function(c){if(!a.options.disabled){clearTimeout(a.searching);a.closing=setTimeout(function(){a.close(c);a._change(c)},150)}});this._initSource();this.response=function(){return a._response.apply(a,arguments)};
-this.menu=d("<ul></ul>").addClass("ui-autocomplete").appendTo(d(this.options.appendTo||"body",b)[0]).mousedown(function(c){var f=a.menu.element[0];d(c.target).closest(".ui-menu-item").length||setTimeout(function(){d(document).one("mousedown",function(h){h.target!==a.element[0]&&h.target!==f&&!d.ui.contains(f,h.target)&&a.close()})},1);setTimeout(function(){clearTimeout(a.closing)},13)}).menu({focus:function(c,f){f=f.item.data("item.autocomplete");false!==a._trigger("focus",c,{item:f})&&/^key/.test(c.originalEvent.type)&&
-a.element.val(f.value)},selected:function(c,f){var h=f.item.data("item.autocomplete"),i=a.previous;if(a.element[0]!==b.activeElement){a.element.focus();a.previous=i;setTimeout(function(){a.previous=i;a.selectedItem=h},1)}false!==a._trigger("select",c,{item:h})&&a.element.val(h.value);a.term=a.element.val();a.close(c);a.selectedItem=h},blur:function(){a.menu.element.is(":visible")&&a.element.val()!==a.term&&a.element.val(a.term)}}).zIndex(this.element.zIndex()+1).css({top:0,left:0}).hide().data("menu");
-d.fn.bgiframe&&this.menu.element.bgiframe()},destroy:function(){this.element.removeClass("ui-autocomplete-input").removeAttr("autocomplete").removeAttr("role").removeAttr("aria-autocomplete").removeAttr("aria-haspopup");this.menu.element.remove();d.Widget.prototype.destroy.call(this)},_setOption:function(a,b){d.Widget.prototype._setOption.apply(this,arguments);a==="source"&&this._initSource();if(a==="appendTo")this.menu.element.appendTo(d(b||"body",this.element[0].ownerDocument)[0]);a==="disabled"&&
-b&&this.xhr&&this.xhr.abort()},_initSource:function(){var a=this,b,g;if(d.isArray(this.options.source)){b=this.options.source;this.source=function(c,f){f(d.ui.autocomplete.filter(b,c.term))}}else if(typeof this.options.source==="string"){g=this.options.source;this.source=function(c,f){a.xhr&&a.xhr.abort();a.xhr=d.ajax({url:g,data:c,dataType:"json",autocompleteRequest:++e,success:function(h){this.autocompleteRequest===e&&f(h)},error:function(){this.autocompleteRequest===e&&f([])}})}}else this.source=
-this.options.source},search:function(a,b){a=a!=null?a:this.element.val();this.term=this.element.val();if(a.length<this.options.minLength)return this.close(b);clearTimeout(this.closing);if(this._trigger("search",b)!==false)return this._search(a)},_search:function(a){this.pending++;this.element.addClass("ui-autocomplete-loading");this.source({term:a},this.response)},_response:function(a){if(!this.options.disabled&&a&&a.length){a=this._normalize(a);this._suggest(a);this._trigger("open")}else this.close();
-this.pending--;this.pending||this.element.removeClass("ui-autocomplete-loading")},close:function(a){clearTimeout(this.closing);if(this.menu.element.is(":visible")){this.menu.element.hide();this.menu.deactivate();this._trigger("close",a)}},_change:function(a){this.previous!==this.element.val()&&this._trigger("change",a,{item:this.selectedItem})},_normalize:function(a){if(a.length&&a[0].label&&a[0].value)return a;return d.map(a,function(b){if(typeof b==="string")return{label:b,value:b};return d.extend({label:b.label||
-b.value,value:b.value||b.label},b)})},_suggest:function(a){var b=this.menu.element.empty().zIndex(this.element.zIndex()+1);this._renderMenu(b,a);this.menu.deactivate();this.menu.refresh();b.show();this._resizeMenu();b.position(d.extend({of:this.element},this.options.position));this.options.autoFocus&&this.menu.next(new d.Event("mouseover"))},_resizeMenu:function(){var a=this.menu.element;a.outerWidth(Math.max(a.width("").outerWidth(),this.element.outerWidth()))},_renderMenu:function(a,b){var g=this;
-d.each(b,function(c,f){g._renderItem(a,f)})},_renderItem:function(a,b){return d("<li></li>").data("item.autocomplete",b).append(d("<a></a>").text(b.label)).appendTo(a)},_move:function(a,b){if(this.menu.element.is(":visible"))if(this.menu.first()&&/^previous/.test(a)||this.menu.last()&&/^next/.test(a)){this.element.val(this.term);this.menu.deactivate()}else this.menu[a](b);else this.search(null,b)},widget:function(){return this.menu.element}});d.extend(d.ui.autocomplete,{escapeRegex:function(a){return a.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,
-"\\$&")},filter:function(a,b){var g=new RegExp(d.ui.autocomplete.escapeRegex(b),"i");return d.grep(a,function(c){return g.test(c.label||c.value||c)})}})})(jQuery);
-(function(d){d.widget("ui.menu",{_create:function(){var e=this;this.element.addClass("ui-menu ui-widget ui-widget-content ui-corner-all").attr({role:"listbox","aria-activedescendant":"ui-active-menuitem"}).click(function(a){if(d(a.target).closest(".ui-menu-item a").length){a.preventDefault();e.select(a)}});this.refresh()},refresh:function(){var e=this;this.element.children("li:not(.ui-menu-item):has(a)").addClass("ui-menu-item").attr("role","menuitem").children("a").addClass("ui-corner-all").attr("tabindex",
--1).mouseenter(function(a){e.activate(a,d(this).parent())}).mouseleave(function(){e.deactivate()})},activate:function(e,a){this.deactivate();if(this.hasScroll()){var b=a.offset().top-this.element.offset().top,g=this.element.attr("scrollTop"),c=this.element.height();if(b<0)this.element.attr("scrollTop",g+b);else b>=c&&this.element.attr("scrollTop",g+b-c+a.height())}this.active=a.eq(0).children("a").addClass("ui-state-hover").attr("id","ui-active-menuitem").end();this._trigger("focus",e,{item:a})},
-deactivate:function(){if(this.active){this.active.children("a").removeClass("ui-state-hover").removeAttr("id");this._trigger("blur");this.active=null}},next:function(e){this.move("next",".ui-menu-item:first",e)},previous:function(e){this.move("prev",".ui-menu-item:last",e)},first:function(){return this.active&&!this.active.prevAll(".ui-menu-item").length},last:function(){return this.active&&!this.active.nextAll(".ui-menu-item").length},move:function(e,a,b){if(this.active){e=this.active[e+"All"](".ui-menu-item").eq(0);
-e.length?this.activate(b,e):this.activate(b,this.element.children(a))}else this.activate(b,this.element.children(a))},nextPage:function(e){if(this.hasScroll())if(!this.active||this.last())this.activate(e,this.element.children(".ui-menu-item:first"));else{var a=this.active.offset().top,b=this.element.height(),g=this.element.children(".ui-menu-item").filter(function(){var c=d(this).offset().top-a-b+d(this).height();return c<10&&c>-10});g.length||(g=this.element.children(".ui-menu-item:last"));this.activate(e,
-g)}else this.activate(e,this.element.children(".ui-menu-item").filter(!this.active||this.last()?":first":":last"))},previousPage:function(e){if(this.hasScroll())if(!this.active||this.first())this.activate(e,this.element.children(".ui-menu-item:last"));else{var a=this.active.offset().top,b=this.element.height();result=this.element.children(".ui-menu-item").filter(function(){var g=d(this).offset().top-a+b-d(this).height();return g<10&&g>-10});result.length||(result=this.element.children(".ui-menu-item:first"));
-this.activate(e,result)}else this.activate(e,this.element.children(".ui-menu-item").filter(!this.active||this.first()?":last":":first"))},hasScroll:function(){return this.element.height()<this.element.attr("scrollHeight")},select:function(e){this._trigger("selected",e,{item:this.active})}})})(jQuery);
-; \ No newline at end of file
diff --git a/share/www/script/test/attachment_ranges.js b/share/www/script/test/attachment_ranges.js
deleted file mode 100644
index e1d40eae..00000000
--- a/share/www/script/test/attachment_ranges.js
+++ /dev/null
@@ -1,134 +0,0 @@
-// Licensed under the Apache License, Version 2.0 (the "License"); you may not
-// use this file except in compliance with the License. You may obtain a copy of
-// the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-couchTests.attachment_ranges = function(debug) {
- var db = new CouchDB("test_suite_db", {
- "X-Couch-Full-Commit": "false"
- });
- db.deleteDb();
- db.createDb();
-
- if (debug) debugger;
-
- var binAttDoc = {
- _id: "bin_doc",
- _attachments: {
- "foo.txt": {
- content_type: "application/octet-stream",
- data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="
- }
- }
- };
-
- var save_response = db.save(binAttDoc);
- T(save_response.ok);
-
- // Fetching the whole entity is a 206.
- var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
- headers: {
- "Range": "bytes=0-28"
- }
- });
- TEquals(206, xhr.status, "fetch 0-28");
- TEquals("This is a base64 encoded text", xhr.responseText);
- TEquals("bytes 0-28/29", xhr.getResponseHeader("Content-Range"));
- TEquals("29", xhr.getResponseHeader("Content-Length"));
-
- // Fetch the whole entity without an end offset is a 206.
- var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
- headers: {
- "Range": "bytes=0-"
- }
- });
- TEquals(206, xhr.status, "fetch 0-");
- TEquals("This is a base64 encoded text", xhr.responseText);
- TEquals("bytes 0-28/29", xhr.getResponseHeader("Content-Range"));
- TEquals("29", xhr.getResponseHeader("Content-Length"));
-
- // Badly formed range header is a 200.
- var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
- headers: {
- "Range": "bytes:0-"
- }
- });
- TEquals(200, xhr.status, "fetch with bad range header");
-
- // Fetch the end of an entity without an end offset is a 206.
- var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
- headers: {
- "Range": "bytes=2-"
- }
- });
- TEquals(206, xhr.status, "fetch 2-");
- TEquals("is is a base64 encoded text", xhr.responseText);
- TEquals("bytes 2-28/29", xhr.getResponseHeader("Content-Range"));
- TEquals("27", xhr.getResponseHeader("Content-Length"));
-
- // Fetch past the end of the entity is a 206
- var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
- headers: {
- "Range": "bytes=0-29"
- }
- });
- TEquals(206, xhr.status, "fetch 0-29");
- TEquals("bytes 0-28/29", xhr.getResponseHeader("Content-Range"));
- TEquals("29", xhr.getResponseHeader("Content-Length"));
-
- // Fetch first part of entity is a 206
- var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
- headers: {
- "Range": "bytes=0-3"
- }
- });
- TEquals(206, xhr.status, "fetch 0-3");
- TEquals("This", xhr.responseText);
- TEquals("4", xhr.getResponseHeader("Content-Length"));
- TEquals("bytes 0-3/29", xhr.getResponseHeader("Content-Range"));
-
- // Fetch middle of entity is also a 206
- var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
- headers: {
- "Range": "bytes=10-15"
- }
- });
- TEquals(206, xhr.status, "fetch 10-15");
- TEquals("base64", xhr.responseText);
- TEquals("6", xhr.getResponseHeader("Content-Length"));
- TEquals("bytes 10-15/29", xhr.getResponseHeader("Content-Range"));
-
- // Fetch end of entity is also a 206
- var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
- headers: {
- "Range": "bytes=-3"
- }
- });
- TEquals(206, xhr.status, "fetch -3");
- TEquals("ext", xhr.responseText);
- TEquals("3", xhr.getResponseHeader("Content-Length"));
- TEquals("bytes 26-28/29", xhr.getResponseHeader("Content-Range"));
-
- // backward range is 416
- var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
- headers: {
- "Range": "bytes=5-3"
- }
- });
- TEquals(416, xhr.status, "fetch 5-3");
-
- // range completely outside of entity is 416
- var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
- headers: {
- "Range": "bytes=300-310"
- }
- });
- TEquals(416, xhr.status, "fetch 300-310");
-
-};
diff --git a/share/www/script/test/replicator_db.js b/share/www/script/test/replicator_db.js
deleted file mode 100644
index 4434124e..00000000
--- a/share/www/script/test/replicator_db.js
+++ /dev/null
@@ -1,1380 +0,0 @@
-// Licensed under the Apache License, Version 2.0 (the "License"); you may not
-// use this file except in compliance with the License. You may obtain a copy of
-// the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-
-couchTests.replicator_db = function(debug) {
-
- if (debug) debugger;
-
- var wait_rep_doc = 500; // number of millisecs to wait after saving a Rep Doc
- var host = CouchDB.host;
- var dbA = new CouchDB("test_suite_rep_db_a", {"X-Couch-Full-Commit":"false"});
- var dbB = new CouchDB("test_suite_rep_db_b", {"X-Couch-Full-Commit":"false"});
- var repDb = new CouchDB("test_suite_rep_db", {"X-Couch-Full-Commit":"false"});
- var usersDb = new CouchDB("test_suite_auth", {"X-Couch-Full-Commit":"false"});
-
- var docs1 = [
- {
- _id: "foo1",
- value: 11
- },
- {
- _id: "foo2",
- value: 22
- },
- {
- _id: "foo3",
- value: 33
- }
- ];
-
- function waitForRep(repDb, repDoc, state) {
- var newRep,
- t0 = new Date(),
- t1,
- ms = 3000;
-
- do {
- newRep = repDb.open(repDoc._id);
- t1 = new Date();
- } while (((t1 - t0) <= ms) && newRep._replication_state !== state);
- }
-
- function waitForSeq(sourceDb, targetDb) {
- var targetSeq,
- sourceSeq = sourceDb.info().update_seq,
- t0 = new Date(),
- t1,
- ms = 3000;
-
- do {
- targetSeq = targetDb.info().update_seq;
- t1 = new Date();
- } while (((t1 - t0) <= ms) && targetSeq < sourceSeq);
- }
-
- function waitForDocPos(db, docId, pos) {
- var doc, curPos, t0, t1,
- maxWait = 3000;
-
- doc = db.open(docId);
- curPos = Number(doc._rev.split("-", 1));
- t0 = t1 = new Date();
-
- while ((curPos < pos) && ((t1 - t0) <= maxWait)) {
- doc = db.open(docId);
- curPos = Number(doc._rev.split("-", 1));
- t1 = new Date();
- }
-
- return doc;
- }
-
- function wait(ms) {
- var t0 = new Date(), t1;
- do {
- CouchDB.request("GET", "/");
- t1 = new Date();
- } while ((t1 - t0) <= ms);
- }
-
-
- function populate_db(db, docs) {
- db.deleteDb();
- db.createDb();
- for (var i = 0; i < docs.length; i++) {
- var d = docs[i];
- delete d._rev;
- T(db.save(d).ok);
- }
- }
-
- function simple_replication() {
- populate_db(dbA, docs1);
- populate_db(dbB, []);
-
- var repDoc = {
- _id: "foo_simple_rep",
- source: dbA.name,
- target: dbB.name
- };
- T(repDb.save(repDoc).ok);
-
- waitForRep(repDb, repDoc, "completed");
- for (var i = 0; i < docs1.length; i++) {
- var doc = docs1[i];
- var copy = dbB.open(doc._id);
- T(copy !== null);
- T(copy.value === doc.value);
- }
-
- var repDoc1 = repDb.open(repDoc._id);
- T(repDoc1 !== null);
- T(repDoc1.source === repDoc.source);
- T(repDoc1.target === repDoc.target);
- T(repDoc1._replication_state === "completed", "simple");
- T(typeof repDoc1._replication_state_time === "string");
- T(typeof repDoc1._replication_id === "string");
- }
-
-
- function filtered_replication() {
- var docs2 = docs1.concat([
- {
- _id: "_design/mydesign",
- language : "javascript",
- filters : {
- myfilter : (function(doc, req) {
- return (doc.value % 2) !== Number(req.query.myparam);
- }).toString()
- }
- }
- ]);
-
- populate_db(dbA, docs2);
- populate_db(dbB, []);
-
- var repDoc = {
- _id: "foo_filt_rep_doc",
- source: "http://" + host + "/" + dbA.name,
- target: dbB.name,
- filter: "mydesign/myfilter",
- query_params: {
- myparam: 1
- }
- };
- T(repDb.save(repDoc).ok);
-
- waitForRep(repDb, repDoc, "completed");
- for (var i = 0; i < docs2.length; i++) {
- var doc = docs2[i];
- var copy = dbB.open(doc._id);
-
- if (typeof doc.value === "number") {
- if ((doc.value % 2) !== 1) {
- T(copy !== null);
- T(copy.value === doc.value);
- } else {
- T(copy === null);
- }
- }
- }
-
- var repDoc1 = repDb.open(repDoc._id);
- T(repDoc1 !== null);
- T(repDoc1.source === repDoc.source);
- T(repDoc1.target === repDoc.target);
- T(repDoc1._replication_state === "completed", "filtered");
- T(typeof repDoc1._replication_state_time === "string");
- T(typeof repDoc1._replication_id === "string");
- }
-
-
- function continuous_replication() {
- populate_db(dbA, docs1);
- populate_db(dbB, []);
-
- var repDoc = {
- _id: "foo_cont_rep_doc",
- source: "http://" + host + "/" + dbA.name,
- target: dbB.name,
- continuous: true,
- user_ctx: {
- roles: ["_admin"]
- }
- };
-
- T(repDb.save(repDoc).ok);
-
- waitForSeq(dbA, dbB);
- for (var i = 0; i < docs1.length; i++) {
- var doc = docs1[i];
- var copy = dbB.open(doc._id);
- T(copy !== null);
- T(copy.value === doc.value);
- }
-
- // add another doc to source, it will be replicated to target
- var docX = {
- _id: "foo1000",
- value: 1001
- };
-
- T(dbA.save(docX).ok);
-
- waitForSeq(dbA, dbB);
- var copy = dbB.open("foo1000");
- T(copy !== null);
- T(copy.value === 1001);
-
- var repDoc1 = repDb.open(repDoc._id);
- T(repDoc1 !== null);
- T(repDoc1.source === repDoc.source);
- T(repDoc1.target === repDoc.target);
- T(repDoc1._replication_state === "triggered");
- T(typeof repDoc1._replication_state_time === "string");
- T(typeof repDoc1._replication_id === "string");
-
- // Design documents are only replicated to local targets if the respective
- // replication document has a user_ctx filed with the "_admin" role in it.
- var ddoc = {
- _id: "_design/foobar",
- language: "javascript"
- };
-
- T(dbA.save(ddoc).ok);
-
- waitForSeq(dbA, dbB);
- var ddoc_copy = dbB.open("_design/foobar");
- T(ddoc_copy !== null);
- T(ddoc.language === "javascript");
-
- // update the design doc on source, test that the new revision is replicated
- ddoc.language = "erlang";
- T(dbA.save(ddoc).ok);
- T(ddoc._rev.indexOf("2-") === 0);
-
- waitForSeq(dbA, dbB);
- ddoc_copy = dbB.open("_design/foobar");
- T(ddoc_copy !== null);
- T(ddoc_copy._rev === ddoc._rev);
- T(ddoc.language === "erlang");
-
- // stop replication by deleting the replication document
- T(repDb.deleteDoc(repDoc1).ok);
-
- // add another doc to source, it will NOT be replicated to target
- var docY = {
- _id: "foo666",
- value: 999
- };
-
- T(dbA.save(docY).ok);
-
- wait(200); // is there a way to avoid wait here?
- var copy = dbB.open("foo666");
- T(copy === null);
- }
-
-
- function by_doc_ids_replication() {
- // to test that we can replicate docs with slashes in their IDs
- var docs2 = docs1.concat([
- {
- _id: "_design/mydesign",
- language : "javascript"
- }
- ]);
-
- populate_db(dbA, docs2);
- populate_db(dbB, []);
-
- var repDoc = {
- _id: "foo_cont_rep_doc",
- source: "http://" + host + "/" + dbA.name,
- target: dbB.name,
- doc_ids: ["foo666", "foo3", "_design/mydesign", "foo999", "foo1"]
- };
- T(repDb.save(repDoc).ok);
-
- waitForRep(repDb, repDoc, "completed");
- var copy = dbB.open("foo1");
- T(copy !== null);
- T(copy.value === 11);
-
- copy = dbB.open("foo2");
- T(copy === null);
-
- copy = dbB.open("foo3");
- T(copy !== null);
- T(copy.value === 33);
-
- copy = dbB.open("foo666");
- T(copy === null);
-
- copy = dbB.open("foo999");
- T(copy === null);
-
- copy = dbB.open("_design/mydesign");
- T(copy === null);
- }
-
-
- function successive_identical_replications() {
- populate_db(dbA, docs1);
- populate_db(dbB, []);
-
- var repDoc1 = {
- _id: "foo_ident_rep_1",
- source: dbA.name,
- target: dbB.name
- };
- T(repDb.save(repDoc1).ok);
-
- waitForRep(repDb, repDoc1, "completed");
- for (var i = 0; i < docs1.length; i++) {
- var doc = docs1[i];
- var copy = dbB.open(doc._id);
- T(copy !== null);
- T(copy.value === doc.value);
- }
-
- var repDoc1_copy = repDb.open(repDoc1._id);
- T(repDoc1_copy !== null);
- T(repDoc1_copy.source === repDoc1.source);
- T(repDoc1_copy.target === repDoc1.target);
- T(repDoc1_copy._replication_state === "completed");
- T(typeof repDoc1_copy._replication_state_time === "string");
- T(typeof repDoc1_copy._replication_id === "string");
-
- var newDoc = {
- _id: "doc666",
- value: 666
- };
- T(dbA.save(newDoc).ok);
-
- wait(200);
- var newDoc_copy = dbB.open(newDoc._id);
- // not replicated because first replication is complete (not continuous)
- T(newDoc_copy === null);
-
- var repDoc2 = {
- _id: "foo_ident_rep_2",
- source: dbA.name,
- target: dbB.name
- };
- T(repDb.save(repDoc2).ok);
-
- waitForRep(repDb, repDoc2, "completed");
- var newDoc_copy = dbB.open(newDoc._id);
- T(newDoc_copy !== null);
- T(newDoc_copy.value === newDoc.value);
-
- var repDoc2_copy = repDb.open(repDoc2._id);
- T(repDoc2_copy !== null);
- T(repDoc2_copy.source === repDoc1.source);
- T(repDoc2_copy.target === repDoc1.target);
- T(repDoc2_copy._replication_state === "completed");
- T(typeof repDoc2_copy._replication_state_time === "string");
- T(typeof repDoc2_copy._replication_id === "string");
- T(repDoc2_copy._replication_id === repDoc1_copy._replication_id);
- }
-
-
- // test the case where multiple replication docs (different IDs)
- // describe in fact the same replication (source, target, etc)
- function identical_rep_docs() {
- populate_db(dbA, docs1);
- populate_db(dbB, []);
-
- var repDoc1 = {
- _id: "foo_dup_rep_doc_1",
- source: "http://" + host + "/" + dbA.name,
- target: dbB.name
- };
- var repDoc2 = {
- _id: "foo_dup_rep_doc_2",
- source: "http://" + host + "/" + dbA.name,
- target: dbB.name
- };
-
- T(repDb.save(repDoc1).ok);
- T(repDb.save(repDoc2).ok);
-
- waitForRep(repDb, repDoc1, "completed");
- for (var i = 0; i < docs1.length; i++) {
- var doc = docs1[i];
- var copy = dbB.open(doc._id);
- T(copy !== null);
- T(copy.value === doc.value);
- }
-
- repDoc1 = repDb.open("foo_dup_rep_doc_1");
- T(repDoc1 !== null);
- T(repDoc1._replication_state === "completed", "identical");
- T(typeof repDoc1._replication_state_time === "string");
- T(typeof repDoc1._replication_id === "string");
-
- repDoc2 = repDb.open("foo_dup_rep_doc_2");
- T(repDoc2 !== null);
- T(typeof repDoc2._replication_state === "undefined");
- T(typeof repDoc2._replication_state_time === "undefined");
- T(repDoc2._replication_id === repDoc1._replication_id);
- }
-
-
- // test the case where multiple replication docs (different IDs)
- // describe in fact the same continuous replication (source, target, etc)
- function identical_continuous_rep_docs() {
- populate_db(dbA, docs1);
- populate_db(dbB, []);
-
- var repDoc1 = {
- _id: "foo_dup_cont_rep_doc_1",
- source: "http://" + host + "/" + dbA.name,
- target: dbB.name,
- continuous: true
- };
- var repDoc2 = {
- _id: "foo_dup_cont_rep_doc_2",
- source: "http://" + host + "/" + dbA.name,
- target: dbB.name,
- continuous: true
- };
-
- T(repDb.save(repDoc1).ok);
- T(repDb.save(repDoc2).ok);
-
- waitForSeq(dbA, dbB);
- for (var i = 0; i < docs1.length; i++) {
- var doc = docs1[i];
- var copy = dbB.open(doc._id);
- T(copy !== null);
- T(copy.value === doc.value);
- }
-
- repDoc1 = repDb.open("foo_dup_cont_rep_doc_1");
- T(repDoc1 !== null);
- T(repDoc1._replication_state === "triggered");
- T(typeof repDoc1._replication_state_time === "string");
- T(typeof repDoc1._replication_id === "string");
-
- repDoc2 = repDb.open("foo_dup_cont_rep_doc_2");
- T(repDoc2 !== null);
- T(typeof repDoc2._replication_state === "undefined");
- T(typeof repDoc2._replication_state_time === "undefined");
- T(repDoc2._replication_id === repDoc1._replication_id);
-
- var newDoc = {
- _id: "foo666",
- value: 999
- };
- T(dbA.save(newDoc).ok);
-
- waitForSeq(dbA, dbB);
- var copy = dbB.open("foo666");
- T(copy !== null);
- T(copy.value === 999);
-
- // deleting second replication doc, doesn't affect the 1st one and
- // neither it stops the replication
- T(repDb.deleteDoc(repDoc2).ok);
- repDoc1 = repDb.open("foo_dup_cont_rep_doc_1");
- T(repDoc1 !== null);
- T(repDoc1._replication_state === "triggered");
- T(typeof repDoc1._replication_state_time === "string");
-
- var newDoc2 = {
- _id: "foo5000",
- value: 5000
- };
- T(dbA.save(newDoc2).ok);
-
- waitForSeq(dbA, dbB);
- var copy = dbB.open("foo5000");
- T(copy !== null);
- T(copy.value === 5000);
-
- // deleting the 1st replication document stops the replication
- T(repDb.deleteDoc(repDoc1).ok);
- var newDoc3 = {
- _id: "foo1983",
- value: 1983
- };
- T(dbA.save(newDoc3).ok);
-
- wait(wait_rep_doc); //how to remove wait?
- var copy = dbB.open("foo1983");
- T(copy === null);
- }
-
-
- function test_replication_credentials_delegation() {
- populate_db(usersDb, []);
-
- var joeUserDoc = CouchDB.prepareUserDoc({
- name: "joe",
- roles: ["god", "erlanger"]
- }, "erly");
- T(usersDb.save(joeUserDoc).ok);
-
- var ddoc = {
- _id: "_design/beer",
- language: "javascript"
- };
- populate_db(dbA, docs1.concat([ddoc]));
- populate_db(dbB, []);
-
- T(dbB.setSecObj({
- admins: {
- names: [],
- roles: ["god"]
- }
- }).ok);
-
- var server_admins_config = [
- {
- section: "admins",
- key: "fdmanana",
- value: "qwerty"
- }
- ];
-
- run_on_modified_server(server_admins_config, function() {
-
- T(CouchDB.login("fdmanana", "qwerty").ok);
- T(CouchDB.session().userCtx.name === "fdmanana");
- T(CouchDB.session().userCtx.roles.indexOf("_admin") !== -1);
-
- var repDoc = {
- _id: "foo_rep_del_doc_1",
- source: dbA.name,
- target: dbB.name,
- user_ctx: {
- name: "joe",
- roles: ["erlanger"]
- }
- };
-
- T(repDb.save(repDoc).ok);
-
- waitForRep(repDb, repDoc, "completed");
- for (var i = 0; i < docs1.length; i++) {
- var doc = docs1[i];
- var copy = dbB.open(doc._id);
- T(copy !== null);
- T(copy.value === doc.value);
- }
-
- // design doc was not replicated, because joe is not an admin of db B
- var doc = dbB.open(ddoc._id);
- T(doc === null);
-
- // now test the same replication but putting the role "god" in the
- // delegation user context property
- var repDoc2 = {
- _id: "foo_rep_del_doc_2",
- source: dbA.name,
- target: dbB.name,
- user_ctx: {
- name: "joe",
- roles: ["erlanger", "god"]
- }
- };
- T(repDb.save(repDoc2).ok);
-
- waitForRep(repDb, repDoc2, "completed");
- for (var i = 0; i < docs1.length; i++) {
- var doc = docs1[i];
- var copy = dbB.open(doc._id);
- T(copy !== null);
- T(copy.value === doc.value);
- }
-
- // because anyone with a 'god' role is an admin of db B, a replication
- // that is delegated to a 'god' role can write design docs to db B
- doc = dbB.open(ddoc._id);
- T(doc !== null);
- T(doc.language === ddoc.language);
- });
- }
-
-
- function continuous_replication_survives_restart() {
- var origRepDbName = CouchDB.request(
- "GET", "/_config/replicator/db").responseText;
-
- repDb.deleteDb();
-
- var xhr = CouchDB.request("PUT", "/_config/replicator/db", {
- body : JSON.stringify(repDb.name),
- headers: {"X-Couch-Persist": "false"}
- });
- T(xhr.status === 200);
-
- populate_db(dbA, docs1);
- populate_db(dbB, []);
-
- var repDoc = {
- _id: "foo_cont_rep_survives_doc",
- source: "http://" + host + "/" + dbA.name,
- target: dbB.name,
- continuous: true
- };
-
- T(repDb.save(repDoc).ok);
-
- waitForSeq(dbA, dbB);
- for (var i = 0; i < docs1.length; i++) {
- var doc = docs1[i];
- var copy = dbB.open(doc._id);
- T(copy !== null);
- T(copy.value === doc.value);
- }
-
- repDb.ensureFullCommit();
- dbA.ensureFullCommit();
-
- restartServer();
-
- xhr = CouchDB.request("PUT", "/_config/replicator/db", {
- body : JSON.stringify(repDb.name),
- headers: {"X-Couch-Persist": "false"}
- });
-
- T(xhr.status === 200);
-
- // add another doc to source, it will be replicated to target
- var docX = {
- _id: "foo1000",
- value: 1001
- };
-
- T(dbA.save(docX).ok);
-
- waitForSeq(dbA, dbB);
- var copy = dbB.open("foo1000");
- T(copy !== null);
- T(copy.value === 1001);
-
- repDoc = waitForDocPos(repDb, "foo_cont_rep_survives_doc", 3);
- T(repDoc !== null);
- T(repDoc.continuous === true);
-
- // stop replication
- T(repDb.deleteDoc(repDoc).ok);
-
- xhr = CouchDB.request("PUT", "/_config/replicator/db", {
- body : origRepDbName,
- headers: {"X-Couch-Persist": "false"}
- });
- T(xhr.status === 200);
- }
-
-
- function rep_db_write_authorization() {
- populate_db(dbA, docs1);
- populate_db(dbB, []);
-
- var server_admins_config = [
- {
- section: "admins",
- key: "fdmanana",
- value: "qwerty"
- }
- ];
-
- run_on_modified_server(server_admins_config, function() {
- var repDoc = {
- _id: "foo_rep_doc",
- source: dbA.name,
- target: dbB.name,
- continuous: true
- };
-
- T(CouchDB.login("fdmanana", "qwerty").ok);
- T(CouchDB.session().userCtx.name === "fdmanana");
- T(CouchDB.session().userCtx.roles.indexOf("_admin") !== -1);
-
- T(repDb.save(repDoc).ok);
-
- waitForRep(repDb, repDoc, "completed");
-
- for (var i = 0; i < docs1.length; i++) {
- var doc = docs1[i];
- var copy = dbB.open(doc._id);
-
- T(copy !== null);
- T(copy.value === doc.value);
- }
-
- repDoc = repDb.open("foo_rep_doc");
- T(repDoc !== null);
- repDoc.target = "test_suite_foo_db";
- repDoc.create_target = true;
-
- // Only the replicator can update replication documents.
- // Admins can only add and delete replication documents.
- try {
- repDb.save(repDoc);
- T(false && "Should have thrown an exception");
- } catch (x) {
- T(x["error"] === "forbidden");
- }
- });
- }
-
-
- function test_user_ctx_validation() {
- populate_db(dbA, docs1);
- populate_db(dbB, []);
- populate_db(usersDb, []);
-
- var joeUserDoc = CouchDB.prepareUserDoc({
- name: "joe",
- roles: ["erlanger", "bar"]
- }, "erly");
- var fdmananaUserDoc = CouchDB.prepareUserDoc({
- name: "fdmanana",
- roles: ["a", "b", "c"]
- }, "qwerty");
-
- TEquals(true, usersDb.save(joeUserDoc).ok);
- TEquals(true, usersDb.save(fdmananaUserDoc).ok);
-
- T(dbB.setSecObj({
- admins: {
- names: [],
- roles: ["god"]
- },
- readers: {
- names: [],
- roles: ["foo"]
- }
- }).ok);
-
- TEquals(true, CouchDB.login("joe", "erly").ok);
- TEquals("joe", CouchDB.session().userCtx.name);
- TEquals(-1, CouchDB.session().userCtx.roles.indexOf("_admin"));
-
- var repDoc = {
- _id: "foo_rep",
- source: CouchDB.protocol + host + "/" + dbA.name,
- target: dbB.name
- };
-
- try {
- repDb.save(repDoc);
- T(false, "Should have failed, user_ctx missing.");
- } catch (x) {
- TEquals("forbidden", x.error);
- }
-
- repDoc.user_ctx = {
- name: "john",
- roles: ["erlanger"]
- };
-
- try {
- repDb.save(repDoc);
- T(false, "Should have failed, wrong user_ctx.name.");
- } catch (x) {
- TEquals("forbidden", x.error);
- }
-
- repDoc.user_ctx = {
- name: "joe",
- roles: ["bar", "god", "erlanger"]
- };
-
- try {
- repDb.save(repDoc);
- T(false, "Should have failed, a bad role in user_ctx.roles.");
- } catch (x) {
- TEquals("forbidden", x.error);
- }
-
- // user_ctx.roles might contain only a subset of the user's roles
- repDoc.user_ctx = {
- name: "joe",
- roles: ["erlanger"]
- };
-
- TEquals(true, repDb.save(repDoc).ok);
- CouchDB.logout();
-
- waitForRep(repDb, repDoc, "error");
- var repDoc1 = repDb.open(repDoc._id);
- T(repDoc1 !== null);
- TEquals(repDoc.source, repDoc1.source);
- TEquals(repDoc.target, repDoc1.target);
- TEquals("error", repDoc1._replication_state);
- TEquals("string", typeof repDoc1._replication_id);
- TEquals("string", typeof repDoc1._replication_state_time);
-
- TEquals(true, CouchDB.login("fdmanana", "qwerty").ok);
- TEquals("fdmanana", CouchDB.session().userCtx.name);
- TEquals(-1, CouchDB.session().userCtx.roles.indexOf("_admin"));
-
- try {
- T(repDb.deleteDoc(repDoc1).ok);
- T(false, "Shouldn't be able to delete replication document.");
- } catch (x) {
- TEquals("forbidden", x.error);
- }
-
- CouchDB.logout();
- TEquals(true, CouchDB.login("joe", "erly").ok);
- TEquals("joe", CouchDB.session().userCtx.name);
- TEquals(-1, CouchDB.session().userCtx.roles.indexOf("_admin"));
-
- T(repDb.deleteDoc(repDoc1).ok);
- CouchDB.logout();
-
- for (var i = 0; i < docs1.length; i++) {
- var doc = docs1[i];
- var copy = dbB.open(doc._id);
-
- TEquals(null, copy);
- }
-
- T(dbB.setSecObj({
- admins: {
- names: [],
- roles: ["god", "erlanger"]
- },
- readers: {
- names: [],
- roles: ["foo"]
- }
- }).ok);
-
- TEquals(true, CouchDB.login("joe", "erly").ok);
- TEquals("joe", CouchDB.session().userCtx.name);
- TEquals(-1, CouchDB.session().userCtx.roles.indexOf("_admin"));
-
- repDoc = {
- _id: "foo_rep_2",
- source: CouchDB.protocol + host + "/" + dbA.name,
- target: dbB.name,
- user_ctx: {
- name: "joe",
- roles: ["erlanger"]
- }
- };
-
- TEquals(true, repDb.save(repDoc).ok);
- CouchDB.logout();
-
- waitForRep(repDb, repDoc, "complete");
- repDoc1 = repDb.open(repDoc._id);
- T(repDoc1 !== null);
- TEquals(repDoc.source, repDoc1.source);
- TEquals(repDoc.target, repDoc1.target);
- TEquals("completed", repDoc1._replication_state);
- TEquals("string", typeof repDoc1._replication_id);
- TEquals("string", typeof repDoc1._replication_state_time);
-
- for (var i = 0; i < docs1.length; i++) {
- var doc = docs1[i];
- var copy = dbB.open(doc._id);
-
- T(copy !== null);
- TEquals(doc.value, copy.value);
- }
-
- // Admins don't need to supply a user_ctx property in replication docs.
- // If they do not, the implicit user_ctx "user_ctx": {name: null, roles: []}
- // is used, meaning that design documents will not be replicated into
- // local targets
- T(dbB.setSecObj({
- admins: {
- names: [],
- roles: []
- },
- readers: {
- names: [],
- roles: []
- }
- }).ok);
-
- var ddoc = { _id: "_design/foo" };
- TEquals(true, dbA.save(ddoc).ok);
-
- repDoc = {
- _id: "foo_rep_3",
- source: CouchDB.protocol + host + "/" + dbA.name,
- target: dbB.name
- };
-
- TEquals(true, repDb.save(repDoc).ok);
- waitForRep(repDb, repDoc, "complete");
- repDoc1 = repDb.open(repDoc._id);
- T(repDoc1 !== null);
- TEquals(repDoc.source, repDoc1.source);
- TEquals(repDoc.target, repDoc1.target);
- TEquals("completed", repDoc1._replication_state);
- TEquals("string", typeof repDoc1._replication_id);
- TEquals("string", typeof repDoc1._replication_state_time);
-
- var ddoc_copy = dbB.open(ddoc._id);
- T(ddoc_copy === null);
-
- repDoc = {
- _id: "foo_rep_4",
- source: CouchDB.protocol + host + "/" + dbA.name,
- target: dbB.name,
- user_ctx: {
- roles: ["_admin"]
- }
- };
-
- TEquals(true, repDb.save(repDoc).ok);
- waitForRep(repDb, repDoc, "complete");
- repDoc1 = repDb.open(repDoc._id);
- T(repDoc1 !== null);
- TEquals(repDoc.source, repDoc1.source);
- TEquals(repDoc.target, repDoc1.target);
- TEquals("completed", repDoc1._replication_state);
- TEquals("string", typeof repDoc1._replication_id);
- TEquals("string", typeof repDoc1._replication_state_time);
-
- ddoc_copy = dbB.open(ddoc._id);
- T(ddoc_copy !== null);
- }
-
-
- function rep_doc_with_bad_rep_id() {
- populate_db(dbA, docs1);
- populate_db(dbB, []);
-
- var repDoc = {
- _id: "foo_rep",
- source: dbA.name,
- target: dbB.name,
- replication_id: "1234abc"
- };
- T(repDb.save(repDoc).ok);
-
- waitForRep(repDb, repDoc, "completed");
- for (var i = 0; i < docs1.length; i++) {
- var doc = docs1[i];
- var copy = dbB.open(doc._id);
- T(copy !== null);
- T(copy.value === doc.value);
- }
-
- var repDoc1 = repDb.open(repDoc._id);
- T(repDoc1 !== null);
- T(repDoc1.source === repDoc.source);
- T(repDoc1.target === repDoc.target);
- T(repDoc1._replication_state === "completed",
- "replication document with bad replication id failed");
- T(typeof repDoc1._replication_state_time === "string");
- T(typeof repDoc1._replication_id === "string");
- T(repDoc1._replication_id !== "1234abc");
- }
-
-
- function swap_rep_db() {
- var repDb2 = new CouchDB("test_suite_rep_db_2");
- var dbA = new CouchDB("test_suite_rep_db_a");
- var dbA_copy = new CouchDB("test_suite_rep_db_a_copy");
- var dbB = new CouchDB("test_suite_rep_db_b");
- var dbB_copy = new CouchDB("test_suite_rep_db_b_copy");
- var dbC = new CouchDB("test_suite_rep_db_c");
- var dbC_copy = new CouchDB("test_suite_rep_db_c_copy");
- var repDoc1, repDoc2, repDoc3;
- var xhr, i, doc, copy, new_doc;
-
- populate_db(dbA, docs1);
- populate_db(dbB, docs1);
- populate_db(dbC, docs1);
- populate_db(dbA_copy, []);
- populate_db(dbB_copy, []);
- populate_db(dbC_copy, []);
- populate_db(repDb2, []);
-
- repDoc1 = {
- _id: "rep1",
- source: CouchDB.protocol + host + "/" + dbA.name,
- target: dbA_copy.name,
- continuous: true
- };
- repDoc2 = {
- _id: "rep2",
- source: CouchDB.protocol + host + "/" + dbB.name,
- target: dbB_copy.name,
- continuous: true
- };
- repDoc3 = {
- _id: "rep3",
- source: CouchDB.protocol + host + "/" + dbC.name,
- target: dbC_copy.name,
- continuous: true
- };
-
- TEquals(true, repDb.save(repDoc1).ok);
- TEquals(true, repDb.save(repDoc2).ok);
-
- waitForSeq(dbA, dbA_copy);
- waitForSeq(dbB, dbB_copy);
-
- xhr = CouchDB.request("PUT", "/_config/replicator/db",{
- body : JSON.stringify(repDb2.name),
- headers: {"X-Couch-Persist": "false"}
- });
- TEquals(200, xhr.status);
-
- new_doc = {
- _id: "foo666",
- value: 666
- };
-
- TEquals(true, dbA.save(new_doc).ok);
- TEquals(true, dbB.save(new_doc).ok);
- waitForSeq(dbA, dbA_copy);
- waitForSeq(dbB, dbB_copy);
-
- TEquals(true, repDb2.save(repDoc3).ok);
- waitForSeq(dbC, dbC_copy);
-
- for (i = 0; i < docs1.length; i++) {
- doc = docs1[i];
- copy = dbA_copy.open(doc._id);
- T(copy !== null);
- TEquals(doc.value, copy.value);
- copy = dbB_copy.open(doc._id);
- T(copy !== null);
- TEquals(doc.value, copy.value);
- copy = dbC_copy.open(doc._id);
- T(copy !== null);
- TEquals(doc.value, copy.value);
- }
-
- // replications rep1 and rep2 should have been stopped when the replicator
- // database was swapped
- copy = dbA_copy.open(new_doc._id);
- TEquals(null, copy);
- copy = dbB_copy.open(new_doc._id);
- TEquals(null, copy);
-
- xhr = CouchDB.request("PUT", "/_config/replicator/db",{
- body : JSON.stringify(repDb.name),
- headers: {"X-Couch-Persist": "false"}
- });
- TEquals(200, xhr.status);
-
- // after setting the replicator database to the former, replications rep1
- // and rep2 should have been resumed, while rep3 was stopped
- TEquals(true, dbC.save(new_doc).ok);
- wait(1000);
-
- waitForSeq(dbA, dbA_copy);
- waitForSeq(dbB, dbB_copy);
-
- copy = dbA_copy.open(new_doc._id);
- T(copy !== null);
- TEquals(new_doc.value, copy.value);
- copy = dbB_copy.open(new_doc._id);
- T(copy !== null);
- TEquals(new_doc.value, copy.value);
- copy = dbC_copy.open(new_doc._id);
- TEquals(null, copy);
- }
-
-
- function compact_rep_db() {
- var dbA_copy = new CouchDB("test_suite_rep_db_a_copy");
- var dbB_copy = new CouchDB("test_suite_rep_db_b_copy");
- var repDoc1, repDoc2;
- var xhr, i, doc, copy, new_doc;
- var docs = makeDocs(1, 50);
-
- populate_db(dbA, docs);
- populate_db(dbB, docs);
- populate_db(dbA_copy, []);
- populate_db(dbB_copy, []);
-
- repDoc1 = {
- _id: "rep1",
- source: CouchDB.protocol + host + "/" + dbA.name,
- target: dbA_copy.name,
- continuous: true
- };
- repDoc2 = {
- _id: "rep2",
- source: CouchDB.protocol + host + "/" + dbB.name,
- target: dbB_copy.name,
- continuous: true
- };
-
- TEquals(true, repDb.save(repDoc1).ok);
- TEquals(true, repDb.save(repDoc2).ok);
-
- TEquals(true, repDb.compact().ok);
- TEquals(202, repDb.last_req.status);
-
- waitForSeq(dbA, dbA_copy);
- waitForSeq(dbB, dbB_copy);
-
- while (repDb.info().compact_running) {};
-
- for (i = 0; i < docs.length; i++) {
- copy = dbA_copy.open(docs[i]._id);
- T(copy !== null);
- copy = dbB_copy.open(docs[i]._id);
- T(copy !== null);
- }
-
- new_doc = {
- _id: "foo666",
- value: 666
- };
-
- TEquals(true, dbA.save(new_doc).ok);
- TEquals(true, dbB.save(new_doc).ok);
-
- waitForSeq(dbA, dbA_copy);
- waitForSeq(dbB, dbB_copy);
-
- copy = dbA.open(new_doc._id);
- T(copy !== null);
- TEquals(666, copy.value);
- copy = dbB.open(new_doc._id);
- T(copy !== null);
- TEquals(666, copy.value);
- }
-
-
- function error_state_replication() {
- populate_db(dbA, docs1);
-
- var repDoc = {
- _id: "foo_error_rep",
- source: dbA.name,
- target: "nonexistent_test_db"
- };
- T(repDb.save(repDoc).ok);
-
- waitForRep(repDb, repDoc, "error");
- var repDoc1 = repDb.open(repDoc._id);
- T(repDoc1 !== null);
- T(repDoc1._replication_state === "error");
- T(typeof repDoc1._replication_state_time === "string");
- T(typeof repDoc1._replication_id === "string");
- }
-
-
- function rep_doc_field_validation() {
- var docs = makeDocs(1, 5);
-
- populate_db(dbA, docs);
- populate_db(dbB, []);
-
- var repDoc = {
- _id: "rep1",
- target: dbB.name
- };
-
- try {
- repDb.save(repDoc);
- T(false, "should have failed because source field is missing");
- } catch (x) {
- TEquals("forbidden", x.error);
- }
-
- repDoc = {
- _id: "rep1",
- source: 123,
- target: dbB.name
- };
-
- try {
- repDb.save(repDoc);
- T(false, "should have failed because source field is a number");
- } catch (x) {
- TEquals("forbidden", x.error);
- }
-
- repDoc = {
- _id: "rep1",
- source: dbA.name
- };
-
- try {
- repDb.save(repDoc);
- T(false, "should have failed because target field is missing");
- } catch (x) {
- TEquals("forbidden", x.error);
- }
-
- repDoc = {
- _id: "rep1",
- source: dbA.name,
- target: null
- };
-
- try {
- repDb.save(repDoc);
- T(false, "should have failed because target field is null");
- } catch (x) {
- TEquals("forbidden", x.error);
- }
-
- repDoc = {
- _id: "rep1",
- source: dbA.name,
- target: { url: 123 }
- };
-
- try {
- repDb.save(repDoc);
- T(false, "should have failed because target.url field is not a string");
- } catch (x) {
- TEquals("forbidden", x.error);
- }
-
- repDoc = {
- _id: "rep1",
- source: dbA.name,
- target: { url: dbB.name, auth: null }
- };
-
- try {
- repDb.save(repDoc);
- T(false, "should have failed because target.auth field is null");
- } catch (x) {
- TEquals("forbidden", x.error);
- }
-
- repDoc = {
- _id: "rep1",
- source: dbA.name,
- target: { url: dbB.name, auth: "foo:bar" }
- };
-
- try {
- repDb.save(repDoc);
- T(false, "should have failed because target.auth field is not an object");
- } catch (x) {
- TEquals("forbidden", x.error);
- }
-
- repDoc = {
- _id: "rep1",
- source: dbA.name,
- target: dbB.name,
- continuous: "true"
- };
-
- try {
- repDb.save(repDoc);
- T(false, "should have failed because continuous is not a boolean");
- } catch (x) {
- TEquals("forbidden", x.error);
- }
-
- repDoc = {
- _id: "rep1",
- source: dbA.name,
- target: dbB.name,
- filter: 123
- };
-
- try {
- repDb.save(repDoc);
- T(false, "should have failed because filter is not a string");
- } catch (x) {
- TEquals("forbidden", x.error);
- }
- }
-
-
- // run all the tests
- var server_config = [
- {
- section: "replicator",
- key: "db",
- value: repDb.name
- }
- ];
-
- repDb.deleteDb();
- run_on_modified_server(server_config, simple_replication);
-
- repDb.deleteDb();
- restartServer();
- run_on_modified_server(server_config, filtered_replication);
-
- repDb.deleteDb();
- restartServer();
- run_on_modified_server(server_config, continuous_replication);
-
- repDb.deleteDb();
- restartServer();
- run_on_modified_server(server_config, by_doc_ids_replication);
-
- repDb.deleteDb();
- restartServer();
- run_on_modified_server(server_config, successive_identical_replications);
-
- repDb.deleteDb();
- restartServer();
- run_on_modified_server(server_config, identical_rep_docs);
-
- repDb.deleteDb();
- restartServer();
- run_on_modified_server(server_config, identical_continuous_rep_docs);
-
- repDb.deleteDb();
- restartServer();
- run_on_modified_server(server_config, rep_db_write_authorization);
-
- repDb.deleteDb();
- restartServer();
- run_on_modified_server(server_config, rep_doc_with_bad_rep_id);
-
- var server_config_2 = server_config.concat([
- {
- section: "couch_httpd_auth",
- key: "authentication_db",
- value: usersDb.name
- }
- ]);
-
- repDb.deleteDb();
- restartServer();
- run_on_modified_server(server_config_2, test_user_ctx_validation);
-
- repDb.deleteDb();
- restartServer();
- run_on_modified_server(server_config_2, test_replication_credentials_delegation);
-
- repDb.deleteDb();
- restartServer();
- continuous_replication_survives_restart();
-
- repDb.deleteDb();
- restartServer();
- run_on_modified_server(server_config, swap_rep_db);
-
- repDb.deleteDb();
- restartServer();
- run_on_modified_server(server_config, compact_rep_db);
-
- repDb.deleteDb();
- restartServer();
- run_on_modified_server(server_config, rep_doc_field_validation);
-
-/*
- * Disabled, since error state would be set on the document only after
- * the exponential backoff retry done by the replicator database listener
- * terminates, which takes too much time for a unit test.
- */
-/*
- * repDb.deleteDb();
- * restartServer();
- * run_on_modified_server(server_config, error_state_replication);
- */
-
-
- // cleanup
- repDb.deleteDb();
- usersDb.deleteDb();
- dbA.deleteDb();
- dbB.deleteDb();
- (new CouchDB("test_suite_rep_db_2")).deleteDb();
- (new CouchDB("test_suite_rep_db_c")).deleteDb();
- (new CouchDB("test_suite_rep_db_a_copy")).deleteDb();
- (new CouchDB("test_suite_rep_db_b_copy")).deleteDb();
- (new CouchDB("test_suite_rep_db_c_copy")).deleteDb();
-};
diff --git a/share/www/style/jquery-ui-1.8.11.custom.css b/share/www/style/jquery-ui-1.8.11.custom.css
deleted file mode 100644
index a6b2f744..00000000
--- a/share/www/style/jquery-ui-1.8.11.custom.css
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * jQuery UI CSS Framework 1.8.11
- *
- * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
- * Dual licensed under the MIT or GPL Version 2 licenses.
- * http://jquery.org/license
- *
- * http://docs.jquery.com/UI/Theming/API
- */
-
-/* Layout helpers
-----------------------------------*/
-.ui-helper-hidden { display: none; }
-.ui-helper-hidden-accessible { position: absolute !important; clip: rect(1px 1px 1px 1px); clip: rect(1px,1px,1px,1px); }
-.ui-helper-reset { margin: 0; padding: 0; border: 0; outline: 0; line-height: 1.3; text-decoration: none; font-size: 100%; list-style: none; }
-.ui-helper-clearfix:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
-.ui-helper-clearfix { display: inline-block; }
-/* required comment for clearfix to work in Opera \*/
-* html .ui-helper-clearfix { height:1%; }
-.ui-helper-clearfix { display:block; }
-/* end clearfix */
-.ui-helper-zfix { width: 100%; height: 100%; top: 0; left: 0; position: absolute; opacity: 0; filter:Alpha(Opacity=0); }
-
-
-/* Interaction Cues
-----------------------------------*/
-.ui-state-disabled { cursor: default !important; }
-
-
-/* Icons
-----------------------------------*/
-
-/* states and images */
-.ui-icon { display: block; text-indent: -99999px; overflow: hidden; background-repeat: no-repeat; }
-
-
-/* Misc visuals
-----------------------------------*/
-
-/* Overlays */
-.ui-widget-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
-
-
-/*
- * jQuery UI CSS Framework 1.8.11
- *
- * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
- * Dual licensed under the MIT or GPL Version 2 licenses.
- * http://jquery.org/license
- *
- * http://docs.jquery.com/UI/Theming/API
- *
- * To view and modify this theme, visit http://jqueryui.com/themeroller/?ffDefault=Trebuchet%20MS,%20Tahoma,%20Verdana,%20Arial,%20sans-serif&fwDefault=bold&fsDefault=1.1em&cornerRadius=4px&bgColorHeader=f6a828&bgTextureHeader=12_gloss_wave.png&bgImgOpacityHeader=35&borderColorHeader=e78f08&fcHeader=ffffff&iconColorHeader=ffffff&bgColorContent=eeeeee&bgTextureContent=03_highlight_soft.png&bgImgOpacityContent=100&borderColorContent=dddddd&fcContent=333333&iconColorContent=222222&bgColorDefault=f6f6f6&bgTextureDefault=02_glass.png&bgImgOpacityDefault=100&borderColorDefault=cccccc&fcDefault=1c94c4&iconColorDefault=ef8c08&bgColorHover=fdf5ce&bgTextureHover=02_glass.png&bgImgOpacityHover=100&borderColorHover=fbcb09&fcHover=c77405&iconColorHover=ef8c08&bgColorActive=ffffff&bgTextureActive=02_glass.png&bgImgOpacityActive=65&borderColorActive=fbd850&fcActive=eb8f00&iconColorActive=ef8c08&bgColorHighlight=ffe45c&bgTextureHighlight=03_highlight_soft.png&bgImgOpacityHighlight=75&borderColorHighlight=fed22f&fcHighlight=363636&iconColorHighlight=228ef1&bgColorError=b81900&bgTextureError=08_diagonals_thick.png&bgImgOpacityError=18&borderColorError=cd0a0a&fcError=ffffff&iconColorError=ffd27a&bgColorOverlay=666666&bgTextureOverlay=08_diagonals_thick.png&bgImgOpacityOverlay=20&opacityOverlay=50&bgColorShadow=000000&bgTextureShadow=01_flat.png&bgImgOpacityShadow=10&opacityShadow=20&thicknessShadow=5px&offsetTopShadow=-5px&offsetLeftShadow=-5px&cornerRadiusShadow=5px
- */
-
-
-/* Component containers
-----------------------------------*/
-.ui-widget { font-family: Trebuchet MS, Tahoma, Verdana, Arial, sans-serif; font-size: 1.1em; }
-.ui-widget .ui-widget { font-size: 1em; }
-.ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button { font-family: Trebuchet MS, Tahoma, Verdana, Arial, sans-serif; font-size: 1em; }
-.ui-widget-content { border: 1px solid #dddddd; background: #eeeeee 50% top repeat-x; color: #333333; }
-.ui-widget-content a { color: #333333; }
-.ui-widget-header { border: 1px solid #e78f08; background: #f6a828 50% 50% repeat-x; color: #ffffff; font-weight: bold; }
-.ui-widget-header a { color: #ffffff; }
-
-/* Interaction states
-----------------------------------*/
-.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #cccccc; background: #f6f6f6 50% 50% repeat-x; font-weight: bold; color: #1c94c4; }
-.ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited { color: #1c94c4; text-decoration: none; }
-.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { border: 1px solid #fbcb09; background: #fdf5ce 50% 50% repeat-x; font-weight: bold; color: #c77405; }
-.ui-state-hover a, .ui-state-hover a:hover { color: #c77405; text-decoration: none; }
-.ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #fbd850; background: #ffffff 50% 50% repeat-x; font-weight: bold; color: #eb8f00; }
-.ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #eb8f00; text-decoration: none; }
-.ui-widget :active { outline: none; }
-
-/* Interaction Cues
-----------------------------------*/
-.ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {border: 1px solid #fed22f; background: #ffe45c 50% top repeat-x; color: #363636; }
-.ui-state-highlight a, .ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a { color: #363636; }
-.ui-state-error, .ui-widget-content .ui-state-error, .ui-widget-header .ui-state-error {border: 1px solid #cd0a0a; background: #b81900 50% 50% repeat; color: #ffffff; }
-.ui-state-error a, .ui-widget-content .ui-state-error a, .ui-widget-header .ui-state-error a { color: #ffffff; }
-.ui-state-error-text, .ui-widget-content .ui-state-error-text, .ui-widget-header .ui-state-error-text { color: #ffffff; }
-.ui-priority-primary, .ui-widget-content .ui-priority-primary, .ui-widget-header .ui-priority-primary { font-weight: bold; }
-.ui-priority-secondary, .ui-widget-content .ui-priority-secondary, .ui-widget-header .ui-priority-secondary { opacity: .7; filter:Alpha(Opacity=70); font-weight: normal; }
-.ui-state-disabled, .ui-widget-content .ui-state-disabled, .ui-widget-header .ui-state-disabled { opacity: .35; filter:Alpha(Opacity=35); background-image: none; }
-
-/* Icons
-----------------------------------*/
-
-/* states and images */
-.ui-icon { width: 16px; height: 16px; background-image: url(images/ui-icons_222222_256x240.png); }
-.ui-widget-content .ui-icon {background-image: url(images/ui-icons_222222_256x240.png); }
-.ui-widget-header .ui-icon {background-image: url(images/ui-icons_ffffff_256x240.png); }
-.ui-state-default .ui-icon { background-image: url(images/ui-icons_ef8c08_256x240.png); }
-.ui-state-hover .ui-icon, .ui-state-focus .ui-icon {background-image: url(images/ui-icons_ef8c08_256x240.png); }
-.ui-state-active .ui-icon {background-image: url(images/ui-icons_ef8c08_256x240.png); }
-.ui-state-highlight .ui-icon {background-image: url(images/ui-icons_228ef1_256x240.png); }
-.ui-state-error .ui-icon, .ui-state-error-text .ui-icon {background-image: url(images/ui-icons_ffd27a_256x240.png); }
-
-/* positioning */
-.ui-icon-carat-1-n { background-position: 0 0; }
-.ui-icon-carat-1-ne { background-position: -16px 0; }
-.ui-icon-carat-1-e { background-position: -32px 0; }
-.ui-icon-carat-1-se { background-position: -48px 0; }
-.ui-icon-carat-1-s { background-position: -64px 0; }
-.ui-icon-carat-1-sw { background-position: -80px 0; }
-.ui-icon-carat-1-w { background-position: -96px 0; }
-.ui-icon-carat-1-nw { background-position: -112px 0; }
-.ui-icon-carat-2-n-s { background-position: -128px 0; }
-.ui-icon-carat-2-e-w { background-position: -144px 0; }
-.ui-icon-triangle-1-n { background-position: 0 -16px; }
-.ui-icon-triangle-1-ne { background-position: -16px -16px; }
-.ui-icon-triangle-1-e { background-position: -32px -16px; }
-.ui-icon-triangle-1-se { background-position: -48px -16px; }
-.ui-icon-triangle-1-s { background-position: -64px -16px; }
-.ui-icon-triangle-1-sw { background-position: -80px -16px; }
-.ui-icon-triangle-1-w { background-position: -96px -16px; }
-.ui-icon-triangle-1-nw { background-position: -112px -16px; }
-.ui-icon-triangle-2-n-s { background-position: -128px -16px; }
-.ui-icon-triangle-2-e-w { background-position: -144px -16px; }
-.ui-icon-arrow-1-n { background-position: 0 -32px; }
-.ui-icon-arrow-1-ne { background-position: -16px -32px; }
-.ui-icon-arrow-1-e { background-position: -32px -32px; }
-.ui-icon-arrow-1-se { background-position: -48px -32px; }
-.ui-icon-arrow-1-s { background-position: -64px -32px; }
-.ui-icon-arrow-1-sw { background-position: -80px -32px; }
-.ui-icon-arrow-1-w { background-position: -96px -32px; }
-.ui-icon-arrow-1-nw { background-position: -112px -32px; }
-.ui-icon-arrow-2-n-s { background-position: -128px -32px; }
-.ui-icon-arrow-2-ne-sw { background-position: -144px -32px; }
-.ui-icon-arrow-2-e-w { background-position: -160px -32px; }
-.ui-icon-arrow-2-se-nw { background-position: -176px -32px; }
-.ui-icon-arrowstop-1-n { background-position: -192px -32px; }
-.ui-icon-arrowstop-1-e { background-position: -208px -32px; }
-.ui-icon-arrowstop-1-s { background-position: -224px -32px; }
-.ui-icon-arrowstop-1-w { background-position: -240px -32px; }
-.ui-icon-arrowthick-1-n { background-position: 0 -48px; }
-.ui-icon-arrowthick-1-ne { background-position: -16px -48px; }
-.ui-icon-arrowthick-1-e { background-position: -32px -48px; }
-.ui-icon-arrowthick-1-se { background-position: -48px -48px; }
-.ui-icon-arrowthick-1-s { background-position: -64px -48px; }
-.ui-icon-arrowthick-1-sw { background-position: -80px -48px; }
-.ui-icon-arrowthick-1-w { background-position: -96px -48px; }
-.ui-icon-arrowthick-1-nw { background-position: -112px -48px; }
-.ui-icon-arrowthick-2-n-s { background-position: -128px -48px; }
-.ui-icon-arrowthick-2-ne-sw { background-position: -144px -48px; }
-.ui-icon-arrowthick-2-e-w { background-position: -160px -48px; }
-.ui-icon-arrowthick-2-se-nw { background-position: -176px -48px; }
-.ui-icon-arrowthickstop-1-n { background-position: -192px -48px; }
-.ui-icon-arrowthickstop-1-e { background-position: -208px -48px; }
-.ui-icon-arrowthickstop-1-s { background-position: -224px -48px; }
-.ui-icon-arrowthickstop-1-w { background-position: -240px -48px; }
-.ui-icon-arrowreturnthick-1-w { background-position: 0 -64px; }
-.ui-icon-arrowreturnthick-1-n { background-position: -16px -64px; }
-.ui-icon-arrowreturnthick-1-e { background-position: -32px -64px; }
-.ui-icon-arrowreturnthick-1-s { background-position: -48px -64px; }
-.ui-icon-arrowreturn-1-w { background-position: -64px -64px; }
-.ui-icon-arrowreturn-1-n { background-position: -80px -64px; }
-.ui-icon-arrowreturn-1-e { background-position: -96px -64px; }
-.ui-icon-arrowreturn-1-s { background-position: -112px -64px; }
-.ui-icon-arrowrefresh-1-w { background-position: -128px -64px; }
-.ui-icon-arrowrefresh-1-n { background-position: -144px -64px; }
-.ui-icon-arrowrefresh-1-e { background-position: -160px -64px; }
-.ui-icon-arrowrefresh-1-s { background-position: -176px -64px; }
-.ui-icon-arrow-4 { background-position: 0 -80px; }
-.ui-icon-arrow-4-diag { background-position: -16px -80px; }
-.ui-icon-extlink { background-position: -32px -80px; }
-.ui-icon-newwin { background-position: -48px -80px; }
-.ui-icon-refresh { background-position: -64px -80px; }
-.ui-icon-shuffle { background-position: -80px -80px; }
-.ui-icon-transfer-e-w { background-position: -96px -80px; }
-.ui-icon-transferthick-e-w { background-position: -112px -80px; }
-.ui-icon-folder-collapsed { background-position: 0 -96px; }
-.ui-icon-folder-open { background-position: -16px -96px; }
-.ui-icon-document { background-position: -32px -96px; }
-.ui-icon-document-b { background-position: -48px -96px; }
-.ui-icon-note { background-position: -64px -96px; }
-.ui-icon-mail-closed { background-position: -80px -96px; }
-.ui-icon-mail-open { background-position: -96px -96px; }
-.ui-icon-suitcase { background-position: -112px -96px; }
-.ui-icon-comment { background-position: -128px -96px; }
-.ui-icon-person { background-position: -144px -96px; }
-.ui-icon-print { background-position: -160px -96px; }
-.ui-icon-trash { background-position: -176px -96px; }
-.ui-icon-locked { background-position: -192px -96px; }
-.ui-icon-unlocked { background-position: -208px -96px; }
-.ui-icon-bookmark { background-position: -224px -96px; }
-.ui-icon-tag { background-position: -240px -96px; }
-.ui-icon-home { background-position: 0 -112px; }
-.ui-icon-flag { background-position: -16px -112px; }
-.ui-icon-calendar { background-position: -32px -112px; }
-.ui-icon-cart { background-position: -48px -112px; }
-.ui-icon-pencil { background-position: -64px -112px; }
-.ui-icon-clock { background-position: -80px -112px; }
-.ui-icon-disk { background-position: -96px -112px; }
-.ui-icon-calculator { background-position: -112px -112px; }
-.ui-icon-zoomin { background-position: -128px -112px; }
-.ui-icon-zoomout { background-position: -144px -112px; }
-.ui-icon-search { background-position: -160px -112px; }
-.ui-icon-wrench { background-position: -176px -112px; }
-.ui-icon-gear { background-position: -192px -112px; }
-.ui-icon-heart { background-position: -208px -112px; }
-.ui-icon-star { background-position: -224px -112px; }
-.ui-icon-link { background-position: -240px -112px; }
-.ui-icon-cancel { background-position: 0 -128px; }
-.ui-icon-plus { background-position: -16px -128px; }
-.ui-icon-plusthick { background-position: -32px -128px; }
-.ui-icon-minus { background-position: -48px -128px; }
-.ui-icon-minusthick { background-position: -64px -128px; }
-.ui-icon-close { background-position: -80px -128px; }
-.ui-icon-closethick { background-position: -96px -128px; }
-.ui-icon-key { background-position: -112px -128px; }
-.ui-icon-lightbulb { background-position: -128px -128px; }
-.ui-icon-scissors { background-position: -144px -128px; }
-.ui-icon-clipboard { background-position: -160px -128px; }
-.ui-icon-copy { background-position: -176px -128px; }
-.ui-icon-contact { background-position: -192px -128px; }
-.ui-icon-image { background-position: -208px -128px; }
-.ui-icon-video { background-position: -224px -128px; }
-.ui-icon-script { background-position: -240px -128px; }
-.ui-icon-alert { background-position: 0 -144px; }
-.ui-icon-info { background-position: -16px -144px; }
-.ui-icon-notice { background-position: -32px -144px; }
-.ui-icon-help { background-position: -48px -144px; }
-.ui-icon-check { background-position: -64px -144px; }
-.ui-icon-bullet { background-position: -80px -144px; }
-.ui-icon-radio-off { background-position: -96px -144px; }
-.ui-icon-radio-on { background-position: -112px -144px; }
-.ui-icon-pin-w { background-position: -128px -144px; }
-.ui-icon-pin-s { background-position: -144px -144px; }
-.ui-icon-play { background-position: 0 -160px; }
-.ui-icon-pause { background-position: -16px -160px; }
-.ui-icon-seek-next { background-position: -32px -160px; }
-.ui-icon-seek-prev { background-position: -48px -160px; }
-.ui-icon-seek-end { background-position: -64px -160px; }
-.ui-icon-seek-start { background-position: -80px -160px; }
-/* ui-icon-seek-first is deprecated, use ui-icon-seek-start instead */
-.ui-icon-seek-first { background-position: -80px -160px; }
-.ui-icon-stop { background-position: -96px -160px; }
-.ui-icon-eject { background-position: -112px -160px; }
-.ui-icon-volume-off { background-position: -128px -160px; }
-.ui-icon-volume-on { background-position: -144px -160px; }
-.ui-icon-power { background-position: 0 -176px; }
-.ui-icon-signal-diag { background-position: -16px -176px; }
-.ui-icon-signal { background-position: -32px -176px; }
-.ui-icon-battery-0 { background-position: -48px -176px; }
-.ui-icon-battery-1 { background-position: -64px -176px; }
-.ui-icon-battery-2 { background-position: -80px -176px; }
-.ui-icon-battery-3 { background-position: -96px -176px; }
-.ui-icon-circle-plus { background-position: 0 -192px; }
-.ui-icon-circle-minus { background-position: -16px -192px; }
-.ui-icon-circle-close { background-position: -32px -192px; }
-.ui-icon-circle-triangle-e { background-position: -48px -192px; }
-.ui-icon-circle-triangle-s { background-position: -64px -192px; }
-.ui-icon-circle-triangle-w { background-position: -80px -192px; }
-.ui-icon-circle-triangle-n { background-position: -96px -192px; }
-.ui-icon-circle-arrow-e { background-position: -112px -192px; }
-.ui-icon-circle-arrow-s { background-position: -128px -192px; }
-.ui-icon-circle-arrow-w { background-position: -144px -192px; }
-.ui-icon-circle-arrow-n { background-position: -160px -192px; }
-.ui-icon-circle-zoomin { background-position: -176px -192px; }
-.ui-icon-circle-zoomout { background-position: -192px -192px; }
-.ui-icon-circle-check { background-position: -208px -192px; }
-.ui-icon-circlesmall-plus { background-position: 0 -208px; }
-.ui-icon-circlesmall-minus { background-position: -16px -208px; }
-.ui-icon-circlesmall-close { background-position: -32px -208px; }
-.ui-icon-squaresmall-plus { background-position: -48px -208px; }
-.ui-icon-squaresmall-minus { background-position: -64px -208px; }
-.ui-icon-squaresmall-close { background-position: -80px -208px; }
-.ui-icon-grip-dotted-vertical { background-position: 0 -224px; }
-.ui-icon-grip-dotted-horizontal { background-position: -16px -224px; }
-.ui-icon-grip-solid-vertical { background-position: -32px -224px; }
-.ui-icon-grip-solid-horizontal { background-position: -48px -224px; }
-.ui-icon-gripsmall-diagonal-se { background-position: -64px -224px; }
-.ui-icon-grip-diagonal-se { background-position: -80px -224px; }
-
-
-/* Misc visuals
-----------------------------------*/
-
-/* Corner radius */
-.ui-corner-tl { -moz-border-radius-topleft: 4px; -webkit-border-top-left-radius: 4px; border-top-left-radius: 4px; }
-.ui-corner-tr { -moz-border-radius-topright: 4px; -webkit-border-top-right-radius: 4px; border-top-right-radius: 4px; }
-.ui-corner-bl { -moz-border-radius-bottomleft: 4px; -webkit-border-bottom-left-radius: 4px; border-bottom-left-radius: 4px; }
-.ui-corner-br { -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 4px; border-bottom-right-radius: 4px; }
-.ui-corner-top { -moz-border-radius-topleft: 4px; -webkit-border-top-left-radius: 4px; border-top-left-radius: 4px; -moz-border-radius-topright: 4px; -webkit-border-top-right-radius: 4px; border-top-right-radius: 4px; }
-.ui-corner-bottom { -moz-border-radius-bottomleft: 4px; -webkit-border-bottom-left-radius: 4px; border-bottom-left-radius: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 4px; border-bottom-right-radius: 4px; }
-.ui-corner-right { -moz-border-radius-topright: 4px; -webkit-border-top-right-radius: 4px; border-top-right-radius: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 4px; border-bottom-right-radius: 4px; }
-.ui-corner-left { -moz-border-radius-topleft: 4px; -webkit-border-top-left-radius: 4px; border-top-left-radius: 4px; -moz-border-radius-bottomleft: 4px; -webkit-border-bottom-left-radius: 4px; border-bottom-left-radius: 4px; }
-.ui-corner-all { -moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px; }
-
-/* Overlays */
-.ui-widget-overlay { background: #666666 50% 50% repeat; opacity: .50;filter:Alpha(Opacity=50); }
-.ui-widget-shadow { margin: -5px 0 0 -5px; padding: 5px; background: #000000 50% 50% repeat-x; opacity: .20;filter:Alpha(Opacity=20); -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; }/*
- * jQuery UI Autocomplete 1.8.11
- *
- * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
- * Dual licensed under the MIT or GPL Version 2 licenses.
- * http://jquery.org/license
- *
- * http://docs.jquery.com/UI/Autocomplete#theming
- */
-.ui-autocomplete { position: absolute; cursor: default; }
-
-/* workarounds */
-* html .ui-autocomplete { width:1px; } /* without this, the menu expands to 100% in IE6 */
-
-/*
- * jQuery UI Menu 1.8.11
- *
- * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
- * Dual licensed under the MIT or GPL Version 2 licenses.
- * http://jquery.org/license
- *
- * http://docs.jquery.com/UI/Menu#theming
- */
-.ui-menu {
- list-style:none;
- padding: 2px;
- margin: 0;
- display:block;
- float: left;
-}
-.ui-menu .ui-menu {
- margin-top: -3px;
-}
-.ui-menu .ui-menu-item {
- margin:0;
- padding: 0;
- zoom: 1;
- float: left;
- clear: left;
- width: 100%;
-}
-.ui-menu .ui-menu-item a {
- text-decoration:none;
- display:block;
- padding:.2em .4em;
- line-height:1.5;
- zoom:1;
-}
-.ui-menu .ui-menu-item a.ui-state-hover,
-.ui-menu .ui-menu-item a.ui-state-active {
- font-weight: normal;
- margin: -1px;
-}
diff --git a/src/Makefile.am b/src/Makefile.am
deleted file mode 100644
index b9529f94..00000000
--- a/src/Makefile.am
+++ /dev/null
@@ -1,13 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-SUBDIRS = couchdb erlang-oauth etap ibrowse mochiweb
diff --git a/src/couchdb/Makefile.am b/src/couchdb/Makefile.am
deleted file mode 100644
index 92f6dcf6..00000000
--- a/src/couchdb/Makefile.am
+++ /dev/null
@@ -1,209 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-SUBDIRS = priv
-
-# devdocdir = $(localdocdir)/developer/couchdb
-couchlibdir = $(localerlanglibdir)/couch-$(version)
-couchincludedir = $(couchlibdir)/include
-couchebindir = $(couchlibdir)/ebin
-
-couchinclude_DATA = couch_db.hrl couch_js_functions.hrl
-couchebin_DATA = $(compiled_files)
-
-# dist_devdoc_DATA = $(doc_base) $(doc_modules)
-
-CLEANFILES = $(compiled_files) $(doc_base)
-
-# CLEANFILES = $(doc_modules) edoc-info
-
-source_files = \
- couch.erl \
- couch_app.erl \
- couch_auth_cache.erl \
- couch_btree.erl \
- couch_changes.erl \
- couch_config.erl \
- couch_config_writer.erl \
- couch_db.erl \
- couch_db_update_notifier.erl \
- couch_db_update_notifier_sup.erl \
- couch_doc.erl \
- couch_event_sup.erl \
- couch_external_manager.erl \
- couch_external_server.erl \
- couch_file.erl \
- couch_httpd.erl \
- couch_httpd_db.erl \
- couch_httpd_auth.erl \
- couch_httpd_oauth.erl \
- couch_httpd_external.erl \
- couch_httpd_show.erl \
- couch_httpd_view.erl \
- couch_httpd_misc_handlers.erl \
- couch_httpd_proxy.erl \
- couch_httpd_rewrite.erl \
- couch_httpd_stats_handlers.erl \
- couch_httpd_vhost.erl \
- couch_key_tree.erl \
- couch_log.erl \
- couch_native_process.erl \
- couch_os_daemons.erl \
- couch_os_process.erl \
- couch_query_servers.erl \
- couch_ref_counter.erl \
- couch_rep.erl \
- couch_rep_att.erl \
- couch_rep_changes_feed.erl \
- couch_rep_httpc.erl \
- couch_rep_missing_revs.erl \
- couch_rep_reader.erl \
- couch_rep_sup.erl \
- couch_rep_writer.erl \
- couch_replication_manager.erl \
- couch_server.erl \
- couch_server_sup.erl \
- couch_stats_aggregator.erl \
- couch_stats_collector.erl \
- couch_stream.erl \
- couch_task_status.erl \
- couch_util.erl \
- couch_uuids.erl \
- couch_view.erl \
- couch_view_compactor.erl \
- couch_view_updater.erl \
- couch_view_group.erl \
- couch_db_updater.erl \
- couch_work_queue.erl
-
-EXTRA_DIST = $(source_files) couch_db.hrl couch_js_functions.hrl
-
-compiled_files = \
- couch.app \
- couch.beam \
- couch_app.beam \
- couch_auth_cache.beam \
- couch_btree.beam \
- couch_changes.beam \
- couch_config.beam \
- couch_config_writer.beam \
- couch_db.beam \
- couch_db_update_notifier.beam \
- couch_db_update_notifier_sup.beam \
- couch_doc.beam \
- couch_event_sup.beam \
- couch_external_manager.beam \
- couch_external_server.beam \
- couch_file.beam \
- couch_httpd.beam \
- couch_httpd_db.beam \
- couch_httpd_auth.beam \
- couch_httpd_oauth.beam \
- couch_httpd_proxy.beam \
- couch_httpd_external.beam \
- couch_httpd_show.beam \
- couch_httpd_view.beam \
- couch_httpd_misc_handlers.beam \
- couch_httpd_rewrite.beam \
- couch_httpd_stats_handlers.beam \
- couch_httpd_vhost.beam \
- couch_key_tree.beam \
- couch_log.beam \
- couch_native_process.beam \
- couch_os_daemons.beam \
- couch_os_process.beam \
- couch_query_servers.beam \
- couch_ref_counter.beam \
- couch_rep.beam \
- couch_rep_att.beam \
- couch_rep_changes_feed.beam \
- couch_rep_httpc.beam \
- couch_rep_missing_revs.beam \
- couch_rep_reader.beam \
- couch_rep_sup.beam \
- couch_rep_writer.beam \
- couch_replication_manager.beam \
- couch_server.beam \
- couch_server_sup.beam \
- couch_stats_aggregator.beam \
- couch_stats_collector.beam \
- couch_stream.beam \
- couch_task_status.beam \
- couch_util.beam \
- couch_uuids.beam \
- couch_view.beam \
- couch_view_compactor.beam \
- couch_view_updater.beam \
- couch_view_group.beam \
- couch_db_updater.beam \
- couch_work_queue.beam
-
-# doc_base = \
-# erlang.png \
-# index.html \
-# modules-frame.html \
-# overview-summary.html \
-# packages-frame.html \
-# stylesheet.css
-
-# doc_modules = \
-# couch_btree.html \
-# couch_config.html \
-# couch_config_writer.html \
-# couch_db.html \
-# couch_db_update_notifier.html \
-# couch_db_update_notifier_sup.html \
-# couch_doc.html \
-# couch_event_sup.html \
-# couch_file.html \
-# couch_httpd.html \
-# couch_key_tree.html \
-# couch_log.html \
-# couch_query_servers.html \
-# couch_rep.html \
-# couch_rep_sup.html \
-# couch_server.html \
-# couch_server_sup.html \
-# couch_stream.html \
-# couch_util.html \
-# couch_view.html
-
-if WINDOWS
-couch.app: couch.app.tpl
- modules=`find . -name "couch*.erl" -exec basename {} .erl \; | tr '\n' ',' | sed "s/,$$//"`; \
- sed -e "s|%package_name%|@package_name@|g" \
- -e "s|%version%|@version@|g" \
- -e "s|@modules@|$$modules|g" \
- -e "s|%localconfdir%|../etc/couchdb|g" \
- -e "s|@defaultini@|default.ini|g" \
- -e "s|@localini@|local.ini|g" > \
- $@ < $<
-else
-couch.app: couch.app.tpl
- modules=`{ find . -name "*.erl" -exec basename {} .erl \; | tr '\n' ','; echo ''; } | sed "s/,$$//"`; \
- sed -e "s|%package_name%|@package_name@|g" \
- -e "s|%version%|@version@|g" \
- -e "s|@modules@|$$modules|g" \
- -e "s|%localconfdir%|@localconfdir@|g" \
- -e "s|@defaultini@|default.ini|g" \
- -e "s|@localini@|local.ini|g" > \
- $@ < $<
- chmod +x $@
-endif
-
-# $(dist_devdoc_DATA): edoc-info
-
-# $(ERL) -noshell -run edoc_run files [\"$<\"]
-
-%.beam: %.erl couch_db.hrl couch_js_functions.hrl
- $(ERLC) $(ERLC_FLAGS) ${TEST} $<;
-
diff --git a/src/couchdb/couch_query_servers.erl b/src/couchdb/couch_query_servers.erl
deleted file mode 100644
index b0e46937..00000000
--- a/src/couchdb/couch_query_servers.erl
+++ /dev/null
@@ -1,589 +0,0 @@
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
--module(couch_query_servers).
--behaviour(gen_server).
-
--export([start_link/0]).
-
--export([init/1, terminate/2, handle_call/3, handle_cast/2, handle_info/2,code_change/3]).
--export([start_doc_map/3, map_docs/2, stop_doc_map/1]).
--export([reduce/3, rereduce/3,validate_doc_update/5]).
--export([filter_docs/5]).
-
--export([with_ddoc_proc/2, proc_prompt/2, ddoc_prompt/3, ddoc_proc_prompt/3, json_doc/1]).
-
-% -export([test/0]).
-
--include("couch_db.hrl").
-
--record(proc, {
- pid,
- lang,
- ddoc_keys = [],
- prompt_fun,
- set_timeout_fun,
- stop_fun
-}).
-
--record(qserver, {
- langs, % Keyed by language name, value is {Mod,Func,Arg}
- pid_procs, % Keyed by PID, valus is a #proc record.
- lang_procs, % Keyed by language name, value is a #proc record
- lang_limits, % Keyed by language name, value is {Lang, Limit, Current}
- waitlist = [],
- config
-}).
-
-start_link() ->
- gen_server:start_link({local, couch_query_servers}, couch_query_servers, [], []).
-
-start_doc_map(Lang, Functions, Lib) ->
- Proc = get_os_process(Lang),
- case Lib of
- {[]} -> ok;
- Lib ->
- true = proc_prompt(Proc, [<<"add_lib">>, Lib])
- end,
- lists:foreach(fun(FunctionSource) ->
- true = proc_prompt(Proc, [<<"add_fun">>, FunctionSource])
- end, Functions),
- {ok, Proc}.
-
-map_docs(Proc, Docs) ->
- % send the documents
- Results = lists:map(
- fun(Doc) ->
- Json = couch_doc:to_json_obj(Doc, []),
-
- FunsResults = proc_prompt(Proc, [<<"map_doc">>, Json]),
- % the results are a json array of function map yields like this:
- % [FunResults1, FunResults2 ...]
- % where funresults is are json arrays of key value pairs:
- % [[Key1, Value1], [Key2, Value2]]
- % Convert the key, value pairs to tuples like
- % [{Key1, Value1}, {Key2, Value2}]
- lists:map(
- fun(FunRs) ->
- [list_to_tuple(FunResult) || FunResult <- FunRs]
- end,
- FunsResults)
- end,
- Docs),
- {ok, Results}.
-
-
-stop_doc_map(nil) ->
- ok;
-stop_doc_map(Proc) ->
- ok = ret_os_process(Proc).
-
-group_reductions_results([]) ->
- [];
-group_reductions_results(List) ->
- {Heads, Tails} = lists:foldl(
- fun([H|T], {HAcc,TAcc}) ->
- {[H|HAcc], [T|TAcc]}
- end, {[], []}, List),
- case Tails of
- [[]|_] -> % no tails left
- [Heads];
- _ ->
- [Heads | group_reductions_results(Tails)]
- end.
-
-rereduce(_Lang, [], _ReducedValues) ->
- {ok, []};
-rereduce(Lang, RedSrcs, ReducedValues) ->
- Grouped = group_reductions_results(ReducedValues),
- Results = lists:zipwith(
- fun
- (<<"_", _/binary>> = FunSrc, Values) ->
- {ok, [Result]} = builtin_reduce(rereduce, [FunSrc], [[[], V] || V <- Values], []),
- Result;
- (FunSrc, Values) ->
- os_rereduce(Lang, [FunSrc], Values)
- end, RedSrcs, Grouped),
- {ok, Results}.
-
-reduce(_Lang, [], _KVs) ->
- {ok, []};
-reduce(Lang, RedSrcs, KVs) ->
- {OsRedSrcs, BuiltinReds} = lists:partition(fun
- (<<"_", _/binary>>) -> false;
- (_OsFun) -> true
- end, RedSrcs),
- {ok, OsResults} = os_reduce(Lang, OsRedSrcs, KVs),
- {ok, BuiltinResults} = builtin_reduce(reduce, BuiltinReds, KVs, []),
- recombine_reduce_results(RedSrcs, OsResults, BuiltinResults, []).
-
-recombine_reduce_results([], [], [], Acc) ->
- {ok, lists:reverse(Acc)};
-recombine_reduce_results([<<"_", _/binary>>|RedSrcs], OsResults, [BRes|BuiltinResults], Acc) ->
- recombine_reduce_results(RedSrcs, OsResults, BuiltinResults, [BRes|Acc]);
-recombine_reduce_results([_OsFun|RedSrcs], [OsR|OsResults], BuiltinResults, Acc) ->
- recombine_reduce_results(RedSrcs, OsResults, BuiltinResults, [OsR|Acc]).
-
-os_reduce(_Lang, [], _KVs) ->
- {ok, []};
-os_reduce(Lang, OsRedSrcs, KVs) ->
- Proc = get_os_process(Lang),
- OsResults = try proc_prompt(Proc, [<<"reduce">>, OsRedSrcs, KVs]) of
- [true, Reductions] -> Reductions
- after
- ok = ret_os_process(Proc)
- end,
- {ok, OsResults}.
-
-os_rereduce(Lang, OsRedSrcs, KVs) ->
- Proc = get_os_process(Lang),
- try proc_prompt(Proc, [<<"rereduce">>, OsRedSrcs, KVs]) of
- [true, [Reduction]] -> Reduction
- after
- ok = ret_os_process(Proc)
- end.
-
-
-builtin_reduce(_Re, [], _KVs, Acc) ->
- {ok, lists:reverse(Acc)};
-builtin_reduce(Re, [<<"_sum",_/binary>>|BuiltinReds], KVs, Acc) ->
- Sum = builtin_sum_rows(KVs),
- builtin_reduce(Re, BuiltinReds, KVs, [Sum|Acc]);
-builtin_reduce(reduce, [<<"_count",_/binary>>|BuiltinReds], KVs, Acc) ->
- Count = length(KVs),
- builtin_reduce(reduce, BuiltinReds, KVs, [Count|Acc]);
-builtin_reduce(rereduce, [<<"_count",_/binary>>|BuiltinReds], KVs, Acc) ->
- Count = builtin_sum_rows(KVs),
- builtin_reduce(rereduce, BuiltinReds, KVs, [Count|Acc]);
-builtin_reduce(Re, [<<"_stats",_/binary>>|BuiltinReds], KVs, Acc) ->
- Stats = builtin_stats(Re, KVs),
- builtin_reduce(Re, BuiltinReds, KVs, [Stats|Acc]).
-
-builtin_sum_rows(KVs) ->
- lists:foldl(fun
- ([_Key, Value], Acc) when is_number(Value), is_number(Acc) ->
- Acc + Value;
- ([_Key, Value], Acc) when is_list(Value), is_list(Acc) ->
- sum_terms(Acc, Value);
- ([_Key, Value], Acc) when is_number(Value), is_list(Acc) ->
- sum_terms(Acc, [Value]);
- ([_Key, Value], Acc) when is_list(Value), is_number(Acc) ->
- sum_terms([Acc], Value);
- (_Else, _Acc) ->
- throw({invalid_value, <<"builtin _sum function requires map values to be numbers or lists of numbers">>})
- end, 0, KVs).
-
-sum_terms([], []) ->
- [];
-sum_terms([_|_]=Xs, []) ->
- Xs;
-sum_terms([], [_|_]=Ys) ->
- Ys;
-sum_terms([X|Xs], [Y|Ys]) when is_number(X), is_number(Y) ->
- [X+Y | sum_terms(Xs,Ys)];
-sum_terms(_, _) ->
- throw({invalid_value, <<"builtin _sum function requires map values to be numbers or lists of numbers">>}).
-
-builtin_stats(reduce, [[_,First]|Rest]) when is_number(First) ->
- Stats = lists:foldl(fun([_K,V], {S,C,Mi,Ma,Sq}) when is_number(V) ->
- {S+V, C+1, lists:min([Mi, V]), lists:max([Ma, V]), Sq+(V*V)};
- (_, _) ->
- throw({invalid_value,
- <<"builtin _stats function requires map values to be numbers">>})
- end, {First,1,First,First,First*First}, Rest),
- {Sum, Cnt, Min, Max, Sqr} = Stats,
- {[{sum,Sum}, {count,Cnt}, {min,Min}, {max,Max}, {sumsqr,Sqr}]};
-
-builtin_stats(rereduce, [[_,First]|Rest]) ->
- {[{sum,Sum0}, {count,Cnt0}, {min,Min0}, {max,Max0}, {sumsqr,Sqr0}]} = First,
- Stats = lists:foldl(fun([_K,Red], {S,C,Mi,Ma,Sq}) ->
- {[{sum,Sum}, {count,Cnt}, {min,Min}, {max,Max}, {sumsqr,Sqr}]} = Red,
- {Sum+S, Cnt+C, lists:min([Min, Mi]), lists:max([Max, Ma]), Sqr+Sq}
- end, {Sum0,Cnt0,Min0,Max0,Sqr0}, Rest),
- {Sum, Cnt, Min, Max, Sqr} = Stats,
- {[{sum,Sum}, {count,Cnt}, {min,Min}, {max,Max}, {sumsqr,Sqr}]}.
-
-% use the function stored in ddoc.validate_doc_update to test an update.
-validate_doc_update(DDoc, EditDoc, DiskDoc, Ctx, SecObj) ->
- JsonEditDoc = couch_doc:to_json_obj(EditDoc, [revs]),
- JsonDiskDoc = json_doc(DiskDoc),
- case ddoc_prompt(DDoc, [<<"validate_doc_update">>], [JsonEditDoc, JsonDiskDoc, Ctx, SecObj]) of
- 1 ->
- ok;
- {[{<<"forbidden">>, Message}]} ->
- throw({forbidden, Message});
- {[{<<"unauthorized">>, Message}]} ->
- throw({unauthorized, Message})
- end.
-
-json_doc(nil) -> null;
-json_doc(Doc) ->
- couch_doc:to_json_obj(Doc, [revs]).
-
-filter_docs(Req, Db, DDoc, FName, Docs) ->
- JsonReq = case Req of
- {json_req, JsonObj} ->
- JsonObj;
- #httpd{} = HttpReq ->
- couch_httpd_external:json_req_obj(HttpReq, Db)
- end,
- JsonDocs = [couch_doc:to_json_obj(Doc, [revs]) || Doc <- Docs],
- [true, Passes] = ddoc_prompt(DDoc, [<<"filters">>, FName], [JsonDocs, JsonReq]),
- {ok, Passes}.
-
-ddoc_proc_prompt({Proc, DDocId}, FunPath, Args) ->
- proc_prompt(Proc, [<<"ddoc">>, DDocId, FunPath, Args]).
-
-ddoc_prompt(DDoc, FunPath, Args) ->
- with_ddoc_proc(DDoc, fun({Proc, DDocId}) ->
- proc_prompt(Proc, [<<"ddoc">>, DDocId, FunPath, Args])
- end).
-
-with_ddoc_proc(#doc{id=DDocId,revs={Start, [DiskRev|_]}}=DDoc, Fun) ->
- Rev = couch_doc:rev_to_str({Start, DiskRev}),
- DDocKey = {DDocId, Rev},
- Proc = get_ddoc_process(DDoc, DDocKey),
- try Fun({Proc, DDocId})
- after
- ok = ret_os_process(Proc)
- end.
-
-init([]) ->
- % read config and register for configuration changes
-
- % just stop if one of the config settings change. couch_server_sup
- % will restart us and then we will pick up the new settings.
-
- ok = couch_config:register(
- fun("query_servers" ++ _, _) ->
- supervisor:terminate_child(couch_secondary_services, query_servers),
- supervisor:restart_child(couch_secondary_services, query_servers)
- end),
- ok = couch_config:register(
- fun("native_query_servers" ++ _, _) ->
- supervisor:terminate_child(couch_secondary_services, query_servers),
- [supervisor:restart_child(couch_secondary_services, query_servers)]
- end),
- ok = couch_config:register(
- fun("query_server_config" ++ _, _) ->
- supervisor:terminate_child(couch_secondary_services, query_servers),
- supervisor:restart_child(couch_secondary_services, query_servers)
- end),
-
- Langs = ets:new(couch_query_server_langs, [set, private]),
- LangLimits = ets:new(couch_query_server_lang_limits, [set, private]),
- PidProcs = ets:new(couch_query_server_pid_langs, [set, private]),
- LangProcs = ets:new(couch_query_server_procs, [set, private]),
-
- ProcTimeout = list_to_integer(couch_config:get(
- "couchdb", "os_process_timeout", "5000")),
- ReduceLimit = list_to_atom(
- couch_config:get("query_server_config","reduce_limit","true")),
- OsProcLimit = list_to_integer(
- couch_config:get("query_server_config","os_process_limit","10")),
-
- % 'query_servers' specifies an OS command-line to execute.
- lists:foreach(fun({Lang, Command}) ->
- true = ets:insert(LangLimits, {?l2b(Lang), OsProcLimit, 0}),
- true = ets:insert(Langs, {?l2b(Lang),
- couch_os_process, start_link, [Command]})
- end, couch_config:get("query_servers")),
- % 'native_query_servers' specifies a {Module, Func, Arg} tuple.
- lists:foreach(fun({Lang, SpecStr}) ->
- {ok, {Mod, Fun, SpecArg}} = couch_util:parse_term(SpecStr),
- true = ets:insert(LangLimits, {?l2b(Lang), 0, 0}), % 0 means no limit
- true = ets:insert(Langs, {?l2b(Lang),
- Mod, Fun, SpecArg})
- end, couch_config:get("native_query_servers")),
-
-
- process_flag(trap_exit, true),
- {ok, #qserver{
- langs = Langs, % Keyed by language name, value is {Mod,Func,Arg}
- pid_procs = PidProcs, % Keyed by PID, valus is a #proc record.
- lang_procs = LangProcs, % Keyed by language name, value is a #proc record
- lang_limits = LangLimits, % Keyed by language name, value is {Lang, Limit, Current}
- config = {[{<<"reduce_limit">>, ReduceLimit},{<<"timeout">>, ProcTimeout}]}
- }}.
-
-terminate(_Reason, #qserver{pid_procs=PidProcs}) ->
- [couch_util:shutdown_sync(P) || {P,_} <- ets:tab2list(PidProcs)],
- ok.
-
-handle_call({get_proc, #doc{body={Props}}=DDoc, DDocKey}, From, Server) ->
- Lang = couch_util:get_value(<<"language">>, Props, <<"javascript">>),
- case lang_proc(Lang, Server, fun(Procs) ->
- % find a proc in the set that has the DDoc
- proc_with_ddoc(DDoc, DDocKey, Procs)
- end) of
- {ok, Proc} ->
- {reply, {ok, Proc, Server#qserver.config}, Server};
- wait ->
- {noreply, add_to_waitlist({DDoc, DDocKey}, From, Server)};
- Error ->
- {reply, Error, Server}
- end;
-handle_call({get_proc, Lang}, From, Server) ->
- case lang_proc(Lang, Server, fun([P|_Procs]) ->
- {ok, P}
- end) of
- {ok, Proc} ->
- {reply, {ok, Proc, Server#qserver.config}, Server};
- wait ->
- {noreply, add_to_waitlist({Lang}, From, Server)};
- Error ->
- {reply, Error, Server}
- end;
-handle_call({unlink_proc, Pid}, _From, #qserver{pid_procs=PidProcs}=Server) ->
- rem_value(PidProcs, Pid),
- unlink(Pid),
- {reply, ok, Server};
-handle_call({ret_proc, Proc}, _From, #qserver{
- pid_procs=PidProcs,
- lang_procs=LangProcs}=Server) ->
- % Along with max process limit, here we should check
- % if we're over the limit and discard when we are.
- add_value(PidProcs, Proc#proc.pid, Proc),
- add_to_list(LangProcs, Proc#proc.lang, Proc),
- link(Proc#proc.pid),
- {reply, true, service_waitlist(Server)}.
-
-handle_cast(_Whatever, Server) ->
- {noreply, Server}.
-
-handle_info({'EXIT', Pid, Status}, #qserver{
- pid_procs=PidProcs,
- lang_procs=LangProcs,
- lang_limits=LangLimits}=Server) ->
- case ets:lookup(PidProcs, Pid) of
- [{Pid, Proc}] ->
- case Status of
- normal -> ok;
- _ -> ?LOG_DEBUG("Linked process died abnormally: ~p (reason: ~p)", [Pid, Status])
- end,
- rem_value(PidProcs, Pid),
- catch rem_from_list(LangProcs, Proc#proc.lang, Proc),
- [{Lang, Lim, Current}] = ets:lookup(LangLimits, Proc#proc.lang),
- true = ets:insert(LangLimits, {Lang, Lim, Current-1}),
- {noreply, service_waitlist(Server)};
- [] ->
- case Status of
- normal ->
- {noreply, Server};
- _ ->
- {stop, Status, Server}
- end
- end.
-
-code_change(_OldVsn, State, _Extra) ->
- {ok, State}.
-
-% Private API
-
-add_to_waitlist(Info, From, #qserver{waitlist=Waitlist}=Server) ->
- Server#qserver{waitlist=[{Info, From}|Waitlist]}.
-
-service_waitlist(#qserver{waitlist=[]}=Server) ->
- Server;
-service_waitlist(#qserver{waitlist=Waitlist}=Server) ->
- [Oldest|RevWList] = lists:reverse(Waitlist),
- case service_waiting(Oldest, Server) of
- ok ->
- Server#qserver{waitlist=lists:reverse(RevWList)};
- wait ->
- Server#qserver{waitlist=Waitlist}
- end.
-
-% todo get rid of duplication
-service_waiting({{#doc{body={Props}}=DDoc, DDocKey}, From}, Server) ->
- Lang = couch_util:get_value(<<"language">>, Props, <<"javascript">>),
- case lang_proc(Lang, Server, fun(Procs) ->
- % find a proc in the set that has the DDoc
- proc_with_ddoc(DDoc, DDocKey, Procs)
- end) of
- {ok, Proc} ->
- gen_server:reply(From, {ok, Proc, Server#qserver.config}),
- ok;
- wait -> % this should never happen
- wait;
- Error ->
- gen_server:reply(From, Error),
- ok
- end;
-service_waiting({{Lang}, From}, Server) ->
- case lang_proc(Lang, Server, fun([P|_Procs]) ->
- {ok, P}
- end) of
- {ok, Proc} ->
- gen_server:reply(From, {ok, Proc, Server#qserver.config}),
- ok;
- wait -> % this should never happen
- wait;
- Error ->
- gen_server:reply(From, Error),
- ok
- end.
-
-lang_proc(Lang, #qserver{
- langs=Langs,
- pid_procs=PidProcs,
- lang_procs=LangProcs,
- lang_limits=LangLimits}, PickFun) ->
- % Note to future self. Add max process limit.
- case ets:lookup(LangProcs, Lang) of
- [{Lang, [P|Procs]}] ->
- {ok, Proc} = PickFun([P|Procs]),
- rem_from_list(LangProcs, Lang, Proc),
- {ok, Proc};
- _ ->
- case (catch new_process(Langs, LangLimits, Lang)) of
- {ok, Proc} ->
- add_value(PidProcs, Proc#proc.pid, Proc),
- PickFun([Proc]);
- ErrorOrWait ->
- ErrorOrWait
- end
- end.
-
-new_process(Langs, LangLimits, Lang) ->
- [{Lang, Lim, Current}] = ets:lookup(LangLimits, Lang),
- if (Lim == 0) or (Current < Lim) -> % Lim == 0 means no limit
- % we are below the limit for our language, make a new one
- case ets:lookup(Langs, Lang) of
- [{Lang, Mod, Func, Arg}] ->
- {ok, Pid} = apply(Mod, Func, Arg),
- true = ets:insert(LangLimits, {Lang, Lim, Current+1}),
- {ok, #proc{lang=Lang,
- pid=Pid,
- % Called via proc_prompt, proc_set_timeout, and proc_stop
- prompt_fun={Mod, prompt},
- set_timeout_fun={Mod, set_timeout},
- stop_fun={Mod, stop}}};
- _ ->
- {unknown_query_language, Lang}
- end;
- true ->
- wait
- end.
-
-proc_with_ddoc(DDoc, DDocKey, LangProcs) ->
- DDocProcs = lists:filter(fun(#proc{ddoc_keys=Keys}) ->
- lists:any(fun(Key) ->
- Key == DDocKey
- end, Keys)
- end, LangProcs),
- case DDocProcs of
- [DDocProc|_] ->
- ?LOG_DEBUG("DDocProc found for DDocKey: ~p",[DDocKey]),
- {ok, DDocProc};
- [] ->
- [TeachProc|_] = LangProcs,
- ?LOG_DEBUG("Teach ddoc to new proc ~p with DDocKey: ~p",[TeachProc, DDocKey]),
- {ok, SmartProc} = teach_ddoc(DDoc, DDocKey, TeachProc),
- {ok, SmartProc}
- end.
-
-proc_prompt(Proc, Args) ->
- {Mod, Func} = Proc#proc.prompt_fun,
- apply(Mod, Func, [Proc#proc.pid, Args]).
-
-proc_stop(Proc) ->
- {Mod, Func} = Proc#proc.stop_fun,
- apply(Mod, Func, [Proc#proc.pid]).
-
-proc_set_timeout(Proc, Timeout) ->
- {Mod, Func} = Proc#proc.set_timeout_fun,
- apply(Mod, Func, [Proc#proc.pid, Timeout]).
-
-teach_ddoc(DDoc, {DDocId, _Rev}=DDocKey, #proc{ddoc_keys=Keys}=Proc) ->
- % send ddoc over the wire
- % we only share the rev with the client we know to update code
- % but it only keeps the latest copy, per each ddoc, around.
- true = proc_prompt(Proc, [<<"ddoc">>, <<"new">>, DDocId, couch_doc:to_json_obj(DDoc, [])]),
- % we should remove any other ddocs keys for this docid
- % because the query server overwrites without the rev
- Keys2 = [{D,R} || {D,R} <- Keys, D /= DDocId],
- % add ddoc to the proc
- {ok, Proc#proc{ddoc_keys=[DDocKey|Keys2]}}.
-
-get_ddoc_process(#doc{} = DDoc, DDocKey) ->
- % remove this case statement
- case gen_server:call(couch_query_servers, {get_proc, DDoc, DDocKey}) of
- {ok, Proc, {QueryConfig}} ->
- % process knows the ddoc
- case (catch proc_prompt(Proc, [<<"reset">>, {QueryConfig}])) of
- true ->
- proc_set_timeout(Proc, couch_util:get_value(<<"timeout">>, QueryConfig)),
- link(Proc#proc.pid),
- gen_server:call(couch_query_servers, {unlink_proc, Proc#proc.pid}),
- Proc;
- _ ->
- catch proc_stop(Proc),
- get_ddoc_process(DDoc, DDocKey)
- end;
- Error ->
- throw(Error)
- end.
-
-get_os_process(Lang) ->
- case gen_server:call(couch_query_servers, {get_proc, Lang}) of
- {ok, Proc, {QueryConfig}} ->
- case (catch proc_prompt(Proc, [<<"reset">>, {QueryConfig}])) of
- true ->
- proc_set_timeout(Proc, couch_util:get_value(<<"timeout">>, QueryConfig)),
- link(Proc#proc.pid),
- gen_server:call(couch_query_servers, {unlink_proc, Proc#proc.pid}),
- Proc;
- _ ->
- catch proc_stop(Proc),
- get_os_process(Lang)
- end;
- Error ->
- throw(Error)
- end.
-
-ret_os_process(Proc) ->
- true = gen_server:call(couch_query_servers, {ret_proc, Proc}),
- catch unlink(Proc#proc.pid),
- ok.
-
-add_value(Tid, Key, Value) ->
- true = ets:insert(Tid, {Key, Value}).
-
-rem_value(Tid, Key) ->
- true = ets:delete(Tid, Key).
-
-add_to_list(Tid, Key, Value) ->
- case ets:lookup(Tid, Key) of
- [{Key, Vals}] ->
- true = ets:insert(Tid, {Key, [Value|Vals]});
- [] ->
- true = ets:insert(Tid, {Key, [Value]})
- end.
-
-rem_from_list(Tid, Key, Value) when is_record(Value, proc)->
- Pid = Value#proc.pid,
- case ets:lookup(Tid, Key) of
- [{Key, Vals}] ->
- % make a new values list that doesn't include the Value arg
- NewValues = [Val || #proc{pid=P}=Val <- Vals, P /= Pid],
- ets:insert(Tid, {Key, NewValues});
- [] -> ok
- end;
-rem_from_list(Tid, Key, Value) ->
- case ets:lookup(Tid, Key) of
- [{Key, Vals}] ->
- % make a new values list that doesn't include the Value arg
- NewValues = [Val || Val <- Vals, Val /= Value],
- ets:insert(Tid, {Key, NewValues});
- [] -> ok
- end.
diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl
deleted file mode 100644
index 7870d69e..00000000
--- a/src/couchdb/couch_server.erl
+++ /dev/null
@@ -1,405 +0,0 @@
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
--module(couch_server).
--behaviour(gen_server).
-
--export([open/2,create/2,delete/2,all_databases/0,get_version/0]).
--export([init/1, handle_call/3,sup_start_link/0]).
--export([handle_cast/2,code_change/3,handle_info/2,terminate/2]).
--export([dev_start/0,is_admin/2,has_admins/0,get_stats/0]).
-
--include("couch_db.hrl").
-
--record(server,{
- root_dir = [],
- dbname_regexp,
- max_dbs_open=100,
- dbs_open=0,
- start_time=""
- }).
-
-dev_start() ->
- couch:stop(),
- up_to_date = make:all([load, debug_info]),
- couch:start().
-
-get_version() ->
- Apps = application:loaded_applications(),
- case lists:keysearch(couch, 1, Apps) of
- {value, {_, _, Vsn}} ->
- Vsn;
- false ->
- "0.0.0"
- end.
-
-get_stats() ->
- {ok, #server{start_time=Time,dbs_open=Open}} =
- gen_server:call(couch_server, get_server),
- [{start_time, ?l2b(Time)}, {dbs_open, Open}].
-
-sup_start_link() ->
- gen_server:start_link({local, couch_server}, couch_server, [], []).
-
-open(DbName, Options) ->
- case gen_server:call(couch_server, {open, DbName, Options}, infinity) of
- {ok, Db} ->
- Ctx = couch_util:get_value(user_ctx, Options, #user_ctx{}),
- {ok, Db#db{user_ctx=Ctx}};
- Error ->
- Error
- end.
-
-create(DbName, Options) ->
- case gen_server:call(couch_server, {create, DbName, Options}, infinity) of
- {ok, Db} ->
- Ctx = couch_util:get_value(user_ctx, Options, #user_ctx{}),
- {ok, Db#db{user_ctx=Ctx}};
- Error ->
- Error
- end.
-
-delete(DbName, Options) ->
- gen_server:call(couch_server, {delete, DbName, Options}, infinity).
-
-check_dbname(#server{dbname_regexp=RegExp}, DbName) ->
- case re:run(DbName, RegExp, [{capture, none}]) of
- nomatch ->
- case DbName of
- "_users" -> ok;
- "_replicator" -> ok;
- _Else ->
- {error, illegal_database_name}
- end;
- match ->
- ok
- end.
-
-is_admin(User, ClearPwd) ->
- case couch_config:get("admins", User) of
- "-hashed-" ++ HashedPwdAndSalt ->
- [HashedPwd, Salt] = string:tokens(HashedPwdAndSalt, ","),
- couch_util:to_hex(crypto:sha(ClearPwd ++ Salt)) == HashedPwd;
- _Else ->
- false
- end.
-
-has_admins() ->
- couch_config:get("admins") /= [].
-
-get_full_filename(Server, DbName) ->
- filename:join([Server#server.root_dir, "./" ++ DbName ++ ".couch"]).
-
-hash_admin_passwords() ->
- hash_admin_passwords(true).
-
-hash_admin_passwords(Persist) ->
- lists:foreach(
- fun({_User, "-hashed-" ++ _}) ->
- ok; % already hashed
- ({User, ClearPassword}) ->
- Salt = ?b2l(couch_uuids:random()),
- Hashed = couch_util:to_hex(crypto:sha(ClearPassword ++ Salt)),
- couch_config:set("admins",
- User, "-hashed-" ++ Hashed ++ "," ++ Salt, Persist)
- end, couch_config:get("admins")).
-
-init([]) ->
- % read config and register for configuration changes
-
- % just stop if one of the config settings change. couch_server_sup
- % will restart us and then we will pick up the new settings.
-
- RootDir = couch_config:get("couchdb", "database_dir", "."),
- MaxDbsOpen = list_to_integer(
- couch_config:get("couchdb", "max_dbs_open")),
- Self = self(),
- ok = couch_config:register(
- fun("couchdb", "database_dir") ->
- exit(Self, config_change)
- end),
- ok = couch_config:register(
- fun("couchdb", "max_dbs_open", Max) ->
- gen_server:call(couch_server,
- {set_max_dbs_open, list_to_integer(Max)})
- end),
- ok = couch_file:init_delete_dir(RootDir),
- hash_admin_passwords(),
- ok = couch_config:register(
- fun("admins", _Key, _Value, Persist) ->
- % spawn here so couch_config doesn't try to call itself
- spawn(fun() -> hash_admin_passwords(Persist) end)
- end, false),
- {ok, RegExp} = re:compile("^[a-z][a-z0-9\\_\\$()\\+\\-\\/]*$"),
- ets:new(couch_dbs_by_name, [set, private, named_table]),
- ets:new(couch_dbs_by_pid, [set, private, named_table]),
- ets:new(couch_dbs_by_lru, [ordered_set, private, named_table]),
- ets:new(couch_sys_dbs, [set, private, named_table]),
- process_flag(trap_exit, true),
- {ok, #server{root_dir=RootDir,
- dbname_regexp=RegExp,
- max_dbs_open=MaxDbsOpen,
- start_time=httpd_util:rfc1123_date()}}.
-
-terminate(_Reason, _Srv) ->
- [couch_util:shutdown_sync(Pid) || {_, {Pid, _LruTime}} <-
- ets:tab2list(couch_dbs_by_name)],
- ok.
-
-all_databases() ->
- {ok, #server{root_dir=Root}} = gen_server:call(couch_server, get_server),
- NormRoot = couch_util:normpath(Root),
- Filenames =
- filelib:fold_files(Root, "^[a-z0-9\\_\\$()\\+\\-]*[\\.]couch$", true,
- fun(Filename, AccIn) ->
- NormFilename = couch_util:normpath(Filename),
- case NormFilename -- NormRoot of
- [$/ | RelativeFilename] -> ok;
- RelativeFilename -> ok
- end,
- [list_to_binary(filename:rootname(RelativeFilename, ".couch")) | AccIn]
- end, []),
- {ok, lists:usort(Filenames)}.
-
-
-maybe_close_lru_db(#server{dbs_open=NumOpen, max_dbs_open=MaxOpen}=Server)
- when NumOpen < MaxOpen ->
- {ok, Server};
-maybe_close_lru_db(#server{dbs_open=NumOpen}=Server) ->
- % must free up the lru db.
- case try_close_lru(now()) of
- ok ->
- {ok, Server#server{dbs_open=NumOpen - 1}};
- Error -> Error
- end.
-
-try_close_lru(StartTime) ->
- LruTime = get_lru(),
- if LruTime > StartTime ->
- % this means we've looped through all our opened dbs and found them
- % all in use.
- {error, all_dbs_active};
- true ->
- [{_, DbName}] = ets:lookup(couch_dbs_by_lru, LruTime),
- [{_, {opened, MainPid, LruTime}}] = ets:lookup(couch_dbs_by_name, DbName),
- case couch_db:is_idle(MainPid) of
- true ->
- ok = shutdown_idle_db(DbName, MainPid, LruTime);
- false ->
- % this still has referrers. Go ahead and give it a current lru time
- % and try the next one in the table.
- NewLruTime = now(),
- true = ets:insert(couch_dbs_by_name, {DbName, {opened, MainPid, NewLruTime}}),
- true = ets:insert(couch_dbs_by_pid, {MainPid, DbName}),
- true = ets:delete(couch_dbs_by_lru, LruTime),
- true = ets:insert(couch_dbs_by_lru, {NewLruTime, DbName}),
- try_close_lru(StartTime)
- end
- end.
-
-get_lru() ->
- get_lru(ets:first(couch_dbs_by_lru)).
-
-get_lru(LruTime) ->
- [{LruTime, DbName}] = ets:lookup(couch_dbs_by_lru, LruTime),
- case ets:member(couch_sys_dbs, DbName) of
- false ->
- LruTime;
- true ->
- [{_, {opened, MainPid, _}}] = ets:lookup(couch_dbs_by_name, DbName),
- case couch_db:is_idle(MainPid) of
- true ->
- NextLru = ets:next(couch_dbs_by_lru, LruTime),
- ok = shutdown_idle_db(DbName, MainPid, LruTime),
- get_lru(NextLru);
- false ->
- get_lru(ets:next(couch_dbs_by_lru, LruTime))
- end
- end.
-
-shutdown_idle_db(DbName, MainPid, LruTime) ->
- couch_util:shutdown_sync(MainPid),
- true = ets:delete(couch_dbs_by_lru, LruTime),
- true = ets:delete(couch_dbs_by_name, DbName),
- true = ets:delete(couch_dbs_by_pid, MainPid),
- true = ets:delete(couch_sys_dbs, DbName),
- ok.
-
-open_async(Server, From, DbName, Filepath, Options) ->
- Parent = self(),
- Opener = spawn_link(fun() ->
- Res = couch_db:start_link(DbName, Filepath, Options),
- gen_server:call(
- Parent, {open_result, DbName, Res, Options}, infinity
- ),
- unlink(Parent),
- case Res of
- {ok, DbReader} ->
- unlink(DbReader);
- _ ->
- ok
- end
- end),
- true = ets:insert(couch_dbs_by_name, {DbName, {opening, Opener, [From]}}),
- true = ets:insert(couch_dbs_by_pid, {Opener, DbName}),
- DbsOpen = case lists:member(sys_db, Options) of
- true ->
- true = ets:insert(couch_sys_dbs, {DbName, true}),
- Server#server.dbs_open;
- false ->
- Server#server.dbs_open + 1
- end,
- Server#server{dbs_open = DbsOpen}.
-
-handle_call({set_max_dbs_open, Max}, _From, Server) ->
- {reply, ok, Server#server{max_dbs_open=Max}};
-handle_call(get_server, _From, Server) ->
- {reply, {ok, Server}, Server};
-handle_call({open_result, DbName, {ok, OpenedDbPid}, Options}, _From, Server) ->
- link(OpenedDbPid),
- [{DbName, {opening,Opener,Froms}}] = ets:lookup(couch_dbs_by_name, DbName),
- lists:foreach(fun({FromPid,_}=From) ->
- gen_server:reply(From,
- catch couch_db:open_ref_counted(OpenedDbPid, FromPid))
- end, Froms),
- LruTime = now(),
- true = ets:insert(couch_dbs_by_name,
- {DbName, {opened, OpenedDbPid, LruTime}}),
- true = ets:delete(couch_dbs_by_pid, Opener),
- true = ets:insert(couch_dbs_by_pid, {OpenedDbPid, DbName}),
- true = ets:insert(couch_dbs_by_lru, {LruTime, DbName}),
- case lists:member(create, Options) of
- true ->
- couch_db_update_notifier:notify({created, DbName});
- false ->
- ok
- end,
- {reply, ok, Server};
-handle_call({open_result, DbName, Error, Options}, _From, Server) ->
- [{DbName, {opening,Opener,Froms}}] = ets:lookup(couch_dbs_by_name, DbName),
- lists:foreach(fun(From) ->
- gen_server:reply(From, Error)
- end, Froms),
- true = ets:delete(couch_dbs_by_name, DbName),
- true = ets:delete(couch_dbs_by_pid, Opener),
- DbsOpen = case lists:member(sys_db, Options) of
- true ->
- true = ets:delete(couch_sys_dbs, DbName),
- Server#server.dbs_open;
- false ->
- Server#server.dbs_open - 1
- end,
- {reply, ok, Server#server{dbs_open = DbsOpen}};
-handle_call({open, DbName, Options}, {FromPid,_}=From, Server) ->
- LruTime = now(),
- case ets:lookup(couch_dbs_by_name, DbName) of
- [] ->
- open_db(DbName, Server, Options, From);
- [{_, {opening, Opener, Froms}}] ->
- true = ets:insert(couch_dbs_by_name, {DbName, {opening, Opener, [From|Froms]}}),
- {noreply, Server};
- [{_, {opened, MainPid, PrevLruTime}}] ->
- true = ets:insert(couch_dbs_by_name, {DbName, {opened, MainPid, LruTime}}),
- true = ets:delete(couch_dbs_by_lru, PrevLruTime),
- true = ets:insert(couch_dbs_by_lru, {LruTime, DbName}),
- {reply, couch_db:open_ref_counted(MainPid, FromPid), Server}
- end;
-handle_call({create, DbName, Options}, From, Server) ->
- case ets:lookup(couch_dbs_by_name, DbName) of
- [] ->
- open_db(DbName, Server, [create | Options], From);
- [_AlreadyRunningDb] ->
- {reply, file_exists, Server}
- end;
-handle_call({delete, DbName, _Options}, _From, Server) ->
- DbNameList = binary_to_list(DbName),
- case check_dbname(Server, DbNameList) of
- ok ->
- FullFilepath = get_full_filename(Server, DbNameList),
- UpdateState =
- case ets:lookup(couch_dbs_by_name, DbName) of
- [] -> false;
- [{_, {opening, Pid, Froms}}] ->
- couch_util:shutdown_sync(Pid),
- true = ets:delete(couch_dbs_by_name, DbName),
- true = ets:delete(couch_dbs_by_pid, Pid),
- [gen_server:reply(F, not_found) || F <- Froms],
- true;
- [{_, {opened, Pid, LruTime}}] ->
- couch_util:shutdown_sync(Pid),
- true = ets:delete(couch_dbs_by_name, DbName),
- true = ets:delete(couch_dbs_by_pid, Pid),
- true = ets:delete(couch_dbs_by_lru, LruTime),
- true
- end,
- Server2 = case UpdateState of
- true ->
- DbsOpen = case ets:member(couch_sys_dbs, DbName) of
- true ->
- true = ets:delete(couch_sys_dbs, DbName),
- Server#server.dbs_open;
- false ->
- Server#server.dbs_open - 1
- end,
- Server#server{dbs_open = DbsOpen};
- false ->
- Server
- end,
-
- %% Delete any leftover .compact files. If we don't do this a subsequent
- %% request for this DB will try to open the .compact file and use it.
- couch_file:delete(Server#server.root_dir, FullFilepath ++ ".compact"),
-
- case couch_file:delete(Server#server.root_dir, FullFilepath) of
- ok ->
- couch_db_update_notifier:notify({deleted, DbName}),
- {reply, ok, Server2};
- {error, enoent} ->
- {reply, not_found, Server2};
- Else ->
- {reply, Else, Server2}
- end;
- Error ->
- {reply, Error, Server}
- end.
-
-handle_cast(Msg, _Server) ->
- exit({unknown_cast_message, Msg}).
-
-code_change(_OldVsn, State, _Extra) ->
- {ok, State}.
-
-handle_info({'EXIT', _Pid, config_change}, Server) ->
- {noreply, shutdown, Server};
-handle_info(Error, _Server) ->
- ?LOG_ERROR("Unexpected message, restarting couch_server: ~p", [Error]),
- exit(kill).
-
-open_db(DbName, Server, Options, From) ->
- DbNameList = binary_to_list(DbName),
- case check_dbname(Server, DbNameList) of
- ok ->
- Filepath = get_full_filename(Server, DbNameList),
- case lists:member(sys_db, Options) of
- true ->
- {noreply, open_async(Server, From, DbName, Filepath, Options)};
- false ->
- case maybe_close_lru_db(Server) of
- {ok, Server2} ->
- {noreply, open_async(Server2, From, DbName, Filepath, Options)};
- CloseError ->
- {reply, CloseError, Server}
- end
- end;
- Error ->
- {reply, Error, Server}
- end.
diff --git a/src/couchdb/priv/Makefile.am b/src/couchdb/priv/Makefile.am
deleted file mode 100644
index b36d828d..00000000
--- a/src/couchdb/priv/Makefile.am
+++ /dev/null
@@ -1,93 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-couchlibdir = $(localerlanglibdir)/couch-$(version)
-couchprivdir = $(couchlibdir)/priv
-couchprivlibdir = $(couchlibdir)/priv/lib
-
-EXTRA_DIST = \
- spawnkillable/couchspawnkillable.sh \
- stat_descriptions.cfg.in
-
-CLEANFILES = stat_descriptions.cfg
-
-ICU_LOCAL_FLAGS = $(ICU_LOCAL_CFLAGS) $(ICU_LOCAL_LDFLAGS)
-if WINDOWS
-ICU_LOCAL_LIBS=-licuuc -licudt -licuin
-else
-ICU_LOCAL_LIBS=-licuuc -licudata -licui18n
-endif
-
-couchprivlib_LTLIBRARIES = couch_icu_driver.la
-couch_icu_driver_la_SOURCES = icu_driver/couch_icu_driver.c
-couch_icu_driver_la_LDFLAGS = -module -avoid-version $(ICU_LOCAL_FLAGS)
-couch_icu_driver_la_CFLAGS = $(ICU_LOCAL_FLAGS)
-couch_icu_driver_la_LIBADD = $(ICU_LOCAL_LIBS)
-
-if WINDOWS
-couch_icu_driver_la_LDFLAGS += -no-undefined
-endif
-
-COUCHJS_SRCS = \
- couch_js/http.c \
- couch_js/http.h \
- couch_js/main.c \
- couch_js/utf8.c \
- couch_js/utf8.h
-
-locallibbin_PROGRAMS = couchjs
-couchjs_SOURCES = $(COUCHJS_SRCS)
-couchjs_LDFLAGS = $(CURL_LDFLAGS)
-couchjs_CFLAGS = -D_BSD_SOURCE $(CURL_CFLAGS)
-couchjs_LDADD = $(CURL_LDFLAGS) @JSLIB@
-
-couchpriv_DATA = stat_descriptions.cfg
-couchpriv_PROGRAMS = couchspawnkillable
-
-%.cfg: %.cfg.in
- cp $< $@
-
-if WINDOWS
-couchspawnkillable_SOURCES = spawnkillable/couchspawnkillable_win.c
-endif
-
-if !WINDOWS
-couchspawnkillable: spawnkillable/couchspawnkillable.sh
- cp $< $@
- chmod +x $@
-endif
-
-# libtool and automake have defeated markh. For each of our executables
-# we end up with 2 copies - one directly in the 'target' folder (eg, 'priv')
-# and another - the correct one - in .libs. The former doesn't work but is
-# what gets installed for 'couchspawnkillable' - but the correct one for
-# couchjs.exe *does* get copied. *shrug* So just clobber it with the
-# correct one as the last step. See bug COUCHDB-439
-install-data-hook:
- if test -f "$(DESTDIR)$(couchprivlibdir)/couch_icu_driver"; then \
- rm -f "$(DESTDIR)$(couchprivlibdir)/couch_icu_driver.so"; \
- cd "$(DESTDIR)$(couchprivlibdir)" && \
- $(LN_S) couch_icu_driver couch_icu_driver.so; \
- fi
-if WINDOWS
- $(INSTALL) $(ICU_LOCAL_BIN)/icuuc42.dll $(bindir)
- $(INSTALL) $(ICU_LOCAL_BIN)/icudt42.dll $(bindir)
- $(INSTALL) $(ICU_LOCAL_BIN)/icuin42.dll $(bindir)
- $(INSTALL) $(JS_LIB_BINARY) $(bindir)
- $(INSTALL) .libs/couchspawnkillable.exe \
- "$(DESTDIR)$(couchprivdir)/couchspawnkillable.exe"
-endif
-
-uninstall-local:
- if test -f "$(DESTDIR)$(couchprivlibdir)/couch_erl_driver"; then \
- rm -f "$(DESTDIR)$(couchprivlibdir)/couch_erl_driver.so"; \
- fi
diff --git a/src/erlang-oauth/Makefile.am b/src/erlang-oauth/Makefile.am
deleted file mode 100644
index 48b76482..00000000
--- a/src/erlang-oauth/Makefile.am
+++ /dev/null
@@ -1,50 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy
-## of the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-oauthebindir = $(localerlanglibdir)/erlang-oauth/ebin
-
-oauth_file_collection = \
- oauth.app.in \
- oauth.erl \
- oauth_hmac_sha1.erl \
- oauth_http.erl \
- oauth_plaintext.erl \
- oauth_rsa_sha1.erl \
- oauth_unix.erl \
- oauth_uri.erl
-
-# Removed oauth_rsa_sha1.beam until we require R12B5 or
-# we add a ./configure option to enable it.
-
-oauthebin_make_generated_file_list = \
- oauth.app \
- oauth.beam \
- oauth_hmac_sha1.beam \
- oauth_http.beam \
- oauth_plaintext.beam \
- oauth_unix.beam \
- oauth_uri.beam
-
-oauthebin_DATA = \
- $(oauthebin_make_generated_file_list)
-
-EXTRA_DIST = \
- $(oauth_file_collection)
-
-CLEANFILES = \
- $(oauthebin_make_generated_file_list)
-
-%.app: %.app.in
- cp $< $@
-
-%.beam: %.erl
- $(ERLC) $(ERLC_FLAGS) $<
diff --git a/src/erlang-oauth/oauth.app.in b/src/erlang-oauth/oauth.app.in
deleted file mode 100644
index 6357b9b0..00000000
--- a/src/erlang-oauth/oauth.app.in
+++ /dev/null
@@ -1,20 +0,0 @@
-{application, oauth, [
- {description, "Erlang OAuth implementation"},
- {vsn, "dev"},
- {modules, [
- oauth,
- oauth_hmac_sha1,
- oauth_http,
- oauth_plaintext,
- oauth_rsa_sha1,
- oauth_unix,
- oauth_uri
- ]},
- {registered, []},
- {applications, [
- kernel,
- stdlib,
- crypto,
- inets
- ]}
-]}.
diff --git a/src/erlang-oauth/oauth.erl b/src/erlang-oauth/oauth.erl
deleted file mode 100644
index 866655c9..00000000
--- a/src/erlang-oauth/oauth.erl
+++ /dev/null
@@ -1,107 +0,0 @@
--module(oauth).
-
--export(
- [ get/5
- , header/1
- , post/5
- , signature/5
- , signature_base_string/3
- , signed_params/6
- , token/1
- , token_secret/1
- , uri/2
- , verify/6
- ]).
-
-
-get(URL, ExtraParams, Consumer, Token, TokenSecret) ->
- SignedParams = signed_params("GET", URL, ExtraParams, Consumer, Token, TokenSecret),
- oauth_http:get(uri(URL, SignedParams)).
-
-post(URL, ExtraParams, Consumer, Token, TokenSecret) ->
- SignedParams = signed_params("POST", URL, ExtraParams, Consumer, Token, TokenSecret),
- oauth_http:post(URL, oauth_uri:params_to_string(SignedParams)).
-
-uri(Base, []) ->
- Base;
-uri(Base, Params) ->
- lists:concat([Base, "?", oauth_uri:params_to_string(Params)]).
-
-header(Params) ->
- {"Authorization", "OAuth " ++ oauth_uri:params_to_header_string(Params)}.
-
-token(Params) ->
- proplists:get_value("oauth_token", Params).
-
-token_secret(Params) ->
- proplists:get_value("oauth_token_secret", Params).
-
-verify(Signature, HttpMethod, URL, Params, Consumer, TokenSecret) ->
- case signature_method(Consumer) of
- plaintext ->
- oauth_plaintext:verify(Signature, consumer_secret(Consumer), TokenSecret);
- hmac_sha1 ->
- BaseString = signature_base_string(HttpMethod, URL, Params),
- oauth_hmac_sha1:verify(Signature, BaseString, consumer_secret(Consumer), TokenSecret);
- rsa_sha1 ->
- BaseString = signature_base_string(HttpMethod, URL, Params),
- oauth_rsa_sha1:verify(Signature, BaseString, consumer_secret(Consumer))
- end.
-
-signed_params(HttpMethod, URL, ExtraParams, Consumer, Token, TokenSecret) ->
- Params = token_param(Token, params(Consumer, ExtraParams)),
- [{"oauth_signature", signature(HttpMethod, URL, Params, Consumer, TokenSecret)}|Params].
-
-signature(HttpMethod, URL, Params, Consumer, TokenSecret) ->
- case signature_method(Consumer) of
- plaintext ->
- oauth_plaintext:signature(consumer_secret(Consumer), TokenSecret);
- hmac_sha1 ->
- BaseString = signature_base_string(HttpMethod, URL, Params),
- oauth_hmac_sha1:signature(BaseString, consumer_secret(Consumer), TokenSecret);
- rsa_sha1 ->
- BaseString = signature_base_string(HttpMethod, URL, Params),
- oauth_rsa_sha1:signature(BaseString, consumer_secret(Consumer))
- end.
-
-signature_base_string(HttpMethod, URL, Params) ->
- NormalizedURL = oauth_uri:normalize(URL),
- NormalizedParams = oauth_uri:params_to_string(lists:sort(Params)),
- oauth_uri:calate("&", [HttpMethod, NormalizedURL, NormalizedParams]).
-
-token_param("", Params) ->
- Params;
-token_param(Token, Params) ->
- [{"oauth_token", Token}|Params].
-
-params(Consumer, Params) ->
- Nonce = base64:encode_to_string(crypto:rand_bytes(32)), % cf. ruby-oauth
- params(Consumer, oauth_unix:timestamp(), Nonce, Params).
-
-params(Consumer, Timestamp, Nonce, Params) ->
- [ {"oauth_version", "1.0"}
- , {"oauth_nonce", Nonce}
- , {"oauth_timestamp", integer_to_list(Timestamp)}
- , {"oauth_signature_method", signature_method_string(Consumer)}
- , {"oauth_consumer_key", consumer_key(Consumer)}
- | Params
- ].
-
-signature_method_string(Consumer) ->
- case signature_method(Consumer) of
- plaintext ->
- "PLAINTEXT";
- hmac_sha1 ->
- "HMAC-SHA1";
- rsa_sha1 ->
- "RSA-SHA1"
- end.
-
-signature_method(_Consumer={_, _, Method}) ->
- Method.
-
-consumer_secret(_Consumer={_, Secret, _}) ->
- Secret.
-
-consumer_key(_Consumer={Key, _, _}) ->
- Key.
diff --git a/src/erlang-oauth/oauth_hmac_sha1.erl b/src/erlang-oauth/oauth_hmac_sha1.erl
deleted file mode 100644
index 79d59f37..00000000
--- a/src/erlang-oauth/oauth_hmac_sha1.erl
+++ /dev/null
@@ -1,11 +0,0 @@
--module(oauth_hmac_sha1).
-
--export([signature/3, verify/4]).
-
-
-signature(BaseString, CS, TS) ->
- Key = oauth_uri:calate("&", [CS, TS]),
- base64:encode_to_string(crypto:sha_mac(Key, BaseString)).
-
-verify(Signature, BaseString, CS, TS) ->
- couch_util:verify(signature(BaseString, CS, TS), Signature).
diff --git a/src/erlang-oauth/oauth_http.erl b/src/erlang-oauth/oauth_http.erl
deleted file mode 100644
index bf5a4bac..00000000
--- a/src/erlang-oauth/oauth_http.erl
+++ /dev/null
@@ -1,22 +0,0 @@
--module(oauth_http).
-
--export([get/1, post/2, response_params/1, response_body/1, response_code/1]).
-
-
-get(URL) ->
- request(get, {URL, []}).
-
-post(URL, Data) ->
- request(post, {URL, [], "application/x-www-form-urlencoded", Data}).
-
-request(Method, Request) ->
- http:request(Method, Request, [{autoredirect, false}], []).
-
-response_params(Response) ->
- oauth_uri:params_from_string(response_body(Response)).
-
-response_body({{_, _, _}, _, Body}) ->
- Body.
-
-response_code({{_, Code, _}, _, _}) ->
- Code.
diff --git a/src/erlang-oauth/oauth_plaintext.erl b/src/erlang-oauth/oauth_plaintext.erl
deleted file mode 100644
index 41a1e9b2..00000000
--- a/src/erlang-oauth/oauth_plaintext.erl
+++ /dev/null
@@ -1,10 +0,0 @@
--module(oauth_plaintext).
-
--export([signature/2, verify/3]).
-
-
-signature(CS, TS) ->
- oauth_uri:calate("&", [CS, TS]).
-
-verify(Signature, CS, TS) ->
- couch_util:verify(signature(CS, TS), Signature).
diff --git a/src/erlang-oauth/oauth_rsa_sha1.erl b/src/erlang-oauth/oauth_rsa_sha1.erl
deleted file mode 100644
index 6f4828e0..00000000
--- a/src/erlang-oauth/oauth_rsa_sha1.erl
+++ /dev/null
@@ -1,30 +0,0 @@
--module(oauth_rsa_sha1).
-
--export([signature/2, verify/3]).
-
--include_lib("public_key/include/public_key.hrl").
-
-
-signature(BaseString, PrivateKeyPath) ->
- {ok, [Info]} = public_key:pem_to_der(PrivateKeyPath),
- {ok, PrivateKey} = public_key:decode_private_key(Info),
- base64:encode_to_string(public_key:sign(list_to_binary(BaseString), PrivateKey)).
-
-verify(Signature, BaseString, PublicKey) ->
- public_key:verify_signature(to_binary(BaseString), sha, base64:decode(Signature), public_key(PublicKey)).
-
-to_binary(Term) when is_list(Term) ->
- list_to_binary(Term);
-to_binary(Term) when is_binary(Term) ->
- Term.
-
-public_key(Path) when is_list(Path) ->
- {ok, [{cert, DerCert, not_encrypted}]} = public_key:pem_to_der(Path),
- {ok, Cert} = public_key:pkix_decode_cert(DerCert, otp),
- public_key(Cert);
-public_key(#'OTPCertificate'{tbsCertificate=Cert}) ->
- public_key(Cert);
-public_key(#'OTPTBSCertificate'{subjectPublicKeyInfo=Info}) ->
- public_key(Info);
-public_key(#'OTPSubjectPublicKeyInfo'{subjectPublicKey=Key}) ->
- Key.
diff --git a/src/erlang-oauth/oauth_unix.erl b/src/erlang-oauth/oauth_unix.erl
deleted file mode 100644
index 73ca3143..00000000
--- a/src/erlang-oauth/oauth_unix.erl
+++ /dev/null
@@ -1,16 +0,0 @@
--module(oauth_unix).
-
--export([timestamp/0]).
-
-
-timestamp() ->
- timestamp(calendar:universal_time()).
-
-timestamp(DateTime) ->
- seconds(DateTime) - epoch().
-
-epoch() ->
- seconds({{1970,1,1},{00,00,00}}).
-
-seconds(DateTime) ->
- calendar:datetime_to_gregorian_seconds(DateTime).
diff --git a/src/erlang-oauth/oauth_uri.erl b/src/erlang-oauth/oauth_uri.erl
deleted file mode 100644
index 5023f983..00000000
--- a/src/erlang-oauth/oauth_uri.erl
+++ /dev/null
@@ -1,98 +0,0 @@
--module(oauth_uri).
-
--export([normalize/1, calate/2, encode/1]).
--export([params_from_string/1, params_to_string/1,
- params_from_header_string/1, params_to_header_string/1]).
-
--import(lists, [concat/1]).
-
-
-normalize(URI) ->
- case http_uri:parse(URI) of
- {Scheme, UserInfo, Host, Port, Path, _Query} ->
- normalize(Scheme, UserInfo, string:to_lower(Host), Port, [Path]);
- Else ->
- Else
- end.
-
-normalize(http, UserInfo, Host, 80, Acc) ->
- normalize(http, UserInfo, [Host|Acc]);
-normalize(https, UserInfo, Host, 443, Acc) ->
- normalize(https, UserInfo, [Host|Acc]);
-normalize(Scheme, UserInfo, Host, Port, Acc) ->
- normalize(Scheme, UserInfo, [Host, ":", Port|Acc]).
-
-normalize(Scheme, [], Acc) ->
- concat([Scheme, "://"|Acc]);
-normalize(Scheme, UserInfo, Acc) ->
- concat([Scheme, "://", UserInfo, "@"|Acc]).
-
-params_to_header_string(Params) ->
- intercalate(", ", [concat([encode(K), "=\"", encode(V), "\""]) || {K, V} <- Params]).
-
-params_from_header_string(String) ->
- [param_from_header_string(Param) || Param <- re:split(String, ",\\s*", [{return, list}]), Param =/= ""].
-
-param_from_header_string(Param) ->
- [Key, QuotedValue] = string:tokens(Param, "="),
- Value = string:substr(QuotedValue, 2, length(QuotedValue) - 2),
- {decode(Key), decode(Value)}.
-
-params_from_string(Params) ->
- [param_from_string(Param) || Param <- string:tokens(Params, "&")].
-
-param_from_string(Param) ->
- list_to_tuple([decode(Value) || Value <- string:tokens(Param, "=")]).
-
-params_to_string(Params) ->
- intercalate("&", [calate("=", [K, V]) || {K, V} <- Params]).
-
-calate(Sep, Xs) ->
- intercalate(Sep, [encode(X) || X <- Xs]).
-
-intercalate(Sep, Xs) ->
- concat(intersperse(Sep, Xs)).
-
-intersperse(_, []) -> [];
-intersperse(_, [X]) -> [X];
-intersperse(Sep, [X|Xs]) ->
- [X, Sep|intersperse(Sep, Xs)].
-
--define(is_alphanum(C), C >= $A, C =< $Z; C >= $a, C =< $z; C >= $0, C =< $9).
-
-encode(Term) when is_integer(Term) ->
- integer_to_list(Term);
-encode(Term) when is_atom(Term) ->
- encode(atom_to_list(Term));
-encode(Term) when is_list(Term) ->
- encode(lists:reverse(Term, []), []).
-
-encode([X | T], Acc) when ?is_alphanum(X); X =:= $-; X =:= $_; X =:= $.; X =:= $~ ->
- encode(T, [X | Acc]);
-encode([X | T], Acc) ->
- NewAcc = [$%, dec2hex(X bsr 4), dec2hex(X band 16#0f) | Acc],
- encode(T, NewAcc);
-encode([], Acc) ->
- Acc.
-
-decode(Str) when is_list(Str) ->
- decode(Str, []).
-
-decode([$%, A, B | T], Acc) ->
- decode(T, [(hex2dec(A) bsl 4) + hex2dec(B) | Acc]);
-decode([X | T], Acc) ->
- decode(T, [X | Acc]);
-decode([], Acc) ->
- lists:reverse(Acc, []).
-
--compile({inline, [{dec2hex, 1}, {hex2dec, 1}]}).
-
-dec2hex(N) when N >= 10 andalso N =< 15 ->
- N + $A - 10;
-dec2hex(N) when N >= 0 andalso N =< 9 ->
- N + $0.
-
-hex2dec(C) when C >= $A andalso C =< $F ->
- C - $A + 10;
-hex2dec(C) when C >= $0 andalso C =< $9 ->
- C - $0.
diff --git a/src/etap/Makefile.am b/src/etap/Makefile.am
deleted file mode 100644
index 732347bf..00000000
--- a/src/etap/Makefile.am
+++ /dev/null
@@ -1,44 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy
-## of the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-etapebindir = $(localerlanglibdir)/etap/ebin
-
-etap_file_collection = \
- etap.erl \
- etap_application.erl \
- etap_can.erl \
- etap_exception.erl \
- etap_process.erl \
- etap_report.erl \
- etap_request.erl \
- etap_string.erl \
- etap_web.erl
-
-etapebin_make_generated_file_list = \
- etap.beam \
- etap_application.beam \
- etap_can.beam \
- etap_exception.beam \
- etap_process.beam \
- etap_report.beam \
- etap_request.beam \
- etap_string.beam \
- etap_web.beam
-
-etapebin_DATA = $(etapebin_make_generated_file_list)
-
-EXTRA_DIST = $(etap_file_collection)
-
-CLEANFILES = $(etapebin_make_generated_file_list)
-
-%.beam: %.erl
- $(ERLC) $(ERLC_FLAGS) $<
diff --git a/src/etap/etap.erl b/src/etap/etap.erl
deleted file mode 100644
index 5ad5dba3..00000000
--- a/src/etap/etap.erl
+++ /dev/null
@@ -1,416 +0,0 @@
-%% Copyright (c) 2008-2009 Nick Gerakines <nick@gerakines.net>
-%%
-%% Permission is hereby granted, free of charge, to any person
-%% obtaining a copy of this software and associated documentation
-%% files (the "Software"), to deal in the Software without
-%% restriction, including without limitation the rights to use,
-%% copy, modify, merge, publish, distribute, sublicense, and/or sell
-%% copies of the Software, and to permit persons to whom the
-%% Software is furnished to do so, subject to the following
-%% conditions:
-%%
-%% The above copyright notice and this permission notice shall be
-%% included in all copies or substantial portions of the Software.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-%% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-%% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-%% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-%% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-%% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-%% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-%% OTHER DEALINGS IN THE SOFTWARE.
-%%
-%% @author Nick Gerakines <nick@gerakines.net> [http://socklabs.com/]
-%% @author Jeremy Wall <jeremy@marzhillstudios.com>
-%% @version 0.3.4
-%% @copyright 2007-2008 Jeremy Wall, 2008-2009 Nick Gerakines
-%% @reference http://testanything.org/wiki/index.php/Main_Page
-%% @reference http://en.wikipedia.org/wiki/Test_Anything_Protocol
-%% @todo Finish implementing the skip directive.
-%% @todo Document the messages handled by this receive loop.
-%% @todo Explain in documentation why we use a process to handle test input.
-%% @doc etap is a TAP testing module for Erlang components and applications.
-%% This module allows developers to test their software using the TAP method.
-%%
-%% <blockquote cite="http://en.wikipedia.org/wiki/Test_Anything_Protocol"><p>
-%% TAP, the Test Anything Protocol, is a simple text-based interface between
-%% testing modules in a test harness. TAP started life as part of the test
-%% harness for Perl but now has implementations in C/C++, Python, PHP, Perl
-%% and probably others by the time you read this.
-%% </p></blockquote>
-%%
-%% The testing process begins by defining a plan using etap:plan/1, running
-%% a number of etap tests and then calling eta:end_tests/0. Please refer to
-%% the Erlang modules in the t directory of this project for example tests.
--module(etap).
--export([
- ensure_test_server/0, start_etap_server/0, test_server/1,
- diag/1, diag/2, plan/1, end_tests/0, not_ok/2, ok/2, is/3, isnt/3,
- any/3, none/3, fun_is/3, is_greater/3, skip/1, skip/2,
- ensure_coverage_starts/0, ensure_coverage_ends/0, coverage_report/0,
- datetime/1, skip/3, bail/0, bail/1
-]).
--record(test_state, {planned = 0, count = 0, pass = 0, fail = 0, skip = 0, skip_reason = ""}).
--vsn("0.3.4").
-
-%% @spec plan(N) -> Result
-%% N = unknown | skip | {skip, string()} | integer()
-%% Result = ok
-%% @doc Create a test plan and boot strap the test server.
-plan(unknown) ->
- ensure_coverage_starts(),
- ensure_test_server(),
- etap_server ! {self(), plan, unknown},
- ok;
-plan(skip) ->
- io:format("1..0 # skip~n");
-plan({skip, Reason}) ->
- io:format("1..0 # skip ~s~n", [Reason]);
-plan(N) when is_integer(N), N > 0 ->
- ensure_coverage_starts(),
- ensure_test_server(),
- etap_server ! {self(), plan, N},
- ok.
-
-%% @spec end_tests() -> ok
-%% @doc End the current test plan and output test results.
-%% @todo This should probably be done in the test_server process.
-end_tests() ->
- ensure_coverage_ends(),
- etap_server ! {self(), state},
- State = receive X -> X end,
- if
- State#test_state.planned == -1 ->
- io:format("1..~p~n", [State#test_state.count]);
- true ->
- ok
- end,
- case whereis(etap_server) of
- undefined -> ok;
- _ -> etap_server ! done, ok
- end.
-
-%% @private
-ensure_coverage_starts() ->
- case os:getenv("COVER") of
- false -> ok;
- _ ->
- BeamDir = case os:getenv("COVER_BIN") of false -> "ebin"; X -> X end,
- cover:compile_beam_directory(BeamDir)
- end.
-
-%% @private
-%% @doc Attempts to write out any collected coverage data to the cover/
-%% directory. This function should not be called externally, but it could be.
-ensure_coverage_ends() ->
- case os:getenv("COVER") of
- false -> ok;
- _ ->
- filelib:ensure_dir("cover/"),
- Name = lists:flatten([
- io_lib:format("~.16b", [X]) || X <- binary_to_list(erlang:md5(
- term_to_binary({make_ref(), now()})
- ))
- ]),
- cover:export("cover/" ++ Name ++ ".coverdata")
- end.
-
-%% @spec coverage_report() -> ok
-%% @doc Use the cover module's covreage report builder to create code coverage
-%% reports from recently created coverdata files.
-coverage_report() ->
- [cover:import(File) || File <- filelib:wildcard("cover/*.coverdata")],
- lists:foreach(
- fun(Mod) ->
- cover:analyse_to_file(Mod, atom_to_list(Mod) ++ "_coverage.txt", [])
- end,
- cover:imported_modules()
- ),
- ok.
-
-bail() ->
- bail("").
-
-bail(Reason) ->
- etap_server ! {self(), diag, "Bail out! " ++ Reason},
- ensure_coverage_ends(),
- etap_server ! done, ok,
- ok.
-
-
-%% @spec diag(S) -> ok
-%% S = string()
-%% @doc Print a debug/status message related to the test suite.
-diag(S) -> etap_server ! {self(), diag, "# " ++ S}, ok.
-
-%% @spec diag(Format, Data) -> ok
-%% Format = atom() | string() | binary()
-%% Data = [term()]
-%% UnicodeList = [Unicode]
-%% Unicode = int()
-%% @doc Print a debug/status message related to the test suite.
-%% Function arguments are passed through io_lib:format/2.
-diag(Format, Data) -> diag(io_lib:format(Format, Data)).
-
-%% @spec ok(Expr, Desc) -> Result
-%% Expr = true | false
-%% Desc = string()
-%% Result = true | false
-%% @doc Assert that a statement is true.
-ok(Expr, Desc) -> mk_tap(Expr == true, Desc).
-
-%% @spec not_ok(Expr, Desc) -> Result
-%% Expr = true | false
-%% Desc = string()
-%% Result = true | false
-%% @doc Assert that a statement is false.
-not_ok(Expr, Desc) -> mk_tap(Expr == false, Desc).
-
-%% @spec is(Got, Expected, Desc) -> Result
-%% Got = any()
-%% Expected = any()
-%% Desc = string()
-%% Result = true | false
-%% @doc Assert that two values are the same.
-is(Got, Expected, Desc) ->
- case mk_tap(Got == Expected, Desc) of
- false ->
- etap_server ! {self(), diag, " ---"},
- etap_server ! {self(), diag, io_lib:format(" description: ~p", [Desc])},
- etap_server ! {self(), diag, io_lib:format(" found: ~p", [Got])},
- etap_server ! {self(), diag, io_lib:format(" wanted: ~p", [Expected])},
- etap_server ! {self(), diag, " ..."},
- false;
- true -> true
- end.
-
-%% @spec isnt(Got, Expected, Desc) -> Result
-%% Got = any()
-%% Expected = any()
-%% Desc = string()
-%% Result = true | false
-%% @doc Assert that two values are not the same.
-isnt(Got, Expected, Desc) -> mk_tap(Got /= Expected, Desc).
-
-%% @spec is_greater(ValueA, ValueB, Desc) -> Result
-%% ValueA = number()
-%% ValueB = number()
-%% Desc = string()
-%% Result = true | false
-%% @doc Assert that an integer is greater than another.
-is_greater(ValueA, ValueB, Desc) when is_integer(ValueA), is_integer(ValueB) ->
- mk_tap(ValueA > ValueB, Desc).
-
-%% @spec any(Got, Items, Desc) -> Result
-%% Got = any()
-%% Items = [any()]
-%% Desc = string()
-%% Result = true | false
-%% @doc Assert that an item is in a list.
-any(Got, Items, Desc) ->
- is(lists:member(Got, Items), true, Desc).
-
-%% @spec none(Got, Items, Desc) -> Result
-%% Got = any()
-%% Items = [any()]
-%% Desc = string()
-%% Result = true | false
-%% @doc Assert that an item is not in a list.
-none(Got, Items, Desc) ->
- is(lists:member(Got, Items), false, Desc).
-
-%% @spec fun_is(Fun, Expected, Desc) -> Result
-%% Fun = function()
-%% Expected = any()
-%% Desc = string()
-%% Result = true | false
-%% @doc Use an anonymous function to assert a pattern match.
-fun_is(Fun, Expected, Desc) when is_function(Fun) ->
- is(Fun(Expected), true, Desc).
-
-%% @equiv skip(TestFun, "")
-skip(TestFun) when is_function(TestFun) ->
- skip(TestFun, "").
-
-%% @spec skip(TestFun, Reason) -> ok
-%% TestFun = function()
-%% Reason = string()
-%% @doc Skip a test.
-skip(TestFun, Reason) when is_function(TestFun), is_list(Reason) ->
- begin_skip(Reason),
- catch TestFun(),
- end_skip(),
- ok.
-
-%% @spec skip(Q, TestFun, Reason) -> ok
-%% Q = true | false | function()
-%% TestFun = function()
-%% Reason = string()
-%% @doc Skips a test conditionally. The first argument to this function can
-%% either be the 'true' or 'false' atoms or a function that returns 'true' or
-%% 'false'.
-skip(QFun, TestFun, Reason) when is_function(QFun), is_function(TestFun), is_list(Reason) ->
- case QFun() of
- true -> begin_skip(Reason), TestFun(), end_skip();
- _ -> TestFun()
- end,
- ok;
-
-skip(Q, TestFun, Reason) when is_function(TestFun), is_list(Reason), Q == true ->
- begin_skip(Reason),
- TestFun(),
- end_skip(),
- ok;
-
-skip(_, TestFun, Reason) when is_function(TestFun), is_list(Reason) ->
- TestFun(),
- ok.
-
-%% @private
-begin_skip(Reason) ->
- etap_server ! {self(), begin_skip, Reason}.
-
-%% @private
-end_skip() ->
- etap_server ! {self(), end_skip}.
-
-% ---
-% Internal / Private functions
-
-%% @private
-%% @doc Start the etap_server process if it is not running already.
-ensure_test_server() ->
- case whereis(etap_server) of
- undefined ->
- proc_lib:start(?MODULE, start_etap_server,[]);
- _ ->
- diag("The test server is already running.")
- end.
-
-%% @private
-%% @doc Start the etap_server loop and register itself as the etap_server
-%% process.
-start_etap_server() ->
- catch register(etap_server, self()),
- proc_lib:init_ack(ok),
- etap:test_server(#test_state{
- planned = 0,
- count = 0,
- pass = 0,
- fail = 0,
- skip = 0,
- skip_reason = ""
- }).
-
-
-%% @private
-%% @doc The main etap_server receive/run loop. The etap_server receive loop
-%% responds to seven messages apperatining to failure or passing of tests.
-%% It is also used to initiate the testing process with the {_, plan, _}
-%% message that clears the current test state.
-test_server(State) ->
- NewState = receive
- {_From, plan, unknown} ->
- io:format("# Current time local ~s~n", [datetime(erlang:localtime())]),
- io:format("# Using etap version ~p~n", [ proplists:get_value(vsn, proplists:get_value(attributes, etap:module_info())) ]),
- State#test_state{
- planned = -1,
- count = 0,
- pass = 0,
- fail = 0,
- skip = 0,
- skip_reason = ""
- };
- {_From, plan, N} ->
- io:format("# Current time local ~s~n", [datetime(erlang:localtime())]),
- io:format("# Using etap version ~p~n", [ proplists:get_value(vsn, proplists:get_value(attributes, etap:module_info())) ]),
- io:format("1..~p~n", [N]),
- State#test_state{
- planned = N,
- count = 0,
- pass = 0,
- fail = 0,
- skip = 0,
- skip_reason = ""
- };
- {_From, begin_skip, Reason} ->
- State#test_state{
- skip = 1,
- skip_reason = Reason
- };
- {_From, end_skip} ->
- State#test_state{
- skip = 0,
- skip_reason = ""
- };
- {_From, pass, Desc} ->
- FullMessage = skip_diag(
- " - " ++ Desc,
- State#test_state.skip,
- State#test_state.skip_reason
- ),
- io:format("ok ~p ~s~n", [State#test_state.count + 1, FullMessage]),
- State#test_state{
- count = State#test_state.count + 1,
- pass = State#test_state.pass + 1
- };
-
- {_From, fail, Desc} ->
- FullMessage = skip_diag(
- " - " ++ Desc,
- State#test_state.skip,
- State#test_state.skip_reason
- ),
- io:format("not ok ~p ~s~n", [State#test_state.count + 1, FullMessage]),
- State#test_state{
- count = State#test_state.count + 1,
- fail = State#test_state.fail + 1
- };
- {From, state} ->
- From ! State,
- State;
- {_From, diag, Message} ->
- io:format("~s~n", [Message]),
- State;
- {From, count} ->
- From ! State#test_state.count,
- State;
- {From, is_skip} ->
- From ! State#test_state.skip,
- State;
- done ->
- exit(normal)
- end,
- test_server(NewState).
-
-%% @private
-%% @doc Process the result of a test and send it to the etap_server process.
-mk_tap(Result, Desc) ->
- IsSkip = lib:sendw(etap_server, is_skip),
- case [IsSkip, Result] of
- [_, true] ->
- etap_server ! {self(), pass, Desc},
- true;
- [1, _] ->
- etap_server ! {self(), pass, Desc},
- true;
- _ ->
- etap_server ! {self(), fail, Desc},
- false
- end.
-
-%% @private
-%% @doc Format a date/time string.
-datetime(DateTime) ->
- {{Year, Month, Day}, {Hour, Min, Sec}} = DateTime,
- io_lib:format("~4.10.0B-~2.10.0B-~2.10.0B ~2.10.0B:~2.10.0B:~2.10.0B", [Year, Month, Day, Hour, Min, Sec]).
-
-%% @private
-%% @doc Craft an output message taking skip/todo into consideration.
-skip_diag(Message, 0, _) ->
- Message;
-skip_diag(_Message, 1, "") ->
- " # SKIP";
-skip_diag(_Message, 1, Reason) ->
- " # SKIP : " ++ Reason.
diff --git a/src/etap/etap_application.erl b/src/etap/etap_application.erl
deleted file mode 100644
index 98b52751..00000000
--- a/src/etap/etap_application.erl
+++ /dev/null
@@ -1,72 +0,0 @@
-%% Copyright (c) 2008-2009 Nick Gerakines <nick@gerakines.net>
-%%
-%% Permission is hereby granted, free of charge, to any person
-%% obtaining a copy of this software and associated documentation
-%% files (the "Software"), to deal in the Software without
-%% restriction, including without limitation the rights to use,
-%% copy, modify, merge, publish, distribute, sublicense, and/or sell
-%% copies of the Software, and to permit persons to whom the
-%% Software is furnished to do so, subject to the following
-%% conditions:
-%%
-%% The above copyright notice and this permission notice shall be
-%% included in all copies or substantial portions of the Software.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-%% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-%% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-%% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-%% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-%% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-%% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-%% OTHER DEALINGS IN THE SOFTWARE.
-%%
-%% @author Nick Gerakines <nick@gerakines.net> [http://socklabs.com/]
-%% @copyright 2008 Nick Gerakines
-%% @reference http://testanything.org/wiki/index.php/Main_Page
-%% @reference http://en.wikipedia.org/wiki/Test_Anything_Protocol
-%% @todo Explain in documentation why we use a process to handle test input.
-%% @todo Add test to verify the number of members in a pg2 group.
-%% @doc Provide test functionality to the application and related behaviors.
--module(etap_application).
--export([
- start_ok/2, ensure_loaded/3, load_ok/2,
- pg2_group_exists/2, pg2_group_doesntexist/2
-]).
-
-%% @spec load_ok(string(), string()) -> true | false
-%% @doc Assert that an application can be loaded successfully.
-load_ok(AppName, Desc) ->
- etap:ok(application:load(AppName) == ok, Desc).
-
-%% @spec start_ok(string(), string()) -> true | false
-%% @doc Assert that an application can be started successfully.
-start_ok(AppName, Desc) ->
- etap:ok(application:start(AppName) == ok, Desc).
-
-%% @spec ensure_loaded(string(), string(), string()) -> true | false
-%% @doc Assert that an application has been loaded successfully.
-ensure_loaded(AppName, AppVsn, Desc) ->
- etap:any(
- fun(Match) -> case Match of {AppName, _, AppVsn} -> true; _ -> false end end,
- application:loaded_applications(),
- Desc
- ).
-
-%% @spec pg2_group_exists(string(), string()) -> true | false
-%% @doc Assert that a pg2 group exists.
-pg2_group_exists(GroupName, Desc) ->
- etap:any(
- fun(Match) -> Match == GroupName end,
- pg2:which_groups(),
- Desc
- ).
-
-%% @spec pg2_group_doesntexist(string(), string()) -> true | false
-%% @doc Assert that a pg2 group does not exists.
-pg2_group_doesntexist(GroupName, Desc) ->
- etap:none(
- fun(Match) -> Match == GroupName end,
- pg2:which_groups(),
- Desc
- ).
diff --git a/src/etap/etap_can.erl b/src/etap/etap_can.erl
deleted file mode 100644
index 552b7174..00000000
--- a/src/etap/etap_can.erl
+++ /dev/null
@@ -1,79 +0,0 @@
-%% Copyright (c) 2008-2009 Nick Gerakines <nick@gerakines.net>
-%%
-%% Permission is hereby granted, free of charge, to any person
-%% obtaining a copy of this software and associated documentation
-%% files (the "Software"), to deal in the Software without
-%% restriction, including without limitation the rights to use,
-%% copy, modify, merge, publish, distribute, sublicense, and/or sell
-%% copies of the Software, and to permit persons to whom the
-%% Software is furnished to do so, subject to the following
-%% conditions:
-%%
-%% The above copyright notice and this permission notice shall be
-%% included in all copies or substantial portions of the Software.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-%% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-%% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-%% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-%% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-%% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-%% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-%% OTHER DEALINGS IN THE SOFTWARE.
-%%
-%% @reference http://testanything.org/wiki/index.php/Main_Page
-%% @reference http://en.wikipedia.org/wiki/Test_Anything_Protocol
-%% @doc Provide test functionality modules
--module(etap_can).
-
--export([
- loaded_ok/2, can_ok/2, can_ok/3,
- has_attrib/2, is_attrib/3, is_behaviour/2
-]).
-
-%% @spec loaded_ok(atom(), string()) -> true | false
-%% @doc Assert that a module has been loaded successfully.
-loaded_ok(M, Desc) when is_atom(M) ->
- etap:fun_is(fun({module, _}) -> true; (_) -> false end, code:load_file(M), Desc).
-
-%% @spec can_ok(atom(), atom()) -> true | false
-%% @doc Assert that a module exports a given function.
-can_ok(M, F) when is_atom(M), is_atom(F) ->
- Matches = [X || {X, _} <- M:module_info(exports), X == F],
- etap:ok(Matches > 0, lists:concat([M, " can ", F])).
-
-%% @spec can_ok(atom(), atom(), integer()) -> true | false
-%% @doc Assert that a module exports a given function with a given arity.
-can_ok(M, F, A) when is_atom(M); is_atom(F), is_number(A) ->
- Matches = [X || X <- M:module_info(exports), X == {F, A}],
- etap:ok(Matches > 0, lists:concat([M, " can ", F, "/", A])).
-
-%% @spec has_attrib(M, A) -> true | false
-%% M = atom()
-%% A = atom()
-%% @doc Asserts that a module has a given attribute.
-has_attrib(M, A) when is_atom(M), is_atom(A) ->
- etap:isnt(
- proplists:get_value(A, M:module_info(attributes), 'asdlkjasdlkads'),
- 'asdlkjasdlkads',
- lists:concat([M, " has attribute ", A])
- ).
-
-%% @spec has_attrib(M, A. V) -> true | false
-%% M = atom()
-%% A = atom()
-%% V = any()
-%% @doc Asserts that a module has a given attribute with a given value.
-is_attrib(M, A, V) when is_atom(M) andalso is_atom(A) ->
- etap:is(
- proplists:get_value(A, M:module_info(attributes)),
- [V],
- lists:concat([M, "'s ", A, " is ", V])
- ).
-
-%% @spec is_behavior(M, B) -> true | false
-%% M = atom()
-%% B = atom()
-%% @doc Asserts that a given module has a specific behavior.
-is_behaviour(M, B) when is_atom(M) andalso is_atom(B) ->
- is_attrib(M, behaviour, B).
diff --git a/src/etap/etap_exception.erl b/src/etap/etap_exception.erl
deleted file mode 100644
index ba660727..00000000
--- a/src/etap/etap_exception.erl
+++ /dev/null
@@ -1,66 +0,0 @@
-%% Copyright (c) 2008-2009 Nick Gerakines <nick@gerakines.net>
-%%
-%% Permission is hereby granted, free of charge, to any person
-%% obtaining a copy of this software and associated documentation
-%% files (the "Software"), to deal in the Software without
-%% restriction, including without limitation the rights to use,
-%% copy, modify, merge, publish, distribute, sublicense, and/or sell
-%% copies of the Software, and to permit persons to whom the
-%% Software is furnished to do so, subject to the following
-%% conditions:
-%%
-%% The above copyright notice and this permission notice shall be
-%% included in all copies or substantial portions of the Software.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-%% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-%% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-%% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-%% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-%% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-%% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-%% OTHER DEALINGS IN THE SOFTWARE.
-%%
-%% @reference http://testanything.org/wiki/index.php/Main_Page
-%% @reference http://en.wikipedia.org/wiki/Test_Anything_Protocol
-%% @doc Adds exception based testing to the etap suite.
--module(etap_exception).
-
--export([dies_ok/2, lives_ok/2, throws_ok/3]).
-
-% ---
-% External / Public functions
-
-%% @doc Assert that an exception is raised when running a given function.
-dies_ok(F, Desc) ->
- case (catch F()) of
- {'EXIT', _} -> etap:ok(true, Desc);
- _ -> etap:ok(false, Desc)
- end.
-
-%% @doc Assert that an exception is not raised when running a given function.
-lives_ok(F, Desc) ->
- etap:is(try_this(F), success, Desc).
-
-%% @doc Assert that the exception thrown by a function matches the given exception.
-throws_ok(F, Exception, Desc) ->
- try F() of
- _ -> etap:ok(nok, Desc)
- catch
- _:E ->
- etap:is(E, Exception, Desc)
- end.
-
-% ---
-% Internal / Private functions
-
-%% @private
-%% @doc Run a function and catch any exceptions.
-try_this(F) when is_function(F, 0) ->
- try F() of
- _ -> success
- catch
- throw:E -> {throw, E};
- error:E -> {error, E};
- exit:E -> {exit, E}
- end.
diff --git a/src/etap/etap_process.erl b/src/etap/etap_process.erl
deleted file mode 100644
index 69f5ba00..00000000
--- a/src/etap/etap_process.erl
+++ /dev/null
@@ -1,42 +0,0 @@
-%% Copyright (c) 2008-2009 Nick Gerakines <nick@gerakines.net>
-%%
-%% Permission is hereby granted, free of charge, to any person
-%% obtaining a copy of this software and associated documentation
-%% files (the "Software"), to deal in the Software without
-%% restriction, including without limitation the rights to use,
-%% copy, modify, merge, publish, distribute, sublicense, and/or sell
-%% copies of the Software, and to permit persons to whom the
-%% Software is furnished to do so, subject to the following
-%% conditions:
-%%
-%% The above copyright notice and this permission notice shall be
-%% included in all copies or substantial portions of the Software.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-%% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-%% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-%% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-%% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-%% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-%% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-%% OTHER DEALINGS IN THE SOFTWARE.
-%%
-%% @doc Adds process/pid testing to the etap suite.
--module(etap_process).
-
--export([is_pid/2, is_alive/2, is_mfa/3]).
-
-% ---
-% External / Public functions
-
-%% @doc Assert that a given variable is a pid.
-is_pid(Pid, Desc) when is_pid(Pid) -> etap:ok(true, Desc);
-is_pid(_, Desc) -> etap:ok(false, Desc).
-
-%% @doc Assert that a given process/pid is alive.
-is_alive(Pid, Desc) ->
- etap:ok(erlang:is_process_alive(Pid), Desc).
-
-%% @doc Assert that the current function of a pid is a given {M, F, A} tuple.
-is_mfa(Pid, MFA, Desc) ->
- etap:is({current_function, MFA}, erlang:process_info(Pid, current_function), Desc).
diff --git a/src/etap/etap_report.erl b/src/etap/etap_report.erl
deleted file mode 100644
index 6d692fb6..00000000
--- a/src/etap/etap_report.erl
+++ /dev/null
@@ -1,343 +0,0 @@
-%% Copyright (c) 2008-2009 Nick Gerakines <nick@gerakines.net>
-%%
-%% Permission is hereby granted, free of charge, to any person
-%% obtaining a copy of this software and associated documentation
-%% files (the "Software"), to deal in the Software without
-%% restriction, including without limitation the rights to use,
-%% copy, modify, merge, publish, distribute, sublicense, and/or sell
-%% copies of the Software, and to permit persons to whom the
-%% Software is furnished to do so, subject to the following
-%% conditions:
-%%
-%% The above copyright notice and this permission notice shall be
-%% included in all copies or substantial portions of the Software.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-%% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-%% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-%% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-%% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-%% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-%% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-%% OTHER DEALINGS IN THE SOFTWARE.
-%%
-%% @doc A module for creating nice looking code coverage reports.
--module(etap_report).
--export([create/0]).
-
-%% @spec create() -> ok
-%% @doc Create html code coverage reports for each module that code coverage
-%% data exists for.
-create() ->
- [cover:import(File) || File <- filelib:wildcard("cover/*.coverdata")],
- Modules = lists:foldl(
- fun(Module, Acc) ->
- [{Module, file_report(Module)} | Acc]
- end,
- [],
- cover:imported_modules()
- ),
- index(Modules).
-
-%% @private
-index(Modules) ->
- {ok, IndexFD} = file:open("cover/index.html", [write]),
- io:format(IndexFD, "<html><head><style>
- table.percent_graph { height: 12px; border:1px solid #E2E6EF; empty-cells: show; }
- table.percent_graph td.covered { height: 10px; background: #00f000; }
- table.percent_graph td.uncovered { height: 10px; background: #e00000; }
- .odd { background-color: #ddd; }
- .even { background-color: #fff; }
- </style></head>", []),
- io:format(IndexFD, "<body>", []),
- lists:foldl(
- fun({Module, {Good, Bad, Source}}, LastRow) ->
- case {Good + Bad, Source} of
- {0, _} -> LastRow;
- {_, none} -> LastRow;
- _ ->
- CovPer = round((Good / (Good + Bad)) * 100),
- UnCovPer = round((Bad / (Good + Bad)) * 100),
- RowClass = case LastRow of 1 -> "odd"; _ -> "even" end,
- io:format(IndexFD, "<div class=\"~s\">", [RowClass]),
- io:format(IndexFD, "<a href=\"~s\">~s</a>", [atom_to_list(Module) ++ "_report.html", atom_to_list(Module)]),
- io:format(IndexFD, "
- <table cellspacing='0' cellpadding='0' align='right'>
- <tr>
- <td><tt>~p%</tt>&nbsp;</td><td>
- <table cellspacing='0' class='percent_graph' cellpadding='0' width='100'>
- <tr><td class='covered' width='~p' /><td class='uncovered' width='~p' /></tr>
- </table>
- </td>
- </tr>
- </table>
- ", [CovPer, CovPer, UnCovPer]),
- io:format(IndexFD, "</div>", []),
- case LastRow of
- 1 -> 0;
- 0 -> 1
- end
- end
- end,
- 0,
- lists:sort(Modules)
- ),
- {TotalGood, TotalBad} = lists:foldl(
- fun({_, {Good, Bad, Source}}, {TGood, TBad}) ->
- case Source of none -> {TGood, TBad}; _ -> {TGood + Good, TBad + Bad} end
- end,
- {0, 0},
- Modules
- ),
- io:format(IndexFD, "<p>Generated on ~s.</p>~n", [etap:datetime({date(), time()})]),
- case TotalGood + TotalBad of
- 0 -> ok;
- _ ->
- TotalCovPer = round((TotalGood / (TotalGood + TotalBad)) * 100),
- TotalUnCovPer = round((TotalBad / (TotalGood + TotalBad)) * 100),
- io:format(IndexFD, "<div>", []),
- io:format(IndexFD, "Total
- <table cellspacing='0' cellpadding='0' align='right'>
- <tr>
- <td><tt>~p%</tt>&nbsp;</td><td>
- <table cellspacing='0' class='percent_graph' cellpadding='0' width='100'>
- <tr><td class='covered' width='~p' /><td class='uncovered' width='~p' /></tr>
- </table>
- </td>
- </tr>
- </table>
- ", [TotalCovPer, TotalCovPer, TotalUnCovPer]),
- io:format(IndexFD, "</div>", [])
- end,
- io:format(IndexFD, "</body></html>", []),
- file:close(IndexFD),
- ok.
-
-%% @private
-file_report(Module) ->
- {ok, Data} = cover:analyse(Module, calls, line),
- Source = find_source(Module),
- {Good, Bad} = collect_coverage(Data, {0, 0}),
- case {Source, Good + Bad} of
- {none, _} -> ok;
- {_, 0} -> ok;
- _ ->
- {ok, SourceFD} = file:open(Source, [read]),
- {ok, WriteFD} = file:open("cover/" ++ atom_to_list(Module) ++ "_report.html", [write]),
- io:format(WriteFD, "~s", [header(Module, Good, Bad)]),
- output_lines(Data, WriteFD, SourceFD, 1),
- io:format(WriteFD, "~s", [footer()]),
- file:close(WriteFD),
- file:close(SourceFD),
- ok
- end,
- {Good, Bad, Source}.
-
-%% @private
-collect_coverage([], Acc) -> Acc;
-collect_coverage([{{_, _}, 0} | Data], {Good, Bad}) ->
- collect_coverage(Data, {Good, Bad + 1});
-collect_coverage([_ | Data], {Good, Bad}) ->
- collect_coverage(Data, {Good + 1, Bad}).
-
-%% @private
-output_lines(Data, WriteFD, SourceFD, LineNumber) ->
- {Match, NextData} = datas_match(Data, LineNumber),
- case io:get_line(SourceFD, '') of
- eof -> ok;
- Line = "%% @todo" ++ _ ->
- io:format(WriteFD, "~s", [out_line(LineNumber, highlight, Line)]),
- output_lines(NextData, WriteFD, SourceFD, LineNumber + 1);
- Line = "% " ++ _ ->
- io:format(WriteFD, "~s", [out_line(LineNumber, none, Line)]),
- output_lines(NextData, WriteFD, SourceFD, LineNumber + 1);
- Line ->
- case Match of
- {true, CC} ->
- io:format(WriteFD, "~s", [out_line(LineNumber, CC, Line)]),
- output_lines(NextData, WriteFD, SourceFD, LineNumber + 1);
- false ->
- io:format(WriteFD, "~s", [out_line(LineNumber, none, Line)]),
- output_lines(NextData, WriteFD, SourceFD, LineNumber + 1)
- end
- end.
-
-%% @private
-out_line(Number, none, Line) ->
- PadNu = string:right(integer_to_list(Number), 5, $.),
- io_lib:format("<span class=\"marked\"><a name=\"line~p\"></a>~s ~s</span>", [Number, PadNu, Line]);
-out_line(Number, highlight, Line) ->
- PadNu = string:right(integer_to_list(Number), 5, $.),
- io_lib:format("<span class=\"highlight\"><a name=\"line~p\"></a>~s ~s</span>", [Number, PadNu, Line]);
-out_line(Number, 0, Line) ->
- PadNu = string:right(integer_to_list(Number), 5, $.),
- io_lib:format("<span class=\"uncovered\"><a name=\"line~p\"></a>~s ~s</span>", [Number, PadNu, Line]);
-out_line(Number, _, Line) ->
- PadNu = string:right(integer_to_list(Number), 5, $.),
- io_lib:format("<span class=\"covered\"><a name=\"line~p\"></a>~s ~s</span>", [Number, PadNu, Line]).
-
-%% @private
-datas_match([], _) -> {false, []};
-datas_match([{{_, Line}, CC} | Datas], LineNumber) when Line == LineNumber -> {{true, CC}, Datas};
-datas_match(Data, _) -> {false, Data}.
-
-%% @private
-find_source(Module) when is_atom(Module) ->
- Root = filename:rootname(Module),
- Dir = filename:dirname(Root),
- XDir = case os:getenv("SRC") of false -> "src"; X -> X end,
- find_source([
- filename:join([Dir, Root ++ ".erl"]),
- filename:join([Dir, "..", "src", Root ++ ".erl"]),
- filename:join([Dir, "src", Root ++ ".erl"]),
- filename:join([Dir, "elibs", Root ++ ".erl"]),
- filename:join([Dir, "..", "elibs", Root ++ ".erl"]),
- filename:join([Dir, XDir, Root ++ ".erl"])
- ]);
-find_source([]) -> none;
-find_source([Test | Tests]) ->
- case filelib:is_file(Test) of
- true -> Test;
- false -> find_source(Tests)
- end.
-
-%% @private
-header(Module, Good, Bad) ->
- io:format("Good ~p~n", [Good]),
- io:format("Bad ~p~n", [Bad]),
- CovPer = round((Good / (Good + Bad)) * 100),
- UnCovPer = round((Bad / (Good + Bad)) * 100),
- io:format("CovPer ~p~n", [CovPer]),
- io_lib:format("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
- <html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
- <head>
- <title>~s - C0 code coverage information</title>
- <style type='text/css'>body { background-color: rgb(240, 240, 245); }</style>
- <style type='text/css'>span.marked0 {
- background-color: rgb(185, 210, 200);
- display: block;
- }
- span.marked { display: block; background-color: #ffffff; }
- span.highlight { display: block; background-color: #fff9d7; }
- span.covered { display: block; background-color: #f7f7f7 ; }
- span.uncovered { display: block; background-color: #ffebe8 ; }
- span.overview {
- border-bottom: 1px solid #E2E6EF;
- }
- div.overview {
- border-bottom: 1px solid #E2E6EF;
- }
- body {
- font-family: verdana, arial, helvetica;
- }
- div.footer {
- font-size: 68%;
- margin-top: 1.5em;
- }
- h1, h2, h3, h4, h5, h6 {
- margin-bottom: 0.5em;
- }
- h5 {
- margin-top: 0.5em;
- }
- .hidden {
- display: none;
- }
- div.separator {
- height: 10px;
- }
- table.percent_graph {
- height: 12px;
- border: 1px solid #E2E6EF;
- empty-cells: show;
- }
- table.percent_graph td.covered {
- height: 10px;
- background: #00f000;
- }
- table.percent_graph td.uncovered {
- height: 10px;
- background: #e00000;
- }
- table.percent_graph td.NA {
- height: 10px;
- background: #eaeaea;
- }
- table.report {
- border-collapse: collapse;
- width: 100%;
- }
- table.report td.heading {
- background: #dcecff;
- border: 1px solid #E2E6EF;
- font-weight: bold;
- text-align: center;
- }
- table.report td.heading:hover {
- background: #c0ffc0;
- }
- table.report td.text {
- border: 1px solid #E2E6EF;
- }
- table.report td.value {
- text-align: right;
- border: 1px solid #E2E6EF;
- }
- table.report tr.light {
- background-color: rgb(240, 240, 245);
- }
- table.report tr.dark {
- background-color: rgb(230, 230, 235);
- }
- </style>
- </head>
- <body>
- <h3>C0 code coverage information</h3>
- <p>Generated on ~s with <a href='http://github.com/ngerakines/etap'>etap 0.3.4</a>.
- </p>
- <table class='report'>
- <thead>
- <tr>
- <td class='heading'>Name</td>
- <td class='heading'>Total lines</td>
- <td class='heading'>Lines of code</td>
- <td class='heading'>Total coverage</td>
- <td class='heading'>Code coverage</td>
- </tr>
- </thead>
- <tbody>
- <tr class='light'>
-
- <td>
- <a href='~s'>~s</a>
- </td>
- <td class='value'>
- <tt>??</tt>
- </td>
- <td class='value'>
- <tt>??</tt>
- </td>
- <td class='value'>
- <tt>??</tt>
- </td>
- <td>
- <table cellspacing='0' cellpadding='0' align='right'>
- <tr>
- <td><tt>~p%</tt>&nbsp;</td><td>
- <table cellspacing='0' class='percent_graph' cellpadding='0' width='100'>
- <tr><td class='covered' width='~p' /><td class='uncovered' width='~p' /></tr>
- </table>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </tbody>
- </table><pre>", [Module, etap:datetime({date(), time()}), atom_to_list(Module) ++ "_report.html", Module, CovPer, CovPer, UnCovPer]).
-
-%% @private
-footer() ->
- "</pre><hr /><p>Generated using <a href='http://github.com/ngerakines/etap'>etap 0.3.4</a>.</p>
- </body>
- </html>
- ".
diff --git a/src/etap/etap_request.erl b/src/etap/etap_request.erl
deleted file mode 100644
index 9fd23aca..00000000
--- a/src/etap/etap_request.erl
+++ /dev/null
@@ -1,89 +0,0 @@
-%% Copyright (c) 2008-2009 Nick Gerakines <nick@gerakines.net>
-%%
-%% Permission is hereby granted, free of charge, to any person
-%% obtaining a copy of this software and associated documentation
-%% files (the "Software"), to deal in the Software without
-%% restriction, including without limitation the rights to use,
-%% copy, modify, merge, publish, distribute, sublicense, and/or sell
-%% copies of the Software, and to permit persons to whom the
-%% Software is furnished to do so, subject to the following
-%% conditions:
-%%
-%% The above copyright notice and this permission notice shall be
-%% included in all copies or substantial portions of the Software.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-%% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-%% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-%% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-%% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-%% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-%% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-%% OTHER DEALINGS IN THE SOFTWARE.
-%%
-%% @doc Provides test functionality against a specific web request. Many of
-%% the exported methods can be used to build your own more complex tests.
--module(etap_request, [Method, Url, InHeaders, InBody, Status, OutHeaders, OutBody]).
-
--export([status_is/2]).
-
--export([
- method/0, url/0, status/0, status_code/0, status_line/0, rheaders/0,
- has_rheader/1, rheader/1, rbody/0, header_is/3, body_is/2,
- body_has_string/2
-]).
-
-% ---
-% Tests
-
-%% @doc Assert that response status code is the given status code.
-status_is(Code, Desc) ->
- etap:is(status_code(), Code, Desc).
-
-header_is(Name, Value, Desc) ->
- etap:is(rheader(Name), Value, Desc).
-
-body_is(Value, Desc) ->
- etap:is(rbody(), Value, Desc).
-
-body_has_string(String, Desc) when is_list(OutBody), is_list(String) ->
- etap_string:contains_ok(OutBody, String, Desc).
-
-% ---
-% Accessor functions
-
-%% @doc Access a request's method.
-method() -> Method.
-
-%% @doc Access a request's URL.
-url() -> Url.
-
-%% @doc Access a request's status.
-status() -> Status.
-
-%% @doc Access a request's status code.
-status_code() ->
- {_, Code, _} = Status,
- Code.
-
-%% @doc Access a request's status line.
-status_line() ->
- {_, _, Line} = Status,
- Line.
-
-%% @doc Access a request's headers.
-rheaders() -> OutHeaders.
-
-%% @doc Dertermine if a specific request header exists.
-has_rheader(Key) ->
- lists:keymember(Key, 1, OutHeaders).
-
-%% @doc Return a specific request header.
-rheader(Key) ->
- case lists:keysearch(Key, 1, OutHeaders) of
- false -> undefined;
- {value, {Key, Value}} -> Value
- end.
-
-%% @doc Access the request's body.
-rbody() -> OutBody.
diff --git a/src/etap/etap_string.erl b/src/etap/etap_string.erl
deleted file mode 100644
index 67aa3d54..00000000
--- a/src/etap/etap_string.erl
+++ /dev/null
@@ -1,47 +0,0 @@
-%% Copyright (c) 2008-2009 Nick Gerakines <nick@gerakines.net>
-%%
-%% Permission is hereby granted, free of charge, to any person
-%% obtaining a copy of this software and associated documentation
-%% files (the "Software"), to deal in the Software without
-%% restriction, including without limitation the rights to use,
-%% copy, modify, merge, publish, distribute, sublicense, and/or sell
-%% copies of the Software, and to permit persons to whom the
-%% Software is furnished to do so, subject to the following
-%% conditions:
-%%
-%% The above copyright notice and this permission notice shall be
-%% included in all copies or substantial portions of the Software.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-%% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-%% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-%% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-%% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-%% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-%% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-%% OTHER DEALINGS IN THE SOFTWARE.
-%%
-%% @author Nick Gerakines <nick@gerakines.net> [http://socklabs.com/]
-%% @copyright 2008 Nick Gerakines
-%% @doc Provide testing functionality for strings.
--module(etap_string).
-
--export([contains_ok/3, is_before/4]).
-
-%% @spec contains_ok(string(), string(), string()) -> true | false
-%% @doc Assert that a string is contained in another string.
-contains_ok(Source, String, Desc) ->
- etap:isnt(
- string:str(Source, String),
- 0,
- Desc
- ).
-
-%% @spec is_before(string(), string(), string(), string()) -> true | false
-%% @doc Assert that a string comes before another string within a larger body.
-is_before(Source, StringA, StringB, Desc) ->
- etap:is_greater(
- string:str(Source, StringB),
- string:str(Source, StringA),
- Desc
- ).
diff --git a/src/etap/etap_web.erl b/src/etap/etap_web.erl
deleted file mode 100644
index fb7aee16..00000000
--- a/src/etap/etap_web.erl
+++ /dev/null
@@ -1,65 +0,0 @@
-%% Copyright (c) 2008-2009 Nick Gerakines <nick@gerakines.net>
-%%
-%% Permission is hereby granted, free of charge, to any person
-%% obtaining a copy of this software and associated documentation
-%% files (the "Software"), to deal in the Software without
-%% restriction, including without limitation the rights to use,
-%% copy, modify, merge, publish, distribute, sublicense, and/or sell
-%% copies of the Software, and to permit persons to whom the
-%% Software is furnished to do so, subject to the following
-%% conditions:
-%%
-%% The above copyright notice and this permission notice shall be
-%% included in all copies or substantial portions of the Software.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-%% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-%% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-%% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-%% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-%% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-%% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-%% OTHER DEALINGS IN THE SOFTWARE.
-%%
-%% @author Nick Gerakines <nick@gerakines.net> [http://socklabs.com/]
-%% @copyright 2008 Nick Gerakines
-%% @todo Support cookies.
-%% @doc Provide testing functionality for web requests.
--module(etap_web).
-
--export([simple_200/2, simple_404/2, build_request/4]).
-
-%% @doc Fetch a url and verify that it returned a 200 status.
-simple_200(Url, Desc) ->
- Request = build_request(get, Url, [], []),
- Request:status_is(200, Desc).
-
-%% @doc Fetch a url and verify that it returned a 404 status.
-simple_404(Url, Desc) ->
- Request = build_request(get, Url, [], []),
- Request:status_is(404, Desc).
-
-%% @doc Create and return a request structure.
-build_request(Method, Url, Headers, Body)
- when Method==options;Method==get;Method==head;Method==delete;Method==trace ->
- try http:request(Method, {Url, Headers}, [{autoredirect, false}], []) of
- {ok, {OutStatus, OutHeaders, OutBody}} ->
- etap_request:new(Method, Url, Headers, Body, OutStatus, OutHeaders, OutBody);
- _ -> error
- catch
- _:_ -> error
- end;
-
-%% @doc Create and return a request structure.
-build_request(Method, Url, Headers, Body) when Method == post; Method == put ->
- ContentType = case lists:keysearch("Content-Type", 1, Headers) of
- {value, {"Content-Type", X}} -> X;
- _ -> []
- end,
- try http:request(Method, {Url, Headers, ContentType, Body}, [{autoredirect, false}], []) of
- {ok, {OutStatus, OutHeaders, OutBody}} ->
- etap_request:new(Method, Url, Headers, Body, OutStatus, OutHeaders, OutBody);
- _ -> error
- catch
- _:_ -> error
- end.
diff --git a/src/ibrowse/Makefile.am b/src/ibrowse/Makefile.am
deleted file mode 100644
index 869bd107..00000000
--- a/src/ibrowse/Makefile.am
+++ /dev/null
@@ -1,49 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-ibrowseebindir = $(localerlanglibdir)/ibrowse-2.2.0/ebin
-
-ibrowse_file_collection = \
- ibrowse.app.in \
- ibrowse.erl \
- ibrowse_app.erl \
- ibrowse_http_client.erl \
- ibrowse_lb.erl \
- ibrowse_lib.erl \
- ibrowse_sup.erl \
- ibrowse_test.erl
-
-ibrowseebin_make_generated_file_list = \
- ibrowse.app \
- ibrowse.beam \
- ibrowse_app.beam \
- ibrowse_http_client.beam \
- ibrowse_lb.beam \
- ibrowse_lib.beam \
- ibrowse_sup.beam \
- ibrowse_test.beam
-
-ibrowseebin_DATA = \
- $(ibrowseebin_make_generated_file_list)
-
-EXTRA_DIST = \
- $(ibrowse_file_collection) \
- ibrowse.hrl
-
-CLEANFILES = \
- $(ibrowseebin_make_generated_file_list)
-
-%.app: %.app.in
- cp $< $@
-
-%.beam: %.erl
- $(ERLC) $(ERLC_FLAGS) $<
diff --git a/src/ibrowse/ibrowse.app.in b/src/ibrowse/ibrowse.app.in
deleted file mode 100644
index af46d8a5..00000000
--- a/src/ibrowse/ibrowse.app.in
+++ /dev/null
@@ -1,13 +0,0 @@
-{application, ibrowse,
- [{description, "HTTP client application"},
- {vsn, "2.2.0"},
- {modules, [ ibrowse,
- ibrowse_http_client,
- ibrowse_app,
- ibrowse_sup,
- ibrowse_lib,
- ibrowse_lb ]},
- {registered, []},
- {applications, [kernel,stdlib,sasl]},
- {env, []},
- {mod, {ibrowse_app, []}}]}.
diff --git a/src/ibrowse/ibrowse.erl b/src/ibrowse/ibrowse.erl
deleted file mode 100644
index f70f92f1..00000000
--- a/src/ibrowse/ibrowse.erl
+++ /dev/null
@@ -1,863 +0,0 @@
-%%%-------------------------------------------------------------------
-%%% File : ibrowse.erl
-%%% Author : Chandrashekhar Mullaparthi <chandrashekhar.mullaparthi@t-mobile.co.uk>
-%%% Description : Load balancer process for HTTP client connections.
-%%%
-%%% Created : 11 Oct 2003 by Chandrashekhar Mullaparthi <chandrashekhar.mullaparthi@t-mobile.co.uk>
-%%%-------------------------------------------------------------------
-%% @author Chandrashekhar Mullaparthi <chandrashekhar dot mullaparthi at gmail dot com>
-%% @copyright 2005-2011 Chandrashekhar Mullaparthi
-%% @version 2.1.3
-%% @doc The ibrowse application implements an HTTP 1.1 client in erlang. This
-%% module implements the API of the HTTP client. There is one named
-%% process called 'ibrowse' which assists in load balancing and maintaining configuration. There is one load balancing process per unique webserver. There is
-%% one process to handle one TCP connection to a webserver
-%% (implemented in the module ibrowse_http_client). Multiple connections to a
-%% webserver are setup based on the settings for each webserver. The
-%% ibrowse process also determines which connection to pipeline a
-%% certain request on. The functions to call are send_req/3,
-%% send_req/4, send_req/5, send_req/6.
-%%
-%% <p>Here are a few sample invocations.</p>
-%%
-%% <code>
-%% ibrowse:send_req("http://intranet/messenger/", [], get).
-%% <br/><br/>
-%%
-%% ibrowse:send_req("http://www.google.com/", [], get, [],
-%% [{proxy_user, "XXXXX"},
-%% {proxy_password, "XXXXX"},
-%% {proxy_host, "proxy"},
-%% {proxy_port, 8080}], 1000).
-%% <br/><br/>
-%%
-%%ibrowse:send_req("http://www.erlang.org/download/otp_src_R10B-3.tar.gz", [], get, [],
-%% [{proxy_user, "XXXXX"},
-%% {proxy_password, "XXXXX"},
-%% {proxy_host, "proxy"},
-%% {proxy_port, 8080},
-%% {save_response_to_file, true}], 1000).
-%% <br/><br/>
-%%
-%% ibrowse:send_req("http://www.erlang.org", [], head).
-%%
-%% <br/><br/>
-%% ibrowse:send_req("http://www.sun.com", [], options).
-%%
-%% <br/><br/>
-%% ibrowse:send_req("http://www.bbc.co.uk", [], trace).
-%%
-%% <br/><br/>
-%% ibrowse:send_req("http://www.google.com", [], get, [],
-%% [{stream_to, self()}]).
-%% </code>
-%%
-
--module(ibrowse).
--behaviour(gen_server).
-%%--------------------------------------------------------------------
-%% Include files
-%%--------------------------------------------------------------------
-
-%%--------------------------------------------------------------------
-%% External exports
--export([start_link/0, start/0, stop/0]).
-
-%% gen_server callbacks
--export([init/1, handle_call/3, handle_cast/2, handle_info/2,
- terminate/2, code_change/3]).
-
-%% API interface
--export([
- rescan_config/0,
- rescan_config/1,
- get_config_value/1,
- get_config_value/2,
- spawn_worker_process/1,
- spawn_worker_process/2,
- spawn_link_worker_process/1,
- spawn_link_worker_process/2,
- stop_worker_process/1,
- send_req/3,
- send_req/4,
- send_req/5,
- send_req/6,
- send_req_direct/4,
- send_req_direct/5,
- send_req_direct/6,
- send_req_direct/7,
- stream_next/1,
- stream_close/1,
- set_max_sessions/3,
- set_max_pipeline_size/3,
- set_dest/3,
- trace_on/0,
- trace_off/0,
- trace_on/2,
- trace_off/2,
- all_trace_off/0,
- show_dest_status/0,
- show_dest_status/2
- ]).
-
--ifdef(debug).
--compile(export_all).
--endif.
-
--import(ibrowse_lib, [
- parse_url/1,
- get_value/3,
- do_trace/2
- ]).
-
--record(state, {trace = false}).
-
--include("ibrowse.hrl").
--include_lib("stdlib/include/ms_transform.hrl").
-
--define(DEF_MAX_SESSIONS,10).
--define(DEF_MAX_PIPELINE_SIZE,10).
-
-%%====================================================================
-%% External functions
-%%====================================================================
-%%--------------------------------------------------------------------
-%% Function: start_link/0
-%% Description: Starts the server
-%%--------------------------------------------------------------------
-%% @doc Starts the ibrowse process linked to the calling process. Usually invoked by the supervisor ibrowse_sup
-%% @spec start_link() -> {ok, pid()}
-start_link() ->
- gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
-
-%% @doc Starts the ibrowse process without linking. Useful when testing using the shell
-start() ->
- gen_server:start({local, ?MODULE}, ?MODULE, [], [{debug, []}]).
-
-%% @doc Stop the ibrowse process. Useful when testing using the shell.
-stop() ->
- catch gen_server:call(ibrowse, stop).
-
-%% @doc This is the basic function to send a HTTP request.
-%% The Status return value indicates the HTTP status code returned by the webserver
-%% @spec send_req(Url::string(), Headers::headerList(), Method::method()) -> response()
-%% headerList() = [{header(), value()}]
-%% header() = atom() | string()
-%% value() = term()
-%% method() = get | post | head | options | put | delete | trace | mkcol | propfind | proppatch | lock | unlock | move | copy
-%% Status = string()
-%% ResponseHeaders = [respHeader()]
-%% respHeader() = {headerName(), headerValue()}
-%% headerName() = string()
-%% headerValue() = string()
-%% response() = {ok, Status, ResponseHeaders, ResponseBody} | {ibrowse_req_id, req_id() } | {error, Reason}
-%% req_id() = term()
-%% ResponseBody = string() | {file, Filename}
-%% Reason = term()
-send_req(Url, Headers, Method) ->
- send_req(Url, Headers, Method, [], []).
-
-%% @doc Same as send_req/3.
-%% If a list is specified for the body it has to be a flat list. The body can also be a fun/0 or a fun/1. <br/>
-%% If fun/0, the connection handling process will repeatdely call the fun until it returns an error or eof. <pre>Fun() = {ok, Data} | eof</pre><br/>
-%% If fun/1, the connection handling process will repeatedly call the fun with the supplied state until it returns an error or eof. <pre>Fun(State) = {ok, Data} | {ok, Data, NewState} | eof</pre>
-%% @spec send_req(Url, Headers, Method::method(), Body::body()) -> response()
-%% body() = [] | string() | binary() | fun_arity_0() | {fun_arity_1(), initial_state()}
-%% initial_state() = term()
-send_req(Url, Headers, Method, Body) ->
- send_req(Url, Headers, Method, Body, []).
-
-%% @doc Same as send_req/4.
-%% For a description of SSL Options, look in the <a href="http://www.erlang.org/doc/apps/ssl/index.html">ssl</a> manpage. If the
-%% HTTP Version to use is not specified, the default is 1.1.
-%% <br/>
-%% <ul>
-%% <li>The <code>host_header</code> option is useful in the case where ibrowse is
-%% connecting to a component such as <a
-%% href="http://www.stunnel.org">stunnel</a> which then sets up a
-%% secure connection to a webserver. In this case, the URL supplied to
-%% ibrowse must have the stunnel host/port details, but that won't
-%% make sense to the destination webserver. This option can then be
-%% used to specify what should go in the <code>Host</code> header in
-%% the request.</li>
-%% <li>The <code>stream_to</code> option can be used to have the HTTP
-%% response streamed to a process as messages as data arrives on the
-%% socket. If the calling process wishes to control the rate at which
-%% data is received from the server, the option <code>{stream_to,
-%% {process(), once}}</code> can be specified. The calling process
-%% will have to invoke <code>ibrowse:stream_next(Request_id)</code> to
-%% receive the next packet.</li>
-%%
-%% <li>When both the options <code>save_response_to_file</code> and <code>stream_to</code>
-%% are specified, the former takes precedence.</li>
-%%
-%% <li>For the <code>save_response_to_file</code> option, the response body is saved to
-%% file only if the status code is in the 200-299 range. If not, the response body is returned
-%% as a string.</li>
-%% <li>Whenever an error occurs in the processing of a request, ibrowse will return as much
-%% information as it has, such as HTTP Status Code and HTTP Headers. When this happens, the response
-%% is of the form <code>{error, {Reason, {stat_code, StatusCode}, HTTP_headers}}</code></li>
-%%
-%% <li>The <code>inactivity_timeout</code> option is useful when
-%% dealing with large response bodies and/or slow links. In these
-%% cases, it might be hard to estimate how long a request will take to
-%% complete. In such cases, the client might want to timeout if no
-%% data has been received on the link for a certain time interval.
-%%
-%% This value is also used to close connections which are not in use for
-%% the specified timeout value.
-%% </li>
-%%
-%% <li>
-%% The <code>connect_timeout</code> option is to specify how long the
-%% client process should wait for connection establishment. This is
-%% useful in scenarios where connections to servers are usually setup
-%% very fast, but responses might take much longer compared to
-%% connection setup. In such cases, it is better for the calling
-%% process to timeout faster if there is a problem (DNS lookup
-%% delays/failures, network routing issues, etc). The total timeout
-%% value specified for the request will enforced. To illustrate using
-%% an example:
-%% <code>
-%% ibrowse:send_req("http://www.example.com/cgi-bin/request", [], get, [], [{connect_timeout, 100}], 1000).
-%% </code>
-%% In the above invocation, if the connection isn't established within
-%% 100 milliseconds, the request will fail with
-%% <code>{error, conn_failed}</code>.<br/>
-%% If connection setup succeeds, the total time allowed for the
-%% request to complete will be 1000 milliseconds minus the time taken
-%% for connection setup.
-%% </li>
-%%
-%% <li> The <code>socket_options</code> option can be used to set
-%% specific options on the socket. The <code>{active, true | false | once}</code>
-%% and <code>{packet_type, Packet_type}</code> will be filtered out by ibrowse. </li>
-%%
-%% <li> The <code>headers_as_is</code> option is to enable the caller
-%% to send headers exactly as specified in the request without ibrowse
-%% adding some of its own. Required for some picky servers apparently. </li>
-%%
-%% <li>The <code>give_raw_headers</code> option is to enable the
-%% caller to get access to the raw status line and raw unparsed
-%% headers. Not quite sure why someone would want this, but one of my
-%% users asked for it, so here it is. </li>
-%%
-%% <li> The <code>preserve_chunked_encoding</code> option enables the caller
-%% to receive the raw data stream when the Transfer-Encoding of the server
-%% response is Chunked.
-%% </li>
-%% </ul>
-%%
-%% @spec send_req(Url::string(), Headers::headerList(), Method::method(), Body::body(), Options::optionList()) -> response()
-%% optionList() = [option()]
-%% option() = {max_sessions, integer()} |
-%% {response_format,response_format()}|
-%% {stream_chunk_size, integer()} |
-%% {max_pipeline_size, integer()} |
-%% {trace, boolean()} |
-%% {is_ssl, boolean()} |
-%% {ssl_options, [SSLOpt]} |
-%% {pool_name, atom()} |
-%% {proxy_host, string()} |
-%% {proxy_port, integer()} |
-%% {proxy_user, string()} |
-%% {proxy_password, string()} |
-%% {use_absolute_uri, boolean()} |
-%% {basic_auth, {username(), password()}} |
-%% {cookie, string()} |
-%% {content_length, integer()} |
-%% {content_type, string()} |
-%% {save_response_to_file, srtf()} |
-%% {stream_to, stream_to()} |
-%% {http_vsn, {MajorVsn, MinorVsn}} |
-%% {host_header, string()} |
-%% {inactivity_timeout, integer()} |
-%% {connect_timeout, integer()} |
-%% {socket_options, Sock_opts} |
-%% {transfer_encoding, {chunked, ChunkSize}} |
-%% {headers_as_is, boolean()} |
-%% {give_raw_headers, boolean()} |
-%% {preserve_chunked_encoding,boolean()}
-%%
-%% stream_to() = process() | {process(), once}
-%% process() = pid() | atom()
-%% username() = string()
-%% password() = string()
-%% SSLOpt = term()
-%% Sock_opts = [Sock_opt]
-%% Sock_opt = term()
-%% ChunkSize = integer()
-%% srtf() = boolean() | filename()
-%% filename() = string()
-%% response_format() = list | binary
-send_req(Url, Headers, Method, Body, Options) ->
- send_req(Url, Headers, Method, Body, Options, 30000).
-
-%% @doc Same as send_req/5.
-%% All timeout values are in milliseconds.
-%% @spec send_req(Url, Headers::headerList(), Method::method(), Body::body(), Options::optionList(), Timeout) -> response()
-%% Timeout = integer() | infinity
-send_req(Url, Headers, Method, Body, Options, Timeout) ->
- case catch parse_url(Url) of
- #url{host = Host,
- port = Port,
- protocol = Protocol} = Parsed_url ->
- Lb_pid = case ets:lookup(ibrowse_lb, {Host, Port}) of
- [] ->
- get_lb_pid(Parsed_url);
- [#lb_pid{pid = Lb_pid_1}] ->
- Lb_pid_1
- end,
- Max_sessions = get_max_sessions(Host, Port, Options),
- Max_pipeline_size = get_max_pipeline_size(Host, Port, Options),
- Options_1 = merge_options(Host, Port, Options),
- {SSLOptions, IsSSL} =
- case (Protocol == https) orelse
- get_value(is_ssl, Options_1, false) of
- false -> {[], false};
- true -> {get_value(ssl_options, Options_1, []), true}
- end,
- try_routing_request(Lb_pid, Parsed_url,
- Max_sessions,
- Max_pipeline_size,
- {SSLOptions, IsSSL},
- Headers, Method, Body, Options_1, Timeout, 0);
- Err ->
- {error, {url_parsing_failed, Err}}
- end.
-
-try_routing_request(Lb_pid, Parsed_url,
- Max_sessions,
- Max_pipeline_size,
- {SSLOptions, IsSSL},
- Headers, Method, Body, Options_1, Timeout, Try_count) when Try_count < 3 ->
- case ibrowse_lb:spawn_connection(Lb_pid, Parsed_url,
- Max_sessions,
- Max_pipeline_size,
- {SSLOptions, IsSSL}) of
- {ok, Conn_Pid} ->
- case do_send_req(Conn_Pid, Parsed_url, Headers,
- Method, Body, Options_1, Timeout) of
- {error, sel_conn_closed} ->
- try_routing_request(Lb_pid, Parsed_url,
- Max_sessions,
- Max_pipeline_size,
- {SSLOptions, IsSSL},
- Headers, Method, Body, Options_1, Timeout, Try_count + 1);
- Res ->
- Res
- end;
- Err ->
- Err
- end;
-try_routing_request(_, _, _, _, _, _, _, _, _, _, _) ->
- {error, retry_later}.
-
-merge_options(Host, Port, Options) ->
- Config_options = get_config_value({options, Host, Port}, []),
- lists:foldl(
- fun({Key, Val}, Acc) ->
- case lists:keysearch(Key, 1, Options) of
- false ->
- [{Key, Val} | Acc];
- _ ->
- Acc
- end
- end, Options, Config_options).
-
-get_lb_pid(Url) ->
- gen_server:call(?MODULE, {get_lb_pid, Url}).
-
-get_max_sessions(Host, Port, Options) ->
- get_value(max_sessions, Options,
- get_config_value({max_sessions, Host, Port},
- default_max_sessions())).
-
-get_max_pipeline_size(Host, Port, Options) ->
- get_value(max_pipeline_size, Options,
- get_config_value({max_pipeline_size, Host, Port},
- default_max_pipeline_size())).
-
-default_max_sessions() ->
- safe_get_env(ibrowse, default_max_sessions, ?DEF_MAX_SESSIONS).
-
-default_max_pipeline_size() ->
- safe_get_env(ibrowse, default_max_pipeline_size, ?DEF_MAX_PIPELINE_SIZE).
-
-safe_get_env(App, Key, Def_val) ->
- case application:get_env(App, Key) of
- undefined ->
- Def_val;
- {ok, Val} ->
- Val
- end.
-
-%% @doc Deprecated. Use set_max_sessions/3 and set_max_pipeline_size/3
-%% for achieving the same effect.
-set_dest(Host, Port, [{max_sessions, Max} | T]) ->
- set_max_sessions(Host, Port, Max),
- set_dest(Host, Port, T);
-set_dest(Host, Port, [{max_pipeline_size, Max} | T]) ->
- set_max_pipeline_size(Host, Port, Max),
- set_dest(Host, Port, T);
-set_dest(Host, Port, [{trace, Bool} | T]) when Bool == true; Bool == false ->
- ibrowse ! {trace, true, Host, Port},
- set_dest(Host, Port, T);
-set_dest(_Host, _Port, [H | _]) ->
- exit({invalid_option, H});
-set_dest(_, _, []) ->
- ok.
-
-%% @doc Set the maximum number of connections allowed to a specific Host:Port.
-%% @spec set_max_sessions(Host::string(), Port::integer(), Max::integer()) -> ok
-set_max_sessions(Host, Port, Max) when is_integer(Max), Max > 0 ->
- gen_server:call(?MODULE, {set_config_value, {max_sessions, Host, Port}, Max}).
-
-%% @doc Set the maximum pipeline size for each connection to a specific Host:Port.
-%% @spec set_max_pipeline_size(Host::string(), Port::integer(), Max::integer()) -> ok
-set_max_pipeline_size(Host, Port, Max) when is_integer(Max), Max > 0 ->
- gen_server:call(?MODULE, {set_config_value, {max_pipeline_size, Host, Port}, Max}).
-
-do_send_req(Conn_Pid, Parsed_url, Headers, Method, Body, Options, Timeout) ->
- case catch ibrowse_http_client:send_req(Conn_Pid, Parsed_url,
- Headers, Method, ensure_bin(Body),
- Options, Timeout) of
- {'EXIT', {timeout, _}} ->
- {error, req_timedout};
- {'EXIT', {noproc, {gen_server, call, [Conn_Pid, _, _]}}} ->
- {error, sel_conn_closed};
- {error, connection_closed} ->
- {error, sel_conn_closed};
- {'EXIT', Reason} ->
- {error, {'EXIT', Reason}};
- {ok, St_code, Headers, Body} = Ret when is_binary(Body) ->
- case get_value(response_format, Options, list) of
- list ->
- {ok, St_code, Headers, binary_to_list(Body)};
- binary ->
- Ret
- end;
- Ret ->
- Ret
- end.
-
-ensure_bin(L) when is_list(L) -> list_to_binary(L);
-ensure_bin(B) when is_binary(B) -> B;
-ensure_bin(Fun) when is_function(Fun) -> Fun;
-ensure_bin({Fun}) when is_function(Fun) -> Fun;
-ensure_bin({Fun, _} = Body) when is_function(Fun) -> Body.
-
-%% @doc Creates a HTTP client process to the specified Host:Port which
-%% is not part of the load balancing pool. This is useful in cases
-%% where some requests to a webserver might take a long time whereas
-%% some might take a very short time. To avoid getting these quick
-%% requests stuck in the pipeline behind time consuming requests, use
-%% this function to get a handle to a connection process. <br/>
-%% <b>Note:</b> Calling this function only creates a worker process. No connection
-%% is setup. The connection attempt is made only when the first
-%% request is sent via any of the send_req_direct/4,5,6,7 functions.<br/>
-%% <b>Note:</b> It is the responsibility of the calling process to control
-%% pipeline size on such connections.
-%%
-%% @spec spawn_worker_process(Url::string()) -> {ok, pid()}
-spawn_worker_process(Url) ->
- ibrowse_http_client:start(Url).
-
-%% @doc Same as spawn_worker_process/1 but takes as input a Host and Port
-%% instead of a URL.
-%% @spec spawn_worker_process(Host::string(), Port::integer()) -> {ok, pid()}
-spawn_worker_process(Host, Port) ->
- ibrowse_http_client:start({Host, Port}).
-
-%% @doc Same as spawn_worker_process/1 except the the calling process
-%% is linked to the worker process which is spawned.
-%% @spec spawn_link_worker_process(Url::string()) -> {ok, pid()}
-spawn_link_worker_process(Url) ->
- ibrowse_http_client:start_link(Url).
-
-%% @doc Same as spawn_worker_process/2 except the the calling process
-%% is linked to the worker process which is spawned.
-%% @spec spawn_link_worker_process(Host::string(), Port::integer()) -> {ok, pid()}
-spawn_link_worker_process(Host, Port) ->
- ibrowse_http_client:start_link({Host, Port}).
-
-%% @doc Terminate a worker process spawned using
-%% spawn_worker_process/2 or spawn_link_worker_process/2. Requests in
-%% progress will get the error response <pre>{error, closing_on_request}</pre>
-%% @spec stop_worker_process(Conn_pid::pid()) -> ok
-stop_worker_process(Conn_pid) ->
- ibrowse_http_client:stop(Conn_pid).
-
-%% @doc Same as send_req/3 except that the first argument is the PID
-%% returned by spawn_worker_process/2 or spawn_link_worker_process/2
-send_req_direct(Conn_pid, Url, Headers, Method) ->
- send_req_direct(Conn_pid, Url, Headers, Method, [], []).
-
-%% @doc Same as send_req/4 except that the first argument is the PID
-%% returned by spawn_worker_process/2 or spawn_link_worker_process/2
-send_req_direct(Conn_pid, Url, Headers, Method, Body) ->
- send_req_direct(Conn_pid, Url, Headers, Method, Body, []).
-
-%% @doc Same as send_req/5 except that the first argument is the PID
-%% returned by spawn_worker_process/2 or spawn_link_worker_process/2
-send_req_direct(Conn_pid, Url, Headers, Method, Body, Options) ->
- send_req_direct(Conn_pid, Url, Headers, Method, Body, Options, 30000).
-
-%% @doc Same as send_req/6 except that the first argument is the PID
-%% returned by spawn_worker_process/2 or spawn_link_worker_process/2
-send_req_direct(Conn_pid, Url, Headers, Method, Body, Options, Timeout) ->
- case catch parse_url(Url) of
- #url{host = Host,
- port = Port} = Parsed_url ->
- Options_1 = merge_options(Host, Port, Options),
- case do_send_req(Conn_pid, Parsed_url, Headers, Method, Body, Options_1, Timeout) of
- {error, {'EXIT', {noproc, _}}} ->
- {error, worker_is_dead};
- Ret ->
- Ret
- end;
- Err ->
- {error, {url_parsing_failed, Err}}
- end.
-
-%% @doc Tell ibrowse to stream the next chunk of data to the
-%% caller. Should be used in conjunction with the
-%% <code>stream_to</code> option
-%% @spec stream_next(Req_id :: req_id()) -> ok | {error, unknown_req_id}
-stream_next(Req_id) ->
- case ets:lookup(ibrowse_stream, {req_id_pid, Req_id}) of
- [] ->
- {error, unknown_req_id};
- [{_, Pid}] ->
- catch Pid ! {stream_next, Req_id},
- ok
- end.
-
-%% @doc Tell ibrowse to close the connection associated with the
-%% specified stream. Should be used in conjunction with the
-%% <code>stream_to</code> option. Note that all requests in progress on
-%% the connection which is serving this Req_id will be aborted, and an
-%% error returned.
-%% @spec stream_close(Req_id :: req_id()) -> ok | {error, unknown_req_id}
-stream_close(Req_id) ->
- case ets:lookup(ibrowse_stream, {req_id_pid, Req_id}) of
- [] ->
- {error, unknown_req_id};
- [{_, Pid}] ->
- catch Pid ! {stream_close, Req_id},
- ok
- end.
-
-%% @doc Turn tracing on for the ibrowse process
-trace_on() ->
- ibrowse ! {trace, true}.
-%% @doc Turn tracing off for the ibrowse process
-trace_off() ->
- ibrowse ! {trace, false}.
-
-%% @doc Turn tracing on for all connections to the specified HTTP
-%% server. Host is whatever is specified as the domain name in the URL
-%% @spec trace_on(Host, Port) -> ok
-%% Host = string()
-%% Port = integer()
-trace_on(Host, Port) ->
- ibrowse ! {trace, true, Host, Port},
- ok.
-
-%% @doc Turn tracing OFF for all connections to the specified HTTP
-%% server.
-%% @spec trace_off(Host, Port) -> ok
-trace_off(Host, Port) ->
- ibrowse ! {trace, false, Host, Port},
- ok.
-
-%% @doc Turn Off ALL tracing
-%% @spec all_trace_off() -> ok
-all_trace_off() ->
- ibrowse ! all_trace_off,
- ok.
-
-%% @doc Shows some internal information about load balancing. Info
-%% about workers spawned using spawn_worker_process/2 or
-%% spawn_link_worker_process/2 is not included.
-show_dest_status() ->
- Dests = lists:filter(fun({lb_pid, {Host, Port}, _}) when is_list(Host),
- is_integer(Port) ->
- true;
- (_) ->
- false
- end, ets:tab2list(ibrowse_lb)),
- All_ets = ets:all(),
- io:format("~-40.40s | ~-5.5s | ~-10.10s | ~s~n",
- ["Server:port", "ETS", "Num conns", "LB Pid"]),
- io:format("~80.80.=s~n", [""]),
- lists:foreach(fun({lb_pid, {Host, Port}, Lb_pid}) ->
- case lists:dropwhile(
- fun(Tid) ->
- ets:info(Tid, owner) /= Lb_pid
- end, All_ets) of
- [] ->
- io:format("~40.40s | ~-5.5s | ~-5.5s | ~s~n",
- [Host ++ ":" ++ integer_to_list(Port),
- "",
- "",
- io_lib:format("~p", [Lb_pid])]
- );
- [Tid | _] ->
- catch (
- begin
- Size = ets:info(Tid, size),
- io:format("~40.40s | ~-5.5s | ~-5.5s | ~s~n",
- [Host ++ ":" ++ integer_to_list(Port),
- io_lib:format("~p", [Tid]),
- integer_to_list(Size),
- io_lib:format("~p", [Lb_pid])]
- )
- end
- )
- end
- end, Dests).
-
-%% @doc Shows some internal information about load balancing to a
-%% specified Host:Port. Info about workers spawned using
-%% spawn_worker_process/2 or spawn_link_worker_process/2 is not
-%% included.
-show_dest_status(Host, Port) ->
- case ets:lookup(ibrowse_lb, {Host, Port}) of
- [] ->
- no_active_processes;
- [#lb_pid{pid = Lb_pid}] ->
- io:format("Load Balancer Pid : ~p~n", [Lb_pid]),
- io:format("LB process msg q size : ~p~n", [(catch process_info(Lb_pid, message_queue_len))]),
- case lists:dropwhile(
- fun(Tid) ->
- ets:info(Tid, owner) /= Lb_pid
- end, ets:all()) of
- [] ->
- io:format("Couldn't locate ETS table for ~p~n", [Lb_pid]);
- [Tid | _] ->
- First = ets:first(Tid),
- Last = ets:last(Tid),
- Size = ets:info(Tid, size),
- io:format("LB ETS table id : ~p~n", [Tid]),
- io:format("Num Connections : ~p~n", [Size]),
- case Size of
- 0 ->
- ok;
- _ ->
- {First_p_sz, _} = First,
- {Last_p_sz, _} = Last,
- io:format("Smallest pipeline : ~1000.p~n", [First_p_sz]),
- io:format("Largest pipeline : ~1000.p~n", [Last_p_sz])
- end
- end
- end.
-
-%% @doc Clear current configuration for ibrowse and load from the file
-%% ibrowse.conf in the IBROWSE_EBIN/../priv directory. Current
-%% configuration is cleared only if the ibrowse.conf file is readable
-%% using file:consult/1
-rescan_config() ->
- gen_server:call(?MODULE, rescan_config).
-
-%% Clear current configuration for ibrowse and load from the specified
-%% file. Current configuration is cleared only if the specified
-%% file is readable using file:consult/1
-rescan_config(File) when is_list(File) ->
- gen_server:call(?MODULE, {rescan_config, File}).
-
-%%====================================================================
-%% Server functions
-%%====================================================================
-
-%%--------------------------------------------------------------------
-%% Function: init/1
-%% Description: Initiates the server
-%% Returns: {ok, State} |
-%% {ok, State, Timeout} |
-%% ignore |
-%% {stop, Reason}
-%%--------------------------------------------------------------------
-init(_) ->
- process_flag(trap_exit, true),
- State = #state{},
- put(my_trace_flag, State#state.trace),
- put(ibrowse_trace_token, "ibrowse"),
- ibrowse_lb = ets:new(ibrowse_lb, [named_table, public, {keypos, 2}]),
- ibrowse_conf = ets:new(ibrowse_conf, [named_table, protected, {keypos, 2}]),
- ibrowse_stream = ets:new(ibrowse_stream, [named_table, public]),
- import_config(),
- {ok, #state{}}.
-
-import_config() ->
- case code:priv_dir(ibrowse) of
- {error, _} ->
- ok;
- PrivDir ->
- Filename = filename:join(PrivDir, "ibrowse.conf"),
- import_config(Filename)
- end.
-
-import_config(Filename) ->
- case file:consult(Filename) of
- {ok, Terms} ->
- ets:delete_all_objects(ibrowse_conf),
- Fun = fun({dest, Host, Port, MaxSess, MaxPipe, Options})
- when is_list(Host), is_integer(Port),
- is_integer(MaxSess), MaxSess > 0,
- is_integer(MaxPipe), MaxPipe > 0, is_list(Options) ->
- I = [{{max_sessions, Host, Port}, MaxSess},
- {{max_pipeline_size, Host, Port}, MaxPipe},
- {{options, Host, Port}, Options}],
- lists:foreach(
- fun({X, Y}) ->
- ets:insert(ibrowse_conf,
- #ibrowse_conf{key = X,
- value = Y})
- end, I);
- ({K, V}) ->
- ets:insert(ibrowse_conf,
- #ibrowse_conf{key = K,
- value = V});
- (X) ->
- io:format("Skipping unrecognised term: ~p~n", [X])
- end,
- lists:foreach(Fun, Terms);
- _Err ->
- ok
- end.
-
-%% @doc Internal export
-get_config_value(Key) ->
- [#ibrowse_conf{value = V}] = ets:lookup(ibrowse_conf, Key),
- V.
-
-%% @doc Internal export
-get_config_value(Key, DefVal) ->
- case ets:lookup(ibrowse_conf, Key) of
- [] ->
- DefVal;
- [#ibrowse_conf{value = V}] ->
- V
- end.
-
-set_config_value(Key, Val) ->
- ets:insert(ibrowse_conf, #ibrowse_conf{key = Key, value = Val}).
-%%--------------------------------------------------------------------
-%% Function: handle_call/3
-%% Description: Handling call messages
-%% Returns: {reply, Reply, State} |
-%% {reply, Reply, State, Timeout} |
-%% {noreply, State} |
-%% {noreply, State, Timeout} |
-%% {stop, Reason, Reply, State} | (terminate/2 is called)
-%% {stop, Reason, State} (terminate/2 is called)
-%%--------------------------------------------------------------------
-handle_call({get_lb_pid, #url{host = Host, port = Port} = Url}, _From, State) ->
- Pid = do_get_connection(Url, ets:lookup(ibrowse_lb, {Host, Port})),
- {reply, Pid, State};
-
-handle_call(stop, _From, State) ->
- do_trace("IBROWSE shutting down~n", []),
- ets:foldl(fun(#lb_pid{pid = Pid}, Acc) ->
- ibrowse_lb:stop(Pid),
- Acc
- end, [], ibrowse_lb),
- {stop, normal, ok, State};
-
-handle_call({set_config_value, Key, Val}, _From, State) ->
- set_config_value(Key, Val),
- {reply, ok, State};
-
-handle_call(rescan_config, _From, State) ->
- Ret = (catch import_config()),
- {reply, Ret, State};
-
-handle_call({rescan_config, File}, _From, State) ->
- Ret = (catch import_config(File)),
- {reply, Ret, State};
-
-handle_call(Request, _From, State) ->
- Reply = {unknown_request, Request},
- {reply, Reply, State}.
-
-%%--------------------------------------------------------------------
-%% Function: handle_cast/2
-%% Description: Handling cast messages
-%% Returns: {noreply, State} |
-%% {noreply, State, Timeout} |
-%% {stop, Reason, State} (terminate/2 is called)
-%%--------------------------------------------------------------------
-
-handle_cast(_Msg, State) ->
- {noreply, State}.
-
-%%--------------------------------------------------------------------
-%% Function: handle_info/2
-%% Description: Handling all non call/cast messages
-%% Returns: {noreply, State} |
-%% {noreply, State, Timeout} |
-%% {stop, Reason, State} (terminate/2 is called)
-%%--------------------------------------------------------------------
-handle_info(all_trace_off, State) ->
- Mspec = [{{ibrowse_conf,{trace,'$1','$2'},true},[],[{{'$1','$2'}}]}],
- Trace_on_dests = ets:select(ibrowse_conf, Mspec),
- Fun = fun(#lb_pid{host_port = {H, P}, pid = Pid}, _) ->
- case lists:member({H, P}, Trace_on_dests) of
- false ->
- ok;
- true ->
- catch Pid ! {trace, false}
- end;
- (_, Acc) ->
- Acc
- end,
- ets:foldl(Fun, undefined, ibrowse_lb),
- ets:select_delete(ibrowse_conf, [{{ibrowse_conf,{trace,'$1','$2'},true},[],['true']}]),
- {noreply, State};
-
-handle_info({trace, Bool}, State) ->
- put(my_trace_flag, Bool),
- {noreply, State};
-
-handle_info({trace, Bool, Host, Port}, State) ->
- Fun = fun(#lb_pid{host_port = {H, P}, pid = Pid}, _)
- when H == Host,
- P == Port ->
- catch Pid ! {trace, Bool};
- (_, Acc) ->
- Acc
- end,
- ets:foldl(Fun, undefined, ibrowse_lb),
- ets:insert(ibrowse_conf, #ibrowse_conf{key = {trace, Host, Port},
- value = Bool}),
- {noreply, State};
-
-handle_info(_Info, State) ->
- {noreply, State}.
-
-%%--------------------------------------------------------------------
-%% Function: terminate/2
-%% Description: Shutdown the server
-%% Returns: any (ignored by gen_server)
-%%--------------------------------------------------------------------
-terminate(_Reason, _State) ->
- ok.
-
-%%--------------------------------------------------------------------
-%% Func: code_change/3
-%% Purpose: Convert process state when code is changed
-%% Returns: {ok, NewState}
-%%--------------------------------------------------------------------
-code_change(_OldVsn, State, _Extra) ->
- {ok, State}.
-
-%%--------------------------------------------------------------------
-%%% Internal functions
-%%--------------------------------------------------------------------
-do_get_connection(#url{host = Host, port = Port}, []) ->
- {ok, Pid} = ibrowse_lb:start_link([Host, Port]),
- ets:insert(ibrowse_lb, #lb_pid{host_port = {Host, Port}, pid = Pid}),
- Pid;
-do_get_connection(_Url, [#lb_pid{pid = Pid}]) ->
- Pid.
diff --git a/src/ibrowse/ibrowse.hrl b/src/ibrowse/ibrowse.hrl
deleted file mode 100644
index 18dde827..00000000
--- a/src/ibrowse/ibrowse.hrl
+++ /dev/null
@@ -1,21 +0,0 @@
--ifndef(IBROWSE_HRL).
--define(IBROWSE_HRL, "ibrowse.hrl").
-
--record(url, {
- abspath,
- host,
- port,
- username,
- password,
- path,
- protocol,
- host_type % 'hostname', 'ipv4_address' or 'ipv6_address'
-}).
-
--record(lb_pid, {host_port, pid}).
-
--record(client_conn, {key, cur_pipeline_size = 0, reqs_served = 0}).
-
--record(ibrowse_conf, {key, value}).
-
--endif.
diff --git a/src/ibrowse/ibrowse_app.erl b/src/ibrowse/ibrowse_app.erl
deleted file mode 100644
index d3a0f7bb..00000000
--- a/src/ibrowse/ibrowse_app.erl
+++ /dev/null
@@ -1,63 +0,0 @@
-%%%-------------------------------------------------------------------
-%%% File : ibrowse_app.erl
-%%% Author : Chandrashekhar Mullaparthi <chandrashekhar.mullaparthi@t-mobile.co.uk>
-%%% Description :
-%%%
-%%% Created : 15 Oct 2003 by Chandrashekhar Mullaparthi <chandrashekhar.mullaparthi@t-mobile.co.uk>
-%%%-------------------------------------------------------------------
--module(ibrowse_app).
-
--behaviour(application).
-%%--------------------------------------------------------------------
-%% Include files
-%%--------------------------------------------------------------------
-
-%%--------------------------------------------------------------------
-%% External exports
-%%--------------------------------------------------------------------
--export([
- start/2,
- stop/1
- ]).
-
-%%--------------------------------------------------------------------
-%% Internal exports
-%%--------------------------------------------------------------------
--export([
- ]).
-
-%%--------------------------------------------------------------------
-%% Macros
-%%--------------------------------------------------------------------
-
-%%--------------------------------------------------------------------
-%% Records
-%%--------------------------------------------------------------------
-
-%%====================================================================
-%% External functions
-%%====================================================================
-%%--------------------------------------------------------------------
-%% Func: start/2
-%% Returns: {ok, Pid} |
-%% {ok, Pid, State} |
-%% {error, Reason}
-%%--------------------------------------------------------------------
-start(_Type, _StartArgs) ->
- case ibrowse_sup:start_link() of
- {ok, Pid} ->
- {ok, Pid};
- Error ->
- Error
- end.
-
-%%--------------------------------------------------------------------
-%% Func: stop/1
-%% Returns: any
-%%--------------------------------------------------------------------
-stop(_State) ->
- ok.
-
-%%====================================================================
-%% Internal functions
-%%====================================================================
diff --git a/src/ibrowse/ibrowse_http_client.erl b/src/ibrowse/ibrowse_http_client.erl
deleted file mode 100644
index eb2bf315..00000000
--- a/src/ibrowse/ibrowse_http_client.erl
+++ /dev/null
@@ -1,1855 +0,0 @@
-%%%-------------------------------------------------------------------
-%%% File : ibrowse_http_client.erl
-%%% Author : Chandrashekhar Mullaparthi <chandrashekhar.mullaparthi@t-mobile.co.uk>
-%%% Description : The name says it all
-%%%
-%%% Created : 11 Oct 2003 by Chandrashekhar Mullaparthi <chandrashekhar.mullaparthi@t-mobile.co.uk>
-%%%-------------------------------------------------------------------
--module(ibrowse_http_client).
--behaviour(gen_server).
-%%--------------------------------------------------------------------
-%% Include files
-%%--------------------------------------------------------------------
-
-%%--------------------------------------------------------------------
-%% External exports
--export([
- start_link/1,
- start/1,
- stop/1,
- send_req/7
- ]).
-
--ifdef(debug).
--compile(export_all).
--endif.
-
-%% gen_server callbacks
--export([
- init/1,
- handle_call/3,
- handle_cast/2,
- handle_info/2,
- terminate/2,
- code_change/3
- ]).
-
--include("ibrowse.hrl").
--include_lib("kernel/include/inet.hrl").
-
--record(state, {host, port, connect_timeout,
- inactivity_timer_ref,
- use_proxy = false, proxy_auth_digest,
- ssl_options = [], is_ssl = false, socket,
- proxy_tunnel_setup = false,
- tunnel_setup_queue = [],
- reqs=queue:new(), cur_req, status=idle, http_status_code,
- reply_buffer = <<>>, rep_buf_size=0, streamed_size = 0,
- recvd_headers=[],
- status_line, raw_headers,
- is_closing, send_timer, content_length,
- deleted_crlf = false, transfer_encoding,
- chunk_size, chunk_size_buffer = <<>>,
- recvd_chunk_size, interim_reply_sent = false,
- lb_ets_tid, cur_pipeline_size = 0, prev_req_id
- }).
-
--record(request, {url, method, options, from,
- stream_to, caller_controls_socket = false,
- caller_socket_options = [],
- req_id,
- stream_chunk_size,
- save_response_to_file = false,
- tmp_file_name, tmp_file_fd, preserve_chunked_encoding,
- response_format}).
-
--import(ibrowse_lib, [
- get_value/2,
- get_value/3,
- do_trace/2
- ]).
-
--define(DEFAULT_STREAM_CHUNK_SIZE, 1024*1024).
--define(dec2hex(X), erlang:integer_to_list(X, 16)).
-%%====================================================================
-%% External functions
-%%====================================================================
-%%--------------------------------------------------------------------
-%% Function: start_link/0
-%% Description: Starts the server
-%%--------------------------------------------------------------------
-start(Args) ->
- gen_server:start(?MODULE, Args, []).
-
-start_link(Args) ->
- gen_server:start_link(?MODULE, Args, []).
-
-stop(Conn_pid) ->
- case catch gen_server:call(Conn_pid, stop) of
- {'EXIT', {timeout, _}} ->
- exit(Conn_pid, kill),
- ok;
- _ ->
- ok
- end.
-
-send_req(Conn_Pid, Url, Headers, Method, Body, Options, Timeout) ->
- gen_server:call(
- Conn_Pid,
- {send_req, {Url, Headers, Method, Body, Options, Timeout}}, Timeout).
-
-%%====================================================================
-%% Server functions
-%%====================================================================
-
-%%--------------------------------------------------------------------
-%% Function: init/1
-%% Description: Initiates the server
-%% Returns: {ok, State} |
-%% {ok, State, Timeout} |
-%% ignore |
-%% {stop, Reason}
-%%--------------------------------------------------------------------
-init({Lb_Tid, #url{host = Host, port = Port}, {SSLOptions, Is_ssl}}) ->
- State = #state{host = Host,
- port = Port,
- ssl_options = SSLOptions,
- is_ssl = Is_ssl,
- lb_ets_tid = Lb_Tid},
- put(ibrowse_trace_token, [Host, $:, integer_to_list(Port)]),
- put(my_trace_flag, ibrowse_lib:get_trace_status(Host, Port)),
- {ok, State};
-init(Url) when is_list(Url) ->
- case catch ibrowse_lib:parse_url(Url) of
- #url{protocol = Protocol} = Url_rec ->
- init({undefined, Url_rec, {[], Protocol == https}});
- {'EXIT', _} ->
- {error, invalid_url}
- end;
-init({Host, Port}) ->
- State = #state{host = Host,
- port = Port},
- put(ibrowse_trace_token, [Host, $:, integer_to_list(Port)]),
- put(my_trace_flag, ibrowse_lib:get_trace_status(Host, Port)),
- {ok, State}.
-
-%%--------------------------------------------------------------------
-%% Function: handle_call/3
-%% Description: Handling call messages
-%% Returns: {reply, Reply, State} |
-%% {reply, Reply, State, Timeout} |
-%% {noreply, State} |
-%% {noreply, State, Timeout} |
-%% {stop, Reason, Reply, State} | (terminate/2 is called)
-%% {stop, Reason, State} (terminate/2 is called)
-%%--------------------------------------------------------------------
-%% Received a request when the remote server has already sent us a
-%% Connection: Close header
-handle_call({send_req, _}, _From, #state{is_closing = true} = State) ->
- {reply, {error, connection_closing}, State};
-
-handle_call({send_req, {Url, Headers, Method, Body, Options, Timeout}},
- From, State) ->
- send_req_1(From, Url, Headers, Method, Body, Options, Timeout, State);
-
-handle_call(stop, _From, State) ->
- do_close(State),
- do_error_reply(State, closing_on_request),
- {stop, normal, ok, State};
-
-handle_call(Request, _From, State) ->
- Reply = {unknown_request, Request},
- {reply, Reply, State}.
-
-%%--------------------------------------------------------------------
-%% Function: handle_cast/2
-%% Description: Handling cast messages
-%% Returns: {noreply, State} |
-%% {noreply, State, Timeout} |
-%% {stop, Reason, State} (terminate/2 is called)
-%%--------------------------------------------------------------------
-handle_cast(_Msg, State) ->
- {noreply, State}.
-
-%%--------------------------------------------------------------------
-%% Function: handle_info/2
-%% Description: Handling all non call/cast messages
-%% Returns: {noreply, State} |
-%% {noreply, State, Timeout} |
-%% {stop, Reason, State} (terminate/2 is called)
-%%--------------------------------------------------------------------
-handle_info({tcp, _Sock, Data}, #state{status = Status} = State) ->
-%% io:format("Recvd data: ~p~n", [Data]),
- do_trace("Data recvd in state: ~p. Size: ~p. ~p~n~n", [Status, size(Data), Data]),
- handle_sock_data(Data, State);
-handle_info({ssl, _Sock, Data}, State) ->
- handle_sock_data(Data, State);
-
-handle_info({stream_next, Req_id}, #state{socket = Socket,
- cur_req = #request{req_id = Req_id}} = State) ->
- %% io:format("Client process set {active, once}~n", []),
- do_setopts(Socket, [{active, once}], State),
- {noreply, set_inac_timer(State)};
-
-handle_info({stream_next, _Req_id}, State) ->
- _Cur_req_id = case State#state.cur_req of
- #request{req_id = Cur} ->
- Cur;
- _ ->
- undefined
- end,
-%% io:format("Ignoring stream_next as ~1000.p is not cur req (~1000.p)~n",
-%% [_Req_id, _Cur_req_id]),
- {noreply, State};
-
-handle_info({stream_close, _Req_id}, State) ->
- shutting_down(State),
- do_close(State),
- do_error_reply(State, closing_on_request),
- {stop, normal, State};
-
-handle_info({tcp_closed, _Sock}, State) ->
- do_trace("TCP connection closed by peer!~n", []),
- handle_sock_closed(State),
- {stop, normal, State};
-handle_info({ssl_closed, _Sock}, State) ->
- do_trace("SSL connection closed by peer!~n", []),
- handle_sock_closed(State),
- {stop, normal, State};
-
-handle_info({tcp_error, _Sock, Reason}, State) ->
- do_trace("Error on connection to ~1000.p:~1000.p -> ~1000.p~n",
- [State#state.host, State#state.port, Reason]),
- handle_sock_closed(State),
- {stop, normal, State};
-handle_info({ssl_error, _Sock, Reason}, State) ->
- do_trace("Error on SSL connection to ~1000.p:~1000.p -> ~1000.p~n",
- [State#state.host, State#state.port, Reason]),
- handle_sock_closed(State),
- {stop, normal, State};
-
-handle_info({req_timedout, From}, State) ->
- case lists:keymember(From, #request.from, queue:to_list(State#state.reqs)) of
- false ->
- {noreply, State};
- true ->
- shutting_down(State),
- do_error_reply(State, req_timedout),
- {stop, normal, State}
- end;
-
-handle_info(timeout, State) ->
- do_trace("Inactivity timeout triggered. Shutting down connection~n", []),
- shutting_down(State),
- do_error_reply(State, req_timedout),
- {stop, normal, State};
-
-handle_info({trace, Bool}, State) ->
- put(my_trace_flag, Bool),
- {noreply, State};
-
-handle_info(Info, State) ->
- io:format("Unknown message recvd for ~1000.p:~1000.p -> ~p~n",
- [State#state.host, State#state.port, Info]),
- io:format("Recvd unknown message ~p when in state: ~p~n", [Info, State]),
- {noreply, State}.
-
-%%--------------------------------------------------------------------
-%% Function: terminate/2
-%% Description: Shutdown the server
-%% Returns: any (ignored by gen_server)
-%%--------------------------------------------------------------------
-terminate(_Reason, State) ->
- do_close(State),
- ok.
-
-%%--------------------------------------------------------------------
-%% Func: code_change/3
-%% Purpose: Convert process state when code is changed
-%% Returns: {ok, NewState}
-%%--------------------------------------------------------------------
-code_change(_OldVsn, State, _Extra) ->
- {ok, State}.
-
-%%--------------------------------------------------------------------
-%%% Internal functions
-%%--------------------------------------------------------------------
-
-%%--------------------------------------------------------------------
-%% Handles data recvd on the socket
-%%--------------------------------------------------------------------
-handle_sock_data(Data, #state{status=idle}=State) ->
- do_trace("Data recvd on socket in state idle!. ~1000.p~n", [Data]),
- shutting_down(State),
- do_error_reply(State, data_in_status_idle),
- do_close(State),
- {stop, normal, State};
-
-handle_sock_data(Data, #state{status = get_header}=State) ->
- case parse_response(Data, State) of
- {error, _Reason} ->
- shutting_down(State),
- {stop, normal, State};
- #state{socket = Socket, status = Status, cur_req = CurReq} = State_1 ->
- case {Status, CurReq} of
- {get_header, #request{caller_controls_socket = true}} ->
- do_setopts(Socket, [{active, once}], State_1);
- _ ->
- active_once(State_1)
- end,
- {noreply, set_inac_timer(State_1)}
- end;
-
-handle_sock_data(Data, #state{status = get_body,
- socket = Socket,
- content_length = CL,
- http_status_code = StatCode,
- recvd_headers = Headers,
- chunk_size = CSz} = State) ->
- case (CL == undefined) and (CSz == undefined) of
- true ->
- case accumulate_response(Data, State) of
- {error, Reason} ->
- shutting_down(State),
- fail_pipelined_requests(State,
- {error, {Reason, {stat_code, StatCode}, Headers}}),
- {stop, normal, State};
- State_1 ->
- active_once(State_1),
- State_2 = set_inac_timer(State_1),
- {noreply, State_2}
- end;
- _ ->
- case parse_11_response(Data, State) of
- {error, Reason} ->
- shutting_down(State),
- fail_pipelined_requests(State,
- {error, {Reason, {stat_code, StatCode}, Headers}}),
- {stop, normal, State};
- #state{cur_req = #request{caller_controls_socket = Ccs},
- interim_reply_sent = Irs} = State_1 ->
- case Irs of
- true ->
- active_once(State_1);
- false when Ccs == true ->
- do_setopts(Socket, [{active, once}], State);
- false ->
- active_once(State_1)
- end,
- State_2 = State_1#state{interim_reply_sent = false},
- case Ccs of
- true ->
- cancel_timer(State_2#state.inactivity_timer_ref, {eat_message, timeout}),
- {noreply, State_2#state{inactivity_timer_ref = undefined}};
- _ ->
- {noreply, set_inac_timer(State_2)}
- end;
- State_1 ->
- active_once(State_1),
- State_2 = set_inac_timer(State_1),
- {noreply, State_2}
- end
- end.
-
-accumulate_response(Data,
- #state{
- cur_req = #request{save_response_to_file = Srtf,
- tmp_file_fd = undefined} = CurReq,
- http_status_code=[$2 | _]}=State) when Srtf /= false ->
- TmpFilename = make_tmp_filename(Srtf),
- case file:open(TmpFilename, [write, delayed_write, raw]) of
- {ok, Fd} ->
- accumulate_response(Data, State#state{
- cur_req = CurReq#request{
- tmp_file_fd = Fd,
- tmp_file_name = TmpFilename}});
- {error, Reason} ->
- {error, {file_open_error, Reason}}
- end;
-accumulate_response(Data, #state{cur_req = #request{save_response_to_file = Srtf,
- tmp_file_fd = Fd},
- transfer_encoding=chunked,
- reply_buffer = Reply_buf,
- http_status_code=[$2 | _]
- } = State) when Srtf /= false ->
- case file:write(Fd, [Reply_buf, Data]) of
- ok ->
- State#state{reply_buffer = <<>>};
- {error, Reason} ->
- {error, {file_write_error, Reason}}
- end;
-accumulate_response(Data, #state{cur_req = #request{save_response_to_file = Srtf,
- tmp_file_fd = Fd},
- reply_buffer = RepBuf,
- http_status_code=[$2 | _]
- } = State) when Srtf /= false ->
- case file:write(Fd, [RepBuf, Data]) of
- ok ->
- State#state{reply_buffer = <<>>};
- {error, Reason} ->
- {error, {file_write_error, Reason}}
- end;
-accumulate_response(Data, #state{reply_buffer = RepBuf,
- rep_buf_size = RepBufSize,
- streamed_size = Streamed_size,
- cur_req = CurReq}=State) ->
- #request{stream_to = StreamTo,
- req_id = ReqId,
- stream_chunk_size = Stream_chunk_size,
- response_format = Response_format,
- caller_controls_socket = Caller_controls_socket} = CurReq,
- RepBuf_1 = <<RepBuf/binary, Data/binary>>,
- New_data_size = RepBufSize - Streamed_size,
- case StreamTo of
- undefined ->
- State#state{reply_buffer = RepBuf_1};
- _ when Caller_controls_socket == true ->
- do_interim_reply(StreamTo, Response_format, ReqId, RepBuf_1),
- State#state{reply_buffer = <<>>,
- interim_reply_sent = true,
- streamed_size = Streamed_size + size(RepBuf_1)};
- _ when New_data_size >= Stream_chunk_size ->
- {Stream_chunk, Rem_data} = split_binary(RepBuf_1, Stream_chunk_size),
- do_interim_reply(StreamTo, Response_format, ReqId, Stream_chunk),
- State_1 = State#state{
- reply_buffer = <<>>,
- interim_reply_sent = true,
- streamed_size = Streamed_size + Stream_chunk_size},
- case Rem_data of
- <<>> ->
- State_1;
- _ ->
- accumulate_response(Rem_data, State_1)
- end;
- _ ->
- State#state{reply_buffer = RepBuf_1}
- end.
-
-make_tmp_filename(true) ->
- DownloadDir = ibrowse:get_config_value(download_dir, filename:absname("./")),
- {A,B,C} = now(),
- filename:join([DownloadDir,
- "ibrowse_tmp_file_"++
- integer_to_list(A) ++
- integer_to_list(B) ++
- integer_to_list(C)]);
-make_tmp_filename(File) when is_list(File) ->
- File.
-
-
-%%--------------------------------------------------------------------
-%% Handles the case when the server closes the socket
-%%--------------------------------------------------------------------
-handle_sock_closed(#state{status=get_header} = State) ->
- shutting_down(State),
- do_error_reply(State, connection_closed);
-
-handle_sock_closed(#state{cur_req=undefined} = State) ->
- shutting_down(State);
-
-%% We check for IsClosing because this the server could have sent a
-%% Connection-Close header and has closed the socket to indicate end
-%% of response. There maybe requests pipelined which need a response.
-handle_sock_closed(#state{reply_buffer = Buf, reqs = Reqs, http_status_code = SC,
- is_closing = IsClosing,
- cur_req = #request{tmp_file_name=TmpFilename,
- tmp_file_fd=Fd} = CurReq,
- status = get_body,
- recvd_headers = Headers,
- status_line = Status_line,
- raw_headers = Raw_headers
- }=State) ->
- #request{from=From, stream_to=StreamTo, req_id=ReqId,
- response_format = Resp_format,
- options = Options} = CurReq,
- case IsClosing of
- true ->
- {_, Reqs_1} = queue:out(Reqs),
- Body = case TmpFilename of
- undefined ->
- Buf;
- _ ->
- ok = file:close(Fd),
- {file, TmpFilename}
- end,
- Reply = case get_value(give_raw_headers, Options, false) of
- true ->
- {ok, Status_line, Raw_headers, Body};
- false ->
- {ok, SC, Headers, Buf}
- end,
- State_1 = do_reply(State, From, StreamTo, ReqId, Resp_format, Reply),
- ok = do_error_reply(State_1#state{reqs = Reqs_1}, connection_closed),
- State_1;
- _ ->
- ok = do_error_reply(State, connection_closed),
- State
- end.
-
-do_connect(Host, Port, Options, #state{is_ssl = true,
- use_proxy = false,
- ssl_options = SSLOptions},
- Timeout) ->
- ssl:connect(Host, Port, get_sock_options(Host, Options, SSLOptions), Timeout);
-do_connect(Host, Port, Options, _State, Timeout) ->
- gen_tcp:connect(Host, Port, get_sock_options(Host, Options, []), Timeout).
-
-get_sock_options(Host, Options, SSLOptions) ->
- Caller_socket_options = get_value(socket_options, Options, []),
- Ipv6Options = case is_ipv6_host(Host) of
- true ->
- [inet6];
- false ->
- []
- end,
- Other_sock_options = filter_sock_options(SSLOptions ++ Caller_socket_options ++ Ipv6Options),
- case lists:keysearch(nodelay, 1, Other_sock_options) of
- false ->
- [{nodelay, true}, binary, {active, false} | Other_sock_options];
- {value, _} ->
- [binary, {active, false} | Other_sock_options]
- end.
-
-is_ipv6_host(Host) ->
- case inet_parse:address(Host) of
- {ok, {_, _, _, _, _, _, _, _}} ->
- true;
- {ok, {_, _, _, _}} ->
- false;
- _ ->
- case inet:gethostbyname(Host) of
- {ok, #hostent{h_addrtype = inet6}} ->
- true;
- _ ->
- false
- end
- end.
-
-%% We don't want the caller to specify certain options
-filter_sock_options(Opts) ->
- lists:filter(fun({active, _}) ->
- false;
- ({packet, _}) ->
- false;
- (list) ->
- false;
- (_) ->
- true
- end, Opts).
-
-do_send(Req, #state{socket = Sock,
- is_ssl = true,
- use_proxy = true,
- proxy_tunnel_setup = Pts}) when Pts /= done -> gen_tcp:send(Sock, Req);
-do_send(Req, #state{socket = Sock, is_ssl = true}) -> ssl:send(Sock, Req);
-do_send(Req, #state{socket = Sock, is_ssl = false}) -> gen_tcp:send(Sock, Req).
-
-%% @spec do_send_body(Sock::socket_descriptor(), Source::source_descriptor(), IsSSL::boolean()) -> ok | error()
-%% source_descriptor() = fun_arity_0 |
-%% {fun_arity_0} |
-%% {fun_arity_1, term()}
-%% error() = term()
-do_send_body(Source, State, TE) when is_function(Source) ->
- do_send_body({Source}, State, TE);
-do_send_body({Source}, State, TE) when is_function(Source) ->
- do_send_body1(Source, Source(), State, TE);
-do_send_body({Source, Source_state}, State, TE) when is_function(Source) ->
- do_send_body1(Source, Source(Source_state), State, TE);
-do_send_body(Body, State, _TE) ->
- do_send(Body, State).
-
-do_send_body1(Source, Resp, State, TE) ->
- case Resp of
- {ok, Data} ->
- do_send(maybe_chunked_encode(Data, TE), State),
- do_send_body({Source}, State, TE);
- {ok, Data, New_source_state} ->
- do_send(maybe_chunked_encode(Data, TE), State),
- do_send_body({Source, New_source_state}, State, TE);
- eof when TE == true ->
- do_send(<<"0\r\n\r\n">>, State),
- ok;
- eof ->
- ok;
- Err ->
- Err
- end.
-
-maybe_chunked_encode(Data, false) ->
- Data;
-maybe_chunked_encode(Data, true) ->
- [?dec2hex(iolist_size(Data)), "\r\n", Data, "\r\n"].
-
-do_close(#state{socket = undefined}) -> ok;
-do_close(#state{socket = Sock,
- is_ssl = true,
- use_proxy = true,
- proxy_tunnel_setup = Pts
- }) when Pts /= done -> catch gen_tcp:close(Sock);
-do_close(#state{socket = Sock, is_ssl = true}) -> catch ssl:close(Sock);
-do_close(#state{socket = Sock, is_ssl = false}) -> catch gen_tcp:close(Sock).
-
-active_once(#state{cur_req = #request{caller_controls_socket = true}}) ->
- ok;
-active_once(#state{socket = Socket} = State) ->
- do_setopts(Socket, [{active, once}], State).
-
-do_setopts(_Sock, [], _) -> ok;
-do_setopts(Sock, Opts, #state{is_ssl = true,
- use_proxy = true,
- proxy_tunnel_setup = Pts}
- ) when Pts /= done -> inet:setopts(Sock, Opts);
-do_setopts(Sock, Opts, #state{is_ssl = true}) -> ssl:setopts(Sock, Opts);
-do_setopts(Sock, Opts, _) -> inet:setopts(Sock, Opts).
-
-check_ssl_options(Options, State) ->
- case get_value(is_ssl, Options, false) of
- false ->
- State;
- true ->
- State#state{is_ssl=true, ssl_options=get_value(ssl_options, Options)}
- end.
-
-send_req_1(From,
- #url{host = Host,
- port = Port} = Url,
- Headers, Method, Body, Options, Timeout,
- #state{socket = undefined} = State) ->
- {Host_1, Port_1, State_1} =
- case get_value(proxy_host, Options, false) of
- false ->
- {Host, Port, State};
- PHost ->
- ProxyUser = get_value(proxy_user, Options, []),
- ProxyPassword = get_value(proxy_password, Options, []),
- Digest = http_auth_digest(ProxyUser, ProxyPassword),
- {PHost, get_value(proxy_port, Options, 80),
- State#state{use_proxy = true,
- proxy_auth_digest = Digest}}
- end,
- State_2 = check_ssl_options(Options, State_1),
- do_trace("Connecting...~n", []),
- Conn_timeout = get_value(connect_timeout, Options, Timeout),
- case do_connect(Host_1, Port_1, Options, State_2, Conn_timeout) of
- {ok, Sock} ->
- do_trace("Connected! Socket: ~1000.p~n", [Sock]),
- State_3 = State_2#state{socket = Sock,
- connect_timeout = Conn_timeout},
- send_req_1(From, Url, Headers, Method, Body, Options, Timeout, State_3);
- Err ->
- shutting_down(State_2),
- do_trace("Error connecting. Reason: ~1000.p~n", [Err]),
- gen_server:reply(From, {error, {conn_failed, Err}}),
- {stop, normal, State_2}
- end;
-
-%% Send a CONNECT request.
-%% Wait for 200 OK
-%% Upgrade to SSL connection
-%% Then send request
-
-send_req_1(From,
- #url{
- host = Server_host,
- port = Server_port
- } = Url,
- Headers, Method, Body, Options, Timeout,
- #state{
- proxy_tunnel_setup = false,
- use_proxy = true,
- is_ssl = true} = State) ->
- NewReq = #request{
- method = connect,
- preserve_chunked_encoding = get_value(preserve_chunked_encoding, Options, false),
- options = Options
- },
- State_1 = State#state{reqs=queue:in(NewReq, State#state.reqs)},
- Pxy_auth_headers = maybe_modify_headers(Url, Method, Options, [], State_1),
- Path = [Server_host, $:, integer_to_list(Server_port)],
- {Req, Body_1} = make_request(connect, Pxy_auth_headers,
- Path, Path,
- [], Options, State_1, undefined),
- TE = is_chunked_encoding_specified(Options),
- trace_request(Req),
- case do_send(Req, State) of
- ok ->
- case do_send_body(Body_1, State_1, TE) of
- ok ->
- trace_request_body(Body_1),
- active_once(State_1),
- Ref = case Timeout of
- infinity ->
- undefined;
- _ ->
- erlang:send_after(Timeout, self(), {req_timedout, From})
- end,
- State_2 = State_1#state{status = get_header,
- cur_req = NewReq,
- send_timer = Ref,
- proxy_tunnel_setup = in_progress,
- tunnel_setup_queue = [{From, Url, Headers, Method, Body, Options, Timeout}]},
- State_3 = set_inac_timer(State_2),
- {noreply, State_3};
- Err ->
- shutting_down(State_1),
- do_trace("Send failed... Reason: ~p~n", [Err]),
- gen_server:reply(From, {error, {send_failed, Err}}),
- {stop, normal, State_1}
- end;
- Err ->
- shutting_down(State_1),
- do_trace("Send failed... Reason: ~p~n", [Err]),
- gen_server:reply(From, {error, {send_failed, Err}}),
- {stop, normal, State_1}
- end;
-
-send_req_1(From, Url, Headers, Method, Body, Options, Timeout,
- #state{proxy_tunnel_setup = in_progress,
- tunnel_setup_queue = Q} = State) ->
- do_trace("Queued SSL request awaiting tunnel setup: ~n"
- "URL : ~s~n"
- "Method : ~p~n"
- "Headers : ~p~n", [Url, Method, Headers]),
- {noreply, State#state{tunnel_setup_queue = [{From, Url, Headers, Method, Body, Options, Timeout} | Q]}};
-
-send_req_1(From,
- #url{abspath = AbsPath,
- path = RelPath} = Url,
- Headers, Method, Body, Options, Timeout,
- #state{status = Status,
- socket = Socket} = State) ->
- cancel_timer(State#state.inactivity_timer_ref, {eat_message, timeout}),
- ReqId = make_req_id(),
- Resp_format = get_value(response_format, Options, list),
- Caller_socket_options = get_value(socket_options, Options, []),
- {StreamTo, Caller_controls_socket} =
- case get_value(stream_to, Options, undefined) of
- {Caller, once} when is_pid(Caller) or
- is_atom(Caller) ->
- Async_pid_rec = {{req_id_pid, ReqId}, self()},
- true = ets:insert(ibrowse_stream, Async_pid_rec),
- {Caller, true};
- undefined ->
- {undefined, false};
- Caller when is_pid(Caller) or
- is_atom(Caller) ->
- {Caller, false};
- Stream_to_inv ->
- exit({invalid_option, {stream_to, Stream_to_inv}})
- end,
- SaveResponseToFile = get_value(save_response_to_file, Options, false),
- NewReq = #request{url = Url,
- method = Method,
- stream_to = StreamTo,
- caller_controls_socket = Caller_controls_socket,
- caller_socket_options = Caller_socket_options,
- options = Options,
- req_id = ReqId,
- save_response_to_file = SaveResponseToFile,
- stream_chunk_size = get_stream_chunk_size(Options),
- response_format = Resp_format,
- from = From,
- preserve_chunked_encoding = get_value(preserve_chunked_encoding, Options, false)
- },
- State_1 = State#state{reqs=queue:in(NewReq, State#state.reqs)},
- Headers_1 = maybe_modify_headers(Url, Method, Options, Headers, State_1),
- {Req, Body_1} = make_request(Method,
- Headers_1,
- AbsPath, RelPath, Body, Options, State_1,
- ReqId),
- trace_request(Req),
- do_setopts(Socket, Caller_socket_options, State_1),
- TE = is_chunked_encoding_specified(Options),
- case do_send(Req, State_1) of
- ok ->
- case do_send_body(Body_1, State_1, TE) of
- ok ->
- trace_request_body(Body_1),
- State_2 = inc_pipeline_counter(State_1),
- active_once(State_2),
- Ref = case Timeout of
- infinity ->
- undefined;
- _ ->
- erlang:send_after(Timeout, self(), {req_timedout, From})
- end,
- State_3 = case Status of
- idle ->
- State_2#state{status = get_header,
- cur_req = NewReq,
- send_timer = Ref};
- _ ->
- State_2#state{send_timer = Ref}
- end,
- case StreamTo of
- undefined ->
- ok;
- _ ->
- gen_server:reply(From, {ibrowse_req_id, ReqId})
- end,
- State_4 = set_inac_timer(State_3),
- {noreply, State_4};
- Err ->
- shutting_down(State_1),
- do_trace("Send failed... Reason: ~p~n", [Err]),
- gen_server:reply(From, {error, {send_failed, Err}}),
- {stop, normal, State_1}
- end;
- Err ->
- shutting_down(State_1),
- do_trace("Send failed... Reason: ~p~n", [Err]),
- gen_server:reply(From, {error, {send_failed, Err}}),
- {stop, normal, State_1}
- end.
-
-maybe_modify_headers(#url{}, connect, _, Headers, State) ->
- add_proxy_auth_headers(State, Headers);
-maybe_modify_headers(#url{host = Host, port = Port} = Url,
- _Method,
- Options, Headers, State) ->
- case get_value(headers_as_is, Options, false) of
- false ->
- Headers_1 = add_auth_headers(Url, Options, Headers, State),
- HostHeaderValue = case lists:keysearch(host_header, 1, Options) of
- false ->
- case Port of
- 80 -> Host;
- 443 -> Host;
- _ -> [Host, ":", integer_to_list(Port)]
- end;
- {value, {_, Host_h_val}} ->
- Host_h_val
- end,
- [{"Host", HostHeaderValue} | Headers_1];
- true ->
- Headers
- end.
-
-add_auth_headers(#url{username = User,
- password = UPw},
- Options,
- Headers,
- State) ->
- Headers_1 = case User of
- undefined ->
- case get_value(basic_auth, Options, undefined) of
- undefined ->
- Headers;
- {U,P} ->
- [{"Authorization", ["Basic ", http_auth_digest(U, P)]} | Headers]
- end;
- _ ->
- [{"Authorization", ["Basic ", http_auth_digest(User, UPw)]} | Headers]
- end,
- add_proxy_auth_headers(State, Headers_1).
-
-add_proxy_auth_headers(#state{use_proxy = false}, Headers) ->
- Headers;
-add_proxy_auth_headers(#state{proxy_auth_digest = []}, Headers) ->
- Headers;
-add_proxy_auth_headers(#state{proxy_auth_digest = Auth_digest}, Headers) ->
- [{"Proxy-Authorization", ["Basic ", Auth_digest]} | Headers].
-
-http_auth_digest([], []) ->
- [];
-http_auth_digest(Username, Password) ->
- ibrowse_lib:encode_base64(Username ++ [$: | Password]).
-
-make_request(Method, Headers, AbsPath, RelPath, Body, Options,
- #state{use_proxy = UseProxy, is_ssl = Is_ssl}, ReqId) ->
- HttpVsn = http_vsn_string(get_value(http_vsn, Options, {1,1})),
- Fun1 = fun({X, Y}) when is_atom(X) ->
- {to_lower(atom_to_list(X)), X, Y};
- ({X, Y}) when is_list(X) ->
- {to_lower(X), X, Y}
- end,
- Headers_0 = [Fun1(X) || X <- Headers],
- Headers_1 =
- case lists:keysearch("content-length", 1, Headers_0) of
- false when (Body =:= [] orelse Body =:= <<>>) andalso
- (Method =:= post orelse Method =:= put) ->
- [{"content-length", "Content-Length", "0"} | Headers_0];
- false when is_binary(Body) orelse is_list(Body) ->
- [{"content-length", "Content-Length", integer_to_list(iolist_size(Body))} | Headers_0];
- _ ->
- %% Content-Length is already specified or Body is a
- %% function or function/state pair
- Headers_0
- end,
- {Headers_2, Body_1} =
- case is_chunked_encoding_specified(Options) of
- false ->
- {[{Y, Z} || {_, Y, Z} <- Headers_1], Body};
- true ->
- Chunk_size_1 = case get_value(transfer_encoding, Options) of
- chunked ->
- 5120;
- {chunked, Chunk_size} ->
- Chunk_size
- end,
- {[{Y, Z} || {X, Y, Z} <- Headers_1,
- X /= "content-length"] ++
- [{"Transfer-Encoding", "chunked"}],
- chunk_request_body(Body, Chunk_size_1)}
- end,
- Headers_3 = case lists:member({include_ibrowse_req_id, true}, Options) of
- true ->
- [{"x-ibrowse-request-id", io_lib:format("~1000.p",[ReqId])} | Headers_2];
- false ->
- Headers_2
- end,
- Headers_4 = cons_headers(Headers_3),
- Uri = case get_value(use_absolute_uri, Options, false) or UseProxy of
- true ->
- case Is_ssl of
- true ->
- RelPath;
- false ->
- AbsPath
- end;
- false ->
- RelPath
- end,
- {[method(Method), " ", Uri, " ", HttpVsn, crnl(), Headers_4, crnl()], Body_1}.
-
-is_chunked_encoding_specified(Options) ->
- case get_value(transfer_encoding, Options, false) of
- false ->
- false;
- {chunked, _} ->
- true;
- chunked ->
- true
- end.
-
-http_vsn_string({0,9}) -> "HTTP/0.9";
-http_vsn_string({1,0}) -> "HTTP/1.0";
-http_vsn_string({1,1}) -> "HTTP/1.1".
-
-cons_headers(Headers) ->
- cons_headers(Headers, []).
-cons_headers([], Acc) ->
- encode_headers(Acc);
-cons_headers([{basic_auth, {U,P}} | T], Acc) ->
- cons_headers(T, [{"Authorization",
- ["Basic ", ibrowse_lib:encode_base64(U++":"++P)]} | Acc]);
-cons_headers([{cookie, Cookie} | T], Acc) ->
- cons_headers(T, [{"Cookie", Cookie} | Acc]);
-cons_headers([{content_length, L} | T], Acc) ->
- cons_headers(T, [{"Content-Length", L} | Acc]);
-cons_headers([{content_type, L} | T], Acc) ->
- cons_headers(T, [{"Content-Type", L} | Acc]);
-cons_headers([H | T], Acc) ->
- cons_headers(T, [H | Acc]).
-
-encode_headers(L) ->
- encode_headers(L, []).
-encode_headers([{http_vsn, _Val} | T], Acc) ->
- encode_headers(T, Acc);
-encode_headers([{Name,Val} | T], Acc) when is_list(Name) ->
- encode_headers(T, [[Name, ": ", fmt_val(Val), crnl()] | Acc]);
-encode_headers([{Name,Val} | T], Acc) when is_atom(Name) ->
- encode_headers(T, [[atom_to_list(Name), ": ", fmt_val(Val), crnl()] | Acc]);
-encode_headers([], Acc) ->
- lists:reverse(Acc).
-
-chunk_request_body(Body, _ChunkSize) when is_tuple(Body) orelse
- is_function(Body) ->
- Body;
-chunk_request_body(Body, ChunkSize) ->
- chunk_request_body(Body, ChunkSize, []).
-
-chunk_request_body(Body, _ChunkSize, Acc) when Body == <<>>; Body == [] ->
- LastChunk = "0\r\n",
- lists:reverse(["\r\n", LastChunk | Acc]);
-chunk_request_body(Body, ChunkSize, Acc) when is_binary(Body),
- size(Body) >= ChunkSize ->
- <<ChunkBody:ChunkSize/binary, Rest/binary>> = Body,
- Chunk = [?dec2hex(ChunkSize),"\r\n",
- ChunkBody, "\r\n"],
- chunk_request_body(Rest, ChunkSize, [Chunk | Acc]);
-chunk_request_body(Body, _ChunkSize, Acc) when is_binary(Body) ->
- BodySize = size(Body),
- Chunk = [?dec2hex(BodySize),"\r\n",
- Body, "\r\n"],
- LastChunk = "0\r\n",
- lists:reverse(["\r\n", LastChunk, Chunk | Acc]);
-chunk_request_body(Body, ChunkSize, Acc) when length(Body) >= ChunkSize ->
- {ChunkBody, Rest} = split_list_at(Body, ChunkSize),
- Chunk = [?dec2hex(ChunkSize),"\r\n",
- ChunkBody, "\r\n"],
- chunk_request_body(Rest, ChunkSize, [Chunk | Acc]);
-chunk_request_body(Body, _ChunkSize, Acc) when is_list(Body) ->
- BodySize = length(Body),
- Chunk = [?dec2hex(BodySize),"\r\n",
- Body, "\r\n"],
- LastChunk = "0\r\n",
- lists:reverse(["\r\n", LastChunk, Chunk | Acc]).
-
-
-parse_response(_Data, #state{cur_req = undefined}=State) ->
- State#state{status = idle};
-parse_response(Data, #state{reply_buffer = Acc, reqs = Reqs,
- cur_req = CurReq} = State) ->
- #request{from=From, stream_to=StreamTo, req_id=ReqId,
- method=Method, response_format = Resp_format,
- options = Options
- } = CurReq,
- MaxHeaderSize = ibrowse:get_config_value(max_headers_size, infinity),
- case scan_header(Acc, Data) of
- {yes, Headers, Data_1} ->
- do_trace("Recvd Header Data -> ~s~n----~n", [Headers]),
- do_trace("Recvd headers~n--- Headers Begin ---~n~s~n--- Headers End ---~n~n", [Headers]),
- {HttpVsn, StatCode, Headers_1, Status_line, Raw_headers} = parse_headers(Headers),
- do_trace("HttpVsn: ~p StatusCode: ~p Headers_1 -> ~1000.p~n", [HttpVsn, StatCode, Headers_1]),
- LCHeaders = [{to_lower(X), Y} || {X,Y} <- Headers_1],
- ConnClose = to_lower(get_value("connection", LCHeaders, "false")),
- IsClosing = is_connection_closing(HttpVsn, ConnClose),
- case IsClosing of
- true ->
- shutting_down(State);
- false ->
- ok
- end,
- Give_raw_headers = get_value(give_raw_headers, Options, false),
- State_1 = case Give_raw_headers of
- true ->
- State#state{recvd_headers=Headers_1, status=get_body,
- reply_buffer = <<>>,
- status_line = Status_line,
- raw_headers = Raw_headers,
- http_status_code=StatCode, is_closing=IsClosing};
- false ->
- State#state{recvd_headers=Headers_1, status=get_body,
- reply_buffer = <<>>,
- http_status_code=StatCode, is_closing=IsClosing}
- end,
- put(conn_close, ConnClose),
- TransferEncoding = to_lower(get_value("transfer-encoding", LCHeaders, "false")),
- case get_value("content-length", LCHeaders, undefined) of
- _ when Method == connect,
- hd(StatCode) == $2 ->
- cancel_timer(State#state.send_timer),
- {_, Reqs_1} = queue:out(Reqs),
- upgrade_to_ssl(set_cur_request(State#state{reqs = Reqs_1,
- recvd_headers = [],
- status = idle
- }));
- _ when Method == connect ->
- {_, Reqs_1} = queue:out(Reqs),
- do_error_reply(State#state{reqs = Reqs_1},
- {error, proxy_tunnel_failed}),
- {error, proxy_tunnel_failed};
- _ when Method == head ->
- {_, Reqs_1} = queue:out(Reqs),
- send_async_headers(ReqId, StreamTo, Give_raw_headers, State_1),
- State_1_1 = do_reply(State_1, From, StreamTo, ReqId, Resp_format,
- {ok, StatCode, Headers_1, []}),
- cancel_timer(State_1_1#state.send_timer, {eat_message, {req_timedout, From}}),
- State_2 = reset_state(State_1_1),
- State_3 = set_cur_request(State_2#state{reqs = Reqs_1}),
- parse_response(Data_1, State_3);
- _ when hd(StatCode) =:= $1 ->
- %% No message body is expected. Server may send
- %% one or more 1XX responses before a proper
- %% response.
- send_async_headers(ReqId, StreamTo, Give_raw_headers, State_1),
- do_trace("Recvd a status code of ~p. Ignoring and waiting for a proper response~n", [StatCode]),
- parse_response(Data_1, State_1#state{recvd_headers = [],
- status = get_header});
- _ when StatCode =:= "204";
- StatCode =:= "304" ->
- %% No message body is expected for these Status Codes.
- %% RFC2616 - Sec 4.4
- {_, Reqs_1} = queue:out(Reqs),
- send_async_headers(ReqId, StreamTo, Give_raw_headers, State_1),
- State_1_1 = do_reply(State_1, From, StreamTo, ReqId, Resp_format,
- {ok, StatCode, Headers_1, []}),
- cancel_timer(State_1_1#state.send_timer, {eat_message, {req_timedout, From}}),
- State_2 = reset_state(State_1_1),
- State_3 = set_cur_request(State_2#state{reqs = Reqs_1}),
- parse_response(Data_1, State_3);
- _ when TransferEncoding =:= "chunked" ->
- do_trace("Chunked encoding detected...~n",[]),
- send_async_headers(ReqId, StreamTo, Give_raw_headers, State_1),
- case parse_11_response(Data_1, State_1#state{transfer_encoding=chunked,
- chunk_size=chunk_start,
- reply_buffer = <<>>}) of
- {error, Reason} ->
- fail_pipelined_requests(State_1,
- {error, {Reason,
- {stat_code, StatCode}, Headers_1}}),
- {error, Reason};
- State_2 ->
- State_2
- end;
- undefined when HttpVsn =:= "HTTP/1.0";
- ConnClose =:= "close" ->
- send_async_headers(ReqId, StreamTo, Give_raw_headers, State_1),
- State_1#state{reply_buffer = Data_1};
- undefined ->
- fail_pipelined_requests(State_1,
- {error, {content_length_undefined,
- {stat_code, StatCode}, Headers}}),
- {error, content_length_undefined};
- V ->
- case catch list_to_integer(V) of
- V_1 when is_integer(V_1), V_1 >= 0 ->
- send_async_headers(ReqId, StreamTo, Give_raw_headers, State_1),
- do_trace("Recvd Content-Length of ~p~n", [V_1]),
- State_2 = State_1#state{rep_buf_size=0,
- reply_buffer = <<>>,
- content_length=V_1},
- case parse_11_response(Data_1, State_2) of
- {error, Reason} ->
- fail_pipelined_requests(State_1,
- {error, {Reason,
- {stat_code, StatCode}, Headers_1}}),
- {error, Reason};
- State_3 ->
- State_3
- end;
- _ ->
- fail_pipelined_requests(State_1,
- {error, {content_length_undefined,
- {stat_code, StatCode}, Headers}}),
- {error, content_length_undefined}
- end
- end;
- {no, Acc_1} when MaxHeaderSize == infinity ->
- State#state{reply_buffer = Acc_1};
- {no, Acc_1} when size(Acc_1) < MaxHeaderSize ->
- State#state{reply_buffer = Acc_1};
- {no, _Acc_1} ->
- fail_pipelined_requests(State, {error, max_headers_size_exceeded}),
- {error, max_headers_size_exceeded}
- end.
-
-upgrade_to_ssl(#state{socket = Socket,
- connect_timeout = Conn_timeout,
- ssl_options = Ssl_options,
- tunnel_setup_queue = Q} = State) ->
- case ssl:connect(Socket, Ssl_options, Conn_timeout) of
- {ok, Ssl_socket} ->
- do_trace("Upgraded to SSL socket!!~n", []),
- State_1 = State#state{socket = Ssl_socket,
- proxy_tunnel_setup = done},
- send_queued_requests(lists:reverse(Q), State_1);
- Err ->
- do_trace("Upgrade to SSL socket failed. Reson: ~p~n", [Err]),
- do_error_reply(State, {error, {send_failed, Err}}),
- {error, send_failed}
- end.
-
-send_queued_requests([], State) ->
- do_trace("Sent all queued requests via SSL connection~n", []),
- State#state{tunnel_setup_queue = []};
-send_queued_requests([{From, Url, Headers, Method, Body, Options, Timeout} | Q],
- State) ->
- case send_req_1(From, Url, Headers, Method, Body, Options, Timeout, State) of
- {noreply, State_1} ->
- send_queued_requests(Q, State_1);
- Err ->
- do_trace("Error sending queued SSL request: ~n"
- "URL : ~s~n"
- "Method : ~p~n"
- "Headers : ~p~n", [Url, Method, Headers]),
- do_error_reply(State, {error, {send_failed, Err}}),
- {error, send_failed}
- end.
-
-is_connection_closing("HTTP/0.9", _) -> true;
-is_connection_closing(_, "close") -> true;
-is_connection_closing("HTTP/1.0", "false") -> true;
-is_connection_closing(_, _) -> false.
-
-%% This clause determines the chunk size when given data from the beginning of the chunk
-parse_11_response(DataRecvd,
- #state{transfer_encoding = chunked,
- chunk_size = chunk_start,
- chunk_size_buffer = Chunk_sz_buf
- } = State) ->
- case scan_crlf(Chunk_sz_buf, DataRecvd) of
- {yes, ChunkHeader, Data_1} ->
- State_1 = maybe_accumulate_ce_data(State, <<ChunkHeader/binary, $\r, $\n>>),
- ChunkSize = parse_chunk_header(ChunkHeader),
- %%
- %% Do we have to preserve the chunk encoding when
- %% streaming? NO. This should be transparent to the client
- %% process. Chunked encoding was only introduced to make
- %% it efficient for the server.
- %%
- RemLen = size(Data_1),
- do_trace("Determined chunk size: ~p. Already recvd: ~p~n",
- [ChunkSize, RemLen]),
- parse_11_response(Data_1, State_1#state{chunk_size_buffer = <<>>,
- deleted_crlf = true,
- recvd_chunk_size = 0,
- chunk_size = ChunkSize});
- {no, Data_1} ->
- State#state{chunk_size_buffer = Data_1}
- end;
-
-%% This clause is to remove the CRLF between two chunks
-%%
-parse_11_response(DataRecvd,
- #state{transfer_encoding = chunked,
- chunk_size = tbd,
- chunk_size_buffer = Buf
- } = State) ->
- case scan_crlf(Buf, DataRecvd) of
- {yes, _, NextChunk} ->
- State_1 = maybe_accumulate_ce_data(State, <<$\r, $\n>>),
- State_2 = State_1#state{chunk_size = chunk_start,
- chunk_size_buffer = <<>>,
- deleted_crlf = true},
- parse_11_response(NextChunk, State_2);
- {no, Data_1} ->
- State#state{chunk_size_buffer = Data_1}
- end;
-
-%% This clause deals with the end of a chunked transfer. ibrowse does
-%% not support Trailers in the Chunked Transfer encoding. Any trailer
-%% received is silently discarded.
-parse_11_response(DataRecvd,
- #state{transfer_encoding = chunked, chunk_size = 0,
- cur_req = CurReq,
- deleted_crlf = DelCrlf,
- chunk_size_buffer = Trailer,
- reqs = Reqs} = State) ->
- do_trace("Detected end of chunked transfer...~n", []),
- DataRecvd_1 = case DelCrlf of
- false ->
- DataRecvd;
- true ->
- <<$\r, $\n, DataRecvd/binary>>
- end,
- case scan_header(Trailer, DataRecvd_1) of
- {yes, TEHeaders, Rem} ->
- {_, Reqs_1} = queue:out(Reqs),
- State_1 = maybe_accumulate_ce_data(State, <<TEHeaders/binary, $\r, $\n>>),
- State_2 = handle_response(CurReq,
- State_1#state{reqs = Reqs_1}),
- parse_response(Rem, reset_state(State_2));
- {no, Rem} ->
- accumulate_response(<<>>, State#state{chunk_size_buffer = Rem, deleted_crlf = false})
- end;
-
-%% This clause extracts a chunk, given the size.
-parse_11_response(DataRecvd,
- #state{transfer_encoding = chunked,
- chunk_size = CSz,
- recvd_chunk_size = Recvd_csz,
- rep_buf_size = RepBufSz} = State) ->
- NeedBytes = CSz - Recvd_csz,
- DataLen = size(DataRecvd),
- do_trace("Recvd more data: size: ~p. NeedBytes: ~p~n", [DataLen, NeedBytes]),
- case DataLen >= NeedBytes of
- true ->
- {RemChunk, RemData} = split_binary(DataRecvd, NeedBytes),
- do_trace("Recvd another chunk...~p~n", [RemChunk]),
- do_trace("RemData -> ~p~n", [RemData]),
- case accumulate_response(RemChunk, State) of
- {error, Reason} ->
- do_trace("Error accumulating response --> ~p~n", [Reason]),
- {error, Reason};
- #state{} = State_1 ->
- State_2 = State_1#state{chunk_size=tbd},
- parse_11_response(RemData, State_2)
- end;
- false ->
- accumulate_response(DataRecvd,
- State#state{rep_buf_size = RepBufSz + DataLen,
- recvd_chunk_size = Recvd_csz + DataLen})
- end;
-
-%% This clause to extract the body when Content-Length is specified
-parse_11_response(DataRecvd,
- #state{content_length=CL, rep_buf_size=RepBufSz,
- reqs=Reqs}=State) ->
- NeedBytes = CL - RepBufSz,
- DataLen = size(DataRecvd),
- case DataLen >= NeedBytes of
- true ->
- {RemBody, Rem} = split_binary(DataRecvd, NeedBytes),
- {_, Reqs_1} = queue:out(Reqs),
- State_1 = accumulate_response(RemBody, State),
- State_2 = handle_response(State_1#state.cur_req, State_1#state{reqs=Reqs_1}),
- State_3 = reset_state(State_2),
- parse_response(Rem, State_3);
- false ->
- accumulate_response(DataRecvd, State#state{rep_buf_size = (RepBufSz+DataLen)})
- end.
-
-maybe_accumulate_ce_data(#state{cur_req = #request{preserve_chunked_encoding = false}} = State, _) ->
- State;
-maybe_accumulate_ce_data(State, Data) ->
- accumulate_response(Data, State).
-
-handle_response(#request{from=From, stream_to=StreamTo, req_id=ReqId,
- response_format = Resp_format,
- save_response_to_file = SaveResponseToFile,
- tmp_file_name = TmpFilename,
- tmp_file_fd = Fd,
- options = Options
- },
- #state{http_status_code = SCode,
- status_line = Status_line,
- raw_headers = Raw_headers,
- send_timer = ReqTimer,
- reply_buffer = RepBuf,
- recvd_headers = RespHeaders}=State) when SaveResponseToFile /= false ->
- Body = RepBuf,
- case Fd of
- undefined ->
- ok;
- _ ->
- ok = file:close(Fd)
- end,
- ResponseBody = case TmpFilename of
- undefined ->
- Body;
- _ ->
- {file, TmpFilename}
- end,
- {Resp_headers_1, Raw_headers_1} = maybe_add_custom_headers(RespHeaders, Raw_headers, Options),
- Reply = case get_value(give_raw_headers, Options, false) of
- true ->
- {ok, Status_line, Raw_headers_1, ResponseBody};
- false ->
- {ok, SCode, Resp_headers_1, ResponseBody}
- end,
- State_1 = do_reply(State, From, StreamTo, ReqId, Resp_format, Reply),
- cancel_timer(ReqTimer, {eat_message, {req_timedout, From}}),
- set_cur_request(State_1);
-handle_response(#request{from=From, stream_to=StreamTo, req_id=ReqId,
- response_format = Resp_format,
- options = Options},
- #state{http_status_code = SCode,
- status_line = Status_line,
- raw_headers = Raw_headers,
- recvd_headers = Resp_headers,
- reply_buffer = RepBuf,
- send_timer = ReqTimer} = State) ->
- Body = RepBuf,
- {Resp_headers_1, Raw_headers_1} = maybe_add_custom_headers(Resp_headers, Raw_headers, Options),
- Reply = case get_value(give_raw_headers, Options, false) of
- true ->
- {ok, Status_line, Raw_headers_1, Body};
- false ->
- {ok, SCode, Resp_headers_1, Body}
- end,
- State_1 = do_reply(State, From, StreamTo, ReqId, Resp_format, Reply),
- cancel_timer(ReqTimer, {eat_message, {req_timedout, From}}),
- set_cur_request(State_1).
-
-reset_state(State) ->
- State#state{status = get_header,
- rep_buf_size = 0,
- streamed_size = 0,
- content_length = undefined,
- reply_buffer = <<>>,
- chunk_size_buffer = <<>>,
- recvd_headers = [],
- status_line = undefined,
- raw_headers = undefined,
- deleted_crlf = false,
- http_status_code = undefined,
- chunk_size = undefined,
- transfer_encoding = undefined
- }.
-
-set_cur_request(#state{reqs = Reqs, socket = Socket} = State) ->
- case queue:to_list(Reqs) of
- [] ->
- State#state{cur_req = undefined};
- [#request{caller_controls_socket = Ccs} = NextReq | _] ->
- case Ccs of
- true ->
- do_setopts(Socket, [{active, once}], State);
- _ ->
- ok
- end,
- State#state{cur_req = NextReq}
- end.
-
-parse_headers(Headers) ->
- case scan_crlf(Headers) of
- {yes, StatusLine, T} ->
- parse_headers(StatusLine, T);
- {no, StatusLine} ->
- parse_headers(StatusLine, <<>>)
- end.
-
-parse_headers(StatusLine, Headers) ->
- Headers_1 = parse_headers_1(Headers),
- case parse_status_line(StatusLine) of
- {ok, HttpVsn, StatCode, _Msg} ->
- put(http_prot_vsn, HttpVsn),
- {HttpVsn, StatCode, Headers_1, StatusLine, Headers};
- _ -> %% A HTTP 0.9 response?
- put(http_prot_vsn, "HTTP/0.9"),
- {"HTTP/0.9", undefined, Headers, StatusLine, Headers}
- end.
-
-% From RFC 2616
-%
-% HTTP/1.1 header field values can be folded onto multiple lines if
-% the continuation line begins with a space or horizontal tab. All
-% linear white space, including folding, has the same semantics as
-% SP. A recipient MAY replace any linear white space with a single
-% SP before interpreting the field value or forwarding the message
-% downstream.
-parse_headers_1(B) when is_binary(B) ->
- parse_headers_1(binary_to_list(B));
-parse_headers_1(String) ->
- parse_headers_1(String, [], []).
-
-parse_headers_1([$\n, H |T], [$\r | L], Acc) when H =:= 32;
- H =:= $\t ->
- parse_headers_1(lists:dropwhile(fun(X) ->
- is_whitespace(X)
- end, T), [32 | L], Acc);
-parse_headers_1([$\n|T], [$\r | L], Acc) ->
- case parse_header(lists:reverse(L)) of
- invalid ->
- parse_headers_1(T, [], Acc);
- NewHeader ->
- parse_headers_1(T, [], [NewHeader | Acc])
- end;
-parse_headers_1([H|T], L, Acc) ->
- parse_headers_1(T, [H|L], Acc);
-parse_headers_1([], [], Acc) ->
- lists:reverse(Acc);
-parse_headers_1([], L, Acc) ->
- Acc_1 = case parse_header(lists:reverse(L)) of
- invalid ->
- Acc;
- NewHeader ->
- [NewHeader | Acc]
- end,
- lists:reverse(Acc_1).
-
-parse_status_line(Line) when is_binary(Line) ->
- parse_status_line(binary_to_list(Line));
-parse_status_line(Line) ->
- parse_status_line(Line, get_prot_vsn, [], []).
-parse_status_line([32 | T], get_prot_vsn, ProtVsn, StatCode) ->
- parse_status_line(T, get_status_code, ProtVsn, StatCode);
-parse_status_line([32 | T], get_status_code, ProtVsn, StatCode) ->
- {ok, lists:reverse(ProtVsn), lists:reverse(StatCode), T};
-parse_status_line([], get_status_code, ProtVsn, StatCode) ->
- {ok, lists:reverse(ProtVsn), lists:reverse(StatCode), []};
-parse_status_line([H | T], get_prot_vsn, ProtVsn, StatCode) ->
- parse_status_line(T, get_prot_vsn, [H|ProtVsn], StatCode);
-parse_status_line([H | T], get_status_code, ProtVsn, StatCode) ->
- parse_status_line(T, get_status_code, ProtVsn, [H | StatCode]);
-parse_status_line([], _, _, _) ->
- http_09.
-
-parse_header(L) ->
- parse_header(L, []).
-
-parse_header([$: | V], Acc) ->
- {lists:reverse(Acc), string:strip(V)};
-parse_header([H | T], Acc) ->
- parse_header(T, [H | Acc]);
-parse_header([], _) ->
- invalid.
-
-scan_header(Bin) ->
- case get_crlf_crlf_pos(Bin, 0) of
- {yes, Pos} ->
- {Headers, <<_:4/binary, Body/binary>>} = split_binary(Bin, Pos),
- {yes, Headers, Body};
- no ->
- {no, Bin}
- end.
-
-scan_header(Bin1, Bin2) when size(Bin1) < 4 ->
- scan_header(<<Bin1/binary, Bin2/binary>>);
-scan_header(Bin1, <<>>) ->
- scan_header(Bin1);
-scan_header(Bin1, Bin2) ->
- Bin1_already_scanned_size = size(Bin1) - 4,
- <<Headers_prefix:Bin1_already_scanned_size/binary, Rest/binary>> = Bin1,
- Bin_to_scan = <<Rest/binary, Bin2/binary>>,
- case get_crlf_crlf_pos(Bin_to_scan, 0) of
- {yes, Pos} ->
- {Headers_suffix, <<_:4/binary, Body/binary>>} = split_binary(Bin_to_scan, Pos),
- {yes, <<Headers_prefix/binary, Headers_suffix/binary>>, Body};
- no ->
- {no, <<Bin1/binary, Bin2/binary>>}
- end.
-
-get_crlf_crlf_pos(<<$\r, $\n, $\r, $\n, _/binary>>, Pos) -> {yes, Pos};
-get_crlf_crlf_pos(<<_, Rest/binary>>, Pos) -> get_crlf_crlf_pos(Rest, Pos + 1);
-get_crlf_crlf_pos(<<>>, _) -> no.
-
-scan_crlf(Bin) ->
- case get_crlf_pos(Bin) of
- {yes, Pos} ->
- {Prefix, <<_, _, Suffix/binary>>} = split_binary(Bin, Pos),
- {yes, Prefix, Suffix};
- no ->
- {no, Bin}
- end.
-
-scan_crlf(<<>>, Bin2) ->
- scan_crlf(Bin2);
-scan_crlf(Bin1, Bin2) when size(Bin1) < 2 ->
- scan_crlf(<<Bin1/binary, Bin2/binary>>);
-scan_crlf(Bin1, Bin2) ->
- scan_crlf_1(size(Bin1) - 2, Bin1, Bin2).
-
-scan_crlf_1(Bin1_head_size, Bin1, Bin2) ->
- <<Bin1_head:Bin1_head_size/binary, Bin1_tail/binary>> = Bin1,
- Bin3 = <<Bin1_tail/binary, Bin2/binary>>,
- case get_crlf_pos(Bin3) of
- {yes, Pos} ->
- {Prefix, <<_, _, Suffix/binary>>} = split_binary(Bin3, Pos),
- {yes, list_to_binary([Bin1_head, Prefix]), Suffix};
- no ->
- {no, list_to_binary([Bin1, Bin2])}
- end.
-
-get_crlf_pos(Bin) ->
- get_crlf_pos(Bin, 0).
-
-get_crlf_pos(<<$\r, $\n, _/binary>>, Pos) -> {yes, Pos};
-get_crlf_pos(<<_, Rest/binary>>, Pos) -> get_crlf_pos(Rest, Pos + 1);
-get_crlf_pos(<<>>, _) -> no.
-
-fmt_val(L) when is_list(L) -> L;
-fmt_val(I) when is_integer(I) -> integer_to_list(I);
-fmt_val(A) when is_atom(A) -> atom_to_list(A);
-fmt_val(Term) -> io_lib:format("~p", [Term]).
-
-crnl() -> "\r\n".
-
-method(get) -> "GET";
-method(post) -> "POST";
-method(head) -> "HEAD";
-method(options) -> "OPTIONS";
-method(put) -> "PUT";
-method(delete) -> "DELETE";
-method(trace) -> "TRACE";
-method(mkcol) -> "MKCOL";
-method(propfind) -> "PROPFIND";
-method(proppatch) -> "PROPPATCH";
-method(lock) -> "LOCK";
-method(unlock) -> "UNLOCK";
-method(move) -> "MOVE";
-method(copy) -> "COPY";
-method(connect) -> "CONNECT".
-
-%% From RFC 2616
-%%
-% The chunked encoding modifies the body of a message in order to
-% transfer it as a series of chunks, each with its own size indicator,
-% followed by an OPTIONAL trailer containing entity-header
-% fields. This allows dynamically produced content to be transferred
-% along with the information necessary for the recipient to verify
-% that it has received the full message.
-% Chunked-Body = *chunk
-% last-chunk
-% trailer
-% CRLF
-% chunk = chunk-size [ chunk-extension ] CRLF
-% chunk-data CRLF
-% chunk-size = 1*HEX
-% last-chunk = 1*("0") [ chunk-extension ] CRLF
-% chunk-extension= *( ";" chunk-ext-name [ "=" chunk-ext-val ] )
-% chunk-ext-name = token
-% chunk-ext-val = token | quoted-string
-% chunk-data = chunk-size(OCTET)
-% trailer = *(entity-header CRLF)
-% The chunk-size field is a string of hex digits indicating the size
-% of the chunk. The chunked encoding is ended by any chunk whose size
-% is zero, followed by the trailer, which is terminated by an empty
-% line.
-%%
-%% The parsing implemented here discards all chunk extensions. It also
-%% strips trailing spaces from the chunk size fields as Apache 1.3.27 was
-%% sending them.
-parse_chunk_header(ChunkHeader) ->
- parse_chunk_header(ChunkHeader, []).
-
-parse_chunk_header(<<$;, _/binary>>, Acc) ->
- hexlist_to_integer(lists:reverse(Acc));
-parse_chunk_header(<<H, T/binary>>, Acc) ->
- case is_whitespace(H) of
- true ->
- parse_chunk_header(T, Acc);
- false ->
- parse_chunk_header(T, [H | Acc])
- end;
-parse_chunk_header(<<>>, Acc) ->
- hexlist_to_integer(lists:reverse(Acc)).
-
-is_whitespace($\s) -> true;
-is_whitespace($\r) -> true;
-is_whitespace($\n) -> true;
-is_whitespace($\t) -> true;
-is_whitespace(_) -> false.
-
-send_async_headers(_ReqId, undefined, _, _State) ->
- ok;
-send_async_headers(ReqId, StreamTo, Give_raw_headers,
- #state{status_line = Status_line, raw_headers = Raw_headers,
- recvd_headers = Headers, http_status_code = StatCode,
- cur_req = #request{options = Opts}
- }) ->
- {Headers_1, Raw_headers_1} = maybe_add_custom_headers(Headers, Raw_headers, Opts),
- case Give_raw_headers of
- false ->
- catch StreamTo ! {ibrowse_async_headers, ReqId, StatCode, Headers_1};
- true ->
- catch StreamTo ! {ibrowse_async_headers, ReqId, Status_line, Raw_headers_1}
- end.
-
-maybe_add_custom_headers(Headers, Raw_headers, Opts) ->
- Custom_headers = get_value(add_custom_headers, Opts, []),
- Headers_1 = Headers ++ Custom_headers,
- Raw_headers_1 = case Custom_headers of
- [_ | _] when is_binary(Raw_headers) ->
- Custom_headers_bin = list_to_binary(string:join([[X, $:, Y] || {X, Y} <- Custom_headers], "\r\n")),
- <<Raw_headers/binary, "\r\n", Custom_headers_bin/binary>>;
- _ ->
- Raw_headers
- end,
- {Headers_1, Raw_headers_1}.
-
-format_response_data(Resp_format, Body) ->
- case Resp_format of
- list when is_list(Body) ->
- flatten(Body);
- list when is_binary(Body) ->
- binary_to_list(Body);
- binary when is_list(Body) ->
- list_to_binary(Body);
- _ ->
- %% This is to cater for sending messages such as
- %% {chunk_start, _}, chunk_end etc
- Body
- end.
-
-do_reply(State, From, undefined, _, Resp_format, {ok, St_code, Headers, Body}) ->
- Msg_1 = {ok, St_code, Headers, format_response_data(Resp_format, Body)},
- gen_server:reply(From, Msg_1),
- dec_pipeline_counter(State);
-do_reply(State, From, undefined, _, _, Msg) ->
- gen_server:reply(From, Msg),
- dec_pipeline_counter(State);
-do_reply(#state{prev_req_id = Prev_req_id} = State,
- _From, StreamTo, ReqId, Resp_format, {ok, _, _, Body}) ->
- State_1 = dec_pipeline_counter(State),
- case Body of
- [] ->
- ok;
- _ ->
- Body_1 = format_response_data(Resp_format, Body),
- catch StreamTo ! {ibrowse_async_response, ReqId, Body_1}
- end,
- catch StreamTo ! {ibrowse_async_response_end, ReqId},
- %% We don't want to delete the Req-id to Pid mapping straightaway
- %% as the client may send a stream_next message just while we are
- %% sending back this ibrowse_async_response_end message. If we
- %% deleted this mapping straightaway, the caller will see a
- %% {error, unknown_req_id} when it calls ibrowse:stream_next/1. To
- %% get around this, we store the req id, and clear it after the
- %% next request. If there are wierd combinations of stream,
- %% stream_once and sync requests on the same connection, it will
- %% take a while for the req_id-pid mapping to get cleared, but it
- %% should do no harm.
- ets:delete(ibrowse_stream, {req_id_pid, Prev_req_id}),
- State_1#state{prev_req_id = ReqId};
-do_reply(State, _From, StreamTo, ReqId, Resp_format, Msg) ->
- State_1 = dec_pipeline_counter(State),
- Msg_1 = format_response_data(Resp_format, Msg),
- catch StreamTo ! {ibrowse_async_response, ReqId, Msg_1},
- State_1.
-
-do_interim_reply(undefined, _, _ReqId, _Msg) ->
- ok;
-do_interim_reply(StreamTo, Response_format, ReqId, Msg) ->
- Msg_1 = format_response_data(Response_format, Msg),
- catch StreamTo ! {ibrowse_async_response, ReqId, Msg_1}.
-
-do_error_reply(#state{reqs = Reqs, tunnel_setup_queue = Tun_q} = State, Err) ->
- ReqList = queue:to_list(Reqs),
- lists:foreach(fun(#request{from=From, stream_to=StreamTo, req_id=ReqId,
- response_format = Resp_format}) ->
- ets:delete(ibrowse_stream, {req_id_pid, ReqId}),
- do_reply(State, From, StreamTo, ReqId, Resp_format, {error, Err})
- end, ReqList),
- lists:foreach(
- fun({From, _Url, _Headers, _Method, _Body, _Options, _Timeout}) ->
- do_reply(State, From, undefined, undefined, undefined, Err)
- end, Tun_q).
-
-fail_pipelined_requests(#state{reqs = Reqs, cur_req = CurReq} = State, Reply) ->
- {_, Reqs_1} = queue:out(Reqs),
- #request{from=From, stream_to=StreamTo, req_id=ReqId,
- response_format = Resp_format} = CurReq,
- State_1 = do_reply(State, From, StreamTo, ReqId, Resp_format, Reply),
- do_error_reply(State_1#state{reqs = Reqs_1}, previous_request_failed).
-
-split_list_at(List, N) ->
- split_list_at(List, N, []).
-
-split_list_at([], _, Acc) ->
- {lists:reverse(Acc), []};
-split_list_at(List2, 0, List1) ->
- {lists:reverse(List1), List2};
-split_list_at([H | List2], N, List1) ->
- split_list_at(List2, N-1, [H | List1]).
-
-hexlist_to_integer(List) ->
- hexlist_to_integer(lists:reverse(List), 1, 0).
-
-hexlist_to_integer([H | T], Multiplier, Acc) ->
- hexlist_to_integer(T, Multiplier*16, Multiplier*to_ascii(H) + Acc);
-hexlist_to_integer([], _, Acc) ->
- Acc.
-
-to_ascii($A) -> 10;
-to_ascii($a) -> 10;
-to_ascii($B) -> 11;
-to_ascii($b) -> 11;
-to_ascii($C) -> 12;
-to_ascii($c) -> 12;
-to_ascii($D) -> 13;
-to_ascii($d) -> 13;
-to_ascii($E) -> 14;
-to_ascii($e) -> 14;
-to_ascii($F) -> 15;
-to_ascii($f) -> 15;
-to_ascii($1) -> 1;
-to_ascii($2) -> 2;
-to_ascii($3) -> 3;
-to_ascii($4) -> 4;
-to_ascii($5) -> 5;
-to_ascii($6) -> 6;
-to_ascii($7) -> 7;
-to_ascii($8) -> 8;
-to_ascii($9) -> 9;
-to_ascii($0) -> 0.
-
-cancel_timer(undefined) -> ok;
-cancel_timer(Ref) -> _ = erlang:cancel_timer(Ref),
- ok.
-
-cancel_timer(Ref, {eat_message, Msg}) ->
- cancel_timer(Ref),
- receive
- Msg ->
- ok
- after 0 ->
- ok
- end.
-
-make_req_id() ->
- now().
-
-to_lower(Str) ->
- to_lower(Str, []).
-to_lower([H|T], Acc) when H >= $A, H =< $Z ->
- to_lower(T, [H+32|Acc]);
-to_lower([H|T], Acc) ->
- to_lower(T, [H|Acc]);
-to_lower([], Acc) ->
- lists:reverse(Acc).
-
-shutting_down(#state{lb_ets_tid = undefined}) ->
- ok;
-shutting_down(#state{lb_ets_tid = Tid,
- cur_pipeline_size = Sz}) ->
- catch ets:delete(Tid, {Sz, self()}).
-
-inc_pipeline_counter(#state{is_closing = true} = State) ->
- State;
-inc_pipeline_counter(#state{cur_pipeline_size = Pipe_sz} = State) ->
- State#state{cur_pipeline_size = Pipe_sz + 1}.
-
-dec_pipeline_counter(#state{is_closing = true} = State) ->
- State;
-dec_pipeline_counter(#state{lb_ets_tid = undefined} = State) ->
- State;
-dec_pipeline_counter(#state{cur_pipeline_size = Pipe_sz,
- lb_ets_tid = Tid} = State) ->
- ets:delete(Tid, {Pipe_sz, self()}),
- ets:insert(Tid, {{Pipe_sz - 1, self()}, []}),
- State#state{cur_pipeline_size = Pipe_sz - 1}.
-
-flatten([H | _] = L) when is_integer(H) ->
- L;
-flatten([H | _] = L) when is_list(H) ->
- lists:flatten(L);
-flatten([]) ->
- [].
-
-get_stream_chunk_size(Options) ->
- case lists:keysearch(stream_chunk_size, 1, Options) of
- {value, {_, V}} when V > 0 ->
- V;
- _ ->
- ?DEFAULT_STREAM_CHUNK_SIZE
- end.
-
-set_inac_timer(State) ->
- cancel_timer(State#state.inactivity_timer_ref),
- set_inac_timer(State#state{inactivity_timer_ref = undefined},
- get_inac_timeout(State)).
-
-set_inac_timer(State, Timeout) when is_integer(Timeout) ->
- Ref = erlang:send_after(Timeout, self(), timeout),
- State#state{inactivity_timer_ref = Ref};
-set_inac_timer(State, _) ->
- State.
-
-get_inac_timeout(#state{cur_req = #request{options = Opts}}) ->
- get_value(inactivity_timeout, Opts, infinity);
-get_inac_timeout(#state{cur_req = undefined}) ->
- case ibrowse:get_config_value(inactivity_timeout, undefined) of
- Val when is_integer(Val) ->
- Val;
- _ ->
- case application:get_env(ibrowse, inactivity_timeout) of
- {ok, Val} when is_integer(Val), Val > 0 ->
- Val;
- _ ->
- 10000
- end
- end.
-
-trace_request(Req) ->
- case get(my_trace_flag) of
- true ->
- %%Avoid the binary operations if trace is not on...
- NReq = to_binary(Req),
- do_trace("Sending request: ~n"
- "--- Request Begin ---~n~s~n"
- "--- Request End ---~n", [NReq]);
- _ -> ok
- end.
-
-trace_request_body(Body) ->
- case get(my_trace_flag) of
- true ->
- %%Avoid the binary operations if trace is not on...
- NBody = to_binary(Body),
- case size(NBody) > 1024 of
- true ->
- ok;
- false ->
- do_trace("Sending request body: ~n"
- "--- Request Body Begin ---~n~s~n"
- "--- Request Body End ---~n", [NBody])
- end;
- false ->
- ok
- end.
-
-to_binary(X) when is_list(X) -> list_to_binary(X);
-to_binary(X) when is_binary(X) -> X.
diff --git a/src/ibrowse/ibrowse_lb.erl b/src/ibrowse/ibrowse_lb.erl
deleted file mode 100644
index 0e001d48..00000000
--- a/src/ibrowse/ibrowse_lb.erl
+++ /dev/null
@@ -1,235 +0,0 @@
-%%%-------------------------------------------------------------------
-%%% File : ibrowse_lb.erl
-%%% Author : chandru <chandrashekhar.mullaparthi@t-mobile.co.uk>
-%%% Description :
-%%%
-%%% Created : 6 Mar 2008 by chandru <chandrashekhar.mullaparthi@t-mobile.co.uk>
-%%%-------------------------------------------------------------------
--module(ibrowse_lb).
--author(chandru).
--behaviour(gen_server).
-%%--------------------------------------------------------------------
-%% Include files
-%%--------------------------------------------------------------------
-
-%%--------------------------------------------------------------------
-%% External exports
--export([
- start_link/1,
- spawn_connection/5,
- stop/1
- ]).
-
-%% gen_server callbacks
--export([
- init/1,
- handle_call/3,
- handle_cast/2,
- handle_info/2,
- terminate/2,
- code_change/3
- ]).
-
--record(state, {parent_pid,
- ets_tid,
- host,
- port,
- max_sessions,
- max_pipeline_size,
- num_cur_sessions = 0}).
-
--include("ibrowse.hrl").
-
-%%====================================================================
-%% External functions
-%%====================================================================
-%%--------------------------------------------------------------------
-%% Function: start_link/0
-%% Description: Starts the server
-%%--------------------------------------------------------------------
-start_link(Args) ->
- gen_server:start_link(?MODULE, Args, []).
-
-%%====================================================================
-%% Server functions
-%%====================================================================
-
-%%--------------------------------------------------------------------
-%% Function: init/1
-%% Description: Initiates the server
-%% Returns: {ok, State} |
-%% {ok, State, Timeout} |
-%% ignore |
-%% {stop, Reason}
-%%--------------------------------------------------------------------
-init([Host, Port]) ->
- process_flag(trap_exit, true),
- Max_sessions = ibrowse:get_config_value({max_sessions, Host, Port}, 10),
- Max_pipe_sz = ibrowse:get_config_value({max_pipeline_size, Host, Port}, 10),
- put(my_trace_flag, ibrowse_lib:get_trace_status(Host, Port)),
- put(ibrowse_trace_token, ["LB: ", Host, $:, integer_to_list(Port)]),
- Tid = ets:new(ibrowse_lb, [public, ordered_set]),
- {ok, #state{parent_pid = whereis(ibrowse),
- host = Host,
- port = Port,
- ets_tid = Tid,
- max_pipeline_size = Max_pipe_sz,
- max_sessions = Max_sessions}}.
-
-spawn_connection(Lb_pid, Url,
- Max_sessions,
- Max_pipeline_size,
- SSL_options)
- when is_pid(Lb_pid),
- is_record(Url, url),
- is_integer(Max_pipeline_size),
- is_integer(Max_sessions) ->
- gen_server:call(Lb_pid,
- {spawn_connection, Url, Max_sessions, Max_pipeline_size, SSL_options}).
-
-stop(Lb_pid) ->
- case catch gen_server:call(Lb_pid, stop) of
- {'EXIT', {timeout, _}} ->
- exit(Lb_pid, kill);
- ok ->
- ok
- end.
-%%--------------------------------------------------------------------
-%% Function: handle_call/3
-%% Description: Handling call messages
-%% Returns: {reply, Reply, State} |
-%% {reply, Reply, State, Timeout} |
-%% {noreply, State} |
-%% {noreply, State, Timeout} |
-%% {stop, Reason, Reply, State} | (terminate/2 is called)
-%% {stop, Reason, State} (terminate/2 is called)
-%%--------------------------------------------------------------------
-% handle_call({spawn_connection, _Url, Max_sess, Max_pipe, _}, _From,
-% #state{max_sessions = Max_sess,
-% ets_tid = Tid,
-% max_pipeline_size = Max_pipe_sz,
-% num_cur_sessions = Num} = State)
-% when Num >= Max ->
-% Reply = find_best_connection(Tid),
-% {reply, sorry_dude_reuse, State};
-
-%% Update max_sessions in #state with supplied value
-handle_call({spawn_connection, _Url, Max_sess, Max_pipe, _}, _From,
- #state{num_cur_sessions = Num} = State)
- when Num >= Max_sess ->
- State_1 = maybe_create_ets(State),
- Reply = find_best_connection(State_1#state.ets_tid, Max_pipe),
- {reply, Reply, State_1#state{max_sessions = Max_sess}};
-
-handle_call({spawn_connection, Url, _Max_sess, _Max_pipe, SSL_options}, _From,
- #state{num_cur_sessions = Cur} = State) ->
- State_1 = maybe_create_ets(State),
- Tid = State_1#state.ets_tid,
- {ok, Pid} = ibrowse_http_client:start_link({Tid, Url, SSL_options}),
- ets:insert(Tid, {{1, Pid}, []}),
- {reply, {ok, Pid}, State_1#state{num_cur_sessions = Cur + 1}};
-
-handle_call(stop, _From, #state{ets_tid = undefined} = State) ->
- gen_server:reply(_From, ok),
- {stop, normal, State};
-
-handle_call(stop, _From, #state{ets_tid = Tid} = State) ->
- ets:foldl(fun({{_, Pid}, _}, Acc) ->
- ibrowse_http_client:stop(Pid),
- Acc
- end, [], Tid),
- gen_server:reply(_From, ok),
- {stop, normal, State};
-
-handle_call(Request, _From, State) ->
- Reply = {unknown_request, Request},
- {reply, Reply, State}.
-
-%%--------------------------------------------------------------------
-%% Function: handle_cast/2
-%% Description: Handling cast messages
-%% Returns: {noreply, State} |
-%% {noreply, State, Timeout} |
-%% {stop, Reason, State} (terminate/2 is called)
-%%--------------------------------------------------------------------
-handle_cast(_Msg, State) ->
- {noreply, State}.
-
-%%--------------------------------------------------------------------
-%% Function: handle_info/2
-%% Description: Handling all non call/cast messages
-%% Returns: {noreply, State} |
-%% {noreply, State, Timeout} |
-%% {stop, Reason, State} (terminate/2 is called)
-%%--------------------------------------------------------------------
-handle_info({'EXIT', Parent, _Reason}, #state{parent_pid = Parent} = State) ->
- {stop, normal, State};
-
-handle_info({'EXIT', _Pid, _Reason}, #state{ets_tid = undefined} = State) ->
- {noreply, State};
-
-handle_info({'EXIT', Pid, _Reason},
- #state{num_cur_sessions = Cur,
- ets_tid = Tid} = State) ->
- ets:match_delete(Tid, {{'_', Pid}, '_'}),
- Cur_1 = Cur - 1,
- State_1 = case Cur_1 of
- 0 ->
- ets:delete(Tid),
- State#state{ets_tid = undefined};
- _ ->
- State
- end,
- {noreply, State_1#state{num_cur_sessions = Cur_1}};
-
-handle_info({trace, Bool}, #state{ets_tid = undefined} = State) ->
- put(my_trace_flag, Bool),
- {noreply, State};
-
-handle_info({trace, Bool}, #state{ets_tid = Tid} = State) ->
- ets:foldl(fun({{_, Pid}, _}, Acc) when is_pid(Pid) ->
- catch Pid ! {trace, Bool},
- Acc;
- (_, Acc) ->
- Acc
- end, undefined, Tid),
- put(my_trace_flag, Bool),
- {noreply, State};
-
-handle_info(_Info, State) ->
- {noreply, State}.
-
-%%--------------------------------------------------------------------
-%% Function: terminate/2
-%% Description: Shutdown the server
-%% Returns: any (ignored by gen_server)
-%%--------------------------------------------------------------------
-terminate(_Reason, _State) ->
- ok.
-
-%%--------------------------------------------------------------------
-%% Func: code_change/3
-%% Purpose: Convert process state when code is changed
-%% Returns: {ok, NewState}
-%%--------------------------------------------------------------------
-code_change(_OldVsn, State, _Extra) ->
- {ok, State}.
-
-%%--------------------------------------------------------------------
-%%% Internal functions
-%%--------------------------------------------------------------------
-find_best_connection(Tid, Max_pipe) ->
- case ets:first(Tid) of
- {Cur_sz, Pid} when Cur_sz < Max_pipe ->
- ets:delete(Tid, {Cur_sz, Pid}),
- ets:insert(Tid, {{Cur_sz + 1, Pid}, []}),
- {ok, Pid};
- _ ->
- {error, retry_later}
- end.
-
-maybe_create_ets(#state{ets_tid = undefined} = State) ->
- Tid = ets:new(ibrowse_lb, [public, ordered_set]),
- State#state{ets_tid = Tid};
-maybe_create_ets(State) ->
- State.
diff --git a/src/ibrowse/ibrowse_lib.erl b/src/ibrowse/ibrowse_lib.erl
deleted file mode 100644
index 3cbe3ace..00000000
--- a/src/ibrowse/ibrowse_lib.erl
+++ /dev/null
@@ -1,391 +0,0 @@
-%%% File : ibrowse_lib.erl
-%%% Author : Chandrashekhar Mullaparthi <chandrashekhar.mullaparthi@t-mobile.co.uk>
-%%% Description :
-%%% Created : 27 Feb 2004 by Chandrashekhar Mullaparthi <chandrashekhar.mullaparthi@t-mobile.co.uk>
-%% @doc Module with a few useful functions
-
--module(ibrowse_lib).
--author('chandru').
--ifdef(debug).
--compile(export_all).
--endif.
-
--include("ibrowse.hrl").
-
--export([
- get_trace_status/2,
- do_trace/2,
- do_trace/3,
- url_encode/1,
- decode_rfc822_date/1,
- status_code/1,
- encode_base64/1,
- decode_base64/1,
- get_value/2,
- get_value/3,
- parse_url/1,
- printable_date/0
- ]).
-
-get_trace_status(Host, Port) ->
- ibrowse:get_config_value({trace, Host, Port}, false).
-
-%% @doc URL-encodes a string based on RFC 1738. Returns a flat list.
-%% @spec url_encode(Str) -> UrlEncodedStr
-%% Str = string()
-%% UrlEncodedStr = string()
-url_encode(Str) when is_list(Str) ->
- url_encode_char(lists:reverse(Str), []).
-
-url_encode_char([X | T], Acc) when X >= $0, X =< $9 ->
- url_encode_char(T, [X | Acc]);
-url_encode_char([X | T], Acc) when X >= $a, X =< $z ->
- url_encode_char(T, [X | Acc]);
-url_encode_char([X | T], Acc) when X >= $A, X =< $Z ->
- url_encode_char(T, [X | Acc]);
-url_encode_char([X | T], Acc) when X == $-; X == $_; X == $. ->
- url_encode_char(T, [X | Acc]);
-url_encode_char([32 | T], Acc) ->
- url_encode_char(T, [$+ | Acc]);
-url_encode_char([X | T], Acc) ->
- url_encode_char(T, [$%, d2h(X bsr 4), d2h(X band 16#0f) | Acc]);
-url_encode_char([], Acc) ->
- Acc.
-
-d2h(N) when N<10 -> N+$0;
-d2h(N) -> N+$a-10.
-
-decode_rfc822_date(String) when is_list(String) ->
- case catch decode_rfc822_date_1(string:tokens(String, ", \t\r\n")) of
- {'EXIT', _} ->
- {error, invalid_date};
- Res ->
- Res
- end.
-
-% TODO: Have to handle the Zone
-decode_rfc822_date_1([_,DayInt,Month,Year, Time,Zone]) ->
- decode_rfc822_date_1([DayInt,Month,Year, Time,Zone]);
-decode_rfc822_date_1([Day,Month,Year, Time,_Zone]) ->
- DayI = list_to_integer(Day),
- MonthI = month_int(Month),
- YearI = list_to_integer(Year),
- TimeTup = case string:tokens(Time, ":") of
- [H,M] ->
- {list_to_integer(H),
- list_to_integer(M),
- 0};
- [H,M,S] ->
- {list_to_integer(H),
- list_to_integer(M),
- list_to_integer(S)}
- end,
- {{YearI,MonthI,DayI}, TimeTup}.
-
-month_int("Jan") -> 1;
-month_int("Feb") -> 2;
-month_int("Mar") -> 3;
-month_int("Apr") -> 4;
-month_int("May") -> 5;
-month_int("Jun") -> 6;
-month_int("Jul") -> 7;
-month_int("Aug") -> 8;
-month_int("Sep") -> 9;
-month_int("Oct") -> 10;
-month_int("Nov") -> 11;
-month_int("Dec") -> 12.
-
-%% @doc Given a status code, returns an atom describing the status code.
-%% @spec status_code(StatusCode::status_code()) -> StatusDescription
-%% status_code() = string() | integer()
-%% StatusDescription = atom()
-status_code(100) -> continue;
-status_code(101) -> switching_protocols;
-status_code(102) -> processing;
-status_code(200) -> ok;
-status_code(201) -> created;
-status_code(202) -> accepted;
-status_code(203) -> non_authoritative_information;
-status_code(204) -> no_content;
-status_code(205) -> reset_content;
-status_code(206) -> partial_content;
-status_code(207) -> multi_status;
-status_code(300) -> multiple_choices;
-status_code(301) -> moved_permanently;
-status_code(302) -> found;
-status_code(303) -> see_other;
-status_code(304) -> not_modified;
-status_code(305) -> use_proxy;
-status_code(306) -> unused;
-status_code(307) -> temporary_redirect;
-status_code(400) -> bad_request;
-status_code(401) -> unauthorized;
-status_code(402) -> payment_required;
-status_code(403) -> forbidden;
-status_code(404) -> not_found;
-status_code(405) -> method_not_allowed;
-status_code(406) -> not_acceptable;
-status_code(407) -> proxy_authentication_required;
-status_code(408) -> request_timeout;
-status_code(409) -> conflict;
-status_code(410) -> gone;
-status_code(411) -> length_required;
-status_code(412) -> precondition_failed;
-status_code(413) -> request_entity_too_large;
-status_code(414) -> request_uri_too_long;
-status_code(415) -> unsupported_media_type;
-status_code(416) -> requested_range_not_satisfiable;
-status_code(417) -> expectation_failed;
-status_code(422) -> unprocessable_entity;
-status_code(423) -> locked;
-status_code(424) -> failed_dependency;
-status_code(500) -> internal_server_error;
-status_code(501) -> not_implemented;
-status_code(502) -> bad_gateway;
-status_code(503) -> service_unavailable;
-status_code(504) -> gateway_timeout;
-status_code(505) -> http_version_not_supported;
-status_code(507) -> insufficient_storage;
-status_code(X) when is_list(X) -> status_code(list_to_integer(X));
-status_code(_) -> unknown_status_code.
-
-%% @doc Implements the base64 encoding algorithm. The output data type matches in the input data type.
-%% @spec encode_base64(In) -> Out
-%% In = string() | binary()
-%% Out = string() | binary()
-encode_base64(List) when is_list(List) ->
- binary_to_list(base64:encode(List));
-encode_base64(Bin) when is_binary(Bin) ->
- base64:encode(Bin).
-
-%% @doc Implements the base64 decoding algorithm. The output data type matches in the input data type.
-%% @spec decode_base64(In) -> Out | exit({error, invalid_input})
-%% In = string() | binary()
-%% Out = string() | binary()
-decode_base64(List) when is_list(List) ->
- binary_to_list(base64:decode(List));
-decode_base64(Bin) when is_binary(Bin) ->
- base64:decode(Bin).
-
-get_value(Tag, TVL, DefVal) ->
- case lists:keysearch(Tag, 1, TVL) of
- false ->
- DefVal;
- {value, {_, Val}} ->
- Val
- end.
-
-get_value(Tag, TVL) ->
- {value, {_, V}} = lists:keysearch(Tag,1,TVL),
- V.
-
-parse_url(Url) ->
- case parse_url(Url, get_protocol, #url{abspath=Url}, []) of
- #url{host_type = undefined, host = Host} = UrlRec ->
- case inet_parse:address(Host) of
- {ok, {_, _, _, _, _, _, _, _}} ->
- UrlRec#url{host_type = ipv6_address};
- {ok, {_, _, _, _}} ->
- UrlRec#url{host_type = ipv4_address};
- _ ->
- UrlRec#url{host_type = hostname}
- end;
- Else ->
- Else
- end.
-
-parse_url([$:, $/, $/ | _], get_protocol, Url, []) ->
- {invalid_uri_1, Url};
-parse_url([$:, $/, $/ | T], get_protocol, Url, TmpAcc) ->
- Prot = list_to_existing_atom(lists:reverse(TmpAcc)),
- parse_url(T, get_username,
- Url#url{protocol = Prot},
- []);
-parse_url([H | T], get_username, Url, TmpAcc) when H == $/;
- H == $? ->
- Path = case H of
- $/ ->
- [$/ | T];
- $? ->
- [$/, $? | T]
- end,
- %% No username/password. No port number
- Url#url{host = lists:reverse(TmpAcc),
- port = default_port(Url#url.protocol),
- path = Path};
-parse_url([$: | T], get_username, Url, TmpAcc) ->
- %% It is possible that no username/password has been
- %% specified. But we'll continue with the assumption that there is
- %% a username/password. If we encounter a '@' later on, there is a
- %% username/password indeed. If we encounter a '/', it was
- %% actually the hostname
- parse_url(T, get_password,
- Url#url{username = lists:reverse(TmpAcc)},
- []);
-parse_url([$@ | T], get_username, Url, TmpAcc) ->
- parse_url(T, get_host,
- Url#url{username = lists:reverse(TmpAcc),
- password = ""},
- []);
-parse_url([$[ | T], get_username, Url, []) ->
- % IPv6 address literals are enclosed by square brackets:
- % http://www.ietf.org/rfc/rfc2732.txt
- parse_url(T, get_ipv6_address, Url#url{host_type = ipv6_address}, []);
-parse_url([$[ | T], get_username, _Url, TmpAcc) ->
- {error, {invalid_username_or_host, lists:reverse(TmpAcc) ++ "[" ++ T}};
-parse_url([$[ | _], get_password, _Url, []) ->
- {error, missing_password};
-parse_url([$[ | T], get_password, Url, TmpAcc) ->
- % IPv6 address literals are enclosed by square brackets:
- % http://www.ietf.org/rfc/rfc2732.txt
- parse_url(T, get_ipv6_address,
- Url#url{host_type = ipv6_address,
- password = lists:reverse(TmpAcc)},
- []);
-parse_url([$@ | T], get_password, Url, TmpAcc) ->
- parse_url(T, get_host,
- Url#url{password = lists:reverse(TmpAcc)},
- []);
-parse_url([H | T], get_password, Url, TmpAcc) when H == $/;
- H == $? ->
- %% Ok, what we thought was the username/password was the hostname
- %% and portnumber
- #url{username=User} = Url,
- Port = list_to_integer(lists:reverse(TmpAcc)),
- Path = case H of
- $/ ->
- [$/ | T];
- $? ->
- [$/, $? | T]
- end,
- Url#url{host = User,
- port = Port,
- username = undefined,
- password = undefined,
- path = Path};
-parse_url([$] | T], get_ipv6_address, #url{protocol = Prot} = Url, TmpAcc) ->
- Addr = lists:reverse(TmpAcc),
- case inet_parse:address(Addr) of
- {ok, {_, _, _, _, _, _, _, _}} ->
- Url2 = Url#url{host = Addr, port = default_port(Prot)},
- case T of
- [$: | T2] ->
- parse_url(T2, get_port, Url2, []);
- [$/ | T2] ->
- Url2#url{path = [$/ | T2]};
- [$? | T2] ->
- Url2#url{path = [$/, $? | T2]};
- [] ->
- Url2#url{path = "/"};
- _ ->
- {error, {invalid_host, "[" ++ Addr ++ "]" ++ T}}
- end;
- _ ->
- {error, {invalid_ipv6_address, Addr}}
- end;
-parse_url([$[ | T], get_host, #url{} = Url, []) ->
- parse_url(T, get_ipv6_address, Url#url{host_type = ipv6_address}, []);
-parse_url([$: | T], get_host, #url{} = Url, TmpAcc) ->
- parse_url(T, get_port,
- Url#url{host = lists:reverse(TmpAcc)},
- []);
-parse_url([H | T], get_host, #url{protocol=Prot} = Url, TmpAcc) when H == $/;
- H == $? ->
- Path = case H of
- $/ ->
- [$/ | T];
- $? ->
- [$/, $? | T]
- end,
- Url#url{host = lists:reverse(TmpAcc),
- port = default_port(Prot),
- path = Path};
-parse_url([H | T], get_port, #url{protocol=Prot} = Url, TmpAcc) when H == $/;
- H == $? ->
- Path = case H of
- $/ ->
- [$/ | T];
- $? ->
- [$/, $? | T]
- end,
- Port = case TmpAcc of
- [] ->
- default_port(Prot);
- _ ->
- list_to_integer(lists:reverse(TmpAcc))
- end,
- Url#url{port = Port, path = Path};
-parse_url([H | T], State, Url, TmpAcc) ->
- parse_url(T, State, Url, [H | TmpAcc]);
-parse_url([], get_host, Url, TmpAcc) when TmpAcc /= [] ->
- Url#url{host = lists:reverse(TmpAcc),
- port = default_port(Url#url.protocol),
- path = "/"};
-parse_url([], get_username, Url, TmpAcc) when TmpAcc /= [] ->
- Url#url{host = lists:reverse(TmpAcc),
- port = default_port(Url#url.protocol),
- path = "/"};
-parse_url([], get_port, #url{protocol=Prot} = Url, TmpAcc) ->
- Port = case TmpAcc of
- [] ->
- default_port(Prot);
- _ ->
- list_to_integer(lists:reverse(TmpAcc))
- end,
- Url#url{port = Port,
- path = "/"};
-parse_url([], get_password, Url, TmpAcc) ->
- %% Ok, what we thought was the username/password was the hostname
- %% and portnumber
- #url{username=User} = Url,
- Port = case TmpAcc of
- [] ->
- default_port(Url#url.protocol);
- _ ->
- list_to_integer(lists:reverse(TmpAcc))
- end,
- Url#url{host = User,
- port = Port,
- username = undefined,
- password = undefined,
- path = "/"};
-parse_url([], State, Url, TmpAcc) ->
- {invalid_uri_2, State, Url, TmpAcc}.
-
-default_port(http) -> 80;
-default_port(https) -> 443;
-default_port(ftp) -> 21.
-
-printable_date() ->
- {{Y,Mo,D},{H, M, S}} = calendar:local_time(),
- {_,_,MicroSecs} = now(),
- [integer_to_list(Y),
- $-,
- integer_to_list(Mo),
- $-,
- integer_to_list(D),
- $_,
- integer_to_list(H),
- $:,
- integer_to_list(M),
- $:,
- integer_to_list(S),
- $:,
- integer_to_list(MicroSecs div 1000)].
-
-do_trace(Fmt, Args) ->
- do_trace(get(my_trace_flag), Fmt, Args).
-
--ifdef(DEBUG).
-do_trace(_, Fmt, Args) ->
- io:format("~s -- (~s) - "++Fmt,
- [printable_date(),
- get(ibrowse_trace_token) | Args]).
--else.
-do_trace(true, Fmt, Args) ->
- io:format("~s -- (~s) - "++Fmt,
- [printable_date(),
- get(ibrowse_trace_token) | Args]);
-do_trace(_, _, _) ->
- ok.
--endif.
diff --git a/src/ibrowse/ibrowse_sup.erl b/src/ibrowse/ibrowse_sup.erl
deleted file mode 100644
index ace33d16..00000000
--- a/src/ibrowse/ibrowse_sup.erl
+++ /dev/null
@@ -1,63 +0,0 @@
-%%%-------------------------------------------------------------------
-%%% File : ibrowse_sup.erl
-%%% Author : Chandrashekhar Mullaparthi <chandrashekhar.mullaparthi@t-mobile.co.uk>
-%%% Description :
-%%%
-%%% Created : 15 Oct 2003 by Chandrashekhar Mullaparthi <chandrashekhar.mullaparthi@t-mobile.co.uk>
-%%%-------------------------------------------------------------------
--module(ibrowse_sup).
--behaviour(supervisor).
-%%--------------------------------------------------------------------
-%% Include files
-%%--------------------------------------------------------------------
-
-%%--------------------------------------------------------------------
-%% External exports
-%%--------------------------------------------------------------------
--export([
- start_link/0
- ]).
-
-%%--------------------------------------------------------------------
-%% Internal exports
-%%--------------------------------------------------------------------
--export([
- init/1
- ]).
-
-%%--------------------------------------------------------------------
-%% Macros
-%%--------------------------------------------------------------------
--define(SERVER, ?MODULE).
-
-%%--------------------------------------------------------------------
-%% Records
-%%--------------------------------------------------------------------
-
-%%====================================================================
-%% External functions
-%%====================================================================
-%%--------------------------------------------------------------------
-%% Function: start_link/0
-%% Description: Starts the supervisor
-%%--------------------------------------------------------------------
-start_link() ->
- supervisor:start_link({local, ?SERVER}, ?MODULE, []).
-
-%%====================================================================
-%% Server functions
-%%====================================================================
-%%--------------------------------------------------------------------
-%% Func: init/1
-%% Returns: {ok, {SupFlags, [ChildSpec]}} |
-%% ignore |
-%% {error, Reason}
-%%--------------------------------------------------------------------
-init([]) ->
- AChild = {ibrowse,{ibrowse,start_link,[]},
- permanent,2000,worker,[ibrowse, ibrowse_http_client]},
- {ok,{{one_for_all,10,1}, [AChild]}}.
-
-%%====================================================================
-%% Internal functions
-%%====================================================================
diff --git a/src/ibrowse/ibrowse_test.erl b/src/ibrowse/ibrowse_test.erl
deleted file mode 100644
index ff3b5304..00000000
--- a/src/ibrowse/ibrowse_test.erl
+++ /dev/null
@@ -1,513 +0,0 @@
-%%% File : ibrowse_test.erl
-%%% Author : Chandrashekhar Mullaparthi <chandrashekhar.mullaparthi@t-mobile.co.uk>
-%%% Description : Test ibrowse
-%%% Created : 14 Oct 2003 by Chandrashekhar Mullaparthi <chandrashekhar.mullaparthi@t-mobile.co.uk>
-
--module(ibrowse_test).
--export([
- load_test/3,
- send_reqs_1/3,
- do_send_req/2,
- unit_tests/0,
- unit_tests/1,
- unit_tests_1/2,
- ue_test/0,
- ue_test/1,
- verify_chunked_streaming/0,
- verify_chunked_streaming/1,
- test_chunked_streaming_once/0,
- i_do_async_req_list/4,
- test_stream_once/3,
- test_stream_once/4,
- test_20122010/0,
- test_20122010/1
- ]).
-
-test_stream_once(Url, Method, Options) ->
- test_stream_once(Url, Method, Options, 5000).
-
-test_stream_once(Url, Method, Options, Timeout) ->
- case ibrowse:send_req(Url, [], Method, [], [{stream_to, {self(), once}} | Options], Timeout) of
- {ibrowse_req_id, Req_id} ->
- case ibrowse:stream_next(Req_id) of
- ok ->
- test_stream_once(Req_id);
- Err ->
- Err
- end;
- Err ->
- Err
- end.
-
-test_stream_once(Req_id) ->
- receive
- {ibrowse_async_headers, Req_id, StatCode, Headers} ->
- io:format("Recvd headers~n~p~n", [{ibrowse_async_headers, Req_id, StatCode, Headers}]),
- case ibrowse:stream_next(Req_id) of
- ok ->
- test_stream_once(Req_id);
- Err ->
- Err
- end;
- {ibrowse_async_response, Req_id, {error, Err}} ->
- io:format("Recvd error: ~p~n", [Err]);
- {ibrowse_async_response, Req_id, Body_1} ->
- io:format("Recvd body part: ~n~p~n", [{ibrowse_async_response, Req_id, Body_1}]),
- case ibrowse:stream_next(Req_id) of
- ok ->
- test_stream_once(Req_id);
- Err ->
- Err
- end;
- {ibrowse_async_response_end, Req_id} ->
- ok
- end.
-%% Use ibrowse:set_max_sessions/3 and ibrowse:set_max_pipeline_size/3 to
-%% tweak settings before running the load test. The defaults are 10 and 10.
-load_test(Url, NumWorkers, NumReqsPerWorker) when is_list(Url),
- is_integer(NumWorkers),
- is_integer(NumReqsPerWorker),
- NumWorkers > 0,
- NumReqsPerWorker > 0 ->
- proc_lib:spawn(?MODULE, send_reqs_1, [Url, NumWorkers, NumReqsPerWorker]).
-
-send_reqs_1(Url, NumWorkers, NumReqsPerWorker) ->
- Start_time = now(),
- ets:new(pid_table, [named_table, public]),
- ets:new(ibrowse_test_results, [named_table, public]),
- ets:new(ibrowse_errors, [named_table, public, ordered_set]),
- init_results(),
- process_flag(trap_exit, true),
- log_msg("Starting spawning of workers...~n", []),
- spawn_workers(Url, NumWorkers, NumReqsPerWorker),
- log_msg("Finished spawning workers...~n", []),
- do_wait(),
- End_time = now(),
- log_msg("All workers are done...~n", []),
- log_msg("ibrowse_test_results table: ~n~p~n", [ets:tab2list(ibrowse_test_results)]),
- log_msg("Start time: ~1000.p~n", [calendar:now_to_local_time(Start_time)]),
- log_msg("End time : ~1000.p~n", [calendar:now_to_local_time(End_time)]),
- Elapsed_time_secs = trunc(timer:now_diff(End_time, Start_time) / 1000000),
- log_msg("Elapsed : ~p~n", [Elapsed_time_secs]),
- log_msg("Reqs/sec : ~p~n", [round(trunc((NumWorkers*NumReqsPerWorker) / Elapsed_time_secs))]),
- dump_errors().
-
-init_results() ->
- ets:insert(ibrowse_test_results, {crash, 0}),
- ets:insert(ibrowse_test_results, {send_failed, 0}),
- ets:insert(ibrowse_test_results, {other_error, 0}),
- ets:insert(ibrowse_test_results, {success, 0}),
- ets:insert(ibrowse_test_results, {retry_later, 0}),
- ets:insert(ibrowse_test_results, {trid_mismatch, 0}),
- ets:insert(ibrowse_test_results, {success_no_trid, 0}),
- ets:insert(ibrowse_test_results, {failed, 0}),
- ets:insert(ibrowse_test_results, {timeout, 0}),
- ets:insert(ibrowse_test_results, {req_id, 0}).
-
-spawn_workers(_Url, 0, _) ->
- ok;
-spawn_workers(Url, NumWorkers, NumReqsPerWorker) ->
- Pid = proc_lib:spawn_link(?MODULE, do_send_req, [Url, NumReqsPerWorker]),
- ets:insert(pid_table, {Pid, []}),
- spawn_workers(Url, NumWorkers - 1, NumReqsPerWorker).
-
-do_wait() ->
- receive
- {'EXIT', _, normal} ->
- do_wait();
- {'EXIT', Pid, Reason} ->
- ets:delete(pid_table, Pid),
- ets:insert(ibrowse_errors, {Pid, Reason}),
- ets:update_counter(ibrowse_test_results, crash, 1),
- do_wait();
- Msg ->
- io:format("Recvd unknown message...~p~n", [Msg]),
- do_wait()
- after 1000 ->
- case ets:info(pid_table, size) of
- 0 ->
- done;
- _ ->
- do_wait()
- end
- end.
-
-do_send_req(Url, NumReqs) ->
- do_send_req_1(Url, NumReqs).
-
-do_send_req_1(_Url, 0) ->
- ets:delete(pid_table, self());
-do_send_req_1(Url, NumReqs) ->
- Counter = integer_to_list(ets:update_counter(ibrowse_test_results, req_id, 1)),
- case ibrowse:send_req(Url, [{"ib_req_id", Counter}], get, [], [], 10000) of
- {ok, _Status, Headers, _Body} ->
- case lists:keysearch("ib_req_id", 1, Headers) of
- {value, {_, Counter}} ->
- ets:update_counter(ibrowse_test_results, success, 1);
- {value, _} ->
- ets:update_counter(ibrowse_test_results, trid_mismatch, 1);
- false ->
- ets:update_counter(ibrowse_test_results, success_no_trid, 1)
- end;
- {error, req_timedout} ->
- ets:update_counter(ibrowse_test_results, timeout, 1);
- {error, send_failed} ->
- ets:update_counter(ibrowse_test_results, send_failed, 1);
- {error, retry_later} ->
- ets:update_counter(ibrowse_test_results, retry_later, 1);
- Err ->
- ets:insert(ibrowse_errors, {now(), Err}),
- ets:update_counter(ibrowse_test_results, other_error, 1),
- ok
- end,
- do_send_req_1(Url, NumReqs-1).
-
-dump_errors() ->
- case ets:info(ibrowse_errors, size) of
- 0 ->
- ok;
- _ ->
- {A, B, C} = now(),
- Filename = lists:flatten(
- io_lib:format("ibrowse_errors_~p_~p_~p.txt" , [A, B, C])),
- case file:open(Filename, [write, delayed_write, raw]) of
- {ok, Iod} ->
- dump_errors(ets:first(ibrowse_errors), Iod);
- Err ->
- io:format("failed to create file ~s. Reason: ~p~n", [Filename, Err]),
- ok
- end
- end.
-
-dump_errors('$end_of_table', Iod) ->
- file:close(Iod);
-dump_errors(Key, Iod) ->
- [{_, Term}] = ets:lookup(ibrowse_errors, Key),
- file:write(Iod, io_lib:format("~p~n", [Term])),
- dump_errors(ets:next(ibrowse_errors, Key), Iod).
-
-%%------------------------------------------------------------------------------
-%% Unit Tests
-%%------------------------------------------------------------------------------
--define(TEST_LIST, [{"http://intranet/messenger", get},
- {"http://www.google.co.uk", get},
- {"http://www.google.com", get},
- {"http://www.google.com", options},
- {"https://mail.google.com", get},
- {"http://www.sun.com", get},
- {"http://www.oracle.com", get},
- {"http://www.bbc.co.uk", get},
- {"http://www.bbc.co.uk", trace},
- {"http://www.bbc.co.uk", options},
- {"http://yaws.hyber.org", get},
- {"http://jigsaw.w3.org/HTTP/ChunkedScript", get},
- {"http://jigsaw.w3.org/HTTP/TE/foo.txt", get},
- {"http://jigsaw.w3.org/HTTP/TE/bar.txt", get},
- {"http://jigsaw.w3.org/HTTP/connection.html", get},
- {"http://jigsaw.w3.org/HTTP/cc.html", get},
- {"http://jigsaw.w3.org/HTTP/cc-private.html", get},
- {"http://jigsaw.w3.org/HTTP/cc-proxy-revalidate.html", get},
- {"http://jigsaw.w3.org/HTTP/cc-nocache.html", get},
- {"http://jigsaw.w3.org/HTTP/h-content-md5.html", get},
- {"http://jigsaw.w3.org/HTTP/h-retry-after.html", get},
- {"http://jigsaw.w3.org/HTTP/h-retry-after-date.html", get},
- {"http://jigsaw.w3.org/HTTP/neg", get},
- {"http://jigsaw.w3.org/HTTP/negbad", get},
- {"http://jigsaw.w3.org/HTTP/400/toolong/", get},
- {"http://jigsaw.w3.org/HTTP/300/", get},
- {"http://jigsaw.w3.org/HTTP/Basic/", get, [{basic_auth, {"guest", "guest"}}]},
- {"http://jigsaw.w3.org/HTTP/CL/", get},
- {"http://www.httpwatch.com/httpgallery/chunked/", get},
- {"https://github.com", get, [{ssl_options, [{depth, 2}]}]},
- {local_test_fun, test_20122010, []}
- ]).
-
-unit_tests() ->
- unit_tests([]).
-
-unit_tests(Options) ->
- application:start(crypto),
- application:start(public_key),
- application:start(ssl),
- (catch ibrowse_test_server:start_server(8181, tcp)),
- ibrowse:start(),
- Options_1 = Options ++ [{connect_timeout, 5000}],
- {Pid, Ref} = erlang:spawn_monitor(?MODULE, unit_tests_1, [self(), Options_1]),
- receive
- {done, Pid} ->
- ok;
- {'DOWN', Ref, _, _, Info} ->
- io:format("Test process crashed: ~p~n", [Info])
- after 60000 ->
- exit(Pid, kill),
- io:format("Timed out waiting for tests to complete~n", [])
- end.
-
-unit_tests_1(Parent, Options) ->
- lists:foreach(fun({local_test_fun, Fun_name, Args}) ->
- execute_req(local_test_fun, Fun_name, Args);
- ({Url, Method}) ->
- execute_req(Url, Method, Options);
- ({Url, Method, X_Opts}) ->
- execute_req(Url, Method, X_Opts ++ Options)
- end, ?TEST_LIST),
- Parent ! {done, self()}.
-
-verify_chunked_streaming() ->
- verify_chunked_streaming([]).
-
-verify_chunked_streaming(Options) ->
- io:format("~nVerifying that chunked streaming is working...~n", []),
- Url = "http://www.httpwatch.com/httpgallery/chunked/",
- io:format(" URL: ~s~n", [Url]),
- io:format(" Fetching data without streaming...~n", []),
- Result_without_streaming = ibrowse:send_req(
- Url, [], get, [],
- [{response_format, binary} | Options]),
- io:format(" Fetching data with streaming as list...~n", []),
- Async_response_list = do_async_req_list(
- Url, get, [{response_format, list} | Options]),
- io:format(" Fetching data with streaming as binary...~n", []),
- Async_response_bin = do_async_req_list(
- Url, get, [{response_format, binary} | Options]),
- io:format(" Fetching data with streaming as binary, {active, once}...~n", []),
- Async_response_bin_once = do_async_req_list(
- Url, get, [once, {response_format, binary} | Options]),
- Res1 = compare_responses(Result_without_streaming, Async_response_list, Async_response_bin),
- Res2 = compare_responses(Result_without_streaming, Async_response_list, Async_response_bin_once),
- case {Res1, Res2} of
- {success, success} ->
- io:format(" Chunked streaming working~n", []);
- _ ->
- ok
- end.
-
-test_chunked_streaming_once() ->
- test_chunked_streaming_once([]).
-
-test_chunked_streaming_once(Options) ->
- io:format("~nTesting chunked streaming with the {stream_to, {Pid, once}} option...~n", []),
- Url = "http://www.httpwatch.com/httpgallery/chunked/",
- io:format(" URL: ~s~n", [Url]),
- io:format(" Fetching data with streaming as binary, {active, once}...~n", []),
- case do_async_req_list(Url, get, [once, {response_format, binary} | Options]) of
- {ok, _, _, _} ->
- io:format(" Success!~n", []);
- Err ->
- io:format(" Fail: ~p~n", [Err])
- end.
-
-compare_responses({ok, St_code, _, Body}, {ok, St_code, _, Body}, {ok, St_code, _, Body}) ->
- success;
-compare_responses({ok, St_code, _, Body_1}, {ok, St_code, _, Body_2}, {ok, St_code, _, Body_3}) ->
- case Body_1 of
- Body_2 ->
- io:format("Body_1 and Body_2 match~n", []);
- Body_3 ->
- io:format("Body_1 and Body_3 match~n", []);
- _ when Body_2 == Body_3 ->
- io:format("Body_2 and Body_3 match~n", []);
- _ ->
- io:format("All three bodies are different!~n", [])
- end,
- io:format("Body_1 -> ~p~n", [Body_1]),
- io:format("Body_2 -> ~p~n", [Body_2]),
- io:format("Body_3 -> ~p~n", [Body_3]),
- fail_bodies_mismatch;
-compare_responses(R1, R2, R3) ->
- io:format("R1 -> ~p~n", [R1]),
- io:format("R2 -> ~p~n", [R2]),
- io:format("R3 -> ~p~n", [R3]),
- fail.
-
-%% do_async_req_list(Url) ->
-%% do_async_req_list(Url, get).
-
-%% do_async_req_list(Url, Method) ->
-%% do_async_req_list(Url, Method, [{stream_to, self()},
-%% {stream_chunk_size, 1000}]).
-
-do_async_req_list(Url, Method, Options) ->
- {Pid,_} = erlang:spawn_monitor(?MODULE, i_do_async_req_list,
- [self(), Url, Method,
- Options ++ [{stream_chunk_size, 1000}]]),
-%% io:format("Spawned process ~p~n", [Pid]),
- wait_for_resp(Pid).
-
-wait_for_resp(Pid) ->
- receive
- {async_result, Pid, Res} ->
- Res;
- {async_result, Other_pid, _} ->
- io:format("~p: Waiting for result from ~p: got from ~p~n", [self(), Pid, Other_pid]),
- wait_for_resp(Pid);
- {'DOWN', _, _, Pid, Reason} ->
- {'EXIT', Reason};
- {'DOWN', _, _, _, _} ->
- wait_for_resp(Pid);
- Msg ->
- io:format("Recvd unknown message: ~p~n", [Msg]),
- wait_for_resp(Pid)
- after 100000 ->
- {error, timeout}
- end.
-
-i_do_async_req_list(Parent, Url, Method, Options) ->
- Options_1 = case lists:member(once, Options) of
- true ->
- [{stream_to, {self(), once}} | (Options -- [once])];
- false ->
- [{stream_to, self()} | Options]
- end,
- Res = ibrowse:send_req(Url, [], Method, [], Options_1),
- case Res of
- {ibrowse_req_id, Req_id} ->
- Result = wait_for_async_resp(Req_id, Options, undefined, undefined, []),
- Parent ! {async_result, self(), Result};
- Err ->
- Parent ! {async_result, self(), Err}
- end.
-
-wait_for_async_resp(Req_id, Options, Acc_Stat_code, Acc_Headers, Body) ->
- receive
- {ibrowse_async_headers, Req_id, StatCode, Headers} ->
- %% io:format("Recvd headers...~n", []),
- maybe_stream_next(Req_id, Options),
- wait_for_async_resp(Req_id, Options, StatCode, Headers, Body);
- {ibrowse_async_response_end, Req_id} ->
- %% io:format("Recvd end of response.~n", []),
- Body_1 = list_to_binary(lists:reverse(Body)),
- {ok, Acc_Stat_code, Acc_Headers, Body_1};
- {ibrowse_async_response, Req_id, Data} ->
- maybe_stream_next(Req_id, Options),
- %% io:format("Recvd data...~n", []),
- wait_for_async_resp(Req_id, Options, Acc_Stat_code, Acc_Headers, [Data | Body]);
- {ibrowse_async_response, Req_id, {error, _} = Err} ->
- {ok, Acc_Stat_code, Acc_Headers, Err};
- Err ->
- {ok, Acc_Stat_code, Acc_Headers, Err}
- after 10000 ->
- {timeout, Acc_Stat_code, Acc_Headers, Body}
- end.
-
-maybe_stream_next(Req_id, Options) ->
- case lists:member(once, Options) of
- true ->
- ibrowse:stream_next(Req_id);
- false ->
- ok
- end.
-
-execute_req(local_test_fun, Method, Args) ->
- io:format(" ~-54.54w: ", [Method]),
- Result = (catch apply(?MODULE, Method, Args)),
- io:format("~p~n", [Result]);
-execute_req(Url, Method, Options) ->
- io:format("~7.7w, ~50.50s: ", [Method, Url]),
- Result = (catch ibrowse:send_req(Url, [], Method, [], Options)),
- case Result of
- {ok, SCode, _H, _B} ->
- io:format("Status code: ~p~n", [SCode]);
- Err ->
- io:format("~p~n", [Err])
- end.
-
-ue_test() ->
- ue_test(lists:duplicate(1024, $?)).
-ue_test(Data) ->
- {Time, Res} = timer:tc(ibrowse_lib, url_encode, [Data]),
- io:format("Time -> ~p~n", [Time]),
- io:format("Data Length -> ~p~n", [length(Data)]),
- io:format("Res Length -> ~p~n", [length(Res)]).
-% io:format("Result -> ~s~n", [Res]).
-
-log_msg(Fmt, Args) ->
- io:format("~s -- " ++ Fmt,
- [ibrowse_lib:printable_date() | Args]).
-
-%%------------------------------------------------------------------------------
-%%
-%%------------------------------------------------------------------------------
-
-test_20122010() ->
- test_20122010("http://localhost:8181").
-
-test_20122010(Url) ->
- {ok, Pid} = ibrowse:spawn_worker_process(Url),
- Expected_resp = <<"1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51-52-53-54-55-56-57-58-59-60-61-62-63-64-65-66-67-68-69-70-71-72-73-74-75-76-77-78-79-80-81-82-83-84-85-86-87-88-89-90-91-92-93-94-95-96-97-98-99-100">>,
- Test_parent = self(),
- Fun = fun() ->
- do_test_20122010(Url, Pid, Expected_resp, Test_parent)
- end,
- Pids = [erlang:spawn_monitor(Fun) || _ <- lists:seq(1,10)],
- wait_for_workers(Pids).
-
-wait_for_workers([{Pid, _Ref} | Pids]) ->
- receive
- {Pid, success} ->
- wait_for_workers(Pids)
- after 60000 ->
- test_failed
- end;
-wait_for_workers([]) ->
- success.
-
-do_test_20122010(Url, Pid, Expected_resp, Test_parent) ->
- do_test_20122010(10, Url, Pid, Expected_resp, Test_parent).
-
-do_test_20122010(0, _Url, _Pid, _Expected_resp, Test_parent) ->
- Test_parent ! {self(), success};
-do_test_20122010(Rem_count, Url, Pid, Expected_resp, Test_parent) ->
- {ibrowse_req_id, Req_id} = ibrowse:send_req_direct(
- Pid,
- Url ++ "/ibrowse_stream_once_chunk_pipeline_test",
- [], get, [],
- [{stream_to, {self(), once}},
- {inactivity_timeout, 10000},
- {include_ibrowse_req_id, true}]),
- do_trace("~p -- sent request ~1000.p~n", [self(), Req_id]),
- Req_id_str = lists:flatten(io_lib:format("~1000.p",[Req_id])),
- receive
- {ibrowse_async_headers, Req_id, "200", Headers} ->
- case lists:keysearch("x-ibrowse-request-id", 1, Headers) of
- {value, {_, Req_id_str}} ->
- ok;
- {value, {_, Req_id_1}} ->
- do_trace("~p -- Sent req-id: ~1000.p. Recvd: ~1000.p~n",
- [self(), Req_id, Req_id_1]),
- exit(req_id_mismatch)
- end
- after 5000 ->
- do_trace("~p -- response headers not received~n", [self()]),
- exit({timeout, test_failed})
- end,
- do_trace("~p -- response headers received~n", [self()]),
- ok = ibrowse:stream_next(Req_id),
- case do_test_20122010_1(Expected_resp, Req_id, []) of
- true ->
- do_test_20122010(Rem_count - 1, Url, Pid, Expected_resp, Test_parent);
- false ->
- Test_parent ! {self(), failed}
- end.
-
-do_test_20122010_1(Expected_resp, Req_id, Acc) ->
- receive
- {ibrowse_async_response, Req_id, Body_part} ->
- ok = ibrowse:stream_next(Req_id),
- do_test_20122010_1(Expected_resp, Req_id, [Body_part | Acc]);
- {ibrowse_async_response_end, Req_id} ->
- Acc_1 = list_to_binary(lists:reverse(Acc)),
- Result = Acc_1 == Expected_resp,
- do_trace("~p -- End of response. Result: ~p~n", [self(), Result]),
- Result
- after 1000 ->
- exit({timeout, test_failed})
- end.
-
-do_trace(Fmt, Args) ->
- do_trace(get(my_trace_flag), Fmt, Args).
-
-do_trace(true, Fmt, Args) ->
- io:format("~s -- " ++ Fmt, [ibrowse_lib:printable_date() | Args]);
-do_trace(_, _, _) ->
- ok.
diff --git a/src/mochiweb/Makefile.am b/src/mochiweb/Makefile.am
deleted file mode 100644
index 4fa49631..00000000
--- a/src/mochiweb/Makefile.am
+++ /dev/null
@@ -1,102 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-mochiwebebindir = $(localerlanglibdir)/mochiweb-7c2bc2/ebin
-
-mochiweb_file_collection = \
- mochifmt.erl \
- mochifmt_records.erl \
- mochifmt_std.erl \
- mochiglobal.erl \
- mochihex.erl \
- mochijson.erl \
- mochijson2.erl \
- mochilists.erl \
- mochilogfile2.erl \
- mochinum.erl \
- mochitemp.erl \
- mochiutf8.erl \
- mochiweb.app.in \
- mochiweb.erl \
- mochiweb_acceptor.erl \
- mochiweb_app.erl \
- mochiweb_charref.erl \
- mochiweb_cookies.erl \
- mochiweb_cover.erl \
- mochiweb_echo.erl \
- mochiweb_headers.erl \
- mochiweb_html.erl \
- mochiweb_http.erl \
- mochiweb_io.erl \
- mochiweb_mime.erl \
- mochiweb_multipart.erl \
- mochiweb_request.erl \
- mochiweb_response.erl \
- mochiweb_skel.erl \
- mochiweb_socket.erl \
- mochiweb_socket_server.erl \
- mochiweb_sup.erl \
- mochiweb_util.erl \
- reloader.erl
-
-mochiwebebin_make_generated_file_list = \
- mochifmt.beam \
- mochifmt_records.beam \
- mochifmt_std.beam \
- mochiglobal.beam \
- mochihex.beam \
- mochijson.beam \
- mochijson2.beam \
- mochilists.beam \
- mochilogfile2.beam \
- mochinum.beam \
- mochitemp.beam \
- mochiutf8.beam \
- mochiweb.app \
- mochiweb.beam \
- mochiweb_acceptor.beam \
- mochiweb_app.beam \
- mochiweb_charref.beam \
- mochiweb_cookies.beam \
- mochiweb_cover.beam \
- mochiweb_echo.beam \
- mochiweb_headers.beam \
- mochiweb_html.beam \
- mochiweb_http.beam \
- mochiweb_io.beam \
- mochiweb_mime.beam \
- mochiweb_multipart.beam \
- mochiweb_request.beam \
- mochiweb_response.beam \
- mochiweb_skel.beam \
- mochiweb_socket.beam \
- mochiweb_socket_server.beam \
- mochiweb_sup.beam \
- mochiweb_util.beam \
- reloader.beam
-
-mochiwebebin_DATA = \
- $(mochiwebebin_make_generated_file_list)
-
-EXTRA_DIST = \
- $(mochiweb_file_collection) \
- mochiweb.app.src \
- internal.hrl
-
-CLEANFILES = \
- $(mochiwebebin_make_generated_file_list)
-
-%.app: %.app.in
- cp $< $@
-
-%.beam: %.erl
- $(ERLC) $(ERLC_FLAGS) $<
diff --git a/src/mochiweb/internal.hrl b/src/mochiweb/internal.hrl
deleted file mode 100644
index 6db899a0..00000000
--- a/src/mochiweb/internal.hrl
+++ /dev/null
@@ -1,3 +0,0 @@
-
--define(RECBUF_SIZE, 8192).
-
diff --git a/src/mochiweb/mochifmt.erl b/src/mochiweb/mochifmt.erl
deleted file mode 100644
index 5bc6b9c4..00000000
--- a/src/mochiweb/mochifmt.erl
+++ /dev/null
@@ -1,425 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2008 Mochi Media, Inc.
-
-%% @doc String Formatting for Erlang, inspired by Python 2.6
-%% (<a href="http://www.python.org/dev/peps/pep-3101/">PEP 3101</a>).
-%%
--module(mochifmt).
--author('bob@mochimedia.com').
--export([format/2, format_field/2, convert_field/2, get_value/2, get_field/2]).
--export([tokenize/1, format/3, get_field/3, format_field/3]).
--export([bformat/2, bformat/3]).
--export([f/2, f/3]).
-
--record(conversion, {length, precision, ctype, align, fill_char, sign}).
-
-%% @spec tokenize(S::string()) -> tokens()
-%% @doc Tokenize a format string into mochifmt's internal format.
-tokenize(S) ->
- {?MODULE, tokenize(S, "", [])}.
-
-%% @spec convert_field(Arg, Conversion::conversion()) -> term()
-%% @doc Process Arg according to the given explicit conversion specifier.
-convert_field(Arg, "") ->
- Arg;
-convert_field(Arg, "r") ->
- repr(Arg);
-convert_field(Arg, "s") ->
- str(Arg).
-
-%% @spec get_value(Key::string(), Args::args()) -> term()
-%% @doc Get the Key from Args. If Args is a tuple then convert Key to
-%% an integer and get element(1 + Key, Args). If Args is a list and Key
-%% can be parsed as an integer then use lists:nth(1 + Key, Args),
-%% otherwise try and look for Key in Args as a proplist, converting
-%% Key to an atom or binary if necessary.
-get_value(Key, Args) when is_tuple(Args) ->
- element(1 + list_to_integer(Key), Args);
-get_value(Key, Args) when is_list(Args) ->
- try lists:nth(1 + list_to_integer(Key), Args)
- catch error:_ ->
- {_K, V} = proplist_lookup(Key, Args),
- V
- end.
-
-%% @spec get_field(Key::string(), Args) -> term()
-%% @doc Consecutively call get_value/2 on parts of Key delimited by ".",
-%% replacing Args with the result of the previous get_value. This
-%% is used to implement formats such as {0.0}.
-get_field(Key, Args) ->
- get_field(Key, Args, ?MODULE).
-
-%% @spec get_field(Key::string(), Args, Module) -> term()
-%% @doc Consecutively call Module:get_value/2 on parts of Key delimited by ".",
-%% replacing Args with the result of the previous get_value. This
-%% is used to implement formats such as {0.0}.
-get_field(Key, Args, Module) ->
- {Name, Next} = lists:splitwith(fun (C) -> C =/= $. end, Key),
- Res = try Module:get_value(Name, Args)
- catch error:undef -> get_value(Name, Args) end,
- case Next of
- "" ->
- Res;
- "." ++ S1 ->
- get_field(S1, Res, Module)
- end.
-
-%% @spec format(Format::string(), Args) -> iolist()
-%% @doc Format Args with Format.
-format(Format, Args) ->
- format(Format, Args, ?MODULE).
-
-%% @spec format(Format::string(), Args, Module) -> iolist()
-%% @doc Format Args with Format using Module.
-format({?MODULE, Parts}, Args, Module) ->
- format2(Parts, Args, Module, []);
-format(S, Args, Module) ->
- format(tokenize(S), Args, Module).
-
-%% @spec format_field(Arg, Format) -> iolist()
-%% @doc Format Arg with Format.
-format_field(Arg, Format) ->
- format_field(Arg, Format, ?MODULE).
-
-%% @spec format_field(Arg, Format, _Module) -> iolist()
-%% @doc Format Arg with Format.
-format_field(Arg, Format, _Module) ->
- F = default_ctype(Arg, parse_std_conversion(Format)),
- fix_padding(fix_sign(convert2(Arg, F), F), F).
-
-%% @spec f(Format::string(), Args) -> string()
-%% @doc Format Args with Format and return a string().
-f(Format, Args) ->
- f(Format, Args, ?MODULE).
-
-%% @spec f(Format::string(), Args, Module) -> string()
-%% @doc Format Args with Format using Module and return a string().
-f(Format, Args, Module) ->
- case lists:member(${, Format) of
- true ->
- binary_to_list(bformat(Format, Args, Module));
- false ->
- Format
- end.
-
-%% @spec bformat(Format::string(), Args) -> binary()
-%% @doc Format Args with Format and return a binary().
-bformat(Format, Args) ->
- iolist_to_binary(format(Format, Args)).
-
-%% @spec bformat(Format::string(), Args, Module) -> binary()
-%% @doc Format Args with Format using Module and return a binary().
-bformat(Format, Args, Module) ->
- iolist_to_binary(format(Format, Args, Module)).
-
-%% Internal API
-
-add_raw("", Acc) ->
- Acc;
-add_raw(S, Acc) ->
- [{raw, lists:reverse(S)} | Acc].
-
-tokenize([], S, Acc) ->
- lists:reverse(add_raw(S, Acc));
-tokenize("{{" ++ Rest, S, Acc) ->
- tokenize(Rest, "{" ++ S, Acc);
-tokenize("{" ++ Rest, S, Acc) ->
- {Format, Rest1} = tokenize_format(Rest),
- tokenize(Rest1, "", [{format, make_format(Format)} | add_raw(S, Acc)]);
-tokenize("}}" ++ Rest, S, Acc) ->
- tokenize(Rest, "}" ++ S, Acc);
-tokenize([C | Rest], S, Acc) ->
- tokenize(Rest, [C | S], Acc).
-
-tokenize_format(S) ->
- tokenize_format(S, 1, []).
-
-tokenize_format("}" ++ Rest, 1, Acc) ->
- {lists:reverse(Acc), Rest};
-tokenize_format("}" ++ Rest, N, Acc) ->
- tokenize_format(Rest, N - 1, "}" ++ Acc);
-tokenize_format("{" ++ Rest, N, Acc) ->
- tokenize_format(Rest, 1 + N, "{" ++ Acc);
-tokenize_format([C | Rest], N, Acc) ->
- tokenize_format(Rest, N, [C | Acc]).
-
-make_format(S) ->
- {Name0, Spec} = case lists:splitwith(fun (C) -> C =/= $: end, S) of
- {_, ""} ->
- {S, ""};
- {SN, ":" ++ SS} ->
- {SN, SS}
- end,
- {Name, Transform} = case lists:splitwith(fun (C) -> C =/= $! end, Name0) of
- {_, ""} ->
- {Name0, ""};
- {TN, "!" ++ TT} ->
- {TN, TT}
- end,
- {Name, Transform, Spec}.
-
-proplist_lookup(S, P) ->
- A = try list_to_existing_atom(S)
- catch error:_ -> make_ref() end,
- B = try list_to_binary(S)
- catch error:_ -> make_ref() end,
- proplist_lookup2({S, A, B}, P).
-
-proplist_lookup2({KS, KA, KB}, [{K, V} | _])
- when KS =:= K orelse KA =:= K orelse KB =:= K ->
- {K, V};
-proplist_lookup2(Keys, [_ | Rest]) ->
- proplist_lookup2(Keys, Rest).
-
-format2([], _Args, _Module, Acc) ->
- lists:reverse(Acc);
-format2([{raw, S} | Rest], Args, Module, Acc) ->
- format2(Rest, Args, Module, [S | Acc]);
-format2([{format, {Key, Convert, Format0}} | Rest], Args, Module, Acc) ->
- Format = f(Format0, Args, Module),
- V = case Module of
- ?MODULE ->
- V0 = get_field(Key, Args),
- V1 = convert_field(V0, Convert),
- format_field(V1, Format);
- _ ->
- V0 = try Module:get_field(Key, Args)
- catch error:undef -> get_field(Key, Args, Module) end,
- V1 = try Module:convert_field(V0, Convert)
- catch error:undef -> convert_field(V0, Convert) end,
- try Module:format_field(V1, Format)
- catch error:undef -> format_field(V1, Format, Module) end
- end,
- format2(Rest, Args, Module, [V | Acc]).
-
-default_ctype(_Arg, C=#conversion{ctype=N}) when N =/= undefined ->
- C;
-default_ctype(Arg, C) when is_integer(Arg) ->
- C#conversion{ctype=decimal};
-default_ctype(Arg, C) when is_float(Arg) ->
- C#conversion{ctype=general};
-default_ctype(_Arg, C) ->
- C#conversion{ctype=string}.
-
-fix_padding(Arg, #conversion{length=undefined}) ->
- Arg;
-fix_padding(Arg, F=#conversion{length=Length, fill_char=Fill0, align=Align0,
- ctype=Type}) ->
- Padding = Length - iolist_size(Arg),
- Fill = case Fill0 of
- undefined ->
- $\s;
- _ ->
- Fill0
- end,
- Align = case Align0 of
- undefined ->
- case Type of
- string ->
- left;
- _ ->
- right
- end;
- _ ->
- Align0
- end,
- case Padding > 0 of
- true ->
- do_padding(Arg, Padding, Fill, Align, F);
- false ->
- Arg
- end.
-
-do_padding(Arg, Padding, Fill, right, _F) ->
- [lists:duplicate(Padding, Fill), Arg];
-do_padding(Arg, Padding, Fill, center, _F) ->
- LPadding = lists:duplicate(Padding div 2, Fill),
- RPadding = case Padding band 1 of
- 1 ->
- [Fill | LPadding];
- _ ->
- LPadding
- end,
- [LPadding, Arg, RPadding];
-do_padding([$- | Arg], Padding, Fill, sign_right, _F) ->
- [[$- | lists:duplicate(Padding, Fill)], Arg];
-do_padding(Arg, Padding, Fill, sign_right, #conversion{sign=$-}) ->
- [lists:duplicate(Padding, Fill), Arg];
-do_padding([S | Arg], Padding, Fill, sign_right, #conversion{sign=S}) ->
- [[S | lists:duplicate(Padding, Fill)], Arg];
-do_padding(Arg, Padding, Fill, sign_right, #conversion{sign=undefined}) ->
- [lists:duplicate(Padding, Fill), Arg];
-do_padding(Arg, Padding, Fill, left, _F) ->
- [Arg | lists:duplicate(Padding, Fill)].
-
-fix_sign(Arg, #conversion{sign=$+}) when Arg >= 0 ->
- [$+, Arg];
-fix_sign(Arg, #conversion{sign=$\s}) when Arg >= 0 ->
- [$\s, Arg];
-fix_sign(Arg, _F) ->
- Arg.
-
-ctype($\%) -> percent;
-ctype($s) -> string;
-ctype($b) -> bin;
-ctype($o) -> oct;
-ctype($X) -> upper_hex;
-ctype($x) -> hex;
-ctype($c) -> char;
-ctype($d) -> decimal;
-ctype($g) -> general;
-ctype($f) -> fixed;
-ctype($e) -> exp.
-
-align($<) -> left;
-align($>) -> right;
-align($^) -> center;
-align($=) -> sign_right.
-
-convert2(Arg, F=#conversion{ctype=percent}) ->
- [convert2(100.0 * Arg, F#conversion{ctype=fixed}), $\%];
-convert2(Arg, #conversion{ctype=string}) ->
- str(Arg);
-convert2(Arg, #conversion{ctype=bin}) ->
- erlang:integer_to_list(Arg, 2);
-convert2(Arg, #conversion{ctype=oct}) ->
- erlang:integer_to_list(Arg, 8);
-convert2(Arg, #conversion{ctype=upper_hex}) ->
- erlang:integer_to_list(Arg, 16);
-convert2(Arg, #conversion{ctype=hex}) ->
- string:to_lower(erlang:integer_to_list(Arg, 16));
-convert2(Arg, #conversion{ctype=char}) when Arg < 16#80 ->
- [Arg];
-convert2(Arg, #conversion{ctype=char}) ->
- xmerl_ucs:to_utf8(Arg);
-convert2(Arg, #conversion{ctype=decimal}) ->
- integer_to_list(Arg);
-convert2(Arg, #conversion{ctype=general, precision=undefined}) ->
- try mochinum:digits(Arg)
- catch error:undef -> io_lib:format("~g", [Arg]) end;
-convert2(Arg, #conversion{ctype=fixed, precision=undefined}) ->
- io_lib:format("~f", [Arg]);
-convert2(Arg, #conversion{ctype=exp, precision=undefined}) ->
- io_lib:format("~e", [Arg]);
-convert2(Arg, #conversion{ctype=general, precision=P}) ->
- io_lib:format("~." ++ integer_to_list(P) ++ "g", [Arg]);
-convert2(Arg, #conversion{ctype=fixed, precision=P}) ->
- io_lib:format("~." ++ integer_to_list(P) ++ "f", [Arg]);
-convert2(Arg, #conversion{ctype=exp, precision=P}) ->
- io_lib:format("~." ++ integer_to_list(P) ++ "e", [Arg]).
-
-str(A) when is_atom(A) ->
- atom_to_list(A);
-str(I) when is_integer(I) ->
- integer_to_list(I);
-str(F) when is_float(F) ->
- try mochinum:digits(F)
- catch error:undef -> io_lib:format("~g", [F]) end;
-str(L) when is_list(L) ->
- L;
-str(B) when is_binary(B) ->
- B;
-str(P) ->
- repr(P).
-
-repr(P) when is_float(P) ->
- try mochinum:digits(P)
- catch error:undef -> float_to_list(P) end;
-repr(P) ->
- io_lib:format("~p", [P]).
-
-parse_std_conversion(S) ->
- parse_std_conversion(S, #conversion{}).
-
-parse_std_conversion("", Acc) ->
- Acc;
-parse_std_conversion([Fill, Align | Spec], Acc)
- when Align =:= $< orelse Align =:= $> orelse Align =:= $= orelse Align =:= $^ ->
- parse_std_conversion(Spec, Acc#conversion{fill_char=Fill,
- align=align(Align)});
-parse_std_conversion([Align | Spec], Acc)
- when Align =:= $< orelse Align =:= $> orelse Align =:= $= orelse Align =:= $^ ->
- parse_std_conversion(Spec, Acc#conversion{align=align(Align)});
-parse_std_conversion([Sign | Spec], Acc)
- when Sign =:= $+ orelse Sign =:= $- orelse Sign =:= $\s ->
- parse_std_conversion(Spec, Acc#conversion{sign=Sign});
-parse_std_conversion("0" ++ Spec, Acc) ->
- Align = case Acc#conversion.align of
- undefined ->
- sign_right;
- A ->
- A
- end,
- parse_std_conversion(Spec, Acc#conversion{fill_char=$0, align=Align});
-parse_std_conversion(Spec=[D|_], Acc) when D >= $0 andalso D =< $9 ->
- {W, Spec1} = lists:splitwith(fun (C) -> C >= $0 andalso C =< $9 end, Spec),
- parse_std_conversion(Spec1, Acc#conversion{length=list_to_integer(W)});
-parse_std_conversion([$. | Spec], Acc) ->
- case lists:splitwith(fun (C) -> C >= $0 andalso C =< $9 end, Spec) of
- {"", Spec1} ->
- parse_std_conversion(Spec1, Acc);
- {P, Spec1} ->
- parse_std_conversion(Spec1,
- Acc#conversion{precision=list_to_integer(P)})
- end;
-parse_std_conversion([Type], Acc) ->
- parse_std_conversion("", Acc#conversion{ctype=ctype(Type)}).
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-tokenize_test() ->
- {?MODULE, [{raw, "ABC"}]} = tokenize("ABC"),
- {?MODULE, [{format, {"0", "", ""}}]} = tokenize("{0}"),
- {?MODULE, [{raw, "ABC"}, {format, {"1", "", ""}}, {raw, "DEF"}]} =
- tokenize("ABC{1}DEF"),
- ok.
-
-format_test() ->
- <<" -4">> = bformat("{0:4}", [-4]),
- <<" 4">> = bformat("{0:4}", [4]),
- <<" 4">> = bformat("{0:{0}}", [4]),
- <<"4 ">> = bformat("{0:4}", ["4"]),
- <<"4 ">> = bformat("{0:{0}}", ["4"]),
- <<"1.2yoDEF">> = bformat("{2}{0}{1}{3}", {yo, "DE", 1.2, <<"F">>}),
- <<"cafebabe">> = bformat("{0:x}", {16#cafebabe}),
- <<"CAFEBABE">> = bformat("{0:X}", {16#cafebabe}),
- <<"CAFEBABE">> = bformat("{0:X}", {16#cafebabe}),
- <<"755">> = bformat("{0:o}", {8#755}),
- <<"a">> = bformat("{0:c}", {97}),
- %% Horizontal ellipsis
- <<226, 128, 166>> = bformat("{0:c}", {16#2026}),
- <<"11">> = bformat("{0:b}", {3}),
- <<"11">> = bformat("{0:b}", [3]),
- <<"11">> = bformat("{three:b}", [{three, 3}]),
- <<"11">> = bformat("{three:b}", [{"three", 3}]),
- <<"11">> = bformat("{three:b}", [{<<"three">>, 3}]),
- <<"\"foo\"">> = bformat("{0!r}", {"foo"}),
- <<"2008-5-4">> = bformat("{0.0}-{0.1}-{0.2}", {{2008,5,4}}),
- <<"2008-05-04">> = bformat("{0.0:04}-{0.1:02}-{0.2:02}", {{2008,5,4}}),
- <<"foo6bar-6">> = bformat("foo{1}{0}-{1}", {bar, 6}),
- <<"-'atom test'-">> = bformat("-{arg!r}-", [{arg, 'atom test'}]),
- <<"2008-05-04">> = bformat("{0.0:0{1.0}}-{0.1:0{1.1}}-{0.2:0{1.2}}",
- {{2008,5,4}, {4, 2, 2}}),
- ok.
-
-std_test() ->
- M = mochifmt_std:new(),
- <<"01">> = bformat("{0}{1}", [0, 1], M),
- ok.
-
-records_test() ->
- M = mochifmt_records:new([{conversion, record_info(fields, conversion)}]),
- R = #conversion{length=long, precision=hard, sign=peace},
- long = M:get_value("length", R),
- hard = M:get_value("precision", R),
- peace = M:get_value("sign", R),
- <<"long hard">> = bformat("{length} {precision}", R, M),
- <<"long hard">> = bformat("{0.length} {0.precision}", [R], M),
- ok.
-
--endif.
diff --git a/src/mochiweb/mochifmt_records.erl b/src/mochiweb/mochifmt_records.erl
deleted file mode 100644
index 2326d1dd..00000000
--- a/src/mochiweb/mochifmt_records.erl
+++ /dev/null
@@ -1,38 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2008 Mochi Media, Inc.
-
-%% @doc Formatter that understands records.
-%%
-%% Usage:
-%%
-%% 1> M = mochifmt_records:new([{rec, record_info(fields, rec)}]),
-%% M:format("{0.bar}", [#rec{bar=foo}]).
-%% foo
-
--module(mochifmt_records, [Recs]).
--author('bob@mochimedia.com').
--export([get_value/2]).
-
-get_value(Key, Rec) when is_tuple(Rec) and is_atom(element(1, Rec)) ->
- try begin
- Atom = list_to_existing_atom(Key),
- {_, Fields} = proplists:lookup(element(1, Rec), Recs),
- element(get_rec_index(Atom, Fields, 2), Rec)
- end
- catch error:_ -> mochifmt:get_value(Key, Rec)
- end;
-get_value(Key, Args) ->
- mochifmt:get_value(Key, Args).
-
-get_rec_index(Atom, [Atom | _], Index) ->
- Index;
-get_rec_index(Atom, [_ | Rest], Index) ->
- get_rec_index(Atom, Rest, 1 + Index).
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
--endif.
diff --git a/src/mochiweb/mochifmt_std.erl b/src/mochiweb/mochifmt_std.erl
deleted file mode 100644
index d4d74f6f..00000000
--- a/src/mochiweb/mochifmt_std.erl
+++ /dev/null
@@ -1,30 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2008 Mochi Media, Inc.
-
-%% @doc Template module for a mochifmt formatter.
-
--module(mochifmt_std, []).
--author('bob@mochimedia.com').
--export([format/2, get_value/2, format_field/2, get_field/2, convert_field/2]).
-
-format(Format, Args) ->
- mochifmt:format(Format, Args, THIS).
-
-get_field(Key, Args) ->
- mochifmt:get_field(Key, Args, THIS).
-
-convert_field(Key, Args) ->
- mochifmt:convert_field(Key, Args).
-
-get_value(Key, Args) ->
- mochifmt:get_value(Key, Args).
-
-format_field(Arg, Format) ->
- mochifmt:format_field(Arg, Format, THIS).
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
--endif.
diff --git a/src/mochiweb/mochiglobal.erl b/src/mochiweb/mochiglobal.erl
deleted file mode 100644
index c740b878..00000000
--- a/src/mochiweb/mochiglobal.erl
+++ /dev/null
@@ -1,107 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2010 Mochi Media, Inc.
-%% @doc Abuse module constant pools as a "read-only shared heap" (since erts 5.6)
-%% <a href="http://www.erlang.org/pipermail/erlang-questions/2009-March/042503.html">[1]</a>.
--module(mochiglobal).
--author("Bob Ippolito <bob@mochimedia.com>").
--export([get/1, get/2, put/2, delete/1]).
-
--spec get(atom()) -> any() | undefined.
-%% @equiv get(K, undefined)
-get(K) ->
- get(K, undefined).
-
--spec get(atom(), T) -> any() | T.
-%% @doc Get the term for K or return Default.
-get(K, Default) ->
- get(K, Default, key_to_module(K)).
-
-get(_K, Default, Mod) ->
- try Mod:term()
- catch error:undef ->
- Default
- end.
-
--spec put(atom(), any()) -> ok.
-%% @doc Store term V at K, replaces an existing term if present.
-put(K, V) ->
- put(K, V, key_to_module(K)).
-
-put(_K, V, Mod) ->
- Bin = compile(Mod, V),
- code:purge(Mod),
- code:load_binary(Mod, atom_to_list(Mod) ++ ".erl", Bin),
- ok.
-
--spec delete(atom()) -> boolean().
-%% @doc Delete term stored at K, no-op if non-existent.
-delete(K) ->
- delete(K, key_to_module(K)).
-
-delete(_K, Mod) ->
- code:purge(Mod),
- code:delete(Mod).
-
--spec key_to_module(atom()) -> atom().
-key_to_module(K) ->
- list_to_atom("mochiglobal:" ++ atom_to_list(K)).
-
--spec compile(atom(), any()) -> binary().
-compile(Module, T) ->
- {ok, Module, Bin} = compile:forms(forms(Module, T),
- [verbose, report_errors]),
- Bin.
-
--spec forms(atom(), any()) -> [erl_syntax:syntaxTree()].
-forms(Module, T) ->
- [erl_syntax:revert(X) || X <- term_to_abstract(Module, term, T)].
-
--spec term_to_abstract(atom(), atom(), any()) -> [erl_syntax:syntaxTree()].
-term_to_abstract(Module, Getter, T) ->
- [%% -module(Module).
- erl_syntax:attribute(
- erl_syntax:atom(module),
- [erl_syntax:atom(Module)]),
- %% -export([Getter/0]).
- erl_syntax:attribute(
- erl_syntax:atom(export),
- [erl_syntax:list(
- [erl_syntax:arity_qualifier(
- erl_syntax:atom(Getter),
- erl_syntax:integer(0))])]),
- %% Getter() -> T.
- erl_syntax:function(
- erl_syntax:atom(Getter),
- [erl_syntax:clause([], none, [erl_syntax:abstract(T)])])].
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-get_put_delete_test() ->
- K = '$$test$$mochiglobal',
- delete(K),
- ?assertEqual(
- bar,
- get(K, bar)),
- try
- ?MODULE:put(K, baz),
- ?assertEqual(
- baz,
- get(K, bar)),
- ?MODULE:put(K, wibble),
- ?assertEqual(
- wibble,
- ?MODULE:get(K))
- after
- delete(K)
- end,
- ?assertEqual(
- bar,
- get(K, bar)),
- ?assertEqual(
- undefined,
- ?MODULE:get(K)),
- ok.
--endif.
diff --git a/src/mochiweb/mochihex.erl b/src/mochiweb/mochihex.erl
deleted file mode 100644
index 44a2aa7f..00000000
--- a/src/mochiweb/mochihex.erl
+++ /dev/null
@@ -1,91 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2006 Mochi Media, Inc.
-
-%% @doc Utilities for working with hexadecimal strings.
-
--module(mochihex).
--author('bob@mochimedia.com').
-
--export([to_hex/1, to_bin/1, to_int/1, dehex/1, hexdigit/1]).
-
-%% @type iolist() = [char() | binary() | iolist()]
-%% @type iodata() = iolist() | binary()
-
-%% @spec to_hex(integer | iolist()) -> string()
-%% @doc Convert an iolist to a hexadecimal string.
-to_hex(0) ->
- "0";
-to_hex(I) when is_integer(I), I > 0 ->
- to_hex_int(I, []);
-to_hex(B) ->
- to_hex(iolist_to_binary(B), []).
-
-%% @spec to_bin(string()) -> binary()
-%% @doc Convert a hexadecimal string to a binary.
-to_bin(L) ->
- to_bin(L, []).
-
-%% @spec to_int(string()) -> integer()
-%% @doc Convert a hexadecimal string to an integer.
-to_int(L) ->
- erlang:list_to_integer(L, 16).
-
-%% @spec dehex(char()) -> integer()
-%% @doc Convert a hex digit to its integer value.
-dehex(C) when C >= $0, C =< $9 ->
- C - $0;
-dehex(C) when C >= $a, C =< $f ->
- C - $a + 10;
-dehex(C) when C >= $A, C =< $F ->
- C - $A + 10.
-
-%% @spec hexdigit(integer()) -> char()
-%% @doc Convert an integer less than 16 to a hex digit.
-hexdigit(C) when C >= 0, C =< 9 ->
- C + $0;
-hexdigit(C) when C =< 15 ->
- C + $a - 10.
-
-%% Internal API
-
-to_hex(<<>>, Acc) ->
- lists:reverse(Acc);
-to_hex(<<C1:4, C2:4, Rest/binary>>, Acc) ->
- to_hex(Rest, [hexdigit(C2), hexdigit(C1) | Acc]).
-
-to_hex_int(0, Acc) ->
- Acc;
-to_hex_int(I, Acc) ->
- to_hex_int(I bsr 4, [hexdigit(I band 15) | Acc]).
-
-to_bin([], Acc) ->
- iolist_to_binary(lists:reverse(Acc));
-to_bin([C1, C2 | Rest], Acc) ->
- to_bin(Rest, [(dehex(C1) bsl 4) bor dehex(C2) | Acc]).
-
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-to_hex_test() ->
- "ff000ff1" = to_hex([255, 0, 15, 241]),
- "ff000ff1" = to_hex(16#ff000ff1),
- "0" = to_hex(16#0),
- ok.
-
-to_bin_test() ->
- <<255, 0, 15, 241>> = to_bin("ff000ff1"),
- <<255, 0, 10, 161>> = to_bin("Ff000aA1"),
- ok.
-
-to_int_test() ->
- 16#ff000ff1 = to_int("ff000ff1"),
- 16#ff000aa1 = to_int("FF000Aa1"),
- 16#0 = to_int("0"),
- ok.
-
--endif.
diff --git a/src/mochiweb/mochijson.erl b/src/mochiweb/mochijson.erl
deleted file mode 100644
index 2e3d1452..00000000
--- a/src/mochiweb/mochijson.erl
+++ /dev/null
@@ -1,531 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2006 Mochi Media, Inc.
-
-%% @doc Yet another JSON (RFC 4627) library for Erlang.
--module(mochijson).
--author('bob@mochimedia.com').
--export([encoder/1, encode/1]).
--export([decoder/1, decode/1]).
--export([binary_encoder/1, binary_encode/1]).
--export([binary_decoder/1, binary_decode/1]).
-
-% This is a macro to placate syntax highlighters..
--define(Q, $\").
--define(ADV_COL(S, N), S#decoder{column=N+S#decoder.column}).
--define(INC_COL(S), S#decoder{column=1+S#decoder.column}).
--define(INC_LINE(S), S#decoder{column=1, line=1+S#decoder.line}).
-
-%% @type iolist() = [char() | binary() | iolist()]
-%% @type iodata() = iolist() | binary()
-%% @type json_string() = atom | string() | binary()
-%% @type json_number() = integer() | float()
-%% @type json_array() = {array, [json_term()]}
-%% @type json_object() = {struct, [{json_string(), json_term()}]}
-%% @type json_term() = json_string() | json_number() | json_array() |
-%% json_object()
-%% @type encoding() = utf8 | unicode
-%% @type encoder_option() = {input_encoding, encoding()} |
-%% {handler, function()}
-%% @type decoder_option() = {input_encoding, encoding()} |
-%% {object_hook, function()}
-%% @type bjson_string() = binary()
-%% @type bjson_number() = integer() | float()
-%% @type bjson_array() = [bjson_term()]
-%% @type bjson_object() = {struct, [{bjson_string(), bjson_term()}]}
-%% @type bjson_term() = bjson_string() | bjson_number() | bjson_array() |
-%% bjson_object()
-%% @type binary_encoder_option() = {handler, function()}
-%% @type binary_decoder_option() = {object_hook, function()}
-
--record(encoder, {input_encoding=unicode,
- handler=null}).
-
--record(decoder, {input_encoding=utf8,
- object_hook=null,
- line=1,
- column=1,
- state=null}).
-
-%% @spec encoder([encoder_option()]) -> function()
-%% @doc Create an encoder/1 with the given options.
-encoder(Options) ->
- State = parse_encoder_options(Options, #encoder{}),
- fun (O) -> json_encode(O, State) end.
-
-%% @spec encode(json_term()) -> iolist()
-%% @doc Encode the given as JSON to an iolist.
-encode(Any) ->
- json_encode(Any, #encoder{}).
-
-%% @spec decoder([decoder_option()]) -> function()
-%% @doc Create a decoder/1 with the given options.
-decoder(Options) ->
- State = parse_decoder_options(Options, #decoder{}),
- fun (O) -> json_decode(O, State) end.
-
-%% @spec decode(iolist()) -> json_term()
-%% @doc Decode the given iolist to Erlang terms.
-decode(S) ->
- json_decode(S, #decoder{}).
-
-%% @spec binary_decoder([binary_decoder_option()]) -> function()
-%% @doc Create a binary_decoder/1 with the given options.
-binary_decoder(Options) ->
- mochijson2:decoder(Options).
-
-%% @spec binary_encoder([binary_encoder_option()]) -> function()
-%% @doc Create a binary_encoder/1 with the given options.
-binary_encoder(Options) ->
- mochijson2:encoder(Options).
-
-%% @spec binary_encode(bjson_term()) -> iolist()
-%% @doc Encode the given as JSON to an iolist, using lists for arrays and
-%% binaries for strings.
-binary_encode(Any) ->
- mochijson2:encode(Any).
-
-%% @spec binary_decode(iolist()) -> bjson_term()
-%% @doc Decode the given iolist to Erlang terms, using lists for arrays and
-%% binaries for strings.
-binary_decode(S) ->
- mochijson2:decode(S).
-
-%% Internal API
-
-parse_encoder_options([], State) ->
- State;
-parse_encoder_options([{input_encoding, Encoding} | Rest], State) ->
- parse_encoder_options(Rest, State#encoder{input_encoding=Encoding});
-parse_encoder_options([{handler, Handler} | Rest], State) ->
- parse_encoder_options(Rest, State#encoder{handler=Handler}).
-
-parse_decoder_options([], State) ->
- State;
-parse_decoder_options([{input_encoding, Encoding} | Rest], State) ->
- parse_decoder_options(Rest, State#decoder{input_encoding=Encoding});
-parse_decoder_options([{object_hook, Hook} | Rest], State) ->
- parse_decoder_options(Rest, State#decoder{object_hook=Hook}).
-
-json_encode(true, _State) ->
- "true";
-json_encode(false, _State) ->
- "false";
-json_encode(null, _State) ->
- "null";
-json_encode(I, _State) when is_integer(I) ->
- integer_to_list(I);
-json_encode(F, _State) when is_float(F) ->
- mochinum:digits(F);
-json_encode(L, State) when is_list(L); is_binary(L); is_atom(L) ->
- json_encode_string(L, State);
-json_encode({array, Props}, State) when is_list(Props) ->
- json_encode_array(Props, State);
-json_encode({struct, Props}, State) when is_list(Props) ->
- json_encode_proplist(Props, State);
-json_encode(Bad, #encoder{handler=null}) ->
- exit({json_encode, {bad_term, Bad}});
-json_encode(Bad, State=#encoder{handler=Handler}) ->
- json_encode(Handler(Bad), State).
-
-json_encode_array([], _State) ->
- "[]";
-json_encode_array(L, State) ->
- F = fun (O, Acc) ->
- [$,, json_encode(O, State) | Acc]
- end,
- [$, | Acc1] = lists:foldl(F, "[", L),
- lists:reverse([$\] | Acc1]).
-
-json_encode_proplist([], _State) ->
- "{}";
-json_encode_proplist(Props, State) ->
- F = fun ({K, V}, Acc) ->
- KS = case K of
- K when is_atom(K) ->
- json_encode_string_utf8(atom_to_list(K));
- K when is_integer(K) ->
- json_encode_string(integer_to_list(K), State);
- K when is_list(K); is_binary(K) ->
- json_encode_string(K, State)
- end,
- VS = json_encode(V, State),
- [$,, VS, $:, KS | Acc]
- end,
- [$, | Acc1] = lists:foldl(F, "{", Props),
- lists:reverse([$\} | Acc1]).
-
-json_encode_string(A, _State) when is_atom(A) ->
- json_encode_string_unicode(xmerl_ucs:from_utf8(atom_to_list(A)));
-json_encode_string(B, _State) when is_binary(B) ->
- json_encode_string_unicode(xmerl_ucs:from_utf8(B));
-json_encode_string(S, #encoder{input_encoding=utf8}) ->
- json_encode_string_utf8(S);
-json_encode_string(S, #encoder{input_encoding=unicode}) ->
- json_encode_string_unicode(S).
-
-json_encode_string_utf8(S) ->
- [?Q | json_encode_string_utf8_1(S)].
-
-json_encode_string_utf8_1([C | Cs]) when C >= 0, C =< 16#7f ->
- NewC = case C of
- $\\ -> "\\\\";
- ?Q -> "\\\"";
- _ when C >= $\s, C < 16#7f -> C;
- $\t -> "\\t";
- $\n -> "\\n";
- $\r -> "\\r";
- $\f -> "\\f";
- $\b -> "\\b";
- _ when C >= 0, C =< 16#7f -> unihex(C);
- _ -> exit({json_encode, {bad_char, C}})
- end,
- [NewC | json_encode_string_utf8_1(Cs)];
-json_encode_string_utf8_1(All=[C | _]) when C >= 16#80, C =< 16#10FFFF ->
- [?Q | Rest] = json_encode_string_unicode(xmerl_ucs:from_utf8(All)),
- Rest;
-json_encode_string_utf8_1([]) ->
- "\"".
-
-json_encode_string_unicode(S) ->
- [?Q | json_encode_string_unicode_1(S)].
-
-json_encode_string_unicode_1([C | Cs]) ->
- NewC = case C of
- $\\ -> "\\\\";
- ?Q -> "\\\"";
- _ when C >= $\s, C < 16#7f -> C;
- $\t -> "\\t";
- $\n -> "\\n";
- $\r -> "\\r";
- $\f -> "\\f";
- $\b -> "\\b";
- _ when C >= 0, C =< 16#10FFFF -> unihex(C);
- _ -> exit({json_encode, {bad_char, C}})
- end,
- [NewC | json_encode_string_unicode_1(Cs)];
-json_encode_string_unicode_1([]) ->
- "\"".
-
-dehex(C) when C >= $0, C =< $9 ->
- C - $0;
-dehex(C) when C >= $a, C =< $f ->
- C - $a + 10;
-dehex(C) when C >= $A, C =< $F ->
- C - $A + 10.
-
-hexdigit(C) when C >= 0, C =< 9 ->
- C + $0;
-hexdigit(C) when C =< 15 ->
- C + $a - 10.
-
-unihex(C) when C < 16#10000 ->
- <<D3:4, D2:4, D1:4, D0:4>> = <<C:16>>,
- Digits = [hexdigit(D) || D <- [D3, D2, D1, D0]],
- [$\\, $u | Digits];
-unihex(C) when C =< 16#10FFFF ->
- N = C - 16#10000,
- S1 = 16#d800 bor ((N bsr 10) band 16#3ff),
- S2 = 16#dc00 bor (N band 16#3ff),
- [unihex(S1), unihex(S2)].
-
-json_decode(B, S) when is_binary(B) ->
- json_decode(binary_to_list(B), S);
-json_decode(L, S) ->
- {Res, L1, S1} = decode1(L, S),
- {eof, [], _} = tokenize(L1, S1#decoder{state=trim}),
- Res.
-
-decode1(L, S=#decoder{state=null}) ->
- case tokenize(L, S#decoder{state=any}) of
- {{const, C}, L1, S1} ->
- {C, L1, S1};
- {start_array, L1, S1} ->
- decode_array(L1, S1#decoder{state=any}, []);
- {start_object, L1, S1} ->
- decode_object(L1, S1#decoder{state=key}, [])
- end.
-
-make_object(V, #decoder{object_hook=null}) ->
- V;
-make_object(V, #decoder{object_hook=Hook}) ->
- Hook(V).
-
-decode_object(L, S=#decoder{state=key}, Acc) ->
- case tokenize(L, S) of
- {end_object, Rest, S1} ->
- V = make_object({struct, lists:reverse(Acc)}, S1),
- {V, Rest, S1#decoder{state=null}};
- {{const, K}, Rest, S1} when is_list(K) ->
- {colon, L2, S2} = tokenize(Rest, S1),
- {V, L3, S3} = decode1(L2, S2#decoder{state=null}),
- decode_object(L3, S3#decoder{state=comma}, [{K, V} | Acc])
- end;
-decode_object(L, S=#decoder{state=comma}, Acc) ->
- case tokenize(L, S) of
- {end_object, Rest, S1} ->
- V = make_object({struct, lists:reverse(Acc)}, S1),
- {V, Rest, S1#decoder{state=null}};
- {comma, Rest, S1} ->
- decode_object(Rest, S1#decoder{state=key}, Acc)
- end.
-
-decode_array(L, S=#decoder{state=any}, Acc) ->
- case tokenize(L, S) of
- {end_array, Rest, S1} ->
- {{array, lists:reverse(Acc)}, Rest, S1#decoder{state=null}};
- {start_array, Rest, S1} ->
- {Array, Rest1, S2} = decode_array(Rest, S1#decoder{state=any}, []),
- decode_array(Rest1, S2#decoder{state=comma}, [Array | Acc]);
- {start_object, Rest, S1} ->
- {Array, Rest1, S2} = decode_object(Rest, S1#decoder{state=key}, []),
- decode_array(Rest1, S2#decoder{state=comma}, [Array | Acc]);
- {{const, Const}, Rest, S1} ->
- decode_array(Rest, S1#decoder{state=comma}, [Const | Acc])
- end;
-decode_array(L, S=#decoder{state=comma}, Acc) ->
- case tokenize(L, S) of
- {end_array, Rest, S1} ->
- {{array, lists:reverse(Acc)}, Rest, S1#decoder{state=null}};
- {comma, Rest, S1} ->
- decode_array(Rest, S1#decoder{state=any}, Acc)
- end.
-
-tokenize_string(IoList=[C | _], S=#decoder{input_encoding=utf8}, Acc)
- when is_list(C); is_binary(C); C >= 16#7f ->
- List = xmerl_ucs:from_utf8(iolist_to_binary(IoList)),
- tokenize_string(List, S#decoder{input_encoding=unicode}, Acc);
-tokenize_string("\"" ++ Rest, S, Acc) ->
- {lists:reverse(Acc), Rest, ?INC_COL(S)};
-tokenize_string("\\\"" ++ Rest, S, Acc) ->
- tokenize_string(Rest, ?ADV_COL(S, 2), [$\" | Acc]);
-tokenize_string("\\\\" ++ Rest, S, Acc) ->
- tokenize_string(Rest, ?ADV_COL(S, 2), [$\\ | Acc]);
-tokenize_string("\\/" ++ Rest, S, Acc) ->
- tokenize_string(Rest, ?ADV_COL(S, 2), [$/ | Acc]);
-tokenize_string("\\b" ++ Rest, S, Acc) ->
- tokenize_string(Rest, ?ADV_COL(S, 2), [$\b | Acc]);
-tokenize_string("\\f" ++ Rest, S, Acc) ->
- tokenize_string(Rest, ?ADV_COL(S, 2), [$\f | Acc]);
-tokenize_string("\\n" ++ Rest, S, Acc) ->
- tokenize_string(Rest, ?ADV_COL(S, 2), [$\n | Acc]);
-tokenize_string("\\r" ++ Rest, S, Acc) ->
- tokenize_string(Rest, ?ADV_COL(S, 2), [$\r | Acc]);
-tokenize_string("\\t" ++ Rest, S, Acc) ->
- tokenize_string(Rest, ?ADV_COL(S, 2), [$\t | Acc]);
-tokenize_string([$\\, $u, C3, C2, C1, C0 | Rest], S, Acc) ->
- % coalesce UTF-16 surrogate pair?
- C = dehex(C0) bor
- (dehex(C1) bsl 4) bor
- (dehex(C2) bsl 8) bor
- (dehex(C3) bsl 12),
- tokenize_string(Rest, ?ADV_COL(S, 6), [C | Acc]);
-tokenize_string([C | Rest], S, Acc) when C >= $\s; C < 16#10FFFF ->
- tokenize_string(Rest, ?ADV_COL(S, 1), [C | Acc]).
-
-tokenize_number(IoList=[C | _], Mode, S=#decoder{input_encoding=utf8}, Acc)
- when is_list(C); is_binary(C); C >= 16#7f ->
- List = xmerl_ucs:from_utf8(iolist_to_binary(IoList)),
- tokenize_number(List, Mode, S#decoder{input_encoding=unicode}, Acc);
-tokenize_number([$- | Rest], sign, S, []) ->
- tokenize_number(Rest, int, ?INC_COL(S), [$-]);
-tokenize_number(Rest, sign, S, []) ->
- tokenize_number(Rest, int, S, []);
-tokenize_number([$0 | Rest], int, S, Acc) ->
- tokenize_number(Rest, frac, ?INC_COL(S), [$0 | Acc]);
-tokenize_number([C | Rest], int, S, Acc) when C >= $1, C =< $9 ->
- tokenize_number(Rest, int1, ?INC_COL(S), [C | Acc]);
-tokenize_number([C | Rest], int1, S, Acc) when C >= $0, C =< $9 ->
- tokenize_number(Rest, int1, ?INC_COL(S), [C | Acc]);
-tokenize_number(Rest, int1, S, Acc) ->
- tokenize_number(Rest, frac, S, Acc);
-tokenize_number([$., C | Rest], frac, S, Acc) when C >= $0, C =< $9 ->
- tokenize_number(Rest, frac1, ?ADV_COL(S, 2), [C, $. | Acc]);
-tokenize_number([E | Rest], frac, S, Acc) when E == $e; E == $E ->
- tokenize_number(Rest, esign, ?INC_COL(S), [$e, $0, $. | Acc]);
-tokenize_number(Rest, frac, S, Acc) ->
- {{int, lists:reverse(Acc)}, Rest, S};
-tokenize_number([C | Rest], frac1, S, Acc) when C >= $0, C =< $9 ->
- tokenize_number(Rest, frac1, ?INC_COL(S), [C | Acc]);
-tokenize_number([E | Rest], frac1, S, Acc) when E == $e; E == $E ->
- tokenize_number(Rest, esign, ?INC_COL(S), [$e | Acc]);
-tokenize_number(Rest, frac1, S, Acc) ->
- {{float, lists:reverse(Acc)}, Rest, S};
-tokenize_number([C | Rest], esign, S, Acc) when C == $-; C == $+ ->
- tokenize_number(Rest, eint, ?INC_COL(S), [C | Acc]);
-tokenize_number(Rest, esign, S, Acc) ->
- tokenize_number(Rest, eint, S, Acc);
-tokenize_number([C | Rest], eint, S, Acc) when C >= $0, C =< $9 ->
- tokenize_number(Rest, eint1, ?INC_COL(S), [C | Acc]);
-tokenize_number([C | Rest], eint1, S, Acc) when C >= $0, C =< $9 ->
- tokenize_number(Rest, eint1, ?INC_COL(S), [C | Acc]);
-tokenize_number(Rest, eint1, S, Acc) ->
- {{float, lists:reverse(Acc)}, Rest, S}.
-
-tokenize([], S=#decoder{state=trim}) ->
- {eof, [], S};
-tokenize([L | Rest], S) when is_list(L) ->
- tokenize(L ++ Rest, S);
-tokenize([B | Rest], S) when is_binary(B) ->
- tokenize(xmerl_ucs:from_utf8(B) ++ Rest, S);
-tokenize("\r\n" ++ Rest, S) ->
- tokenize(Rest, ?INC_LINE(S));
-tokenize("\n" ++ Rest, S) ->
- tokenize(Rest, ?INC_LINE(S));
-tokenize([C | Rest], S) when C == $\s; C == $\t ->
- tokenize(Rest, ?INC_COL(S));
-tokenize("{" ++ Rest, S) ->
- {start_object, Rest, ?INC_COL(S)};
-tokenize("}" ++ Rest, S) ->
- {end_object, Rest, ?INC_COL(S)};
-tokenize("[" ++ Rest, S) ->
- {start_array, Rest, ?INC_COL(S)};
-tokenize("]" ++ Rest, S) ->
- {end_array, Rest, ?INC_COL(S)};
-tokenize("," ++ Rest, S) ->
- {comma, Rest, ?INC_COL(S)};
-tokenize(":" ++ Rest, S) ->
- {colon, Rest, ?INC_COL(S)};
-tokenize("null" ++ Rest, S) ->
- {{const, null}, Rest, ?ADV_COL(S, 4)};
-tokenize("true" ++ Rest, S) ->
- {{const, true}, Rest, ?ADV_COL(S, 4)};
-tokenize("false" ++ Rest, S) ->
- {{const, false}, Rest, ?ADV_COL(S, 5)};
-tokenize("\"" ++ Rest, S) ->
- {String, Rest1, S1} = tokenize_string(Rest, ?INC_COL(S), []),
- {{const, String}, Rest1, S1};
-tokenize(L=[C | _], S) when C >= $0, C =< $9; C == $- ->
- case tokenize_number(L, sign, S, []) of
- {{int, Int}, Rest, S1} ->
- {{const, list_to_integer(Int)}, Rest, S1};
- {{float, Float}, Rest, S1} ->
- {{const, list_to_float(Float)}, Rest, S1}
- end.
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-%% testing constructs borrowed from the Yaws JSON implementation.
-
-%% Create an object from a list of Key/Value pairs.
-
-obj_new() ->
- {struct, []}.
-
-is_obj({struct, Props}) ->
- F = fun ({K, _}) when is_list(K) ->
- true;
- (_) ->
- false
- end,
- lists:all(F, Props).
-
-obj_from_list(Props) ->
- Obj = {struct, Props},
- case is_obj(Obj) of
- true -> Obj;
- false -> exit(json_bad_object)
- end.
-
-%% Test for equivalence of Erlang terms.
-%% Due to arbitrary order of construction, equivalent objects might
-%% compare unequal as erlang terms, so we need to carefully recurse
-%% through aggregates (tuples and objects).
-
-equiv({struct, Props1}, {struct, Props2}) ->
- equiv_object(Props1, Props2);
-equiv({array, L1}, {array, L2}) ->
- equiv_list(L1, L2);
-equiv(N1, N2) when is_number(N1), is_number(N2) -> N1 == N2;
-equiv(S1, S2) when is_list(S1), is_list(S2) -> S1 == S2;
-equiv(true, true) -> true;
-equiv(false, false) -> true;
-equiv(null, null) -> true.
-
-%% Object representation and traversal order is unknown.
-%% Use the sledgehammer and sort property lists.
-
-equiv_object(Props1, Props2) ->
- L1 = lists:keysort(1, Props1),
- L2 = lists:keysort(1, Props2),
- Pairs = lists:zip(L1, L2),
- true = lists:all(fun({{K1, V1}, {K2, V2}}) ->
- equiv(K1, K2) and equiv(V1, V2)
- end, Pairs).
-
-%% Recursively compare tuple elements for equivalence.
-
-equiv_list([], []) ->
- true;
-equiv_list([V1 | L1], [V2 | L2]) ->
- equiv(V1, V2) andalso equiv_list(L1, L2).
-
-e2j_vec_test() ->
- test_one(e2j_test_vec(utf8), 1).
-
-issue33_test() ->
- %% http://code.google.com/p/mochiweb/issues/detail?id=33
- Js = {struct, [{"key", [194, 163]}]},
- Encoder = encoder([{input_encoding, utf8}]),
- "{\"key\":\"\\u00a3\"}" = lists:flatten(Encoder(Js)).
-
-test_one([], _N) ->
- %% io:format("~p tests passed~n", [N-1]),
- ok;
-test_one([{E, J} | Rest], N) ->
- %% io:format("[~p] ~p ~p~n", [N, E, J]),
- true = equiv(E, decode(J)),
- true = equiv(E, decode(encode(E))),
- test_one(Rest, 1+N).
-
-e2j_test_vec(utf8) ->
- [
- {1, "1"},
- {3.1416, "3.14160"}, % text representation may truncate, trail zeroes
- {-1, "-1"},
- {-3.1416, "-3.14160"},
- {12.0e10, "1.20000e+11"},
- {1.234E+10, "1.23400e+10"},
- {-1.234E-10, "-1.23400e-10"},
- {10.0, "1.0e+01"},
- {123.456, "1.23456E+2"},
- {10.0, "1e1"},
- {"foo", "\"foo\""},
- {"foo" ++ [5] ++ "bar", "\"foo\\u0005bar\""},
- {"", "\"\""},
- {"\"", "\"\\\"\""},
- {"\n\n\n", "\"\\n\\n\\n\""},
- {"\\", "\"\\\\\""},
- {"\" \b\f\r\n\t\"", "\"\\\" \\b\\f\\r\\n\\t\\\"\""},
- {obj_new(), "{}"},
- {obj_from_list([{"foo", "bar"}]), "{\"foo\":\"bar\"}"},
- {obj_from_list([{"foo", "bar"}, {"baz", 123}]),
- "{\"foo\":\"bar\",\"baz\":123}"},
- {{array, []}, "[]"},
- {{array, [{array, []}]}, "[[]]"},
- {{array, [1, "foo"]}, "[1,\"foo\"]"},
-
- % json array in a json object
- {obj_from_list([{"foo", {array, [123]}}]),
- "{\"foo\":[123]}"},
-
- % json object in a json object
- {obj_from_list([{"foo", obj_from_list([{"bar", true}])}]),
- "{\"foo\":{\"bar\":true}}"},
-
- % fold evaluation order
- {obj_from_list([{"foo", {array, []}},
- {"bar", obj_from_list([{"baz", true}])},
- {"alice", "bob"}]),
- "{\"foo\":[],\"bar\":{\"baz\":true},\"alice\":\"bob\"}"},
-
- % json object in a json array
- {{array, [-123, "foo", obj_from_list([{"bar", {array, []}}]), null]},
- "[-123,\"foo\",{\"bar\":[]},null]"}
- ].
-
--endif.
diff --git a/src/mochiweb/mochijson2.erl b/src/mochiweb/mochijson2.erl
deleted file mode 100644
index 64cabc86..00000000
--- a/src/mochiweb/mochijson2.erl
+++ /dev/null
@@ -1,802 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2007 Mochi Media, Inc.
-
-%% @doc Yet another JSON (RFC 4627) library for Erlang. mochijson2 works
-%% with binaries as strings, arrays as lists (without an {array, _})
-%% wrapper and it only knows how to decode UTF-8 (and ASCII).
-
--module(mochijson2).
--author('bob@mochimedia.com').
--export([encoder/1, encode/1]).
--export([decoder/1, decode/1]).
-
-% This is a macro to placate syntax highlighters..
--define(Q, $\").
--define(ADV_COL(S, N), S#decoder{offset=N+S#decoder.offset,
- column=N+S#decoder.column}).
--define(INC_COL(S), S#decoder{offset=1+S#decoder.offset,
- column=1+S#decoder.column}).
--define(INC_LINE(S), S#decoder{offset=1+S#decoder.offset,
- column=1,
- line=1+S#decoder.line}).
--define(INC_CHAR(S, C),
- case C of
- $\n ->
- S#decoder{column=1,
- line=1+S#decoder.line,
- offset=1+S#decoder.offset};
- _ ->
- S#decoder{column=1+S#decoder.column,
- offset=1+S#decoder.offset}
- end).
--define(IS_WHITESPACE(C),
- (C =:= $\s orelse C =:= $\t orelse C =:= $\r orelse C =:= $\n)).
-
-%% @type iolist() = [char() | binary() | iolist()]
-%% @type iodata() = iolist() | binary()
-%% @type json_string() = atom | binary()
-%% @type json_number() = integer() | float()
-%% @type json_array() = [json_term()]
-%% @type json_object() = {struct, [{json_string(), json_term()}]}
-%% @type json_iolist() = {json, iolist()}
-%% @type json_term() = json_string() | json_number() | json_array() |
-%% json_object() | json_iolist()
-
--record(encoder, {handler=null,
- utf8=false}).
-
--record(decoder, {object_hook=null,
- offset=0,
- line=1,
- column=1,
- state=null}).
-
-%% @spec encoder([encoder_option()]) -> function()
-%% @doc Create an encoder/1 with the given options.
-%% @type encoder_option() = handler_option() | utf8_option()
-%% @type utf8_option() = boolean(). Emit unicode as utf8 (default - false)
-encoder(Options) ->
- State = parse_encoder_options(Options, #encoder{}),
- fun (O) -> json_encode(O, State) end.
-
-%% @spec encode(json_term()) -> iolist()
-%% @doc Encode the given as JSON to an iolist.
-encode(Any) ->
- json_encode(Any, #encoder{}).
-
-%% @spec decoder([decoder_option()]) -> function()
-%% @doc Create a decoder/1 with the given options.
-decoder(Options) ->
- State = parse_decoder_options(Options, #decoder{}),
- fun (O) -> json_decode(O, State) end.
-
-%% @spec decode(iolist()) -> json_term()
-%% @doc Decode the given iolist to Erlang terms.
-decode(S) ->
- json_decode(S, #decoder{}).
-
-%% Internal API
-
-parse_encoder_options([], State) ->
- State;
-parse_encoder_options([{handler, Handler} | Rest], State) ->
- parse_encoder_options(Rest, State#encoder{handler=Handler});
-parse_encoder_options([{utf8, Switch} | Rest], State) ->
- parse_encoder_options(Rest, State#encoder{utf8=Switch}).
-
-parse_decoder_options([], State) ->
- State;
-parse_decoder_options([{object_hook, Hook} | Rest], State) ->
- parse_decoder_options(Rest, State#decoder{object_hook=Hook}).
-
-json_encode(true, _State) ->
- <<"true">>;
-json_encode(false, _State) ->
- <<"false">>;
-json_encode(null, _State) ->
- <<"null">>;
-json_encode(I, _State) when is_integer(I) ->
- integer_to_list(I);
-json_encode(F, _State) when is_float(F) ->
- mochinum:digits(F);
-json_encode(S, State) when is_binary(S); is_atom(S) ->
- json_encode_string(S, State);
-json_encode(Array, State) when is_list(Array) ->
- json_encode_array(Array, State);
-json_encode({struct, Props}, State) when is_list(Props) ->
- json_encode_proplist(Props, State);
-json_encode({json, IoList}, _State) ->
- IoList;
-json_encode(Bad, #encoder{handler=null}) ->
- exit({json_encode, {bad_term, Bad}});
-json_encode(Bad, State=#encoder{handler=Handler}) ->
- json_encode(Handler(Bad), State).
-
-json_encode_array([], _State) ->
- <<"[]">>;
-json_encode_array(L, State) ->
- F = fun (O, Acc) ->
- [$,, json_encode(O, State) | Acc]
- end,
- [$, | Acc1] = lists:foldl(F, "[", L),
- lists:reverse([$\] | Acc1]).
-
-json_encode_proplist([], _State) ->
- <<"{}">>;
-json_encode_proplist(Props, State) ->
- F = fun ({K, V}, Acc) ->
- KS = json_encode_string(K, State),
- VS = json_encode(V, State),
- [$,, VS, $:, KS | Acc]
- end,
- [$, | Acc1] = lists:foldl(F, "{", Props),
- lists:reverse([$\} | Acc1]).
-
-json_encode_string(A, State) when is_atom(A) ->
- L = atom_to_list(A),
- case json_string_is_safe(L) of
- true ->
- [?Q, L, ?Q];
- false ->
- json_encode_string_unicode(xmerl_ucs:from_utf8(L), State, [?Q])
- end;
-json_encode_string(B, State) when is_binary(B) ->
- case json_bin_is_safe(B) of
- true ->
- [?Q, B, ?Q];
- false ->
- json_encode_string_unicode(xmerl_ucs:from_utf8(B), State, [?Q])
- end;
-json_encode_string(I, _State) when is_integer(I) ->
- [?Q, integer_to_list(I), ?Q];
-json_encode_string(L, State) when is_list(L) ->
- case json_string_is_safe(L) of
- true ->
- [?Q, L, ?Q];
- false ->
- json_encode_string_unicode(L, State, [?Q])
- end.
-
-json_string_is_safe([]) ->
- true;
-json_string_is_safe([C | Rest]) ->
- case C of
- ?Q ->
- false;
- $\\ ->
- false;
- $\b ->
- false;
- $\f ->
- false;
- $\n ->
- false;
- $\r ->
- false;
- $\t ->
- false;
- C when C >= 0, C < $\s; C >= 16#7f, C =< 16#10FFFF ->
- false;
- C when C < 16#7f ->
- json_string_is_safe(Rest);
- _ ->
- false
- end.
-
-json_bin_is_safe(<<>>) ->
- true;
-json_bin_is_safe(<<C, Rest/binary>>) ->
- case C of
- ?Q ->
- false;
- $\\ ->
- false;
- $\b ->
- false;
- $\f ->
- false;
- $\n ->
- false;
- $\r ->
- false;
- $\t ->
- false;
- C when C >= 0, C < $\s; C >= 16#7f ->
- false;
- C when C < 16#7f ->
- json_bin_is_safe(Rest)
- end.
-
-json_encode_string_unicode([], _State, Acc) ->
- lists:reverse([$\" | Acc]);
-json_encode_string_unicode([C | Cs], State, Acc) ->
- Acc1 = case C of
- ?Q ->
- [?Q, $\\ | Acc];
- %% Escaping solidus is only useful when trying to protect
- %% against "</script>" injection attacks which are only
- %% possible when JSON is inserted into a HTML document
- %% in-line. mochijson2 does not protect you from this, so
- %% if you do insert directly into HTML then you need to
- %% uncomment the following case or escape the output of encode.
- %%
- %% $/ ->
- %% [$/, $\\ | Acc];
- %%
- $\\ ->
- [$\\, $\\ | Acc];
- $\b ->
- [$b, $\\ | Acc];
- $\f ->
- [$f, $\\ | Acc];
- $\n ->
- [$n, $\\ | Acc];
- $\r ->
- [$r, $\\ | Acc];
- $\t ->
- [$t, $\\ | Acc];
- C when C >= 0, C < $\s ->
- [unihex(C) | Acc];
- C when C >= 16#7f, C =< 16#10FFFF, State#encoder.utf8 ->
- [xmerl_ucs:to_utf8(C) | Acc];
- C when C >= 16#7f, C =< 16#10FFFF, not State#encoder.utf8 ->
- [unihex(C) | Acc];
- C when C < 16#7f ->
- [C | Acc];
- _ ->
- exit({json_encode, {bad_char, C}})
- end,
- json_encode_string_unicode(Cs, State, Acc1).
-
-hexdigit(C) when C >= 0, C =< 9 ->
- C + $0;
-hexdigit(C) when C =< 15 ->
- C + $a - 10.
-
-unihex(C) when C < 16#10000 ->
- <<D3:4, D2:4, D1:4, D0:4>> = <<C:16>>,
- Digits = [hexdigit(D) || D <- [D3, D2, D1, D0]],
- [$\\, $u | Digits];
-unihex(C) when C =< 16#10FFFF ->
- N = C - 16#10000,
- S1 = 16#d800 bor ((N bsr 10) band 16#3ff),
- S2 = 16#dc00 bor (N band 16#3ff),
- [unihex(S1), unihex(S2)].
-
-json_decode(L, S) when is_list(L) ->
- json_decode(iolist_to_binary(L), S);
-json_decode(B, S) ->
- {Res, S1} = decode1(B, S),
- {eof, _} = tokenize(B, S1#decoder{state=trim}),
- Res.
-
-decode1(B, S=#decoder{state=null}) ->
- case tokenize(B, S#decoder{state=any}) of
- {{const, C}, S1} ->
- {C, S1};
- {start_array, S1} ->
- decode_array(B, S1);
- {start_object, S1} ->
- decode_object(B, S1)
- end.
-
-make_object(V, #decoder{object_hook=null}) ->
- V;
-make_object(V, #decoder{object_hook=Hook}) ->
- Hook(V).
-
-decode_object(B, S) ->
- decode_object(B, S#decoder{state=key}, []).
-
-decode_object(B, S=#decoder{state=key}, Acc) ->
- case tokenize(B, S) of
- {end_object, S1} ->
- V = make_object({struct, lists:reverse(Acc)}, S1),
- {V, S1#decoder{state=null}};
- {{const, K}, S1} ->
- {colon, S2} = tokenize(B, S1),
- {V, S3} = decode1(B, S2#decoder{state=null}),
- decode_object(B, S3#decoder{state=comma}, [{K, V} | Acc])
- end;
-decode_object(B, S=#decoder{state=comma}, Acc) ->
- case tokenize(B, S) of
- {end_object, S1} ->
- V = make_object({struct, lists:reverse(Acc)}, S1),
- {V, S1#decoder{state=null}};
- {comma, S1} ->
- decode_object(B, S1#decoder{state=key}, Acc)
- end.
-
-decode_array(B, S) ->
- decode_array(B, S#decoder{state=any}, []).
-
-decode_array(B, S=#decoder{state=any}, Acc) ->
- case tokenize(B, S) of
- {end_array, S1} ->
- {lists:reverse(Acc), S1#decoder{state=null}};
- {start_array, S1} ->
- {Array, S2} = decode_array(B, S1),
- decode_array(B, S2#decoder{state=comma}, [Array | Acc]);
- {start_object, S1} ->
- {Array, S2} = decode_object(B, S1),
- decode_array(B, S2#decoder{state=comma}, [Array | Acc]);
- {{const, Const}, S1} ->
- decode_array(B, S1#decoder{state=comma}, [Const | Acc])
- end;
-decode_array(B, S=#decoder{state=comma}, Acc) ->
- case tokenize(B, S) of
- {end_array, S1} ->
- {lists:reverse(Acc), S1#decoder{state=null}};
- {comma, S1} ->
- decode_array(B, S1#decoder{state=any}, Acc)
- end.
-
-tokenize_string(B, S=#decoder{offset=O}) ->
- case tokenize_string_fast(B, O) of
- {escape, O1} ->
- Length = O1 - O,
- S1 = ?ADV_COL(S, Length),
- <<_:O/binary, Head:Length/binary, _/binary>> = B,
- tokenize_string(B, S1, lists:reverse(binary_to_list(Head)));
- O1 ->
- Length = O1 - O,
- <<_:O/binary, String:Length/binary, ?Q, _/binary>> = B,
- {{const, String}, ?ADV_COL(S, Length + 1)}
- end.
-
-tokenize_string_fast(B, O) ->
- case B of
- <<_:O/binary, ?Q, _/binary>> ->
- O;
- <<_:O/binary, $\\, _/binary>> ->
- {escape, O};
- <<_:O/binary, C1, _/binary>> when C1 < 128 ->
- tokenize_string_fast(B, 1 + O);
- <<_:O/binary, C1, C2, _/binary>> when C1 >= 194, C1 =< 223,
- C2 >= 128, C2 =< 191 ->
- tokenize_string_fast(B, 2 + O);
- <<_:O/binary, C1, C2, C3, _/binary>> when C1 >= 224, C1 =< 239,
- C2 >= 128, C2 =< 191,
- C3 >= 128, C3 =< 191 ->
- tokenize_string_fast(B, 3 + O);
- <<_:O/binary, C1, C2, C3, C4, _/binary>> when C1 >= 240, C1 =< 244,
- C2 >= 128, C2 =< 191,
- C3 >= 128, C3 =< 191,
- C4 >= 128, C4 =< 191 ->
- tokenize_string_fast(B, 4 + O);
- _ ->
- throw(invalid_utf8)
- end.
-
-tokenize_string(B, S=#decoder{offset=O}, Acc) ->
- case B of
- <<_:O/binary, ?Q, _/binary>> ->
- {{const, iolist_to_binary(lists:reverse(Acc))}, ?INC_COL(S)};
- <<_:O/binary, "\\\"", _/binary>> ->
- tokenize_string(B, ?ADV_COL(S, 2), [$\" | Acc]);
- <<_:O/binary, "\\\\", _/binary>> ->
- tokenize_string(B, ?ADV_COL(S, 2), [$\\ | Acc]);
- <<_:O/binary, "\\/", _/binary>> ->
- tokenize_string(B, ?ADV_COL(S, 2), [$/ | Acc]);
- <<_:O/binary, "\\b", _/binary>> ->
- tokenize_string(B, ?ADV_COL(S, 2), [$\b | Acc]);
- <<_:O/binary, "\\f", _/binary>> ->
- tokenize_string(B, ?ADV_COL(S, 2), [$\f | Acc]);
- <<_:O/binary, "\\n", _/binary>> ->
- tokenize_string(B, ?ADV_COL(S, 2), [$\n | Acc]);
- <<_:O/binary, "\\r", _/binary>> ->
- tokenize_string(B, ?ADV_COL(S, 2), [$\r | Acc]);
- <<_:O/binary, "\\t", _/binary>> ->
- tokenize_string(B, ?ADV_COL(S, 2), [$\t | Acc]);
- <<_:O/binary, "\\u", C3, C2, C1, C0, Rest/binary>> ->
- C = erlang:list_to_integer([C3, C2, C1, C0], 16),
- if C > 16#D7FF, C < 16#DC00 ->
- %% coalesce UTF-16 surrogate pair
- <<"\\u", D3, D2, D1, D0, _/binary>> = Rest,
- D = erlang:list_to_integer([D3,D2,D1,D0], 16),
- [CodePoint] = xmerl_ucs:from_utf16be(<<C:16/big-unsigned-integer,
- D:16/big-unsigned-integer>>),
- Acc1 = lists:reverse(xmerl_ucs:to_utf8(CodePoint), Acc),
- tokenize_string(B, ?ADV_COL(S, 12), Acc1);
- true ->
- Acc1 = lists:reverse(xmerl_ucs:to_utf8(C), Acc),
- tokenize_string(B, ?ADV_COL(S, 6), Acc1)
- end;
- <<_:O/binary, C1, _/binary>> when C1 < 128 ->
- tokenize_string(B, ?INC_CHAR(S, C1), [C1 | Acc]);
- <<_:O/binary, C1, C2, _/binary>> when C1 >= 194, C1 =< 223,
- C2 >= 128, C2 =< 191 ->
- tokenize_string(B, ?ADV_COL(S, 2), [C2, C1 | Acc]);
- <<_:O/binary, C1, C2, C3, _/binary>> when C1 >= 224, C1 =< 239,
- C2 >= 128, C2 =< 191,
- C3 >= 128, C3 =< 191 ->
- tokenize_string(B, ?ADV_COL(S, 3), [C3, C2, C1 | Acc]);
- <<_:O/binary, C1, C2, C3, C4, _/binary>> when C1 >= 240, C1 =< 244,
- C2 >= 128, C2 =< 191,
- C3 >= 128, C3 =< 191,
- C4 >= 128, C4 =< 191 ->
- tokenize_string(B, ?ADV_COL(S, 4), [C4, C3, C2, C1 | Acc]);
- _ ->
- throw(invalid_utf8)
- end.
-
-tokenize_number(B, S) ->
- case tokenize_number(B, sign, S, []) of
- {{int, Int}, S1} ->
- {{const, list_to_integer(Int)}, S1};
- {{float, Float}, S1} ->
- {{const, list_to_float(Float)}, S1}
- end.
-
-tokenize_number(B, sign, S=#decoder{offset=O}, []) ->
- case B of
- <<_:O/binary, $-, _/binary>> ->
- tokenize_number(B, int, ?INC_COL(S), [$-]);
- _ ->
- tokenize_number(B, int, S, [])
- end;
-tokenize_number(B, int, S=#decoder{offset=O}, Acc) ->
- case B of
- <<_:O/binary, $0, _/binary>> ->
- tokenize_number(B, frac, ?INC_COL(S), [$0 | Acc]);
- <<_:O/binary, C, _/binary>> when C >= $1 andalso C =< $9 ->
- tokenize_number(B, int1, ?INC_COL(S), [C | Acc])
- end;
-tokenize_number(B, int1, S=#decoder{offset=O}, Acc) ->
- case B of
- <<_:O/binary, C, _/binary>> when C >= $0 andalso C =< $9 ->
- tokenize_number(B, int1, ?INC_COL(S), [C | Acc]);
- _ ->
- tokenize_number(B, frac, S, Acc)
- end;
-tokenize_number(B, frac, S=#decoder{offset=O}, Acc) ->
- case B of
- <<_:O/binary, $., C, _/binary>> when C >= $0, C =< $9 ->
- tokenize_number(B, frac1, ?ADV_COL(S, 2), [C, $. | Acc]);
- <<_:O/binary, E, _/binary>> when E =:= $e orelse E =:= $E ->
- tokenize_number(B, esign, ?INC_COL(S), [$e, $0, $. | Acc]);
- _ ->
- {{int, lists:reverse(Acc)}, S}
- end;
-tokenize_number(B, frac1, S=#decoder{offset=O}, Acc) ->
- case B of
- <<_:O/binary, C, _/binary>> when C >= $0 andalso C =< $9 ->
- tokenize_number(B, frac1, ?INC_COL(S), [C | Acc]);
- <<_:O/binary, E, _/binary>> when E =:= $e orelse E =:= $E ->
- tokenize_number(B, esign, ?INC_COL(S), [$e | Acc]);
- _ ->
- {{float, lists:reverse(Acc)}, S}
- end;
-tokenize_number(B, esign, S=#decoder{offset=O}, Acc) ->
- case B of
- <<_:O/binary, C, _/binary>> when C =:= $- orelse C=:= $+ ->
- tokenize_number(B, eint, ?INC_COL(S), [C | Acc]);
- _ ->
- tokenize_number(B, eint, S, Acc)
- end;
-tokenize_number(B, eint, S=#decoder{offset=O}, Acc) ->
- case B of
- <<_:O/binary, C, _/binary>> when C >= $0 andalso C =< $9 ->
- tokenize_number(B, eint1, ?INC_COL(S), [C | Acc])
- end;
-tokenize_number(B, eint1, S=#decoder{offset=O}, Acc) ->
- case B of
- <<_:O/binary, C, _/binary>> when C >= $0 andalso C =< $9 ->
- tokenize_number(B, eint1, ?INC_COL(S), [C | Acc]);
- _ ->
- {{float, lists:reverse(Acc)}, S}
- end.
-
-tokenize(B, S=#decoder{offset=O}) ->
- case B of
- <<_:O/binary, C, _/binary>> when ?IS_WHITESPACE(C) ->
- tokenize(B, ?INC_CHAR(S, C));
- <<_:O/binary, "{", _/binary>> ->
- {start_object, ?INC_COL(S)};
- <<_:O/binary, "}", _/binary>> ->
- {end_object, ?INC_COL(S)};
- <<_:O/binary, "[", _/binary>> ->
- {start_array, ?INC_COL(S)};
- <<_:O/binary, "]", _/binary>> ->
- {end_array, ?INC_COL(S)};
- <<_:O/binary, ",", _/binary>> ->
- {comma, ?INC_COL(S)};
- <<_:O/binary, ":", _/binary>> ->
- {colon, ?INC_COL(S)};
- <<_:O/binary, "null", _/binary>> ->
- {{const, null}, ?ADV_COL(S, 4)};
- <<_:O/binary, "true", _/binary>> ->
- {{const, true}, ?ADV_COL(S, 4)};
- <<_:O/binary, "false", _/binary>> ->
- {{const, false}, ?ADV_COL(S, 5)};
- <<_:O/binary, "\"", _/binary>> ->
- tokenize_string(B, ?INC_COL(S));
- <<_:O/binary, C, _/binary>> when (C >= $0 andalso C =< $9)
- orelse C =:= $- ->
- tokenize_number(B, S);
- <<_:O/binary>> ->
- trim = S#decoder.state,
- {eof, S}
- end.
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-
-%% testing constructs borrowed from the Yaws JSON implementation.
-
-%% Create an object from a list of Key/Value pairs.
-
-obj_new() ->
- {struct, []}.
-
-is_obj({struct, Props}) ->
- F = fun ({K, _}) when is_binary(K) -> true end,
- lists:all(F, Props).
-
-obj_from_list(Props) ->
- Obj = {struct, Props},
- ?assert(is_obj(Obj)),
- Obj.
-
-%% Test for equivalence of Erlang terms.
-%% Due to arbitrary order of construction, equivalent objects might
-%% compare unequal as erlang terms, so we need to carefully recurse
-%% through aggregates (tuples and objects).
-
-equiv({struct, Props1}, {struct, Props2}) ->
- equiv_object(Props1, Props2);
-equiv(L1, L2) when is_list(L1), is_list(L2) ->
- equiv_list(L1, L2);
-equiv(N1, N2) when is_number(N1), is_number(N2) -> N1 == N2;
-equiv(B1, B2) when is_binary(B1), is_binary(B2) -> B1 == B2;
-equiv(A, A) when A =:= true orelse A =:= false orelse A =:= null -> true.
-
-%% Object representation and traversal order is unknown.
-%% Use the sledgehammer and sort property lists.
-
-equiv_object(Props1, Props2) ->
- L1 = lists:keysort(1, Props1),
- L2 = lists:keysort(1, Props2),
- Pairs = lists:zip(L1, L2),
- true = lists:all(fun({{K1, V1}, {K2, V2}}) ->
- equiv(K1, K2) and equiv(V1, V2)
- end, Pairs).
-
-%% Recursively compare tuple elements for equivalence.
-
-equiv_list([], []) ->
- true;
-equiv_list([V1 | L1], [V2 | L2]) ->
- equiv(V1, V2) andalso equiv_list(L1, L2).
-
-decode_test() ->
- [1199344435545.0, 1] = decode(<<"[1199344435545.0,1]">>),
- <<16#F0,16#9D,16#9C,16#95>> = decode([34,"\\ud835","\\udf15",34]).
-
-e2j_vec_test() ->
- test_one(e2j_test_vec(utf8), 1).
-
-test_one([], _N) ->
- %% io:format("~p tests passed~n", [N-1]),
- ok;
-test_one([{E, J} | Rest], N) ->
- %% io:format("[~p] ~p ~p~n", [N, E, J]),
- true = equiv(E, decode(J)),
- true = equiv(E, decode(encode(E))),
- test_one(Rest, 1+N).
-
-e2j_test_vec(utf8) ->
- [
- {1, "1"},
- {3.1416, "3.14160"}, %% text representation may truncate, trail zeroes
- {-1, "-1"},
- {-3.1416, "-3.14160"},
- {12.0e10, "1.20000e+11"},
- {1.234E+10, "1.23400e+10"},
- {-1.234E-10, "-1.23400e-10"},
- {10.0, "1.0e+01"},
- {123.456, "1.23456E+2"},
- {10.0, "1e1"},
- {<<"foo">>, "\"foo\""},
- {<<"foo", 5, "bar">>, "\"foo\\u0005bar\""},
- {<<"">>, "\"\""},
- {<<"\n\n\n">>, "\"\\n\\n\\n\""},
- {<<"\" \b\f\r\n\t\"">>, "\"\\\" \\b\\f\\r\\n\\t\\\"\""},
- {obj_new(), "{}"},
- {obj_from_list([{<<"foo">>, <<"bar">>}]), "{\"foo\":\"bar\"}"},
- {obj_from_list([{<<"foo">>, <<"bar">>}, {<<"baz">>, 123}]),
- "{\"foo\":\"bar\",\"baz\":123}"},
- {[], "[]"},
- {[[]], "[[]]"},
- {[1, <<"foo">>], "[1,\"foo\"]"},
-
- %% json array in a json object
- {obj_from_list([{<<"foo">>, [123]}]),
- "{\"foo\":[123]}"},
-
- %% json object in a json object
- {obj_from_list([{<<"foo">>, obj_from_list([{<<"bar">>, true}])}]),
- "{\"foo\":{\"bar\":true}}"},
-
- %% fold evaluation order
- {obj_from_list([{<<"foo">>, []},
- {<<"bar">>, obj_from_list([{<<"baz">>, true}])},
- {<<"alice">>, <<"bob">>}]),
- "{\"foo\":[],\"bar\":{\"baz\":true},\"alice\":\"bob\"}"},
-
- %% json object in a json array
- {[-123, <<"foo">>, obj_from_list([{<<"bar">>, []}]), null],
- "[-123,\"foo\",{\"bar\":[]},null]"}
- ].
-
-%% test utf8 encoding
-encoder_utf8_test() ->
- %% safe conversion case (default)
- [34,"\\u0001","\\u0442","\\u0435","\\u0441","\\u0442",34] =
- encode(<<1,"\321\202\320\265\321\201\321\202">>),
-
- %% raw utf8 output (optional)
- Enc = mochijson2:encoder([{utf8, true}]),
- [34,"\\u0001",[209,130],[208,181],[209,129],[209,130],34] =
- Enc(<<1,"\321\202\320\265\321\201\321\202">>).
-
-input_validation_test() ->
- Good = [
- {16#00A3, <<?Q, 16#C2, 16#A3, ?Q>>}, %% pound
- {16#20AC, <<?Q, 16#E2, 16#82, 16#AC, ?Q>>}, %% euro
- {16#10196, <<?Q, 16#F0, 16#90, 16#86, 16#96, ?Q>>} %% denarius
- ],
- lists:foreach(fun({CodePoint, UTF8}) ->
- Expect = list_to_binary(xmerl_ucs:to_utf8(CodePoint)),
- Expect = decode(UTF8)
- end, Good),
-
- Bad = [
- %% 2nd, 3rd, or 4th byte of a multi-byte sequence w/o leading byte
- <<?Q, 16#80, ?Q>>,
- %% missing continuations, last byte in each should be 80-BF
- <<?Q, 16#C2, 16#7F, ?Q>>,
- <<?Q, 16#E0, 16#80,16#7F, ?Q>>,
- <<?Q, 16#F0, 16#80, 16#80, 16#7F, ?Q>>,
- %% we don't support code points > 10FFFF per RFC 3629
- <<?Q, 16#F5, 16#80, 16#80, 16#80, ?Q>>,
- %% escape characters trigger a different code path
- <<?Q, $\\, $\n, 16#80, ?Q>>
- ],
- lists:foreach(
- fun(X) ->
- ok = try decode(X) catch invalid_utf8 -> ok end,
- %% could be {ucs,{bad_utf8_character_code}} or
- %% {json_encode,{bad_char,_}}
- {'EXIT', _} = (catch encode(X))
- end, Bad).
-
-inline_json_test() ->
- ?assertEqual(<<"\"iodata iodata\"">>,
- iolist_to_binary(
- encode({json, [<<"\"iodata">>, " iodata\""]}))),
- ?assertEqual({struct, [{<<"key">>, <<"iodata iodata">>}]},
- decode(
- encode({struct,
- [{key, {json, [<<"\"iodata">>, " iodata\""]}}]}))),
- ok.
-
-big_unicode_test() ->
- UTF8Seq = list_to_binary(xmerl_ucs:to_utf8(16#0001d120)),
- ?assertEqual(
- <<"\"\\ud834\\udd20\"">>,
- iolist_to_binary(encode(UTF8Seq))),
- ?assertEqual(
- UTF8Seq,
- decode(iolist_to_binary(encode(UTF8Seq)))),
- ok.
-
-custom_decoder_test() ->
- ?assertEqual(
- {struct, [{<<"key">>, <<"value">>}]},
- (decoder([]))("{\"key\": \"value\"}")),
- F = fun ({struct, [{<<"key">>, <<"value">>}]}) -> win end,
- ?assertEqual(
- win,
- (decoder([{object_hook, F}]))("{\"key\": \"value\"}")),
- ok.
-
-atom_test() ->
- %% JSON native atoms
- [begin
- ?assertEqual(A, decode(atom_to_list(A))),
- ?assertEqual(iolist_to_binary(atom_to_list(A)),
- iolist_to_binary(encode(A)))
- end || A <- [true, false, null]],
- %% Atom to string
- ?assertEqual(
- <<"\"foo\"">>,
- iolist_to_binary(encode(foo))),
- ?assertEqual(
- <<"\"\\ud834\\udd20\"">>,
- iolist_to_binary(encode(list_to_atom(xmerl_ucs:to_utf8(16#0001d120))))),
- ok.
-
-key_encode_test() ->
- %% Some forms are accepted as keys that would not be strings in other
- %% cases
- ?assertEqual(
- <<"{\"foo\":1}">>,
- iolist_to_binary(encode({struct, [{foo, 1}]}))),
- ?assertEqual(
- <<"{\"foo\":1}">>,
- iolist_to_binary(encode({struct, [{<<"foo">>, 1}]}))),
- ?assertEqual(
- <<"{\"foo\":1}">>,
- iolist_to_binary(encode({struct, [{"foo", 1}]}))),
- ?assertEqual(
- <<"{\"\\ud834\\udd20\":1}">>,
- iolist_to_binary(
- encode({struct, [{[16#0001d120], 1}]}))),
- ?assertEqual(
- <<"{\"1\":1}">>,
- iolist_to_binary(encode({struct, [{1, 1}]}))),
- ok.
-
-unsafe_chars_test() ->
- Chars = "\"\\\b\f\n\r\t",
- [begin
- ?assertEqual(false, json_string_is_safe([C])),
- ?assertEqual(false, json_bin_is_safe(<<C>>)),
- ?assertEqual(<<C>>, decode(encode(<<C>>)))
- end || C <- Chars],
- ?assertEqual(
- false,
- json_string_is_safe([16#0001d120])),
- ?assertEqual(
- false,
- json_bin_is_safe(list_to_binary(xmerl_ucs:to_utf8(16#0001d120)))),
- ?assertEqual(
- [16#0001d120],
- xmerl_ucs:from_utf8(
- binary_to_list(
- decode(encode(list_to_atom(xmerl_ucs:to_utf8(16#0001d120))))))),
- ?assertEqual(
- false,
- json_string_is_safe([16#110000])),
- ?assertEqual(
- false,
- json_bin_is_safe(list_to_binary(xmerl_ucs:to_utf8([16#110000])))),
- %% solidus can be escaped but isn't unsafe by default
- ?assertEqual(
- <<"/">>,
- decode(<<"\"\\/\"">>)),
- ok.
-
-int_test() ->
- ?assertEqual(0, decode("0")),
- ?assertEqual(1, decode("1")),
- ?assertEqual(11, decode("11")),
- ok.
-
-large_int_test() ->
- ?assertEqual(<<"-2147483649214748364921474836492147483649">>,
- iolist_to_binary(encode(-2147483649214748364921474836492147483649))),
- ?assertEqual(<<"2147483649214748364921474836492147483649">>,
- iolist_to_binary(encode(2147483649214748364921474836492147483649))),
- ok.
-
-float_test() ->
- ?assertEqual(<<"-2147483649.0">>, iolist_to_binary(encode(-2147483649.0))),
- ?assertEqual(<<"2147483648.0">>, iolist_to_binary(encode(2147483648.0))),
- ok.
-
-handler_test() ->
- ?assertEqual(
- {'EXIT',{json_encode,{bad_term,{}}}},
- catch encode({})),
- F = fun ({}) -> [] end,
- ?assertEqual(
- <<"[]">>,
- iolist_to_binary((encoder([{handler, F}]))({}))),
- ok.
-
--endif.
diff --git a/src/mochiweb/mochilists.erl b/src/mochiweb/mochilists.erl
deleted file mode 100644
index 8981e7b6..00000000
--- a/src/mochiweb/mochilists.erl
+++ /dev/null
@@ -1,104 +0,0 @@
-%% @copyright Copyright (c) 2010 Mochi Media, Inc.
-%% @author David Reid <dreid@mochimedia.com>
-
-%% @doc Utility functions for dealing with proplists.
-
--module(mochilists).
--author("David Reid <dreid@mochimedia.com>").
--export([get_value/2, get_value/3, is_defined/2, set_default/2, set_defaults/2]).
-
-%% @spec set_default({Key::term(), Value::term()}, Proplist::list()) -> list()
-%%
-%% @doc Return new Proplist with {Key, Value} set if not is_defined(Key, Proplist).
-set_default({Key, Value}, Proplist) ->
- case is_defined(Key, Proplist) of
- true ->
- Proplist;
- false ->
- [{Key, Value} | Proplist]
- end.
-
-%% @spec set_defaults([{Key::term(), Value::term()}], Proplist::list()) -> list()
-%%
-%% @doc Return new Proplist with {Key, Value} set if not is_defined(Key, Proplist).
-set_defaults(DefaultProps, Proplist) ->
- lists:foldl(fun set_default/2, Proplist, DefaultProps).
-
-
-%% @spec is_defined(Key::term(), Proplist::list()) -> bool()
-%%
-%% @doc Returns true if Propist contains at least one entry associated
-%% with Key, otherwise false is returned.
-is_defined(Key, Proplist) ->
- lists:keyfind(Key, 1, Proplist) =/= false.
-
-
-%% @spec get_value(Key::term(), Proplist::list()) -> term() | undefined
-%%
-%% @doc Return the value of <code>Key</code> or undefined
-get_value(Key, Proplist) ->
- get_value(Key, Proplist, undefined).
-
-%% @spec get_value(Key::term(), Proplist::list(), Default::term()) -> term()
-%%
-%% @doc Return the value of <code>Key</code> or <code>Default</code>
-get_value(_Key, [], Default) ->
- Default;
-get_value(Key, Proplist, Default) ->
- case lists:keyfind(Key, 1, Proplist) of
- false ->
- Default;
- {Key, Value} ->
- Value
- end.
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-set_defaults_test() ->
- ?assertEqual(
- [{k, v}],
- set_defaults([{k, v}], [])),
- ?assertEqual(
- [{k, v}],
- set_defaults([{k, vee}], [{k, v}])),
- ?assertEqual(
- lists:sort([{kay, vee}, {k, v}]),
- lists:sort(set_defaults([{k, vee}, {kay, vee}], [{k, v}]))),
- ok.
-
-set_default_test() ->
- ?assertEqual(
- [{k, v}],
- set_default({k, v}, [])),
- ?assertEqual(
- [{k, v}],
- set_default({k, vee}, [{k, v}])),
- ok.
-
-get_value_test() ->
- ?assertEqual(
- undefined,
- get_value(foo, [])),
- ?assertEqual(
- undefined,
- get_value(foo, [{bar, baz}])),
- ?assertEqual(
- bar,
- get_value(foo, [{foo, bar}])),
- ?assertEqual(
- default,
- get_value(foo, [], default)),
- ?assertEqual(
- default,
- get_value(foo, [{bar, baz}], default)),
- ?assertEqual(
- bar,
- get_value(foo, [{foo, bar}], default)),
- ok.
-
--endif.
-
diff --git a/src/mochiweb/mochilogfile2.erl b/src/mochiweb/mochilogfile2.erl
deleted file mode 100644
index c34ee73a..00000000
--- a/src/mochiweb/mochilogfile2.erl
+++ /dev/null
@@ -1,140 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2010 Mochi Media, Inc.
-
-%% @doc Write newline delimited log files, ensuring that if a truncated
-%% entry is found on log open then it is fixed before writing. Uses
-%% delayed writes and raw files for performance.
--module(mochilogfile2).
--author('bob@mochimedia.com').
-
--export([open/1, write/2, close/1, name/1]).
-
-%% @spec open(Name) -> Handle
-%% @doc Open the log file Name, creating or appending as necessary. All data
-%% at the end of the file will be truncated until a newline is found, to
-%% ensure that all records are complete.
-open(Name) ->
- {ok, FD} = file:open(Name, [raw, read, write, delayed_write, binary]),
- fix_log(FD),
- {?MODULE, Name, FD}.
-
-%% @spec name(Handle) -> string()
-%% @doc Return the path of the log file.
-name({?MODULE, Name, _FD}) ->
- Name.
-
-%% @spec write(Handle, IoData) -> ok
-%% @doc Write IoData to the log file referenced by Handle.
-write({?MODULE, _Name, FD}, IoData) ->
- ok = file:write(FD, [IoData, $\n]),
- ok.
-
-%% @spec close(Handle) -> ok
-%% @doc Close the log file referenced by Handle.
-close({?MODULE, _Name, FD}) ->
- ok = file:sync(FD),
- ok = file:close(FD),
- ok.
-
-fix_log(FD) ->
- {ok, Location} = file:position(FD, eof),
- Seek = find_last_newline(FD, Location),
- {ok, Seek} = file:position(FD, Seek),
- ok = file:truncate(FD),
- ok.
-
-%% Seek backwards to the last valid log entry
-find_last_newline(_FD, N) when N =< 1 ->
- 0;
-find_last_newline(FD, Location) ->
- case file:pread(FD, Location - 1, 1) of
- {ok, <<$\n>>} ->
- Location;
- {ok, _} ->
- find_last_newline(FD, Location - 1)
- end.
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-name_test() ->
- D = mochitemp:mkdtemp(),
- FileName = filename:join(D, "open_close_test.log"),
- H = open(FileName),
- ?assertEqual(
- FileName,
- name(H)),
- close(H),
- file:delete(FileName),
- file:del_dir(D),
- ok.
-
-open_close_test() ->
- D = mochitemp:mkdtemp(),
- FileName = filename:join(D, "open_close_test.log"),
- OpenClose = fun () ->
- H = open(FileName),
- ?assertEqual(
- true,
- filelib:is_file(FileName)),
- ok = close(H),
- ?assertEqual(
- {ok, <<>>},
- file:read_file(FileName)),
- ok
- end,
- OpenClose(),
- OpenClose(),
- file:delete(FileName),
- file:del_dir(D),
- ok.
-
-write_test() ->
- D = mochitemp:mkdtemp(),
- FileName = filename:join(D, "write_test.log"),
- F = fun () ->
- H = open(FileName),
- write(H, "test line"),
- close(H),
- ok
- end,
- F(),
- ?assertEqual(
- {ok, <<"test line\n">>},
- file:read_file(FileName)),
- F(),
- ?assertEqual(
- {ok, <<"test line\ntest line\n">>},
- file:read_file(FileName)),
- file:delete(FileName),
- file:del_dir(D),
- ok.
-
-fix_log_test() ->
- D = mochitemp:mkdtemp(),
- FileName = filename:join(D, "write_test.log"),
- file:write_file(FileName, <<"first line good\nsecond line bad">>),
- F = fun () ->
- H = open(FileName),
- write(H, "test line"),
- close(H),
- ok
- end,
- F(),
- ?assertEqual(
- {ok, <<"first line good\ntest line\n">>},
- file:read_file(FileName)),
- file:write_file(FileName, <<"first line bad">>),
- F(),
- ?assertEqual(
- {ok, <<"test line\n">>},
- file:read_file(FileName)),
- F(),
- ?assertEqual(
- {ok, <<"test line\ntest line\n">>},
- file:read_file(FileName)),
- ok.
-
--endif.
diff --git a/src/mochiweb/mochinum.erl b/src/mochiweb/mochinum.erl
deleted file mode 100644
index a7e2bfbc..00000000
--- a/src/mochiweb/mochinum.erl
+++ /dev/null
@@ -1,331 +0,0 @@
-%% @copyright 2007 Mochi Media, Inc.
-%% @author Bob Ippolito <bob@mochimedia.com>
-
-%% @doc Useful numeric algorithms for floats that cover some deficiencies
-%% in the math module. More interesting is digits/1, which implements
-%% the algorithm from:
-%% http://www.cs.indiana.edu/~burger/fp/index.html
-%% See also "Printing Floating-Point Numbers Quickly and Accurately"
-%% in Proceedings of the SIGPLAN '96 Conference on Programming Language
-%% Design and Implementation.
-
--module(mochinum).
--author("Bob Ippolito <bob@mochimedia.com>").
--export([digits/1, frexp/1, int_pow/2, int_ceil/1]).
-
-%% IEEE 754 Float exponent bias
--define(FLOAT_BIAS, 1022).
--define(MIN_EXP, -1074).
--define(BIG_POW, 4503599627370496).
-
-%% External API
-
-%% @spec digits(number()) -> string()
-%% @doc Returns a string that accurately represents the given integer or float
-%% using a conservative amount of digits. Great for generating
-%% human-readable output, or compact ASCII serializations for floats.
-digits(N) when is_integer(N) ->
- integer_to_list(N);
-digits(0.0) ->
- "0.0";
-digits(Float) ->
- {Frac, Exp} = frexp(Float),
- Exp1 = Exp - 53,
- Frac1 = trunc(abs(Frac) * (1 bsl 53)),
- [Place | Digits] = digits1(Float, Exp1, Frac1),
- R = insert_decimal(Place, [$0 + D || D <- Digits]),
- case Float < 0 of
- true ->
- [$- | R];
- _ ->
- R
- end.
-
-%% @spec frexp(F::float()) -> {Frac::float(), Exp::float()}
-%% @doc Return the fractional and exponent part of an IEEE 754 double,
-%% equivalent to the libc function of the same name.
-%% F = Frac * pow(2, Exp).
-frexp(F) ->
- frexp1(unpack(F)).
-
-%% @spec int_pow(X::integer(), N::integer()) -> Y::integer()
-%% @doc Moderately efficient way to exponentiate integers.
-%% int_pow(10, 2) = 100.
-int_pow(_X, 0) ->
- 1;
-int_pow(X, N) when N > 0 ->
- int_pow(X, N, 1).
-
-%% @spec int_ceil(F::float()) -> integer()
-%% @doc Return the ceiling of F as an integer. The ceiling is defined as
-%% F when F == trunc(F);
-%% trunc(F) when F &lt; 0;
-%% trunc(F) + 1 when F &gt; 0.
-int_ceil(X) ->
- T = trunc(X),
- case (X - T) of
- Neg when Neg < 0 -> T;
- Pos when Pos > 0 -> T + 1;
- _ -> T
- end.
-
-
-%% Internal API
-
-int_pow(X, N, R) when N < 2 ->
- R * X;
-int_pow(X, N, R) ->
- int_pow(X * X, N bsr 1, case N band 1 of 1 -> R * X; 0 -> R end).
-
-insert_decimal(0, S) ->
- "0." ++ S;
-insert_decimal(Place, S) when Place > 0 ->
- L = length(S),
- case Place - L of
- 0 ->
- S ++ ".0";
- N when N < 0 ->
- {S0, S1} = lists:split(L + N, S),
- S0 ++ "." ++ S1;
- N when N < 6 ->
- %% More places than digits
- S ++ lists:duplicate(N, $0) ++ ".0";
- _ ->
- insert_decimal_exp(Place, S)
- end;
-insert_decimal(Place, S) when Place > -6 ->
- "0." ++ lists:duplicate(abs(Place), $0) ++ S;
-insert_decimal(Place, S) ->
- insert_decimal_exp(Place, S).
-
-insert_decimal_exp(Place, S) ->
- [C | S0] = S,
- S1 = case S0 of
- [] ->
- "0";
- _ ->
- S0
- end,
- Exp = case Place < 0 of
- true ->
- "e-";
- false ->
- "e+"
- end,
- [C] ++ "." ++ S1 ++ Exp ++ integer_to_list(abs(Place - 1)).
-
-
-digits1(Float, Exp, Frac) ->
- Round = ((Frac band 1) =:= 0),
- case Exp >= 0 of
- true ->
- BExp = 1 bsl Exp,
- case (Frac =/= ?BIG_POW) of
- true ->
- scale((Frac * BExp * 2), 2, BExp, BExp,
- Round, Round, Float);
- false ->
- scale((Frac * BExp * 4), 4, (BExp * 2), BExp,
- Round, Round, Float)
- end;
- false ->
- case (Exp =:= ?MIN_EXP) orelse (Frac =/= ?BIG_POW) of
- true ->
- scale((Frac * 2), 1 bsl (1 - Exp), 1, 1,
- Round, Round, Float);
- false ->
- scale((Frac * 4), 1 bsl (2 - Exp), 2, 1,
- Round, Round, Float)
- end
- end.
-
-scale(R, S, MPlus, MMinus, LowOk, HighOk, Float) ->
- Est = int_ceil(math:log10(abs(Float)) - 1.0e-10),
- %% Note that the scheme implementation uses a 326 element look-up table
- %% for int_pow(10, N) where we do not.
- case Est >= 0 of
- true ->
- fixup(R, S * int_pow(10, Est), MPlus, MMinus, Est,
- LowOk, HighOk);
- false ->
- Scale = int_pow(10, -Est),
- fixup(R * Scale, S, MPlus * Scale, MMinus * Scale, Est,
- LowOk, HighOk)
- end.
-
-fixup(R, S, MPlus, MMinus, K, LowOk, HighOk) ->
- TooLow = case HighOk of
- true ->
- (R + MPlus) >= S;
- false ->
- (R + MPlus) > S
- end,
- case TooLow of
- true ->
- [(K + 1) | generate(R, S, MPlus, MMinus, LowOk, HighOk)];
- false ->
- [K | generate(R * 10, S, MPlus * 10, MMinus * 10, LowOk, HighOk)]
- end.
-
-generate(R0, S, MPlus, MMinus, LowOk, HighOk) ->
- D = R0 div S,
- R = R0 rem S,
- TC1 = case LowOk of
- true ->
- R =< MMinus;
- false ->
- R < MMinus
- end,
- TC2 = case HighOk of
- true ->
- (R + MPlus) >= S;
- false ->
- (R + MPlus) > S
- end,
- case TC1 of
- false ->
- case TC2 of
- false ->
- [D | generate(R * 10, S, MPlus * 10, MMinus * 10,
- LowOk, HighOk)];
- true ->
- [D + 1]
- end;
- true ->
- case TC2 of
- false ->
- [D];
- true ->
- case R * 2 < S of
- true ->
- [D];
- false ->
- [D + 1]
- end
- end
- end.
-
-unpack(Float) ->
- <<Sign:1, Exp:11, Frac:52>> = <<Float:64/float>>,
- {Sign, Exp, Frac}.
-
-frexp1({_Sign, 0, 0}) ->
- {0.0, 0};
-frexp1({Sign, 0, Frac}) ->
- Exp = log2floor(Frac),
- <<Frac1:64/float>> = <<Sign:1, ?FLOAT_BIAS:11, (Frac-1):52>>,
- {Frac1, -(?FLOAT_BIAS) - 52 + Exp};
-frexp1({Sign, Exp, Frac}) ->
- <<Frac1:64/float>> = <<Sign:1, ?FLOAT_BIAS:11, Frac:52>>,
- {Frac1, Exp - ?FLOAT_BIAS}.
-
-log2floor(Int) ->
- log2floor(Int, 0).
-
-log2floor(0, N) ->
- N;
-log2floor(Int, N) ->
- log2floor(Int bsr 1, 1 + N).
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-int_ceil_test() ->
- 1 = int_ceil(0.0001),
- 0 = int_ceil(0.0),
- 1 = int_ceil(0.99),
- 1 = int_ceil(1.0),
- -1 = int_ceil(-1.5),
- -2 = int_ceil(-2.0),
- ok.
-
-int_pow_test() ->
- 1 = int_pow(1, 1),
- 1 = int_pow(1, 0),
- 1 = int_pow(10, 0),
- 10 = int_pow(10, 1),
- 100 = int_pow(10, 2),
- 1000 = int_pow(10, 3),
- ok.
-
-digits_test() ->
- ?assertEqual("0",
- digits(0)),
- ?assertEqual("0.0",
- digits(0.0)),
- ?assertEqual("1.0",
- digits(1.0)),
- ?assertEqual("-1.0",
- digits(-1.0)),
- ?assertEqual("0.1",
- digits(0.1)),
- ?assertEqual("0.01",
- digits(0.01)),
- ?assertEqual("0.001",
- digits(0.001)),
- ?assertEqual("1.0e+6",
- digits(1000000.0)),
- ?assertEqual("0.5",
- digits(0.5)),
- ?assertEqual("4503599627370496.0",
- digits(4503599627370496.0)),
- %% small denormalized number
- %% 4.94065645841246544177e-324
- <<SmallDenorm/float>> = <<0,0,0,0,0,0,0,1>>,
- ?assertEqual("4.9406564584124654e-324",
- digits(SmallDenorm)),
- ?assertEqual(SmallDenorm,
- list_to_float(digits(SmallDenorm))),
- %% large denormalized number
- %% 2.22507385850720088902e-308
- <<BigDenorm/float>> = <<0,15,255,255,255,255,255,255>>,
- ?assertEqual("2.225073858507201e-308",
- digits(BigDenorm)),
- ?assertEqual(BigDenorm,
- list_to_float(digits(BigDenorm))),
- %% small normalized number
- %% 2.22507385850720138309e-308
- <<SmallNorm/float>> = <<0,16,0,0,0,0,0,0>>,
- ?assertEqual("2.2250738585072014e-308",
- digits(SmallNorm)),
- ?assertEqual(SmallNorm,
- list_to_float(digits(SmallNorm))),
- %% large normalized number
- %% 1.79769313486231570815e+308
- <<LargeNorm/float>> = <<127,239,255,255,255,255,255,255>>,
- ?assertEqual("1.7976931348623157e+308",
- digits(LargeNorm)),
- ?assertEqual(LargeNorm,
- list_to_float(digits(LargeNorm))),
- ok.
-
-frexp_test() ->
- %% zero
- {0.0, 0} = frexp(0.0),
- %% one
- {0.5, 1} = frexp(1.0),
- %% negative one
- {-0.5, 1} = frexp(-1.0),
- %% small denormalized number
- %% 4.94065645841246544177e-324
- <<SmallDenorm/float>> = <<0,0,0,0,0,0,0,1>>,
- {0.5, -1073} = frexp(SmallDenorm),
- %% large denormalized number
- %% 2.22507385850720088902e-308
- <<BigDenorm/float>> = <<0,15,255,255,255,255,255,255>>,
- {0.99999999999999978, -1022} = frexp(BigDenorm),
- %% small normalized number
- %% 2.22507385850720138309e-308
- <<SmallNorm/float>> = <<0,16,0,0,0,0,0,0>>,
- {0.5, -1021} = frexp(SmallNorm),
- %% large normalized number
- %% 1.79769313486231570815e+308
- <<LargeNorm/float>> = <<127,239,255,255,255,255,255,255>>,
- {0.99999999999999989, 1024} = frexp(LargeNorm),
- ok.
-
--endif.
diff --git a/src/mochiweb/mochitemp.erl b/src/mochiweb/mochitemp.erl
deleted file mode 100644
index bb23d2a6..00000000
--- a/src/mochiweb/mochitemp.erl
+++ /dev/null
@@ -1,310 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2010 Mochi Media, Inc.
-
-%% @doc Create temporary files and directories. Requires crypto to be started.
-
--module(mochitemp).
--export([gettempdir/0]).
--export([mkdtemp/0, mkdtemp/3]).
--export([rmtempdir/1]).
-%% -export([mkstemp/4]).
--define(SAFE_CHARS, {$a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k, $l, $m,
- $n, $o, $p, $q, $r, $s, $t, $u, $v, $w, $x, $y, $z,
- $A, $B, $C, $D, $E, $F, $G, $H, $I, $J, $K, $L, $M,
- $N, $O, $P, $Q, $R, $S, $T, $U, $V, $W, $X, $Y, $Z,
- $0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $_}).
--define(TMP_MAX, 10000).
-
--include_lib("kernel/include/file.hrl").
-
-%% TODO: An ugly wrapper over the mktemp tool with open_port and sadness?
-%% We can't implement this race-free in Erlang without the ability
-%% to issue O_CREAT|O_EXCL. I suppose we could hack something with
-%% mkdtemp, del_dir, open.
-%% mkstemp(Suffix, Prefix, Dir, Options) ->
-%% ok.
-
-rmtempdir(Dir) ->
- case file:del_dir(Dir) of
- {error, eexist} ->
- ok = rmtempdirfiles(Dir),
- ok = file:del_dir(Dir);
- ok ->
- ok
- end.
-
-rmtempdirfiles(Dir) ->
- {ok, Files} = file:list_dir(Dir),
- ok = rmtempdirfiles(Dir, Files).
-
-rmtempdirfiles(_Dir, []) ->
- ok;
-rmtempdirfiles(Dir, [Basename | Rest]) ->
- Path = filename:join([Dir, Basename]),
- case filelib:is_dir(Path) of
- true ->
- ok = rmtempdir(Path);
- false ->
- ok = file:delete(Path)
- end,
- rmtempdirfiles(Dir, Rest).
-
-mkdtemp() ->
- mkdtemp("", "tmp", gettempdir()).
-
-mkdtemp(Suffix, Prefix, Dir) ->
- mkdtemp_n(rngpath_fun(Suffix, Prefix, Dir), ?TMP_MAX).
-
-
-
-mkdtemp_n(RngPath, 1) ->
- make_dir(RngPath());
-mkdtemp_n(RngPath, N) ->
- try make_dir(RngPath())
- catch throw:{error, eexist} ->
- mkdtemp_n(RngPath, N - 1)
- end.
-
-make_dir(Path) ->
- case file:make_dir(Path) of
- ok ->
- ok;
- E={error, eexist} ->
- throw(E)
- end,
- %% Small window for a race condition here because dir is created 777
- ok = file:write_file_info(Path, #file_info{mode=8#0700}),
- Path.
-
-rngpath_fun(Prefix, Suffix, Dir) ->
- fun () ->
- filename:join([Dir, Prefix ++ rngchars(6) ++ Suffix])
- end.
-
-rngchars(0) ->
- "";
-rngchars(N) ->
- [rngchar() | rngchars(N - 1)].
-
-rngchar() ->
- rngchar(crypto:rand_uniform(0, tuple_size(?SAFE_CHARS))).
-
-rngchar(C) ->
- element(1 + C, ?SAFE_CHARS).
-
-%% @spec gettempdir() -> string()
-%% @doc Get a usable temporary directory using the first of these that is a directory:
-%% $TMPDIR, $TMP, $TEMP, "/tmp", "/var/tmp", "/usr/tmp", ".".
-gettempdir() ->
- gettempdir(gettempdir_checks(), fun normalize_dir/1).
-
-gettempdir_checks() ->
- [{fun os:getenv/1, ["TMPDIR", "TMP", "TEMP"]},
- {fun gettempdir_identity/1, ["/tmp", "/var/tmp", "/usr/tmp"]},
- {fun gettempdir_cwd/1, [cwd]}].
-
-gettempdir_identity(L) ->
- L.
-
-gettempdir_cwd(cwd) ->
- {ok, L} = file:get_cwd(),
- L.
-
-gettempdir([{_F, []} | RestF], Normalize) ->
- gettempdir(RestF, Normalize);
-gettempdir([{F, [L | RestL]} | RestF], Normalize) ->
- case Normalize(F(L)) of
- false ->
- gettempdir([{F, RestL} | RestF], Normalize);
- Dir ->
- Dir
- end.
-
-normalize_dir(False) when False =:= false orelse False =:= "" ->
- %% Erlang doesn't have an unsetenv, wtf.
- false;
-normalize_dir(L) ->
- Dir = filename:absname(L),
- case filelib:is_dir(Dir) of
- false ->
- false;
- true ->
- Dir
- end.
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-pushenv(L) ->
- [{K, os:getenv(K)} || K <- L].
-popenv(L) ->
- F = fun ({K, false}) ->
- %% Erlang doesn't have an unsetenv, wtf.
- os:putenv(K, "");
- ({K, V}) ->
- os:putenv(K, V)
- end,
- lists:foreach(F, L).
-
-gettempdir_fallback_test() ->
- ?assertEqual(
- "/",
- gettempdir([{fun gettempdir_identity/1, ["/--not-here--/"]},
- {fun gettempdir_identity/1, ["/"]}],
- fun normalize_dir/1)),
- ?assertEqual(
- "/",
- %% simulate a true os:getenv unset env
- gettempdir([{fun gettempdir_identity/1, [false]},
- {fun gettempdir_identity/1, ["/"]}],
- fun normalize_dir/1)),
- ok.
-
-gettempdir_identity_test() ->
- ?assertEqual(
- "/",
- gettempdir([{fun gettempdir_identity/1, ["/"]}], fun normalize_dir/1)),
- ok.
-
-gettempdir_cwd_test() ->
- {ok, Cwd} = file:get_cwd(),
- ?assertEqual(
- normalize_dir(Cwd),
- gettempdir([{fun gettempdir_cwd/1, [cwd]}], fun normalize_dir/1)),
- ok.
-
-rngchars_test() ->
- crypto:start(),
- ?assertEqual(
- "",
- rngchars(0)),
- ?assertEqual(
- 10,
- length(rngchars(10))),
- ok.
-
-rngchar_test() ->
- ?assertEqual(
- $a,
- rngchar(0)),
- ?assertEqual(
- $A,
- rngchar(26)),
- ?assertEqual(
- $_,
- rngchar(62)),
- ok.
-
-mkdtemp_n_failonce_test() ->
- crypto:start(),
- D = mkdtemp(),
- Path = filename:join([D, "testdir"]),
- %% Toggle the existence of a dir so that it fails
- %% the first time and succeeds the second.
- F = fun () ->
- case filelib:is_dir(Path) of
- true ->
- file:del_dir(Path);
- false ->
- file:make_dir(Path)
- end,
- Path
- end,
- try
- %% Fails the first time
- ?assertThrow(
- {error, eexist},
- mkdtemp_n(F, 1)),
- %% Reset state
- file:del_dir(Path),
- %% Succeeds the second time
- ?assertEqual(
- Path,
- mkdtemp_n(F, 2))
- after rmtempdir(D)
- end,
- ok.
-
-mkdtemp_n_fail_test() ->
- {ok, Cwd} = file:get_cwd(),
- ?assertThrow(
- {error, eexist},
- mkdtemp_n(fun () -> Cwd end, 1)),
- ?assertThrow(
- {error, eexist},
- mkdtemp_n(fun () -> Cwd end, 2)),
- ok.
-
-make_dir_fail_test() ->
- {ok, Cwd} = file:get_cwd(),
- ?assertThrow(
- {error, eexist},
- make_dir(Cwd)),
- ok.
-
-mkdtemp_test() ->
- crypto:start(),
- D = mkdtemp(),
- ?assertEqual(
- true,
- filelib:is_dir(D)),
- ?assertEqual(
- ok,
- file:del_dir(D)),
- ok.
-
-rmtempdir_test() ->
- crypto:start(),
- D1 = mkdtemp(),
- ?assertEqual(
- true,
- filelib:is_dir(D1)),
- ?assertEqual(
- ok,
- rmtempdir(D1)),
- D2 = mkdtemp(),
- ?assertEqual(
- true,
- filelib:is_dir(D2)),
- ok = file:write_file(filename:join([D2, "foo"]), <<"bytes">>),
- D3 = mkdtemp("suffix", "prefix", D2),
- ?assertEqual(
- true,
- filelib:is_dir(D3)),
- ok = file:write_file(filename:join([D3, "foo"]), <<"bytes">>),
- ?assertEqual(
- ok,
- rmtempdir(D2)),
- ?assertEqual(
- {error, enoent},
- file:consult(D3)),
- ?assertEqual(
- {error, enoent},
- file:consult(D2)),
- ok.
-
-gettempdir_env_test() ->
- Env = pushenv(["TMPDIR", "TEMP", "TMP"]),
- FalseEnv = [{"TMPDIR", false}, {"TEMP", false}, {"TMP", false}],
- try
- popenv(FalseEnv),
- popenv([{"TMPDIR", "/"}]),
- ?assertEqual(
- "/",
- os:getenv("TMPDIR")),
- ?assertEqual(
- "/",
- gettempdir()),
- {ok, Cwd} = file:get_cwd(),
- popenv(FalseEnv),
- popenv([{"TMP", Cwd}]),
- ?assertEqual(
- normalize_dir(Cwd),
- gettempdir())
- after popenv(Env)
- end,
- ok.
-
--endif.
diff --git a/src/mochiweb/mochiutf8.erl b/src/mochiweb/mochiutf8.erl
deleted file mode 100644
index 206e1186..00000000
--- a/src/mochiweb/mochiutf8.erl
+++ /dev/null
@@ -1,316 +0,0 @@
-%% @copyright 2010 Mochi Media, Inc.
-%% @author Bob Ippolito <bob@mochimedia.com>
-
-%% @doc Algorithm to convert any binary to a valid UTF-8 sequence by ignoring
-%% invalid bytes.
-
--module(mochiutf8).
--export([valid_utf8_bytes/1, codepoint_to_bytes/1, bytes_to_codepoints/1]).
--export([bytes_foldl/3, codepoint_foldl/3, read_codepoint/1, len/1]).
-
-%% External API
-
--type unichar_low() :: 0..16#d7ff.
--type unichar_high() :: 16#e000..16#10ffff.
--type unichar() :: unichar_low() | unichar_high().
-
--spec codepoint_to_bytes(unichar()) -> binary().
-%% @doc Convert a unicode codepoint to UTF-8 bytes.
-codepoint_to_bytes(C) when (C >= 16#00 andalso C =< 16#7f) ->
- %% U+0000 - U+007F - 7 bits
- <<C>>;
-codepoint_to_bytes(C) when (C >= 16#080 andalso C =< 16#07FF) ->
- %% U+0080 - U+07FF - 11 bits
- <<0:5, B1:5, B0:6>> = <<C:16>>,
- <<2#110:3, B1:5,
- 2#10:2, B0:6>>;
-codepoint_to_bytes(C) when (C >= 16#0800 andalso C =< 16#FFFF) andalso
- (C < 16#D800 orelse C > 16#DFFF) ->
- %% U+0800 - U+FFFF - 16 bits (excluding UTC-16 surrogate code points)
- <<B2:4, B1:6, B0:6>> = <<C:16>>,
- <<2#1110:4, B2:4,
- 2#10:2, B1:6,
- 2#10:2, B0:6>>;
-codepoint_to_bytes(C) when (C >= 16#010000 andalso C =< 16#10FFFF) ->
- %% U+10000 - U+10FFFF - 21 bits
- <<0:3, B3:3, B2:6, B1:6, B0:6>> = <<C:24>>,
- <<2#11110:5, B3:3,
- 2#10:2, B2:6,
- 2#10:2, B1:6,
- 2#10:2, B0:6>>.
-
--spec codepoints_to_bytes([unichar()]) -> binary().
-%% @doc Convert a list of codepoints to a UTF-8 binary.
-codepoints_to_bytes(L) ->
- <<<<(codepoint_to_bytes(C))/binary>> || C <- L>>.
-
--spec read_codepoint(binary()) -> {unichar(), binary(), binary()}.
-read_codepoint(Bin = <<2#0:1, C:7, Rest/binary>>) ->
- %% U+0000 - U+007F - 7 bits
- <<B:1/binary, _/binary>> = Bin,
- {C, B, Rest};
-read_codepoint(Bin = <<2#110:3, B1:5,
- 2#10:2, B0:6,
- Rest/binary>>) ->
- %% U+0080 - U+07FF - 11 bits
- case <<B1:5, B0:6>> of
- <<C:11>> when C >= 16#80 ->
- <<B:2/binary, _/binary>> = Bin,
- {C, B, Rest}
- end;
-read_codepoint(Bin = <<2#1110:4, B2:4,
- 2#10:2, B1:6,
- 2#10:2, B0:6,
- Rest/binary>>) ->
- %% U+0800 - U+FFFF - 16 bits (excluding UTC-16 surrogate code points)
- case <<B2:4, B1:6, B0:6>> of
- <<C:16>> when (C >= 16#0800 andalso C =< 16#FFFF) andalso
- (C < 16#D800 orelse C > 16#DFFF) ->
- <<B:3/binary, _/binary>> = Bin,
- {C, B, Rest}
- end;
-read_codepoint(Bin = <<2#11110:5, B3:3,
- 2#10:2, B2:6,
- 2#10:2, B1:6,
- 2#10:2, B0:6,
- Rest/binary>>) ->
- %% U+10000 - U+10FFFF - 21 bits
- case <<B3:3, B2:6, B1:6, B0:6>> of
- <<C:21>> when (C >= 16#010000 andalso C =< 16#10FFFF) ->
- <<B:4/binary, _/binary>> = Bin,
- {C, B, Rest}
- end.
-
--spec codepoint_foldl(fun((unichar(), _) -> _), _, binary()) -> _.
-codepoint_foldl(F, Acc, <<>>) when is_function(F, 2) ->
- Acc;
-codepoint_foldl(F, Acc, Bin) ->
- {C, _, Rest} = read_codepoint(Bin),
- codepoint_foldl(F, F(C, Acc), Rest).
-
--spec bytes_foldl(fun((binary(), _) -> _), _, binary()) -> _.
-bytes_foldl(F, Acc, <<>>) when is_function(F, 2) ->
- Acc;
-bytes_foldl(F, Acc, Bin) ->
- {_, B, Rest} = read_codepoint(Bin),
- bytes_foldl(F, F(B, Acc), Rest).
-
--spec bytes_to_codepoints(binary()) -> [unichar()].
-bytes_to_codepoints(B) ->
- lists:reverse(codepoint_foldl(fun (C, Acc) -> [C | Acc] end, [], B)).
-
--spec len(binary()) -> non_neg_integer().
-len(<<>>) ->
- 0;
-len(B) ->
- {_, _, Rest} = read_codepoint(B),
- 1 + len(Rest).
-
--spec valid_utf8_bytes(B::binary()) -> binary().
-%% @doc Return only the bytes in B that represent valid UTF-8. Uses
-%% the following recursive algorithm: skip one byte if B does not
-%% follow UTF-8 syntax (a 1-4 byte encoding of some number),
-%% skip sequence of 2-4 bytes if it represents an overlong encoding
-%% or bad code point (surrogate U+D800 - U+DFFF or > U+10FFFF).
-valid_utf8_bytes(B) when is_binary(B) ->
- binary_skip_bytes(B, invalid_utf8_indexes(B)).
-
-%% Internal API
-
--spec binary_skip_bytes(binary(), [non_neg_integer()]) -> binary().
-%% @doc Return B, but skipping the 0-based indexes in L.
-binary_skip_bytes(B, []) ->
- B;
-binary_skip_bytes(B, L) ->
- binary_skip_bytes(B, L, 0, []).
-
-%% @private
--spec binary_skip_bytes(binary(), [non_neg_integer()], non_neg_integer(), iolist()) -> binary().
-binary_skip_bytes(B, [], _N, Acc) ->
- iolist_to_binary(lists:reverse([B | Acc]));
-binary_skip_bytes(<<_, RestB/binary>>, [N | RestL], N, Acc) ->
- binary_skip_bytes(RestB, RestL, 1 + N, Acc);
-binary_skip_bytes(<<C, RestB/binary>>, L, N, Acc) ->
- binary_skip_bytes(RestB, L, 1 + N, [C | Acc]).
-
--spec invalid_utf8_indexes(binary()) -> [non_neg_integer()].
-%% @doc Return the 0-based indexes in B that are not valid UTF-8.
-invalid_utf8_indexes(B) ->
- invalid_utf8_indexes(B, 0, []).
-
-%% @private.
--spec invalid_utf8_indexes(binary(), non_neg_integer(), [non_neg_integer()]) -> [non_neg_integer()].
-invalid_utf8_indexes(<<C, Rest/binary>>, N, Acc) when C < 16#80 ->
- %% U+0000 - U+007F - 7 bits
- invalid_utf8_indexes(Rest, 1 + N, Acc);
-invalid_utf8_indexes(<<C1, C2, Rest/binary>>, N, Acc)
- when C1 band 16#E0 =:= 16#C0,
- C2 band 16#C0 =:= 16#80 ->
- %% U+0080 - U+07FF - 11 bits
- case ((C1 band 16#1F) bsl 6) bor (C2 band 16#3F) of
- C when C < 16#80 ->
- %% Overlong encoding.
- invalid_utf8_indexes(Rest, 2 + N, [1 + N, N | Acc]);
- _ ->
- %% Upper bound U+07FF does not need to be checked
- invalid_utf8_indexes(Rest, 2 + N, Acc)
- end;
-invalid_utf8_indexes(<<C1, C2, C3, Rest/binary>>, N, Acc)
- when C1 band 16#F0 =:= 16#E0,
- C2 band 16#C0 =:= 16#80,
- C3 band 16#C0 =:= 16#80 ->
- %% U+0800 - U+FFFF - 16 bits
- case ((((C1 band 16#0F) bsl 6) bor (C2 band 16#3F)) bsl 6) bor
- (C3 band 16#3F) of
- C when (C < 16#800) orelse (C >= 16#D800 andalso C =< 16#DFFF) ->
- %% Overlong encoding or surrogate.
- invalid_utf8_indexes(Rest, 3 + N, [2 + N, 1 + N, N | Acc]);
- _ ->
- %% Upper bound U+FFFF does not need to be checked
- invalid_utf8_indexes(Rest, 3 + N, Acc)
- end;
-invalid_utf8_indexes(<<C1, C2, C3, C4, Rest/binary>>, N, Acc)
- when C1 band 16#F8 =:= 16#F0,
- C2 band 16#C0 =:= 16#80,
- C3 band 16#C0 =:= 16#80,
- C4 band 16#C0 =:= 16#80 ->
- %% U+10000 - U+10FFFF - 21 bits
- case ((((((C1 band 16#0F) bsl 6) bor (C2 band 16#3F)) bsl 6) bor
- (C3 band 16#3F)) bsl 6) bor (C4 band 16#3F) of
- C when (C < 16#10000) orelse (C > 16#10FFFF) ->
- %% Overlong encoding or invalid code point.
- invalid_utf8_indexes(Rest, 4 + N, [3 + N, 2 + N, 1 + N, N | Acc]);
- _ ->
- invalid_utf8_indexes(Rest, 4 + N, Acc)
- end;
-invalid_utf8_indexes(<<_, Rest/binary>>, N, Acc) ->
- %% Invalid char
- invalid_utf8_indexes(Rest, 1 + N, [N | Acc]);
-invalid_utf8_indexes(<<>>, _N, Acc) ->
- lists:reverse(Acc).
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-binary_skip_bytes_test() ->
- ?assertEqual(<<"foo">>,
- binary_skip_bytes(<<"foo">>, [])),
- ?assertEqual(<<"foobar">>,
- binary_skip_bytes(<<"foo bar">>, [3])),
- ?assertEqual(<<"foo">>,
- binary_skip_bytes(<<"foo bar">>, [3, 4, 5, 6])),
- ?assertEqual(<<"oo bar">>,
- binary_skip_bytes(<<"foo bar">>, [0])),
- ok.
-
-invalid_utf8_indexes_test() ->
- ?assertEqual(
- [],
- invalid_utf8_indexes(<<"unicode snowman for you: ", 226, 152, 131>>)),
- ?assertEqual(
- [0],
- invalid_utf8_indexes(<<128>>)),
- ?assertEqual(
- [57,59,60,64,66,67],
- invalid_utf8_indexes(<<"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; (",
- 167, 65, 170, 186, 73, 83, 80, 166, 87, 186, 217, 41, 41>>)),
- ok.
-
-codepoint_to_bytes_test() ->
- %% U+0000 - U+007F - 7 bits
- %% U+0080 - U+07FF - 11 bits
- %% U+0800 - U+FFFF - 16 bits (excluding UTC-16 surrogate code points)
- %% U+10000 - U+10FFFF - 21 bits
- ?assertEqual(
- <<"a">>,
- codepoint_to_bytes($a)),
- ?assertEqual(
- <<16#c2, 16#80>>,
- codepoint_to_bytes(16#80)),
- ?assertEqual(
- <<16#df, 16#bf>>,
- codepoint_to_bytes(16#07ff)),
- ?assertEqual(
- <<16#ef, 16#bf, 16#bf>>,
- codepoint_to_bytes(16#ffff)),
- ?assertEqual(
- <<16#f4, 16#8f, 16#bf, 16#bf>>,
- codepoint_to_bytes(16#10ffff)),
- ok.
-
-bytes_foldl_test() ->
- ?assertEqual(
- <<"abc">>,
- bytes_foldl(fun (B, Acc) -> <<Acc/binary, B/binary>> end, <<>>, <<"abc">>)),
- ?assertEqual(
- <<"abc", 226, 152, 131, 228, 184, 173, 194, 133, 244,143,191,191>>,
- bytes_foldl(fun (B, Acc) -> <<Acc/binary, B/binary>> end, <<>>,
- <<"abc", 226, 152, 131, 228, 184, 173, 194, 133, 244,143,191,191>>)),
- ok.
-
-bytes_to_codepoints_test() ->
- ?assertEqual(
- "abc" ++ [16#2603, 16#4e2d, 16#85, 16#10ffff],
- bytes_to_codepoints(<<"abc", 226, 152, 131, 228, 184, 173, 194, 133, 244,143,191,191>>)),
- ok.
-
-codepoint_foldl_test() ->
- ?assertEqual(
- "cba",
- codepoint_foldl(fun (C, Acc) -> [C | Acc] end, [], <<"abc">>)),
- ?assertEqual(
- [16#10ffff, 16#85, 16#4e2d, 16#2603 | "cba"],
- codepoint_foldl(fun (C, Acc) -> [C | Acc] end, [],
- <<"abc", 226, 152, 131, 228, 184, 173, 194, 133, 244,143,191,191>>)),
- ok.
-
-len_test() ->
- ?assertEqual(
- 29,
- len(<<"unicode snowman for you: ", 226, 152, 131, 228, 184, 173, 194, 133, 244, 143, 191, 191>>)),
- ok.
-
-codepoints_to_bytes_test() ->
- ?assertEqual(
- iolist_to_binary(lists:map(fun codepoint_to_bytes/1, lists:seq(1, 1000))),
- codepoints_to_bytes(lists:seq(1, 1000))),
- ok.
-
-valid_utf8_bytes_test() ->
- ?assertEqual(
- <<"invalid U+11ffff: ">>,
- valid_utf8_bytes(<<"invalid U+11ffff: ", 244, 159, 191, 191>>)),
- ?assertEqual(
- <<"U+10ffff: ", 244, 143, 191, 191>>,
- valid_utf8_bytes(<<"U+10ffff: ", 244, 143, 191, 191>>)),
- ?assertEqual(
- <<"overlong 2-byte encoding (a): ">>,
- valid_utf8_bytes(<<"overlong 2-byte encoding (a): ", 2#11000001, 2#10100001>>)),
- ?assertEqual(
- <<"overlong 2-byte encoding (!): ">>,
- valid_utf8_bytes(<<"overlong 2-byte encoding (!): ", 2#11000000, 2#10100001>>)),
- ?assertEqual(
- <<"mu: ", 194, 181>>,
- valid_utf8_bytes(<<"mu: ", 194, 181>>)),
- ?assertEqual(
- <<"bad coding bytes: ">>,
- valid_utf8_bytes(<<"bad coding bytes: ", 2#10011111, 2#10111111, 2#11111111>>)),
- ?assertEqual(
- <<"low surrogate (unpaired): ">>,
- valid_utf8_bytes(<<"low surrogate (unpaired): ", 237, 176, 128>>)),
- ?assertEqual(
- <<"high surrogate (unpaired): ">>,
- valid_utf8_bytes(<<"high surrogate (unpaired): ", 237, 191, 191>>)),
- ?assertEqual(
- <<"unicode snowman for you: ", 226, 152, 131>>,
- valid_utf8_bytes(<<"unicode snowman for you: ", 226, 152, 131>>)),
- ?assertEqual(
- <<"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; (AISPW))">>,
- valid_utf8_bytes(<<"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; (",
- 167, 65, 170, 186, 73, 83, 80, 166, 87, 186, 217, 41, 41>>)),
- ok.
-
--endif.
diff --git a/src/mochiweb/mochiweb.app.in b/src/mochiweb/mochiweb.app.in
deleted file mode 100644
index c6a2630b..00000000
--- a/src/mochiweb/mochiweb.app.in
+++ /dev/null
@@ -1,32 +0,0 @@
-{application, mochiweb,
- [{description, "MochiMedia Web Server"},
- {vsn, "7c2bc2"},
- {modules, [
- mochihex,
- mochijson,
- mochijson2,
- mochinum,
- mochiweb,
- mochiweb_app,
- mochiweb_charref,
- mochiweb_cookies,
- mochiweb_echo,
- mochiweb_headers,
- mochiweb_html,
- mochiweb_http,
- mochiweb_multipart,
- mochiweb_request,
- mochiweb_response,
- mochiweb_skel,
- mochiweb_socket_server,
- mochiweb_sup,
- mochiweb_util,
- reloader,
- mochifmt,
- mochifmt_std,
- mochifmt_records
- ]},
- {registered, []},
- {mod, {mochiweb_app, []}},
- {env, []},
- {applications, [kernel, stdlib]}]}.
diff --git a/src/mochiweb/mochiweb.app.src b/src/mochiweb/mochiweb.app.src
deleted file mode 100644
index a1c95aae..00000000
--- a/src/mochiweb/mochiweb.app.src
+++ /dev/null
@@ -1,9 +0,0 @@
-%% This is generated from src/mochiweb.app.src
-{application, mochiweb,
- [{description, "MochiMedia Web Server"},
- {vsn, "7c2bc2"},
- {modules, []},
- {registered, []},
- {mod, {mochiweb_app, []}},
- {env, []},
- {applications, [kernel, stdlib, crypto, inets]}]}.
diff --git a/src/mochiweb/mochiweb.erl b/src/mochiweb/mochiweb.erl
deleted file mode 100644
index 3118028b..00000000
--- a/src/mochiweb/mochiweb.erl
+++ /dev/null
@@ -1,289 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2007 Mochi Media, Inc.
-
-%% @doc Start and stop the MochiWeb server.
-
--module(mochiweb).
--author('bob@mochimedia.com').
-
--export([start/0, stop/0]).
--export([new_request/1, new_response/1]).
--export([all_loaded/0, all_loaded/1, reload/0]).
-
-%% @spec start() -> ok
-%% @doc Start the MochiWeb server.
-start() ->
- ensure_started(crypto),
- application:start(mochiweb).
-
-%% @spec stop() -> ok
-%% @doc Stop the MochiWeb server.
-stop() ->
- Res = application:stop(mochiweb),
- application:stop(crypto),
- Res.
-
-reload() ->
- [c:l(Module) || Module <- all_loaded()].
-
-all_loaded() ->
- all_loaded(filename:dirname(code:which(?MODULE))).
-
-all_loaded(Base) when is_atom(Base) ->
- [];
-all_loaded(Base) ->
- FullBase = Base ++ "/",
- F = fun ({_Module, Loaded}, Acc) when is_atom(Loaded) ->
- Acc;
- ({Module, Loaded}, Acc) ->
- case lists:prefix(FullBase, Loaded) of
- true ->
- [Module | Acc];
- false ->
- Acc
- end
- end,
- lists:foldl(F, [], code:all_loaded()).
-
-
-%% @spec new_request({Socket, Request, Headers}) -> MochiWebRequest
-%% @doc Return a mochiweb_request data structure.
-new_request({Socket, {Method, {abs_path, Uri}, Version}, Headers}) ->
- mochiweb_request:new(Socket,
- Method,
- Uri,
- Version,
- mochiweb_headers:make(Headers));
-% this case probably doesn't "exist".
-new_request({Socket, {Method, {absoluteURI, _Protocol, _Host, _Port, Uri},
- Version}, Headers}) ->
- mochiweb_request:new(Socket,
- Method,
- Uri,
- Version,
- mochiweb_headers:make(Headers));
-%% Request-URI is "*"
-%% From http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.2
-new_request({Socket, {Method, '*'=Uri, Version}, Headers}) ->
- mochiweb_request:new(Socket,
- Method,
- Uri,
- Version,
- mochiweb_headers:make(Headers)).
-
-%% @spec new_response({Request, integer(), Headers}) -> MochiWebResponse
-%% @doc Return a mochiweb_response data structure.
-new_response({Request, Code, Headers}) ->
- mochiweb_response:new(Request,
- Code,
- mochiweb_headers:make(Headers)).
-
-%% Internal API
-
-ensure_started(App) ->
- case application:start(App) of
- ok ->
- ok;
- {error, {already_started, App}} ->
- ok
- end.
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
--record(treq, {path, body= <<>>, xreply= <<>>}).
-
-ssl_cert_opts() ->
- EbinDir = filename:dirname(code:which(?MODULE)),
- CertDir = filename:join([EbinDir, "..", "support", "test-materials"]),
- CertFile = filename:join(CertDir, "test_ssl_cert.pem"),
- KeyFile = filename:join(CertDir, "test_ssl_key.pem"),
- [{certfile, CertFile}, {keyfile, KeyFile}].
-
-with_server(Transport, ServerFun, ClientFun) ->
- ServerOpts0 = [{ip, "127.0.0.1"}, {port, 0}, {loop, ServerFun}],
- ServerOpts = case Transport of
- plain ->
- ServerOpts0;
- ssl ->
- ServerOpts0 ++ [{ssl, true}, {ssl_opts, ssl_cert_opts()}]
- end,
- {ok, Server} = mochiweb_http:start(ServerOpts),
- Port = mochiweb_socket_server:get(Server, port),
- Res = (catch ClientFun(Transport, Port)),
- mochiweb_http:stop(Server),
- Res.
-
-request_test() ->
- R = mochiweb_request:new(z, z, "/foo/bar/baz%20wibble+quux?qs=2", z, []),
- "/foo/bar/baz wibble quux" = R:get(path),
- ok.
-
-single_http_GET_test() ->
- do_GET(plain, 1).
-
-single_https_GET_test() ->
- do_GET(ssl, 1).
-
-multiple_http_GET_test() ->
- do_GET(plain, 3).
-
-multiple_https_GET_test() ->
- do_GET(ssl, 3).
-
-hundred_http_GET_test() ->
- do_GET(plain, 100).
-
-hundred_https_GET_test() ->
- do_GET(ssl, 100).
-
-single_128_http_POST_test() ->
- do_POST(plain, 128, 1).
-
-single_128_https_POST_test() ->
- do_POST(ssl, 128, 1).
-
-single_2k_http_POST_test() ->
- do_POST(plain, 2048, 1).
-
-single_2k_https_POST_test() ->
- do_POST(ssl, 2048, 1).
-
-single_100k_http_POST_test() ->
- do_POST(plain, 102400, 1).
-
-single_100k_https_POST_test() ->
- do_POST(ssl, 102400, 1).
-
-multiple_100k_http_POST_test() ->
- do_POST(plain, 102400, 3).
-
-multiple_100K_https_POST_test() ->
- do_POST(ssl, 102400, 3).
-
-hundred_128_http_POST_test() ->
- do_POST(plain, 128, 100).
-
-hundred_128_https_POST_test() ->
- do_POST(ssl, 128, 100).
-
-do_GET(Transport, Times) ->
- PathPrefix = "/whatever/",
- ReplyPrefix = "You requested: ",
- ServerFun = fun (Req) ->
- Reply = ReplyPrefix ++ Req:get(path),
- Req:ok({"text/plain", Reply})
- end,
- TestReqs = [begin
- Path = PathPrefix ++ integer_to_list(N),
- ExpectedReply = list_to_binary(ReplyPrefix ++ Path),
- #treq{path=Path, xreply=ExpectedReply}
- end || N <- lists:seq(1, Times)],
- ClientFun = new_client_fun('GET', TestReqs),
- ok = with_server(Transport, ServerFun, ClientFun),
- ok.
-
-do_POST(Transport, Size, Times) ->
- ServerFun = fun (Req) ->
- Body = Req:recv_body(),
- Headers = [{"Content-Type", "application/octet-stream"}],
- Req:respond({201, Headers, Body})
- end,
- TestReqs = [begin
- Path = "/stuff/" ++ integer_to_list(N),
- Body = crypto:rand_bytes(Size),
- #treq{path=Path, body=Body, xreply=Body}
- end || N <- lists:seq(1, Times)],
- ClientFun = new_client_fun('POST', TestReqs),
- ok = with_server(Transport, ServerFun, ClientFun),
- ok.
-
-new_client_fun(Method, TestReqs) ->
- fun (Transport, Port) ->
- client_request(Transport, Port, Method, TestReqs)
- end.
-
-client_request(Transport, Port, Method, TestReqs) ->
- Opts = [binary, {active, false}, {packet, http}],
- SockFun = case Transport of
- plain ->
- {ok, Socket} = gen_tcp:connect("127.0.0.1", Port, Opts),
- fun (recv) ->
- gen_tcp:recv(Socket, 0);
- ({recv, Length}) ->
- gen_tcp:recv(Socket, Length);
- ({send, Data}) ->
- gen_tcp:send(Socket, Data);
- ({setopts, L}) ->
- inet:setopts(Socket, L)
- end;
- ssl ->
- {ok, Socket} = ssl:connect("127.0.0.1", Port, [{ssl_imp, new} | Opts]),
- fun (recv) ->
- ssl:recv(Socket, 0);
- ({recv, Length}) ->
- ssl:recv(Socket, Length);
- ({send, Data}) ->
- ssl:send(Socket, Data);
- ({setopts, L}) ->
- ssl:setopts(Socket, L)
- end
- end,
- client_request(SockFun, Method, TestReqs).
-
-client_request(SockFun, _Method, []) ->
- {the_end, {error, closed}} = {the_end, SockFun(recv)},
- ok;
-client_request(SockFun, Method,
- [#treq{path=Path, body=Body, xreply=ExReply} | Rest]) ->
- Request = [atom_to_list(Method), " ", Path, " HTTP/1.1\r\n",
- client_headers(Body, Rest =:= []),
- "\r\n",
- Body],
- ok = SockFun({send, Request}),
- case Method of
- 'GET' ->
- {ok, {http_response, {1,1}, 200, "OK"}} = SockFun(recv);
- 'POST' ->
- {ok, {http_response, {1,1}, 201, "Created"}} = SockFun(recv)
- end,
- ok = SockFun({setopts, [{packet, httph}]}),
- {ok, {http_header, _, 'Server', _, "MochiWeb" ++ _}} = SockFun(recv),
- {ok, {http_header, _, 'Date', _, _}} = SockFun(recv),
- {ok, {http_header, _, 'Content-Type', _, _}} = SockFun(recv),
- {ok, {http_header, _, 'Content-Length', _, ConLenStr}} = SockFun(recv),
- ContentLength = list_to_integer(ConLenStr),
- {ok, http_eoh} = SockFun(recv),
- ok = SockFun({setopts, [{packet, raw}]}),
- {payload, ExReply} = {payload, drain_reply(SockFun, ContentLength, <<>>)},
- ok = SockFun({setopts, [{packet, http}]}),
- client_request(SockFun, Method, Rest).
-
-client_headers(Body, IsLastRequest) ->
- ["Host: localhost\r\n",
- case Body of
- <<>> ->
- "";
- _ ->
- ["Content-Type: application/octet-stream\r\n",
- "Content-Length: ", integer_to_list(byte_size(Body)), "\r\n"]
- end,
- case IsLastRequest of
- true ->
- "Connection: close\r\n";
- false ->
- ""
- end].
-
-drain_reply(_SockFun, 0, Acc) ->
- Acc;
-drain_reply(SockFun, Length, Acc) ->
- Sz = erlang:min(Length, 1024),
- {ok, B} = SockFun({recv, Sz}),
- drain_reply(SockFun, Length - Sz, <<Acc/bytes, B/bytes>>).
-
--endif.
diff --git a/src/mochiweb/mochiweb_acceptor.erl b/src/mochiweb/mochiweb_acceptor.erl
deleted file mode 100644
index 79d172c3..00000000
--- a/src/mochiweb/mochiweb_acceptor.erl
+++ /dev/null
@@ -1,48 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2010 Mochi Media, Inc.
-
-%% @doc MochiWeb acceptor.
-
--module(mochiweb_acceptor).
--author('bob@mochimedia.com').
-
--include("internal.hrl").
-
--export([start_link/3, init/3]).
-
-start_link(Server, Listen, Loop) ->
- proc_lib:spawn_link(?MODULE, init, [Server, Listen, Loop]).
-
-init(Server, Listen, Loop) ->
- T1 = now(),
- case catch mochiweb_socket:accept(Listen) of
- {ok, Socket} ->
- gen_server:cast(Server, {accepted, self(), timer:now_diff(now(), T1)}),
- call_loop(Loop, Socket);
- {error, closed} ->
- exit(normal);
- {error, timeout} ->
- exit(normal);
- {error, esslaccept} ->
- exit(normal);
- Other ->
- error_logger:error_report(
- [{application, mochiweb},
- "Accept failed error",
- lists:flatten(io_lib:format("~p", [Other]))]),
- exit({error, accept_failed})
- end.
-
-call_loop({M, F}, Socket) ->
- M:F(Socket);
-call_loop({M, F, A}, Socket) ->
- erlang:apply(M, F, [Socket | A]);
-call_loop(Loop, Socket) ->
- Loop(Socket).
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
--endif.
diff --git a/src/mochiweb/mochiweb_app.erl b/src/mochiweb/mochiweb_app.erl
deleted file mode 100644
index 5d67787b..00000000
--- a/src/mochiweb/mochiweb_app.erl
+++ /dev/null
@@ -1,27 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2007 Mochi Media, Inc.
-
-%% @doc Callbacks for the mochiweb application.
-
--module(mochiweb_app).
--author('bob@mochimedia.com').
-
--behaviour(application).
--export([start/2,stop/1]).
-
-%% @spec start(_Type, _StartArgs) -> ServerRet
-%% @doc application start callback for mochiweb.
-start(_Type, _StartArgs) ->
- mochiweb_sup:start_link().
-
-%% @spec stop(_State) -> ServerRet
-%% @doc application stop callback for mochiweb.
-stop(_State) ->
- ok.
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
--endif.
diff --git a/src/mochiweb/mochiweb_charref.erl b/src/mochiweb/mochiweb_charref.erl
deleted file mode 100644
index 99cd5502..00000000
--- a/src/mochiweb/mochiweb_charref.erl
+++ /dev/null
@@ -1,308 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2007 Mochi Media, Inc.
-
-%% @doc Converts HTML 4 charrefs and entities to codepoints.
--module(mochiweb_charref).
--export([charref/1]).
-
-%% External API.
-
-%% @spec charref(S) -> integer() | undefined
-%% @doc Convert a decimal charref, hex charref, or html entity to a unicode
-%% codepoint, or return undefined on failure.
-%% The input should not include an ampersand or semicolon.
-%% charref("#38") = 38, charref("#x26") = 38, charref("amp") = 38.
-charref(B) when is_binary(B) ->
- charref(binary_to_list(B));
-charref([$#, C | L]) when C =:= $x orelse C =:= $X ->
- try erlang:list_to_integer(L, 16)
- catch
- error:badarg -> undefined
- end;
-charref([$# | L]) ->
- try list_to_integer(L)
- catch
- error:badarg -> undefined
- end;
-charref(L) ->
- entity(L).
-
-%% Internal API.
-
-entity("nbsp") -> 160;
-entity("iexcl") -> 161;
-entity("cent") -> 162;
-entity("pound") -> 163;
-entity("curren") -> 164;
-entity("yen") -> 165;
-entity("brvbar") -> 166;
-entity("sect") -> 167;
-entity("uml") -> 168;
-entity("copy") -> 169;
-entity("ordf") -> 170;
-entity("laquo") -> 171;
-entity("not") -> 172;
-entity("shy") -> 173;
-entity("reg") -> 174;
-entity("macr") -> 175;
-entity("deg") -> 176;
-entity("plusmn") -> 177;
-entity("sup2") -> 178;
-entity("sup3") -> 179;
-entity("acute") -> 180;
-entity("micro") -> 181;
-entity("para") -> 182;
-entity("middot") -> 183;
-entity("cedil") -> 184;
-entity("sup1") -> 185;
-entity("ordm") -> 186;
-entity("raquo") -> 187;
-entity("frac14") -> 188;
-entity("frac12") -> 189;
-entity("frac34") -> 190;
-entity("iquest") -> 191;
-entity("Agrave") -> 192;
-entity("Aacute") -> 193;
-entity("Acirc") -> 194;
-entity("Atilde") -> 195;
-entity("Auml") -> 196;
-entity("Aring") -> 197;
-entity("AElig") -> 198;
-entity("Ccedil") -> 199;
-entity("Egrave") -> 200;
-entity("Eacute") -> 201;
-entity("Ecirc") -> 202;
-entity("Euml") -> 203;
-entity("Igrave") -> 204;
-entity("Iacute") -> 205;
-entity("Icirc") -> 206;
-entity("Iuml") -> 207;
-entity("ETH") -> 208;
-entity("Ntilde") -> 209;
-entity("Ograve") -> 210;
-entity("Oacute") -> 211;
-entity("Ocirc") -> 212;
-entity("Otilde") -> 213;
-entity("Ouml") -> 214;
-entity("times") -> 215;
-entity("Oslash") -> 216;
-entity("Ugrave") -> 217;
-entity("Uacute") -> 218;
-entity("Ucirc") -> 219;
-entity("Uuml") -> 220;
-entity("Yacute") -> 221;
-entity("THORN") -> 222;
-entity("szlig") -> 223;
-entity("agrave") -> 224;
-entity("aacute") -> 225;
-entity("acirc") -> 226;
-entity("atilde") -> 227;
-entity("auml") -> 228;
-entity("aring") -> 229;
-entity("aelig") -> 230;
-entity("ccedil") -> 231;
-entity("egrave") -> 232;
-entity("eacute") -> 233;
-entity("ecirc") -> 234;
-entity("euml") -> 235;
-entity("igrave") -> 236;
-entity("iacute") -> 237;
-entity("icirc") -> 238;
-entity("iuml") -> 239;
-entity("eth") -> 240;
-entity("ntilde") -> 241;
-entity("ograve") -> 242;
-entity("oacute") -> 243;
-entity("ocirc") -> 244;
-entity("otilde") -> 245;
-entity("ouml") -> 246;
-entity("divide") -> 247;
-entity("oslash") -> 248;
-entity("ugrave") -> 249;
-entity("uacute") -> 250;
-entity("ucirc") -> 251;
-entity("uuml") -> 252;
-entity("yacute") -> 253;
-entity("thorn") -> 254;
-entity("yuml") -> 255;
-entity("fnof") -> 402;
-entity("Alpha") -> 913;
-entity("Beta") -> 914;
-entity("Gamma") -> 915;
-entity("Delta") -> 916;
-entity("Epsilon") -> 917;
-entity("Zeta") -> 918;
-entity("Eta") -> 919;
-entity("Theta") -> 920;
-entity("Iota") -> 921;
-entity("Kappa") -> 922;
-entity("Lambda") -> 923;
-entity("Mu") -> 924;
-entity("Nu") -> 925;
-entity("Xi") -> 926;
-entity("Omicron") -> 927;
-entity("Pi") -> 928;
-entity("Rho") -> 929;
-entity("Sigma") -> 931;
-entity("Tau") -> 932;
-entity("Upsilon") -> 933;
-entity("Phi") -> 934;
-entity("Chi") -> 935;
-entity("Psi") -> 936;
-entity("Omega") -> 937;
-entity("alpha") -> 945;
-entity("beta") -> 946;
-entity("gamma") -> 947;
-entity("delta") -> 948;
-entity("epsilon") -> 949;
-entity("zeta") -> 950;
-entity("eta") -> 951;
-entity("theta") -> 952;
-entity("iota") -> 953;
-entity("kappa") -> 954;
-entity("lambda") -> 955;
-entity("mu") -> 956;
-entity("nu") -> 957;
-entity("xi") -> 958;
-entity("omicron") -> 959;
-entity("pi") -> 960;
-entity("rho") -> 961;
-entity("sigmaf") -> 962;
-entity("sigma") -> 963;
-entity("tau") -> 964;
-entity("upsilon") -> 965;
-entity("phi") -> 966;
-entity("chi") -> 967;
-entity("psi") -> 968;
-entity("omega") -> 969;
-entity("thetasym") -> 977;
-entity("upsih") -> 978;
-entity("piv") -> 982;
-entity("bull") -> 8226;
-entity("hellip") -> 8230;
-entity("prime") -> 8242;
-entity("Prime") -> 8243;
-entity("oline") -> 8254;
-entity("frasl") -> 8260;
-entity("weierp") -> 8472;
-entity("image") -> 8465;
-entity("real") -> 8476;
-entity("trade") -> 8482;
-entity("alefsym") -> 8501;
-entity("larr") -> 8592;
-entity("uarr") -> 8593;
-entity("rarr") -> 8594;
-entity("darr") -> 8595;
-entity("harr") -> 8596;
-entity("crarr") -> 8629;
-entity("lArr") -> 8656;
-entity("uArr") -> 8657;
-entity("rArr") -> 8658;
-entity("dArr") -> 8659;
-entity("hArr") -> 8660;
-entity("forall") -> 8704;
-entity("part") -> 8706;
-entity("exist") -> 8707;
-entity("empty") -> 8709;
-entity("nabla") -> 8711;
-entity("isin") -> 8712;
-entity("notin") -> 8713;
-entity("ni") -> 8715;
-entity("prod") -> 8719;
-entity("sum") -> 8721;
-entity("minus") -> 8722;
-entity("lowast") -> 8727;
-entity("radic") -> 8730;
-entity("prop") -> 8733;
-entity("infin") -> 8734;
-entity("ang") -> 8736;
-entity("and") -> 8743;
-entity("or") -> 8744;
-entity("cap") -> 8745;
-entity("cup") -> 8746;
-entity("int") -> 8747;
-entity("there4") -> 8756;
-entity("sim") -> 8764;
-entity("cong") -> 8773;
-entity("asymp") -> 8776;
-entity("ne") -> 8800;
-entity("equiv") -> 8801;
-entity("le") -> 8804;
-entity("ge") -> 8805;
-entity("sub") -> 8834;
-entity("sup") -> 8835;
-entity("nsub") -> 8836;
-entity("sube") -> 8838;
-entity("supe") -> 8839;
-entity("oplus") -> 8853;
-entity("otimes") -> 8855;
-entity("perp") -> 8869;
-entity("sdot") -> 8901;
-entity("lceil") -> 8968;
-entity("rceil") -> 8969;
-entity("lfloor") -> 8970;
-entity("rfloor") -> 8971;
-entity("lang") -> 9001;
-entity("rang") -> 9002;
-entity("loz") -> 9674;
-entity("spades") -> 9824;
-entity("clubs") -> 9827;
-entity("hearts") -> 9829;
-entity("diams") -> 9830;
-entity("quot") -> 34;
-entity("amp") -> 38;
-entity("lt") -> 60;
-entity("gt") -> 62;
-entity("OElig") -> 338;
-entity("oelig") -> 339;
-entity("Scaron") -> 352;
-entity("scaron") -> 353;
-entity("Yuml") -> 376;
-entity("circ") -> 710;
-entity("tilde") -> 732;
-entity("ensp") -> 8194;
-entity("emsp") -> 8195;
-entity("thinsp") -> 8201;
-entity("zwnj") -> 8204;
-entity("zwj") -> 8205;
-entity("lrm") -> 8206;
-entity("rlm") -> 8207;
-entity("ndash") -> 8211;
-entity("mdash") -> 8212;
-entity("lsquo") -> 8216;
-entity("rsquo") -> 8217;
-entity("sbquo") -> 8218;
-entity("ldquo") -> 8220;
-entity("rdquo") -> 8221;
-entity("bdquo") -> 8222;
-entity("dagger") -> 8224;
-entity("Dagger") -> 8225;
-entity("permil") -> 8240;
-entity("lsaquo") -> 8249;
-entity("rsaquo") -> 8250;
-entity("euro") -> 8364;
-entity(_) -> undefined.
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-exhaustive_entity_test() ->
- T = mochiweb_cover:clause_lookup_table(?MODULE, entity),
- [?assertEqual(V, entity(K)) || {K, V} <- T].
-
-charref_test() ->
- 1234 = charref("#1234"),
- 255 = charref("#xfF"),
- 255 = charref(<<"#XFf">>),
- 38 = charref("amp"),
- 38 = charref(<<"amp">>),
- undefined = charref("not_an_entity"),
- undefined = charref("#not_an_entity"),
- undefined = charref("#xnot_an_entity"),
- ok.
-
--endif.
diff --git a/src/mochiweb/mochiweb_cookies.erl b/src/mochiweb/mochiweb_cookies.erl
deleted file mode 100644
index c090b714..00000000
--- a/src/mochiweb/mochiweb_cookies.erl
+++ /dev/null
@@ -1,309 +0,0 @@
-%% @author Emad El-Haraty <emad@mochimedia.com>
-%% @copyright 2007 Mochi Media, Inc.
-
-%% @doc HTTP Cookie parsing and generating (RFC 2109, RFC 2965).
-
--module(mochiweb_cookies).
--export([parse_cookie/1, cookie/3, cookie/2]).
-
--define(QUOTE, $\").
-
--define(IS_WHITESPACE(C),
- (C =:= $\s orelse C =:= $\t orelse C =:= $\r orelse C =:= $\n)).
-
-%% RFC 2616 separators (called tspecials in RFC 2068)
--define(IS_SEPARATOR(C),
- (C < 32 orelse
- C =:= $\s orelse C =:= $\t orelse
- C =:= $( orelse C =:= $) orelse C =:= $< orelse C =:= $> orelse
- C =:= $@ orelse C =:= $, orelse C =:= $; orelse C =:= $: orelse
- C =:= $\\ orelse C =:= $\" orelse C =:= $/ orelse
- C =:= $[ orelse C =:= $] orelse C =:= $? orelse C =:= $= orelse
- C =:= ${ orelse C =:= $})).
-
-%% @type proplist() = [{Key::string(), Value::string()}].
-%% @type header() = {Name::string(), Value::string()}.
-
-%% @spec cookie(Key::string(), Value::string()) -> header()
-%% @doc Short-hand for <code>cookie(Key, Value, [])</code>.
-cookie(Key, Value) ->
- cookie(Key, Value, []).
-
-%% @spec cookie(Key::string(), Value::string(), Options::[Option]) -> header()
-%% where Option = {max_age, integer()} | {local_time, {date(), time()}}
-%% | {domain, string()} | {path, string()}
-%% | {secure, true | false} | {http_only, true | false}
-%%
-%% @doc Generate a Set-Cookie header field tuple.
-cookie(Key, Value, Options) ->
- Cookie = [any_to_list(Key), "=", quote(Value), "; Version=1"],
- %% Set-Cookie:
- %% Comment, Domain, Max-Age, Path, Secure, Version
- %% Set-Cookie2:
- %% Comment, CommentURL, Discard, Domain, Max-Age, Path, Port, Secure,
- %% Version
- ExpiresPart =
- case proplists:get_value(max_age, Options) of
- undefined ->
- "";
- RawAge ->
- When = case proplists:get_value(local_time, Options) of
- undefined ->
- calendar:local_time();
- LocalTime ->
- LocalTime
- end,
- Age = case RawAge < 0 of
- true ->
- 0;
- false ->
- RawAge
- end,
- ["; Expires=", age_to_cookie_date(Age, When),
- "; Max-Age=", quote(Age)]
- end,
- SecurePart =
- case proplists:get_value(secure, Options) of
- true ->
- "; Secure";
- _ ->
- ""
- end,
- DomainPart =
- case proplists:get_value(domain, Options) of
- undefined ->
- "";
- Domain ->
- ["; Domain=", quote(Domain)]
- end,
- PathPart =
- case proplists:get_value(path, Options) of
- undefined ->
- "";
- Path ->
- ["; Path=", quote(Path)]
- end,
- HttpOnlyPart =
- case proplists:get_value(http_only, Options) of
- true ->
- "; HttpOnly";
- _ ->
- ""
- end,
- CookieParts = [Cookie, ExpiresPart, SecurePart, DomainPart, PathPart, HttpOnlyPart],
- {"Set-Cookie", lists:flatten(CookieParts)}.
-
-
-%% Every major browser incorrectly handles quoted strings in a
-%% different and (worse) incompatible manner. Instead of wasting time
-%% writing redundant code for each browser, we restrict cookies to
-%% only contain characters that browsers handle compatibly.
-%%
-%% By replacing the definition of quote with this, we generate
-%% RFC-compliant cookies:
-%%
-%% quote(V) ->
-%% Fun = fun(?QUOTE, Acc) -> [$\\, ?QUOTE | Acc];
-%% (Ch, Acc) -> [Ch | Acc]
-%% end,
-%% [?QUOTE | lists:foldr(Fun, [?QUOTE], V)].
-
-%% Convert to a string and raise an error if quoting is required.
-quote(V0) ->
- V = any_to_list(V0),
- lists:all(fun(Ch) -> Ch =:= $/ orelse not ?IS_SEPARATOR(Ch) end, V)
- orelse erlang:error({cookie_quoting_required, V}),
- V.
-
-add_seconds(Secs, LocalTime) ->
- Greg = calendar:datetime_to_gregorian_seconds(LocalTime),
- calendar:gregorian_seconds_to_datetime(Greg + Secs).
-
-age_to_cookie_date(Age, LocalTime) ->
- httpd_util:rfc1123_date(add_seconds(Age, LocalTime)).
-
-%% @spec parse_cookie(string()) -> [{K::string(), V::string()}]
-%% @doc Parse the contents of a Cookie header field, ignoring cookie
-%% attributes, and return a simple property list.
-parse_cookie("") ->
- [];
-parse_cookie(Cookie) ->
- parse_cookie(Cookie, []).
-
-%% Internal API
-
-parse_cookie([], Acc) ->
- lists:reverse(Acc);
-parse_cookie(String, Acc) ->
- {{Token, Value}, Rest} = read_pair(String),
- Acc1 = case Token of
- "" ->
- Acc;
- "$" ++ _ ->
- Acc;
- _ ->
- [{Token, Value} | Acc]
- end,
- parse_cookie(Rest, Acc1).
-
-read_pair(String) ->
- {Token, Rest} = read_token(skip_whitespace(String)),
- {Value, Rest1} = read_value(skip_whitespace(Rest)),
- {{Token, Value}, skip_past_separator(Rest1)}.
-
-read_value([$= | Value]) ->
- Value1 = skip_whitespace(Value),
- case Value1 of
- [?QUOTE | _] ->
- read_quoted(Value1);
- _ ->
- read_token(Value1)
- end;
-read_value(String) ->
- {"", String}.
-
-read_quoted([?QUOTE | String]) ->
- read_quoted(String, []).
-
-read_quoted([], Acc) ->
- {lists:reverse(Acc), []};
-read_quoted([?QUOTE | Rest], Acc) ->
- {lists:reverse(Acc), Rest};
-read_quoted([$\\, Any | Rest], Acc) ->
- read_quoted(Rest, [Any | Acc]);
-read_quoted([C | Rest], Acc) ->
- read_quoted(Rest, [C | Acc]).
-
-skip_whitespace(String) ->
- F = fun (C) -> ?IS_WHITESPACE(C) end,
- lists:dropwhile(F, String).
-
-read_token(String) ->
- F = fun (C) -> not ?IS_SEPARATOR(C) end,
- lists:splitwith(F, String).
-
-skip_past_separator([]) ->
- [];
-skip_past_separator([$; | Rest]) ->
- Rest;
-skip_past_separator([$, | Rest]) ->
- Rest;
-skip_past_separator([_ | Rest]) ->
- skip_past_separator(Rest).
-
-any_to_list(V) when is_list(V) ->
- V;
-any_to_list(V) when is_atom(V) ->
- atom_to_list(V);
-any_to_list(V) when is_binary(V) ->
- binary_to_list(V);
-any_to_list(V) when is_integer(V) ->
- integer_to_list(V).
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-quote_test() ->
- %% ?assertError eunit macro is not compatible with coverage module
- try quote(":wq")
- catch error:{cookie_quoting_required, ":wq"} -> ok
- end,
- ?assertEqual(
- "foo",
- quote(foo)),
- ok.
-
-parse_cookie_test() ->
- %% RFC example
- C1 = "$Version=\"1\"; Customer=\"WILE_E_COYOTE\"; $Path=\"/acme\";
- Part_Number=\"Rocket_Launcher_0001\"; $Path=\"/acme\";
- Shipping=\"FedEx\"; $Path=\"/acme\"",
- ?assertEqual(
- [{"Customer","WILE_E_COYOTE"},
- {"Part_Number","Rocket_Launcher_0001"},
- {"Shipping","FedEx"}],
- parse_cookie(C1)),
- %% Potential edge cases
- ?assertEqual(
- [{"foo", "x"}],
- parse_cookie("foo=\"\\x\"")),
- ?assertEqual(
- [],
- parse_cookie("=")),
- ?assertEqual(
- [{"foo", ""}, {"bar", ""}],
- parse_cookie(" foo ; bar ")),
- ?assertEqual(
- [{"foo", ""}, {"bar", ""}],
- parse_cookie("foo=;bar=")),
- ?assertEqual(
- [{"foo", "\";"}, {"bar", ""}],
- parse_cookie("foo = \"\\\";\";bar ")),
- ?assertEqual(
- [{"foo", "\";bar"}],
- parse_cookie("foo=\"\\\";bar")),
- ?assertEqual(
- [],
- parse_cookie([])),
- ?assertEqual(
- [{"foo", "bar"}, {"baz", "wibble"}],
- parse_cookie("foo=bar , baz=wibble ")),
- ok.
-
-domain_test() ->
- ?assertEqual(
- {"Set-Cookie",
- "Customer=WILE_E_COYOTE; "
- "Version=1; "
- "Domain=acme.com; "
- "HttpOnly"},
- cookie("Customer", "WILE_E_COYOTE",
- [{http_only, true}, {domain, "acme.com"}])),
- ok.
-
-local_time_test() ->
- {"Set-Cookie", S} = cookie("Customer", "WILE_E_COYOTE",
- [{max_age, 111}, {secure, true}]),
- ?assertMatch(
- ["Customer=WILE_E_COYOTE",
- " Version=1",
- " Expires=" ++ _,
- " Max-Age=111",
- " Secure"],
- string:tokens(S, ";")),
- ok.
-
-cookie_test() ->
- C1 = {"Set-Cookie",
- "Customer=WILE_E_COYOTE; "
- "Version=1; "
- "Path=/acme"},
- C1 = cookie("Customer", "WILE_E_COYOTE", [{path, "/acme"}]),
- C1 = cookie("Customer", "WILE_E_COYOTE",
- [{path, "/acme"}, {badoption, "negatory"}]),
- C1 = cookie('Customer', 'WILE_E_COYOTE', [{path, '/acme'}]),
- C1 = cookie(<<"Customer">>, <<"WILE_E_COYOTE">>, [{path, <<"/acme">>}]),
-
- {"Set-Cookie","=NoKey; Version=1"} = cookie("", "NoKey", []),
- {"Set-Cookie","=NoKey; Version=1"} = cookie("", "NoKey"),
- LocalTime = calendar:universal_time_to_local_time({{2007, 5, 15}, {13, 45, 33}}),
- C2 = {"Set-Cookie",
- "Customer=WILE_E_COYOTE; "
- "Version=1; "
- "Expires=Tue, 15 May 2007 13:45:33 GMT; "
- "Max-Age=0"},
- C2 = cookie("Customer", "WILE_E_COYOTE",
- [{max_age, -111}, {local_time, LocalTime}]),
- C3 = {"Set-Cookie",
- "Customer=WILE_E_COYOTE; "
- "Version=1; "
- "Expires=Wed, 16 May 2007 13:45:50 GMT; "
- "Max-Age=86417"},
- C3 = cookie("Customer", "WILE_E_COYOTE",
- [{max_age, 86417}, {local_time, LocalTime}]),
- ok.
-
--endif.
diff --git a/src/mochiweb/mochiweb_cover.erl b/src/mochiweb/mochiweb_cover.erl
deleted file mode 100644
index 6a14ef51..00000000
--- a/src/mochiweb/mochiweb_cover.erl
+++ /dev/null
@@ -1,75 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2010 Mochi Media, Inc.
-
-%% @doc Workarounds for various cover deficiencies.
--module(mochiweb_cover).
--export([get_beam/1, get_abstract_code/1,
- get_clauses/2, clause_lookup_table/1]).
--export([clause_lookup_table/2]).
-
-%% Internal
-
-get_beam(Module) ->
- {Module, Beam, _Path} = code:get_object_code(Module),
- Beam.
-
-get_abstract_code(Beam) ->
- {ok, {_Module,
- [{abstract_code,
- {raw_abstract_v1, L}}]}} = beam_lib:chunks(Beam, [abstract_code]),
- L.
-
-get_clauses(Function, Code) ->
- [L] = [Clauses || {function, _, FName, _, Clauses}
- <- Code, FName =:= Function],
- L.
-
-clause_lookup_table(Module, Function) ->
- clause_lookup_table(
- get_clauses(Function,
- get_abstract_code(get_beam(Module)))).
-
-clause_lookup_table(Clauses) ->
- lists:foldr(fun clause_fold/2, [], Clauses).
-
-clause_fold({clause, _,
- [InTerm],
- _Guards=[],
- [OutTerm]},
- Acc) ->
- try [{erl_parse:normalise(InTerm), erl_parse:normalise(OutTerm)} | Acc]
- catch error:_ -> Acc
- end;
-clause_fold(_, Acc) ->
- Acc.
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-foo_table(a) -> b;
-foo_table("a") -> <<"b">>;
-foo_table(123) -> {4, 3, 2};
-foo_table([list]) -> [];
-foo_table([list1, list2]) -> [list1, list2, list3];
-foo_table(ignored) -> some, code, ignored;
-foo_table(Var) -> Var.
-
-foo_table_test() ->
- T = clause_lookup_table(?MODULE, foo_table),
- [?assertEqual(V, foo_table(K)) || {K, V} <- T].
-
-clause_lookup_table_test() ->
- ?assertEqual(b, foo_table(a)),
- ?assertEqual(ignored, foo_table(ignored)),
- ?assertEqual('Var', foo_table('Var')),
- ?assertEqual(
- [{a, b},
- {"a", <<"b">>},
- {123, {4, 3, 2}},
- {[list], []},
- {[list1, list2], [list1, list2, list3]}],
- clause_lookup_table(?MODULE, foo_table)).
-
--endif.
diff --git a/src/mochiweb/mochiweb_echo.erl b/src/mochiweb/mochiweb_echo.erl
deleted file mode 100644
index 6f7872b9..00000000
--- a/src/mochiweb/mochiweb_echo.erl
+++ /dev/null
@@ -1,38 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2007 Mochi Media, Inc.
-
-%% @doc Simple and stupid echo server to demo mochiweb_socket_server.
-
--module(mochiweb_echo).
--author('bob@mochimedia.com').
--export([start/0, stop/0, loop/1]).
-
-stop() ->
- mochiweb_socket_server:stop(?MODULE).
-
-start() ->
- mochiweb_socket_server:start([{name, ?MODULE},
- {port, 6789},
- {ip, "127.0.0.1"},
- {max, 1},
- {loop, {?MODULE, loop}}]).
-
-loop(Socket) ->
- case mochiweb_socket:recv(Socket, 0, 30000) of
- {ok, Data} ->
- case mochiweb_socket:send(Socket, Data) of
- ok ->
- loop(Socket);
- _ ->
- exit(normal)
- end;
- _Other ->
- exit(normal)
- end.
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
--endif.
diff --git a/src/mochiweb/mochiweb_headers.erl b/src/mochiweb/mochiweb_headers.erl
deleted file mode 100644
index 4fce9838..00000000
--- a/src/mochiweb/mochiweb_headers.erl
+++ /dev/null
@@ -1,299 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2007 Mochi Media, Inc.
-
-%% @doc Case preserving (but case insensitive) HTTP Header dictionary.
-
--module(mochiweb_headers).
--author('bob@mochimedia.com').
--export([empty/0, from_list/1, insert/3, enter/3, get_value/2, lookup/2]).
--export([delete_any/2, get_primary_value/2]).
--export([default/3, enter_from_list/2, default_from_list/2]).
--export([to_list/1, make/1]).
--export([from_binary/1]).
-
-%% @type headers().
-%% @type key() = atom() | binary() | string().
-%% @type value() = atom() | binary() | string() | integer().
-
-%% @spec empty() -> headers()
-%% @doc Create an empty headers structure.
-empty() ->
- gb_trees:empty().
-
-%% @spec make(headers() | [{key(), value()}]) -> headers()
-%% @doc Construct a headers() from the given list.
-make(L) when is_list(L) ->
- from_list(L);
-%% assume a tuple is already mochiweb_headers.
-make(T) when is_tuple(T) ->
- T.
-
-%% @spec from_binary(iolist()) -> headers()
-%% @doc Transforms a raw HTTP header into a mochiweb headers structure.
-%%
-%% The given raw HTTP header can be one of the following:
-%%
-%% 1) A string or a binary representing a full HTTP header ending with
-%% double CRLF.
-%% Examples:
-%% ```
-%% "Content-Length: 47\r\nContent-Type: text/plain\r\n\r\n"
-%% <<"Content-Length: 47\r\nContent-Type: text/plain\r\n\r\n">>'''
-%%
-%% 2) A list of binaries or strings where each element represents a raw
-%% HTTP header line ending with a single CRLF.
-%% Examples:
-%% ```
-%% [<<"Content-Length: 47\r\n">>, <<"Content-Type: text/plain\r\n">>]
-%% ["Content-Length: 47\r\n", "Content-Type: text/plain\r\n"]
-%% ["Content-Length: 47\r\n", <<"Content-Type: text/plain\r\n">>]'''
-%%
-from_binary(RawHttpHeader) when is_binary(RawHttpHeader) ->
- from_binary(RawHttpHeader, []);
-from_binary(RawHttpHeaderList) ->
- from_binary(list_to_binary([RawHttpHeaderList, "\r\n"])).
-
-from_binary(RawHttpHeader, Acc) ->
- case erlang:decode_packet(httph, RawHttpHeader, []) of
- {ok, {http_header, _, H, _, V}, Rest} ->
- from_binary(Rest, [{H, V} | Acc]);
- _ ->
- make(Acc)
- end.
-
-%% @spec from_list([{key(), value()}]) -> headers()
-%% @doc Construct a headers() from the given list.
-from_list(List) ->
- lists:foldl(fun ({K, V}, T) -> insert(K, V, T) end, empty(), List).
-
-%% @spec enter_from_list([{key(), value()}], headers()) -> headers()
-%% @doc Insert pairs into the headers, replace any values for existing keys.
-enter_from_list(List, T) ->
- lists:foldl(fun ({K, V}, T1) -> enter(K, V, T1) end, T, List).
-
-%% @spec default_from_list([{key(), value()}], headers()) -> headers()
-%% @doc Insert pairs into the headers for keys that do not already exist.
-default_from_list(List, T) ->
- lists:foldl(fun ({K, V}, T1) -> default(K, V, T1) end, T, List).
-
-%% @spec to_list(headers()) -> [{key(), string()}]
-%% @doc Return the contents of the headers. The keys will be the exact key
-%% that was first inserted (e.g. may be an atom or binary, case is
-%% preserved).
-to_list(T) ->
- F = fun ({K, {array, L}}, Acc) ->
- L1 = lists:reverse(L),
- lists:foldl(fun (V, Acc1) -> [{K, V} | Acc1] end, Acc, L1);
- (Pair, Acc) ->
- [Pair | Acc]
- end,
- lists:reverse(lists:foldl(F, [], gb_trees:values(T))).
-
-%% @spec get_value(key(), headers()) -> string() | undefined
-%% @doc Return the value of the given header using a case insensitive search.
-%% undefined will be returned for keys that are not present.
-get_value(K, T) ->
- case lookup(K, T) of
- {value, {_, V}} ->
- expand(V);
- none ->
- undefined
- end.
-
-%% @spec get_primary_value(key(), headers()) -> string() | undefined
-%% @doc Return the value of the given header up to the first semicolon using
-%% a case insensitive search. undefined will be returned for keys
-%% that are not present.
-get_primary_value(K, T) ->
- case get_value(K, T) of
- undefined ->
- undefined;
- V ->
- lists:takewhile(fun (C) -> C =/= $; end, V)
- end.
-
-%% @spec lookup(key(), headers()) -> {value, {key(), string()}} | none
-%% @doc Return the case preserved key and value for the given header using
-%% a case insensitive search. none will be returned for keys that are
-%% not present.
-lookup(K, T) ->
- case gb_trees:lookup(normalize(K), T) of
- {value, {K0, V}} ->
- {value, {K0, expand(V)}};
- none ->
- none
- end.
-
-%% @spec default(key(), value(), headers()) -> headers()
-%% @doc Insert the pair into the headers if it does not already exist.
-default(K, V, T) ->
- K1 = normalize(K),
- V1 = any_to_list(V),
- try gb_trees:insert(K1, {K, V1}, T)
- catch
- error:{key_exists, _} ->
- T
- end.
-
-%% @spec enter(key(), value(), headers()) -> headers()
-%% @doc Insert the pair into the headers, replacing any pre-existing key.
-enter(K, V, T) ->
- K1 = normalize(K),
- V1 = any_to_list(V),
- gb_trees:enter(K1, {K, V1}, T).
-
-%% @spec insert(key(), value(), headers()) -> headers()
-%% @doc Insert the pair into the headers, merging with any pre-existing key.
-%% A merge is done with Value = V0 ++ ", " ++ V1.
-insert(K, V, T) ->
- K1 = normalize(K),
- V1 = any_to_list(V),
- try gb_trees:insert(K1, {K, V1}, T)
- catch
- error:{key_exists, _} ->
- {K0, V0} = gb_trees:get(K1, T),
- V2 = merge(K1, V1, V0),
- gb_trees:update(K1, {K0, V2}, T)
- end.
-
-%% @spec delete_any(key(), headers()) -> headers()
-%% @doc Delete the header corresponding to key if it is present.
-delete_any(K, T) ->
- K1 = normalize(K),
- gb_trees:delete_any(K1, T).
-
-%% Internal API
-
-expand({array, L}) ->
- mochiweb_util:join(lists:reverse(L), ", ");
-expand(V) ->
- V.
-
-merge("set-cookie", V1, {array, L}) ->
- {array, [V1 | L]};
-merge("set-cookie", V1, V0) ->
- {array, [V1, V0]};
-merge(_, V1, V0) ->
- V0 ++ ", " ++ V1.
-
-normalize(K) when is_list(K) ->
- string:to_lower(K);
-normalize(K) when is_atom(K) ->
- normalize(atom_to_list(K));
-normalize(K) when is_binary(K) ->
- normalize(binary_to_list(K)).
-
-any_to_list(V) when is_list(V) ->
- V;
-any_to_list(V) when is_atom(V) ->
- atom_to_list(V);
-any_to_list(V) when is_binary(V) ->
- binary_to_list(V);
-any_to_list(V) when is_integer(V) ->
- integer_to_list(V).
-
-%%
-%% Tests.
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-make_test() ->
- Identity = make([{hdr, foo}]),
- ?assertEqual(
- Identity,
- make(Identity)).
-
-enter_from_list_test() ->
- H = make([{hdr, foo}]),
- ?assertEqual(
- [{baz, "wibble"}, {hdr, "foo"}],
- to_list(enter_from_list([{baz, wibble}], H))),
- ?assertEqual(
- [{hdr, "bar"}],
- to_list(enter_from_list([{hdr, bar}], H))),
- ok.
-
-default_from_list_test() ->
- H = make([{hdr, foo}]),
- ?assertEqual(
- [{baz, "wibble"}, {hdr, "foo"}],
- to_list(default_from_list([{baz, wibble}], H))),
- ?assertEqual(
- [{hdr, "foo"}],
- to_list(default_from_list([{hdr, bar}], H))),
- ok.
-
-get_primary_value_test() ->
- H = make([{hdr, foo}, {baz, <<"wibble;taco">>}]),
- ?assertEqual(
- "foo",
- get_primary_value(hdr, H)),
- ?assertEqual(
- undefined,
- get_primary_value(bar, H)),
- ?assertEqual(
- "wibble",
- get_primary_value(<<"baz">>, H)),
- ok.
-
-set_cookie_test() ->
- H = make([{"set-cookie", foo}, {"set-cookie", bar}, {"set-cookie", baz}]),
- ?assertEqual(
- [{"set-cookie", "foo"}, {"set-cookie", "bar"}, {"set-cookie", "baz"}],
- to_list(H)),
- ok.
-
-headers_test() ->
- H = ?MODULE:make([{hdr, foo}, {"Hdr", "bar"}, {'Hdr', 2}]),
- [{hdr, "foo, bar, 2"}] = ?MODULE:to_list(H),
- H1 = ?MODULE:insert(taco, grande, H),
- [{hdr, "foo, bar, 2"}, {taco, "grande"}] = ?MODULE:to_list(H1),
- H2 = ?MODULE:make([{"Set-Cookie", "foo"}]),
- [{"Set-Cookie", "foo"}] = ?MODULE:to_list(H2),
- H3 = ?MODULE:insert("Set-Cookie", "bar", H2),
- [{"Set-Cookie", "foo"}, {"Set-Cookie", "bar"}] = ?MODULE:to_list(H3),
- "foo, bar" = ?MODULE:get_value("set-cookie", H3),
- {value, {"Set-Cookie", "foo, bar"}} = ?MODULE:lookup("set-cookie", H3),
- undefined = ?MODULE:get_value("shibby", H3),
- none = ?MODULE:lookup("shibby", H3),
- H4 = ?MODULE:insert("content-type",
- "application/x-www-form-urlencoded; charset=utf8",
- H3),
- "application/x-www-form-urlencoded" = ?MODULE:get_primary_value(
- "content-type", H4),
- H4 = ?MODULE:delete_any("nonexistent-header", H4),
- H3 = ?MODULE:delete_any("content-type", H4),
- HB = <<"Content-Length: 47\r\nContent-Type: text/plain\r\n\r\n">>,
- H_HB = ?MODULE:from_binary(HB),
- H_HB = ?MODULE:from_binary(binary_to_list(HB)),
- "47" = ?MODULE:get_value("Content-Length", H_HB),
- "text/plain" = ?MODULE:get_value("Content-Type", H_HB),
- L_H_HB = ?MODULE:to_list(H_HB),
- 2 = length(L_H_HB),
- true = lists:member({'Content-Length', "47"}, L_H_HB),
- true = lists:member({'Content-Type', "text/plain"}, L_H_HB),
- HL = [ <<"Content-Length: 47\r\n">>, <<"Content-Type: text/plain\r\n">> ],
- HL2 = [ "Content-Length: 47\r\n", <<"Content-Type: text/plain\r\n">> ],
- HL3 = [ <<"Content-Length: 47\r\n">>, "Content-Type: text/plain\r\n" ],
- H_HL = ?MODULE:from_binary(HL),
- H_HL = ?MODULE:from_binary(HL2),
- H_HL = ?MODULE:from_binary(HL3),
- "47" = ?MODULE:get_value("Content-Length", H_HL),
- "text/plain" = ?MODULE:get_value("Content-Type", H_HL),
- L_H_HL = ?MODULE:to_list(H_HL),
- 2 = length(L_H_HL),
- true = lists:member({'Content-Length', "47"}, L_H_HL),
- true = lists:member({'Content-Type', "text/plain"}, L_H_HL),
- [] = ?MODULE:to_list(?MODULE:from_binary(<<>>)),
- [] = ?MODULE:to_list(?MODULE:from_binary(<<"">>)),
- [] = ?MODULE:to_list(?MODULE:from_binary(<<"\r\n">>)),
- [] = ?MODULE:to_list(?MODULE:from_binary(<<"\r\n\r\n">>)),
- [] = ?MODULE:to_list(?MODULE:from_binary("")),
- [] = ?MODULE:to_list(?MODULE:from_binary([<<>>])),
- [] = ?MODULE:to_list(?MODULE:from_binary([<<"">>])),
- [] = ?MODULE:to_list(?MODULE:from_binary([<<"\r\n">>])),
- [] = ?MODULE:to_list(?MODULE:from_binary([<<"\r\n\r\n">>])),
- ok.
-
--endif.
diff --git a/src/mochiweb/mochiweb_html.erl b/src/mochiweb/mochiweb_html.erl
deleted file mode 100644
index a15c359c..00000000
--- a/src/mochiweb/mochiweb_html.erl
+++ /dev/null
@@ -1,1061 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2007 Mochi Media, Inc.
-
-%% @doc Loosely tokenizes and generates parse trees for HTML 4.
--module(mochiweb_html).
--export([tokens/1, parse/1, parse_tokens/1, to_tokens/1, escape/1,
- escape_attr/1, to_html/1]).
-
-%% This is a macro to placate syntax highlighters..
--define(QUOTE, $\").
--define(SQUOTE, $\').
--define(ADV_COL(S, N),
- S#decoder{column=N+S#decoder.column,
- offset=N+S#decoder.offset}).
--define(INC_COL(S),
- S#decoder{column=1+S#decoder.column,
- offset=1+S#decoder.offset}).
--define(INC_LINE(S),
- S#decoder{column=1,
- line=1+S#decoder.line,
- offset=1+S#decoder.offset}).
--define(INC_CHAR(S, C),
- case C of
- $\n ->
- S#decoder{column=1,
- line=1+S#decoder.line,
- offset=1+S#decoder.offset};
- _ ->
- S#decoder{column=1+S#decoder.column,
- offset=1+S#decoder.offset}
- end).
-
--define(IS_WHITESPACE(C),
- (C =:= $\s orelse C =:= $\t orelse C =:= $\r orelse C =:= $\n)).
--define(IS_LITERAL_SAFE(C),
- ((C >= $A andalso C =< $Z) orelse (C >= $a andalso C =< $z)
- orelse (C >= $0 andalso C =< $9))).
--define(PROBABLE_CLOSE(C),
- (C =:= $> orelse ?IS_WHITESPACE(C))).
-
--record(decoder, {line=1,
- column=1,
- offset=0}).
-
-%% @type html_node() = {string(), [html_attr()], [html_node() | string()]}
-%% @type html_attr() = {string(), string()}
-%% @type html_token() = html_data() | start_tag() | end_tag() | inline_html() | html_comment() | html_doctype()
-%% @type html_data() = {data, string(), Whitespace::boolean()}
-%% @type start_tag() = {start_tag, Name, [html_attr()], Singleton::boolean()}
-%% @type end_tag() = {end_tag, Name}
-%% @type html_comment() = {comment, Comment}
-%% @type html_doctype() = {doctype, [Doctype]}
-%% @type inline_html() = {'=', iolist()}
-
-%% External API.
-
-%% @spec parse(string() | binary()) -> html_node()
-%% @doc tokenize and then transform the token stream into a HTML tree.
-parse(Input) ->
- parse_tokens(tokens(Input)).
-
-%% @spec parse_tokens([html_token()]) -> html_node()
-%% @doc Transform the output of tokens(Doc) into a HTML tree.
-parse_tokens(Tokens) when is_list(Tokens) ->
- %% Skip over doctype, processing instructions
- F = fun (X) ->
- case X of
- {start_tag, _, _, false} ->
- false;
- _ ->
- true
- end
- end,
- [{start_tag, Tag, Attrs, false} | Rest] = lists:dropwhile(F, Tokens),
- {Tree, _} = tree(Rest, [norm({Tag, Attrs})]),
- Tree.
-
-%% @spec tokens(StringOrBinary) -> [html_token()]
-%% @doc Transform the input UTF-8 HTML into a token stream.
-tokens(Input) ->
- tokens(iolist_to_binary(Input), #decoder{}, []).
-
-%% @spec to_tokens(html_node()) -> [html_token()]
-%% @doc Convert a html_node() tree to a list of tokens.
-to_tokens({Tag0}) ->
- to_tokens({Tag0, [], []});
-to_tokens(T={'=', _}) ->
- [T];
-to_tokens(T={doctype, _}) ->
- [T];
-to_tokens(T={comment, _}) ->
- [T];
-to_tokens({Tag0, Acc}) ->
- %% This is only allowed in sub-tags: {p, [{"class", "foo"}]}
- to_tokens({Tag0, [], Acc});
-to_tokens({Tag0, Attrs, Acc}) ->
- Tag = to_tag(Tag0),
- to_tokens([{Tag, Acc}], [{start_tag, Tag, Attrs, is_singleton(Tag)}]).
-
-%% @spec to_html([html_token()] | html_node()) -> iolist()
-%% @doc Convert a list of html_token() to a HTML document.
-to_html(Node) when is_tuple(Node) ->
- to_html(to_tokens(Node));
-to_html(Tokens) when is_list(Tokens) ->
- to_html(Tokens, []).
-
-%% @spec escape(string() | atom() | binary()) -> binary()
-%% @doc Escape a string such that it's safe for HTML (amp; lt; gt;).
-escape(B) when is_binary(B) ->
- escape(binary_to_list(B), []);
-escape(A) when is_atom(A) ->
- escape(atom_to_list(A), []);
-escape(S) when is_list(S) ->
- escape(S, []).
-
-%% @spec escape_attr(string() | binary() | atom() | integer() | float()) -> binary()
-%% @doc Escape a string such that it's safe for HTML attrs
-%% (amp; lt; gt; quot;).
-escape_attr(B) when is_binary(B) ->
- escape_attr(binary_to_list(B), []);
-escape_attr(A) when is_atom(A) ->
- escape_attr(atom_to_list(A), []);
-escape_attr(S) when is_list(S) ->
- escape_attr(S, []);
-escape_attr(I) when is_integer(I) ->
- escape_attr(integer_to_list(I), []);
-escape_attr(F) when is_float(F) ->
- escape_attr(mochinum:digits(F), []).
-
-to_html([], Acc) ->
- lists:reverse(Acc);
-to_html([{'=', Content} | Rest], Acc) ->
- to_html(Rest, [Content | Acc]);
-to_html([{pi, Tag, Attrs} | Rest], Acc) ->
- Open = [<<"<?">>,
- Tag,
- attrs_to_html(Attrs, []),
- <<"?>">>],
- to_html(Rest, [Open | Acc]);
-to_html([{comment, Comment} | Rest], Acc) ->
- to_html(Rest, [[<<"<!--">>, Comment, <<"-->">>] | Acc]);
-to_html([{doctype, Parts} | Rest], Acc) ->
- Inside = doctype_to_html(Parts, Acc),
- to_html(Rest, [[<<"<!DOCTYPE">>, Inside, <<">">>] | Acc]);
-to_html([{data, Data, _Whitespace} | Rest], Acc) ->
- to_html(Rest, [escape(Data) | Acc]);
-to_html([{start_tag, Tag, Attrs, Singleton} | Rest], Acc) ->
- Open = [<<"<">>,
- Tag,
- attrs_to_html(Attrs, []),
- case Singleton of
- true -> <<" />">>;
- false -> <<">">>
- end],
- to_html(Rest, [Open | Acc]);
-to_html([{end_tag, Tag} | Rest], Acc) ->
- to_html(Rest, [[<<"</">>, Tag, <<">">>] | Acc]).
-
-doctype_to_html([], Acc) ->
- lists:reverse(Acc);
-doctype_to_html([Word | Rest], Acc) ->
- case lists:all(fun (C) -> ?IS_LITERAL_SAFE(C) end,
- binary_to_list(iolist_to_binary(Word))) of
- true ->
- doctype_to_html(Rest, [[<<" ">>, Word] | Acc]);
- false ->
- doctype_to_html(Rest, [[<<" \"">>, escape_attr(Word), ?QUOTE] | Acc])
- end.
-
-attrs_to_html([], Acc) ->
- lists:reverse(Acc);
-attrs_to_html([{K, V} | Rest], Acc) ->
- attrs_to_html(Rest,
- [[<<" ">>, escape(K), <<"=\"">>,
- escape_attr(V), <<"\"">>] | Acc]).
-
-escape([], Acc) ->
- list_to_binary(lists:reverse(Acc));
-escape("<" ++ Rest, Acc) ->
- escape(Rest, lists:reverse("&lt;", Acc));
-escape(">" ++ Rest, Acc) ->
- escape(Rest, lists:reverse("&gt;", Acc));
-escape("&" ++ Rest, Acc) ->
- escape(Rest, lists:reverse("&amp;", Acc));
-escape([C | Rest], Acc) ->
- escape(Rest, [C | Acc]).
-
-escape_attr([], Acc) ->
- list_to_binary(lists:reverse(Acc));
-escape_attr("<" ++ Rest, Acc) ->
- escape_attr(Rest, lists:reverse("&lt;", Acc));
-escape_attr(">" ++ Rest, Acc) ->
- escape_attr(Rest, lists:reverse("&gt;", Acc));
-escape_attr("&" ++ Rest, Acc) ->
- escape_attr(Rest, lists:reverse("&amp;", Acc));
-escape_attr([?QUOTE | Rest], Acc) ->
- escape_attr(Rest, lists:reverse("&quot;", Acc));
-escape_attr([C | Rest], Acc) ->
- escape_attr(Rest, [C | Acc]).
-
-to_tag(A) when is_atom(A) ->
- norm(atom_to_list(A));
-to_tag(L) ->
- norm(L).
-
-to_tokens([], Acc) ->
- lists:reverse(Acc);
-to_tokens([{Tag, []} | Rest], Acc) ->
- to_tokens(Rest, [{end_tag, to_tag(Tag)} | Acc]);
-to_tokens([{Tag0, [{T0} | R1]} | Rest], Acc) ->
- %% Allow {br}
- to_tokens([{Tag0, [{T0, [], []} | R1]} | Rest], Acc);
-to_tokens([{Tag0, [T0={'=', _C0} | R1]} | Rest], Acc) ->
- %% Allow {'=', iolist()}
- to_tokens([{Tag0, R1} | Rest], [T0 | Acc]);
-to_tokens([{Tag0, [T0={comment, _C0} | R1]} | Rest], Acc) ->
- %% Allow {comment, iolist()}
- to_tokens([{Tag0, R1} | Rest], [T0 | Acc]);
-to_tokens([{Tag0, [T0={pi, _S0, _A0} | R1]} | Rest], Acc) ->
- %% Allow {pi, binary(), list()}
- to_tokens([{Tag0, R1} | Rest], [T0 | Acc]);
-to_tokens([{Tag0, [{T0, A0=[{_, _} | _]} | R1]} | Rest], Acc) ->
- %% Allow {p, [{"class", "foo"}]}
- to_tokens([{Tag0, [{T0, A0, []} | R1]} | Rest], Acc);
-to_tokens([{Tag0, [{T0, C0} | R1]} | Rest], Acc) ->
- %% Allow {p, "content"} and {p, <<"content">>}
- to_tokens([{Tag0, [{T0, [], C0} | R1]} | Rest], Acc);
-to_tokens([{Tag0, [{T0, A1, C0} | R1]} | Rest], Acc) when is_binary(C0) ->
- %% Allow {"p", [{"class", "foo"}], <<"content">>}
- to_tokens([{Tag0, [{T0, A1, binary_to_list(C0)} | R1]} | Rest], Acc);
-to_tokens([{Tag0, [{T0, A1, C0=[C | _]} | R1]} | Rest], Acc)
- when is_integer(C) ->
- %% Allow {"p", [{"class", "foo"}], "content"}
- to_tokens([{Tag0, [{T0, A1, [C0]} | R1]} | Rest], Acc);
-to_tokens([{Tag0, [{T0, A1, C1} | R1]} | Rest], Acc) ->
- %% Native {"p", [{"class", "foo"}], ["content"]}
- Tag = to_tag(Tag0),
- T1 = to_tag(T0),
- case is_singleton(norm(T1)) of
- true ->
- to_tokens([{Tag, R1} | Rest], [{start_tag, T1, A1, true} | Acc]);
- false ->
- to_tokens([{T1, C1}, {Tag, R1} | Rest],
- [{start_tag, T1, A1, false} | Acc])
- end;
-to_tokens([{Tag0, [L | R1]} | Rest], Acc) when is_list(L) ->
- %% List text
- Tag = to_tag(Tag0),
- to_tokens([{Tag, R1} | Rest], [{data, iolist_to_binary(L), false} | Acc]);
-to_tokens([{Tag0, [B | R1]} | Rest], Acc) when is_binary(B) ->
- %% Binary text
- Tag = to_tag(Tag0),
- to_tokens([{Tag, R1} | Rest], [{data, B, false} | Acc]).
-
-tokens(B, S=#decoder{offset=O}, Acc) ->
- case B of
- <<_:O/binary>> ->
- lists:reverse(Acc);
- _ ->
- {Tag, S1} = tokenize(B, S),
- case parse_flag(Tag) of
- script ->
- {Tag2, S2} = tokenize_script(B, S1),
- tokens(B, S2, [Tag2, Tag | Acc]);
- textarea ->
- {Tag2, S2} = tokenize_textarea(B, S1),
- tokens(B, S2, [Tag2, Tag | Acc]);
- none ->
- tokens(B, S1, [Tag | Acc])
- end
- end.
-
-parse_flag({start_tag, B, _, false}) ->
- case string:to_lower(binary_to_list(B)) of
- "script" ->
- script;
- "textarea" ->
- textarea;
- _ ->
- none
- end;
-parse_flag(_) ->
- none.
-
-tokenize(B, S=#decoder{offset=O}) ->
- case B of
- <<_:O/binary, "<!--", _/binary>> ->
- tokenize_comment(B, ?ADV_COL(S, 4));
- <<_:O/binary, "<!DOCTYPE", _/binary>> ->
- tokenize_doctype(B, ?ADV_COL(S, 10));
- <<_:O/binary, "<![CDATA[", _/binary>> ->
- tokenize_cdata(B, ?ADV_COL(S, 9));
- <<_:O/binary, "<?", _/binary>> ->
- {Tag, S1} = tokenize_literal(B, ?ADV_COL(S, 2)),
- {Attrs, S2} = tokenize_attributes(B, S1),
- S3 = find_qgt(B, S2),
- {{pi, Tag, Attrs}, S3};
- <<_:O/binary, "&", _/binary>> ->
- tokenize_charref(B, ?INC_COL(S));
- <<_:O/binary, "</", _/binary>> ->
- {Tag, S1} = tokenize_literal(B, ?ADV_COL(S, 2)),
- {S2, _} = find_gt(B, S1),
- {{end_tag, Tag}, S2};
- <<_:O/binary, "<", C, _/binary>> when ?IS_WHITESPACE(C) ->
- %% This isn't really strict HTML
- {{data, Data, _Whitespace}, S1} = tokenize_data(B, ?INC_COL(S)),
- {{data, <<$<, Data/binary>>, false}, S1};
- <<_:O/binary, "<", _/binary>> ->
- {Tag, S1} = tokenize_literal(B, ?INC_COL(S)),
- {Attrs, S2} = tokenize_attributes(B, S1),
- {S3, HasSlash} = find_gt(B, S2),
- Singleton = HasSlash orelse is_singleton(norm(binary_to_list(Tag))),
- {{start_tag, Tag, Attrs, Singleton}, S3};
- _ ->
- tokenize_data(B, S)
- end.
-
-tree_data([{data, Data, Whitespace} | Rest], AllWhitespace, Acc) ->
- tree_data(Rest, (Whitespace andalso AllWhitespace), [Data | Acc]);
-tree_data(Rest, AllWhitespace, Acc) ->
- {iolist_to_binary(lists:reverse(Acc)), AllWhitespace, Rest}.
-
-tree([], Stack) ->
- {destack(Stack), []};
-tree([{end_tag, Tag} | Rest], Stack) ->
- case destack(norm(Tag), Stack) of
- S when is_list(S) ->
- tree(Rest, S);
- Result ->
- {Result, []}
- end;
-tree([{start_tag, Tag, Attrs, true} | Rest], S) ->
- tree(Rest, append_stack_child(norm({Tag, Attrs}), S));
-tree([{start_tag, Tag, Attrs, false} | Rest], S) ->
- tree(Rest, stack(norm({Tag, Attrs}), S));
-tree([T={pi, _Tag, _Attrs} | Rest], S) ->
- tree(Rest, append_stack_child(T, S));
-tree([T={comment, _Comment} | Rest], S) ->
- tree(Rest, append_stack_child(T, S));
-tree(L=[{data, _Data, _Whitespace} | _], S) ->
- case tree_data(L, true, []) of
- {_, true, Rest} ->
- tree(Rest, S);
- {Data, false, Rest} ->
- tree(Rest, append_stack_child(Data, S))
- end;
-tree([{doctype, _} | Rest], Stack) ->
- tree(Rest, Stack).
-
-norm({Tag, Attrs}) ->
- {norm(Tag), [{norm(K), iolist_to_binary(V)} || {K, V} <- Attrs], []};
-norm(Tag) when is_binary(Tag) ->
- Tag;
-norm(Tag) ->
- list_to_binary(string:to_lower(Tag)).
-
-stack(T1={TN, _, _}, Stack=[{TN, _, _} | _Rest])
- when TN =:= <<"li">> orelse TN =:= <<"option">> ->
- [T1 | destack(TN, Stack)];
-stack(T1={TN0, _, _}, Stack=[{TN1, _, _} | _Rest])
- when (TN0 =:= <<"dd">> orelse TN0 =:= <<"dt">>) andalso
- (TN1 =:= <<"dd">> orelse TN1 =:= <<"dt">>) ->
- [T1 | destack(TN1, Stack)];
-stack(T1, Stack) ->
- [T1 | Stack].
-
-append_stack_child(StartTag, [{Name, Attrs, Acc} | Stack]) ->
- [{Name, Attrs, [StartTag | Acc]} | Stack].
-
-destack(TagName, Stack) when is_list(Stack) ->
- F = fun (X) ->
- case X of
- {TagName, _, _} ->
- false;
- _ ->
- true
- end
- end,
- case lists:splitwith(F, Stack) of
- {_, []} ->
- %% If we're parsing something like XML we might find
- %% a <link>tag</link> that is normally a singleton
- %% in HTML but isn't here
- case {is_singleton(TagName), Stack} of
- {true, [{T0, A0, Acc0} | Post0]} ->
- case lists:splitwith(F, Acc0) of
- {_, []} ->
- %% Actually was a singleton
- Stack;
- {Pre, [{T1, A1, []} | Post1]} ->
- [{T0, A0, [{T1, A1, lists:reverse(Pre)} | Post1]}
- | Post0]
- end;
- _ ->
- %% No match, no state change
- Stack
- end;
- {_Pre, [_T]} ->
- %% Unfurl the whole stack, we're done
- destack(Stack);
- {Pre, [T, {T0, A0, Acc0} | Post]} ->
- %% Unfurl up to the tag, then accumulate it
- [{T0, A0, [destack(Pre ++ [T]) | Acc0]} | Post]
- end.
-
-destack([{Tag, Attrs, Acc}]) ->
- {Tag, Attrs, lists:reverse(Acc)};
-destack([{T1, A1, Acc1}, {T0, A0, Acc0} | Rest]) ->
- destack([{T0, A0, [{T1, A1, lists:reverse(Acc1)} | Acc0]} | Rest]).
-
-is_singleton(<<"br">>) -> true;
-is_singleton(<<"hr">>) -> true;
-is_singleton(<<"img">>) -> true;
-is_singleton(<<"input">>) -> true;
-is_singleton(<<"base">>) -> true;
-is_singleton(<<"meta">>) -> true;
-is_singleton(<<"link">>) -> true;
-is_singleton(<<"area">>) -> true;
-is_singleton(<<"param">>) -> true;
-is_singleton(<<"col">>) -> true;
-is_singleton(_) -> false.
-
-tokenize_data(B, S=#decoder{offset=O}) ->
- tokenize_data(B, S, O, true).
-
-tokenize_data(B, S=#decoder{offset=O}, Start, Whitespace) ->
- case B of
- <<_:O/binary, C, _/binary>> when (C =/= $< andalso C =/= $&) ->
- tokenize_data(B, ?INC_CHAR(S, C), Start,
- (Whitespace andalso ?IS_WHITESPACE(C)));
- _ ->
- Len = O - Start,
- <<_:Start/binary, Data:Len/binary, _/binary>> = B,
- {{data, Data, Whitespace}, S}
- end.
-
-tokenize_attributes(B, S) ->
- tokenize_attributes(B, S, []).
-
-tokenize_attributes(B, S=#decoder{offset=O}, Acc) ->
- case B of
- <<_:O/binary>> ->
- {lists:reverse(Acc), S};
- <<_:O/binary, C, _/binary>> when (C =:= $> orelse C =:= $/) ->
- {lists:reverse(Acc), S};
- <<_:O/binary, "?>", _/binary>> ->
- {lists:reverse(Acc), S};
- <<_:O/binary, C, _/binary>> when ?IS_WHITESPACE(C) ->
- tokenize_attributes(B, ?INC_CHAR(S, C), Acc);
- _ ->
- {Attr, S1} = tokenize_literal(B, S),
- {Value, S2} = tokenize_attr_value(Attr, B, S1),
- tokenize_attributes(B, S2, [{Attr, Value} | Acc])
- end.
-
-tokenize_attr_value(Attr, B, S) ->
- S1 = skip_whitespace(B, S),
- O = S1#decoder.offset,
- case B of
- <<_:O/binary, "=", _/binary>> ->
- S2 = skip_whitespace(B, ?INC_COL(S1)),
- tokenize_word_or_literal(B, S2);
- _ ->
- {Attr, S1}
- end.
-
-skip_whitespace(B, S=#decoder{offset=O}) ->
- case B of
- <<_:O/binary, C, _/binary>> when ?IS_WHITESPACE(C) ->
- skip_whitespace(B, ?INC_CHAR(S, C));
- _ ->
- S
- end.
-
-tokenize_literal(Bin, S) ->
- tokenize_literal(Bin, S, []).
-
-tokenize_literal(Bin, S=#decoder{offset=O}, Acc) ->
- case Bin of
- <<_:O/binary, $&, _/binary>> ->
- {{data, Data, false}, S1} = tokenize_charref(Bin, ?INC_COL(S)),
- tokenize_literal(Bin, S1, [Data | Acc]);
- <<_:O/binary, C, _/binary>> when not (?IS_WHITESPACE(C)
- orelse C =:= $>
- orelse C =:= $/
- orelse C =:= $=) ->
- tokenize_literal(Bin, ?INC_COL(S), [C | Acc]);
- _ ->
- {iolist_to_binary(lists:reverse(Acc)), S}
- end.
-
-find_qgt(Bin, S=#decoder{offset=O}) ->
- case Bin of
- <<_:O/binary, "?>", _/binary>> ->
- ?ADV_COL(S, 2);
- %% tokenize_attributes takes care of this state:
- %% <<_:O/binary, C, _/binary>> ->
- %% find_qgt(Bin, ?INC_CHAR(S, C));
- <<_:O/binary>> ->
- S
- end.
-
-find_gt(Bin, S) ->
- find_gt(Bin, S, false).
-
-find_gt(Bin, S=#decoder{offset=O}, HasSlash) ->
- case Bin of
- <<_:O/binary, $/, _/binary>> ->
- find_gt(Bin, ?INC_COL(S), true);
- <<_:O/binary, $>, _/binary>> ->
- {?INC_COL(S), HasSlash};
- <<_:O/binary, C, _/binary>> ->
- find_gt(Bin, ?INC_CHAR(S, C), HasSlash);
- _ ->
- {S, HasSlash}
- end.
-
-tokenize_charref(Bin, S=#decoder{offset=O}) ->
- tokenize_charref(Bin, S, O).
-
-tokenize_charref(Bin, S=#decoder{offset=O}, Start) ->
- case Bin of
- <<_:O/binary>> ->
- <<_:Start/binary, Raw/binary>> = Bin,
- {{data, Raw, false}, S};
- <<_:O/binary, C, _/binary>> when ?IS_WHITESPACE(C)
- orelse C =:= ?SQUOTE
- orelse C =:= ?QUOTE
- orelse C =:= $/
- orelse C =:= $> ->
- Len = O - Start,
- <<_:Start/binary, Raw:Len/binary, _/binary>> = Bin,
- {{data, Raw, false}, S};
- <<_:O/binary, $;, _/binary>> ->
- Len = O - Start,
- <<_:Start/binary, Raw:Len/binary, _/binary>> = Bin,
- Data = case mochiweb_charref:charref(Raw) of
- undefined ->
- Start1 = Start - 1,
- Len1 = Len + 2,
- <<_:Start1/binary, R:Len1/binary, _/binary>> = Bin,
- R;
- Unichar ->
- mochiutf8:codepoint_to_bytes(Unichar)
- end,
- {{data, Data, false}, ?INC_COL(S)};
- _ ->
- tokenize_charref(Bin, ?INC_COL(S), Start)
- end.
-
-tokenize_doctype(Bin, S) ->
- tokenize_doctype(Bin, S, []).
-
-tokenize_doctype(Bin, S=#decoder{offset=O}, Acc) ->
- case Bin of
- <<_:O/binary>> ->
- {{doctype, lists:reverse(Acc)}, S};
- <<_:O/binary, $>, _/binary>> ->
- {{doctype, lists:reverse(Acc)}, ?INC_COL(S)};
- <<_:O/binary, C, _/binary>> when ?IS_WHITESPACE(C) ->
- tokenize_doctype(Bin, ?INC_CHAR(S, C), Acc);
- _ ->
- {Word, S1} = tokenize_word_or_literal(Bin, S),
- tokenize_doctype(Bin, S1, [Word | Acc])
- end.
-
-tokenize_word_or_literal(Bin, S=#decoder{offset=O}) ->
- case Bin of
- <<_:O/binary, C, _/binary>> when C =:= ?QUOTE orelse C =:= ?SQUOTE ->
- tokenize_word(Bin, ?INC_COL(S), C);
- <<_:O/binary, C, _/binary>> when not ?IS_WHITESPACE(C) ->
- %% Sanity check for whitespace
- tokenize_literal(Bin, S, [])
- end.
-
-tokenize_word(Bin, S, Quote) ->
- tokenize_word(Bin, S, Quote, []).
-
-tokenize_word(Bin, S=#decoder{offset=O}, Quote, Acc) ->
- case Bin of
- <<_:O/binary>> ->
- {iolist_to_binary(lists:reverse(Acc)), S};
- <<_:O/binary, Quote, _/binary>> ->
- {iolist_to_binary(lists:reverse(Acc)), ?INC_COL(S)};
- <<_:O/binary, $&, _/binary>> ->
- {{data, Data, false}, S1} = tokenize_charref(Bin, ?INC_COL(S)),
- tokenize_word(Bin, S1, Quote, [Data | Acc]);
- <<_:O/binary, C, _/binary>> ->
- tokenize_word(Bin, ?INC_CHAR(S, C), Quote, [C | Acc])
- end.
-
-tokenize_cdata(Bin, S=#decoder{offset=O}) ->
- tokenize_cdata(Bin, S, O).
-
-tokenize_cdata(Bin, S=#decoder{offset=O}, Start) ->
- case Bin of
- <<_:O/binary, "]]>", _/binary>> ->
- Len = O - Start,
- <<_:Start/binary, Raw:Len/binary, _/binary>> = Bin,
- {{data, Raw, false}, ?ADV_COL(S, 3)};
- <<_:O/binary, C, _/binary>> ->
- tokenize_cdata(Bin, ?INC_CHAR(S, C), Start);
- _ ->
- <<_:O/binary, Raw/binary>> = Bin,
- {{data, Raw, false}, S}
- end.
-
-tokenize_comment(Bin, S=#decoder{offset=O}) ->
- tokenize_comment(Bin, S, O).
-
-tokenize_comment(Bin, S=#decoder{offset=O}, Start) ->
- case Bin of
- <<_:O/binary, "-->", _/binary>> ->
- Len = O - Start,
- <<_:Start/binary, Raw:Len/binary, _/binary>> = Bin,
- {{comment, Raw}, ?ADV_COL(S, 3)};
- <<_:O/binary, C, _/binary>> ->
- tokenize_comment(Bin, ?INC_CHAR(S, C), Start);
- <<_:Start/binary, Raw/binary>> ->
- {{comment, Raw}, S}
- end.
-
-tokenize_script(Bin, S=#decoder{offset=O}) ->
- tokenize_script(Bin, S, O).
-
-tokenize_script(Bin, S=#decoder{offset=O}, Start) ->
- case Bin of
- %% Just a look-ahead, we want the end_tag separately
- <<_:O/binary, $<, $/, SS, CC, RR, II, PP, TT, ZZ, _/binary>>
- when (SS =:= $s orelse SS =:= $S) andalso
- (CC =:= $c orelse CC =:= $C) andalso
- (RR =:= $r orelse RR =:= $R) andalso
- (II =:= $i orelse II =:= $I) andalso
- (PP =:= $p orelse PP =:= $P) andalso
- (TT=:= $t orelse TT =:= $T) andalso
- ?PROBABLE_CLOSE(ZZ) ->
- Len = O - Start,
- <<_:Start/binary, Raw:Len/binary, _/binary>> = Bin,
- {{data, Raw, false}, S};
- <<_:O/binary, C, _/binary>> ->
- tokenize_script(Bin, ?INC_CHAR(S, C), Start);
- <<_:Start/binary, Raw/binary>> ->
- {{data, Raw, false}, S}
- end.
-
-tokenize_textarea(Bin, S=#decoder{offset=O}) ->
- tokenize_textarea(Bin, S, O).
-
-tokenize_textarea(Bin, S=#decoder{offset=O}, Start) ->
- case Bin of
- %% Just a look-ahead, we want the end_tag separately
- <<_:O/binary, $<, $/, TT, EE, XX, TT2, AA, RR, EE2, AA2, ZZ, _/binary>>
- when (TT =:= $t orelse TT =:= $T) andalso
- (EE =:= $e orelse EE =:= $E) andalso
- (XX =:= $x orelse XX =:= $X) andalso
- (TT2 =:= $t orelse TT2 =:= $T) andalso
- (AA =:= $a orelse AA =:= $A) andalso
- (RR =:= $r orelse RR =:= $R) andalso
- (EE2 =:= $e orelse EE2 =:= $E) andalso
- (AA2 =:= $a orelse AA2 =:= $A) andalso
- ?PROBABLE_CLOSE(ZZ) ->
- Len = O - Start,
- <<_:Start/binary, Raw:Len/binary, _/binary>> = Bin,
- {{data, Raw, false}, S};
- <<_:O/binary, C, _/binary>> ->
- tokenize_textarea(Bin, ?INC_CHAR(S, C), Start);
- <<_:Start/binary, Raw/binary>> ->
- {{data, Raw, false}, S}
- end.
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-to_html_test() ->
- ?assertEqual(
- <<"<html><head><title>hey!</title></head><body><p class=\"foo\">what's up<br /></p><div>sucka</div>RAW!<!-- comment! --></body></html>">>,
- iolist_to_binary(
- to_html({html, [],
- [{<<"head">>, [],
- [{title, <<"hey!">>}]},
- {body, [],
- [{p, [{class, foo}], [<<"what's">>, <<" up">>, {br}]},
- {'div', <<"sucka">>},
- {'=', <<"RAW!">>},
- {comment, <<" comment! ">>}]}]}))),
- ?assertEqual(
- <<"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">">>,
- iolist_to_binary(
- to_html({doctype,
- [<<"html">>, <<"PUBLIC">>,
- <<"-//W3C//DTD XHTML 1.0 Transitional//EN">>,
- <<"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">>]}))),
- ?assertEqual(
- <<"<html><?xml:namespace prefix=\"o\" ns=\"urn:schemas-microsoft-com:office:office\"?></html>">>,
- iolist_to_binary(
- to_html({<<"html">>,[],
- [{pi, <<"xml:namespace">>,
- [{<<"prefix">>,<<"o">>},
- {<<"ns">>,<<"urn:schemas-microsoft-com:office:office">>}]}]}))),
- ok.
-
-escape_test() ->
- ?assertEqual(
- <<"&amp;quot;\"word &gt;&lt;&lt;up!&amp;quot;">>,
- escape(<<"&quot;\"word ><<up!&quot;">>)),
- ?assertEqual(
- <<"&amp;quot;\"word &gt;&lt;&lt;up!&amp;quot;">>,
- escape("&quot;\"word ><<up!&quot;")),
- ?assertEqual(
- <<"&amp;quot;\"word &gt;&lt;&lt;up!&amp;quot;">>,
- escape('&quot;\"word ><<up!&quot;')),
- ok.
-
-escape_attr_test() ->
- ?assertEqual(
- <<"&amp;quot;&quot;word &gt;&lt;&lt;up!&amp;quot;">>,
- escape_attr(<<"&quot;\"word ><<up!&quot;">>)),
- ?assertEqual(
- <<"&amp;quot;&quot;word &gt;&lt;&lt;up!&amp;quot;">>,
- escape_attr("&quot;\"word ><<up!&quot;")),
- ?assertEqual(
- <<"&amp;quot;&quot;word &gt;&lt;&lt;up!&amp;quot;">>,
- escape_attr('&quot;\"word ><<up!&quot;')),
- ?assertEqual(
- <<"12345">>,
- escape_attr(12345)),
- ?assertEqual(
- <<"1.5">>,
- escape_attr(1.5)),
- ok.
-
-tokens_test() ->
- ?assertEqual(
- [{start_tag, <<"foo">>, [{<<"bar">>, <<"baz">>},
- {<<"wibble">>, <<"wibble">>},
- {<<"alice">>, <<"bob">>}], true}],
- tokens(<<"<foo bar=baz wibble='wibble' alice=\"bob\"/>">>)),
- ?assertEqual(
- [{start_tag, <<"foo">>, [{<<"bar">>, <<"baz">>},
- {<<"wibble">>, <<"wibble">>},
- {<<"alice">>, <<"bob">>}], true}],
- tokens(<<"<foo bar=baz wibble='wibble' alice=bob/>">>)),
- ?assertEqual(
- [{comment, <<"[if lt IE 7]>\n<style type=\"text/css\">\n.no_ie { display: none; }\n</style>\n<![endif]">>}],
- tokens(<<"<!--[if lt IE 7]>\n<style type=\"text/css\">\n.no_ie { display: none; }\n</style>\n<![endif]-->">>)),
- ?assertEqual(
- [{start_tag, <<"script">>, [{<<"type">>, <<"text/javascript">>}], false},
- {data, <<" A= B <= C ">>, false},
- {end_tag, <<"script">>}],
- tokens(<<"<script type=\"text/javascript\"> A= B <= C </script>">>)),
- ?assertEqual(
- [{start_tag, <<"script">>, [{<<"type">>, <<"text/javascript">>}], false},
- {data, <<" A= B <= C ">>, false},
- {end_tag, <<"script">>}],
- tokens(<<"<script type =\"text/javascript\"> A= B <= C </script>">>)),
- ?assertEqual(
- [{start_tag, <<"script">>, [{<<"type">>, <<"text/javascript">>}], false},
- {data, <<" A= B <= C ">>, false},
- {end_tag, <<"script">>}],
- tokens(<<"<script type = \"text/javascript\"> A= B <= C </script>">>)),
- ?assertEqual(
- [{start_tag, <<"script">>, [{<<"type">>, <<"text/javascript">>}], false},
- {data, <<" A= B <= C ">>, false},
- {end_tag, <<"script">>}],
- tokens(<<"<script type= \"text/javascript\"> A= B <= C </script>">>)),
- ?assertEqual(
- [{start_tag, <<"textarea">>, [], false},
- {data, <<"<html></body>">>, false},
- {end_tag, <<"textarea">>}],
- tokens(<<"<textarea><html></body></textarea>">>)),
- ?assertEqual(
- [{start_tag, <<"textarea">>, [], false},
- {data, <<"<html></body></textareaz>">>, false}],
- tokens(<<"<textarea ><html></body></textareaz>">>)),
- ?assertEqual(
- [{pi, <<"xml:namespace">>,
- [{<<"prefix">>,<<"o">>},
- {<<"ns">>,<<"urn:schemas-microsoft-com:office:office">>}]}],
- tokens(<<"<?xml:namespace prefix=\"o\" ns=\"urn:schemas-microsoft-com:office:office\"?>">>)),
- ?assertEqual(
- [{pi, <<"xml:namespace">>,
- [{<<"prefix">>,<<"o">>},
- {<<"ns">>,<<"urn:schemas-microsoft-com:office:office">>}]}],
- tokens(<<"<?xml:namespace prefix=o ns=urn:schemas-microsoft-com:office:office \n?>">>)),
- ?assertEqual(
- [{pi, <<"xml:namespace">>,
- [{<<"prefix">>,<<"o">>},
- {<<"ns">>,<<"urn:schemas-microsoft-com:office:office">>}]}],
- tokens(<<"<?xml:namespace prefix=o ns=urn:schemas-microsoft-com:office:office">>)),
- ?assertEqual(
- [{data, <<"<">>, false}],
- tokens(<<"&lt;">>)),
- ?assertEqual(
- [{data, <<"not html ">>, false},
- {data, <<"< at all">>, false}],
- tokens(<<"not html < at all">>)),
- ok.
-
-parse_test() ->
- D0 = <<"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">
-<html>
- <head>
- <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
- <title>Foo</title>
- <link rel=\"stylesheet\" type=\"text/css\" href=\"/static/rel/dojo/resources/dojo.css\" media=\"screen\">
- <link rel=\"stylesheet\" type=\"text/css\" href=\"/static/foo.css\" media=\"screen\">
- <!--[if lt IE 7]>
- <style type=\"text/css\">
- .no_ie { display: none; }
- </style>
- <![endif]-->
- <link rel=\"icon\" href=\"/static/images/favicon.ico\" type=\"image/x-icon\">
- <link rel=\"shortcut icon\" href=\"/static/images/favicon.ico\" type=\"image/x-icon\">
- </head>
- <body id=\"home\" class=\"tundra\"><![CDATA[&lt;<this<!-- is -->CDATA>&gt;]]></body>
-</html>">>,
- ?assertEqual(
- {<<"html">>, [],
- [{<<"head">>, [],
- [{<<"meta">>,
- [{<<"http-equiv">>,<<"Content-Type">>},
- {<<"content">>,<<"text/html; charset=UTF-8">>}],
- []},
- {<<"title">>,[],[<<"Foo">>]},
- {<<"link">>,
- [{<<"rel">>,<<"stylesheet">>},
- {<<"type">>,<<"text/css">>},
- {<<"href">>,<<"/static/rel/dojo/resources/dojo.css">>},
- {<<"media">>,<<"screen">>}],
- []},
- {<<"link">>,
- [{<<"rel">>,<<"stylesheet">>},
- {<<"type">>,<<"text/css">>},
- {<<"href">>,<<"/static/foo.css">>},
- {<<"media">>,<<"screen">>}],
- []},
- {comment,<<"[if lt IE 7]>\n <style type=\"text/css\">\n .no_ie { display: none; }\n </style>\n <![endif]">>},
- {<<"link">>,
- [{<<"rel">>,<<"icon">>},
- {<<"href">>,<<"/static/images/favicon.ico">>},
- {<<"type">>,<<"image/x-icon">>}],
- []},
- {<<"link">>,
- [{<<"rel">>,<<"shortcut icon">>},
- {<<"href">>,<<"/static/images/favicon.ico">>},
- {<<"type">>,<<"image/x-icon">>}],
- []}]},
- {<<"body">>,
- [{<<"id">>,<<"home">>},
- {<<"class">>,<<"tundra">>}],
- [<<"&lt;<this<!-- is -->CDATA>&gt;">>]}]},
- parse(D0)),
- ?assertEqual(
- {<<"html">>,[],
- [{pi, <<"xml:namespace">>,
- [{<<"prefix">>,<<"o">>},
- {<<"ns">>,<<"urn:schemas-microsoft-com:office:office">>}]}]},
- parse(
- <<"<html><?xml:namespace prefix=\"o\" ns=\"urn:schemas-microsoft-com:office:office\"?></html>">>)),
- ?assertEqual(
- {<<"html">>, [],
- [{<<"dd">>, [], [<<"foo">>]},
- {<<"dt">>, [], [<<"bar">>]}]},
- parse(<<"<html><dd>foo<dt>bar</html>">>)),
- %% Singleton sadness
- ?assertEqual(
- {<<"html">>, [],
- [{<<"link">>, [], []},
- <<"foo">>,
- {<<"br">>, [], []},
- <<"bar">>]},
- parse(<<"<html><link>foo<br>bar</html>">>)),
- ?assertEqual(
- {<<"html">>, [],
- [{<<"link">>, [], [<<"foo">>,
- {<<"br">>, [], []},
- <<"bar">>]}]},
- parse(<<"<html><link>foo<br>bar</link></html>">>)),
- ok.
-
-exhaustive_is_singleton_test() ->
- T = mochiweb_cover:clause_lookup_table(?MODULE, is_singleton),
- [?assertEqual(V, is_singleton(K)) || {K, V} <- T].
-
-tokenize_attributes_test() ->
- ?assertEqual(
- {<<"foo">>,
- [{<<"bar">>, <<"b\"az">>},
- {<<"wibble">>, <<"wibble">>},
- {<<"taco", 16#c2, 16#a9>>, <<"bell">>},
- {<<"quux">>, <<"quux">>}],
- []},
- parse(<<"<foo bar=\"b&quot;az\" wibble taco&copy;=bell quux">>)),
- ok.
-
-tokens2_test() ->
- D0 = <<"<channel><title>from __future__ import *</title><link>http://bob.pythonmac.org</link><description>Bob's Rants</description></channel>">>,
- ?assertEqual(
- [{start_tag,<<"channel">>,[],false},
- {start_tag,<<"title">>,[],false},
- {data,<<"from __future__ import *">>,false},
- {end_tag,<<"title">>},
- {start_tag,<<"link">>,[],true},
- {data,<<"http://bob.pythonmac.org">>,false},
- {end_tag,<<"link">>},
- {start_tag,<<"description">>,[],false},
- {data,<<"Bob's Rants">>,false},
- {end_tag,<<"description">>},
- {end_tag,<<"channel">>}],
- tokens(D0)),
- ok.
-
-to_tokens_test() ->
- ?assertEqual(
- [{start_tag, <<"p">>, [{class, 1}], false},
- {end_tag, <<"p">>}],
- to_tokens({p, [{class, 1}], []})),
- ?assertEqual(
- [{start_tag, <<"p">>, [], false},
- {end_tag, <<"p">>}],
- to_tokens({p})),
- ?assertEqual(
- [{'=', <<"data">>}],
- to_tokens({'=', <<"data">>})),
- ?assertEqual(
- [{comment, <<"comment">>}],
- to_tokens({comment, <<"comment">>})),
- %% This is only allowed in sub-tags:
- %% {p, [{"class", "foo"}]} as {p, [{"class", "foo"}], []}
- %% On the outside it's always treated as follows:
- %% {p, [], [{"class", "foo"}]} as {p, [], [{"class", "foo"}]}
- ?assertEqual(
- [{start_tag, <<"html">>, [], false},
- {start_tag, <<"p">>, [{class, 1}], false},
- {end_tag, <<"p">>},
- {end_tag, <<"html">>}],
- to_tokens({html, [{p, [{class, 1}]}]})),
- ok.
-
-parse2_test() ->
- D0 = <<"<channel><title>from __future__ import *</title><link>http://bob.pythonmac.org<br>foo</link><description>Bob's Rants</description></channel>">>,
- ?assertEqual(
- {<<"channel">>,[],
- [{<<"title">>,[],[<<"from __future__ import *">>]},
- {<<"link">>,[],[
- <<"http://bob.pythonmac.org">>,
- {<<"br">>,[],[]},
- <<"foo">>]},
- {<<"description">>,[],[<<"Bob's Rants">>]}]},
- parse(D0)),
- ok.
-
-parse_tokens_test() ->
- D0 = [{doctype,[<<"HTML">>,<<"PUBLIC">>,<<"-//W3C//DTD HTML 4.01 Transitional//EN">>]},
- {data,<<"\n">>,true},
- {start_tag,<<"html">>,[],false}],
- ?assertEqual(
- {<<"html">>, [], []},
- parse_tokens(D0)),
- D1 = D0 ++ [{end_tag, <<"html">>}],
- ?assertEqual(
- {<<"html">>, [], []},
- parse_tokens(D1)),
- D2 = D0 ++ [{start_tag, <<"body">>, [], false}],
- ?assertEqual(
- {<<"html">>, [], [{<<"body">>, [], []}]},
- parse_tokens(D2)),
- D3 = D0 ++ [{start_tag, <<"head">>, [], false},
- {end_tag, <<"head">>},
- {start_tag, <<"body">>, [], false}],
- ?assertEqual(
- {<<"html">>, [], [{<<"head">>, [], []}, {<<"body">>, [], []}]},
- parse_tokens(D3)),
- D4 = D3 ++ [{data,<<"\n">>,true},
- {start_tag,<<"div">>,[{<<"class">>,<<"a">>}],false},
- {start_tag,<<"a">>,[{<<"name">>,<<"#anchor">>}],false},
- {end_tag,<<"a">>},
- {end_tag,<<"div">>},
- {start_tag,<<"div">>,[{<<"class">>,<<"b">>}],false},
- {start_tag,<<"div">>,[{<<"class">>,<<"c">>}],false},
- {end_tag,<<"div">>},
- {end_tag,<<"div">>}],
- ?assertEqual(
- {<<"html">>, [],
- [{<<"head">>, [], []},
- {<<"body">>, [],
- [{<<"div">>, [{<<"class">>, <<"a">>}], [{<<"a">>, [{<<"name">>, <<"#anchor">>}], []}]},
- {<<"div">>, [{<<"class">>, <<"b">>}], [{<<"div">>, [{<<"class">>, <<"c">>}], []}]}
- ]}]},
- parse_tokens(D4)),
- D5 = [{start_tag,<<"html">>,[],false},
- {data,<<"\n">>,true},
- {data,<<"boo">>,false},
- {data,<<"hoo">>,false},
- {data,<<"\n">>,true},
- {end_tag,<<"html">>}],
- ?assertEqual(
- {<<"html">>, [], [<<"\nboohoo\n">>]},
- parse_tokens(D5)),
- D6 = [{start_tag,<<"html">>,[],false},
- {data,<<"\n">>,true},
- {data,<<"\n">>,true},
- {end_tag,<<"html">>}],
- ?assertEqual(
- {<<"html">>, [], []},
- parse_tokens(D6)),
- D7 = [{start_tag,<<"html">>,[],false},
- {start_tag,<<"ul">>,[],false},
- {start_tag,<<"li">>,[],false},
- {data,<<"word">>,false},
- {start_tag,<<"li">>,[],false},
- {data,<<"up">>,false},
- {end_tag,<<"li">>},
- {start_tag,<<"li">>,[],false},
- {data,<<"fdsa">>,false},
- {start_tag,<<"br">>,[],true},
- {data,<<"asdf">>,false},
- {end_tag,<<"ul">>},
- {end_tag,<<"html">>}],
- ?assertEqual(
- {<<"html">>, [],
- [{<<"ul">>, [],
- [{<<"li">>, [], [<<"word">>]},
- {<<"li">>, [], [<<"up">>]},
- {<<"li">>, [], [<<"fdsa">>,{<<"br">>, [], []}, <<"asdf">>]}]}]},
- parse_tokens(D7)),
- ok.
-
-destack_test() ->
- {<<"a">>, [], []} =
- destack([{<<"a">>, [], []}]),
- {<<"a">>, [], [{<<"b">>, [], []}]} =
- destack([{<<"b">>, [], []}, {<<"a">>, [], []}]),
- {<<"a">>, [], [{<<"b">>, [], [{<<"c">>, [], []}]}]} =
- destack([{<<"c">>, [], []}, {<<"b">>, [], []}, {<<"a">>, [], []}]),
- [{<<"a">>, [], [{<<"b">>, [], [{<<"c">>, [], []}]}]}] =
- destack(<<"b">>,
- [{<<"c">>, [], []}, {<<"b">>, [], []}, {<<"a">>, [], []}]),
- [{<<"b">>, [], [{<<"c">>, [], []}]}, {<<"a">>, [], []}] =
- destack(<<"c">>,
- [{<<"c">>, [], []}, {<<"b">>, [], []},{<<"a">>, [], []}]),
- ok.
-
-doctype_test() ->
- ?assertEqual(
- {<<"html">>,[],[{<<"head">>,[],[]}]},
- mochiweb_html:parse("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
- "<html><head></head></body></html>")),
- %% http://code.google.com/p/mochiweb/issues/detail?id=52
- ?assertEqual(
- {<<"html">>,[],[{<<"head">>,[],[]}]},
- mochiweb_html:parse("<html>"
- "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
- "<head></head></body></html>")),
- ok.
-
--endif.
diff --git a/src/mochiweb/mochiweb_http.erl b/src/mochiweb/mochiweb_http.erl
deleted file mode 100644
index ab0af7e8..00000000
--- a/src/mochiweb/mochiweb_http.erl
+++ /dev/null
@@ -1,273 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2007 Mochi Media, Inc.
-
-%% @doc HTTP server.
-
--module(mochiweb_http).
--author('bob@mochimedia.com').
--export([start/0, start/1, stop/0, stop/1]).
--export([loop/2, default_body/1]).
--export([after_response/2, reentry/1]).
--export([parse_range_request/1, range_skip_length/2]).
-
--define(REQUEST_RECV_TIMEOUT, 300000). % timeout waiting for request line
--define(HEADERS_RECV_TIMEOUT, 30000). % timeout waiting for headers
-
--define(MAX_HEADERS, 1000).
--define(DEFAULTS, [{name, ?MODULE},
- {port, 8888}]).
-
-parse_options(Options) ->
- {loop, HttpLoop} = proplists:lookup(loop, Options),
- Loop = fun (S) ->
- ?MODULE:loop(S, HttpLoop)
- end,
- Options1 = [{loop, Loop} | proplists:delete(loop, Options)],
- mochilists:set_defaults(?DEFAULTS, Options1).
-
-stop() ->
- mochiweb_socket_server:stop(?MODULE).
-
-stop(Name) ->
- mochiweb_socket_server:stop(Name).
-
-start() ->
- start([{ip, "127.0.0.1"},
- {loop, {?MODULE, default_body}}]).
-
-start(Options) ->
- mochiweb_socket_server:start(parse_options(Options)).
-
-frm(Body) ->
- ["<html><head></head><body>"
- "<form method=\"POST\">"
- "<input type=\"hidden\" value=\"message\" name=\"hidden\"/>"
- "<input type=\"submit\" value=\"regular POST\">"
- "</form>"
- "<br />"
- "<form method=\"POST\" enctype=\"multipart/form-data\""
- " action=\"/multipart\">"
- "<input type=\"hidden\" value=\"multipart message\" name=\"hidden\"/>"
- "<input type=\"file\" name=\"file\"/>"
- "<input type=\"submit\" value=\"multipart POST\" />"
- "</form>"
- "<pre>", Body, "</pre>"
- "</body></html>"].
-
-default_body(Req, M, "/chunked") when M =:= 'GET'; M =:= 'HEAD' ->
- Res = Req:ok({"text/plain", [], chunked}),
- Res:write_chunk("First chunk\r\n"),
- timer:sleep(5000),
- Res:write_chunk("Last chunk\r\n"),
- Res:write_chunk("");
-default_body(Req, M, _Path) when M =:= 'GET'; M =:= 'HEAD' ->
- Body = io_lib:format("~p~n", [[{parse_qs, Req:parse_qs()},
- {parse_cookie, Req:parse_cookie()},
- Req:dump()]]),
- Req:ok({"text/html",
- [mochiweb_cookies:cookie("mochiweb_http", "test_cookie")],
- frm(Body)});
-default_body(Req, 'POST', "/multipart") ->
- Body = io_lib:format("~p~n", [[{parse_qs, Req:parse_qs()},
- {parse_cookie, Req:parse_cookie()},
- {body, Req:recv_body()},
- Req:dump()]]),
- Req:ok({"text/html", [], frm(Body)});
-default_body(Req, 'POST', _Path) ->
- Body = io_lib:format("~p~n", [[{parse_qs, Req:parse_qs()},
- {parse_cookie, Req:parse_cookie()},
- {parse_post, Req:parse_post()},
- Req:dump()]]),
- Req:ok({"text/html", [], frm(Body)});
-default_body(Req, _Method, _Path) ->
- Req:respond({501, [], []}).
-
-default_body(Req) ->
- default_body(Req, Req:get(method), Req:get(path)).
-
-loop(Socket, Body) ->
- mochiweb_socket:setopts(Socket, [{packet, http}]),
- request(Socket, Body).
-
-request(Socket, Body) ->
- case mochiweb_socket:recv(Socket, 0, ?REQUEST_RECV_TIMEOUT) of
- {ok, {http_request, Method, Path, Version}} ->
- mochiweb_socket:setopts(Socket, [{packet, httph}]),
- headers(Socket, {Method, Path, Version}, [], Body, 0);
- {error, {http_error, "\r\n"}} ->
- request(Socket, Body);
- {error, {http_error, "\n"}} ->
- request(Socket, Body);
- {error, closed} ->
- mochiweb_socket:close(Socket),
- exit(normal);
- {error, timeout} ->
- mochiweb_socket:close(Socket),
- exit(normal);
- _Other ->
- handle_invalid_request(Socket)
- end.
-
-reentry(Body) ->
- fun (Req) ->
- ?MODULE:after_response(Body, Req)
- end.
-
-headers(Socket, Request, Headers, _Body, ?MAX_HEADERS) ->
- %% Too many headers sent, bad request.
- mochiweb_socket:setopts(Socket, [{packet, raw}]),
- handle_invalid_request(Socket, Request, Headers);
-headers(Socket, Request, Headers, Body, HeaderCount) ->
- case mochiweb_socket:recv(Socket, 0, ?HEADERS_RECV_TIMEOUT) of
- {ok, http_eoh} ->
- mochiweb_socket:setopts(Socket, [{packet, raw}]),
- Req = mochiweb:new_request({Socket, Request,
- lists:reverse(Headers)}),
- call_body(Body, Req),
- ?MODULE:after_response(Body, Req);
- {ok, {http_header, _, Name, _, Value}} ->
- headers(Socket, Request, [{Name, Value} | Headers], Body,
- 1 + HeaderCount);
- {error, closed} ->
- mochiweb_socket:close(Socket),
- exit(normal);
- _Other ->
- handle_invalid_request(Socket, Request, Headers)
- end.
-
-call_body({M, F}, Req) ->
- M:F(Req);
-call_body(Body, Req) ->
- Body(Req).
-
-handle_invalid_request(Socket) ->
- handle_invalid_request(Socket, {'GET', {abs_path, "/"}, {0,9}}, []).
-
-handle_invalid_request(Socket, Request, RevHeaders) ->
- mochiweb_socket:setopts(Socket, [{packet, raw}]),
- Req = mochiweb:new_request({Socket, Request,
- lists:reverse(RevHeaders)}),
- Req:respond({400, [], []}),
- mochiweb_socket:close(Socket),
- exit(normal).
-
-after_response(Body, Req) ->
- Socket = Req:get(socket),
- case Req:should_close() of
- true ->
- mochiweb_socket:close(Socket),
- exit(normal);
- false ->
- Req:cleanup(),
- ?MODULE:loop(Socket, Body)
- end.
-
-parse_range_request(RawRange) when is_list(RawRange) ->
- try
- "bytes=" ++ RangeString = RawRange,
- Ranges = string:tokens(RangeString, ","),
- lists:map(fun ("-" ++ V) ->
- {none, list_to_integer(V)};
- (R) ->
- case string:tokens(R, "-") of
- [S1, S2] ->
- {list_to_integer(S1), list_to_integer(S2)};
- [S] ->
- {list_to_integer(S), none}
- end
- end,
- Ranges)
- catch
- _:_ ->
- fail
- end.
-
-range_skip_length(Spec, Size) ->
- case Spec of
- {none, R} when R =< Size, R >= 0 ->
- {Size - R, R};
- {none, _OutOfRange} ->
- {0, Size};
- {R, none} when R >= 0, R < Size ->
- {R, Size - R};
- {_OutOfRange, none} ->
- invalid_range;
- {Start, End} when 0 =< Start, Start =< End, End < Size ->
- {Start, End - Start + 1};
- {_OutOfRange, _End} ->
- invalid_range
- end.
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-range_test() ->
- %% valid, single ranges
- ?assertEqual([{20, 30}], parse_range_request("bytes=20-30")),
- ?assertEqual([{20, none}], parse_range_request("bytes=20-")),
- ?assertEqual([{none, 20}], parse_range_request("bytes=-20")),
-
- %% trivial single range
- ?assertEqual(undefined, parse_range_request("bytes=0-")),
-
- %% invalid, single ranges
- ?assertEqual(fail, parse_range_request("")),
- ?assertEqual(fail, parse_range_request("garbage")),
- ?assertEqual(fail, parse_range_request("bytes=-20-30")),
-
- %% valid, multiple range
- ?assertEqual(
- [{20, 30}, {50, 100}, {110, 200}],
- parse_range_request("bytes=20-30,50-100,110-200")),
- ?assertEqual(
- [{20, none}, {50, 100}, {none, 200}],
- parse_range_request("bytes=20-,50-100,-200")),
-
- %% no ranges
- ?assertEqual([], parse_range_request("bytes=")),
- ok.
-
-range_skip_length_test() ->
- Body = <<"012345678901234567890123456789012345678901234567890123456789">>,
- BodySize = byte_size(Body), %% 60
- BodySize = 60,
-
- %% these values assume BodySize =:= 60
- ?assertEqual({1,9}, range_skip_length({1,9}, BodySize)), %% 1-9
- ?assertEqual({10,10}, range_skip_length({10,19}, BodySize)), %% 10-19
- ?assertEqual({40, 20}, range_skip_length({none, 20}, BodySize)), %% -20
- ?assertEqual({30, 30}, range_skip_length({30, none}, BodySize)), %% 30-
-
- %% valid edge cases for range_skip_length
- ?assertEqual({BodySize, 0}, range_skip_length({none, 0}, BodySize)),
- ?assertEqual({0, BodySize}, range_skip_length({none, BodySize}, BodySize)),
- ?assertEqual({0, BodySize}, range_skip_length({0, none}, BodySize)),
- BodySizeLess1 = BodySize - 1,
- ?assertEqual({BodySizeLess1, 1},
- range_skip_length({BodySize - 1, none}, BodySize)),
-
- %% out of range, return whole thing
- ?assertEqual({0, BodySize},
- range_skip_length({none, BodySize + 1}, BodySize)),
- ?assertEqual({0, BodySize},
- range_skip_length({none, -1}, BodySize)),
-
- %% invalid ranges
- ?assertEqual(invalid_range,
- range_skip_length({-1, 30}, BodySize)),
- ?assertEqual(invalid_range,
- range_skip_length({0, BodySize + 1}, BodySize)),
- ?assertEqual(invalid_range,
- range_skip_length({-1, BodySize + 1}, BodySize)),
- ?assertEqual(invalid_range,
- range_skip_length({BodySize, 40}, BodySize)),
- ?assertEqual(invalid_range,
- range_skip_length({-1, none}, BodySize)),
- ?assertEqual(invalid_range,
- range_skip_length({BodySize, none}, BodySize)),
- ok.
-
--endif.
diff --git a/src/mochiweb/mochiweb_io.erl b/src/mochiweb/mochiweb_io.erl
deleted file mode 100644
index 6ce57ec8..00000000
--- a/src/mochiweb/mochiweb_io.erl
+++ /dev/null
@@ -1,46 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2007 Mochi Media, Inc.
-
-%% @doc Utilities for dealing with IO devices (open files).
-
--module(mochiweb_io).
--author('bob@mochimedia.com').
-
--export([iodevice_stream/3, iodevice_stream/2]).
--export([iodevice_foldl/4, iodevice_foldl/3]).
--export([iodevice_size/1]).
--define(READ_SIZE, 8192).
-
-iodevice_foldl(F, Acc, IoDevice) ->
- iodevice_foldl(F, Acc, IoDevice, ?READ_SIZE).
-
-iodevice_foldl(F, Acc, IoDevice, BufferSize) ->
- case file:read(IoDevice, BufferSize) of
- eof ->
- Acc;
- {ok, Data} ->
- iodevice_foldl(F, F(Data, Acc), IoDevice, BufferSize)
- end.
-
-iodevice_stream(Callback, IoDevice) ->
- iodevice_stream(Callback, IoDevice, ?READ_SIZE).
-
-iodevice_stream(Callback, IoDevice, BufferSize) ->
- F = fun (Data, ok) -> Callback(Data) end,
- ok = iodevice_foldl(F, ok, IoDevice, BufferSize).
-
-iodevice_size(IoDevice) ->
- {ok, Size} = file:position(IoDevice, eof),
- {ok, 0} = file:position(IoDevice, bof),
- Size.
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-
-
--endif.
diff --git a/src/mochiweb/mochiweb_mime.erl b/src/mochiweb/mochiweb_mime.erl
deleted file mode 100644
index 5344aee7..00000000
--- a/src/mochiweb/mochiweb_mime.erl
+++ /dev/null
@@ -1,94 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2007 Mochi Media, Inc.
-
-%% @doc Gives a good MIME type guess based on file extension.
-
--module(mochiweb_mime).
--author('bob@mochimedia.com').
--export([from_extension/1]).
-
-%% @spec from_extension(S::string()) -> string() | undefined
-%% @doc Given a filename extension (e.g. ".html") return a guess for the MIME
-%% type such as "text/html". Will return the atom undefined if no good
-%% guess is available.
-from_extension(".html") ->
- "text/html";
-from_extension(".xhtml") ->
- "application/xhtml+xml";
-from_extension(".xml") ->
- "application/xml";
-from_extension(".css") ->
- "text/css";
-from_extension(".js") ->
- "application/x-javascript";
-from_extension(".jpg") ->
- "image/jpeg";
-from_extension(".gif") ->
- "image/gif";
-from_extension(".png") ->
- "image/png";
-from_extension(".swf") ->
- "application/x-shockwave-flash";
-from_extension(".zip") ->
- "application/zip";
-from_extension(".bz2") ->
- "application/x-bzip2";
-from_extension(".gz") ->
- "application/x-gzip";
-from_extension(".tar") ->
- "application/x-tar";
-from_extension(".tgz") ->
- "application/x-gzip";
-from_extension(".txt") ->
- "text/plain";
-from_extension(".doc") ->
- "application/msword";
-from_extension(".pdf") ->
- "application/pdf";
-from_extension(".xls") ->
- "application/vnd.ms-excel";
-from_extension(".rtf") ->
- "application/rtf";
-from_extension(".mov") ->
- "video/quicktime";
-from_extension(".mp3") ->
- "audio/mpeg";
-from_extension(".z") ->
- "application/x-compress";
-from_extension(".wav") ->
- "audio/x-wav";
-from_extension(".ico") ->
- "image/x-icon";
-from_extension(".bmp") ->
- "image/bmp";
-from_extension(".m4a") ->
- "audio/mpeg";
-from_extension(".m3u") ->
- "audio/x-mpegurl";
-from_extension(".exe") ->
- "application/octet-stream";
-from_extension(".csv") ->
- "text/csv";
-from_extension(_) ->
- undefined.
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-exhaustive_from_extension_test() ->
- T = mochiweb_cover:clause_lookup_table(?MODULE, from_extension),
- [?assertEqual(V, from_extension(K)) || {K, V} <- T].
-
-from_extension_test() ->
- ?assertEqual("text/html",
- from_extension(".html")),
- ?assertEqual(undefined,
- from_extension("")),
- ?assertEqual(undefined,
- from_extension(".wtf")),
- ok.
-
--endif.
diff --git a/src/mochiweb/mochiweb_multipart.erl b/src/mochiweb/mochiweb_multipart.erl
deleted file mode 100644
index 3069cf4d..00000000
--- a/src/mochiweb/mochiweb_multipart.erl
+++ /dev/null
@@ -1,824 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2007 Mochi Media, Inc.
-
-%% @doc Utilities for parsing multipart/form-data.
-
--module(mochiweb_multipart).
--author('bob@mochimedia.com').
-
--export([parse_form/1, parse_form/2]).
--export([parse_multipart_request/2]).
--export([parts_to_body/3, parts_to_multipart_body/4]).
--export([default_file_handler/2]).
-
--define(CHUNKSIZE, 4096).
-
--record(mp, {state, boundary, length, buffer, callback, req}).
-
-%% TODO: DOCUMENT THIS MODULE.
-%% @type key() = atom() | string() | binary().
-%% @type value() = atom() | iolist() | integer().
-%% @type header() = {key(), value()}.
-%% @type bodypart() = {Start::integer(), End::integer(), Body::iolist()}.
-%% @type formfile() = {Name::string(), ContentType::string(), Content::binary()}.
-%% @type request().
-%% @type file_handler() = (Filename::string(), ContentType::string()) -> file_handler_callback().
-%% @type file_handler_callback() = (binary() | eof) -> file_handler_callback() | term().
-
-%% @spec parts_to_body([bodypart()], ContentType::string(),
-%% Size::integer()) -> {[header()], iolist()}
-%% @doc Return {[header()], iolist()} representing the body for the given
-%% parts, may be a single part or multipart.
-parts_to_body([{Start, End, Body}], ContentType, Size) ->
- HeaderList = [{"Content-Type", ContentType},
- {"Content-Range",
- ["bytes ",
- mochiweb_util:make_io(Start), "-", mochiweb_util:make_io(End),
- "/", mochiweb_util:make_io(Size)]}],
- {HeaderList, Body};
-parts_to_body(BodyList, ContentType, Size) when is_list(BodyList) ->
- parts_to_multipart_body(BodyList, ContentType, Size,
- mochihex:to_hex(crypto:rand_bytes(8))).
-
-%% @spec parts_to_multipart_body([bodypart()], ContentType::string(),
-%% Size::integer(), Boundary::string()) ->
-%% {[header()], iolist()}
-%% @doc Return {[header()], iolist()} representing the body for the given
-%% parts, always a multipart response.
-parts_to_multipart_body(BodyList, ContentType, Size, Boundary) ->
- HeaderList = [{"Content-Type",
- ["multipart/byteranges; ",
- "boundary=", Boundary]}],
- MultiPartBody = multipart_body(BodyList, ContentType, Boundary, Size),
-
- {HeaderList, MultiPartBody}.
-
-%% @spec multipart_body([bodypart()], ContentType::string(),
-%% Boundary::string(), Size::integer()) -> iolist()
-%% @doc Return the representation of a multipart body for the given [bodypart()].
-multipart_body([], _ContentType, Boundary, _Size) ->
- ["--", Boundary, "--\r\n"];
-multipart_body([{Start, End, Body} | BodyList], ContentType, Boundary, Size) ->
- ["--", Boundary, "\r\n",
- "Content-Type: ", ContentType, "\r\n",
- "Content-Range: ",
- "bytes ", mochiweb_util:make_io(Start), "-", mochiweb_util:make_io(End),
- "/", mochiweb_util:make_io(Size), "\r\n\r\n",
- Body, "\r\n"
- | multipart_body(BodyList, ContentType, Boundary, Size)].
-
-%% @spec parse_form(request()) -> [{string(), string() | formfile()}]
-%% @doc Parse a multipart form from the given request using the in-memory
-%% default_file_handler/2.
-parse_form(Req) ->
- parse_form(Req, fun default_file_handler/2).
-
-%% @spec parse_form(request(), F::file_handler()) -> [{string(), string() | term()}]
-%% @doc Parse a multipart form from the given request using the given file_handler().
-parse_form(Req, FileHandler) ->
- Callback = fun (Next) -> parse_form_outer(Next, FileHandler, []) end,
- {_, _, Res} = parse_multipart_request(Req, Callback),
- Res.
-
-parse_form_outer(eof, _, Acc) ->
- lists:reverse(Acc);
-parse_form_outer({headers, H}, FileHandler, State) ->
- {"form-data", H1} = proplists:get_value("content-disposition", H),
- Name = proplists:get_value("name", H1),
- Filename = proplists:get_value("filename", H1),
- case Filename of
- undefined ->
- fun (Next) ->
- parse_form_value(Next, {Name, []}, FileHandler, State)
- end;
- _ ->
- ContentType = proplists:get_value("content-type", H),
- Handler = FileHandler(Filename, ContentType),
- fun (Next) ->
- parse_form_file(Next, {Name, Handler}, FileHandler, State)
- end
- end.
-
-parse_form_value(body_end, {Name, Acc}, FileHandler, State) ->
- Value = binary_to_list(iolist_to_binary(lists:reverse(Acc))),
- State1 = [{Name, Value} | State],
- fun (Next) -> parse_form_outer(Next, FileHandler, State1) end;
-parse_form_value({body, Data}, {Name, Acc}, FileHandler, State) ->
- Acc1 = [Data | Acc],
- fun (Next) -> parse_form_value(Next, {Name, Acc1}, FileHandler, State) end.
-
-parse_form_file(body_end, {Name, Handler}, FileHandler, State) ->
- Value = Handler(eof),
- State1 = [{Name, Value} | State],
- fun (Next) -> parse_form_outer(Next, FileHandler, State1) end;
-parse_form_file({body, Data}, {Name, Handler}, FileHandler, State) ->
- H1 = Handler(Data),
- fun (Next) -> parse_form_file(Next, {Name, H1}, FileHandler, State) end.
-
-default_file_handler(Filename, ContentType) ->
- default_file_handler_1(Filename, ContentType, []).
-
-default_file_handler_1(Filename, ContentType, Acc) ->
- fun(eof) ->
- Value = iolist_to_binary(lists:reverse(Acc)),
- {Filename, ContentType, Value};
- (Next) ->
- default_file_handler_1(Filename, ContentType, [Next | Acc])
- end.
-
-parse_multipart_request(Req, Callback) ->
- %% TODO: Support chunked?
- Length = list_to_integer(Req:get_header_value("content-length")),
- Boundary = iolist_to_binary(
- get_boundary(Req:get_header_value("content-type"))),
- Prefix = <<"\r\n--", Boundary/binary>>,
- BS = byte_size(Boundary),
- Chunk = read_chunk(Req, Length),
- Length1 = Length - byte_size(Chunk),
- <<"--", Boundary:BS/binary, "\r\n", Rest/binary>> = Chunk,
- feed_mp(headers, flash_multipart_hack(#mp{boundary=Prefix,
- length=Length1,
- buffer=Rest,
- callback=Callback,
- req=Req})).
-
-parse_headers(<<>>) ->
- [];
-parse_headers(Binary) ->
- parse_headers(Binary, []).
-
-parse_headers(Binary, Acc) ->
- case find_in_binary(<<"\r\n">>, Binary) of
- {exact, N} ->
- <<Line:N/binary, "\r\n", Rest/binary>> = Binary,
- parse_headers(Rest, [split_header(Line) | Acc]);
- not_found ->
- lists:reverse([split_header(Binary) | Acc])
- end.
-
-split_header(Line) ->
- {Name, [$: | Value]} = lists:splitwith(fun (C) -> C =/= $: end,
- binary_to_list(Line)),
- {string:to_lower(string:strip(Name)),
- mochiweb_util:parse_header(Value)}.
-
-read_chunk(Req, Length) when Length > 0 ->
- case Length of
- Length when Length < ?CHUNKSIZE ->
- Req:recv(Length);
- _ ->
- Req:recv(?CHUNKSIZE)
- end.
-
-read_more(State=#mp{length=Length, buffer=Buffer, req=Req}) ->
- Data = read_chunk(Req, Length),
- Buffer1 = <<Buffer/binary, Data/binary>>,
- flash_multipart_hack(State#mp{length=Length - byte_size(Data),
- buffer=Buffer1}).
-
-flash_multipart_hack(State=#mp{length=0, buffer=Buffer, boundary=Prefix}) ->
- %% http://code.google.com/p/mochiweb/issues/detail?id=22
- %% Flash doesn't terminate multipart with \r\n properly so we fix it up here
- PrefixSize = size(Prefix),
- case size(Buffer) - (2 + PrefixSize) of
- Seek when Seek >= 0 ->
- case Buffer of
- <<_:Seek/binary, Prefix:PrefixSize/binary, "--">> ->
- Buffer1 = <<Buffer/binary, "\r\n">>,
- State#mp{buffer=Buffer1};
- _ ->
- State
- end;
- _ ->
- State
- end;
-flash_multipart_hack(State) ->
- State.
-
-feed_mp(headers, State=#mp{buffer=Buffer, callback=Callback}) ->
- {State1, P} = case find_in_binary(<<"\r\n\r\n">>, Buffer) of
- {exact, N} ->
- {State, N};
- _ ->
- S1 = read_more(State),
- %% Assume headers must be less than ?CHUNKSIZE
- {exact, N} = find_in_binary(<<"\r\n\r\n">>,
- S1#mp.buffer),
- {S1, N}
- end,
- <<Headers:P/binary, "\r\n\r\n", Rest/binary>> = State1#mp.buffer,
- NextCallback = Callback({headers, parse_headers(Headers)}),
- feed_mp(body, State1#mp{buffer=Rest,
- callback=NextCallback});
-feed_mp(body, State=#mp{boundary=Prefix, buffer=Buffer, callback=Callback}) ->
- Boundary = find_boundary(Prefix, Buffer),
- case Boundary of
- {end_boundary, Start, Skip} ->
- <<Data:Start/binary, _:Skip/binary, Rest/binary>> = Buffer,
- C1 = Callback({body, Data}),
- C2 = C1(body_end),
- {State#mp.length, Rest, C2(eof)};
- {next_boundary, Start, Skip} ->
- <<Data:Start/binary, _:Skip/binary, Rest/binary>> = Buffer,
- C1 = Callback({body, Data}),
- feed_mp(headers, State#mp{callback=C1(body_end),
- buffer=Rest});
- {maybe, Start} ->
- <<Data:Start/binary, Rest/binary>> = Buffer,
- feed_mp(body, read_more(State#mp{callback=Callback({body, Data}),
- buffer=Rest}));
- not_found ->
- {Data, Rest} = {Buffer, <<>>},
- feed_mp(body, read_more(State#mp{callback=Callback({body, Data}),
- buffer=Rest}))
- end.
-
-get_boundary(ContentType) ->
- {"multipart/form-data", Opts} = mochiweb_util:parse_header(ContentType),
- case proplists:get_value("boundary", Opts) of
- S when is_list(S) ->
- S
- end.
-
-find_in_binary(B, Data) when size(B) > 0 ->
- case size(Data) - size(B) of
- Last when Last < 0 ->
- partial_find(B, Data, 0, size(Data));
- Last ->
- find_in_binary(B, size(B), Data, 0, Last)
- end.
-
-find_in_binary(B, BS, D, N, Last) when N =< Last->
- case D of
- <<_:N/binary, B:BS/binary, _/binary>> ->
- {exact, N};
- _ ->
- find_in_binary(B, BS, D, 1 + N, Last)
- end;
-find_in_binary(B, BS, D, N, Last) when N =:= 1 + Last ->
- partial_find(B, D, N, BS - 1).
-
-partial_find(_B, _D, _N, 0) ->
- not_found;
-partial_find(B, D, N, K) ->
- <<B1:K/binary, _/binary>> = B,
- case D of
- <<_Skip:N/binary, B1:K/binary>> ->
- {partial, N, K};
- _ ->
- partial_find(B, D, 1 + N, K - 1)
- end.
-
-find_boundary(Prefix, Data) ->
- case find_in_binary(Prefix, Data) of
- {exact, Skip} ->
- PrefixSkip = Skip + size(Prefix),
- case Data of
- <<_:PrefixSkip/binary, "\r\n", _/binary>> ->
- {next_boundary, Skip, size(Prefix) + 2};
- <<_:PrefixSkip/binary, "--\r\n", _/binary>> ->
- {end_boundary, Skip, size(Prefix) + 4};
- _ when size(Data) < PrefixSkip + 4 ->
- %% Underflow
- {maybe, Skip};
- _ ->
- %% False positive
- not_found
- end;
- {partial, Skip, Length} when (Skip + Length) =:= size(Data) ->
- %% Underflow
- {maybe, Skip};
- _ ->
- not_found
- end.
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-ssl_cert_opts() ->
- EbinDir = filename:dirname(code:which(?MODULE)),
- CertDir = filename:join([EbinDir, "..", "support", "test-materials"]),
- CertFile = filename:join(CertDir, "test_ssl_cert.pem"),
- KeyFile = filename:join(CertDir, "test_ssl_key.pem"),
- [{certfile, CertFile}, {keyfile, KeyFile}].
-
-with_socket_server(Transport, ServerFun, ClientFun) ->
- ServerOpts0 = [{ip, "127.0.0.1"}, {port, 0}, {loop, ServerFun}],
- ServerOpts = case Transport of
- plain ->
- ServerOpts0;
- ssl ->
- ServerOpts0 ++ [{ssl, true}, {ssl_opts, ssl_cert_opts()}]
- end,
- {ok, Server} = mochiweb_socket_server:start(ServerOpts),
- Port = mochiweb_socket_server:get(Server, port),
- ClientOpts = [binary, {active, false}],
- {ok, Client} = case Transport of
- plain ->
- gen_tcp:connect("127.0.0.1", Port, ClientOpts);
- ssl ->
- ClientOpts1 = [{ssl_imp, new} | ClientOpts],
- {ok, SslSocket} = ssl:connect("127.0.0.1", Port, ClientOpts1),
- {ok, {ssl, SslSocket}}
- end,
- Res = (catch ClientFun(Client)),
- mochiweb_socket_server:stop(Server),
- Res.
-
-fake_request(Socket, ContentType, Length) ->
- mochiweb_request:new(Socket,
- 'POST',
- "/multipart",
- {1,1},
- mochiweb_headers:make(
- [{"content-type", ContentType},
- {"content-length", Length}])).
-
-test_callback({body, <<>>}, Rest=[body_end | _]) ->
- %% When expecting the body_end we might get an empty binary
- fun (Next) -> test_callback(Next, Rest) end;
-test_callback({body, Got}, [{body, Expect} | Rest]) when Got =/= Expect ->
- %% Partial response
- GotSize = size(Got),
- <<Got:GotSize/binary, Expect1/binary>> = Expect,
- fun (Next) -> test_callback(Next, [{body, Expect1} | Rest]) end;
-test_callback(Got, [Expect | Rest]) ->
- ?assertEqual(Got, Expect),
- case Rest of
- [] ->
- ok;
- _ ->
- fun (Next) -> test_callback(Next, Rest) end
- end.
-
-parse3_http_test() ->
- parse3(plain).
-
-parse3_https_test() ->
- parse3(ssl).
-
-parse3(Transport) ->
- ContentType = "multipart/form-data; boundary=---------------------------7386909285754635891697677882",
- BinContent = <<"-----------------------------7386909285754635891697677882\r\nContent-Disposition: form-data; name=\"hidden\"\r\n\r\nmultipart message\r\n-----------------------------7386909285754635891697677882\r\nContent-Disposition: form-data; name=\"file\"; filename=\"test_file.txt\"\r\nContent-Type: text/plain\r\n\r\nWoo multiline text file\n\nLa la la\r\n-----------------------------7386909285754635891697677882--\r\n">>,
- Expect = [{headers,
- [{"content-disposition",
- {"form-data", [{"name", "hidden"}]}}]},
- {body, <<"multipart message">>},
- body_end,
- {headers,
- [{"content-disposition",
- {"form-data", [{"name", "file"}, {"filename", "test_file.txt"}]}},
- {"content-type", {"text/plain", []}}]},
- {body, <<"Woo multiline text file\n\nLa la la">>},
- body_end,
- eof],
- TestCallback = fun (Next) -> test_callback(Next, Expect) end,
- ServerFun = fun (Socket) ->
- ok = mochiweb_socket:send(Socket, BinContent),
- exit(normal)
- end,
- ClientFun = fun (Socket) ->
- Req = fake_request(Socket, ContentType,
- byte_size(BinContent)),
- Res = parse_multipart_request(Req, TestCallback),
- {0, <<>>, ok} = Res,
- ok
- end,
- ok = with_socket_server(Transport, ServerFun, ClientFun),
- ok.
-
-parse2_http_test() ->
- parse2(plain).
-
-parse2_https_test() ->
- parse2(ssl).
-
-parse2(Transport) ->
- ContentType = "multipart/form-data; boundary=---------------------------6072231407570234361599764024",
- BinContent = <<"-----------------------------6072231407570234361599764024\r\nContent-Disposition: form-data; name=\"hidden\"\r\n\r\nmultipart message\r\n-----------------------------6072231407570234361599764024\r\nContent-Disposition: form-data; name=\"file\"; filename=\"\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----------------------------6072231407570234361599764024--\r\n">>,
- Expect = [{headers,
- [{"content-disposition",
- {"form-data", [{"name", "hidden"}]}}]},
- {body, <<"multipart message">>},
- body_end,
- {headers,
- [{"content-disposition",
- {"form-data", [{"name", "file"}, {"filename", ""}]}},
- {"content-type", {"application/octet-stream", []}}]},
- {body, <<>>},
- body_end,
- eof],
- TestCallback = fun (Next) -> test_callback(Next, Expect) end,
- ServerFun = fun (Socket) ->
- ok = mochiweb_socket:send(Socket, BinContent),
- exit(normal)
- end,
- ClientFun = fun (Socket) ->
- Req = fake_request(Socket, ContentType,
- byte_size(BinContent)),
- Res = parse_multipart_request(Req, TestCallback),
- {0, <<>>, ok} = Res,
- ok
- end,
- ok = with_socket_server(Transport, ServerFun, ClientFun),
- ok.
-
-parse_form_http_test() ->
- do_parse_form(plain).
-
-parse_form_https_test() ->
- do_parse_form(ssl).
-
-do_parse_form(Transport) ->
- ContentType = "multipart/form-data; boundary=AaB03x",
- "AaB03x" = get_boundary(ContentType),
- Content = mochiweb_util:join(
- ["--AaB03x",
- "Content-Disposition: form-data; name=\"submit-name\"",
- "",
- "Larry",
- "--AaB03x",
- "Content-Disposition: form-data; name=\"files\";"
- ++ "filename=\"file1.txt\"",
- "Content-Type: text/plain",
- "",
- "... contents of file1.txt ...",
- "--AaB03x--",
- ""], "\r\n"),
- BinContent = iolist_to_binary(Content),
- ServerFun = fun (Socket) ->
- ok = mochiweb_socket:send(Socket, BinContent),
- exit(normal)
- end,
- ClientFun = fun (Socket) ->
- Req = fake_request(Socket, ContentType,
- byte_size(BinContent)),
- Res = parse_form(Req),
- [{"submit-name", "Larry"},
- {"files", {"file1.txt", {"text/plain",[]},
- <<"... contents of file1.txt ...">>}
- }] = Res,
- ok
- end,
- ok = with_socket_server(Transport, ServerFun, ClientFun),
- ok.
-
-parse_http_test() ->
- do_parse(plain).
-
-parse_https_test() ->
- do_parse(ssl).
-
-do_parse(Transport) ->
- ContentType = "multipart/form-data; boundary=AaB03x",
- "AaB03x" = get_boundary(ContentType),
- Content = mochiweb_util:join(
- ["--AaB03x",
- "Content-Disposition: form-data; name=\"submit-name\"",
- "",
- "Larry",
- "--AaB03x",
- "Content-Disposition: form-data; name=\"files\";"
- ++ "filename=\"file1.txt\"",
- "Content-Type: text/plain",
- "",
- "... contents of file1.txt ...",
- "--AaB03x--",
- ""], "\r\n"),
- BinContent = iolist_to_binary(Content),
- Expect = [{headers,
- [{"content-disposition",
- {"form-data", [{"name", "submit-name"}]}}]},
- {body, <<"Larry">>},
- body_end,
- {headers,
- [{"content-disposition",
- {"form-data", [{"name", "files"}, {"filename", "file1.txt"}]}},
- {"content-type", {"text/plain", []}}]},
- {body, <<"... contents of file1.txt ...">>},
- body_end,
- eof],
- TestCallback = fun (Next) -> test_callback(Next, Expect) end,
- ServerFun = fun (Socket) ->
- ok = mochiweb_socket:send(Socket, BinContent),
- exit(normal)
- end,
- ClientFun = fun (Socket) ->
- Req = fake_request(Socket, ContentType,
- byte_size(BinContent)),
- Res = parse_multipart_request(Req, TestCallback),
- {0, <<>>, ok} = Res,
- ok
- end,
- ok = with_socket_server(Transport, ServerFun, ClientFun),
- ok.
-
-parse_partial_body_boundary_http_test() ->
- parse_partial_body_boundary(plain).
-
-parse_partial_body_boundary_https_test() ->
- parse_partial_body_boundary(ssl).
-
-parse_partial_body_boundary(Transport) ->
- Boundary = string:copies("$", 2048),
- ContentType = "multipart/form-data; boundary=" ++ Boundary,
- ?assertEqual(Boundary, get_boundary(ContentType)),
- Content = mochiweb_util:join(
- ["--" ++ Boundary,
- "Content-Disposition: form-data; name=\"submit-name\"",
- "",
- "Larry",
- "--" ++ Boundary,
- "Content-Disposition: form-data; name=\"files\";"
- ++ "filename=\"file1.txt\"",
- "Content-Type: text/plain",
- "",
- "... contents of file1.txt ...",
- "--" ++ Boundary ++ "--",
- ""], "\r\n"),
- BinContent = iolist_to_binary(Content),
- Expect = [{headers,
- [{"content-disposition",
- {"form-data", [{"name", "submit-name"}]}}]},
- {body, <<"Larry">>},
- body_end,
- {headers,
- [{"content-disposition",
- {"form-data", [{"name", "files"}, {"filename", "file1.txt"}]}},
- {"content-type", {"text/plain", []}}
- ]},
- {body, <<"... contents of file1.txt ...">>},
- body_end,
- eof],
- TestCallback = fun (Next) -> test_callback(Next, Expect) end,
- ServerFun = fun (Socket) ->
- ok = mochiweb_socket:send(Socket, BinContent),
- exit(normal)
- end,
- ClientFun = fun (Socket) ->
- Req = fake_request(Socket, ContentType,
- byte_size(BinContent)),
- Res = parse_multipart_request(Req, TestCallback),
- {0, <<>>, ok} = Res,
- ok
- end,
- ok = with_socket_server(Transport, ServerFun, ClientFun),
- ok.
-
-parse_large_header_http_test() ->
- parse_large_header(plain).
-
-parse_large_header_https_test() ->
- parse_large_header(ssl).
-
-parse_large_header(Transport) ->
- ContentType = "multipart/form-data; boundary=AaB03x",
- "AaB03x" = get_boundary(ContentType),
- Content = mochiweb_util:join(
- ["--AaB03x",
- "Content-Disposition: form-data; name=\"submit-name\"",
- "",
- "Larry",
- "--AaB03x",
- "Content-Disposition: form-data; name=\"files\";"
- ++ "filename=\"file1.txt\"",
- "Content-Type: text/plain",
- "x-large-header: " ++ string:copies("%", 4096),
- "",
- "... contents of file1.txt ...",
- "--AaB03x--",
- ""], "\r\n"),
- BinContent = iolist_to_binary(Content),
- Expect = [{headers,
- [{"content-disposition",
- {"form-data", [{"name", "submit-name"}]}}]},
- {body, <<"Larry">>},
- body_end,
- {headers,
- [{"content-disposition",
- {"form-data", [{"name", "files"}, {"filename", "file1.txt"}]}},
- {"content-type", {"text/plain", []}},
- {"x-large-header", {string:copies("%", 4096), []}}
- ]},
- {body, <<"... contents of file1.txt ...">>},
- body_end,
- eof],
- TestCallback = fun (Next) -> test_callback(Next, Expect) end,
- ServerFun = fun (Socket) ->
- ok = mochiweb_socket:send(Socket, BinContent),
- exit(normal)
- end,
- ClientFun = fun (Socket) ->
- Req = fake_request(Socket, ContentType,
- byte_size(BinContent)),
- Res = parse_multipart_request(Req, TestCallback),
- {0, <<>>, ok} = Res,
- ok
- end,
- ok = with_socket_server(Transport, ServerFun, ClientFun),
- ok.
-
-find_boundary_test() ->
- B = <<"\r\n--X">>,
- {next_boundary, 0, 7} = find_boundary(B, <<"\r\n--X\r\nRest">>),
- {next_boundary, 1, 7} = find_boundary(B, <<"!\r\n--X\r\nRest">>),
- {end_boundary, 0, 9} = find_boundary(B, <<"\r\n--X--\r\nRest">>),
- {end_boundary, 1, 9} = find_boundary(B, <<"!\r\n--X--\r\nRest">>),
- not_found = find_boundary(B, <<"--X\r\nRest">>),
- {maybe, 0} = find_boundary(B, <<"\r\n--X\r">>),
- {maybe, 1} = find_boundary(B, <<"!\r\n--X\r">>),
- P = <<"\r\n-----------------------------16037454351082272548568224146">>,
- B0 = <<55,212,131,77,206,23,216,198,35,87,252,118,252,8,25,211,132,229,
- 182,42,29,188,62,175,247,243,4,4,0,59, 13,10,45,45,45,45,45,45,45,
- 45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,
- 49,54,48,51,55,52,53,52,51,53,49>>,
- {maybe, 30} = find_boundary(P, B0),
- not_found = find_boundary(B, <<"\r\n--XJOPKE">>),
- ok.
-
-find_in_binary_test() ->
- {exact, 0} = find_in_binary(<<"foo">>, <<"foobarbaz">>),
- {exact, 1} = find_in_binary(<<"oo">>, <<"foobarbaz">>),
- {exact, 8} = find_in_binary(<<"z">>, <<"foobarbaz">>),
- not_found = find_in_binary(<<"q">>, <<"foobarbaz">>),
- {partial, 7, 2} = find_in_binary(<<"azul">>, <<"foobarbaz">>),
- {exact, 0} = find_in_binary(<<"foobarbaz">>, <<"foobarbaz">>),
- {partial, 0, 3} = find_in_binary(<<"foobar">>, <<"foo">>),
- {partial, 1, 3} = find_in_binary(<<"foobar">>, <<"afoo">>),
- ok.
-
-flash_parse_http_test() ->
- flash_parse(plain).
-
-flash_parse_https_test() ->
- flash_parse(ssl).
-
-flash_parse(Transport) ->
- ContentType = "multipart/form-data; boundary=----------ei4GI3GI3Ij5Ef1ae0KM7Ij5ei4Ij5",
- "----------ei4GI3GI3Ij5Ef1ae0KM7Ij5ei4Ij5" = get_boundary(ContentType),
- BinContent = <<"------------ei4GI3GI3Ij5Ef1ae0KM7Ij5ei4Ij5\r\nContent-Disposition: form-data; name=\"Filename\"\r\n\r\nhello.txt\r\n------------ei4GI3GI3Ij5Ef1ae0KM7Ij5ei4Ij5\r\nContent-Disposition: form-data; name=\"success_action_status\"\r\n\r\n201\r\n------------ei4GI3GI3Ij5Ef1ae0KM7Ij5ei4Ij5\r\nContent-Disposition: form-data; name=\"file\"; filename=\"hello.txt\"\r\nContent-Type: application/octet-stream\r\n\r\nhello\n\r\n------------ei4GI3GI3Ij5Ef1ae0KM7Ij5ei4Ij5\r\nContent-Disposition: form-data; name=\"Upload\"\r\n\r\nSubmit Query\r\n------------ei4GI3GI3Ij5Ef1ae0KM7Ij5ei4Ij5--">>,
- Expect = [{headers,
- [{"content-disposition",
- {"form-data", [{"name", "Filename"}]}}]},
- {body, <<"hello.txt">>},
- body_end,
- {headers,
- [{"content-disposition",
- {"form-data", [{"name", "success_action_status"}]}}]},
- {body, <<"201">>},
- body_end,
- {headers,
- [{"content-disposition",
- {"form-data", [{"name", "file"}, {"filename", "hello.txt"}]}},
- {"content-type", {"application/octet-stream", []}}]},
- {body, <<"hello\n">>},
- body_end,
- {headers,
- [{"content-disposition",
- {"form-data", [{"name", "Upload"}]}}]},
- {body, <<"Submit Query">>},
- body_end,
- eof],
- TestCallback = fun (Next) -> test_callback(Next, Expect) end,
- ServerFun = fun (Socket) ->
- ok = mochiweb_socket:send(Socket, BinContent),
- exit(normal)
- end,
- ClientFun = fun (Socket) ->
- Req = fake_request(Socket, ContentType,
- byte_size(BinContent)),
- Res = parse_multipart_request(Req, TestCallback),
- {0, <<>>, ok} = Res,
- ok
- end,
- ok = with_socket_server(Transport, ServerFun, ClientFun),
- ok.
-
-flash_parse2_http_test() ->
- flash_parse2(plain).
-
-flash_parse2_https_test() ->
- flash_parse2(ssl).
-
-flash_parse2(Transport) ->
- ContentType = "multipart/form-data; boundary=----------ei4GI3GI3Ij5Ef1ae0KM7Ij5ei4Ij5",
- "----------ei4GI3GI3Ij5Ef1ae0KM7Ij5ei4Ij5" = get_boundary(ContentType),
- Chunk = iolist_to_binary(string:copies("%", 4096)),
- BinContent = <<"------------ei4GI3GI3Ij5Ef1ae0KM7Ij5ei4Ij5\r\nContent-Disposition: form-data; name=\"Filename\"\r\n\r\nhello.txt\r\n------------ei4GI3GI3Ij5Ef1ae0KM7Ij5ei4Ij5\r\nContent-Disposition: form-data; name=\"success_action_status\"\r\n\r\n201\r\n------------ei4GI3GI3Ij5Ef1ae0KM7Ij5ei4Ij5\r\nContent-Disposition: form-data; name=\"file\"; filename=\"hello.txt\"\r\nContent-Type: application/octet-stream\r\n\r\n", Chunk/binary, "\r\n------------ei4GI3GI3Ij5Ef1ae0KM7Ij5ei4Ij5\r\nContent-Disposition: form-data; name=\"Upload\"\r\n\r\nSubmit Query\r\n------------ei4GI3GI3Ij5Ef1ae0KM7Ij5ei4Ij5--">>,
- Expect = [{headers,
- [{"content-disposition",
- {"form-data", [{"name", "Filename"}]}}]},
- {body, <<"hello.txt">>},
- body_end,
- {headers,
- [{"content-disposition",
- {"form-data", [{"name", "success_action_status"}]}}]},
- {body, <<"201">>},
- body_end,
- {headers,
- [{"content-disposition",
- {"form-data", [{"name", "file"}, {"filename", "hello.txt"}]}},
- {"content-type", {"application/octet-stream", []}}]},
- {body, Chunk},
- body_end,
- {headers,
- [{"content-disposition",
- {"form-data", [{"name", "Upload"}]}}]},
- {body, <<"Submit Query">>},
- body_end,
- eof],
- TestCallback = fun (Next) -> test_callback(Next, Expect) end,
- ServerFun = fun (Socket) ->
- ok = mochiweb_socket:send(Socket, BinContent),
- exit(normal)
- end,
- ClientFun = fun (Socket) ->
- Req = fake_request(Socket, ContentType,
- byte_size(BinContent)),
- Res = parse_multipart_request(Req, TestCallback),
- {0, <<>>, ok} = Res,
- ok
- end,
- ok = with_socket_server(Transport, ServerFun, ClientFun),
- ok.
-
-parse_headers_test() ->
- ?assertEqual([], parse_headers(<<>>)).
-
-flash_multipart_hack_test() ->
- Buffer = <<"prefix-">>,
- Prefix = <<"prefix">>,
- State = #mp{length=0, buffer=Buffer, boundary=Prefix},
- ?assertEqual(State,
- flash_multipart_hack(State)).
-
-parts_to_body_single_test() ->
- {HL, B} = parts_to_body([{0, 5, <<"01234">>}],
- "text/plain",
- 10),
- [{"Content-Range", Range},
- {"Content-Type", Type}] = lists:sort(HL),
- ?assertEqual(
- <<"bytes 0-5/10">>,
- iolist_to_binary(Range)),
- ?assertEqual(
- <<"text/plain">>,
- iolist_to_binary(Type)),
- ?assertEqual(
- <<"01234">>,
- iolist_to_binary(B)),
- ok.
-
-parts_to_body_multi_test() ->
- {[{"Content-Type", Type}],
- _B} = parts_to_body([{0, 5, <<"01234">>}, {5, 10, <<"56789">>}],
- "text/plain",
- 10),
- ?assertMatch(
- <<"multipart/byteranges; boundary=", _/binary>>,
- iolist_to_binary(Type)),
- ok.
-
-parts_to_multipart_body_test() ->
- {[{"Content-Type", V}], B} = parts_to_multipart_body(
- [{0, 5, <<"01234">>}, {5, 10, <<"56789">>}],
- "text/plain",
- 10,
- "BOUNDARY"),
- MB = multipart_body(
- [{0, 5, <<"01234">>}, {5, 10, <<"56789">>}],
- "text/plain",
- "BOUNDARY",
- 10),
- ?assertEqual(
- <<"multipart/byteranges; boundary=BOUNDARY">>,
- iolist_to_binary(V)),
- ?assertEqual(
- iolist_to_binary(MB),
- iolist_to_binary(B)),
- ok.
-
-multipart_body_test() ->
- ?assertEqual(
- <<"--BOUNDARY--\r\n">>,
- iolist_to_binary(multipart_body([], "text/plain", "BOUNDARY", 0))),
- ?assertEqual(
- <<"--BOUNDARY\r\n"
- "Content-Type: text/plain\r\n"
- "Content-Range: bytes 0-5/10\r\n\r\n"
- "01234\r\n"
- "--BOUNDARY\r\n"
- "Content-Type: text/plain\r\n"
- "Content-Range: bytes 5-10/10\r\n\r\n"
- "56789\r\n"
- "--BOUNDARY--\r\n">>,
- iolist_to_binary(multipart_body([{0, 5, <<"01234">>}, {5, 10, <<"56789">>}],
- "text/plain",
- "BOUNDARY",
- 10))),
- ok.
-
--endif.
diff --git a/src/mochiweb/mochiweb_request.erl b/src/mochiweb/mochiweb_request.erl
deleted file mode 100644
index ffe4e9eb..00000000
--- a/src/mochiweb/mochiweb_request.erl
+++ /dev/null
@@ -1,768 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2007 Mochi Media, Inc.
-
-%% @doc MochiWeb HTTP Request abstraction.
-
--module(mochiweb_request, [Socket, Method, RawPath, Version, Headers]).
--author('bob@mochimedia.com').
-
--include_lib("kernel/include/file.hrl").
--include("internal.hrl").
-
--define(QUIP, "Any of you quaids got a smint?").
-
--export([get_header_value/1, get_primary_header_value/1, get/1, dump/0]).
--export([send/1, recv/1, recv/2, recv_body/0, recv_body/1, stream_body/3]).
--export([start_response/1, start_response_length/1, start_raw_response/1]).
--export([respond/1, ok/1]).
--export([not_found/0, not_found/1]).
--export([parse_post/0, parse_qs/0]).
--export([should_close/0, cleanup/0]).
--export([parse_cookie/0, get_cookie_value/1]).
--export([serve_file/2, serve_file/3]).
--export([accepted_encodings/1]).
--export([accepts_content_type/1]).
-
--define(SAVE_QS, mochiweb_request_qs).
--define(SAVE_PATH, mochiweb_request_path).
--define(SAVE_RECV, mochiweb_request_recv).
--define(SAVE_BODY, mochiweb_request_body).
--define(SAVE_BODY_LENGTH, mochiweb_request_body_length).
--define(SAVE_POST, mochiweb_request_post).
--define(SAVE_COOKIE, mochiweb_request_cookie).
--define(SAVE_FORCE_CLOSE, mochiweb_request_force_close).
-
-%% @type iolist() = [iolist() | binary() | char()].
-%% @type iodata() = binary() | iolist().
-%% @type key() = atom() | string() | binary()
-%% @type value() = atom() | string() | binary() | integer()
-%% @type headers(). A mochiweb_headers structure.
-%% @type response(). A mochiweb_response parameterized module instance.
-%% @type ioheaders() = headers() | [{key(), value()}].
-
-% 10 second default idle timeout
--define(IDLE_TIMEOUT, 10000).
-
-% Maximum recv_body() length of 1MB
--define(MAX_RECV_BODY, (1024*1024)).
-
-%% @spec get_header_value(K) -> undefined | Value
-%% @doc Get the value of a given request header.
-get_header_value(K) ->
- mochiweb_headers:get_value(K, Headers).
-
-get_primary_header_value(K) ->
- mochiweb_headers:get_primary_value(K, Headers).
-
-%% @type field() = socket | scheme | method | raw_path | version | headers | peer | path | body_length | range
-
-%% @spec get(field()) -> term()
-%% @doc Return the internal representation of the given field. If
-%% <code>socket</code> is requested on a HTTPS connection, then
-%% an ssl socket will be returned as <code>{ssl, SslSocket}</code>.
-%% You can use <code>SslSocket</code> with the <code>ssl</code>
-%% application, eg: <code>ssl:peercert(SslSocket)</code>.
-get(socket) ->
- Socket;
-get(scheme) ->
- case mochiweb_socket:type(Socket) of
- plain ->
- http;
- ssl ->
- https
- end;
-get(method) ->
- Method;
-get(raw_path) ->
- RawPath;
-get(version) ->
- Version;
-get(headers) ->
- Headers;
-get(peer) ->
- case mochiweb_socket:peername(Socket) of
- {ok, {Addr={10, _, _, _}, _Port}} ->
- case get_header_value("x-forwarded-for") of
- undefined ->
- inet_parse:ntoa(Addr);
- Hosts ->
- string:strip(lists:last(string:tokens(Hosts, ",")))
- end;
- {ok, {{127, 0, 0, 1}, _Port}} ->
- case get_header_value("x-forwarded-for") of
- undefined ->
- "127.0.0.1";
- Hosts ->
- string:strip(lists:last(string:tokens(Hosts, ",")))
- end;
- {ok, {Addr, _Port}} ->
- inet_parse:ntoa(Addr);
- {error, enotconn} ->
- exit(normal)
- end;
-get(path) ->
- case erlang:get(?SAVE_PATH) of
- undefined ->
- {Path0, _, _} = mochiweb_util:urlsplit_path(RawPath),
- Path = mochiweb_util:unquote(Path0),
- put(?SAVE_PATH, Path),
- Path;
- Cached ->
- Cached
- end;
-get(body_length) ->
- case erlang:get(?SAVE_BODY_LENGTH) of
- undefined ->
- BodyLength = body_length(),
- put(?SAVE_BODY_LENGTH, {cached, BodyLength}),
- BodyLength;
- {cached, Cached} ->
- Cached
- end;
-get(range) ->
- case get_header_value(range) of
- undefined ->
- undefined;
- RawRange ->
- mochiweb_http:parse_range_request(RawRange)
- end.
-
-%% @spec dump() -> {mochiweb_request, [{atom(), term()}]}
-%% @doc Dump the internal representation to a "human readable" set of terms
-%% for debugging/inspection purposes.
-dump() ->
- {?MODULE, [{method, Method},
- {version, Version},
- {raw_path, RawPath},
- {headers, mochiweb_headers:to_list(Headers)}]}.
-
-%% @spec send(iodata()) -> ok
-%% @doc Send data over the socket.
-send(Data) ->
- case mochiweb_socket:send(Socket, Data) of
- ok ->
- ok;
- _ ->
- exit(normal)
- end.
-
-%% @spec recv(integer()) -> binary()
-%% @doc Receive Length bytes from the client as a binary, with the default
-%% idle timeout.
-recv(Length) ->
- recv(Length, ?IDLE_TIMEOUT).
-
-%% @spec recv(integer(), integer()) -> binary()
-%% @doc Receive Length bytes from the client as a binary, with the given
-%% Timeout in msec.
-recv(Length, Timeout) ->
- case mochiweb_socket:recv(Socket, Length, Timeout) of
- {ok, Data} ->
- put(?SAVE_RECV, true),
- Data;
- _ ->
- exit(normal)
- end.
-
-%% @spec body_length() -> undefined | chunked | unknown_transfer_encoding | integer()
-%% @doc Infer body length from transfer-encoding and content-length headers.
-body_length() ->
- case get_header_value("transfer-encoding") of
- undefined ->
- case get_header_value("content-length") of
- undefined ->
- undefined;
- Length ->
- list_to_integer(Length)
- end;
- "chunked" ->
- chunked;
- Unknown ->
- {unknown_transfer_encoding, Unknown}
- end.
-
-
-%% @spec recv_body() -> binary()
-%% @doc Receive the body of the HTTP request (defined by Content-Length).
-%% Will only receive up to the default max-body length of 1MB.
-recv_body() ->
- recv_body(?MAX_RECV_BODY).
-
-%% @spec recv_body(integer()) -> binary()
-%% @doc Receive the body of the HTTP request (defined by Content-Length).
-%% Will receive up to MaxBody bytes.
-recv_body(MaxBody) ->
- case erlang:get(?SAVE_BODY) of
- undefined ->
- % we could use a sane constant for max chunk size
- Body = stream_body(?MAX_RECV_BODY, fun
- ({0, _ChunkedFooter}, {_LengthAcc, BinAcc}) ->
- iolist_to_binary(lists:reverse(BinAcc));
- ({Length, Bin}, {LengthAcc, BinAcc}) ->
- NewLength = Length + LengthAcc,
- if NewLength > MaxBody ->
- exit({body_too_large, chunked});
- true ->
- {NewLength, [Bin | BinAcc]}
- end
- end, {0, []}, MaxBody),
- put(?SAVE_BODY, Body),
- Body;
- Cached -> Cached
- end.
-
-stream_body(MaxChunkSize, ChunkFun, FunState) ->
- stream_body(MaxChunkSize, ChunkFun, FunState, undefined).
-
-stream_body(MaxChunkSize, ChunkFun, FunState, MaxBodyLength) ->
- Expect = case get_header_value("expect") of
- undefined ->
- undefined;
- Value when is_list(Value) ->
- string:to_lower(Value)
- end,
- case Expect of
- "100-continue" ->
- start_raw_response({100, gb_trees:empty()});
- _Else ->
- ok
- end,
- case body_length() of
- undefined ->
- undefined;
- {unknown_transfer_encoding, Unknown} ->
- exit({unknown_transfer_encoding, Unknown});
- chunked ->
- % In this case the MaxBody is actually used to
- % determine the maximum allowed size of a single
- % chunk.
- stream_chunked_body(MaxChunkSize, ChunkFun, FunState);
- 0 ->
- <<>>;
- Length when is_integer(Length) ->
- case MaxBodyLength of
- MaxBodyLength when is_integer(MaxBodyLength), MaxBodyLength < Length ->
- exit({body_too_large, content_length});
- _ ->
- stream_unchunked_body(Length, ChunkFun, FunState)
- end;
- Length ->
- exit({length_not_integer, Length})
- end.
-
-
-%% @spec start_response({integer(), ioheaders()}) -> response()
-%% @doc Start the HTTP response by sending the Code HTTP response and
-%% ResponseHeaders. The server will set header defaults such as Server
-%% and Date if not present in ResponseHeaders.
-start_response({Code, ResponseHeaders}) ->
- HResponse = mochiweb_headers:make(ResponseHeaders),
- HResponse1 = mochiweb_headers:default_from_list(server_headers(),
- HResponse),
- start_raw_response({Code, HResponse1}).
-
-%% @spec start_raw_response({integer(), headers()}) -> response()
-%% @doc Start the HTTP response by sending the Code HTTP response and
-%% ResponseHeaders.
-start_raw_response({Code, ResponseHeaders}) ->
- F = fun ({K, V}, Acc) ->
- [mochiweb_util:make_io(K), <<": ">>, V, <<"\r\n">> | Acc]
- end,
- End = lists:foldl(F, [<<"\r\n">>],
- mochiweb_headers:to_list(ResponseHeaders)),
- send([make_version(Version), make_code(Code), <<"\r\n">> | End]),
- mochiweb:new_response({THIS, Code, ResponseHeaders}).
-
-
-%% @spec start_response_length({integer(), ioheaders(), integer()}) -> response()
-%% @doc Start the HTTP response by sending the Code HTTP response and
-%% ResponseHeaders including a Content-Length of Length. The server
-%% will set header defaults such as Server
-%% and Date if not present in ResponseHeaders.
-start_response_length({Code, ResponseHeaders, Length}) ->
- HResponse = mochiweb_headers:make(ResponseHeaders),
- HResponse1 = mochiweb_headers:enter("Content-Length", Length, HResponse),
- start_response({Code, HResponse1}).
-
-%% @spec respond({integer(), ioheaders(), iodata() | chunked | {file, IoDevice}}) -> response()
-%% @doc Start the HTTP response with start_response, and send Body to the
-%% client (if the get(method) /= 'HEAD'). The Content-Length header
-%% will be set by the Body length, and the server will insert header
-%% defaults.
-respond({Code, ResponseHeaders, {file, IoDevice}}) ->
- Length = mochiweb_io:iodevice_size(IoDevice),
- Response = start_response_length({Code, ResponseHeaders, Length}),
- case Method of
- 'HEAD' ->
- ok;
- _ ->
- mochiweb_io:iodevice_stream(fun send/1, IoDevice)
- end,
- Response;
-respond({Code, ResponseHeaders, chunked}) ->
- HResponse = mochiweb_headers:make(ResponseHeaders),
- HResponse1 = case Method of
- 'HEAD' ->
- %% This is what Google does, http://www.google.com/
- %% is chunked but HEAD gets Content-Length: 0.
- %% The RFC is ambiguous so emulating Google is smart.
- mochiweb_headers:enter("Content-Length", "0",
- HResponse);
- _ when Version >= {1, 1} ->
- %% Only use chunked encoding for HTTP/1.1
- mochiweb_headers:enter("Transfer-Encoding", "chunked",
- HResponse);
- _ ->
- %% For pre-1.1 clients we send the data as-is
- %% without a Content-Length header and without
- %% chunk delimiters. Since the end of the document
- %% is now ambiguous we must force a close.
- put(?SAVE_FORCE_CLOSE, true),
- HResponse
- end,
- start_response({Code, HResponse1});
-respond({Code, ResponseHeaders, Body}) ->
- Response = start_response_length({Code, ResponseHeaders, iolist_size(Body)}),
- case Method of
- 'HEAD' ->
- ok;
- _ ->
- send(Body)
- end,
- Response.
-
-%% @spec not_found() -> response()
-%% @doc Alias for <code>not_found([])</code>.
-not_found() ->
- not_found([]).
-
-%% @spec not_found(ExtraHeaders) -> response()
-%% @doc Alias for <code>respond({404, [{"Content-Type", "text/plain"}
-%% | ExtraHeaders], &lt;&lt;"Not found."&gt;&gt;})</code>.
-not_found(ExtraHeaders) ->
- respond({404, [{"Content-Type", "text/plain"} | ExtraHeaders],
- <<"Not found.">>}).
-
-%% @spec ok({value(), iodata()} | {value(), ioheaders(), iodata() | {file, IoDevice}}) ->
-%% response()
-%% @doc respond({200, [{"Content-Type", ContentType} | Headers], Body}).
-ok({ContentType, Body}) ->
- ok({ContentType, [], Body});
-ok({ContentType, ResponseHeaders, Body}) ->
- HResponse = mochiweb_headers:make(ResponseHeaders),
- case THIS:get(range) of
- X when (X =:= undefined orelse X =:= fail) orelse Body =:= chunked ->
- %% http://code.google.com/p/mochiweb/issues/detail?id=54
- %% Range header not supported when chunked, return 200 and provide
- %% full response.
- HResponse1 = mochiweb_headers:enter("Content-Type", ContentType,
- HResponse),
- respond({200, HResponse1, Body});
- Ranges ->
- {PartList, Size} = range_parts(Body, Ranges),
- case PartList of
- [] -> %% no valid ranges
- HResponse1 = mochiweb_headers:enter("Content-Type",
- ContentType,
- HResponse),
- %% could be 416, for now we'll just return 200
- respond({200, HResponse1, Body});
- PartList ->
- {RangeHeaders, RangeBody} =
- mochiweb_multipart:parts_to_body(PartList, ContentType, Size),
- HResponse1 = mochiweb_headers:enter_from_list(
- [{"Accept-Ranges", "bytes"} |
- RangeHeaders],
- HResponse),
- respond({206, HResponse1, RangeBody})
- end
- end.
-
-%% @spec should_close() -> bool()
-%% @doc Return true if the connection must be closed. If false, using
-%% Keep-Alive should be safe.
-should_close() ->
- ForceClose = erlang:get(mochiweb_request_force_close) =/= undefined,
- DidNotRecv = erlang:get(mochiweb_request_recv) =:= undefined,
- ForceClose orelse Version < {1, 0}
- %% Connection: close
- orelse get_header_value("connection") =:= "close"
- %% HTTP 1.0 requires Connection: Keep-Alive
- orelse (Version =:= {1, 0}
- andalso get_header_value("connection") =/= "Keep-Alive")
- %% unread data left on the socket, can't safely continue
- orelse (DidNotRecv
- andalso get_header_value("content-length") =/= undefined
- andalso list_to_integer(get_header_value("content-length")) > 0)
- orelse (DidNotRecv
- andalso get_header_value("transfer-encoding") =:= "chunked").
-
-%% @spec cleanup() -> ok
-%% @doc Clean up any junk in the process dictionary, required before continuing
-%% a Keep-Alive request.
-cleanup() ->
- [erase(K) || K <- [?SAVE_QS,
- ?SAVE_PATH,
- ?SAVE_RECV,
- ?SAVE_BODY,
- ?SAVE_POST,
- ?SAVE_COOKIE,
- ?SAVE_FORCE_CLOSE]],
- ok.
-
-%% @spec parse_qs() -> [{Key::string(), Value::string()}]
-%% @doc Parse the query string of the URL.
-parse_qs() ->
- case erlang:get(?SAVE_QS) of
- undefined ->
- {_, QueryString, _} = mochiweb_util:urlsplit_path(RawPath),
- Parsed = mochiweb_util:parse_qs(QueryString),
- put(?SAVE_QS, Parsed),
- Parsed;
- Cached ->
- Cached
- end.
-
-%% @spec get_cookie_value(Key::string) -> string() | undefined
-%% @doc Get the value of the given cookie.
-get_cookie_value(Key) ->
- proplists:get_value(Key, parse_cookie()).
-
-%% @spec parse_cookie() -> [{Key::string(), Value::string()}]
-%% @doc Parse the cookie header.
-parse_cookie() ->
- case erlang:get(?SAVE_COOKIE) of
- undefined ->
- Cookies = case get_header_value("cookie") of
- undefined ->
- [];
- Value ->
- mochiweb_cookies:parse_cookie(Value)
- end,
- put(?SAVE_COOKIE, Cookies),
- Cookies;
- Cached ->
- Cached
- end.
-
-%% @spec parse_post() -> [{Key::string(), Value::string()}]
-%% @doc Parse an application/x-www-form-urlencoded form POST. This
-%% has the side-effect of calling recv_body().
-parse_post() ->
- case erlang:get(?SAVE_POST) of
- undefined ->
- Parsed = case recv_body() of
- undefined ->
- [];
- Binary ->
- case get_primary_header_value("content-type") of
- "application/x-www-form-urlencoded" ++ _ ->
- mochiweb_util:parse_qs(Binary);
- _ ->
- []
- end
- end,
- put(?SAVE_POST, Parsed),
- Parsed;
- Cached ->
- Cached
- end.
-
-%% @spec stream_chunked_body(integer(), fun(), term()) -> term()
-%% @doc The function is called for each chunk.
-%% Used internally by read_chunked_body.
-stream_chunked_body(MaxChunkSize, Fun, FunState) ->
- case read_chunk_length() of
- 0 ->
- Fun({0, read_chunk(0)}, FunState);
- Length when Length > MaxChunkSize ->
- NewState = read_sub_chunks(Length, MaxChunkSize, Fun, FunState),
- stream_chunked_body(MaxChunkSize, Fun, NewState);
- Length ->
- NewState = Fun({Length, read_chunk(Length)}, FunState),
- stream_chunked_body(MaxChunkSize, Fun, NewState)
- end.
-
-stream_unchunked_body(0, Fun, FunState) ->
- Fun({0, <<>>}, FunState);
-stream_unchunked_body(Length, Fun, FunState) when Length > 0 ->
- PktSize = case Length > ?RECBUF_SIZE of
- true ->
- ?RECBUF_SIZE;
- false ->
- Length
- end,
- Bin = recv(PktSize),
- NewState = Fun({PktSize, Bin}, FunState),
- stream_unchunked_body(Length - PktSize, Fun, NewState).
-
-%% @spec read_chunk_length() -> integer()
-%% @doc Read the length of the next HTTP chunk.
-read_chunk_length() ->
- mochiweb_socket:setopts(Socket, [{packet, line}]),
- case mochiweb_socket:recv(Socket, 0, ?IDLE_TIMEOUT) of
- {ok, Header} ->
- mochiweb_socket:setopts(Socket, [{packet, raw}]),
- Splitter = fun (C) ->
- C =/= $\r andalso C =/= $\n andalso C =/= $
- end,
- {Hex, _Rest} = lists:splitwith(Splitter, binary_to_list(Header)),
- mochihex:to_int(Hex);
- _ ->
- exit(normal)
- end.
-
-%% @spec read_chunk(integer()) -> Chunk::binary() | [Footer::binary()]
-%% @doc Read in a HTTP chunk of the given length. If Length is 0, then read the
-%% HTTP footers (as a list of binaries, since they're nominal).
-read_chunk(0) ->
- mochiweb_socket:setopts(Socket, [{packet, line}]),
- F = fun (F1, Acc) ->
- case mochiweb_socket:recv(Socket, 0, ?IDLE_TIMEOUT) of
- {ok, <<"\r\n">>} ->
- Acc;
- {ok, Footer} ->
- F1(F1, [Footer | Acc]);
- _ ->
- exit(normal)
- end
- end,
- Footers = F(F, []),
- mochiweb_socket:setopts(Socket, [{packet, raw}]),
- put(?SAVE_RECV, true),
- Footers;
-read_chunk(Length) ->
- case mochiweb_socket:recv(Socket, 2 + Length, ?IDLE_TIMEOUT) of
- {ok, <<Chunk:Length/binary, "\r\n">>} ->
- Chunk;
- _ ->
- exit(normal)
- end.
-
-read_sub_chunks(Length, MaxChunkSize, Fun, FunState) when Length > MaxChunkSize ->
- Bin = recv(MaxChunkSize),
- NewState = Fun({size(Bin), Bin}, FunState),
- read_sub_chunks(Length - MaxChunkSize, MaxChunkSize, Fun, NewState);
-
-read_sub_chunks(Length, _MaxChunkSize, Fun, FunState) ->
- Fun({Length, read_chunk(Length)}, FunState).
-
-%% @spec serve_file(Path, DocRoot) -> Response
-%% @doc Serve a file relative to DocRoot.
-serve_file(Path, DocRoot) ->
- serve_file(Path, DocRoot, []).
-
-%% @spec serve_file(Path, DocRoot, ExtraHeaders) -> Response
-%% @doc Serve a file relative to DocRoot.
-serve_file(Path, DocRoot, ExtraHeaders) ->
- case mochiweb_util:safe_relative_path(Path) of
- undefined ->
- not_found(ExtraHeaders);
- RelPath ->
- FullPath = filename:join([DocRoot, RelPath]),
- case filelib:is_dir(FullPath) of
- true ->
- maybe_redirect(RelPath, FullPath, ExtraHeaders);
- false ->
- maybe_serve_file(FullPath, ExtraHeaders)
- end
- end.
-
-%% Internal API
-
-%% This has the same effect as the DirectoryIndex directive in httpd
-directory_index(FullPath) ->
- filename:join([FullPath, "index.html"]).
-
-maybe_redirect([], FullPath, ExtraHeaders) ->
- maybe_serve_file(directory_index(FullPath), ExtraHeaders);
-
-maybe_redirect(RelPath, FullPath, ExtraHeaders) ->
- case string:right(RelPath, 1) of
- "/" ->
- maybe_serve_file(directory_index(FullPath), ExtraHeaders);
- _ ->
- Host = mochiweb_headers:get_value("host", Headers),
- Location = "http://" ++ Host ++ "/" ++ RelPath ++ "/",
- LocationBin = list_to_binary(Location),
- MoreHeaders = [{"Location", Location},
- {"Content-Type", "text/html"} | ExtraHeaders],
- Top = <<"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">"
- "<html><head>"
- "<title>301 Moved Permanently</title>"
- "</head><body>"
- "<h1>Moved Permanently</h1>"
- "<p>The document has moved <a href=\"">>,
- Bottom = <<">here</a>.</p></body></html>\n">>,
- Body = <<Top/binary, LocationBin/binary, Bottom/binary>>,
- respond({301, MoreHeaders, Body})
- end.
-
-maybe_serve_file(File, ExtraHeaders) ->
- case file:read_file_info(File) of
- {ok, FileInfo} ->
- LastModified = httpd_util:rfc1123_date(FileInfo#file_info.mtime),
- case get_header_value("if-modified-since") of
- LastModified ->
- respond({304, ExtraHeaders, ""});
- _ ->
- case file:open(File, [raw, binary]) of
- {ok, IoDevice} ->
- ContentType = mochiweb_util:guess_mime(File),
- Res = ok({ContentType,
- [{"last-modified", LastModified}
- | ExtraHeaders],
- {file, IoDevice}}),
- file:close(IoDevice),
- Res;
- _ ->
- not_found(ExtraHeaders)
- end
- end;
- {error, _} ->
- not_found(ExtraHeaders)
- end.
-
-server_headers() ->
- [{"Server", "MochiWeb/1.0 (" ++ ?QUIP ++ ")"},
- {"Date", httpd_util:rfc1123_date()}].
-
-make_code(X) when is_integer(X) ->
- [integer_to_list(X), [" " | httpd_util:reason_phrase(X)]];
-make_code(Io) when is_list(Io); is_binary(Io) ->
- Io.
-
-make_version({1, 0}) ->
- <<"HTTP/1.0 ">>;
-make_version(_) ->
- <<"HTTP/1.1 ">>.
-
-range_parts({file, IoDevice}, Ranges) ->
- Size = mochiweb_io:iodevice_size(IoDevice),
- F = fun (Spec, Acc) ->
- case mochiweb_http:range_skip_length(Spec, Size) of
- invalid_range ->
- Acc;
- V ->
- [V | Acc]
- end
- end,
- LocNums = lists:foldr(F, [], Ranges),
- {ok, Data} = file:pread(IoDevice, LocNums),
- Bodies = lists:zipwith(fun ({Skip, Length}, PartialBody) ->
- {Skip, Skip + Length - 1, PartialBody}
- end,
- LocNums, Data),
- {Bodies, Size};
-range_parts(Body0, Ranges) ->
- Body = iolist_to_binary(Body0),
- Size = size(Body),
- F = fun(Spec, Acc) ->
- case mochiweb_http:range_skip_length(Spec, Size) of
- invalid_range ->
- Acc;
- {Skip, Length} ->
- <<_:Skip/binary, PartialBody:Length/binary, _/binary>> = Body,
- [{Skip, Skip + Length - 1, PartialBody} | Acc]
- end
- end,
- {lists:foldr(F, [], Ranges), Size}.
-
-%% @spec accepted_encodings([encoding()]) -> [encoding()] | bad_accept_encoding_value
-%% @type encoding() = string().
-%%
-%% @doc Returns a list of encodings accepted by a request. Encodings that are
-%% not supported by the server will not be included in the return list.
-%% This list is computed from the "Accept-Encoding" header and
-%% its elements are ordered, descendingly, according to their Q values.
-%%
-%% Section 14.3 of the RFC 2616 (HTTP 1.1) describes the "Accept-Encoding"
-%% header and the process of determining which server supported encodings
-%% can be used for encoding the body for the request's response.
-%%
-%% Examples
-%%
-%% 1) For a missing "Accept-Encoding" header:
-%% accepted_encodings(["gzip", "identity"]) -> ["identity"]
-%%
-%% 2) For an "Accept-Encoding" header with value "gzip, deflate":
-%% accepted_encodings(["gzip", "identity"]) -> ["gzip", "identity"]
-%%
-%% 3) For an "Accept-Encoding" header with value "gzip;q=0.5, deflate":
-%% accepted_encodings(["gzip", "deflate", "identity"]) ->
-%% ["deflate", "gzip", "identity"]
-%%
-accepted_encodings(SupportedEncodings) ->
- AcceptEncodingHeader = case get_header_value("Accept-Encoding") of
- undefined ->
- "";
- Value ->
- Value
- end,
- case mochiweb_util:parse_qvalues(AcceptEncodingHeader) of
- invalid_qvalue_string ->
- bad_accept_encoding_value;
- QList ->
- mochiweb_util:pick_accepted_encodings(
- QList, SupportedEncodings, "identity"
- )
- end.
-
-%% @spec accepts_content_type(string() | binary()) -> boolean() | bad_accept_header
-%%
-%% @doc Determines whether a request accepts a given media type by analyzing its
-%% "Accept" header.
-%%
-%% Examples
-%%
-%% 1) For a missing "Accept" header:
-%% accepts_content_type("application/json") -> true
-%%
-%% 2) For an "Accept" header with value "text/plain, application/*":
-%% accepts_content_type("application/json") -> true
-%%
-%% 3) For an "Accept" header with value "text/plain, */*; q=0.0":
-%% accepts_content_type("application/json") -> false
-%%
-%% 4) For an "Accept" header with value "text/plain; q=0.5, */*; q=0.1":
-%% accepts_content_type("application/json") -> true
-%%
-%% 5) For an "Accept" header with value "text/*; q=0.0, */*":
-%% accepts_content_type("text/plain") -> false
-%%
-accepts_content_type(ContentType) when is_binary(ContentType) ->
- accepts_content_type(binary_to_list(ContentType));
-accepts_content_type(ContentType1) ->
- ContentType = re:replace(ContentType1, "\\s", "", [global, {return, list}]),
- AcceptHeader = case get_header_value("Accept") of
- undefined ->
- "*/*";
- Value ->
- Value
- end,
- case mochiweb_util:parse_qvalues(AcceptHeader) of
- invalid_qvalue_string ->
- bad_accept_header;
- QList ->
- [MainType, _SubType] = string:tokens(ContentType, "/"),
- SuperType = MainType ++ "/*",
- lists:any(
- fun({"*/*", Q}) when Q > 0.0 ->
- true;
- ({Type, Q}) when Q > 0.0 ->
- Type =:= ContentType orelse Type =:= SuperType;
- (_) ->
- false
- end,
- QList
- ) andalso
- (not lists:member({ContentType, 0.0}, QList)) andalso
- (not lists:member({SuperType, 0.0}, QList))
- end.
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
--endif.
diff --git a/src/mochiweb/mochiweb_response.erl b/src/mochiweb/mochiweb_response.erl
deleted file mode 100644
index ab8ee61c..00000000
--- a/src/mochiweb/mochiweb_response.erl
+++ /dev/null
@@ -1,64 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2007 Mochi Media, Inc.
-
-%% @doc Response abstraction.
-
--module(mochiweb_response, [Request, Code, Headers]).
--author('bob@mochimedia.com').
-
--define(QUIP, "Any of you quaids got a smint?").
-
--export([get_header_value/1, get/1, dump/0]).
--export([send/1, write_chunk/1]).
-
-%% @spec get_header_value(string() | atom() | binary()) -> string() | undefined
-%% @doc Get the value of the given response header.
-get_header_value(K) ->
- mochiweb_headers:get_value(K, Headers).
-
-%% @spec get(request | code | headers) -> term()
-%% @doc Return the internal representation of the given field.
-get(request) ->
- Request;
-get(code) ->
- Code;
-get(headers) ->
- Headers.
-
-%% @spec dump() -> {mochiweb_request, [{atom(), term()}]}
-%% @doc Dump the internal representation to a "human readable" set of terms
-%% for debugging/inspection purposes.
-dump() ->
- [{request, Request:dump()},
- {code, Code},
- {headers, mochiweb_headers:to_list(Headers)}].
-
-%% @spec send(iodata()) -> ok
-%% @doc Send data over the socket if the method is not HEAD.
-send(Data) ->
- case Request:get(method) of
- 'HEAD' ->
- ok;
- _ ->
- Request:send(Data)
- end.
-
-%% @spec write_chunk(iodata()) -> ok
-%% @doc Write a chunk of a HTTP chunked response. If Data is zero length,
-%% then the chunked response will be finished.
-write_chunk(Data) ->
- case Request:get(version) of
- Version when Version >= {1, 1} ->
- Length = iolist_size(Data),
- send([io_lib:format("~.16b\r\n", [Length]), Data, <<"\r\n">>]);
- _ ->
- send(Data)
- end.
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
--endif.
diff --git a/src/mochiweb/mochiweb_skel.erl b/src/mochiweb/mochiweb_skel.erl
deleted file mode 100644
index 76eefa60..00000000
--- a/src/mochiweb/mochiweb_skel.erl
+++ /dev/null
@@ -1,86 +0,0 @@
--module(mochiweb_skel).
--export([skelcopy/2]).
-
--include_lib("kernel/include/file.hrl").
-
-%% External API
-
-skelcopy(DestDir, Name) ->
- ok = ensuredir(DestDir),
- LDst = case length(filename:dirname(DestDir)) of
- 1 -> %% handle case when dirname returns "/"
- 0;
- N ->
- N + 1
- end,
- skelcopy(src(), DestDir, Name, LDst),
- DestLink = filename:join([DestDir, Name, "deps", "mochiweb-src"]),
- ok = filelib:ensure_dir(DestLink),
- ok = file:make_symlink(
- filename:join(filename:dirname(code:which(?MODULE)), ".."),
- DestLink).
-
-%% Internal API
-
-src() ->
- Dir = filename:dirname(code:which(?MODULE)),
- filename:join(Dir, "../priv/skel").
-
-skel() ->
- "skel".
-
-skelcopy(Src, DestDir, Name, LDst) ->
- Dest = re:replace(filename:basename(Src), skel(), Name,
- [global, {return, list}]),
- case file:read_file_info(Src) of
- {ok, #file_info{type=directory, mode=Mode}} ->
- Dir = DestDir ++ "/" ++ Dest,
- EDst = lists:nthtail(LDst, Dir),
- ok = ensuredir(Dir),
- ok = file:write_file_info(Dir, #file_info{mode=Mode}),
- case filename:basename(Src) of
- "ebin" ->
- ok;
- _ ->
- {ok, Files} = file:list_dir(Src),
- io:format("~s/~n", [EDst]),
- lists:foreach(fun ("." ++ _) -> ok;
- (F) ->
- skelcopy(filename:join(Src, F),
- Dir,
- Name,
- LDst)
- end,
- Files),
- ok
- end;
- {ok, #file_info{type=regular, mode=Mode}} ->
- OutFile = filename:join(DestDir, Dest),
- {ok, B} = file:read_file(Src),
- S = re:replace(binary_to_list(B), skel(), Name,
- [{return, list}, global]),
- ok = file:write_file(OutFile, list_to_binary(S)),
- ok = file:write_file_info(OutFile, #file_info{mode=Mode}),
- io:format(" ~s~n", [filename:basename(Src)]),
- ok;
- {ok, _} ->
- io:format("ignored source file: ~p~n", [Src]),
- ok
- end.
-
-ensuredir(Dir) ->
- case file:make_dir(Dir) of
- ok ->
- ok;
- {error, eexist} ->
- ok;
- E ->
- E
- end.
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
--endif.
diff --git a/src/mochiweb/mochiweb_socket.erl b/src/mochiweb/mochiweb_socket.erl
deleted file mode 100644
index 76b018c8..00000000
--- a/src/mochiweb/mochiweb_socket.erl
+++ /dev/null
@@ -1,84 +0,0 @@
-%% @copyright 2010 Mochi Media, Inc.
-
-%% @doc MochiWeb socket - wrapper for plain and ssl sockets.
-
--module(mochiweb_socket).
-
--export([listen/4, accept/1, recv/3, send/2, close/1, port/1, peername/1,
- setopts/2, type/1]).
-
--define(ACCEPT_TIMEOUT, 2000).
-
-listen(Ssl, Port, Opts, SslOpts) ->
- case Ssl of
- true ->
- case ssl:listen(Port, Opts ++ SslOpts) of
- {ok, ListenSocket} ->
- {ok, {ssl, ListenSocket}};
- {error, _} = Err ->
- Err
- end;
- false ->
- gen_tcp:listen(Port, Opts)
- end.
-
-accept({ssl, ListenSocket}) ->
- % There's a bug in ssl:transport_accept/2 at the moment, which is the
- % reason for the try...catch block. Should be fixed in OTP R14.
- try ssl:transport_accept(ListenSocket) of
- {ok, Socket} ->
- case ssl:ssl_accept(Socket) of
- ok ->
- {ok, {ssl, Socket}};
- {error, _} = Err ->
- Err
- end;
- {error, _} = Err ->
- Err
- catch
- error:{badmatch, {error, Reason}} ->
- {error, Reason}
- end;
-accept(ListenSocket) ->
- gen_tcp:accept(ListenSocket, ?ACCEPT_TIMEOUT).
-
-recv({ssl, Socket}, Length, Timeout) ->
- ssl:recv(Socket, Length, Timeout);
-recv(Socket, Length, Timeout) ->
- gen_tcp:recv(Socket, Length, Timeout).
-
-send({ssl, Socket}, Data) ->
- ssl:send(Socket, Data);
-send(Socket, Data) ->
- gen_tcp:send(Socket, Data).
-
-close({ssl, Socket}) ->
- ssl:close(Socket);
-close(Socket) ->
- gen_tcp:close(Socket).
-
-port({ssl, Socket}) ->
- case ssl:sockname(Socket) of
- {ok, {_, Port}} ->
- {ok, Port};
- {error, _} = Err ->
- Err
- end;
-port(Socket) ->
- inet:port(Socket).
-
-peername({ssl, Socket}) ->
- ssl:peername(Socket);
-peername(Socket) ->
- inet:peername(Socket).
-
-setopts({ssl, Socket}, Opts) ->
- ssl:setopts(Socket, Opts);
-setopts(Socket, Opts) ->
- inet:setopts(Socket, Opts).
-
-type({ssl, _}) ->
- ssl;
-type(_) ->
- plain.
-
diff --git a/src/mochiweb/mochiweb_socket_server.erl b/src/mochiweb/mochiweb_socket_server.erl
deleted file mode 100644
index 1aae09ac..00000000
--- a/src/mochiweb/mochiweb_socket_server.erl
+++ /dev/null
@@ -1,272 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2007 Mochi Media, Inc.
-
-%% @doc MochiWeb socket server.
-
--module(mochiweb_socket_server).
--author('bob@mochimedia.com').
--behaviour(gen_server).
-
--include("internal.hrl").
-
--export([start/1, stop/1]).
--export([init/1, handle_call/3, handle_cast/2, terminate/2, code_change/3,
- handle_info/2]).
--export([get/2]).
-
--record(mochiweb_socket_server,
- {port,
- loop,
- name=undefined,
- %% NOTE: This is currently ignored.
- max=2048,
- ip=any,
- listen=null,
- nodelay=false,
- backlog=128,
- active_sockets=0,
- acceptor_pool_size=16,
- ssl=false,
- ssl_opts=[{ssl_imp, new}],
- acceptor_pool=sets:new()}).
-
-start(State=#mochiweb_socket_server{}) ->
- start_server(State);
-start(Options) ->
- start(parse_options(Options)).
-
-get(Name, Property) ->
- gen_server:call(Name, {get, Property}).
-
-stop(Name) when is_atom(Name) ->
- gen_server:cast(Name, stop);
-stop(Pid) when is_pid(Pid) ->
- gen_server:cast(Pid, stop);
-stop({local, Name}) ->
- stop(Name);
-stop({global, Name}) ->
- stop(Name);
-stop(Options) ->
- State = parse_options(Options),
- stop(State#mochiweb_socket_server.name).
-
-%% Internal API
-
-parse_options(Options) ->
- parse_options(Options, #mochiweb_socket_server{}).
-
-parse_options([], State) ->
- State;
-parse_options([{name, L} | Rest], State) when is_list(L) ->
- Name = {local, list_to_atom(L)},
- parse_options(Rest, State#mochiweb_socket_server{name=Name});
-parse_options([{name, A} | Rest], State) when A =:= undefined ->
- parse_options(Rest, State#mochiweb_socket_server{name=A});
-parse_options([{name, A} | Rest], State) when is_atom(A) ->
- Name = {local, A},
- parse_options(Rest, State#mochiweb_socket_server{name=Name});
-parse_options([{name, Name} | Rest], State) ->
- parse_options(Rest, State#mochiweb_socket_server{name=Name});
-parse_options([{port, L} | Rest], State) when is_list(L) ->
- Port = list_to_integer(L),
- parse_options(Rest, State#mochiweb_socket_server{port=Port});
-parse_options([{port, Port} | Rest], State) ->
- parse_options(Rest, State#mochiweb_socket_server{port=Port});
-parse_options([{ip, Ip} | Rest], State) ->
- ParsedIp = case Ip of
- any ->
- any;
- Ip when is_tuple(Ip) ->
- Ip;
- Ip when is_list(Ip) ->
- {ok, IpTuple} = inet_parse:address(Ip),
- IpTuple
- end,
- parse_options(Rest, State#mochiweb_socket_server{ip=ParsedIp});
-parse_options([{loop, Loop} | Rest], State) ->
- parse_options(Rest, State#mochiweb_socket_server{loop=Loop});
-parse_options([{backlog, Backlog} | Rest], State) ->
- parse_options(Rest, State#mochiweb_socket_server{backlog=Backlog});
-parse_options([{nodelay, NoDelay} | Rest], State) ->
- parse_options(Rest, State#mochiweb_socket_server{nodelay=NoDelay});
-parse_options([{acceptor_pool_size, Max} | Rest], State) ->
- MaxInt = ensure_int(Max),
- parse_options(Rest,
- State#mochiweb_socket_server{acceptor_pool_size=MaxInt});
-parse_options([{max, Max} | Rest], State) ->
- error_logger:info_report([{warning, "TODO: max is currently unsupported"},
- {max, Max}]),
- MaxInt = ensure_int(Max),
- parse_options(Rest, State#mochiweb_socket_server{max=MaxInt});
-parse_options([{ssl, Ssl} | Rest], State) when is_boolean(Ssl) ->
- parse_options(Rest, State#mochiweb_socket_server{ssl=Ssl});
-parse_options([{ssl_opts, SslOpts} | Rest], State) when is_list(SslOpts) ->
- SslOpts1 = [{ssl_imp, new} | proplists:delete(ssl_imp, SslOpts)],
- parse_options(Rest, State#mochiweb_socket_server{ssl_opts=SslOpts1}).
-
-start_server(State=#mochiweb_socket_server{ssl=Ssl, name=Name}) ->
- case Ssl of
- true ->
- application:start(crypto),
- application:start(public_key),
- application:start(ssl);
- false ->
- void
- end,
- case Name of
- undefined ->
- gen_server:start_link(?MODULE, State, []);
- _ ->
- gen_server:start_link(Name, ?MODULE, State, [])
- end.
-
-ensure_int(N) when is_integer(N) ->
- N;
-ensure_int(S) when is_list(S) ->
- integer_to_list(S).
-
-ipv6_supported() ->
- case (catch inet:getaddr("localhost", inet6)) of
- {ok, _Addr} ->
- true;
- {error, _} ->
- false
- end.
-
-init(State=#mochiweb_socket_server{ip=Ip, port=Port, backlog=Backlog, nodelay=NoDelay}) ->
- process_flag(trap_exit, true),
- BaseOpts = [binary,
- {reuseaddr, true},
- {packet, 0},
- {backlog, Backlog},
- {recbuf, ?RECBUF_SIZE},
- {active, false},
- {nodelay, NoDelay}],
- Opts = case Ip of
- any ->
- case ipv6_supported() of % IPv4, and IPv6 if supported
- true -> [inet, inet6 | BaseOpts];
- _ -> BaseOpts
- end;
- {_, _, _, _} -> % IPv4
- [inet, {ip, Ip} | BaseOpts];
- {_, _, _, _, _, _, _, _} -> % IPv6
- [inet6, {ip, Ip} | BaseOpts]
- end,
- case listen(Port, Opts, State) of
- {stop, eacces} ->
- case Port < 1024 of
- true ->
- case fdsrv:start() of
- {ok, _} ->
- case fdsrv:bind_socket(tcp, Port) of
- {ok, Fd} ->
- listen(Port, [{fd, Fd} | Opts], State);
- _ ->
- {stop, fdsrv_bind_failed}
- end;
- _ ->
- {stop, fdsrv_start_failed}
- end;
- false ->
- {stop, eacces}
- end;
- Other ->
- Other
- end.
-
-new_acceptor_pool(Listen,
- State=#mochiweb_socket_server{acceptor_pool=Pool,
- acceptor_pool_size=Size,
- loop=Loop}) ->
- F = fun (_, S) ->
- Pid = mochiweb_acceptor:start_link(self(), Listen, Loop),
- sets:add_element(Pid, S)
- end,
- Pool1 = lists:foldl(F, Pool, lists:seq(1, Size)),
- State#mochiweb_socket_server{acceptor_pool=Pool1}.
-
-listen(Port, Opts, State=#mochiweb_socket_server{ssl=Ssl, ssl_opts=SslOpts}) ->
- case mochiweb_socket:listen(Ssl, Port, Opts, SslOpts) of
- {ok, Listen} ->
- {ok, ListenPort} = mochiweb_socket:port(Listen),
- {ok, new_acceptor_pool(
- Listen,
- State#mochiweb_socket_server{listen=Listen,
- port=ListenPort})};
- {error, Reason} ->
- {stop, Reason}
- end.
-
-do_get(port, #mochiweb_socket_server{port=Port}) ->
- Port;
-do_get(active_sockets, #mochiweb_socket_server{active_sockets=ActiveSockets}) ->
- ActiveSockets.
-
-handle_call({get, Property}, _From, State) ->
- Res = do_get(Property, State),
- {reply, Res, State};
-handle_call(_Message, _From, State) ->
- Res = error,
- {reply, Res, State}.
-
-handle_cast({accepted, Pid, _Timing},
- State=#mochiweb_socket_server{active_sockets=ActiveSockets}) ->
- State1 = State#mochiweb_socket_server{active_sockets=1 + ActiveSockets},
- {noreply, recycle_acceptor(Pid, State1)};
-handle_cast(stop, State) ->
- {stop, normal, State}.
-
-terminate(_Reason, #mochiweb_socket_server{listen=Listen, port=Port}) ->
- mochiweb_socket:close(Listen),
- case Port < 1024 of
- true ->
- catch fdsrv:stop(),
- ok;
- false ->
- ok
- end.
-
-code_change(_OldVsn, State, _Extra) ->
- State.
-
-recycle_acceptor(Pid, State=#mochiweb_socket_server{
- acceptor_pool=Pool,
- listen=Listen,
- loop=Loop,
- active_sockets=ActiveSockets}) ->
- case sets:is_element(Pid, Pool) of
- true ->
- Acceptor = mochiweb_acceptor:start_link(self(), Listen, Loop),
- Pool1 = sets:add_element(Acceptor, sets:del_element(Pid, Pool)),
- State#mochiweb_socket_server{acceptor_pool=Pool1};
- false ->
- State#mochiweb_socket_server{active_sockets=ActiveSockets - 1}
- end.
-
-handle_info({'EXIT', Pid, normal}, State) ->
- {noreply, recycle_acceptor(Pid, State)};
-handle_info({'EXIT', Pid, Reason},
- State=#mochiweb_socket_server{acceptor_pool=Pool}) ->
- case sets:is_element(Pid, Pool) of
- true ->
- %% If there was an unexpected error accepting, log and sleep.
- error_logger:error_report({?MODULE, ?LINE,
- {acceptor_error, Reason}}),
- timer:sleep(100);
- false ->
- ok
- end,
- {noreply, recycle_acceptor(Pid, State)};
-handle_info(Info, State) ->
- error_logger:info_report([{'INFO', Info}, {'State', State}]),
- {noreply, State}.
-
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
--endif.
diff --git a/src/mochiweb/mochiweb_sup.erl b/src/mochiweb/mochiweb_sup.erl
deleted file mode 100644
index af7df9b3..00000000
--- a/src/mochiweb/mochiweb_sup.erl
+++ /dev/null
@@ -1,41 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2007 Mochi Media, Inc.
-
-%% @doc Supervisor for the mochiweb application.
-
--module(mochiweb_sup).
--author('bob@mochimedia.com').
-
--behaviour(supervisor).
-
-%% External exports
--export([start_link/0, upgrade/0]).
-
-%% supervisor callbacks
--export([init/1]).
-
-%% @spec start_link() -> ServerRet
-%% @doc API for starting the supervisor.
-start_link() ->
- supervisor:start_link({local, ?MODULE}, ?MODULE, []).
-
-%% @spec upgrade() -> ok
-%% @doc Add processes if necessary.
-upgrade() ->
- {ok, {_, Specs}} = init([]),
- [supervisor:start_child(?MODULE, Spec) || Spec <- Specs],
- ok.
-
-%% @spec init([]) -> SupervisorTree
-%% @doc supervisor callback, ensures yaws is in embedded mode and then
-%% returns the supervisor tree.
-init([]) ->
- Processes = [],
- {ok, {{one_for_one, 10, 10}, Processes}}.
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
--endif.
diff --git a/src/mochiweb/mochiweb_util.erl b/src/mochiweb/mochiweb_util.erl
deleted file mode 100644
index 62ff0d06..00000000
--- a/src/mochiweb/mochiweb_util.erl
+++ /dev/null
@@ -1,973 +0,0 @@
-%% @author Bob Ippolito <bob@mochimedia.com>
-%% @copyright 2007 Mochi Media, Inc.
-
-%% @doc Utilities for parsing and quoting.
-
--module(mochiweb_util).
--author('bob@mochimedia.com').
--export([join/2, quote_plus/1, urlencode/1, parse_qs/1, unquote/1]).
--export([path_split/1]).
--export([urlsplit/1, urlsplit_path/1, urlunsplit/1, urlunsplit_path/1]).
--export([guess_mime/1, parse_header/1]).
--export([shell_quote/1, cmd/1, cmd_string/1, cmd_port/2, cmd_status/1]).
--export([record_to_proplist/2, record_to_proplist/3]).
--export([safe_relative_path/1, partition/2]).
--export([parse_qvalues/1, pick_accepted_encodings/3]).
--export([make_io/1]).
-
--define(PERCENT, 37). % $\%
--define(FULLSTOP, 46). % $\.
--define(IS_HEX(C), ((C >= $0 andalso C =< $9) orelse
- (C >= $a andalso C =< $f) orelse
- (C >= $A andalso C =< $F))).
--define(QS_SAFE(C), ((C >= $a andalso C =< $z) orelse
- (C >= $A andalso C =< $Z) orelse
- (C >= $0 andalso C =< $9) orelse
- (C =:= ?FULLSTOP orelse C =:= $- orelse C =:= $~ orelse
- C =:= $_))).
-
-hexdigit(C) when C < 10 -> $0 + C;
-hexdigit(C) when C < 16 -> $A + (C - 10).
-
-unhexdigit(C) when C >= $0, C =< $9 -> C - $0;
-unhexdigit(C) when C >= $a, C =< $f -> C - $a + 10;
-unhexdigit(C) when C >= $A, C =< $F -> C - $A + 10.
-
-%% @spec partition(String, Sep) -> {String, [], []} | {Prefix, Sep, Postfix}
-%% @doc Inspired by Python 2.5's str.partition:
-%% partition("foo/bar", "/") = {"foo", "/", "bar"},
-%% partition("foo", "/") = {"foo", "", ""}.
-partition(String, Sep) ->
- case partition(String, Sep, []) of
- undefined ->
- {String, "", ""};
- Result ->
- Result
- end.
-
-partition("", _Sep, _Acc) ->
- undefined;
-partition(S, Sep, Acc) ->
- case partition2(S, Sep) of
- undefined ->
- [C | Rest] = S,
- partition(Rest, Sep, [C | Acc]);
- Rest ->
- {lists:reverse(Acc), Sep, Rest}
- end.
-
-partition2(Rest, "") ->
- Rest;
-partition2([C | R1], [C | R2]) ->
- partition2(R1, R2);
-partition2(_S, _Sep) ->
- undefined.
-
-
-
-%% @spec safe_relative_path(string()) -> string() | undefined
-%% @doc Return the reduced version of a relative path or undefined if it
-%% is not safe. safe relative paths can be joined with an absolute path
-%% and will result in a subdirectory of the absolute path.
-safe_relative_path("/" ++ _) ->
- undefined;
-safe_relative_path(P) ->
- safe_relative_path(P, []).
-
-safe_relative_path("", Acc) ->
- case Acc of
- [] ->
- "";
- _ ->
- string:join(lists:reverse(Acc), "/")
- end;
-safe_relative_path(P, Acc) ->
- case partition(P, "/") of
- {"", "/", _} ->
- %% /foo or foo//bar
- undefined;
- {"..", _, _} when Acc =:= [] ->
- undefined;
- {"..", _, Rest} ->
- safe_relative_path(Rest, tl(Acc));
- {Part, "/", ""} ->
- safe_relative_path("", ["", Part | Acc]);
- {Part, _, Rest} ->
- safe_relative_path(Rest, [Part | Acc])
- end.
-
-%% @spec shell_quote(string()) -> string()
-%% @doc Quote a string according to UNIX shell quoting rules, returns a string
-%% surrounded by double quotes.
-shell_quote(L) ->
- shell_quote(L, [$\"]).
-
-%% @spec cmd_port([string()], Options) -> port()
-%% @doc open_port({spawn, mochiweb_util:cmd_string(Argv)}, Options).
-cmd_port(Argv, Options) ->
- open_port({spawn, cmd_string(Argv)}, Options).
-
-%% @spec cmd([string()]) -> string()
-%% @doc os:cmd(cmd_string(Argv)).
-cmd(Argv) ->
- os:cmd(cmd_string(Argv)).
-
-%% @spec cmd_string([string()]) -> string()
-%% @doc Create a shell quoted command string from a list of arguments.
-cmd_string(Argv) ->
- string:join([shell_quote(X) || X <- Argv], " ").
-
-%% @spec cmd_status([string()]) -> {ExitStatus::integer(), Stdout::binary()}
-%% @doc Accumulate the output and exit status from the given application, will be
-%% spawned with cmd_port/2.
-cmd_status(Argv) ->
- Port = cmd_port(Argv, [exit_status, stderr_to_stdout,
- use_stdio, binary]),
- try cmd_loop(Port, [])
- after catch port_close(Port)
- end.
-
-%% @spec cmd_loop(port(), list()) -> {ExitStatus::integer(), Stdout::binary()}
-%% @doc Accumulate the output and exit status from a port.
-cmd_loop(Port, Acc) ->
- receive
- {Port, {exit_status, Status}} ->
- {Status, iolist_to_binary(lists:reverse(Acc))};
- {Port, {data, Data}} ->
- cmd_loop(Port, [Data | Acc])
- end.
-
-%% @spec join([iolist()], iolist()) -> iolist()
-%% @doc Join a list of strings or binaries together with the given separator
-%% string or char or binary. The output is flattened, but may be an
-%% iolist() instead of a string() if any of the inputs are binary().
-join([], _Separator) ->
- [];
-join([S], _Separator) ->
- lists:flatten(S);
-join(Strings, Separator) ->
- lists:flatten(revjoin(lists:reverse(Strings), Separator, [])).
-
-revjoin([], _Separator, Acc) ->
- Acc;
-revjoin([S | Rest], Separator, []) ->
- revjoin(Rest, Separator, [S]);
-revjoin([S | Rest], Separator, Acc) ->
- revjoin(Rest, Separator, [S, Separator | Acc]).
-
-%% @spec quote_plus(atom() | integer() | float() | string() | binary()) -> string()
-%% @doc URL safe encoding of the given term.
-quote_plus(Atom) when is_atom(Atom) ->
- quote_plus(atom_to_list(Atom));
-quote_plus(Int) when is_integer(Int) ->
- quote_plus(integer_to_list(Int));
-quote_plus(Binary) when is_binary(Binary) ->
- quote_plus(binary_to_list(Binary));
-quote_plus(Float) when is_float(Float) ->
- quote_plus(mochinum:digits(Float));
-quote_plus(String) ->
- quote_plus(String, []).
-
-quote_plus([], Acc) ->
- lists:reverse(Acc);
-quote_plus([C | Rest], Acc) when ?QS_SAFE(C) ->
- quote_plus(Rest, [C | Acc]);
-quote_plus([$\s | Rest], Acc) ->
- quote_plus(Rest, [$+ | Acc]);
-quote_plus([C | Rest], Acc) ->
- <<Hi:4, Lo:4>> = <<C>>,
- quote_plus(Rest, [hexdigit(Lo), hexdigit(Hi), ?PERCENT | Acc]).
-
-%% @spec urlencode([{Key, Value}]) -> string()
-%% @doc URL encode the property list.
-urlencode(Props) ->
- Pairs = lists:foldr(
- fun ({K, V}, Acc) ->
- [quote_plus(K) ++ "=" ++ quote_plus(V) | Acc]
- end, [], Props),
- string:join(Pairs, "&").
-
-%% @spec parse_qs(string() | binary()) -> [{Key, Value}]
-%% @doc Parse a query string or application/x-www-form-urlencoded.
-parse_qs(Binary) when is_binary(Binary) ->
- parse_qs(binary_to_list(Binary));
-parse_qs(String) ->
- parse_qs(String, []).
-
-parse_qs([], Acc) ->
- lists:reverse(Acc);
-parse_qs(String, Acc) ->
- {Key, Rest} = parse_qs_key(String),
- {Value, Rest1} = parse_qs_value(Rest),
- parse_qs(Rest1, [{Key, Value} | Acc]).
-
-parse_qs_key(String) ->
- parse_qs_key(String, []).
-
-parse_qs_key([], Acc) ->
- {qs_revdecode(Acc), ""};
-parse_qs_key([$= | Rest], Acc) ->
- {qs_revdecode(Acc), Rest};
-parse_qs_key(Rest=[$; | _], Acc) ->
- {qs_revdecode(Acc), Rest};
-parse_qs_key(Rest=[$& | _], Acc) ->
- {qs_revdecode(Acc), Rest};
-parse_qs_key([C | Rest], Acc) ->
- parse_qs_key(Rest, [C | Acc]).
-
-parse_qs_value(String) ->
- parse_qs_value(String, []).
-
-parse_qs_value([], Acc) ->
- {qs_revdecode(Acc), ""};
-parse_qs_value([$; | Rest], Acc) ->
- {qs_revdecode(Acc), Rest};
-parse_qs_value([$& | Rest], Acc) ->
- {qs_revdecode(Acc), Rest};
-parse_qs_value([C | Rest], Acc) ->
- parse_qs_value(Rest, [C | Acc]).
-
-%% @spec unquote(string() | binary()) -> string()
-%% @doc Unquote a URL encoded string.
-unquote(Binary) when is_binary(Binary) ->
- unquote(binary_to_list(Binary));
-unquote(String) ->
- qs_revdecode(lists:reverse(String)).
-
-qs_revdecode(S) ->
- qs_revdecode(S, []).
-
-qs_revdecode([], Acc) ->
- Acc;
-qs_revdecode([$+ | Rest], Acc) ->
- qs_revdecode(Rest, [$\s | Acc]);
-qs_revdecode([Lo, Hi, ?PERCENT | Rest], Acc) when ?IS_HEX(Lo), ?IS_HEX(Hi) ->
- qs_revdecode(Rest, [(unhexdigit(Lo) bor (unhexdigit(Hi) bsl 4)) | Acc]);
-qs_revdecode([C | Rest], Acc) ->
- qs_revdecode(Rest, [C | Acc]).
-
-%% @spec urlsplit(Url) -> {Scheme, Netloc, Path, Query, Fragment}
-%% @doc Return a 5-tuple, does not expand % escapes. Only supports HTTP style
-%% URLs.
-urlsplit(Url) ->
- {Scheme, Url1} = urlsplit_scheme(Url),
- {Netloc, Url2} = urlsplit_netloc(Url1),
- {Path, Query, Fragment} = urlsplit_path(Url2),
- {Scheme, Netloc, Path, Query, Fragment}.
-
-urlsplit_scheme(Url) ->
- case urlsplit_scheme(Url, []) of
- no_scheme ->
- {"", Url};
- Res ->
- Res
- end.
-
-urlsplit_scheme([C | Rest], Acc) when ((C >= $a andalso C =< $z) orelse
- (C >= $A andalso C =< $Z) orelse
- (C >= $0 andalso C =< $9) orelse
- C =:= $+ orelse C =:= $- orelse
- C =:= $.) ->
- urlsplit_scheme(Rest, [C | Acc]);
-urlsplit_scheme([$: | Rest], Acc=[_ | _]) ->
- {string:to_lower(lists:reverse(Acc)), Rest};
-urlsplit_scheme(_Rest, _Acc) ->
- no_scheme.
-
-urlsplit_netloc("//" ++ Rest) ->
- urlsplit_netloc(Rest, []);
-urlsplit_netloc(Path) ->
- {"", Path}.
-
-urlsplit_netloc("", Acc) ->
- {lists:reverse(Acc), ""};
-urlsplit_netloc(Rest=[C | _], Acc) when C =:= $/; C =:= $?; C =:= $# ->
- {lists:reverse(Acc), Rest};
-urlsplit_netloc([C | Rest], Acc) ->
- urlsplit_netloc(Rest, [C | Acc]).
-
-
-%% @spec path_split(string()) -> {Part, Rest}
-%% @doc Split a path starting from the left, as in URL traversal.
-%% path_split("foo/bar") = {"foo", "bar"},
-%% path_split("/foo/bar") = {"", "foo/bar"}.
-path_split(S) ->
- path_split(S, []).
-
-path_split("", Acc) ->
- {lists:reverse(Acc), ""};
-path_split("/" ++ Rest, Acc) ->
- {lists:reverse(Acc), Rest};
-path_split([C | Rest], Acc) ->
- path_split(Rest, [C | Acc]).
-
-
-%% @spec urlunsplit({Scheme, Netloc, Path, Query, Fragment}) -> string()
-%% @doc Assemble a URL from the 5-tuple. Path must be absolute.
-urlunsplit({Scheme, Netloc, Path, Query, Fragment}) ->
- lists:flatten([case Scheme of "" -> ""; _ -> [Scheme, "://"] end,
- Netloc,
- urlunsplit_path({Path, Query, Fragment})]).
-
-%% @spec urlunsplit_path({Path, Query, Fragment}) -> string()
-%% @doc Assemble a URL path from the 3-tuple.
-urlunsplit_path({Path, Query, Fragment}) ->
- lists:flatten([Path,
- case Query of "" -> ""; _ -> [$? | Query] end,
- case Fragment of "" -> ""; _ -> [$# | Fragment] end]).
-
-%% @spec urlsplit_path(Url) -> {Path, Query, Fragment}
-%% @doc Return a 3-tuple, does not expand % escapes. Only supports HTTP style
-%% paths.
-urlsplit_path(Path) ->
- urlsplit_path(Path, []).
-
-urlsplit_path("", Acc) ->
- {lists:reverse(Acc), "", ""};
-urlsplit_path("?" ++ Rest, Acc) ->
- {Query, Fragment} = urlsplit_query(Rest),
- {lists:reverse(Acc), Query, Fragment};
-urlsplit_path("#" ++ Rest, Acc) ->
- {lists:reverse(Acc), "", Rest};
-urlsplit_path([C | Rest], Acc) ->
- urlsplit_path(Rest, [C | Acc]).
-
-urlsplit_query(Query) ->
- urlsplit_query(Query, []).
-
-urlsplit_query("", Acc) ->
- {lists:reverse(Acc), ""};
-urlsplit_query("#" ++ Rest, Acc) ->
- {lists:reverse(Acc), Rest};
-urlsplit_query([C | Rest], Acc) ->
- urlsplit_query(Rest, [C | Acc]).
-
-%% @spec guess_mime(string()) -> string()
-%% @doc Guess the mime type of a file by the extension of its filename.
-guess_mime(File) ->
- case mochiweb_mime:from_extension(filename:extension(File)) of
- undefined ->
- "text/plain";
- Mime ->
- Mime
- end.
-
-%% @spec parse_header(string()) -> {Type, [{K, V}]}
-%% @doc Parse a Content-Type like header, return the main Content-Type
-%% and a property list of options.
-parse_header(String) ->
- %% TODO: This is exactly as broken as Python's cgi module.
- %% Should parse properly like mochiweb_cookies.
- [Type | Parts] = [string:strip(S) || S <- string:tokens(String, ";")],
- F = fun (S, Acc) ->
- case lists:splitwith(fun (C) -> C =/= $= end, S) of
- {"", _} ->
- %% Skip anything with no name
- Acc;
- {_, ""} ->
- %% Skip anything with no value
- Acc;
- {Name, [$\= | Value]} ->
- [{string:to_lower(string:strip(Name)),
- unquote_header(string:strip(Value))} | Acc]
- end
- end,
- {string:to_lower(Type),
- lists:foldr(F, [], Parts)}.
-
-unquote_header("\"" ++ Rest) ->
- unquote_header(Rest, []);
-unquote_header(S) ->
- S.
-
-unquote_header("", Acc) ->
- lists:reverse(Acc);
-unquote_header("\"", Acc) ->
- lists:reverse(Acc);
-unquote_header([$\\, C | Rest], Acc) ->
- unquote_header(Rest, [C | Acc]);
-unquote_header([C | Rest], Acc) ->
- unquote_header(Rest, [C | Acc]).
-
-%% @spec record_to_proplist(Record, Fields) -> proplist()
-%% @doc calls record_to_proplist/3 with a default TypeKey of '__record'
-record_to_proplist(Record, Fields) ->
- record_to_proplist(Record, Fields, '__record').
-
-%% @spec record_to_proplist(Record, Fields, TypeKey) -> proplist()
-%% @doc Return a proplist of the given Record with each field in the
-%% Fields list set as a key with the corresponding value in the Record.
-%% TypeKey is the key that is used to store the record type
-%% Fields should be obtained by calling record_info(fields, record_type)
-%% where record_type is the record type of Record
-record_to_proplist(Record, Fields, TypeKey)
- when tuple_size(Record) - 1 =:= length(Fields) ->
- lists:zip([TypeKey | Fields], tuple_to_list(Record)).
-
-
-shell_quote([], Acc) ->
- lists:reverse([$\" | Acc]);
-shell_quote([C | Rest], Acc) when C =:= $\" orelse C =:= $\` orelse
- C =:= $\\ orelse C =:= $\$ ->
- shell_quote(Rest, [C, $\\ | Acc]);
-shell_quote([C | Rest], Acc) ->
- shell_quote(Rest, [C | Acc]).
-
-%% @spec parse_qvalues(string()) -> [qvalue()] | invalid_qvalue_string
-%% @type qvalue() = {media_type() | encoding() , float()}.
-%% @type media_type() = string().
-%% @type encoding() = string().
-%%
-%% @doc Parses a list (given as a string) of elements with Q values associated
-%% to them. Elements are separated by commas and each element is separated
-%% from its Q value by a semicolon. Q values are optional but when missing
-%% the value of an element is considered as 1.0. A Q value is always in the
-%% range [0.0, 1.0]. A Q value list is used for example as the value of the
-%% HTTP "Accept" and "Accept-Encoding" headers.
-%%
-%% Q values are described in section 2.9 of the RFC 2616 (HTTP 1.1).
-%%
-%% Example:
-%%
-%% parse_qvalues("gzip; q=0.5, deflate, identity;q=0.0") ->
-%% [{"gzip", 0.5}, {"deflate", 1.0}, {"identity", 0.0}]
-%%
-parse_qvalues(QValuesStr) ->
- try
- lists:map(
- fun(Pair) ->
- [Type | Params] = string:tokens(Pair, ";"),
- NormParams = normalize_media_params(Params),
- {Q, NonQParams} = extract_q(NormParams),
- {string:join([string:strip(Type) | NonQParams], ";"), Q}
- end,
- string:tokens(string:to_lower(QValuesStr), ",")
- )
- catch
- _Type:_Error ->
- invalid_qvalue_string
- end.
-
-normalize_media_params(Params) ->
- {ok, Re} = re:compile("\\s"),
- normalize_media_params(Re, Params, []).
-
-normalize_media_params(_Re, [], Acc) ->
- lists:reverse(Acc);
-normalize_media_params(Re, [Param | Rest], Acc) ->
- NormParam = re:replace(Param, Re, "", [global, {return, list}]),
- normalize_media_params(Re, Rest, [NormParam | Acc]).
-
-extract_q(NormParams) ->
- {ok, KVRe} = re:compile("^([^=]+)=([^=]+)$"),
- {ok, QRe} = re:compile("^((?:0|1)(?:\\.\\d{1,3})?)$"),
- extract_q(KVRe, QRe, NormParams, []).
-
-extract_q(_KVRe, _QRe, [], Acc) ->
- {1.0, lists:reverse(Acc)};
-extract_q(KVRe, QRe, [Param | Rest], Acc) ->
- case re:run(Param, KVRe, [{capture, [1, 2], list}]) of
- {match, [Name, Value]} ->
- case Name of
- "q" ->
- {match, [Q]} = re:run(Value, QRe, [{capture, [1], list}]),
- QVal = case Q of
- "0" ->
- 0.0;
- "1" ->
- 1.0;
- Else ->
- list_to_float(Else)
- end,
- case QVal < 0.0 orelse QVal > 1.0 of
- false ->
- {QVal, lists:reverse(Acc) ++ Rest}
- end;
- _ ->
- extract_q(KVRe, QRe, Rest, [Param | Acc])
- end
- end.
-
-%% @spec pick_accepted_encodings([qvalue()], [encoding()], encoding()) ->
-%% [encoding()]
-%%
-%% @doc Determines which encodings specified in the given Q values list are
-%% valid according to a list of supported encodings and a default encoding.
-%%
-%% The returned list of encodings is sorted, descendingly, according to the
-%% Q values of the given list. The last element of this list is the given
-%% default encoding unless this encoding is explicitily or implicitily
-%% marked with a Q value of 0.0 in the given Q values list.
-%% Note: encodings with the same Q value are kept in the same order as
-%% found in the input Q values list.
-%%
-%% This encoding picking process is described in section 14.3 of the
-%% RFC 2616 (HTTP 1.1).
-%%
-%% Example:
-%%
-%% pick_accepted_encodings(
-%% [{"gzip", 0.5}, {"deflate", 1.0}],
-%% ["gzip", "identity"],
-%% "identity"
-%% ) ->
-%% ["gzip", "identity"]
-%%
-pick_accepted_encodings(AcceptedEncs, SupportedEncs, DefaultEnc) ->
- SortedQList = lists:reverse(
- lists:sort(fun({_, Q1}, {_, Q2}) -> Q1 < Q2 end, AcceptedEncs)
- ),
- {Accepted, Refused} = lists:foldr(
- fun({E, Q}, {A, R}) ->
- case Q > 0.0 of
- true ->
- {[E | A], R};
- false ->
- {A, [E | R]}
- end
- end,
- {[], []},
- SortedQList
- ),
- Refused1 = lists:foldr(
- fun(Enc, Acc) ->
- case Enc of
- "*" ->
- lists:subtract(SupportedEncs, Accepted) ++ Acc;
- _ ->
- [Enc | Acc]
- end
- end,
- [],
- Refused
- ),
- Accepted1 = lists:foldr(
- fun(Enc, Acc) ->
- case Enc of
- "*" ->
- lists:subtract(SupportedEncs, Accepted ++ Refused1) ++ Acc;
- _ ->
- [Enc | Acc]
- end
- end,
- [],
- Accepted
- ),
- Accepted2 = case lists:member(DefaultEnc, Accepted1) of
- true ->
- Accepted1;
- false ->
- Accepted1 ++ [DefaultEnc]
- end,
- [E || E <- Accepted2, lists:member(E, SupportedEncs),
- not lists:member(E, Refused1)].
-
-make_io(Atom) when is_atom(Atom) ->
- atom_to_list(Atom);
-make_io(Integer) when is_integer(Integer) ->
- integer_to_list(Integer);
-make_io(Io) when is_list(Io); is_binary(Io) ->
- Io.
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-make_io_test() ->
- ?assertEqual(
- <<"atom">>,
- iolist_to_binary(make_io(atom))),
- ?assertEqual(
- <<"20">>,
- iolist_to_binary(make_io(20))),
- ?assertEqual(
- <<"list">>,
- iolist_to_binary(make_io("list"))),
- ?assertEqual(
- <<"binary">>,
- iolist_to_binary(make_io(<<"binary">>))),
- ok.
-
--record(test_record, {field1=f1, field2=f2}).
-record_to_proplist_test() ->
- ?assertEqual(
- [{'__record', test_record},
- {field1, f1},
- {field2, f2}],
- record_to_proplist(#test_record{}, record_info(fields, test_record))),
- ?assertEqual(
- [{'typekey', test_record},
- {field1, f1},
- {field2, f2}],
- record_to_proplist(#test_record{},
- record_info(fields, test_record),
- typekey)),
- ok.
-
-shell_quote_test() ->
- ?assertEqual(
- "\"foo \\$bar\\\"\\`' baz\"",
- shell_quote("foo $bar\"`' baz")),
- ok.
-
-cmd_port_test_spool(Port, Acc) ->
- receive
- {Port, eof} ->
- Acc;
- {Port, {data, {eol, Data}}} ->
- cmd_port_test_spool(Port, ["\n", Data | Acc]);
- {Port, Unknown} ->
- throw({unknown, Unknown})
- after 100 ->
- throw(timeout)
- end.
-
-cmd_port_test() ->
- Port = cmd_port(["echo", "$bling$ `word`!"],
- [eof, stream, {line, 4096}]),
- Res = try lists:append(lists:reverse(cmd_port_test_spool(Port, [])))
- after catch port_close(Port)
- end,
- self() ! {Port, wtf},
- try cmd_port_test_spool(Port, [])
- catch throw:{unknown, wtf} -> ok
- end,
- try cmd_port_test_spool(Port, [])
- catch throw:timeout -> ok
- end,
- ?assertEqual(
- "$bling$ `word`!\n",
- Res).
-
-cmd_test() ->
- ?assertEqual(
- "$bling$ `word`!\n",
- cmd(["echo", "$bling$ `word`!"])),
- ok.
-
-cmd_string_test() ->
- ?assertEqual(
- "\"echo\" \"\\$bling\\$ \\`word\\`!\"",
- cmd_string(["echo", "$bling$ `word`!"])),
- ok.
-
-cmd_status_test() ->
- ?assertEqual(
- {0, <<"$bling$ `word`!\n">>},
- cmd_status(["echo", "$bling$ `word`!"])),
- ok.
-
-
-parse_header_test() ->
- ?assertEqual(
- {"multipart/form-data", [{"boundary", "AaB03x"}]},
- parse_header("multipart/form-data; boundary=AaB03x")),
- %% This tests (currently) intentionally broken behavior
- ?assertEqual(
- {"multipart/form-data",
- [{"b", ""},
- {"cgi", "is"},
- {"broken", "true\"e"}]},
- parse_header("multipart/form-data;b=;cgi=\"i\\s;broken=true\"e;=z;z")),
- ok.
-
-guess_mime_test() ->
- "text/plain" = guess_mime(""),
- "text/plain" = guess_mime(".text"),
- "application/zip" = guess_mime(".zip"),
- "application/zip" = guess_mime("x.zip"),
- "text/html" = guess_mime("x.html"),
- "application/xhtml+xml" = guess_mime("x.xhtml"),
- ok.
-
-path_split_test() ->
- {"", "foo/bar"} = path_split("/foo/bar"),
- {"foo", "bar"} = path_split("foo/bar"),
- {"bar", ""} = path_split("bar"),
- ok.
-
-urlsplit_test() ->
- {"", "", "/foo", "", "bar?baz"} = urlsplit("/foo#bar?baz"),
- {"http", "host:port", "/foo", "", "bar?baz"} =
- urlsplit("http://host:port/foo#bar?baz"),
- {"http", "host", "", "", ""} = urlsplit("http://host"),
- {"", "", "/wiki/Category:Fruit", "", ""} =
- urlsplit("/wiki/Category:Fruit"),
- ok.
-
-urlsplit_path_test() ->
- {"/foo/bar", "", ""} = urlsplit_path("/foo/bar"),
- {"/foo", "baz", ""} = urlsplit_path("/foo?baz"),
- {"/foo", "", "bar?baz"} = urlsplit_path("/foo#bar?baz"),
- {"/foo", "", "bar?baz#wibble"} = urlsplit_path("/foo#bar?baz#wibble"),
- {"/foo", "bar", "baz"} = urlsplit_path("/foo?bar#baz"),
- {"/foo", "bar?baz", "baz"} = urlsplit_path("/foo?bar?baz#baz"),
- ok.
-
-urlunsplit_test() ->
- "/foo#bar?baz" = urlunsplit({"", "", "/foo", "", "bar?baz"}),
- "http://host:port/foo#bar?baz" =
- urlunsplit({"http", "host:port", "/foo", "", "bar?baz"}),
- ok.
-
-urlunsplit_path_test() ->
- "/foo/bar" = urlunsplit_path({"/foo/bar", "", ""}),
- "/foo?baz" = urlunsplit_path({"/foo", "baz", ""}),
- "/foo#bar?baz" = urlunsplit_path({"/foo", "", "bar?baz"}),
- "/foo#bar?baz#wibble" = urlunsplit_path({"/foo", "", "bar?baz#wibble"}),
- "/foo?bar#baz" = urlunsplit_path({"/foo", "bar", "baz"}),
- "/foo?bar?baz#baz" = urlunsplit_path({"/foo", "bar?baz", "baz"}),
- ok.
-
-join_test() ->
- ?assertEqual("foo,bar,baz",
- join(["foo", "bar", "baz"], $,)),
- ?assertEqual("foo,bar,baz",
- join(["foo", "bar", "baz"], ",")),
- ?assertEqual("foo bar",
- join([["foo", " bar"]], ",")),
- ?assertEqual("foo bar,baz",
- join([["foo", " bar"], "baz"], ",")),
- ?assertEqual("foo",
- join(["foo"], ",")),
- ?assertEqual("foobarbaz",
- join(["foo", "bar", "baz"], "")),
- ?assertEqual("foo" ++ [<<>>] ++ "bar" ++ [<<>>] ++ "baz",
- join(["foo", "bar", "baz"], <<>>)),
- ?assertEqual("foobar" ++ [<<"baz">>],
- join(["foo", "bar", <<"baz">>], "")),
- ?assertEqual("",
- join([], "any")),
- ok.
-
-quote_plus_test() ->
- "foo" = quote_plus(foo),
- "1" = quote_plus(1),
- "1.1" = quote_plus(1.1),
- "foo" = quote_plus("foo"),
- "foo+bar" = quote_plus("foo bar"),
- "foo%0A" = quote_plus("foo\n"),
- "foo%0A" = quote_plus("foo\n"),
- "foo%3B%26%3D" = quote_plus("foo;&="),
- "foo%3B%26%3D" = quote_plus(<<"foo;&=">>),
- ok.
-
-unquote_test() ->
- ?assertEqual("foo bar",
- unquote("foo+bar")),
- ?assertEqual("foo bar",
- unquote("foo%20bar")),
- ?assertEqual("foo\r\n",
- unquote("foo%0D%0A")),
- ?assertEqual("foo\r\n",
- unquote(<<"foo%0D%0A">>)),
- ok.
-
-urlencode_test() ->
- "foo=bar&baz=wibble+%0D%0A&z=1" = urlencode([{foo, "bar"},
- {"baz", "wibble \r\n"},
- {z, 1}]),
- ok.
-
-parse_qs_test() ->
- ?assertEqual(
- [{"foo", "bar"}, {"baz", "wibble \r\n"}, {"z", "1"}],
- parse_qs("foo=bar&baz=wibble+%0D%0a&z=1")),
- ?assertEqual(
- [{"", "bar"}, {"baz", "wibble \r\n"}, {"z", ""}],
- parse_qs("=bar&baz=wibble+%0D%0a&z=")),
- ?assertEqual(
- [{"foo", "bar"}, {"baz", "wibble \r\n"}, {"z", "1"}],
- parse_qs(<<"foo=bar&baz=wibble+%0D%0a&z=1">>)),
- ?assertEqual(
- [],
- parse_qs("")),
- ?assertEqual(
- [{"foo", ""}, {"bar", ""}, {"baz", ""}],
- parse_qs("foo;bar&baz")),
- ok.
-
-partition_test() ->
- {"foo", "", ""} = partition("foo", "/"),
- {"foo", "/", "bar"} = partition("foo/bar", "/"),
- {"foo", "/", ""} = partition("foo/", "/"),
- {"", "/", "bar"} = partition("/bar", "/"),
- {"f", "oo/ba", "r"} = partition("foo/bar", "oo/ba"),
- ok.
-
-safe_relative_path_test() ->
- "foo" = safe_relative_path("foo"),
- "foo/" = safe_relative_path("foo/"),
- "foo" = safe_relative_path("foo/bar/.."),
- "bar" = safe_relative_path("foo/../bar"),
- "bar/" = safe_relative_path("foo/../bar/"),
- "" = safe_relative_path("foo/.."),
- "" = safe_relative_path("foo/../"),
- undefined = safe_relative_path("/foo"),
- undefined = safe_relative_path("../foo"),
- undefined = safe_relative_path("foo/../.."),
- undefined = safe_relative_path("foo//"),
- ok.
-
-parse_qvalues_test() ->
- [] = parse_qvalues(""),
- [{"identity", 0.0}] = parse_qvalues("identity;q=0"),
- [{"identity", 0.0}] = parse_qvalues("identity ;q=0"),
- [{"identity", 0.0}] = parse_qvalues(" identity; q =0 "),
- [{"identity", 0.0}] = parse_qvalues("identity ; q = 0"),
- [{"identity", 0.0}] = parse_qvalues("identity ; q= 0.0"),
- [{"gzip", 1.0}, {"deflate", 1.0}, {"identity", 0.0}] = parse_qvalues(
- "gzip,deflate,identity;q=0.0"
- ),
- [{"deflate", 1.0}, {"gzip", 1.0}, {"identity", 0.0}] = parse_qvalues(
- "deflate,gzip,identity;q=0.0"
- ),
- [{"gzip", 1.0}, {"deflate", 1.0}, {"gzip", 1.0}, {"identity", 0.0}] =
- parse_qvalues("gzip,deflate,gzip,identity;q=0"),
- [{"gzip", 1.0}, {"deflate", 1.0}, {"identity", 0.0}] = parse_qvalues(
- "gzip, deflate , identity; q=0.0"
- ),
- [{"gzip", 1.0}, {"deflate", 1.0}, {"identity", 0.0}] = parse_qvalues(
- "gzip; q=1, deflate;q=1.0, identity;q=0.0"
- ),
- [{"gzip", 0.5}, {"deflate", 1.0}, {"identity", 0.0}] = parse_qvalues(
- "gzip; q=0.5, deflate;q=1.0, identity;q=0"
- ),
- [{"gzip", 0.5}, {"deflate", 1.0}, {"identity", 0.0}] = parse_qvalues(
- "gzip; q=0.5, deflate , identity;q=0.0"
- ),
- [{"gzip", 0.5}, {"deflate", 0.8}, {"identity", 0.0}] = parse_qvalues(
- "gzip; q=0.5, deflate;q=0.8, identity;q=0.0"
- ),
- [{"gzip", 0.5}, {"deflate", 1.0}, {"identity", 1.0}] = parse_qvalues(
- "gzip; q=0.5,deflate,identity"
- ),
- [{"gzip", 0.5}, {"deflate", 1.0}, {"identity", 1.0}, {"identity", 1.0}] =
- parse_qvalues("gzip; q=0.5,deflate,identity, identity "),
- [{"text/html;level=1", 1.0}, {"text/plain", 0.5}] =
- parse_qvalues("text/html;level=1, text/plain;q=0.5"),
- [{"text/html;level=1", 0.3}, {"text/plain", 1.0}] =
- parse_qvalues("text/html;level=1;q=0.3, text/plain"),
- [{"text/html;level=1", 0.3}, {"text/plain", 1.0}] =
- parse_qvalues("text/html; level = 1; q = 0.3, text/plain"),
- [{"text/html;level=1", 0.3}, {"text/plain", 1.0}] =
- parse_qvalues("text/html;q=0.3;level=1, text/plain"),
- invalid_qvalue_string = parse_qvalues("gzip; q=1.1, deflate"),
- invalid_qvalue_string = parse_qvalues("gzip; q=0.5, deflate;q=2"),
- invalid_qvalue_string = parse_qvalues("gzip, deflate;q=AB"),
- invalid_qvalue_string = parse_qvalues("gzip; q=2.1, deflate"),
- invalid_qvalue_string = parse_qvalues("gzip; q=0.1234, deflate"),
- invalid_qvalue_string = parse_qvalues("text/html;level=1;q=0.3, text/html;level"),
- ok.
-
-pick_accepted_encodings_test() ->
- ["identity"] = pick_accepted_encodings(
- [],
- ["gzip", "identity"],
- "identity"
- ),
- ["gzip", "identity"] = pick_accepted_encodings(
- [{"gzip", 1.0}],
- ["gzip", "identity"],
- "identity"
- ),
- ["identity"] = pick_accepted_encodings(
- [{"gzip", 0.0}],
- ["gzip", "identity"],
- "identity"
- ),
- ["gzip", "identity"] = pick_accepted_encodings(
- [{"gzip", 1.0}, {"deflate", 1.0}],
- ["gzip", "identity"],
- "identity"
- ),
- ["gzip", "identity"] = pick_accepted_encodings(
- [{"gzip", 0.5}, {"deflate", 1.0}],
- ["gzip", "identity"],
- "identity"
- ),
- ["identity"] = pick_accepted_encodings(
- [{"gzip", 0.0}, {"deflate", 0.0}],
- ["gzip", "identity"],
- "identity"
- ),
- ["gzip"] = pick_accepted_encodings(
- [{"gzip", 1.0}, {"deflate", 1.0}, {"identity", 0.0}],
- ["gzip", "identity"],
- "identity"
- ),
- ["gzip", "deflate", "identity"] = pick_accepted_encodings(
- [{"gzip", 1.0}, {"deflate", 1.0}],
- ["gzip", "deflate", "identity"],
- "identity"
- ),
- ["gzip", "deflate"] = pick_accepted_encodings(
- [{"gzip", 1.0}, {"deflate", 1.0}, {"identity", 0.0}],
- ["gzip", "deflate", "identity"],
- "identity"
- ),
- ["deflate", "gzip", "identity"] = pick_accepted_encodings(
- [{"gzip", 0.2}, {"deflate", 1.0}],
- ["gzip", "deflate", "identity"],
- "identity"
- ),
- ["deflate", "deflate", "gzip", "identity"] = pick_accepted_encodings(
- [{"gzip", 0.2}, {"deflate", 1.0}, {"deflate", 1.0}],
- ["gzip", "deflate", "identity"],
- "identity"
- ),
- ["deflate", "gzip", "gzip", "identity"] = pick_accepted_encodings(
- [{"gzip", 0.2}, {"deflate", 1.0}, {"gzip", 1.0}],
- ["gzip", "deflate", "identity"],
- "identity"
- ),
- ["gzip", "deflate", "gzip", "identity"] = pick_accepted_encodings(
- [{"gzip", 0.2}, {"deflate", 0.9}, {"gzip", 1.0}],
- ["gzip", "deflate", "identity"],
- "identity"
- ),
- [] = pick_accepted_encodings(
- [{"*", 0.0}],
- ["gzip", "deflate", "identity"],
- "identity"
- ),
- ["gzip", "deflate", "identity"] = pick_accepted_encodings(
- [{"*", 1.0}],
- ["gzip", "deflate", "identity"],
- "identity"
- ),
- ["gzip", "deflate", "identity"] = pick_accepted_encodings(
- [{"*", 0.6}],
- ["gzip", "deflate", "identity"],
- "identity"
- ),
- ["gzip"] = pick_accepted_encodings(
- [{"gzip", 1.0}, {"*", 0.0}],
- ["gzip", "deflate", "identity"],
- "identity"
- ),
- ["gzip", "deflate"] = pick_accepted_encodings(
- [{"gzip", 1.0}, {"deflate", 0.6}, {"*", 0.0}],
- ["gzip", "deflate", "identity"],
- "identity"
- ),
- ["deflate", "gzip"] = pick_accepted_encodings(
- [{"gzip", 0.5}, {"deflate", 1.0}, {"*", 0.0}],
- ["gzip", "deflate", "identity"],
- "identity"
- ),
- ["gzip", "identity"] = pick_accepted_encodings(
- [{"deflate", 0.0}, {"*", 1.0}],
- ["gzip", "deflate", "identity"],
- "identity"
- ),
- ["gzip", "identity"] = pick_accepted_encodings(
- [{"*", 1.0}, {"deflate", 0.0}],
- ["gzip", "deflate", "identity"],
- "identity"
- ),
- ok.
-
--endif.
diff --git a/src/mochiweb/reloader.erl b/src/mochiweb/reloader.erl
deleted file mode 100644
index c0f5de88..00000000
--- a/src/mochiweb/reloader.erl
+++ /dev/null
@@ -1,161 +0,0 @@
-%% @copyright 2007 Mochi Media, Inc.
-%% @author Matthew Dempsky <matthew@mochimedia.com>
-%%
-%% @doc Erlang module for automatically reloading modified modules
-%% during development.
-
--module(reloader).
--author("Matthew Dempsky <matthew@mochimedia.com>").
-
--include_lib("kernel/include/file.hrl").
-
--behaviour(gen_server).
--export([start/0, start_link/0]).
--export([stop/0]).
--export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
--export([all_changed/0]).
--export([is_changed/1]).
--export([reload_modules/1]).
--record(state, {last, tref}).
-
-%% External API
-
-%% @spec start() -> ServerRet
-%% @doc Start the reloader.
-start() ->
- gen_server:start({local, ?MODULE}, ?MODULE, [], []).
-
-%% @spec start_link() -> ServerRet
-%% @doc Start the reloader.
-start_link() ->
- gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
-
-%% @spec stop() -> ok
-%% @doc Stop the reloader.
-stop() ->
- gen_server:call(?MODULE, stop).
-
-%% gen_server callbacks
-
-%% @spec init([]) -> {ok, State}
-%% @doc gen_server init, opens the server in an initial state.
-init([]) ->
- {ok, TRef} = timer:send_interval(timer:seconds(1), doit),
- {ok, #state{last = stamp(), tref = TRef}}.
-
-%% @spec handle_call(Args, From, State) -> tuple()
-%% @doc gen_server callback.
-handle_call(stop, _From, State) ->
- {stop, shutdown, stopped, State};
-handle_call(_Req, _From, State) ->
- {reply, {error, badrequest}, State}.
-
-%% @spec handle_cast(Cast, State) -> tuple()
-%% @doc gen_server callback.
-handle_cast(_Req, State) ->
- {noreply, State}.
-
-%% @spec handle_info(Info, State) -> tuple()
-%% @doc gen_server callback.
-handle_info(doit, State) ->
- Now = stamp(),
- doit(State#state.last, Now),
- {noreply, State#state{last = Now}};
-handle_info(_Info, State) ->
- {noreply, State}.
-
-%% @spec terminate(Reason, State) -> ok
-%% @doc gen_server termination callback.
-terminate(_Reason, State) ->
- {ok, cancel} = timer:cancel(State#state.tref),
- ok.
-
-
-%% @spec code_change(_OldVsn, State, _Extra) -> State
-%% @doc gen_server code_change callback (trivial).
-code_change(_Vsn, State, _Extra) ->
- {ok, State}.
-
-%% @spec reload_modules([atom()]) -> [{module, atom()} | {error, term()}]
-%% @doc code:purge/1 and code:load_file/1 the given list of modules in order,
-%% return the results of code:load_file/1.
-reload_modules(Modules) ->
- [begin code:purge(M), code:load_file(M) end || M <- Modules].
-
-%% @spec all_changed() -> [atom()]
-%% @doc Return a list of beam modules that have changed.
-all_changed() ->
- [M || {M, Fn} <- code:all_loaded(), is_list(Fn), is_changed(M)].
-
-%% @spec is_changed(atom()) -> boolean()
-%% @doc true if the loaded module is a beam with a vsn attribute
-%% and does not match the on-disk beam file, returns false otherwise.
-is_changed(M) ->
- try
- module_vsn(M:module_info()) =/= module_vsn(code:get_object_code(M))
- catch _:_ ->
- false
- end.
-
-%% Internal API
-
-module_vsn({M, Beam, _Fn}) ->
- {ok, {M, Vsn}} = beam_lib:version(Beam),
- Vsn;
-module_vsn(L) when is_list(L) ->
- {_, Attrs} = lists:keyfind(attributes, 1, L),
- {_, Vsn} = lists:keyfind(vsn, 1, Attrs),
- Vsn.
-
-doit(From, To) ->
- [case file:read_file_info(Filename) of
- {ok, #file_info{mtime = Mtime}} when Mtime >= From, Mtime < To ->
- reload(Module);
- {ok, _} ->
- unmodified;
- {error, enoent} ->
- %% The Erlang compiler deletes existing .beam files if
- %% recompiling fails. Maybe it's worth spitting out a
- %% warning here, but I'd want to limit it to just once.
- gone;
- {error, Reason} ->
- io:format("Error reading ~s's file info: ~p~n",
- [Filename, Reason]),
- error
- end || {Module, Filename} <- code:all_loaded(), is_list(Filename)].
-
-reload(Module) ->
- io:format("Reloading ~p ...", [Module]),
- code:purge(Module),
- case code:load_file(Module) of
- {module, Module} ->
- io:format(" ok.~n"),
- case erlang:function_exported(Module, test, 0) of
- true ->
- io:format(" - Calling ~p:test() ...", [Module]),
- case catch Module:test() of
- ok ->
- io:format(" ok.~n"),
- reload;
- Reason ->
- io:format(" fail: ~p.~n", [Reason]),
- reload_but_test_failed
- end;
- false ->
- reload
- end;
- {error, Reason} ->
- io:format(" fail: ~p.~n", [Reason]),
- error
- end.
-
-
-stamp() ->
- erlang:localtime().
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
--endif.
diff --git a/test/Makefile.am b/test/Makefile.am
deleted file mode 100644
index 45130a64..00000000
--- a/test/Makefile.am
+++ /dev/null
@@ -1,14 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-SUBDIRS = bench etap javascript view_server
-
diff --git a/test/bench/Makefile.am b/test/bench/Makefile.am
deleted file mode 100644
index ce39c4b0..00000000
--- a/test/bench/Makefile.am
+++ /dev/null
@@ -1,22 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-EXTRA_DIST = benchbulk.sh bench_marks.js run.tpl
-
-noinst_SCRIPTS = run
-CLEANFILES = run
-
-run: run.tpl
- sed -e "s|%abs_top_srcdir%|$(abs_top_srcdir)|" \
- -e "s|%abs_top_builddir%|$(abs_top_builddir)|" \
- < $< > $@
- chmod +x $@
diff --git a/test/etap/070-couch-db.t b/test/etap/070-couch-db.t
deleted file mode 100755
index 787d6c6a..00000000
--- a/test/etap/070-couch-db.t
+++ /dev/null
@@ -1,73 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
-main(_) ->
- test_util:init_code_path(),
-
- etap:plan(4),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail(Other)
- end,
- ok.
-
-test() ->
-
- couch_server_sup:start_link(test_util:config_files()),
-
- couch_db:create(<<"etap-test-db">>, []),
- {ok, AllDbs} = couch_server:all_databases(),
- etap:ok(lists:member(<<"etap-test-db">>, AllDbs), "Database was created."),
-
- couch_server:delete(<<"etap-test-db">>, []),
- {ok, AllDbs2} = couch_server:all_databases(),
- etap:ok(not lists:member(<<"etap-test-db">>, AllDbs2),
- "Database was deleted."),
-
- gen_server:call(couch_server, {set_max_dbs_open, 3}),
- MkDbName = fun(Int) -> list_to_binary("lru-" ++ integer_to_list(Int)) end,
-
- lists:foreach(fun(Int) ->
- {ok, TestDbs} = couch_server:all_databases(),
- ok = case lists:member(MkDbName(Int), TestDbs) of
- true -> couch_server:delete(MkDbName(Int), []);
- _ -> ok
- end,
- {ok, Db} = couch_db:create(MkDbName(Int), []),
- ok = couch_db:close(Db)
- end, lists:seq(1, 6)),
-
- {ok, AllDbs3} = couch_server:all_databases(),
- NumCreated = lists:foldl(fun(Int, Acc) ->
- true = lists:member(MkDbName(Int), AllDbs3),
- Acc+1
- end, 0, lists:seq(1, 6)),
- etap:is(6, NumCreated, "Created all databases."),
-
- lists:foreach(fun(Int) ->
- ok = couch_server:delete(MkDbName(Int), [])
- end, lists:seq(1, 6)),
-
- {ok, AllDbs4} = couch_server:all_databases(),
- NumDeleted = lists:foldl(fun(Int, Acc) ->
- false = lists:member(MkDbName(Int), AllDbs4),
- Acc+1
- end, 0, lists:seq(1, 6)),
- etap:is(6, NumDeleted, "Deleted all databases."),
-
- ok.
diff --git a/test/etap/110-replication-httpc.t b/test/etap/110-replication-httpc.t
deleted file mode 100755
index 39b0755e..00000000
--- a/test/etap/110-replication-httpc.t
+++ /dev/null
@@ -1,132 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
-%% XXX: Figure out how to -include("couch_rep.hrl")
--record(http_db, {
- url,
- auth = [],
- resource = "",
- headers = [
- {"User-Agent", "CouchDB/"++couch_server:get_version()},
- {"Accept", "application/json"},
- {"Accept-Encoding", "gzip"}
- ],
- qs = [],
- method = get,
- body = nil,
- options = [
- {response_format,binary},
- {inactivity_timeout, 30000}
- ],
- retries = 10,
- pause = 1,
- conn = nil
-}).
-
-server() ->
- lists:concat([
- "http://127.0.0.1:", mochiweb_socket_server:get(couch_httpd, port), "/"
- ]).
-
-dbname() -> "etap-test-db".
-
-main(_) ->
- test_util:init_code_path(),
-
- etap:plan(6),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail(Other)
- end,
- ok.
-
-test() ->
- couch_server_sup:start_link(test_util:config_files()),
- ibrowse:start(),
- crypto:start(),
-
- couch_server:delete(list_to_binary(dbname()), []),
- {ok, Db} = couch_db:create(list_to_binary(dbname()), []),
-
- test_welcome(),
- test_binary_url(),
- test_put(),
- test_qs(),
- test_db_exists(),
-
- couch_db:close(Db),
- couch_server:delete(list_to_binary(dbname()), []),
- ok.
-
-test_welcome() ->
- WelcomeReq = #http_db{url=server()},
- Expect = {[
- {<<"couchdb">>, <<"Welcome">>},
- {<<"version">>, list_to_binary(couch_server:get_version())}
- ]},
- etap:is(
- couch_rep_httpc:request(WelcomeReq),
- Expect,
- "welcome request with url-as-list"
- ).
-
-test_binary_url() ->
- Req = #http_db{url=list_to_binary(server())},
- Expect = {[
- {<<"couchdb">>, <<"Welcome">>},
- {<<"version">>, list_to_binary(couch_server:get_version())}
- ]},
- etap:is(
- couch_rep_httpc:request(Req),
- Expect,
- "welcome request with url-as-binary"
- ).
-
-test_put() ->
- Req = #http_db{
- url = server() ++ dbname() ++ "/",
- resource = "test_put",
- body = {[{<<"foo">>, <<"bar">>}]},
- method = put
- },
- {Resp} = couch_rep_httpc:request(Req),
- etap:ok(couch_util:get_value(<<"ok">>, Resp), "ok:true on upload"),
- etap:is(<<"test_put">>, couch_util:get_value(<<"id">>, Resp), "id is correct").
-
-test_qs() ->
- Req = #http_db{
- url = server() ++ dbname() ++ "/",
- resource = "foo",
- qs = [
- {bar, true},
- {baz, 1.03},
- {bif, mochijson2:encode(<<"1-23456">>)}
- ]
- },
- Expect = server() ++ dbname() ++ "/foo?bar=true&baz=1.03&bif=\"1-23456\"",
- etap:is(
- couch_rep_httpc:full_url(Req),
- Expect,
- "query-string proplist encoding ok"
- ).
-
-test_db_exists() ->
- Req1 = #http_db{url=server() ++ dbname() ++ "/"},
- Req2 = #http_db{url=server() ++ dbname() ++ "_foo/"},
- etap:is(couch_rep_httpc:db_exists(Req1), Req1, "db_exists true check").
- % etap:is(couch_rep_httpc:db_exists(Req2), false, "db_exists false check").
diff --git a/test/etap/111-replication-changes-feed.t b/test/etap/111-replication-changes-feed.t
deleted file mode 100755
index 358bf1e2..00000000
--- a/test/etap/111-replication-changes-feed.t
+++ /dev/null
@@ -1,253 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
-%% XXX: Figure out how to -include("couch_db.hrl")
--record(doc, {id= <<"">>, revs={0, []}, body={[]},
- attachments=[], deleted=false, meta=[]}).
-
--record(http_db, {
- url,
- auth = [],
- resource = "",
- headers = [
- {"User-Agent", "CouchDB/"++couch_server:get_version()},
- {"Accept", "application/json"},
- {"Accept-Encoding", "gzip"}
- ],
- qs = [],
- method = get,
- body = nil,
- options = [
- {response_format,binary},
- {inactivity_timeout, 30000}
- ],
- retries = 10,
- pause = 1,
- conn = nil
-}).
-
-main(_) ->
- test_util:init_code_path(),
-
- etap:plan(13),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail(Other)
- end,
- ok.
-
-test() ->
- couch_server_sup:start_link(test_util:config_files()),
- ibrowse:start(),
- crypto:start(),
-
- couch_server:delete(<<"etap-test-db">>, []),
- {ok, Db1} = couch_db:create(<<"etap-test-db">>, []),
- test_all(local),
- couch_db:close(Db1),
- couch_server:delete(<<"etap-test-db">>, []),
-
- couch_server:delete(<<"etap-test-db">>, []),
- {ok, Db2} = couch_db:create(<<"etap-test-db">>, []),
- test_all(remote),
- test_remote_only(),
- couch_db:close(Db2),
- couch_server:delete(<<"etap-test-db">>, []),
-
- ok.
-
-test_all(Type) ->
- test_unchanged_db(Type),
- test_simple_change(Type),
- test_since_parameter(Type),
- test_continuous_parameter(Type),
- test_conflicts(Type),
- test_deleted_conflicts(Type).
-
-test_remote_only() ->
- test_chunk_reassembly(remote).
-
-test_unchanged_db(Type) ->
- {ok, Pid} = start_changes_feed(Type, 0, false),
- etap:is(
- couch_rep_changes_feed:next(Pid),
- complete,
- io_lib:format(
- "(~p) changes feed for unchanged DB is automatically complete",
- [Type])
- ).
-
-test_simple_change(Type) ->
- Expect = generate_change(),
- {ok, Pid} = start_changes_feed(Type, 0, false),
- etap:is(
- {couch_rep_changes_feed:next(Pid), couch_rep_changes_feed:next(Pid)},
- {[Expect], complete},
- io_lib:format("(~p) change one document, get one row", [Type])
- ).
-
-test_since_parameter(Type) ->
- {ok, Pid} = start_changes_feed(Type, get_update_seq(), false),
- etap:is(
- couch_rep_changes_feed:next(Pid),
- complete,
- io_lib:format(
- "(~p) since query-string parameter allows us to skip changes",
- [Type])
- ).
-
-test_continuous_parameter(Type) ->
- {ok, Pid} = start_changes_feed(Type, get_update_seq(), true),
-
- % make the changes_feed request before the next update
- Self = self(),
- spawn(fun() ->
- Change = couch_rep_changes_feed:next(Pid),
- Self ! {actual, Change}
- end),
-
- Expect = generate_change(),
- etap:is(
- receive {actual, Actual} -> Actual end,
- [Expect],
- io_lib:format(
- "(~p) feed=continuous query-string parameter picks up new changes",
- [Type])
- ),
-
- ok = couch_rep_changes_feed:stop(Pid).
-
-test_conflicts(Type) ->
- Since = get_update_seq(),
- Expect = generate_conflict(),
- {ok, Pid} = start_changes_feed(Type, Since, false),
- etap:is(
- {couch_rep_changes_feed:next(Pid), couch_rep_changes_feed:next(Pid)},
- {[Expect], complete},
- io_lib:format("(~p) conflict revisions show up in feed", [Type])
- ).
-
-test_deleted_conflicts(Type) ->
- Since = get_update_seq(),
- {ExpectProps} = generate_conflict(),
-
- %% delete the conflict revision
- Id = couch_util:get_value(<<"id">>, ExpectProps),
- [Win, {[{<<"rev">>, Lose}]}] = couch_util:get_value(<<"changes">>, ExpectProps),
- Doc = couch_doc:from_json_obj({[
- {<<"_id">>, Id},
- {<<"_rev">>, Lose},
- {<<"_deleted">>, true}
- ]}),
- Db = get_db(),
- {ok, Rev} = couch_db:update_doc(Db, Doc, [full_commit]),
- couch_db:close(Db),
-
- Expect = {[
- {<<"seq">>, get_update_seq()},
- {<<"id">>, Id},
- {<<"changes">>, [Win, {[{<<"rev">>, couch_doc:rev_to_str(Rev)}]}]}
- ]},
-
- {ok, Pid} = start_changes_feed(Type, Since, false),
- etap:is(
- {couch_rep_changes_feed:next(Pid), couch_rep_changes_feed:next(Pid)},
- {[Expect], complete},
- io_lib:format("(~p) deleted conflict revisions show up in feed", [Type])
- ).
-
-test_chunk_reassembly(Type) ->
- Since = get_update_seq(),
- Expect = [generate_change() || _I <- lists:seq(1,30)],
- {ok, Pid} = start_changes_feed(Type, Since, false),
- etap:is(
- get_all_changes(Pid, []),
- Expect,
- io_lib:format("(~p) reassembles chunks split across TCP frames",
- [Type])
- ).
-
-get_all_changes(Pid, Acc) ->
- case couch_rep_changes_feed:next(Pid) of
- complete ->
- lists:flatten(lists:reverse(Acc));
- Else ->
- get_all_changes(Pid, [Else|Acc])
- end.
-
-generate_change() ->
- generate_change(couch_uuids:random()).
-
-generate_change(Id) ->
- generate_change(Id, {[]}).
-
-generate_change(Id, EJson) ->
- Doc = couch_doc:from_json_obj(EJson),
- Db = get_db(),
- {ok, Rev} = couch_db:update_doc(Db, Doc#doc{id = Id}, [full_commit]),
- couch_db:close(Db),
- {[
- {<<"seq">>, get_update_seq()},
- {<<"id">>, Id},
- {<<"changes">>, [{[{<<"rev">>, couch_doc:rev_to_str(Rev)}]}]}
- ]}.
-
-generate_conflict() ->
- Id = couch_uuids:random(),
- Db = get_db(),
- Doc1 = (couch_doc:from_json_obj({[<<"foo">>, <<"bar">>]}))#doc{id = Id},
- Doc2 = (couch_doc:from_json_obj({[<<"foo">>, <<"baz">>]}))#doc{id = Id},
- {ok, Rev1} = couch_db:update_doc(Db, Doc1, [full_commit]),
- {ok, Rev2} = couch_db:update_doc(Db, Doc2, [full_commit, all_or_nothing]),
-
- %% relies on undocumented CouchDB conflict winner algo and revision sorting!
- RevList = [{[{<<"rev">>, couch_doc:rev_to_str(R)}]} || R
- <- lists:sort(fun(A,B) -> B<A end, [Rev1,Rev2])],
- {[
- {<<"seq">>, get_update_seq()},
- {<<"id">>, Id},
- {<<"changes">>, RevList}
- ]}.
-
-get_db() ->
- {ok, Db} = couch_db:open(<<"etap-test-db">>, []),
- Db.
-
-get_dbname(local) ->
- "etap-test-db";
-get_dbname(remote) ->
- server() ++ "etap-test-db/".
-
-server() ->
- lists:concat([
- "http://127.0.0.1:", mochiweb_socket_server:get(couch_httpd, port), "/"
- ]).
-
-get_update_seq() ->
- Db = get_db(),
- Seq = couch_db:get_update_seq(Db),
- couch_db:close(Db),
- Seq.
-
-start_changes_feed(local, Since, Continuous) ->
- Props = [{<<"continuous">>, Continuous}],
- couch_rep_changes_feed:start_link(self(), get_db(), Since, Props);
-start_changes_feed(remote, Since, Continuous) ->
- Props = [{<<"continuous">>, Continuous}],
- Db = #http_db{url = get_dbname(remote)},
- couch_rep_changes_feed:start_link(self(), Db, Since, Props).
diff --git a/test/etap/112-replication-missing-revs.t b/test/etap/112-replication-missing-revs.t
deleted file mode 100755
index 39280aee..00000000
--- a/test/etap/112-replication-missing-revs.t
+++ /dev/null
@@ -1,207 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
-%% XXX: Figure out how to -include("couch_db.hrl")
-
--record(doc, {id= <<"">>, revs={0, []}, body={[]},
- attachments=[], deleted=false, meta=[]}).
-
--record(http_db, {
- url,
- auth = [],
- resource = "",
- headers = [
- {"User-Agent", "CouchDB/"++couch_server:get_version()},
- {"Accept", "application/json"},
- {"Accept-Encoding", "gzip"}
- ],
- qs = [],
- method = get,
- body = nil,
- options = [
- {response_format,binary},
- {inactivity_timeout, 30000}
- ],
- retries = 10,
- pause = 1,
- conn = nil
-}).
-
-main(_) ->
- test_util:init_code_path(),
-
- etap:plan(12),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail(Other)
- end,
- ok.
-
-test() ->
- couch_server_sup:start_link(test_util:config_files()),
- ibrowse:start(),
- crypto:start(),
-
- couch_server:delete(<<"etap-test-source">>, []),
- couch_server:delete(<<"etap-test-target">>, []),
-
- Dbs1 = setup(),
- test_all(local, local),
- ok = teardown(Dbs1),
-
- Dbs2 = setup(),
- test_all(local, remote),
- ok = teardown(Dbs2),
-
- Dbs3 = setup(),
- test_all(remote, local),
- ok = teardown(Dbs3),
-
- Dbs4 = setup(),
- test_all(remote, remote),
- ok = teardown(Dbs4),
-
- ok.
-
-test_all(SrcType, TgtType) ->
- test_unchanged_db(SrcType, TgtType),
- test_multiple_changes(SrcType, TgtType),
- test_changes_not_missing(SrcType, TgtType).
-
-test_unchanged_db(SrcType, TgtType) ->
- {ok, Pid1} = start_changes_feed(SrcType, 0, false),
- {ok, Pid2} = start_missing_revs(TgtType, Pid1),
- etap:is(
- couch_rep_missing_revs:next(Pid2),
- complete,
- io_lib:format(
- "(~p, ~p) no missing revs if source is unchanged",
- [SrcType, TgtType])
- ).
-
-test_multiple_changes(SrcType, TgtType) ->
- Expect = {2, [generate_change(), generate_change()]},
- {ok, Pid1} = start_changes_feed(SrcType, 0, false),
- {ok, Pid2} = start_missing_revs(TgtType, Pid1),
- etap:is(
- get_all_missing_revs(Pid2, {0, []}),
- Expect,
- io_lib:format("(~p, ~p) add src docs, get missing tgt revs + high seq",
- [SrcType, TgtType])
- ).
-
-test_changes_not_missing(SrcType, TgtType) ->
- %% put identical changes on source and target
- Id = couch_uuids:random(),
- {Id, _Seq, [Rev]} = Expect = generate_change(Id, {[]}, get_db(source)),
- {Id, _, [Rev]} = generate_change(Id, {[]}, get_db(target)),
-
- %% confirm that this change is not in missing revs feed
- {ok, Pid1} = start_changes_feed(SrcType, 0, false),
- {ok, Pid2} = start_missing_revs(TgtType, Pid1),
- {HighSeq, AllRevs} = get_all_missing_revs(Pid2, {0, []}),
-
- %% etap:none/3 has a bug, so just define it correctly here
- etap:is(
- lists:member(Expect, AllRevs),
- false,
- io_lib:format(
- "(~p, ~p) skip revs that already exist on target",
- [SrcType, TgtType])
- ).
-
-generate_change() ->
- generate_change(couch_uuids:random()).
-
-generate_change(Id) ->
- generate_change(Id, {[]}).
-
-generate_change(Id, EJson) ->
- generate_change(Id, EJson, get_db(source)).
-
-generate_change(Id, EJson, Db) ->
- Doc = couch_doc:from_json_obj(EJson),
- Seq = get_update_seq(),
- {ok, Rev} = couch_db:update_doc(Db, Doc#doc{id = Id}, [full_commit]),
- couch_db:close(Db),
- {Id, Seq+1, [Rev]}.
-
-get_all_missing_revs(Pid, {HighSeq, Revs}) ->
- case couch_rep_missing_revs:next(Pid) of
- complete ->
- {HighSeq, lists:flatten(lists:reverse(Revs))};
- {Seq, More} ->
- get_all_missing_revs(Pid, {Seq, [More|Revs]})
- end.
-
-get_db(source) ->
- {ok, Db} = couch_db:open(<<"etap-test-source">>, []),
- Db;
-get_db(target) ->
- {ok, Db} = couch_db:open(<<"etap-test-target">>, []),
- Db.
-
-get_update_seq() ->
- Db = get_db(source),
- Seq = couch_db:get_update_seq(Db),
- couch_db:close(Db),
- Seq.
-
-setup() ->
- {ok, DbA} = couch_db:create(<<"etap-test-source">>, []),
- {ok, DbB} = couch_db:create(<<"etap-test-target">>, []),
- [DbA, DbB].
-
-teardown([DbA, DbB]) ->
- couch_db:close(DbA),
- couch_db:close(DbB),
- couch_server:delete(<<"etap-test-source">>, []),
- couch_server:delete(<<"etap-test-target">>, []),
- ok.
-
-start_changes_feed(local, Since, Continuous) ->
- Props = [{<<"continuous">>, Continuous}],
- couch_rep_changes_feed:start_link(self(), get_db(source), Since, Props);
-start_changes_feed(remote, Since, Continuous) ->
- Props = [{<<"continuous">>, Continuous}],
- Db = #http_db{url = server() ++ "etap-test-source/"},
- couch_rep_changes_feed:start_link(self(), Db, Since, Props).
-
-server() ->
- lists:concat([
- "http://127.0.0.1:", mochiweb_socket_server:get(couch_httpd, port), "/"
- ]).
-
-couch_rep_pid(Db) ->
- spawn(fun() -> couch_rep_pid_loop(Db) end).
-
-couch_rep_pid_loop(Db) ->
- receive
- {'$gen_call', From, get_target_db} ->
- gen_server:reply(From, {ok, Db})
- end,
- couch_rep_pid_loop(Db).
-
-start_missing_revs(local, Changes) ->
- TargetDb = get_db(target),
- MainPid = couch_rep_pid(TargetDb),
- couch_rep_missing_revs:start_link(MainPid, TargetDb, Changes, []);
-start_missing_revs(remote, Changes) ->
- TargetDb = #http_db{url = server() ++ "etap-test-target/"},
- MainPid = couch_rep_pid(TargetDb),
- couch_rep_missing_revs:start_link(MainPid, TargetDb, Changes, []).
diff --git a/test/etap/113-replication-attachment-comp.t b/test/etap/113-replication-attachment-comp.t
deleted file mode 100755
index e30a96bc..00000000
--- a/test/etap/113-replication-attachment-comp.t
+++ /dev/null
@@ -1,314 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
--record(user_ctx, {
- name = null,
- roles = [],
- handler
-}).
-
-test_db_a_name() ->
- <<"couch_test_rep_att_comp_a">>.
-
-test_db_b_name() ->
- <<"couch_test_rep_att_comp_b">>.
-
-main(_) ->
- test_util:init_code_path(),
- etap:plan(45),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail(Other)
- end,
- ok.
-
-test() ->
- couch_server_sup:start_link(test_util:config_files()),
- put(addr, couch_config:get("httpd", "bind_address", "127.0.0.1")),
- put(port, integer_to_list(mochiweb_socket_server:get(couch_httpd, port))),
- application:start(inets),
- ibrowse:start(),
- timer:sleep(1000),
-
- %
- % test pull replication
- %
-
- delete_db(test_db_a_name()),
- delete_db(test_db_b_name()),
- create_db(test_db_a_name()),
- create_db(test_db_b_name()),
-
- % enable compression
- couch_config:set("attachments", "compression_level", "8", false),
- couch_config:set("attachments", "compressible_types", "text/*", false),
-
- % store doc with text attachment in DB A
- put_text_att(test_db_a_name()),
-
- % disable attachment compression
- couch_config:set("attachments", "compression_level", "0", false),
-
- % do pull replication
- do_pull_replication(test_db_a_name(), test_db_b_name()),
-
- % verify that DB B has the attachment stored in compressed form
- check_att_is_compressed(test_db_b_name()),
- check_server_can_decompress_att(test_db_b_name()),
- check_att_stubs(test_db_a_name(), test_db_b_name()),
-
- %
- % test push replication
- %
-
- delete_db(test_db_a_name()),
- delete_db(test_db_b_name()),
- create_db(test_db_a_name()),
- create_db(test_db_b_name()),
-
- % enable compression
- couch_config:set("attachments", "compression_level", "8", false),
- couch_config:set("attachments", "compressible_types", "text/*", false),
-
- % store doc with text attachment in DB A
- put_text_att(test_db_a_name()),
-
- % disable attachment compression
- couch_config:set("attachments", "compression_level", "0", false),
-
- % do push replication
- do_push_replication(test_db_a_name(), test_db_b_name()),
-
- % verify that DB B has the attachment stored in compressed form
- check_att_is_compressed(test_db_b_name()),
- check_server_can_decompress_att(test_db_b_name()),
- check_att_stubs(test_db_a_name(), test_db_b_name()),
-
- %
- % test local replication
- %
-
- delete_db(test_db_a_name()),
- delete_db(test_db_b_name()),
- create_db(test_db_a_name()),
- create_db(test_db_b_name()),
-
- % enable compression
- couch_config:set("attachments", "compression_level", "8", false),
- couch_config:set("attachments", "compressible_types", "text/*", false),
-
- % store doc with text attachment in DB A
- put_text_att(test_db_a_name()),
-
- % disable attachment compression
- couch_config:set("attachments", "compression_level", "0", false),
-
- % do local-local replication
- do_local_replication(test_db_a_name(), test_db_b_name()),
-
- % verify that DB B has the attachment stored in compressed form
- check_att_is_compressed(test_db_b_name()),
- check_server_can_decompress_att(test_db_b_name()),
- check_att_stubs(test_db_a_name(), test_db_b_name()),
-
- timer:sleep(3000), % to avoid mochiweb socket closed exceptions
- delete_db(test_db_a_name()),
- delete_db(test_db_b_name()),
- couch_server_sup:stop(),
- ok.
-
-put_text_att(DbName) ->
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
- put,
- {db_url(DbName) ++ "/testdoc1/readme.txt", [],
- "text/plain", test_text_data()},
- [],
- [{sync, true}]),
- etap:is(Code, 201, "Created text attachment"),
- ok.
-
-do_pull_replication(SourceDbName, TargetDbName) ->
- RepObj = {[
- {<<"source">>, list_to_binary(db_url(SourceDbName))},
- {<<"target">>, TargetDbName}
- ]},
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- post,
- {rep_url(), [],
- "application/json", list_to_binary(couch_util:json_encode(RepObj))},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "Pull replication successfully triggered"),
- Json = couch_util:json_decode(Body),
- RepOk = couch_util:get_nested_json_value(Json, [<<"ok">>]),
- etap:is(RepOk, true, "Pull replication completed with success"),
- ok.
-
-do_push_replication(SourceDbName, TargetDbName) ->
- RepObj = {[
- {<<"source">>, SourceDbName},
- {<<"target">>, list_to_binary(db_url(TargetDbName))}
- ]},
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- post,
- {rep_url(), [],
- "application/json", list_to_binary(couch_util:json_encode(RepObj))},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "Push replication successfully triggered"),
- Json = couch_util:json_decode(Body),
- RepOk = couch_util:get_nested_json_value(Json, [<<"ok">>]),
- etap:is(RepOk, true, "Push replication completed with success"),
- ok.
-
-do_local_replication(SourceDbName, TargetDbName) ->
- RepObj = {[
- {<<"source">>, SourceDbName},
- {<<"target">>, TargetDbName}
- ]},
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- post,
- {rep_url(), [],
- "application/json", list_to_binary(couch_util:json_encode(RepObj))},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "Local replication successfully triggered"),
- Json = couch_util:json_decode(Body),
- RepOk = couch_util:get_nested_json_value(Json, [<<"ok">>]),
- etap:is(RepOk, true, "Local replication completed with success"),
- ok.
-
-check_att_is_compressed(DbName) ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url(DbName) ++ "/testdoc1/readme.txt",
- [{"Accept-Encoding", "gzip"}]},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code for the attachment request is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
- etap:is(Gziped, true, "The attachment was received in compressed form"),
- Uncompressed = binary_to_list(zlib:gunzip(list_to_binary(Body))),
- etap:is(
- Uncompressed,
- test_text_data(),
- "The attachment content is valid after decompression at the client side"
- ),
- ok.
-
-check_server_can_decompress_att(DbName) ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url(DbName) ++ "/testdoc1/readme.txt", []},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code for the attachment request is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
- etap:is(
- Gziped, false, "The attachment was not received in compressed form"
- ),
- etap:is(
- Body,
- test_text_data(),
- "The attachment content is valid after server decompression"
- ),
- ok.
-
-check_att_stubs(SourceDbName, TargetDbName) ->
- {ok, {{_, Code1, _}, _Headers1, Body1}} = http:request(
- get,
- {db_url(SourceDbName) ++ "/testdoc1?att_encoding_info=true", []},
- [],
- [{sync, true}]),
- etap:is(
- Code1,
- 200,
- "HTTP response code is 200 for the source DB doc request"
- ),
- Json1 = couch_util:json_decode(Body1),
- SourceAttStub = couch_util:get_nested_json_value(
- Json1,
- [<<"_attachments">>, <<"readme.txt">>]
- ),
- {ok, {{_, Code2, _}, _Headers2, Body2}} = http:request(
- get,
- {db_url(TargetDbName) ++ "/testdoc1?att_encoding_info=true", []},
- [],
- [{sync, true}]),
- etap:is(
- Code2,
- 200,
- "HTTP response code is 200 for the target DB doc request"
- ),
- Json2 = couch_util:json_decode(Body2),
- TargetAttStub = couch_util:get_nested_json_value(
- Json2,
- [<<"_attachments">>, <<"readme.txt">>]
- ),
- IdenticalStubs = (SourceAttStub =:= TargetAttStub),
- etap:is(IdenticalStubs, true, "Attachment stubs are identical"),
- TargetAttStubLength = couch_util:get_nested_json_value(
- TargetAttStub,
- [<<"length">>]
- ),
- TargetAttStubEnc = couch_util:get_nested_json_value(
- TargetAttStub,
- [<<"encoding">>]
- ),
- etap:is(
- TargetAttStubEnc,
- <<"gzip">>,
- "Attachment stub has encoding property set to gzip"
- ),
- TargetAttStubEncLength = couch_util:get_nested_json_value(
- TargetAttStub,
- [<<"encoded_length">>]
- ),
- EncLengthDefined = is_integer(TargetAttStubEncLength),
- etap:is(
- EncLengthDefined,
- true,
- "Stubs have the encoded_length field properly defined"
- ),
- EncLengthSmaller = (TargetAttStubEncLength < TargetAttStubLength),
- etap:is(
- EncLengthSmaller,
- true,
- "Stubs have the encoded_length field smaller than their length field"
- ),
- ok.
-
-admin_user_ctx() ->
- {user_ctx, #user_ctx{roles=[<<"_admin">>]}}.
-
-create_db(DbName) ->
- {ok, _} = couch_db:create(DbName, [admin_user_ctx()]).
-
-delete_db(DbName) ->
- couch_server:delete(DbName, [admin_user_ctx()]).
-
-db_url(DbName) ->
- "http://" ++ get(addr) ++ ":" ++ get(port) ++ "/" ++
- binary_to_list(DbName).
-
-rep_url() ->
- "http://" ++ get(addr) ++ ":" ++ get(port) ++ "/_replicate".
-
-test_text_data() ->
- {ok, Data} = file:read_file(test_util:source_file("README")),
- binary_to_list(Data).
diff --git a/test/etap/130-attachments-md5.t b/test/etap/130-attachments-md5.t
deleted file mode 100755
index 6296e08a..00000000
--- a/test/etap/130-attachments-md5.t
+++ /dev/null
@@ -1,248 +0,0 @@
-#!/usr/bin/env escript
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
-test_db_name() ->
- <<"etap-test-db">>.
-
-docid() ->
- case get(docid) of
- undefined ->
- put(docid, 1),
- "1";
- Count ->
- put(docid, Count+1),
- integer_to_list(Count+1)
- end.
-
-main(_) ->
- test_util:init_code_path(),
-
- etap:plan(16),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail(Other)
- end,
- ok.
-
-test() ->
- couch_server_sup:start_link(test_util:config_files()),
- Addr = couch_config:get("httpd", "bind_address", any),
- put(addr, Addr),
- put(port, mochiweb_socket_server:get(couch_httpd, port)),
- timer:sleep(1000),
-
- couch_server:delete(test_db_name(), []),
- couch_db:create(test_db_name(), []),
-
- test_identity_without_md5(),
- test_chunked_without_md5(),
-
- test_identity_with_valid_md5(),
- test_chunked_with_valid_md5_header(),
- test_chunked_with_valid_md5_trailer(),
-
- test_identity_with_invalid_md5(),
- test_chunked_with_invalid_md5_header(),
- test_chunked_with_invalid_md5_trailer(),
-
- couch_server:delete(test_db_name(), []),
- couch_server_sup:stop(),
- ok.
-
-test_identity_without_md5() ->
- Data = [
- "PUT /", test_db_name(), "/", docid(), "/readme.txt HTTP/1.1\r\n",
- "Content-Type: text/plain\r\n",
- "Content-Length: 34\r\n",
- "\r\n",
- "We all live in a yellow submarine!"],
-
- {Code, Json} = do_request(Data),
- etap:is(Code, 201, "Stored with identity encoding and no MD5"),
- etap:is(get_json(Json, [<<"ok">>]), true, "Body indicates success.").
-
-test_chunked_without_md5() ->
- AttData = <<"We all live in a yellow submarine!">>,
- <<Part1:21/binary, Part2:13/binary>> = AttData,
- Data = [
- "PUT /", test_db_name(), "/", docid(), "/readme.txt HTTP/1.1\r\n",
- "Content-Type: text/plain\r\n",
- "Transfer-Encoding: chunked\r\n",
- "\r\n",
- to_hex(size(Part1)), "\r\n",
- Part1, "\r\n",
- to_hex(size(Part2)), "\r\n",
- Part2, "\r\n"
- "0\r\n"
- "\r\n"],
-
- {Code, Json} = do_request(Data),
- etap:is(Code, 201, "Stored with chunked encoding and no MD5"),
- etap:is(get_json(Json, [<<"ok">>]), true, "Body indicates success.").
-
-test_identity_with_valid_md5() ->
- AttData = "We all live in a yellow submarine!",
- Data = [
- "PUT /", test_db_name(), "/", docid(), "/readme.txt HTTP/1.1\r\n",
- "Content-Type: text/plain\r\n",
- "Content-Length: 34\r\n",
- "Content-MD5: ", base64:encode(couch_util:md5(AttData)), "\r\n",
- "\r\n",
- AttData],
-
- {Code, Json} = do_request(Data),
- etap:is(Code, 201, "Stored with identity encoding and valid MD5"),
- etap:is(get_json(Json, [<<"ok">>]), true, "Body indicates success.").
-
-test_chunked_with_valid_md5_header() ->
- AttData = <<"We all live in a yellow submarine!">>,
- <<Part1:21/binary, Part2:13/binary>> = AttData,
- Data = [
- "PUT /", test_db_name(), "/", docid(), "/readme.txt HTTP/1.1\r\n",
- "Content-Type: text/plain\r\n",
- "Transfer-Encoding: chunked\r\n",
- "Content-MD5: ", base64:encode(couch_util:md5(AttData)), "\r\n",
- "\r\n",
- to_hex(size(Part1)), "\r\n",
- Part1, "\r\n",
- to_hex(size(Part2)), "\r\n",
- Part2, "\r\n",
- "0\r\n",
- "\r\n"],
-
- {Code, Json} = do_request(Data),
- etap:is(Code, 201, "Stored with chunked encoding and valid MD5 header."),
- etap:is(get_json(Json, [<<"ok">>]), true, "Body indicates success.").
-
-test_chunked_with_valid_md5_trailer() ->
- AttData = <<"We all live in a yellow submarine!">>,
- <<Part1:21/binary, Part2:13/binary>> = AttData,
- Data = [
- "PUT /", test_db_name(), "/", docid(), "/readme.txt HTTP/1.1\r\n",
- "Content-Type: text/plain\r\n",
- "Transfer-Encoding: chunked\r\n",
- "Trailer: Content-MD5\r\n",
- "\r\n",
- to_hex(size(Part1)), "\r\n",
- Part1, "\r\n",
- to_hex(size(Part2)), "\r\n",
- Part2, "\r\n",
- "0\r\n",
- "Content-MD5: ", base64:encode(couch_util:md5(AttData)), "\r\n",
- "\r\n"],
-
- {Code, Json} = do_request(Data),
- etap:is(Code, 201, "Stored with chunked encoding and valid MD5 trailer."),
- etap:is(get_json(Json, [<<"ok">>]), true, "Body indicates success.").
-
-test_identity_with_invalid_md5() ->
- Data = [
- "PUT /", test_db_name(), "/", docid(), "/readme.txt HTTP/1.1\r\n",
- "Content-Type: text/plain\r\n",
- "Content-Length: 34\r\n",
- "Content-MD5: ", base64:encode(<<"foobar!">>), "\r\n",
- "\r\n",
- "We all live in a yellow submarine!"],
-
- {Code, Json} = do_request(Data),
- etap:is(Code, 400, "Invalid MD5 header causes an error: identity"),
- etap:is(
- get_json(Json, [<<"error">>]),
- <<"content_md5_mismatch">>,
- "Body indicates reason for failure."
- ).
-
-test_chunked_with_invalid_md5_header() ->
- AttData = <<"We all live in a yellow submarine!">>,
- <<Part1:21/binary, Part2:13/binary>> = AttData,
- Data = [
- "PUT /", test_db_name(), "/", docid(), "/readme.txt HTTP/1.1\r\n",
- "Content-Type: text/plain\r\n",
- "Transfer-Encoding: chunked\r\n",
- "Content-MD5: ", base64:encode(<<"so sneaky...">>), "\r\n",
- "\r\n",
- to_hex(size(Part1)), "\r\n",
- Part1, "\r\n",
- to_hex(size(Part2)), "\r\n",
- Part2, "\r\n",
- "0\r\n",
- "\r\n"],
-
- {Code, Json} = do_request(Data),
- etap:is(Code, 400, "Invalid MD5 header causes an error: chunked"),
- etap:is(
- get_json(Json, [<<"error">>]),
- <<"content_md5_mismatch">>,
- "Body indicates reason for failure."
- ).
-
-test_chunked_with_invalid_md5_trailer() ->
- AttData = <<"We all live in a yellow submarine!">>,
- <<Part1:21/binary, Part2:13/binary>> = AttData,
- Data = [
- "PUT /", test_db_name(), "/", docid(), "/readme.txt HTTP/1.1\r\n",
- "Content-Type: text/plain\r\n",
- "Transfer-Encoding: chunked\r\n",
- "Trailer: Content-MD5\r\n",
- "\r\n",
- to_hex(size(Part1)), "\r\n",
- Part1, "\r\n",
- to_hex(size(Part2)), "\r\n",
- Part2, "\r\n",
- "0\r\n",
- "Content-MD5: ", base64:encode(<<"Kool-Aid Fountain!">>), "\r\n",
- "\r\n"],
-
- {Code, Json} = do_request(Data),
- etap:is(Code, 400, "Invalid MD5 Trailer causes an error"),
- etap:is(
- get_json(Json, [<<"error">>]),
- <<"content_md5_mismatch">>,
- "Body indicates reason for failure."
- ).
-
-
-get_socket() ->
- Options = [binary, {packet, 0}, {active, false}],
- {ok, Sock} = gen_tcp:connect(get(addr), get(port), Options),
- Sock.
-
-do_request(Request) ->
- Sock = get_socket(),
- gen_tcp:send(Sock, list_to_binary(lists:flatten(Request))),
- timer:sleep(1000),
- {ok, R} = gen_tcp:recv(Sock, 0),
- gen_tcp:close(Sock),
- [Header, Body] = re:split(R, "\r\n\r\n", [{return, binary}]),
- {ok, {http_response, _, Code, _}, _} =
- erlang:decode_packet(http, Header, []),
- Json = couch_util:json_decode(Body),
- {Code, Json}.
-
-get_json(Json, Path) ->
- couch_util:get_nested_json_value(Json, Path).
-
-to_hex(Val) ->
- to_hex(Val, []).
-
-to_hex(0, Acc) ->
- Acc;
-to_hex(Val, Acc) ->
- to_hex(Val div 16, [hex_char(Val rem 16) | Acc]).
-
-hex_char(V) when V < 10 -> $0 + V;
-hex_char(V) -> $A + V - 10.
-
diff --git a/test/etap/140-attachment-comp.t b/test/etap/140-attachment-comp.t
deleted file mode 100755
index 475f4fb0..00000000
--- a/test/etap/140-attachment-comp.t
+++ /dev/null
@@ -1,762 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
-test_db_name() ->
- <<"couch_test_atts_compression">>.
-
-main(_) ->
- test_util:init_code_path(),
-
- etap:plan(85),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail(Other)
- end,
- ok.
-
-test() ->
- couch_server_sup:start_link(test_util:config_files()),
- put(addr, couch_config:get("httpd", "bind_address", "127.0.0.1")),
- put(port, integer_to_list(mochiweb_socket_server:get(couch_httpd, port))),
- application:start(inets),
- timer:sleep(1000),
- couch_server:delete(test_db_name(), []),
- couch_db:create(test_db_name(), []),
-
- couch_config:set("attachments", "compression_level", "8", false),
- couch_config:set("attachments", "compressible_types", "text/*", false),
-
- create_1st_text_att(),
- create_1st_png_att(),
- create_2nd_text_att(),
- create_2nd_png_att(),
-
- tests_for_1st_text_att(),
- tests_for_1st_png_att(),
- tests_for_2nd_text_att(),
- tests_for_2nd_png_att(),
-
- create_already_compressed_att(db_url() ++ "/doc_comp_att", "readme.txt"),
- test_already_compressed_att(db_url() ++ "/doc_comp_att", "readme.txt"),
-
- test_create_already_compressed_att_with_invalid_content_encoding(
- db_url() ++ "/doc_att_deflate",
- "readme.txt",
- zlib:compress(test_text_data()),
- "deflate"
- ),
-
- test_create_already_compressed_att_with_invalid_content_encoding(
- db_url() ++ "/doc_att_compress",
- "readme.txt",
- % Note: As of OTP R13B04, it seems there's no LZW compression
- % (i.e. UNIX compress utility implementation) lib in OTP.
- % However there's a simple working Erlang implementation at:
- % http://scienceblogs.com/goodmath/2008/01/simple_lempelziv_compression_i.php
- test_text_data(),
- "compress"
- ),
-
- test_compressible_type_with_parameters(),
-
- timer:sleep(3000), % to avoid mochiweb socket closed exceptions
- couch_server:delete(test_db_name(), []),
- couch_server_sup:stop(),
- ok.
-
-db_url() ->
- "http://" ++ get(addr) ++ ":" ++ get(port) ++ "/" ++
- binary_to_list(test_db_name()).
-
-create_1st_text_att() ->
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
- put,
- {db_url() ++ "/testdoc1/readme.txt", [],
- "text/plain", test_text_data()},
- [],
- [{sync, true}]),
- etap:is(Code, 201, "Created text attachment using the standalone api"),
- ok.
-
-create_1st_png_att() ->
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
- put,
- {db_url() ++ "/testdoc2/icon.png", [],
- "image/png", test_png_data()},
- [],
- [{sync, true}]),
- etap:is(Code, 201, "Created png attachment using the standalone api"),
- ok.
-
-% create a text attachment using the non-standalone attachment api
-create_2nd_text_att() ->
- DocJson = {[
- {<<"_attachments">>, {[
- {<<"readme.txt">>, {[
- {<<"content_type">>, <<"text/plain">>},
- {<<"data">>, base64:encode(test_text_data())}
- ]}
- }]}}
- ]},
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
- put,
- {db_url() ++ "/testdoc3", [],
- "application/json", list_to_binary(couch_util:json_encode(DocJson))},
- [],
- [{sync, true}]),
- etap:is(Code, 201, "Created text attachment using the non-standalone api"),
- ok.
-
-% create a png attachment using the non-standalone attachment api
-create_2nd_png_att() ->
- DocJson = {[
- {<<"_attachments">>, {[
- {<<"icon.png">>, {[
- {<<"content_type">>, <<"image/png">>},
- {<<"data">>, base64:encode(test_png_data())}
- ]}
- }]}}
- ]},
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
- put,
- {db_url() ++ "/testdoc4", [],
- "application/json", list_to_binary(couch_util:json_encode(DocJson))},
- [],
- [{sync, true}]),
- etap:is(Code, 201, "Created png attachment using the non-standalone api"),
- ok.
-
-create_already_compressed_att(DocUri, AttName) ->
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
- put,
- {DocUri ++ "/" ++ AttName, [{"Content-Encoding", "gzip"}],
- "text/plain", zlib:gzip(test_text_data())},
- [],
- [{sync, true}]),
- etap:is(
- Code,
- 201,
- "Created already compressed attachment using the standalone api"
- ),
- ok.
-
-tests_for_1st_text_att() ->
- test_get_1st_text_att_with_accept_encoding_gzip(),
- test_get_1st_text_att_without_accept_encoding_header(),
- test_get_1st_text_att_with_accept_encoding_deflate(),
- test_get_1st_text_att_with_accept_encoding_deflate_only(),
- test_get_doc_with_1st_text_att(),
- test_1st_text_att_stub().
-
-tests_for_1st_png_att() ->
- test_get_1st_png_att_without_accept_encoding_header(),
- test_get_1st_png_att_with_accept_encoding_gzip(),
- test_get_1st_png_att_with_accept_encoding_deflate(),
- test_get_doc_with_1st_png_att(),
- test_1st_png_att_stub().
-
-tests_for_2nd_text_att() ->
- test_get_2nd_text_att_with_accept_encoding_gzip(),
- test_get_2nd_text_att_without_accept_encoding_header(),
- test_get_doc_with_2nd_text_att(),
- test_2nd_text_att_stub().
-
-tests_for_2nd_png_att() ->
- test_get_2nd_png_att_without_accept_encoding_header(),
- test_get_2nd_png_att_with_accept_encoding_gzip(),
- test_get_doc_with_2nd_png_att(),
- test_2nd_png_att_stub().
-
-test_get_1st_text_att_with_accept_encoding_gzip() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc1/readme.txt", [{"Accept-Encoding", "gzip"}]},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
- etap:is(Gziped, true, "received body is gziped"),
- Uncompressed = binary_to_list(zlib:gunzip(list_to_binary(Body))),
- etap:is(
- Uncompressed,
- test_text_data(),
- "received data for the 1st text attachment is ok"
- ),
- ok.
-
-test_get_1st_text_att_without_accept_encoding_header() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc1/readme.txt", []},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
- etap:is(Gziped, false, "received body is not gziped"),
- etap:is(
- Body,
- test_text_data(),
- "received data for the 1st text attachment is ok"
- ),
- ok.
-
-test_get_1st_text_att_with_accept_encoding_deflate() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc1/readme.txt", [{"Accept-Encoding", "deflate"}]},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
- etap:is(Gziped, false, "received body is not gziped"),
- Deflated = lists:member({"content-encoding", "deflate"}, Headers),
- etap:is(Deflated, false, "received body is not deflated"),
- etap:is(
- Body,
- test_text_data(),
- "received data for the 1st text attachment is ok"
- ),
- ok.
-
-test_get_1st_text_att_with_accept_encoding_deflate_only() ->
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
- get,
- {db_url() ++ "/testdoc1/readme.txt",
- [{"Accept-Encoding", "deflate, *;q=0"}]},
- [],
- [{sync, true}]),
- etap:is(
- Code,
- 406,
- "HTTP response code is 406 for an unsupported content encoding request"
- ),
- ok.
-
-test_get_1st_png_att_without_accept_encoding_header() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc2/icon.png", []},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Encoding = couch_util:get_value("content-encoding", Headers),
- etap:is(Encoding, undefined, "received body is not gziped"),
- etap:is(
- Body,
- test_png_data(),
- "received data for the 1st png attachment is ok"
- ),
- ok.
-
-test_get_1st_png_att_with_accept_encoding_gzip() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc2/icon.png", [{"Accept-Encoding", "gzip"}]},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Encoding = couch_util:get_value("content-encoding", Headers),
- etap:is(Encoding, undefined, "received body is not gziped"),
- etap:is(
- Body,
- test_png_data(),
- "received data for the 1st png attachment is ok"
- ),
- ok.
-
-test_get_1st_png_att_with_accept_encoding_deflate() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc2/icon.png", [{"Accept-Encoding", "deflate"}]},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Encoding = couch_util:get_value("content-encoding", Headers),
- etap:is(Encoding, undefined, "received body is in identity form"),
- etap:is(
- Body,
- test_png_data(),
- "received data for the 1st png attachment is ok"
- ),
- ok.
-
-test_get_doc_with_1st_text_att() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc1?attachments=true",
- [{"Accept", "application/json"}]},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Json = couch_util:json_decode(Body),
- TextAttJson = couch_util:get_nested_json_value(
- Json,
- [<<"_attachments">>, <<"readme.txt">>]
- ),
- TextAttType = couch_util:get_nested_json_value(
- TextAttJson,
- [<<"content_type">>]
- ),
- TextAttData = couch_util:get_nested_json_value(
- TextAttJson,
- [<<"data">>]
- ),
- etap:is(
- TextAttType,
- <<"text/plain">>,
- "1st text attachment has type text/plain"
- ),
- %% check the attachment's data is the base64 encoding of the plain text
- %% and not the base64 encoding of the gziped plain text
- etap:is(
- TextAttData,
- base64:encode(test_text_data()),
- "1st text attachment data is properly base64 encoded"
- ),
- ok.
-
-test_1st_text_att_stub() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc1?att_encoding_info=true", []},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Json = couch_util:json_decode(Body),
- {TextAttJson} = couch_util:get_nested_json_value(
- Json,
- [<<"_attachments">>, <<"readme.txt">>]
- ),
- TextAttLength = couch_util:get_value(<<"length">>, TextAttJson),
- etap:is(
- TextAttLength,
- length(test_text_data()),
- "1st text attachment stub length matches the uncompressed length"
- ),
- TextAttEncoding = couch_util:get_value(<<"encoding">>, TextAttJson),
- etap:is(
- TextAttEncoding,
- <<"gzip">>,
- "1st text attachment stub has the encoding field set to gzip"
- ),
- TextAttEncLength = couch_util:get_value(<<"encoded_length">>, TextAttJson),
- etap:is(
- TextAttEncLength,
- iolist_size(zlib:gzip(test_text_data())),
- "1st text attachment stub encoded_length matches the compressed length"
- ),
- ok.
-
-test_get_doc_with_1st_png_att() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc2?attachments=true",
- [{"Accept", "application/json"}]},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Json = couch_util:json_decode(Body),
- PngAttJson = couch_util:get_nested_json_value(
- Json,
- [<<"_attachments">>, <<"icon.png">>]
- ),
- PngAttType = couch_util:get_nested_json_value(
- PngAttJson,
- [<<"content_type">>]
- ),
- PngAttData = couch_util:get_nested_json_value(
- PngAttJson,
- [<<"data">>]
- ),
- etap:is(PngAttType, <<"image/png">>, "attachment has type image/png"),
- etap:is(
- PngAttData,
- base64:encode(test_png_data()),
- "1st png attachment data is properly base64 encoded"
- ),
- ok.
-
-test_1st_png_att_stub() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc2?att_encoding_info=true", []},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Json = couch_util:json_decode(Body),
- {PngAttJson} = couch_util:get_nested_json_value(
- Json,
- [<<"_attachments">>, <<"icon.png">>]
- ),
- PngAttLength = couch_util:get_value(<<"length">>, PngAttJson),
- etap:is(
- PngAttLength,
- length(test_png_data()),
- "1st png attachment stub length matches the uncompressed length"
- ),
- PngEncoding = couch_util:get_value(<<"encoding">>, PngAttJson),
- etap:is(
- PngEncoding,
- undefined,
- "1st png attachment stub doesn't have an encoding field"
- ),
- PngEncLength = couch_util:get_value(<<"encoded_length">>, PngAttJson),
- etap:is(
- PngEncLength,
- undefined,
- "1st png attachment stub doesn't have an encoded_length field"
- ),
- ok.
-
-test_get_2nd_text_att_with_accept_encoding_gzip() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc3/readme.txt", [{"Accept-Encoding", "gzip"}]},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
- etap:is(Gziped, true, "received body is gziped"),
- Uncompressed = binary_to_list(zlib:gunzip(list_to_binary(Body))),
- etap:is(
- Uncompressed,
- test_text_data(),
- "received data for the 2nd text attachment is ok"
- ),
- ok.
-
-test_get_2nd_text_att_without_accept_encoding_header() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc3/readme.txt", []},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
- etap:is(Gziped, false, "received body is not gziped"),
- etap:is(
- Body,
- test_text_data(),
- "received data for the 2nd text attachment is ok"
- ),
- ok.
-
-test_get_2nd_png_att_without_accept_encoding_header() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc4/icon.png", []},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
- etap:is(Gziped, false, "received body is not gziped"),
- etap:is(
- Body,
- test_png_data(),
- "received data for the 2nd png attachment is ok"
- ),
- ok.
-
-test_get_2nd_png_att_with_accept_encoding_gzip() ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc4/icon.png", [{"Accept-Encoding", "gzip"}]},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
- etap:is(Gziped, false, "received body is not gziped"),
- etap:is(
- Body,
- test_png_data(),
- "received data for the 2nd png attachment is ok"
- ),
- ok.
-
-test_get_doc_with_2nd_text_att() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc3?attachments=true",
- [{"Accept", "application/json"}]},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Json = couch_util:json_decode(Body),
- TextAttJson = couch_util:get_nested_json_value(
- Json,
- [<<"_attachments">>, <<"readme.txt">>]
- ),
- TextAttType = couch_util:get_nested_json_value(
- TextAttJson,
- [<<"content_type">>]
- ),
- TextAttData = couch_util:get_nested_json_value(
- TextAttJson,
- [<<"data">>]
- ),
- etap:is(TextAttType, <<"text/plain">>, "attachment has type text/plain"),
- %% check the attachment's data is the base64 encoding of the plain text
- %% and not the base64 encoding of the gziped plain text
- etap:is(
- TextAttData,
- base64:encode(test_text_data()),
- "2nd text attachment data is properly base64 encoded"
- ),
- ok.
-
-test_2nd_text_att_stub() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc3?att_encoding_info=true", []},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Json = couch_util:json_decode(Body),
- {TextAttJson} = couch_util:get_nested_json_value(
- Json,
- [<<"_attachments">>, <<"readme.txt">>]
- ),
- TextAttLength = couch_util:get_value(<<"length">>, TextAttJson),
- etap:is(
- TextAttLength,
- length(test_text_data()),
- "2nd text attachment stub length matches the uncompressed length"
- ),
- TextAttEncoding = couch_util:get_value(<<"encoding">>, TextAttJson),
- etap:is(
- TextAttEncoding,
- <<"gzip">>,
- "2nd text attachment stub has the encoding field set to gzip"
- ),
- TextAttEncLength = couch_util:get_value(<<"encoded_length">>, TextAttJson),
- etap:is(
- TextAttEncLength,
- iolist_size(zlib:gzip(test_text_data())),
- "2nd text attachment stub encoded_length matches the compressed length"
- ),
- ok.
-
-test_get_doc_with_2nd_png_att() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc4?attachments=true",
- [{"Accept", "application/json"}]},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Json = couch_util:json_decode(Body),
- PngAttJson = couch_util:get_nested_json_value(
- Json,
- [<<"_attachments">>, <<"icon.png">>]
- ),
- PngAttType = couch_util:get_nested_json_value(
- PngAttJson,
- [<<"content_type">>]
- ),
- PngAttData = couch_util:get_nested_json_value(
- PngAttJson,
- [<<"data">>]
- ),
- etap:is(PngAttType, <<"image/png">>, "attachment has type image/png"),
- etap:is(
- PngAttData,
- base64:encode(test_png_data()),
- "2nd png attachment data is properly base64 encoded"
- ),
- ok.
-
-test_2nd_png_att_stub() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc4?att_encoding_info=true", []},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Json = couch_util:json_decode(Body),
- {PngAttJson} = couch_util:get_nested_json_value(
- Json,
- [<<"_attachments">>, <<"icon.png">>]
- ),
- PngAttLength = couch_util:get_value(<<"length">>, PngAttJson),
- etap:is(
- PngAttLength,
- length(test_png_data()),
- "2nd png attachment stub length matches the uncompressed length"
- ),
- PngEncoding = couch_util:get_value(<<"encoding">>, PngAttJson),
- etap:is(
- PngEncoding,
- undefined,
- "2nd png attachment stub doesn't have an encoding field"
- ),
- PngEncLength = couch_util:get_value(<<"encoded_length">>, PngAttJson),
- etap:is(
- PngEncLength,
- undefined,
- "2nd png attachment stub doesn't have an encoded_length field"
- ),
- ok.
-
-test_already_compressed_att(DocUri, AttName) ->
- test_get_already_compressed_att_with_accept_gzip(DocUri, AttName),
- test_get_already_compressed_att_without_accept(DocUri, AttName),
- test_get_already_compressed_att_stub(DocUri, AttName).
-
-test_get_already_compressed_att_with_accept_gzip(DocUri, AttName) ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {DocUri ++ "/" ++ AttName, [{"Accept-Encoding", "gzip"}]},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
- etap:is(Gziped, true, "received body is gziped"),
- etap:is(
- iolist_to_binary(Body),
- iolist_to_binary(zlib:gzip(test_text_data())),
- "received data for the already compressed attachment is ok"
- ),
- ok.
-
-test_get_already_compressed_att_without_accept(DocUri, AttName) ->
- {ok, {{_, Code, _}, Headers, Body}} = http:request(
- get,
- {DocUri ++ "/" ++ AttName, []},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers),
- etap:is(Gziped, false, "received body is not gziped"),
- etap:is(
- iolist_to_binary(Body),
- iolist_to_binary(test_text_data()),
- "received data for the already compressed attachment is ok"
- ),
- ok.
-
-test_get_already_compressed_att_stub(DocUri, AttName) ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {DocUri ++ "?att_encoding_info=true", []},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "HTTP response code is 200"),
- Json = couch_util:json_decode(Body),
- {AttJson} = couch_util:get_nested_json_value(
- Json,
- [<<"_attachments">>, iolist_to_binary(AttName)]
- ),
- AttLength = couch_util:get_value(<<"length">>, AttJson),
- etap:is(
- AttLength,
- iolist_size((zlib:gzip(test_text_data()))),
- "Already compressed attachment stub length matches the "
- "compressed length"
- ),
- Encoding = couch_util:get_value(<<"encoding">>, AttJson),
- etap:is(
- Encoding,
- <<"gzip">>,
- "Already compressed attachment stub has the encoding field set to gzip"
- ),
- EncLength = couch_util:get_value(<<"encoded_length">>, AttJson),
- etap:is(
- EncLength,
- AttLength,
- "Already compressed attachment stub encoded_length matches the "
- "length field value"
- ),
- ok.
-
-test_create_already_compressed_att_with_invalid_content_encoding(
- DocUri, AttName, AttData, Encoding) ->
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
- put,
- {DocUri ++ "/" ++ AttName, [{"Content-Encoding", Encoding}],
- "text/plain", AttData},
- [],
- [{sync, true}]),
- etap:is(
- Code,
- 415,
- "Couldn't create an already compressed attachment using the "
- "unsupported encoding '" ++ Encoding ++ "'"
- ),
- ok.
-
-test_compressible_type_with_parameters() ->
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
- put,
- {db_url() ++ "/testdoc5/readme.txt", [],
- "text/plain; charset=UTF-8", test_text_data()},
- [],
- [{sync, true}]),
- etap:is(Code, 201, "Created text attachment with MIME type "
- "'text/plain; charset=UTF-8' using the standalone api"),
- {ok, {{_, Code2, _}, Headers2, Body}} = http:request(
- get,
- {db_url() ++ "/testdoc5/readme.txt", [{"Accept-Encoding", "gzip"}]},
- [],
- [{sync, true}]),
- etap:is(Code2, 200, "HTTP response code is 200"),
- Gziped = lists:member({"content-encoding", "gzip"}, Headers2),
- etap:is(Gziped, true, "received body is gziped"),
- Uncompressed = binary_to_list(zlib:gunzip(list_to_binary(Body))),
- etap:is(Uncompressed, test_text_data(), "received data is gzipped"),
- {ok, {{_, Code3, _}, _Headers3, Body3}} = http:request(
- get,
- {db_url() ++ "/testdoc5?att_encoding_info=true", []},
- [],
- [{sync, true}]),
- etap:is(Code3, 200, "HTTP response code is 200"),
- Json = couch_util:json_decode(Body3),
- {TextAttJson} = couch_util:get_nested_json_value(
- Json,
- [<<"_attachments">>, <<"readme.txt">>]
- ),
- TextAttLength = couch_util:get_value(<<"length">>, TextAttJson),
- etap:is(
- TextAttLength,
- length(test_text_data()),
- "text attachment stub length matches the uncompressed length"
- ),
- TextAttEncoding = couch_util:get_value(<<"encoding">>, TextAttJson),
- etap:is(
- TextAttEncoding,
- <<"gzip">>,
- "text attachment stub has the encoding field set to gzip"
- ),
- TextAttEncLength = couch_util:get_value(<<"encoded_length">>, TextAttJson),
- etap:is(
- TextAttEncLength,
- iolist_size(zlib:gzip(test_text_data())),
- "text attachment stub encoded_length matches the compressed length"
- ),
- ok.
-
-test_png_data() ->
- {ok, Data} = file:read_file(
- test_util:source_file("share/www/image/logo.png")
- ),
- binary_to_list(Data).
-
-test_text_data() ->
- {ok, Data} = file:read_file(
- test_util:source_file("README")
- ),
- binary_to_list(Data).
diff --git a/test/etap/150-invalid-view-seq.t b/test/etap/150-invalid-view-seq.t
deleted file mode 100755
index 594d3416..00000000
--- a/test/etap/150-invalid-view-seq.t
+++ /dev/null
@@ -1,190 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
--record(user_ctx, {
- name = null,
- roles = [],
- handler
-}).
-
-test_db_name() ->
- <<"couch_test_invalid_view_seq">>.
-
-main(_) ->
- test_util:init_code_path(),
-
- etap:plan(10),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail(Other)
- end,
- ok.
-
-%% NOTE: since during the test we stop the server,
-%% a huge and ugly but harmless stack trace is sent to stderr
-%%
-test() ->
- couch_server_sup:start_link(test_util:config_files()),
- timer:sleep(1000),
- delete_db(),
- create_db(),
-
- create_docs(),
- create_design_doc(),
-
- % make DB file backup
- backup_db_file(),
-
- put(addr, couch_config:get("httpd", "bind_address", "127.0.0.1")),
- put(port, integer_to_list(mochiweb_socket_server:get(couch_httpd, port))),
- application:start(inets),
-
- create_new_doc(),
- query_view_before_restore_backup(),
-
- % restore DB file backup after querying view
- restore_backup_db_file(),
-
- query_view_after_restore_backup(),
-
- delete_db(),
- couch_server_sup:stop(),
- ok.
-
-admin_user_ctx() ->
- {user_ctx, #user_ctx{roles=[<<"_admin">>]}}.
-
-create_db() ->
- {ok, _} = couch_db:create(test_db_name(), [admin_user_ctx()]).
-
-delete_db() ->
- couch_server:delete(test_db_name(), [admin_user_ctx()]).
-
-create_docs() ->
- {ok, Db} = couch_db:open(test_db_name(), [admin_user_ctx()]),
- Doc1 = couch_doc:from_json_obj({[
- {<<"_id">>, <<"doc1">>},
- {<<"value">>, 1}
-
- ]}),
- Doc2 = couch_doc:from_json_obj({[
- {<<"_id">>, <<"doc2">>},
- {<<"value">>, 2}
-
- ]}),
- Doc3 = couch_doc:from_json_obj({[
- {<<"_id">>, <<"doc3">>},
- {<<"value">>, 3}
-
- ]}),
- {ok, _} = couch_db:update_docs(Db, [Doc1, Doc2, Doc3]),
- couch_db:ensure_full_commit(Db),
- couch_db:close(Db).
-
-create_design_doc() ->
- {ok, Db} = couch_db:open(test_db_name(), [admin_user_ctx()]),
- DDoc = couch_doc:from_json_obj({[
- {<<"_id">>, <<"_design/foo">>},
- {<<"language">>, <<"javascript">>},
- {<<"views">>, {[
- {<<"bar">>, {[
- {<<"map">>, <<"function(doc) { emit(doc.value, 1); }">>}
- ]}}
- ]}}
- ]}),
- {ok, _} = couch_db:update_docs(Db, [DDoc]),
- couch_db:ensure_full_commit(Db),
- couch_db:close(Db).
-
-backup_db_file() ->
- DbFile = test_util:build_file("tmp/lib/" ++
- binary_to_list(test_db_name()) ++ ".couch"),
- {ok, _} = file:copy(DbFile, DbFile ++ ".backup"),
- ok.
-
-create_new_doc() ->
- {ok, Db} = couch_db:open(test_db_name(), [admin_user_ctx()]),
- Doc666 = couch_doc:from_json_obj({[
- {<<"_id">>, <<"doc666">>},
- {<<"value">>, 999}
-
- ]}),
- {ok, _} = couch_db:update_docs(Db, [Doc666]),
- couch_db:ensure_full_commit(Db),
- couch_db:close(Db).
-
-db_url() ->
- "http://" ++ get(addr) ++ ":" ++ get(port) ++ "/" ++
- binary_to_list(test_db_name()).
-
-query_view_before_restore_backup() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/_design/foo/_view/bar", []},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "Got view response before restoring backup."),
- ViewJson = couch_util:json_decode(Body),
- Rows = couch_util:get_nested_json_value(ViewJson, [<<"rows">>]),
- HasDoc1 = has_doc("doc1", Rows),
- HasDoc2 = has_doc("doc2", Rows),
- HasDoc3 = has_doc("doc3", Rows),
- HasDoc666 = has_doc("doc666", Rows),
- etap:is(HasDoc1, true, "Before backup restore, view has doc1"),
- etap:is(HasDoc2, true, "Before backup restore, view has doc2"),
- etap:is(HasDoc3, true, "Before backup restore, view has doc3"),
- etap:is(HasDoc666, true, "Before backup restore, view has doc666"),
- ok.
-
-has_doc(DocId1, Rows) ->
- DocId = iolist_to_binary(DocId1),
- lists:any(
- fun({R}) -> lists:member({<<"id">>, DocId}, R) end,
- Rows
- ).
-
-restore_backup_db_file() ->
- couch_server_sup:stop(),
- timer:sleep(3000),
- DbFile = test_util:build_file("tmp/lib/" ++
- binary_to_list(test_db_name()) ++ ".couch"),
- ok = file:delete(DbFile),
- ok = file:rename(DbFile ++ ".backup", DbFile),
- couch_server_sup:start_link(test_util:config_files()),
- timer:sleep(1000),
- put(port, integer_to_list(mochiweb_socket_server:get(couch_httpd, port))),
- ok.
-
-query_view_after_restore_backup() ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/_design/foo/_view/bar", []},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "Got view response after restoring backup."),
- ViewJson = couch_util:json_decode(Body),
- Rows = couch_util:get_nested_json_value(ViewJson, [<<"rows">>]),
- HasDoc1 = has_doc("doc1", Rows),
- HasDoc2 = has_doc("doc2", Rows),
- HasDoc3 = has_doc("doc3", Rows),
- HasDoc666 = has_doc("doc666", Rows),
- etap:is(HasDoc1, true, "After backup restore, view has doc1"),
- etap:is(HasDoc2, true, "After backup restore, view has doc2"),
- etap:is(HasDoc3, true, "After backup restore, view has doc3"),
- etap:is(HasDoc666, false, "After backup restore, view does not have doc666"),
- ok.
diff --git a/test/etap/160-vhosts.t b/test/etap/160-vhosts.t
deleted file mode 100755
index 8dac53e5..00000000
--- a/test/etap/160-vhosts.t
+++ /dev/null
@@ -1,291 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
-%% XXX: Figure out how to -include("couch_rep.hrl")
--record(http_db, {
- url,
- auth = [],
- resource = "",
- headers = [
- {"User-Agent", "CouchDB/"++couch_server:get_version()},
- {"Accept", "application/json"},
- {"Accept-Encoding", "gzip"}
- ],
- qs = [],
- method = get,
- body = nil,
- options = [
- {response_format,binary},
- {inactivity_timeout, 30000}
- ],
- retries = 10,
- pause = 1,
- conn = nil
-}).
-
--record(user_ctx, {
- name = null,
- roles = [],
- handler
-}).
-
-server() ->
- lists:concat([
- "http://127.0.0.1:", mochiweb_socket_server:get(couch_httpd, port), "/"
- ]).
-
-dbname() -> "etap-test-db".
-admin_user_ctx() -> {user_ctx, #user_ctx{roles=[<<"_admin">>]}}.
-
-main(_) ->
- test_util:init_code_path(),
-
- etap:plan(14),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail(Other)
- end,
- ok.
-
-test() ->
- couch_server_sup:start_link(test_util:config_files()),
- ibrowse:start(),
- crypto:start(),
-
- timer:sleep(1000),
- couch_server:delete(list_to_binary(dbname()), [admin_user_ctx()]),
- {ok, Db} = couch_db:create(list_to_binary(dbname()), [admin_user_ctx()]),
-
- Doc = couch_doc:from_json_obj({[
- {<<"_id">>, <<"doc1">>},
- {<<"value">>, 666}
- ]}),
-
- Doc1 = couch_doc:from_json_obj({[
- {<<"_id">>, <<"_design/doc1">>},
- {<<"shows">>, {[
- {<<"test">>, <<"function(doc, req) {
- return { json: {
- requested_path: '/' + req.requested_path.join('/'),
- path: '/' + req.path.join('/')
- }};
-}">>}
- ]}},
- {<<"rewrites">>, [
- {[
- {<<"from">>, <<"/">>},
- {<<"to">>, <<"_show/test">>}
- ]}
- ]}
- ]}),
-
- {ok, _} = couch_db:update_docs(Db, [Doc, Doc1]),
-
- couch_db:ensure_full_commit(Db),
-
- %% end boilerplate, start test
-
- ok = couch_config:set("vhosts", "example.com", "/etap-test-db", false),
- ok = couch_config:set("vhosts", "*.example.com",
- "/etap-test-db/_design/doc1/_rewrite", false),
- ok = couch_config:set("vhosts", "example.com/test", "/etap-test-db", false),
- ok = couch_config:set("vhosts", "example1.com",
- "/etap-test-db/_design/doc1/_rewrite/", false),
- ok = couch_config:set("vhosts",":appname.:dbname.example1.com",
- "/:dbname/_design/:appname/_rewrite/", false),
- ok = couch_config:set("vhosts", ":dbname.example1.com", "/:dbname", false),
-
- ok = couch_config:set("vhosts", "*.example2.com", "/*", false),
- ok = couch_config:set("vhosts", "*/test", "/etap-test-db", false),
- ok = couch_config:set("vhosts", "*.example2.com/test", "/*", false),
- ok = couch_config:set("vhosts", "*/test1",
- "/etap-test-db/_design/doc1/_show/test", false),
-
- % let couch_httpd restart
- timer:sleep(100),
-
- test_regular_request(),
- test_vhost_request(),
- test_vhost_request_with_qs(),
- test_vhost_request_with_global(),
- test_vhost_requested_path(),
- test_vhost_requested_path_path(),
- test_vhost_request_wildcard(),
- test_vhost_request_replace_var(),
- test_vhost_request_replace_var1(),
- test_vhost_request_replace_wildcard(),
- test_vhost_request_path(),
- test_vhost_request_path1(),
- test_vhost_request_path2(),
- test_vhost_request_path3(),
-
- %% restart boilerplate
- couch_db:close(Db),
- timer:sleep(3000),
- couch_server_sup:stop(),
-
- ok.
-
-test_regular_request() ->
- Result = case ibrowse:send_req(server(), [], get, []) of
- {ok, _, _, Body} ->
- {[{<<"couchdb">>, <<"Welcome">>},
- {<<"version">>,_}
- ]} = couch_util:json_decode(Body),
- etap:is(true, true, "should return server info");
- _Else ->
- etap:is(false, true, <<"ibrowse fail">>)
- end.
-
-test_vhost_request() ->
- case ibrowse:send_req(server(), [], get, [], [{host_header, "example.com"}]) of
- {ok, _, _, Body} ->
- {JsonBody} = couch_util:json_decode(Body),
- HasDbNameInfo = proplists:is_defined(<<"db_name">>, JsonBody),
- etap:is(HasDbNameInfo, true, "should return database info");
- _Else ->
- etap:is(false, true, <<"ibrowse fail">>)
- end.
-
-test_vhost_request_with_qs() ->
- Url = server() ++ "doc1?revs_info=true",
- case ibrowse:send_req(Url, [], get, [], [{host_header, "example.com"}]) of
- {ok, _, _, Body} ->
- {JsonProps} = couch_util:json_decode(Body),
- HasRevsInfo = proplists:is_defined(<<"_revs_info">>, JsonProps),
- etap:is(HasRevsInfo, true, "should return _revs_info");
- _Else ->
- etap:is(false, true, <<"ibrowse fail">>)
- end.
-
-test_vhost_request_with_global() ->
- Url2 = server() ++ "_utils/index.html",
- case ibrowse:send_req(Url2, [], get, [], [{host_header, "example.com"}]) of
- {ok, _, _, Body2} ->
- "<!DOCTYPE" ++ _Foo = Body2,
- etap:is(true, true, "should serve /_utils even inside vhosts");
- _Else ->
- etap:is(false, true, <<"ibrowse fail">>)
- end.
-
-test_vhost_requested_path() ->
- case ibrowse:send_req(server(), [], get, [], [{host_header, "example1.com"}]) of
- {ok, _, _, Body} ->
- {Json} = couch_util:json_decode(Body),
- etap:is(case proplists:get_value(<<"requested_path">>, Json) of
- <<"/">> -> true;
- _ -> false
- end, true, <<"requested path in req ok">>);
- _Else ->
- etap:is(false, true, <<"ibrowse fail">>)
- end.
-
-test_vhost_requested_path_path() ->
- case ibrowse:send_req(server(), [], get, [], [{host_header, "example1.com"}]) of
- {ok, _, _, Body} ->
- {Json} = couch_util:json_decode(Body),
- etap:is(case proplists:get_value(<<"path">>, Json) of
- <<"/etap-test-db/_design/doc1/_show/test">> -> true;
- _ -> false
- end, true, <<"path in req ok">>);
- _Else ->
- etap:is(false, true, <<"ibrowse fail">>)
- end.
-
-test_vhost_request_wildcard()->
- case ibrowse:send_req(server(), [], get, [], [{host_header, "test.example.com"}]) of
- {ok, _, _, Body} ->
- {Json} = couch_util:json_decode(Body),
- etap:is(case proplists:get_value(<<"path">>, Json) of
- <<"/etap-test-db/_design/doc1/_show/test">> -> true;
- _ -> false
- end, true, <<"wildcard ok">>);
- _Else -> etap:is(false, true, <<"ibrowse fail">>)
- end.
-
-
-test_vhost_request_replace_var() ->
- case ibrowse:send_req(server(), [], get, [], [{host_header,"etap-test-db.example1.com"}]) of
- {ok, _, _, Body} ->
- {JsonBody} = couch_util:json_decode(Body),
- HasDbNameInfo = proplists:is_defined(<<"db_name">>, JsonBody),
- etap:is(HasDbNameInfo, true, "should return database info");
- _Else -> etap:is(false, true, <<"ibrowse fail">>)
- end.
-
-test_vhost_request_replace_var1() ->
- case ibrowse:send_req(server(), [], get, [], [{host_header, "doc1.etap-test-db.example1.com"}]) of
- {ok, _, _, Body} ->
- {Json} = couch_util:json_decode(Body),
- etap:is(case proplists:get_value(<<"path">>, Json) of
- <<"/etap-test-db/_design/doc1/_show/test">> -> true;
- _ -> false
- end, true, <<"wildcard ok">>);
- _Else -> etap:is(false, true, <<"ibrowse fail">>)
- end.
-
-test_vhost_request_replace_wildcard() ->
- case ibrowse:send_req(server(), [], get, [], [{host_header,"etap-test-db.example2.com"}]) of
- {ok, _, _, Body} ->
- {JsonBody} = couch_util:json_decode(Body),
- HasDbNameInfo = proplists:is_defined(<<"db_name">>, JsonBody),
- etap:is(HasDbNameInfo, true, "should return database info");
- _Else -> etap:is(false, true, <<"ibrowse fail">>)
- end.
-
-test_vhost_request_path() ->
- Uri = server() ++ "test",
- case ibrowse:send_req(Uri, [], get, [], [{host_header, "example.com"}]) of
- {ok, _, _, Body} ->
- {JsonBody} = couch_util:json_decode(Body),
- HasDbNameInfo = proplists:is_defined(<<"db_name">>, JsonBody),
- etap:is(HasDbNameInfo, true, "should return database info");
- _Else -> etap:is(false, true, <<"ibrowse fail">>)
- end.
-
-test_vhost_request_path1() ->
- Url = server() ++ "test/doc1?revs_info=true",
- case ibrowse:send_req(Url, [], get, [], []) of
- {ok, _, _, Body} ->
- {JsonProps} = couch_util:json_decode(Body),
- HasRevsInfo = proplists:is_defined(<<"_revs_info">>, JsonProps),
- etap:is(HasRevsInfo, true, "should return _revs_info");
- _Else -> etap:is(false, true, <<"ibrowse fail">>)
- end.
-
-test_vhost_request_path2() ->
- Uri = server() ++ "test",
- case ibrowse:send_req(Uri, [], get, [], [{host_header,"etap-test-db.example2.com"}]) of
- {ok, _, _, Body} ->
- {JsonBody} = couch_util:json_decode(Body),
- HasDbNameInfo = proplists:is_defined(<<"db_name">>, JsonBody),
- etap:is(HasDbNameInfo, true, "should return database info");
- _Else -> etap:is(false, true, <<"ibrowse fail">>)
- end.
-
-test_vhost_request_path3() ->
- Uri = server() ++ "test1",
- case ibrowse:send_req(Uri, [], get, [], []) of
- {ok, _, _, Body} ->
- {Json} = couch_util:json_decode(Body),
- etap:is(case proplists:get_value(<<"path">>, Json) of
- <<"/etap-test-db/_design/doc1/_show/test">> -> true;
- _ -> false
- end, true, <<"path in req ok">>);
- _Else -> etap:is(false, true, <<"ibrowse fail">>)
- end.
diff --git a/test/etap/170-os-daemons.es b/test/etap/170-os-daemons.es
deleted file mode 100755
index 73974e90..00000000
--- a/test/etap/170-os-daemons.es
+++ /dev/null
@@ -1,26 +0,0 @@
-#! /usr/bin/env escript
-
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
-loop() ->
- loop(io:read("")).
-
-loop({ok, _}) ->
- loop(io:read(""));
-loop(eof) ->
- stop;
-loop({error, Reason}) ->
- throw({error, Reason}).
-
-main([]) ->
- loop().
diff --git a/test/etap/170-os-daemons.t b/test/etap/170-os-daemons.t
deleted file mode 100755
index 6feaa1bf..00000000
--- a/test/etap/170-os-daemons.t
+++ /dev/null
@@ -1,114 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
--record(daemon, {
- port,
- name,
- cmd,
- kill,
- status=running,
- cfg_patterns=[],
- errors=[],
- buf=[]
-}).
-
-config_files() ->
- lists:map(fun test_util:build_file/1, [
- "etc/couchdb/default_dev.ini"
- ]).
-
-daemon_cmd() ->
- test_util:source_file("test/etap/170-os-daemons.es").
-
-main(_) ->
- test_util:init_code_path(),
-
- etap:plan(49),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail(Other)
- end,
- ok.
-
-test() ->
- couch_config:start_link(config_files()),
- couch_os_daemons:start_link(),
-
- etap:diag("Daemons boot after configuration added."),
- couch_config:set("os_daemons", "foo", daemon_cmd(), false),
- timer:sleep(1000),
-
- {ok, [D1]} = couch_os_daemons:info([table]),
- check_daemon(D1, "foo"),
-
- % Check table form
- {ok, Tab1} = couch_os_daemons:info(),
- [T1] = ets:tab2list(Tab1),
- check_daemon(T1, "foo"),
-
- etap:diag("Daemons stop after configuration removed."),
- couch_config:delete("os_daemons", "foo", false),
- timer:sleep(500),
-
- {ok, []} = couch_os_daemons:info([table]),
- {ok, Tab2} = couch_os_daemons:info(),
- etap:is(ets:tab2list(Tab2), [], "As table returns empty table."),
-
- etap:diag("Adding multiple daemons causes both to boot."),
- couch_config:set("os_daemons", "bar", daemon_cmd(), false),
- couch_config:set("os_daemons", "baz", daemon_cmd(), false),
- timer:sleep(500),
- {ok, Daemons} = couch_os_daemons:info([table]),
- lists:foreach(fun(D) ->
- check_daemon(D)
- end, Daemons),
-
- {ok, Tab3} = couch_os_daemons:info(),
- lists:foreach(fun(D) ->
- check_daemon(D)
- end, ets:tab2list(Tab3)),
-
- etap:diag("Removing one daemon leaves the other alive."),
- couch_config:delete("os_daemons", "bar", false),
- timer:sleep(500),
-
- {ok, [D2]} = couch_os_daemons:info([table]),
- check_daemon(D2, "baz"),
-
- % Check table version
- {ok, Tab4} = couch_os_daemons:info(),
- [T4] = ets:tab2list(Tab4),
- check_daemon(T4, "baz"),
-
- ok.
-
-check_daemon(D) ->
- check_daemon(D, D#daemon.name).
-
-check_daemon(D, Name) ->
- BaseName = "170-os-daemons.es",
- BaseLen = length(BaseName),
- CmdLen = length(D#daemon.cmd),
- CmdName = lists:sublist(D#daemon.cmd, CmdLen-BaseLen+1, BaseLen),
-
- etap:is(is_port(D#daemon.port), true, "Daemon port is a port."),
- etap:is(D#daemon.name, Name, "Daemon name was set correctly."),
- etap:is(CmdName, BaseName, "Command name was set correctly."),
- etap:isnt(D#daemon.kill, undefined, "Kill command was set."),
- etap:is(D#daemon.errors, [], "No errors occurred while booting."),
- etap:is(D#daemon.buf, [], "No extra data left in the buffer.").
diff --git a/test/etap/171-os-daemons-config.es b/test/etap/171-os-daemons-config.es
deleted file mode 100755
index 1f68ddc6..00000000
--- a/test/etap/171-os-daemons-config.es
+++ /dev/null
@@ -1,83 +0,0 @@
-#! /usr/bin/env escript
-
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
-filename() ->
- list_to_binary(test_util:source_file("test/etap/171-os-daemons-config.es")).
-
-read() ->
- case io:get_line('') of
- eof ->
- stop;
- Data ->
- couch_util:json_decode(Data)
- end.
-
-write(Mesg) ->
- Data = iolist_to_binary(couch_util:json_encode(Mesg)),
- io:format(binary_to_list(Data) ++ "\n", []).
-
-get_cfg(Section) ->
- write([<<"get">>, Section]),
- read().
-
-get_cfg(Section, Name) ->
- write([<<"get">>, Section, Name]),
- read().
-
-log(Mesg) ->
- write([<<"log">>, Mesg]).
-
-log(Mesg, Level) ->
- write([<<"log">>, Mesg, {[{<<"level">>, Level}]}]).
-
-test_get_cfg1() ->
- FileName = filename(),
- {[{<<"foo">>, FileName}]} = get_cfg(<<"os_daemons">>).
-
-test_get_cfg2() ->
- FileName = filename(),
- FileName = get_cfg(<<"os_daemons">>, <<"foo">>),
- <<"sequential">> = get_cfg(<<"uuids">>, <<"algorithm">>).
-
-test_get_unknown_cfg() ->
- {[]} = get_cfg(<<"aal;3p4">>),
- null = get_cfg(<<"aal;3p4">>, <<"313234kjhsdfl">>).
-
-test_log() ->
- log(<<"foobar!">>),
- log(<<"some stuff!">>, <<"debug">>),
- log(2),
- log(true),
- write([<<"log">>, <<"stuff">>, 2]),
- write([<<"log">>, 3, null]),
- write([<<"log">>, [1, 2], {[{<<"level">>, <<"debug">>}]}]),
- write([<<"log">>, <<"true">>, {[]}]).
-
-do_tests() ->
- test_get_cfg1(),
- test_get_cfg2(),
- test_get_unknown_cfg(),
- test_log(),
- loop(io:read("")).
-
-loop({ok, _}) ->
- loop(io:read(""));
-loop(eof) ->
- init:stop();
-loop({error, _Reason}) ->
- init:stop().
-
-main([]) ->
- test_util:init_code_path(),
- do_tests().
diff --git a/test/etap/171-os-daemons-config.t b/test/etap/171-os-daemons-config.t
deleted file mode 100755
index e9dc3f32..00000000
--- a/test/etap/171-os-daemons-config.t
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
--record(daemon, {
- port,
- name,
- cmd,
- kill,
- status=running,
- cfg_patterns=[],
- errors=[],
- buf=[]
-}).
-
-config_files() ->
- lists:map(fun test_util:build_file/1, [
- "etc/couchdb/default_dev.ini"
- ]).
-
-daemon_cmd() ->
- test_util:source_file("test/etap/171-os-daemons-config.es").
-
-main(_) ->
- test_util:init_code_path(),
-
- etap:plan(6),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail(Other)
- end,
- ok.
-
-test() ->
- couch_config:start_link(config_files()),
- couch_config:set("log", "level", "debug", false),
- couch_log:start_link(),
- couch_os_daemons:start_link(),
-
- % "foo" is a required name by this test.
- couch_config:set("os_daemons", "foo", daemon_cmd(), false),
- timer:sleep(1000),
-
- {ok, [D1]} = couch_os_daemons:info([table]),
- check_daemon(D1, "foo"),
-
- ok.
-
-check_daemon(D, Name) ->
- BaseName = "171-os-daemons-config.es",
- BaseLen = length(BaseName),
- CmdLen = length(D#daemon.cmd),
- CmdName = lists:sublist(D#daemon.cmd, CmdLen-BaseLen+1, BaseLen),
-
- etap:is(is_port(D#daemon.port), true, "Daemon port is a port."),
- etap:is(D#daemon.name, Name, "Daemon name was set correctly."),
- etap:is(CmdName, BaseName, "Command name was set correctly."),
- etap:isnt(D#daemon.kill, undefined, "Kill command was set."),
- etap:is(D#daemon.errors, [], "No errors occurred while booting."),
- etap:is(D#daemon.buf, [], "No extra data left in the buffer.").
diff --git a/test/etap/172-os-daemon-errors.3.sh b/test/etap/172-os-daemon-errors.3.sh
deleted file mode 100755
index f5a13684..00000000
--- a/test/etap/172-os-daemon-errors.3.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh -e
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may not
-# use this file except in compliance with the License. You may obtain a copy of
-# the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations under
-# the License.
-
-sleep 1
diff --git a/test/etap/172-os-daemon-errors.4.sh b/test/etap/172-os-daemon-errors.4.sh
deleted file mode 100755
index 5bc10e83..00000000
--- a/test/etap/172-os-daemon-errors.4.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh -e
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may not
-# use this file except in compliance with the License. You may obtain a copy of
-# the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations under
-# the License.
-
-sleep 2
diff --git a/test/etap/172-os-daemon-errors.t b/test/etap/172-os-daemon-errors.t
deleted file mode 100755
index bde5c6ff..00000000
--- a/test/etap/172-os-daemon-errors.t
+++ /dev/null
@@ -1,126 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
--record(daemon, {
- port,
- name,
- cmd,
- kill,
- status=running,
- cfg_patterns=[],
- errors=[],
- buf=[]
-}).
-
-config_files() ->
- lists:map(fun test_util:build_file/1, [
- "etc/couchdb/default_dev.ini"
- ]).
-
-bad_perms() ->
- test_util:source_file("test/etap/172-os-daemon-errors.1.sh").
-
-die_on_boot() ->
- test_util:source_file("test/etap/172-os-daemon-errors.2.sh").
-
-die_quickly() ->
- test_util:source_file("test/etap/172-os-daemon-errors.3.sh").
-
-can_reboot() ->
- test_util:source_file("test/etap/172-os-daemon-errors.4.sh").
-
-main(_) ->
- test_util:init_code_path(),
-
- etap:plan(36),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail(Other)
- end,
- ok.
-
-test() ->
- couch_config:start_link(config_files()),
- couch_os_daemons:start_link(),
-
- etap:diag("Daemon not executable."),
- test_halts("foo", bad_perms(), 1000),
-
- etap:diag("Daemon dies on boot."),
- test_halts("bar", die_on_boot(), 1000),
-
- etap:diag("Daemon dies quickly after boot."),
- test_halts("baz", die_quickly(), 4000),
-
- etap:diag("Daemon dies, but not quickly enough to be halted."),
- test_runs("bam", can_reboot()),
-
- ok.
-
-test_halts(Name, Cmd, Time) ->
- couch_config:set("os_daemons", Name, Cmd ++ " 2> /dev/null", false),
- timer:sleep(Time),
- {ok, [D]} = couch_os_daemons:info([table]),
- check_dead(D, Name, Cmd),
- couch_config:delete("os_daemons", Name, false).
-
-test_runs(Name, Cmd) ->
- couch_config:set("os_daemons", Name, Cmd, false),
-
- timer:sleep(1000),
- {ok, [D1]} = couch_os_daemons:info([table]),
- check_daemon(D1, Name, Cmd, 0),
-
- % Should reboot every two seconds. We're at 1s, so wait
- % utnil 3s to be in the middle of the next invocation's
- % life span.
- timer:sleep(2000),
- {ok, [D2]} = couch_os_daemons:info([table]),
- check_daemon(D2, Name, Cmd, 1),
-
- % If the kill command changed, that means we rebooted the process.
- etap:isnt(D1#daemon.kill, D2#daemon.kill, "Kill command changed.").
-
-check_dead(D, Name, Cmd) ->
- BaseName = filename:basename(Cmd) ++ " 2> /dev/null",
- BaseLen = length(BaseName),
- CmdLen = length(D#daemon.cmd),
- CmdName = lists:sublist(D#daemon.cmd, CmdLen-BaseLen+1, BaseLen),
-
- etap:is(is_port(D#daemon.port), true, "Daemon port is a port."),
- etap:is(D#daemon.name, Name, "Daemon name was set correctly."),
- etap:is(CmdName, BaseName, "Command name was set correctly."),
- etap:isnt(D#daemon.kill, undefined, "Kill command was set."),
- etap:is(D#daemon.status, halted, "Daemon has been halted."),
- etap:is(D#daemon.errors, nil, "Errors have been disabled."),
- etap:is(D#daemon.buf, nil, "Buffer has been switched off.").
-
-check_daemon(D, Name, Cmd, Errs) ->
- BaseName = filename:basename(Cmd),
- BaseLen = length(BaseName),
- CmdLen = length(D#daemon.cmd),
- CmdName = lists:sublist(D#daemon.cmd, CmdLen-BaseLen+1, BaseLen),
-
- etap:is(is_port(D#daemon.port), true, "Daemon port is a port."),
- etap:is(D#daemon.name, Name, "Daemon name was set correctly."),
- etap:is(CmdName, BaseName, "Command name was set correctly."),
- etap:isnt(D#daemon.kill, undefined, "Kill command was set."),
- etap:is(D#daemon.status, running, "Daemon still running."),
- etap:is(length(D#daemon.errors), Errs, "Found expected number of errors."),
- etap:is(D#daemon.buf, [], "No extra data left in the buffer.").
-
diff --git a/test/etap/173-os-daemon-cfg-register.t b/test/etap/173-os-daemon-cfg-register.t
deleted file mode 100755
index 71181aa2..00000000
--- a/test/etap/173-os-daemon-cfg-register.t
+++ /dev/null
@@ -1,93 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
--record(daemon, {
- port,
- name,
- cmd,
- kill,
- status=running,
- cfg_patterns=[],
- errors=[],
- buf=[]
-}).
-
-daemon_name() ->
- "wheee".
-
-daemon_cmd() ->
- test_util:build_file("test/etap/test_cfg_register").
-
-main(_) ->
- test_util:init_code_path(),
-
- etap:plan(27),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail(Other)
- end,
- ok.
-
-test() ->
- couch_config:start_link(test_util:config_files()),
- couch_os_daemons:start_link(),
-
- DaemonCmd = daemon_cmd() ++ " 2> /dev/null",
-
- etap:diag("Booting the daemon"),
- couch_config:set("os_daemons", daemon_name(), DaemonCmd, false),
- timer:sleep(1000),
- {ok, [D1]} = couch_os_daemons:info([table]),
- check_daemon(D1, running),
-
- etap:diag("Daemon restarts when section changes."),
- couch_config:set("s1", "k", "foo", false),
- timer:sleep(1000),
- {ok, [D2]} = couch_os_daemons:info([table]),
- check_daemon(D2, running),
- etap:isnt(D2#daemon.kill, D1#daemon.kill, "Kill command shows restart."),
-
- etap:diag("Daemon doesn't restart for ignored section key."),
- couch_config:set("s2", "k2", "baz", false),
- timer:sleep(1000),
- {ok, [D3]} = couch_os_daemons:info([table]),
- etap:is(D3, D2, "Same daemon info after ignored config change."),
-
- etap:diag("Daemon restarts for specific section/key pairs."),
- couch_config:set("s2", "k", "bingo", false),
- timer:sleep(1000),
- {ok, [D4]} = couch_os_daemons:info([table]),
- check_daemon(D4, running),
- etap:isnt(D4#daemon.kill, D3#daemon.kill, "Kill command changed again."),
-
- ok.
-
-check_daemon(D, Status) ->
- BaseName = filename:basename(daemon_cmd()) ++ " 2> /dev/null",
- BaseLen = length(BaseName),
- CmdLen = length(D#daemon.cmd),
- CmdName = lists:sublist(D#daemon.cmd, CmdLen-BaseLen+1, BaseLen),
-
- etap:is(is_port(D#daemon.port), true, "Daemon port is a port."),
- etap:is(D#daemon.name, daemon_name(), "Daemon name was set correctly."),
- etap:is(CmdName, BaseName, "Command name was set correctly."),
- etap:isnt(D#daemon.kill, undefined, "Kill command was set."),
- etap:is(D#daemon.status, Status, "Daemon status is correct."),
- etap:is(D#daemon.cfg_patterns, [{"s1"}, {"s2", "k"}], "Cfg patterns set"),
- etap:is(D#daemon.errors, [], "No errors have occurred."),
- etap:isnt(D#daemon.buf, nil, "Buffer is active.").
diff --git a/test/etap/180-http-proxy.ini b/test/etap/180-http-proxy.ini
deleted file mode 100644
index 3e2ba137..00000000
--- a/test/etap/180-http-proxy.ini
+++ /dev/null
@@ -1,20 +0,0 @@
-; Licensed to the Apache Software Foundation (ASF) under one
-; or more contributor license agreements. See the NOTICE file
-; distributed with this work for additional information
-; regarding copyright ownership. The ASF licenses this file
-; to you under the Apache License, Version 2.0 (the
-; "License"); you may not use this file except in compliance
-; with the License. You may obtain a copy of the License at
-;
-; http://www.apache.org/licenses/LICENSE-2.0
-;
-; Unless required by applicable law or agreed to in writing,
-; software distributed under the License is distributed on an
-; "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-; KIND, either express or implied. See the License for the
-; specific language governing permissions and limitations
-; under the License.
-
-; 49151 is IANA Reserved, let's assume no one is listening there
-[httpd_global_handlers]
-_error = {couch_httpd_proxy, handle_proxy_req, <<"http://127.0.0.1:49151/">>}
diff --git a/test/etap/180-http-proxy.t b/test/etap/180-http-proxy.t
deleted file mode 100755
index 41c77631..00000000
--- a/test/etap/180-http-proxy.t
+++ /dev/null
@@ -1,378 +0,0 @@
-#!/usr/bin/env escript
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
--record(req, {method=get, path="", headers=[], body="", opts=[]}).
-
-server() ->
- lists:concat([
- "http://127.0.0.1:",
- mochiweb_socket_server:get(couch_httpd, port),
- "/_test/"
- ]).
-
-proxy() ->
- "http://127.0.0.1:" ++ integer_to_list(test_web:get_port()) ++ "/".
-
-external() -> "https://www.google.com/".
-
-main(_) ->
- test_util:init_code_path(),
-
- etap:plan(61),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag("Test died abnormally: ~p", [Other]),
- etap:bail("Bad return value.")
- end,
- ok.
-
-check_request(Name, Req, Remote, Local) ->
- case Remote of
- no_remote -> ok;
- _ -> test_web:set_assert(Remote)
- end,
- Url = case proplists:lookup(url, Req#req.opts) of
- none -> server() ++ Req#req.path;
- {url, DestUrl} -> DestUrl
- end,
- Opts = [{headers_as_is, true} | Req#req.opts],
- Resp =ibrowse:send_req(
- Url, Req#req.headers, Req#req.method, Req#req.body, Opts
- ),
- %etap:diag("ibrowse response: ~p", [Resp]),
- case Local of
- no_local -> ok;
- _ -> etap:fun_is(Local, Resp, Name)
- end,
- case {Remote, Local} of
- {no_remote, _} ->
- ok;
- {_, no_local} ->
- ok;
- _ ->
- etap:is(test_web:check_last(), was_ok, Name ++ " - request handled")
- end,
- Resp.
-
-test() ->
- couch_server_sup:start_link([
- test_util:source_file("test/etap/180-http-proxy.ini") |
- test_util:config_files()
- ]),
- ibrowse:start(),
- crypto:start(),
-
- % start the test_web server on a random port
- test_web:start_link(),
- Url = lists:concat([
- "{couch_httpd_proxy, handle_proxy_req, <<\"http://127.0.0.1:",
- test_web:get_port(),
- "/\">>}"
- ]),
- couch_config:set("httpd_global_handlers", "_test", Url, false),
-
- % let couch_httpd restart
- timer:sleep(100),
-
- test_basic(),
- test_alternate_status(),
- test_trailing_slash(),
- test_passes_header(),
- test_passes_host_header(),
- test_passes_header_back(),
- test_rewrites_location_headers(),
- test_doesnt_rewrite_external_locations(),
- test_rewrites_relative_location(),
- test_uses_same_version(),
- test_passes_body(),
- test_passes_eof_body_back(),
- test_passes_chunked_body(),
- test_passes_chunked_body_back(),
-
- test_connect_error(),
-
- ok.
-
-test_basic() ->
- Remote = fun(Req) ->
- 'GET' = Req:get(method),
- "/" = Req:get(path),
- 0 = Req:get(body_length),
- <<>> = Req:recv_body(),
- {ok, {200, [{"Content-Type", "text/plain"}], "ok"}}
- end,
- Local = fun({ok, "200", _, "ok"}) -> true; (_) -> false end,
- check_request("Basic proxy test", #req{}, Remote, Local).
-
-test_alternate_status() ->
- Remote = fun(Req) ->
- "/alternate_status" = Req:get(path),
- {ok, {201, [], "ok"}}
- end,
- Local = fun({ok, "201", _, "ok"}) -> true; (_) -> false end,
- Req = #req{path="alternate_status"},
- check_request("Alternate status", Req, Remote, Local).
-
-test_trailing_slash() ->
- Remote = fun(Req) ->
- "/trailing_slash/" = Req:get(path),
- {ok, {200, [], "ok"}}
- end,
- Local = fun({ok, "200", _, "ok"}) -> true; (_) -> false end,
- Req = #req{path="trailing_slash/"},
- check_request("Trailing slash", Req, Remote, Local).
-
-test_passes_header() ->
- Remote = fun(Req) ->
- "/passes_header" = Req:get(path),
- "plankton" = Req:get_header_value("X-CouchDB-Ralph"),
- {ok, {200, [], "ok"}}
- end,
- Local = fun({ok, "200", _, "ok"}) -> true; (_) -> false end,
- Req = #req{
- path="passes_header",
- headers=[{"X-CouchDB-Ralph", "plankton"}]
- },
- check_request("Passes header", Req, Remote, Local).
-
-test_passes_host_header() ->
- Remote = fun(Req) ->
- "/passes_host_header" = Req:get(path),
- "www.google.com" = Req:get_header_value("Host"),
- {ok, {200, [], "ok"}}
- end,
- Local = fun({ok, "200", _, "ok"}) -> true; (_) -> false end,
- Req = #req{
- path="passes_host_header",
- headers=[{"Host", "www.google.com"}]
- },
- check_request("Passes host header", Req, Remote, Local).
-
-test_passes_header_back() ->
- Remote = fun(Req) ->
- "/passes_header_back" = Req:get(path),
- {ok, {200, [{"X-CouchDB-Plankton", "ralph"}], "ok"}}
- end,
- Local = fun
- ({ok, "200", Headers, "ok"}) ->
- lists:member({"X-CouchDB-Plankton", "ralph"}, Headers);
- (_) ->
- false
- end,
- Req = #req{path="passes_header_back"},
- check_request("Passes header back", Req, Remote, Local).
-
-test_rewrites_location_headers() ->
- etap:diag("Testing location header rewrites."),
- do_rewrite_tests([
- {"Location", proxy() ++ "foo/bar", server() ++ "foo/bar"},
- {"Content-Location", proxy() ++ "bing?q=2", server() ++ "bing?q=2"},
- {"Uri", proxy() ++ "zip#frag", server() ++ "zip#frag"},
- {"Destination", proxy(), server()}
- ]).
-
-test_doesnt_rewrite_external_locations() ->
- etap:diag("Testing no rewrite of external locations."),
- do_rewrite_tests([
- {"Location", external() ++ "search", external() ++ "search"},
- {"Content-Location", external() ++ "s?q=2", external() ++ "s?q=2"},
- {"Uri", external() ++ "f#f", external() ++ "f#f"},
- {"Destination", external() ++ "f?q=2#f", external() ++ "f?q=2#f"}
- ]).
-
-test_rewrites_relative_location() ->
- etap:diag("Testing relative rewrites."),
- do_rewrite_tests([
- {"Location", "/foo", server() ++ "foo"},
- {"Content-Location", "bar", server() ++ "bar"},
- {"Uri", "/zing?q=3", server() ++ "zing?q=3"},
- {"Destination", "bing?q=stuff#yay", server() ++ "bing?q=stuff#yay"}
- ]).
-
-do_rewrite_tests(Tests) ->
- lists:foreach(fun({Header, Location, Url}) ->
- do_rewrite_test(Header, Location, Url)
- end, Tests).
-
-do_rewrite_test(Header, Location, Url) ->
- Remote = fun(Req) ->
- "/rewrite_test" = Req:get(path),
- {ok, {302, [{Header, Location}], "ok"}}
- end,
- Local = fun
- ({ok, "302", Headers, "ok"}) ->
- etap:is(
- couch_util:get_value(Header, Headers),
- Url,
- "Header rewritten correctly."
- ),
- true;
- (_) ->
- false
- end,
- Req = #req{path="rewrite_test"},
- Label = "Rewrite test for ",
- check_request(Label ++ Header, Req, Remote, Local).
-
-test_uses_same_version() ->
- Remote = fun(Req) ->
- "/uses_same_version" = Req:get(path),
- {1, 0} = Req:get(version),
- {ok, {200, [], "ok"}}
- end,
- Local = fun({ok, "200", _, "ok"}) -> true; (_) -> false end,
- Req = #req{
- path="uses_same_version",
- opts=[{http_vsn, {1, 0}}]
- },
- check_request("Uses same version", Req, Remote, Local).
-
-test_passes_body() ->
- Remote = fun(Req) ->
- 'PUT' = Req:get(method),
- "/passes_body" = Req:get(path),
- <<"Hooray!">> = Req:recv_body(),
- {ok, {201, [], "ok"}}
- end,
- Local = fun({ok, "201", _, "ok"}) -> true; (_) -> false end,
- Req = #req{
- method=put,
- path="passes_body",
- body="Hooray!"
- },
- check_request("Passes body", Req, Remote, Local).
-
-test_passes_eof_body_back() ->
- BodyChunks = [<<"foo">>, <<"bar">>, <<"bazinga">>],
- Remote = fun(Req) ->
- 'GET' = Req:get(method),
- "/passes_eof_body" = Req:get(path),
- {raw, {200, [{"Connection", "close"}], BodyChunks}}
- end,
- Local = fun({ok, "200", _, "foobarbazinga"}) -> true; (_) -> false end,
- Req = #req{path="passes_eof_body"},
- check_request("Passes eof body", Req, Remote, Local).
-
-test_passes_chunked_body() ->
- BodyChunks = [<<"foo">>, <<"bar">>, <<"bazinga">>],
- Remote = fun(Req) ->
- 'POST' = Req:get(method),
- "/passes_chunked_body" = Req:get(path),
- RecvBody = fun
- ({Length, Chunk}, [Chunk | Rest]) ->
- Length = size(Chunk),
- Rest;
- ({0, []}, []) ->
- ok
- end,
- ok = Req:stream_body(1024*1024, RecvBody, BodyChunks),
- {ok, {201, [], "ok"}}
- end,
- Local = fun({ok, "201", _, "ok"}) -> true; (_) -> false end,
- Req = #req{
- method=post,
- path="passes_chunked_body",
- headers=[{"Transfer-Encoding", "chunked"}],
- body=mk_chunked_body(BodyChunks)
- },
- check_request("Passes chunked body", Req, Remote, Local).
-
-test_passes_chunked_body_back() ->
- Name = "Passes chunked body back",
- Remote = fun(Req) ->
- 'GET' = Req:get(method),
- "/passes_chunked_body_back" = Req:get(path),
- BodyChunks = [<<"foo">>, <<"bar">>, <<"bazinga">>],
- {chunked, {200, [{"Transfer-Encoding", "chunked"}], BodyChunks}}
- end,
- Req = #req{
- path="passes_chunked_body_back",
- opts=[{stream_to, self()}]
- },
-
- Resp = check_request(Name, Req, Remote, no_local),
-
- etap:fun_is(
- fun({ibrowse_req_id, _}) -> true; (_) -> false end,
- Resp,
- "Received an ibrowse request id."
- ),
- {_, ReqId} = Resp,
-
- % Grab headers from response
- receive
- {ibrowse_async_headers, ReqId, "200", Headers} ->
- etap:is(
- proplists:get_value("Transfer-Encoding", Headers),
- "chunked",
- "Response included the Transfer-Encoding: chunked header"
- ),
- ibrowse:stream_next(ReqId)
- after 1000 ->
- throw({error, timeout})
- end,
-
- % Check body received
- % TODO: When we upgrade to ibrowse >= 2.0.0 this check needs to
- % check that the chunks returned are what we sent from the
- % Remote test.
- etap:diag("TODO: UPGRADE IBROWSE"),
- etap:is(recv_body(ReqId, []), <<"foobarbazinga">>, "Decoded chunked body."),
-
- % Check test_web server.
- etap:is(test_web:check_last(), was_ok, Name ++ " - request handled").
-
-test_connect_error() ->
- Local = fun({ok, "500", _Headers, _Body}) -> true; (_) -> false end,
- Url = lists:concat([
- "http://127.0.0.1:",
- mochiweb_socket_server:get(couch_httpd, port),
- "/_error"
- ]),
- Req = #req{opts=[{url, Url}]},
- check_request("Connect error", Req, no_remote, Local).
-
-
-mk_chunked_body(Chunks) ->
- mk_chunked_body(Chunks, []).
-
-mk_chunked_body([], Acc) ->
- iolist_to_binary(lists:reverse(Acc, "0\r\n\r\n"));
-mk_chunked_body([Chunk | Rest], Acc) ->
- Size = to_hex(size(Chunk)),
- mk_chunked_body(Rest, ["\r\n", Chunk, "\r\n", Size | Acc]).
-
-to_hex(Val) ->
- to_hex(Val, []).
-
-to_hex(0, Acc) ->
- Acc;
-to_hex(Val, Acc) ->
- to_hex(Val div 16, [hex_char(Val rem 16) | Acc]).
-
-hex_char(V) when V < 10 -> $0 + V;
-hex_char(V) -> $A + V - 10.
-
-recv_body(ReqId, Acc) ->
- receive
- {ibrowse_async_response, ReqId, Data} ->
- recv_body(ReqId, [Data | Acc]);
- {ibrowse_async_response_end, ReqId} ->
- iolist_to_binary(lists:reverse(Acc));
- Else ->
- throw({error, unexpected_mesg, Else})
- after 5000 ->
- throw({error, timeout})
- end.
diff --git a/test/etap/190-oauth.t b/test/etap/190-oauth.t
deleted file mode 100755
index 09922049..00000000
--- a/test/etap/190-oauth.t
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/usr/bin/env escript
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
-main(_) ->
- test_util:init_code_path(),
- etap:plan(1),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail(Other)
- end,
- ok.
-
-test() ->
- etap:is(
- oauth_uri:params_from_string("realm=http://localhost:5984"),
- [{"realm","http://localhost:5984"}],
- "decode should handle non-percent encoded input."),
- ok.
diff --git a/test/etap/200-view-group-no-db-leaks.t b/test/etap/200-view-group-no-db-leaks.t
deleted file mode 100755
index 9c77f1a8..00000000
--- a/test/etap/200-view-group-no-db-leaks.t
+++ /dev/null
@@ -1,262 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
--record(user_ctx, {
- name = null,
- roles = [],
- handler
-}).
-
--define(LATEST_DISK_VERSION, 5).
-
--record(db_header,
- {disk_version = ?LATEST_DISK_VERSION,
- update_seq = 0,
- unused = 0,
- fulldocinfo_by_id_btree_state = nil,
- docinfo_by_seq_btree_state = nil,
- local_docs_btree_state = nil,
- purge_seq = 0,
- purged_docs = nil,
- security_ptr = nil,
- revs_limit = 1000
-}).
-
--record(db, {
- main_pid = nil,
- update_pid = nil,
- compactor_pid = nil,
- instance_start_time, % number of microsecs since jan 1 1970 as a binary string
- fd,
- fd_ref_counter,
- header = #db_header{},
- committed_update_seq,
- fulldocinfo_by_id_btree,
- docinfo_by_seq_btree,
- local_docs_btree,
- update_seq,
- name,
- filepath,
- validate_doc_funs = [],
- security = [],
- security_ptr = nil,
- user_ctx = #user_ctx{},
- waiting_delayed_commit = nil,
- revs_limit = 1000,
- fsync_options = [],
- is_sys_db = false
-}).
-
-test_db_name() -> <<"couch_test_view_group_db_leaks">>.
-ddoc_name() -> <<"foo">>.
-
-main(_) ->
- test_util:init_code_path(),
-
- etap:plan(18),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail(Other)
- end,
- ok.
-
-test() ->
- couch_server_sup:start_link(test_util:config_files()),
- timer:sleep(1000),
- put(addr, couch_config:get("httpd", "bind_address", "127.0.0.1")),
- put(port, integer_to_list(mochiweb_socket_server:get(couch_httpd, port))),
- application:start(inets),
-
- delete_db(),
- create_db(),
-
- create_docs(),
- create_design_doc(),
-
- ViewGroup = couch_view:get_group_server(
- test_db_name(), <<"_design/", (ddoc_name())/binary>>),
- etap:is(is_pid(ViewGroup), true, "got view group pid"),
- etap:is(is_process_alive(ViewGroup), true, "view group pid is alive"),
-
- query_view(),
- check_db_ref_count(),
- etap:is(is_process_alive(ViewGroup), true, "view group pid is alive"),
-
- create_new_doc(<<"doc1000">>),
- query_view(),
- check_db_ref_count(),
- etap:is(is_process_alive(ViewGroup), true, "view group pid is alive"),
-
- Ref1 = get_db_ref_counter(),
- compact_db(),
- check_db_ref_count(),
- Ref2 = get_db_ref_counter(),
- etap:isnt(Ref1, Ref2, "DB ref counter changed"),
- etap:is(false, is_process_alive(Ref1), "old DB ref counter is not alive"),
- etap:is(is_process_alive(ViewGroup), true, "view group pid is alive"),
-
- compact_view_group(),
- check_db_ref_count(),
- Ref3 = get_db_ref_counter(),
- etap:is(Ref3, Ref2, "DB ref counter didn't change"),
- etap:is(is_process_alive(ViewGroup), true, "view group pid is alive"),
-
- create_new_doc(<<"doc1001">>),
- query_view(),
- check_db_ref_count(),
- etap:is(is_process_alive(ViewGroup), true, "view group pid is alive"),
-
- MonRef = erlang:monitor(process, ViewGroup),
- ok = couch_server:delete(test_db_name(), []),
- receive
- {'DOWN', MonRef, _, _, _} ->
- etap:diag("view group is dead after DB deletion")
- after 5000 ->
- etap:bail("view group did not die after DB deletion")
- end,
-
- ok = timer:sleep(1000),
- delete_db(),
- couch_server_sup:stop(),
- ok.
-
-admin_user_ctx() ->
- {user_ctx, #user_ctx{roles=[<<"_admin">>]}}.
-
-create_db() ->
- {ok, Db} = couch_db:create(test_db_name(), [admin_user_ctx()]),
- ok = couch_db:close(Db).
-
-delete_db() ->
- couch_server:delete(test_db_name(), [admin_user_ctx()]).
-
-compact_db() ->
- {ok, Db} = couch_db:open_int(test_db_name(), []),
- ok = couch_db:start_compact(Db),
- ok = couch_db:close(Db),
- wait_db_compact_done(10).
-
-wait_db_compact_done(0) ->
- etap:bail("DB compaction failed to finish.");
-wait_db_compact_done(N) ->
- {ok, Db} = couch_db:open_int(test_db_name(), []),
- ok = couch_db:close(Db),
- case is_pid(Db#db.compactor_pid) of
- false ->
- ok;
- true ->
- ok = timer:sleep(500),
- wait_db_compact_done(N - 1)
- end.
-
-compact_view_group() ->
- ok = couch_view_compactor:start_compact(test_db_name(), ddoc_name()),
- wait_view_compact_done(10).
-
-wait_view_compact_done(0) ->
- etap:bail("View group compaction failed to finish.");
-wait_view_compact_done(N) ->
- {ok, {{_, Code, _}, _Headers, Body}} = http:request(
- get,
- {db_url() ++ "/_design/" ++ binary_to_list(ddoc_name()) ++ "/_info", []},
- [],
- [{sync, true}]),
- case Code of
- 200 -> ok;
- _ -> etap:bail("Invalid view group info.")
- end,
- {Info} = couch_util:json_decode(Body),
- {IndexInfo} = couch_util:get_value(<<"view_index">>, Info),
- CompactRunning = couch_util:get_value(<<"compact_running">>, IndexInfo),
- case CompactRunning of
- false ->
- ok;
- true ->
- ok = timer:sleep(500),
- wait_view_compact_done(N - 1)
- end.
-
-get_db_ref_counter() ->
- {ok, #db{fd_ref_counter = Ref} = Db} = couch_db:open_int(test_db_name(), []),
- ok = couch_db:close(Db),
- Ref.
-
-check_db_ref_count() ->
- {ok, #db{fd_ref_counter = Ref} = Db} = couch_db:open_int(test_db_name(), []),
- ok = couch_db:close(Db),
- etap:is(couch_ref_counter:count(Ref), 2,
- "DB ref counter is only held by couch_db and couch_db_updater"),
- ok.
-
-create_docs() ->
- {ok, Db} = couch_db:open(test_db_name(), [admin_user_ctx()]),
- Doc1 = couch_doc:from_json_obj({[
- {<<"_id">>, <<"doc1">>},
- {<<"value">>, 1}
- ]}),
- Doc2 = couch_doc:from_json_obj({[
- {<<"_id">>, <<"doc2">>},
- {<<"value">>, 2}
-
- ]}),
- Doc3 = couch_doc:from_json_obj({[
- {<<"_id">>, <<"doc3">>},
- {<<"value">>, 3}
- ]}),
- {ok, _} = couch_db:update_docs(Db, [Doc1, Doc2, Doc3]),
- couch_db:ensure_full_commit(Db),
- couch_db:close(Db).
-
-create_design_doc() ->
- {ok, Db} = couch_db:open(test_db_name(), [admin_user_ctx()]),
- DDoc = couch_doc:from_json_obj({[
- {<<"_id">>, <<"_design/", (ddoc_name())/binary>>},
- {<<"language">>, <<"javascript">>},
- {<<"views">>, {[
- {<<"bar">>, {[
- {<<"map">>, <<"function(doc) { emit(doc._id, null); }">>}
- ]}}
- ]}}
- ]}),
- {ok, _} = couch_db:update_docs(Db, [DDoc]),
- couch_db:ensure_full_commit(Db),
- couch_db:close(Db).
-
-create_new_doc(Id) ->
- {ok, Db} = couch_db:open(test_db_name(), [admin_user_ctx()]),
- Doc666 = couch_doc:from_json_obj({[
- {<<"_id">>, Id},
- {<<"value">>, 999}
- ]}),
- {ok, _} = couch_db:update_docs(Db, [Doc666]),
- couch_db:ensure_full_commit(Db),
- couch_db:close(Db).
-
-db_url() ->
- "http://" ++ get(addr) ++ ":" ++ get(port) ++ "/" ++
- binary_to_list(test_db_name()).
-
-query_view() ->
- {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
- get,
- {db_url() ++ "/_design/" ++ binary_to_list(ddoc_name()) ++
- "/_view/bar", []},
- [],
- [{sync, true}]),
- etap:is(Code, 200, "got view response"),
- ok.
diff --git a/test/etap/Makefile.am b/test/etap/Makefile.am
deleted file mode 100644
index ce52d430..00000000
--- a/test/etap/Makefile.am
+++ /dev/null
@@ -1,89 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-noinst_SCRIPTS = run
-noinst_DATA = test_util.beam test_web.beam
-
-noinst_PROGRAMS = test_cfg_register
-test_cfg_register_SOURCES = test_cfg_register.c
-test_cfg_register_CFLAGS = -D_BSD_SOURCE
-
-%.beam: %.erl
- $(ERLC) $<
-
-run: run.tpl
- sed -e "s|%abs_top_srcdir%|@abs_top_srcdir@|g" \
- -e "s|%abs_top_builddir%|@abs_top_builddir@|g" > \
- $@ < $<
- chmod +x $@
-
-CLEANFILES = run *.beam
-DISTCLEANFILES = temp.*
-
-EXTRA_DIST = \
- run.tpl \
- test_web.erl \
- random_port.ini \
- 001-load.t \
- 002-icu-driver.t \
- 010-file-basics.t \
- 011-file-headers.t \
- 020-btree-basics.t \
- 021-btree-reductions.t \
- 030-doc-from-json.t \
- 031-doc-to-json.t \
- 040-util.t \
- 041-uuid-gen-seq.ini \
- 041-uuid-gen-utc.ini \
- 041-uuid-gen.t \
- 050-stream.t \
- 060-kt-merging.t \
- 061-kt-missing-leaves.t \
- 062-kt-remove-leaves.t \
- 063-kt-get-leaves.t \
- 064-kt-counting.t \
- 065-kt-stemming.t \
- 070-couch-db.t \
- 080-config-get-set.t \
- 081-config-override.1.ini \
- 081-config-override.2.ini \
- 081-config-override.t \
- 082-config-register.t \
- 083-config-no-files.t \
- 090-task-status.t \
- 100-ref-counter.t \
- 110-replication-httpc.t \
- 111-replication-changes-feed.t \
- 112-replication-missing-revs.t \
- 113-replication-attachment-comp.t \
- 120-stats-collect.t \
- 121-stats-aggregates.cfg \
- 121-stats-aggregates.ini \
- 121-stats-aggregates.t \
- 130-attachments-md5.t \
- 140-attachment-comp.t \
- 150-invalid-view-seq.t \
- 160-vhosts.t \
- 170-os-daemons.es \
- 170-os-daemons.t \
- 171-os-daemons-config.es \
- 171-os-daemons-config.t \
- 172-os-daemon-errors.1.sh \
- 172-os-daemon-errors.2.sh \
- 172-os-daemon-errors.3.sh \
- 172-os-daemon-errors.4.sh \
- 172-os-daemon-errors.t \
- 173-os-daemon-cfg-register.t \
- 180-http-proxy.ini \
- 180-http-proxy.t \
- 190-oauth.t \
- 200-view-group-no-db-leaks.t
diff --git a/test/javascript/Makefile.am b/test/javascript/Makefile.am
deleted file mode 100644
index 71f9ae62..00000000
--- a/test/javascript/Makefile.am
+++ /dev/null
@@ -1,25 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-EXTRA_DIST = \
- cli_runner.js \
- couch_http.js \
- run.tpl
-
-noinst_SCRIPTS = run
-CLEANFILES = run
-
-run: run.tpl
- sed -e "s|%abs_top_srcdir%|$(abs_top_srcdir)|" \
- -e "s|%abs_top_builddir%|$(abs_top_builddir)|" \
- < $< > $@
- chmod +x $@
diff --git a/test/view_server/Makefile.am b/test/view_server/Makefile.am
deleted file mode 100644
index 11e7feb4..00000000
--- a/test/view_server/Makefile.am
+++ /dev/null
@@ -1,15 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-EXTRA_DIST = \
- query_server_spec.rb \
- run_native_process.es
diff --git a/utils/Makefile.am b/utils/Makefile.am
deleted file mode 100644
index 379c1eb0..00000000
--- a/utils/Makefile.am
+++ /dev/null
@@ -1,42 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-noinst_SCRIPTS = run
-
-CLEANFILES = $(noinst_SCRIPTS)
-
-transform = @program_transform_name@
-couchdb_command_name = `echo couchdb | sed '$(transform)'`
-
-run: ../bin/couchdb.tpl
- sed -e "s|%ERL%|$(ERL)|g" \
- -e "s|%ICU_CONFIG%|$(ICU_CONFIG)|g" \
- -e "s|%bindir%|$(abs_top_builddir)/bin|g" \
- -e "s|%defaultini%|default_dev.ini|g" \
- -e "s|%localini%|local_dev.ini|g" \
- -e "s|%localerlanglibdir%|foo \
- -pa $(abs_top_builddir)\/src\/couchdb \
- -pa $(abs_top_builddir)\/src\/erlang-oauth \
- -pa $(abs_top_builddir)\/src\/ibrowse \
- -pa $(abs_top_builddir)\/src\/mochiweb|g" \
- -e "s|%localconfdir%|$(abs_top_builddir)/etc/couchdb|g" \
- -e "s|%localstatelogdir%|$(abs_top_builddir)/tmp/log|g" \
- -e "s|%localstatelibdir%|$(abs_top_builddir)/tmp/lib|g" \
- -e "s|%localstatedir%|$(abs_top_builddir)/tmp|g" \
- -e "s|%bug_uri%|@bug_uri@|g" \
- -e "s|%package_author_address%|@package_author_address@|g" \
- -e "s|%package_author_name%|@package_author_name@|g" \
- -e "s|%package_name%|@package_name@|g" \
- -e "s|%version%|@version@|g" \
- -e "s|%couchdb_command_name%|$(couchdb_command_name)|g" > \
- $@ < $<
- chmod +x $@
diff --git a/var/Makefile.am b/var/Makefile.am
deleted file mode 100644
index 901ab2b7..00000000
--- a/var/Makefile.am
+++ /dev/null
@@ -1,23 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-install-data-hook:
- if test ! "$(mkdir_p)" = ""; then \
- $(mkdir_p) "$(DESTDIR)$(localstatelibdir)"; \
- $(mkdir_p) "$(DESTDIR)$(localstatelogdir)"; \
- $(mkdir_p) "$(DESTDIR)$(localstaterundir)"; \
- else \
- echo "WARNING: You may have to create these directories by hand."; \
- mkdir -p "$(DESTDIR)$(localstatelibdir)"; \
- mkdir -p "$(DESTDIR)$(localstatelogdir)"; \
- mkdir -p "$(DESTDIR)$(localstaterundir)"; \
- fi