1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

Simplify pbjs build with hack.

Just check in the generated files and create them using
js/pbjs_hack.py. This allows vscode to be used and sane
compilations.
This commit is contained in:
Ryan Dahl 2018-06-12 05:16:41 +02:00
parent 0f71da91d3
commit dd48f8095c
6 changed files with 2191 additions and 32 deletions

4
.gitignore vendored
View file

@ -4,5 +4,5 @@ dist/
deno deno
assets.go assets.go
msg.pb.go msg.pb.go
msg.pb.js /msg.pb.js
msg.pb.d.ts /msg.pb.d.ts

View file

@ -98,8 +98,8 @@ run_node("bundle") {
run_node("run_tsc") { run_node("run_tsc") {
main_source = "js/main.ts" main_source = "js/main.ts"
sources = [ sources = [
"$target_gen_dir/node_modules/deno_pb/msg.pb.d.ts", "js/msg.pb.d.ts",
"$target_gen_dir/node_modules/deno_pb/msg.pb.js", "js/msg.pb.js",
"js/tsconfig.json", "js/tsconfig.json",
main_source, main_source,
] ]
@ -109,50 +109,28 @@ run_node("run_tsc") {
out_dir + "/main.map", out_dir + "/main.map",
] ]
deps = [ deps = [
":run_pbjs", ":pbjs_hack",
":run_pbts",
] ]
args = [ args = [
"./node_modules/.bin/tsc", "./node_modules/.bin/tsc",
"-p", "-p",
rebase_path("js/tsconfig.json", root_build_dir), rebase_path("js/tsconfig.json", root_build_dir),
"--baseUrl",
rebase_path(target_gen_dir + "/node_modules", root_build_dir),
"--outDir", "--outDir",
rebase_path(out_dir, root_build_dir), rebase_path(out_dir, root_build_dir),
] ]
} }
run_node("run_pbjs") { action("pbjs_hack") {
script = "js/pbjs_hack.py"
sources = [ sources = [
"msg.proto", "msg.proto",
] ]
outputs = [ outputs = [
"$target_gen_dir/node_modules/deno_pb/msg.pb.js", "$target_gen_dir/pbjs_hack.stamp",
] ]
args = [ args = [
"./node_modules/.bin/pbjs",
"--target=static-module",
"--wraper=commonjs",
"--out=" + rebase_path(outputs[0], root_build_dir),
rebase_path(sources[0], root_build_dir), rebase_path(sources[0], root_build_dir),
] rebase_path(outputs[0], root_build_dir),
}
run_node("run_pbts") {
sources = [
"$target_gen_dir/node_modules/deno_pb/msg.pb.js",
]
outputs = [
"$target_gen_dir/node_modules/deno_pb/msg.pb.d.ts",
]
args = [
"./node_modules/.bin/pbts",
"--out=" + rebase_path(outputs[0], root_build_dir),
rebase_path(sources[0], root_build_dir),
]
deps = [
":run_pbjs",
] ]
} }

View file

@ -1,5 +1,5 @@
/// <reference path="deno.d.ts" /> /// <reference path="deno.d.ts" />
//import { main as pb } from "deno_pb/msg.pb" //import { main as pb } from "./msg.pb"
import * as ts from "typescript"; import * as ts from "typescript";
const globalEval = eval; const globalEval = eval;

432
deno2/js/msg.pb.d.ts vendored Normal file
View file

@ -0,0 +1,432 @@
import * as $protobuf from "protobufjs";
/** Namespace main. */
export namespace main {
/** Properties of a BaseMsg. */
interface IBaseMsg {
/** BaseMsg channel */
channel?: string | null;
/** BaseMsg payload */
payload?: Uint8Array | null;
}
/** Represents a BaseMsg. */
class BaseMsg implements IBaseMsg {
/**
* Constructs a new BaseMsg.
* @param [properties] Properties to set
*/
constructor(properties?: main.IBaseMsg);
/** BaseMsg channel. */
public channel: string;
/** BaseMsg payload. */
public payload: Uint8Array;
/**
* Creates a new BaseMsg instance using the specified properties.
* @param [properties] Properties to set
* @returns BaseMsg instance
*/
public static create(properties?: main.IBaseMsg): main.BaseMsg;
/**
* Encodes the specified BaseMsg message. Does not implicitly {@link main.BaseMsg.verify|verify} messages.
* @param message BaseMsg message or plain object to encode
* @param [writer] Writer to encode to
* @returns Writer
*/
public static encode(
message: main.IBaseMsg,
writer?: $protobuf.Writer
): $protobuf.Writer;
/**
* Encodes the specified BaseMsg message, length delimited. Does not implicitly {@link main.BaseMsg.verify|verify} messages.
* @param message BaseMsg message or plain object to encode
* @param [writer] Writer to encode to
* @returns Writer
*/
public static encodeDelimited(
message: main.IBaseMsg,
writer?: $protobuf.Writer
): $protobuf.Writer;
/**
* Decodes a BaseMsg message from the specified reader or buffer.
* @param reader Reader or buffer to decode from
* @param [length] Message length if known beforehand
* @returns BaseMsg
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
public static decode(
reader: $protobuf.Reader | Uint8Array,
length?: number
): main.BaseMsg;
/**
* Decodes a BaseMsg message from the specified reader or buffer, length delimited.
* @param reader Reader or buffer to decode from
* @returns BaseMsg
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
public static decodeDelimited(
reader: $protobuf.Reader | Uint8Array
): main.BaseMsg;
/**
* Verifies a BaseMsg message.
* @param message Plain object to verify
* @returns `null` if valid, otherwise the reason why it is not
*/
public static verify(message: { [k: string]: any }): string | null;
/**
* Creates a BaseMsg message from a plain object. Also converts values to their respective internal types.
* @param object Plain object
* @returns BaseMsg
*/
public static fromObject(object: { [k: string]: any }): main.BaseMsg;
/**
* Creates a plain object from a BaseMsg message. Also converts values to other types if specified.
* @param message BaseMsg
* @param [options] Conversion options
* @returns Plain object
*/
public static toObject(
message: main.BaseMsg,
options?: $protobuf.IConversionOptions
): { [k: string]: any };
/**
* Converts this BaseMsg to JSON.
* @returns JSON object
*/
public toJSON(): { [k: string]: any };
}
/** Properties of a Msg. */
interface IMsg {
/** Msg command */
command?: main.Msg.Command | null;
/** Msg error */
error?: string | null;
/** Msg startCwd */
startCwd?: string | null;
/** Msg startArgv */
startArgv?: string[] | null;
/** Msg startDebugFlag */
startDebugFlag?: boolean | null;
/** Msg startMainJs */
startMainJs?: string | null;
/** Msg startMainMap */
startMainMap?: string | null;
/** Msg codeFetchModuleSpecifier */
codeFetchModuleSpecifier?: string | null;
/** Msg codeFetchContainingFile */
codeFetchContainingFile?: string | null;
/** Msg codeFetchResModuleName */
codeFetchResModuleName?: string | null;
/** Msg codeFetchResFilename */
codeFetchResFilename?: string | null;
/** Msg codeFetchResSourceCode */
codeFetchResSourceCode?: string | null;
/** Msg codeFetchResOutputCode */
codeFetchResOutputCode?: string | null;
/** Msg codeCacheFilename */
codeCacheFilename?: string | null;
/** Msg codeCacheSourceCode */
codeCacheSourceCode?: string | null;
/** Msg codeCacheOutputCode */
codeCacheOutputCode?: string | null;
/** Msg exitCode */
exitCode?: number | null;
/** Msg timerStartId */
timerStartId?: number | null;
/** Msg timerStartInterval */
timerStartInterval?: boolean | null;
/** Msg timerStartDelay */
timerStartDelay?: number | null;
/** Msg timerReadyId */
timerReadyId?: number | null;
/** Msg timerReadyDone */
timerReadyDone?: boolean | null;
/** Msg timerClearId */
timerClearId?: number | null;
/** Msg fetchReqId */
fetchReqId?: number | null;
/** Msg fetchReqUrl */
fetchReqUrl?: string | null;
/** Msg fetchResId */
fetchResId?: number | null;
/** Msg fetchResStatus */
fetchResStatus?: number | null;
/** Msg fetchResHeaderLine */
fetchResHeaderLine?: string[] | null;
/** Msg fetchResBody */
fetchResBody?: Uint8Array | null;
/** Msg readFileSyncFilename */
readFileSyncFilename?: string | null;
/** Msg readFileSyncData */
readFileSyncData?: Uint8Array | null;
/** Msg writeFileSyncFilename */
writeFileSyncFilename?: string | null;
/** Msg writeFileSyncData */
writeFileSyncData?: Uint8Array | null;
/** Msg writeFileSyncPerm */
writeFileSyncPerm?: number | null;
}
/** Represents a Msg. */
class Msg implements IMsg {
/**
* Constructs a new Msg.
* @param [properties] Properties to set
*/
constructor(properties?: main.IMsg);
/** Msg command. */
public command: main.Msg.Command;
/** Msg error. */
public error: string;
/** Msg startCwd. */
public startCwd: string;
/** Msg startArgv. */
public startArgv: string[];
/** Msg startDebugFlag. */
public startDebugFlag: boolean;
/** Msg startMainJs. */
public startMainJs: string;
/** Msg startMainMap. */
public startMainMap: string;
/** Msg codeFetchModuleSpecifier. */
public codeFetchModuleSpecifier: string;
/** Msg codeFetchContainingFile. */
public codeFetchContainingFile: string;
/** Msg codeFetchResModuleName. */
public codeFetchResModuleName: string;
/** Msg codeFetchResFilename. */
public codeFetchResFilename: string;
/** Msg codeFetchResSourceCode. */
public codeFetchResSourceCode: string;
/** Msg codeFetchResOutputCode. */
public codeFetchResOutputCode: string;
/** Msg codeCacheFilename. */
public codeCacheFilename: string;
/** Msg codeCacheSourceCode. */
public codeCacheSourceCode: string;
/** Msg codeCacheOutputCode. */
public codeCacheOutputCode: string;
/** Msg exitCode. */
public exitCode: number;
/** Msg timerStartId. */
public timerStartId: number;
/** Msg timerStartInterval. */
public timerStartInterval: boolean;
/** Msg timerStartDelay. */
public timerStartDelay: number;
/** Msg timerReadyId. */
public timerReadyId: number;
/** Msg timerReadyDone. */
public timerReadyDone: boolean;
/** Msg timerClearId. */
public timerClearId: number;
/** Msg fetchReqId. */
public fetchReqId: number;
/** Msg fetchReqUrl. */
public fetchReqUrl: string;
/** Msg fetchResId. */
public fetchResId: number;
/** Msg fetchResStatus. */
public fetchResStatus: number;
/** Msg fetchResHeaderLine. */
public fetchResHeaderLine: string[];
/** Msg fetchResBody. */
public fetchResBody: Uint8Array;
/** Msg readFileSyncFilename. */
public readFileSyncFilename: string;
/** Msg readFileSyncData. */
public readFileSyncData: Uint8Array;
/** Msg writeFileSyncFilename. */
public writeFileSyncFilename: string;
/** Msg writeFileSyncData. */
public writeFileSyncData: Uint8Array;
/** Msg writeFileSyncPerm. */
public writeFileSyncPerm: number;
/**
* Creates a new Msg instance using the specified properties.
* @param [properties] Properties to set
* @returns Msg instance
*/
public static create(properties?: main.IMsg): main.Msg;
/**
* Encodes the specified Msg message. Does not implicitly {@link main.Msg.verify|verify} messages.
* @param message Msg message or plain object to encode
* @param [writer] Writer to encode to
* @returns Writer
*/
public static encode(
message: main.IMsg,
writer?: $protobuf.Writer
): $protobuf.Writer;
/**
* Encodes the specified Msg message, length delimited. Does not implicitly {@link main.Msg.verify|verify} messages.
* @param message Msg message or plain object to encode
* @param [writer] Writer to encode to
* @returns Writer
*/
public static encodeDelimited(
message: main.IMsg,
writer?: $protobuf.Writer
): $protobuf.Writer;
/**
* Decodes a Msg message from the specified reader or buffer.
* @param reader Reader or buffer to decode from
* @param [length] Message length if known beforehand
* @returns Msg
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
public static decode(
reader: $protobuf.Reader | Uint8Array,
length?: number
): main.Msg;
/**
* Decodes a Msg message from the specified reader or buffer, length delimited.
* @param reader Reader or buffer to decode from
* @returns Msg
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
public static decodeDelimited(
reader: $protobuf.Reader | Uint8Array
): main.Msg;
/**
* Verifies a Msg message.
* @param message Plain object to verify
* @returns `null` if valid, otherwise the reason why it is not
*/
public static verify(message: { [k: string]: any }): string | null;
/**
* Creates a Msg message from a plain object. Also converts values to their respective internal types.
* @param object Plain object
* @returns Msg
*/
public static fromObject(object: { [k: string]: any }): main.Msg;
/**
* Creates a plain object from a Msg message. Also converts values to other types if specified.
* @param message Msg
* @param [options] Conversion options
* @returns Plain object
*/
public static toObject(
message: main.Msg,
options?: $protobuf.IConversionOptions
): { [k: string]: any };
/**
* Converts this Msg to JSON.
* @returns JSON object
*/
public toJSON(): { [k: string]: any };
}
namespace Msg {
/** Command enum. */
enum Command {
ERROR = 0,
START = 1,
CODE_FETCH = 2,
CODE_FETCH_RES = 3,
CODE_CACHE = 4,
EXIT = 5,
TIMER_START = 6,
TIMER_READY = 7,
TIMER_CLEAR = 8,
FETCH_REQ = 9,
FETCH_RES = 10,
READ_FILE_SYNC = 11,
READ_FILE_SYNC_RES = 12,
WRITE_FILE_SYNC = 13
}
}
}

1700
deno2/js/msg.pb.js Normal file

File diff suppressed because it is too large Load diff

49
deno2/js/pbjs_hack.py Executable file
View file

@ -0,0 +1,49 @@
#!/usr/bin/env python
"""
gn can only run python scripts.
protobuf.js must generate some javascript files.
it's very difficult to get this into the gn build sanely.
therefore we write them into the source directory.
"""
import subprocess
import sys
import os
js_path = os.path.dirname(os.path.realpath(__file__))
bin_path = os.path.join(js_path, "node_modules", ".bin")
pbjs_bin = os.path.join(bin_path, "pbjs")
pbts_bin = os.path.join(bin_path, "pbts")
msg_pbjs_out = os.path.join(js_path, "msg.pb.js")
msg_pbts_out = os.path.join(js_path, "msg.pb.d.ts")
assert os.path.exists(pbjs_bin)
assert os.path.exists(pbts_bin)
proto_in = sys.argv[1]
stamp_file = sys.argv[2]
def touch(fname):
if os.path.exists(fname):
os.utime(fname, None)
else:
open(fname, 'a').close()
subprocess.check_call([
"node",
pbjs_bin,
"--target=static-module",
"--wraper=commonjs",
"--out=" + msg_pbjs_out,
proto_in
])
assert os.path.exists(msg_pbjs_out)
subprocess.check_call([
"node",
pbts_bin,
"--out=" + msg_pbts_out,
msg_pbjs_out
])
assert os.path.exists(msg_pbts_out)
touch(stamp_file)