diff --git a/Blueprints b/Blueprints index 7ccfb0e..a1cf51b 100644 --- a/Blueprints +++ b/Blueprints @@ -176,6 +176,13 @@ bootstrap_go_binary{ blueprint_go_binary { name: "microfactory", + deps: ["blueprint-microfactory"], + srcs: ["microfactory/main/main.go"], +} + +bootstrap_go_package { + name: "blueprint-microfactory", + pkgPath: "github.com/google/blueprint/microfactory", srcs: ["microfactory/microfactory.go"], testSrcs: ["microfactory/microfactory_test.go"], } diff --git a/microfactory/main/main.go b/microfactory/main/main.go new file mode 100644 index 0000000..f639963 --- /dev/null +++ b/microfactory/main/main.go @@ -0,0 +1,23 @@ +// Copyright 2017 Google Inc. All rights reserved. +// +// 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. + +package main + +import ( + "github.com/google/blueprint/microfactory" +) + +func main() { + microfactory.Main() +} diff --git a/microfactory/microfactory.bash b/microfactory/microfactory.bash index 8898512..ded7b33 100644 --- a/microfactory/microfactory.bash +++ b/microfactory/microfactory.bash @@ -47,7 +47,12 @@ function build_go local mf_cmd if [ $from_src -eq 1 ]; then - mf_cmd="${GOROOT}/bin/go run ${mf_src}/microfactory.go" + # `go run` requires a single main package, so create one + local gen_src_dir="${BUILDDIR}/.microfactory_$(uname)_intermediates/src" + mkdir -p "${gen_src_dir}" + sed "s/^package microfactory/package main/" "${mf_src}/microfactory.go" >"${gen_src_dir}/microfactory.go" + + mf_cmd="${GOROOT}/bin/go run ${gen_src_dir}/microfactory.go" else mf_cmd="${mf_bin}" fi diff --git a/microfactory/microfactory.go b/microfactory/microfactory.go index ad1c7fa..c1d41dc 100644 --- a/microfactory/microfactory.go +++ b/microfactory/microfactory.go @@ -39,7 +39,7 @@ // Combined with a shell script like microfactory.bash that uses `go run` to // run Microfactory for the first time, go programs can be quickly bootstrapped // entirely from source (and a standard go distribution). -package main +package microfactory import ( "bytes" @@ -430,7 +430,7 @@ func (p *GoPackage) Link(out string) error { // and if does, it will launch a new copy and return true. Otherwise it will return // false to continue executing. func rebuildMicrofactory(mybin string, pkgMap *pkgPathMapping) bool { - mysrc, ok, err := pkgMap.Path("github.com/google/blueprint/microfactory") + mysrc, ok, err := pkgMap.Path("github.com/google/blueprint/microfactory/main") if err != nil { fmt.Println(os.Stderr, "Error finding microfactory source:", err) os.Exit(1) @@ -501,7 +501,9 @@ func un(f func()) { f() } -func main() { +// microfactory.bash will make a copy of this file renamed into the main package for use with `go run` +func main() { Main() } +func Main() { var output, mybin, trimPath string var pkgMap pkgPathMapping diff --git a/microfactory/microfactory_test.go b/microfactory/microfactory_test.go index 8c02bcf..ad0967c 100644 --- a/microfactory/microfactory_test.go +++ b/microfactory/microfactory_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package microfactory import ( "flag"