From ddaabf258811182865a8552ab06b2a826a133c5d Mon Sep 17 00:00:00 2001 From: Elias Kassell Date: Thu, 7 Dec 2023 14:22:39 +0000 Subject: [PATCH 1/5] fix file namings --- packages/@dataform/core/BUILD | 24 +++++++++++++++--------- packages/index.bzl | 31 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/packages/@dataform/core/BUILD b/packages/@dataform/core/BUILD index 669fc6b6f..94c6300ea 100644 --- a/packages/@dataform/core/BUILD +++ b/packages/@dataform/core/BUILD @@ -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"]) @@ -29,11 +29,11 @@ load("@build_bazel_rules_nodejs//:index.bzl", "npm_package_bin") npm_package_bin( name = "bundle", outs = [ - "bundle.js", + "bundle-tmp.js", ], args = [ "--config=$(location webpack.config.js)", - "--output=$(location bundle.js)", + "--output=$(location bundle-tmp.js)", "--mode=production" ], data = [ @@ -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", ], ) diff --git a/packages/index.bzl b/packages/index.bzl index 18a857d02..db3360bb4 100644 --- a/packages/index.bzl +++ b/packages/index.bzl @@ -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) + ), + ) From f0d24745c0e238d0b06fcdcf5a1803f72a8eae24 Mon Sep 17 00:00:00 2001 From: Elias Kassell Date: Thu, 7 Dec 2023 14:27:00 +0000 Subject: [PATCH 2/5] Add licenses to the CLI too --- packages/@dataform/cli/BUILD | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/@dataform/cli/BUILD b/packages/@dataform/cli/BUILD index 56ae623a6..cdb46ab38 100644 --- a/packages/@dataform/cli/BUILD +++ b/packages/@dataform/cli/BUILD @@ -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", "pkg_bundle", "pkg_json", "pkg_npm_tar", "add_license_header_to_file") package(default_visibility = ["//visibility:public"]) @@ -64,7 +64,7 @@ pkg_json( ) pkg_bundle( - name = "bundle", + name = "bundle_no_license", args = ["--banner='#!/usr/bin/env node'"], entry_point = "index.ts", allow_node_builtins = True, @@ -75,7 +75,7 @@ pkg_bundle( ) pkg_bundle( - name = "worker_bundle", + name = "worker_bundle_no_license", args = ["--banner='#!/usr/bin/env node'"], entry_point = "worker.ts", allow_node_builtins = True, @@ -85,11 +85,23 @@ pkg_bundle( ], ) +add_license_header_to_file( + name="bundle_with_license", + from_file=":bundle_no_license", + to_file=":bundle.js", +) + +add_license_header_to_file( + name="worker_bundle_with_license", + from_file=":worker_bundle_no_license", + to_file=":worker_bundle.js", +) + pkg_npm_tar( name = "package", deps = [ - ":bundle", + ":bundle_with_license", ":package.json", - ":worker_bundle", + ":worker_bundle_with_license", ], ) From e692c8bbd72bcabd962057b839a54c11dbeb11df Mon Sep 17 00:00:00 2001 From: Elias Kassell Date: Thu, 7 Dec 2023 14:31:34 +0000 Subject: [PATCH 3/5] Tidy usage --- packages/@dataform/core/BUILD | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/@dataform/core/BUILD b/packages/@dataform/core/BUILD index 94c6300ea..a530a3008 100644 --- a/packages/@dataform/core/BUILD +++ b/packages/@dataform/core/BUILD @@ -29,11 +29,11 @@ load("@build_bazel_rules_nodejs//:index.bzl", "npm_package_bin") npm_package_bin( name = "bundle", outs = [ - "bundle-tmp.js", + "bundle_no_license.js", ], args = [ "--config=$(location webpack.config.js)", - "--output=$(location bundle-tmp.js)", + "--output=$(location bundle_no_license.js)", "--mode=production" ], data = [ @@ -51,7 +51,7 @@ pkg_json( "//:package.json", "//packages/@dataform:package.layer.json", ], - main = "bundle.js", + main = "bundle.js.no_license", version = DF_VERSION, ) From df11c358cc141a39f6f7fea0d017eacf8b4b15f5 Mon Sep 17 00:00:00 2001 From: Elias Kassell Date: Thu, 7 Dec 2023 15:17:46 +0000 Subject: [PATCH 4/5] Fix build and bump version --- cli/vm/compile.ts | 2 +- packages/@dataform/cli/BUILD | 31 ++++++++++--------------------- packages/@dataform/core/BUILD | 8 ++++---- version.bzl | 2 +- 4 files changed, 16 insertions(+), 27 deletions(-) diff --git a/cli/vm/compile.ts b/cli/vm/compile.ts index caff6d25f..7800d70cc 100644 --- a/cli/vm/compile.ts +++ b/cli/vm/compile.ts @@ -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."); } diff --git a/packages/@dataform/cli/BUILD b/packages/@dataform/cli/BUILD index cdb46ab38..5429abcd5 100644 --- a/packages/@dataform/cli/BUILD +++ b/packages/@dataform/cli/BUILD @@ -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", "add_license_header_to_file") +load("//packages:index.bzl", "LICENSE_HEADER", "add_license_header_to_file", "pkg_bundle", "pkg_json", "pkg_npm_tar") package(default_visibility = ["//visibility:public"]) @@ -64,10 +64,10 @@ pkg_json( ) pkg_bundle( - name = "bundle_no_license", - args = ["--banner='#!/usr/bin/env node'"], - entry_point = "index.ts", + name = "bundle", allow_node_builtins = True, + args = ["--banner='#!/usr/bin/env node\n" + LICENSE_HEADER + "'"], + entry_point = "index.ts", externals = externals, deps = [ ":cli", @@ -75,33 +75,22 @@ pkg_bundle( ) pkg_bundle( - name = "worker_bundle_no_license", - args = ["--banner='#!/usr/bin/env node'"], - entry_point = "worker.ts", + name = "worker_bundle", allow_node_builtins = True, + args = ["--banner='#!/usr/bin/env node\n" + LICENSE_HEADER + "'"], + entry_point = "worker.ts", externals = externals, deps = [ ":cli", ], ) -add_license_header_to_file( - name="bundle_with_license", - from_file=":bundle_no_license", - to_file=":bundle.js", -) - -add_license_header_to_file( - name="worker_bundle_with_license", - from_file=":worker_bundle_no_license", - to_file=":worker_bundle.js", -) - pkg_npm_tar( name = "package", deps = [ - ":bundle_with_license", + ":bundle", ":package.json", - ":worker_bundle_with_license", + ":worker_bundle", + ], ) diff --git a/packages/@dataform/core/BUILD b/packages/@dataform/core/BUILD index a530a3008..a5fb23c48 100644 --- a/packages/@dataform/core/BUILD +++ b/packages/@dataform/core/BUILD @@ -51,20 +51,20 @@ pkg_json( "//:package.json", "//packages/@dataform:package.layer.json", ], - main = "bundle.js.no_license", + main = "bundle.js", version = DF_VERSION, ) add_license_header_to_file( name="core_proto_with_license", from_file="//protos:core.proto", - to_file=":core.proto", + to_file="core.proto", ) add_license_header_to_file( name="bundle_with_license", - from_file=":bundle", - to_file=":bundle.js", + from_file="bundle", + to_file="bundle.js", ) pkg_npm_tar( diff --git a/version.bzl b/version.bzl index 58b7b25d3..6689c3325 100644 --- a/version.bzl +++ b/version.bzl @@ -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" From f46ddc12232b5cc29b31e829e0ac60c4d023c163 Mon Sep 17 00:00:00 2001 From: Elias Kassell Date: Thu, 7 Dec 2023 15:34:22 +0000 Subject: [PATCH 5/5] Fix core version in test --- core/main_test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/main_test.ts b/core/main_test.ts index b2f714802..656765b49 100644 --- a/core/main_test.ts +++ b/core/main_test.ts @@ -195,7 +195,7 @@ select 1 AS \${dataform.projectConfig.vars.selectVar}` expect(asPlainObject(result.compile.compiledGraph)).deep.equals( asPlainObject({ - dataformCoreVersion: "3.0.0", + dataformCoreVersion: "3.0.0-alpha.0", graphErrors: {}, projectConfig: { defaultDatabase: "dataform", @@ -342,7 +342,7 @@ select 1 AS \${dataform.projectConfig.vars.columnVar}` } } ], - dataformCoreVersion: "3.0.0", + dataformCoreVersion: "3.0.0-alpha.0", graphErrors: {}, projectConfig: { defaultLocation: "us",