Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add licenses as prefixes to output bundles #1605

Merged
merged 5 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/vm/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function compile(compileConfig: dataform.ICompileConfig) {
vmIndexFileName,
'return require("@dataform/core").version || "0.0.0"'
);
if (semver.lt(dataformCoreVersion, "3.0.0")) {
if (semver.lt(dataformCoreVersion, "3.0.0-alpha.0")) {
throw new Error("@dataform/core ^3.0.0 required.");
}

Expand Down
11 changes: 6 additions & 5 deletions packages/@dataform/cli/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("//tools:ts_library.bzl", "ts_library")
load("//:version.bzl", "DF_VERSION")
load("//packages:index.bzl", "pkg_bundle", "pkg_json", "pkg_npm_tar")
load("//packages:index.bzl", "LICENSE_HEADER", "add_license_header_to_file", "pkg_bundle", "pkg_json", "pkg_npm_tar")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -65,9 +65,9 @@ pkg_json(

pkg_bundle(
name = "bundle",
args = ["--banner='#!/usr/bin/env node'"],
entry_point = "index.ts",
allow_node_builtins = True,
args = ["--banner='#!/usr/bin/env node\n" + LICENSE_HEADER + "'"],
entry_point = "index.ts",
externals = externals,
deps = [
":cli",
Expand All @@ -76,9 +76,9 @@ pkg_bundle(

pkg_bundle(
name = "worker_bundle",
args = ["--banner='#!/usr/bin/env node'"],
entry_point = "worker.ts",
allow_node_builtins = True,
args = ["--banner='#!/usr/bin/env node\n" + LICENSE_HEADER + "'"],
entry_point = "worker.ts",
externals = externals,
deps = [
":cli",
Expand All @@ -91,5 +91,6 @@ pkg_npm_tar(
":bundle",
":package.json",
":worker_bundle",

],
)
24 changes: 15 additions & 9 deletions packages/@dataform/core/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("//tools:ts_library.bzl", "ts_library")
load("//:version.bzl", "DF_VERSION")
load("//packages:index.bzl", "pkg_bundle", "pkg_bundle_dts", "pkg_json", "pkg_npm_tar")
load("//packages:index.bzl", "pkg_json", "pkg_npm_tar", "add_license_header_to_file")
load("//tools/common:copy.bzl", "copy_file")

package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -29,11 +29,11 @@ load("@build_bazel_rules_nodejs//:index.bzl", "npm_package_bin")
npm_package_bin(
name = "bundle",
outs = [
"bundle.js",
"bundle_no_license.js",
],
args = [
"--config=$(location webpack.config.js)",
"--output=$(location bundle.js)",
"--output=$(location bundle_no_license.js)",
"--mode=production"
],
data = [
Expand All @@ -55,17 +55,23 @@ pkg_json(
version = DF_VERSION,
)

copy_file(
name = "core_proto",
src = "//protos:core.proto",
out = "core.proto",
add_license_header_to_file(
name="core_proto_with_license",
from_file="//protos:core.proto",
to_file="core.proto",
)

add_license_header_to_file(
name="bundle_with_license",
from_file="bundle",
to_file="bundle.js",
)

pkg_npm_tar(
name = "package",
deps = [
":bundle",
":bundle_with_license",
":package.json",
":core.proto",
":core_proto_with_license",
],
)
31 changes: 31 additions & 0 deletions packages/index.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,34 @@ def pkg_npm_tar(name, srcs = [], deps = []):
cmd = "tar -cvzf $(location {name}.tgz) -C $(location :{name})/.. --dereference {name}"
.format(name = name),
)

LICENSE_HEADER = """// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
"""

def add_license_header_to_file(name, from_file, to_file):
"""
Adds the Apache 2.0 license header to a file. This is not done in-place because Bazel requires
separate output and input files.
"""
native.genrule(
name=name,
srcs=[from_file],
outs=[to_file],
cmd=(
(
"echo '{license_header}' | cat - $(location {from_file}) > $(location {to_file})"
).format(from_file=from_file, to_file=to_file, license_header=LICENSE_HEADER)
),
)
2 changes: 1 addition & 1 deletion version.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# NOTE: If you change the format of this line, you must change the bash command
# in /scripts/publish to extract the version string correctly.
DF_VERSION = "3.0.0"
DF_VERSION = "3.0.0-alpha.0"