diff --git a/.gitignore b/.gitignore index 5d407f3..e3236a8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -/build /coverage /node_modules *.log +/.nyc_output +/package-lock.json diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 6998f69..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "deps/jsstyle"] - path = deps/jsstyle - url = https://github.com/joyent/jsstyle.git diff --git a/.npmignore b/.npmignore index c0daf5f..bae0420 100644 --- a/.npmignore +++ b/.npmignore @@ -1,12 +1,7 @@ *.log -/Makefile -/deps /test -/tools -/.gitmodules /.npmignore +/.nyc_output /.eslintrc -/.travis.yml /CONTRIBUTING.md -/build /coverage diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index c84387d..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,65 +0,0 @@ -@Library('jenkins-joylib@v1.0.3') _ - -pipeline { - - agent none - - options { - buildDiscarder(logRotator(numToKeepStr: '45')) - timestamps() - } - - stages { - stage('top') { - parallel { - stage('v4-zone') { - agent { - label joyCommonLabels(image_ver: '15.4.1') - } - tools { - nodejs 'sdcnode-v4-zone' - } - stages { - stage('check') { - steps{ - sh('make check') - } - } - stage('test') { - steps{ - sh('make test') - } - } - } - } - - stage('v6-zone64') { - agent { - label joyCommonLabels(image_ver: '18.4.0') - } - tools { - nodejs 'sdcnode-v6-zone64' - } - stages { - stage('check') { - steps{ - sh('make check') - } - } - stage('test') { - steps{ - sh('make test') - } - } - } - } - } - } - } - - post { - always { - joyMattermostNotification() - } - } -} diff --git a/Makefile b/Makefile deleted file mode 100644 index b9a8bd5..0000000 --- a/Makefile +++ /dev/null @@ -1,59 +0,0 @@ -# -# 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 2019, Joyent, Inc. -# - -# -# node-asn1 Makefile -# - -# -# Tools -# - -ISTANBUL := node_modules/.bin/istanbul -FAUCET := node_modules/.bin/faucet -NODE := node -NPM := npm - -# -# Files -# - -JS_FILES := $(shell find lib test -name '*.js') -JSSTYLE_FILES = $(JS_FILES) -JSSTYLE_FLAGS = -f tools/jsstyle.conf -ESLINT = ./node_modules/.bin/eslint -ESLINT_FILES = $(JS_FILES) - -include ./tools/mk/Makefile.defs -include ./tools/mk/Makefile.smf.defs - -# -# Repo-specific targets -# - -.PHONY: all -all: $(TAPE) - $(NPM) rebuild - -$(ISTANBUL): | $(NPM_EXEC) - $(NPM) install - -$(FAUCET): | $(NPM_EXEC) - $(NPM) install - -CLEAN_FILES += ./node_modules/ - -.PHONY: test -test: $(ISTANBUL) $(FAUCET) - $(ISTANBUL) cover --print none test/run.js | $(FAUCET) - -include ./tools/mk/Makefile.deps -include ./tools/mk/Makefile.smf.targ -include ./tools/mk/Makefile.targ diff --git a/deps/jsstyle b/deps/jsstyle deleted file mode 160000 index 52dc973..0000000 --- a/deps/jsstyle +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 52dc973cf64da11834eca7cf46ebce8518e3ee88 diff --git a/lib/ber/index.js b/lib/ber/index.js index 387d132..cb67d88 100644 --- a/lib/ber/index.js +++ b/lib/ber/index.js @@ -18,10 +18,12 @@ module.exports = { }; for (var t in types) { - if (types.hasOwnProperty(t)) + if (Object.prototype.hasOwnProperty.call(types, t)) { module.exports[t] = types[t]; + } } for (var e in errors) { - if (errors.hasOwnProperty(e)) + if (Object.prototype.hasOwnProperty.call(errors, e)) { module.exports[e] = errors[e]; + } } diff --git a/lib/ber/reader.js b/lib/ber/reader.js index 8a7e4ca..fc46987 100644 --- a/lib/ber/reader.js +++ b/lib/ber/reader.js @@ -16,8 +16,9 @@ var newInvalidAsn1Error = errors.newInvalidAsn1Error; // --- API function Reader(data) { - if (!data || !Buffer.isBuffer(data)) + if (!data || !Buffer.isBuffer(data)) { throw new TypeError('data must be a node Buffer'); + } this._buf = data; this._size = data.length; @@ -54,13 +55,11 @@ Object.defineProperty(Reader.prototype, 'buffer', { * @return {Number} the next byte, null if not enough data. */ Reader.prototype.readByte = function (peek) { - if (this._size - this._offset < 1) - return null; + if (this._size - this._offset < 1) { return null; } var b = this._buf[this._offset] & 0xff; - if (!peek) - this._offset += 1; + if (!peek) { this._offset += 1; } return b; }; @@ -83,32 +82,28 @@ Reader.prototype.peek = function () { * @throws {InvalidAsn1Error} on bad ASN.1 */ Reader.prototype.readLength = function (offset) { - if (offset === undefined) - offset = this._offset; + if (offset === undefined) { offset = this._offset; } - if (offset >= this._size) - return null; + if (offset >= this._size) { return null; } var lenB = this._buf[offset++] & 0xff; - if (lenB === null) - return null; + if (lenB === null) { return null; } if ((lenB & 0x80) === 0x80) { lenB &= 0x7f; - if (lenB === 0) + if (lenB === 0) { throw newInvalidAsn1Error('Indefinite length not supported'); + } - if (lenB > 4) - throw newInvalidAsn1Error('encoding too long'); + if (lenB > 4) { throw newInvalidAsn1Error('encoding too long'); } - if (this._size - offset < lenB) - return null; + if (this._size - offset < lenB) { return null; } this._len = 0; - for (var i = 0; i < lenB; i++) + for (var i = 0; i < lenB; i++) { this._len = (this._len << 8) + (this._buf[offset++] & 0xff); - + } } else { // Wasn't a variable length this._len = lenB; @@ -127,15 +122,14 @@ Reader.prototype.readLength = function (offset) { */ Reader.prototype.readSequence = function (tag) { var seq = this.peek(); - if (seq === null) - return null; - if (tag !== undefined && tag !== seq) - throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) + + if (seq === null) { return null; } + if (tag !== undefined && tag !== seq) { + throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) + ': got 0x' + seq.toString(16)); +} var o = this.readLength(this._offset + 1); // stored in `length` - if (o === null) - return null; + if (o === null) { return null; } this._offset = o; return seq; @@ -148,7 +142,7 @@ Reader.prototype.readInt = function () { Reader.prototype.readBoolean = function () { - return (this._readTag(ASN1.Boolean) === 0 ? false : true); + return (this._readTag(ASN1.Boolean) !== 0); }; @@ -158,29 +152,25 @@ Reader.prototype.readEnumeration = function () { Reader.prototype.readString = function (tag, retbuf) { - if (!tag) - tag = ASN1.OctetString; + if (!tag) { tag = ASN1.OctetString; } var b = this.peek(); - if (b === null) - return null; + if (b === null) { return null; } - if (b !== tag) - throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) + + if (b !== tag) { + throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) + ': got 0x' + b.toString(16)); +} var o = this.readLength(this._offset + 1); // stored in `length` - if (o === null) - return null; + if (o === null) { return null; } - if (this.length > this._size - o) - return null; + if (this.length > this._size - o) { return null; } this._offset = o; - if (this.length === 0) - return retbuf ? Buffer.alloc(0) : ''; + if (this.length === 0) { return retbuf ? Buffer.alloc(0) : ''; } var str = this._buf.slice(this._offset, this._offset + this.length); this._offset += this.length; @@ -189,12 +179,10 @@ Reader.prototype.readString = function (tag, retbuf) { }; Reader.prototype.readOID = function (tag) { - if (!tag) - tag = ASN1.OID; + if (!tag) { tag = ASN1.OID; } var b = this.readString(tag, true); - if (b === null) - return null; + if (b === null) { return null; } var values = []; var value = 0; @@ -223,22 +211,21 @@ Reader.prototype._readTag = function (tag) { var b = this.peek(); - if (b === null) - return null; + if (b === null) { return null; } - if (b !== tag) - throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) + + if (b !== tag) { + throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) + ': got 0x' + b.toString(16)); +} var o = this.readLength(this._offset + 1); // stored in `length` - if (o === null) - return null; + if (o === null) { return null; } - if (this.length > 4) + if (this.length > 4) { throw newInvalidAsn1Error('Integer too long: ' + this.length); + } - if (this.length > this._size - o) - return null; + if (this.length > this._size - o) { return null; } this._offset = o; var fb = this._buf[this._offset]; @@ -249,8 +236,7 @@ Reader.prototype._readTag = function (tag) { value |= (this._buf[this._offset++] & 0xff); } - if ((fb & 0x80) === 0x80 && i !== 4) - value -= (1 << (i * 8)); + if ((fb & 0x80) === 0x80 && i !== 4) { value -= (1 << (i * 8)); } return value >> 0; }; diff --git a/lib/ber/writer.js b/lib/ber/writer.js index ca6400e..4d4cf2c 100644 --- a/lib/ber/writer.js +++ b/lib/ber/writer.js @@ -26,8 +26,7 @@ function merge(from, to) { var keys = Object.getOwnPropertyNames(from); keys.forEach(function (key) { - if (to[key]) - return; + if (to[key]) { return; } var value = Object.getOwnPropertyDescriptor(from, key); Object.defineProperty(to, key, value); @@ -55,16 +54,18 @@ function Writer(options) { Object.defineProperty(Writer.prototype, 'buffer', { get: function () { - if (this._seq.length) + if (this._seq.length) { throw newInvalidAsn1Error(this._seq.length + ' unended sequence(s)'); + } return (this._buf.slice(0, this._offset)); } }); Writer.prototype.writeByte = function (b) { - if (typeof (b) !== 'number') + if (typeof (b) !== 'number') { throw new TypeError('argument must be a Number'); + } this._ensure(1); this._buf[this._offset++] = b; @@ -72,21 +73,23 @@ Writer.prototype.writeByte = function (b) { Writer.prototype.writeInt = function (i, tag) { - if (typeof (i) !== 'number') + if (typeof (i) !== 'number') { throw new TypeError('argument must be a Number'); - if (typeof (tag) !== 'number') - tag = ASN1.Integer; + } + if (typeof (tag) !== 'number') { tag = ASN1.Integer; } var sz = 4; - while ((((i & 0xff800000) === 0) || ((i & 0xff800000) === 0xff800000 >> 0)) && - (sz > 1)) { + while ((( + (i & 0xff800000) === 0) || + ((i & 0xff800000) === 0xff800000 >> 0) + ) && + (sz > 1)) { sz--; i <<= 8; } - if (sz > 4) - throw newInvalidAsn1Error('BER ints cannot be > 0xffffffff'); + if (sz > 4) { throw newInvalidAsn1Error('BER ints cannot be > 0xffffffff'); } this._ensure(2 + sz); this._buf[this._offset++] = tag; @@ -96,7 +99,6 @@ Writer.prototype.writeInt = function (i, tag) { this._buf[this._offset++] = ((i & 0xff000000) >>> 24); i <<= 8; } - }; @@ -107,20 +109,20 @@ Writer.prototype.writeNull = function () { Writer.prototype.writeEnumeration = function (i, tag) { - if (typeof (i) !== 'number') + if (typeof (i) !== 'number') { throw new TypeError('argument must be a Number'); - if (typeof (tag) !== 'number') - tag = ASN1.Enumeration; + } + if (typeof (tag) !== 'number') { tag = ASN1.Enumeration; } return this.writeInt(i, tag); }; Writer.prototype.writeBoolean = function (b, tag) { - if (typeof (b) !== 'boolean') + if (typeof (b) !== 'boolean') { throw new TypeError('argument must be a Boolean'); - if (typeof (tag) !== 'number') - tag = ASN1.Boolean; + } + if (typeof (tag) !== 'number') { tag = ASN1.Boolean; } this._ensure(3); this._buf[this._offset++] = tag; @@ -130,10 +132,10 @@ Writer.prototype.writeBoolean = function (b, tag) { Writer.prototype.writeString = function (s, tag) { - if (typeof (s) !== 'string') + if (typeof (s) !== 'string') { throw new TypeError('argument must be a string (was: ' + typeof (s) + ')'); - if (typeof (tag) !== 'number') - tag = ASN1.OctetString; + } + if (typeof (tag) !== 'number') { tag = ASN1.OctetString; } var len = Buffer.byteLength(s); this.writeByte(tag); @@ -147,10 +149,12 @@ Writer.prototype.writeString = function (s, tag) { Writer.prototype.writeBuffer = function (buf, tag) { - if (typeof (tag) !== 'number') + if (typeof (tag) !== 'number') { throw new TypeError('tag must be a number'); - if (!Buffer.isBuffer(buf)) + } + if (!Buffer.isBuffer(buf)) { throw new TypeError('argument must be a buffer'); + } this.writeByte(tag); this.writeLength(buf.length); @@ -161,8 +165,9 @@ Writer.prototype.writeBuffer = function (buf, tag) { Writer.prototype.writeStringArray = function (strings) { - if (!Array.isArray(strings)) + if (!Array.isArray(strings)) { throw new TypeError('argument must be an Array[String]'); + } var self = this; strings.forEach(function (s) { @@ -172,13 +177,14 @@ Writer.prototype.writeStringArray = function (strings) { // This is really to solve DER cases, but whatever for now Writer.prototype.writeOID = function (s, tag) { - if (typeof (s) !== 'string') + if (typeof (s) !== 'string') { throw new TypeError('argument must be a string'); - if (typeof (tag) !== 'number') - tag = ASN1.OID; + } + if (typeof (tag) !== 'number') { tag = ASN1.OID; } - if (!/^([0-9]+\.){3,}[0-9]+$/.test(s)) + if (!/^([0-9]+\.){3,}[0-9]+$/.test(s)) { throw new Error('argument is not a valid OID string'); + } function encodeOctet(bytes, octet) { if (octet < 128) { @@ -222,8 +228,9 @@ Writer.prototype.writeOID = function (s, tag) { Writer.prototype.writeLength = function (len) { - if (typeof (len) !== 'number') + if (typeof (len) !== 'number') { throw new TypeError('argument must be a Number'); + } this._ensure(4); @@ -247,8 +254,7 @@ Writer.prototype.writeLength = function (len) { }; Writer.prototype.startSequence = function (tag) { - if (typeof (tag) !== 'number') - tag = ASN1.Sequence | ASN1.Constructor; + if (typeof (tag) !== 'number') { tag = ASN1.Sequence | ASN1.Constructor; } this.writeByte(tag); this._seq.push(this._offset); @@ -299,8 +305,7 @@ Writer.prototype._ensure = function (len) { if (this._size - this._offset < len) { var sz = this._size * this._options.growthFactor; - if (sz - this._offset < len) - sz += len; + if (sz - this._offset < len) { sz += len; } var buf = Buffer.alloc(sz); diff --git a/package.json b/package.json index 801c3c3..0273d98 100644 --- a/package.json +++ b/package.json @@ -15,17 +15,18 @@ }, "main": "lib/index.js", "dependencies": { - "safer-buffer": "~2.1.0" + "safer-buffer": "~2.1.2" }, "devDependencies": { - "istanbul": "^0.3.6", - "faucet": "0.0.1", - "tape": "^3.5.0", - "eslint": "2.13.1", - "eslint-plugin-joyent": "~1.3.0" + "tape": "^5.0.1", + "eslint": "^7.1.0", + "eslint-plugin-joyent": "^2.1.0", + "nyc": "^15.1.0", + "tap-nyc": "^1.0.3" }, "scripts": { "test": "tape ./test/ber/*.test.js", + "cover": "nyc tape test/run.js | tap-nyc", "lint": "eslint ." }, "license": "MIT" diff --git a/test/ber/reader.test.js b/test/ber/reader.test.js index 95ac5a9..467bcbe 100644 --- a/test/ber/reader.test.js +++ b/test/ber/reader.test.js @@ -161,20 +161,20 @@ test('read sequence', function (t) { test('anonymous LDAPv3 bind', function (t) { var BIND = Buffer.alloc(14); - BIND[0] = 0x30; // Sequence - BIND[1] = 12; // len - BIND[2] = 0x02; // ASN.1 Integer - BIND[3] = 1; // len - BIND[4] = 0x04; // msgid (make up 4) - BIND[5] = 0x60; // Bind Request - BIND[6] = 7; // len - BIND[7] = 0x02; // ASN.1 Integer - BIND[8] = 1; // len - BIND[9] = 0x03; // v3 + BIND[0] = 0x30; // Sequence + BIND[1] = 12; // len + BIND[2] = 0x02; // ASN.1 Integer + BIND[3] = 1; // len + BIND[4] = 0x04; // msgid (make up 4) + BIND[5] = 0x60; // Bind Request + BIND[6] = 7; // len + BIND[7] = 0x02; // ASN.1 Integer + BIND[8] = 1; // len + BIND[9] = 0x03; // v3 BIND[10] = 0x04; // String (bind dn) - BIND[11] = 0; // len + BIND[11] = 0; // len BIND[12] = 0x80; // ContextSpecific (choice) - BIND[13] = 0; // simple bind + BIND[13] = 0; // simple bind // Start testing ^^ var ber = new BerReader(BIND); diff --git a/test/ber/writer.test.js b/test/ber/writer.test.js index 17c4671..a9d483e 100644 --- a/test/ber/writer.test.js +++ b/test/ber/writer.test.js @@ -321,9 +321,9 @@ test('LDAP bind message', function (t) { var dn = 'cn=foo,ou=unit,o=test'; var writer = new BerWriter(); writer.startSequence(); - writer.writeInt(3); // msgid = 3 - writer.startSequence(0x60); // ldap bind - writer.writeInt(3); // ldap v3 + writer.writeInt(3); // msgid = 3 + writer.startSequence(0x60); // ldap bind + writer.writeInt(3); // ldap v3 writer.writeString(dn); writer.writeByte(0x80); writer.writeByte(0x00); diff --git a/tools/jsstyle.conf b/tools/jsstyle.conf deleted file mode 100644 index 6f09704..0000000 --- a/tools/jsstyle.conf +++ /dev/null @@ -1,14 +0,0 @@ -# -# 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) 2018, Joyent, Inc. -# - -indent=2 -doxygen -unparenthesized-return=0 -strict-indent=true diff --git a/tools/mk/Makefile.defs b/tools/mk/Makefile.defs deleted file mode 100644 index 73dd612..0000000 --- a/tools/mk/Makefile.defs +++ /dev/null @@ -1,105 +0,0 @@ -# -# 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) 2018, 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. -# -# MAKE_STAMPS_DIR The directory in which make stamp files are to be -# created. See comments below on expensive targets. -# -# CACHE_DIR A directory tree in which temporary files may be -# collected by download, tarball extraction, etc. This -# directory is completely removed by "make distclean". -# Files in this directory are not intended to be shipped. -# - -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 - -CACHE_DIR ?= cache -DISTCLEAN_FILES += $(CACHE_DIR) - -# -# EXPENSIVE TARGETS AND MAKE STAMP FILES -# -# Targets which are expensive to run and lack a single file that marks -# completion are difficult to track with make; e.g., "npm install". One -# solution to this problem is to create "stamp" files with symbolic names which -# are created as the final step in a complex make rule in order to mark -# completion. -# -# In order to make these more uniform, and easier to target with "make clean", -# we will attempt to store them under a single directory. Note that these -# files are never targets for shipping in build artefacts. -# -# Stamp-backed targets come in several parts. First, a macro should be defined -# which names a file in the MAKE_STAMPS_DIR directory. Then, a target which -# creates this stamp file must be provided. The recipe for this target should -# use MAKE_STAMP_REMOVE and MAKE_STAMP_CREATE to perform the appropriate stamp -# management. -# -# For example: -# -# --- Makefile.*.defs: -# -# $(STAMP_EXPENSIVE_RESULT) := $(MAKE_STAMPS_DIR)/expensive-result -# -# --- Makefile.*.targ: -# -# $(STAMP_EXPENSIVE_RESULT): input/file another/input/file -# $(MAKE_STAMP_REMOVE) -# rm -rf output_tree/ # <--- ensure a clean slate -# expensive_program -o output_tree/ $^ -# $(MAKE_STAMP_CREATE) -# -# NOTE: Every stamp file is exposed as an implicit "stamp-$STAMP_NAME" target. -# The example above could be built manually by invoking: -# -# make stamp-expensive-result -# -MAKE_STAMPS_DIR ?= make_stamps -CLEAN_FILES += $(MAKE_STAMPS_DIR) - -MAKE_STAMP_REMOVE = mkdir -p $(@D); rm -f $(@) -MAKE_STAMP_CREATE = mkdir -p $(@D); touch $(@) diff --git a/tools/mk/Makefile.deps b/tools/mk/Makefile.deps deleted file mode 100644 index 91f8346..0000000 --- a/tools/mk/Makefile.deps +++ /dev/null @@ -1,87 +0,0 @@ -# -*- 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) 2017, 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 - -# -# eslint -# -ESLINT_EXEC ?= node_modules/.bin/eslint -ifdef NODE - ESLINT := $(NODE) $(ESLINT_EXEC) -else - ESLINT ?= $(ESLINT_EXEC) -endif - -# Install eslint. -# -# The install of specific modules is to allow running "make check" -# without having to do a complete install of all npm dependencies. -# -# NPM_EXEC will be defined if either of "Makefile.{node,node_prebuilt}.defs" -# is included. -ifdef NPM -$(ESLINT_EXEC): package.json | $(NPM_EXEC) - ESLINT_VER=$$($(NODE) -e 'console.log(require("./package.json").devDependencies["eslint"] || "")') && \ - ESLINT_JOY_VER=$$($(NODE) -e 'console.log(require("./package.json").devDependencies["eslint-plugin-joyent"] || "")') && \ - [[ -n $$ESLINT_VER && -n $$ESLINT_JOY_VER ]] && \ - $(NPM) install --no-save eslint@$$ESLINT_VER eslint-plugin-joyent@$$ESLINT_JOY_VER && \ - touch $(ESLINT_EXEC) -else -$(ESLINT_EXEC): package.json - ESLINT_VER=$$(node -e 'console.log(require("./package.json").devDependencies["eslint"] || "")') && \ - ESLINT_JOY_VER=$$(node -e 'console.log(require("./package.json").devDependencies["eslint-plugin-joyent"] || "")') && \ - [[ -n $$ESLINT_VER && -n $$ESLINT_JOY_VER ]] && \ - npm install --no-save eslint@$$ESLINT_VER eslint-plugin-joyent@$$ESLINT_JOY_VER && \ - touch $(ESLINT_EXEC) -endif - -# -# 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 deleted file mode 100644 index 487824d..0000000 --- a/tools/mk/Makefile.node.defs +++ /dev/null @@ -1,110 +0,0 @@ -# -# 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) 2017, 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 - -# -# These paths should be used during the build process to invoke Node and -# Node-related build tools like NPM. All paths are fully qualified so that -# they work regardless of the current working directory at the point of -# invocation. -# -# Note that where PATH is overridden, the value chosen must cause execution of -# "node" to find the same binary to which the NODE macro refers. -# -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 deleted file mode 100644 index bf53f78..0000000 --- a/tools/mk/Makefile.node.targ +++ /dev/null @@ -1,42 +0,0 @@ -# -*- 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 deleted file mode 100644 index 29a83f7..0000000 --- a/tools/mk/Makefile.node_deps.defs +++ /dev/null @@ -1,43 +0,0 @@ -# -*- 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 deleted file mode 100644 index bb2ab4f..0000000 --- a/tools/mk/Makefile.node_deps.targ +++ /dev/null @@ -1,24 +0,0 @@ -# -*- 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 deleted file mode 100644 index 2129742..0000000 --- a/tools/mk/Makefile.node_prebuilt.defs +++ /dev/null @@ -1,159 +0,0 @@ -# -# 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) 2017, 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) - -# -# These paths should be used during the build process to invoke Node and -# Node-related build tools like NPM. All paths are fully qualified so that -# they work regardless of the current working directory at the point of -# invocation. -# -# Note that where PATH is overridden, the value chosen must cause execution of -# "node" to find the same binary to which the NODE macro refers. -# -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 deleted file mode 100644 index 6877333..0000000 --- a/tools/mk/Makefile.node_prebuilt.targ +++ /dev/null @@ -1,42 +0,0 @@ -# -*- 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 deleted file mode 100644 index b988bbe..0000000 --- a/tools/mk/Makefile.smf.defs +++ /dev/null @@ -1,40 +0,0 @@ -# -*- 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 deleted file mode 100644 index f78de96..0000000 --- a/tools/mk/Makefile.smf.targ +++ /dev/null @@ -1,29 +0,0 @@ -# -*- 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 deleted file mode 100644 index dac448a..0000000 --- a/tools/mk/Makefile.targ +++ /dev/null @@ -1,345 +0,0 @@ -# -# 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) 2017, 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: ".") -# -# ESLINT Path to eslint (default: "eslint") -# -# ESLINT_FLAGS Additional flags to pass through to eslint -# -# 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 ?= $(NODE) tools/bashstyle -CP ?= cp -CSCOPE ?= cscope -CSCOPE_DIRS ?= . -ESLINT ?= eslint -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. -# - -ESLINT_TARGET = $(if $(ESLINT_FILES), check-eslint) -.PHONY: check-eslint -check-eslint: $(ESLINT_EXEC) - $(ESLINT) $(ESLINT_FLAGS) $(ESLINT_FILES) - -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:: $(ESLINT_TARGET) 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) - $(MKDIR) $(shell dirname $@) - $(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 - -# -# This rule automatically exposes every "stamp" file as a target that can be -# invoked manually as "stamp-$STAMP_NAME". For example, if a stamp has been -# defined thus: -# -# STAMP_EXPENSIVE_RESULT := $(MAKE_STAMPS_DIR)/expensive-result -# -# ... this can be invoked manually as "make stamp-expensive-result". Note that -# these phony targets are essentially just for interactive usage. Targets -# should be specified to depend on the macro containing the stamp file name. -# -# See also the comments in "Makefile.defs". -# -stamp-%: $(MAKE_STAMPS_DIR)/% - @: