diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ce891c9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +/node_modules +/tmp +build +docs/*.json +docs/*.html +cscope.in.out +cscope.po.out +cscope.out +smf/manifests/bapi.xml diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..14e5f4b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "deps/jsstyle"] + path = deps/jsstyle + url = https://github.com/davepacheco/jsstyle.git diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..14e2f77 --- /dev/null +++ b/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ede6a48 --- /dev/null +++ b/Makefile @@ -0,0 +1,81 @@ +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +# +# Copyright (c) 2014, Joyent, Inc. +# + +# +# Makefile: basic Makefile for template API service +# +# This Makefile is a template for new repos. It contains only repo-specific +# logic and uses included makefiles to supply common targets (javascriptlint, +# jsstyle, restdown, etc.), which are used by other repos as well. You may well +# need to rewrite most of this file, but you shouldn't need to touch the +# included makefiles. +# +# If you find yourself adding support for new targets that could be useful for +# other projects too, you should add these to the original versions of the +# included Makefiles (in eng.git) so that other teams can use them too. +# + +# +# Tools +# +TAP := ./node_modules/.bin/tap + +# +# Files +# +DOC_FILES = index.md boilerplateapi.md +JS_FILES := $(shell ls *.js) $(shell find lib test -name '*.js') +JSON_FILES = package.json +JSL_CONF_NODE = tools/jsl.node.conf +JSL_FILES_NODE = $(JS_FILES) +JSSTYLE_FILES = $(JS_FILES) +JSSTYLE_FLAGS = -f tools/jsstyle.conf +REPO_MODULES = src/node-dummy +SMF_MANIFESTS_IN = smf/manifests/bapi.xml.in + +NODE_PREBUILT_VERSION=v0.8.28 + +ifeq ($(shell uname -s),SunOS) + NODE_PREBUILT_CC_VERSION=4.6.2 + NODE_PREBUILT_TAG=zone +endif + +include ./tools/mk/Makefile.defs +ifeq ($(shell uname -s),SunOS) + include ./tools/mk/Makefile.node_prebuilt.defs +else + include ./tools/mk/Makefile.node.defs +endif +include ./tools/mk/Makefile.smf.defs + +# +# Repo-specific targets +# +.PHONY: all +all: $(SMF_MANIFESTS) | $(TAP) $(REPO_DEPS) + $(NPM) rebuild + +$(TAP): | $(NPM_EXEC) + $(NPM) install + +CLEAN_FILES += $(TAP) ./node_modules/tap + +.PHONY: test +test: $(TAP) + TAP=1 $(TAP) test/*.test.js + +include ./tools/mk/Makefile.deps +ifeq ($(shell uname -s),SunOS) + include ./tools/mk/Makefile.node_prebuilt.targ +else + include ./tools/mk/Makefile.node.targ +endif +include ./tools/mk/Makefile.smf.targ +include ./tools/mk/Makefile.targ diff --git a/README.md b/README.md new file mode 100644 index 0000000..7965bac --- /dev/null +++ b/README.md @@ -0,0 +1,60 @@ + + + + +# node-sdc-changefeed + +Provides support for publishing and listening to change feeds in SmartDataCenter +/ Triton via Node.js libraries and a CLI. + + +## Installation + +``` +$ npm install node-sdc-changefeed # use -g if you'd like the CLI portion +``` + + +## Development + +Before committing be sure to, at least run: + +``` +$ make check # lint and style checks +$ make test # run tests +``` + + +## Test + +Simple tests can be run using: + +``` +$ make test +``` + +If you'd like to integration test against CoaL: + +``` +$ make test-integration-in-coal +``` + + +## Documentation + +[Detailed documentation is located at docs/index.md](docs/index.md). + +See [RFD 0005 Triton Change Feed Support](https://github.com/joyent/rfd/blob/master/rfd/0005/README.md) +for current design and architecture decisions. + +## License + +"node-sdc-changefeed" is licensed under the +[Mozilla Public License version 2.0](http://mozilla.org/MPL/2.0/). +See the file LICENSE. diff --git a/deps/jsstyle b/deps/jsstyle new file mode 160000 index 0000000..194dde7 --- /dev/null +++ b/deps/jsstyle @@ -0,0 +1 @@ +Subproject commit 194dde793f58b707b0416a106e1f7679795e50df diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..2e9901f --- /dev/null +++ b/docs/index.md @@ -0,0 +1,17 @@ +--- +title: node-sdc-changefeed documentation +markdown2extras: tables, code-friendly +apisections: +--- + + + + +Please see [Joyent Engineering Guidelines](https://github.com/joyent/eng/blob/master/docs/index.md) +for a general set of guidelines that apply to all Joyent repositories. diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..81111d7 --- /dev/null +++ b/lib/index.js @@ -0,0 +1,15 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* + * Copyright (c) 2014, Joyent, Inc. + */ + +/* + * A brief overview of this source file: what is its purpose. + */ + +// TODO: put stuff here diff --git a/package.json b/package.json new file mode 100644 index 0000000..b8f96cb --- /dev/null +++ b/package.json @@ -0,0 +1,21 @@ +{ + "name": "node-sdc-changefeed", + "description": "SmartDataCenter Change Feed Modules", + "version": "1.0.0", + "author": "Joyent (joyent.com)", + "private": true, + "dependencies": { + "restify": "2.2.1", + "node-uuid": "1.4.0", + "filed": "0.0.5", + "bunyan": "0.18.2" + }, + "devDependencies": { + "tap": "0.4.0" + }, + "scripts": { + "start": "node ./server.js", + "test": "./node_modules/.bin/tap test/*.test.js" + }, + "license": "MPL-2.0" +} diff --git a/test/api.test.js b/test/api.test.js new file mode 100644 index 0000000..8ac6a1b --- /dev/null +++ b/test/api.test.js @@ -0,0 +1,19 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* + * Copyright (c) 2014, Joyent, Inc. + */ + +/* Test the Boilerplate API endpoints */ + +var test = require('tap').test; + + +test('douglas adams', function (t) { + t.ok(42, 'the answer to life the universe and everything'); + t.end(); +}); diff --git a/tools/bashstyle b/tools/bashstyle new file mode 100644 index 0000000..3e8052e --- /dev/null +++ b/tools/bashstyle @@ -0,0 +1,164 @@ +#!/usr/bin/env node +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* + * Copyright (c) 2014, Joyent, Inc. + */ + +/* + * bashstyle: check bash scripts for adherence to style guidelines, including: + * + * o no lines longer than 80 characters + * o file does not end with a blank line + * o Do not use 'local' and var initialization *using a subshell* in the + * same statement. See + * + * for why not. Arguably this belongs in a separate 'bashlint'. + * + * Future enhancements could include: + * o indents consistent with respect to tabs, spaces + * o indents consistently sized (all are some multiple of the smallest + * indent, which must be a tab or 4 or 8 spaces) + */ + +var VERSION = '2.0.0'; + +var mod_assert = require('assert'); +var mod_fs = require('fs'); + +var nerrors = 0; + +main(); +process.exit(0); + +function main() +{ + var files = process.argv.slice(2); + + if (files.length === 0) { + console.error('usage: %s file1 [...]', + process.argv.slice(0, 2).join(' ')); + process.exit(2); + } + + files.forEach(checkFile); + + if (nerrors != 0) + process.exit(1); +} + +function checkFile(filename) +{ + var text = mod_fs.readFileSync(filename, 'utf-8'); + var lines = text.split('\n'); + var i; + var styled = false; + var styleStart; + + mod_assert.ok(lines.length > 0); + + /* + * Expand tabs in each line and check for long lines. + */ + for (i = 1; i <= lines.length; i++) { + var line = expandTabs(lines[i - 1]); + + if (i > 1 && lines[i-2].match(/# BASHSTYLED/)) { + continue; + } + + if (line.match(/# BEGIN BASHSTYLED/)) { + styleStart = i; + styled = true; + } + + if (line.match(/# END BASHSTYLED/)) { + if (styled != true) { + nerrors++; + console.log('%s: %d: END BASHSTYLED w/o corresponding BEGIN', + filename, i); + } + styled = false; + } + + if (!styled && line.match(/^\s*local\s+(\w+)\s*=.*\$\(/)) { + nerrors++; + var m = line.match(/^\s*local\s+(\w+)\s*=/); + console.log('%s: %d: declaring and setting a "local" ' + + 'var in the same statement ' + + 'ignores a subshell return code ' + + ': ' + + 'local %s=...', + filename, i, m[1]); + } + + // Regexplanation: non-[, [, space (contents) space, ], non-] + // groups before and after brackets to ease search/replace. + if (!styled && line.match(/(^|[^\[])\[(\s.+\s)\]([^\]])/)) { + nerrors++; + console.log('%s: %d: prefer [[ to [ for tests.', filename, i); + } + + if (!styled && line.length > 80) { + nerrors++; + console.log('%s: %d: line exceeds 80 columns', + filename, i); + } + } + + if (styled) { + nerrors++; + console.log('%s: %d: BEGIN BASHSTYLED that does not END', + filename, styleStart); + } + + + /* + * No sane editor lets you save a file without a newline at the very end. + */ + if (lines[lines.length - 1].length !== 0) { + nerrors++; + console.log('%s: %d: file does not end with newline', + filename, lines.length); + } + + /* + * Since the file will always end with a newline, the last entry of + * "lines" will actually be blank. + */ + if (lines.length > 1 && lines[lines.length - 2].length === 0) { + nerrors++; + console.log('%s: %d: file ends with a blank line', + filename, lines.length - 1); + } +} + +function expandTabs(text) +{ + var out = ''; + var col = 0; + var j, k; + + for (j = 0; j < text.length; j++) { + if (text[j] != '\t') { + out += text[j]; + col++; + continue; + } + + k = 8 - (col % 8); + col += k; + + do { + out += ' '; + } while (--k > 0); + + col += k; + } + + return (out); +} diff --git a/tools/jsl.node.conf b/tools/jsl.node.conf new file mode 100644 index 0000000..c44e8ee --- /dev/null +++ b/tools/jsl.node.conf @@ -0,0 +1,139 @@ +# +# Configuration File for JavaScript Lint +# +# This configuration file can be used to lint a collection of scripts, or to enable +# or disable warnings for scripts that are linted via the command line. +# + +### Warnings +# Enable or disable warnings based on requirements. +# Use "+WarningName" to display or "-WarningName" to suppress. +# ++ambiguous_else_stmt # the else statement could be matched with one of multiple if statements (use curly braces to indicate intent ++ambiguous_nested_stmt # block statements containing block statements should use curly braces to resolve ambiguity ++ambiguous_newline # unexpected end of line; it is ambiguous whether these lines are part of the same statement ++anon_no_return_value # anonymous function does not always return value ++assign_to_function_call # assignment to a function call +-block_without_braces # block statement without curly braces ++comma_separated_stmts # multiple statements separated by commas (use semicolons?) ++comparison_type_conv # comparisons against null, 0, true, false, or an empty string allowing implicit type conversion (use === or !==) ++default_not_at_end # the default case is not at the end of the switch statement ++dup_option_explicit # duplicate "option explicit" control comment ++duplicate_case_in_switch # duplicate case in switch statement ++duplicate_formal # duplicate formal argument {name} ++empty_statement # empty statement or extra semicolon ++identifier_hides_another # identifer {name} hides an identifier in a parent scope +-inc_dec_within_stmt # increment (++) and decrement (--) operators used as part of greater statement ++incorrect_version # Expected /*jsl:content-type*/ control comment. The script was parsed with the wrong version. ++invalid_fallthru # unexpected "fallthru" control comment ++invalid_pass # unexpected "pass" control comment ++jsl_cc_not_understood # couldn't understand control comment using /*jsl:keyword*/ syntax ++leading_decimal_point # leading decimal point may indicate a number or an object member ++legacy_cc_not_understood # couldn't understand control comment using /*@keyword@*/ syntax ++meaningless_block # meaningless block; curly braces have no impact ++mismatch_ctrl_comments # mismatched control comment; "ignore" and "end" control comments must have a one-to-one correspondence ++misplaced_regex # regular expressions should be preceded by a left parenthesis, assignment, colon, or comma ++missing_break # missing break statement ++missing_break_for_last_case # missing break statement for last case in switch ++missing_default_case # missing default case in switch statement ++missing_option_explicit # the "option explicit" control comment is missing ++missing_semicolon # missing semicolon ++missing_semicolon_for_lambda # missing semicolon for lambda assignment ++multiple_plus_minus # unknown order of operations for successive plus (e.g. x+++y) or minus (e.g. x---y) signs ++nested_comment # nested comment ++no_return_value # function {name} does not always return a value ++octal_number # leading zeros make an octal number ++parseint_missing_radix # parseInt missing radix parameter ++partial_option_explicit # the "option explicit" control comment, if used, must be in the first script tag ++redeclared_var # redeclaration of {name} ++trailing_comma_in_array # extra comma is not recommended in array initializers ++trailing_decimal_point # trailing decimal point may indicate a number or an object member ++undeclared_identifier # undeclared identifier: {name} ++unreachable_code # unreachable code +-unreferenced_argument # argument declared but never referenced: {name} +-unreferenced_function # function is declared but never referenced: {name} ++unreferenced_variable # variable is declared but never referenced: {name} ++unsupported_version # JavaScript {version} is not supported ++use_of_label # use of label ++useless_assign # useless assignment ++useless_comparison # useless comparison; comparing identical expressions +-useless_quotes # the quotation marks are unnecessary ++useless_void # use of the void type may be unnecessary (void is always undefined) ++var_hides_arg # variable {name} hides argument ++want_assign_or_call # expected an assignment or function call ++with_statement # with statement hides undeclared variables; use temporary variable instead + + +### Output format +# Customize the format of the error message. +# __FILE__ indicates current file path +# __FILENAME__ indicates current file name +# __LINE__ indicates current line +# __COL__ indicates current column +# __ERROR__ indicates error message (__ERROR_PREFIX__: __ERROR_MSG__) +# __ERROR_NAME__ indicates error name (used in configuration file) +# __ERROR_PREFIX__ indicates error prefix +# __ERROR_MSG__ indicates error message +# +# For machine-friendly output, the output format can be prefixed with +# "encode:". If specified, all items will be encoded with C-slashes. +# +# Visual Studio syntax (default): ++output-format __FILE__(__LINE__): __ERROR__ +# Alternative syntax: +#+output-format __FILE__:__LINE__: __ERROR__ + + +### Context +# Show the in-line position of the error. +# Use "+context" to display or "-context" to suppress. +# ++context + + +### Control Comments +# Both JavaScript Lint and the JScript interpreter confuse each other with the syntax for +# the /*@keyword@*/ control comments and JScript conditional comments. (The latter is +# enabled in JScript with @cc_on@). The /*jsl:keyword*/ syntax is preferred for this reason, +# although legacy control comments are enabled by default for backward compatibility. +# +-legacy_control_comments + + +### Defining identifiers +# By default, "option explicit" is enabled on a per-file basis. +# To enable this for all files, use "+always_use_option_explicit" +-always_use_option_explicit + +# Define certain identifiers of which the lint is not aware. +# (Use this in conjunction with the "undeclared identifier" warning.) +# +# Common uses for webpages might be: ++define __dirname ++define clearInterval ++define clearTimeout ++define console ++define exports ++define global ++define module ++define process ++define require ++define setInterval ++define setImmediate ++define setTimeout ++define Buffer ++define JSON ++define Math + +### JavaScript Version +# To change the default JavaScript version: +#+default-type text/javascript;version=1.5 +#+default-type text/javascript;e4x=1 + +### Files +# Specify which files to lint +# Use "+recurse" to enable recursion (disabled by default). +# To add a set of files, use "+process FileName", "+process Folder\Path\*.js", +# or "+process Folder\Path\*.htm". +# + diff --git a/tools/jsl.web.conf b/tools/jsl.web.conf new file mode 100644 index 0000000..b135000 --- /dev/null +++ b/tools/jsl.web.conf @@ -0,0 +1,137 @@ +# +# Configuration File for JavaScript Lint +# Developed by Matthias Miller (http://www.JavaScriptLint.com) +# +# This configuration file can be used to lint a collection of scripts, or to enable +# or disable warnings for scripts that are linted via the command line. +# + +### Warnings +# Enable or disable warnings based on requirements. +# Use "+WarningName" to display or "-WarningName" to suppress. +# ++ambiguous_else_stmt # the else statement could be matched with one of multiple if statements (use curly braces to indicate intent ++ambiguous_nested_stmt # block statements containing block statements should use curly braces to resolve ambiguity ++ambiguous_newline # unexpected end of line; it is ambiguous whether these lines are part of the same statement ++anon_no_return_value # anonymous function does not always return value ++assign_to_function_call # assignment to a function call +-block_without_braces # block statement without curly braces ++comma_separated_stmts # multiple statements separated by commas (use semicolons?) ++comparison_type_conv # comparisons against null, 0, true, false, or an empty string allowing implicit type conversion (use === or !==) ++default_not_at_end # the default case is not at the end of the switch statement ++dup_option_explicit # duplicate "option explicit" control comment ++duplicate_case_in_switch # duplicate case in switch statement ++duplicate_formal # duplicate formal argument {name} ++empty_statement # empty statement or extra semicolon ++identifier_hides_another # identifer {name} hides an identifier in a parent scope ++inc_dec_within_stmt # increment (++) and decrement (--) operators used as part of greater statement ++incorrect_version # Expected /*jsl:content-type*/ control comment. The script was parsed with the wrong version. ++invalid_fallthru # unexpected "fallthru" control comment ++invalid_pass # unexpected "pass" control comment ++jsl_cc_not_understood # couldn't understand control comment using /*jsl:keyword*/ syntax ++leading_decimal_point # leading decimal point may indicate a number or an object member ++legacy_cc_not_understood # couldn't understand control comment using /*@keyword@*/ syntax ++meaningless_block # meaningless block; curly braces have no impact ++mismatch_ctrl_comments # mismatched control comment; "ignore" and "end" control comments must have a one-to-one correspondence ++misplaced_regex # regular expressions should be preceded by a left parenthesis, assignment, colon, or comma ++missing_break # missing break statement ++missing_break_for_last_case # missing break statement for last case in switch ++missing_default_case # missing default case in switch statement ++missing_option_explicit # the "option explicit" control comment is missing ++missing_semicolon # missing semicolon ++missing_semicolon_for_lambda # missing semicolon for lambda assignment ++multiple_plus_minus # unknown order of operations for successive plus (e.g. x+++y) or minus (e.g. x---y) signs ++nested_comment # nested comment ++no_return_value # function {name} does not always return a value ++octal_number # leading zeros make an octal number ++parseint_missing_radix # parseInt missing radix parameter ++partial_option_explicit # the "option explicit" control comment, if used, must be in the first script tag ++redeclared_var # redeclaration of {name} ++trailing_comma_in_array # extra comma is not recommended in array initializers ++trailing_decimal_point # trailing decimal point may indicate a number or an object member ++undeclared_identifier # undeclared identifier: {name} ++unreachable_code # unreachable code ++unreferenced_argument # argument declared but never referenced: {name} ++unreferenced_function # function is declared but never referenced: {name} ++unreferenced_variable # variable is declared but never referenced: {name} ++unsupported_version # JavaScript {version} is not supported ++use_of_label # use of label ++useless_assign # useless assignment ++useless_comparison # useless comparison; comparing identical expressions ++useless_quotes # the quotation marks are unnecessary ++useless_void # use of the void type may be unnecessary (void is always undefined) ++var_hides_arg # variable {name} hides argument ++want_assign_or_call # expected an assignment or function call ++with_statement # with statement hides undeclared variables; use temporary variable instead + + +### Output format +# Customize the format of the error message. +# __FILE__ indicates current file path +# __FILENAME__ indicates current file name +# __LINE__ indicates current line +# __COL__ indicates current column +# __ERROR__ indicates error message (__ERROR_PREFIX__: __ERROR_MSG__) +# __ERROR_NAME__ indicates error name (used in configuration file) +# __ERROR_PREFIX__ indicates error prefix +# __ERROR_MSG__ indicates error message +# +# For machine-friendly output, the output format can be prefixed with +# "encode:". If specified, all items will be encoded with C-slashes. +# +# Visual Studio syntax (default): ++output-format __FILE__(__LINE__): __ERROR__ +# Alternative syntax: +#+output-format __FILE__:__LINE__: __ERROR__ + + +### Context +# Show the in-line position of the error. +# Use "+context" to display or "-context" to suppress. +# ++context + + +### Control Comments +# Both JavaScript Lint and the JScript interpreter confuse each other with the syntax for +# the /*@keyword@*/ control comments and JScript conditional comments. (The latter is +# enabled in JScript with @cc_on@). The /*jsl:keyword*/ syntax is preferred for this reason, +# although legacy control comments are enabled by default for backward compatibility. +# +-legacy_control_comments + + +### Defining identifiers +# By default, "option explicit" is enabled on a per-file basis. +# To enable this for all files, use "+always_use_option_explicit" ++always_use_option_explicit + +# Define certain identifiers of which the lint is not aware. +# (Use this in conjunction with the "undeclared identifier" warning.) +# +# Common uses for webpages might be: ++define JSON ++define Math ++define $ ++define XMLHttpRequest ++define alert ++define clearInterval ++define clearTimeout ++define confirm ++define document ++define setInterval ++define setTimeout ++define window + +### JavaScript Version +# To change the default JavaScript version: +#+default-type text/javascript;version=1.5 +#+default-type text/javascript;e4x=1 + +### Files +# Specify which files to lint +# Use "+recurse" to enable recursion (disabled by default). +# To add a set of files, use "+process FileName", "+process Folder\Path\*.js", +# or "+process Folder\Path\*.htm". +# + diff --git a/tools/jsstyle.conf b/tools/jsstyle.conf new file mode 100644 index 0000000..bbf409a --- /dev/null +++ b/tools/jsstyle.conf @@ -0,0 +1,14 @@ +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +# +# Copyright (c) 2014, Joyent, Inc. +# + +indent=2 +doxygen +unparenthesized-return=0 +blank-after-start-comment=0 diff --git a/tools/mk/Makefile.defs b/tools/mk/Makefile.defs new file mode 100644 index 0000000..85139d7 --- /dev/null +++ b/tools/mk/Makefile.defs @@ -0,0 +1,51 @@ +# -*- mode: makefile -*- +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +# +# Copyright (c) 2014, Joyent, Inc. +# + +# +# Makefile.defs: common defines. +# +# NOTE: This makefile comes from the "eng" repo. It's designed to be dropped +# into other repos as-is without requiring any modifications. If you find +# yourself changing this file, you should instead update the original copy in +# eng.git and then update your repo to use the new version. +# +# This makefile defines some useful defines. Include it at the top of +# your Makefile. +# +# Definitions in this Makefile: +# +# TOP The absolute path to the project directory. The top dir. +# BRANCH The current git branch. +# TIMESTAMP The timestamp for the build. This can be set via +# the TIMESTAMP envvar (used by MG-based builds). +# STAMP A build stamp to use in built package names. +# + +TOP := $(shell pwd) + +# +# Mountain Gorilla-spec'd versioning. +# See "Package Versioning" in MG's README.md: +# +# +# Need GNU awk for multi-char arg to "-F". +_AWK := $(shell (which gawk >/dev/null && echo gawk) \ + || (which nawk >/dev/null && echo nawk) \ + || echo awk) +BRANCH := $(shell git symbolic-ref HEAD | $(_AWK) -F/ '{print $$3}') +ifeq ($(TIMESTAMP),) + TIMESTAMP := $(shell date -u "+%Y%m%dT%H%M%SZ") +endif +_GITDESCRIBE := g$(shell git describe --all --long --dirty | $(_AWK) -F'-g' '{print $$NF}') +STAMP := $(BRANCH)-$(TIMESTAMP)-$(_GITDESCRIBE) + +# node-gyp will print build info useful for debugging with V=1 +export V=1 diff --git a/tools/mk/Makefile.deps b/tools/mk/Makefile.deps new file mode 100644 index 0000000..1cffbe7 --- /dev/null +++ b/tools/mk/Makefile.deps @@ -0,0 +1,54 @@ +# -*- mode: makefile -*- +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +# +# Copyright (c) 2014, Joyent, Inc. +# + +# +# Makefile.deps: Makefile for including common tools as dependencies +# +# NOTE: This makefile comes from the "eng" repo. It's designed to be dropped +# into other repos as-is without requiring any modifications. If you find +# yourself changing this file, you should instead update the original copy in +# eng.git and then update your repo to use the new version. +# +# This file is separate from Makefile.targ so that teams can choose +# independently whether to use the common targets in Makefile.targ and the +# common tools here. +# + +# +# javascriptlint +# +JSL_EXEC ?= deps/javascriptlint/build/install/jsl +JSL ?= $(JSL_EXEC) + +$(JSL_EXEC): | deps/javascriptlint/.git + cd deps/javascriptlint && make install + +distclean:: + if [[ -f deps/javascriptlint/Makefile ]]; then \ + cd deps/javascriptlint && make clean; \ + fi + +# +# jsstyle +# +JSSTYLE_EXEC ?= deps/jsstyle/jsstyle +JSSTYLE ?= $(JSSTYLE_EXEC) + +$(JSSTYLE_EXEC): | deps/jsstyle/.git + +# +# restdown +# +RESTDOWN_EXEC ?= deps/restdown/bin/restdown +RESTDOWN ?= python $(RESTDOWN_EXEC) +$(RESTDOWN_EXEC): | deps/restdown/.git + +EXTRA_DOC_DEPS ?= diff --git a/tools/mk/Makefile.node.defs b/tools/mk/Makefile.node.defs new file mode 100644 index 0000000..9376841 --- /dev/null +++ b/tools/mk/Makefile.node.defs @@ -0,0 +1,104 @@ +# -*- mode: makefile -*- +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +# +# Copyright (c) 2014, Joyent, Inc. +# + +# +# Makefile.node.defs: Makefile for building and bundling your own Node.js. +# +# NOTE: This makefile comes from the "eng" repo. It's designed to be dropped +# into other repos as-is without requiring any modifications. If you find +# yourself changing this file, you should instead update the original copy in +# eng.git and then update your repo to use the new version. +# + +# +# This Makefile facilitates building and bundling your own copy of Node.js in +# your repo. All it does is define variables for node, node-waf, and npm for +# you to use elsewhere in your Makefile and rules to build these tools when +# needed. +# +# To use this facility, include "Makefile.node.defs", use the variables as +# described below to define targets, and then include "Makefile.node.targ". +# +# There are two use cases addressed here: +# +# (1) Invoking node, node-waf, or npm as part of the build process, as in "npm +# install" and "node-waf configure build". To facilitate this, this +# Makefile defines Make variables NODE, NODE_WAF, and NPM that you can use +# to invoke these commands during the build process. You MUST NOT assume +# that these variables just evaluate to the filenames themselves, as they +# may have environment variable definitions and other things that prevent +# you from using them directly as a filename. If you want that, see (2). +# +# Wherever you use one of these variables, you MUST include a dependency on +# the corresponding *_EXEC variable as well, like so: +# +# node_modules/restify: deps/restify $(NPM_EXEC) +# $(NPM) install deps/restify +# +# or better, use an order-only dependency to avoid spurious rebuilds: +# +# node_modules/restify: deps/restify | $(NPM_EXEC) +# $(NPM) install deps/restify +# +# Otherwise, the underlying file will not get built. We don't +# automatically build them as part of "all" because that approach is +# brittle. +# +# (2) Specifying paths for invoking node, node-waf, or npm at RUNTIME, as in +# specifying the path to node used for the start method of your service's +# SMF manifest. For this, this Makefile defines variables NODE_EXEC, +# NODE_WAF_EXEC, and NPM_EXEC, which represent the relative paths of these +# files from the root of the workspace. You MUST NOT use these variables +# to invoke these commands during the build process. See (1) instead. +# +# However, in order to work at runtime, you must build the tool as well. +# That is, if you use NODE_EXEC to specify the path to node, you must +# depend on NODE_EXEC somewhere. This usually happens anyway because you +# usually need them during the build process too, but if you don't then +# you need to explicitly add NODE_EXEC (or whichever) to your "all" +# target. +# +# When including this Makefile, you MAY also specify: +# +# BUILD top-level directory for built binaries +# (default: "build") +# +# NODE_INSTALL where node should install its built items +# (default: "$BUILD/node") +# +# NODE_CONFIG_FLAGS extra flags to pass to Node's "configure" +# (default: "--with-dtrace" on SmartOS; empty +# otherwise.) +# + +TOP ?= $(error You must include Makefile.defs before this makefile) + +BUILD ?= build +NODE_INSTALL ?= $(BUILD)/node +DISTCLEAN_FILES += $(NODE_INSTALL) + +NODE_CONFIG_FLAGS += --prefix=$(TOP)/$(NODE_INSTALL) + +ifeq ($(shell uname -s),SunOS) + NODE_CONFIG_FLAGS += --with-dtrace \ + --openssl-libpath=/opt/local/lib \ + --openssl-includes=/opt/local/include +endif + +NODE_EXEC = $(NODE_INSTALL)/bin/node +NODE_WAF_EXEC = $(NODE_INSTALL)/bin/node-waf +NPM_EXEC = $(NODE_INSTALL)/bin/npm + +# Ensure these use absolute paths to the executables to allow running +# from a dir other than the project top. +NODE := $(TOP)/$(NODE_EXEC) +NODE_WAF := $(TOP)/$(NODE_WAF_EXEC) +NPM := PATH=$(TOP)/$(NODE_INSTALL)/bin:$(PATH) node $(TOP)/$(NPM_EXEC) diff --git a/tools/mk/Makefile.node.targ b/tools/mk/Makefile.node.targ new file mode 100644 index 0000000..bf53f78 --- /dev/null +++ b/tools/mk/Makefile.node.targ @@ -0,0 +1,42 @@ +# -*- mode: makefile -*- +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +# +# Copyright (c) 2014, Joyent, Inc. +# + +# +# Makefile.node.targ: See Makefile.node.defs. +# +# NOTE: This makefile comes from the "eng" repo. It's designed to be dropped +# into other repos as-is without requiring any modifications. If you find +# yourself changing this file, you should instead update the original copy in +# eng.git and then update your repo to use the new version. +# + +ifneq ($(shell uname -s),SunOS) +NODE_PREBUILT_VERSION ?= $(error You must define NODE_PREBUILT_VERSION to use Makefile.node.targ on non-SunOS) +endif + +ifeq ($(shell uname -s),SunOS) +$(NODE_EXEC) $(NPM_EXEC) $(NODE_WAF_EXEC): | deps/node/.git + (cd deps/node; ./configure $(NODE_CONFIG_FLAGS) && $(MAKE) && $(MAKE) install) +else +$(NODE_EXEC) $(NPM_EXEC) $(NODE_WAF_EXEC): + (mkdir -p $(BUILD) \ + && cd $(BUILD) \ + && [[ -d src-node ]] && (cd src-node && git checkout master && git pull) || git clone https://github.com/joyent/node.git src-node \ + && cd src-node \ + && git checkout $(NODE_PREBUILT_VERSION) \ + && ./configure $(NODE_CONFIG_FLAGS) \ + && $(MAKE) && $(MAKE) install) +endif + +DISTCLEAN_FILES += $(NODE_INSTALL) $(BUILD)/src-node + +distclean:: + -([[ ! -d deps/node ]] || (cd deps/node && $(MAKE) distclean)) diff --git a/tools/mk/Makefile.node_deps.defs b/tools/mk/Makefile.node_deps.defs new file mode 100644 index 0000000..29a83f7 --- /dev/null +++ b/tools/mk/Makefile.node_deps.defs @@ -0,0 +1,43 @@ +# -*- mode: makefile -*- +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +# +# Copyright (c) 2014, Joyent, Inc. +# + +# +# Makefile.node_deps.defs: Makefile for including npm modules whose sources +# reside inside the repo. This should NOT be used for modules in the npm +# public repo or modules that could be specified with git SHAs. +# +# NOTE: This makefile comes from the "eng" repo. It's designed to be dropped +# into other repos as-is without requiring any modifications. If you find +# yourself changing this file, you should instead update the original copy in +# eng.git and then update your repo to use the new version. +# + +# +# This Makefile takes as input the following make variable: +# +# REPO_MODULES List of relative paths to node modules (i.e., npm +# packages) inside this repo. For example: +# src/node-canative, where there's a binary npm package +# in src/node-canative. +# +# Based on the above, this Makefile defines the following new variables: +# +# REPO_DEPS List of relative paths to the installed modules. For +# example: "node_modules/canative". +# +# The accompanying Makefile.node_deps.targ defines a target that will install +# each of REPO_MODULES into REPO_DEPS and remove REPO_DEPS with "make clean". +# The top-level Makefile is responsible for depending on REPO_DEPS where +# appropriate (usually the "deps" or "all" target). +# + +REPO_DEPS = $(REPO_MODULES:src/node-%=node_modules/%) +CLEAN_FILES += $(REPO_DEPS) diff --git a/tools/mk/Makefile.node_deps.targ b/tools/mk/Makefile.node_deps.targ new file mode 100644 index 0000000..bb2ab4f --- /dev/null +++ b/tools/mk/Makefile.node_deps.targ @@ -0,0 +1,24 @@ +# -*- mode: makefile -*- +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +# +# Copyright (c) 2014, Joyent, Inc. +# + +# +# Makefile.node_deps.targ: targets for Makefile.node_deps.defs. +# +# NOTE: This makefile comes from the "eng" repo. It's designed to be dropped +# into other repos as-is without requiring any modifications. If you find +# yourself changing this file, you should instead update the original copy in +# eng.git and then update your repo to use the new version. +# + +NPM_EXEC ?= $(error NPM_EXEC must be defined for Makefile.node_deps.targ) + +node_modules/%: src/node-% | $(NPM_EXEC) + $(NPM) install $< diff --git a/tools/mk/Makefile.node_prebuilt.defs b/tools/mk/Makefile.node_prebuilt.defs new file mode 100644 index 0000000..5744489 --- /dev/null +++ b/tools/mk/Makefile.node_prebuilt.defs @@ -0,0 +1,153 @@ +# -*- mode: makefile -*- +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +# +# Copyright (c) 2014, Joyent, Inc. +# + +# +# Makefile.node_prebuilt.defs: Makefile for including a prebuilt Node.js build. +# +# NOTE: This makefile comes from the "eng" repo. It's designed to be dropped +# into other repos as-is without requiring any modifications. If you find +# yourself changing this file, you should instead update the original copy in +# eng.git and then update your repo to use the new version. +# + +# +# This Makefile facilitates downloading and bundling a prebuilt node.js +# build (using the 'sdcnode' distro builds). This is an alternative to +# the "Makefile.node.*" makefiles for *building* a node from source. +# +# Usage: +# +# - Define `NODE_PREBUILT_VERSION` in your Makefile to choose a node version. +# E.g.: `NODE_PREBUILT_VERSION=v0.6.19`. See other optional variables +# below. +# - `include tools/mk/Makefile.node_prebuilt.defs` after this in your Makefile. +# - `include tools/mk/Makefile.node_prebuilt.targ` near the end of your +# Makefile. +# - Have at least one of your Makefile targets depend on either `$(NODE_EXEC)` +# or `$(NPM_EXEC)`. E.g.: +# +# node_modules/restify: deps/restify $(NPM_EXEC) +# $(NPM) install deps/restify +# +# or better, use an order-only dependency to avoid spurious rebuilds: +# +# node_modules/restify: deps/restify | $(NPM_EXEC) +# $(NPM) install deps/restify +# +# - Use `$(NPM)` or `$(NODE)` to use your node build. +# - Include the "$(NODE_INSTALL)" tree in your release package. +# +# +# When including this Makefile, you MUST also specify: +# +# NODE_PREBUILT_VERSION The node version in the prebuilt 'sdcnode' +# package to use. Typically this is one of the +# node version tags, e.g. "v0.6.18" but it +# can be any commitish. +# +# When including this Makefile, you MAY also specify: +# +# NODE_PREBUILT_DIR The dir in which to find sdcnode builds. This +# can either be a *local directory* or *a +# URL* dir (with trailing '/') which serves +# Apache/Nginx dir listing HTML. +# (default: sdcnode master build dir on stuff) +# +# NODE_PREBUILT_TAG The 'sdcnode' project supports special +# configuration builds of node, e.g. say a +# build configured `--without-ssl`. These +# special configurations are given a tag, e.g. +# 'gz', that is used in the filename. Optionally +# specify a tag name here. +# (default: empty) +# +# NODE_PREBUILT_BRANCH Specify a particular branch of 'sdcnode' builds +# from which to pull. Generally one should stick +# with the default. +# (default: master) +# +# NODE_PREBUILT_IMAGE If you have a zone image that differs from that +# for an sdcnode build that you want to use (potential compat +# issues be damned), then set this to the UUID of the sdcnode +# build you want. See here for available build image uuids: +# +# +# BUILD top-level directory for built binaries +# (default: "build") +# +# NODE_INSTALL where node should install its built items +# (default: "$BUILD/node") +# +# +# Dev Notes: +# +# This works by getting "NODE_PREBUILT_NAME" from the provided "NODE_PREBUILT_*" +# vars and the image version (via 'mdata-get sdc:image_uuid'). The image uuid is +# included to ensure an exact match with the build machine. This name (e.g. +# "v0.6.18-zone-$uuid") is used to find a matching "sdcnode-$name-*.tgz" build +# in "NODE_PREBUILT_DIR" (either a local directory or a URL). That tarball is +# downloaded and extracted into "NODE_INSTALL". +# +# The "*_EXEC" vars are set to named symlinks, e.g. +# "build/prebuilt-node-v0.6.18-$uuid", so that a change of selected node +# build (say the developer changes NODE_PREBUILT_VERSION) will recreate the +# node install. +# +# See for details on 'sdcnode-*' +# package naming. +# + +TOP ?= $(error You must include Makefile.defs before this makefile) +NODE_PREBUILT_VERSION ?= $(error NODE_PREBUILT_VERSION is not set.) + + +BUILD ?= build +NODE_INSTALL ?= $(BUILD)/node +DISTCLEAN_FILES += $(NODE_INSTALL) \ + $(BUILD)/prebuilt-node-* $(BUILD)/prebuilt-npm-* + +NODE_PREBUILT_BRANCH ?= master +NODE_PREBUILT_IMAGE ?= $(shell pfexec mdata-get sdc:image_uuid) +ifeq ($(NODE_PREBUILT_TAG),) + NODE_PREBUILT_NAME := $(NODE_PREBUILT_VERSION)-$(NODE_PREBUILT_IMAGE) +else + NODE_PREBUILT_NAME := $(NODE_PREBUILT_VERSION)-$(NODE_PREBUILT_TAG)-$(NODE_PREBUILT_IMAGE) +endif +NODE_PREBUILT_PATTERN := sdcnode-$(NODE_PREBUILT_NAME)-$(NODE_PREBUILT_BRANCH)-.*\.tgz +NODE_PREBUILT_DIR ?= https://download.joyent.com/pub/build/sdcnode/$(NODE_PREBUILT_IMAGE)/$(NODE_PREBUILT_BRANCH)-latest/sdcnode/ +ifeq ($(shell echo $(NODE_PREBUILT_DIR) | cut -c 1-4),http) + NODE_PREBUILT_BASE := $(shell curl -ksS --fail --connect-timeout 30 $(NODE_PREBUILT_DIR) | grep 'href=' | cut -d'"' -f2 | grep "^$(NODE_PREBUILT_PATTERN)$$" | sort | tail -1) + ifneq ($(NODE_PREBUILT_BASE),) + NODE_PREBUILT_TARBALL := $(NODE_PREBUILT_DIR)$(NODE_PREBUILT_BASE) + endif +else + NODE_PREBUILT_BASE := $(shell ls -1 $(NODE_PREBUILT_DIR)/ | grep "^$(NODE_PREBUILT_PATTERN)$$" 2>/dev/null | sort | tail -1) + ifneq ($(NODE_PREBUILT_BASE),) + NODE_PREBUILT_TARBALL := $(NODE_PREBUILT_DIR)/$(NODE_PREBUILT_BASE) + endif +endif +ifeq ($(NODE_PREBUILT_TARBALL),) + NODE_PREBUILT_TARBALL = $(error NODE_PREBUILT_TARBALL is empty: no '$(NODE_PREBUILT_DIR)/$(NODE_PREBUILT_PATTERN)' found) +endif + + +# Prebuild-specific paths for the "*_EXEC" vars to ensure that +# a prebuild change (e.g. if master Makefile's NODE_PREBUILT_VERSION +# choice changes) causes a install of the new node. +NODE_EXEC := $(BUILD)/prebuilt-node-$(NODE_PREBUILT_NAME) +NODE_WAF_EXEC := $(BUILD)/prebuilt-node-waf-$(NODE_PREBUILT_NAME) +NPM_EXEC := $(BUILD)/prebuilt-npm-$(NODE_PREBUILT_NAME) + +# Ensure these use absolute paths to the executables to allow running +# from a dir other than the project top. +NODE := $(TOP)/$(NODE_INSTALL)/bin/node +NODE_WAF := $(TOP)/$(NODE_INSTALL)/bin/node-waf +NPM := PATH=$(TOP)/$(NODE_INSTALL)/bin:$(PATH) node $(TOP)/$(NODE_INSTALL)/bin/npm diff --git a/tools/mk/Makefile.node_prebuilt.targ b/tools/mk/Makefile.node_prebuilt.targ new file mode 100644 index 0000000..6877333 --- /dev/null +++ b/tools/mk/Makefile.node_prebuilt.targ @@ -0,0 +1,42 @@ +# -*- mode: makefile -*- +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +# +# Copyright (c) 2014, Joyent, Inc. +# + +# +# Makefile.node_prebuilt.targ: Makefile for including a prebuilt Node.js +# build. +# +# NOTE: This makefile comes from the "eng" repo. It's designed to be dropped +# into other repos as-is without requiring any modifications. If you find +# yourself changing this file, you should instead update the original copy in +# eng.git and then update your repo to use the new version. + + +NODE_PREBUILT_TARBALL ?= $(error NODE_PREBUILT_TARBALL is not set: was Makefile.node_prebuilt.defs included?) + + +# TODO: remove this limitation +# Limitation: currently presuming that the NODE_INSTALL basename is +# 'node' and that sdcnode tarballs have a 'node' top-level dir. +$(NODE_EXEC) $(NPM_EXEC) $(NODE_WAF_EXEC): + [[ $(shell basename $(NODE_INSTALL)) == "node" ]] \ + || (echo "Limitation: 'basename NODE_INSTALL' is not 'node'" && exit 1) + rm -rf $(NODE_INSTALL) \ + $(BUILD)/prebuilt-node-* $(BUILD)/prebuilt-npm-* + mkdir -p $(shell dirname $(NODE_INSTALL)) + if [[ $(shell echo $(NODE_PREBUILT_TARBALL) | cut -c 1-4) == "http" ]]; then \ + echo "Downloading '$(NODE_PREBUILT_BASE)'."; \ + curl -ksS --fail --connect-timeout 30 -o $(shell dirname $(NODE_INSTALL))/$(NODE_PREBUILT_BASE) $(NODE_PREBUILT_TARBALL); \ + (cd $(shell dirname $(NODE_INSTALL)) && $(TAR) xf $(NODE_PREBUILT_BASE)); \ + else \ + (cd $(shell dirname $(NODE_INSTALL)) && $(TAR) xf $(NODE_PREBUILT_TARBALL)); \ + fi + ln -s $(TOP)/$(NODE_INSTALL)/bin/node $(NODE_EXEC) + ln -s $(TOP)/$(NODE_INSTALL)/bin/npm $(NPM_EXEC) diff --git a/tools/mk/Makefile.smf.defs b/tools/mk/Makefile.smf.defs new file mode 100644 index 0000000..b988bbe --- /dev/null +++ b/tools/mk/Makefile.smf.defs @@ -0,0 +1,40 @@ +# -*- mode: makefile -*- +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +# +# Copyright (c) 2014, Joyent, Inc. +# + +# +# Makefile.smf.defs: common targets for SMF manifests +# +# NOTE: This makefile comes from the "eng" repo. It's designed to be dropped +# into other repos as-is without requiring any modifications. If you find +# yourself changing this file, you should instead update the original copy in +# eng.git and then update your repo to use the new version. +# +# This Makefile uses the following definitions: +# +# SMF_MANIFESTS_IN Source files for SMF manifests. The following +# substitutions will be made on these files: +# +# @@NODE@@ path to installed node +# +# It updates SMF_MANIFESTS with the set of files generated by SMF_MANIFESTS_IN. +# It also updates the "check" target to check the XML syntax of all manifests, +# generated or otherwise. +# +# To use this file, be sure to also include Makefile.smf.targ after defining +# targets. +# + +SED ?= sed +SMF_DTD ?= tools/service_bundle.dtd.1 +XMLLINT ?= xmllint --noout + +SMF_MANIFESTS += $(SMF_MANIFESTS_IN:%.in=%) +CLEAN_FILES += $(SMF_MANIFESTS_IN:%.in=%) diff --git a/tools/mk/Makefile.smf.targ b/tools/mk/Makefile.smf.targ new file mode 100644 index 0000000..f78de96 --- /dev/null +++ b/tools/mk/Makefile.smf.targ @@ -0,0 +1,29 @@ +# -*- mode: makefile -*- +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +# +# Copyright (c) 2014, Joyent, Inc. +# + +# +# Makefile.smf.targ: see Makefile.smf.defs. +# +# NOTE: This makefile comes from the "eng" repo. It's designed to be dropped +# into other repos as-is without requiring any modifications. If you find +# yourself changing this file, you should instead update the original copy in +# eng.git and then update your repo to use the new version. +# +.PHONY: check-manifests +check-manifests: $(SMF_MANIFESTS:%=%.smfchk) + +%.smfchk: % + $(XMLLINT) --path $(dir $(SMF_DTD)) --dtdvalid $(SMF_DTD) $^ + +check:: check-manifests + +$(SMF_MANIFESTS): %: %.in + $(SED) -e 's#@@NODE@@#@@PREFIX@@/$(NODE_INSTALL)/bin/node#' $< > $@ diff --git a/tools/mk/Makefile.targ b/tools/mk/Makefile.targ new file mode 100644 index 0000000..9950458 --- /dev/null +++ b/tools/mk/Makefile.targ @@ -0,0 +1,318 @@ +# -*- mode: makefile -*- +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +# +# Copyright (c) 2014, Joyent, Inc. +# + +# +# Makefile.targ: common targets. +# +# NOTE: This makefile comes from the "eng" repo. It's designed to be dropped +# into other repos as-is without requiring any modifications. If you find +# yourself changing this file, you should instead update the original copy in +# eng.git and then update your repo to use the new version. +# +# This Makefile defines several useful targets and rules. You can use it by +# including it from a Makefile that specifies some of the variables below. +# +# Targets defined in this Makefile: +# +# check Checks JavaScript files for lint and style +# Checks bash scripts for syntax +# Checks SMF manifests for validity against the SMF DTD +# +# clean Removes built files +# +# docs Builds restdown documentation in docs/ +# +# prepush Depends on "check" and "test" +# +# test Does nothing (you should override this) +# +# xref Generates cscope (source cross-reference index) +# +# For details on what these targets are supposed to do, see the Joyent +# Engineering Guide. +# +# To make use of these targets, you'll need to set some of these variables. Any +# variables left unset will simply not be used. +# +# BASH_FILES Bash scripts to check for syntax +# (paths relative to top-level Makefile) +# +# CLEAN_FILES Files to remove as part of the "clean" target. Note +# that files generated by targets in this Makefile are +# automatically included in CLEAN_FILES. These include +# restdown-generated HTML and JSON files. +# +# DOC_FILES Restdown (documentation source) files. These are +# assumed to be contained in "docs/", and must NOT +# contain the "docs/" prefix. +# +# JSL_CONF_NODE Specify JavaScriptLint configuration files +# JSL_CONF_WEB (paths relative to top-level Makefile) +# +# Node.js and Web configuration files are separate +# because you'll usually want different global variable +# configurations. If no file is specified, none is given +# to jsl, which causes it to use a default configuration, +# which probably isn't what you want. +# +# JSL_FILES_NODE JavaScript files to check with Node config file. +# JSL_FILES_WEB JavaScript files to check with Web config file. +# +# JSON_FILES JSON files to be validated +# +# JSSTYLE_FILES JavaScript files to be style-checked +# +# You can also override these variables: +# +# BASH Path to bash (default: "bash") +# +# CSCOPE_DIRS Directories to search for source files for the cscope +# index. (default: ".") +# +# JSL Path to JavaScriptLint (default: "jsl") +# +# JSL_FLAGS_NODE Additional flags to pass through to JSL +# JSL_FLAGS_WEB +# JSL_FLAGS +# +# JSON Path to json tool (default: "json") +# +# JSSTYLE Path to jsstyle (default: "jsstyle") +# +# JSSTYLE_FLAGS Additional flags to pass through to jsstyle +# +# RESTDOWN_EXT By default '.md' is required for DOC_FILES (see above). +# If you want to use, say, '.restdown' instead, then set +# 'RESTDOWN_EXT=.restdown' in your Makefile. +# + +# +# Defaults for the various tools we use. +# +BASH ?= bash +BASHSTYLE ?= tools/bashstyle +CP ?= cp +CSCOPE ?= cscope +CSCOPE_DIRS ?= . +JSL ?= jsl +JSON ?= json +JSSTYLE ?= jsstyle +MKDIR ?= mkdir -p +MV ?= mv +RESTDOWN_FLAGS ?= +RESTDOWN_EXT ?= .md +RMTREE ?= rm -rf +JSL_FLAGS ?= --nologo --nosummary + +ifeq ($(shell uname -s),SunOS) + TAR ?= gtar +else + TAR ?= tar +endif + + +# +# Defaults for other fixed values. +# +BUILD = build +DISTCLEAN_FILES += $(BUILD) +DOC_BUILD = $(BUILD)/docs/public + +# +# Configure JSL_FLAGS_{NODE,WEB} based on JSL_CONF_{NODE,WEB}. +# +ifneq ($(origin JSL_CONF_NODE), undefined) + JSL_FLAGS_NODE += --conf=$(JSL_CONF_NODE) +endif + +ifneq ($(origin JSL_CONF_WEB), undefined) + JSL_FLAGS_WEB += --conf=$(JSL_CONF_WEB) +endif + +# +# Targets. For descriptions on what these are supposed to do, see the +# Joyent Engineering Guide. +# + +# +# Instruct make to keep around temporary files. We have rules below that +# automatically update git submodules as needed, but they employ a deps/*/.git +# temporary file. Without this directive, make tries to remove these .git +# directories after the build has completed. +# +.SECONDARY: $($(wildcard deps/*):%=%/.git) + +# +# This rule enables other rules that use files from a git submodule to have +# those files depend on deps/module/.git and have "make" automatically check +# out the submodule as needed. +# +deps/%/.git: + git submodule update --init deps/$* + +# +# These recipes make heavy use of dynamically-created phony targets. The parent +# Makefile defines a list of input files like BASH_FILES. We then say that each +# of these files depends on a fake target called filename.bashchk, and then we +# define a pattern rule for those targets that runs bash in check-syntax-only +# mode. This mechanism has the nice properties that if you specify zero files, +# the rule becomes a noop (unlike a single rule to check all bash files, which +# would invoke bash with zero files), and you can check individual files from +# the command line with "make filename.bashchk". +# +.PHONY: check-bash +check-bash: $(BASH_FILES:%=%.bashchk) $(BASH_FILES:%=%.bashstyle) + +%.bashchk: % + $(BASH) -n $^ + +%.bashstyle: % + $(BASHSTYLE) $^ + +.PHONY: check-json +check-json: $(JSON_FILES:%=%.jsonchk) + +%.jsonchk: % + $(JSON) --validate -f $^ + +# +# The above approach can be slow when there are many files to check because it +# requires that "make" invoke the check tool once for each file, rather than +# passing in several files at once. For the JavaScript check targets, we define +# a variable for the target itself *only if* the list of input files is +# non-empty. This avoids invoking the tool if there are no files to check. +# +JSL_NODE_TARGET = $(if $(JSL_FILES_NODE), check-jsl-node) +.PHONY: check-jsl-node +check-jsl-node: $(JSL_EXEC) + $(JSL) $(JSL_FLAGS) $(JSL_FLAGS_NODE) $(JSL_FILES_NODE) + +JSL_WEB_TARGET = $(if $(JSL_FILES_WEB), check-jsl-web) +.PHONY: check-jsl-web +check-jsl-web: $(JSL_EXEC) + $(JSL) $(JSL_FLAGS) $(JSL_FLAGS_WEB) $(JSL_FILES_WEB) + +.PHONY: check-jsl +check-jsl: $(JSL_NODE_TARGET) $(JSL_WEB_TARGET) + +JSSTYLE_TARGET = $(if $(JSSTYLE_FILES), check-jsstyle) +.PHONY: check-jsstyle +check-jsstyle: $(JSSTYLE_EXEC) + $(JSSTYLE) $(JSSTYLE_FLAGS) $(JSSTYLE_FILES) + +.PHONY: check +check:: check-jsl check-json $(JSSTYLE_TARGET) check-bash + @echo check ok + +.PHONY: clean +clean:: + -$(RMTREE) $(CLEAN_FILES) + +.PHONY: distclean +distclean:: clean + -$(RMTREE) $(DISTCLEAN_FILES) + +CSCOPE_FILES = cscope.in.out cscope.out cscope.po.out +CLEAN_FILES += $(CSCOPE_FILES) + +.PHONY: xref +xref: cscope.files + $(CSCOPE) -bqR + +.PHONY: cscope.files +cscope.files: + find $(CSCOPE_DIRS) -name '*.c' -o -name '*.h' -o -name '*.cc' \ + -o -name '*.js' -o -name '*.s' -o -name '*.cpp' > $@ + +# +# The "docs" target is complicated because we do several things here: +# +# (1) Use restdown to build HTML and JSON files from each of DOC_FILES. +# +# (2) Copy these files into $(DOC_BUILD) (build/docs/public), which +# functions as a complete copy of the documentation that could be +# mirrored or served over HTTP. +# +# (3) Then copy any directories and media from docs/media into +# $(DOC_BUILD)/media. This allows projects to include their own media, +# including files that will override same-named files provided by +# restdown. +# +# Step (3) is the surprisingly complex part: in order to do this, we need to +# identify the subdirectories in docs/media, recreate them in +# $(DOC_BUILD)/media, then do the same with the files. +# +DOC_MEDIA_DIRS := $(shell find docs/media -type d 2>/dev/null | grep -v "^docs/media$$") +DOC_MEDIA_DIRS := $(DOC_MEDIA_DIRS:docs/media/%=%) +DOC_MEDIA_DIRS_BUILD := $(DOC_MEDIA_DIRS:%=$(DOC_BUILD)/media/%) + +DOC_MEDIA_FILES := $(shell find docs/media -type f 2>/dev/null) +DOC_MEDIA_FILES := $(DOC_MEDIA_FILES:docs/media/%=%) +DOC_MEDIA_FILES_BUILD := $(DOC_MEDIA_FILES:%=$(DOC_BUILD)/media/%) + +# +# Like the other targets, "docs" just depends on the final files we want to +# create in $(DOC_BUILD), leveraging other targets and recipes to define how +# to get there. +# +.PHONY: docs +docs:: \ + $(DOC_FILES:%$(RESTDOWN_EXT)=$(DOC_BUILD)/%.html) \ + $(DOC_FILES:%$(RESTDOWN_EXT)=$(DOC_BUILD)/%.json) \ + $(DOC_MEDIA_FILES_BUILD) + +# +# We keep the intermediate files so that the next build can see whether the +# files in DOC_BUILD are up to date. +# +.PRECIOUS: \ + $(DOC_FILES:%$(RESTDOWN_EXT)=docs/%.html) \ + $(DOC_FILES:%$(RESTDOWN_EXT)=docs/%json) + +# +# We do clean those intermediate files, as well as all of DOC_BUILD. +# +CLEAN_FILES += \ + $(DOC_BUILD) \ + $(DOC_FILES:%$(RESTDOWN_EXT)=docs/%.html) \ + $(DOC_FILES:%$(RESTDOWN_EXT)=docs/%.json) + +# +# Before installing the files, we must make sure the directories exist. The | +# syntax tells make that the dependency need only exist, not be up to date. +# Otherwise, it might try to rebuild spuriously because the directory itself +# appears out of date. +# +$(DOC_MEDIA_FILES_BUILD): | $(DOC_MEDIA_DIRS_BUILD) + +$(DOC_BUILD)/%: docs/% | $(DOC_BUILD) + $(CP) $< $@ + +docs/%.json docs/%.html: docs/%$(RESTDOWN_EXT) | $(DOC_BUILD) $(RESTDOWN_EXEC) \ + $(EXTRA_DOC_DEPS) + $(RESTDOWN) $(RESTDOWN_FLAGS) -m $(DOC_BUILD) $< + +$(DOC_BUILD): + $(MKDIR) $@ + +$(DOC_MEDIA_DIRS_BUILD): + $(MKDIR) $@ + +# +# The default "test" target does nothing. This should usually be overridden by +# the parent Makefile. It's included here so we can define "prepush" without +# requiring the repo to define "test". +# +.PHONY: test +test: + +.PHONY: prepush +prepush: check test diff --git a/tools/mkrepo b/tools/mkrepo new file mode 100644 index 0000000..3b0d624 --- /dev/null +++ b/tools/mkrepo @@ -0,0 +1,121 @@ +#!/usr/bin/env node +// -*- mode: js -*- +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* + * Copyright (c) 2014, Joyent, Inc. + */ + +var child_process = require('child_process'); +var fs = require('fs'); +var path = require('path'); + + + +///--- Globals + +var DIRS = [ + 'deps', + 'docs', + 'docs/media', + 'lib', + 'smf', + 'smf/manifests', + 'test', + 'tools', + 'tools/mk' +]; + +var SUBMODULES = { + 'javascriptlint': 'https://github.com/davepacheco/javascriptlint.git', + 'jsstyle': 'https://github.com/davepacheco/jsstyle.git', + 'restdown': 'https://github.com/trentm/restdown.git' +}; + + + +///--- Internal Functions + +function usage(code, message) { + if (message) + console.error(message); + + console.error('usage: %s [repo ...]', path.basename(process.argv[1])); + process.exit(code); +} + + +function ensureDirectoryNotExists(dir) { + try { + var stats = fs.statSync(dir); + usage(1, dir + ' already exists'); + } catch (e) { + return false; + } +} + + +function cp(src, dest) { + fs.createReadStream(src).pipe(fs.createWriteStream(dest)); +} + + +function exec(cmd, dir, cb) { + child_process.exec(cmd, {cwd: dir}, function (err, stdout, stderr) { + if (err) + process.exit(err.code || 1); + + if (typeof (cb) === 'function') + return cb(null); + }); +} + + +function mkdir(d) { + fs.mkdirSync(d, '0750'); +} + +function gitify(dir, repo) { + exec('git init', dir, function () { + exec('git remote add origin git@github.com:joyent/' + repo + '.git', + dir); + + Object.keys(SUBMODULES).forEach(function (k) { + // stub out the git submodule call + console.error('Cloning into deps/' + k + '...'); + exec('git submodule add ' + SUBMODULES[k] + ' ./deps/' + k, dir); + }); + }); +} + + + +///--- Mainline + +if (process.argv.length < 3) + usage(1, 'repo required'); + +process.argv.slice(2).forEach(function (arg) { + var repo = path.resolve(arg); + ensureDirectoryNotExists(repo); + mkdir(repo); + DIRS.concat('.').forEach(function (d) { + var dir = repo + '/' + d; + if (d != '.') + mkdir(dir); + + fs.readdirSync('./' + d).forEach(function (f) { + var src = './' + d + '/' + f; + var dest = dir + '/' + f; + if (fs.statSync(src).isFile() && !/^\..*/.test(f)) + cp(src, dest); + }); + }); + + cp('./.gitignore', repo + '/.gitignore'); + gitify(repo, arg); +}); diff --git a/tools/runtests.in b/tools/runtests.in new file mode 100644 index 0000000..2d72b6f --- /dev/null +++ b/tools/runtests.in @@ -0,0 +1,136 @@ +#!/bin/bash +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +# +# Copyright (c) 2014, Joyent, Inc. +# + +# +# Run the TODONAME tests. +# Run `./runtests -h` for usage info. +# + +if [ "$TRACE" != "" ]; then + export PS4='${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' + set -o xtrace +fi +set -o errexit +set -o pipefail + + + +#---- guard + +if [[ ! -f "/lib/sdc/.sdc-test-no-production-data" ]]; then + cat < + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +]]> + + + + +]]> + + + + + + +]]> + + + + +]]> + + + + + + +]]> + + + + +]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +