@ohos-ports/bin-build 0.0.0-stage → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +102 -0
- package/license +21 -0
- package/package.json +48 -4
- package/readme.md +103 -0
- package/README.md +0 -3
package/index.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const decompress = require('decompress');
|
|
6
|
+
const download = require('download');
|
|
7
|
+
const execa = require('execa');
|
|
8
|
+
const pMapSeries = require('p-map-series');
|
|
9
|
+
const tempfile = require('tempfile');
|
|
10
|
+
|
|
11
|
+
// HarmonyOS platform adaptation:
|
|
12
|
+
// On HarmonyOS the FUSE-based user storage makes any directory created while
|
|
13
|
+
// umask 077 is in effect permanently unwritable by its owner (chmod cannot
|
|
14
|
+
// repair it). Autotools `config.status` always creates its `./confXXXXXX`
|
|
15
|
+
// temporary directory with `(umask 077 && mktemp -d ...)` (or a mkdir
|
|
16
|
+
// fallback), so every `./configure && make` build fails with
|
|
17
|
+
// "can't create ./confXXXXX/subs1.awk: Permission denied".
|
|
18
|
+
// Fix: shim `mktemp`/`mkdir` on PATH so they run with a safe umask (022),
|
|
19
|
+
// guaranteeing directories created by build scripts are owner-writable.
|
|
20
|
+
let shimDir = null;
|
|
21
|
+
|
|
22
|
+
const isHarmonyOS = () => process.platform === 'openharmony' || process.platform === 'ohos';
|
|
23
|
+
|
|
24
|
+
const resolveTool = name => {
|
|
25
|
+
for (const dir of (process.env.PATH || '').split(path.delimiter)) {
|
|
26
|
+
if (!dir) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
fs.accessSync(path.join(dir, name), fs.constants.X_OK);
|
|
32
|
+
return path.join(dir, name);
|
|
33
|
+
} catch (_) {}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return null;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const harmonyUmaskShimDir = () => {
|
|
40
|
+
if (shimDir) {
|
|
41
|
+
return shimDir;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
shimDir = fs.mkdtempSync(path.join(os.tmpdir(), 'bin-build-umask-shim-'));
|
|
45
|
+
|
|
46
|
+
for (const tool of ['mktemp', 'mkdir']) {
|
|
47
|
+
const real = resolveTool(tool);
|
|
48
|
+
|
|
49
|
+
if (!real) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
fs.writeFileSync(path.join(shimDir, tool), `#!/bin/sh\numask 022\nexec '${real}' "$@"\n`, {mode: 0o755});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return shimDir;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const exec = (cmd, cwd) => {
|
|
60
|
+
if (isHarmonyOS()) {
|
|
61
|
+
const dir = harmonyUmaskShimDir();
|
|
62
|
+
const prefix = `PATH="${dir}:$PATH"; export PATH; `;
|
|
63
|
+
return pMapSeries(cmd, x => execa.shell(prefix + x, {cwd}));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return pMapSeries(cmd, x => execa.shell(x, {cwd}));
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
exports.directory = (dir, cmd) => {
|
|
70
|
+
if (typeof dir !== 'string') {
|
|
71
|
+
return Promise.reject(new TypeError(`Expected a \`string\`, got \`${typeof dir}\``));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return exec(cmd, dir);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
exports.file = (file, cmd, opts) => {
|
|
78
|
+
opts = Object.assign({strip: 1}, opts);
|
|
79
|
+
|
|
80
|
+
if (typeof file !== 'string') {
|
|
81
|
+
return Promise.reject(new TypeError(`Expected a \`string\`, got \`${typeof file}\``));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const tmp = tempfile();
|
|
85
|
+
|
|
86
|
+
return decompress(file, tmp, opts).then(() => exec(cmd, tmp));
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
exports.url = (url, cmd, opts) => {
|
|
90
|
+
opts = Object.assign({
|
|
91
|
+
extract: true,
|
|
92
|
+
strip: 1
|
|
93
|
+
}, opts);
|
|
94
|
+
|
|
95
|
+
if (typeof url !== 'string') {
|
|
96
|
+
return Promise.reject(new TypeError(`Expected a \`string\`, got \`${typeof url}\``));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const tmp = tempfile();
|
|
100
|
+
|
|
101
|
+
return download(url, tmp, opts).then(() => exec(cmd, tmp));
|
|
102
|
+
};
|
package/license
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) Kevin Martensson <kevinmartensson@gmail.com> (github.com/kevva)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohos-ports/bin-build",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "3.0.0-beta.0",
|
|
4
|
+
"description": "Easily build binaries",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/ohos-ports/ohos-ports.git",
|
|
9
|
+
"directory": "ports/bin-build/3.0.0"
|
|
10
|
+
},
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Kevin Mårtensson",
|
|
13
|
+
"email": "kevinmartensson@gmail.com",
|
|
14
|
+
"url": "https://github.com/kevva"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=4"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"test": "xo && ava"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"index.js"
|
|
24
|
+
],
|
|
25
|
+
"keywords": [
|
|
26
|
+
"binary",
|
|
27
|
+
"build",
|
|
28
|
+
"make"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"decompress": "^4.0.0",
|
|
32
|
+
"download": "^6.2.2",
|
|
33
|
+
"execa": "^0.7.0",
|
|
34
|
+
"p-map-series": "^1.0.0",
|
|
35
|
+
"tempfile": "^2.0.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"ava": "*",
|
|
39
|
+
"del": "^3.0.0",
|
|
40
|
+
"nock": "^9.0.0",
|
|
41
|
+
"path-exists": "^3.0.0",
|
|
42
|
+
"@ohos-ports/xo": "^5.0.1-beta.0"
|
|
43
|
+
},
|
|
44
|
+
"xo": {
|
|
45
|
+
"esnext": true
|
|
46
|
+
},
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/ohos-ports/ohos-ports/issues"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# bin-build [](https://travis-ci.org/kevva/bin-build)
|
|
2
|
+
|
|
3
|
+
> Easily build binaries
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
$ npm install --save bin-build
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
const binBuild = require('bin-build');
|
|
17
|
+
|
|
18
|
+
binBuild.url('http://www.lcdf.org/gifsicle/gifsicle-1.80.tar.gz', [
|
|
19
|
+
'./configure --disable-gifview --disable-gifdiff',
|
|
20
|
+
'make install'
|
|
21
|
+
]).then(() => {
|
|
22
|
+
console.log('gifsicle built successfully');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
binBuild.file('gifsicle-1.80.tar.gz', [
|
|
26
|
+
'./configure --disable-gifview --disable-gifdiff',
|
|
27
|
+
'make install'
|
|
28
|
+
]).then(() => {
|
|
29
|
+
console.log('gifsicle built successfully');
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## API
|
|
35
|
+
|
|
36
|
+
### binBuild.directory(directory, commands)
|
|
37
|
+
|
|
38
|
+
#### directory
|
|
39
|
+
|
|
40
|
+
Type: `string`
|
|
41
|
+
|
|
42
|
+
Path to a directory containing the source code.
|
|
43
|
+
|
|
44
|
+
#### commands
|
|
45
|
+
|
|
46
|
+
Type: `Array`
|
|
47
|
+
|
|
48
|
+
Commands to run when building.
|
|
49
|
+
|
|
50
|
+
### binBuild.file(file, commands, [options])
|
|
51
|
+
|
|
52
|
+
#### file
|
|
53
|
+
|
|
54
|
+
Type: `string`
|
|
55
|
+
|
|
56
|
+
Path to a archive file containing the source code.
|
|
57
|
+
|
|
58
|
+
#### commands
|
|
59
|
+
|
|
60
|
+
Type: `Array`
|
|
61
|
+
|
|
62
|
+
Commands to run when building.
|
|
63
|
+
|
|
64
|
+
#### options
|
|
65
|
+
|
|
66
|
+
Type: `Object`
|
|
67
|
+
|
|
68
|
+
##### strip
|
|
69
|
+
|
|
70
|
+
Type: `number`<br>
|
|
71
|
+
Default: `1`
|
|
72
|
+
|
|
73
|
+
Strip a number of leading paths from file names on extraction.
|
|
74
|
+
|
|
75
|
+
### binBuild.url(url, commands, [options])
|
|
76
|
+
|
|
77
|
+
#### url
|
|
78
|
+
|
|
79
|
+
Type: `string`
|
|
80
|
+
|
|
81
|
+
URL to a archive file containing the source code.
|
|
82
|
+
|
|
83
|
+
#### commands
|
|
84
|
+
|
|
85
|
+
Type: `Array`
|
|
86
|
+
|
|
87
|
+
Commands to run when building.
|
|
88
|
+
|
|
89
|
+
#### options
|
|
90
|
+
|
|
91
|
+
Type: `Object`
|
|
92
|
+
|
|
93
|
+
##### strip
|
|
94
|
+
|
|
95
|
+
Type: `number`<br>
|
|
96
|
+
Default: `1`
|
|
97
|
+
|
|
98
|
+
Strip a number of leading paths from file names on extraction.
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
MIT © [Kevin Mårtensson](https://github.com/kevva)
|
package/README.md
DELETED