(buildCtx context.Context)
| 133 | } |
| 134 | |
| 135 | func (ctx *BuildContext) Build(buildCtx context.Context) (meta *BuildMeta, err error) { |
| 136 | if buildCtx == nil { |
| 137 | buildCtx = context.Background() |
| 138 | } |
| 139 | ctx.ctx = buildCtx |
| 140 | if err = ctx.checkCanceled(); err != nil { |
| 141 | return |
| 142 | } |
| 143 | if ctx.target == "types" { |
| 144 | return ctx.buildTypes() |
| 145 | } |
| 146 | |
| 147 | // check previous build |
| 148 | meta, ok, err := ctx.Exists() |
| 149 | if err != nil || ok { |
| 150 | return |
| 151 | } |
| 152 | if err = ctx.checkCanceled(); err != nil { |
| 153 | return |
| 154 | } |
| 155 | |
| 156 | // install the package |
| 157 | ctx.status = "install" |
| 158 | err = ctx.install() |
| 159 | if err != nil { |
| 160 | return |
| 161 | } |
| 162 | |
| 163 | // check previous build again after installation (in case the sub-module path has been changed by the `install` function) |
| 164 | meta, ok, err = ctx.Exists() |
| 165 | if err != nil || ok { |
| 166 | return |
| 167 | } |
| 168 | if err = ctx.checkCanceled(); err != nil { |
| 169 | return |
| 170 | } |
| 171 | |
| 172 | // analyze splitting modules if bundling |
| 173 | if ctx.pkgJson.Exports.Len() > 1 && ctx.shouldBundle() { |
| 174 | ctx.status = "analyze" |
| 175 | err = ctx.analyzeSplitting() |
| 176 | if err != nil { |
| 177 | return |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | // build the module |
| 182 | ctx.status = "build" |
| 183 | meta, _, err = ctx.buildModule(false) |
| 184 | if err != nil { |
| 185 | return |
| 186 | } |
| 187 | if err = ctx.checkCanceled(); err != nil { |
| 188 | return |
| 189 | } |
| 190 | |
| 191 | // save the build result to the storage |
| 192 | key := ctx.Path() |
no test coverage detected