Skip to content

Commit 44cc5ce

Browse files
committed
清理无用代码,并排序Import
1 parent 33fb9e6 commit 44cc5ce

11 files changed

Lines changed: 63 additions & 200 deletions

File tree

config/config.example.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ name = "TestJudger"
1212
"xc6slx9-2-ftg256.verilog.xst" = "/usr/src/xc6slx9-2-ftg256.verilog.xst"
1313
[language]
1414
cat = "/usr/bin/cat"
15-
ise = "/usr/bin/ise" # TODO: delete
16-
shell = "/usr/bin/shell" # TODO: delete?
17-
verilog = "/usr/bin/verilog" # TODO: delete
18-
vhdl = "/usr/bin/vhdl" # TODO: delete
1915
xst = "/usr/bin/xst"
2016
ngdbuild = "/usr/bin/ngdbuild"
2117
map = "/usr/bin/map"

src/Config.ts

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,21 @@ import { plainToClass, Type } from "class-transformer";
33
import {
44
ArrayNotEmpty,
55
ArrayUnique,
6-
isBoolean,
76
IsBoolean,
87
IsHexadecimal,
98
IsInt,
109
IsNotEmpty,
1110
IsNumber,
1211
IsOptional,
1312
IsPositive,
14-
isString,
1513
IsString,
1614
Min,
17-
ValidateBy,
1815
ValidateNested,
1916
validateSync,
20-
ValidationOptions,
2117
} from "class-validator";
2218
import fs from "fs";
2319
import { getLogger } from "log4js";
2420

