Skip to content

Commit 926836b

Browse files
authored
Merge pull request #293 from dscho/make-/dev/fd/-work
Ensure that /dev/fd/ & friends exist
2 parents 1f655ba + 176c355 commit 926836b

File tree

7 files changed

+81
-18
lines changed

7 files changed

+81
-18
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,6 @@ jobs:
6161
6262
# Verify that the locale is set, enabling `grep -P` to work
6363
test 123 = "$(printf '1248\n123\n' | grep -P '2(?!4)')"
64+
65+
# Verify that /dev/fd/<pid> works
66+
test hello = "$(cat <(echo hello))"

.vscode/settings.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
"vstfs://.*"
1111
],
1212
"cSpell.words": [
13+
"artifactsize",
14+
"autodrain",
1315
"Backoff",
16+
"mqueue",
1417
"MSYSTEM",
1518
"Pacman",
16-
"artifactsize",
17-
"autodrain",
1819
"unzipper",
19-
"vercel"
20+
"vercel",
21+
"winsymlinks"
2022
],
2123
"git.ignoreLimitWarning": true
2224
}

__tests__/main.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,15 @@ if (process.env.RUN_NETWORK_TESTS !== 'true') {
5858
expect(
5959
statSync.bind(null, `${outputDirectory}/mingw64/bin/gcc.exe`)
6060
).not.toThrow()
61+
62+
const hello = child_process.spawnSync(
63+
'usr\\bin\\bash.exe',
64+
['-lc', 'cat <(echo hello)'],
65+
{
66+
cwd: outputDirectory
67+
}
68+
)
69+
expect(hello.stderr.toString()).toBe('')
70+
expect(hello.stdout.toString()).toBe('hello\n')
6171
})
6272
}

dist/index.js

Lines changed: 36 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

main.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as core from '@actions/core'
2+
import {get, mkdirp} from './src/downloader'
23
import {restoreCache, saveCache} from '@actions/cache'
3-
import {get} from './src/downloader'
44
import process from 'process'
5+
import {spawnSync} from 'child_process'
56

67
async function run(): Promise<void> {
78
try {
@@ -80,6 +81,29 @@ async function run(): Promise<void> {
8081
) {
8182
core.exportVariable('LC_CTYPE', 'C.UTF-8')
8283
}
84+
85+
// ensure that /dev/fd/*, /dev/mqueue and friends exist
86+
for (const path of ['/dev/mqueue', '/dev/shm']) {
87+
mkdirp(`${outputDirectory}${path}`)
88+
}
89+
90+
const ln = (linkPath: string, target: string): void => {
91+
const child = spawnSync('ln.exe', ['-s', target, linkPath], {
92+
cwd: outputDirectory,
93+
env: {
94+
MSYS: 'winsymlinks:sys'
95+
}
96+
})
97+
if (child.error) throw child.error
98+
}
99+
for (const [linkPath, target] of Object.entries({
100+
fd: 'fd',
101+
stdin: 'fd/0',
102+
stdout: 'fd/1',
103+
stderr: 'fd/2'
104+
})) {
105+
ln(`/dev/${linkPath}`, `/proc/self/${target}`)
106+
}
83107
} catch (error) {
84108
core.setFailed(error instanceof Error ? error.message : `${error}`)
85109
}

src/downloader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function fetchJSONFromURL<T>(url: string): Promise<T> {
1919
return (await res.json()) as T
2020
}
2121

22-
function mkdirp(directoryPath: string): void {
22+
export function mkdirp(directoryPath: string): void {
2323
try {
2424
const stat = fs.statSync(directoryPath)
2525
if (stat.isDirectory()) {

0 commit comments

Comments
 (0)