cflag: remove circular dependency

pull/4487/head
Kris Cherven 2020-04-18 10:29:43 -04:00 committed by GitHub
parent eb923b4995
commit 3cc7009440
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 101 additions and 95 deletions

View File

@ -6,6 +6,7 @@ module builder
import (
os
time
v.cflag
v.pref
v.util
term
@ -570,7 +571,7 @@ fn (c &Builder) build_thirdparty_obj_files() {
}
}
fn (v &Builder) build_thirdparty_obj_file(path string, moduleflags []CFlag) {
fn (v &Builder) build_thirdparty_obj_file(path string, moduleflags []cflag.CFlag) {
obj_path := os.real_path(path)
if os.exists(obj_path) {
return

View File

@ -1,25 +1,10 @@
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module builder
import os
// parsed cflag
struct CFlag {
mod string // the module in which the flag was given
os string // eg. windows | darwin | linux
name string // eg. -I
value string // eg. /path/to/include
}
pub fn (c &CFlag) str() string {
return 'CFlag{ name: "$c.name" value: "$c.value" mod: "$c.mod" os: "$c.os" }'
}
import v.cflag
// get flags for current os
fn (v &Builder) get_os_cflags() []CFlag {
mut flags := []CFlag
fn (v &Builder) get_os_cflags() []cflag.CFlag {
mut flags := []cflag.CFlag
mut ctimedefines := []string
if v.pref.compile_defines.len > 0 {
ctimedefines << v.pref.compile_defines
@ -38,8 +23,8 @@ fn (v &Builder) get_os_cflags() []CFlag {
return flags
}
fn (v &Builder) get_rest_of_module_cflags(c &CFlag) []CFlag {
mut flags := []CFlag
fn (v &Builder) get_rest_of_module_cflags(c &cflag.CFlag) []cflag.CFlag {
mut flags := []cflag.CFlag
cflags := v.get_os_cflags()
for flag in cflags {
if c.mod == flag.mod {
@ -52,67 +37,3 @@ fn (v &Builder) get_rest_of_module_cflags(c &CFlag) []CFlag {
return flags
}
// format flag
fn (cf &CFlag) format() string {
mut value := cf.value
if cf.name in ['-l', '-Wa', '-Wl', '-Wp'] && value.len > 0 {
return '${cf.name}${value}'.trim_space()
}
// convert to absolute path
if cf.name == '-I' || cf.name == '-L' || value.ends_with('.o') {
value = '"' + os.real_path(value) + '"'
}
return '$cf.name $value'.trim_space()
}
// TODO: implement msvc specific c_options_before_target and c_options_after_target ...
fn (cflags []CFlag) c_options_before_target_msvc() string {
return ''
}
fn (cflags []CFlag) c_options_after_target_msvc() string {
return ''
}
fn (cflags []CFlag) c_options_before_target() string {
// -I flags, optimization flags and so on
mut args := []string
for flag in cflags {
if flag.name != '-l' {
args << flag.format()
}
}
return args.join(' ')
}
fn (cflags []CFlag) c_options_after_target() string {
// -l flags (libs)
mut args := []string
for flag in cflags {
if flag.name == '-l' {
args << flag.format()
}
}
return args.join(' ')
}
fn (cflags []CFlag) c_options_without_object_files() string {
mut args := []string
for flag in cflags {
if flag.value.ends_with('.o') || flag.value.ends_with('.obj') {
continue
}
args << flag.format()
}
return args.join(' ')
}
fn (cflags []CFlag) c_options_only_object_files() string {
mut args := []string
for flag in cflags {
if flag.value.ends_with('.o') || flag.value.ends_with('.obj') {
args << flag.format()
}
}
return args.join(' ')
}

View File

@ -2,6 +2,7 @@ module builder
import os
import v.pref
import v.cflag
#flag windows -l shell32
#flag windows -l dbghelp
@ -304,7 +305,7 @@ pub fn (v mut Builder) cc_msvc() {
os.rm(out_name_obj)
}
fn build_thirdparty_obj_file_with_msvc(path string, moduleflags []CFlag) {
fn build_thirdparty_obj_file_with_msvc(path string, moduleflags []cflag.CFlag) {
msvc := find_msvc()or{
println('Could not find visual studio')
return
@ -355,7 +356,7 @@ mut:
other_flags []string
}
fn (cflags []CFlag) msvc_string_flags() MsvcStringFlags {
fn (cflags []cflag.CFlag) msvc_string_flags() MsvcStringFlags {
mut real_libs := []string
mut inc_paths := []string
mut lib_paths := []string

View File

@ -0,0 +1,83 @@
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module cflag
import os
// parsed cflag
struct CFlag {
mod string // the module in which the flag was given
os string // eg. windows | darwin | linux
name string // eg. -I
value string // eg. /path/to/include
}
pub fn (c &CFlag) str() string {
return 'CFlag{ name: "$c.name" value: "$c.value" mod: "$c.mod" os: "$c.os" }'
}
// format flag
pub fn (cf &CFlag) format() string {
mut value := cf.value
if cf.name in ['-l', '-Wa', '-Wl', '-Wp'] && value.len > 0 {
return '${cf.name}${value}'.trim_space()
}
// convert to absolute path
if cf.name == '-I' || cf.name == '-L' || value.ends_with('.o') {
value = '"' + os.real_path(value) + '"'
}
return '$cf.name $value'.trim_space()
}
// TODO: implement msvc specific c_options_before_target and c_options_after_target ...
fn (cflags []CFlag) c_options_before_target_msvc() string {
return ''
}
fn (cflags []CFlag) c_options_after_target_msvc() string {
return ''
}
fn (cflags []CFlag) c_options_before_target() string {
// -I flags, optimization flags and so on
mut args := []string
for flag in cflags {
if flag.name != '-l' {
args << flag.format()
}
}
return args.join(' ')
}
fn (cflags []CFlag) c_options_after_target() string {
// -l flags (libs)
mut args := []string
for flag in cflags {
if flag.name == '-l' {
args << flag.format()
}
}
return args.join(' ')
}
fn (cflags []CFlag) c_options_without_object_files() string {
mut args := []string
for flag in cflags {
if flag.value.ends_with('.o') || flag.value.ends_with('.obj') {
continue
}
args << flag.format()
}
return args.join(' ')
}
fn (cflags []CFlag) c_options_only_object_files() string {
mut args := []string
for flag in cflags {
if flag.value.ends_with('.o') || flag.value.ends_with('.obj') {
args << flag.format()
}
}
return args.join(' ')
}

View File

@ -3,12 +3,12 @@
// that can be found in the LICENSE file.
module table
import v.builder
import v.cflag
// check if cflag is in table
fn (table &Table) has_cflag(cflag builder.CFlag) bool {
fn (table &Table) has_cflag(flag cflag.CFlag) bool {
for cf in table.cflags {
if cf.os == cflag.os && cf.name == cflag.name && cf.value == cflag.value {
if cf.os == flag.os && cf.name == flag.name && cf.value == flag.value {
return true
}
}
@ -17,9 +17,9 @@ fn (table &Table) has_cflag(cflag builder.CFlag) bool {
// parse the flags to (table.cflags) []CFlag
// Note: clean up big time (joe-c)
pub fn (var table Table) parse_cflag(cflag, mod string, ctimedefines []string) ?bool {
pub fn (var table Table) parse_cflag(cflg, mod string, ctimedefines []string) ?bool {
allowed_flags := ['framework', 'library', 'Wa', 'Wl', 'Wp', 'I', 'l', 'L']
flag_orig := cflag.trim_space()
flag_orig := cflg.trim_space()
var flag := flag_orig
if flag == '' {
return true
@ -76,7 +76,7 @@ pub fn (var table Table) parse_cflag(cflag, mod string, ctimedefines []string) ?
hint := if name == '-l' { 'library name' } else { 'path' }
return error('bad #flag `$flag_orig`: missing $hint after `$name`')
}
cf := builder.CFlag{
cf := cflag.CFlag{
mod: mod
os: fos
name: name

View File

@ -4,7 +4,7 @@
module table
import os
import v.builder
import v.cflag
pub struct Table {
pub mut:
@ -13,7 +13,7 @@ pub mut:
fns map[string]Fn
imports []string // List of all imports
modules []string // List of all modules registered by the application
cflags []builder.CFlag // TODO a different module? importing builder from table feels weird
cflags []cflag.CFlag
}
pub struct Fn {