25-
function Or(...constraints: ((value: unknown) => boolean)[]): PropertyDecorator;
26-
function Or(
27-
validationOptions?: ValidationOptions,
28-
...constraints: ((value: unknown) => boolean)[]
29-
): PropertyDecorator;
30-
function Or(
31-
validationOptions?: ValidationOptions | ((value: unknown) => boolean),
32-
...constraints: ((value: unknown) => boolean)[]
33-
): PropertyDecorator {
34-
if (typeof validationOptions === "function") {
35-
constraints = [validationOptions, ...constraints];
36-
validationOptions = undefined;
37-
}
38-
return ValidateBy(
39-
{
40-
name: "or",
41-
constraints,
42-
validator: {
43-
validate: (value, validationArguments) => {
44-
if (validationArguments) {
45-
for (const constraint of validationArguments.constraints) {
46-
if (constraint(value)) {
47-
return true;
48-
}
49-
}
50-
}
51-
return false;
52-
},
53-
},
54-
},
55-
validationOptions
56-
);
57-
}
58-
5921
const logger = getLogger("ConfigService");
6022
const configToml = fs.readFileSync("config/config.toml").toString();
6123
export class LanguageConfig {
@@ -64,18 +26,6 @@ export class LanguageConfig {
6426
cat!: string;
6527
@IsString()
6628
@IsNotEmpty()
67-
ise!: string;
68-
@Or(isBoolean, isString)
69-
@IsNotEmpty()
70-
shell!: string | boolean;
71-
@IsString()
72-
@IsNotEmpty()
73-
verilog!: string;
74-
@IsString()
75-
@IsNotEmpty()
76-
vhdl!: string;
77-
@IsString()
78-
@IsNotEmpty()
7929
xst!: string;
8030
@IsString()
8131
@IsNotEmpty()
@@ -157,20 +107,6 @@ export class FpgaConfig {
157107
})
158108
serial!: string[];
159109
}
160-
export class Builtin {
161-
@IsString()
162-
@IsNotEmpty()
163-
"ax309.ucf"!: string;
164-
@IsString()
165-
@IsNotEmpty()
166-
"main.cmd"!: string;
167-
@IsString()
168-
@IsNotEmpty()
169-
"verilog.prj"!: string;
170-
@IsString()
171-
@IsNotEmpty()
172-
"xc6slx9-2-ftg256.verilog.xst"!: string;
173-
}
174110
export class Config {
175111
@ValidateNested()
176112
@IsNotEmpty()

src/Spawn/Language/PlainText.ts

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,21 @@
11
import path from "path";
22
import { getConfig } from "../../Config";
33
import {
4-
RunOption,
4+
ExecType,
55
Language,
66
LanguageConfigureOption,
7-
ExecType,
7+
RunOption,
88
RunType,
99
} from "./decl";
1010

1111
export class PlainText extends Language {
12-
private src = "src.in";
13-
1412
constructor(option: LanguageConfigureOption) {
1513
super(option);
1614
if (this.execType !== ExecType.Usr)
1715
throw new Error("Unrecognized language");
1816
}
1917

20-
get compileCacheable(): boolean {
21-
return true;
22-
}
23-
24-
get srcFileName(): string {
25-
return this.src;
26-
}
27-
28-
compileOptionGenerator(): RunOption {
29-
return { skip: true };
30-
}
31-
32-
get compiledFiles(): string[] {
33-
return [];
34-
}
35-
36-
pragramOptionGenerator(): RunOption {
37-
const binPath = path.join(this.runDir, this.src);
38-
return {
39-
skip: false,
40-
command: getConfig().language.cat,
41-
args: [binPath],
42-
};
43-
}
44-
45-
get judgeTimeout() {
46-
return 1000;
47-
}
18+
srcFileName = "src.in";
4819

4920
[RunType.Synthesis] = {
5021
cacheable: true,
@@ -85,4 +56,13 @@ export class PlainText extends Language {
8556
return { skip: true };
8657
},
8758
};
59+
60+
pragramOptionGenerator(): RunOption {
61+
const binPath = path.join(this.runDir, this.srcFileName);
62+
return {
63+
skip: false,
64+
command: getConfig().language.cat,
65+
args: [binPath],
66+
};
67+
}
8868
}

src/Spawn/Language/Verilog.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,8 @@
11
import { join } from "path";
2-
import { Language, RunOption, RunType } from "./decl";
32
import { getConfig } from "../../Config";
3+
import { Language, RunOption, RunType } from "./decl";
44

55
export class Verilog extends Language {
6-
get compileCacheable() {
7-
return true;
8-
}
9-
10-
get compiledFiles() {
11-
return [join(this.runDir, "par.bit")];
12-
}
13-
14-
compileOptionGenerator(): RunOption {
15-
return {
16-
skip: false,
17-
command: getConfig().language.verilog,
18-
args: [getConfig().language.ise],
19-
spawnOption: {
20-
timeLimit: 60000,
21-
},
22-
};
23-
}
24-
25-
get judgeTimeout() {
26-
return 1000;
27-
}
28-
296
srcFileName = "main.v";
307

318
[RunType.Synthesis] = {

src/Spawn/Language/decl.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ export abstract class Language {
5454
this.excutable = option.excutable;
5555
this.runDir = option.runDir;
5656
}
57-
abstract get compileCacheable(): boolean;
58-
abstract get compiledFiles(): string[];
59-
abstract get judgeTimeout(): number;
60-
abstract compileOptionGenerator(): RunOption;
6157
abstract get srcFileName(): string;
6258
abstract [RunType.Synthesis]: compileOption;
6359
abstract [RunType.Translate]: compileOption;

src/Spawn/index.ts

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { ChildProcess, spawn } from "child_process";
1+
import { spawn } from "child_process";
22
import { getLogger } from "log4js";
3+
import { constants } from "os";
34
import { BasicSpawnOption, CompleteStdioOptions } from "./BasicSpawn";
45
import { MeteredChildProcess } from "./Meter";
5-
import { constants } from "os";
6-
import { getConfig } from "../Config";
76

87
const logger = getLogger("JailMeterSpawn");
98

@@ -22,33 +21,14 @@ export interface HengSpawnOption {
2221
gid?: number; // nsjail(append root), meter
2322
}
2423

25-
export function loggedSpawn(
26-
spawnFunction: (command: string, args: string[]) => ChildProcess
27-
): (command: string, args: string[]) => ChildProcess {
28-
return function (command: string, args: string[]) {
29-
logger.info(`${command} ${args.join(" ")}`);
30-
return spawnFunction(command, args);
31-
};
32-
}
33-
34-
// intended typo, seted => set
35-
export function optionSetedSpawn<V, T>(
36-
spawn: (command: string, args: string[], options: V) => T,
37-
options: V
38-
): (command: string, args: string[]) => T {
39-
return function (command: string, args: string[]) {
40-
return spawn(command, args, options);
41-
};
42-
}
43-
4424
export function hengSpawn(
4525
command: string,
4626
args: string[],
4727
options: HengSpawnOption
4828
): MeteredChildProcess {
4929
const basicOption: BasicSpawnOption = {
5030
cwd: options.cwd,
51-
shell: getConfig().language.shell,
31+
// shell: getConfig().language.shell,
5232
timeout: options.timeLimit,
5333
};
5434

@@ -59,10 +39,8 @@ export function hengSpawn(
5939
options.stdio.push("pipe");
6040
basicOption.stdio = options.stdio;
6141

62-
const subProcess = loggedSpawn(optionSetedSpawn(spawn, basicOption))(
63-
command,
64-
args
65-
);
42+
logger.info(`${command} ${args.join(" ")}`);
43+
const subProcess = spawn(command, args, basicOption);
6644
return {
6745
...(subProcess as MeteredChildProcess),
6846
result: new Promise((resolve, reject) => {

src/Utilities/ExecutableAgent.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import * as crypto from "crypto";
2+
import fs from "fs";
3+
import { FileHandle } from "fs/promises";
24
import { DynamicFile, Executable } from "heng-protocol";
5+
import { getLogger } from "log4js";
36
import path from "path";
4-
import fs from "fs";
5-
import { ExecType, Language, RunType } from "../Spawn/Language/decl";
6-
import { FileAgent } from "./File";
77
import { getBuiltin, getConfig } from "../Config";
8+
import { hengSpawn, HengSpawnOption } from "../Spawn";
89
import { CompleteStdioOptions } from "../Spawn/BasicSpawn";
910
import { getConfiguredLanguage } from "../Spawn/Language";
10-
import { getLogger } from "log4js";
11-
import { FileHandle } from "fs/promises";
12-
import { hengSpawn, HengSpawnOption } from "../Spawn";
11+
import { ExecType, Language, RunType } from "../Spawn/Language/decl";
1312
import { MeterResult } from "../Spawn/Meter";
13+
import { FileAgent } from "./File";
1414

1515
export const SourceCodeName = "srcCode";
1616
export const runLogName = "run.log";

src/Utilities/File.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import axios from "axios";
2+
import * as crypto from "crypto";
13
import fs from "fs";
4+
import { getLogger } from "log4js";
5+
import path, { PlatformPath } from "path";
26
import stream, { Readable } from "stream";
37
import unzip from "unzip-stream";
4-
import path, { PlatformPath } from "path";
58
import util from "util";
69
import { getConfig } from "../Config";
7-
import * as crypto from "crypto";
810
import { Throttle } from "./Throttle";
9-
import { getLogger } from "log4js";
10-
import axios from "axios";
1111
const pipeline = util.promisify(stream.pipeline);
1212

1313
const logger = getLogger("File");

src/Utilities/Judge.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as crypto from "crypto";
2+
import fs from "fs";
13
import {
24
Executable,
35
JudgeCaseResult,
@@ -9,23 +11,21 @@ import {
911
TestPolicy,
1012
} from "heng-protocol";
1113
import { CreateJudgeArgs } from "heng-protocol/internal-protocol/ws";
12-
import path from "path";
13-
import fs from "fs";
14-
import os from "os";
14+
import { range } from "lodash";
1515
import { getLogger } from "log4js";
16+
import os from "os";
17+
import path from "path";
18+
import { SerialPort } from "serialport";
1619
import { getConfig } from "../Config";
17-
import { FileAgent, readStream } from "./File";
18-
import { Throttle } from "./Throttle";
20+
import { Controller } from "../controller";
1921
import { Tests } from "../SelfTest";
20-
import { runLogName, ExecutableAgent } from "./ExecutableAgent";
2122
import { ExecType, RunType } from "../Spawn/Language/decl";
22-
import { range } from "lodash";
23-
import { Controller } from "../controller";
24-
import { stat } from "./Statistics";
25-
import * as crypto from "crypto";
2623
import { MeterResult } from "../Spawn/Meter";
27-
import { SerialPort } from "serialport";
24+
import { ExecutableAgent, runLogName } from "./ExecutableAgent";
25+
import { FileAgent, readStream } from "./File";
2826
import { closePort } from "./Serial";
27+
import { stat } from "./Statistics";
28+
import { Throttle } from "./Throttle";
2929

3030
const UsrCompileResultTransformer = {
3131
mle: JudgeResultKind.CompileMemoryLimitExceeded,

0 commit comments

Comments
 (0)